diff --git a/frameworks/include/bundle_test_tool.h b/frameworks/include/bundle_test_tool.h index 3f21ae1c62896f1d568a523c5808a0c1e11edc5a..86c22be7e9ee5a97e1d516430636e2af4445123a 100644 --- a/frameworks/include/bundle_test_tool.h +++ b/frameworks/include/bundle_test_tool.h @@ -98,6 +98,7 @@ private: ErrCode RunAsQueryAbilityInfoByContinueType(); ErrCode RunAsCleanBundleCacheFilesAutomaticCommand(); ErrCode RunAsGetBundleNameByAppId(); + ErrCode RunAsGetSimpleAppInfoForUid(); std::condition_variable cv_; std::mutex mutex_; @@ -172,6 +173,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 5af0bd39f0fdcdae92f4ca5580cc761215bf915b..812353c4d1df1bd809f8853f2100fa8d32f3e557 100644 --- a/frameworks/src/bundle_test_tool.cpp +++ b/frameworks/src/bundle_test_tool.cpp @@ -171,6 +171,7 @@ static const std::string HELP_MSG = " queryAbilityInfoByContinueType get ability info by continue type\n" " cleanBundleCacheFilesAutomatic clear cache data of a specified size\n" " getContinueBundleName get continue bundle name list\n" + " getSimpleAppInfoForUid get bundlename list and appIndex list by uid list\n" " getBundleNameByAppId get bundlename by appid or appIdentifier\n"; const std::string HELP_MSG_GET_REMOVABLE = @@ -542,6 +543,12 @@ 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 HELP_MSG_GET_BUNDLENAME_BY_APPID = "usage: bundle_test_tool getBundleNameByAppId \n" "eg:bundle_test_tool getBundleNameByAppId -a \n" @@ -551,6 +558,11 @@ const std::string HELP_MSG_GET_BUNDLENAME_BY_APPID = const std::string STRING_GET_BUNDLENAME_BY_APPID_OK = "getBundleNameByAppId is ok \n"; const std::string STRING_GET_BUNDLENAME_BY_APPID_NG = "error: failed to getBundleNameByAppId \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"; @@ -657,6 +669,13 @@ const struct option LONG_OPTIONS_GET_BUNDLENAME_BY_APPID[] = { {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'}, @@ -911,6 +930,8 @@ ErrCode BundleTestTool::CreateCommandMap() std::bind(&BundleTestTool::RunAsCleanBundleCacheFilesAutomaticCommand, this)}, {"getContinueBundleName", std::bind(&BundleTestTool::RunAsGetContinueBundleName, this)}, + {"getSimpleAppInfoForUid", + std::bind(&BundleTestTool::RunAsGetSimpleAppInfoForUid, this)}, {"getBundleNameByAppId", std::bind(&BundleTestTool::RunAsGetBundleNameByAppId, this)} }; @@ -4399,6 +4420,76 @@ ErrCode BundleTestTool::RunAsQueryAbilityInfoByContinueType() 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::RunAsGetBundleNameByAppId() { APP_LOGI("RunAsGetBundleNameByAppId start");