!15484 not transmitting ability name

Merge pull request !15484 from wangbing/OpenAtomicService_0705
This commit is contained in:
openharmony_ci
2025-07-07 06:41:07 +00:00
committed by Gitee
7 changed files with 84 additions and 4 deletions
@@ -485,7 +485,7 @@ void ExtensionImpl::ScheduleAbilityRequestSuccess(const std::string &requestId,
{
TAG_LOGD(AAFwkTag::EXT, "ScheduleAbilityRequestSuccess called");
if (extension_ == nullptr) {
TAG_LOGE(AAFwkTag::EXT, "null ability_");
TAG_LOGE(AAFwkTag::EXT, "null extension_");
return;
}
nlohmann::json jsonObject = nlohmann::json {
@@ -132,6 +132,8 @@ private:
void NotifyAbilityRequestFailure(const std::string &dialogSessionId, const Want &want);
AppExecFwk::ElementName GetWantElement(const Want &want);
mutable ffrt::mutex dialogSessionRecordLock_;
std::unordered_map<std::string, sptr<DialogSessionInfo>> dialogSessionInfoMap_;
std::unordered_map<std::string, std::shared_ptr<DialogCallerInfo>> dialogCallerInfoMap_;
@@ -460,6 +460,7 @@ private:
void SetLastExitReason(std::shared_ptr<AbilityRecord> &abilityRecord) const;
void SetReceiverInfo(const AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &abilityRecord) const;
AppExecFwk::ElementName GetWantElement(sptr<SessionInfo> &sessionInfo, const AbilityRequest &abilityRequest);
/**
* @brief Execute PrepareTerminateApp when it is implemented
@@ -234,6 +234,28 @@ void DialogSessionManager::GenerateDialogCallerInfo(AbilityRequest &abilityReque
dialogCallerInfo->needGrantUriPermission = needGrantUriPermission;
}
AppExecFwk::ElementName DialogSessionManager::GetWantElement(const Want &want)
{
auto bms = AbilityUtil::GetBundleManagerHelper();
auto abilityMgr = DelayedSingleton<AbilityManagerService>::GetInstance();
if (bms == nullptr || abilityMgr == nullptr) {
return want.GetElement();
}
AppExecFwk::BundleInfo bundleInfo;
if (!IN_PROCESS_CALL(bms->GetBundleInfo(want.GetBundle(),
static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION),
bundleInfo, abilityMgr->GetUserId()))) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "GetBundleInfo failed");
return want.GetElement();
}
if (bundleInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE) {
AppExecFwk::ElementName element;
element.SetBundleName(want.GetElement().GetBundleName());
return element;
}
return want.GetElement();
}
void DialogSessionManager::NotifyAbilityRequestFailure(const std::string &dialogSessionId, const Want &want)
{
auto callerInfo = GetDialogCallerInfo(dialogSessionId);
@@ -254,7 +276,7 @@ void DialogSessionManager::NotifyAbilityRequestFailure(const std::string &dialog
} else if (callerInfo->type == SelectorType::INTERCEPTOR_SELECTOR) {
message = "User closed the interceptor picker";
}
abilityRecord->NotifyAbilityRequestFailure(requestId, want.GetElement(), message);
abilityRecord->NotifyAbilityRequestFailure(requestId, GetWantElement(want), message);
}
int DialogSessionManager::SendDialogResult(const Want &want, const std::string &dialogSessionId, bool isAllowed)
@@ -1493,6 +1493,17 @@ sptr<SessionInfo> UIAbilityLifecycleManager::CreateSessionInfo(const AbilityRequ
return sessionInfo;
}
AppExecFwk::ElementName UIAbilityLifecycleManager::GetWantElement(
sptr<SessionInfo> &sessionInfo, const AbilityRequest &abilityRequest)
{
if (sessionInfo != nullptr && sessionInfo->isAtomicService) {
AppExecFwk::ElementName element;
element.SetBundleName(abilityRequest.want.GetElement().GetBundleName());
return element;
}
return abilityRequest.want.GetElement();
}
int UIAbilityLifecycleManager::NotifySCBPendingActivation(sptr<SessionInfo> &sessionInfo,
const AbilityRequest &abilityRequest, std::string &errMsg)
{
@@ -1527,7 +1538,7 @@ int UIAbilityLifecycleManager::NotifySCBPendingActivation(sptr<SessionInfo> &ses
CheckCallerFromBackground(abilityRecord, sessionInfo);
auto requestId = abilityRequest.want.GetStringParam(KEY_REQUEST_ID);
if (!requestId.empty()) {
abilityRecord->NotifyAbilityRequestSuccess(requestId, abilityRequest.want.GetElement());
abilityRecord->NotifyAbilityRequestSuccess(requestId, GetWantElement(sessionInfo, abilityRequest));
}
const_cast<AbilityRequest &>(abilityRequest).want.RemoveParam(KEY_REQUEST_ID);
TAG_LOGI(AAFwkTag::ABILITYMGR, "scb call, NotifySCBPendingActivation for callerSession, target: %{public}s"
@@ -1545,7 +1556,7 @@ int UIAbilityLifecycleManager::NotifySCBPendingActivation(sptr<SessionInfo> &ses
auto requestId = abilityRequest.want.GetStringParam(KEY_REQUEST_ID);
if (!requestId.empty()) {
TAG_LOGI(AAFwkTag::ABILITYMGR, "notify request success, requestId:%{public}s", requestId.c_str());
abilityRecord->NotifyAbilityRequestSuccess(requestId, abilityRequest.want.GetElement());
abilityRecord->NotifyAbilityRequestSuccess(requestId, GetWantElement(sessionInfo, abilityRequest));
}
const_cast<AbilityRequest &>(abilityRequest).want.RemoveParam(KEY_REQUEST_ID);
}
@@ -872,5 +872,22 @@ HWTEST_F(DialogSessionManagerTest, HandleErmsResultBySCB_001, TestSize.Level1)
EXPECT_NE(result, ERR_INVALID_VALUE);
GTEST_LOG_(INFO) << "HandleErmsResultBySCB_001 end";
}
/**
* @tc.name: GetWantElement_001
* @tc.desc: test GetWantElement function
* @tc.type: FUNC
*/
HWTEST_F(DialogSessionManagerTest, GetWantElement_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "GetWantElement_001 start";
DialogSessionManager dialogSessionManager;
Want want;
AppExecFwk::ElementName element("", "com.test.demo", "MainAbility");
want.SetElement(element);
AppExecFwk::ElementName result = dialogSessionManager.GetWantElement(want);
EXPECT_EQ(result.GetAbilityName(), "MainAbility");
GTEST_LOG_(INFO) << "GetWantElement_001 end";
}
} // namespace AAFwk
} // namespace OHOS
@@ -6724,5 +6724,32 @@ HWTEST_F(UIAbilityLifecycleManagerTest, EnableListForSCBRecovery_001, TestSize.L
EXPECT_TRUE(mgr->isSCBRecovery_);
EXPECT_TRUE(mgr->coldStartInSCBRecovery_.empty());
}
/**
* @tc.name: UIAbilityLifecycleManager_GetWantElement_0100
* @tc.desc: GetWantElement
* @tc.type: FUNC
*/
HWTEST_F(UIAbilityLifecycleManagerTest, GetWantElement_0100, TestSize.Level1)
{
auto mgr = std::make_unique<UIAbilityLifecycleManager>();
Want want;
AppExecFwk::ElementName element("", "com.test.demo", "MainAbility");
want.SetElement(element);
AbilityRequest abilityRequest;
abilityRequest.want = want;
sptr<SessionInfo> sessionInfo = nullptr;
AppExecFwk::ElementName result = mgr->GetWantElement(sessionInfo, abilityRequest);
EXPECT_EQ(result.GetAbilityName(), "MainAbility");
sessionInfo = new SessionInfo();
ASSERT_NE(sessionInfo, nullptr);
sessionInfo->isAtomicService = false;
result = mgr->GetWantElement(sessionInfo, abilityRequest);
EXPECT_EQ(result.GetAbilityName(), "MainAbility");
sessionInfo->isAtomicService = true;
result = mgr->GetWantElement(sessionInfo, abilityRequest);
EXPECT_TRUE(result.GetAbilityName().empty());
}
} // namespace AAFwk
} // namespace OHOS