From a96c6f4841a10354ec245dd2509ded6133c5701f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zen=E7=9F=A5=E4=BB=81?= Date: Fri, 8 Jul 2022 10:25:13 +0800 Subject: [PATCH 1/3] feat: make dlsm_service start on condition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zen知仁 Change-Id: I3c2a7bfd2e758bc0a43c014d6bb33c348e8232dc Signed-off-by: Zen知仁 --- profile/dslm_service.cfg | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/profile/dslm_service.cfg b/profile/dslm_service.cfg index 2d7e489..19bbd0a 100644 --- a/profile/dslm_service.cfg +++ b/profile/dslm_service.cfg @@ -1,10 +1,27 @@ { - "services": [{ - "name": "dslm_service", - "path": ["/system/bin/sa_main", "/system/profile/dslm_service.xml"], - "uid": "3046", - "gid": "3046", - "secon" : "u:r:dslm_service:s0", - "permission" : ["ohos.permission.ACCESS_IDS"] - }] -} + "jobs": [ + { + "name": "param:startup.service.ctl.dhardware=running", + "condition": "startup.service.ctl.dhardware=running", + "cmds": [ + "start dslm_service" + ] + } + ], + "services": [ + { + "name": "dslm_service", + "start-mode": "condition", + "path": [ + "/system/bin/sa_main", + "/system/profile/dslm_service.xml" + ], + "uid": "3046", + "gid": "3046", + "secon": "u:r:dslm_service:s0", + "permission": [ + "ohos.permission.ACCESS_IDS" + ] + } + ] +} \ No newline at end of file -- Gitee From ce78e1e9a74a8cb5c5840f5996e1b8c33bcd058c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zen=E7=9F=A5=E4=BB=81?= Date: Fri, 8 Jul 2022 16:25:35 +0800 Subject: [PATCH 2/3] feat: support sa startup ondemand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zen知仁 Change-Id: Id88375c2b8c6a019d711684c994328815858b8b3 --- interfaces/inner_api/BUILD.gn | 1 + .../src/standard/device_security_info.cpp | 14 +--- .../standard/device_security_level_loader.cpp | 68 +++++++++++++++++++ .../standard/device_security_level_loader.h | 51 ++++++++++++++ .../standard/device_security_level_proxy.h | 2 +- profile/dslm_service.cfg | 1 + services/sa/standard/dslm_service.cpp | 7 +- 7 files changed, 127 insertions(+), 17 deletions(-) create mode 100644 interfaces/inner_api/src/standard/device_security_level_loader.cpp create mode 100644 interfaces/inner_api/src/standard/device_security_level_loader.h diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index 867f1e4..a843faa 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -22,6 +22,7 @@ ohos_shared_library("dslm_sdk") { "src/standard/device_security_info.cpp", "src/standard/device_security_level_callback_helper.cpp", "src/standard/device_security_level_callback_stub.cpp", + "src/standard/device_security_level_loader.cpp", "src/standard/device_security_level_proxy.cpp", ] diff --git a/interfaces/inner_api/src/standard/device_security_info.cpp b/interfaces/inner_api/src/standard/device_security_info.cpp index 4192fdb..fedd552 100644 --- a/interfaces/inner_api/src/standard/device_security_info.cpp +++ b/interfaces/inner_api/src/standard/device_security_info.cpp @@ -18,11 +18,11 @@ #include #include "hilog/log.h" -#include "iservice_registry.h" #include "device_security_level_callback_helper.h" #include "device_security_level_callback_stub.h" #include "device_security_level_defines.h" +#include "device_security_level_loader.h" #include "device_security_level_proxy.h" using namespace OHOS::HiviewDFX; @@ -46,17 +46,7 @@ static int32_t RequestDeviceSecurityInfoAsyncImpl(const DeviceIdentify *identify HiLog::Error(LABEL, "GetDeviceSecurityInfo input error, timeout too len."); return ERR_INVALID_PARA; } - - auto registry = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (registry == nullptr) { - HiLog::Error(LABEL, "GetDeviceSecurityInfo get registry error."); - return ERR_IPC_REGISTER_ERR; - } - auto object = registry->GetSystemAbility(DEVICE_SECURITY_LEVEL_MANAGER_SA_ID); - if (object == nullptr) { - HiLog::Error(LABEL, "GetDeviceSecurityInfo get object error."); - return ERR_IPC_REMOTE_OBJ_ERR; - } + auto object = DeviceSecurityLevelLoader::GetInstance().LoadDslmService(); auto proxy = iface_cast(object); if (proxy == nullptr) { HiLog::Error(LABEL, "GetDeviceSecurityInfo iface_cast error."); diff --git a/interfaces/inner_api/src/standard/device_security_level_loader.cpp b/interfaces/inner_api/src/standard/device_security_level_loader.cpp new file mode 100644 index 0000000..42372c8 --- /dev/null +++ b/interfaces/inner_api/src/standard/device_security_level_loader.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_security_level_loader.h" + +#include "hilog/log.h" +#include "iservice_registry.h" + +#include "device_security_level_defines.h" +#include "idevice_security_level.h" + +namespace OHOS { +namespace Security { +namespace DeviceSecurityLevel { +using namespace OHOS::HiviewDFX; + +sptr DeviceSecurityLevelLoader::LoadDslmService() +{ + auto registry = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (registry == nullptr) { + HiLog::Error(LABEL, "GetDeviceSecurityInfo get registry error."); + return {}; + } + auto object = registry->GetSystemAbility(DEVICE_SECURITY_LEVEL_MANAGER_SA_ID); + if (object != nullptr) { + return object; + } + + sptr callback = new (std::nothrow) LoadCallback(); + int32_t result = registry->LoadSystemAbility(DEVICE_SECURITY_LEVEL_MANAGER_SA_ID, callback); + if (result != ERR_OK) { + HiLog::Error(LABEL, "GetDeviceSecurityInfo LoadSystemAbility error."); + return {}; + } + return callback->Promise(); +} + +void DeviceSecurityLevelLoader::LoadCallback::OnLoadSystemAbilitySuccess(int32_t sid, const sptr &object) +{ + HiLog::Info(LABEL, "OnLoadSystemAbilitySuccess."); + promise_.set_value(object); +} + +void DeviceSecurityLevelLoader::LoadCallback::OnLoadSystemAbilityFail(int32_t sid) +{ + HiLog::Error(LABEL, "OnLoadSystemAbilityFail."); +} + +sptr DeviceSecurityLevelLoader::LoadCallback::Promise() +{ + return promise_.get_future().get(); +} + +} // namespace DeviceSecurityLevel +} // namespace Security +} // namespace OHOS diff --git a/interfaces/inner_api/src/standard/device_security_level_loader.h b/interfaces/inner_api/src/standard/device_security_level_loader.h new file mode 100644 index 0000000..82bdc91 --- /dev/null +++ b/interfaces/inner_api/src/standard/device_security_level_loader.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVICE_SECURITY_LEVEL_LOADER +#define DEVICE_SECURITY_LEVEL_LOADER + +#include + +#include "iremote_object.h" +#include "nocopyable.h" +#include "singleton.h" +#include "system_ability_load_callback_stub.h" + +namespace OHOS { +namespace Security { +namespace DeviceSecurityLevel { +using namespace OHOS; +class DeviceSecurityLevelLoader : public Singleton { +public: + DeviceSecurityLevelLoader() = default; + ~DeviceSecurityLevelLoader() override = default; + sptr LoadDslmService(); + +private: + class LoadCallback : public SystemAbilityLoadCallbackStub { + public: + void OnLoadSystemAbilitySuccess(int32_t sid, const sptr &object) override; + void OnLoadSystemAbilityFail(int32_t sid) override; + sptr Promise(); + + private: + std::promise> promise_; + }; +}; +} // namespace DeviceSecurityLevel +} // namespace Security +} // namespace OHOS + +#endif // DEVICE_SECURITY_LEVEL_LOADER \ No newline at end of file diff --git a/interfaces/inner_api/src/standard/device_security_level_proxy.h b/interfaces/inner_api/src/standard/device_security_level_proxy.h index 11fee2a..2517385 100644 --- a/interfaces/inner_api/src/standard/device_security_level_proxy.h +++ b/interfaces/inner_api/src/standard/device_security_level_proxy.h @@ -30,7 +30,7 @@ using namespace OHOS; class DeviceSecurityLevelProxy : public IRemoteProxy, public NoCopyable { public: explicit DeviceSecurityLevelProxy(const sptr &impl); - virtual ~DeviceSecurityLevelProxy() = default; + ~DeviceSecurityLevelProxy() override = default; int32_t RequestDeviceSecurityLevel(const DeviceIdentify &identify, const RequestOption &option, const sptr &callback, uint64_t cookie); diff --git a/profile/dslm_service.cfg b/profile/dslm_service.cfg index 19bbd0a..38aa02d 100644 --- a/profile/dslm_service.cfg +++ b/profile/dslm_service.cfg @@ -11,6 +11,7 @@ "services": [ { "name": "dslm_service", + "ondemand" : true, "start-mode": "condition", "path": [ "/system/bin/sa_main", diff --git a/services/sa/standard/dslm_service.cpp b/services/sa/standard/dslm_service.cpp index 06ae03e..ef2a05a 100644 --- a/services/sa/standard/dslm_service.cpp +++ b/services/sa/standard/dslm_service.cpp @@ -36,14 +36,13 @@ DslmService::DslmService(int32_t saId, bool runOnCreate) : SystemAbility(saId, r void DslmService::OnStart() { SECURITY_LOG_INFO("start"); - if (!Publish(this)) { - SECURITY_LOG_ERROR("publish service failed"); - } std::thread t([this]() { if (InitService() == SUCCESS) { SECURITY_LOG_INFO("init service success"); - return; + } + if (!Publish(this)) { + SECURITY_LOG_ERROR("publish service failed"); } }); t.detach(); -- Gitee From 98f4f4e475cc821d944a26d076dd49be21f4aecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zen=E7=9F=A5=E4=BB=81?= Date: Fri, 8 Jul 2022 17:07:56 +0800 Subject: [PATCH 3/3] style: code style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zen知仁 Change-Id: Id88df1dd60c7b98ee17675e0ada03d1f275701d3 --- .../inner_api/src/standard/device_security_level_loader.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/inner_api/src/standard/device_security_level_loader.cpp b/interfaces/inner_api/src/standard/device_security_level_loader.cpp index 42372c8..e503c68 100644 --- a/interfaces/inner_api/src/standard/device_security_level_loader.cpp +++ b/interfaces/inner_api/src/standard/device_security_level_loader.cpp @@ -62,7 +62,6 @@ sptr DeviceSecurityLevelLoader::LoadCallback::Promise() { return promise_.get_future().get(); } - } // namespace DeviceSecurityLevel } // namespace Security } // namespace OHOS -- Gitee