From 96255a165ba628fdbc5abe03ebcd12ace768b554 Mon Sep 17 00:00:00 2001 From: RuiChen Date: Thu, 4 Sep 2025 10:00:12 +0800 Subject: [PATCH] add support sh Signed-off-by: RuiChen --- .../app_manager/include/appmgr/app_mgr_client.h | 5 +++-- .../app_manager/include/appmgr/app_mgr_interface.h | 5 +++-- .../app_manager/include/appmgr/app_mgr_proxy.h | 3 ++- .../app_manager/src/appmgr/app_mgr_client.cpp | 5 +++-- .../app_manager/src/appmgr/app_mgr_proxy.cpp | 8 +++++++- .../inner_api/app_manager/src/appmgr/app_mgr_stub.cpp | 3 ++- services/appmgr/include/app_mgr_service.h | 6 +++--- services/appmgr/include/app_mgr_service_inner.h | 3 ++- services/appmgr/src/app_mgr_service.cpp | 5 +++-- services/appmgr/src/app_mgr_service_inner.cpp | 11 ++++++++--- .../include/mock_app_mgr_service.h | 3 ++- .../include/mock_app_mgr_service.h | 3 ++- .../app_mgr_client_test/app_mgr_client_test.cpp | 6 +++--- .../mock/include/mock_app_mgr_service.h | 3 ++- .../app_mgr_client_test/app_mgr_client_test.cpp | 2 +- .../app_mgr_service_inner_seventh_test.cpp | 2 +- .../app_mgr_service_inner_test.cpp | 8 ++++---- .../app_mgr_service_test/app_mgr_service_test.cpp | 4 ++-- .../include/mock_app_mgr_service.h | 3 ++- .../mock/include/mock_app_mgr_service.h | 3 ++- 20 files changed, 57 insertions(+), 34 deletions(-) diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index f846e868a5..4368c7b711 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -439,10 +439,11 @@ public: * Register configuration observer. * * @param observer Configuration observer. When configuration changed, observer will be called. + * @param userId The userId provided by caller. * @return Returns RESULT_OK on success, others on failure. */ - virtual AppMgrResultCode RegisterConfigurationObserver(const sptr &observer); - + virtual AppMgrResultCode RegisterConfigurationObserver(const sptr &observer, + const int32_t userId = -1); /** * Unregister configuration observer. * diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 23f1637d92..ee8f42c297 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -484,10 +484,11 @@ public: * Register configuration observer. * * @param observer Configuration observer. When configuration changed, observer will be called. + * @param userId The userId provided by caller. * @return Returns RESULT_OK on success, others on failure. */ - virtual int32_t RegisterConfigurationObserver(const sptr &observer) = 0; - + virtual int32_t RegisterConfigurationObserver(const sptr &observer, + const int32_t userId = -1) = 0; /** * Unregister configuration observer. * diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index b2ffb02bd4..886b620bb7 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -446,7 +446,8 @@ public: virtual int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name, int32_t appIndex = 0) override; - virtual int32_t RegisterConfigurationObserver(const sptr &observer) override; + virtual int32_t RegisterConfigurationObserver(const sptr &observer, + const int32_t userId = -1) override; virtual int32_t UnregisterConfigurationObserver(const sptr &observer) override; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index 7833693174..684bc02520 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -895,11 +895,12 @@ AppMgrResultCode AppMgrClient::UpdateConfigurationByBundleName(const Configurati return AppMgrResultCode::RESULT_OK; } -AppMgrResultCode AppMgrClient::RegisterConfigurationObserver(const sptr &observer) +AppMgrResultCode AppMgrClient::RegisterConfigurationObserver(const sptr &observer, + const int32_t userId) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); if (service != nullptr) { - int32_t result = service->RegisterConfigurationObserver(observer); + int32_t result = service->RegisterConfigurationObserver(observer, userId); if (result == ERR_OK) { return AppMgrResultCode::RESULT_OK; } diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index 396c3d446b..34ffabc71f 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -1076,7 +1076,8 @@ int32_t AppMgrProxy::GetConfiguration(Configuration& config) return reply.ReadInt32(); } -int32_t AppMgrProxy::RegisterConfigurationObserver(const sptr& observer) +int32_t AppMgrProxy::RegisterConfigurationObserver(const sptr& observer, + const int32_t userId) { if (!observer) { TAG_LOGE(AAFwkTag::APPMGR, "observer null"); @@ -1095,6 +1096,11 @@ int32_t AppMgrProxy::RegisterConfigurationObserver(const sptr &observer) override; - + virtual int32_t RegisterConfigurationObserver(const sptr &observer, + const int32_t userId = -1) override; /** * @brief unregister a configuration observer registered before. * @param observer the configuration observer registered before. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 30ece18d74..59f67ce3f4 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -822,7 +822,8 @@ public: std::shared_ptr GetConfiguration(); - int32_t RegisterConfigurationObserver(const sptr& observer); + int32_t RegisterConfigurationObserver(const sptr& observer, + const int32_t userId = -1); int32_t UnregisterConfigurationObserver(const sptr& observer); diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 4e3ce704dd..dcd643ea5c 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -1151,13 +1151,14 @@ int32_t AppMgrService::UpdateConfigurationByBundleName(const Configuration& conf return appMgrServiceInner_->UpdateConfigurationByBundleName(config, name, appIndex); } -int32_t AppMgrService::RegisterConfigurationObserver(const sptr &observer) +int32_t AppMgrService::RegisterConfigurationObserver(const sptr &observer, + const int32_t userId) { if (!IsReady()) { TAG_LOGE(AAFwkTag::APPMGR, "not ready"); return ERR_INVALID_OPERATION; } - return appMgrServiceInner_->RegisterConfigurationObserver(observer); + return appMgrServiceInner_->RegisterConfigurationObserver(observer, userId); } int32_t AppMgrService::UnregisterConfigurationObserver(const sptr &observer) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 9a5c544c45..f270824769 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -6028,7 +6028,8 @@ void AppMgrServiceInner::HandleConfigurationChange(const Configuration& config, } } -int32_t AppMgrServiceInner::RegisterConfigurationObserver(const sptr& observer) +int32_t AppMgrServiceInner::RegisterConfigurationObserver(const sptr& observer, + const int32_t userId) { TAG_LOGD(AAFwkTag::APPMGR, "called"); if (!AAFwk::PermissionVerification::GetInstance()->IsSACall()) { @@ -6049,8 +6050,12 @@ int32_t AppMgrServiceInner::RegisterConfigurationObserver(const sptr= 0) { + configurationObservers_.push_back(ConfigurationObserverWithUserId { observer, userId }); + } else { + configurationObservers_.push_back( + ConfigurationObserverWithUserId { observer, GetUserIdByUid(IPCSkeleton::GetCallingUid()) }); + } return NO_ERROR; } diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index 027abc6443..f5b88f71ca 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -60,7 +60,8 @@ public: MOCK_METHOD2(GetRenderProcessTerminationStatus, int(pid_t renderPid, int& status)); MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config)); MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId)); - MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr& observer)); + MOCK_METHOD2(RegisterConfigurationObserver, + int32_t(const sptr& observer, const int32_t userId)); MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr& observer)); MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName)); MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName, diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index fdd8d4ff95..379d976b12 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -78,7 +78,8 @@ public: const AppExecFwk::ConfigurationPolicy &policy, const int32_t userId)); MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name, int32_t appIndex)); - MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr& observer)); + MOCK_METHOD2(RegisterConfigurationObserver, + int32_t(const sptr& observer, const int32_t userId)); MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr& observer)); MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName)); MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName, diff --git a/test/moduletest/app_mgr_client_test/app_mgr_client_test.cpp b/test/moduletest/app_mgr_client_test/app_mgr_client_test.cpp index 70b0094550..e0ce69f8a6 100644 --- a/test/moduletest/app_mgr_client_test/app_mgr_client_test.cpp +++ b/test/moduletest/app_mgr_client_test/app_mgr_client_test.cpp @@ -120,7 +120,7 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_RegisterConfigurationObserver_0100, Test EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); sptr observer(new (std::nothrow) MockConfigurationObserver()); - result = appMgrClient->RegisterConfigurationObserver(observer); + result = appMgrClient->RegisterConfigurationObserver(observer, -1); EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); sleep(1); @@ -152,11 +152,11 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_RegisterConfigurationObserver_0200, Test EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); sptr observer(new (std::nothrow) MockConfigurationObserver()); - result = appMgrClient->RegisterConfigurationObserver(observer); + result = appMgrClient->RegisterConfigurationObserver(observer, -1); EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); sptr observerOther(new (std::nothrow) MockConfigurationObserver()); - result = appMgrClient->RegisterConfigurationObserver(observerOther); + result = appMgrClient->RegisterConfigurationObserver(observerOther, -1); EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); sleep(1); diff --git a/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h b/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h index c320e789f3..c1114d7059 100644 --- a/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h +++ b/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h @@ -75,7 +75,8 @@ public: MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId)); MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name, int32_t appIndex)); - MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr& observer)); + MOCK_METHOD2(RegisterConfigurationObserver, + int32_t(const sptr& observer, const int32_t userId)); MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr& observer)); MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName)); MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName, diff --git a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp index e5b715445d..767f017ec1 100644 --- a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp +++ b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp @@ -1242,7 +1242,7 @@ HWTEST_F(AppMgrClientTest, RegisterConfigurationObserver_001, TestSize.Level1) { auto appMgrClient = std::make_unique(); sptr observer; - appMgrClient->RegisterConfigurationObserver(observer); + appMgrClient->RegisterConfigurationObserver(observer, -1); EXPECT_NE(appMgrClient, nullptr); } diff --git a/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp b/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp index fd93fb03ae..8cb170dee0 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp +++ b/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp @@ -1946,7 +1946,7 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, RegisterConfigurationObserver_001, TestS auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().isSACall_ = false; - auto ret = appMgrServiceInner->RegisterConfigurationObserver(nullptr); + auto ret = appMgrServiceInner->RegisterConfigurationObserver(nullptr, -1); EXPECT_EQ(ret, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "RegisterConfigurationObserver_001 end"); } diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 7c82bdb960..466f867d77 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -2871,11 +2871,11 @@ HWTEST_F(AppMgrServiceInnerTest, RegisterConfigurationObserver_001, TestSize.Lev appMgrServiceInner->configurationObservers_.clear(); - appMgrServiceInner->RegisterConfigurationObserver(nullptr); + appMgrServiceInner->RegisterConfigurationObserver(nullptr, -1); sptr observer(new (std::nothrow) MockConfigurationObserver()); - appMgrServiceInner->RegisterConfigurationObserver(observer); - appMgrServiceInner->RegisterConfigurationObserver(observer); + appMgrServiceInner->RegisterConfigurationObserver(observer, -1); + appMgrServiceInner->RegisterConfigurationObserver(observer, -1); TAG_LOGI(AAFwkTag::TEST, "RegisterConfigurationObserver_001 end"); } @@ -2899,7 +2899,7 @@ HWTEST_F(AppMgrServiceInnerTest, UnregisterConfigurationObserver_001, TestSize.L sptr observer(new (std::nothrow) MockConfigurationObserver()); appMgrServiceInner->UnregisterConfigurationObserver(observer); - appMgrServiceInner->RegisterConfigurationObserver(observer); + appMgrServiceInner->RegisterConfigurationObserver(observer, -1); appMgrServiceInner->UnregisterConfigurationObserver(observer); TAG_LOGI(AAFwkTag::TEST, "UnregisterConfigurationObserver_001 end"); diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index 1727f940f5..456a3d6aa2 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -969,7 +969,7 @@ HWTEST_F(AppMgrServiceTest, RegisterConfigurationObserver_001, TestSize.Level2) auto appMgrService = std::make_shared(); sptr observer = nullptr; appMgrService->SetInnerService(nullptr); - int32_t res = appMgrService->RegisterConfigurationObserver(observer); + int32_t res = appMgrService->RegisterConfigurationObserver(observer, -1); EXPECT_EQ(res, ERR_INVALID_OPERATION); } @@ -988,7 +988,7 @@ HWTEST_F(AppMgrServiceTest, RegisterConfigurationObserver_002, TestSize.Level2) appMgrService->SetInnerService(std::make_shared()); appMgrService->taskHandler_ = taskHandler_; appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); - int32_t res = appMgrService->RegisterConfigurationObserver(observer); + int32_t res = appMgrService->RegisterConfigurationObserver(observer, -1); EXPECT_NE(res, ERR_INVALID_OPERATION); } diff --git a/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h b/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h index 27d687b235..eafb83fa36 100644 --- a/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h +++ b/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h @@ -75,7 +75,8 @@ public: MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId)); MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name, int32_t appIndex)); - MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr& observer)); + MOCK_METHOD2(RegisterConfigurationObserver, + int32_t(const sptr& observer, const int32_t userId)); MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr& observer)); MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName)); MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName, diff --git a/test/unittest/ui_ability_lifecycle_manager_third_test/mock/include/mock_app_mgr_service.h b/test/unittest/ui_ability_lifecycle_manager_third_test/mock/include/mock_app_mgr_service.h index 979970c0b4..50f185b9a7 100644 --- a/test/unittest/ui_ability_lifecycle_manager_third_test/mock/include/mock_app_mgr_service.h +++ b/test/unittest/ui_ability_lifecycle_manager_third_test/mock/include/mock_app_mgr_service.h @@ -75,7 +75,8 @@ public: MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId)); MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name, int32_t appIndex)); - MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr& observer)); + MOCK_METHOD2(RegisterConfigurationObserver, + int32_t(const sptr& observer, const int32_t userId)); MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr& observer)); MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName)); MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName,