1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef WUKONG_WUKONG_COMMAND_H 17 #define WUKONG_WUKONG_COMMAND_H 18 19 #include "shell_command.h" 20 #include "app_log_wrapper.h" 21 #include "bundle_mgr_interface.h" 22 23 #include <map> 24 #include <vector> 25 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 namespace { 30 const std::string WUKONG_TOOL_NAME = "wukong"; 31 32 const std::string WUKONG_TOOL_VERSION = "1.0.1\n"; 33 34 const std::string WUKONG_HELP_MSG = "usage: wukong exec <options> <arguments>\n" 35 "These are common wukong options list:\n" 36 " -a, appswitch event percent\n" 37 " -b, specific the bundle name\n" 38 " -t, touch event percent\n" 39 " -c, count\n" 40 " -h, help\n" 41 " -i, interval\n" 42 " -s, seed\n" 43 " -v, version\n" 44 " --spec_insomnia, spec test: sleep and awake\n"; 45 46 const std::string STRING_WUKONG_INFO_OK = "wukong info successfully.\n"; 47 const std::string STRING_WUKONG_INFO_NG = "error: failed to wukong info.\n"; 48 } 49 class WuKongCommand : public OHOS::AAFwk::ShellCommand { 50 public: 51 WuKongCommand(int argc, char *argv[]); ~WuKongCommand()52 ~WuKongCommand() override 53 {}; 54 private: 55 ErrCode init() override; 56 ErrCode CreateCommandMap() override; 57 ErrCode CreateMessageMap() override; 58 59 ErrCode RunAsParseCommand(); 60 ErrCode RunAsExecCommand(); 61 ErrCode RunAsHelpCommand(); 62 ErrCode RunTouchCommand(); 63 64 ErrCode GetWuKongVersion(); 65 ErrCode GetAllAppInfo(); 66 67 ErrCode ShowAllAppInfo(); 68 ErrCode InsertEvent(); 69 70 ErrCode RandomInsertTouch(); 71 ErrCode RandomInsertMotion(); 72 ErrCode RandomSleepAndAwake(); 73 74 ErrCode HandleUnknownOption(const char optopt); 75 ErrCode HandleNormalOption(const int option); 76 ErrCode PrintResultOfStartAbility(const ErrCode result, int index); 77 78 int FindElement(std::vector<std::string> bundleList, std::string key); 79 80 int getAbilityIndex(); 81 void checkPosition(int width, int height); 82 std::string bundleNameArgs = ""; 83 std::vector<std::string> bundleList; 84 std::vector<std::string> abilityList; 85 86 int countArgs = 10; 87 int intervalArgs = 1500; 88 int seedArgs = -1; 89 float touchPercent = 0.50; 90 float abilityPercent = 0.20; 91 int xSrcPosi = 0; 92 int ySrcPosi = 0; 93 int xDstPosi = 0; 94 int yDstPosi = 0; 95 const int userId = 100; 96 }; 97 } 98 } 99 100 #endif // WUKONG_WUKONG_COMMAND_H 101