mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-25 12:23:20 -04:00
修复start user
Signed-off-by: lidongrui <lidongrui3@huawei.com> Change-Id: I4c4d0eda067d41b5327023827216e8e379bdb698
This commit is contained in:
@@ -2567,7 +2567,7 @@ private:
|
||||
int SwitchToUser(int32_t oldUserId, int32_t userId, uint64_t displayId, sptr<IUserCallback> callback,
|
||||
bool isAppRecovery = false);
|
||||
void SwitchManagers(int32_t userId, bool switchUser = true);
|
||||
void StartUserApps();
|
||||
bool StartUserApps(int32_t oldUserId);
|
||||
void PauseOldUser(int32_t userId);
|
||||
void PauseOldMissionListManager(int32_t userId);
|
||||
void PauseOldConnectManager(int32_t userId);
|
||||
|
||||
@@ -9570,6 +9570,8 @@ int AbilityManagerService::StartUser(int userId, uint64_t displayId, sptr<IUserC
|
||||
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->SetEnableStartProcessFlagByUserId(userId, true);
|
||||
auto oldUserId = AbilityRuntime::UserController::GetInstance().GetForegroundUserId(displayId);
|
||||
// True indicates that a user has been created on this displayId, false indicates that no user has been created
|
||||
auto hasDisplayId = AbilityRuntime::UserController::GetInstance().IsExistDisplayId(displayId);
|
||||
if (oldUserId != U0_USER_ID && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
// start freezing screen
|
||||
AbilityRuntime::UserController::GetInstance().SetFreezingNewUserId(userId);
|
||||
@@ -9588,7 +9590,16 @@ int AbilityManagerService::StartUser(int userId, uint64_t displayId, sptr<IUserC
|
||||
}
|
||||
|
||||
AbilityRuntime::UserController::GetInstance().SetForegroundUserId(userId, displayId);
|
||||
return SwitchToUser(oldUserId, userId, displayId, callback, isAppRecovery);
|
||||
auto ret = SwitchToUser(oldUserId, userId, displayId, callback, isAppRecovery);
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "SwitchToUser filed,oldUserId:%{public}d, hasDisplayId:%{public}d", oldUserId, hasDisplayId);
|
||||
if (hasDisplayId) {
|
||||
AbilityRuntime::UserController::GetInstance().SetForegroundUserId(oldUserId, displayId);
|
||||
} else {
|
||||
AbilityRuntime::UserController::GetInstance().ClearDisplayId(displayId);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AbilityManagerService::StopUser(int userId, const sptr<IUserCallback> &callback)
|
||||
@@ -10304,23 +10315,20 @@ int AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, uint6
|
||||
"%{public}s, oldUserId:%{public}d, newUserId:%{public}d, isAppRecovery:%{public}d", __func__,
|
||||
oldUserId, userId, isAppRecovery);
|
||||
SwitchManagers(userId);
|
||||
if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
PauseOldUser(oldUserId);
|
||||
ConnectServices();
|
||||
StartUserApps();
|
||||
}
|
||||
int32_t ret = ERR_OK;
|
||||
#ifndef DISABLE_LAUNCHER
|
||||
bool isBoot = oldUserId == U0_USER_ID ? true : false;
|
||||
auto ret = StartHighestPriorityAbility(userId, displayId, isBoot, isAppRecovery);
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "StartHighestPriorityAbility failed: %{public}d", ret);
|
||||
if (!StartUserApps(oldUserId)) {
|
||||
bool isBoot = oldUserId == U0_USER_ID ? true : false;
|
||||
ret = StartHighestPriorityAbility(userId, displayId, isBoot, isAppRecovery);
|
||||
}
|
||||
#else
|
||||
auto ret = ERR_OK;
|
||||
#endif
|
||||
if (callback) {
|
||||
callback->OnStartUserDone(userId, ret);
|
||||
}
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "StartHighestPriorityAbility failed: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
if (taskHandler_) {
|
||||
taskHandler_->SubmitTask([abilityMs = shared_from_this(), userId]() {
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "StartResidentApps userId:%{public}d", userId);
|
||||
@@ -10409,13 +10417,19 @@ void AbilityManagerService::PauseOldConnectManager(int32_t userId)
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s, PauseOldConnectManager:%{public}d-----end", __func__, userId);
|
||||
}
|
||||
|
||||
void AbilityManagerService::StartUserApps()
|
||||
bool AbilityManagerService::StartUserApps(int32_t oldUserId)
|
||||
{
|
||||
auto missionListManager = GetCurrentMissionListManager();
|
||||
if (missionListManager && missionListManager->IsStarted()) {
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "missionListManager ResumeManager");
|
||||
missionListManager->ResumeManager();
|
||||
if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
PauseOldUser(oldUserId);
|
||||
ConnectServices();
|
||||
auto missionListManager = GetCurrentMissionListManager();
|
||||
if (missionListManager && missionListManager->IsStarted()) {
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "missionListManager ResumeManager");
|
||||
missionListManager->ResumeManager();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t AbilityManagerService::GetValidUserId(int32_t userId)
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
void SetForegroundUserId(int32_t userId, uint64_t displayId);
|
||||
|
||||
bool GetDisplayIdByForegroundUserId(int32_t userId, uint64_t &displayId);
|
||||
bool IsExistDisplayId(uint64_t displayId);
|
||||
|
||||
bool IsForegroundUser(int32_t userId);
|
||||
bool IsForegroundUser(int32_t userId, uint64_t displayId);
|
||||
@@ -44,6 +45,7 @@ public:
|
||||
void GetAllForegroundUserId(std::vector<int32_t> &userIds);
|
||||
|
||||
void ClearUserId(int32_t userId);
|
||||
void ClearDisplayId(uint64_t displayId);
|
||||
|
||||
int32_t GetCallerUserId();
|
||||
|
||||
|
||||
@@ -50,6 +50,12 @@ void UserController::ClearUserId(int32_t userId)
|
||||
}
|
||||
}
|
||||
|
||||
void UserController::ClearDisplayId(uint64_t displayId)
|
||||
{
|
||||
std::lock_guard<ffrt::mutex> guard(userLock_);
|
||||
displayIdMap_.erase(displayId);
|
||||
}
|
||||
|
||||
int32_t UserController::GetForegroundUserId(uint64_t displayId)
|
||||
{
|
||||
std::lock_guard<ffrt::mutex> guard(userLock_);
|
||||
@@ -60,6 +66,13 @@ int32_t UserController::GetForegroundUserId(uint64_t displayId)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool UserController::IsExistDisplayId(uint64_t displayId)
|
||||
{
|
||||
std::lock_guard<ffrt::mutex> guard(userLock_);
|
||||
auto iter = displayIdMap_.find(displayId);
|
||||
return iter != displayIdMap_.end();
|
||||
}
|
||||
|
||||
bool UserController::GetDisplayIdByForegroundUserId(int32_t userId, uint64_t &displayId)
|
||||
{
|
||||
std::lock_guard<ffrt::mutex> guard(userLock_);
|
||||
|
||||
@@ -88,6 +88,7 @@ ohos_unittest("ability_manager_service_twelfth_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 = [
|
||||
|
||||
+89
@@ -22,6 +22,7 @@
|
||||
#include "ability_manager_service.h"
|
||||
#include "modal_system_dialog/modal_system_dialog_ui_extension.h"
|
||||
#include "utils/modal_system_dialog_util.h"
|
||||
#include "user_controller/user_controller.h"
|
||||
#include "remote_on_listener_stub_mock.h"
|
||||
#include "ability_connect_manager.h"
|
||||
#include "ui_extension_ability_manager.h"
|
||||
@@ -481,6 +482,94 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, StartUser_001, TestSize.Level1)
|
||||
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_001 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: StartUser
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: AbilityManagerService StartUser - U1_USER_ID special case
|
||||
*/
|
||||
HWTEST_F(AbilityManagerServiceTwelfthTest, StartUser_002, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_002 start");
|
||||
auto abilityMs_ = std::make_shared<AbilityManagerService>();
|
||||
int32_t userId = U1_USER_ID; // userId = 1
|
||||
uint64_t displayId = 0;
|
||||
sptr<IUserCallback> callback = new MockIUserCallback();
|
||||
bool isAppRecovery = false;
|
||||
|
||||
IPCSkeleton::SetCallingUid(ACCOUNT_MGR_SERVICE_UID);
|
||||
auto retCode = abilityMs_->StartUser(userId, displayId, callback, isAppRecovery);
|
||||
EXPECT_EQ(retCode, INVALID_USERID_VALUE);
|
||||
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_002 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: StartUser
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: AbilityManagerService StartUser - Already foreground user
|
||||
*/
|
||||
HWTEST_F(AbilityManagerServiceTwelfthTest, StartUser_003, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_003 start");
|
||||
auto abilityMs_ = std::make_shared<AbilityManagerService>();
|
||||
int32_t userId = 100;
|
||||
uint64_t displayId = 0;
|
||||
sptr<IUserCallback> callback = new MockIUserCallback();
|
||||
bool isAppRecovery = false;
|
||||
|
||||
IPCSkeleton::SetCallingUid(ACCOUNT_MGR_SERVICE_UID);
|
||||
abilityMs_->subManagersHelper_ = std::make_shared<SubManagersHelper>(nullptr, nullptr);
|
||||
|
||||
AbilityRuntime::UserController::GetInstance().SetForegroundUserId(userId, displayId);
|
||||
|
||||
auto retCode = abilityMs_->StartUser(userId, displayId, callback, isAppRecovery);
|
||||
EXPECT_EQ(retCode, ERR_OK);
|
||||
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_003 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: StartUser
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: AbilityManagerService StartUser - Invalid userId negative value
|
||||
*/
|
||||
HWTEST_F(AbilityManagerServiceTwelfthTest, StartUser_004, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_004 start");
|
||||
auto abilityMs_ = std::make_shared<AbilityManagerService>();
|
||||
int32_t userId = -1; // invalid userId
|
||||
uint64_t displayId = 0;
|
||||
sptr<IUserCallback> callback = new MockIUserCallback();
|
||||
bool isAppRecovery = false;
|
||||
|
||||
IPCSkeleton::SetCallingUid(ACCOUNT_MGR_SERVICE_UID);
|
||||
auto retCode = abilityMs_->StartUser(userId, displayId, callback, isAppRecovery);
|
||||
EXPECT_EQ(retCode, INVALID_USERID_VALUE);
|
||||
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_004 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: StartUser
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: AbilityManagerService StartUser - Without permission
|
||||
*/
|
||||
HWTEST_F(AbilityManagerServiceTwelfthTest, StartUser_005, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_005 start");
|
||||
auto abilityMs_ = std::make_shared<AbilityManagerService>();
|
||||
int32_t userId = 100;
|
||||
uint64_t displayId = 0;
|
||||
sptr<IUserCallback> callback = new MockIUserCallback();
|
||||
bool isAppRecovery = false;
|
||||
|
||||
IPCSkeleton::SetCallingUid(1000);
|
||||
auto retCode = abilityMs_->StartUser(userId, displayId, callback, isAppRecovery);
|
||||
EXPECT_EQ(retCode, CHECK_PERMISSION_FAILED);
|
||||
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest StartUser_005 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: StartAbilityByCallWithErrMsg
|
||||
|
||||
Reference in New Issue
Block a user