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 7a1bc1288b8ca3a7084eea5dc80615c57c2416ae..ddf39fa74f6c89e93af7b14bed19bb7ca6e0291d 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 @@ -364,6 +364,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. @@ -425,6 +426,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 0cab8f3e01c9edcb7607cb3f41e80a78df3587c2..6adc51428ba20b0194c4dacf7830dd8d52e2bab7 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 @@ -460,6 +460,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. * @@ -469,6 +471,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 c650c94910cc0cfd5666d33902aa2bd775fd9dd6..c7a98b77a8e955dcaaa86bfd6e16f929acb93fbe 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 @@ -137,6 +137,8 @@ enum class AppMgrInterfaceCode { QUERY_RUNNING_SHARED_BUNDLES = 112, EXIT_MASTER_PROCESS_ROLE = 113, REGISTER_APPLICATION_STATE_OBSERVER_WITH_FILTER = 114, + UPDATE_CONFIGURATION_MULTI_USER = 115, + GET_CONFIGURATION_BY_USERID = 116, }; } // 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 66b09a3ff9c04b40d223fa1c3a578c82012a03a9..2dc79fe4fa421e6d8a640a802b8fd1b147e7fa7c 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 790efd5c6aa22b66a405938269f9e281a4f757b9..1060efad829c1c70898007ab9e79960dfff1e307 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 9d188d1f20af9f3aa28d17ea533c23e126bb2f0b..0c414ee3bf2b152fe9d74dfce3e738bdfd5be75d 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 f828f11cf55a95af001fffaf9cd68628f116c6eb..45b6105535a2e3e06cde41bd1eb79db2bbe833bc 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 193064e7a03a47c7f51687a3bc1d25b3bd8a109e..679fc1c87965cf12e6a94296a634f8637076c355 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 @@ -216,6 +216,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; } @@ -1050,6 +1054,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()); @@ -1065,6 +1093,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 0006f76ecf1de7f7e0180f853183b7476d6dbfc1..859099c509d2f0287672c5807878c2b3f54bc89d 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 3d1efa6eaed568a673cf7c979248a271b2a10e1f..9978afa962d784f0aad1bfc837f65f53c73f22c3 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 61303c919d8002c93984ad76e81f487b1d6a9df3..5c49cb9850e7cc1eacc83743b7144af6128d9d37 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -425,6 +425,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. @@ -434,6 +435,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 19af2a59a135a675008b89194bd4339f6b39c4dd..5f036256c5334c593be464dfb32cc5f432e49b83 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -810,6 +810,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. @@ -824,6 +826,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 dabe800b878565e5ea32e69a13bf23d6c44ba183..c536053c95afebc2fa61f6a25ef851ccdc67ab0c 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -1122,6 +1122,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__); @@ -1132,6 +1142,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 397e8d9ba389e3b5f82d8a8eb8039a472bd010f5..39dd1d2d79e492265a0b3959a227110ea8550113 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 f5b88f71cad2ae7b67f2e9aeb43df616ad68e005..9d599683f90c103159551576bb56689eed972ce0 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 379d976b1219196c15da3f93e9bbe9338f2340a7..c1447eadb292f56e6d6418645a136e4a73d85864 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 060eb782c47120833daf83148a803a48ee534400..1ea7d4b05979f1f0434aa8a7681043612e073282 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 c1114d70590101ecb7790446e2fdcfec629d0c5c..a36ad39cb1632202a6272a4b08428b4d0896b14c 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 767f017ec1d013e8464e116b203948e1f5be103a..5a6a6c49ed2ad4adc430c4961c798e20528a77ce 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 1ce51c9df870d020cc6e169200d3605b46a86d72..bc9d09f7c04cfe4a9f682588ae38b57d701c02c6 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 ad69ceaace3b951454592273dd5c830d06a2bfba..27894c3fe40cabf52c8c4d3f4b569af2d26bcbb6 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 466f867d7781c1fda1922932f49bbd8950d74f4c..886c74d7f384a0d3672489f877aaf31a064768c7 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 0000000000000000000000000000000000000000..fef304a2684caba3fda1467ba783bc58ee3bebe4 --- /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 0000000000000000000000000000000000000000..1deae87c45a530cab7e9a393dce3c03e60284afa --- /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 0000000000000000000000000000000000000000..e21af59a45f641a45a68a81775f64f2890241f71 --- /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 0000000000000000000000000000000000000000..69d2b18f73dd4a205fe2e84706c4a79ea705b711 --- /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 456a3d6aa2265347a898bb52b2feaeb3cd873c46..44c645bf2c91b94a40e009a7a824e2fd4690ce28 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 c96fe9d0260b9e79646c9837fa2383b805648208..7e43f252d73b4e0e7f44507fc16bb8b69004096d 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 eafb83fa365c54fb675490f9449112740a896677..95861f115210d3ad72ee19c9307f4e00823cc7a5 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 50f185b9a7690be43b9a7b88b112c93541403c95..355575ee3d4f9dffb7f66a2d6a24683624f1c4ce 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,