diff --git a/frameworks/include/bundle_test_tool.h b/frameworks/include/bundle_test_tool.h index b19bcabe43753b98c46a23c5c836f9dc97d6603c..8191eb55dde3c9a7fad120dc87b9dd68bbac0da5 100644 --- a/frameworks/include/bundle_test_tool.h +++ b/frameworks/include/bundle_test_tool.h @@ -77,6 +77,8 @@ private: ErrCode RunAsGetAppProvisionInfo(); ErrCode RunAsGetDistributedBundleName(); ErrCode HandleBundleEventCallback(); + ErrCode RunAsGetProxyDataCommand(); + ErrCode RunAsGetAllProxyDataCommand(); std::condition_variable cv_; std::mutex mutex_; @@ -112,6 +114,8 @@ private: ErrCode CheckGetAppRunningRuleResultCorrectOption(int option, const std::string &commandName, std::string &bundleName, int32_t &userId, int &euid); bool CheckSandboxCorrectOption(int option, const std::string &commandName, int &data, std::string &bundleName); + bool CheckGetProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); + bool CheckGetAllProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); ErrCode InstallSandboxOperation( const std::string &bundleName, const int32_t userId, const int32_t dlpType, int32_t &appIndex) const; ErrCode UninstallSandboxOperation( diff --git a/frameworks/src/bundle_command_common.cpp b/frameworks/src/bundle_command_common.cpp index ba564922e342a5fbf1260560b5273e6dab27b074..0521d54e5397ad47950ac0f18ee2784a8b3fb0a8 100644 --- a/frameworks/src/bundle_command_common.cpp +++ b/frameworks/src/bundle_command_common.cpp @@ -616,7 +616,7 @@ std::map BundleCommandCommon::bundleMessageMap_ = { }, { IStatusReceiver::ERR_INSATLL_CHECK_PROXY_DATA_URI_FAILED, - "error, bundle name in proxy data uri is different", + "error, uri in proxy data is wrong", }, { IStatusReceiver::ERR_INSATLL_CHECK_PROXY_DATA_PERMISSION_FAILED, diff --git a/frameworks/src/bundle_test_tool.cpp b/frameworks/src/bundle_test_tool.cpp index 48a9e1e1670a417d77a4813cdb620c3a53d7a9b9..965c910406bdbc122450237cb15e61ec1f206fe9 100644 --- a/frameworks/src/bundle_test_tool.cpp +++ b/frameworks/src/bundle_test_tool.cpp @@ -407,6 +407,22 @@ const std::string HELP_MSG_BUNDLE_EVENT_CALLBACK = " -o, --onlyUnregister only call unregister, default will call register then unregister\n" " -u, --uid specify a uid, default is foundation uid\n"; +const std::string HELP_MSG_GET_PROXY_DATA = + "usage: bundle_test_tool getProxyDataInfos \n" + "eg:bundle_test_tool getProxyDataInfos -m -n -u \n" + "options list:\n" + " -h, --help list available commands\n" + " -n, --bundle-name specify bundle name of the application\n" + " -m, --module-name specify module name of the application\n" + " -u, --user-id specify a user id\n"; + +const std::string HELP_MSG_GET_ALL_PROXY_DATA = + "usage: bundle_test_tool getAllProxyDataInfos \n" + "eg:bundle_test_tool getProxyDataInfos -u \n" + "options list:\n" + " -h, --help list available commands\n" + " -u, --user-id specify a user id\n"; + const std::string HELP_MSG_NO_BUNDLE_NAME_OPTION = "error: you must specify a bundle name with '-n' or '--bundle-name' \n"; @@ -466,6 +482,8 @@ const std::string GET_DISTRIBUTED_BUNDLE_NAME_COMMAND_NAME = "getDistributedBund const std::string STRING_GET_DISTRIBUTED_BUNDLE_NAME_OK = "get distributedBundleName successfully\n"; const std::string STRING_GET_DISTRIBUTED_BUNDLE_NAME_NG = "get distributedBundleName failed\n"; +const std::string STRING_GET_PROXY_DATA_NG = "get proxyData failed"; + const std::string GET_BUNDLE_STATS_ARRAY[] = { "app data size: ", "user data size: ", @@ -564,6 +582,22 @@ const struct option LONG_OPTIONS_BUNDLE_EVENT_CALLBACK[] = { {"uid", required_argument, nullptr, 'u'}, {nullptr, 0, nullptr, 0}, }; + +const std::string SHORT_OPTIONS_PROXY_DATA = "hn:m:u:"; +const struct option LONG_OPTIONS_PROXY_DATA[] = { + {"help", no_argument, nullptr, 'h'}, + {"bundle-name", required_argument, nullptr, 'n'}, + {"module-name", required_argument, nullptr, 'm'}, + {"user-id", required_argument, nullptr, 'u'}, + {nullptr, 0, nullptr, 0}, +}; + +const std::string SHORT_OPTIONS_ALL_PROXY_DATA = "hu:"; +const struct option LONG_OPTIONS_ALL_PROXY_DATA[] = { + {"help", no_argument, nullptr, 'h'}, + {"user-id", required_argument, nullptr, 'u'}, + {nullptr, 0, nullptr, 0}, +}; } // namespace BundleEventCallbackImpl::BundleEventCallbackImpl() @@ -620,6 +654,8 @@ ErrCode BundleTestTool::CreateCommandMap() {"getAppProvisionInfo", std::bind(&BundleTestTool::RunAsGetAppProvisionInfo, this)}, {"getDistributedBundleName", std::bind(&BundleTestTool::RunAsGetDistributedBundleName, this)}, {"eventCB", std::bind(&BundleTestTool::HandleBundleEventCallback, this)}, + {"getProxyDataInfos", std::bind(&BundleTestTool::RunAsGetProxyDataCommand, this)}, + {"getAllProxyDataInfos", std::bind(&BundleTestTool::RunAsGetAllProxyDataCommand, this)}, }; return OHOS::ERR_OK; @@ -1356,6 +1392,163 @@ bool BundleTestTool::CheckGetStringCorrectOption( return ret; } +bool BundleTestTool::CheckGetProxyDataCorrectOption( + int option, const std::string &commandName, int &temp, std::string &name) +{ + bool ret = true; + switch (option) { + case 'h': { + APP_LOGD("bundle_test_tool %{public}s %{public}s", commandName.c_str(), argv_[optind - 1]); + ret = false; + break; + } + case 'n': { + name = optarg; + APP_LOGD("bundle_test_tool %{public}s -n %{public}s", commandName.c_str(), argv_[optind - 1]); + break; + } + case 'm': { + name = optarg; + APP_LOGD("bundle_test_tool %{public}s -m module-name:%{public}s, %{public}s", + commandName.c_str(), name.c_str(), argv_[optind - 1]); + break; + } + case 'u': { + StringToInt(optarg, commandName, temp, ret); + break; + } + default: { + std::string unknownOption = ""; + std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); + APP_LOGD("bundle_test_tool %{public}s with an unknown option.", commandName.c_str()); + resultReceiver_.append(unknownOptionMsg); + ret = false; + break; + } + } + return ret; +} + +bool BundleTestTool::CheckGetAllProxyDataCorrectOption( + int option, const std::string &commandName, int &temp, std::string &name) +{ + bool ret = true; + switch (option) { + case 'h': { + APP_LOGD("bundle_test_tool %{public}s %{public}s", commandName.c_str(), argv_[optind - 1]); + ret = false; + break; + } + case 'u': { + StringToInt(optarg, commandName, temp, ret); + break; + } + default: { + std::string unknownOption = ""; + std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption); + APP_LOGD("bundle_test_tool %{public}s with an unknown option.", commandName.c_str()); + resultReceiver_.append(unknownOptionMsg); + ret = false; + break; + } + } + return ret; +} + +ErrCode BundleTestTool::RunAsGetProxyDataCommand() +{ + int result = OHOS::ERR_OK; + int counter = 0; + std::string commandName = "getProxyData"; + std::string name = ""; + std::string bundleName = ""; + std::string moduleName = ""; + int userId = Constants::ALL_USERID; + APP_LOGD("RunAsGetProxyDataCommand is start"); + while (true) { + counter++; + int32_t option = getopt_long( + argc_, argv_, SHORT_OPTIONS_PROXY_DATA.c_str(), LONG_OPTIONS_PROXY_DATA, 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) { + if ((counter == 1) && (strcmp(argv_[optind], cmd_.c_str()) == 0)) { + APP_LOGD("bundle_test_tool getProxyData with no option."); + resultReceiver_.append(HELP_MSG_GET_PROXY_DATA); + return OHOS::ERR_INVALID_VALUE; + } + break; + } + int temp = 0; + result = !CheckGetProxyDataCorrectOption(option, commandName, temp, name) + ? OHOS::ERR_INVALID_VALUE : result; + moduleName = option == 'm' ? name : moduleName; + bundleName = option == 'n' ? name : bundleName; + userId = option == 'u' ? temp : userId; + } + + if (result != OHOS::ERR_OK) { + resultReceiver_.append(HELP_MSG_GET_PROXY_DATA); + } else { + std::vector proxyDatas; + result = bundleMgrProxy_->GetProxyDataInfos(bundleName, moduleName, proxyDatas, userId); + if (result == ERR_OK) { + nlohmann::json jsonObject = proxyDatas; + std::string results = jsonObject.dump(Constants::DUMP_INDENT); + resultReceiver_.append(results); + } else { + resultReceiver_.append(STRING_GET_PROXY_DATA_NG + " errCode is "+ std::to_string(result) + "\n"); + } + } + return result; +} + +ErrCode BundleTestTool::RunAsGetAllProxyDataCommand() +{ + int result = OHOS::ERR_OK; + int counter = 0; + std::string commandName = "getProxyData"; + std::string name = ""; + std::string bundleName = ""; + std::string moduleName = ""; + int userId = Constants::ALL_USERID; + APP_LOGD("RunAsGetAllProxyDataCommand is start"); + while (true) { + counter++; + int32_t option = getopt_long( + argc_, argv_, SHORT_OPTIONS_ALL_PROXY_DATA.c_str(), LONG_OPTIONS_ALL_PROXY_DATA, 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) { + break; + } + + int temp = 0; + result = !CheckGetAllProxyDataCorrectOption(option, commandName, temp, name) + ? OHOS::ERR_INVALID_VALUE : result; + userId = option == 'u' ? temp : userId; + } + + if (result != OHOS::ERR_OK) { + resultReceiver_.append(HELP_MSG_GET_ALL_PROXY_DATA); + } else { + std::vector proxyDatas; + result = bundleMgrProxy_->GetAllProxyDataInfos(proxyDatas, userId); + if (result == ERR_OK) { + nlohmann::json jsonObject = proxyDatas; + std::string results = jsonObject.dump(Constants::DUMP_INDENT); + resultReceiver_.append(results); + } else { + resultReceiver_.append(STRING_GET_PROXY_DATA_NG + " errCode is "+ std::to_string(result) + "\n"); + } + } + return result; +} + ErrCode BundleTestTool::RunAsGetStringCommand() { int result = OHOS::ERR_OK;