已合并
fix foreground #20360
xhz-sz创建于 14 天前
fix foreground #20360
已合并
共 2 个文件变更+92-14
| @@ -343,24 +343,34 @@ void UIExtensionAbilityManager::OnAbilityRequestDone(const sptr<IRemoteObject> & | |||
| 343 | std::lock_guard guard(serialMutex_); | 343 | std::lock_guard guard(serialMutex_); |
| 344 | 344 | ||
| 345 | AppAbilityState abilityState = DelayedSingleton<AppScheduler>::GetInstance()->ConvertToAppAbilityState(state); | 345 | AppAbilityState abilityState = DelayedSingleton<AppScheduler>::GetInstance()->ConvertToAppAbilityState(state); |
| 346 | - if (abilityState == AppAbilityState::ABILITY_STATE_FOREGROUND) { | 346 | + if (abilityState != AppAbilityState::ABILITY_STATE_FOREGROUND) { |
| 347 | - auto abilityRecord = GetExtensionByTokenFromServiceMap(token); | 347 | + return; |
| 348 | - CHECK_POINTER(abilityRecord); | 348 | + } |
| 349 | 349 | ||
| 350 | - if (!IsUIExtensionAbility(abilityRecord)) { | 350 | + auto abilityRecord = GetExtensionByTokenFromServiceMap(token); |
| 351 | - TAG_LOGE(AAFwkTag::EXT, "Not ui extension"); | 351 | + CHECK_POINTER(abilityRecord); |
| 352 | - return; | ||
| 353 | - } | ||
| 354 | 352 | ||
| 355 | - if (abilityRecord->IsAbilityState(AbilityState::FOREGROUNDING)) { | 353 | + if (!IsUIExtensionAbility(abilityRecord)) { |
| 356 | - TAG_LOGW(AAFwkTag::EXT, "abilityRecord foregrounding"); | 354 | + TAG_LOGE(AAFwkTag::EXT, "Not ui extension"); |
| 357 | - return; | 355 | + return; |
| 358 | - } | 356 | + } |
| 359 | 357 | ||
| 360 | - std::string element = abilityRecord->GetURI(); | 358 | + auto currentAbilityState = abilityRecord->GetAbilityState(); |
| 361 | - TAG_LOGD(AAFwkTag::EXT, "Ability is %{public}s, start to foreground.", element.c_str()); | 359 | + auto sessionInfo = abilityRecord->GetSessionInfo(); |
| 360 | + TAG_LOGI(AAFwkTag::UI_EXT, "%{public}s/%{public}s, persistentId:%{public}d, Id:%{public}d, " | ||
| 361 | + "abilityState:%{public}d, pendingState:%{public}d", | ||
| 362 | + abilityRecord->GetInfoBundleName().c_str(), | ||
| 363 | + abilityRecord->GetInfoAbilityName().c_str(), | ||
| 364 | + sessionInfo ? sessionInfo->persistentId : -1, | ||
| 365 | + abilityRecord->GetUIExtensionAbilityId(), | ||
| 366 | + static_cast<int32_t>(currentAbilityState), | ||
| 367 | + static_cast<int32_t>(abilityRecord->GetPendingState())); | ||
| 368 | + if (currentAbilityState == AbilityState::BACKGROUND || currentAbilityState == AbilityState::INITIAL || | ||
| 369 | + currentAbilityState == AbilityState::INACTIVE || currentAbilityState == AbilityState::ACTIVE) { | ||
| 362 | abilityRecord->ForegroundUIExtensionAbility(); | 370 | abilityRecord->ForegroundUIExtensionAbility(); |
| 363 | abilityRecord->RemoveUIExtensionLaunchTimestamp(); | 371 | abilityRecord->RemoveUIExtensionLaunchTimestamp(); |
| 372 | + } else { | ||
| 373 | + TAG_LOGW(AAFwkTag::UI_EXT, "skip foreground, abilityState not in {BACKGROUND, INITIAL, INACTIVE, ACTIVE}"); | ||
| 364 | } | 374 | } |
| 365 | } | 375 | } |
| 366 | 376 | ||
| @@ -1591,4 +1601,4 @@ void UIExtensionAbilityManager::CompleteBackground(const std::shared_ptr<BaseExt | |||
| 1591 | TerminateAbilityLocked(abilityRecord->GetToken()); | 1601 | TerminateAbilityLocked(abilityRecord->GetToken()); |
| 1592 | } | 1602 | } |
| 1593 | } // namespace AAFwk | 1603 | } // namespace AAFwk |
| 1594 | -} // namespace OHOS | 1604 | +} // namespace OHOS |
Mtest/unittest/ui_extension_ability_manager_third_test/ui_extension_ability_manager_third_test.cpp+68-0
| @@ -25,7 +25,9 @@ | |||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | + | ||
| 28 | 29 | ||
| 30 | + | ||
| 29 | 31 | ||
| 30 | 32 | ||
| 31 | 33 | ||
| @@ -35,6 +37,10 @@ using namespace testing::ext; | |||
| 35 | 37 | ||
| 36 | namespace OHOS { | 38 | namespace OHOS { |
| 37 | namespace AAFwk { | 39 | namespace AAFwk { |
| 40 | +namespace { | ||
| 41 | +const std::string UIEXTENSION_LAUNCH_TIMESTAMP_HIGH = "ohos.ability.params.uiExtensionLaunchTimestampHigh"; | ||
| 42 | +} | ||
| 43 | + | ||
| 38 | class MockPreloadHostClient final : public IRemoteObject { | 44 | class MockPreloadHostClient final : public IRemoteObject { |
| 39 | public: | 45 | public: |
| 40 | explicit MockPreloadHostClient(bool addDeathRecipientResult) | 46 | explicit MockPreloadHostClient(bool addDeathRecipientResult) |
| @@ -106,6 +112,68 @@ public: | |||
| 106 | 112 | ||
| 107 | class UIExtensionAbilityManagerThirdTest : public testing::Test {}; | 113 | class UIExtensionAbilityManagerThirdTest : public testing::Test {}; |
| 108 | 114 | ||
| 115 | +/* | ||
| 116 | + * Feature: UIExtensionAbilityManager | ||
| 117 | + * Function: OnAbilityRequestDone | ||
| 118 | + * CaseDescription: Verify a foregrounding UIExtension retains its modal launch timestamp | ||
| 119 | + */ | ||
| 120 | +HWTEST_F(UIExtensionAbilityManagerThirdTest, OnAbilityRequestDone_001, TestSize.Level1) | ||
| 121 | +{ | ||
| 122 | + auto connectManager = std::make_shared<UIExtensionAbilityManager>(0); | ||
| 123 | + ASSERT_NE(connectManager, nullptr); | ||
| 124 | + | ||
| 125 | + AbilityRequest abilityRequest; | ||
| 126 | + abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SYS_COMMON_UI; | ||
| 127 | + abilityRequest.abilityInfo.bundleName = "com.test.uiextension"; | ||
| 128 | + abilityRequest.abilityInfo.name = "TestUIExtension"; | ||
| 129 | + auto abilityRecord = BaseExtensionRecord::CreateBaseExtensionRecord(abilityRequest); | ||
| 130 | + ASSERT_NE(abilityRecord, nullptr); | ||
| 131 | + abilityRecord->SetAbilityState(AbilityState::FOREGROUNDING); | ||
| 132 | + auto sessionInfo = sptr<SessionInfo>::MakeSptr(); | ||
| 133 | + ASSERT_NE(sessionInfo, nullptr); | ||
| 134 | + sessionInfo->persistentId = 1; | ||
| 135 | + sessionInfo->uiExtensionUsage = AppExecFwk::UIExtensionUsage::MODAL; | ||
| 136 | + abilityRecord->SetSessionInfo(sessionInfo); | ||
| 137 | + abilityRecord->AddUIExtensionLaunchTimestamp(); | ||
| 138 | + EXPECT_NE(abilityRecord->GetWant().GetIntParam(UIEXTENSION_LAUNCH_TIMESTAMP_HIGH, -1), -1); | ||
| 139 | + connectManager->CallAddToServiceMap("uiextension", abilityRecord); | ||
| 140 | + | ||
| 141 | + connectManager->OnAbilityRequestDone(abilityRecord->GetToken(), | ||
| 142 | + static_cast<int32_t>(AppAbilityState::ABILITY_STATE_FOREGROUND)); | ||
| 143 | + EXPECT_NE(abilityRecord->GetWant().GetIntParam(UIEXTENSION_LAUNCH_TIMESTAMP_HIGH, -1), -1); | ||
| 144 | +} | ||
| 145 | + | ||
| 146 | +/* | ||
| 147 | + * Feature: UIExtensionAbilityManager | ||
| 148 | + * Function: OnAbilityRequestDone | ||
| 149 | + * CaseDescription: Verify an already foreground UIExtension skips foreground and retains timestamp | ||
| 150 | + */ | ||
| 151 | +HWTEST_F(UIExtensionAbilityManagerThirdTest, OnAbilityRequestDone_002, TestSize.Level1) | ||
| 152 | +{ | ||
| 153 | + auto connectManager = std::make_shared<UIExtensionAbilityManager>(0); | ||
| 154 | + ASSERT_NE(connectManager, nullptr); | ||
| 155 | + | ||
| 156 | + AbilityRequest abilityRequest; | ||
| 157 | + abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SYS_COMMON_UI; | ||
| 158 | + abilityRequest.abilityInfo.bundleName = "com.test.uiextension"; | ||
| 159 | + abilityRequest.abilityInfo.name = "TestUIExtension"; | ||
| 160 | + auto abilityRecord = BaseExtensionRecord::CreateBaseExtensionRecord(abilityRequest); | ||
| 161 | + ASSERT_NE(abilityRecord, nullptr); | ||
| 162 | + abilityRecord->SetAbilityState(AbilityState::FOREGROUND); | ||
| 163 | + auto sessionInfo = sptr<SessionInfo>::MakeSptr(); | ||
| 164 | + ASSERT_NE(sessionInfo, nullptr); | ||
| 165 | + sessionInfo->persistentId = 1; | ||
| 166 | + sessionInfo->uiExtensionUsage = AppExecFwk::UIExtensionUsage::MODAL; | ||
| 167 | + abilityRecord->SetSessionInfo(sessionInfo); | ||
| 168 | + abilityRecord->AddUIExtensionLaunchTimestamp(); | ||
| 169 | + EXPECT_NE(abilityRecord->GetWant().GetIntParam(UIEXTENSION_LAUNCH_TIMESTAMP_HIGH, -1), -1); | ||
| 170 | + connectManager->CallAddToServiceMap("uiextension", abilityRecord); | ||
| 171 | + | ||
| 172 | + connectManager->OnAbilityRequestDone(abilityRecord->GetToken(), | ||
| 173 | + static_cast<int32_t>(AppAbilityState::ABILITY_STATE_FOREGROUND)); | ||
| 174 | + EXPECT_NE(abilityRecord->GetWant().GetIntParam(UIEXTENSION_LAUNCH_TIMESTAMP_HIGH, -1), -1); | ||
| 175 | +} | ||
| 176 | + | ||
| 109 | /* | 177 | /* |
| 110 | * Feature: UIExtensionAbilityManager | 178 | * Feature: UIExtensionAbilityManager |
| 111 | * Function: RegisterPreloadUIExtensionHostClient | 179 | * Function: RegisterPreloadUIExtensionHostClient |
是什么状态给漏了