From 25dcd04e1e33253975233a79339d980fbb79e7da 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 | 5 +++++ .../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 ++++++++--- 10 files changed, 34 insertions(+), 17 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 f846e868a50..5df5b1331b0 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 provide by user of default value:-1 * @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 23f1637d927..1355eff386e 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 provide by user of default value:-1 * @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 b2ffb02bd46..886b620bb7e 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 7833693174d..684bc02520b 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 396c3d446b8..4debbd281b5 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 @@ -1090,6 +1090,11 @@ int32_t AppMgrProxy::RegisterConfigurationObserver(const sptrAsObject())) { TAG_LOGE(AAFwkTag::APPMGR, "observer write failed."); return ERR_FLATTEN_OBJECT; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index a99518bebb2..d1400e57bbb 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -1122,7 +1122,8 @@ int32_t AppMgrStub::HandleRegisterConfigurationObserver(MessageParcel &data, Mes TAG_LOGE(AAFwkTag::APPMGR, "Observer is null."); return ERR_INVALID_VALUE; } - int32_t result = RegisterConfigurationObserver(observer); + int32_t userId = data.ReadInt32(); + int32_t result = RegisterConfigurationObserver(observer, userId); reply.WriteInt32(result); return NO_ERROR; } diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 79a7c7e2090..6f0aba54425 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -465,11 +465,11 @@ public: /** * @brief register a configuration observer which will receive notifies when updated. * @param observer the configuration observer to receive notify. - * + * @param userId provide by user of default value:-1 * @return Returns ERR_OK on success, others on failure. */ - virtual int32_t 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 30ece18d74d..59f67ce3f48 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 4e3ce704dd0..40d5beb47f7 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 = -1) { 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 9a5c544c456..363bd67176a 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 = -1) { 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; } -- Gitee