• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FOUNDATION_APPEXECFWK_STANDARD_TOOLS_FM_INCLUDE_FMS_COMMAND_H
17 #define FOUNDATION_APPEXECFWK_STANDARD_TOOLS_FM_INCLUDE_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     // ErrCode RunAsDumpCommand();
80 
81     /**
82      * @brief Query all of form storage infos.
83      * @return Returns ERR_OK on success, others on failure.
84      */
85     int32_t QueryStorageFormInfos();
86     /**
87      * @brief Query form infos by bundleName.
88      * @param bundleName BundleName.
89      * @return Returns ERR_OK on success, others on failure.
90      */
91     int32_t QueryFormInfoByBundleName(const std::string& bundleName);
92     /**
93      * @brief Query form infos by form id.
94      * @param formId The id of the form.
95      * @return Returns ERR_OK on success, others on failure.
96      */
97     int32_t QueryFormInfoByFormId(const std::int64_t formId);
98     /**
99      * @brief Handle command args.
100      * @param optopt Command optopt.
101      * @return Returns ERR_OK on success, others on failure.
102      */
103     int32_t HandleUnknownOption(const char optopt);
104     /**
105      * @brief Handle command args.
106      * @param option Command option.
107      * @param bundleName BundleName.
108      * @param formId The id of the form.
109      * @param cmdFlag Command Flag.
110      * @return Returns ERR_OK on success, others on failure.
111      */
112     int32_t HandleNormalOption(const int option, std::string &bundleName, int64_t &formId, int32_t &cmdFlag);
113 
114     /**
115      * @brief Execute query form info command.
116      * @param bundleName BundleName.
117      * @param formId The id of the form.
118      * @param cmdFlag Command Flag.
119      * @return Returns ERR_OK on success, others on failure.
120      */
121     int32_t ExecuteQuery(const std::string &bundleName, const int64_t formId, const int32_t cmdFlag);
122 
123     /**
124      * @brief Connect form manager service.
125      * @return Returns ERR_OK on success, others on failure.
126      */
127     int32_t ConnectFms();
128 
129     bool WriteInterfaceToken(MessageParcel &data);
130     int GetStringInfo(IFormMgr::Message code, MessageParcel &data, std::string &stringInfo);
131     int SendTransactCmd(IFormMgr::Message code, MessageParcel &data, MessageParcel &reply);
132 private:
133     sptr<IRemoteObject> remoteObject_;
134 };
135 
136 }  // namespace AppExecFwk
137 }  // namespace OHOS
138 
139 #endif  // FOUNDATION_APPEXECFWK_STANDARD_TOOLS_FM_INCLUDE_FMS_COMMAND_H