From e325b40a46662a506fdb14cf72b5eda0e7391c78 Mon Sep 17 00:00:00 2001 From: shenxz Date: Mon, 11 Aug 2025 12:14:44 +0800 Subject: [PATCH] support install app with devicetype glasses Signed-off-by: shenxz --- appexecfwk.gni | 1 + bundle.json | 3 +- services/bundlemgr/BUILD.gn | 4 +++ .../bundlemgr/src/bundle_install_checker.cpp | 8 +++++ .../test/mock/src/parameter/parameter.cpp | 3 ++ .../bms_bundle_installer_test/BUILD.gn | 4 +++ .../bms_bundle_install_device_type_test.cpp | 30 +++++++++++++++++++ 7 files changed, 52 insertions(+), 1 deletion(-) diff --git a/appexecfwk.gni b/appexecfwk.gni index edce603724..e650b46086 100644 --- a/appexecfwk.gni +++ b/appexecfwk.gni @@ -53,6 +53,7 @@ declare_args() { bundle_framework_bundle_resource = true bundle_framework_form_dimension_2_3 = false bundle_framework_form_dimension_3_3 = false + bundle_framework_support_glasses = false ability_runtime_enable = true account_enable = true diff --git a/bundle.json b/bundle.json index ab0d64e3d2..432eaf5dd4 100644 --- a/bundle.json +++ b/bundle.json @@ -28,7 +28,8 @@ "bundle_framework_sandbox_app", "bundle_framework_quick_fix", "bundle_framework_form_dimension_2_3", - "bundle_framework_form_dimension_3_3" + "bundle_framework_form_dimension_3_3", + "bundle_framework_support_glasses" ], "hisysevent_config": [ "//foundation/bundlemanager/bundle_framework/hisysevent.yaml", diff --git a/services/bundlemgr/BUILD.gn b/services/bundlemgr/BUILD.gn index 128fe9006b..7dd3513305 100644 --- a/services/bundlemgr/BUILD.gn +++ b/services/bundlemgr/BUILD.gn @@ -527,6 +527,10 @@ ohos_shared_library("libbms") { sources += user_auth } + if (bundle_framework_support_glasses) { + defines += [ "BMS_SUPPORT_GLASSES=\"glasses\"" ] + } + subsystem_name = "bundlemanager" part_name = "bundle_framework" } diff --git a/services/bundlemgr/src/bundle_install_checker.cpp b/services/bundlemgr/src/bundle_install_checker.cpp index aba821249d..48ed5eaa51 100644 --- a/services/bundlemgr/src/bundle_install_checker.cpp +++ b/services/bundlemgr/src/bundle_install_checker.cpp @@ -1474,6 +1474,14 @@ ErrCode BundleInstallChecker::CheckDeviceType(std::unordered_map(DEVICE_TYPE_OF_DEFAULT); } + if (strcmp(g_testDeviceType, "glasses") == 0) { + return g_testDeviceType; + } return const_cast(EMPTY_STRING); } diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_bundle_installer_test/BUILD.gn index c53d5dc0ee..49e27c1296 100755 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/BUILD.gn @@ -1122,6 +1122,10 @@ ohos_unittest("BmsBundleInstallDeviceTypeTest") { [ "${services_path}/bundlemgr/src/aot/aot_sign_data_cache_mgr.cpp" ] defines += [ "CODE_SIGNATURE_ENABLE" ] } + + if (bundle_framework_support_glasses) { + defines += [ "BMS_SUPPORT_GLASSES=\"glasses\"" ] + } } ohos_unittest("BmsSystemBundleInstallerTest") { diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_device_type_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_device_type_test.cpp index dafcecaa3c..51855fc960 100755 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_device_type_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_device_type_test.cpp @@ -233,6 +233,36 @@ HWTEST_F(BmsBundleInstallDeviceTypeTest, DeviceTypeTest_0700, Function | SmallTe EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_DEVICE_TYPE_NOT_SUPPORTED); } +#ifdef BMS_SUPPORT_GLASSES +/** + * @tc.number: DeviceTypeTest_0800 + * @tc.name: test CheckDeviceType function of BundleInstallChecker + * @tc.desc: 1. Obtain current device type + * 2. Obtain device type list of the unordered_map of InnerbundleInfo + * 3. checking should be passed when device type is 'glasses' + */ +HWTEST_F(BmsBundleInstallDeviceTypeTest, DeviceTypeTest_0800, Function | SmallTest | Level0) +{ + // mock innerbundleinfo with default device type + std::unordered_map infos; + std::vector vec = {"wearable"}; + SetDeviceTypes(infos, vec); + + char deviceTypeOfGlasses[] = "glasses"; + g_testDeviceType = deviceTypeOfGlasses; + // device type list is wearable and current device is glasses, check should be passed + BundleInstallChecker checker; + auto ret = checker.CheckDeviceType(infos); + EXPECT_EQ(ret, ERR_OK); + + vec[0] = DEVICE_TYPE_OF_PHONE; + SetDeviceTypes(infos, vec); + // device type list is phone and current device is glasses, check should be failed + ret = checker.CheckDeviceType(infos); + EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_DEVICE_TYPE_NOT_SUPPORTED); +} +#endif + /** * @tc.number: CheckSupportAppTypes_0100 * @tc.name: test CheckSupportAppTypes function of BundleInstallChecker -- Gitee