diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index d1e21a26046850eaa92b032759be33703464638a..bade9dd60fd7401c2d11e57e44812f9a818c0026 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -912,8 +912,25 @@ private: void StartFreezingScreen(); void StopFreezingScreen(); void UserStarted(int32_t userId); - void SwitchToUser(int32_t userId); - void StartLauncherAbility(int32_t userId); + void SwitchToUser(int32_t oldUserId, int32_t userId); + void SwitchManagers(int32_t userId); + void StartUserApps(int32_t userId); + void StartSystemAbilityByUser(int32_t userId); + void PauseOldUser(int32_t userId); + void PauseOldStackManager(int32_t userId); + void PauseOldMissionListManager(int32_t userId); + bool IsSystemUI(const std::string &bundleName) const; + + bool VerificationAllToken(const sptr &token); + bool CheckDataAbilityRequest(AbilityRequest &abilityRequest); + std::shared_ptr GetStackManagerByUserId(int32_t userId); + std::shared_ptr GetListManagerByUserId(int32_t userId); + std::shared_ptr GetConnectManagerByUserId(int32_t userId); + std::shared_ptr GetDataAbilityManagerByUserId(int32_t userId); + std::shared_ptr GetStackManagerByToken(const sptr &token); + std::shared_ptr GetListManagerByToken(const sptr &token); + std::shared_ptr GetConnectManagerByToken(const sptr &token); + std::shared_ptr GetDataAbilityManagerByToken(const sptr &token); using DumpFuncType = void (AbilityManagerService::*)(const std::string &args, std::vector &info); std::map dumpFuncMap_; @@ -932,6 +949,7 @@ private: std::shared_ptr appScheduler_; std::unordered_map> dataAbilityManagers_; std::shared_ptr dataAbilityManager_; + std::shared_ptr systemDataAbilityManager_; std::unordered_map> pendingWantManagers_; std::shared_ptr pendingWantManager_; std::shared_ptr systemAppManager_; diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 8400c826cfb4562628eed69508161e286e485037..20b0bdc8c1f3fdf2b4f0f8b116fbe5f19713d41f 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -737,6 +737,8 @@ public: int GetId() override; void SetUid(int32_t uid); int32_t GetUid(); + void SetSwitchingPause(bool state); + bool IsSwitchingPause(); /** * get the type of ability. @@ -817,6 +819,7 @@ public: std::weak_ptr missionList_; std::weak_ptr mission_; int32_t missionId_ = -1; + bool isSwitchingPause_ = false; int32_t restartCount_ = -1; int32_t restratMax_ = -1; std::string specifiedFlag_; diff --git a/services/abilitymgr/include/ability_stack_manager.h b/services/abilitymgr/include/ability_stack_manager.h index 3e4ef96cc0018a2d7e2a5ea4d192eb6029e69e9f..32553b3b2ef299b49a8e7fe78ed1fc149a84ca6d 100644 --- a/services/abilitymgr/include/ability_stack_manager.h +++ b/services/abilitymgr/include/ability_stack_manager.h @@ -437,6 +437,10 @@ public: int SetShowOnLockScreen(const std::string &bundleName, bool isAllow); void UpdateLockScreenState(bool isLockScreen); + + bool IsStarted(); + void PauseManager(); + void ResumeManager(); private: /** * dispatch ability life cycle . diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index f40e1fd5972bee38d1a1e43c2cd43a2e8047fe76..5c27dab79eca6b90da9df08186de0d07fbcbd5a1 100755 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -280,6 +280,10 @@ public: void GetMissionSnapshot(int32_t missionId, const sptr& abilityToken, MissionSnapshot& missionSnapshot); void GetAbilityRunningInfos(std::vector &info); + + bool IsStarted(); + void PauseManager(); + void ResumeManager(); private: int StartAbilityLocked(const std::shared_ptr ¤tTopAbility, const std::shared_ptr &callerAbility, const AbilityRequest &abilityRequest); @@ -325,6 +329,9 @@ private: void HandleAbilityDiedByDefault(std::shared_ptr abilityRecord); void DelayedStartLauncher(); void BackToLauncher(); + void GetAllForegroundAbilities(std::list>& foregroundList); + void GetForegroundAbilities(const std::shared_ptr& missionList, + std::list>& foregroundList); bool IsPC(); std::shared_ptr GetMissionBySpecifiedFlag(const std::string &flag) const; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 1e2ecf9de5d1f76df058bc3b4e28622772c999bf..77fe550e64c12fe62eeaccb0b5d5de3358f56acf 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -49,6 +49,8 @@ using OHOS::AppExecFwk::ElementName; namespace OHOS { namespace AAFwk { using namespace std::chrono; +const int32_t MAIN_USER_ID = 100; +const int32_t BASE_USER_RANGE = 200000; static const int EXPERIENCE_MEM_THRESHOLD = 20; constexpr auto DATA_ABILITY_START_TIMEOUT = 5s; constexpr int32_t NON_ANONYMIZE_LENGTH = 6; @@ -139,7 +141,7 @@ bool AbilityManagerService::Init() // init user controller. userController_ = std::make_shared(); userController_->Init(); - int userId = GetUserId(); + int userId = MAIN_USER_ID; InitConnectManager(userId, true); @@ -148,6 +150,7 @@ bool AbilityManagerService::Init() InitDataAbilityManager(userId, true); InitPendWantManager(userId, true); + systemDataAbilityManager_ = std::make_shared(); amsConfigResolver_ = std::make_shared(); if (amsConfigResolver_) { @@ -161,11 +164,11 @@ bool AbilityManagerService::Init() GetGlobalConfiguration(); SetStackManager(userId, true); - systemAppManager_ = std::make_shared(userId); + systemAppManager_ = std::make_shared(0); CHECK_POINTER_RETURN_BOOL(systemAppManager_); InitMissionListManager(userId, true); - kernalAbilityManager_ = std::make_shared(userId); + kernalAbilityManager_ = std::make_shared(0); CHECK_POINTER_RETURN_BOOL(kernalAbilityManager_); auto startLauncherAbilityTask = [aams = shared_from_this()]() { aams->StartSystemApplication(); }; @@ -591,7 +594,7 @@ int AbilityManagerService::TerminateAbilityByCaller(const sptr &c int AbilityManagerService::MinimizeAbility(const sptr &token) { HILOG_INFO("Minimize ability."); - if (!VerificationToken(token)) { + if (!VerificationToken(token) && !VerificationAllToken(token)) { return ERR_INVALID_VALUE; } @@ -614,9 +617,13 @@ int AbilityManagerService::MinimizeAbility(const sptr &token) } if (useNewMission_) { - return currentMissionListManager_->MinimizeAbility(token); + auto manager = GetListManagerByToken(token); + CHECK_POINTER_AND_RETURN(manager, ERR_INVALID_VALUE); + return manager->MinimizeAbility(token); } else { - return currentStackManager_->MinimizeAbility(token); + auto manager = GetStackManagerByToken(token); + CHECK_POINTER_AND_RETURN(manager, ERR_INVALID_VALUE); + return manager->MinimizeAbility(token); } } @@ -1338,33 +1345,48 @@ sptr AbilityManagerService::AcquireDataAbility( return nullptr; } + auto userId = GetUserId(); AbilityRequest abilityRequest; std::string dataAbilityUri = localUri.ToString(); - bool queryResult = iBundleManager_->QueryAbilityInfoByUri(dataAbilityUri, abilityRequest.abilityInfo); + HILOG_INFO("%{public}s, called. userId %{public}d", __func__, userId); + bool queryResult = iBundleManager_->QueryAbilityInfoByUri(dataAbilityUri, userId, abilityRequest.abilityInfo); if (!queryResult || abilityRequest.abilityInfo.name.empty() || abilityRequest.abilityInfo.bundleName.empty()) { HILOG_ERROR("Invalid ability info for data ability acquiring."); return nullptr; } + + if (!CheckDataAbilityRequest(abilityRequest)) { + HILOG_ERROR("Invalid ability request info for data ability acquiring."); + return nullptr; + } + + HILOG_DEBUG("Query data ability info: %{public}s|%{public}s|%{public}s", + abilityRequest.appInfo.name.c_str(), + abilityRequest.appInfo.bundleName.c_str(), + abilityRequest.abilityInfo.name.c_str()); + + CHECK_POINTER_AND_RETURN(dataAbilityManager_, nullptr); + return dataAbilityManager_->Acquire(abilityRequest, tryBind, callerToken, isSystem); +} + +bool AbilityManagerService::CheckDataAbilityRequest(AbilityRequest &abilityRequest) +{ int result = AbilityUtil::JudgeAbilityVisibleControl(abilityRequest.abilityInfo); if (result != ERR_OK) { HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__); - return nullptr; + return false; } abilityRequest.appInfo = abilityRequest.abilityInfo.applicationInfo; if (abilityRequest.appInfo.name.empty() || abilityRequest.appInfo.bundleName.empty()) { HILOG_ERROR("Invalid app info for data ability acquiring."); - return nullptr; + return false; } if (abilityRequest.abilityInfo.type != AppExecFwk::AbilityType::DATA) { HILOG_ERROR("BMS query result is not a data ability."); - return nullptr; + return false; } - HILOG_DEBUG("Query data ability info: %{public}s|%{public}s|%{public}s", - abilityRequest.appInfo.name.c_str(), - abilityRequest.appInfo.bundleName.c_str(), - abilityRequest.abilityInfo.name.c_str()); - - return dataAbilityManager_->Acquire(abilityRequest, tryBind, callerToken, isSystem); + abilityRequest.uid = abilityRequest.appInfo.uid; + return true; } int AbilityManagerService::ReleaseDataAbility( @@ -1612,9 +1634,10 @@ int AbilityManagerService::AbilityTransitionDone(const sptr &toke { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_INFO("Ability transition done, state:%{public}d", state); - if (!VerificationToken(token)) { + if (!VerificationToken(token) && !VerificationAllToken(token)) { return ERR_INVALID_VALUE; } + int32_t userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; // get caller user id. auto abilityRecord = Token::GetAbilityRecordByToken(token); CHECK_POINTER_AND_RETURN_LOG(abilityRecord, ERR_INVALID_VALUE, "Ability record is nullptr."); @@ -1631,23 +1654,31 @@ int AbilityManagerService::AbilityTransitionDone(const sptr &toke } if (type == AppExecFwk::AbilityType::SERVICE || type == AppExecFwk::AbilityType::EXTENSION) { - return connectManager_->AbilityTransitionDone(token, state); + auto manager = GetConnectManagerByUserId(userId); + CHECK_POINTER_AND_RETURN_LOG(manager, ERR_INVALID_VALUE, "no connectManager."); + return manager->AbilityTransitionDone(token, state); } if (type == AppExecFwk::AbilityType::DATA) { - return dataAbilityManager_->AbilityTransitionDone(token, state); + auto manager = GetDataAbilityManagerByUserId(userId); + CHECK_POINTER_AND_RETURN_LOG(manager, ERR_INVALID_VALUE, "no data ability Manager."); + return manager->AbilityTransitionDone(token, state); } if (useNewMission_) { if (IsSystemUiApp(abilityInfo)) { return kernalAbilityManager_->AbilityTransitionDone(token, state); } - return currentMissionListManager_->AbilityTransactionDone(token, state, saveData); + auto manager = GetListManagerByUserId(userId); + CHECK_POINTER_AND_RETURN_LOG(manager, ERR_INVALID_VALUE, "no mission list manager."); + return manager->AbilityTransactionDone(token, state, saveData); } else { if (IsSystemUiApp(abilityInfo)) { return systemAppManager_->AbilityTransitionDone(token, state); } - return currentStackManager_->AbilityTransitionDone(token, state, saveData); + auto manager = GetStackManagerByUserId(userId); + CHECK_POINTER_AND_RETURN_LOG(manager, ERR_INVALID_VALUE, "no ability stack manager."); + return manager->AbilityTransitionDone(token, state, saveData); } } @@ -1725,9 +1756,6 @@ void AbilityManagerService::OnAbilityRequestDone(const sptr &toke { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_INFO("On ability request done."); - if (!VerificationToken(token)) { - return; - } auto abilityRecord = Token::GetAbilityRecordByToken(token); CHECK_POINTER(abilityRecord); @@ -1735,25 +1763,41 @@ void AbilityManagerService::OnAbilityRequestDone(const sptr &toke auto type = abilityRecord->GetAbilityInfo().type; switch (type) { case AppExecFwk::AbilityType::SERVICE: - case AppExecFwk::AbilityType::EXTENSION: - connectManager_->OnAbilityRequestDone(token, state); + case AppExecFwk::AbilityType::EXTENSION: { + auto manager = GetConnectManagerByToken(token); + if (manager) { + manager->OnAbilityRequestDone(token, state); + } break; - case AppExecFwk::AbilityType::DATA: - dataAbilityManager_->OnAbilityRequestDone(token, state); + } + case AppExecFwk::AbilityType::DATA: { + auto manager = GetDataAbilityManagerByToken(token); + if (manager) { + manager->OnAbilityRequestDone(token, state); + } break; + } default: { if (useNewMission_) { if (IsSystemUiApp(abilityRecord->GetAbilityInfo())) { kernalAbilityManager_->OnAbilityRequestDone(token, state); break; } - currentMissionListManager_->OnAbilityRequestDone(token, state); + + auto manager = GetListManagerByToken(token); + if (manager) { + manager->OnAbilityRequestDone(token, state); + } } else { if (IsSystemUiApp(abilityRecord->GetAbilityInfo())) { systemAppManager_->OnAbilityRequestDone(token, state); break; } - currentStackManager_->OnAbilityRequestDone(token, state); + + auto manager = GetStackManagerByToken(token); + if (manager) { + manager->OnAbilityRequestDone(token, state); + } } break; } @@ -1843,9 +1887,11 @@ void AbilityManagerService::StartingLauncherAbility() /* query if launcher ability has installed */ AppExecFwk::AbilityInfo abilityInfo; /* First stage, hardcoding for the first launcher App */ + auto userId = GetUserId(); Want want; want.SetElementName(AbilityConfig::LAUNCHER_BUNDLE_NAME, AbilityConfig::LAUNCHER_ABILITY_NAME); - while (!(iBundleManager_->QueryAbilityInfo(want, abilityInfo))) { + while (!(iBundleManager_->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, + userId, abilityInfo))) { HILOG_INFO("Waiting query launcher ability info completed."); usleep(REPOLL_TIME_MICRO_SECONDS); } @@ -1869,9 +1915,14 @@ void AbilityManagerService::StartingPhoneServiceAbility() phoneServiceWant.SetElementName(AbilityConfig::PHONE_SERVICE_BUNDLE_NAME, AbilityConfig::PHONE_SERVICE_ABILITY_NAME); - while (!(iBundleManager_->QueryAbilityInfo(phoneServiceWant, phoneServiceInfo))) { + auto userId = GetUserId(); + int attemptNums = 1; + while (!(iBundleManager_->QueryAbilityInfo(phoneServiceWant, + OHOS::AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, userId, phoneServiceInfo)) && + attemptNums <= 5) { HILOG_INFO("Waiting query phone service ability info completed."); usleep(REPOLL_TIME_MICRO_SECONDS); + attemptNums++; } (void)StartAbility(phoneServiceWant, DEFAULT_INVAL_VALUE); @@ -1889,8 +1940,10 @@ void AbilityManagerService::StartingContactsAbility() Want contactsWant; contactsWant.SetElementName(AbilityConfig::CONTACTS_BUNDLE_NAME, AbilityConfig::CONTACTS_ABILITY_NAME); + auto userId = GetUserId(); int attemptNums = 1; - while (!(iBundleManager_->QueryAbilityInfo(contactsWant, contactsInfo)) && + while (!(iBundleManager_->QueryAbilityInfo(contactsWant, + OHOS::AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, userId, contactsInfo)) && attemptNums <= MAX_NUMBER_OF_CONNECT_BMS) { HILOG_INFO("Waiting query contacts service completed."); usleep(REPOLL_TIME_MICRO_SECONDS); @@ -1915,8 +1968,10 @@ void AbilityManagerService::StartingMmsAbility() Want mmsWant; mmsWant.SetElementName(AbilityConfig::MMS_BUNDLE_NAME, AbilityConfig::MMS_ABILITY_NAME); + auto userId = GetUserId(); int attemptNums = 1; - while (!(iBundleManager_->QueryAbilityInfo(mmsWant, mmsInfo)) && + while (!(iBundleManager_->QueryAbilityInfo(mmsWant, + OHOS::AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, userId, mmsInfo)) && attemptNums <= MAX_NUMBER_OF_CONNECT_BMS) { HILOG_INFO("Waiting query mms service completed."); usleep(REPOLL_TIME_MICRO_SECONDS); @@ -1952,6 +2007,10 @@ int AbilityManagerService::GenerateAbilityRequest( CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED); int userId = GetUserId(); + if (IsSystemUI(want.GetBundle())) { + userId = MAIN_USER_ID; + } + bms->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, userId, request.abilityInfo); if (request.abilityInfo.name.empty() || request.abilityInfo.bundleName.empty()) { @@ -1966,7 +2025,7 @@ int AbilityManagerService::GenerateAbilityRequest( if (request.abilityInfo.type == AppExecFwk::AbilityType::SERVICE) { AppExecFwk::BundleInfo bundleInfo; bool ret = bms->GetBundleInfo(request.abilityInfo.bundleName, - AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo); + AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId); if (!ret) { HILOG_ERROR("Failed to get bundle info when GenerateAbilityRequest."); return RESOLVE_ABILITY_ERR; @@ -2058,9 +2117,10 @@ void AbilityManagerService::OnAbilityDied(std::shared_ptr ability return; } - if (currentMissionListManager_) { - int32_t currentUserId = userController_? userController_->GetCurrentUserId() : USER_ID_DEFAULT; - currentMissionListManager_->OnAbilityDied(abilityRecord, currentUserId); + auto manager = GetListManagerByToken(abilityRecord->GetToken()); + if (manager) { + manager->OnAbilityDied(abilityRecord, GetUserId()); + return; } } else { if (systemAppManager_ && abilityRecord->IsKernalSystemAbility()) { @@ -2068,17 +2128,22 @@ void AbilityManagerService::OnAbilityDied(std::shared_ptr ability return; } - if (currentStackManager_) { - currentStackManager_->OnAbilityDied(abilityRecord); + auto manager = GetStackManagerByToken(abilityRecord->GetToken()); + if (manager) { + manager->OnAbilityDied(abilityRecord); + return; } } - if (connectManager_) { - connectManager_->OnAbilityDied(abilityRecord); + auto manager = GetConnectManagerByToken(abilityRecord->GetToken()); + if (manager) { + manager->OnAbilityDied(abilityRecord); + return; } - if (dataAbilityManager_) { - dataAbilityManager_->OnAbilityDied(abilityRecord); + auto dataAbilityManager = GetDataAbilityManagerByToken(abilityRecord->GetToken()); + if (dataAbilityManager) { + dataAbilityManager->OnAbilityDied(abilityRecord); } } @@ -2168,7 +2233,8 @@ int AbilityManagerService::PreLoadAppDataAbilities(const std::string &bundleName return ERR_INVALID_VALUE; } - if (dataAbilityManager_ == nullptr) { + auto dataAbilityManager = dataAbilityManager_; + if (dataAbilityManager == nullptr) { HILOG_ERROR("Invalid data ability manager when app data abilities preloading."); return ERR_INVALID_STATE; } @@ -2178,6 +2244,9 @@ int AbilityManagerService::PreLoadAppDataAbilities(const std::string &bundleName AppExecFwk::BundleInfo bundleInfo; int32_t userId = GetUserId(); + if (IsSystemUI(bundleName)) { + userId = MAIN_USER_ID; + } bool ret = bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId); if (!ret) { HILOG_ERROR("Failed to get bundle info when app data abilities preloading."); @@ -2201,7 +2270,7 @@ int AbilityManagerService::PreLoadAppDataAbilities(const std::string &bundleName dataAbilityRequest.uid = bundleInfo.uid; HILOG_INFO("App data ability preloading: '%{public}s.%{public}s'...", it->bundleName.c_str(), it->name.c_str()); - auto dataAbility = dataAbilityManager_->Acquire(dataAbilityRequest, false, nullptr, false); + auto dataAbility = dataAbilityManager->Acquire(dataAbilityRequest, false, nullptr, false); if (dataAbility == nullptr) { HILOG_ERROR( "Failed to preload data ability '%{public}s.%{public}s'.", it->bundleName.c_str(), it->name.c_str()); @@ -2222,6 +2291,11 @@ bool AbilityManagerService::IsSystemUiApp(const AppExecFwk::AbilityInfo &info) c return (info.name == AbilityConfig::SYSTEM_UI_NAVIGATION_BAR || info.name == AbilityConfig::SYSTEM_UI_STATUS_BAR); } +bool AbilityManagerService::IsSystemUI(const std::string &bundleName) const +{ + return bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME; +} + void AbilityManagerService::HandleLoadTimeOut(int64_t eventId) { HILOG_DEBUG("Handle load timeout."); @@ -2229,15 +2303,19 @@ void AbilityManagerService::HandleLoadTimeOut(int64_t eventId) if (kernalAbilityManager_) { kernalAbilityManager_->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); } - if (currentMissionListManager_) { - currentMissionListManager_->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); + for (auto& item : missionListManagers_) { + if (item.second) { + item.second->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); + } } } else { if (systemAppManager_) { systemAppManager_->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); } - if (currentStackManager_) { - currentStackManager_->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); + for (auto& item : stackManagers_) { + if (item.second) { + item.second->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); + } } } } @@ -2250,15 +2328,19 @@ void AbilityManagerService::HandleActiveTimeOut(int64_t eventId) if (kernalAbilityManager_) { kernalAbilityManager_->OnTimeOut(AbilityManagerService::ACTIVE_TIMEOUT_MSG, eventId); } - if (currentMissionListManager_) { - currentMissionListManager_->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); + for (auto& item : missionListManagers_) { + if (item.second) { + item.second->OnTimeOut(AbilityManagerService::ACTIVE_TIMEOUT_MSG, eventId); + } } } else { if (systemAppManager_) { systemAppManager_->OnTimeOut(AbilityManagerService::ACTIVE_TIMEOUT_MSG, eventId); } - if (currentStackManager_) { - currentStackManager_->OnTimeOut(AbilityManagerService::ACTIVE_TIMEOUT_MSG, eventId); + for (auto& item : stackManagers_) { + if (item.second) { + item.second->OnTimeOut(AbilityManagerService::ACTIVE_TIMEOUT_MSG, eventId); + } } } } @@ -2267,12 +2349,16 @@ void AbilityManagerService::HandleInactiveTimeOut(int64_t eventId) { HILOG_DEBUG("Handle inactive timeout."); if (useNewMission_) { - if (currentMissionListManager_) { - currentMissionListManager_->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); + for (auto& item : missionListManagers_) { + if (item.second) { + item.second->OnTimeOut(AbilityManagerService::INACTIVE_TIMEOUT_MSG, eventId); + } } } else { - if (currentStackManager_) { - currentStackManager_->OnTimeOut(AbilityManagerService::INACTIVE_TIMEOUT_MSG, eventId); + for (auto& item : stackManagers_) { + if (item.second) { + item.second->OnTimeOut(AbilityManagerService::INACTIVE_TIMEOUT_MSG, eventId); + } } } } @@ -2284,15 +2370,19 @@ void AbilityManagerService::HandleForegroundNewTimeOut(int64_t eventId) if (kernalAbilityManager_) { kernalAbilityManager_->OnTimeOut(AbilityManagerService::FOREGROUNDNEW_TIMEOUT_MSG, eventId); } - if (currentMissionListManager_) { - currentMissionListManager_->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, eventId); + for (auto& item : missionListManagers_) { + if (item.second) { + item.second->OnTimeOut(AbilityManagerService::FOREGROUNDNEW_TIMEOUT_MSG, eventId); + } } } else { if (systemAppManager_) { systemAppManager_->OnTimeOut(AbilityManagerService::FOREGROUNDNEW_TIMEOUT_MSG, eventId); } - if (currentStackManager_) { - currentStackManager_->OnTimeOut(AbilityManagerService::FOREGROUNDNEW_TIMEOUT_MSG, eventId); + for (auto& item : stackManagers_) { + if (item.second) { + item.second->OnTimeOut(AbilityManagerService::FOREGROUNDNEW_TIMEOUT_MSG, eventId); + } } } } @@ -2304,13 +2394,20 @@ void AbilityManagerService::HandleBackgroundNewTimeOut(int64_t eventId) if (kernalAbilityManager_) { kernalAbilityManager_->OnTimeOut(AbilityManagerService::BACKGROUNDNEW_TIMEOUT_MSG, eventId); } + for (auto& item : missionListManagers_) { + if (item.second) { + item.second->OnTimeOut(AbilityManagerService::BACKGROUNDNEW_TIMEOUT_MSG, eventId); + } + } } else { if (systemAppManager_) { systemAppManager_->OnTimeOut(AbilityManagerService::BACKGROUNDNEW_TIMEOUT_MSG, eventId); } - } - if (currentStackManager_) { - currentStackManager_->OnTimeOut(AbilityManagerService::BACKGROUNDNEW_TIMEOUT_MSG, eventId); + for (auto& item : stackManagers_) { + if (item.second) { + item.second->OnTimeOut(AbilityManagerService::BACKGROUNDNEW_TIMEOUT_MSG, eventId); + } + } } } @@ -2363,6 +2460,153 @@ bool AbilityManagerService::VerificationToken(const sptr &token) return false; } +bool AbilityManagerService::VerificationAllToken(const sptr &token) +{ + HILOG_INFO("VerificationAllToken."); + + if (useNewMission_) { + for (auto item: missionListManagers_) { + if (item.second && item.second->GetAbilityRecordByToken(token)) { + return true; + } + + if (item.second && item.second->GetAbilityFromTerminateList(token)) { + return true; + } + } + } else { + for (auto item: stackManagers_) { + if (item.second && item.second->GetAbilityRecordByToken(token)) { + return true; + } + + if (item.second && item.second->GetAbilityFromTerminateList(token)) { + return true; + } + } + } + + for (auto item: dataAbilityManagers_) { + if (item.second && item.second->GetAbilityRecordByToken(token)) { + return true; + } + } + + for (auto item: connectManagers_) { + if (item.second && item.second->GetServiceRecordByToken(token)) { + return true; + } + } + + if (useNewMission_) { + if (kernalAbilityManager_->GetAbilityRecordByToken(token)) { + return true; + } + } else { + if (systemAppManager_->GetAbilityRecordByToken(token)) { + return true; + } + } + + HILOG_ERROR("Failed to verify all token."); + return false; +} + +std::shared_ptr AbilityManagerService::GetStackManagerByUserId(int32_t userId) +{ + auto it = stackManagers_.find(userId); + if (it != stackManagers_.end()) { + return it->second; + } + + return nullptr; +} + +std::shared_ptr AbilityManagerService::GetListManagerByUserId(int32_t userId) +{ + auto it = missionListManagers_.find(userId); + if (it != missionListManagers_.end()) { + return it->second; + } + + return nullptr; +} + +std::shared_ptr AbilityManagerService::GetConnectManagerByUserId(int32_t userId) +{ + auto it = connectManagers_.find(userId); + if (it != connectManagers_.end()) { + return it->second; + } + + return nullptr; +} + +std::shared_ptr AbilityManagerService::GetDataAbilityManagerByUserId(int32_t userId) +{ + auto it = dataAbilityManagers_.find(userId); + if (it != dataAbilityManagers_.end()) { + return it->second; + } + + return nullptr; +} + +std::shared_ptr AbilityManagerService::GetStackManagerByToken(const sptr &token) +{ + for (auto item: stackManagers_) { + if (item.second && item.second->GetAbilityRecordByToken(token)) { + return item.second; + } + + if (item.second && item.second->GetAbilityFromTerminateList(token)) { + return item.second; + } + } + + return nullptr; +} + +std::shared_ptr AbilityManagerService::GetListManagerByToken(const sptr &token) +{ + for (auto item: missionListManagers_) { + if (item.second && item.second->GetAbilityRecordByToken(token)) { + return item.second; + } + + if (item.second && item.second->GetAbilityFromTerminateList(token)) { + return item.second; + } + } + + return nullptr; +} + +std::shared_ptr AbilityManagerService::GetConnectManagerByToken( + const sptr &token) +{ + for (auto item: connectManagers_) { + if (item.second && item.second->GetServiceRecordByToken(token)) { + return item.second; + } + } + + return nullptr; +} + +std::shared_ptr AbilityManagerService::GetDataAbilityManagerByToken( + const sptr &token) +{ + for (auto item: dataAbilityManagers_) { + if (item.second && item.second->GetAbilityRecordByToken(token)) { + return item.second; + } + } + + return nullptr; +} + + int AbilityManagerService::MoveMissionToFloatingStack(const MissionOption &missionOption) { HILOG_INFO("Move mission to floating stack."); @@ -2532,22 +2776,10 @@ void AbilityManagerService::StartSystemApplication() if (!amsConfigResolver_ || amsConfigResolver_->NonConfigFile()) { HILOG_INFO("start all"); - StartingLauncherAbility(); - StartingSettingsDataAbility(); StartingSystemUiAbility(SatrtUiMode::STARTUIBOTH); return; } - if (amsConfigResolver_->GetStartLauncherState()) { - HILOG_INFO("start launcher"); - StartingLauncherAbility(); - } - - if (amsConfigResolver_->GetStartSettingsDataState()) { - HILOG_INFO("start settingsdata"); - StartingSettingsDataAbility(); - } - if (amsConfigResolver_->GetStatusBarState()) { HILOG_INFO("start status bar"); StartingSystemUiAbility(SatrtUiMode::STATUSBAR); @@ -2558,21 +2790,6 @@ void AbilityManagerService::StartSystemApplication() StartingSystemUiAbility(SatrtUiMode::NAVIGATIONBAR); } - if (amsConfigResolver_->GetPhoneServiceState()) { - HILOG_INFO("start phone service"); - StartingPhoneServiceAbility(); - } - - if (amsConfigResolver_->GetStartContactsState()) { - HILOG_INFO("start contacts"); - StartingContactsAbility(); - } - - if (amsConfigResolver_->GetStartMmsState()) { - HILOG_INFO("start mms"); - StartingMmsAbility(); - } - // Location may change DelayedSingleton::GetInstance()->StartupResidentProcess(); } @@ -2618,8 +2835,12 @@ void AbilityManagerService::StartingSystemUiAbility(const SatrtUiMode &mode) navigationBarWant.SetElementName(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_NAVIGATION_BAR); uint32_t waitCnt = 0; // Wait 10 minutes for the installation to complete. - while ((!(iBundleManager_->QueryAbilityInfo(statusBarWant, statusBarInfo)) || - !(iBundleManager_->QueryAbilityInfo(navigationBarWant, navigationBarInfo))) && + auto userId = MAIN_USER_ID; + while ((!(iBundleManager_->QueryAbilityInfo(statusBarWant, + OHOS::AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, + userId, statusBarInfo)) || + !(iBundleManager_->QueryAbilityInfo(navigationBarWant, + OHOS::AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, userId, navigationBarInfo))) && waitCnt < MAX_WAIT_SYSTEM_UI_NUM) { HILOG_INFO("Waiting query system ui info completed."); usleep(REPOLL_TIME_MICRO_SECONDS); @@ -2734,7 +2955,9 @@ void AbilityManagerService::StartingSettingsDataAbility() want.SetElementName(AbilityConfig::SETTINGS_DATA_BUNDLE_NAME, AbilityConfig::SETTINGS_DATA_ABILITY_NAME); uint32_t waitCnt = 0; // Wait 5 minutes for the installation to complete. - while (!iBundleManager_->QueryAbilityInfo(want, abilityInfo) && waitCnt < MAX_WAIT_SETTINGS_DATA_NUM) { + auto userId = GetUserId(); + while (!iBundleManager_->QueryAbilityInfo(want, OHOS::AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, + userId, abilityInfo) && waitCnt < MAX_WAIT_SETTINGS_DATA_NUM) { HILOG_INFO("Waiting query settings data info completed."); usleep(REPOLL_TIME_MICRO_SECONDS); waitCnt++; @@ -2778,7 +3001,10 @@ int AbilityManagerService::SetMissionLabel(const sptr &token, con int AbilityManagerService::StartUser(int userId) { - HILOG_DEBUG("%{public}s", __func__); + HILOG_DEBUG("%{public}s, userId:%{public}d", __func__, userId); + if (userController_) { + return userController_->StartUser(userId, true); + } return 0; } @@ -2912,17 +3138,17 @@ int32_t AbilityManagerService::GetRemoteMissionSnapshotInfo(const std::string& d void AbilityManagerService::StartFreezingScreen() { - HILOG_DEBUG("%{public}s", __func__); + HILOG_INFO("%{public}s", __func__); } void AbilityManagerService::StopFreezingScreen() { - HILOG_DEBUG("%{public}s", __func__); + HILOG_INFO("%{public}s", __func__); } void AbilityManagerService::UserStarted(int32_t userId) { - HILOG_DEBUG("%{public}s", __func__); + HILOG_INFO("%{public}s", __func__); InitConnectManager(userId, false); SetStackManager(userId, false); InitMissionListManager(userId, false); @@ -2930,21 +3156,121 @@ void AbilityManagerService::UserStarted(int32_t userId) InitPendWantManager(userId, false); } -void AbilityManagerService::SwitchToUser(int32_t userId) +void AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId) { - HILOG_DEBUG("%{public}s", __func__); + HILOG_INFO("%{public}s, oldUserId:%{public}d, newUserId:%{public}d", __func__, oldUserId, userId); + SwitchManagers(userId); + PauseOldUser(oldUserId); + StartUserApps(userId); +} + +void AbilityManagerService::SwitchManagers(int32_t userId) +{ + HILOG_INFO("%{public}s, SwitchManagers:%{public}d-----begin", __func__, userId); InitConnectManager(userId, true); SetStackManager(userId, true); InitMissionListManager(userId, true); InitDataAbilityManager(userId, true); InitPendWantManager(userId, true); + HILOG_INFO("%{public}s, SwitchManagers:%{public}d-----end", __func__, userId); +} + +void AbilityManagerService::PauseOldUser(int32_t userId) +{ + HILOG_INFO("%{public}s, PauseOldUser:%{public}d-----begin", __func__, userId); + if (useNewMission_) { + PauseOldMissionListManager(userId); + } else { + PauseOldStackManager(userId); + } + HILOG_INFO("%{public}s, PauseOldUser:%{public}d-----end", __func__, userId); +} + +void AbilityManagerService::PauseOldMissionListManager(int32_t userId) +{ + HILOG_INFO("%{public}s, PauseOldMissionListManager:%{public}d-----begin", __func__, userId); + auto it = missionListManagers_.find(userId); + if (it == missionListManagers_.end()) { + HILOG_INFO("%{public}s, PauseOldMissionListManager:%{public}d-----end1", __func__, userId); + return; + } + auto manager = it->second; + if (!manager) { + HILOG_INFO("%{public}s, PauseOldMissionListManager:%{public}d-----end2", __func__, userId); + return; + } + manager->PauseManager(); + HILOG_INFO("%{public}s, PauseOldMissionListManager:%{public}d-----end", __func__, userId); +} + +void AbilityManagerService::PauseOldStackManager(int32_t userId) +{ + auto it = stackManagers_.find(userId); + if (it == stackManagers_.end()) { + return; + } + auto manager = it->second; + if (!manager) { + return; + } + manager->PauseManager(); +} + +void AbilityManagerService::StartUserApps(int32_t userId) +{ + HILOG_INFO("StartUserApps, userId:%{public}d, currentUserId:%{public}d", userId, GetUserId()); + if (useNewMission_) { + if (currentMissionListManager_ && currentMissionListManager_->IsStarted()) { + HILOG_INFO("missionListManager ResumeManager"); + currentMissionListManager_->ResumeManager(); + return; + } + } else { + if (currentStackManager_ && currentStackManager_->IsStarted()) { + HILOG_INFO("stack ResumeManager"); + currentStackManager_->ResumeManager(); + return; + } + } + StartSystemAbilityByUser(userId); } -void AbilityManagerService::StartLauncherAbility(int32_t userId) +void AbilityManagerService::StartSystemAbilityByUser(int32_t userId) { - HILOG_DEBUG("StartLauncherAbility, userId:%{public}d, currentUserId:%{public}d", userId, GetUserId()); + HILOG_INFO("StartSystemAbilityByUser, userId:%{public}d, currentUserId:%{public}d", userId, GetUserId()); ConnectBmsService(); - StartingLauncherAbility(); + + if (!amsConfigResolver_ || amsConfigResolver_->NonConfigFile()) { + HILOG_INFO("start all"); + StartingLauncherAbility(); + StartingSettingsDataAbility(); + return; + } + + if (amsConfigResolver_->GetStartLauncherState()) { + HILOG_INFO("start launcher"); + StartingLauncherAbility(); + } + + if (amsConfigResolver_->GetStartSettingsDataState()) { + HILOG_INFO("start settingsdata"); + StartingSettingsDataAbility(); + } + + if (amsConfigResolver_->GetPhoneServiceState()) { + HILOG_INFO("start phone service"); + StartingPhoneServiceAbility(); + } + + if (amsConfigResolver_->GetStartContactsState()) { + HILOG_INFO("start contacts"); + StartingContactsAbility(); + } + + if (amsConfigResolver_->GetStartMmsState()) { + HILOG_INFO("start mms"); + StartingMmsAbility(); + } } void AbilityManagerService::InitConnectManager(int32_t userId, bool switchUser) diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index f8d4d9f72e9eb889cf05b3c22294b0f552c4220f..5afb6cab5c81c9bc6ea6d58ca63805a4762313c1 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -1390,5 +1390,15 @@ void AbilityRecord::ContinueAbility(const std::string& deviceId) lifecycleDeal_->ContinueAbility(deviceId); } + +void AbilityRecord::SetSwitchingPause(bool state) +{ + isSwitchingPause_ = state; +} + +bool AbilityRecord::IsSwitchingPause() +{ + return isSwitchingPause_; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_stack_manager.cpp b/services/abilitymgr/src/ability_stack_manager.cpp index bce2de61c806c0276b2dd99f98eb78ac6a3ef67f..5e7cffdacde3077abeafbea064c1d4ff3c759244 100644 --- a/services/abilitymgr/src/ability_stack_manager.cpp +++ b/services/abilitymgr/src/ability_stack_manager.cpp @@ -1643,6 +1643,12 @@ void AbilityStackManager::CompleteInactive(const std::shared_ptr HILOG_INFO("ability: %{public}s", element.c_str()); abilityRecord->SetAbilityState(AbilityState::INACTIVE); + if (abilityRecord->IsSwitchingPause()) { + MoveToBackgroundTask(abilityRecord); + abilityRecord->SetSwitchingPause(false); + return; + } + // 0. multi window moving , complete lifecycle. if (abilityRecord->GetInMovingState()) { if (abilityRecord == GetCurrentTopAbility()) { @@ -4701,6 +4707,12 @@ void AbilityStackManager::CompleteInactiveByNewVersion(const std::shared_ptr guard(stackLock_); + if (abilityRecord->IsSwitchingPause()) { + MoveToBackgroundTask(abilityRecord); + abilityRecord->SetSwitchingPause(false); + return; + } + // 1. it may be inactive callback of terminate ability. if (abilityRecord->IsTerminating()) { abilityRecord->SendResultToCallers(); @@ -4726,6 +4738,11 @@ void AbilityStackManager::CompleteInactiveByNewVersion(const std::shared_ptrIsSwitchingPause()) { + MoveToBackgroundTask(abilityRecord); + return; + } + std::string element = abilityRecord->GetWant().GetElement().GetURI(); HILOG_INFO("ability: %{public}s", element.c_str()); @@ -4912,5 +4929,37 @@ void AbilityStackManager::CompleteBackgroundNew(const std::shared_ptrTerminate(timeoutTask); } } + +bool AbilityStackManager::IsStarted() +{ + std::lock_guard guard(stackLock_); + auto lanucherRoot = GetLauncherRootAbility(); + return lanucherRoot != nullptr; +} + +void AbilityStackManager::PauseManager() +{ + HILOG_INFO("PauseManager."); + std::lock_guard guard(stackLock_); + auto currentTopAbility = GetCurrentTopAbility(); + if (!currentTopAbility) { + HILOG_WARN("get top ability failed."); + return; + } + + currentTopAbility->SetSwitchingPause(true); + if (currentTopAbility->IsAbilityState(AbilityState::ACTIVE)) { + currentTopAbility->ProcessInactivate(); + } + if (currentTopAbility->IsAbilityState(AbilityState::INACTIVE)) { + MoveToBackgroundTask(currentTopAbility); + } +} + +void AbilityStackManager::ResumeManager() +{ + HILOG_INFO("ResumeManager, back to launcher."); + BackToLauncher(); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/mission_info_mgr.cpp b/services/abilitymgr/src/mission_info_mgr.cpp index 54be415b4bf04d4a0b4a5f5e76e44cb19b2f71ca..6c212beace398b18693008bb8abeecdaa557364e 100644 --- a/services/abilitymgr/src/mission_info_mgr.cpp +++ b/services/abilitymgr/src/mission_info_mgr.cpp @@ -57,6 +57,8 @@ bool MissionInfoMgr::Init(int userId) return false; } + missionInfoList_.clear(); + missionIdMap_.clear(); if (!LoadAllMissionInfo()) { return false; } diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index fe1fecc8649db34b64eadb95bb836947c29e980e..a0f1f11adda00356bc80ff74d5ecb7864ecdc24f 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -766,6 +766,12 @@ void MissionListManager::CompleteBackground(const std::shared_ptr // send application state to AppMS. // notify AppMS to update application state. DelayedSingleton::GetInstance()->MoveToBackground(abilityRecord->GetToken()); + + if (abilityRecord->IsSwitchingPause()) { + abilityRecord->SetSwitchingPause(false); + return; + } + // Abilities ahead of the one started with SingleTask mode were put in terminate list, we need to terminate // them. auto self(shared_from_this()); @@ -1467,22 +1473,11 @@ void MissionListManager::BackToLauncher() std::lock_guard guard(managerLock_); CHECK_POINTER(launcherList_); - auto currentTop = GetCurrentTopAbilityLocked(); - if (currentTop && (currentTop->IsAbilityState(AbilityState::FOREGROUND_NEW) || - currentTop->IsAbilityState(AbilityState::FOREGROUNDING_NEW))) { - HILOG_WARN("Current top ability is already foreground, no need to start launcher."); - return; - } - auto launcherRootAbility = launcherList_->GetLauncherRoot(); CHECK_POINTER_LOG(launcherRootAbility, "There is no root launcher ability, back to launcher failed."); auto launcherRootMission = launcherRootAbility->GetMission(); CHECK_POINTER_LOG(launcherRootMission, "There is no root launcher mission, back to launcher failed."); - if (launcherRootAbility->IsAbilityState(AbilityState::FOREGROUND_NEW) || - launcherRootAbility->IsAbilityState(AbilityState::FOREGROUNDING_NEW)) { - HILOG_WARN("launcher is already foreground, no need to start launcher."); - return; - } + std::queue emptyQueue; std::swap(waittingAbilityQueue_, emptyQueue); @@ -1748,5 +1743,67 @@ void MissionListManager::GetAbilityRunningInfos(std::vector } } } + +bool MissionListManager::IsStarted() +{ + std::lock_guard guard(managerLock_); + auto launcherRoot = launcherList_->GetLauncherRoot(); + return launcherRoot != nullptr; +} + +void MissionListManager::PauseManager() +{ + HILOG_INFO("MissionListManager PauseManager. move foreground to background."); + std::lock_guard guard(managerLock_); + std::list> foregroundAbilities; + GetAllForegroundAbilities(foregroundAbilities); + + for (auto& abilityRecord : foregroundAbilities) { + if (!abilityRecord) { + continue; + } + abilityRecord->SetSwitchingPause(true); + MoveToBackgroundTask(abilityRecord); + } +} + +void MissionListManager::ResumeManager() +{ + HILOG_INFO("ResumeManager, back to launcher."); + BackToLauncher(); +} + +void MissionListManager::GetAllForegroundAbilities(std::list>& foregroundList) +{ + std::shared_ptr abilityRecord = nullptr; + for (auto& missionList : currentMissionLists_) { + GetForegroundAbilities(missionList, foregroundList); + } + GetForegroundAbilities(defaultSingleList_, foregroundList); + GetForegroundAbilities(defaultStandardList_, foregroundList); +} + +void MissionListManager::GetForegroundAbilities(const std::shared_ptr& missionList, + std::list>& foregroundList) +{ + if (!missionList || missionList->IsEmpty()) { + return; + } + + for (auto& mission : missionList->GetAllMissions()) { + if (!mission) { + continue; + } + + auto abilityRecord = mission->GetAbilityRecord(); + if (!abilityRecord) { + continue; + } + + if (abilityRecord->IsActiveState()) { + foregroundList.emplace_back(abilityRecord); + } + } +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/user_controller.cpp b/services/abilitymgr/src/user_controller.cpp index 74b49f2e9d1ea3c016666563987f61c35f35c93b..68857ab1ec73c9d8da9618369d60e6e3444d7a53 100644 --- a/services/abilitymgr/src/user_controller.cpp +++ b/services/abilitymgr/src/user_controller.cpp @@ -26,22 +26,6 @@ namespace AAFwk { using namespace OHOS::AppExecFwk; namespace { const int64_t USER_SWITCH_TIMEOUT = 3 * 1000; // 3s - -class Holder { -public: - Holder() - { - identity_ = IPCSkeleton::ResetCallingIdentity(); - } - - ~Holder() - { - IPCSkeleton::SetCallingIdentity(identity_); - } - -private: - std::string identity_; -}; } UserItem::UserItem(int32_t id) : userId_(id) @@ -256,12 +240,11 @@ void UserController::SetCurrentUserId(int32_t userId) void UserController::MoveUserToForeground(int32_t oldUserId, int32_t newUserId) { - auto ams = DelayedSingleton::GetInstance(); - if (!ams) { + auto manager = DelayedSingleton::GetInstance(); + if (!manager) { return; } - ams->SwitchToUser(newUserId); - ams->StartLauncherAbility(newUserId); + manager->SwitchToUser(oldUserId, newUserId); BroacastUserBackground(oldUserId); BroacastUserForeground(newUserId); } @@ -283,11 +266,11 @@ void UserController::UserBootDone(std::shared_ptr &item) return; } item->SetState(UserState::STATE_STARTED); - auto ams = DelayedSingleton::GetInstance(); - if (!ams) { + auto manager = DelayedSingleton::GetInstance(); + if (!manager) { return; } - ams->UserStarted(userId); + manager->UserStarted(userId); } void UserController::BroacastUserStarted(int32_t userId) @@ -479,9 +462,9 @@ void UserController::HandleUserSwitchTimeout(int32_t oldUserId, int32_t newUserI void UserController::HandleContinueUserSwitch(int32_t oldUserId, int32_t newUserId, std::shared_ptr &usrItem) { - auto ams = DelayedSingleton::GetInstance(); - if (ams) { - ams->StopFreezingScreen(); + auto manager = DelayedSingleton::GetInstance(); + if (manager) { + manager->StopFreezingScreen(); } SendUserSwitchDone(newUserId); } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 1323c9035a9e05ceb4585e63890544773ab6e5d7..3c8b386f916de0bf673c465c20b1f00b3041ae35 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -58,6 +58,13 @@ const std::string REQ_PERMISSION = "ohos.permission.LOCATION_IN_BACKGROUND"; constexpr int32_t SYSTEM_UID = 1000; constexpr int32_t USER_SCALE = 200000; #define ENUM_TO_STRING(s) #s + +constexpr int32_t BASE_USER_RANGE = 200000; + +int32_t GetUserIdByUid(int32_t uid) +{ + return uid / BASE_USER_RANGE; +} } // namespace using OHOS::AppExecFwk::Constants::PERMISSION_GRANTED; @@ -164,7 +171,9 @@ bool AppMgrServiceInner::GetBundleAndHapInfo(const AbilityInfo &abilityInfo, return false; } - bool bundleMgrResult = bundleMgr_->GetBundleInfo(appInfo->bundleName, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo); + auto userId = GetUserIdByUid(abilityInfo.applicationInfo.uid); + bool bundleMgrResult = bundleMgr_->GetBundleInfo(appInfo->bundleName, + BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId); if (!bundleMgrResult) { APP_LOGE("GetBundleInfo is fail"); return false; @@ -1167,10 +1176,12 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str return; } + auto userId = GetUserIdByUid(uid); AppSpawnStartMsg startMsg; BundleInfo bundleInfo; std::vector bundleInfos; - bool bundleMgrResult = bundleMgr_->GetBundleInfos(AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfos); + bool bundleMgrResult = bundleMgr_->GetBundleInfos(AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, + bundleInfos, userId); if (!bundleMgrResult) { APP_LOGE("GetBundleInfo is fail"); return;