diff --git a/services/abilitymgr/include/user_controller.h b/services/abilitymgr/include/user_controller.h index 44741bb2779a77da5012a8c5c396d27c7910c3b6..fa08f4771853657426d5402da3fc2276fca62dfb 100644 --- a/services/abilitymgr/include/user_controller.h +++ b/services/abilitymgr/include/user_controller.h @@ -24,7 +24,8 @@ namespace OHOS { namespace AAFwk { -const int32_t USER_ID_DEFAULT = 0; +const int32_t USER_ID_NO_HEAD = 0; +const int32_t USER_ID_DEFAULT = 100; enum UserState { STATE_BOOTING = 0, @@ -89,13 +90,13 @@ private: bool IsExistOsAccount(int32_t userId); std::shared_ptr GetOrCreateUserItem(int32_t userId); void SetCurrentUserId(int32_t userId); - void BroacastUserStarted(int32_t userId); + void BroadcastUserStarted(int32_t userId); void MoveUserToForeground(int32_t oldUserId, int32_t newUserId); void UserBootDone(std::shared_ptr &item); - void BroacastUserBackground(int32_t userId); - void BroacastUserForeground(int32_t userId); - void BroacastUserStopping(int32_t userId); - void BroacastUserStopped(int32_t userId); + 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); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index ee1f96c73137ba0ba23262fbb11f1a558905a532..61affa04723ef5086ddf083f5221906dacb7f29d 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -39,6 +39,7 @@ #include "locale_config.h" #include "lock_screen_white_list.h" #include "mission/mission_info_converter.h" +#include "mission_info_mgr.h" #include "sa_mgr_client.h" #include "softbus_bus_center.h" #include "string_ex.h" @@ -2197,6 +2198,7 @@ void AbilityManagerService::InitMissionListManager(int userId, bool switchUser) auto iterator = missionListManagers_.find(userId); if (iterator != missionListManagers_.end()) { if (switchUser) { + DelayedSingleton::GetInstance()->Init(userId); currentMissionListManager_ = iterator->second; } } else { @@ -3504,8 +3506,13 @@ int AbilityManagerService::StartUser(int userId) int AbilityManagerService::StopUser(int userId, const sptr &callback) { HILOG_DEBUG("%{public}s", __func__); + auto ret = -1; + if (userController_) { + ret = userController_->StopUser(userId); + HILOG_DEBUG("ret = %{public}d", ret); + } if (callback) { - callback->OnStopUserDone(userId, ERR_OK); + callback->OnStopUserDone(userId, ret); } return 0; } diff --git a/services/abilitymgr/src/user_controller.cpp b/services/abilitymgr/src/user_controller.cpp index 68857ab1ec73c9d8da9618369d60e6e3444d7a53..97a45404ad15c799f1553bb079763307f8662248 100644 --- a/services/abilitymgr/src/user_controller.cpp +++ b/services/abilitymgr/src/user_controller.cpp @@ -80,7 +80,7 @@ void UserController::Init() int32_t UserController::StartUser(int32_t userId, bool isForeground) { - if (userId < 0 || userId == USER_ID_DEFAULT) { + if (userId < 0 || userId == USER_ID_NO_HEAD) { HILOG_ERROR("StartUser userId is invalid:%{public}d", userId); return -1; } @@ -127,7 +127,7 @@ int32_t UserController::StartUser(int32_t userId, bool isForeground) } if (needStart) { - BroacastUserStarted(userId); + BroadcastUserStarted(userId); } UserBootDone(userItem); @@ -140,7 +140,7 @@ int32_t UserController::StartUser(int32_t userId, bool isForeground) int32_t UserController::StopUser(int32_t userId) { - if (userId < 0 || userId == USER_ID_DEFAULT) { + if (userId < 0 || userId == USER_ID_NO_HEAD || userId == USER_ID_DEFAULT) { HILOG_ERROR("userId is invalid:%{public}d", userId); return -1; } @@ -155,7 +155,7 @@ int32_t UserController::StopUser(int32_t userId) return -1; } - BroacastUserStopping(userId); + BroadcastUserStopping(userId); auto appScheduler = DelayedSingleton::GetInstance(); if (!appScheduler) { @@ -178,7 +178,7 @@ int32_t UserController::StopUser(int32_t userId) } abilityManagerService->ClearUserData(userId); - BroacastUserStopped(userId); + BroadcastUserStopped(userId); return 0; } @@ -245,8 +245,8 @@ void UserController::MoveUserToForeground(int32_t oldUserId, int32_t newUserId) return; } manager->SwitchToUser(oldUserId, newUserId); - BroacastUserBackground(oldUserId); - BroacastUserForeground(newUserId); + BroadcastUserBackground(oldUserId); + BroadcastUserForeground(newUserId); } void UserController::UserBootDone(std::shared_ptr &item) @@ -273,27 +273,27 @@ void UserController::UserBootDone(std::shared_ptr &item) manager->UserStarted(userId); } -void UserController::BroacastUserStarted(int32_t userId) +void UserController::BroadcastUserStarted(int32_t userId) { // todo: broadcast event user start. } -void UserController::BroacastUserBackground(int32_t userId) +void UserController::BroadcastUserBackground(int32_t userId) { // todo: broadcast event user switch to bg. } -void UserController::BroacastUserForeground(int32_t userId) +void UserController::BroadcastUserForeground(int32_t userId) { // todo: broadcast event user switch to fg. } -void UserController::BroacastUserStopping(int32_t userId) +void UserController::BroadcastUserStopping(int32_t userId) { // todo } -void UserController::BroacastUserStopped(int32_t userId) +void UserController::BroadcastUserStopped(int32_t userId) { // todo } diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 59897231db5b2a583c809d3ef9d65318753a3ad2..db78229fbcebcf538aaf86d07c1ab8a593253b9c 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -20,19 +20,11 @@ #include "app_log_wrapper.h" #include "appexecfwk_errors.h" +#include "os_account_manager.h" #include "perf_profile.h" namespace OHOS { namespace AppExecFwk { -namespace { -static const int32_t USER_UID_RANGE = 200000; - -bool IsUidBelongsToUser(int32_t uid, int32_t userId) -{ - return (uid / USER_UID_RANGE) == userId; -} -} // namespace - AppRunningManager::AppRunningManager() {} AppRunningManager::~AppRunningManager() @@ -167,11 +159,15 @@ bool AppRunningManager::GetPidsByUserId(int32_t userId, std::list &pids) std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; - if (appRecord && IsUidBelongsToUser(appRecord->GetUid(), userId)) { - pid_t pid = appRecord->GetPriorityObject()->GetPid(); - if (pid > 0) { - pids.push_back(pid); - appRecord->ScheduleProcessSecurityExit(); + if (appRecord) { + int32_t id = -1; + if ((AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(appRecord->GetUid(), id) == 0) && + (id == userId)) { + pid_t pid = appRecord->GetPriorityObject()->GetPid(); + if (pid > 0) { + pids.push_back(pid); + appRecord->ScheduleProcessSecurityExit(); + } } } }