From 86f9c96a975682c2e1664d102464c07ba5d70850 Mon Sep 17 00:00:00 2001 From: libing23 Date: Sat, 27 Jan 2024 16:12:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=89=E5=85=A8=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E5=90=AF=E5=8A=A8=E6=B5=81=E7=A8=8B=20Signed-off-by:?= =?UTF-8?q?=20libing23=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/sec_comp_enhance_adapter.h | 5 ++++ .../src/sec_comp_enhance_adapter.cpp | 10 +++++++ .../include/i_sec_comp_service.h | 1 + .../include/sec_comp_client.h | 1 + .../security_component/include/sec_comp_kit.h | 1 + .../include/sec_comp_proxy.h | 1 + ...ity_component_service_ipc_interface_code.h | 2 +- .../src/sec_comp_client.cpp | 11 +++++++ .../security_component/src/sec_comp_kit.cpp | 5 ++++ .../security_component/src/sec_comp_proxy.cpp | 30 +++++++++++++++++++ .../sa/sa_main/sec_comp_manager.cpp | 25 +++++++++++++++- .../sa/sa_main/sec_comp_manager.h | 1 + .../sa/sa_main/sec_comp_service.cpp | 12 ++++++-- .../sa/sa_main/sec_comp_service.h | 1 + .../sa/sa_main/sec_comp_stub.cpp | 13 ++++++++ .../sa/sa_main/sec_comp_stub.h | 1 + .../mock/src/sec_comp_enhance_adapter.cpp | 5 ++++ .../unittest/src/sec_comp_manager_test.cpp | 18 +++++------ .../unittest/src/sec_comp_service_test.cpp | 18 +++++------ .../sa/test/unittest/src/sec_comp_stub_test.h | 9 ++++-- 20 files changed, 146 insertions(+), 24 deletions(-) diff --git a/frameworks/enhance_adapter/include/sec_comp_enhance_adapter.h b/frameworks/enhance_adapter/include/sec_comp_enhance_adapter.h index 65ff6ba..81c3e08 100644 --- a/frameworks/enhance_adapter/include/sec_comp_enhance_adapter.h +++ b/frameworks/enhance_adapter/include/sec_comp_enhance_adapter.h @@ -68,6 +68,9 @@ public: // notify process died virtual void NotifyProcessDied(int32_t pid) = 0; + + // notify process registered + virtual void AddSecurityComponentProcess(int32_t pid) = 0; }; // for client @@ -105,6 +108,8 @@ public: static void RegisterScIdEnhance(int32_t scId); static void UnregisterScIdEnhance(int32_t scId); + static void AddSecurityComponentProcess(int32_t pid); + static SecCompInputEnhanceInterface* inputHandler; static bool isEnhanceInputHandlerInit; diff --git a/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp b/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp index 8478062..5dfa2e9 100644 --- a/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp +++ b/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp @@ -105,6 +105,16 @@ int32_t SecCompEnhanceAdapter::CheckExtraInfo(const SecCompClickEvent& clickInfo return SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE; } +void SecCompEnhanceAdapter::AddSecurityComponentProcess(int32_t pid) +{ + if (!isEnhanceSrvHandlerInit) { + InitEnhanceHandler(SEC_COMP_ENHANCE_SRV_INTERFACE); + } + if (srvHandler != nullptr) { + srvHandler->AddSecurityComponentProcess(pid); + } +} + bool SecCompEnhanceAdapter::EnhanceDataPreprocess(std::string& componentInfo) { if (!isEnhanceClientHandlerInit) { diff --git a/interfaces/inner_api/security_component/include/i_sec_comp_service.h b/interfaces/inner_api/security_component/include/i_sec_comp_service.h index 8df9269..cd76c2e 100644 --- a/interfaces/inner_api/security_component/include/i_sec_comp_service.h +++ b/interfaces/inner_api/security_component/include/i_sec_comp_service.h @@ -38,6 +38,7 @@ public: const SecCompClickEvent& clickInfo, sptr callerToken) = 0; virtual bool VerifySavePermission(AccessToken::AccessTokenID tokenId) = 0; virtual sptr GetEnhanceRemoteObject() = 0; + virtual int32_t PreRegisterSecCompProcess() = 0; }; } // namespace SecurityComponent } // namespace Security diff --git a/interfaces/inner_api/security_component/include/sec_comp_client.h b/interfaces/inner_api/security_component/include/sec_comp_client.h index 719489f..fca78d5 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_client.h +++ b/interfaces/inner_api/security_component/include/sec_comp_client.h @@ -37,6 +37,7 @@ public: const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken); bool VerifySavePermission(AccessToken::AccessTokenID tokenId); sptr GetEnhanceRemoteObject(bool doLoadSa); + int32_t PreRegisterSecCompProcess(); void FinishStartSASuccess(const sptr& remoteObject); void FinishStartSAFail(); diff --git a/interfaces/inner_api/security_component/include/sec_comp_kit.h b/interfaces/inner_api/security_component/include/sec_comp_kit.h index 0f0ee94..93c7e53 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_kit.h +++ b/interfaces/inner_api/security_component/include/sec_comp_kit.h @@ -33,6 +33,7 @@ public: std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken = nullptr); static bool VerifySavePermission(AccessToken::AccessTokenID tokenId); static sptr GetEnhanceRemoteObject(bool isLoad); + static int32_t PreRegisterSecCompProcess(); }; } // namespace SecurityComponent } // namespace Security diff --git a/interfaces/inner_api/security_component/include/sec_comp_proxy.h b/interfaces/inner_api/security_component/include/sec_comp_proxy.h index 9b5b4e2..f634965 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_proxy.h +++ b/interfaces/inner_api/security_component/include/sec_comp_proxy.h @@ -33,6 +33,7 @@ public: const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken) override; bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override; sptr GetEnhanceRemoteObject() override; + int32_t PreRegisterSecCompProcess() override; private: static inline BrokerDelegator delegator_; diff --git a/interfaces/inner_api/security_component/include/security_component_service_ipc_interface_code.h b/interfaces/inner_api/security_component/include/security_component_service_ipc_interface_code.h index 968ad96..f87389d 100644 --- a/interfaces/inner_api/security_component/include/security_component_service_ipc_interface_code.h +++ b/interfaces/inner_api/security_component/include/security_component_service_ipc_interface_code.h @@ -27,6 +27,7 @@ enum SecurityComponentServiceInterfaceCode { REPORT_SECURITY_COMPONENT_CLICK_EVENT = 3, GET_SECURITY_COMPONENT_ENHANCE_OBJECT = 4, VERIFY_TEMP_SAVE_PERMISSION = 5, + PRE_REGISTER_PROCESS = 6, }; enum EnhanceInterfaceCode { @@ -41,4 +42,3 @@ enum EnhanceCallbackCheckCode { } // namespace Security } // namespace OHOS #endif // SECURITY_COMPONENT_IPC_INTERFACE_CODE_H - diff --git a/interfaces/inner_api/security_component/src/sec_comp_client.cpp b/interfaces/inner_api/security_component/src/sec_comp_client.cpp index 27545fa..7ce91dc 100644 --- a/interfaces/inner_api/security_component/src/sec_comp_client.cpp +++ b/interfaces/inner_api/security_component/src/sec_comp_client.cpp @@ -113,6 +113,17 @@ sptr SecCompClient::GetEnhanceRemoteObject(bool doLoadSa) return proxy->GetEnhanceRemoteObject(); } +int32_t SecCompClient::PreRegisterSecCompProcess() +{ + auto proxy = GetProxy(true); + if (proxy == nullptr) { + SC_LOG_ERROR(LABEL, "Proxy is null"); + return SC_SERVICE_ERROR_VALUE_INVALID; + } + + return proxy->PreRegisterSecCompProcess(); +} + bool SecCompClient::StartLoadSecCompSa() { { diff --git a/interfaces/inner_api/security_component/src/sec_comp_kit.cpp b/interfaces/inner_api/security_component/src/sec_comp_kit.cpp index 04562ca..a8314fb 100644 --- a/interfaces/inner_api/security_component/src/sec_comp_kit.cpp +++ b/interfaces/inner_api/security_component/src/sec_comp_kit.cpp @@ -133,6 +133,11 @@ sptr SecCompKit::GetEnhanceRemoteObject(bool isLoad) { return SecCompClient::GetInstance().GetEnhanceRemoteObject(isLoad); } + +int32_t SecCompKit::PreRegisterSecCompProcess() +{ + return SecCompClient::GetInstance().PreRegisterSecCompProcess(); +} } // namespace SecurityComponent } // namespace Security } // namespace OHOS diff --git a/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp b/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp index 3b56769..6182d7a 100644 --- a/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp +++ b/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp @@ -269,6 +269,36 @@ sptr SecCompProxy::GetEnhanceRemoteObject() } return callback; } + +int32_t SecCompProxy::PreRegisterSecCompProcess() +{ + MessageParcel data; + if (!data.WriteInterfaceToken(SecCompProxy::GetDescriptor())) { + SC_LOG_ERROR(LABEL, "PreRegister write descriptor fail"); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + sptr remote = Remote(); + if (remote == nullptr) { + SC_LOG_ERROR(LABEL, "PreRegister remote service is null"); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + int32_t requestResult = remote->SendRequest( + static_cast(SecurityComponentServiceInterfaceCode::PRE_REGISTER_PROCESS), + data, reply, option); + if (requestResult != SC_OK) { + SC_LOG_ERROR(LABEL, "PreRegister request fail, result: %{public}d", requestResult); + return requestResult; + } + int32_t res; + if (!reply.ReadInt32(res)) { + SC_LOG_ERROR(LABEL, "PreRegister read int32 fail"); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + return res; +} } // namespace SecurityComponent } // namespace Security } // namespace OHOS diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp index f4bd825..5dde35d 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp @@ -155,7 +155,7 @@ SecCompEntity* SecCompManager::GetSecurityComponentFromList(int32_t pid, int32_t bool SecCompManager::IsForegroundCompExist() { return std::any_of(componentMap_.begin(), componentMap_.end(), [](const auto & iter) { - return (iter.second.isForeground) && (iter.second.compList.size() > 0); + return iter.second.isForeground; }); } @@ -285,6 +285,29 @@ void SecCompManager::SendCheckInfoEnhanceSysEvent(int32_t scId, } } +int32_t SecCompManager::AddSecurityComponentProcess(const SecCompCallerInfo& caller) +{ + DelayExitTask::GetInstance().Stop(); + { + OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); + if (isSaExit_) { + SC_LOG_ERROR(LABEL, "SA is exiting, retry..."); + return SC_SERVICE_ERROR_SERVICE_NOT_EXIST; + } + + auto iter = componentMap_.find(caller.pid); + if (iter != componentMap_.end()) { + ProcessCompInfos newProcess; + newProcess.isForeground = true; + newProcess.tokenId = caller.tokenId; + componentMap_[caller.pid] = newProcess; + } + SecCompEnhanceAdapter::EnableInputEnhance(); + } + SecCompEnhanceAdapter::AddSecurityComponentProcess(caller.pid); + return SC_OK; +} + int32_t SecCompManager::RegisterSecurityComponent(SecCompType type, const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, int32_t& scId) { diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.h b/services/security_component_service/sa/sa_main/sec_comp_manager.h index d6a79fa..92e0faa 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.h +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.h @@ -65,6 +65,7 @@ public: bool Initialize(); void ExitSaProcess(); void ExitWhenAppMgrDied(); + int32_t AddSecurityComponentProcess(const SecCompCallerInfo& caller); private: SecCompManager(); diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.cpp b/services/security_component_service/sa/sa_main/sec_comp_service.cpp index 19451bd..7dec764 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_service.cpp @@ -84,8 +84,6 @@ void SecCompService::OnStop() SC_LOG_INFO(LABEL, "Stop service"); state_ = ServiceRunningState::STATE_NOT_START; UnregisterAppStateObserver(); - iAppMgr_ = nullptr; - appStateObserver_ = nullptr; } bool SecCompService::RegisterAppStateObserver() @@ -236,6 +234,16 @@ int32_t SecCompService::ReportSecurityComponentClickEvent(int32_t scId, return res; } +int32_t SecCompService::PreRegisterSecCompProcess() +{ + SecCompCallerInfo caller; + if (!GetCallerInfo(caller)) { + SC_LOG_ERROR(LABEL, "Check caller failed"); + return SC_SERVICE_ERROR_VALUE_INVALID; + } + return SecCompManager::GetInstance().AddSecurityComponentProcess(caller); +} + bool SecCompService::VerifySavePermission(AccessToken::AccessTokenID tokenId) { return SecCompPermManager::GetInstance().VerifySavePermission(tokenId); diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.h b/services/security_component_service/sa/sa_main/sec_comp_service.h index f9b43de..0ac59c7 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.h +++ b/services/security_component_service/sa/sa_main/sec_comp_service.h @@ -47,6 +47,7 @@ public: const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken) override; bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override; sptr GetEnhanceRemoteObject() override; + int32_t PreRegisterSecCompProcess() override; int Dump(int fd, const std::vector& args) override; diff --git a/services/security_component_service/sa/sa_main/sec_comp_stub.cpp b/services/security_component_service/sa/sa_main/sec_comp_stub.cpp index 85a36b4..417e512 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_stub.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_stub.cpp @@ -205,6 +205,16 @@ int32_t SecCompStub::GetEnhanceRemoteObjectInner(MessageParcel& data, MessagePar return SC_OK; } +int32_t SecCompStub::PreRegisterSecCompProcessInner(MessageParcel& data, MessageParcel& reply) +{ + int32_t res = this->PreRegisterSecCompProcess(); + if (!reply.WriteInt32(res)) { + SC_LOG_ERROR(LABEL, "preRegister write result fail"); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + return SC_OK; +} + bool SecCompStub::IsMediaLibraryCalling() { int32_t uid = IPCSkeleton::GetCallingUid(); @@ -236,6 +246,9 @@ SecCompStub::SecCompStub() requestFuncMap_[static_cast( SecurityComponentServiceInterfaceCode::GET_SECURITY_COMPONENT_ENHANCE_OBJECT)] = &SecCompStub::GetEnhanceRemoteObjectInner; + requestFuncMap_[static_cast( + SecurityComponentServiceInterfaceCode::PRE_REGISTER_PROCESS)] = + &SecCompStub::PreRegisterSecCompProcessInner; } SecCompStub::~SecCompStub() diff --git a/services/security_component_service/sa/sa_main/sec_comp_stub.h b/services/security_component_service/sa/sa_main/sec_comp_stub.h index 8b4262d..57ce8b4 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_stub.h +++ b/services/security_component_service/sa/sa_main/sec_comp_stub.h @@ -37,6 +37,7 @@ private: int32_t ReportSecurityComponentClickEventInner(MessageParcel& data, MessageParcel& reply); int32_t VerifySavePermissionInner(MessageParcel& data, MessageParcel& reply); int32_t GetEnhanceRemoteObjectInner(MessageParcel& data, MessageParcel& reply); + int32_t PreRegisterSecCompProcessInner(MessageParcel& data, MessageParcel& reply); bool IsMediaLibraryCalling(); using RequestFuncType = int32_t (SecCompStub::*)(MessageParcel& data, MessageParcel& reply); diff --git a/services/security_component_service/sa/test/mock/src/sec_comp_enhance_adapter.cpp b/services/security_component_service/sa/test/mock/src/sec_comp_enhance_adapter.cpp index d6259e3..594d42a 100644 --- a/services/security_component_service/sa/test/mock/src/sec_comp_enhance_adapter.cpp +++ b/services/security_component_service/sa/test/mock/src/sec_comp_enhance_adapter.cpp @@ -105,6 +105,11 @@ sptr SecCompEnhanceAdapter::GetEnhanceRemoteObject() SC_LOG_DEBUG(LABEL, "GetEnhanceRemoteObject success"); return nullptr; } + +void SecCompEnhanceAdapter::AddSecurityComponentProcess(int32_t pid) +{ + SC_LOG_DEBUG(LABEL, "AddSecurityComponentProcess success"); +} } // namespace SecurityComponent } // namespace Security } // namespace OHOS diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp index 8207e36..ce721b3 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp @@ -570,14 +570,14 @@ HWTEST_F(SecCompManagerTest, ExitSaProcess001, TestSize.Level1) std::shared_ptr saClient = std::make_shared(); ASSERT_NE(nullptr, saClient); SystemAbilityManagerClient::clientInstance = saClient.get(); - SystemAbilityManagerProxy proxy(nullptr); - EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy)); + sptr proxy = new SystemAbilityManagerProxy(nullptr); + EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy)); instance->ExitSaProcess(); EXPECT_TRUE(instance->isSaExit_); instance->isSaExit_ = false; - EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy)); - EXPECT_CALL(proxy, UnloadSystemAbility(testing::_)).WillOnce(testing::Return(-1)); + EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy)); + EXPECT_CALL(*proxy, UnloadSystemAbility(testing::_)).WillOnce(testing::Return(-1)); instance->ExitSaProcess(); EXPECT_TRUE(instance->isSaExit_); } @@ -608,17 +608,17 @@ HWTEST_F(SecCompManagerTest, ExitWhenAppMgrDied001, TestSize.Level1) instance->ExitWhenAppMgrDied(); EXPECT_TRUE(instance->isSaExit_); - SystemAbilityManagerProxy proxy(nullptr); - EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy)); + sptr proxy = new SystemAbilityManagerProxy(nullptr); + EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy)); instance->ExitWhenAppMgrDied(); EXPECT_TRUE(instance->isSaExit_); - EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy)); + EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy)); instance->ExitWhenAppMgrDied(); EXPECT_TRUE(instance->isSaExit_); - EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy)); - EXPECT_CALL(proxy, UnloadSystemAbility(testing::_)).WillOnce(testing::Return(-1)); + EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy)); + EXPECT_CALL(*proxy, UnloadSystemAbility(testing::_)).WillOnce(testing::Return(-1)); instance->ExitWhenAppMgrDied(); EXPECT_TRUE(instance->isSaExit_); } diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp index 8f3bc96..8c724c5 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp @@ -114,15 +114,15 @@ HWTEST_F(SecCompServiceTest, RegisterAppStateObserver001, TestSize.Level1) // GetSystemAbility get app mgr failed secCompService_->appStateObserver_ = nullptr; - SystemAbilityManagerProxy proxy(nullptr); - EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy)); + sptr proxy = new SystemAbilityManagerProxy(nullptr); + EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy)); EXPECT_FALSE(secCompService_->RegisterAppStateObserver()); // RegisterApplicationStateObserver failed secCompService_->appStateObserver_ = nullptr; - EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy)); - MockIRemoteObject object; - EXPECT_CALL(proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(&object)); + EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy)); + sptr object = new MockIRemoteObject(); + EXPECT_CALL(*proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(object)); sptr appProxy = new (std::nothrow) MockAppMgrProxy(nullptr); MockAppMgrProxy::g_MockAppMgrProxy = appProxy; EXPECT_CALL(*MockAppMgrProxy::g_MockAppMgrProxy, @@ -131,8 +131,8 @@ HWTEST_F(SecCompServiceTest, RegisterAppStateObserver001, TestSize.Level1) // GetForegroundApplications failed secCompService_->appStateObserver_ = nullptr; - EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy)); - EXPECT_CALL(proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(&object)); + EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy)); + EXPECT_CALL(*proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(object)); EXPECT_CALL(*MockAppMgrProxy::g_MockAppMgrProxy, RegisterApplicationStateObserver(testing::_, testing::_)).WillOnce(testing::Return(0)); EXPECT_CALL(*MockAppMgrProxy::g_MockAppMgrProxy, @@ -142,8 +142,8 @@ HWTEST_F(SecCompServiceTest, RegisterAppStateObserver001, TestSize.Level1) // get one foreground app secCompService_->appStateObserver_ = nullptr; - EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy)); - EXPECT_CALL(proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(&object)); + EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy)); + EXPECT_CALL(*proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(object)); EXPECT_CALL(*MockAppMgrProxy::g_MockAppMgrProxy, RegisterApplicationStateObserver(testing::_, testing::_)).WillOnce(testing::Return(0)); EXPECT_CALL(*MockAppMgrProxy::g_MockAppMgrProxy, GetForegroundApplications(testing::_)) diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h b/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h index 27d6f0e..438c1f5 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h @@ -52,12 +52,17 @@ public: bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override { return true; - } + }; sptr GetEnhanceRemoteObject() override { return nullptr; - } + }; + + int32_t PreRegisterSecCompProcess() override + { + return 0; + }; }; class SecCompStubTest : public testing::Test { -- Gitee