diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 6e7d315b178e1bd5a745f0dfa8c84997ca95d10c..e91c163cbf95c8f1e0517e93d256458f73a123a4 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1025,11 +1025,12 @@ public: /** * @brief start user. * @param accountId accountId. + * @param displayId logical screen id. * @param accountId is appRecovery or not. * * @return Returns ERR_OK on success, others on failure. */ - ErrCode StartUser(int accountId, sptr callback, bool isAppRecovery = false); + ErrCode StartUser(int accountId, uint64_t displayId, sptr callback, bool isAppRecovery = false); /** * @brief stop user. diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 9dd2d0b8deb5e797c2c3139315363d6bd77f90ff..ad2ff6318f2f25df4709624969abdb07de7ce993 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -1109,10 +1109,11 @@ public: /** * @brief start user. * @param accountId accountId. + * @param displayId logical screen id. * @param isAppRecovery is appRecovery or not. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartUser(int userId, sptr callback, bool isAppRecovery = false) = 0; + virtual int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery = false) = 0; /** * @brief stop user. diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h index d2d3c1e1ce35cf3fe5ab659ff09092916e9e51c5..c90a12c037e8755f78b7cf182b2ccadb87260dcd 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h @@ -301,15 +301,6 @@ public: */ virtual int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg) = 0; - /** - * Set the current userId of appMgr. - * - * @param userId the user id. - * - * @return - */ - virtual void SetCurrentUserId(const int32_t userId) = 0; - /** * Set enable start process flag by userId * @param userId the user id. @@ -546,8 +537,7 @@ public: GET_APPLICATION_INFO_BY_PROCESS_ID, KILL_APPLICATION_SELF, UPDATE_APPLICATION_INFO_INSTALLED, - SET_CURRENT_USER_ID, - Get_BUNDLE_NAME_BY_PID, + Get_BUNDLE_NAME_BY_PID = 21, SET_ABILITY_FOREGROUNDING_FLAG, REGISTER_APP_DEBUG_LISTENER, UNREGISTER_APP_DEBUG_LISTENER, diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h index 5f01a91819c59d890fedd5f26f489996620c0fe1..56d971ac3def9f121dcefbc5c22e1e36712bab8f 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h @@ -280,8 +280,6 @@ public: virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0, const std::string &customProcess = "") override; - virtual void SetCurrentUserId(const int32_t userId) override; - virtual void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) override; virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) override; diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h index 9ddbb2efcef6ddad2076262734689dedcf482564..e903a0c4bcd5ad33b5b994530694f958cc891199 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h @@ -70,7 +70,6 @@ private: int32_t HandleGetApplicationInfoByProcessID(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyAppMgrRecordExitReason(MessageParcel &data, MessageParcel &reply); int32_t HandleUpdateApplicationInfoInstalled(MessageParcel &data, MessageParcel &reply); - int32_t HandleSetCurrentUserId(MessageParcel &data, MessageParcel &reply); int32_t HandleSetEnableStartProcessFlagByUserId(MessageParcel &data, MessageParcel &reply); int32_t HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterAppDebugListener(MessageParcel &data, MessageParcel &reply); 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 911ac9825811b7941ad1d583d23b14415dd80432..f0d825d8021e80723b35fc4ea6b491b2a4eccd36 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 @@ -572,15 +572,6 @@ public: */ int32_t StartNativeProcessForDebugger(const AAFwk::Want &want); - /** - * Set the current userId of appMgr. - * - * @param userId the user id. - * - * @return - */ - void SetCurrentUserId(const int32_t userId); - /** * Set enable start process flag by userId * @param userId the user id. diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp index a0f1af9ec0a849934fbf2c11a6c0432fd5cd8f2e..2da9a32ce365d37aa62f3f4f68fe6de9d9861898 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -930,28 +930,6 @@ int32_t AmsMgrProxy::NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, c return reply.ReadInt32(); } -void AmsMgrProxy::SetCurrentUserId(const int32_t userId) -{ - TAG_LOGD(AAFwkTag::APPMGR, "start"); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - if (!WriteInterfaceToken(data)) { - return; - } - if (!data.WriteInt32(userId)) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write userId"); - return; - } - int32_t ret = - SendTransactCmd(static_cast(IAmsMgr::Message::SET_CURRENT_USER_ID), - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret); - } - TAG_LOGD(AAFwkTag::APPMGR, "end"); -} - void AmsMgrProxy::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) { TAG_LOGD(AAFwkTag::APPMGR, "called"); diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp index fa0925a3e5c1f5691b2c831561ba3907769fbf3c..2bb33682b06d3545703db0fc87d36fa1dd95cb9d 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -139,8 +139,6 @@ int32_t AmsMgrStub::OnRemoteRequestInnerSecond(uint32_t code, MessageParcel &dat return HandleNotifyAppMgrRecordExitReason(data, reply); case static_cast(IAmsMgr::Message::UPDATE_APPLICATION_INFO_INSTALLED): return HandleUpdateApplicationInfoInstalled(data, reply); - case static_cast(IAmsMgr::Message::SET_CURRENT_USER_ID): - return HandleSetCurrentUserId(data, reply); case static_cast(IAmsMgr::Message::ENABLE_START_PROCESS_FLAG_BY_USER_ID): return HandleSetEnableStartProcessFlagByUserId(data, reply); case static_cast(IAmsMgr::Message::Get_BUNDLE_NAME_BY_PID): @@ -625,13 +623,6 @@ int32_t AmsMgrStub::HandleUpdateApplicationInfoInstalled(MessageParcel &data, Me return NO_ERROR; } -int32_t AmsMgrStub::HandleSetCurrentUserId(MessageParcel &data, MessageParcel &reply) -{ - int32_t userId = data.ReadInt32(); - SetCurrentUserId(userId); - return NO_ERROR; -} - int32_t AmsMgrStub::HandleSetEnableStartProcessFlagByUserId(MessageParcel &data, MessageParcel &reply) { int32_t userId = data.ReadInt32(); 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 af1eabdb77dc080ca2cb3ab6a5739dd8b4bad18d..92c19f685cf5fbd92e1d35c1bd961687e9f74e7d 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 @@ -1024,19 +1024,6 @@ sptr AppMgrClient::GetRemoteObject() return mgrHolder_->GetRemoteObject(); } -void AppMgrClient::SetCurrentUserId(const int32_t userId) -{ - sptr service = iface_cast(mgrHolder_->GetRemoteObject()); - if (service == nullptr) { - return; - } - sptr amsService = service->GetAmsMgr(); - if (amsService == nullptr) { - return; - } - amsService->SetCurrentUserId(userId); -} - void AppMgrClient::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 51fbe487c25ca163063727899b105a087fad6bcb..70f8536b21c96337efdbeaa3aa6c2c1a7a34c3bc 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -157,6 +157,7 @@ ohos_shared_library("abilityms") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 6e23995589ce98eb03762bffb07f30a2e08cb7a1..63090716cdcd5a0c738e3351bcaac2f14c203569 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -100,10 +100,6 @@ abilityms_files = [ "src/connection_state_manager.cpp", "src/dlp_state_item.cpp", - #multi user - "src/user_controller.cpp", - "src/user_event_handler.cpp", - #free_install "src/atomic_service_status_callback_proxy.cpp", "src/atomic_service_status_callback_stub.cpp", diff --git a/services/abilitymgr/include/ability_manager_event_subscriber.h b/services/abilitymgr/include/ability_manager_event_subscriber.h index 96358d66cb8f3bae4bad024874d867b675c9d197..e779f02149b95823c3e3b354ba3e917c2a04e8b0 100644 --- a/services/abilitymgr/include/ability_manager_event_subscriber.h +++ b/services/abilitymgr/include/ability_manager_event_subscriber.h @@ -28,7 +28,8 @@ namespace AbilityRuntime { class AbilityManagerEventSubscriber : public EventFwk::CommonEventSubscriber { public: explicit AbilityManagerEventSubscriber( - const EventFwk::CommonEventSubscribeInfo &subscribeInfo, const std::function &screenUnlockCallback, + const EventFwk::CommonEventSubscribeInfo &subscribeInfo, + const std::function &screenUnlockCallback, const std::function &userScreenUnlockCallback); ~AbilityManagerEventSubscriber() override = default; @@ -36,7 +37,7 @@ public: void OnReceiveEvent(const EventFwk::CommonEventData &data) override; private: - std::function screenUnlockCallback_; + std::function screenUnlockCallback_; std::function userScreenUnlockCallback_; std::unordered_set eventSet_; std::mutex mutex_; diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 423f9e658dc2ae1ab9e8e36a19fe80bbe596b3ad..8e4c3b26030160f678bed33464c064947382a66f 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -866,10 +866,12 @@ public: /** * @brief start user. * @param accountId accountId. + * @param displayId logical screen id. * @param isAppRecovery is appRecovery or not. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartUser(int userId, sptr callback, bool isAppRecovery = false) override; + virtual int StartUser(int userId, uint64_t displayId, sptr callback, + bool isAppRecovery = false) override; /** * @brief stop user. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 0b2fc81502a8162411ae16d035a20df6375dccd4..eafa46e541ec5232031981a51f3b7dd3475eea94 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -68,7 +68,6 @@ #include "system_ability.h" #include "task_handler_wrap.h" #include "uri.h" -#include "user_controller.h" #ifdef SUPPORT_GRAPHICS #include "implicit_start_processor.h" #include "system_dialog_scheduler.h" @@ -1230,7 +1229,8 @@ public: */ sptr GetAbilityTokenByMissionId(int32_t missionId); - virtual int StartUser(int userId, sptr callback, bool isAppRecovery = false) override; + virtual int StartUser(int userId, uint64_t displayId, sptr callback, + bool isAppRecovery = false) override; virtual int StopUser(int userId, const sptr &callback) override; @@ -1599,12 +1599,6 @@ public: */ sptr GetCollaborator(int32_t type); - /** - * get the user id. - * - */ - int32_t GetUserId() const; - virtual int32_t RegisterStatusBarDelegate(sptr delegate) override; virtual int32_t KillProcessWithPrepareTerminate(const std::vector& pids) override; @@ -2163,8 +2157,6 @@ public: TERMINATE_ABILITY_CODE }; - friend class UserController; - protected: void OnAbilityRequestDone(const sptr &token, const int32_t state) override; int GetUidByBundleName(std::string bundleName); @@ -2228,7 +2220,7 @@ private: * start highest priority ability. * */ - int StartHighestPriorityAbility(int32_t userId, bool isBoot, bool isAppRecovery = false); + int StartHighestPriorityAbility(int32_t userId, uint64_t displayId, bool isBoot, bool isAppRecovery = false); #endif /** * connect bms. @@ -2300,7 +2292,7 @@ private: void DumpMissionListInner(const std::string &args, std::vector &info); void DumpMissionInfosInner(const std::string &args, std::vector &info); - bool JudgeMultiUserConcurrency(const int32_t userId); + bool JudgeMultiUserConcurrency(int32_t userId); bool CheckCrossUser(const int32_t userId, AppExecFwk::ExtensionAbilityType extensionType); void SendExtensionReport(EventInfo &eventInfo, int32_t errCode, bool isService = false); void SendIntentReport(EventInfo &eventInfo, int32_t errCode, const std::string &intentName); @@ -2337,7 +2329,7 @@ private: void StartFreezingScreen(); void StopFreezingScreen(); void UserStarted(int32_t userId); - int SwitchToUser(int32_t oldUserId, int32_t userId, sptr callback, + int SwitchToUser(int32_t oldUserId, int32_t userId, uint64_t displayId, sptr callback, bool isAppRecovery = false); void SwitchManagers(int32_t userId, bool switchUser = true); void StartUserApps(); @@ -2369,7 +2361,7 @@ private: bool JudgeSelfCalled(const std::shared_ptr &abilityRecord); bool IsAppSelfCalled(const std::shared_ptr &abilityRecord); - int32_t GetValidUserId(const int32_t userId); + int32_t GetValidUserId(int32_t userId); int DelegatorMoveMissionToFront(int32_t missionId); @@ -2379,10 +2371,10 @@ private: void StartKeepAliveApps(int32_t userId); - void StartAutoStartupApps(); + void StartAutoStartupApps(int32_t userId); void StartAutoStartupApps(std::queue infoList); void SubscribeScreenUnlockedEvent(); - std::function GetScreenUnlockCallback(); + std::function GetScreenUnlockCallback(); std::function GetUserScreenUnlockCallback(); void UnSubscribeScreenUnlockedEvent(); void RetrySubscribeScreenUnlockedEvent(int32_t retryCount); @@ -2582,7 +2574,7 @@ private: std::vector &abilityRequestList); int32_t StartUIAbilitiesCheckDlp(const Want &want, sptr callerToken, int32_t userId); int32_t StartUIAbilitiesInterceptorCheck(const Want &want, AbilityRequest &abilityRequest, - sptr callerToken, int32_t appIndex); + sptr callerToken, int32_t appIndex, int32_t userId); /** * Start switch user dialog Extension ability. */ @@ -2762,7 +2754,6 @@ private: std::shared_ptr freeInstallManager_; std::shared_ptr subManagersHelper_; - std::shared_ptr userController_; sptr abilityController_ = nullptr; std::multimap timeoutMap_; @@ -2802,7 +2793,7 @@ private: bool ParseJsonFromBoot(const std::string &relativePath); void SetReserveInfo(const std::string &linkString, AbilityRequest& abilityRequest); - void CloseAssertDialog(const std::string &assertSessionId); + void CloseAssertDialog(const std::string &assertSessionId, int32_t userId); int32_t OpenLinkFreeInstallAtomicService(Want &convertedWant, const Want &originalWant, sptr callerToken, int32_t userId, int32_t requestCode, bool removeInsightIntentFlag); @@ -2827,6 +2818,8 @@ private: int StartAbilityWithRemoveIntentFlag(const Want &want, const sptr &callerToken, int32_t userId, int requestCode, bool removeInsightIntentFlag); + int32_t UpdateApplicationKeepAlive(int32_t userId) const; + int32_t OpenLinkInner(const Want &want, sptr callerToken, int32_t userId, int requestCode, bool removeInsightIntentFlag); int32_t KillProcessWithReasonInner(int32_t pid, const ExitReason &reason, bool isKillPrecedeStart); diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 976b318b63c0b84e640c5549844314c41d017526..bdff8680370a94ff31c6ed6bc8c9f26b8973d2d1 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -476,15 +476,6 @@ public: */ virtual int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg); - /** - * Set the current userId of appMgr, only used by abilityMgr. - * - * @param userId the user id. - * - * @return - */ - void SetCurrentUserId(int32_t userId); - /** * Set enable start process flag by userId * @param userId the user id. diff --git a/services/abilitymgr/include/user_controller.h b/services/abilitymgr/include/user_controller.h deleted file mode 100644 index c516fb9206ae69ed6f61eade304529cd81c74bf6..0000000000000000000000000000000000000000 --- a/services/abilitymgr/include/user_controller.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2021-2023 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_USER_CONTROLLER_H -#define OHOS_ABILITY_RUNTIME_USER_CONTROLLER_H - -#include -#include -#include "cpp/mutex.h" - -#include "user_event_handler.h" -#include "refbase.h" - -namespace OHOS { -namespace AAFwk { -class IUserCallback; - -const int32_t USER_ID_NO_HEAD = 0; -const int32_t USER_ID_DEFAULT = 100; - -enum UserState { - STATE_BOOTING = 0, - STATE_STARTED, - STATE_STOPPING, - STATE_SHUTDOWN -}; - -class UserItem { -public: - explicit UserItem(int32_t id); - virtual ~UserItem(); - - int32_t GetUserId(); - void SetState(const UserState &state); - UserState GetState(); - -private: - int32_t userId_; - UserState curState_ = STATE_BOOTING; - UserState lastState_ = STATE_BOOTING; -}; - -class UserEvent : public EventDataBase { -public: - virtual ~UserEvent() = default; - int32_t oldUserId; - int32_t newUserId; - std::shared_ptr userItem; -}; - -class UserController : public std::enable_shared_from_this { -public: - UserController(); - virtual ~UserController(); - - void Init(); - - /** - * Start user, if it is not running.. - * - * @param userId id of started user. - * @param isForeground whether user should brout to foreground. - * @return 0 if the user has been successfully started. - */ - int StartUser(int32_t userId, sptr callback, bool isAppRecovery = false); - - /** - * Stop user, if it is running.. - * - * @param userId id of started user. - * @return 0 if the user has been successfully started. - */ - int32_t StopUser(int32_t userId); - - /** - * Logout user, if it is running.. - * - * @param userId id of Logout user. - * @return 0 if the user has been successfully Logout. - */ - int32_t LogoutUser(int32_t userId, sptr callback = nullptr); - - int32_t GetCurrentUserId(); - - std::shared_ptr GetUserItem(int32_t userId); - - void ProcessEvent(const EventWrap &event); - - int32_t GetFreezingNewUserId() const; - - void SetFreezingNewUserId(int32_t userId); - - void ClearAbilityUserItems(int32_t userId); - -private: - bool IsCurrentUser(int32_t userId); - bool IsExistOsAccount(int32_t userId) const; - std::shared_ptr GetOrCreateUserItem(int32_t userId); - void SetCurrentUserId(int32_t userId); - int MoveUserToForeground(int32_t oldUserId, int32_t newUserId, sptr callback, - bool isAppRecovery = false); - void UserBootDone(std::shared_ptr &item); - void BroadcastUserBackground(int32_t userId); - void BroadcastUserForeground(int32_t userId); - void BroadcastUserStopping(int32_t userId); - void BroadcastUserStopped(int32_t userId); - - void SendSystemUserStart(int32_t userId); - void SendSystemUserCurrent(int32_t oldUserId, int32_t newUserId); - void SendReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void SendUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void SendContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void SendUserSwitchDone(int32_t userId); - - void HandleSystemUserStart(int32_t userId); - void HandleSystemUserCurrent(int32_t oldUserId, int32_t newUserId); - void HandleReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void HandleUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void HandleContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void HandleUserSwitchDone(int32_t userId); - int32_t StartNoHeadUser(int32_t userId, sptr callback) const; - -private: - int32_t currentUserId_ = USER_ID_NO_HEAD; - int32_t freezingNewUserId_ = -1; - std::shared_ptr eventHandler_; - std::unordered_map> userItems_; - ffrt::mutex userLock_; -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_USER_CONTROLLER_H diff --git a/services/abilitymgr/libabilityms.map b/services/abilitymgr/libabilityms.map index 65832ba509c48e23ca58f51e98f1379b4acff835..21026ec494a59be2853787bd24366be0d61fe514 100644 --- a/services/abilitymgr/libabilityms.map +++ b/services/abilitymgr/libabilityms.map @@ -98,7 +98,6 @@ *SenderInfo*; *ExtensionRunningInfo*; *UserCallbackStub*; - *UserItem*; *WantReceiverStub*; *WantReceiverProxy*; *WantSenderProxy*; diff --git a/services/abilitymgr/src/ability_auto_startup_service.cpp b/services/abilitymgr/src/ability_auto_startup_service.cpp index 6c6d2a2218c6000b75a1a8257ac07a30a6390b3c..efccea75b52ff26d4c40b06711aff2e57290040d 100644 --- a/services/abilitymgr/src/ability_auto_startup_service.cpp +++ b/services/abilitymgr/src/ability_auto_startup_service.cpp @@ -19,10 +19,12 @@ #include "ability_manager_service.h" #include "auto_startup_callback_proxy.h" #include "auto_startup_interface.h" +#include "display_util.h" #include "global_constant.h" #include "hilog_tag_wrapper.h" #include "in_process_call_wrapper.h" #include "permission_constants.h" +#include "user_controller/user_controller.h" namespace OHOS { namespace AbilityRuntime { @@ -300,8 +302,7 @@ void AbilityAutoStartupService::ExecuteCallbacks(bool isCallOn, const AutoStartu " accessTokenId: %{public}s, setterUserId: %{public}d, userId: %{public}d", info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str(), info.setterUserId, info.userId); - int32_t currentUserId = DelayedSingleton::GetInstance()->GetUserId(); - bool isUserIdMatch = (info.userId == currentUserId); + bool isUserIdMatch = UserController::GetInstance().IsForegroundUser(info.userId); bool isUserIdU0OrU1 = (U0_USER_ID == info.userId) || (U1_USER_ID == info.userId); if (!isUserIdMatch && !isUserIdU0OrU1) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Condition not satisfied"); @@ -417,7 +418,7 @@ int32_t AbilityAutoStartupService::GetValidUserId(int32_t userId) validUserId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE; } if (validUserId == U0_USER_ID || validUserId == U1_USER_ID) { - validUserId = DelayedSingleton::GetInstance()->GetUserId(); + validUserId = UserController::GetInstance().GetForegroundUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); } return validUserId; } diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 6085e0b6c202a650739dc928103feb2eb7a45e9b..056644424ae6ed999e1cc2bb885b1503ab9f4d83 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -42,6 +42,7 @@ #include "datetime_ex.h" #include "init_reboot.h" #include "string_wrapper.h" +#include "user_controller/user_controller.h" namespace OHOS { namespace AAFwk { @@ -651,8 +652,9 @@ int AbilityConnectManager::ConnectAbilityLocked(const AbilityRequest &abilityReq auto connectObject = connect->AsObject(); #ifdef SUPPORT_UPMS // grant uri to service extension by connect, must call out of serialMutex_ - if (userId_ == U0_USER_ID || - userId_ == DelayedSingleton::GetInstance()->GetUserId()) { + int32_t callerUser = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; + if (userId_ == U0_USER_ID || callerUser == U0_USER_ID || callerUser == U1_USER_ID || + userId_ == AbilityRuntime::UserController::GetInstance().GetCallerUserId()) { UriUtils::GetInstance().GrantUriPermissionForServiceExtension(abilityRequest); } else { TAG_LOGD(AAFwkTag::ABILITYMGR, "cross user, without grantUriPermission"); @@ -1895,7 +1897,7 @@ void AbilityConnectManager::HandleStartTimeoutTask(const std::shared_ptr::GetInstance()->AttachTimeOut(abilityRecord->GetToken()); if (abilityRecord->IsSceneBoard()) { - if (DelayedSingleton::GetInstance()->GetUserId() == userId_) { + if (AbilityRuntime::UserController::GetInstance().IsForegroundUser(userId_)) { RestartAbility(abilityRecord, userId_); } return; @@ -2483,8 +2485,7 @@ void AbilityConnectManager::CleanActivatingTimeoutAbility(std::shared_ptrIsSceneBoard() || - DelayedSingleton::GetInstance()->GetUserId() == userId_) { + if (!abilityRecord->IsSceneBoard() || AbilityRuntime::UserController::GetInstance().IsForegroundUser(userId_)) { RestartAbility(abilityRecord, userId_); } } @@ -2536,7 +2537,7 @@ void AbilityConnectManager::KeepAbilityAlive(const std::shared_ptr } if (abilityRecord->IsSceneBoard()) { requestInfo.want.SetParam("ohos.app.recovery", true); + uint64_t displayId = 0; + if (AbilityRuntime::UserController::GetInstance().GetDisplayIdByForegroundUserId(userId_, displayId)) { + requestInfo.want.SetParam(Want::PARAM_RESV_DISPLAY_ID, static_cast(displayId)); + } DelayedSingleton::GetInstance()->EnableListForSCBRecovery(userId_); } requestInfo.restartCount = abilityRecord->GetRestartCount(); @@ -3029,7 +3034,7 @@ void AbilityConnectManager::PauseExtensions() auto targetExtension = it->second; if (targetExtension != nullptr && targetExtension->GetAbilityInfo().type == AbilityType::EXTENSION && (IsLauncher(targetExtension) || targetExtension->IsSceneBoard() || - (targetExtension->GetKeepAlive() && userId_ != USER_ID_NO_HEAD))) { + (targetExtension->GetKeepAlive() && userId_ != U0_USER_ID))) { terminatingExtensionList_.push_back(it->second); it = serviceMap_.erase(it); TAG_LOGI(AAFwkTag::EXT, "terminate ability:%{public}s, serviceMap size:%{public}zu", diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 860fe0dc0eae26d7d25f74e3a239af626d3f47a9..ff29835a3d8847ce8e274eb6cb28d2c0a42afd35 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1246,13 +1246,14 @@ ErrCode AbilityManagerClient::StopSyncRemoteMissions(const std::string &devId) return abms->StopSyncRemoteMissions(devId); } -ErrCode AbilityManagerClient::StartUser(int accountId, sptr callback, bool isAppRecovery) +ErrCode AbilityManagerClient::StartUser(int accountId, uint64_t displayId, sptr callback, + bool isAppRecovery) { TAG_LOGI(AAFwkTag::ABILITYMGR, "accountId:%{public}d, isAppRecovery:%{public}d", accountId, isAppRecovery); auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->StartUser(accountId, callback, isAppRecovery); + return abms->StartUser(accountId, displayId, callback, isAppRecovery); } ErrCode AbilityManagerClient::StopUser(int accountId, sptr callback) diff --git a/services/abilitymgr/src/ability_manager_event_subscriber.cpp b/services/abilitymgr/src/ability_manager_event_subscriber.cpp index fef49bdb2c80367011c9d514fb42655616b44a85..6ac86dc8115bcf77e7a27511a675007b851490b3 100644 --- a/services/abilitymgr/src/ability_manager_event_subscriber.cpp +++ b/services/abilitymgr/src/ability_manager_event_subscriber.cpp @@ -21,7 +21,7 @@ namespace OHOS { namespace AbilityRuntime { AbilityManagerEventSubscriber::AbilityManagerEventSubscriber( - const EventFwk::CommonEventSubscribeInfo &subscribeInfo, const std::function &screenUnlockCallback, + const EventFwk::CommonEventSubscribeInfo &subscribeInfo, const std::function &screenUnlockCallback, const std::function &userScreenUnlockCallback) : EventFwk::CommonEventSubscriber(subscribeInfo), screenUnlockCallback_(screenUnlockCallback), userScreenUnlockCallback_(userScreenUnlockCallback) @@ -39,7 +39,9 @@ void AbilityManagerEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventDa std::lock_guard lock(mutex_); auto handleEvent = [&](const std::string &event) { if (eventSet_.find(event) != eventSet_.end()) { - screenUnlockCallback_(); + int32_t userId = want.GetIntParam("userId", -1); + TAG_LOGI(AAFwkTag::ABILITYMGR, "The userId: %{public}d.", userId); + screenUnlockCallback_(userId); eventSet_.clear(); } else { eventSet_.insert(action); diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 455bc796bb854c2215bd0dce9e1640e1d59ea3f6..2e2317f1f2b22ef6483dc2609452c1d0e99dcf90 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -3262,7 +3262,7 @@ int AbilityManagerProxy::MoveMissionsToBackground(const std::vector& mi return reply.ReadInt32(); } -int AbilityManagerProxy::StartUser(int userId, sptr callback, bool isAppRecovery) +int AbilityManagerProxy::StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) { MessageParcel data; if (!WriteInterfaceToken(data)) { @@ -3272,6 +3272,10 @@ int AbilityManagerProxy::StartUser(int userId, sptr callback, boo TAG_LOGE(AAFwkTag::ABILITYMGR, "fail"); return ERR_INVALID_VALUE; } + if (!data.WriteUint64(displayId)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write displayId failed"); + return IPC_PROXY_ERR; + } if (!callback) { data.WriteBool(false); } else { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 0777c59b601665536d321080d9d292f2e74d047f..8cd6e6c42097059ba8a99a55134c5776db9ae0e8 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -106,6 +106,7 @@ #include "uri_permission_manager_client.h" #endif // SUPPORT_UPMS #include "uri_utils.h" +#include "user_controller/user_controller.h" #include "utils/ability_permission_util.h" #include "utils/dump_utils.h" #include "utils/extension_permissions_util.h" @@ -331,6 +332,7 @@ constexpr const char* LIFE_CYCLE_MINIMIZE = "minimize"; constexpr const char* LIFE_CYCLE_TERMINATE = "terminate"; constexpr const char* LIFE_CYCLE_PRELOAD = "preload"; constexpr uint32_t TARGET_TYPE_INIT = 100; +constexpr int64_t USER_SWITCH_TIMEOUT = 3 * 1000; // 3s constexpr const char* SUPPORT_LINKAGE_SCENE = "const.window.supportLinkageScene"; const bool REGISTER_RESULT = @@ -407,9 +409,6 @@ bool AbilityManagerService::Init() freeInstallManager_ = std::make_shared(weak_from_this()); CHECK_POINTER_RETURN_BOOL(freeInstallManager_); - // init user controller. - userController_ = std::make_shared(); - userController_->Init(); AmsConfigurationParameter::GetInstance().Parse(); TAG_LOGI(AAFwkTag::ABILITYMGR, "config parse"); subManagersHelper_ = std::make_shared(taskHandler_, eventHandler_); @@ -933,7 +932,7 @@ int AbilityManagerService::StartAbilityAsCallerDetails(const Want &want, const s TAG_LOGI(AAFwkTag::ABILITYMGR, "call from interceptor dialog, callerPkg:%{public}s, targetPkg:%{public}s", callerPkg.c_str(), targetPkg.c_str()); - AbilityUtil::AddAbilityJumpRuleToBms(callerPkg, targetPkg, GetUserId()); + AbilityUtil::AddAbilityJumpRuleToBms(callerPkg, targetPkg, GetValidUserId(userId)); } int32_t ret = StartAbilityWrap(newWant, callerToken, requestCode, false, userId, true, 0, false, isImplicit, false); @@ -971,7 +970,7 @@ int AbilityManagerService::StartAbilityPrechainInterceptor(StartAbilityParams &p HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(params.want, params.requestCode, - GetUserId(), true, nullptr, shouldBlockFunc); + params.GetValidUserId(), true, nullptr, shouldBlockFunc); auto interceptorResult = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); if (interceptorResult != ERR_OK) { @@ -1250,7 +1249,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, validUserId, true, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -1416,6 +1415,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -1436,14 +1436,14 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, validUserId, true, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -1781,7 +1781,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt } AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, requestCode, - GetUserId(), true, callerToken, std::make_shared(abilityInfo), false, appIndex); + validUserId, true, callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); if (result != ERR_OK) { @@ -2026,7 +2026,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, validUserId, true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -2122,6 +2122,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St return result; } + abilityRequest.userId = validUserId; if (!HandleExecuteSAInterceptor(want, callerToken, abilityRequest, result)) { eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "HandleExecuteSAInterceptor failed"); return result; @@ -2221,7 +2222,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } Want newWant = abilityRequest.want; - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, validUserId, true, callerToken, std::make_shared(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -2234,14 +2235,14 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } #ifdef SUPPORT_SCREEN if (result != ERR_OK && isReplaceWantExist) { - result = DialogSessionManager::GetInstance().HandleErmsResult(abilityRequest, GetUserId(), newWant); + result = DialogSessionManager::GetInstance().HandleErmsResult(abilityRequest, validUserId, newWant); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "HandleErmsResult failed"); return result; } if (result == ERR_OK && - DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, GetUserId())) { + DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, validUserId)) { TAG_LOGI(AAFwkTag::ABILITYMGR, "create clone selector dialog"); - result = CreateCloneSelectorDialog(abilityRequest, GetUserId()); + result = CreateCloneSelectorDialog(abilityRequest, validUserId); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "CreateCloneSelectorDialog failed"); return result; } @@ -2408,7 +2409,7 @@ int32_t AbilityManagerService::GenerateAbilityForSplitMode(const AAFwk::Want &se "StartUIAbilitiesInSplitWindowMode checkCallPermission error, result:%{public}d", result); return result; } - result = StartUIAbilitiesInterceptorCheck(secondaryWant, abilityRequest, callerToken, appIndex); + result = StartUIAbilitiesInterceptorCheck(secondaryWant, abilityRequest, callerToken, appIndex, validUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "InterceptorCheck error, result:%{public}d", result); return result; @@ -2589,7 +2590,7 @@ int32_t AbilityManagerService::StartUIAbilitiesHandleWant(const Want &want, sptr return result; } - result = StartUIAbilitiesInterceptorCheck(want, abilityRequest, callerToken, appIndex); + result = StartUIAbilitiesInterceptorCheck(want, abilityRequest, callerToken, appIndex, validUserId); if (result != ERR_OK) { return result; } @@ -2633,13 +2634,13 @@ int32_t AbilityManagerService::StartUIAbilitiesCheckDlp(const Want &want, sptr callerToken, int32_t appIndex) + sptr callerToken, int32_t appIndex, int32_t userId) { int32_t requestCode = DEFAULT_INVAL_VALUE; Want newWant = abilityRequest.want; auto abilityInfo = abilityRequest.abilityInfo; auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, userId, true, nullptr, shouldBlockFunc); int32_t result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : interceptorExecuter_->DoProcess(interceptorParam); @@ -2652,7 +2653,7 @@ int32_t AbilityManagerService::StartUIAbilitiesInterceptorCheck(const Want &want return START_UI_ABILITIES_INTERCEPTOR_CHECK_FAILED; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, userId, true, callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -2734,7 +2735,7 @@ int32_t AbilityManagerService::RequestDialogServiceInner(const Want &want, const int32_t validUserId = GetValidUserId(userId); StartAbilityInfoWrap threadLocalInfo; auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, validUserId, true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -2782,7 +2783,7 @@ int32_t AbilityManagerService::RequestDialogServiceInner(const Want &want, const } AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, requestCode, - GetUserId(), true, callerToken, std::make_shared(abilityInfo)); + validUserId, true, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); if (result != ERR_OK) { @@ -2970,6 +2971,7 @@ int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionI eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "DoProcess error"); return result; } + abilityRequest.userId = currentUserId; if (!HandleExecuteSAInterceptor(sessionInfo->want, sessionInfo->callerToken, abilityRequest, result)) { return result; } @@ -3010,7 +3012,7 @@ int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionI Want newWant = abilityRequest.want; auto callerTokenId = IPCSkeleton::GetCallingTokenID(); RemoveUnauthorizedLaunchReasonMessage(sessionInfo->want, abilityRequest, callerTokenId); - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), true, + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, currentUserId, true, sessionInfo->callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -3114,7 +3116,8 @@ void AbilityManagerService::AppUpgradeCompleted(int32_t uid) auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER(bms); auto userId = uid / BASE_USER_RANGE; - if (userId != U0_USER_ID && userId != U1_USER_ID && userId != GetUserId()) { + if (userId != U0_USER_ID && userId != U1_USER_ID && + !AbilityRuntime::UserController::GetInstance().IsForegroundUser(userId)) { TAG_LOGI(AAFwkTag::ABILITYMGR, "not current user"); return; } @@ -3769,7 +3772,7 @@ int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, cons } StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken, true); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), false, nullptr, + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, validUserId, false, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -3830,6 +3833,7 @@ int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, cons return result; } + abilityRequest.userId = validUserId; if (!HandleExecuteSAInterceptor(want, callerToken, abilityRequest, result)) { return result; } @@ -3858,7 +3862,7 @@ int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, cons return result; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, validUserId, false, callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -4146,8 +4150,8 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte StartAbilityInfoWrap threadLocalInfo; auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(extensionSessionInfo->want, 0, GetUserId(), - true, nullptr, shouldBlockFunc); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(extensionSessionInfo->want, 0, + GetValidUserId(userId), true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); if (result != ERR_OK) { @@ -4189,6 +4193,7 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte } abilityRequest.extensionType = abilityRequest.abilityInfo.extensionAbilityType; + abilityRequest.userId = validUserId; if (!HandleExecuteSAInterceptor(extensionSessionInfo->want, callerToken, abilityRequest, result)) { return result; } @@ -4223,7 +4228,7 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte return result; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, validUserId, true, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -4349,7 +4354,7 @@ void AbilityManagerService::StopSwitchUserDialog() return; } - if (userController_ == nullptr || userController_->GetFreezingNewUserId() == DEFAULT_INVAL_VALUE) { + if (AbilityRuntime::UserController::GetInstance().GetFreezingNewUserId() == DEFAULT_INVAL_VALUE) { TAG_LOGE(AAFwkTag::ABILITYMGR, "get last userId error"); return; } @@ -4360,9 +4365,9 @@ void AbilityManagerService::StopSwitchUserDialog() return; } Want stopWant = sysDialog->GetSwitchUserDialogWant(); - StopSwitchUserDialogInner(stopWant, userController_->GetFreezingNewUserId()); + StopSwitchUserDialogInner(stopWant, AbilityRuntime::UserController::GetInstance().GetFreezingNewUserId()); #endif // SUPPORT_GRAPHICS - userController_->SetFreezingNewUserId(DEFAULT_INVAL_VALUE); + AbilityRuntime::UserController::GetInstance().SetFreezingNewUserId(DEFAULT_INVAL_VALUE); return; } @@ -5075,7 +5080,7 @@ int32_t AbilityManagerService::ConnectAbilityCommon( #endif // WITH_DLP auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), false, nullptr, + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetValidUserId(userId), false, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -5230,7 +5235,7 @@ int AbilityManagerService::ConnectUIExtensionAbility(const Want &want, const spt #endif // WITH_DLP auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), false, nullptr, + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetValidUserId(userId), false, nullptr, shouldBlockFunc); result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -5439,11 +5444,12 @@ int32_t AbilityManagerService::ConnectLocalAbility(const Want &want, const int32 return TARGET_ABILITY_NOT_SERVICE; } + abilityRequest.userId = validUserId; if (!HandleExecuteSAInterceptor(want, callerToken, abilityRequest, result)) { return result; } - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, validUserId, false, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -5535,7 +5541,7 @@ int AbilityManagerService::DisconnectLocalAbility(const sptr } // EnterpriseAdminExtensionAbility Scene - connectManager = GetConnectManagerByUserId(USER_ID_DEFAULT); + connectManager = GetConnectManagerByUserId(MAIN_USER_ID); CHECK_POINTER_AND_RETURN(connectManager, ERR_NO_INIT); return connectManager->DisconnectAbilityLocked(connect); } @@ -6607,7 +6613,7 @@ void AbilityManagerService::DumpSysMissionListInnerBySCB( const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId) { if (!isUserID) { - userId = GetUserId(); + userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); } std::vector argList; @@ -6672,7 +6678,7 @@ void AbilityManagerService::DumpSysAbilityInnerBySCB( const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId) { if (!isUserID) { - userId = GetUserId(); + userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); } std::vector argList; @@ -7403,18 +7409,9 @@ std::shared_ptr AbilityManagerService::GetEventHandler() return eventHandler_; } -// multi user scene -int32_t AbilityManagerService::GetUserId() const -{ - if (userController_) { - auto userId = userController_->GetCurrentUserId(); - TAG_LOGD(AAFwkTag::ABILITYMGR, "userId is %{public}d", userId); - return userId; - } - return U0_USER_ID; -} #ifndef DISABLE_LAUNCHER -int AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isBoot, bool isAppRecovery) +int AbilityManagerService::StartHighestPriorityAbility(int32_t userId, uint64_t displayId, bool isBoot, + bool isAppRecovery) { TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s", __func__); auto bms = AbilityUtil::GetBundleManagerHelper(); @@ -7471,6 +7468,7 @@ int AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isBo #ifdef SUPPORT_GRAPHICS abilityWant.SetParam(NEED_STARTINGWINDOW, false); + abilityWant.SetParam(Want::PARAM_RESV_DISPLAY_ID, static_cast(displayId)); // wait BOOT_ANIMATION_STARTED to start LAUNCHER WaitBootAnimationStart(); #endif @@ -7735,14 +7733,14 @@ void AbilityManagerService::OnAbilityDied(std::shared_ptr ability auto manager = GetMissionListManagerByUserId(abilityRecord->GetOwnerMissionUserId()); if (manager && abilityRecord->GetAbilityInfo().type == AbilityType::PAGE) { ReleaseAbilityTokenMap(abilityRecord->GetToken()); - manager->OnAbilityDied(abilityRecord, GetUserId()); + manager->OnAbilityDied(abilityRecord, abilityRecord->GetOwnerMissionUserId()); return; } } auto connectManager = GetConnectManagerByToken(abilityRecord->GetToken()); if (connectManager) { - connectManager->OnAbilityDied(abilityRecord, GetUserId()); + connectManager->OnAbilityDied(abilityRecord, abilityRecord->GetOwnerMissionUserId()); return; } else { TAG_LOGW(AAFwkTag::ABILITYMGR, "connectManager not found"); @@ -7806,7 +7804,7 @@ int AbilityManagerService::KillProcess(const std::string &bundleName, bool clear auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, KILL_PROCESS_FAILED); - int32_t userId = GetUserId(); + int32_t userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); AppExecFwk::BundleInfo bundleInfo; if (IN_PROCESS_CALL(bms->GetCloneBundleInfoExt(bundleName, static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), @@ -8348,7 +8346,7 @@ void AbilityManagerService::StartKeepAliveApps(int32_t userId) KeepAliveProcessManager::GetInstance().StartKeepAliveProcessWithMainElement(bundleInfos, userId); } -void AbilityManagerService::StartAutoStartupApps() +void AbilityManagerService::StartAutoStartupApps(int32_t userId) { TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); if (abilityAutoStartupService_ == nullptr) { @@ -8356,8 +8354,7 @@ void AbilityManagerService::StartAutoStartupApps() return; } std::vector infoList; - int32_t result = abilityAutoStartupService_->QueryAllAutoStartupApplicationsWithoutPermission(infoList, - GetUserId()); + int32_t result = abilityAutoStartupService_->QueryAllAutoStartupApplicationsWithoutPermission(infoList, userId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "failed query data"); return; @@ -8399,9 +8396,9 @@ void AbilityManagerService::StartAutoStartupApps(std::queue inf int32_t result = ERR_OK; if (info.abilityTypeName == AbilityRuntime::EXTENSION_TYPE_APP_SERVICE) { result = StartExtensionAbility( - want, nullptr, DEFAULT_INVAL_VALUE, AppExecFwk::ExtensionAbilityType::APP_SERVICE); + want, nullptr, info.userId, AppExecFwk::ExtensionAbilityType::APP_SERVICE); } else { - result = StartAbility(want); + result = StartAbility(want, info.userId); } if ((result != ERR_OK) && (info.retryCount > 0)) { info.retryCount--; @@ -8435,9 +8432,9 @@ void AbilityManagerService::SubscribeScreenUnlockedEvent() } } -std::function AbilityManagerService::GetScreenUnlockCallback() +std::function AbilityManagerService::GetScreenUnlockCallback() { - auto screenUnlockCallback = [abilityManager = weak_from_this()]() { + auto screenUnlockCallback = [abilityManager = weak_from_this()](int32_t userId) { TAG_LOGI(AAFwkTag::ABILITYMGR, "on screen unlocked"); auto abilityMgr = abilityManager.lock(); if (abilityMgr == nullptr) { @@ -8460,13 +8457,13 @@ std::function AbilityManagerService::GetScreenUnlockCallback() DelayedSingleton::GetInstance()->StartFailedResidentAbilities(); }; taskHandler->SubmitTask(screenUnlockTask, "ScreenUnlockTask"); - auto delayStartAutoStartupAppTask = [abilityManager]() { + auto delayStartAutoStartupAppTask = [abilityManager, userId]() { auto abilityMgr = abilityManager.lock(); if (abilityMgr == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid abilityMgr pointer"); return; } - abilityMgr->StartAutoStartupApps(); + abilityMgr->StartAutoStartupApps(userId); }; taskHandler->SubmitTask(delayStartAutoStartupAppTask, "DelayStartAutoStartupApps", START_AUTO_START_APP_DELAY_TIME); @@ -8742,8 +8739,12 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const errMsg = "app index is error"; return ERR_APP_CLONE_INDEX_INVALID; } + if (accountId == U0_USER_ID) { + accountId = DEFAULT_INVAL_VALUE; + } + int32_t oriValidUserId = GetValidUserId(accountId); auto checkRet = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), - GetUserId(), appIndex, callerToken, false); + oriValidUserId, appIndex, callerToken, false); if (checkRet != ERR_OK) { return checkRet; } @@ -8752,10 +8753,10 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const DmsUtil::GetInstance().UpdateFlagForCollaboration(want); #endif - StartAbilityInfoWrap threadLocalInfo(want, GetUserId(), appIndex, callerToken); + StartAbilityInfoWrap threadLocalInfo(want, oriValidUserId, appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; isSilent = want.GetBoolParam(Want::PARAM_RESV_CALL_TO_FOREGROUND, false) ? true : !isSilent; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), isSilent, nullptr, + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, oriValidUserId, isSilent, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -8769,10 +8770,6 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const return StartRemoteAbilityByCall(want, callerToken, connect->AsObject()); } - if (accountId == U0_USER_ID) { - accountId = DEFAULT_INVAL_VALUE; - } - int32_t oriValidUserId = GetValidUserId(accountId); if (!JudgeMultiUserConcurrency(oriValidUserId)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "multi-user non-concurrent unsatisfied"); return ERR_CROSS_USER; @@ -8784,12 +8781,13 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const abilityRequest.callerToken = callerToken; abilityRequest.want = want; abilityRequest.connect = connect; - result = GenerateAbilityRequest(want, -1, abilityRequest, callerToken, GetUserId()); + result = GenerateAbilityRequest(want, -1, abilityRequest, callerToken, oriValidUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request error"); return result; } + abilityRequest.userId = oriValidUserId; if (!HandleExecuteSAInterceptor(want, callerToken, abilityRequest, result)) { return result; } @@ -8808,7 +8806,7 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const TAG_LOGD(AAFwkTag::ABILITYMGR, "abilityInfo.applicationInfo.singleton is %{public}s", abilityRequest.abilityInfo.applicationInfo.singleton ? "true" : "false"); UpdateCallerInfoUtil::GetInstance().UpdateCallerInfo(abilityRequest.want, callerToken); - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, oriValidUserId, false, callerToken, std::make_shared(abilityRequest.abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -8909,17 +8907,29 @@ int AbilityManagerService::JudgeAbilityVisibleControl(const AppExecFwk::AbilityI return ABILITY_VISIBLE_FALSE_DENY_REQUEST; } -int AbilityManagerService::StartUser(int userId, sptr callback, bool isAppRecovery) +int AbilityManagerService::StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "startUser in service:%{public}d", userId); + TAG_LOGI(AAFwkTag::ABILITYMGR, "startUser in service:%{public}d, displayId:%{public}" PRIu64"", userId, displayId); + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (callback == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "startUser callback is nullptr"); return INVALID_PARAMETERS_ERR; } - if (IPCSkeleton::GetCallingUid() != ACCOUNT_MGR_SERVICE_UID) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "startUser permission verification failed, not account process"); - callback->OnStartUserDone(userId, CHECK_PERMISSION_FAILED); - return CHECK_PERMISSION_FAILED; + auto checkRet = AbilityRuntime::UserController::GetInstance().CheckUserParam(userId); + if (checkRet != ERR_OK) { + callback->OnStartUserDone(userId, checkRet); + return checkRet; + } + + if (userId == U1_USER_ID) { + UserStarted(userId); + callback->OnStartUserDone(userId, ERR_OK); + return ERR_OK; + } + if (AbilityRuntime::UserController::GetInstance().IsForegroundUser(userId, displayId)) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "StartUser current:%{public}d", userId); + callback->OnStartUserDone(userId, ERR_OK); + return ERR_OK; } if (ShouldBlockAllAppStart() && callback != nullptr) { @@ -8928,32 +8938,67 @@ int AbilityManagerService::StartUser(int userId, sptr callback, b return ERR_ALL_APP_START_BLOCKED; } - if (userController_) { - return userController_->StartUser(userId, callback, isAppRecovery); + DelayedSingleton::GetInstance()->SetEnableStartProcessFlagByUserId(userId, true); + auto oldUserId = AbilityRuntime::UserController::GetInstance().GetForegroundUserId(displayId); + if (oldUserId != U0_USER_ID && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + // start freezing screen + AbilityRuntime::UserController::GetInstance().SetFreezingNewUserId(userId); + StartFreezingScreen(); + auto stopFreezingScreenTask = [weak = weak_from_this()]() { + auto abilityMgr = weak.lock(); + if (abilityMgr == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "ability manager instance null"); + return; + } + abilityMgr->StopFreezingScreen(); + }; + if (taskHandler_) { + taskHandler_->SubmitTask(stopFreezingScreenTask, "StopFreezingScreen", USER_SWITCH_TIMEOUT); + } } - return 0; + + AbilityRuntime::UserController::GetInstance().SetForegroundUserId(userId, displayId); + return SwitchToUser(oldUserId, userId, displayId, callback, isAppRecovery); } int AbilityManagerService::StopUser(int userId, const sptr &callback) { XCOLLIE_TIMER_LESS(__PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "stopUser in service:%{public}d", userId); - if (IPCSkeleton::GetCallingUid() != ACCOUNT_MGR_SERVICE_UID) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "stopUser permission verification failed, not account process"); - if (callback != nullptr) { - callback->OnStopUserDone(userId, CHECK_PERMISSION_FAILED); - } - return CHECK_PERMISSION_FAILED; + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (callback == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "stopUser callback is nullptr"); + return INVALID_PARAMETERS_ERR; } - - auto ret = -1; - if (userController_) { - ret = userController_->StopUser(userId); - TAG_LOGD(AAFwkTag::ABILITYMGR, "ret = %{public}d", ret); + auto checkRet = AbilityRuntime::UserController::GetInstance().CheckStopUserParam(userId); + if (checkRet != ERR_OK) { + callback->OnStopUserDone(userId, checkRet); + return checkRet; } - if (callback) { - callback->OnStopUserDone(userId, ret); + if (AbilityRuntime::UserController::GetInstance().IsForegroundUser(userId)) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "user current:%{public}d", userId); + callback->OnStopUserDone(userId, ERR_OK); + return ERR_OK; } + DelayedSingleton::GetInstance()->KillProcessesByUserId(userId); + + if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + auto missionListWrap = GetMissionListWrap(); + if (!missionListWrap) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListWrap null"); + callback->OnStopUserDone(userId, -1); + return -1; + } + missionListWrap->RemoveUserDir(userId); + } + ClearUserData(userId); + callback->OnStopUserDone(userId, ERR_OK); + UpdateApplicationKeepAlive(userId); + return ERR_OK; +} + +int32_t AbilityManagerService::UpdateApplicationKeepAlive(int32_t userId) const +{ if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) { return 0; } @@ -8971,19 +9016,22 @@ int AbilityManagerService::StopUser(int userId, const sptr &callb bundleInfo.name, false, true, false)); } } - return 0; + return ERR_OK; } int AbilityManagerService::LogoutUser(int32_t userId, sptr callback) { XCOLLIE_TIMER_LESS(__PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "LogoutUser in service:%{public}d", userId); - if (IPCSkeleton::GetCallingUid() != ACCOUNT_MGR_SERVICE_UID) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "permission verification failed, not account process"); - if (callback != nullptr) { - callback->OnLogoutUserDone(userId, CHECK_PERMISSION_FAILED); - } - return CHECK_PERMISSION_FAILED; + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + if (callback == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "logoutUser callback is nullptr"); + return INVALID_PARAMETERS_ERR; + } + auto checkRet = AbilityRuntime::UserController::GetInstance().CheckUserParam(userId); + if (checkRet != ERR_OK) { + callback->OnLogoutUserDone(userId, checkRet); + return checkRet; } // Lister screen unlock for auto startup apps. @@ -8992,11 +9040,11 @@ int AbilityManagerService::LogoutUser(int32_t userId, sptr callba SubscribeScreenUnlockedEvent(); } - if (userController_) { - auto ret = userController_->LogoutUser(userId, callback); - TAG_LOGD(AAFwkTag::ABILITYMGR, "logout user return = %{public}d", ret); - return ret; - } + RemoveLauncherDeathRecipient(userId); + ClearUserData(userId); + DelayedSingleton::GetInstance()->SetEnableStartProcessFlagByUserId(userId, false); + DelayedSingleton::GetInstance()->KillProcessesByUserId(userId, + system::GetBoolParameter(DEVELOPER_MODE_STATE, false), callback); return ERR_OK; } @@ -9138,9 +9186,15 @@ int AbilityManagerService::GetExtensionRunningInfos(int upperLimit, std::vector< TAG_LOGD(AAFwkTag::ABILITYMGR, "Get extension infos, upperLimit : %{public}d", upperLimit); CHECK_CALLER_IS_SYSTEM_APP; auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); - auto connectManager = GetCurrentConnectManager(); - CHECK_POINTER_AND_RETURN(connectManager, ERR_INVALID_VALUE); - connectManager->GetExtensionRunningInfos(upperLimit, info, GetUserId(), isPerm); + std::vector userIds; + AbilityRuntime::UserController::GetInstance().GetAllForegroundUserId(userIds); + auto iter = userIds.begin(); + while (iter != userIds.end()) { + auto connectManager = GetConnectManagerByUserId(*iter); + CHECK_POINTER_AND_RETURN(connectManager, ERR_INVALID_VALUE); + connectManager->GetExtensionRunningInfos(upperLimit, info, *iter, isPerm); + iter++; + } return ERR_OK; } @@ -9458,7 +9512,7 @@ void AbilityManagerService::ScheduleRecoverAbility(const sptr& to CHECK_POINTER_IS_NULLPTR(bms); AppExecFwk::BundleInfo bundleInfo; auto bundleName = want->GetElement().GetBundleName(); - int32_t userId = GetUserId(); + int32_t userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); bool ret = IN_PROCESS_CALL( bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId)); @@ -9516,10 +9570,6 @@ void AbilityManagerService::StartSwitchUserDialog() return; } - if (userController_ == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "user Controller instance null"); - return; - } #ifdef SUPPORT_GRAPHICS auto sysDialog = DelayedSingleton::GetInstance(); if (sysDialog == nullptr) { @@ -9528,7 +9578,7 @@ void AbilityManagerService::StartSwitchUserDialog() } Want dialogWant = sysDialog->GetSwitchUserDialogWant(); - StartSwitchUserDialogInner(dialogWant, userController_->GetFreezingNewUserId()); + StartSwitchUserDialogInner(dialogWant, AbilityRuntime::UserController::GetInstance().GetFreezingNewUserId()); #endif // SUPPORT_GRAPHICS } @@ -9604,8 +9654,8 @@ void AbilityManagerService::UserStarted(int32_t userId) subManagersHelper_->InitSubManagers(userId, false); } -int AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, sptr callback, - bool isAppRecovery) +int AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, uint64_t displayId, + sptr callback, bool isAppRecovery) { TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s, oldUserId:%{public}d, newUserId:%{public}d, isAppRecovery:%{public}d", __func__, @@ -9618,7 +9668,7 @@ int AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, sptr< } #ifndef DISABLE_LAUNCHER bool isBoot = oldUserId == U0_USER_ID ? true : false; - auto ret = StartHighestPriorityAbility(userId, isBoot, isAppRecovery); + auto ret = StartHighestPriorityAbility(userId, displayId, isBoot, isAppRecovery); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "StartHighestPriorityAbility failed: %{public}d", ret); } @@ -9646,9 +9696,6 @@ int AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, sptr< bool AbilityManagerService::IsSceneBoardReady(int32_t userId) { - if (userId < 0) { - userId = GetUserId(); - } auto connectManager = GetConnectManagerByUserId(userId); if (connectManager == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "connectManager is nullptr"); @@ -9724,20 +9771,10 @@ void AbilityManagerService::StartUserApps() } } -int32_t AbilityManagerService::GetValidUserId(const int32_t userId) +int32_t AbilityManagerService::GetValidUserId(int32_t userId) { TAG_LOGD(AAFwkTag::ABILITYMGR, "userId = %{public}d.", userId); - int32_t validUserId = userId; - - if (DEFAULT_INVAL_VALUE == userId) { - validUserId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; - TAG_LOGD(AAFwkTag::ABILITYMGR, "validUserId = %{public}d, CallingUid = %{public}d.", validUserId, - IPCSkeleton::GetCallingUid()); - if (validUserId == U0_USER_ID || validUserId == U1_USER_ID) { - validUserId = GetUserId(); - } - } - return validUserId; + return DEFAULT_INVAL_VALUE == userId ? AbilityRuntime::UserController::GetInstance().GetCallerUserId() : userId; } int AbilityManagerService::SetAbilityController(const sptr &abilityController, @@ -9831,10 +9868,10 @@ int AbilityManagerService::StartUserTest(const Want &want, const sptrGetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, U0_USER_ID))) { TAG_LOGE(AAFwkTag::ABILITYMGR, "failed get bundleInfo by U0_USER_ID %{public}d", U0_USER_ID); - int32_t userId = GetUserId(); TAG_LOGD(AAFwkTag::ABILITYMGR, "bundleName: %{public}s, userId: %{public}d", bundleName.c_str(), userId); if (!IN_PROCESS_CALL( bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId))) { @@ -9849,7 +9886,7 @@ int AbilityManagerService::StartUserTest(const Want &want, const sptr::GetInstance()->StartUserTest(want, observer, bundleInfo, GetUserId()); + return DelayedSingleton::GetInstance()->StartUserTest(want, observer, bundleInfo, userId); } int AbilityManagerService::FinishUserTest( @@ -10007,7 +10044,7 @@ int AbilityManagerService::DelegatorMoveMissionToFront(int32_t missionId) return missionListManager->MoveMissionToFront(missionId); } -bool AbilityManagerService::JudgeMultiUserConcurrency(const int32_t userId) +bool AbilityManagerService::JudgeMultiUserConcurrency(int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (userId == U0_USER_ID || userId == U1_USER_ID) { @@ -10015,15 +10052,11 @@ bool AbilityManagerService::JudgeMultiUserConcurrency(const int32_t userId) return true; } - TAG_LOGD(AAFwkTag::ABILITYMGR, "userId : %{public}d, current userId : %{public}d", userId, GetUserId()); - - // Only non-concurrent mode is supported - bool concurrencyMode = CONCURRENCY_MODE_FALSE; - if (!concurrencyMode) { - return (userId == GetUserId()); + TAG_LOGD(AAFwkTag::ABILITYMGR, "userId : %{public}d", userId); + if (AbilityRuntime::UserController::GetInstance().IsForegroundUser(userId)) { + return true; } - - return true; + return false; } void AbilityManagerService::SendExtensionReport(EventInfo &eventInfo, int32_t errCode, bool isService) @@ -10302,7 +10335,12 @@ void AbilityManagerService::GetAbilityRunningInfo(std::vectorGetCurrentUserId() == userId))) { + if (userId < 0) { + return ERR_OK; + } + int32_t callerUser = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; + if (((callerUser == U0_USER_ID || callerUser == U1_USER_ID) && + UserController::GetInstance().IsForegroundUser(userId)) || callerUser == userId) { return ERR_OK; } return AAFwk::PermissionVerification::GetInstance()->VerifyAccountPermission(); @@ -11777,7 +11815,7 @@ int AbilityManagerService::VerifyPermission(const std::string &permission, int p return CHECK_PERMISSION_FAILED; } - int32_t userId = GetUserId(); + int32_t userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); AppExecFwk::BundleInfo bundleInfo; bool queryBundleInfoRet = IN_PROCESS_CALL( bms->GetBundleInfo(callerBundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId)); @@ -11943,18 +11981,20 @@ int32_t AbilityManagerService::StartSpecifiedAbilityBySCB(const Want &want) TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid app clone index"); return ERR_APP_CLONE_INDEX_INVALID; } + int32_t callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), - GetUserId(), appIndex, nullptr, true); + callerUserId, appIndex, nullptr, true); if (result != ERR_OK) { return result; } AbilityRequest abilityRequest; - result = GenerateAbilityRequest(want, -1, abilityRequest, want.GetRemoteObject(TOKEN_KEY), GetUserId()); + result = GenerateAbilityRequest(want, -1, abilityRequest, want.GetRemoteObject(TOKEN_KEY), callerUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request error"); return result; } + abilityRequest.userId = callerUserId; if (!HandleExecuteSAInterceptor(want, want.GetRemoteObject(TOKEN_KEY), abilityRequest, result)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "interceptor prevented"); return result; @@ -12219,7 +12259,18 @@ int32_t AbilityManagerService::QueryAllAutoStartupApplications(std::vectorQueryAllAutoStartupApplications(infoList, GetUserId()); + std::vector userIds; + AbilityRuntime::UserController::GetInstance().GetAllForegroundUserId(userIds); + int32_t result = ERR_OK; + auto iter = userIds.begin(); + while (iter != userIds.end()) { + result = abilityAutoStartupService_->QueryAllAutoStartupApplications(infoList, *iter); + if (result != ERR_OK) { + return result; + } + iter++; + } + return result; } int AbilityManagerService::PrepareTerminateAbilityBySCB(const sptr &sessionInfo, bool &isTerminate) @@ -12402,7 +12453,8 @@ int32_t AbilityManagerService::ExecuteIntent(uint64_t key, const sptr(AppExecFwk::AbilityType::PAGE); abilityData.appCloneIndex = info.appCloneIndex; AppExecFwk::ApplicationInfo appInfo; - if (!StartAbilityUtils::GetApplicationInfo(abilityData.bundleName, GetUserId(), appInfo)) { + int32_t userId = abilityData.uid / BASE_USER_RANGE; + if (!StartAbilityUtils::GetApplicationInfo(abilityData.bundleName, userId, appInfo)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "can't get applicationInfo through bundleName"); } else if (appInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE) { abilityData.isAtomicService = true; @@ -12674,19 +12727,23 @@ void AbilityManagerService::NotifyConfigurationChange(const AppExecFwk::Configur void AbilityManagerService::NotifyStartResidentProcess(std::vector &bundleInfos) { - if (userController_ == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "userController_ null"); - return; - } - auto currentUser = userController_->GetCurrentUserId(); + int32_t callerUser = + AbilityRuntime::UserController::GetInstance().GetForegroundUserId(DisplayUtil::ObtainDefaultDisplayId()); std::vector bundleInfosForU0; - std::vector bundleInfosForCurrentUser; + std::map> bundleInfosMap; for (const auto &item: bundleInfos) { auto user = item.uid / BASE_USER_RANGE; if (user == U0_USER_ID) { bundleInfosForU0.push_back(item); - } else if (user == currentUser) { - bundleInfosForCurrentUser.push_back(item); + } else if (AbilityRuntime::UserController::GetInstance().IsForegroundUser(user)) { + auto search = bundleInfosMap.find(user); + if (search != bundleInfosMap.end()) { + search->second.push_back(item); + } else { + std::vector bundleInfosForcallerUser; + bundleInfosForcallerUser.push_back(item); + bundleInfosMap.emplace(user, bundleInfosForcallerUser); + } } } @@ -12699,10 +12756,11 @@ void AbilityManagerService::NotifyStartResidentProcess(std::vectorStartResidentProcess(bundleInfosForU0); } - residentProcessMgr->StartResidentProcessWithMainElement( - bundleInfosForCurrentUser, currentUser); - if (!bundleInfosForCurrentUser.empty()) { - residentProcessMgr->StartResidentProcess(bundleInfosForCurrentUser); + for (auto search = bundleInfosMap.rbegin(); search != bundleInfosMap.rend(); ++search) { + residentProcessMgr->StartResidentProcessWithMainElement(search->second, search->first); + if (!search->second.empty()) { + residentProcessMgr->StartResidentProcess(search->second); + } } } @@ -12712,22 +12770,31 @@ void AbilityManagerService::NotifyStartKeepAliveProcess(std::vector bundleInfosForCurrentUser; + auto userId = + AbilityRuntime::UserController::GetInstance().GetForegroundUserId(DisplayUtil::ObtainDefaultDisplayId()); + std::map> bundleInfosMap; std::vector bundleInfosForU1; for (const auto &item: bundleInfos) { - if (item.uid / BASE_USER_RANGE == U1_USER_ID) { + auto user = item.uid / BASE_USER_RANGE; + if (user == U1_USER_ID) { bundleInfosForU1.push_back(item); - } else if (item.uid / BASE_USER_RANGE == userId) { - bundleInfosForCurrentUser.push_back(item); + } else if (AbilityRuntime::UserController::GetInstance().IsForegroundUser(user)) { + auto search = bundleInfosMap.find(user); + if (search != bundleInfosMap.end()) { + search->second.push_back(item); + } else { + std::vector bundleInfosForCurrentUser; + bundleInfosForCurrentUser.push_back(item); + bundleInfosMap.emplace(user, bundleInfosForCurrentUser); + } } else { TAG_LOGI(AAFwkTag::ABILITYMGR, "keepAlive not U1 or current user."); KeepAliveProcessManager::GetInstance().AddNeedRestartKeepAliveUid(item.uid); } } - if (bundleInfosForCurrentUser.size() != 0) { - KeepAliveProcessManager::GetInstance().StartKeepAliveProcessWithMainElement(bundleInfosForCurrentUser, userId); + for (auto search = bundleInfosMap.rbegin(); search != bundleInfosMap.rend(); ++search) { + KeepAliveProcessManager::GetInstance().StartKeepAliveProcessWithMainElement(search->second, search->first); } if (bundleInfosForU1.size() != 0) { @@ -12917,7 +12984,6 @@ bool AbilityManagerService::VerifySameAppOrAppIdentifierAllowListPermission(cons auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, false); AppExecFwk::BundleInfo targetBundleInfo; - int32_t userId = GetUserId(); std::string callerAppIdentifier = abilityRequest.want.GetStringParam(Want::PARAM_RESV_CALLER_APP_IDENTIFIER); if (callerAppIdentifier.empty()) { AppExecFwk::SignatureInfo signatureInfo; @@ -12935,7 +13001,7 @@ bool AbilityManagerService::VerifySameAppOrAppIdentifierAllowListPermission(cons callerAppIdentifier = signatureInfo.appIdentifier; } if (!IN_PROCESS_CALL(bms->GetBundleInfo(targetBundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO, - targetBundleInfo, userId))) { + targetBundleInfo, targetUid / BASE_USER_RANGE))) { TAG_LOGE(AAFwkTag::ABILITYMGR, "bms GetBundleInfo error, BundleFlag: GET_BUNDLE_WITH_EXTENSION_INFO"); return false; } @@ -12952,13 +13018,12 @@ bool AbilityManagerService::VerifySameAppOrAppIdentifierAllowListPermission(cons return false; } -void AbilityManagerService::CloseAssertDialog(const std::string &assertSessionId) +void AbilityManagerService::CloseAssertDialog(const std::string &assertSessionId, int32_t userId) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Close assert fault dialog begin."); - auto validUserId = GetUserId(); - auto connectManager = GetConnectManagerByUserId(validUserId); + auto connectManager = GetConnectManagerByUserId(userId); if (connectManager == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "manager null, userId: %{public}d", validUserId); + TAG_LOGE(AAFwkTag::ABILITYMGR, "manager null, userId: %{public}d", userId); return; } @@ -13030,13 +13095,14 @@ int32_t AbilityManagerService::RequestAssertFaultDialog( TAG_LOGE(AAFwkTag::ABILITYMGR, "get callback death manager instance null"); return ERR_INVALID_VALUE; } - auto callbackTask = [weak = weak_from_this()] (const std::string &assertSessionId) { + int32_t userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; + auto callbackTask = [weak = weak_from_this(), userId] (const std::string &assertSessionId) { auto abilityMgr = weak.lock(); if (abilityMgr == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "ability manager instance null"); return; } - abilityMgr->CloseAssertDialog(assertSessionId); + abilityMgr->CloseAssertDialog(assertSessionId, userId); }; callbackDeathMgr->AddAssertFaultCallback(remoteCallback, callbackTask); TAG_LOGD(AAFwkTag::ABILITYMGR, "Request to display assert fault dialog end."); @@ -13360,14 +13426,15 @@ bool AbilityManagerService::IsEmbeddedOpenAllowed(sptr callerToke want.SetBundle(bundleName); want.SetParam("send_to_erms_embedded", 1); UpdateCallerInfoUtil::GetInstance().UpdateCallerInfo(want, callerToken); - int32_t ret = freeInstallManager_->StartFreeInstall(want, GetUserId(), 0, callerToken); + int32_t callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); + int32_t ret = freeInstallManager_->StartFreeInstall(want, callerUserId, 0, callerToken); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "target not allowed free install"); return false; } want.SetParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME, callerAbility->GetElementName().GetBundleName()); auto erms = std::make_shared(); - return erms->DoProcess(want, GetUserId()); + return erms->DoProcess(want, callerUserId); } int32_t AbilityManagerService::AddQueryERMSObserver(sptr callerToken, @@ -13403,7 +13470,7 @@ int32_t AbilityManagerService::QueryAtomicServiceStartupRule(sptr want.SetBundle(ATOMIC_SERVICE_PREFIX + appId); want.SetParam("send_to_erms_embedded", 1); UpdateCallerInfoUtil::GetInstance().UpdateCallerInfo(want, callerToken); - auto userId = GetUserId(); + auto userId = callerAbility->GetOwnerMissionUserId(); int32_t ret = freeInstallManager_->StartFreeInstall(want, userId, 0, callerToken); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "free install failed:%{public}d", ret); @@ -13415,7 +13482,7 @@ int32_t AbilityManagerService::QueryAtomicServiceStartupRule(sptr want.SetParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME, callerAbility->GetElementName().GetBundleName()); auto erms = std::make_shared(); sptr replaceWant = nullptr; - ret = erms->QueryAtomicServiceStartupRule(want, callerToken, GetUserId(), rule, replaceWant); + ret = erms->QueryAtomicServiceStartupRule(want, callerToken, userId, rule, replaceWant); if (ret == ERR_OK) { TAG_LOGI(AAFwkTag::ABILITYMGR, "QueryAtomicServiceStartupRule succeeded"); return ERR_OK; @@ -14000,7 +14067,7 @@ int AbilityManagerService::StartUIAbilityByPreInstallInner(sptr ses } StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; - AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, validUserId, true, nullptr, shouldBlockFunc); auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(interceptorParam); @@ -14019,6 +14086,7 @@ int AbilityManagerService::StartUIAbilityByPreInstallInner(sptr ses return result; } + abilityRequest.userId = validUserId; if (!HandleExecuteSAInterceptor(want, callerToken, abilityRequest, result)) { return result; } @@ -14056,7 +14124,7 @@ int AbilityManagerService::StartUIAbilityByPreInstallInner(sptr ses } Want newWant = abilityRequest.want; - AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, validUserId, true, callerToken, std::make_shared(abilityInfo), isStartAsCaller, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); @@ -14068,12 +14136,12 @@ int AbilityManagerService::StartUIAbilityByPreInstallInner(sptr ses } #ifdef SUPPORT_SCREEN if (result != ERR_OK && isReplaceWantExist && callerBundleName != BUNDLE_NAME_DIALOG) { - return DialogSessionManager::GetInstance().HandleErmsResult(abilityRequest, GetUserId(), newWant); + return DialogSessionManager::GetInstance().HandleErmsResult(abilityRequest, validUserId, newWant); } if (result == ERR_OK && - DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, GetUserId())) { + DialogSessionManager::GetInstance().IsCreateCloneSelectorDialog(abilityInfo.bundleName, validUserId)) { TAG_LOGI(AAFwkTag::ABILITYMGR, "create clone selector dialog"); - return CreateCloneSelectorDialog(abilityRequest, GetUserId()); + return CreateCloneSelectorDialog(abilityRequest, validUserId); } #endif // SUPPORT_SCREEN @@ -14625,8 +14693,9 @@ int AbilityManagerService::StartSelfUIAbilityInner(StartSelfUIAbilityParam param CHECK_POINTER_AND_RETURN(bundleMgrHelper, INNER_ERR); AppExecFwk::AbilityInfo abilityInfo; + auto callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); CHECK_TRUE_RETURN_RET(!IN_PROCESS_CALL(bundleMgrHelper->QueryAbilityInfo(param.want, - AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, GetUserId(), abilityInfo)), + AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, callerUserId, abilityInfo)), TARGET_BUNDLE_NOT_EXIST, "bundle or ability not exist"); CHECK_TRUE_RETURN_RET(abilityInfo.type != AppExecFwk::AbilityType::PAGE, @@ -15020,7 +15089,15 @@ int32_t AbilityManagerService::GetInsightIntentInfoByIntentName( bool AbilityManagerService::IsCrossUserCall(int32_t userId) const { - return userId != INVALID_USER_ID && userId != U0_USER_ID && userId != U1_USER_ID && userId != GetUserId(); + if (userId == INVALID_USER_ID || userId == U0_USER_ID || userId == U1_USER_ID) { + return false; + } + int32_t callerUser = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; + if (((callerUser == U0_USER_ID || callerUser == U1_USER_ID) && + UserController::GetInstance().IsForegroundUser(userId)) || callerUser == userId) { + return false; + } + return true; } int32_t AbilityManagerService::RestartSelfAtomicService(sptr callerToken) @@ -15149,7 +15226,7 @@ bool AbilityManagerService::HandleExecuteSAInterceptor(const Want &want, sptr callback = nullptr; if (data.ReadBool()) { callback = iface_cast(data.ReadRemoteObject()); @@ -2554,7 +2555,7 @@ int AbilityManagerStub::StartUserInner(MessageParcel &data, MessageParcel &reply return ERR_INVALID_VALUE; } bool isAppRecovery = data.ReadBool(); - int result = StartUser(userId, callback, isAppRecovery); + int result = StartUser(userId, displayId, callback, isAppRecovery); if (!reply.WriteInt32(result)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "startUser fail"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index ac38cf0ac84b429fb3593de814035bf6cd69a182..59db683ffaea11e667757e0b0e686997c8e45ff5 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -564,12 +564,6 @@ int32_t AppScheduler::GetBundleNameByPid(const int pid, std::string &bundleName, return ERR_OK; } -void AppScheduler::SetCurrentUserId(const int32_t userId) -{ - CHECK_POINTER(appMgrClient_); - IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->SetCurrentUserId(userId)); -} - void AppScheduler::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) { CHECK_POINTER(appMgrClient_); diff --git a/services/abilitymgr/src/data_ability/data_ability_manager.cpp b/services/abilitymgr/src/data_ability/data_ability_manager.cpp index fe0a4abfa9895f4ea8dddd188eb3599b62d997c3..101470fdcfab9d575bc1ea8aaaa26f71af590a7d 100644 --- a/services/abilitymgr/src/data_ability/data_ability_manager.cpp +++ b/services/abilitymgr/src/data_ability/data_ability_manager.cpp @@ -28,6 +28,7 @@ using namespace std::placeholders; namespace { constexpr bool DEBUG_ENABLED = false; constexpr system_clock::duration DATA_ABILITY_LOAD_TIMEOUT = 11000ms; +constexpr int32_t USER_ID_NO_HEAD = 0; } // namespace DataAbilityManager::DataAbilityManager() diff --git a/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp b/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp index 0d7afe01f05364b6df4941e49a49a892158225c9..84aa8ea2f0ef63b1255b6038d7d633395f220687 100644 --- a/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp +++ b/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp @@ -18,6 +18,7 @@ #include "ability_keep_alive_data_manager.h" #include "ability_manager_service.h" #include "hilog_tag_wrapper.h" +#include "user_controller/user_controller.h" namespace OHOS { namespace AbilityRuntime { @@ -104,14 +105,9 @@ void AbilityKeepAliveService::GetValidUserId(int32_t &userId) if (userId >= 0) { return; } - auto abilityMgr = DelayedSingleton::GetInstance(); - if (abilityMgr == nullptr) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null abilityMgr"); - return; - } if (userId < 0) { - userId = abilityMgr->GetUserId(); + userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); } } diff --git a/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp b/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp index b32d893f8309b0481ba1d455337a7e9363bf9a76..586b46c8471f09952b5159ebed19da9e9d11d568 100644 --- a/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp +++ b/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp @@ -25,6 +25,7 @@ #include "parameters.h" #include "permission_constants.h" #include "process_options.h" +#include "user_controller/user_controller.h" namespace OHOS { namespace AAFwk { @@ -218,7 +219,7 @@ int32_t KeepAliveProcessManager::SetApplicationKeepAlive(const std::string &bund auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, INNER_ERR); - userId = userId < 0 ? DelayedSingleton::GetInstance()->GetUserId() : userId; + userId = userId < 0 ? AbilityRuntime::UserController::GetInstance().GetCallerUserId() : userId; AppExecFwk::BundleInfo bundleInfo; if (!IN_PROCESS_CALL(bms->GetBundleInfo( bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId))) { diff --git a/services/abilitymgr/src/resident_process/resident_process_manager.cpp b/services/abilitymgr/src/resident_process/resident_process_manager.cpp index c7ff7088eb09abee14a54c08df9f9273265c4d30..644403c08a378a928aa57d120d784a4debee58b9 100644 --- a/services/abilitymgr/src/resident_process/resident_process_manager.cpp +++ b/services/abilitymgr/src/resident_process/resident_process_manager.cpp @@ -22,6 +22,7 @@ #include "ffrt.h" #include "keep_alive_utils.h" #include "main_element_utils.h" +#include "user_controller/user_controller.h" namespace OHOS { namespace AAFwk { @@ -188,7 +189,6 @@ int32_t ResidentProcessManager::SetResidentProcessEnabled( TAG_LOGD(AAFwkTag::ABILITYMGR, "Set keep alive enable state."); IN_PROCESS_CALL_WITHOUT_RET(appMgrClient->SetKeepAliveEnableState(bundleName, updateEnable, 0)); } - ffrt::submit([self = shared_from_this(), bundleName, localEnable, updateEnable]() { self->UpdateResidentProcessesStatus(bundleName, localEnable, updateEnable); }); @@ -210,9 +210,14 @@ void ResidentProcessManager::UpdateResidentProcessesStatus( return; } + std::vector userIds; + AbilityRuntime::UserController::GetInstance().GetAllForegroundUserId(userIds); + std::set users{0}; + auto iter = userIds.begin(); + while (iter != userIds.end()) { + users.emplace(*iter); + } AppExecFwk::BundleInfo bundleInfo; - auto currentUser = DelayedSingleton::GetInstance()->GetUserId(); - std::set users{0, currentUser}; for (const auto &userId: users) { if (!IN_PROCESS_CALL(bms->GetBundleInfo( diff --git a/services/abilitymgr/src/user_controller.cpp b/services/abilitymgr/src/user_controller.cpp deleted file mode 100644 index c1b8408e95a15321ee61d48523980a640566a780..0000000000000000000000000000000000000000 --- a/services/abilitymgr/src/user_controller.cpp +++ /dev/null @@ -1,570 +0,0 @@ -/* - * Copyright (c) 2021-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 "user_controller.h" - -#include "ability_manager_service.h" -#include "hilog_tag_wrapper.h" -#include "mock_session_manager_service.h" -#include "os_account_manager_wrapper.h" -#include "scene_board_judgement.h" - -namespace OHOS { -namespace AAFwk { -using namespace OHOS::AppExecFwk; -namespace { -const int64_t USER_SWITCH_TIMEOUT = 3 * 1000; // 3s -constexpr const char* DEVELOPER_MODE_STATE = "const.security.developermode.state"; -} - -UserItem::UserItem(int32_t id) : userId_(id) -{} - -UserItem::~UserItem() {} - -int32_t UserItem::GetUserId() -{ - return userId_; -} - -void UserItem::SetState(const UserState &state) -{ - if (curState_ == state) { - return; - } - lastState_ = curState_; - curState_ = state; -} - -UserState UserItem::GetState() -{ - return curState_; -} - -UserController::UserController() -{ -} - -UserController::~UserController() -{ -} - -void UserController::Init() -{ - auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); - if (!handler) { - return; - } - - if (eventHandler_) { - return; - } - eventHandler_ = std::make_shared(handler, shared_from_this()); -} - -void UserController::ClearAbilityUserItems(int32_t userId) -{ - std::lock_guard guard(userLock_); - if (userItems_.count(userId)) { - userItems_.erase(userId); - } -} - -int UserController::StartUser(int32_t userId, sptr callback, bool isAppRecovery) -{ - if (userId == U1_USER_ID) { - return StartNoHeadUser(userId, callback); - } - - if (userId < 0 || userId == USER_ID_NO_HEAD) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUserId invalid:%{public}d", userId); - if (callback != nullptr) { - callback->OnStartUserDone(userId, INVALID_USERID_VALUE); - } - return INVALID_USERID_VALUE; - } - - if (IsCurrentUser(userId)) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "StartUser current:%{public}d", userId); - if (callback != nullptr) { - callback->OnStartUserDone(userId, ERR_OK); - } - return ERR_OK; - } - - auto appScheduler = DelayedSingleton::GetInstance(); - if (!appScheduler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null appScheduler"); - return ABILITY_SERVICE_NOT_CONNECTED; - } - appScheduler->SetEnableStartProcessFlagByUserId(userId, true); - - if (!IsExistOsAccount(userId)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null StartUser account:%{public}d", userId); - if (callback != nullptr) { - callback->OnStartUserDone(userId, INVALID_USERID_VALUE); - } - return INVALID_USERID_VALUE; - } - - if (GetCurrentUserId() != USER_ID_NO_HEAD && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - // start freezing screen - SetFreezingNewUserId(userId); - DelayedSingleton::GetInstance()->StartFreezingScreen(); - } - - auto oldUserId = GetCurrentUserId(); - auto userItem = GetOrCreateUserItem(userId); - auto state = userItem->GetState(); - if (state == STATE_STOPPING || state == STATE_SHUTDOWN) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUser user stop, userId:%{public}d", userId); - if (callback != nullptr) { - callback->OnStartUserDone(userId, ERR_DEAD_OBJECT); - } - return ERR_DEAD_OBJECT; - } - - SetCurrentUserId(userId); - if (state == STATE_BOOTING) { - // send user start msg. - SendSystemUserStart(userId); - } - - SendSystemUserCurrent(oldUserId, userId); - SendReportUserSwitch(oldUserId, userId, userItem); - SendUserSwitchTimeout(oldUserId, userId, userItem); - return MoveUserToForeground(oldUserId, userId, callback, isAppRecovery); -} - -int32_t UserController::StartNoHeadUser(int32_t userId, sptr callback) const -{ - if (!IsExistOsAccount(userId)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "U1 not exist"); - callback->OnStartUserDone(userId, INVALID_USERID_VALUE); - return INVALID_USERID_VALUE; - } - - auto abilityManagerService = DelayedSingleton::GetInstance(); - if (!abilityManagerService) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityManagerService is nullptr"); - callback->OnLogoutUserDone(userId, GET_ABILITY_SERVICE_FAILED); - return GET_ABILITY_SERVICE_FAILED; - } - abilityManagerService->UserStarted(userId); - callback->OnStartUserDone(userId, ERR_OK); - return ERR_OK; -} - -int32_t UserController::StopUser(int32_t userId) -{ - if (userId < 0 || userId == USER_ID_NO_HEAD || userId == USER_ID_DEFAULT) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "userId invalid:%{public}d", userId); - return -1; - } - - if (IsCurrentUser(userId)) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "user current:%{public}d", userId); - return 0; - } - - if (!IsExistOsAccount(userId)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null account:%{public}d", userId); - return -1; - } - - BroadcastUserStopping(userId); - - auto appScheduler = DelayedSingleton::GetInstance(); - if (!appScheduler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null appScheduler"); - return -1; - } - appScheduler->KillProcessesByUserId(userId); - - auto abilityManagerService = DelayedSingleton::GetInstance(); - if (!abilityManagerService) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityManagerService null"); - return -1; - } - - if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto missionListWrap = abilityManagerService->GetMissionListWrap(); - if (!missionListWrap) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListWrap null"); - return -1; - } - missionListWrap->RemoveUserDir(userId); - } - - abilityManagerService->ClearUserData(userId); - - BroadcastUserStopped(userId); - return 0; -} - -int32_t UserController::LogoutUser(int32_t userId, sptr callback) -{ - if (userId < 0 || userId == USER_ID_NO_HEAD) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "userId invalid:%{public}d", userId); - if (callback) { - callback->OnLogoutUserDone(userId, INVALID_USERID_VALUE); - } - return INVALID_USERID_VALUE; - } - if (!IsExistOsAccount(userId)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null account:%{public}d", userId); - if (callback) { - callback->OnLogoutUserDone(userId, INVALID_USERID_VALUE); - } - return INVALID_USERID_VALUE; - } - auto abilityManagerService = DelayedSingleton::GetInstance(); - if (!abilityManagerService) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null abilityManagerService"); - if (callback) { - callback->OnLogoutUserDone(userId, -1); - } - return -1; - } - abilityManagerService->RemoveLauncherDeathRecipient(userId); - if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "SceneBoard exit normally."); - Rosen::MockSessionManagerService::GetInstance().NotifyNotKillService(); - } - auto appScheduler = DelayedSingleton::GetInstance(); - if (!appScheduler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null appScheduler"); - if (callback) { - callback->OnLogoutUserDone(userId, INVALID_USERID_VALUE); - } - return INVALID_USERID_VALUE; - } - abilityManagerService->ClearUserData(userId); - appScheduler->SetEnableStartProcessFlagByUserId(userId, false); - if (IsCurrentUser(userId)) { - SetCurrentUserId(0); - } - appScheduler->KillProcessesByUserId(userId, system::GetBoolParameter(DEVELOPER_MODE_STATE, false), callback); - ClearAbilityUserItems(userId); - return 0; -} - -int32_t UserController::GetCurrentUserId() -{ - std::lock_guard guard(userLock_); - return currentUserId_; -} - -std::shared_ptr UserController::GetUserItem(int32_t userId) -{ - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it != userItems_.end()) { - return it->second; - } - - return nullptr; -} - -bool UserController::IsCurrentUser(int32_t userId) -{ - int32_t oldUserId = GetCurrentUserId(); - if (oldUserId == userId) { - auto userItem = GetUserItem(userId); - if (userItem) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "IsCurrentUserId current:%{public}d", userId); - return true; - } - } - return false; -} - -bool UserController::IsExistOsAccount(int32_t userId) const -{ - bool isExist = false; - auto errCode = DelayedSingleton::GetInstance()->IsOsAccountExists(userId, isExist); - return (errCode == 0) && isExist; -} - -std::shared_ptr UserController::GetOrCreateUserItem(int32_t userId) -{ - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it != userItems_.end()) { - return it->second; - } - - auto userItem = std::make_shared(userId); - userItems_.emplace(userId, userItem); - return userItem; -} - -void UserController::SetCurrentUserId(int32_t userId) -{ - std::lock_guard guard(userLock_); - currentUserId_ = userId; - TAG_LOGD(AAFwkTag::ABILITYMGR, "set current userId: %{public}d", userId); - DelayedSingleton::GetInstance()->SetCurrentUserId(userId); -} - -int UserController::MoveUserToForeground(int32_t oldUserId, int32_t newUserId, sptr callback, - bool isAppRecovery) -{ - auto manager = DelayedSingleton::GetInstance(); - if (!manager) { - return ABILITY_SERVICE_NOT_CONNECTED; - } - auto ret = manager->SwitchToUser(oldUserId, newUserId, callback, isAppRecovery); - if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "SwitchToUser failed: %{public}d", ret); - } - BroadcastUserBackground(oldUserId); - BroadcastUserForeground(newUserId); - return ret; -} - -void UserController::UserBootDone(std::shared_ptr &item) -{ - if (!item) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null item"); - return; - } - int32_t userId = item->GetUserId(); - - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it == userItems_.end()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid userId"); - return; - } - - if (item != it->second) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid item"); - return; - } - item->SetState(UserState::STATE_STARTED); - auto manager = DelayedSingleton::GetInstance(); - if (!manager) { - return; - } - manager->UserStarted(userId); -} - -void UserController::BroadcastUserBackground(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "user background"); -} - -void UserController::BroadcastUserForeground(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "user foreground"); -} - -void UserController::BroadcastUserStopping(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "user stopping"); -} - -void UserController::BroadcastUserStopped(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "user stopped"); -} - -void UserController::SendSystemUserStart(int32_t userId) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->newUserId = userId; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_SYSTEM_USER_START, eventData)); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_SYSTEM_USER_START)"); -} - -void UserController::ProcessEvent(const EventWrap &event) -{ - auto eventId = event.GetEventId(); - auto eventData = static_cast(event.GetEventData().get()); - if (!eventData) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "no event data, event id: %{public}u.", eventId); - return; - } - - TAG_LOGD(AAFwkTag::ABILITYMGR, "Event id obtained: %{public}u.", eventId); - switch (eventId) { - case UserEventHandler::EVENT_SYSTEM_USER_START: { - HandleSystemUserStart(eventData->newUserId); - break; - } - case UserEventHandler::EVENT_SYSTEM_USER_CURRENT: { - HandleSystemUserCurrent(eventData->oldUserId, eventData->newUserId); - break; - } - case UserEventHandler::EVENT_REPORT_USER_SWITCH: { - HandleReportUserSwitch(eventData->oldUserId, eventData->newUserId, eventData->userItem); - break; - } - case UserEventHandler::EVENT_CONTINUE_USER_SWITCH: { - HandleContinueUserSwitch(eventData->oldUserId, eventData->newUserId, eventData->userItem); - break; - } - case UserEventHandler::EVENT_USER_SWITCH_TIMEOUT: { - HandleUserSwitchTimeout(eventData->oldUserId, eventData->newUserId, eventData->userItem); - break; - } - case UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE: { - HandleUserSwitchDone(eventData->newUserId); - break; - } - default: { - TAG_LOGW(AAFwkTag::ABILITYMGR, "Unsupported event."); - break; - } - } -} - -void UserController::SendSystemUserCurrent(int32_t oldUserId, int32_t newUserId) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_SYSTEM_USER_CURRENT, eventData)); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_SYSTEM_USER_CURRENT)"); -} - -void UserController::SendReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - eventData->userItem = usrItem; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_REPORT_USER_SWITCH, eventData)); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_REPORT_USER_SWITCH)"); -} - -void UserController::SendUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - eventData->userItem = usrItem; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT, - eventData), USER_SWITCH_TIMEOUT); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_USER_SWITCH_TIMEOUT)"); -} - -void UserController::SendContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - eventData->userItem = usrItem; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_CONTINUE_USER_SWITCH, eventData)); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_CONTINUE_USER_SWITCH)"); -} - -void UserController::SendUserSwitchDone(int32_t userId) -{ - auto handler = eventHandler_; - if (!handler) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null handler"); - return; - } - - auto eventData = std::make_shared(); - eventData->newUserId = userId; - handler->SendEvent(EventWrap(UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE, - eventData)); - TAG_LOGD(AAFwkTag::ABILITYMGR, "SendEvent(EVENT_REPORT_USER_SWITCH_DONE)"); -} - -void UserController::HandleSystemUserStart(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "notify system user start."); -} - -void UserController::HandleSystemUserCurrent(int32_t oldUserId, int32_t newUserId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "notify system user current."); -} - -void UserController::HandleReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "notify report user switch."); -} - -void UserController::HandleUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - SendContinueUserSwitch(oldUserId, newUserId, usrItem); -} - -void UserController::HandleContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto manager = DelayedSingleton::GetInstance(); - if (manager && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - manager->StopFreezingScreen(); - } - SendUserSwitchDone(newUserId); -} - -void UserController::HandleUserSwitchDone(int32_t userId) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "handle user switch done."); -} - -int32_t UserController::GetFreezingNewUserId() const -{ - return freezingNewUserId_; -} - -void UserController::SetFreezingNewUserId(int32_t userId) -{ - freezingNewUserId_ = userId; -} -} -} diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index b9d6640df6bd381647646dd476c29e9e337b77c4..152990173ec0c9626c97c9b77799531e80d0fc5e 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -117,6 +117,7 @@ ohos_shared_library("libappms") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -177,6 +178,7 @@ ohos_shared_library("libappms") { deps += [] external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index 5daa110dacf8b90e4138fc6e1b812bb97a02f93e..54880a748f8b8d3cb520f563bfdcc3718c4919c9 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -293,13 +293,6 @@ public: virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0, const std::string &customProcess = "") override; - /** - * SetCurrentUserId, set the userid to app mgr by ability mgr when switching to another user. - * - * @param userId the new user. - */ - virtual void SetCurrentUserId(const int32_t userId) override; - virtual void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) override; /** diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 95d7b057eed7cf05f86c32d3f339343b14b85fda..8ecd6ea530dade12a7b72d5f5c41c9c15296d487 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1025,14 +1025,6 @@ public: */ void HandleWindowPidVisibilityChanged(const sptr& windowPidVisibilityInfo); #endif //SUPPORT_SCREEN - /** - * Set the current userId, only used by abilityMgr. - * - * @param userId the user id. - * - * @return - */ - void SetCurrentUserId(const int32_t userId); /** * Set enable start process flag by userId @@ -2044,7 +2036,6 @@ private: void SendHiSysEvent(int32_t innerEventId, std::shared_ptr appRecord); int FinishUserTestLocked( const std::string &msg, const int64_t &resultCode, const std::shared_ptr &appRecord); - int32_t GetCurrentAccountId() const; void SendReStartProcessEvent(AAFwk::EventInfo &eventInfo, int32_t appUid); void SendAppLaunchEvent(const std::shared_ptr &appRecord); void InitAppWaitingDebugList(); @@ -2126,7 +2117,6 @@ private: bool isInitAppWaitingDebugListExecuted_ = false; std::atomic sceneBoardAttachFlag_ = true; std::atomic willKillPidsNum_ = 0; - int32_t currentUserId_ = 0; int32_t lastRenderUid_ = Constants::START_UID_FOR_RENDER_PROCESS; const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; std::vector appStateCallbacks_; diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 92cc246bf7928b28454650d6b25de2fec16b9b06..329df9814c888d122714d78c42dd5ecb9577076f 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -536,14 +536,6 @@ int32_t AmsMgrScheduler::NotifyAppMgrRecordExitReason(int32_t pid, int32_t reaso return amsMgrServiceInner_->NotifyAppMgrRecordExitReason(pid, reason, exitMsg); } -void AmsMgrScheduler::SetCurrentUserId(const int32_t userId) -{ - if (!IsReady()) { - return; - } - amsMgrServiceInner_->SetCurrentUserId(userId); -} - void AmsMgrScheduler::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) { if (!IsReady()) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 501d299882e5949452c43e3de753e437fa4d62f5..aecfef532fb81405c880fb4b050e8d8189516130 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -46,6 +46,7 @@ #include "common_event_manager.h" #include "common_event_support.h" #include "datetime_ex.h" +#include "display_util.h" #include "distributed_data_mgr.h" #include "extension_ability_info.h" #include "ffrt.h" @@ -106,6 +107,7 @@ #include "cache_process_manager.h" #include "res_sched_util.h" #include "session_manager_lite.h" +#include "user_controller/user_controller.h" #ifdef APP_NO_RESPONSE_DIALOG #include "fault_data.h" #include "modal_system_app_freeze_uiextension.h" @@ -120,6 +122,7 @@ namespace AppExecFwk { #ifdef SUPPORT_SCREEN using namespace OHOS::Rosen; #endif //SUPPORT_SCREEN +using namespace OHOS::AbilityRuntime; using namespace OHOS::Security; using namespace OHOS::Rosen; @@ -284,7 +287,6 @@ constexpr int32_t ROOT_UID = 0; constexpr int32_t FOUNDATION_UID = 5523; constexpr int32_t QUICKFIX_UID = 5524; constexpr int32_t DEFAULT_USER_ID = 0; -constexpr int32_t CURRENT_USER_ID = -1; constexpr int32_t RESOURCE_MANAGER_UID = 1096; constexpr int32_t BLUETOOTH_GROUPID = 1002; @@ -578,8 +580,11 @@ int32_t AppMgrServiceInner::PreloadApplication(const std::string &bundleName, in TAG_LOGE(AAFwkTag::APPMGR, "null appPreloader"); return ERR_INVALID_VALUE; } - if (userId == CURRENT_USER_ID) { - userId = currentUserId_; + if (userId == DEFAULT_INVAL_VALUE) { + userId = GetUserIdByUid(IPCSkeleton::GetCallingUid()); + if (userId == U0_USER_ID || userId == U1_USER_ID) { + userId = UserController::GetInstance().GetForegroundUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); + } } if (UserRecordManager::GetInstance().IsLogoutUser(userId)) { TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user"); @@ -2299,7 +2304,7 @@ int32_t AppMgrServiceInner::ClearUpApplicationData(const std::string &bundleName if (userId == DEFAULT_INVAL_VALUE) { newUserId = GetUserIdByUid(callerUid); if (newUserId == U0_USER_ID || newUserId == U1_USER_ID) { - newUserId = currentUserId_; + newUserId = UserController::GetInstance().GetForegroundUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); } } TAG_LOGI(AAFwkTag::APPMGR, "bundleName: %{public}s, uId: %{public}d, appIndex: %{public}d", bundleName.c_str(), @@ -2321,7 +2326,7 @@ int32_t AppMgrServiceInner::ClearUpApplicationDataBySelf(int32_t callerUid, pid_ if (userId == DEFAULT_INVAL_VALUE) { newUserId = GetUserIdByUid(callerUid); if (newUserId == U0_USER_ID) { - newUserId = currentUserId_; + newUserId = UserController::GetInstance().GetForegroundUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); } } auto appCloneIndex = appRecord->GetAppIndex(); @@ -2425,12 +2430,13 @@ int32_t AppMgrServiceInner::GetRunningProcessesByBundleType(BundleType bundleTyp TAG_LOGE(AAFwkTag::APPMGR, "permission deny"); return ERR_PERMISSION_DENIED; } + int32_t userId = UserController::GetInstance().GetCallerUserId(); for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) { const auto &appRecord = item.second; if (!appRecord || !appRecord->GetSpawned()) { continue; } - if (GetUserIdByUid(appRecord->GetUid()) != currentUserId_) { + if (GetUserIdByUid(appRecord->GetUid()) != userId) { continue; } auto appInfo = appRecord->GetApplicationInfo(); @@ -2458,9 +2464,10 @@ int32_t AppMgrServiceInner::GetRunningMultiAppInfoByBundleName(const std::string return ERR_INVALID_VALUE; } ApplicationInfo appInfo; - TAG_LOGD(AAFwkTag::APPMGR, "userId: %{public}d, bundleName: %{public}s", currentUserId_, bundleName.c_str()); + int32_t userId = UserController::GetInstance().GetCallerUserId(); + TAG_LOGD(AAFwkTag::APPMGR, "userId: %{public}d, bundleName: %{public}s", userId, bundleName.c_str()); auto queryRet = IN_PROCESS_CALL(bundleMgrHelper->GetApplicationInfo(bundleName, - ApplicationFlag::GET_BASIC_APPLICATION_INFO, currentUserId_, appInfo)); + ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo)); if (!queryRet) { TAG_LOGE(AAFwkTag::APPMGR, "bundle unexist"); return AAFwk::ERR_BUNDLE_NOT_EXIST; @@ -2481,7 +2488,7 @@ int32_t AppMgrServiceInner::GetRunningMultiAppInfoByBundleName(const std::string if (appRecord == nullptr || appRecord->GetBundleName() != bundleName) { continue; } - if (GetUserIdByUid(appRecord->GetUid()) != currentUserId_) { + if (GetUserIdByUid(appRecord->GetUid()) != userId) { continue; } #ifdef SUPPORT_CHILD_PROCESS @@ -2509,14 +2516,15 @@ int32_t AppMgrServiceInner::GetAllRunningInstanceKeysBySelf(std::vector &instanceKeys, int32_t userId) { if (userId == -1) { - userId = currentUserId_; + userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); } if (VerifyAccountPermission(AAFwk::PermissionConstants::PERMISSION_GET_RUNNING_INFO, userId) == ERR_PERMISSION_DENIED) { @@ -5997,7 +6005,8 @@ void AppMgrServiceInner::HandleConfigurationChange(const Configuration& config, for (const auto &item : appStateCallbacks_) { if (item.callback != nullptr && (userId == -1 || item.userId == 0 || item.userId == userId)) { - item.callback->NotifyConfigurationChange(config, currentUserId_); + item.callback->NotifyConfigurationChange(config, + UserController::GetInstance().GetForegroundUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId())); } } } @@ -6355,7 +6364,10 @@ bool AppMgrServiceInner::VerifyAPL() const int AppMgrServiceInner::VerifyAccountPermission(const std::string &permissionName, const int userId) const { - if (userId != currentUserId_) { + int32_t callerUser = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; + if (((callerUser != U0_USER_ID && callerUser != U1_USER_ID) || + !UserController::GetInstance().IsForegroundUser(userId)) && + callerUser != userId) { auto isCallingPermAccount = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( AAFwk::PermissionConstants::PERMISSION_INTERACT_ACROSS_LOCAL_ACCOUNTS); if (!isCallingPermAccount) { @@ -7583,8 +7595,8 @@ int32_t AppMgrServiceInner::IsAppRunning(const std::string &bundleName, int32_t TAG_LOGE(AAFwkTag::APPMGR, "bundleMgrHelper null"); return ERR_INVALID_OPERATION; } + int32_t userId = UserController::GetInstance().GetCallerUserId(); BundleInfo bundleInfo; - auto userId = GetCurrentAccountId(); int32_t bundleMgrResult; if (appCloneIndex == 0) { bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(bundleName, @@ -7621,7 +7633,7 @@ int32_t AppMgrServiceInner::IsAppRunningByBundleNameAndUserId(const std::string } if (userId < 0) { - userId = GetCurrentAccountId(); + userId = UserController::GetInstance().GetCallerUserId(); } return appRunningManager_->IsAppRunningByBundleNameAndUserId(bundleName, userId, isRunning); @@ -7634,7 +7646,7 @@ bool AppMgrServiceInner::CreateAbilityInfo(const AAFwk::Want &want, AbilityInfo TAG_LOGE(AAFwkTag::APPMGR, "get bundle manager helper error"); return false; } - auto userId = GetCurrentAccountId(); + auto userId = UserController::GetInstance().GetCallerUserId(); auto abilityInfoFlag = AbilityRuntime::StartupUtil::BuildAbilityInfoFlag(); if (IN_PROCESS_CALL(bundleMgrHelper->QueryAbilityInfo(want, abilityInfoFlag, userId, abilityInfo))) { TAG_LOGI(AAFwkTag::APPMGR, "queryAbilityInfo ok"); @@ -7714,23 +7726,6 @@ int32_t AppMgrServiceInner::StartNativeProcessForDebugger(const AAFwk::Want &wan return StartPerfProcessByStartMsg(startMsg, pefCmd, debugCmd, isSandboxApp); } -int32_t AppMgrServiceInner::GetCurrentAccountId() const -{ - std::vector osActiveAccountIds; - ErrCode ret = DelayedSingleton::GetInstance()-> - QueryActiveOsAccountIds(osActiveAccountIds); - if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::APPMGR, "queryActiveOsAccountIds fail"); - return DEFAULT_USER_ID; - } - if (osActiveAccountIds.empty()) { - TAG_LOGE(AAFwkTag::APPMGR, "queryActiveOsAccountIds empty"); - return DEFAULT_USER_ID; - } - TAG_LOGD(AAFwkTag::APPMGR, "osActiveAccountId: %{public}d", osActiveAccountIds.front()); - return osActiveAccountIds.front(); -} - void AppMgrServiceInner::SetRunningSharedBundleList(const std::string &bundleName, const std::vector baseSharedBundleInfoList) { @@ -7748,15 +7743,6 @@ void AppMgrServiceInner::RemoveRunningSharedBundleList(const std::string &bundle runningSharedBundleList_.erase(iterator); } -void AppMgrServiceInner::SetCurrentUserId(const int32_t userId) -{ - if (IPCSkeleton::GetCallingUid() != FOUNDATION_UID) { - return; - } - TAG_LOGD(AAFwkTag::APPMGR, "set current userId: %{public}d", userId); - currentUserId_ = userId; -} - void AppMgrServiceInner::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) { UserRecordManager::GetInstance().SetEnableStartProcessFlagByUserId(userId, enableStartProcess); @@ -8083,8 +8069,9 @@ bool AppMgrServiceInner::CheckIsDebugApp(const std::string &bundleName) CHECK_POINTER_AND_RETURN_VALUE(bundleMgrHelper, false); BundleInfo bundleInfo; + auto userId = UserController::GetInstance().GetCallerUserId(); auto ret = IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(bundleName, - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), bundleInfo, currentUserId_)); + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), bundleInfo, userId)); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::APPMGR, "getBundleInfo fail"); return false; @@ -8334,7 +8321,8 @@ void AppMgrServiceInner::ClearResidentProcessAppRunningData(const std::shared_pt return; } auto userId = GetUserIdByUid(appRecord->GetUid()); - if (appRecord->IsKeepAliveApp() && (userId == 0 || userId == currentUserId_) && + bool isCurentUserId = UserController::GetInstance().IsForegroundUser(userId); + if (appRecord->IsKeepAliveApp() && (userId == 0 || isCurentUserId) && appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { if (!IsNeedRestartKeepAliveProcess(appRecord->GetBundleName(), appRecord->GetUid())) { return; @@ -8379,9 +8367,10 @@ void AppMgrServiceInner::ClearNonResidentKeepAliveAppRunningData(const std::shar } auto userId = GetUserIdByUid(appRecord->GetUid()); + bool isCurentUserId = UserController::GetInstance().IsForegroundUser(userId); bool isDefaultInstance = appRecord->GetInstanceKey().empty() || appRecord->GetInstanceKey() == APP_INSTANCE_KEY_0; if (!appRecord->GetRestartAppFlag() && (appRecord->IsKeepAliveDkv() || appRecord->IsKeepAliveAppService()) && - isDefaultInstance && (userId == 0 || userId == 1 ||userId == currentUserId_) && + isDefaultInstance && (userId == 0 || userId == 1 || isCurentUserId) && appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) { if (ExitResidentProcessManager::GetInstance().IsKilledForUpgradeWeb(appRecord->GetBundleName())) { TAG_LOGI(AAFwkTag::APPMGR, "is killed for upgrade web"); diff --git a/services/appmgr/src/user_record_manager.cpp b/services/appmgr/src/user_record_manager.cpp index 2c56e1a0290794eb744ee640a0c169a412bce683..a1df32577b87ffe6e0742509537f305ea20f8fa6 100644 --- a/services/appmgr/src/user_record_manager.cpp +++ b/services/appmgr/src/user_record_manager.cpp @@ -53,4 +53,4 @@ void UserRecordManager::SetEnableStartProcessFlagByUserId(int32_t userId, bool e } } } // namespace AppExecFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 42fc60e83007eb7a2fcc96842ae771635857bb6b..ea50b34e4dcda17acefa46314c1f7ab027411e08 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -284,6 +284,54 @@ ohos_shared_library("hitrace_chain_util") { "hitrace:libhitracechain", ] + innerapi_tags = [ "platformsdk_indirect" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_shared_library("user_controller") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + include_dirs = [ + "include/user_controller", + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/common/include", + ] + + defines = [] + + sources = [ "src/user_controller/user_controller.cpp" ] + + deps = [ "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", ] + + external_deps = [ + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "ipc:ipc_single", + ] + + if (ability_runtime_graphics) { + defines += [ + "SUPPORT_GRAPHICS", + "SUPPORT_SCREEN", + ] + + deps += [] + external_deps += [ + "window_manager:libdm", + "window_manager:libwsutils", + ] + } + innerapi_tags = [ "platformsdk_indirect" ] subsystem_name = "ability" part_name = "ability_runtime" diff --git a/services/common/include/display_util.h b/services/common/include/display_util.h index eb22fda5f3d69897e2021d4c83be8020b54a2ebe..71c5c4fab332bb58d729da0abb7e8ac506dcfeb1 100644 --- a/services/common/include/display_util.h +++ b/services/common/include/display_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -37,6 +37,18 @@ static inline int32_t GetDefaultDisplayId() } return static_cast(Rosen::DisplayManager::GetInstance().GetDefaultDisplayId()); } + +static inline uint64_t ObtainDefaultDisplayId() +{ + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + sptr display = Rosen::DisplayManager::GetInstance().GetPrimaryDisplaySync(); + if (display != nullptr) { + TAG_LOGI(AAFwkTag::DEFAULT, "displayId: %{public}" PRIu64"", display->GetId()); + return display->GetId(); + } + } + return Rosen::DisplayManager::GetInstance().GetDefaultDisplayId(); +} #endif }; } // namespace AAFwk diff --git a/services/common/include/hilog_tag_wrapper.h b/services/common/include/hilog_tag_wrapper.h index ed76e625613feca3e2298f493030876d007eba99..141383708f183891ffdecc1b1ae2f7940ef7a98b 100644 --- a/services/common/include/hilog_tag_wrapper.h +++ b/services/common/include/hilog_tag_wrapper.h @@ -100,6 +100,7 @@ enum class AAFwkLogTag : uint32_t { SA_INTERCEPTOR, APP_SERVICE_EXT, VERTICAL_PANEL, + USER_CONTROLLER, END = 256, // N.B. never use it }; diff --git a/services/abilitymgr/include/user_event_handler.h b/services/common/include/user_controller/user_controller.h similarity index 30% rename from services/abilitymgr/include/user_event_handler.h rename to services/common/include/user_controller/user_controller.h index 49b53eb9244f0149c8a6525618f4da132a7d2ca7..aad11e185e23052f70559c37b3d78df1eaa7564d 100644 --- a/services/abilitymgr/include/user_event_handler.h +++ b/services/common/include/user_controller/user_controller.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -13,39 +13,57 @@ * limitations under the License. */ -#ifndef OHOS_ABILITY_RUNTIME_USER_EVENT_HANDLER_H -#define OHOS_ABILITY_RUNTIME_USER_EVENT_HANDLER_H +#ifndef OHOS_ABILITY_RUNTIME_USER_CONTROLLER_H +#define OHOS_ABILITY_RUNTIME_USER_CONTROLLER_H -#include +#include +#include -#include "event_handler_wrap.h" +#include "cpp/mutex.h" namespace OHOS { namespace AAFwk { -class UserController; -class UserEventHandler : public EventHandlerWrap { +class IUserCallback; +} +namespace AbilityRuntime { +class UserController final { public: - UserEventHandler( - const std::shared_ptr &taskHandler, const std::weak_ptr &owner); - virtual ~UserEventHandler() = default; - - static constexpr uint32_t EVENT_SYSTEM_USER_START = 10; - static constexpr uint32_t EVENT_SYSTEM_USER_CURRENT = 20; - static constexpr uint32_t EVENT_REPORT_USER_SWITCH = 30; - static constexpr uint32_t EVENT_CONTINUE_USER_SWITCH = 40; - static constexpr uint32_t EVENT_USER_SWITCH_TIMEOUT = 50; - static constexpr uint32_t EVENT_REPORT_USER_SWITCH_DONE = 60; - - /** - * ProcessEvent with request. - * - * @param event, inner event loop. - */ - void ProcessEvent(const EventWrap &event) override; + UserController& operator=(const UserController&) = delete; + UserController(const UserController&) = delete; + virtual ~UserController() = default; + static UserController& GetInstance(); + + int32_t GetForegroundUserId(uint64_t displayId); + void SetForegroundUserId(int32_t userId, uint64_t displayId); + + bool GetDisplayIdByForegroundUserId(int32_t userId, uint64_t &displayId); + + bool IsForegroundUser(int32_t userId); + bool IsForegroundUser(int32_t userId, uint64_t displayId); + + void GetAllForegroundUserId(std::vector &userIds); + + void ClearUserId(int32_t userId); + + int32_t GetCallerUserId(); + + int32_t GetFreezingNewUserId() const; + void SetFreezingNewUserId(int32_t userId); + + bool IsExistOsAccount(int32_t userId) const; + + int32_t CheckStopUserParam(int32_t userId) const; + int32_t CheckUserParam(int32_t userId) const; private: - std::weak_ptr controller_; + UserController() = default; + + ffrt::mutex userLock_; + std::unordered_map displayIdMap_; + ffrt::mutex logoutUserIdLock_; + std::unordered_set logoutUserIdSet_; + int32_t freezingNewUserId_ = -1; }; -} // namespace AAFwk +} // namespace AbilityRuntime } // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_USER_EVENT_HANDLER_H +#endif // OHOS_ABILITY_RUNTIME_USER_CONTROLLER_H \ No newline at end of file diff --git a/services/common/src/user_controller/user_controller.cpp b/services/common/src/user_controller/user_controller.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa83e3b348c9a50c3303512f6a8290ca665c2e52 --- /dev/null +++ b/services/common/src/user_controller/user_controller.cpp @@ -0,0 +1,166 @@ +/* + * 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 "user_controller.h" + +#include + +#include "ability_manager_errors.h" +#include "display_util.h" +#include "hilog_tag_wrapper.h" +#include "ipc_skeleton.h" +#include "os_account_manager_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr int32_t BASE_USER_RANGE = 200000; +constexpr int32_t U0_USER_ID = 0; +constexpr int32_t U1_USER_ID = 1; +constexpr int32_t USER_ID_DEFAULT = 100; +constexpr int32_t ACCOUNT_MGR_SERVICE_UID = 3058; +} +UserController& UserController::GetInstance() +{ + static UserController instance; + return instance; +} + +void UserController::ClearUserId(int32_t userId) +{ + std::lock_guard guard(userLock_); + for (auto iter = displayIdMap_.begin(); iter != displayIdMap_.end();) { + if (iter->second == userId) { + displayIdMap_.erase(iter); + break; + } + } +} + +int32_t UserController::GetForegroundUserId(uint64_t displayId) +{ + std::lock_guard guard(userLock_); + auto iter = displayIdMap_.find(displayId); + if (iter != displayIdMap_.end()) { + return iter->second; + } + return 0; +} + +bool UserController::GetDisplayIdByForegroundUserId(int32_t userId, uint64_t &displayId) +{ + std::lock_guard guard(userLock_); + for (auto &item : displayIdMap_) { + if (item.second == userId) { + displayId = item.first; + return true; + } + } + return false; +} + +bool UserController::IsForegroundUser(int32_t userId) +{ + std::lock_guard guard(userLock_); + for (auto &item : displayIdMap_) { + if (item.second == userId) { + return true; + } + } + return false; +} + +bool UserController::IsForegroundUser(int32_t userId, uint64_t displayId) +{ + int32_t foregroundUserId = GetForegroundUserId(displayId); + if (foregroundUserId == userId) { + return true; + } + TAG_LOGI(AAFwkTag::USER_CONTROLLER, "foregroundUserId:%{public}d", foregroundUserId); + return false; +} + +void UserController::SetForegroundUserId(int32_t userId, uint64_t displayId) +{ + std::lock_guard guard(userLock_); + displayIdMap_[displayId] = userId; +} + +void UserController::GetAllForegroundUserId(std::vector &userIds) +{ + std::lock_guard guard(userLock_); + for (auto &item : displayIdMap_) { + userIds.push_back(item.second); + } +} + +int32_t UserController::GetCallerUserId() +{ + int32_t callerUid = IPCSkeleton::GetCallingUid(); + int32_t callerUser = callerUid / BASE_USER_RANGE; + TAG_LOGD(AAFwkTag::USER_CONTROLLER, "callerUser = %{public}d, CallingUid = %{public}d.", callerUser, callerUid); + if (callerUser == U0_USER_ID || callerUser == U1_USER_ID) { + callerUser = GetForegroundUserId(AAFwk::DisplayUtil::ObtainDefaultDisplayId()); + } + return callerUser; +} + +int32_t UserController::GetFreezingNewUserId() const +{ + return freezingNewUserId_; +} + +void UserController::SetFreezingNewUserId(int32_t userId) +{ + freezingNewUserId_ = userId; +} + +bool UserController::IsExistOsAccount(int32_t userId) const +{ + bool isExist = false; + auto errCode = DelayedSingleton::GetInstance()->IsOsAccountExists(userId, + isExist); + return (errCode == 0) && isExist; +} + +int32_t UserController::CheckStopUserParam(int32_t userId) const +{ + if (userId == USER_ID_DEFAULT) { + TAG_LOGE(AAFwkTag::USER_CONTROLLER, "stopUser invalid:%{public}d", userId); + return AAFwk::INVALID_USERID_VALUE; + } + return CheckUserParam(userId); +} + +int32_t UserController::CheckUserParam(int32_t userId) const +{ + if (userId <= U0_USER_ID) { + TAG_LOGE(AAFwkTag::USER_CONTROLLER, "userId invalid:%{public}d", userId); + return AAFwk::INVALID_USERID_VALUE; + } + + if (IPCSkeleton::GetCallingUid() != ACCOUNT_MGR_SERVICE_UID) { + TAG_LOGE(AAFwkTag::USER_CONTROLLER, "permission verification failed, not account process"); + return AAFwk::CHECK_PERMISSION_FAILED; + } + + if (!IsExistOsAccount(userId)) { + TAG_LOGE(AAFwkTag::USER_CONTROLLER, "userId not exist"); + return AAFwk::INVALID_USERID_VALUE; + } + return ERR_OK; +} +} +} \ No newline at end of file diff --git a/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn index 312685efe456ed9b77399573626fc965820a8826..32ad27048f795046926856af9596cdba1b1bbfe9 100755 --- a/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupservicea_fuzzer/BUILD.gn @@ -56,6 +56,7 @@ ohos_fuzztest("AbilityAutoStartupServiceaFuzzTest") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -82,6 +83,7 @@ ohos_fuzztest("AbilityAutoStartupServiceaFuzzTest") { "relational_store:native_rdb", "safwk:api_cache_manager", "samgr:samgr_proxy", + "window_manager:libwsutils", ] if (ability_runtime_graphics) { diff --git a/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn index c1d52c33e18baac6aa81bb34bae53b33827b2cee..e3b96795bde995afd3235644fb0316ac8677da3a 100755 --- a/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupserviceb_fuzzer/BUILD.gn @@ -56,6 +56,7 @@ ohos_fuzztest("AbilityAutoStartupServicebFuzzTest") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -82,6 +83,8 @@ ohos_fuzztest("AbilityAutoStartupServicebFuzzTest") { "relational_store:native_rdb", "safwk:api_cache_manager", "samgr:samgr_proxy", + "window_manager:libdm", + "window_manager:libwsutils", ] if (ability_runtime_graphics) { diff --git a/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp b/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp index 820752e27f54a68e671c33c571108a447b9470dc..a67243b73393c581cb7000391638ba1f0707b564 100755 --- a/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp +++ b/test/fuzztest/abilityautostartupserviceb_fuzzer/abilityautostartupserviceb_fuzzer.cpp @@ -85,7 +85,6 @@ void AbilityStartupServiceFuzztest1(bool boolParam, std::string &stringParam, in service->GetSelfApplicationBundleName(); service->CheckSelfApplication(stringParam); - service->GetValidUserId(int32Param); AppExecFwk::BundleInfo bundleInfo; service->GetBundleInfo(stringParam, int32Param, int32Param, bundleInfo); // branch AutoStartupInfo info; diff --git a/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn index ab0d1d7be62005e014ec4fc684903222ebd80b59..594ca35651f678788a8b20d3cafd39b0ab3cb559 100644 --- a/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityautostartupservicefirst_fuzzer/BUILD.gn @@ -57,6 +57,7 @@ ohos_fuzztest("AbilityAutoStartupServiceFirstFuzzTest") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -83,6 +84,8 @@ ohos_fuzztest("AbilityAutoStartupServiceFirstFuzzTest") { "relational_store:native_rdb", "safwk:api_cache_manager", "samgr:samgr_proxy", + "window_manager:libdm", + "window_manager:libwsutils", ] if (ability_runtime_graphics) { diff --git a/test/fuzztest/abilitykeepalivedatamanager_fuzzer/BUILD.gn b/test/fuzztest/abilitykeepalivedatamanager_fuzzer/BUILD.gn index f9948ac813b609088f19bc23932b361555c5a294..dfec4853e77a83e91b9d8095147ff803be0edf50 100644 --- a/test/fuzztest/abilitykeepalivedatamanager_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitykeepalivedatamanager_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("AbilityKeepAliveDataManagerFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/abilitykeepaliveservice_fuzzer/BUILD.gn b/test/fuzztest/abilitykeepaliveservice_fuzzer/BUILD.gn index 6255d2f21636262bd9c781c3e1ada2239c2b5097..cdc561d273d00db6f72c4304f5a89ca8e70d0df5 100644 --- a/test/fuzztest/abilitykeepaliveservice_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitykeepaliveservice_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("AbilityKeepAliveServiceFuzzTest") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/abilitymanagereventsubscriber_fuzzer/abilitymanagereventsubscriber_fuzzer.cpp b/test/fuzztest/abilitymanagereventsubscriber_fuzzer/abilitymanagereventsubscriber_fuzzer.cpp index 43238bc7e2c54b04fd18cc6b9dc0ab89d1b717d5..b7b25ad326828fa0a4c0b7405cb96e455dd1c023 100644 --- a/test/fuzztest/abilitymanagereventsubscriber_fuzzer/abilitymanagereventsubscriber_fuzzer.cpp +++ b/test/fuzztest/abilitymanagereventsubscriber_fuzzer/abilitymanagereventsubscriber_fuzzer.cpp @@ -36,7 +36,7 @@ bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp) sptr eventData = EventFwk::CommonEventData::Unmarshalling(parcel); EventFwk::CommonEventSubscribeInfo subscribeInfo; - std::function callback; + std::function callback; std::function userScreenUnlockCallback; auto abilityManagerEventSubscriber = std::make_shared (subscribeInfo, callback, userScreenUnlockCallback); diff --git a/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp b/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp index 61dd7800ee8c7ea07ab9739164c8efa54035f931..caeddfac2c4d0f93ab84e24d1e5df0b5906ee7c0 100755 --- a/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp +++ b/test/fuzztest/abilitymanagerservicefourth_fuzzer/abilitymanagerservicefourth_fuzzer.cpp @@ -66,7 +66,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) AppExecFwk::AbilityInfo abilityInfo; abilityms->JudgeAbilityVisibleControl(abilityInfo); sptr callback; - abilityms->StartUser(intParam, callback); + abilityms->StartUser(intParam, 0, callback); abilityms->StopUser(intParam, callback); abilityms->OnAcceptWantResponse(*want, stringParam, 0); abilityms->OnStartSpecifiedAbilityTimeoutResponse(0); diff --git a/test/fuzztest/abilitymanagerservicesixth_fuzzer/abilitymanagerservicesixth_fuzzer.cpp b/test/fuzztest/abilitymanagerservicesixth_fuzzer/abilitymanagerservicesixth_fuzzer.cpp index a47343fac8f8f74c5bc4787cc94cadabe04bb3d7..4b1890151dfc6c36a77b09db96ff59e377b6cfc4 100755 --- a/test/fuzztest/abilitymanagerservicesixth_fuzzer/abilitymanagerservicesixth_fuzzer.cpp +++ b/test/fuzztest/abilitymanagerservicesixth_fuzzer/abilitymanagerservicesixth_fuzzer.cpp @@ -79,7 +79,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) // fuzz for AbilityManagerService auto abilityms = std::make_shared(); abilityms->GetEventHandler(); - abilityms->GetUserId(); AbilityRequest request; abilityms->GenerateAbilityRequest(*want, intParam, request, token, int32Param); abilityms->GenerateExtensionAbilityRequest(*want, request, token, int32Param); diff --git a/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/BUILD.gn index b9515b6872dcdc63eec8bd54034e54a96abfb386..21fdc4596c80409b7e8e9c72a535de5b5097a618 100644 --- a/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerEighteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagereighth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagereighth_fuzzer/BUILD.gn index cb815bf317c08e6b1856483dc0732699b0c9acf9..c40fb532933554302d7a302e98547d6012d85835 100644 --- a/test/fuzztest/keepaliveprocessmanagereighth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagereighth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerEighthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagereleventh_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagereleventh_fuzzer/BUILD.gn index 32bf75cdd8142e7aa97b2b34102414583dc7a930..809e6853865e0532f321d0d795b7ac42d4ea3c30 100644 --- a/test/fuzztest/keepaliveprocessmanagereleventh_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagereleventh_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerEleventhFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerfifteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerfifteenth_fuzzer/BUILD.gn index 65582f901a0267bba6fc6a577ab3981385891604..87fb87da196b7194613d4b9c2ccd310b4a289ab3 100644 --- a/test/fuzztest/keepaliveprocessmanagerfifteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerfifteenth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerFifteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerfifth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerfifth_fuzzer/BUILD.gn index e2e99632a7ae0e63eb819fa58ecdab4b03602b3c..bfc9b0082eca425cc9442a8260d299fe11ca5343 100644 --- a/test/fuzztest/keepaliveprocessmanagerfifth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerfifth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerFifthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerfirst_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerfirst_fuzzer/BUILD.gn index 24974375c8faf08feaee40907b11303df08dad8a..9736f521b871c06c09774fa336a6544393f6db7d 100644 --- a/test/fuzztest/keepaliveprocessmanagerfirst_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerfirst_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerFirstFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerfourteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerfourteenth_fuzzer/BUILD.gn index 63f9807a935a2de52885760d4ce643ca351c153f..c9271fd63591f974c29ae73ea31a1f3fcf3fa8df 100644 --- a/test/fuzztest/keepaliveprocessmanagerfourteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerfourteenth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerFourteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerfourth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerfourth_fuzzer/BUILD.gn index 52e0e169eaad7ff2fa3e3b135b96fa9b22315a64..5c40daa53cb44dd8d2060d19f792c7effd5c2cd9 100644 --- a/test/fuzztest/keepaliveprocessmanagerfourth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerfourth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerFourthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerninteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerninteenth_fuzzer/BUILD.gn index 64d20fa7d020a34a9a08955ba8516c21ed590668..82c7bb58bfaf7b7093a322608104429f867e2fd4 100644 --- a/test/fuzztest/keepaliveprocessmanagerninteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerninteenth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerNinteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerninth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerninth_fuzzer/BUILD.gn index 39fdca3deac74fe1a7c5ad0267fbeebe536cc77a..23ea702923d78e4f01be8d594b020526733a723a 100644 --- a/test/fuzztest/keepaliveprocessmanagerninth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerninth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerNinthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagersecond_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagersecond_fuzzer/BUILD.gn index 2b2d2d882a1c644cd893c1bda7337113d8a067a6..19c3b88f7751b6ca04a4d9661944774e9b0ac9e8 100644 --- a/test/fuzztest/keepaliveprocessmanagersecond_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagersecond_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerSecondFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerseventeenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerseventeenth_fuzzer/BUILD.gn index 59b08590d335e5aa2b136cde8ee9336b6e51e676..cf9a515f3fcf9b4c613aeb07052c43618c6f1dbd 100644 --- a/test/fuzztest/keepaliveprocessmanagerseventeenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerseventeenth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerSeventeenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerseventh_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerseventh_fuzzer/BUILD.gn index a90f941ce083976df89de502aa2dad9c42ad6305..aeac0fc7a15417f0a00c4f6858f47264d12a3bd1 100644 --- a/test/fuzztest/keepaliveprocessmanagerseventh_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerseventh_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerSeventhFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagersixteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagersixteenth_fuzzer/BUILD.gn index f4ec5bf813b6dfbe6075bd856a8153a69e7ec01b..71194513391e5a8a7376bd2107a50c9bc83c747b 100644 --- a/test/fuzztest/keepaliveprocessmanagersixteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagersixteenth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerSixteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagersixth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagersixth_fuzzer/BUILD.gn index 48c3944b2778d46992cbb1d5f79374703787f3d2..45e43404cc87fe2218dfa8f36ae0cb616b010b85 100644 --- a/test/fuzztest/keepaliveprocessmanagersixth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagersixth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerSixthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagertenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagertenth_fuzzer/BUILD.gn index 97b82a07142f29e4087a2eeb7792a3320e264392..593d63355787a9e3263633aa36d7466e1bdd4880 100644 --- a/test/fuzztest/keepaliveprocessmanagertenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagertenth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerTenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerthird_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerthird_fuzzer/BUILD.gn index 7196e59e83a7ace5b5e95782c1bb2393357b861f..f723d51184d8f499a61056aa9817b5cfd75daaea 100644 --- a/test/fuzztest/keepaliveprocessmanagerthird_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerthird_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerThirdFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagerthirteenth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagerthirteenth_fuzzer/BUILD.gn index 0bccb3b546e3fa09ad7016ae75e62025581196f7..eb07b8bcb78fb37fbe88f63714e2300313654b4a 100644 --- a/test/fuzztest/keepaliveprocessmanagerthirteenth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagerthirteenth_fuzzer/BUILD.gn @@ -67,6 +67,7 @@ ohos_fuzztest("KeepAliveProcessManagerThirteenthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/keepaliveprocessmanagertwelfth_fuzzer/BUILD.gn b/test/fuzztest/keepaliveprocessmanagertwelfth_fuzzer/BUILD.gn index 759511eb962f3d0cf25e10b0622f1ba166846bc3..4772c87de8b2289a12cfd275a0a6840e0dec7884 100644 --- a/test/fuzztest/keepaliveprocessmanagertwelfth_fuzzer/BUILD.gn +++ b/test/fuzztest/keepaliveprocessmanagertwelfth_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("KeepAliveProcessManagerTwelfthFuzzTest") { "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:record_cost_time_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/fuzztest/startuser_fuzzer/startuser_fuzzer.cpp b/test/fuzztest/startuser_fuzzer/startuser_fuzzer.cpp index 4c9cc15bbb7e0ceb54339adc403c6bba85707c94..a4b308cac0c01c0372d5d8a8b753efcd00e2931c 100644 --- a/test/fuzztest/startuser_fuzzer/startuser_fuzzer.cpp +++ b/test/fuzztest/startuser_fuzzer/startuser_fuzzer.cpp @@ -42,7 +42,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) int accountId = static_cast(GetU32Data(data)); sptr callback; - abilitymgr->StartUser(accountId, callback); + abilitymgr->StartUser(accountId, 0, callback); return true; } diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp index 9fddcdfc1cc0bb5582305161e308a59e65b10eb0..8eb2af62769321c3c3ad0dabdc9665b189f9f9f4 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp @@ -326,14 +326,15 @@ ErrCode AbilityManagerClient::StopSyncRemoteMissions(const std::string& devId) return abms->StopSyncRemoteMissions(devId); } -ErrCode AbilityManagerClient::StartUser(int accountId, sptr callback, bool isAppRecovery) +ErrCode AbilityManagerClient::StartUser(int accountId, uint64_t displayId, sptr callback, + bool isAppRecovery) { if (g_remoteObject == nullptr) { return ABILITY_SERVICE_NOT_CONNECTED; } sptr abms = iface_cast(g_remoteObject); - return abms->StartUser(accountId, callback); + return abms->StartUser(accountId, displayId, callback); } ErrCode AbilityManagerClient::StopUser(int accountId, sptr callback) diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index 89299aada1bd577ac39976bf5289ea28e376bd74..e731850ebaaf3cc96b1c49fdd07299af60205d1e 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -208,7 +208,7 @@ public: return 0; } - int StartUser(int accountId, sptr callback, bool isAppRecovery) + int StartUser(int accountId, uint64_t displayId, sptr callback, bool isAppRecovery) { return 0; } diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index dd7fe95a1495a3e013f780164891d3afff3030c8..4137df30ef01a361ea5708ac864c9ce263fb4671 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -173,7 +173,7 @@ public: int UninstallApp(const std::string& bundleName, int32_t uid) override; - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp index 127ea466c0af146f0c91b014624e1c00966e999a..b9f0168fda6a2d39d3312e2b33eff1f9455fb0a3 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp @@ -60,7 +60,8 @@ void MockAbilityDelegatorStub::DumpState(const std::string& args, std::vector callback, bool isAppRecovery) +int MockAbilityDelegatorStub::StartUser(int userId, uint64_t displayId, sptr callback, + bool isAppRecovery) { return 0; } @@ -253,7 +254,8 @@ int MockAbilityDelegatorStub2::StopServiceAbility(const Want& want, int32_t user return 0; } -int MockAbilityDelegatorStub2::StartUser(int userId, sptr callback, bool isAppRecovery) +int MockAbilityDelegatorStub2::StartUser(int userId, uint64_t displayId, sptr callback, + bool isAppRecovery) { return 0; } diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index 7d1d71c42446b68dbbf2fc853d6cd3e1fb4e35ab..3cb74a269251e494b74fb897f8716d89df658ea5 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -125,7 +125,7 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); MOCK_METHOD2(SetMissionContinueState, int(const sptr& token, const AAFwk::ContinueState& state)); - int StartUser(int userId, sptr callback, bool isAppRecovery) override; + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override; int StopUser(int userId, const sptr& callback) override; int LogoutUser(int32_t userId, sptr callback = nullptr) override; int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; @@ -306,7 +306,7 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); MOCK_METHOD2(SetMissionContinueState, int(const sptr& token, const AAFwk::ContinueState& state)); - int StartUser(int userId, sptr callback, bool isAppRecovery) override; + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override; int StopUser(int userId, const sptr& callback) override; int LogoutUser(int32_t userId, sptr callback = nullptr) override; int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index 3fb4002e1041dc3728952ad13cb6a64cc3dea46b..44f19bf59acf2ab9891768ae00c682cb9bec61af 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -165,7 +165,7 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index 2f54869dfb90dfd60f8880d7aaf69002fbc98a48..0531d96b543a546046e716fbdd4b4df23c5b27e4 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -179,7 +179,7 @@ public: return 0; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h b/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h index 4682b9fb078deff882dfdf70785d5104cb832644..468a9e3580dac2bed7db5c6c5f540b46ee2d0669 100644 --- a/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h +++ b/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h @@ -289,7 +289,7 @@ public: { return 0; } - int StartUser(int userId, sptr callback, bool isAppRecovery = false) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery = false) override { return 0; } diff --git a/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp b/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp index 3b1167e5522e77ba4a0239665185d8d434d390d0..fad5325e4eab477d4512c27a43360468f17294bf 100644 --- a/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp +++ b/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp @@ -138,18 +138,11 @@ void AbilityTimeoutModuleTest::MockOnStart() abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); EXPECT_TRUE(abilityMs_->taskHandler_); - // init user controller. - abilityMs_->userController_ = std::make_shared(); - EXPECT_TRUE(abilityMs_->userController_); - abilityMs_->userController_->Init(); - AmsConfigurationParameter::GetInstance().Parse(); abilityMs_->subManagersHelper_ = std::make_shared(nullptr, nullptr); abilityMs_->subManagersHelper_->InitSubManagers(MOCK_MAIN_USER_ID, true); abilityMs_->SwitchManagers(MOCK_U0_USER_ID, false); - abilityMs_->userController_->SetCurrentUserId(MOCK_MAIN_USER_ID); - abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; abilityMs_->iBundleManager_ = new BundleMgrService(); @@ -174,7 +167,6 @@ void AbilityTimeoutModuleTest::MockOnStop() abilityMs_->subManagersHelper_->currentPendingWantManager_.reset(); abilityMs_->subManagersHelper_->missionListManagers_.clear(); abilityMs_->subManagersHelper_->currentMissionListManager_.reset(); - abilityMs_->userController_.reset(); abilityMs_->abilityController_.clear(); abilityMs_->OnStop(); } @@ -320,7 +312,6 @@ HWTEST_F(AbilityTimeoutModuleTest, OnAbilityDied_001, TestSize.Level1) EXPECT_EQ(rootLauncher, ability); EXPECT_TRUE(rootLauncher->IsLauncherRoot()); - GTEST_LOG_(INFO) << "userId:" << abilityMs_->GetUserId(); GTEST_LOG_(INFO) << "currentmanager userId" << curListManager->userId_; // died rootlauncher ability diff --git a/test/moduletest/common/ams/BUILD.gn b/test/moduletest/common/ams/BUILD.gn index fcff77e2efed240514302ee00aec55a603ac7750..1ca2625d8a2e1daf4f6e008bb4d33b83c0e5667b 100644 --- a/test/moduletest/common/ams/BUILD.gn +++ b/test/moduletest/common/ams/BUILD.gn @@ -65,6 +65,7 @@ ohos_source_set("appmgr_mst_source") { "init:libbegetutil", "ipc:ipc_core", "json:nlohmann_json_static", + "window_manager:libwsutils", ] public_external_deps = [ diff --git a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn index 60e8956a96764dcb14f918c93c90bda1fb361297..41aeac608c45f508539d2fe234576689ca7cc105 100644 --- a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn +++ b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn @@ -33,6 +33,7 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -55,6 +56,7 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") { if (ability_runtime_graphics) { external_deps += [ + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn index 245d98c4f01a3da300b8bb9f24525061e733bd44..2cf0fe1553f031d7e072cea6c8d8ac55b1193a14 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn +++ b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -66,6 +67,7 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { if (ability_runtime_graphics) { external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", ] } diff --git a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn index d1fbca3d6f0673e7959e68b7a23c42e914eac62d..d6b441d83730c3fef4a949d6ad0c601e30f5f3ba 100644 --- a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn +++ b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_moduletest("AmsAppRecentListModuleTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn index 9a41ae9d754efba4dbb591d1947e5989afbfd2ed..e1e11e547cc2a9938554e6de499c2870a48b5e98 100644 --- a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn +++ b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn @@ -38,6 +38,7 @@ ohos_moduletest("AmsAppServiceFlowModuleTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] diff --git a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn index effd5e6d6f74f418b0f2c0fb2486a8dae20d365f..effbcf849d9301ef82a866c60404b7c07805241a 100644 --- a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn @@ -44,6 +44,7 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -67,7 +68,10 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libdm", + "window_manager:libwm", + ] } if (background_task_mgr_continuous_task_enable) { diff --git a/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn b/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn index 9689d74f1b51e057bcf9901c1a73c784eaa08071..3f08a5282f9f7e85cf1f4694f804c12c38fa71ef 100644 --- a/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_app_mgr_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_moduletest("AmsIpcAppmgrModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -60,6 +61,7 @@ ohos_moduletest("AmsIpcAppmgrModuleTest") { "memory_utils:libmeminfo", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn b/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn index 8f3185e86e175ca71316cc958ecd36a4461ccb6a..969354cc20025199119f600b88654196fc93603a 100644 --- a/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_app_scheduler_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_moduletest("AmsIpcAppSchedulerModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -60,6 +61,7 @@ ohos_moduletest("AmsIpcAppSchedulerModuleTest") { "memory_utils:libmeminfo", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/moduletest/common/ams/service_start_process_test/BUILD.gn b/test/moduletest/common/ams/service_start_process_test/BUILD.gn index 92bf5be75cb7dfd5f0b6551e1a865cef4949f0fe..4f4897ba1df8c90faf0b1c7d1f1c7b885cf01630 100644 --- a/test/moduletest/common/ams/service_start_process_test/BUILD.gn +++ b/test/moduletest/common/ams/service_start_process_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_moduletest("AmsServiceStartModuleTest") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -54,6 +55,7 @@ ohos_moduletest("AmsServiceStartModuleTest") { if (ability_runtime_graphics) { external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", ] } diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index 9f9438d17596815f858047a001e41515cdcdbc8c..2aa5fe0bae265e0711726837abcbe09e934850e6 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -130,7 +130,7 @@ public: return 0; } - virtual int StartUser(int userId, sptr callback, bool isAppRecovery) override + virtual int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/moduletest/running_infos_module_test/running_infos_module_test.cpp b/test/moduletest/running_infos_module_test/running_infos_module_test.cpp index 82cb2a1de86dcbbe81b7f9aad2658b087be196de..dbd0f9735083e2f7464f0b113176dfb7b0018c55 100644 --- a/test/moduletest/running_infos_module_test/running_infos_module_test.cpp +++ b/test/moduletest/running_infos_module_test/running_infos_module_test.cpp @@ -116,13 +116,6 @@ void RunningInfosModuleTest::OnStartAms() abilityMgrServ_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); EXPECT_TRUE(abilityMgrServ_->taskHandler_); - // init user controller. - abilityMgrServ_->userController_ = std::make_shared(); - EXPECT_TRUE(abilityMgrServ_->userController_); - abilityMgrServ_->userController_->Init(); - int userId = MOCK_MAIN_USER_ID; - abilityMgrServ_->userController_->SetCurrentUserId(userId); - AmsConfigurationParameter::GetInstance().Parse(); abilityMgrServ_->interceptorExecuter_ = std::make_shared(); diff --git a/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp b/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp index 4b554b108b44b48033cc807a618b72a92363a7dd..2c8c3a3a8b3967223bc0809fd19d33c06f2e92e5 100644 --- a/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp +++ b/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp @@ -30,6 +30,7 @@ #include "system_ability_definition.h" #include "ui_service_mgr_client_mock.h" #include "mission_list_manager.h" +#include "user_controller/user_controller.h" using namespace testing; using namespace testing::ext; @@ -87,10 +88,6 @@ void StartAbilityImplicitModuleTest::OnStartAms() const abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler("StartAbilityImplicitModuleTest"); - // init user controller. - abilityMs_->userController_ = std::make_shared(); - EXPECT_TRUE(abilityMs_->userController_); - abilityMs_->userController_->Init(); abilityMs_->subManagersHelper_ = std::make_shared(nullptr, nullptr); abilityMs_->subManagersHelper_->InitSubManagers(MOCK_MAIN_USER_ID, true); @@ -105,7 +102,7 @@ void StartAbilityImplicitModuleTest::OnStartAms() const DelayedSingleton::GetInstance()->SetDeviceType("phone"); abilityMs_->SwitchManagers(0, false); - abilityMs_->userController_->SetCurrentUserId(MOCK_MAIN_USER_ID); + AbilityRuntime::UserController::GetInstance().SetForegroundUserId(MOCK_MAIN_USER_ID, 0); return; } diff --git a/test/new_test/mock/ability_manager_service/ability_manager_service.h b/test/new_test/mock/ability_manager_service/ability_manager_service.h index da6132073630a0df214bd2b917ca988129d6e2f8..a7315a46a1e959de0a26e2f7ea5bd58994628f5a 100644 --- a/test/new_test/mock/ability_manager_service/ability_manager_service.h +++ b/test/new_test/mock/ability_manager_service/ability_manager_service.h @@ -45,7 +45,7 @@ public: void StopFreezingScreen() {} void UserStarted(int32_t userId) {} - OH_MOCK_METHOD(int, AbilityManagerService, SwitchToUser, int32_t, int32_t, + OH_MOCK_METHOD(int, AbilityManagerService, SwitchToUser, int32_t, int32_t, uint64_t, sptr, bool isAppRecovery = false); void ClearUserData(int32_t userId) {} }; diff --git a/test/new_test/mock/app_scheduler/app_scheduler.h b/test/new_test/mock/app_scheduler/app_scheduler.h index 156ff64e732ea798475c2e27d3e489d4b03cd472..b4920ec76de3938a01fbe20b3be1551b0b63584d 100644 --- a/test/new_test/mock/app_scheduler/app_scheduler.h +++ b/test/new_test/mock/app_scheduler/app_scheduler.h @@ -125,12 +125,8 @@ public: return false; } - void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) {} - void KillProcessesByUserId(int32_t userId, bool isNeedSendAppSpawnMsg = false, sptr callback = nullptr) {} - - void SetCurrentUserId(int32_t userId) {} }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/user_event_handler.cpp b/test/new_test/mock/dispaly_util/display_util.h similarity index 58% rename from services/abilitymgr/src/user_event_handler.cpp rename to test/new_test/mock/dispaly_util/display_util.h index 416b02f11ddbe3b7e757b290f566244582167476..cd0d94d2cf390d15dda512880b6eff035bb4b190 100644 --- a/services/abilitymgr/src/user_event_handler.cpp +++ b/test/new_test/mock/dispaly_util/display_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -13,24 +13,24 @@ * limitations under the License. */ -#include "user_event_handler.h" +#ifndef OHOS_ABILITY_RUNTIME_DISPLAY_UTIL_H +#define OHOS_ABILITY_RUNTIME_DISPLAY_UTIL_H -#include "user_controller.h" +#include "refbase.h" namespace OHOS { namespace AAFwk { -UserEventHandler::UserEventHandler( - const std::shared_ptr &taskHandler, const std::weak_ptr &owner) - : EventHandlerWrap(taskHandler), controller_(owner) +namespace DisplayUtil { +static inline int32_t GetDefaultDisplayId() { + return 0; } -void UserEventHandler::ProcessEvent(const EventWrap &event) +static inline uint64_t ObtainDefaultDisplayId() { - auto owner = controller_.lock(); - if (owner) { - owner->ProcessEvent(event); - } + return 0; +} } } // namespace AAFwk } // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DISPLAY_UTIL_H \ No newline at end of file diff --git a/test/new_test/mock/hilog_tag_wrapper/hilog_tag_wrapper.h b/test/new_test/mock/hilog_tag_wrapper/hilog_tag_wrapper.h index 9d577ef3055423e24f67d4e7317eb15d3a00f9d2..a95fabbb6beb518e0dbbc40f70393331820119c3 100644 --- a/test/new_test/mock/hilog_tag_wrapper/hilog_tag_wrapper.h +++ b/test/new_test/mock/hilog_tag_wrapper/hilog_tag_wrapper.h @@ -95,6 +95,7 @@ enum class AAFwkLogTag : uint32_t { QUERY_ERMS, LOCAL_CALL = DEFAULT + 0x60, // 0xD001360 + USER_CONTROLLER, END = 256, // N.B. never use it }; diff --git a/test/new_test/mock/user_event_handler/user_event_handler.h b/test/new_test/mock/ipc_skeleton/ipc_skeleton.h similarity index 41% rename from test/new_test/mock/user_event_handler/user_event_handler.h rename to test/new_test/mock/ipc_skeleton/ipc_skeleton.h index e41e001bb5ec45c0371957e33ca9b8f0cf7cdb94..cb0838f3ce72620bcd741eb10dd2d583615dc54b 100644 --- a/test/new_test/mock/user_event_handler/user_event_handler.h +++ b/test/new_test/mock/ipc_skeleton/ipc_skeleton.h @@ -13,32 +13,21 @@ * limitations under the License. */ -#ifndef OHOS_ABILITY_RUNTIME_USER_EVENT_HANDLER_H -#define OHOS_ABILITY_RUNTIME_USER_EVENT_HANDLER_H +#ifndef OHOS_ABILITY_RUNTIME_IPC_SKELETON_H +#define OHOS_ABILITY_RUNTIME_IPC_SKELETON_H -#include - -#include "event_handler_wrap.h" +#include "refbase.h" namespace OHOS { -namespace AAFwk { -class UserController; -class UserEventHandler : public EventHandlerWrap { +class IPCSkeleton { public: - UserEventHandler( - const std::shared_ptr &taskHandler, const std::weak_ptr &owner) {} - - virtual ~UserEventHandler() {} - - static constexpr uint32_t EVENT_SYSTEM_USER_START = 10; - static constexpr uint32_t EVENT_SYSTEM_USER_CURRENT = 20; - static constexpr uint32_t EVENT_REPORT_USER_SWITCH = 30; - static constexpr uint32_t EVENT_CONTINUE_USER_SWITCH = 40; - static constexpr uint32_t EVENT_USER_SWITCH_TIMEOUT = 50; - static constexpr uint32_t EVENT_REPORT_USER_SWITCH_DONE = 60; + IPCSkeleton() = default; + ~IPCSkeleton() = default; - void ProcessEvent(const EventWrap &event) override {} + static int32_t GetCallingUid() + { + return 0; + } }; -} // namespace AAFwk } // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_USER_EVENT_HANDLER_H +#endif // OHOS_ABILITY_RUNTIME_IPC_SKELETON_H \ No newline at end of file diff --git a/test/new_test/unit_test/user_controller_unit_test/BUILD.gn b/test/new_test/unit_test/user_controller_unit_test/BUILD.gn index d7c3f2d7c81248371e1c4f6236dc3f2176b5e11c..098147631dc404dc18f8408dc6cf7726cdf7d1c1 100644 --- a/test/new_test/unit_test/user_controller_unit_test/BUILD.gn +++ b/test/new_test/unit_test/user_controller_unit_test/BUILD.gn @@ -18,17 +18,17 @@ module_output_path = "ability_runtime/user_controller" copy("user_controller_copy") { sources = [ - "${ability_runtime_path}/services/abilitymgr/include/user_controller.h", - "${ability_runtime_path}/services/abilitymgr/src/user_controller.cpp", + "${ability_runtime_path}/services/common/include/user_controller/user_controller.h", + "${ability_runtime_path}/services/common/src/user_controller/user_controller.cpp", ] - outputs = [ "${target_gen_dir}/services/abilitymgr/src/user_controller/{{source_file_part}}" ] + outputs = [ "${target_gen_dir}/services/common/src/user_controller/{{source_file_part}}" ] } ohos_unittest("user_controller_unit_test") { module_out_path = module_output_path include_dirs = [ - "${target_gen_dir}/services/abilitymgr/src/user_controller", + "${target_gen_dir}/services/common/src/user_controller", "../../mock_utils", "../../mock/ability_info", "../../mock/ability_manager_errors", @@ -40,10 +40,12 @@ ohos_unittest("user_controller_unit_test") { "../../mock/application_info", "../../mock/bundle_info", "../../mock/configuration", + "../../mock/dispaly_util", "../../mock/element_name", "../../mock/event_handler_wrap", "../../mock/extension_ability_info", "../../mock/hilog_tag_wrapper", + "../../mock/ipc_skeleton", "../../mock/iremote_broker", "../../mock/iremote_object", "../../mock/last_exit_detail_info", @@ -59,14 +61,13 @@ ohos_unittest("user_controller_unit_test") { "../../mock/task_handler_wrap", "../../mock/task_utils_wrap", "../../mock/uri", - "../../mock/user_event_handler", "../../mock/user_callback", "../../mock/want", "../../mock/want_params", ] sources = - [ "${target_gen_dir}/services/abilitymgr/src/user_controller/user_controller.cpp" ] + [ "${target_gen_dir}/services/common/src/user_controller/user_controller.cpp" ] sources += [ "user_controller_unit_test.cpp", diff --git a/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp b/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp index 1ca61ede91122cd51b7561498bb698ad939b6d38..c782d7aa1bf67663f84a4ce47cb5fb43e1189577 100644 --- a/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp +++ b/test/new_test/unit_test/user_controller_unit_test/user_controller_unit_test.cpp @@ -31,7 +31,7 @@ using namespace testing::ext; namespace OHOS { -namespace AppExecFwk { +namespace AbilityRuntime { class UserControllerTest : public testing::Test { public: static void SetUpTestCase(); @@ -40,854 +40,10 @@ public: void TearDown() override; }; -void UserControllerTest::SetUpTestCase() -{} - -void UserControllerTest::TearDownTestCase() -{} - -void UserControllerTest::SetUp() -{} - -void UserControllerTest::TearDown() -{} - -/** - * @tc.name: UserItem_GetUserId_001 - * @tc.desc: Verify UserItem GetUserId call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserItem_GetUserId_001, TestSize.Level1) -{ - int32_t expectUserId = 101; - std::shared_ptr userItem = std::make_shared(expectUserId); - EXPECT_EQ(userItem->GetUserId(), expectUserId); -} - -/** - * @tc.name: UserItem_SetState_001 - * @tc.desc: Verify UserItem SetState call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserItem_SetState_001, TestSize.Level1) -{ - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(userState); - EXPECT_EQ(userItem->curState_, AAFwk::UserState::STATE_BOOTING); - EXPECT_EQ(userItem->lastState_, AAFwk::UserState::STATE_BOOTING); -} - -/** - * @tc.name: UserItem_SetState_002 - * @tc.desc: Verify UserItem SetState call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserItem_SetState_002, TestSize.Level1) -{ - AAFwk::UserState userState = AAFwk::UserState::STATE_STARTED; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(userState); - EXPECT_EQ(userItem->curState_, AAFwk::UserState::STATE_STARTED); - EXPECT_EQ(userItem->lastState_, AAFwk::UserState::STATE_BOOTING); -} - -/** - * @tc.name: UserItem_GetState_001 - * @tc.desc: Verify UserItem GetState call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserItem_GetState_001, TestSize.Level1) -{ - AAFwk::UserState userState = AAFwk::UserState::STATE_STARTED; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(userState); - EXPECT_EQ(userItem->GetState(), AAFwk::UserState::STATE_STARTED); -} - -/** - * @tc.name: Init_001 - * @tc.desc: Verify Init call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, Init_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr handler = nullptr; - OH_EXPECT_RET({handler}, AbilityManagerService, GetTaskHandler); - controller->Init(); - EXPECT_EQ(controller->eventHandler_, nullptr); -} - -/** - * @tc.name: Init_002 - * @tc.desc: Verify Init call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, Init_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr handler = std::make_shared(); - OH_EXPECT_RET({handler}, AbilityManagerService, GetTaskHandler); - controller->Init(); - EXPECT_NE(controller->eventHandler_, nullptr); -} - -/** - * @tc.name: Init_003 - * @tc.desc: Verify Init call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, Init_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr handler = std::make_shared(); - OH_EXPECT_RET({handler}, AbilityManagerService, GetTaskHandler); - controller->eventHandler_ = std::make_shared(handler, controller); - controller->Init(); - EXPECT_NE(controller->eventHandler_, nullptr); -} - -/** - * @tc.name: ClearAbilityUserItems_001 - * @tc.desc: Verify ClearAbilityUserItems call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ClearAbilityUserItems_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({0, userItem}); - controller->ClearAbilityUserItems(0); - EXPECT_EQ(controller->userItems_.size(), 0); -} - -/** - * @tc.name: ClearAbilityUserItems_002 - * @tc.desc: Verify ClearAbilityUserItems call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ClearAbilityUserItems_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({0, userItem}); - controller->ClearAbilityUserItems(1); - EXPECT_EQ(controller->userItems_.size(), 1); -} - -/** - * @tc.name: StartUser_001 - * @tc.desc: Verify StartUser call. - * Branch userId < 0 && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = -1; - sptr callback = nullptr; - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_002 - * @tc.desc: Verify StartUser call. - * Branch userId < 0 && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = -1; - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_003 - * @tc.desc: Verify StartUser call. - * Branch userId == USER_ID_NO_HEAD && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_NO_HEAD; - sptr callback = nullptr; - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_004 - * @tc.desc: Verify StartUser call. - * Branch userId == USER_ID_NO_HEAD && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_NO_HEAD; - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_005 - * @tc.desc: Verify StartUser call. - * Branch IsCurrentUser == true && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_005, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 101; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); - sptr callback = nullptr; - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); -} - -/** - * @tc.name: StartUser_006 - * @tc.desc: Verify StartUser call. - * Branch IsCurrentUser == true && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_006, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 101; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); -} - -/** - * @tc.name: StartUser_007 - * @tc.desc: Verify StartUser call. - * Branch IsExistOsAccount == false && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_007, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); - sptr callback = nullptr; - bool isAppRecovery = 0; - std::vector> expectOuter = {{false}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_008 - * @tc.desc: Verify StartUser call. - * Branch IsExistOsAccount == false && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_008, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({101, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{false}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartUser_009 - * @tc.desc: Verify StartUser call. - * Branch GetCurrentUserId() != USER_ID_NO_HEAD && IsSceneBoardEnabled() == false - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_009, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - controller->freezingNewUserId_ = 0; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); - EXPECT_EQ(controller->freezingNewUserId_, 101); -} - -/** - * @tc.name: StartUser_010 - * @tc.desc: Verify StartUser call. - * Branch GetCurrentUserId() == USER_ID_NO_HEAD && IsSceneBoardEnabled() == false - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_010, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 0; - controller->freezingNewUserId_ = 0; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); - EXPECT_EQ(controller->freezingNewUserId_, 0); -} - -/** - * @tc.name: StartUser_011 - * @tc.desc: Verify StartUser call. - * Branch GetCurrentUserId() != USER_ID_NO_HEAD && IsSceneBoardEnabled() == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_011, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - controller->freezingNewUserId_ = 0; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); - EXPECT_EQ(controller->freezingNewUserId_, 0); -} - -/** - * @tc.name: StartUser_012 - * @tc.desc: Verify StartUser call. - * Branch GetCurrentUserId() == USER_ID_NO_HEAD && IsSceneBoardEnabled() == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_012, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 0; - controller->freezingNewUserId_ = 0; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_OK); - EXPECT_EQ(controller->freezingNewUserId_, 0); -} - -/** - * @tc.name: StartUser_013 - * @tc.desc: Verify StartUser call. - * Branch state == STATE_STOPPING && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_013, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(AAFwk::STATE_STOPPING); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); -} - -/** - * @tc.name: StartUser_014 - * @tc.desc: Verify StartUser call. - * Branch state == STATE_STOPPING && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_014, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(AAFwk::STATE_STOPPING); - controller->userItems_.insert({userId, userItem}); - sptr callback = nullptr; - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); -} - -/** - * @tc.name: StartUser_015 - * @tc.desc: Verify StartUser call. - * Branch state == STATE_SHUTDOWN && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_015, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(AAFwk::STATE_SHUTDOWN); - controller->userItems_.insert({userId, userItem}); - sptr callback = sptr::MakeSptr(); - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); -} - -/** - * @tc.name: StartUser_016 - * @tc.desc: Verify StartUser call. - * Branch state == STATE_SHUTDOWN && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_016, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(AAFwk::STATE_SHUTDOWN); - controller->userItems_.insert({userId, userItem}); - sptr callback = nullptr; - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); -} - -/** - * @tc.name: StartUser_017 - * @tc.desc: Verify StartUser call. - * Branch state == STATE_BOOTING - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StartUser_017, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - userItem->SetState(AAFwk::STATE_BOOTING); - controller->userItems_.insert({userId, userItem}); - sptr callback = nullptr; - bool isAppRecovery = 0; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_NE(controller->StartUser(userId, callback, isAppRecovery), ERR_DEAD_OBJECT); - EXPECT_EQ(controller->currentUserId_, 101); -} - -/** - * @tc.name: StopUser_001 - * @tc.desc: Verify StopUser call. - * Branch userId < 0 - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = -1; - EXPECT_EQ(controller->StopUser(userId), -1); -} - -/** - * @tc.name: StopUser_002 - * @tc.desc: Verify StopUser call. - * Branch userId == USER_ID_NO_HEAD - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_NO_HEAD; - EXPECT_EQ(controller->StopUser(userId), -1); -} - -/** - * @tc.name: StopUser_003 - * @tc.desc: Verify StopUser call. - * Branch userId == USER_ID_DEFAULT - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_DEFAULT; - EXPECT_EQ(controller->StopUser(userId), -1); -} - -/** - * @tc.name: StopUser_004 - * @tc.desc: Verify StopUser call. - * Branch IsCurrentUser == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 101; - int32_t userId = 101; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->StopUser(userId), 0); -} - -/** - * @tc.name: StopUser_005 - * @tc.desc: Verify StopUser call. - * Branch IsExistOsAccount == false - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_005, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::vector> expectOuter = {{false}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->StopUser(userId), -1); -} - -/** - * @tc.name: StopUser_006 - * @tc.desc: Verify StopUser call. - * Branch IsSceneBoardEnabled == false && GetMissionListWrap == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_006, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr wrap = nullptr; - OH_EXPECT_RET({wrap}, AbilityManagerService, GetMissionListWrap); - EXPECT_EQ(controller->StopUser(userId), -1); -} - -/** - * @tc.name: StopUser_007 - * @tc.desc: Verify StopUser call. - * Branch IsSceneBoardEnabled == false && GetMissionListWrap != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_007, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr wrap = std::make_shared(); - OH_EXPECT_RET({wrap}, AbilityManagerService, GetMissionListWrap); - EXPECT_EQ(controller->StopUser(userId), 0); -} - -/** - * @tc.name: StopUser_008 - * @tc.desc: Verify StopUser call. - * Branch IsSceneBoardEnabled == true && GetMissionListWrap == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_008, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr wrap = nullptr; - OH_EXPECT_RET({wrap}, AbilityManagerService, GetMissionListWrap); - EXPECT_EQ(controller->StopUser(userId), 0); -} - -/** - * @tc.name: StopUser_009 - * @tc.desc: Verify StopUser call. - * Branch IsSceneBoardEnabled == true && GetMissionListWrap != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, StopUser_009, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr wrap = std::make_shared(); - OH_EXPECT_RET({wrap}, AbilityManagerService, GetMissionListWrap); - EXPECT_EQ(controller->StopUser(userId), 0); -} - -/** - * @tc.name: LogoutUser_001 - * @tc.desc: Verify LogoutUser call. - * Branch userId < 0 && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = -1; - sptr callback = nullptr; - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_002 - * @tc.desc: Verify LogoutUser call. - * Branch userId == USER_ID_NO_HEAD && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_NO_HEAD; - sptr callback = nullptr; - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_003 - * @tc.desc: Verify LogoutUser call. - * Branch userId < 0 && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = -1; - sptr callback = sptr::MakeSptr(); - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_004 - * @tc.desc: Verify LogoutUser call. - * Branch userId == USER_ID_NO_HEAD && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = AAFwk::USER_ID_NO_HEAD; - sptr callback = sptr::MakeSptr(); - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_005 - * @tc.desc: Verify LogoutUser call. - * Branch IsExistOsAccount == false && callback == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_005, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - sptr callback = nullptr; - std::vector> expectOuter = {{false}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_006 - * @tc.desc: Verify LogoutUser call. - * Branch IsExistOsAccount == false && callback != nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_006, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - sptr callback = sptr::MakeSptr(); - std::vector> expectOuter = {{false}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - EXPECT_EQ(controller->LogoutUser(userId, callback), AAFwk::INVALID_USERID_VALUE); -} - -/** - * @tc.name: LogoutUser_007 - * @tc.desc: Verify LogoutUser call. - * Branch IsSceneBoardEnabled == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_007, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - sptr callback = sptr::MakeSptr(); - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->LogoutUser(userId, callback), 0); - EXPECT_LOG_MATCH(LOG_INFO, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SceneBoard exit normally."); -} - -/** - * @tc.name: LogoutUser_008 - * @tc.desc: Verify LogoutUser call. - * Branch IsSceneBoardEnabled == false - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_008, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - sptr callback = sptr::MakeSptr(); - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - EXPECT_EQ(controller->LogoutUser(userId, callback), 0); -} - -/** - * @tc.name: LogoutUser_009 - * @tc.desc: Verify LogoutUser call. - * Branch IsSceneBoardEnabled == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_009, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 100; - sptr callback = sptr::MakeSptr(); - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->LogoutUser(userId, callback), 0); - EXPECT_EQ(controller->currentUserId_, 0); -} - -/** - * @tc.name: LogoutUser_010 - * @tc.desc: Verify LogoutUser call. - * Branch IsSceneBoardEnabled == true - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, LogoutUser_010, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - sptr callback = sptr::MakeSptr(); - std::vector> expectOuter = {{true}}; - OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, - IsOsAccountExists, const int, bool& isOsAccountExists); - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->LogoutUser(userId, callback), 0); - EXPECT_EQ(controller->currentUserId_, 100); -} - -/** - * @tc.name: GetCurrentUserId_001 - * @tc.desc: Verify GetCurrentUserId call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetCurrentUserId_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - EXPECT_EQ(controller->GetCurrentUserId(), 100); -} - -/** - * @tc.name: GetUserItem_001 - * @tc.desc: Verify GetUserItem call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetUserItem_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 100; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->GetUserItem(userId), userItem); -} - -/** - * @tc.name: GetUserItem_002 - * @tc.desc: Verify GetUserItem call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetUserItem_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 100; - EXPECT_EQ(controller->GetUserItem(userId), nullptr); -} +void UserControllerTest::SetUpTestCase() {} +void UserControllerTest::TearDownTestCase() {} +void UserControllerTest::SetUp() {} +void UserControllerTest::TearDown() {} /** * @tc.name: IsExistOsAccount_001 @@ -897,7 +53,7 @@ HWTEST_F(UserControllerTest, GetUserItem_002, TestSize.Level1) */ HWTEST_F(UserControllerTest, IsExistOsAccount_001, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); int32_t userId = 100; std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, @@ -913,7 +69,7 @@ HWTEST_F(UserControllerTest, IsExistOsAccount_001, TestSize.Level1) */ HWTEST_F(UserControllerTest, IsExistOsAccount_002, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); int32_t userId = 100; std::vector> expectOuter = {{true}}; OH_EXPECT_RET_AND_OUTPUT({1}, expectOuter, OsAccountManagerWrapper, @@ -929,7 +85,7 @@ HWTEST_F(UserControllerTest, IsExistOsAccount_002, TestSize.Level1) */ HWTEST_F(UserControllerTest, IsExistOsAccount_003, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); int32_t userId = 100; std::vector> expectOuter = {{false}}; OH_EXPECT_RET_AND_OUTPUT({0}, expectOuter, OsAccountManagerWrapper, @@ -945,7 +101,7 @@ HWTEST_F(UserControllerTest, IsExistOsAccount_003, TestSize.Level1) */ HWTEST_F(UserControllerTest, IsExistOsAccount_004, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); int32_t userId = 100; std::vector> expectOuter = {{false}}; OH_EXPECT_RET_AND_OUTPUT({1}, expectOuter, OsAccountManagerWrapper, @@ -953,32 +109,6 @@ HWTEST_F(UserControllerTest, IsExistOsAccount_004, TestSize.Level1) EXPECT_EQ(controller->IsExistOsAccount(userId), false); } -/** - * @tc.name: GetOrCreateUserItem_001 - * @tc.desc: Verify GetOrCreateUserItem call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetOrCreateUserItem_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 100; - std::shared_ptr userItem = std::make_shared(userId); - controller->userItems_.insert({userId, userItem}); - EXPECT_EQ(controller->GetOrCreateUserItem(userId), userItem); -} - -/** - * @tc.name: GetOrCreateUserItem_002 - * @tc.desc: Verify GetOrCreateUserItem call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, GetOrCreateUserItem_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - int32_t userId = 100; - EXPECT_NE(controller->GetOrCreateUserItem(userId), nullptr); -} - /** * @tc.name: SetCurrentUserId_001 * @tc.desc: Verify SetCurrentUserId call. @@ -986,492 +116,13 @@ HWTEST_F(UserControllerTest, GetOrCreateUserItem_002, TestSize.Level1) */ HWTEST_F(UserControllerTest, SetCurrentUserId_001, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - controller->SetCurrentUserId(userId); - EXPECT_EQ(controller->currentUserId_, 101); -} - -/** - * @tc.name: MoveUserToForeground_001 - * @tc.desc: Verify MoveUserToForeground call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, MoveUserToForeground_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - OH_EXPECT_RET({0}, AbilityManagerService, SwitchToUser, int32_t, int32_t, - sptr, bool isAppRecovery = false); - int32_t oldUserId = 100; - int32_t newUserId = 101; - sptr callback = nullptr; - bool isAppRecovery = false; - EXPECT_EQ(controller->MoveUserToForeground(oldUserId, newUserId, callback, isAppRecovery), ERR_OK); -} - -/** - * @tc.name: MoveUserToForeground_002 - * @tc.desc: Verify MoveUserToForeground call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, MoveUserToForeground_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->currentUserId_ = 100; - int32_t userId = 101; - OH_EXPECT_RET({1}, AbilityManagerService, SwitchToUser, int32_t, int32_t, - sptr, bool isAppRecovery = false); - int32_t oldUserId = 100; - int32_t newUserId = 101; - sptr callback = nullptr; - bool isAppRecovery = false; - EXPECT_EQ(controller->MoveUserToForeground(oldUserId, newUserId, callback, isAppRecovery), 1); -} - -/** - * @tc.name: UserBootDone_001 - * @tc.desc: Verify UserBootDone call. - * Branch item == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item = nullptr; - controller->UserBootDone(item); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null item"); -} - -/** - * @tc.name: UserBootDone_002 - * @tc.desc: Verify UserBootDone call. - * Branch userId invalid - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item = std::make_shared(101); - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - item->SetState(userState); - controller->UserBootDone(item); - EXPECT_EQ(item->GetState(), AAFwk::UserState::STATE_BOOTING); -} - -/** - * @tc.name: UserBootDone_003 - * @tc.desc: Verify UserBootDone call. - * Branch item not match - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item1 = std::make_shared(101); - std::shared_ptr item2 = std::make_shared(101); - controller->userItems_.insert({101, item2}); - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - item1->SetState(userState); - controller->UserBootDone(item1); - EXPECT_EQ(item1->GetState(), AAFwk::UserState::STATE_BOOTING); -} - -/** - * @tc.name: UserBootDone_004 - * @tc.desc: Verify UserBootDone call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, UserBootDone_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - std::shared_ptr item = std::make_shared(101); - controller->userItems_.insert({101, item}); - AAFwk::UserState userState = AAFwk::UserState::STATE_BOOTING; - item->SetState(userState); - controller->UserBootDone(item); - EXPECT_EQ(item->GetState(), AAFwk::UserState::STATE_STARTED); -} - -/** - * @tc.name: BroadcastUserBackground_001 - * @tc.desc: Verify BroadcastUserBackground call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, BroadcastUserBackground_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->BroadcastUserBackground(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "user background"); -} - -/** - * @tc.name: BroadcastUserForeground_001 - * @tc.desc: Verify BroadcastUserForeground call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, BroadcastUserForeground_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->BroadcastUserForeground(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "user foreground"); -} - -/** - * @tc.name: BroadcastUserStopping_001 - * @tc.desc: Verify BroadcastUserStopping call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, BroadcastUserStopping_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->BroadcastUserStopping(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "user stopping"); -} - -/** - * @tc.name: BroadcastUserStopped_001 - * @tc.desc: Verify BroadcastUserStopped call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, BroadcastUserStopped_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->BroadcastUserStopped(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "user stopped"); -} - -/** - * @tc.name: SendSystemUserStart_001 - * @tc.desc: Verify SendSystemUserStart call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendSystemUserStart_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - controller->SendSystemUserStart(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_SYSTEM_USER_START)"); -} - -/** - * @tc.name: SendSystemUserStart_002 - * @tc.desc: Verify SendSystemUserStart call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendSystemUserStart_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - controller->SendSystemUserStart(100); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: ProcessEvent_001 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventData() == nullptr - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr eventDataBase = nullptr; - OH_EXPECT_RET({eventDataBase}, EventWrap, GetEventData); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "no event data, event id:"); -} - -/** - * @tc.name: ProcessEvent_002 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_SYSTEM_USER_START - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_SYSTEM_USER_START}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "notify system user start."); -} - -/** - * @tc.name: ProcessEvent_003 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_SYSTEM_USER_CURRENT - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_003, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_SYSTEM_USER_CURRENT}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "notify system user current."); -} - -/** - * @tc.name: ProcessEvent_004 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_REPORT_USER_SWITCH - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_004, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_REPORT_USER_SWITCH}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "notify report user switch."); -} - -/** - * @tc.name: ProcessEvent_005 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_CONTINUE_USER_SWITCH - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_005, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_CONTINUE_USER_SWITCH}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: ProcessEvent_006 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_USER_SWITCH_TIMEOUT - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_006, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_USER_SWITCH_TIMEOUT}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: ProcessEvent_007 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_007, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - OH_EXPECT_RET({AAFwk::UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "handle user switch done."); -} - -/** - * @tc.name: ProcessEvent_008 - * @tc.desc: Verify ProcessEvent call. - * Branch event.GetEventId() == invalid value - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, ProcessEvent_008, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - AAFwk::EventWrap event(0); - std::shared_ptr userEvent = std::make_shared(); - OH_EXPECT_RET({userEvent}, EventWrap, GetEventData); - uint32_t eventId = 111; - OH_EXPECT_RET({eventId}, EventWrap, GetEventId); - controller->ProcessEvent(event); - EXPECT_LOG_MATCH(LOG_WARN, AAFwkTag::ABILITYMGR, "user_controller.cpp", "Unsupported event."); -} - -/** - * @tc.name: SendSystemUserCurrent_001 - * @tc.desc: Verify SendSystemUserCurrent call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendSystemUserCurrent_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - controller->SendSystemUserCurrent(100, 101); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_SYSTEM_USER_CURRENT)"); -} - -/** - * @tc.name: SendSystemUserCurrent_002 - * @tc.desc: Verify SendSystemUserCurrent call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendSystemUserCurrent_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - controller->SendSystemUserCurrent(100, 101); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: SendReportUserSwitch_001 - * @tc.desc: Verify SendReportUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendReportUserSwitch_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - std::shared_ptr usrItem = nullptr; - controller->SendReportUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_REPORT_USER_SWITCH)"); -} - -/** - * @tc.name: SendReportUserSwitch_002 - * @tc.desc: Verify SendReportUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendReportUserSwitch_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - std::shared_ptr usrItem = nullptr; - controller->SendReportUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: SendUserSwitchTimeout_001 - * @tc.desc: Verify SendUserSwitchTimeout call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendUserSwitchTimeout_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - std::shared_ptr usrItem = nullptr; - controller->SendUserSwitchTimeout(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_USER_SWITCH_TIMEOUT)"); -} - -/** - * @tc.name: SendUserSwitchTimeout_002 - * @tc.desc: Verify SendUserSwitchTimeout call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendUserSwitchTimeout_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - std::shared_ptr usrItem = nullptr; - controller->SendUserSwitchTimeout(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: SendContinueUserSwitch_001 - * @tc.desc: Verify SendContinueUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendContinueUserSwitch_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - std::shared_ptr usrItem = nullptr; - controller->SendContinueUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", "SendEvent(EVENT_CONTINUE_USER_SWITCH)"); -} - -/** - * @tc.name: SendContinueUserSwitch_002 - * @tc.desc: Verify SendContinueUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendContinueUserSwitch_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - std::shared_ptr usrItem = nullptr; - controller->SendContinueUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: SendUserSwitchDone_001 - * @tc.desc: Verify SendUserSwitchDone call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendUserSwitchDone_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - controller->SendUserSwitchDone(100); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", - "SendEvent(EVENT_REPORT_USER_SWITCH_DONE)"); -} - -/** - * @tc.name: SendUserSwitchDone_002 - * @tc.desc: Verify SendUserSwitchDone call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, SendUserSwitchDone_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = nullptr; - controller->SendUserSwitchDone(100); - EXPECT_LOG_MATCH(LOG_ERROR, AAFwkTag::ABILITYMGR, "user_controller.cpp", "null handler"); -} - -/** - * @tc.name: HandleContinueUserSwitch_001 - * @tc.desc: Verify HandleContinueUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, HandleContinueUserSwitch_001, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - OH_EXPECT_RET({false}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr usrItem = nullptr; - controller->HandleContinueUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", - "SendEvent(EVENT_REPORT_USER_SWITCH_DONE)"); -} - -/** - * @tc.name: HandleContinueUserSwitch_002 - * @tc.desc: Verify HandleContinueUserSwitch call. - * @tc.type: FUNC - */ -HWTEST_F(UserControllerTest, HandleContinueUserSwitch_002, TestSize.Level1) -{ - std::shared_ptr controller = std::make_shared(); - controller->eventHandler_ = std::make_shared(nullptr, controller); - OH_EXPECT_RET({true}, SceneBoardJudgement, IsSceneBoardEnabled); - std::shared_ptr usrItem = nullptr; - controller->HandleContinueUserSwitch(100, 101, usrItem); - EXPECT_LOG_MATCH(LOG_DEBUG, AAFwkTag::ABILITYMGR, "user_controller.cpp", - "SendEvent(EVENT_REPORT_USER_SWITCH_DONE)"); + std::shared_ptr controller = std::make_shared(); + uint64_t displayId = 0; + int32_t userId = 100; + AbilityRuntime::UserController::GetInstance().SetForegroundUserId(userId, displayId); + userId = 101; + AbilityRuntime::UserController::GetInstance().SetForegroundUserId(userId, displayId); + EXPECT_EQ(AbilityRuntime::UserController::GetInstance().GetForegroundUserId(displayId), 101); } /** @@ -1481,7 +132,7 @@ HWTEST_F(UserControllerTest, HandleContinueUserSwitch_002, TestSize.Level1) */ HWTEST_F(UserControllerTest, GetFreezingNewUserId_001, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); controller->freezingNewUserId_ = 101; EXPECT_EQ(controller->GetFreezingNewUserId(), 101); } @@ -1493,9 +144,9 @@ HWTEST_F(UserControllerTest, GetFreezingNewUserId_001, TestSize.Level1) */ HWTEST_F(UserControllerTest, SetFreezingNewUserId_001, TestSize.Level1) { - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(); controller->SetFreezingNewUserId(101); EXPECT_EQ(controller->freezingNewUserId_, 101); } -} // namespace AppExecFwk +} // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index bfa3e9573ca58ff75805de79e7cb7db397340af9..4f5111ade05bbae953cbfb6bf43466f6bfea4a54 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -481,9 +481,6 @@ group("unittest") { "udmf_utils_test:unittest", "uri_utils_second_test", "uri_utils_test:unittest", - "user_controller_test:unittest", - "user_event_handler_test:unittest", - "user_record_manager_test:unittest", "want_agent_helper_test:unittest", "want_agent_info_test:unittest", "want_agent_test:unittest", diff --git a/test/unittest/ability_auto_startup_service_second_test/BUILD.gn b/test/unittest/ability_auto_startup_service_second_test/BUILD.gn index 03625ff86a4cdc3bbcc667baf8c3ca2e1f16f981..4f35330441f8ce38e05bfd368b6e4b7233d7d7aa 100644 --- a/test/unittest/ability_auto_startup_service_second_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_second_test/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("ability_auto_startup_service_second_test") { "${ability_runtime_native_path}/ability/native:auto_startup_callback", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -77,6 +78,8 @@ ohos_unittest("ability_auto_startup_service_second_test") { "kv_store:distributeddata_inner", "safwk:api_cache_manager", "selinux_adapter:librestorecon", + "window_manager:libdm", + "window_manager:libwsutils", ] cflags_cc = [] diff --git a/test/unittest/ability_auto_startup_service_test/BUILD.gn b/test/unittest/ability_auto_startup_service_test/BUILD.gn index d22348615854f00dabb9bf331e1a7b5b85eab4a6..0f2764be1d765f404a0b8a8cb224c60291b21bef 100644 --- a/test/unittest/ability_auto_startup_service_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_unittest("ability_auto_startup_service_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -74,6 +75,8 @@ ohos_unittest("ability_auto_startup_service_test") { "kv_store:distributeddata_inner", "safwk:api_cache_manager", "selinux_adapter:librestorecon", + "window_manager:libdm", + "window_manager:libwsutils", ] cflags_cc = [] diff --git a/test/unittest/ability_auto_startup_service_third_test/BUILD.gn b/test/unittest/ability_auto_startup_service_third_test/BUILD.gn index 1bd537f1e694688fe30536ed835e3edd543e3c6e..5b328b8a004eed5b54de04f8adb6e0a24d0fc836 100644 --- a/test/unittest/ability_auto_startup_service_third_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_third_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("ability_auto_startup_service_third_test") { "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_native_path}/ability/native:auto_startup_callback", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -60,6 +61,8 @@ ohos_unittest("ability_auto_startup_service_third_test") { "ipc:ipc_core", "kv_store:distributeddata_inner", "safwk:api_cache_manager", + "window_manager:libdm", + "window_manager:libwsutils", ] cflags_cc = [] diff --git a/test/unittest/ability_bundle_event_callback_test/BUILD.gn b/test/unittest/ability_bundle_event_callback_test/BUILD.gn index b59638976588616ce35a4eea9b3865b2149e87ef..ece8fbee925919ba1cb0525c4ee3ce4888f8a34c 100644 --- a/test/unittest/ability_bundle_event_callback_test/BUILD.gn +++ b/test/unittest/ability_bundle_event_callback_test/BUILD.gn @@ -54,6 +54,7 @@ ohos_unittest("ability_bundle_event_callback_test") { "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", ] @@ -80,6 +81,7 @@ ohos_unittest("ability_bundle_event_callback_test") { "init:libbegetutil", "kv_store:distributeddata_inner", "safwk:api_cache_manager", + "window_manager:libdm", "window_manager:libwsutils", "window_manager:sms", ] diff --git a/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp b/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp index 1b1cfd8af25a463008c5a4c9fcc648abe4d1500e..bba3237c6cf73c1210a0fa9fc1e74796e1033497 100644 --- a/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp +++ b/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp @@ -43,39 +43,6 @@ void AbilityEventHandlerTest::SetUp() void AbilityEventHandlerTest::TearDown() {} -/* - * Feature: Ability Event Handler - * Function: ProcessEvent - * SubFunction: NA - * FunctionPoints: Ability Event Handler ProcessEvent - * EnvConditions: NA - * CaseDescription: Verify ProcessEvent - */ -HWTEST_F(AbilityEventHandlerTest, ability_event_handler_001, TestSize.Level1) -{ - std::shared_ptr runner; - std::weak_ptr server; - std::shared_ptr eventData = std::make_shared(); - auto event = EventWrap(UserEventHandler::EVENT_SYSTEM_USER_START, eventData); - auto handler = std::make_shared(runner, server); - SetParameter("libc.hook_mode", "startup:"); - handler->ProcessEvent(event); - SetParameter("libc.hook_mode", "test_parameter"); - handler->ProcessEvent(event); - auto event2 = EventWrap(AbilityManagerService::LOAD_TIMEOUT_MSG, event.GetParam()); - std::string str = std::to_string(event.GetEventId()); - handler->ProcessEvent(event2); - event2 = EventWrap(AbilityManagerService::ACTIVE_TIMEOUT_MSG, event.GetParam()); - handler->ProcessEvent(event2); - event2 = EventWrap(AbilityManagerService::INACTIVE_TIMEOUT_MSG, event.GetParam()); - handler->ProcessEvent(event2); - event2 = EventWrap(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, event.GetParam()); - handler->ProcessEvent(event2); - event2 = EventWrap(AbilityManagerService::BACKGROUND_TIMEOUT_MSG, event.GetParam()); - handler->ProcessEvent(event2); - EXPECT_TRUE(handler != nullptr); -} // namespace AppExecFwk - /* * Feature: Ability Event Handler * Function: EventWrap diff --git a/test/unittest/ability_keep_alive_service_test/BUILD.gn b/test/unittest/ability_keep_alive_service_test/BUILD.gn index 13fa83bf9186c12675dfdefe7e08c21d055b76ed..24437fa828322129842d1dce8678f8a53e3718f7 100644 --- a/test/unittest/ability_keep_alive_service_test/BUILD.gn +++ b/test/unittest/ability_keep_alive_service_test/BUILD.gn @@ -44,6 +44,7 @@ ohos_unittest("ability_keep_alive_service_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h b/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h index 5ed51e73603f771eccedbb3f76339b86be0a7c84..8979dcce4dcf0d526a44038a51f1c1c479775038 100644 --- a/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h +++ b/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h @@ -220,7 +220,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp index aace3c78645c526523fcc9cb6fd02c114b5baedb..63b21f13aa11b3208d922e06e874819077bf12be 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp @@ -959,8 +959,9 @@ HWTEST_F(AbilityManagerClientBranchTest, StopSyncRemoteMissions_0100, TestSize.L HWTEST_F(AbilityManagerClientBranchTest, StartUser_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "StartUser_0100 start"; - int userId = 1; - auto result = client_->StartUser(userId, nullptr); + int userId = 200; + uint64_t displayId = 0; + auto result = client_->StartUser(userId, displayId, nullptr); EXPECT_EQ(result, ERR_OK); GTEST_LOG_(INFO) << "StartUser_0100 end"; diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h index 660d1a744505d20939e43bf1574bfa829d401fe2..c6d8e9c8bc72607339bef876a804dbfd5f65b98c 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -239,7 +239,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h index b27b0e36f800e96f1e059f7d67b26c3ff99da386..2206897b0b0f05922b5de09349a25957309308af 100644 --- a/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h @@ -203,7 +203,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_event_subscriber_test/ability_manager_event_subscriber_test.cpp b/test/unittest/ability_manager_event_subscriber_test/ability_manager_event_subscriber_test.cpp index 1e3eb4e3be1b76afc72adbf61c6537573737a49f..744a0ffe23bad2de1c636c5d8c910d66a68be90a 100644 --- a/test/unittest/ability_manager_event_subscriber_test/ability_manager_event_subscriber_test.cpp +++ b/test/unittest/ability_manager_event_subscriber_test/ability_manager_event_subscriber_test.cpp @@ -46,7 +46,7 @@ void AbilityManagerEventSubscriberTest::SetUp() {} HWTEST_F(AbilityManagerEventSubscriberTest, OnReceiveEvent_0001, TestSize.Level1) { EventFwk::CommonEventSubscribeInfo subscribeInfo; - std::function callback = []() {}; + std::function callback = [](int32_t) {}; std::function userScreenUnlockCallback = []() {}; EXPECT_NE(callback, nullptr); EXPECT_NE(userScreenUnlockCallback, nullptr); diff --git a/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h index b9559de09e78b81827cbec38bfc7716331b7be46..2c53c7a2fedf606e72e0ea905f65a9b736df7096 100644 --- a/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h @@ -236,7 +236,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h index 9c28fbf1e34b2aeb57c860cd873c9f014d14fc56..08386f6c6a877449f0c7c16c87bd0f678dc927e9 100644 --- a/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h @@ -236,7 +236,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h index 6d842980b18ca517df4651354e657334d9756444..18143f6d6a3b4eb104612856be553ea8a5343775 100644 --- a/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h @@ -236,7 +236,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h index 6d842980b18ca517df4651354e657334d9756444..18143f6d6a3b4eb104612856be553ea8a5343775 100644 --- a/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h @@ -236,7 +236,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp index 49af01d529d05c1abfd6f3eced456c749b77b207..96a67d4c1784031fda5f105c72bc641909d677b1 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp +++ b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp @@ -1680,8 +1680,9 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_StartUser_001, TestSize.Le EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); - int userId = 1; - auto res = proxy_->StartUser(userId, nullptr); + int userId = 200; + uint64_t displayId = 0; + auto res = proxy_->StartUser(userId, displayId, nullptr); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::START_USER), mock_->code_); EXPECT_EQ(res, NO_ERROR); } diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index 4cb5157ecff12aeb57ee01917f48b60737d64e84..8461bfaee1cf3c40d2017396e096db7b9b6259b8 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -244,7 +244,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp b/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp index 1a48b715b980fb73a1db49f66451261b340bb302..dbb3019efdf0c61781356e156e020a217825e230 100644 --- a/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp +++ b/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp @@ -1019,7 +1019,8 @@ HWTEST_F(AbilityManagerProxyTest, StartUser_3000, TestSize.Level1) EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeErrorSendRequest)); - int32_t result = proxy_->StartUser(1, callback, false); + int32_t userId = 10000; + int32_t result = proxy_->StartUser(userId, 0, callback, false); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::START_USER), mock_->code_); EXPECT_NE(result, NO_ERROR); @@ -1029,7 +1030,7 @@ HWTEST_F(AbilityManagerProxyTest, StartUser_3000, TestSize.Level1) sptr mockIUserCallback = new MockIUserCallback(); mockIUserCallback->iremoteObject_ = sptr(new (std::nothrow) MockAbilityToken()); callback = mockIUserCallback; - result = proxy_->StartUser(1, callback, false); + result = proxy_->StartUser(userId, 0, callback, false); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::START_USER), mock_->code_); EXPECT_EQ(result, NO_ERROR); @@ -1049,7 +1050,8 @@ HWTEST_F(AbilityManagerProxyTest, StopUser_3100, TestSize.Level1) EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeErrorSendRequest)); - int32_t result = proxy_->StopUser(1, callback); + int32_t userId = 10000; + int32_t result = proxy_->StopUser(userId, callback); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::STOP_USER), mock_->code_); EXPECT_NE(result, NO_ERROR); @@ -1059,7 +1061,7 @@ HWTEST_F(AbilityManagerProxyTest, StopUser_3100, TestSize.Level1) sptr mockIUserCallback = new MockIUserCallback(); mockIUserCallback->iremoteObject_ = sptr(new (std::nothrow) MockAbilityToken()); callback = mockIUserCallback; - result = proxy_->StopUser(1, callback); + result = proxy_->StopUser(userId, callback); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::STOP_USER), mock_->code_); EXPECT_EQ(result, NO_ERROR); @@ -1079,7 +1081,8 @@ HWTEST_F(AbilityManagerProxyTest, LogoutUser_3200, TestSize.Level1) EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeErrorSendRequest)); - int32_t result = proxy_->LogoutUser(1, callback); + int32_t userId = 10000; + int32_t result = proxy_->LogoutUser(userId, callback); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::LOGOUT_USER), mock_->code_); EXPECT_NE(result, NO_ERROR); @@ -1089,7 +1092,7 @@ HWTEST_F(AbilityManagerProxyTest, LogoutUser_3200, TestSize.Level1) sptr mockIUserCallback = new MockIUserCallback(); mockIUserCallback->iremoteObject_ = sptr(new (std::nothrow) MockAbilityToken()); callback = mockIUserCallback; - result = proxy_->LogoutUser(1, callback); + result = proxy_->LogoutUser(userId, callback); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::LOGOUT_USER), mock_->code_); EXPECT_EQ(result, NO_ERROR); diff --git a/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h index b443ad9e07c78b5d1fae762c80f7998a459483dc..09dda28fd277c3b882d2de7a3d40280c5652d065 100644 --- a/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h @@ -208,7 +208,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp b/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp index 088179067f95ca8fb259e37e37d9ec5f78fad381..d370b19b190dfd0f36bc1a00a08cde46cd586079 100644 --- a/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp +++ b/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp @@ -137,7 +137,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_001, TestSize.Le { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_001 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); auto topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(USER_ID_U100)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -149,7 +149,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_001, TestSize.Le WaitUntilTaskFinished(); EXPECT_EQ(OHOS::ERR_OK, result); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -158,7 +158,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_001, TestSize.Le result = abilityMs_->StartAbility(want, newUserId); WaitUntilTaskFinished(); EXPECT_EQ(OHOS::ERR_OK, result); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_001 end"; } @@ -224,7 +224,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_003, TestSize.Le EXPECT_EQ(OHOS::ERR_OK, result); sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -232,7 +232,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_003, TestSize.Le result = abilityMs_->StartAbility(want, abilityStartSetting, nullptr, newUserId, -1); WaitUntilTaskFinished(); EXPECT_EQ(OHOS::ERR_OK, result); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_003 end"; } @@ -261,7 +261,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_004, TestSize.Le EXPECT_EQ(OHOS::ERR_OK, result); sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -269,7 +269,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_004, TestSize.Le result = abilityMs_->StartAbility(want, abilityStartOptions, nullptr, newUserId, -1); WaitUntilTaskFinished(); EXPECT_EQ(OHOS::ERR_OK, result); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_004 end"; } @@ -328,7 +328,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_007, TestSize.Le { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_007 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); Want want; ElementName element("", "com.ix.hiSingleMusicInfo", "SingleMusicAbility"); want.SetElement(element); @@ -351,7 +351,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_008, TestSize.Le { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_008 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); Want want; ElementName element("", "com.ix.hiBackgroundMusic", "hiBackgroundMusic"); want.SetElement(element); @@ -416,7 +416,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StartAbility_011, TestSize.Le { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StartAbility_011 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); auto topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(USER_ID_U100)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -634,7 +634,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ConnectAbility_002, TestSize. { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ConnectAbility_002 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); Want want; ElementName element("", "com.ix.musicService", "MusicService"); want.SetElement(element); @@ -650,7 +650,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ConnectAbility_002, TestSize. auto result2 = abilityMs_->ConnectAbility(want, callback, nullptr, newUserId); EXPECT_EQ(result2, ERR_OK); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ConnectAbility_002 end"; } @@ -832,7 +832,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleConnectAbilityDone_00 { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleConnectAbilityDone_003 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); Want want; ElementName element("", "com.ix.musicService", "MusicService"); want.SetElement(element); @@ -858,7 +858,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleConnectAbilityDone_00 auto result3 = abilityMs_->ScheduleConnectAbilityDone(service->GetToken(), callback->AsObject()); WaitUntilTaskFinished(); EXPECT_EQ(result3, ERR_OK); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleConnectAbilityDone_003 end"; } @@ -876,7 +876,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleConnectAbilityDone_00 { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleConnectAbilityDone_004 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); auto topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -898,7 +898,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleConnectAbilityDone_00 auto result1 = abilityMs_->ScheduleConnectAbilityDone(token, callback->AsObject()); WaitUntilTaskFinished(); EXPECT_EQ(result1, TARGET_ABILITY_NOT_SERVICE); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleConnectAbilityDone_004 end"; } @@ -995,7 +995,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleDisconnectAbilityDone { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleDisconnectAbilityDone_003 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); auto topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -1017,7 +1017,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleDisconnectAbilityDone auto result1 = abilityMs_->ScheduleDisconnectAbilityDone(token); WaitUntilTaskFinished(); EXPECT_EQ(result1, TARGET_ABILITY_NOT_SERVICE); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleDisconnectAbilityDone_003 end"; } @@ -1115,7 +1115,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleCommandAbilityDone_00 { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleCommandAbilityDone_003 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); Want want; ElementName element("", "com.ix.musicService", "MusicService"); want.SetElement(element); @@ -1141,7 +1141,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleCommandAbilityDone_00 auto result3 = abilityMs_->ScheduleCommandAbilityDone(service->GetToken()); WaitUntilTaskFinished(); EXPECT_EQ(result3, ERR_OK); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleCommandAbilityDone_003 end"; } @@ -1159,7 +1159,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleCommandAbilityDone_00 { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleCommandAbilityDone_004 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); auto topAbility = GetMissionListTopAbility(abilityMs_->GetMissionListManagerByUserId(newUserId)); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -1181,7 +1181,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_ScheduleCommandAbilityDone_00 auto result1 = abilityMs_->ScheduleCommandAbilityDone(token); WaitUntilTaskFinished(); EXPECT_EQ(result1, TARGET_ABILITY_NOT_SERVICE); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_ScheduleCommandAbilityDone_004 end"; } @@ -1235,7 +1235,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StopServiceAbility_002, TestS { GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StopServiceAbility_002 start"; sptr callback = new MockIUserCallback(); - abilityMs_->StartUser(newUserId, callback); + abilityMs_->StartUser(newUserId, 0, callback); Want want; ElementName element("", "com.ix.musicService", "MusicService"); want.SetElement(element); @@ -1260,7 +1260,7 @@ HWTEST_F(AbilityManagerServiceAccountTest, Account_StopServiceAbility_002, TestS auto result2 = abilityMs_->StopServiceAbility(want, newUserId); WaitUntilTaskFinished(); EXPECT_EQ(CHECK_PERMISSION_FAILED, result2); - abilityMs_->StartUser(USER_ID_U100, callback); + abilityMs_->StartUser(USER_ID_U100, 0, callback); GTEST_LOG_(INFO) << "AbilityManagerServiceAccountTest Account_StopServiceAbility_002 end"; } diff --git a/test/unittest/ability_manager_service_eighth_test/ability_manager_service_eighth_test.cpp b/test/unittest/ability_manager_service_eighth_test/ability_manager_service_eighth_test.cpp index f11947e1be8875da533996764a5cbcadc516106b..e2fbfa5387216c761e762e71a9acc4d6f85ee3f6 100644 --- a/test/unittest/ability_manager_service_eighth_test/ability_manager_service_eighth_test.cpp +++ b/test/unittest/ability_manager_service_eighth_test/ability_manager_service_eighth_test.cpp @@ -151,11 +151,10 @@ HWTEST_F(AbilityManagerServiceEighthTest, StopUser_001, TestSize.Level1) EXPECT_EQ(abilityMs->StopUser(userId, callback), CHECK_PERMISSION_FAILED); IPCSkeleton::SetCallingUid(ACCOUNT_MGR_SERVICE_UID); sptr callback1 = nullptr; - EXPECT_EQ(abilityMs->StopUser(userId, callback1), 0); - abilityMs->userController_ = std::make_shared(); - EXPECT_EQ(abilityMs->StopUser(userId, callback), 0); + EXPECT_EQ(abilityMs->StopUser(userId, callback1), INVALID_PARAMETERS_ERR); + EXPECT_EQ(abilityMs->StopUser(userId, callback), INVALID_USERID_VALUE); system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, true); - EXPECT_EQ(abilityMs->StopUser(userId, callback), 0); + EXPECT_EQ(abilityMs->StopUser(userId, callback), INVALID_USERID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceEighthTest StopUser_001 end"); } @@ -172,12 +171,11 @@ HWTEST_F(AbilityManagerServiceEighthTest, LogoutUser_001, TestSize.Level1) int userId = 10; IPCSkeleton::SetCallingUid(TEST_UID); sptr callback = nullptr; - EXPECT_EQ(abilityMs->LogoutUser(userId, callback), CHECK_PERMISSION_FAILED); + EXPECT_EQ(abilityMs->LogoutUser(userId, callback), INVALID_PARAMETERS_ERR); sptr callback1 = new MockIUserCallback(); EXPECT_EQ(abilityMs->LogoutUser(userId, callback1), CHECK_PERMISSION_FAILED); IPCSkeleton::SetCallingUid(ACCOUNT_MGR_SERVICE_UID); - EXPECT_EQ(abilityMs->LogoutUser(userId, callback1), ERR_OK); - abilityMs->userController_ = std::make_shared(); + EXPECT_EQ(abilityMs->LogoutUser(userId, callback1), INVALID_USERID_VALUE); system::SetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, true); EXPECT_NE(abilityMs->LogoutUser(userId, callback1), ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceEighthTest LogoutUser_001 end"); @@ -218,17 +216,17 @@ HWTEST_F(AbilityManagerServiceEighthTest, SwitchToUser_001, TestSize.Level1) sptr callback1 = new MockIUserCallback(); EXPECT_CALL(Rosen::SceneBoardJudgement::GetInstance(), MockIsSceneBoardEnabled()) .WillRepeatedly(Return(false)); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback), ERR_OK); abilityMs->taskHandler_ = TaskHandlerWrap::CreateQueueHandler("SetTaskHandler"); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); EXPECT_CALL(Rosen::SceneBoardJudgement::GetInstance(), MockIsSceneBoardEnabled()) .WillRepeatedly(Return(true)); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); AmsConfigurationParameter::GetInstance().multiUserType_ = 1; // multiUserType_ = 1 - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); EXPECT_CALL(Rosen::SceneBoardJudgement::GetInstance(), MockIsSceneBoardEnabled()) .WillRepeatedly(Return(false)); - EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, callback1), ERR_OK); + EXPECT_NE(abilityMs->SwitchToUser(oldUserId, userId, 0, callback1), ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceEighthTest SwitchToUser_001 end"); } diff --git a/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn b/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn index f12b2c99ce4f98ac06e5b97837c002fb9e844668..ef14a92fd8b851b3e86b93270deb23f49ea70507 100644 --- a/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn @@ -177,8 +177,6 @@ ohos_unittest("ability_manager_service_fourteenth_test") { "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record_factory.cpp", "${ability_runtime_services_path}/abilitymgr/src/user_callback_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_controller.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_event_handler.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_permission_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/app_mgr_util.cpp", @@ -264,6 +262,7 @@ ohos_unittest("ability_manager_service_fourteenth_test") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_manager_service_fourth_test/BUILD.gn b/test/unittest/ability_manager_service_fourth_test/BUILD.gn index a4d09d987de94a3bf363b27edb405c0b74669ff0..c9ae54393f4d0abc4a24cf5d5f242b41ee443e18 100644 --- a/test/unittest/ability_manager_service_fourth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_fourth_test/BUILD.gn @@ -85,6 +85,7 @@ ohos_unittest("ability_manager_service_fourth_test") { "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -117,6 +118,7 @@ ohos_unittest("ability_manager_service_fourth_test") { if (ability_runtime_graphics) { external_deps += [ + "window_manager:libdm", "window_manager:libwsutils", "window_manager:scene_session", ] diff --git a/test/unittest/ability_manager_service_second_test/BUILD.gn b/test/unittest/ability_manager_service_second_test/BUILD.gn index bfbd767d918fc074900c59d438e99b08c88b690b..74326d5fb8c2ab7913894c867d5ce8651f8bf7e3 100644 --- a/test/unittest/ability_manager_service_second_test/BUILD.gn +++ b/test/unittest/ability_manager_service_second_test/BUILD.gn @@ -183,8 +183,6 @@ ohos_unittest("ability_manager_service_second_test") { "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record_factory.cpp", "${ability_runtime_services_path}/abilitymgr/src/user_callback_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_controller.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_event_handler.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_permission_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/app_mgr_util.cpp", @@ -265,6 +263,7 @@ ohos_unittest("ability_manager_service_second_test") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ 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 11428f27b02141d056cd6868e14147fdbc870dca..060eb782c47120833daf83148a803a48ee534400 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 @@ -126,9 +126,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, StartSwitchUserDialog_001, TestSize.Le auto abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); abilityMs_->StartSwitchUserDialog(); - - abilityMs_->userController_ = nullptr; - abilityMs_->StartSwitchUserDialog(); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest StartSwitchUserDialog_001 end"); } @@ -160,9 +157,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, StopSwitchUserDialog_001, TestSize.Lev auto abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); abilityMs_->StopSwitchUserDialog(); - - abilityMs_->userController_ = nullptr; - abilityMs_->StopSwitchUserDialog(); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest StopSwitchUserDialog_001 end"); } @@ -1673,20 +1667,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, GetEventHandler_001, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetEventHandler_001 end"); } -/* - * Feature: AbilityManagerService - * Function: GetUserId - * SubFunction: NA - * FunctionPoints: AbilityManagerService GetUserId - */ -HWTEST_F(AbilityManagerServiceSecondTest, GetUserId_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetUserId_001 start"); - auto abilityMs_ = std::make_shared(); - EXPECT_NE(abilityMs_->GetUserId(), 100); - TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest GetUserId_001 end"); -} - /* * Feature: AbilityManagerService * Function: GenerateAbilityRequest diff --git a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp index 402c4912aafe151bd973a9ef8040f0752de4d029..7a0fa71ed47cfa5528a1b4ee33bc8982b6ac7bb1 100644 --- a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp +++ b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp @@ -1581,7 +1581,6 @@ HWTEST_F(AbilityManagerServiceSixthTest, VerifyAccountPermission_001, TestSize.L EXPECT_EQ(ret, ERR_OK); userId = USER_ID_U100; ret = abilityMs->VerifyAccountPermission(userId); - abilityMs->userController_ = std::make_shared(); ret = abilityMs->VerifyAccountPermission(userId); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest VerifyAccountPermission_001 end"); } diff --git a/test/unittest/ability_manager_service_tenth_test/ability_manager_service_tenth_test.cpp b/test/unittest/ability_manager_service_tenth_test/ability_manager_service_tenth_test.cpp index 9211523299c3935d43d9e0f920f630db021bfa93..699c3abb8f9d6c67bd840577888728183763b57f 100644 --- a/test/unittest/ability_manager_service_tenth_test/ability_manager_service_tenth_test.cpp +++ b/test/unittest/ability_manager_service_tenth_test/ability_manager_service_tenth_test.cpp @@ -405,13 +405,13 @@ HWTEST_F(AbilityManagerServiceTenhtTest, GetScreenUnlockCallback_001, TestSize.L TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTenhtTest GetScreenUnlockCallback_001 start"); std::shared_ptr abilityMs_ = std::make_shared(); EXPECT_NE(abilityMs_, nullptr); - abilityMs_->StartAutoStartupApps(); - abilityMs_->abilityAutoStartupService_ = std::make_shared(); - abilityMs_->StartAutoStartupApps(); int32_t userId = 100; + abilityMs_->StartAutoStartupApps(userId); + abilityMs_->abilityAutoStartupService_ = std::make_shared(); + abilityMs_->StartAutoStartupApps(userId); abilityMs_->StartKeepAliveApps(userId); auto screenUnlockCallback = abilityMs_->GetScreenUnlockCallback(); - screenUnlockCallback(); + screenUnlockCallback(userId); EXPECT_NE(screenUnlockCallback, nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTenhtTest GetScreenUnlockCallback_001 end"); } @@ -592,7 +592,7 @@ HWTEST_F(AbilityManagerServiceTenhtTest, StartHighestPriorityAbility_001, TestSi int32_t userId = 1; bool isBoot = false; bool isAppRecovery = true; - auto ret = abilityMs_->StartHighestPriorityAbility(userId, isBoot, isAppRecovery); + auto ret = abilityMs_->StartHighestPriorityAbility(userId, 0, isBoot, isAppRecovery); EXPECT_EQ(ret, RESOLVE_ABILITY_ERR); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTenhtTest StartHighestPriorityAbility_001 end"); } diff --git a/test/unittest/ability_manager_service_third_test/BUILD.gn b/test/unittest/ability_manager_service_third_test/BUILD.gn index 3184a5ee67ff42805d881bc792d5764083b9a239..bb0203923c766aed7766e27535e33a46664d8281 100644 --- a/test/unittest/ability_manager_service_third_test/BUILD.gn +++ b/test/unittest/ability_manager_service_third_test/BUILD.gn @@ -91,6 +91,7 @@ ohos_unittest("ability_manager_service_third_test") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", ] diff --git a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp index 26f35f7997458774c56887067e0ff1a895ccc508..7da2f2620f25c19fde623214ea727001fd4b5d3c 100644 --- a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp +++ b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp @@ -532,12 +532,7 @@ HWTEST_F(AbilityManagerServiceThirdTest, GetExtensionRunningInfos_001, TestSize. auto abilityMs_ = std::make_shared(); abilityMs_->subManagersHelper_ = std::make_shared(nullptr, nullptr); std::vector extensionRunningInfo; - EXPECT_NE(abilityMs_->GetExtensionRunningInfos(10, extensionRunningInfo), ERR_OK); - - auto temp = abilityMs_->subManagersHelper_->currentConnectManager_; - abilityMs_->subManagersHelper_->currentConnectManager_.reset(); - EXPECT_EQ(abilityMs_->GetExtensionRunningInfos(10, extensionRunningInfo), ERR_INVALID_VALUE); - abilityMs_->subManagersHelper_->currentConnectManager_ = temp; + EXPECT_EQ(abilityMs_->GetExtensionRunningInfos(10, extensionRunningInfo), ERR_OK); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest GetExtensionRunningInfos_001 end"); } @@ -735,10 +730,7 @@ HWTEST_F(AbilityManagerServiceThirdTest, JudgeMultiUserConcurrency_001, TestSize auto abilityMs_ = std::make_shared(); EXPECT_TRUE(abilityMs_->JudgeMultiUserConcurrency(0)); - auto temp = abilityMs_->userController_; - abilityMs_->userController_ = nullptr; EXPECT_FALSE(abilityMs_->JudgeMultiUserConcurrency(100)); - abilityMs_->userController_ = temp; TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest JudgeMultiUserConcurrency_001 end"); } @@ -854,7 +846,7 @@ HWTEST_F(AbilityManagerServiceThirdTest, StopUser_001, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest StopUser_001 start"); auto abilityMs_ = std::make_shared(); - EXPECT_EQ(abilityMs_->StopUser(USER_ID_U100, nullptr), CHECK_PERMISSION_FAILED); + EXPECT_EQ(abilityMs_->StopUser(USER_ID_U100, nullptr), INVALID_PARAMETERS_ERR); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest StopUser_001 end"); } diff --git a/test/unittest/ability_manager_service_third_test/abilitymgr.gni b/test/unittest/ability_manager_service_third_test/abilitymgr.gni index f8f156ed39877a47bee5aa565427f0557e65d1c5..e44e4c2226529b5a1b33ba839416ad1a8f7c1068 100644 --- a/test/unittest/ability_manager_service_third_test/abilitymgr.gni +++ b/test/unittest/ability_manager_service_third_test/abilitymgr.gni @@ -99,10 +99,6 @@ abilityms_files = [ "${ability_runtime_services_path}/abilitymgr/src/connection_state_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/dlp_state_item.cpp", - #multi user - "${ability_runtime_services_path}/abilitymgr/src/user_controller.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_event_handler.cpp", - #free_install "${ability_runtime_services_path}/abilitymgr/src/atomic_service_status_callback_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/atomic_service_status_callback_stub.cpp", diff --git a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn index b9601ffea2a72348bc38d38b98cfeb222ad407f7..0ec66c91b9f8ce5859d05fb611051c251789012e 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn @@ -177,8 +177,6 @@ ohos_unittest("ability_manager_service_thirteenth_test") { "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record_factory.cpp", "${ability_runtime_services_path}/abilitymgr/src/user_callback_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_controller.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_event_handler.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/ability_permission_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/app_mgr_util.cpp", @@ -265,6 +263,7 @@ ohos_unittest("ability_manager_service_thirteenth_test") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp b/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp index 7307f4fbb3c2015934a4335a8d2401ca27511587..ec24763cb5696e147d80a85fa3c92a98850210f1 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp @@ -1958,7 +1958,7 @@ HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesInterceptorCheck_0 MyStatus::GetInstance().permPermission_ = true; want.SetElementName("com.ohos.test", "MainAbility"); - EXPECT_EQ(abilityMs_->StartUIAbilitiesInterceptorCheck(want, abilityRequest, callerToken, appIndex), + EXPECT_EQ(abilityMs_->StartUIAbilitiesInterceptorCheck(want, abilityRequest, callerToken, appIndex, userId), START_UI_ABILITIES_INTERCEPTOR_CHECK_FAILED); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesInterceptorCheck_001 end"); diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp index 09d0b3adda34b52e16db9d8f3517a5969801674f..44f449932ec4f4ef8b1b0b46278da1423096eeb2 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp @@ -308,8 +308,6 @@ bool AppScheduler::IsAttachDebug(const std::string &bundleName) return 0; } -void AppScheduler::SetCurrentUserId(const int32_t userId) {} - void AppScheduler::OnCacheExitInfo(uint32_t accessTokenId, const AppExecFwk::RunningProcessInfo &exitInfo, const std::string &bundleName, const std::vector &abilityNames, const std::vector &uiExtensionNames) {} diff --git a/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp index df381738fd94ca836b87a4932912b05ecb8e30cf..72f695170bacb323daab7ee39dd1ed55cae9feae 100644 --- a/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp +++ b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp @@ -545,8 +545,8 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, StartUser_001, TestSize.Level1) int userId = 0; sptr callback = new MockIUserCallback(); bool isAppRecovery = false; - auto retCode = abilityMs_->StartUser(userId, callback, isAppRecovery); - EXPECT_EQ(retCode, CHECK_PERMISSION_FAILED); + auto retCode = abilityMs_->StartUser(userId, 0, callback, isAppRecovery); + EXPECT_EQ(retCode, INVALID_USERID_VALUE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_001 end"); } @@ -622,8 +622,6 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, IsSceneBoardReady_001, TestSize.Level int32_t userId = -1; auto abilityMs = std::make_shared(); EXPECT_NE(abilityMs, nullptr); - abilityMs->userController_ = std::make_shared(); - EXPECT_NE(abilityMs->userController_, nullptr); abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); EXPECT_NE(abilityMs->subManagersHelper_, nullptr); bool result = abilityMs->IsSceneBoardReady(userId); @@ -644,7 +642,6 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, IsSceneBoardReady_002, TestSize.Level int32_t userId = 100; auto abilityMs = std::make_shared(); EXPECT_NE(abilityMs, nullptr); - abilityMs->userController_ = nullptr; abilityMs->subManagersHelper_ = nullptr; bool result = abilityMs->IsSceneBoardReady(userId); EXPECT_FALSE(result); diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index cc1dac2376ae126c490d7cac1f1e7a74834e13f6..57e9c0b150cf492554edd9edefc61a064c6587e7 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -283,7 +283,7 @@ public: { return 0; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index f87fe1e2e185211b62e2a68ebf8044e52c957bf4..d49976677579eb11df1967f1d38beb260edee4a0 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -223,7 +223,7 @@ public: return 0; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ability_record_test/BUILD.gn b/test/unittest/ability_record_test/BUILD.gn index 71eca609330643d4a4e7f7fbe55364bc13999d8b..ca758fc3974b8dff1b356755c551e70ca1681d15 100644 --- a/test/unittest/ability_record_test/BUILD.gn +++ b/test/unittest/ability_record_test/BUILD.gn @@ -191,7 +191,10 @@ ohos_unittest("ability_record_test_call") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libwm", + "window_manager:libwsutils", + ] } cflags_cc = [] if (os_dlp_part_enabled) { diff --git a/test/unittest/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index 7064b15201a53c9f35327d0bf5871ab0138e5b1f..2443ba8cfcd63664366f3070bc193b1dff1d490a 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -68,6 +68,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -106,7 +107,11 @@ ohos_unittest("AmsAbilityRunningRecordTest") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libdm", + "window_manager:libwm", + "window_manager:libwsutils", + ] } if (ability_runtime_upms) { deps += [ diff --git a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp index d598487038e3e7a665ff5d08e661065b23fcf905..05f2d875821c3235f608c2f1b644b7c3417496e9 100644 --- a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp +++ b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp @@ -850,34 +850,6 @@ HWTEST_F(AmsMgrSchedulerTest, NotifyAppMgrRecordExitReason_001, TestSize.Level2) EXPECT_NE(res2, ERR_INVALID_OPERATION); } -/** - * @tc.name: SetCurrentUserId_002 - * @tc.desc: set current userId. - * @tc.type: FUNC - */ -HWTEST_F(AmsMgrSchedulerTest, SetCurrentUserId_002, TestSize.Level2) -{ - auto amsMgrScheduler = std::make_unique(nullptr, nullptr); - amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); - ASSERT_NE(amsMgrScheduler, nullptr); - int userId = 1; - amsMgrScheduler->SetCurrentUserId(userId); -} - -/** - * @tc.name: SetCurrentUserId_001 - * @tc.desc: set current userId. - * @tc.type: FUNC - */ -HWTEST_F(AmsMgrSchedulerTest, SetCurrentUserId_001, TestSize.Level2) -{ - auto amsMgrScheduler = std::make_unique(nullptr, nullptr); - ASSERT_NE(amsMgrScheduler, nullptr); - int userId = 1; - amsMgrScheduler->SetCurrentUserId(userId); -} - /** * @tc.name: RegisterAppDebugListener_001 * @tc.desc: Test the state of RegisterAppDebugListener diff --git a/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/test/unittest/ams_service_load_ability_process_test/BUILD.gn index 8ceefa8055c7d923c4ebc6224413b0caf76bb508..a5e51fd131d1c360d92c52ec002fce6f05abe52c 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -77,6 +77,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -121,6 +122,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { } if (ability_runtime_graphics) { external_deps += [ + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/ams_service_startup_test/BUILD.gn b/test/unittest/ams_service_startup_test/BUILD.gn index 1ba09810280931b979425742af54467ae8f5d225..7af0586e5dd03ebea29b2291cb4e324c06fcdec7 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -69,6 +69,7 @@ ohos_unittest("AmsServiceStartupTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -109,7 +110,11 @@ ohos_unittest("AmsServiceStartupTest") { ] } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libdm", + "window_manager:libwm", + "window_manager:libwsutils", + ] } if (ability_runtime_upms) { deps += [ 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 ebb83ac745756b5bab8c4c3fc7386cab949d2a29..e5b715445debe7e9eb183197f323b10a049a7819 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 @@ -647,23 +647,6 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_StartRenderProcess_001, TestSize.Level2) EXPECT_EQ(ret, ERROR_STATE); } -/** - * @tc.name: AppMgrClient_SetCurrentUserId_001 - * @tc.desc: set current userId. - * @tc.type: FUNC - */ -HWTEST_F(AppMgrClientTest, AppMgrClient_SetCurrentUserId_001, TestSize.Level2) -{ - auto appMgrClient = std::make_unique(); - EXPECT_NE(appMgrClient, nullptr); - - auto result = appMgrClient->ConnectAppMgrService(); - EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); - - int32_t userId = 0; - appMgrClient->SetCurrentUserId(userId); -} - /** * @tc.name: AppMgrClient_UpdateApplicationInfoInstalled_001 * @tc.desc: UpdateApplicationInfoInstalled. diff --git a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index f10ab814e2e7a9227e83a473b61b8ca99d567b81..32bd151db7c85442db72922356191279c11d700a 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -73,6 +73,7 @@ ohos_unittest("AMSEventHandlerTest") { "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -119,6 +120,7 @@ ohos_unittest("AMSEventHandlerTest") { } if (ability_runtime_graphics) { external_deps += [ + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/app_mgr_service_fourth_test/BUILD.gn b/test/unittest/app_mgr_service_fourth_test/BUILD.gn index 3acb0107ed8c1dcc4961c14d323eb66a78326b68..0c4e8e0b2c8ca0f0a2ce7c91ae17ce192fc5feb8 100644 --- a/test/unittest/app_mgr_service_fourth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_fourth_test/BUILD.gn @@ -63,6 +63,7 @@ ohos_unittest("app_mgr_service_fourth_test") { "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -91,6 +92,7 @@ ohos_unittest("app_mgr_service_fourth_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "selinux_adapter:librestorecon", + "window_manager:libdm", ] defines = [] diff --git a/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn index 136073f96b8d6f709f71467ef183ca64947c4ce9..c3d4bdc8e4bb4e987abb489b1bfa6f4c1828506c 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn @@ -105,6 +105,7 @@ ohos_unittest("app_mgr_service_inner_eighth_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -152,6 +153,7 @@ ohos_unittest("app_mgr_service_inner_eighth_test") { defines += [ "SUPPORT_GRAPHICS" ] external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp index cd20ab636696135ab78bdbc83c33f9fd60cc25cd..8289a9341f5a4847f749be18549576d6d2b014bd 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp @@ -587,54 +587,6 @@ HWTEST_F(AppMgrServiceInnerEighthTest, StartNativeProcessForDebugger_006, TestSi TAG_LOGI(AAFwkTag::TEST, "StartNativeProcessForDebugger_006 end"); } -/** - * @tc.name: GetCurrentAccountId_001 - * @tc.desc: test GetCurrentAccountId_001 - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerEighthTest, GetCurrentAccountId_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_001 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().queryActiveOsAccountIds_ = ERR_NO_INIT; - - auto ret = appMgrServiceInner->GetCurrentAccountId(); - EXPECT_EQ(ret, DEFAULT_USER_ID); - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_001 end"); -} - -/** - * @tc.name: GetCurrentAccountId_002 - * @tc.desc: test GetCurrentAccountId_002 - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerEighthTest, GetCurrentAccountId_002, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_002 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().queryActiveOsAccountIds_ = ERR_OK; - - auto ret = appMgrServiceInner->GetCurrentAccountId(); - EXPECT_EQ(ret, DEFAULT_USER_ID); - TAG_LOGI(AAFwkTag::TEST, "GetCurrentAccountId_002 end"); -} - -/** - * @tc.name: SetCurrentUserId_001 - * @tc.desc: test SetCurrentUserId_001 - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerEighthTest, SetCurrentUserId_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "SetCurrentUserId_001 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().getCallingUid_ = FOUNDATION_UID; - - appMgrServiceInner->SetCurrentUserId(2); - EXPECT_EQ(appMgrServiceInner->currentUserId_, 2); - TAG_LOGI(AAFwkTag::TEST, "SetCurrentUserId_001 end"); -} - /** * @tc.name: GetRunningProcessInformation_001 * @tc.desc: test GetRunningProcessInformation_001 diff --git a/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn index 0ad3739a084add947741d41ba8114a71778b38aa..98c1013fa4720745520b427bae038c8963170342 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_ninth_test/BUILD.gn @@ -104,6 +104,7 @@ ohos_unittest("app_mgr_service_inner_ninth_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -142,6 +143,7 @@ ohos_unittest("app_mgr_service_inner_ninth_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "selinux_adapter:librestorecon", + "window_manager:libdm", "window_manager:session_manager_lite", ] defines = [] diff --git a/test/unittest/app_mgr_service_inner_ninth_test/app_mgr_service_inner_ninth_test.cpp b/test/unittest/app_mgr_service_inner_ninth_test/app_mgr_service_inner_ninth_test.cpp index 2f10f7d2899d08ff941c3f1c8088b1c9df3f95ec..811497b32959d190e251f98f734b9f2bce8a23d6 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/app_mgr_service_inner_ninth_test.cpp +++ b/test/unittest/app_mgr_service_inner_ninth_test/app_mgr_service_inner_ninth_test.cpp @@ -196,7 +196,6 @@ HWTEST_F(AppMgrServiceInnerNinthTest, PreloadApplication_003, TestSize.Level1) AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = true; AAFwk::MyStatus::GetInstance().isSACall_ = true; appMgrServiceInner->appPreloader_ = nullptr; - appMgrServiceInner->currentUserId_ = 200; std::string bundleName = "com.test.preload"; int32_t userId = -2; // CURRENT_USER_ID diff --git a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp index 02644d80fb54e3b36bfdf16cfee2d159424b5b68..586eb987047b26d739655cddb319b0fc73fc95d6 100644 --- a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp +++ b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp @@ -474,7 +474,8 @@ HWTEST_F(AppMgrServiceInnerSecondTest, GetAllRunningInstanceKeysByBundleName_010 EXPECT_NE(appMgrServiceInner, nullptr); std::string bundleName = "testBundleName"; std::vector instanceKeys; - auto ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + int32_t userId = 100; + auto ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_NE(ret, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_0100 end"); } @@ -1229,14 +1230,15 @@ HWTEST_F(AppMgrServiceInnerSecondTest, GetAllRunningInstanceKeysByBundleName_100 std::string bundleName = ""; std::vector instanceKeys; auto appMgrServiceInner = std::make_shared(); - auto res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + int32_t userId = 100; + auto res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(res, AAFwk::INVALID_PARAMETERS_ERR); bundleName = TEST_BUNDLE_NAME; appMgrServiceInner->remoteClientManager_ = nullptr; - res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(res, ERR_INVALID_VALUE); appMgrServiceInner->remoteClientManager_ = std::make_shared(); - res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + res = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_GetAllRunningInstanceKeysByBundleName_1000 end"); } @@ -1602,7 +1604,6 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_ClearAppRunn appRecord->SetUid(uid); appMgrServiceInner->ClearAppRunningDataForKeepAlive(appRecord); - appMgrServiceInner->currentUserId_ = 1; appMgrServiceInner->ClearAppRunningDataForKeepAlive(appRecord); appMgrServiceInner->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("AppMgrServiceInnerSecondTest"); diff --git a/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn b/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn index b5a2dfff8d49a54ae944140dfaec6392041c32a4..c81ab32d022fb610f69b944f1042c7c99a08aa65 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_seventh_test/BUILD.gn @@ -104,6 +104,7 @@ ohos_unittest("app_mgr_service_inner_seventh_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -150,6 +151,7 @@ ohos_unittest("app_mgr_service_inner_seventh_test") { defines += [ "SUPPORT_GRAPHICS" ] external_deps += [ "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp b/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp index 103ea96ebb63cb94e3a1eb01cc42f30475d1edab..601795cda918e45217fb9dedb8091e350b59d182 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp +++ b/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp @@ -470,7 +470,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetRunningProcessesByBundleType_001, Tes const std::shared_ptr>(0, appRecord)); AAFwk::MyStatus::GetInstance().getAppRunningRecordMap_.insert(std::pair>(1, appRecord2)); - appMgrServiceInner->currentUserId_ = 1; BundleType bundleType = BundleType::APP; std::vector info; @@ -496,7 +495,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetRunningProcessesByBundleType_002, Tes AAFwk::MyStatus::GetInstance().getAppRunningRecordMap_.clear(); AAFwk::MyStatus::GetInstance().getAppRunningRecordMap_.insert(std::pair>(1, appRecord2)); - appMgrServiceInner->currentUserId_ = 1; BundleType bundleType = BundleType::APP; std::vector info; @@ -523,7 +521,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetRunningProcessesByBundleType_003, Tes appRecord2->SetUid(200000); AAFwk::MyStatus::GetInstance().getAppRunningRecordMap_.insert(std::pair>(1, appRecord2)); - appMgrServiceInner->currentUserId_ = 1; BundleType bundleType = BundleType::APP; std::vector info2; @@ -542,43 +539,24 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_00 TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; - - std::string bundleName = ""; - std::vector instanceKeys; - int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); - EXPECT_EQ(ret, ERR_PERMISSION_DENIED); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 end"); -} - -/** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_001 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_001 -* @tc.type: FUNC -*/ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_001, TestSize.Level1) -{ - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_001 start"); - auto appMgrServiceInner = std::make_shared(); - AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = nullptr; std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_INVALID_VALUE); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_001 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_002 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_002 +* @tc.name: GetAllRunningInstanceKeysByBundleName_002 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_002 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_002, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_002, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_002 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_002 start"); auto appMgrServiceInner = std::make_shared(); appMgrServiceInner->appRunningManager_ = nullptr; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -591,19 +569,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_INVALID_VALUE); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_002 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_002 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_003 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_003 +* @tc.name: GetAllRunningInstanceKeysByBundleName_003 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_003 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_003, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_003, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_003 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_003 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -614,19 +592,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_MULTI_INSTANCE_NOT_SUPPORTED); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_003 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_003 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_004 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_004 +* @tc.name: GetAllRunningInstanceKeysByBundleName_004 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_004 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_004, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_004, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_004 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_004 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -640,19 +618,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_004 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_004 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_005 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_005 +* @tc.name: GetAllRunningInstanceKeysByBundleName_005 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_005 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_005, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_005, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_005 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_005 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -670,19 +648,19 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; int32_t userId = 0; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_005 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_005 end"); } /** -* @tc.name: GetAllRunningInstanceKeysByBundleNameInner_006 -* @tc.desc: test GetAllRunningInstanceKeysByBundleNameInner_006 +* @tc.name: GetAllRunningInstanceKeysByBundleName_006 +* @tc.desc: test GetAllRunningInstanceKeysByBundleName_006 * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInner_006, TestSize.Level1) +HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleName_006, TestSize.Level1) { - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_006 start"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_006 start"); auto appMgrServiceInner = std::make_shared(); AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = false; AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); @@ -699,10 +677,10 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetAllRunningInstanceKeysByBundleNameInn std::string bundleName = "111"; std::vector instanceKeys; - int32_t userId = 1; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleNameInner(bundleName, instanceKeys, userId); + int32_t userId = 100; + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_EQ(ret, ERR_OK); - TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleNameInner_006 end"); + TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_006 end"); } /** @@ -714,7 +692,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetProcessRunningInfosByUserId_001, Test { TAG_LOGI(AAFwkTag::TEST, "GetProcessRunningInfosByUserId_001 start"); auto appMgrServiceInner = std::make_shared(); - appMgrServiceInner->currentUserId_ = 0; std::shared_ptr info = std::make_shared(); std::string temp = ""; auto appRecord2 = std::make_shared(info, 0, temp); @@ -740,7 +717,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetProcessRunningInfosByUserId_002, Test { TAG_LOGI(AAFwkTag::TEST, "GetProcessRunningInfosByUserId_002 start"); auto appMgrServiceInner = std::make_shared(); - appMgrServiceInner->currentUserId_ = 0; AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = true; AAFwk::MyStatus::GetInstance().getAppRunningRecordMap_.insert(std::pair>(1, nullptr)); @@ -761,7 +737,6 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetProcessRunningInfosByUserId_003, Test { TAG_LOGI(AAFwkTag::TEST, "GetProcessRunningInfosByUserId_003 start"); auto appMgrServiceInner = std::make_shared(); - appMgrServiceInner->currentUserId_ = 0; AAFwk::MyStatus::GetInstance().verifyCallingPermission_ = true; std::shared_ptr info = std::make_shared(); std::string temp = ""; diff --git a/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn index e8bb5daeb20988e74b8d22b65a1f4c320d5e4761..73f0921899cd2e10f5be4e90da3bc46a06d7fe9b 100644 --- a/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_tenth_test/BUILD.gn @@ -109,6 +109,7 @@ ohos_unittest("app_mgr_service_inner_tenth_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -146,6 +147,7 @@ ohos_unittest("app_mgr_service_inner_tenth_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "selinux_adapter:librestorecon", + "window_manager:libdm", "window_manager:session_manager_lite", ] defines = [] 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 726854bd4782e4c589cc1ce50603324f213efff8..7c82bdb9603e3993e1fe6ce08930afbdfd041355 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 @@ -4254,24 +4254,6 @@ HWTEST_F(AppMgrServiceInnerTest, NotifyUnLoadRepairPatch_001, TestSize.Level2) TAG_LOGI(AAFwkTag::TEST, "NotifyUnLoadRepairPatch_001 end"); } -/** - * @tc.name: SetCurrentUserId_001 - * @tc.desc: set current userId. - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerTest, SetCurrentUserId_001, TestSize.Level2) -{ - TAG_LOGI(AAFwkTag::TEST, "SetCurrentUserId_001 start"); - auto appMgrServiceInner = std::make_shared(); - EXPECT_NE(appMgrServiceInner, nullptr); - - int userId = 0; - appMgrServiceInner->SetCurrentUserId(userId); - EXPECT_EQ(appMgrServiceInner->currentUserId_, userId); - - TAG_LOGI(AAFwkTag::TEST, "SetCurrentUserId_001 end"); -} - /** * @tc.name: GetProcessMemoryByPid_001 * @tc.desc: Get memorySize by pid. @@ -5666,7 +5648,8 @@ HWTEST_F(AppMgrServiceInnerTest, GetAllRunningInstanceKeysByBundleName_001, Test std::string bundleName = "testBundleName"; std::vector instanceKeys; - int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + int32_t userId = 100; + int32_t ret = appMgrServiceInner->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); EXPECT_NE(ret, ERR_OK); TAG_LOGI(AAFwkTag::TEST, "GetAllRunningInstanceKeysByBundleName_001 end"); diff --git a/test/unittest/app_scheduler_test/app_scheduler_test.cpp b/test/unittest/app_scheduler_test/app_scheduler_test.cpp index 6e21a19bd8cb9a4f9238934ad613125326fe76f6..4f17e2479e20eb8e348e4bb0c5f6acacc6f93a6c 100644 --- a/test/unittest/app_scheduler_test/app_scheduler_test.cpp +++ b/test/unittest/app_scheduler_test/app_scheduler_test.cpp @@ -1045,19 +1045,6 @@ HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_002, TestSi DelayedSingleton::GetInstance()->appMgrClient_.reset(); } -/** - * @tc.name: SetCurrentUserId_001 - * @tc.desc: set current userId. - * @tc.type: FUNC - */ -HWTEST_F(AppSchedulerTest, AppScheduler_SetCurrentUserId_001, TestSize.Level1) -{ - int32_t userId = 0; - DelayedSingleton::GetInstance()->appMgrClient_ = std::make_unique(); - ASSERT_NE(DelayedSingleton::GetInstance()->appMgrClient_, nullptr); - DelayedSingleton::GetInstance()->SetCurrentUserId(userId); -} - /** * @tc.name: AppScheduler_NotifyFault_001 * @tc.desc: Verify that the NotifyFault interface calls normally diff --git a/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h index a1966874fbb4e2074449349d2289c9bd55e54d72..5a830a131565e2890e3888366505aafdd415b0e0 100644 --- a/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h @@ -194,7 +194,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/cache_process_manager_second_test/BUILD.gn b/test/unittest/cache_process_manager_second_test/BUILD.gn index 7e9b86f4e81eb22aa31d365428f8a6a681d1f961..855c317480d3f8378ce497385c94285ebaccea66 100644 --- a/test/unittest/cache_process_manager_second_test/BUILD.gn +++ b/test/unittest/cache_process_manager_second_test/BUILD.gn @@ -118,6 +118,7 @@ ohos_unittest("cache_process_manager_second_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ @@ -183,6 +184,7 @@ ohos_unittest("cache_process_manager_second_test") { external_deps += [ "i18n:i18n_sa_client", "i18n:intl_util", + "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/data_ability_manager_test/BUILD.gn b/test/unittest/data_ability_manager_test/BUILD.gn index 2596754c4780c6b1778a2eab8691c50836d7eedd..ec2e38e20aa874d15c7945f685b75951145cb631 100644 --- a/test/unittest/data_ability_manager_test/BUILD.gn +++ b/test/unittest/data_ability_manager_test/BUILD.gn @@ -93,7 +93,10 @@ ohos_unittest("data_ability_manager_test") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libwm", + "window_manager:libwsutils", + ] } cflags_cc = [] diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp index b46525e93d3065adb8f5a5deb98d7f7556b60099..ad8fa786874f3fac1a4d108c3ee631544459503a 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp @@ -564,7 +564,8 @@ ErrCode AbilityManagerClient::StopSyncRemoteMissions(const std::string &devId) return ERR_OK; } -ErrCode AbilityManagerClient::StartUser(int accountId, sptr callback, bool isAppRecovery) +ErrCode AbilityManagerClient::StartUser(int accountId, uint64_t displayId, sptr callback, + bool isAppRecovery) { return ERR_OK; } diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_connection_manager_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_connection_manager_test.cpp index f42fdc0bd17c6684e0aa32fd4b23fda8b588fa5c..4fd734eb60964c131666baa9fc020c4204f9ba20 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_connection_manager_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_connection_manager_test.cpp @@ -583,7 +583,7 @@ HWTEST_F(ConnectionManagerTest, CreateConnection_0100, TestSize.Level1) int32_t accountId = 0; sptr connectCallback = new (std::nothrow) MockAbilityConnectCallback(); auto result = mgr->CreateConnection(connectCallernew, want, accountId, connectCallback); - EXPECT_EQ(result, AAFwk::CHECK_PERMISSION_FAILED); + EXPECT_EQ(result, AAFwk::RESOLVE_ABILITY_ERR); GTEST_LOG_(INFO) << "ConnectionManagerTest CreateConnection_0100 end"; } diff --git a/test/unittest/keep_alive_process_manager_test/BUILD.gn b/test/unittest/keep_alive_process_manager_test/BUILD.gn index 4e06139b9962421e68eb521ccbe2ef3ff027913c..471bb1d7ed8d448aa421c191a4a18d561c43a744 100644 --- a/test/unittest/keep_alive_process_manager_test/BUILD.gn +++ b/test/unittest/keep_alive_process_manager_test/BUILD.gn @@ -47,7 +47,10 @@ ohos_unittest("keep_alive_process_manager_test") { if (target_cpu == "arm") { cflags += [ "-DBINDER_IPC_32BIT" ] } - deps = [ "${ability_runtime_services_path}/abilitymgr:abilityms" ] + deps = [ + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:user_controller", + ] external_deps = [ "ability_base:base", diff --git a/test/unittest/keep_alive_process_manager_test/mock/include/ability_manager_service.h b/test/unittest/keep_alive_process_manager_test/mock/include/ability_manager_service.h index 4fe12fc613fa16f687f83120742603f05edc6f24..39ead614c364513fb6923e393ff13424a1c1b51c 100644 --- a/test/unittest/keep_alive_process_manager_test/mock/include/ability_manager_service.h +++ b/test/unittest/keep_alive_process_manager_test/mock/include/ability_manager_service.h @@ -50,12 +50,6 @@ public: bool IsSceneBoardReady(int32_t userId); - /** - * get the user id. - * - */ - int32_t GetUserId() const; - /** * Starts a new ability with specific start options. * diff --git a/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp b/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp index dffa2d0e0cda6546d98e18ba557f39585e41ba07..5a8253017a1ae90daa73495cba8a185a1eef2d21 100644 --- a/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp +++ b/test/unittest/keep_alive_process_manager_test/mock/src/ability_manager_service.cpp @@ -56,11 +56,6 @@ bool AbilityManagerService::IsSceneBoardReady(int32_t userId) return isSceneBoardReadyResult; } -int32_t AbilityManagerService::GetUserId() const -{ - return userId_; -} - int32_t AbilityManagerService::StartAbility(const Want &want, const StartOptions &startOptions, const sptr &callerToken, int32_t userId, int requestCode) { diff --git a/test/unittest/resident_process_manager_test/resident_process_manager_test.cpp b/test/unittest/resident_process_manager_test/resident_process_manager_test.cpp index 32e8f94af1549fd885c077d061002ab83fede214..f0ea9afda9d6b01c5026864239c4d02ccddac2cb 100755 --- a/test/unittest/resident_process_manager_test/resident_process_manager_test.cpp +++ b/test/unittest/resident_process_manager_test/resident_process_manager_test.cpp @@ -21,7 +21,6 @@ #undef private #undef protected #include "ability_manager_service.h" -#include "user_controller.h" #include "ability_resident_process_rdb.h" using namespace testing; diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h index a1966874fbb4e2074449349d2289c9bd55e54d72..5a830a131565e2890e3888366505aafdd415b0e0 100644 --- a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -194,7 +194,7 @@ public: return; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h index 7085639344e10e2c618f123b45db99f1b5028a87..d7dc02281d97519b095f9516c8f9ceeaf726bbe0 100644 --- a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -151,7 +151,7 @@ public: MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; } diff --git a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn index dafdb7a015ff2e5e1a94a0f17689d763059b717c..9b0f8420e7892537b245471ff5debbedab4282fa 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn @@ -66,6 +66,7 @@ ohos_unittest("ui_ability_lifecycle_manager_test") { "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:record_cost_time_util", "${ability_runtime_services_path}/common:task_handler_wrap", + "${ability_runtime_services_path}/common:user_controller", ] external_deps = [ diff --git a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp index ff84703e081d7e25da4dca4caca3097ac31e8cc0..0f44336760dd6fd33697189d910eeaa7186e7f81 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp @@ -36,6 +36,7 @@ #include "ability_scheduler_mock.h" #include "ipc_skeleton.h" #include "status_bar_delegate_interface.h" +#include "user_controller/user_controller.h" using namespace testing; using namespace testing::ext; @@ -3162,7 +3163,7 @@ HWTEST_F(UIAbilityLifecycleManagerTest, GetActiveAbilityList_002, TestSize.Level abilityRequest.abilityInfo.bundleName = "com.example.unittest"; abilityRequest.abilityInfo.applicationInfo.uid = TEST_UID; auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); - abilityRecord->SetOwnerMissionUserId(DelayedSingleton::GetInstance()->GetUserId()); + abilityRecord->SetOwnerMissionUserId(AbilityRuntime::UserController::GetInstance().GetCallerUserId()); uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord); std::vector abilityList; int32_t pid = 100; diff --git a/test/unittest/user_controller_test/BUILD.gn b/test/unittest/user_controller_test/BUILD.gn deleted file mode 100644 index 0fbe66cd0d182a729c556b18cfd7cbfd1a33a755..0000000000000000000000000000000000000000 --- a/test/unittest/user_controller_test/BUILD.gn +++ /dev/null @@ -1,62 +0,0 @@ -# Copyright (c) 2022-2024 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. - -import("//build/test.gni") -import("//foundation/ability/ability_runtime/ability_runtime.gni") - -module_output_path = "ability_runtime/ability_runtime/abilitymgr" - -ohos_unittest("user_controller_test") { - module_out_path = module_output_path - - sources = [ "user_controller_test.cpp" ] - - configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] - - deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_services_path}/abilitymgr:abilityms", - "${ability_runtime_services_path}/common:perm_verification", - ] - - external_deps = [ - "ability_base:session_info", - "ability_base:want", - "ability_runtime:ability_deps_wrapper", - "ability_runtime:app_manager", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", - "ffrt:libffrt", - "hilog:libhilog", - "hisysevent:libhisysevent", - "image_framework:image_native", - "ipc:ipc_core", - "safwk:api_cache_manager", - ] - - if (ability_runtime_graphics) { - external_deps += [ - "window_manager:libwsutils", - "window_manager:scene_session", - ] - } -} - -group("unittest") { - testonly = true - - deps = [ ":user_controller_test" ] -} diff --git a/test/unittest/user_controller_test/user_controller_test.cpp b/test/unittest/user_controller_test/user_controller_test.cpp deleted file mode 100644 index e848adeb87c8dd41b12dfce86e19fdf996878ade..0000000000000000000000000000000000000000 --- a/test/unittest/user_controller_test/user_controller_test.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/* - * Copyright (c) 2022 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 - -#define private public -#include "ability_manager_service.h" -#include "user_controller.h" -#undef private -#include "scene_board_judgement.h" -#include "user_callback_stub.h" -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace AAFwk { -class UserControllerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; -}; - -void UserControllerTest::SetUpTestCase() -{ - auto abilityMs = OHOS::DelayedSingleton::GetInstance(); - AmsConfigurationParameter::GetInstance().Parse(); -} - -void UserControllerTest::TearDownTestCase() -{} - -void UserControllerTest::SetUp() -{} - -void UserControllerTest::TearDown() -{} - -class TestUserCallback : public UserCallbackStub { -public: - void OnStopUserDone(int userId, int errcode) override; - void OnStartUserDone(int userId, int errcode) override; - void OnLogoutUserDone(int userId, int errcode) override; - - int errCode_ = -1; -}; - -void TestUserCallback::OnStartUserDone(int userId, int errcode) -{ - errCode_ = errcode; -} - -void TestUserCallback::OnStopUserDone(int userId, int errcode) {} - -void TestUserCallback::OnLogoutUserDone(int userId, int errcode) {} - -/** - * @tc.name: UserItemSetState_0100 - * @tc.desc: UserItemSetState Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, UserItemSetState_0100, TestSize.Level1) -{ - UserItem item(100); - item.SetState(UserState::STATE_BOOTING); - EXPECT_TRUE(item.GetState() == UserState::STATE_BOOTING); - - item.SetState(UserState::STATE_STARTED); - EXPECT_TRUE(item.GetState() == UserState::STATE_STARTED); -} - -/** - * @tc.name: StartUserTest_0100 - * @tc.desc: StartUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, StartUserTest_0100, TestSize.Level0) -{ - UserController userController; - userController.GetOrCreateUserItem(1000); - userController.SetCurrentUserId(1000); - sptr callback = new TestUserCallback(); - userController.StartUser(1000, callback); - EXPECT_TRUE(callback->errCode_ == 0); -} - -/** - * @tc.name: StartUserTest_0200 - * @tc.desc: StartUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, StartUserTest_0200, TestSize.Level0) -{ - UserController userController; - sptr callback = new TestUserCallback(); - userController.StartUser(666, callback); - EXPECT_TRUE(callback->errCode_ != 0); -} - -/** - * @tc.name: StartNoHeadUser_0100 - * @tc.desc: StartNoHeadUser Test - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(UserControllerTest, StartNoHeadUser_0100, TestSize.Level0) -{ - UserController userController; - sptr callback = new TestUserCallback(); - int32_t userId = 666; - auto ret = userController.StartNoHeadUser(userId, callback); - EXPECT_EQ(ret, INVALID_USERID_VALUE); -} - -/** - * @tc.name: StartNoHeadUser_0200 - * @tc.desc: StartNoHeadUser Test - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(UserControllerTest, StartNoHeadUser_0200, TestSize.Level0) -{ - UserController userController; - sptr callback = new TestUserCallback(); - int32_t userId = 100; - auto ret = userController.StartNoHeadUser(userId, callback); - EXPECT_EQ(ret, ERR_OK); -} - -/** - * @tc.name: StopUserTest_0100 - * @tc.desc: StopUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, StopUserTest_0100, TestSize.Level0) -{ - UserController userController; - userController.StopUser(-1); - userController.StopUser(0); - EXPECT_TRUE(userController.StopUser(100) == -1); -} - -/** - * @tc.name: StopUserTest_0200 - * @tc.desc: StopUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, StopUserTest_0200, TestSize.Level0) -{ - UserController userController; - EXPECT_TRUE(userController.StopUser(666) == -1); -} - -/** - * @tc.name: StopUserTest_0300 - * @tc.desc: StopUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, StopUserTest_0300, TestSize.Level0) -{ - UserController userController; - userController.GetOrCreateUserItem(1000); - auto result = userController.StopUser(1000); - EXPECT_TRUE(result = 1000); -} - -/** - * @tc.name: LogoutUserTest_0100 - * @tc.desc: LogoutUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, LogoutUserTest_0100, TestSize.Level1) -{ - UserController userController; - auto result = userController.LogoutUser(-1, nullptr); - if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - EXPECT_EQ(result, INVALID_USERID_VALUE); - } - EXPECT_TRUE(userController.GetCurrentUserId() == 0); -} - -/** - * @tc.name: LogoutUserTest_0200 - * @tc.desc: LogoutUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, LogoutUserTest_0200, TestSize.Level1) -{ - UserController userController; - auto result = userController.LogoutUser(666, nullptr); - if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - EXPECT_EQ(result, INVALID_USERID_VALUE); - } - EXPECT_TRUE(userController.GetCurrentUserId() == 0); -} - -/** - * @tc.name: LogoutUserTest_0300 - * @tc.desc: LogoutUser Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, LogoutUserTest_0300, TestSize.Level1) -{ - UserController userController; - userController.GetOrCreateUserItem(1000); - auto result = userController.LogoutUser(1000, nullptr); - EXPECT_TRUE(result != 0); -} - -/** - * @tc.name: HandleContinueUserSwitchTest_0100 - * @tc.desc: HandleContinueUserSwitch Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, HandleContinueUserSwitchTest_0100, TestSize.Level2) -{ - UserController userController; - auto userItem = std::make_shared(1000); - userController.HandleContinueUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendUserSwitchDoneTest_0100 - * @tc.desc: SendUserSwitchDone Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendUserSwitchDoneTest_0100, TestSize.Level2) -{ - UserController userController; - userController.SendUserSwitchDone(1000); - userController.Init(); - userController.SendUserSwitchDone(1001); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendContinueUserSwitchTest_0200 - * @tc.desc: SendContinueUserSwitch Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendContinueUserSwitchTest_0200, TestSize.Level2) -{ - UserController userController; - auto userItem = std::make_shared(1000); - userController.SendContinueUserSwitch(1000, 1000, userItem); - userController.Init(); - userController.SendContinueUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendUserSwitchTimeoutTest_0100 - * @tc.desc: SendUserSwitchTimeout Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendUserSwitchTimeoutTest_0100, TestSize.Level2) -{ - UserController userController; - auto userItem = std::make_shared(1000); - userController.SendUserSwitchTimeout(1000, 1000, userItem); - userController.Init(); - userController.SendUserSwitchTimeout(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendReportUserSwitchTest_0100 - * @tc.desc: SendReportUserSwitch Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendReportUserSwitchTest_0100, TestSize.Level2) -{ - UserController userController; - auto userItem = std::make_shared(1000); - userController.SendReportUserSwitch(1000, 1000, userItem); - userController.Init(); - userController.SendReportUserSwitch(1000, 1000, userItem); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendSystemUserCurrentTest_0100 - * @tc.desc: SendSystemUserCurrent Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendSystemUserCurrentTest_0100, TestSize.Level2) -{ - UserController userController; - userController.SendSystemUserCurrent(1000, 1000); - userController.Init(); - userController.SendSystemUserCurrent(1000, 1000); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} - -/** - * @tc.name: SendSystemUserStartTest_0100 - * @tc.desc: SendSystemUserStart Test - * @tc.type: FUNC - * @tc.require: issueI581SE - */ -HWTEST_F(UserControllerTest, SendSystemUserStartTest_0100, TestSize.Level2) -{ - UserController userController; - userController.SendSystemUserStart(1000); - userController.Init(); - userController.SendSystemUserStart(1000); - auto result = userController.GetCurrentUserId(); - EXPECT_TRUE(result == 0); -} -} // namespace AAFwk -} // namespace OHOS diff --git a/test/unittest/user_event_handler_test/BUILD.gn b/test/unittest/user_event_handler_test/BUILD.gn deleted file mode 100755 index bf7e0fee8b31e0e389f5011321f1a600e77189c3..0000000000000000000000000000000000000000 --- a/test/unittest/user_event_handler_test/BUILD.gn +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (c) 2022-2024 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. - -import("//build/test.gni") -import("//foundation/ability/ability_runtime/ability_runtime.gni") - -module_output_path = "ability_runtime/ability_runtime/abilitymgr" - -ohos_unittest("user_event_handler_test") { - module_out_path = module_output_path - - include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock" ] - - sources = [ - "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", - "user_event_handler_test.cpp", # add mock file - ] - - configs = [ - "${ability_runtime_services_path}/abilitymgr:abilityms_config", - "${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config", - ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_native_path}/ability/native:abilitykit_native", - "${ability_runtime_services_path}/abilitymgr:abilityms", - "${ability_runtime_services_path}/common:perm_verification", - "${ability_runtime_services_path}/common:task_handler_wrap", - "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", - "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", - "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", - ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "ffrt:libffrt", - "googletest:gtest_main", - "hilog:libhilog", - "ipc:ipc_core", - "napi:ace_napi", - "samgr:samgr_proxy", - ] - - if (background_task_mgr_continuous_task_enable) { - external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] - } -} - -group("unittest") { - testonly = true - - deps = [ ":user_event_handler_test" ] -} diff --git a/test/unittest/user_event_handler_test/user_event_handler_test.cpp b/test/unittest/user_event_handler_test/user_event_handler_test.cpp deleted file mode 100755 index 687bf3812993e672811e520e33834c6387d015e5..0000000000000000000000000000000000000000 --- a/test/unittest/user_event_handler_test/user_event_handler_test.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022 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 -#define private public -#include "user_event_handler.h" -#undef private - -using namespace testing::ext; - -namespace OHOS { -namespace AAFwk { -class UserEventHandlerTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void UserEventHandlerTest::SetUpTestCase(void) -{} -void UserEventHandlerTest::TearDownTestCase(void) -{} -void UserEventHandlerTest::SetUp(void) -{} -void UserEventHandlerTest::TearDown(void) -{} - -/* - * Feature: UserEventHandler - * Function: ProcessEvent - * SubFunction: NA - * FunctionPoints: UserEventHandler ProcessEvent - * EnvConditions: NA - * CaseDescription: Verify ProcessEvent - */ -HWTEST_F(UserEventHandlerTest, ProcessEvent_001, TestSize.Level1) -{ - std::shared_ptr runner; - std::weak_ptr owner; - std::shared_ptr handler = std::make_shared(runner, owner); - EventWrap event(0); - handler->ProcessEvent(event); - EXPECT_TRUE(handler != nullptr); -} -} // namespace AAFwk -} // namespace OHOS diff --git a/test/unittest/user_record_manager_test/BUILD.gn b/test/unittest/user_record_manager_test/BUILD.gn index 69516d79f8ceea8faba7ada659209fb3c29a236c..33a834a3386bb1f704ecf8971f35f65c3c98b2d2 100644 --- a/test/unittest/user_record_manager_test/BUILD.gn +++ b/test/unittest/user_record_manager_test/BUILD.gn @@ -66,4 +66,4 @@ ohos_unittest("user_record_manager_test") { group("unittest") { testonly = true deps = [ ":user_record_manager_test" ] -} +} \ No newline at end of file diff --git a/test/unittest/user_record_manager_test/user_record_manager_test.cpp b/test/unittest/user_record_manager_test/user_record_manager_test.cpp index 580b9115cff6525a2639f10bf098bf569e48367c..8eb59248eb61d2bba7b4d80342a244347a640133 100644 --- a/test/unittest/user_record_manager_test/user_record_manager_test.cpp +++ b/test/unittest/user_record_manager_test/user_record_manager_test.cpp @@ -71,4 +71,4 @@ HWTEST_F(UserRecordManagerTest, UserRecordManagerTest_002, TestSize.Level1) EXPECT_EQ(userRecordManager->IsLogoutUser(userId), true); } } // namespace AppExecFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 0f0e3a697c58b0d677bd7d6cbdeb62727fccac0f..217fcdc52ded5903a0c51bd5c82d7712ba20bbd4 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -146,7 +146,7 @@ public: return 0; } - int StartUser(int userId, sptr callback, bool isAppRecovery) override + int StartUser(int userId, uint64_t displayId, sptr callback, bool isAppRecovery) override { return 0; }