diff --git a/frameworks/cert_manager_standard/main/os_dependency/BUILD.gn b/frameworks/cert_manager_standard/main/os_dependency/BUILD.gn index 72da975..75b2cce 100644 --- a/frameworks/cert_manager_standard/main/os_dependency/BUILD.gn +++ b/frameworks/cert_manager_standard/main/os_dependency/BUILD.gn @@ -79,7 +79,6 @@ ohos_static_library("libcert_manager_ipc_client_static") { sources = [ "./cm_ipc/src/cm_ipc_client.c", "./cm_ipc/src/cm_ipc_client_serialization.c", - "./cm_ipc/src/cm_load_sa.cpp", "./cm_ipc/src/cm_request.cpp", ] deps = [ ":libcert_manager_log_mem_static" ] diff --git a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/include/cm_load_sa.h b/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/include/cm_load_sa.h deleted file mode 100644 index c0567f3..0000000 --- a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/include/cm_load_sa.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 CM_LOAD_SA_H -#define CM_LOAD_SA_H - -#include -#include -#include "iremote_object.h" -#include "system_ability_load_callback_stub.h" - -class OnDemandLoadCertManagerCallback : public OHOS::SystemAbilityLoadCallbackStub { -public: - OnDemandLoadCertManagerCallback(std::string servers); - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const OHOS::sptr& remoteObject) override; - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; - OHOS::sptr Promise(void); -private: - std::string servers; - std::promise> promise_; -}; - -#endif /* CM_LOAD_SA_H */ \ No newline at end of file diff --git a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_load_sa.cpp b/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_load_sa.cpp deleted file mode 100644 index 0d43032..0000000 --- a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_load_sa.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 "cm_load_sa.h" -#include "cm_log.h" - -using namespace std; - -OnDemandLoadCertManagerCallback::OnDemandLoadCertManagerCallback(string servers) : servers(servers) -{ - CM_LOG_I("Servers %s on demand Callback constructor success", servers.c_str()); -} diff --git a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_request.cpp b/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_request.cpp index 276ce46..d851b49 100644 --- a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_request.cpp +++ b/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_request.cpp @@ -21,7 +21,6 @@ #include "securec.h" -#include "cm_load_sa.h" #include "cm_log.h" #include "iservice_registry.h" @@ -31,7 +30,7 @@ using namespace OHOS; namespace { constexpr int SA_ID_KEYSTORE_SERVICE = 3512; - constexpr uint32_t MAX_SA_BOOT_DELAY_TIME = 30; + constexpr int32_t LOAD_ABILITY_TIME_OUT_SECONDS = 3; const std::u16string SA_KEYSTORE_SERVICE_DESCRIPTOR = u"ohos.security.cm.service"; } @@ -48,20 +47,7 @@ static sptr CmLoadSystemAbility(void) return object; } - string servers = "CertManager"; - sptr loadCallBack = new (std::nothrow)OnDemandLoadCertManagerCallback(servers); - if (loadCallBack == nullptr) { - CM_LOG_E("new OnDemandLoadCertManagerCallback failed"); - return {}; - } - - int32_t ret = saManager->LoadSystemAbility(SA_ID_KEYSTORE_SERVICE, loadCallBack); - if (ret != ERR_OK) { - CM_LOG_E("systemAbilityId:%d load failed,result code:%d", SA_ID_KEYSTORE_SERVICE, ret); - return {}; - } - - return loadCallBack->Promise(); + return saManager->LoadSystemAbility(SA_ID_KEYSTORE_SERVICE, LOAD_ABILITY_TIME_OUT_SECONDS); } static int32_t CmReadRequestReply(MessageParcel &reply, struct CmBlob *outBlob) @@ -101,17 +87,12 @@ static int32_t CmReadRequestReply(MessageParcel &reply, struct CmBlob *outBlob) int32_t SendRequest(enum CertManagerInterfaceCode type, const struct CmBlob *inBlob, struct CmBlob *outBlob) { - uint32_t i = 0; sptr cmProxy = CmLoadSystemAbility(); - while ((cmProxy == nullptr) && i < MAX_SA_BOOT_DELAY_TIME) { - CM_LOG_E("cmProxy is nullptr, i = %u", i); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); /* 100 is time */ - i++; - } - - cmProxy = CmLoadSystemAbility(); if (cmProxy == nullptr) { - CM_LOG_E("Certtificate manager Proxy is null."); + cmProxy = CmLoadSystemAbility(); + } + if (cmProxy == nullptr) { + CM_LOG_E("Certificate manager Proxy is null."); return CMR_ERROR_NULL_POINTER; } @@ -135,22 +116,3 @@ int32_t SendRequest(enum CertManagerInterfaceCode type, const struct CmBlob *inB } return CmReadRequestReply(reply, outBlob); } - -void OnDemandLoadCertManagerCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const sptr &remoteObject) -{ - CM_LOG_D("OnLoadSystemAbility Success systemAbilityId: %d, IRemoteObject result:%s", - systemAbilityId, ((remoteObject != nullptr) ? "succeed" : "failed")); - promise_.set_value(remoteObject); -} - -void OnDemandLoadCertManagerCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - CM_LOG_E("OnLoadSystemAbility Fail systemAbilityId: %d", systemAbilityId); - promise_.set_value(nullptr); -} - -sptr OnDemandLoadCertManagerCallback::Promise(void) -{ - return promise_.get_future().get(); -}