1 /* 2 * Copyright (c) 2024 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 EDM_TOOLS_EDM_INCLUDE_EDM_COMMAND_H 17 #define EDM_TOOLS_EDM_INCLUDE_EDM_COMMAND_H 18 19 #include "shell_command.h" 20 #include "enterprise_device_mgr_proxy.h" 21 22 namespace OHOS { 23 namespace EDM { 24 namespace { 25 const std::string TOOL_NAME = "edm"; 26 27 const std::string HELP_MSG = "usage: edm <command> [<options>]\n" 28 "These are common edm commands list:\n" 29 " help list available commands\n" 30 " enable-admin enable a admin with options\n" 31 " disable-admin disable a admin with options\n"; 32 } // namespace 33 34 const std::string HELP_MSG_ENABLE_ADMIN = "usage: edm enable-admin <options>\n" 35 "eg:edm enable-admin -n <bundle-name> -a <ability-name> -t <admin-type>\n" 36 "options list:\n" 37 " -h, --help list available commands\n" 38 " -n, --bundle-name <bundle-name> enable an admin with bundle name\n" 39 " -a, --ability-name <ability-name> enable an admin with ability name\n" 40 " -t, --admin-type <admin-type> enable an admin with admin type," 41 "<admin-type>: super, byod.\n"; 42 43 const std::string HELP_MSG_DISABLE_ADMIN = "usage: edm disable-admin <options>\n" 44 "eg:edm disable-admin -n <bundle-name>\n" 45 "options list:\n" 46 " -h, --help list available commands\n" 47 " -n, --bundle-name <bundle-name> disable an admin with bundle name\n"; 48 49 class EdmCommand : public ShellCommand { 50 public: 51 EdmCommand(int argc, char *argv[]); 52 ~EdmCommand() override = default; 53 54 private: 55 ErrCode CreateCommandMap() override; 56 ErrCode CreateMessageMap() override; 57 ErrCode Init() override; 58 ErrCode RunAsHelpCommand(); 59 ErrCode RunAsEnableCommand(); 60 ErrCode RunAsDisableAdminCommand(); 61 ErrCode ParseEnableAdminCommandOption(std::string &bundleName, std::string &abilityName, AdminType &adminType); 62 ErrCode RunAsEnableCommandMissingOptionArgument(); 63 ErrCode RunAsEnableCommandParseOptionArgument(int option, std::string &bundleName, 64 std::string &abilityName, AdminType &adminType); 65 ErrCode ReportMessage(int32_t code, bool isEnable); 66 ErrCode ConvertStringToAdminType(std::string optarg, AdminType &adminType); 67 68 std::shared_ptr<EnterpriseDeviceMgrProxy> enterpriseDeviceMgrProxy_; 69 }; 70 } // namespace EDM 71 } // namespace OHOS 72 73 #endif // EDM_TOOLS_EDM_INCLUDE_EDM_COMMAND_H 74