1 /* 2 * Copyright (c) 2021 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 OHOS_ABILITY_RUNTIME_FMS_COMMAND_H 17 #define OHOS_ABILITY_RUNTIME_FMS_COMMAND_H 18 19 #include "shell_command.h" 20 #include "form_mgr_interface.h" 21 #include "iremote_proxy.h" 22 23 namespace OHOS { 24 namespace AppExecFwk { 25 namespace { 26 const std::string FM_TOOL_NAME = "fm"; 27 28 const std::string FM_HELP_MSG = "usage: fm <command> <options>\n" 29 "These are common fm commands list:\n" 30 " help list available commands\n" 31 " query query form info with options\n"; 32 33 const std::string HELP_MSG_QUERY = 34 "usage: fm query <options>\n" 35 "options list:\n" 36 " -h, --help list available commands\n" 37 " -s, --storage query form storage info\n" 38 " -n <bundle-name> query form info by a bundle name\n" 39 " -i <form-id> query form info by a form id\n"; 40 41 42 const std::string HELP_MSG_NO_BUNDLE_PATH_OPTION = 43 "error: you must specify a form id with '-1' or '--formid'."; 44 45 const std::string HELP_MSG_NO_BUNDLE_NAME_OPTION = 46 "error: you must specify a bundle name with '-n' or '--name'."; 47 48 const std::string STRING_QUERY_FORM_INFO_OK = "query form info successfully."; 49 const std::string STRING_QUERY_FORM_INFO_NG = "error: failed to query form info."; 50 } // namespace 51 52 class FormMgrShellCommand : public OHOS::AAFwk::ShellCommand { 53 public: 54 FormMgrShellCommand(int argc, char *argv[]); ~FormMgrShellCommand()55 ~FormMgrShellCommand() override 56 {} 57 58 private: 59 /** 60 * @brief Create command map. 61 */ 62 ErrCode CreateCommandMap() override; 63 /** 64 * @brief Create message map. 65 */ 66 ErrCode CreateMessageMap() override; 67 /** 68 * @brief init. 69 */ 70 ErrCode init() override; 71 /** 72 * @brief Run help command. 73 */ 74 ErrCode RunAsHelpCommand(); 75 /** 76 * @brief Run query form info command. 77 */ 78 ErrCode RunAsQueryCommand(); 79 80 /** 81 * @brief Query all of form storage infos. 82 * @return Returns ERR_OK on success, others on failure. 83 */ 84 int32_t QueryStorageFormInfos(); 85 /** 86 * @brief Query form infos by bundleName. 87 * @param bundleName BundleName. 88 * @return Returns ERR_OK on success, others on failure. 89 */ 90 int32_t QueryFormInfoByBundleName(const std::string& bundleName); 91 /** 92 * @brief Query form infos by form id. 93 * @param formId The id of the form. 94 * @return Returns ERR_OK on success, others on failure. 95 */ 96 int32_t QueryFormInfoByFormId(const std::int64_t formId); 97 /** 98 * @brief Handle command args. 99 * @param optopt Command optopt. 100 * @return Returns ERR_OK on success, others on failure. 101 */ 102 int32_t HandleUnknownOption(const char optopt); 103 /** 104 * @brief Handle command args. 105 * @param option Command option. 106 * @param bundleName BundleName. 107 * @param formId The id of the form. 108 * @param cmdFlag Command Flag. 109 * @return Returns ERR_OK on success, others on failure. 110 */ 111 int32_t HandleNormalOption(const int option, std::string &bundleName, int64_t &formId, int32_t &cmdFlag); 112 113 /** 114 * @brief Execute query form info command. 115 * @param bundleName BundleName. 116 * @param formId The id of the form. 117 * @param cmdFlag Command Flag. 118 * @return Returns ERR_OK on success, others on failure. 119 */ 120 int32_t ExecuteQuery(const std::string &bundleName, const int64_t formId, const int32_t cmdFlag); 121 122 /** 123 * @brief Connect form manager service. 124 * @return Returns ERR_OK on success, others on failure. 125 */ 126 int32_t ConnectFms(); 127 128 bool WriteInterfaceToken(MessageParcel &data); 129 int GetStringInfo(IFormMgr::Message code, MessageParcel &data, std::string &stringInfo); 130 int SendTransactCmd(IFormMgr::Message code, MessageParcel &data, MessageParcel &reply); 131 private: 132 sptr<IRemoteObject> remoteObject_; 133 }; 134 } // namespace AppExecFwk 135 } // namespace OHOS 136 137 #endif // OHOS_ABILITY_RUNTIME_FMS_COMMAND_H 138