diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index c07358f10d34d9311d5ef86178429847761d6973..22c0c176f0a01056a6c6236cb0f9d186bb67821d 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -924,12 +924,7 @@ int UIAbilityLifecycleManager::DispatchState(const std::shared_ptr &abilityRecord, bool success, AbilityState state) { - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); - auto taskHandler = DelayedSingleton::GetInstance()->GetTaskHandler(); - CHECK_POINTER_AND_RETURN_LOG(taskHandler, ERR_INVALID_VALUE, "Fail to get AbilityTaskHandler."); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); - RemoveStartingPid(abilityRecord->GetPid()); if (!abilityRecord->IsAbilityState(AbilityState::FOREGROUNDING)) { @@ -943,37 +938,20 @@ int UIAbilityLifecycleManager::DispatchForeground(const std::shared_ptrRemoveForegroundTimeoutTask(); g_deleteLifecycleEventTask(abilityRecord->GetToken()); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(abilityRecord->GetPid()); - auto self(weak_from_this()); if (success) { TAG_LOGD(AAFwkTag::ABILITYMGR, "foreground succeeded."); - auto task = [self, abilityRecord]() { - auto selfObj = self.lock(); - if (!selfObj) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "mgr invalid"); - return; - } - selfObj->CompleteForegroundSuccess(abilityRecord); - }; - taskHandler->SubmitTask(task, TaskQoS::USER_INTERACTIVE); - } else { - auto task = [self, abilityRecord, state]() { - auto selfObj = self.lock(); - if (!selfObj) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "mission list mgr invalid"); - return; - } - if (state == AbilityState::FOREGROUND_WINDOW_FREEZED) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "window freezed"); - if (abilityRecord != nullptr) { - abilityRecord->SetAbilityState(AbilityState::BACKGROUND); - DelayedSingleton::GetInstance()->MoveToBackground(abilityRecord->GetToken()); - } - return; - } - selfObj->HandleForegroundFailed(abilityRecord, state); - }; - taskHandler->SubmitTask(task, TaskQoS::USER_INTERACTIVE); + // do not submitTask, for grant uri permission in terminateSelfWithResult + CompleteForegroundSuccess(abilityRecord); + return ERR_OK; } + // do not submitTask, for grant uri permission in terminateSelfWithResult + if (state == AbilityState::FOREGROUND_WINDOW_FREEZED) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "window freezed"); + abilityRecord->SetAbilityState(AbilityState::BACKGROUND); + DelayedSingleton::GetInstance()->MoveToBackground(abilityRecord->GetToken()); + return ERR_OK; + } + HandleForegroundFailed(abilityRecord, state); return ERR_OK; } @@ -1024,8 +1002,7 @@ int UIAbilityLifecycleManager::DispatchTerminate(const std::shared_ptr &abilityRecord) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - std::lock_guard guard(sessionLock_); - + // do not add sessionLock_, for grant uri permission in terminateSelfWithResult CHECK_POINTER(abilityRecord); // ability do not save window mode abilityRecord->RemoveWindowMode(); @@ -1063,7 +1040,7 @@ void UIAbilityLifecycleManager::HandleForegroundFailed(const std::shared_ptr(state)); HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - std::lock_guard guard(sessionLock_); + // do not add sessionLock_, for grant uri permission in terminateSelfWithResult if (ability == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "null ability record"); return; diff --git a/test/unittest/ui_ability_lifecycle_manager_second_test/ui_ability_lifecycle_manager_second_test.cpp b/test/unittest/ui_ability_lifecycle_manager_second_test/ui_ability_lifecycle_manager_second_test.cpp index 0ea039f3b201ddbfa4c465e694f5773508a9c57e..b44f333c1e1ef035167a09d1962686739c320dab 100644 --- a/test/unittest/ui_ability_lifecycle_manager_second_test/ui_ability_lifecycle_manager_second_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_second_test/ui_ability_lifecycle_manager_second_test.cpp @@ -1160,34 +1160,6 @@ HWTEST_F(UIAbilityLifecycleManagerSecondTest, AddStartCallerTimestamp_003, TestS EXPECT_EQ(ret, true); } -/** - * @tc.name: UIAbilityLifecycleManager_DispatchForeground_0200 - * @tc.desc: DispatchForeground - * @tc.type: FUNC - */ -HWTEST_F(UIAbilityLifecycleManagerSecondTest, DispatchForeground_001, TestSize.Level1) -{ - auto mgr = std::make_unique(); - - AbilityState state = AbilityState::ACTIVE; - - AbilityRequest abilityRequest; - auto abilityRecord = std::make_shared( - abilityRequest.want, abilityRequest.abilityInfo, abilityRequest.appInfo, abilityRequest.requestCode); - abilityRecord->currentState_ = AbilityState::INITIAL; - - std::shared_ptr runner; - std::weak_ptr server; - auto handler = std::make_shared(runner, server); - DelayedSingleton::GetInstance()->eventHandler_ = handler; - - DelayedSingleton::GetInstance()->taskHandler_ = nullptr; - - auto ret = mgr->DispatchForeground(abilityRecord, true, state); - - EXPECT_EQ(ret, ERR_INVALID_VALUE); -} - /** * @tc.name: BackToCallerAbilityWithResultLocked_001 * @tc.desc: BackToCallerAbilityWithResultLocked 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 118b8dff9dc2b764fa51af717b7e09d73d271056..0bee20422da63c8ea8221c8308d7b3a7e827bedb 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 @@ -713,19 +713,6 @@ HWTEST_F(UIAbilityLifecycleManagerTest, DispatchState_004, TestSize.Level1) EXPECT_EQ(mgr->DispatchState(abilityRecord, state), ERR_INVALID_VALUE); } -/** - * @tc.name: UIAbilityLifecycleManager_DispatchForeground_0100 - * @tc.desc: DispatchForeground - * @tc.type: FUNC - */ -HWTEST_F(UIAbilityLifecycleManagerTest, DispatchForeground_001, TestSize.Level1) -{ - auto mgr = std::make_unique(); - AbilityRequest abilityRequest; - auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); - EXPECT_EQ(mgr->DispatchForeground(abilityRecord, true, AbilityState::FOREGROUND), ERR_INVALID_VALUE); -} - /** * @tc.name: UIAbilityLifecycleManager_CompleteForegroundSuccess_0100 * @tc.desc: CompleteForegroundSuccess @@ -6121,50 +6108,22 @@ HWTEST_F(UIAbilityLifecycleManagerTest, DispatchForeground_0001, TestSize.Level1 request.abilityInfo.isStageBasedModel = true; request.abilityInfo.type = AppExecFwk::AbilityType::PAGE; auto record = AbilityRecord::CreateAbilityRecord(request); - record->SetAbilityState(AbilityState::FOREGROUNDING); - - int ret = mgr->DispatchForeground(record, true); + // abilityRecord nullptr + int ret = mgr->DispatchForeground(nullptr, true, AbilityState::FOREGROUNDING); EXPECT_EQ(ret, ERR_INVALID_VALUE); -} - -/** - * @tc.name: DispatchForeground_0002 - * @tc.desc: DispatchForeground - */ -HWTEST_F(UIAbilityLifecycleManagerTest, DispatchForeground_0002, TestSize.Level1) -{ - auto mgr = std::make_shared(); - AbilityRequest request; - request.abilityInfo.bundleName = "com.example.bundle"; - request.abilityInfo.name = "AbilityA"; - request.abilityInfo.moduleName = "moduleA"; - request.abilityInfo.isStageBasedModel = true; - request.abilityInfo.type = AppExecFwk::AbilityType::PAGE; - auto record = AbilityRecord::CreateAbilityRecord(request); - record->SetAbilityState(AbilityState::FOREGROUNDING); - - int ret = mgr->DispatchForeground(record, false, AbilityState::FOREGROUND_FAILED); + + // abilityRecord state INITIAL + record->SetAbilityState(AbilityState::INITIAL); + ret = mgr->DispatchForeground(record, true, AbilityState::FOREGROUNDING); EXPECT_EQ(ret, ERR_INVALID_VALUE); -} -/** - * @tc.name: DispatchForeground_0003 - * @tc.desc: DispatchForeground - */ -HWTEST_F(UIAbilityLifecycleManagerTest, DispatchForeground_0003, TestSize.Level1) -{ - auto mgr = std::make_shared(); - AbilityRequest request; - request.abilityInfo.bundleName = "com.example.bundle"; - request.abilityInfo.name = "AbilityA"; - request.abilityInfo.moduleName = "moduleA"; - request.abilityInfo.isStageBasedModel = true; - request.abilityInfo.type = AppExecFwk::AbilityType::PAGE; - auto record = AbilityRecord::CreateAbilityRecord(request); record->SetAbilityState(AbilityState::FOREGROUNDING); + ret = mgr->DispatchForeground(record, false, AbilityState::FOREGROUNDING); + EXPECT_EQ(ret, ERR_OK); - int ret = mgr->DispatchForeground(record, false, AbilityState::FOREGROUND_WINDOW_FREEZED); - EXPECT_EQ(ret, ERR_INVALID_VALUE); + record->SetAbilityState(AbilityState::FOREGROUNDING); + ret = mgr->DispatchForeground(record, false, AbilityState::FOREGROUND_WINDOW_FREEZED); + EXPECT_EQ(ret, ERR_OK); } /** diff --git a/test/unittest/ui_ability_lifecycle_manager_third_test/ui_ability_lifecycle_manager_third_test.cpp b/test/unittest/ui_ability_lifecycle_manager_third_test/ui_ability_lifecycle_manager_third_test.cpp index 676eb797a07f2b0c3ccef115212e5a738fa6aed3..3ce963fb16ba4bbf44160f87ba1909e08b1be533 100644 --- a/test/unittest/ui_ability_lifecycle_manager_third_test/ui_ability_lifecycle_manager_third_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_third_test/ui_ability_lifecycle_manager_third_test.cpp @@ -508,61 +508,6 @@ HWTEST_F(UIAbilityLifecycleManagerThirdTest, StartSpecifiedRequest_009, TestSize AppMgrUtil::appMgr_ = originAppMgr; } -/** - * @tc.name: UIAbilityLifecycleManager_DispatchForeground_0200 - * @tc.desc: DispatchForeground - * @tc.type: FUNC - */ -HWTEST_F(UIAbilityLifecycleManagerThirdTest, DispatchForeground_002, TestSize.Level1) -{ - auto mgr = std::make_unique(); - - AbilityState state = AbilityState::ACTIVE; - - std::shared_ptr runner; - std::weak_ptr server; - auto handler = std::make_shared(runner, server); - DelayedSingleton::GetInstance()->eventHandler_ = handler; - - auto taskHandler = TaskHandlerWrap::CreateQueueHandler("HelloWorld"); - DelayedSingleton::GetInstance()->taskHandler_ = nullptr; - - std::shared_ptr abilityRecord = nullptr; - - auto ret = mgr->DispatchForeground(abilityRecord, true, state); - - EXPECT_EQ(ret, ERR_INVALID_VALUE); -} - -/** - * @tc.name: UIAbilityLifecycleManager_DispatchForeground_0300 - * @tc.desc: DispatchForeground - * @tc.type: FUNC - */ -HWTEST_F(UIAbilityLifecycleManagerThirdTest, DispatchForeground_003, TestSize.Level1) -{ - auto mgr = std::make_unique(); - - AbilityState state = AbilityState::ACTIVE; - - std::shared_ptr runner; - std::weak_ptr server; - auto handler = std::make_shared(runner, server); - DelayedSingleton::GetInstance()->eventHandler_ = handler; - - auto taskHandler = TaskHandlerWrap::CreateQueueHandler("HelloWorld"); - DelayedSingleton::GetInstance()->taskHandler_ = nullptr; - - AbilityRequest abilityRequest; - auto abilityRecord = std::make_shared( - abilityRequest.want, abilityRequest.abilityInfo, abilityRequest.appInfo, abilityRequest.requestCode); - abilityRecord->currentState_ = AbilityState::ACTIVATING; - - auto ret = mgr->DispatchForeground(abilityRecord, true, state); - - EXPECT_EQ(ret, ERR_INVALID_VALUE); -} - /** * @tc.name: UIAbilityLifecycleManager_DispatchBackground_0200 * @tc.desc: DispatchBackground