diff --git a/frameworks/include/bundle_test_tool.h b/frameworks/include/bundle_test_tool.h index bc40add0f5f4893cdba0973c57ab620c85f2984f..8c111300fd5ebedb819292d97c3975387619af1b 100644 --- a/frameworks/include/bundle_test_tool.h +++ b/frameworks/include/bundle_test_tool.h @@ -97,6 +97,7 @@ private: ErrCode RunAsImplicitQuerySkillUriInfo(); ErrCode RunAsQueryAbilityInfoByContinueType(); ErrCode RunAsCleanBundleCacheFilesAutomaticCommand(); + ErrCode RunAsGetSimpleAppInfoForUid(); std::condition_variable cv_; std::mutex mutex_; @@ -171,6 +172,7 @@ private: ErrCode CheckCleanBundleCacheFilesAutomaticOption(int option, const std::string &commandName, uint64_t &cacheSize); ErrCode GetContinueBundleName(const std::string &bundleName, int32_t userId, std::string& msg); + ErrCode InnerGetSimpleAppInfoForUid(const int32_t &option, std::vector &uids); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/src/bundle_test_tool.cpp b/frameworks/src/bundle_test_tool.cpp index fbe86f9fa0fee0d5d18de3b0d414cdac5d8774e6..ffce7fcb806666a13e2e12d0920d8034c7e545df 100644 --- a/frameworks/src/bundle_test_tool.cpp +++ b/frameworks/src/bundle_test_tool.cpp @@ -170,6 +170,7 @@ static const std::string HELP_MSG = " implicitQuerySkillUriInfo obtain the skill uri info of the implicit query ability\n" " queryAbilityInfoByContinueType get ability info by continue type\n" " cleanBundleCacheFilesAutomatic clear cache data of a specified size\n" + " getSimpleAppInfoForUid get bundlename list and appIndex list by uid list\n" " getContinueBundleName get continue bundle name list\n"; const std::string HELP_MSG_GET_REMOVABLE = @@ -541,6 +542,16 @@ const std::string HELP_MSG_NO_QUERY_ABILITY_INFO_BY_CONTINUE_TYPE = "and a continueType with '-c' or '--continue-type' \n" "and a userId with '-u' or '--user-id' \n"; +const std::string HELP_MSG_GET_SIMPLE_APP_INFO_FOR_UID = + "usage: bundle_test_tool GetSimpleAppInfoForUid \n" + "eg:bundle_test_tool getSimpleAppInfoForUid -u ,,...\n" + "options list:\n" + " -u, --uid specify uid of the application\n"; + +const std::string STRING_GET_SIMPLE_APP_INFO_FOR_UID_OK = "getSimpleAppInfoForUid is ok \n"; +const std::string STRING_GET_SIMPLE_APP_INFO_FOR_UID_NG = + "error: failed to getSimpleAppInfoForUid \n"; + const std::string STRING_SET_REMOVABLE_OK = "set removable is ok \n"; const std::string STRING_SET_REMOVABLE_NG = "error: failed to set removable \n"; const std::string STRING_GET_REMOVABLE_OK = "get removable is ok \n"; @@ -640,6 +651,13 @@ const struct option LONG_OPTIONS[] = { {nullptr, 0, nullptr, 0}, }; +const std::string SHORT_OPTIONS_GET_SIMPLE_APP_INFO_FOR_UID = "hu:"; +const struct option LONG_OPTIONS_GET_SIMPLE_APP_INFO_FOR_UID[] = { + {"help", no_argument, nullptr, 'h'}, + {"uid", required_argument, nullptr, 'u'}, + {nullptr, 0, nullptr, 0}, +}; + const std::string SHORT_OPTIONS_SANDBOX = "hn:d:u:a:"; const struct option LONG_OPTIONS_SANDBOX[] = { {"help", no_argument, nullptr, 'h'}, @@ -892,6 +910,8 @@ ErrCode BundleTestTool::CreateCommandMap() std::bind(&BundleTestTool::RunAsQueryAbilityInfoByContinueType, this)}, {"cleanBundleCacheFilesAutomatic", std::bind(&BundleTestTool::RunAsCleanBundleCacheFilesAutomaticCommand, this)}, + {"getSimpleAppInfoForUid", + std::bind(&BundleTestTool::RunAsGetSimpleAppInfoForUid, this)}, {"getContinueBundleName", std::bind(&BundleTestTool::RunAsGetContinueBundleName, this)} }; @@ -4329,6 +4349,76 @@ ErrCode BundleTestTool::RunAsImplicitQuerySkillUriInfo() return result; } +ErrCode BundleTestTool::InnerGetSimpleAppInfoForUid(const int32_t &option, std::vector &uids) +{ + std::string commandName = "getSimpleAppInfoForUid"; + int32_t uid = Constants::FOUNDATION_UID; + switch (option) { + case 'u': { + std::string arrayUId = optarg; + std::stringstream array(arrayUId); + std::string object; + bool ret = true; + while (getline(array, object, ',')) { + StringToInt(object, commandName, uid, ret); + if (!ret) { + resultReceiver_.append(HELP_MSG_GET_SIMPLE_APP_INFO_FOR_UID); + return OHOS::ERR_INVALID_VALUE; + } + uids.emplace_back(uid); + } + APP_LOGD("bundle_test_tool %{public}s -u %{public}s", commandName.c_str(), argv_[optind - 1]); + break; + } + default: { + resultReceiver_.append(HELP_MSG_GET_SIMPLE_APP_INFO_FOR_UID); + return OHOS::ERR_INVALID_VALUE; + } + } + return OHOS::ERR_OK; +} + +ErrCode BundleTestTool::RunAsGetSimpleAppInfoForUid() +{ + APP_LOGI("RunAsGetSimpleAppInfoForUid start"); + std::vector uids; + int32_t counter = 0; + while (counter <= 1) { + counter++; + int32_t option = getopt_long(argc_, argv_, SHORT_OPTIONS_GET_SIMPLE_APP_INFO_FOR_UID.c_str(), + LONG_OPTIONS_GET_SIMPLE_APP_INFO_FOR_UID, nullptr); + APP_LOGD("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); + if (optind < 0 || optind > argc_) { + return OHOS::ERR_INVALID_VALUE; + } + if (option == -1) { + // When scanning the first argument + if ((counter == 1) && (strcmp(argv_[optind], cmd_.c_str()) == 0)) { + APP_LOGD("bundle_test_tool getSimpleAppInfoForUid with no option."); + resultReceiver_.append(HELP_MSG_GET_SIMPLE_APP_INFO_FOR_UID); + return OHOS::ERR_INVALID_VALUE; + } + break; + } + auto ret = InnerGetSimpleAppInfoForUid(option, uids); + if (ret != OHOS::ERR_OK) { + return ret; + } + } + std::vector simpleAppInfo; + auto result = bundleMgrProxy_->GetSimpleAppInfoForUid(uids, simpleAppInfo); + if (result == ERR_OK) { + resultReceiver_.append(STRING_GET_SIMPLE_APP_INFO_FOR_UID_OK); + for (size_t i = 0; i < simpleAppInfo.size(); i++) { + resultReceiver_.append(simpleAppInfo[i].ToString() + "\n"); + } + } else { + resultReceiver_.append(STRING_GET_SIMPLE_APP_INFO_FOR_UID_NG + "errCode is "+ std::to_string(result) + "\n"); + } + APP_LOGI("RunAsGetSimpleAppInfoForUid end"); + return result; +} + ErrCode BundleTestTool::RunAsQueryAbilityInfoByContinueType() { APP_LOGI("RunAsQueryAbilityInfoByContinueType start");