From a2fd6b3102d971c78138ab5d2cae830e11935ccb Mon Sep 17 00:00:00 2001 From: "zhangyafei.echo" Date: Thu, 21 Apr 2022 15:00:12 +0800 Subject: [PATCH] fixed 2c0730a from https://gitee.com/zhangyafei-echo/aafwk_standard/pulls/1601 Description:1. Fix /system/bin/aa command using ability_tool realization. 2. Add number check to flag and windowMode. Sig:SIG_ApplicationFramework Feature or BugFix: Feature Binary Source: No Signed-off-by: zhangyafei.echo Change-Id: I1df6b5e0660958ab5fcab9b65ed5c51218611867 --- tools/aa/src/ability_tool_command.cpp | 50 ++++++++++++++++----------- tools/aa/src/main.cpp | 4 +-- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/tools/aa/src/ability_tool_command.cpp b/tools/aa/src/ability_tool_command.cpp index 5c9cfeb4018..7f81d13971e 100644 --- a/tools/aa/src/ability_tool_command.cpp +++ b/tools/aa/src/ability_tool_command.cpp @@ -230,8 +230,9 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption std::string deviceId = ""; std::string bundleName = ""; std::string abilityName = ""; - std::string key = ""; - std::string value = ""; + std::string paramName = ""; + std::string paramValue = ""; + std::smatch sm; int32_t windowMode = AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED; int flags = 0; bool isColdStart = false; @@ -267,18 +268,23 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption break; case 'o': if (optind + 1 >= argc_) { - HILOG_DEBUG("'aa %{public}s' %{public}s", cmd_.c_str(), ABILITY_TOOL_HELP_MSG_LACK_VALUE.c_str()); + HILOG_DEBUG("'ability_tool %{public}s' %{public}s", cmd_.c_str(), + ABILITY_TOOL_HELP_MSG_LACK_VALUE.c_str()); resultReceiver_.append(ABILITY_TOOL_HELP_MSG_LACK_VALUE + "\n"); return OHOS::ERR_INVALID_VALUE; } - key = optarg; - value = argv_[optind + 1]; - if (key == "windowMode") { - windowMode = std::stoi(value); + paramName = optarg; + paramValue = argv_[optind + 1]; + if (paramName == "windowMode" && + std::regex_match(paramValue, sm, std::regex(STRING_TEST_REGEX_INTEGER_NUMBERS))) { + windowMode = std::stoi(paramValue); } break; case 'f': - flags = std::stoi(optarg); + paramValue = optarg; + if (std::regex_match(paramValue, sm, std::regex(STRING_TEST_REGEX_INTEGER_NUMBERS))) { + flags = std::stoi(paramValue); + } break; case 'C': isColdStart = true; @@ -293,7 +299,7 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption // Parameter check if (abilityName.size() == 0 || bundleName.size() == 0) { - HILOG_DEBUG("'aa %{public}s' without enough options.", cmd_.c_str()); + HILOG_DEBUG("'ability_tool %{public}s' without enough options.", cmd_.c_str()); if (abilityName.size() == 0) { resultReceiver_.append(ABILITY_TOOL_HELP_MSG_NO_ABILITY_NAME_OPTION + "\n"); } @@ -328,7 +334,8 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption windowMode != AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY && windowMode != AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY && windowMode != AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FLOATING) { - HILOG_DEBUG("'aa %{public}s' %{public}s", cmd_.c_str(), ABILITY_TOOL_HELP_MSG_WINDOW_MODE_INVALID.c_str()); + HILOG_DEBUG("'ability_tool %{public}s' %{public}s", cmd_.c_str(), + ABILITY_TOOL_HELP_MSG_WINDOW_MODE_INVALID.c_str()); resultReceiver_.append(ABILITY_TOOL_HELP_MSG_WINDOW_MODE_INVALID + "\n"); return OHOS::ERR_INVALID_VALUE; } @@ -374,7 +381,7 @@ ErrCode AbilityToolCommand::ParseStopServiceArgsFromCmd(Want& want) } if (abilityName.size() == 0 || bundleName.size() == 0) { - HILOG_INFO("'aa %{public}s' without enough options.", cmd_.c_str()); + HILOG_INFO("'ability_tool %{public}s' without enough options.", cmd_.c_str()); if (abilityName.size() == 0) { resultReceiver_.append(ABILITY_TOOL_HELP_MSG_NO_ABILITY_NAME_OPTION + "\n"); } @@ -393,8 +400,8 @@ ErrCode AbilityToolCommand::ParseStopServiceArgsFromCmd(Want& want) ErrCode AbilityToolCommand::ParseTestArgsFromCmd(std::map& params, bool isDebug) { - std::string key; - std::string value; + std::string paramKey; + std::string paramValue; std::smatch sm; int option = -1; int index = 0; @@ -421,13 +428,14 @@ ErrCode AbilityToolCommand::ParseTestArgsFromCmd(std::map= argc_) { - HILOG_DEBUG("'aa %{public}s' %{public}s", cmd_.c_str(), ABILITY_TOOL_HELP_MSG_LACK_VALUE.c_str()); + HILOG_DEBUG("'ability_tool %{public}s' %{public}s", cmd_.c_str(), + ABILITY_TOOL_HELP_MSG_LACK_VALUE.c_str()); resultReceiver_.append(ABILITY_TOOL_HELP_MSG_LACK_VALUE + "\n"); return OHOS::ERR_INVALID_VALUE; } - key = "-s "; - key.append(optarg); - params[key] = argv_[optind + 1]; + paramKey = "-s "; + paramKey.append(optarg); + params[paramKey] = argv_[optind + 1]; break; case 'p': params["-p"] = optarg; @@ -436,13 +444,13 @@ ErrCode AbilityToolCommand::ParseTestArgsFromCmd(std::map