diff --git a/interfaces/inner_api/ability_manager/include/ui_extension/ui_extension_session_info.h b/interfaces/inner_api/ability_manager/include/ui_extension/ui_extension_session_info.h index ac2d153068848e00a9ca5b3f022977153a795019..aff9b44c2fb7aeed7474c7d284c8dc6a368950e6 100755 --- a/interfaces/inner_api/ability_manager/include/ui_extension/ui_extension_session_info.h +++ b/interfaces/inner_api/ability_manager/include/ui_extension/ui_extension_session_info.h @@ -36,6 +36,7 @@ public: AAFwk::UIExtensionUsage uiExtensionUsage = AAFwk::UIExtensionUsage::MODAL; AppExecFwk::ElementName elementName; AppExecFwk::ExtensionAbilityType extensionAbilityType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED; + AppExecFwk::ElementName hostElementName; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/services/abilitymgr/src/extension_record/extension_record_manager.cpp b/services/abilitymgr/src/extension_record/extension_record_manager.cpp index a4167c102ffa038a05214728e1add8b5acf8469f..962def56597fc98fe39bb7cb3bb66157eda8a79e 100644 --- a/services/abilitymgr/src/extension_record/extension_record_manager.cpp +++ b/services/abilitymgr/src/extension_record/extension_record_manager.cpp @@ -632,6 +632,14 @@ int32_t ExtensionRecordManager::GetUIExtensionSessionInfo( uiExtensionSessionInfo.uiExtensionUsage = sessionInfo->uiExtensionUsage; uiExtensionSessionInfo.elementName = abilityRecord->GetElementName(); uiExtensionSessionInfo.extensionAbilityType = abilityRecord->GetAbilityInfo().extensionAbilityType; + + auto callerToken = sessionInfo->callerToken; + if (callerToken != nullptr) { + auto callerAbilityRecord = AAFwk::Token::GetAbilityRecordByToken(callerToken); + if (callerAbilityRecord != nullptr) { + uiExtensionSessionInfo.hostElementName = callerAbilityRecord->GetElementName(); + } + } return ERR_OK; } diff --git a/services/abilitymgr/src/ui_extension/ui_extension_session_info.cpp b/services/abilitymgr/src/ui_extension/ui_extension_session_info.cpp index 8a533ce95f2053c2c78a048038905e9462787e5c..3956fdd309e9c34003bc61e44e842e3c1f0914bb 100755 --- a/services/abilitymgr/src/ui_extension/ui_extension_session_info.cpp +++ b/services/abilitymgr/src/ui_extension/ui_extension_session_info.cpp @@ -37,6 +37,12 @@ UIExtensionSessionInfo *UIExtensionSessionInfo::Unmarshalling(Parcel &parcel) } info->elementName = *element; info->extensionAbilityType = static_cast(parcel.ReadInt32()); + std::unique_ptr hostElement(parcel.ReadParcelable()); + if (hostElement != nullptr) { + info->hostElementName = *hostElement; + } else { + TAG_LOGW(AAFwkTag::ABILITYMGR, "hostElement is null but allowed"); + } return info; } @@ -67,6 +73,11 @@ bool UIExtensionSessionInfo::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteParcelable(&hostElementName)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write hostElementName failed"); + return false; + } + return true; } } // namespace AbilityRuntime diff --git a/test/unittest/ui_extension/BUILD.gn b/test/unittest/ui_extension/BUILD.gn index 5eca962e025e419026ec9185e4931b3140790464..7d5692103b4350377998b08132c5e0f549b9cb68 100644 --- a/test/unittest/ui_extension/BUILD.gn +++ b/test/unittest/ui_extension/BUILD.gn @@ -18,5 +18,6 @@ group("unittest") { "extension_record_manager_second_test:unittest", "extension_record_manager_test:unittest", "ui_extension_get_host_info_test:unittest", + "ui_extension_session_info_test:unittest", ] } diff --git a/test/unittest/ui_extension/extension_record_manager_test/extension_record_manager_test.cpp b/test/unittest/ui_extension/extension_record_manager_test/extension_record_manager_test.cpp index 427cfa02ed2b6c1771bf916defa9ec04b848a27e..039bf144d69e59822825d85d61506eba28092985 100755 --- a/test/unittest/ui_extension/extension_record_manager_test/extension_record_manager_test.cpp +++ b/test/unittest/ui_extension/extension_record_manager_test/extension_record_manager_test.cpp @@ -549,5 +549,197 @@ HWTEST_F(ExtensionRecordManagerTest, GetOrCreateExtensionRecord_0200, TestSize.L hostBundleName, abilityRecord, isLoaded); EXPECT_NE(ret, ERR_OK); } + +/** + * @tc.name: GetUIExtensionSessionInfo_0100 + * @tc.desc: GetUIExtensionSessionInfo + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ExtensionRecordManagerTest, GetUIExtensionSessionInfo_0100, TestSize.Level1) +{ + sptr token; + UIExtensionSessionInfo uiExtensionSessionInfo; + auto extRecordMgr = std::make_shared(0); + auto ret = extRecordMgr->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo); + EXPECT_NE(ret, ERR_NULL_OBJECT); +} + +/** + * @tc.name: GetUIExtensionSessionInfo_0200 + * @tc.desc: GetUIExtensionSessionInfo + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ExtensionRecordManagerTest, GetUIExtensionSessionInfo_0200, TestSize.Level1) +{ + sptr token = sptr::MakeSptr(); + ASSERT_NE(token, nullptr); + UIExtensionSessionInfo uiExtensionSessionInfo; + auto extRecordMgr = std::make_shared(0); + auto ret = extRecordMgr->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo); + EXPECT_NE(ret, ERR_NULL_OBJECT); +} + +/** + * @tc.name: GetUIExtensionSessionInfo_0300 + * @tc.desc: GetUIExtensionSessionInfo + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ExtensionRecordManagerTest, GetUIExtensionSessionInfo_0300, TestSize.Level1) +{ + auto extRecordMgr = std::make_shared(0); + ASSERT_NE(extRecordMgr, nullptr); + + AAFwk::AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.unittest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; + auto abilityRecord = AAFwk::AbilityRecord::CreateAbilityRecord(abilityRequest); + ASSERT_NE(abilityRecord, nullptr); + auto extRecord = std::make_shared(abilityRecord); + int32_t extensionRecordId = 1; + extRecordMgr->AddExtensionRecord(extensionRecordId, extRecord); + + auto token = abilityRecord->GetToken(); + ASSERT_NE(token, nullptr); + + UIExtensionSessionInfo uiExtensionSessionInfo; + auto ret = extRecordMgr->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo); + EXPECT_NE(ret, ERR_NULL_OBJECT); +} + +/** + * @tc.name: GetUIExtensionSessionInfo_0400 + * @tc.desc: GetUIExtensionSessionInfo + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ExtensionRecordManagerTest, GetUIExtensionSessionInfo_0400, TestSize.Level1) +{ + auto extRecordMgr = std::make_shared(0); + ASSERT_NE(extRecordMgr, nullptr); + + AAFwk::AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.unittest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; + abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SYSDIALOG_COMMON; + auto abilityRecord = AAFwk::AbilityRecord::CreateAbilityRecord(abilityRequest); + ASSERT_NE(abilityRecord, nullptr); + auto extRecord = std::make_shared(abilityRecord); + int32_t extensionRecordId = 1; + extRecordMgr->AddExtensionRecord(extensionRecordId, extRecord); + + auto token = abilityRecord->GetToken(); + ASSERT_NE(token, nullptr); + + UIExtensionSessionInfo uiExtensionSessionInfo; + auto ret = extRecordMgr->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo); + EXPECT_NE(ret, ERR_NULL_OBJECT); +} + +/** + * @tc.name: GetUIExtensionSessionInfo_0500 + * @tc.desc: GetUIExtensionSessionInfo + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ExtensionRecordManagerTest, GetUIExtensionSessionInfo_0500, TestSize.Level1) +{ + auto extRecordMgr = std::make_shared(0); + ASSERT_NE(extRecordMgr, nullptr); + + AAFwk::AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.unittest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; + abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SYSDIALOG_COMMON; + std::string deviceId = "testDeviceId"; + std::string bundleName = "testBundleName"; + std::string abilityName = "testAbilityName"; + std::string moduleName = "testModuleName"; + abilityRequest.want.SetElementName(deviceId, bundleName, abilityName, moduleName); + auto abilityRecord = AAFwk::AbilityRecord::CreateAbilityRecord(abilityRequest); + ASSERT_NE(abilityRecord, nullptr); + auto extRecord = std::make_shared(abilityRecord); + int32_t extensionRecordId = 1; + extRecordMgr->AddExtensionRecord(extensionRecordId, extRecord); + + auto token = abilityRecord->GetToken(); + ASSERT_NE(token, nullptr); + + sptr sessionInfo = sptr::MakeSptr(); + sessionInfo->persistentId = 1; + sessionInfo->hostWindowId = 1; + sessionInfo->uiExtensionUsage = AAFwk::UIExtensionUsage::MODAL; + ASSERT_NE(sessionInfo, nullptr); + extRecord->abilityRecord_->SetSessionInfo(sessionInfo); + + UIExtensionSessionInfo uiExtensionSessionInfo; + auto ret = extRecordMgr->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.name: GetUIExtensionSessionInfo_0600 + * @tc.desc: GetUIExtensionSessionInfo + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ExtensionRecordManagerTest, GetUIExtensionSessionInfo_0600, TestSize.Level1) +{ + auto extRecordMgr = std::make_shared(0); + ASSERT_NE(extRecordMgr, nullptr); + + AAFwk::AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.unittest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; + abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SYSDIALOG_COMMON; + std::string deviceId = "testDeviceId"; + std::string bundleName = "testBundleName"; + std::string abilityName = "testAbilityName"; + std::string moduleName = "testModuleName"; + abilityRequest.want.SetElementName(deviceId, bundleName, abilityName, moduleName); + auto abilityRecord = AAFwk::AbilityRecord::CreateAbilityRecord(abilityRequest); + ASSERT_NE(abilityRecord, nullptr); + auto extRecord = std::make_shared(abilityRecord); + int32_t extensionRecordId = 1; + extRecordMgr->AddExtensionRecord(extensionRecordId, extRecord); + + auto token = abilityRecord->GetToken(); + + AAFwk::AbilityRequest callerAbilityRequest; + callerAbilityRequest.appInfo.bundleName = "com.example.unittest"; + callerAbilityRequest.abilityInfo.name = "MainAbility"; + callerAbilityRequest.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; + callerAbilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::SYSDIALOG_COMMON; + std::string callerDeviceId = "testDeviceId"; + std::string callerBundleName = "testBundleName"; + std::string callerAbilityName = "testAbilityName"; + std::string callerModuleName = "testModuleName"; + callerAbilityRequest.want.SetElementName(callerDeviceId, callerBundleName, callerAbilityName, callerModuleName); + auto callerAbilityRecord = AAFwk::AbilityRecord::CreateAbilityRecord(callerAbilityRequest); + ASSERT_NE(callerAbilityRecord, nullptr); + auto callerExtRecord = std::make_shared(callerAbilityRecord); + int32_t callerExtensionRecordId = 2; + extRecordMgr->AddExtensionRecord(callerExtensionRecordId, callerExtRecord); + sptr callerToken = callerAbilityRecord->GetToken(); + EXPECT_NE(callerToken, nullptr); + + sptr sessionInfo = sptr::MakeSptr(); + sessionInfo->persistentId = 1; + sessionInfo->hostWindowId = 1; + sessionInfo->uiExtensionUsage = AAFwk::UIExtensionUsage::MODAL; + sessionInfo->callerToken = callerToken; + ASSERT_NE(sessionInfo, nullptr); + extRecord->abilityRecord_->SetSessionInfo(sessionInfo); + + UIExtensionSessionInfo uiExtensionSessionInfo; + auto ret = extRecordMgr->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo); + EXPECT_NE(ret, ERR_OK); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/test/unittest/ui_extension/ui_extension_session_info_test/BUILD.gn b/test/unittest/ui_extension/ui_extension_session_info_test/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..210108f52b5e1ed6a0d1e7069feb1c31b9c96399 --- /dev/null +++ b/test/unittest/ui_extension/ui_extension_session_info_test/BUILD.gn @@ -0,0 +1,115 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_unittest("ui_extension_session_info_test") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../../cfi_blocklist.txt" + } + module_out_path = "ability_runtime/ability_runtime/ui_extension" + + cflags_cc = [] + + include_dirs = [ + "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_test_path}/mock/common/include", + ] + + sources = [ + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/ability_state_data.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_mgr_client.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_service_manager.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_state_data.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/application_state_observer_stub.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/page_state_data.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/process_data.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/process_bind_data.cpp", + "${ability_runtime_services_path}/abilitymgr/src/extension_record/extension_record.cpp", + "${ability_runtime_services_path}/abilitymgr/src/extension_record/extension_record_factory.cpp", + "${ability_runtime_services_path}/abilitymgr/src/extension_record/extension_record_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ui_extension/preload_uiext_state_observer.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record/ui_extension_record_factory.cpp", + "${ability_runtime_services_path}/common/src/app_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", + "${ability_runtime_test_path}/mock/common/src/mock_native_token.cpp", + "ui_extension_session_info_test.cpp", + ] + + configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_path}/utils/server/startup:startup_util", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:session_info", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_deps_wrapper", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "bundle_framework:libappexecfwk_common", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (ability_runtime_child_process) { + defines = [ "SUPPORT_CHILD_PROCESS" ] + } + if (ability_runtime_graphics) { + external_deps += [ + "input:libmmi-client", + "window_manager:libwsutils", + "window_manager:scene_session", + ] + } +} + +group("unittest") { + testonly = true + deps = [ ":ui_extension_session_info_test" ] +} diff --git a/test/unittest/ui_extension/ui_extension_session_info_test/ui_extension_session_info_test.cpp b/test/unittest/ui_extension/ui_extension_session_info_test/ui_extension_session_info_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49afccac509e7ccc3b1fb55db7af94f7fdd9e5f8 --- /dev/null +++ b/test/unittest/ui_extension/ui_extension_session_info_test/ui_extension_session_info_test.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "parcel.h" + +#define private public +#include "ui_extension/ui_extension_session_info.h" +#include "hilog_tag_wrapper.h" +#undef private + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AbilityRuntime { +class UIExtensionSessionInfoTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void UIExtensionSessionInfoTest::SetUpTestCase(void) +{} + +void UIExtensionSessionInfoTest::TearDownTestCase(void) +{} + +void UIExtensionSessionInfoTest::SetUp() +{} + +void UIExtensionSessionInfoTest::TearDown() +{} + +/** + * @tc.name: Marshalling_0100 + * @tc.desc: Marshalling + * @tc.type: FUNC + * @tc.require: issueI5OD2E + */ +HWTEST_F(UIExtensionSessionInfoTest, Marshalling_0100, TestSize.Level1) +{ + Parcel parcel; + UIExtensionSessionInfo* parcelable1 = new UIExtensionSessionInfo(); + parcelable1->persistentId = 1; + parcelable1->hostWindowId = 1; + parcelable1->uiExtensionUsage = AAFwk::UIExtensionUsage::MODAL; + std::string deviceId; + std::string bundleName = "ohos.test.bundle"; + std::string abilityName = "TestAbility"; + std::string moduleName = "entry"; + AppExecFwk::ElementName elementName; + elementName.SetDeviceID(deviceId); + elementName.SetBundleName(bundleName); + elementName.SetAbilityName(abilityName); + elementName.SetModuleName(moduleName); + parcelable1->elementName = elementName; + parcelable1->extensionAbilityType = AppExecFwk::ExtensionAbilityType::SYSDIALOG_COMMON; + std::string hostDeviceId; + std::string hostBundleName = "ohos.test.bundle"; + std::string hostAbilityName = "TestAbility"; + std::string hostModuleName = "entry"; + AppExecFwk::ElementName hostElementName; + hostElementName.SetDeviceID(deviceId); + hostElementName.SetBundleName(hostBundleName); + hostElementName.SetAbilityName(hostAbilityName); + hostElementName.SetModuleName(hostModuleName); + parcelable1->hostElementName = hostElementName; + EXPECT_EQ(true, parcelable1->Marshalling(parcel)); + UIExtensionSessionInfo* parcelable2 = parcelable1->Unmarshalling(parcel); + EXPECT_EQ(parcelable2->persistentId, 1); + EXPECT_EQ(parcelable2->hostWindowId, 1); + EXPECT_EQ(parcelable2->uiExtensionUsage, AAFwk::UIExtensionUsage::MODAL); + EXPECT_EQ(parcelable2->elementName, elementName); + EXPECT_EQ(parcelable2->extensionAbilityType, AppExecFwk::ExtensionAbilityType::SYSDIALOG_COMMON); + EXPECT_EQ(parcelable2->hostElementName, hostElementName); +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file