From d40bf7b2e3985b9122ca812bcaae435aabfa91e3 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Sat, 13 Sep 2025 11:00:49 +0800 Subject: [PATCH] UpdateConfiguration adapt multi user Signed-off-by: zhangzezhong --- .../include/appmgr/app_mgr_client.h | 4 + .../include/appmgr/app_mgr_interface.h | 5 ++ .../appmgr/app_mgr_ipc_interface_code.h | 2 + .../include/appmgr/app_mgr_proxy.h | 5 ++ .../app_manager/include/appmgr/app_mgr_stub.h | 2 + .../app_manager/src/appmgr/app_mgr_client.cpp | 24 ++++++ .../app_manager/src/appmgr/app_mgr_proxy.cpp | 56 ++++++++++++++ .../app_manager/src/appmgr/app_mgr_stub.cpp | 48 ++++++++++++ .../include/ability_manager_service.h | 1 + .../src/ability_manager_service.cpp | 11 +++ services/appmgr/include/app_mgr_service.h | 4 + .../appmgr/include/app_mgr_service_inner.h | 4 + services/appmgr/src/app_mgr_service.cpp | 22 ++++++ services/appmgr/src/app_mgr_service_inner.cpp | 76 ++++++++++++++++++- .../include/mock_app_mgr_service.h | 3 + .../include/mock_app_mgr_service.h | 3 + .../ability_manager_service_second_test.cpp | 15 ++++ .../mock/include/mock_app_mgr_service.h | 3 + .../app_mgr_client_test.cpp | 27 +++++-- .../app_mgr_proxy_test/app_mgr_proxy_test.cpp | 56 +++++++++++++- .../app_mgr_service_inner_test/BUILD.gn | 3 + .../app_mgr_service_inner_test.cpp | 38 ++++++++++ .../mock/include/mock_my_flag.h | 26 +++++++ .../include/mock_permission_verification.h | 38 ++++++++++ .../mock/src/mock_my_flag.cpp | 22 ++++++ .../mock/src/mock_permission_verification.cpp | 26 +++++++ .../app_mgr_service_test.cpp | 58 +++++++++++++- .../app_mgr_stub_test/app_mgr_stub_test.cpp | 63 +++++++++++++++ .../include/mock_app_mgr_service.h | 3 + .../mock/include/mock_app_mgr_service.h | 3 + 30 files changed, 640 insertions(+), 11 deletions(-) create mode 100644 test/unittest/app_mgr_service_inner_test/mock/include/mock_my_flag.h create mode 100644 test/unittest/app_mgr_service_inner_test/mock/include/mock_permission_verification.h create mode 100644 test/unittest/app_mgr_service_inner_test/mock/src/mock_my_flag.cpp create mode 100644 test/unittest/app_mgr_service_inner_test/mock/src/mock_permission_verification.cpp 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 4368c7b7113..b24f9bec1f4 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 @@ -363,6 +363,7 @@ public: * @return ERR_OK ,return back success,others fail. */ virtual AppMgrResultCode GetConfiguration(Configuration& config); + virtual AppMgrResultCode GetConfiguration(Configuration& config, int32_t userId); /** * Ability attach timeout. If start ability encounter failure, attach timeout to terminate. @@ -424,6 +425,9 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual AppMgrResultCode UpdateConfiguration(const Configuration &config, const int32_t userId = -1); + + virtual AppMgrResultCode UpdateConfigurationByUserIds( + const Configuration &config, const std::vector userIds = {}); /** * Update config by bundle name. 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 ee8f42c2977..e7b23cc3629 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 @@ -447,6 +447,8 @@ public: */ virtual int32_t GetConfiguration(Configuration& config) = 0; + virtual int32_t GetConfiguration(Configuration& config, int32_t userid) = 0; + /** * UpdateConfiguration, ANotify application update system environment changes. * @@ -456,6 +458,9 @@ public: */ virtual int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) = 0; + virtual int32_t UpdateConfigurationByUserIds( + const Configuration &config, const std::vector userIds) = 0; + /** * UpdateConfigurationForBackgroundApp * diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h index 84c34ddefb1..f7bd1b6b262 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h @@ -136,6 +136,8 @@ enum class AppMgrInterfaceCode { PRELOAD_MODULE_FINISHED = 111, QUERY_RUNNING_SHARED_BUNDLES = 112, EXIT_MASTER_PROCESS_ROLE = 113, + UPDATE_CONFIGURATION_MULTI_USER = 114, + GET_CONFIGURATION_BY_USERID = 115, }; } // AppExecFwk } // OHOS 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 886b620bb7e..77a59d27d11 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 @@ -431,8 +431,13 @@ public: virtual int32_t GetConfiguration(Configuration& config) override; + virtual int32_t GetConfiguration(Configuration& config, int32_t userid) override; + virtual int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) override; + virtual int32_t UpdateConfigurationByUserIds( + const Configuration &config, const std::vector userIds = {}) override; + /** * UpdateConfigurationForBackgroundApp * @param appInfos Background application information. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h index 0701c71a7bf..a7cff24ee95 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h @@ -103,7 +103,9 @@ private: int32_t HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleGetRenderProcessTerminationStatus(MessageParcel &data, MessageParcel &reply); int32_t HandleGetConfiguration(MessageParcel &data, MessageParcel &reply); + int32_t HandleGetConfigurationByUserId(MessageParcel &data, MessageParcel &reply); int32_t HandleUpdateConfiguration(MessageParcel &data, MessageParcel &reply); + int32_t HandleUpdateConfigurationMultiUser(MessageParcel &data, MessageParcel &reply); int32_t HandleUpdateConfigurationForBackgroundApp(MessageParcel &data, MessageParcel &reply); int32_t HandleUpdateConfigurationByBundleName(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterConfigurationObserver(MessageParcel &data, MessageParcel &reply); 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 684bc02520b..e479329bafd 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 @@ -638,6 +638,19 @@ AppMgrResultCode AppMgrClient::GetConfiguration(Configuration& config) return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } +AppMgrResultCode AppMgrClient::GetConfiguration(Configuration& config, int32_t userId) +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service != nullptr) { + int32_t result = service->GetConfiguration(config, userId); + if (result == ERR_OK) { + return AppMgrResultCode::RESULT_OK; + } + return AppMgrResultCode::ERROR_SERVICE_NOT_READY; + } + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; +} + AppMgrResultCode AppMgrClient::ConnectAppMgrService() { if (mgrHolder_) { @@ -881,6 +894,17 @@ AppMgrResultCode AppMgrClient::UpdateConfiguration(const Configuration &config, return AppMgrResultCode::RESULT_OK; } +AppMgrResultCode AppMgrClient::UpdateConfigurationByUserIds( + const Configuration &config, const std::vector userIds) +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; + } + service->UpdateConfigurationByUserIds(config, userIds); + return AppMgrResultCode::RESULT_OK; +} + AppMgrResultCode AppMgrClient::UpdateConfigurationByBundleName(const Configuration &config, const std::string &name, int32_t appIndex) { 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 34ffabc71fa..e8c5b330650 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 @@ -981,6 +981,32 @@ int32_t AppMgrProxy::UpdateConfiguration(const Configuration &config, const int3 return reply.ReadInt32(); } +int32_t AppMgrProxy::UpdateConfigurationByUserIds( + const Configuration &config, const std::vector userIds) +{ + TAG_LOGI(AAFwkTag::APPMGR, "AppMgrProxy UpdateConfiguration"); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&config)) { + TAG_LOGE(AAFwkTag::APPMGR, "parcel config failed"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32Vector(userIds)) { + TAG_LOGE(AAFwkTag::APPMGR, "parcel userIds failed"); + return ERR_INVALID_DATA; + } + int32_t ret = SendRequest(AppMgrInterfaceCode::UPDATE_CONFIGURATION_MULTI_USER, data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); + return ret; + } + return reply.ReadInt32(); +} + int32_t AppMgrProxy::UpdateConfigurationForBackgroundApp(const std::vector& appInfos, const AppExecFwk::ConfigurationPolicy& policy, const int32_t userId) { @@ -1076,6 +1102,36 @@ int32_t AppMgrProxy::GetConfiguration(Configuration& config) return reply.ReadInt32(); } +int32_t AppMgrProxy::GetConfiguration(Configuration& config, int32_t userId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "parcel data failed"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(userId)) { + TAG_LOGE(AAFwkTag::APPMGR, "failed to write userId to parcel"); + return ERR_INVALID_DATA; + } + + int32_t ret = SendRequest(AppMgrInterfaceCode::GET_CONFIGURATION, data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGW(AAFwkTag::APPMGR, "SendRequest failed, error code: %{public}d", ret); + return ret; + } + + std::unique_ptr info(reply.ReadParcelable()); + if (!info) { + TAG_LOGE(AAFwkTag::APPMGR, "read configuration failed"); + return ERR_UNKNOWN_OBJECT; + } + config = *info; + return reply.ReadInt32(); +} + int32_t AppMgrProxy::RegisterConfigurationObserver(const sptr& observer, const int32_t userId) { 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 d1400e57bbb..2d874bbba9b 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 @@ -214,6 +214,10 @@ int32_t AppMgrStub::OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data return HandleGetAllRunningInstanceKeysByBundleName(data, reply); case static_cast(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_SELF): return HandleGetAllRunningInstanceKeysBySelf(data, reply); + case static_cast(AppMgrInterfaceCode::UPDATE_CONFIGURATION_MULTI_USER): + return HandleUpdateConfigurationMultiUser(data, reply); + case static_cast(AppMgrInterfaceCode::GET_CONFIGURATION_BY_USERID): + return HandleGetConfigurationByUserId(data, reply); } return INVALID_FD; } @@ -1048,6 +1052,30 @@ int32_t AppMgrStub::HandleGetConfiguration(MessageParcel &data, MessageParcel &r return NO_ERROR; } +int32_t AppMgrStub::HandleGetConfigurationByUserId(MessageParcel& data, MessageParcel& reply) +{ + int32_t userId = -1; + if (!data.ReadInt32(userId)) { + TAG_LOGE(AAFwkTag::APPMGR, "Failed to read userId from parcel"); + return ERR_INVALID_DATA; + } + + Configuration config; + int32_t ret = GetConfiguration(config, userId); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub GetConfiguration error"); + return ERR_INVALID_VALUE; + } + if (!reply.WriteParcelable(&config)) { + TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub GetConfiguration error"); + return ERR_INVALID_VALUE; + } + if (!reply.WriteInt32(ret)) { + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AppMgrStub::HandleUpdateConfiguration(MessageParcel &data, MessageParcel &reply) { std::unique_ptr config(data.ReadParcelable()); @@ -1063,6 +1091,26 @@ int32_t AppMgrStub::HandleUpdateConfiguration(MessageParcel &data, MessageParcel return NO_ERROR; } +int32_t AppMgrStub::HandleUpdateConfigurationMultiUser(MessageParcel &data, MessageParcel &reply) +{ + std::unique_ptr config(data.ReadParcelable()); + if (!config) { + TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub read configuration error"); + return ERR_INVALID_VALUE; + } + + std::vector userIds; + if (!data.ReadInt32Vector(&userIds)) { + TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub read userIds error"); + return ERR_INVALID_DATA; + } + int32_t ret = UpdateConfigurationByUserIds(*config, userIds); + if (!reply.WriteInt32(ret)) { + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AppMgrStub::HandleUpdateConfigurationForBackgroundApp(MessageParcel &data, MessageParcel &reply) { TAG_LOGD(AAFwkTag::APPMGR, "called"); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 65917fbc6ac..e938e9fb8a0 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1542,6 +1542,7 @@ public: int32_t GetConfiguration(AppExecFwk::Configuration& config); + int32_t GetConfiguration(AppExecFwk::Configuration& config, int32_t userId); /** * Set rootSceneSession by SCB. * diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 131a2e7556d..c806bc514ff 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -3255,6 +3255,17 @@ int32_t AbilityManagerService::GetConfiguration(AppExecFwk::Configuration& confi return appMgr->GetConfiguration(config); } +int32_t AbilityManagerService::GetConfiguration(AppExecFwk::Configuration& config, int32_t userId) +{ + auto appMgr = AppMgrUtil::GetAppMgr(); + if (appMgr == nullptr) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed"); + return -1; + } + + return appMgr->GetConfiguration(config, userId); +} + int AbilityManagerService::CheckOptExtensionAbility(const Want &want, AbilityRequest &abilityRequest, int32_t validUserId, AppExecFwk::ExtensionAbilityType extensionType, bool isImplicit, bool isStartAsCaller) { diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 9ccbf2ad459..cdd3e59cb10 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -424,6 +424,7 @@ public: * @return ERR_OK ,return back success,others fail. */ virtual int32_t GetConfiguration(Configuration& config) override; + virtual int32_t GetConfiguration(Configuration& config, int32_t userId) override; /** * UpdateConfiguration, ANotify application update system environment changes. @@ -433,6 +434,9 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) override; + + virtual int32_t UpdateConfigurationByUserIds( + const Configuration &config, const std::vector userIds = {}) override; /** * Internally, an asynchronous task will be initiated and tasks in the task list will be scheduled according to diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 4aa1d11bf28..abad2f733bc 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -809,6 +809,8 @@ public: */ int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1); + int32_t UpdateConfigurationByUserIds(const Configuration &config, const std::vector userIds); + /** * UpdateConfigurationForBackgroundApp * @param appInfos Background application information. @@ -823,6 +825,8 @@ public: std::shared_ptr GetConfiguration(); + std::shared_ptr GetConfiguration(int32_t userId); + int32_t RegisterConfigurationObserver(const sptr& observer, const int32_t userId = -1); diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index dcd643ea5c3..19e0af0796f 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -1116,6 +1116,16 @@ int32_t AppMgrService::GetConfiguration(Configuration& config) return ERR_OK; } +int32_t AppMgrService::GetConfiguration(Configuration& config, int32_t userId) +{ + if (!IsReady()) { + TAG_LOGE(AAFwkTag::APPMGR, "not ready"); + return ERR_INVALID_OPERATION; + } + config = *(appMgrServiceInner_->GetConfiguration(userId)); + return ERR_OK; +} + int32_t AppMgrService::UpdateConfiguration(const Configuration& config, const int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -1126,6 +1136,18 @@ int32_t AppMgrService::UpdateConfiguration(const Configuration& config, const in return appMgrServiceInner_->UpdateConfiguration(config, userId); } +int32_t AppMgrService::UpdateConfigurationByUserIds( + const Configuration& config, const std::vector userIds) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (!IsReady()) { + TAG_LOGE(AAFwkTag::APPMGR, "not ready"); + return ERR_INVALID_OPERATION; + } + + return appMgrServiceInner_->UpdateConfigurationByUserIds(config, userIds); +} + int32_t AppMgrService::UpdateConfigurationForBackgroundApp(const std::vector& appInfos, const AppExecFwk::ConfigurationPolicy& policy, const int32_t userId) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 2b94074cdf8..3487933dcec 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -5904,7 +5904,6 @@ int32_t AppMgrServiceInner::UpdateConfiguration(const Configuration &config, con if (ret != ERR_OK) { return ret; } - // all app int32_t result = appRunningManager_->UpdateConfiguration(config, notifyUserId); HandleConfigurationChange(config, notifyUserId); @@ -5923,6 +5922,59 @@ int32_t AppMgrServiceInner::UpdateConfiguration(const Configuration &config, con return result; } +int32_t AppMgrServiceInner::UpdateConfigurationByUserIds( + const Configuration &config, const std::vector userIds) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (!appRunningManager_) { + TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null"); + return ERR_INVALID_VALUE; + } + CHECK_CALLER_IS_SYSTEM_APP; + auto ret = AAFwk::PermissionVerification::GetInstance()->VerifyUpdateConfigurationPerm(); + if (ret != ERR_OK) { + return ret; + } + + std::vector effectiveUserIds = userIds; + if (effectiveUserIds.empty()) { + std::vector accounts; + auto errCode = AccountSA::OsAccountManager::GetForegroundOsAccounts(accounts); + if (errCode != ERR_OK) { + return errCode; + } + for (const auto &account : accounts) { + effectiveUserIds.push_back(account.localId); + } + } + + int32_t result = ERR_OK; + for (const auto& userId : effectiveUserIds) { + int32_t notifyUserId = -1; + ret = DealWithUserConfiguration(config, userId, notifyUserId); + if (ret != ERR_OK) { + TAG_LOGW(AAFwkTag::APPMGR, "DealWithUserConfiguration failed for userId: %{public}d", userId); + continue; + } + + int32_t updateResult = appRunningManager_->UpdateConfiguration(config, notifyUserId); + HandleConfigurationChange(config, notifyUserId); + if (updateResult != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "UpdateConfiguration failed for notifyUserId: %{public}d", notifyUserId); + result = updateResult; + } + + std::lock_guard notifyLock(configurationObserverLock_); + for (auto &item : configurationObservers_) { + if (item.observer != nullptr && + (notifyUserId == -1 || item.userId == 0 || item.userId == notifyUserId)) { + item.observer->OnConfigurationUpdated(config); + } + } + } + return result; +} + std::vector AppMgrServiceInner::GetBackgroundAppInfo( const std::vector& allowAppList) { @@ -6150,6 +6202,28 @@ std::shared_ptr AppMgrServiceInner::GetConfiguration( return multiUserConfigurationMgr_->GetConfigurationByUserId(userId); } +std::shared_ptr AppMgrServiceInner::GetConfiguration(int32_t userId) +{ + if (multiUserConfigurationMgr_ == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "multiUserConfigurationMgr_ null"); + return nullptr; + } + + if (userId == -1) { + int32_t currentUserId = 0; + auto errNo = AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(currentUserId); + if (errNo != 0) { + TAG_LOGE(AAFwkTag::APPMGR, "GetForegroundOsAccountLocalId failed: %{public}d", errNo); + currentUserId = USER100; + } + TAG_LOGD(AAFwkTag::APPMGR, "GetForegroundOsAccountLocalId userId: %{public}d", userId); + return multiUserConfigurationMgr_->GetConfigurationByUserId(currentUserId); + } else { + TAG_LOGD(AAFwkTag::APPMGR, "Using specified user ID: %{public}d", userId); + return multiUserConfigurationMgr_->GetConfigurationByUserId(userId); + } +} + void AppMgrServiceInner::KillApplicationByRecord(const std::shared_ptr &appRecord) { TAG_LOGD(AAFwkTag::APPMGR, "Kill application by appRecord."); 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 f5b88f71cad..9d599683f90 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 @@ -59,7 +59,10 @@ public: MOCK_METHOD1(SaveBrowserChannel, void(sptr browser)); MOCK_METHOD2(GetRenderProcessTerminationStatus, int(pid_t renderPid, int& status)); MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config)); + MOCK_METHOD2(GetConfiguration, int32_t(Configuration& config, int32_t userid)); MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId)); + MOCK_METHOD2(UpdateConfigurationByUserIds, int32_t(const Configuration& config, + const std::vector userIds)); MOCK_METHOD2(RegisterConfigurationObserver, int32_t(const sptr& observer, const int32_t userId)); MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr& observer)); 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 379d976b121..c1447eadb29 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 @@ -73,7 +73,10 @@ public: void(const int32_t recordId, const AAFwk::Want& want, const std::string& flag)); MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector>& tokens)); MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config)); + MOCK_METHOD2(GetConfiguration, int32_t(Configuration& config, int32_t userid)); MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId)); + MOCK_METHOD2(UpdateConfigurationByUserIds, int32_t(const Configuration& config, + const std::vector userIds)); MOCK_METHOD3(UpdateConfigurationForBackgroundApp, int32_t(const std::vector &appInfos, const AppExecFwk::ConfigurationPolicy &policy, const int32_t userId)); MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name, diff --git a/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp index 060eb782c47..1ea7d4b0597 100644 --- a/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp +++ b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp @@ -22,6 +22,7 @@ #include "ability_connection.h" #include "ability_start_setting.h" #include "recovery_param.h" +#include "app_mgr_util.h" #undef private #undef protected @@ -1930,5 +1931,19 @@ HWTEST_F(AbilityManagerServiceSecondTest, CheckCallAutoFillExtensionPermission_0 TAG_LOGI(AAFwkTag::TEST, "testcase end."); } #endif // SUPPORT_AUTO_FILL + +/* + * Feature: AbilityManagerService + * Function: GetConfiguration + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetConfiguration + */ +HWTEST_F(AbilityManagerServiceSecondTest, GetConfiguration_001, TestSize.Level1) +{ + auto abilityMs_ = std::make_shared(); + AppExecFwk::Configuration config; + auto ret = abilityMs_->GetConfiguration(config, USER_ID_U100); + EXPECT_EQ(ret, ERR_OK); +} } // namespace AAFwk } // namespace OHOS 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 c1114d70590..a36ad39cb16 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 @@ -72,7 +72,10 @@ public: void(const int32_t recordId, const AAFwk::Want& want, const std::string& flag)); MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector>& tokens)); MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config)); + MOCK_METHOD2(GetConfiguration, int32_t(Configuration& config, int32_t userid)); MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId)); + MOCK_METHOD2(UpdateConfigurationByUserIds, int32_t(const Configuration& config, + const std::vector userIds)); MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name, int32_t appIndex)); MOCK_METHOD2(RegisterConfigurationObserver, 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 767f017ec1d..5a6a6c49ed2 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 @@ -1593,20 +1593,31 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_SetProcessCacheEnable_001, TestSize.Leve } /** - * @tc.name: AppMgrClient_SetProcessCacheEnable_002 + * @tc.name: AppMgrClient_GetConfiguration_001 * @tc.desc: SetProcessCacheEnable. * @tc.type: FUNC */ -HWTEST_F(AppMgrClientTest, AppMgrClient_SetProcessCacheEnable_002, TestSize.Level2) +HWTEST_F(AppMgrClientTest, AppMgrClient_GetConfiguration_001, TestSize.Level2) { auto appMgrClient = std::make_unique(); ASSERT_NE(appMgrClient, nullptr); - auto ret = appMgrClient->ConnectAppMgrService(); - EXPECT_EQ(ret, AppMgrResultCode::RESULT_OK); - int32_t pid = 1; - bool enable = false; - auto result = appMgrClient->SetProcessCacheEnable(pid, enable); - EXPECT_NE(result, AppMgrResultCode::ERROR_SERVICE_NOT_READY); + Configuration config; + auto result = appMgrClient->GetConfiguration(config, INIT_VALUE); + EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); +} + +/** + * @tc.name: AppMgrClient_UpdateConfigurationByUserIds_002 + * @tc.desc: UpdateConfigurationByUserIds. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrClientTest, AppMgrClient_UpdateConfigurationByUserIds_002, TestSize.Level1) +{ + auto appMgrClient = std::make_unique(); + Configuration config; + std::vector userids; + auto result = appMgrClient->UpdateConfigurationByUserIds(config, userids); + EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); } } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 1ce51c9df87..bc9d09f7c04 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -1120,5 +1120,59 @@ HWTEST_F(AppMgrProxyTest, QueryRunningSharedBundles_0400, TestSize.Level1) EXPECT_FALSE(sharedBundles.empty()); TAG_LOGI(AAFwkTag::TEST, "QueryRunningSharedBundles_0300 end."); } + +/** + * @tc.name: UpdateConfigurationByUserIds_001 + * @tc.desc: UpdateConfigurationByUserIds. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AppMgrProxyTest, UpdateConfigurationByUserIds_001, TestSize.Level2) +{ + Configuration config; + std::vector userIds; + auto ret = appMgrProxy_->UpdateConfigurationByUserIds(config, userIds); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.name: GetConfiguration_001 + * @tc.desc: GetConfiguration. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AppMgrProxyTest, GetConfiguration_001, TestSize.Level2) +{ + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .WillOnce(Invoke([](uint32_t, MessageParcel&, MessageParcel& reply, MessageOption&) { + reply.WriteInt32(ERR_OK); + return NO_ERROR; + })); + Configuration config; + int32_t result = appMgrProxy_->GetConfiguration(config, USER_ID); + EXPECT_EQ(result, ERR_UNKNOWN_OBJECT); +} + +/** + * @tc.name: GetConfiguration_002 + * @tc.desc: GetConfiguration. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AppMgrProxyTest, GetConfiguration_002, TestSize.Level2) +{ + Configuration expectedConfig; + expectedConfig.AddItem("key", "test"); + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .WillOnce(Invoke([&expectedConfig](uint32_t, MessageParcel &, MessageParcel &reply, MessageOption &) { + reply.WriteParcelable(&expectedConfig); + reply.WriteInt32(ERR_OK); + return NO_ERROR; + })); + Configuration config; + std::string key = "key"; + int32_t result = appMgrProxy_->GetConfiguration(config, USER_ID); + EXPECT_EQ(result, ERR_OK); +} } // namespace AppExecFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/app_mgr_service_inner_test/BUILD.gn b/test/unittest/app_mgr_service_inner_test/BUILD.gn index ad69ceaace3..27894c3fe40 100644 --- a/test/unittest/app_mgr_service_inner_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_test/BUILD.gn @@ -36,12 +36,15 @@ ohos_unittest("AppMgrServiceInnerTest") { "${ability_runtime_services_path}/abilitymgr/include", "${ability_runtime_test_path}/moduletest/mock/include", + "mock/include", ] sources = [ "${ability_runtime_test_path}/mock/common/src/mock_native_token.cpp", "${ability_runtime_test_path}/mock/task_handler_wrap_mock/src/mock_task_handler_wrap.cpp", "app_mgr_service_inner_test.cpp", + "mock/src/mock_my_flag.cpp", + "mock/src/mock_permission_verification.cpp", ] configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ] 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 466f867d778..886c74d7f38 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 @@ -34,7 +34,9 @@ #include "mock_configuration_observer.h" #include "mock_iapp_state_callback.h" #include "mock_kia_interceptor.h" +#include "mock_my_flag.h" #include "mock_native_token.h" +#include "mock_permission_verification.h" #include "mock_render_scheduler.h" #include "mock_sa_call.h" #include "mock_task_handler_wrap.h" @@ -6054,5 +6056,41 @@ HWTEST_F(AppMgrServiceInnerTest, AfterLoadAbility_0001, TestSize.Level1) appMgrServiceInner->AfterLoadAbility(appRecord, abilityInfoSptr, loadParam); ASSERT_NE(appRecord, nullptr); } + +/** + * @tc.name: UpdateConfigurationByUserIds_0001 + * @tc.desc: UpdateConfigurationByUserIds + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, UpdateConfigurationByUserIds_0001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UpdateConfigurationByUserIds_0001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + MyFlag::flag_ = 0; + Configuration changeConfig; + std::vector userIds = {0, 1}; + auto res = appMgrServiceInner->UpdateConfigurationByUserIds(changeConfig, userIds); + EXPECT_EQ(res, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "UpdateConfigurationByUserIds_0001 end"); +} + +/** + * @tc.name: UpdateConfigurationByUserIds_0002 + * @tc.desc: UpdateConfigurationByUserIds + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, UpdateConfigurationByUserIds_0002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UpdateConfigurationByUserIds_0002 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + MyFlag::flag_ = 0; + Configuration changeConfig; + std::vector userIds; + auto res = appMgrServiceInner->UpdateConfigurationByUserIds(changeConfig, userIds); + EXPECT_EQ(res, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "UpdateConfigurationByUserIds_0002 end"); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_service_inner_test/mock/include/mock_my_flag.h b/test/unittest/app_mgr_service_inner_test/mock/include/mock_my_flag.h new file mode 100644 index 00000000000..fef304a2684 --- /dev/null +++ b/test/unittest/app_mgr_service_inner_test/mock/include/mock_my_flag.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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 MOCK_MY_FLAG_H +#define MOCK_MY_FLAG_H +namespace OHOS { +namespace AAFwk { +class MyFlag { +public: + static int flag_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // MOCK_MY_FLAG_H diff --git a/test/unittest/app_mgr_service_inner_test/mock/include/mock_permission_verification.h b/test/unittest/app_mgr_service_inner_test/mock/include/mock_permission_verification.h new file mode 100644 index 00000000000..1deae87c45a --- /dev/null +++ b/test/unittest/app_mgr_service_inner_test/mock/include/mock_permission_verification.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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 OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H +#define OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H + +#include + +#include "ipc_skeleton.h" +#include "mock_my_flag.h" +#include "singleton.h" +#include "want.h" + +namespace OHOS { +namespace AAFwk { + +class PermissionVerification : public DelayedSingleton { +public: + PermissionVerification() = default; + ~PermissionVerification() = default; + + bool VerifyUpdateConfigurationPerm() const; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H \ No newline at end of file diff --git a/test/unittest/app_mgr_service_inner_test/mock/src/mock_my_flag.cpp b/test/unittest/app_mgr_service_inner_test/mock/src/mock_my_flag.cpp new file mode 100644 index 00000000000..e21af59a45f --- /dev/null +++ b/test/unittest/app_mgr_service_inner_test/mock/src/mock_my_flag.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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 "mock_my_flag.h" + +namespace OHOS { +namespace AAFwk { +int MyFlag::flag_ = 0; +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/app_mgr_service_inner_test/mock/src/mock_permission_verification.cpp b/test/unittest/app_mgr_service_inner_test/mock/src/mock_permission_verification.cpp new file mode 100644 index 00000000000..69d2b18f73d --- /dev/null +++ b/test/unittest/app_mgr_service_inner_test/mock/src/mock_permission_verification.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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 "mock_permission_verification.h" + +namespace OHOS { +namespace AAFwk { + +bool PermissionVerification::VerifyUpdateConfigurationPerm() const +{ + return MyFlag::flag_; +} +} // namespace AAFwk +} // namespace OHOS 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 456a3d6aa22..44c645bf2c9 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -2384,5 +2384,61 @@ HWTEST_F(AppMgrServiceTest, QueryRunningSharedBundles_003, TestSize.Level1) EXPECT_EQ(result, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "QueryRunningSharedBundles_003 end."); } + +/* + * Feature: AppMgrService + * Function: GetConfiguration + * SubFunction: NA + * FunctionPoints: AppMgrService GetConfiguration + * EnvConditions: NA + * CaseDescription: Verify GetConfiguration + */ +HWTEST_F(AppMgrServiceTest, GetConfiguration_003, TestSize.Level2) +{ + auto appMgrService = std::make_shared(); + Configuration config; + int32_t userId = 1; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->GetConfiguration(config, userId); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetConfiguration + * SubFunction: NA + * FunctionPoints: AppMgrService GetConfiguration + * EnvConditions: NA + * CaseDescription: Verify GetConfiguration + */ +HWTEST_F(AppMgrServiceTest, GetConfiguration_004, TestSize.Level2) +{ + auto appMgrService = std::make_shared(); + Configuration config; + int32_t userId = 1; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->GetConfiguration(config, userId); + EXPECT_EQ(res, ERR_OK); +} + +/* + * Feature: AppMgrService + * Function: UpdateConfigurationByUserIds + * SubFunction: NA + * FunctionPoints: AppMgrService UpdateConfigurationByUserIds + * EnvConditions: NA + * CaseDescription: Verify UpdateConfigurationByUserIds + */ +HWTEST_F(AppMgrServiceTest, UpdateConfigurationByUserIds_001, TestSize.Level2) +{ + auto appMgrService = std::make_shared(); + Configuration config; + std::vector userIds; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->UpdateConfigurationByUserIds(config, userIds); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index c96fe9d0260..7e43f252d73 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -976,5 +976,68 @@ HWTEST_F(AppMgrStubTest, HandleQueryRunningSharedBundles_0200, TestSize.Level1) EXPECT_EQ(replyResult, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "HandleQueryRunningSharedBundles_0200 end."); } + +/** + * @tc.name: HandleGetConfigurationByUserId_0100 + * @tc.desc: Test HandleGetConfigurationByUserId. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrStubTest, HandleGetConfigurationByUserId_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "HandleGetConfigurationByUserId_0100 start."); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + WriteInterfaceToken(data); + Configuration config; + int32_t userId = USER_ID; + data.WriteParcelable(&config); + data.WriteInt32(userId); + + EXPECT_CALL(*mockAppMgrService_, GetConfiguration(_, _)) + .Times(1) + .WillOnce(Return(ERR_OK)); + + auto ret = mockAppMgrService_->OnRemoteRequest( + static_cast(AppMgrInterfaceCode::GET_CONFIGURATION_BY_USERID), data, reply, option); + EXPECT_EQ(ret, NO_ERROR); + + std::unique_ptr replyConfig(reply.ReadParcelable()); + auto replyResult = reply.ReadInt32(); + EXPECT_EQ(replyResult, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "HandleGetConfigurationByUserId_0100 end."); +} + +/** + * @tc.name: HandleUpdateConfigurationMultiUser_0100 + * @tc.desc: Test HandleUpdateConfigurationMultiUser. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrStubTest, HandleUpdateConfigurationMultiUser_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "HandleUpdateConfigurationMultiUser_0100 start."); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + WriteInterfaceToken(data); + Configuration config; + std::vector userIds; + data.WriteParcelable(&config); + data.WriteInt32Vector(userIds); + + EXPECT_CALL(*mockAppMgrService_, UpdateConfigurationByUserIds(_, _)) + .Times(1) + .WillOnce(Return(ERR_OK)); + + auto ret = mockAppMgrService_->OnRemoteRequest( + static_cast(AppMgrInterfaceCode::UPDATE_CONFIGURATION_MULTI_USER), data, reply, option); + EXPECT_EQ(ret, NO_ERROR); + + auto replyResult = reply.ReadInt32(); + EXPECT_EQ(replyResult, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "HandleUpdateConfigurationMultiUser_0100 end."); +} } // namespace AppExecFwk } // namespace OHOS 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 eafb83fa365..95861f11521 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 @@ -72,7 +72,10 @@ public: void(const int32_t recordId, const AAFwk::Want& want, const std::string& flag)); MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector>& tokens)); MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config)); + MOCK_METHOD2(GetConfiguration, int32_t(Configuration& config, int32_t userid)); MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId)); + MOCK_METHOD2(UpdateConfigurationByUserIds, int32_t(const Configuration& config, + const std::vector userIds)); MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name, int32_t appIndex)); MOCK_METHOD2(RegisterConfigurationObserver, 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 50f185b9a76..355575ee3d4 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 @@ -72,7 +72,10 @@ public: void(const int32_t recordId, const AAFwk::Want& want, const std::string& flag)); MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector>& tokens)); MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config)); + MOCK_METHOD2(GetConfiguration, int32_t(Configuration& config, int32_t userid)); MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId)); + MOCK_METHOD2(UpdateConfigurationByUserIds, int32_t(const Configuration& config, + const std::vector userIds)); MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name, int32_t appIndex)); MOCK_METHOD2(RegisterConfigurationObserver, -- Gitee