From 7bfc28cf654b9a910c94684f7c414835480acffb Mon Sep 17 00:00:00 2001 From: lanhaoyu Date: Thu, 11 Sep 2025 15:20:27 +0800 Subject: [PATCH] fix_input_suffix_state Signed-off-by: lanhaoyu --- .../include/bundle_constants.h | 1 + .../inner_api/appexecfwk_base/src/skill.cpp | 15 ++++---- .../bundlemgr/include/bundle_mgr_host_impl.h | 2 +- .../bundlemgr/src/bundle_mgr_host_impl.cpp | 36 +++++++++++-------- .../bms_bundle_default_app_test.cpp | 2 +- .../bms_bundle_manager_test.cpp | 14 ++++++-- .../bms_bundle_manager_test_three.cpp | 25 +++++++++++-- 7 files changed, 67 insertions(+), 28 deletions(-) diff --git a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h index b30ef526b9..861d73eec5 100644 --- a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h +++ b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h @@ -186,6 +186,7 @@ constexpr const char* VERIFY_UNINSTALL_RULE_KEY = "ohos.bms.param.verifyUninstal constexpr const char* VERIFY_UNINSTALL_RULE_VALUE = "true"; constexpr const char* SUPPORT_APP_TYPES_SEPARATOR = ","; +constexpr const char* SCHEME_SEPARATOR = "://"; constexpr const char* APP_DISTRIBUTION_TYPE_WHITE_LIST = "appDistributionTypeWhiteList"; constexpr const char* ARKTS_MODE = "arkTSMode"; diff --git a/interfaces/inner_api/appexecfwk_base/src/skill.cpp b/interfaces/inner_api/appexecfwk_base/src/skill.cpp index c170fe80f9..3d1ea8aa14 100644 --- a/interfaces/inner_api/appexecfwk_base/src/skill.cpp +++ b/interfaces/inner_api/appexecfwk_base/src/skill.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -48,7 +48,6 @@ constexpr const char* JSON_KEY_DOMAINVERIFY = "domainVerify"; constexpr const char* BUNDLE_MODULE_PROFILE_KEY_PATHREGX = "pathRegx"; constexpr const char* PARAM_SEPARATOR = "?"; constexpr const char* PORT_SEPARATOR = ":"; -constexpr const char* SCHEME_SEPARATOR = "://"; constexpr const char* PATH_SEPARATOR = "/"; constexpr const char* TYPE_WILDCARD = "*/*"; const char WILDCARD = '*'; @@ -263,7 +262,7 @@ bool Skill::MatchLinkFeature(const std::string &linkFeature, const OHOS::AAFwk:: } for (const std::string ¶mUtd : paramUtdVector) { if ((MatchUri(paramUriString, skillUri) || - (skillUri.scheme.empty() && paramUriString.find(SCHEME_SEPARATOR) == std::string::npos)) && + (skillUri.scheme.empty() && paramUriString.find(Constants::SCHEME_SEPARATOR) == std::string::npos)) && MatchType(paramUtd, skillUri.type)) { matchUriIndex = uriIndex; return true; @@ -343,7 +342,7 @@ std::string Skill::GetOptParamUri(const std::string &uriString) std::string Skill::ConvertUriToLower(const std::string& uri) const { - size_t protocolEnd = uri.find(SCHEME_SEPARATOR); + size_t protocolEnd = uri.find(Constants::SCHEME_SEPARATOR); if (protocolEnd == std::string::npos || protocolEnd + PROTOCOL_OFFSET == uri.size()) { return ConvertToLower(uri); } @@ -360,7 +359,7 @@ std::string Skill::ConvertUriToLower(const std::string& uri) const std::string path = (endHost == std::string::npos) ? "" : uri.substr(endHost); std::transform(protocol.begin(), protocol.end(), protocol.begin(), [](unsigned char c) { return std::tolower(c); }); std::transform(host.begin(), host.end(), host.begin(), [](unsigned char c) { return std::tolower(c); }); - return protocol + SCHEME_SEPARATOR + host + path; + return protocol + Constants::SCHEME_SEPARATOR + host + path; } inline std::string Skill::ConvertToLower(const std::string &str) const @@ -393,7 +392,7 @@ bool Skill::MatchUri(const std::string &uriString, const SkillUri &skillUri) con } std::string optParamUri = ConvertUriToLower(GetOptParamUri(uriString)); std::string skillUriTmpString; - skillUriTmpString.append(skillUri.scheme).append(SCHEME_SEPARATOR).append(skillUri.host); + skillUriTmpString.append(skillUri.scheme).append(Constants::SCHEME_SEPARATOR).append(skillUri.host); std::string skillUriString = ConvertUriToLower(skillUriTmpString); if (!skillUri.port.empty()) { @@ -583,7 +582,7 @@ bool Skill::MatchMimeType(const std::string & uriString) const for (const SkillUri &skillUri : uris) { for (const std::string ¶mUtd : paramUtdVector) { if ((MatchUri(uriString, skillUri) || - (skillUri.scheme.empty() && uriString.find(SCHEME_SEPARATOR) == std::string::npos)) && + (skillUri.scheme.empty() && uriString.find(Constants::SCHEME_SEPARATOR) == std::string::npos)) && MatchType(paramUtd, skillUri.type)) { return true; } @@ -603,7 +602,7 @@ bool Skill::MatchMimeType(const std::string & uriString, size_t &matchUriIndex) const SkillUri &skillUri = uris[uriIndex]; for (const std::string ¶mUtd : paramUtdVector) { if ((MatchUri(uriString, skillUri) || - (skillUri.scheme.empty() && uriString.find(SCHEME_SEPARATOR) == std::string::npos)) && + (skillUri.scheme.empty() && uriString.find(Constants::SCHEME_SEPARATOR) == std::string::npos)) && MatchType(paramUtd, skillUri.type)) { matchUriIndex = uriIndex; return true; diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index bf143ebfa9..6c3f1ea398 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -1263,7 +1263,7 @@ private: const std::string &abilityName, int32_t appIndex, const std::vector &launcherAbilityResourceInfos, LauncherAbilityResourceInfo &resultAbilityResourceInfo); - ErrCode ImplicitQueryAbilityInfosWithDefault(const std::string &normalizedType, + ErrCode ImplicitQueryAbilityInfosWithDefault(const Want &want, std::vector &launcherAbilityResourceInfos); std::atomic isBrokerServiceExisted_ = false; diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index f841ca40e8..3c5d106db9 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -6185,7 +6185,7 @@ bool BundleMgrHostImpl::GetSpecificResourceInfo(const std::string &bundleName, return false; } -ErrCode BundleMgrHostImpl::ImplicitQueryAbilityInfosWithDefault(const std::string &normalizedType, +ErrCode BundleMgrHostImpl::ImplicitQueryAbilityInfosWithDefault(const Want &want, std::vector &launcherAbilityResourceInfos) { #ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE @@ -6194,10 +6194,6 @@ ErrCode BundleMgrHostImpl::ImplicitQueryAbilityInfosWithDefault(const std::strin APP_LOGE("dataMgr is nullptr"); return ERR_APPEXECFWK_NULL_PTR; } - Want want; - want.SetType(normalizedType); - want.SetAction(ACTION_VIEW_DATA); - want.SetUri(FILE_URI); int32_t abilityInfoflags = static_cast(GetAbilityInfoFlag::GET_ABILITY_INFO_DEFAULT); auto uid = IPCSkeleton::GetCallingUid(); int32_t userId = BundleUtil::GetUserIdByUid(uid); @@ -6287,16 +6283,28 @@ ErrCode BundleMgrHostImpl::GetAbilityResourceInfo(const std::string &fileType, APP_LOGE("verify permission failed"); return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; } - std::vector normalizedTypeVector = BundleUtil::FileTypeNormalize(fileType); - APP_LOGI("normalized:%{public}s", BundleUtil::ToString(normalizedTypeVector).c_str()); - if (normalizedTypeVector.empty()) { - APP_LOGW("normalizedTypeVector empty"); - return ERR_APPEXECFWK_INPUT_WRONG_TYPE_FILE; - } - for (const std::string& normalizedType : normalizedTypeVector) { - (void)ImplicitQueryAbilityInfosWithDefault(normalizedType, launcherAbilityResourceInfos); + if (fileType[0] != '.') { + std::vector normalizedTypeVector = BundleUtil::FileTypeNormalize(fileType); + APP_LOGI("normalized:%{public}s", BundleUtil::ToString(normalizedTypeVector).c_str()); + if (normalizedTypeVector.empty()) { + APP_LOGW("normalizedTypeVector empty"); + return ERR_APPEXECFWK_INPUT_WRONG_TYPE_FILE; + } + for (const std::string& normalizedType : normalizedTypeVector) { + Want want; + want.SetType(normalizedType); + want.SetAction(ACTION_VIEW_DATA); + want.SetUri(FILE_URI); + (void)ImplicitQueryAbilityInfosWithDefault(want, launcherAbilityResourceInfos); + } + RemoveSameAbilityResourceInfo(launcherAbilityResourceInfos); + } else { + Want want; + want.SetAction(ACTION_VIEW_DATA); + want.SetUri(FILE_URI + Constants::SCHEME_SEPARATOR + fileType); + (void)ImplicitQueryAbilityInfosWithDefault(want, launcherAbilityResourceInfos); } - RemoveSameAbilityResourceInfo(launcherAbilityResourceInfos); + APP_LOGI("GetAbilityResourceInfo end, size: %{public}zu", launcherAbilityResourceInfos.size()); return ERR_OK; } diff --git a/services/bundlemgr/test/unittest/bms_bundle_default_app_test/bms_bundle_default_app_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_default_app_test/bms_bundle_default_app_test.cpp index 014f97d491..a10a5fa9fd 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_default_app_test/bms_bundle_default_app_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_default_app_test/bms_bundle_default_app_test.cpp @@ -2510,7 +2510,7 @@ HWTEST_F(BmsBundleDefaultAppTest, ImplicitQueryAbilityInfosWithDefault_0200, Fun auto hostImpl = std::make_unique(); std::vector launcherAbilityResourceInfos; setuid(20000001); - ret = hostImpl->ImplicitQueryAbilityInfosWithDefault(PDF_MIME_TYPE, launcherAbilityResourceInfos); + ret = hostImpl->ImplicitQueryAbilityInfosWithDefault(want, launcherAbilityResourceInfos); setuid(0); EXPECT_EQ(ret, ERR_OK); EXPECT_NE(launcherAbilityResourceInfos.size(), 0); diff --git a/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test.cpp index 6cb044d7dd..8ea360f4ea 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test.cpp @@ -91,6 +91,8 @@ const uint32_t BUNDLE_BACKUP_ICON_ID = 16777221; const std::string CALLER_NAME_UT = "ut"; const std::string DEVICETYPE = "deviceType"; const int32_t APPINDEX = 10; +constexpr const char* ACTION_VIEW_DATA = "ohos.want.action.viewData"; +const std::string FILE_URI = "file"; } // namespace class BmsBundleManagerTest : public testing::Test { @@ -3213,7 +3215,11 @@ HWTEST_F(BmsBundleManagerTest, ImplicitQueryAbilityInfosWithDefault_0001, Functi auto hostImpl = std::make_unique(); std::string fileType = "general.general"; std::vector launcherAbilityResourceInfos; - ErrCode ret = hostImpl->ImplicitQueryAbilityInfosWithDefault(fileType, launcherAbilityResourceInfos); + AAFwk::Want want; + want.SetType(fileType); + want.SetAction(ACTION_VIEW_DATA); + want.SetUri(FILE_URI); + ErrCode ret = hostImpl->ImplicitQueryAbilityInfosWithDefault(want, launcherAbilityResourceInfos); EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_ABILITY_INFO_NOT_FOUND); } @@ -3230,7 +3236,11 @@ HWTEST_F(BmsBundleManagerTest, ImplicitQueryAbilityInfosWithDefault_0002, Functi ScopeGuard stateGuard([&] { ResetDataMgr(); }); std::string fileType = "text/html"; std::vector launcherAbilityResourceInfos; - ErrCode ret = hostImpl->ImplicitQueryAbilityInfosWithDefault(fileType, launcherAbilityResourceInfos); + AAFwk::Want want; + want.SetType(fileType); + want.SetAction(ACTION_VIEW_DATA); + want.SetUri(FILE_URI); + ErrCode ret = hostImpl->ImplicitQueryAbilityInfosWithDefault(want, launcherAbilityResourceInfos); EXPECT_EQ(ret, ERR_APPEXECFWK_NULL_PTR); EXPECT_EQ(launcherAbilityResourceInfos.size(), 0); } diff --git a/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp b/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp index f6697dd264..28ebf6c523 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp @@ -92,6 +92,8 @@ const uint32_t BUNDLE_BACKUP_ICON_ID = 16777221; const std::string CALLER_NAME_UT = "ut"; const std::string DEVICETYPE = "deviceType"; const int32_t APPINDEX = 10; +constexpr const char* ACTION_VIEW_DATA = "ohos.want.action.viewData"; +const std::string FILE_URI = "file"; } // namespace class BmsBundleManagerTest3 : public testing::Test { @@ -2170,13 +2172,28 @@ HWTEST_F(BmsBundleManagerTest3, GetAbilityResourceInfo_0002, Function | MediumTe HWTEST_F(BmsBundleManagerTest3, GetAbilityResourceInfo_0003, Function | MediumTest | Level1) { auto hostImpl = std::make_unique(); - std::string fileType = ".?"; + std::string fileType = "image/?"; std::vector launcherAbilityResourceInfos; auto testRet = hostImpl->GetAbilityResourceInfo(fileType, launcherAbilityResourceInfos); EXPECT_EQ(testRet, ERR_APPEXECFWK_INPUT_WRONG_TYPE_FILE); EXPECT_TRUE(launcherAbilityResourceInfos.empty()); } +/** + * @tc.number: GetAbilityResourceInfo_0004 + * @tc.name: test GetAbilityResourceInfo + * @tc.desc: 1.test GetAbilityResourceInfo + 2.text fileType + */ +HWTEST_F(BmsBundleManagerTest3, GetAbilityResourceInfo_0004, Function | MediumTest | Level1) +{ + auto hostImpl = std::make_unique(); + std::string fileType = ".jpg"; + std::vector launcherAbilityResourceInfos; + auto testRet = hostImpl->GetAbilityResourceInfo(fileType, launcherAbilityResourceInfos); + EXPECT_EQ(testRet, ERR_OK); +} + /** * @tc.number: GetSpecificResourceInfo_0001 * @tc.name: test GetSpecificResourceInfo @@ -2241,7 +2258,11 @@ HWTEST_F(BmsBundleManagerTest3, ImplicitQueryAbilityInfosWithDefault_0002, Funct auto hostImpl = std::make_unique(); std::string fileType = "text/html"; std::vector launcherAbilityResourceInfos; - ErrCode ret = hostImpl->ImplicitQueryAbilityInfosWithDefault(fileType, launcherAbilityResourceInfos); + AAFwk::Want want; + want.SetType(fileType); + want.SetAction(ACTION_VIEW_DATA); + want.SetUri(FILE_URI); + ErrCode ret = hostImpl->ImplicitQueryAbilityInfosWithDefault(want, launcherAbilityResourceInfos); EXPECT_EQ(ret, ERR_OK); } -- Gitee