• 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 #include "translate.h"
16 #include "host_updater.h"
17 
18 namespace Hdc {
19 namespace TranslateCommand {
Usage()20     string Usage()
21     {
22         string ret = "";
23         ret = "\n                         OpenHarmony device connector(HDC) ...\n\n"
24               "---------------------------------global commands:----------------------------------\n"
25               " -h/help [verbose]                     - Print hdc help, 'verbose' for more other cmds\n"
26               " -v/version                            - Print hdc version\n"
27               " -t connectkey                         - Use device with given connect key\n"
28               "\n"
29               "---------------------------------component commands:-------------------------------\n"
30               "session commands(on server):\n"
31               " list targets [-v]                     - List all devices status, -v for detail\n"
32               " start [-r]                            - Start server. If with '-r', will be restart server\n"
33               " kill [-r]                             - Kill server. If with '-r', will be restart server\n"
34               "\n"
35               "service commands(on daemon):\n"
36               " target mount                          - Set /system /vendor partition read-write\n"
37               " wait                                  - Wait for the device to become available\n"
38               " target boot [-bootloader|-recovery]   - Reboot the device or boot into bootloader\\recovery.\n"
39               " target boot [MODE]                    - Reboot the into MODE.\n"
40               " smode [-r]                            - Restart daemon with root permissions, '-r' to cancel root\n"
41               "                                         permissions\n"
42               " tmode usb                             - Reboot the device, listening on USB\n"
43               " tmode port [port]                     - Reboot the device, listening on TCP port\n"
44               "\n"
45               "---------------------------------task commands:-------------------------------------\n"
46               "file commands:\n"
47               " file send [option] local remote       - Send file to device\n"
48               " file recv [option] remote local       - Recv file from device\n"
49               "                                         option is -a|-s|-z\n"
50               "                                         -a: hold target file timestamp\n"
51               "                                         -sync: just update newer file\n"
52               "                                         -z: compress transfer, not improve transmission efficiency\n"
53               "                                         for compressed files\n"
54               "                                         -m: mode sync\n"
55               "                                         -b: send/receive file to debug application directory\n"
56               "\n"
57               "forward commands:\n"
58               " fport localnode remotenode            - Forward local traffic to remote device\n"
59               " rport remotenode localnode            - Reserve remote traffic to local host\n"
60               "                                         node config name format 'schema:content'\n"
61               "                                         examples are below:\n"
62               "                                         tcp:<port>\n"
63               "                                         localfilesystem:<unix domain socket name>\n"
64               "                                         localreserved:<unix domain socket name>\n"
65               "                                         localabstract:<unix domain socket name>\n"
66               "                                         dev:<device name>\n"
67               "                                         jdwp:<pid> (remote only)\n"
68               "                                         ark:pid@tid@Debugger"
69               " fport ls                              - Display forward/reverse tasks\n"
70               " fport rm taskstr                      - Remove forward/reverse task by taskstring\n"
71               "\n"
72               "app commands:\n"
73               " install [-r|-s] src                   - Send package(s) to device and install them\n"
74               "                                         src examples: single or multiple packages and directories\n"
75               "                                         (.hap .hsp)\n"
76               "                                         -r: replace existing application\n"
77               "                                         -s: install shared bundle for multi-apps\n"
78               " uninstall [-k] [-s] package           - Remove application package from device\n"
79               "                                         -k: keep the data and cache directories\n"
80               "                                         -s: remove shared bundle\n"
81               "\n"
82               "debug commands:\n"
83               " hilog [-h]                            - Show device log, -h for detail\n"
84               " shell [-b bundlename] [COMMAND...]    - Run shell command (interactive shell if no command given)\n"
85               "                                         -b: run command in specified debug application bundle path\n"
86               "                                             bundle parameter only support non-interactive shell\n"
87               " bugreport [FILE]                      - Return all information from the device, stored in file if "
88               "FILE is specified\n"
89               " jpid                                  - List PIDs of processes hosting a JDWP transport\n"
90               " track-jpid [-a|-p]                    - Track PIDs of debug processes hosting a JDWP transport\n"
91               "                                         -a: include debug and release processes\n"
92               "                                         -p: don't display debug and release tags\n"
93               "\n"
94               "security commands:\n"
95               " keygen FILE                           - Generate public/private key; key stored in FILE and FILE.pub\n"
96               "\n";
97         return ret;
98     }
99 
Verbose()100     string Verbose()
101     {
102         string ret = "\n                         OpenHarmony device connector(HDC) ...\n\n"
103             "---------------------------------global commands:----------------------------------\n"
104             " -h/help [verbose]                     - Print hdc help, 'verbose' for more other cmds\n"
105             " -v/version                            - Print hdc version\n"
106             " -l[0-5]                               - Set runtime loglevel\n"
107             " -t connectkey                         - Use device with given connect key\n"
108             " checkserver                           - check client-server version\n"
109             " checkdevice                           - check server-daemon version(only uart)\n"
110             "\n"
111             "---------------------------------component commands:-------------------------------\n"
112             "session commands(on server):\n"
113             " discover                              - Discover devices listening on TCP via LAN broadcast\n"
114             " list targets [-v]                     - List all devices status, -v for detail\n"
115             " tconn key                             - Connect device via key, TCP use ip:port\n"
116             "                                         example:192.168.0.100:10178/192.168.0.100\n"
117             "                                         USB connect automatic, TCP need to connect manually\n"
118 #ifdef HDC_SUPPORT_UART
119             "\n"
120             "                                         UART connect need connect manually\n"
121             "                                         Baud Rate can be specified with commas\n"
122             "                                         key format: <Port Name>[,Baud Rate]\n"
123             "                                         example: tconn COM5,921600\n"
124             "                                         Default Baud Rate is 921600\n"
125             "\n"
126 #endif
127             " start [-r]                            - Start server. If with '-r', will be restart server\n"
128             " kill [-r]                             - Kill server. If with '-r', will be restart server\n"
129             " -s [ip:]port                          - Set hdc server listen config\n"
130             " -m                                    - Start server at foreground\n"
131             " -p                                    - Skip the server startup, run in single client mode\n"
132             "\n"
133             "service commands(on daemon):\n"
134             " target mount                          - Set /system /vendor partition read-write\n"
135             " target boot [-bootloader|-recovery]   - Reboot the device or boot into bootloader\\recovery\n"
136             " target boot [MODE]                    - Reboot the into MODE\n"
137             " smode [-r]                            - Restart daemon with root permissions, '-r' to cancel root\n"
138             "                                         permissions\n"
139             " tmode usb                             - Reboot the device, listening on USB\n"
140             " tmode port [port]                     - Reboot the device, listening on TCP port\n"
141             "\n"
142             "---------------------------------task commands:-------------------------------------\n"
143             "file commands:\n"
144             " file send [option] local remote       - Send file to device\n"
145             " file recv [option] remote local       - Recv file from device\n"
146             "                                         option is -a|-s|-z\n"
147             "                                         -a: hold target file timestamp\n"
148             "                                         -sync: just update newer file\n"
149             "                                         -z: compress transfer, not improve transmission efficiency\n"
150             "                                         for compressed files\n"
151             "                                         -m: mode sync\n"
152             "                                         -b: send/receive file to debug application directory\n"
153             "\n"
154             "forward commands:\n"
155             " fport localnode remotenode            - Forward local traffic to remote device\n"
156             " rport remotenode localnode            - Reserve remote traffic to local host\n"
157             "                                         node config name format 'schema:content'\n"
158             "                                         examples are below:\n"
159             "                                         tcp:<port>\n"
160             "                                         localfilesystem:<unix domain socket name>\n"
161             "                                         localreserved:<unix domain socket name>\n"
162             "                                         localabstract:<unix domain socket name>\n"
163             "                                         dev:<device name>\n"
164             "                                         jdwp:<pid> (remote only)\n"
165             "                                         ark:pid@tid@Debugger"
166             " fport ls                              - Display forward/reverse tasks\n"
167             " fport rm taskstr                      - Remove forward/reverse task by taskstring\n"
168             "\n"
169             "app commands:\n"
170             " install [-r|-s] src                   - Send package(s) to device and install them\n"
171             "                                         src examples: single or multiple packages and directories\n"
172             "                                         (.hap .hsp)\n"
173             "                                         -r: replace existing application\n"
174             "                                         -s: install shared bundle for multi-apps\n"
175             " uninstall [-k] [-s] package           - Remove application package from device\n"
176             "                                         -k: keep the data and cache directories\n"
177             "                                         -s: remove shared bundle\n"
178             "\n"
179             "debug commands:\n"
180             " hilog [-h]                            - Show device log, -h for detail\n"
181             " shell [-b bundlename] [COMMAND...]    - Run shell command (interactive shell if no command given)\n"
182             "                                         -b: run command in specified debug application bundle path\n"
183             "                                             bundle parameter only support non-interactive shell\n"
184             " bugreport [FILE]                      - Return all information from the device, stored in file if FILE "
185             "is specified\n"
186             " jpid                                  - List PIDs of processes hosting a JDWP transport\n"
187             " sideload [PATH]                       - Sideload the given full OTA package\n"
188             "\n"
189             "security commands:\n"
190             " keygen FILE                           - Generate public/private key; key stored in FILE and FILE.pub\n"
191             "\n"
192             "---------------------------------flash commands:------------------------------------\n"
193             "flash commands:\n"
194             " update packagename                    - Update system by package\n"
195             " flash [-f] partition imagename        - Flash partition by image\n"
196             " erase [-f] partition                  - Erase partition\n"
197             " format [-f] partition                 - Format partition\n"
198             "---------------------------------external commands:------------------------------------\n"
199             "extconn key                            - Connect external device via key, TCP use ip:port(remian)\n"
200             "-S [ip:]port                           - Set hdc external server listen config\n"
201             "\n"
202             "---------------------------------environment variables:-----------------------------\n"
203 #ifdef _WIN32
204             "\%OHOS_HDC_SERVER_PORT\%                - Set hdc server listen port(range 1~65535, default 8710)\n"
205             "\%OHOS_HDC_LOG_LEVEL\%                  - Set hdc server log level(range 0~5, default 5)\n"
206             "\%OHOS_HDC_HEARTBEAT\%                  - Set whether the hdc heartbeat function is disabled\n"
207             "                                          (1: disabled, other: enabled, default: enabled)\n"
208 #ifdef FEATURE_HOST_LOG_COMPRESS
209             "\%OHOS_HDC_LOG_LIMIT\%                  - Set the number of logs that trigger the total"
210             " log file size statistics (default 300 (files))\n"
211 #endif
212 #else
213             "$OHOS_HDC_SERVER_PORT                  - Set hdc server listen port(range 1~65535, default 8710)\n"
214             "$OHOS_HDC_LOG_LEVEL                    - Set hdc server log level(range 0~5, default 5)\n"
215             "$OHOS_HDC_HEARTBEAT                    - Set whether the hdc heartbeat function is disabled\n"
216             "                                         (1: disabled, other: enabled, default: enabled)\n"
217 #ifdef FEATURE_HOST_LOG_COMPRESS
218             "$OHOS_HDC_LOG_LIMIT                    - Set the number of logs that trigger the total"
219             " log file size statistics (default 300 (files))\n"
220 #endif
221 #endif
222             "\n";
223         return ret;
224     }
225 
TargetConnect(FormatCommand * outCmd)226     string TargetConnect(FormatCommand *outCmd)
227     {
228         string stringError;
229         if (Base::StringEndsWith(outCmd->parameters, " -remove")) {
230             outCmd->parameters = outCmd->parameters.substr(0, outCmd->parameters.size() - CMD_REMOTE_SIZE);
231             outCmd->cmdFlag = CMD_KERNEL_TARGET_DISCONNECT;
232         } else {
233             outCmd->cmdFlag = CMD_KERNEL_TARGET_CONNECT;
234             constexpr int maxKeyLength = 50; // 50: tcp max=21,USB max=8bytes, serial device name maybe long
235             if (outCmd->parameters.size() > maxKeyLength) {
236                 stringError = "Error connect key's size";
237                 outCmd->bJumpDo = true;
238             }
239         }
240         size_t pos = outCmd->parameters.find(":");
241         if (pos != std::string::npos) {
242             // tcp mode
243             string ip = outCmd->parameters.substr(0, pos);
244             if (!Base::IsValidIpv4(ip)) {
245                 stringError = "[E001104]:IP address incorrect";
246                 outCmd->bJumpDo = true;
247                 return stringError;
248             }
249             string sport = outCmd->parameters.substr(pos + 1);
250             WRITE_LOG(LOG_INFO, "TargetConnect ip:%s port:%s", ip.c_str(), sport.c_str());
251             if (sport.empty() || !Base::IsDigitString(sport)) {
252                 stringError = "Port incorrect";
253                 outCmd->bJumpDo = true;
254                 return stringError;
255             }
256             if (ip == "localhost") {
257                 ip = "127.0.0.1";
258                 outCmd->parameters.replace(0, pos, ip);
259             }
260             int port = static_cast<int>(strtol(sport.c_str(), nullptr, 10));
261             sockaddr_in addr;
262             if ((port <= 0 || port > MAX_IP_PORT) || uv_ip4_addr(ip.c_str(), port, &addr) < 0) {
263                 stringError = "IP:Port incorrect";
264                 outCmd->bJumpDo = true;
265             }
266         }
267         return stringError;
268     }
269 
ForwardPort(const char * input,FormatCommand * outCmd)270     string ForwardPort(const char *input, FormatCommand *outCmd)
271     {
272         string stringError;
273         const char *pExtra = input + 6;  // CMDSTR_FORWARD_FPORT CMDSTR_FORWARD_RPORT + " " size
274         if (!strncmp(input, CMDSTR_FORWARD_FPORT.c_str(), CMDSTR_FORWARD_FPORT.size()) && !strcmp(pExtra, "ls")) {
275             outCmd->cmdFlag = CMD_FORWARD_LIST;
276         } else if (!strncmp(input, CMDSTR_FORWARD_FPORT.c_str(), CMDSTR_FORWARD_FPORT.size()) &&
277             !strncmp(pExtra, "rm", 2)) { // 2: "rm" size
278             outCmd->cmdFlag = CMD_FORWARD_REMOVE;
279             if (strcmp(pExtra, "rm")) {
280                 outCmd->parameters = input + FORWORD_PORT_RM_BUF_SIZE;
281             }
282         } else {
283             const char *p = input + FORWORD_PORT_OTHER_BUF_SIZE;
284             // clang-format off
285             if (strncmp(p, "tcp:", 4) && // 4: "tcp:" size
286                 strncmp(p, "localabstract:", 14) && // 14: "localabstract:" size
287                 strncmp(p, "localreserved:", 14) && // 14: "localreserved:" size
288                 strncmp(p, "localfilesystem:", 16) && // 16: "localfilesystem:" size
289                 strncmp(p, "dev:", 4) && // 4: "dev:" size
290                 strncmp(p, "jdwp:", 5) && // 5: "jdwp:" size
291                 strncmp(p, "ark:", 4)) { // 4: "ark:" size
292                 stringError = "Incorrect forward command";
293                 outCmd->bJumpDo = true;
294             }
295             // clang-format on
296             outCmd->cmdFlag = CMD_FORWARD_INIT;
297             outCmd->parameters = input;
298         }
299         return stringError;
300     }
301 
RunMode(const char * input,FormatCommand * outCmd)302     string RunMode(const char *input, FormatCommand *outCmd)
303     {
304         string stringError;
305         outCmd->cmdFlag = CMD_UNITY_RUNMODE;
306         outCmd->parameters = input + CMDSTR_TARGET_MODE.size() + 1;  // with  ' '
307         int portLength = 4;
308         int portSpaceLength = 5;
309         if (!strncmp(outCmd->parameters.c_str(), "port", portLength) &&
310             !strcmp(outCmd->parameters.c_str(), CMDSTR_TMODE_USB.c_str())) {
311             stringError = "Error tmode command";
312             outCmd->bJumpDo = true;
313         } else if (!strncmp(outCmd->parameters.c_str(), "port ", portSpaceLength)) {
314             const char *tmp = input + strlen("tmode port ");
315             // command is tmode port close
316             if (strcmp(tmp, "close") == 0) {
317                 return stringError;
318             }
319             int port = atoi(tmp);
320             if (port > MAX_IP_PORT || port <= 0) {
321                 stringError = "Incorrect port range";
322                 outCmd->bJumpDo = true;
323             }
324         }
325         return stringError;
326     }
327 
TargetReboot(const char * input,FormatCommand * outCmd)328     void TargetReboot(const char *input, FormatCommand *outCmd)
329     {
330         outCmd->cmdFlag = CMD_UNITY_REBOOT;
331         if (strcmp(input, CMDSTR_TARGET_REBOOT.c_str())) {
332             outCmd->parameters = input + CMDSTR_TARGET_REBOOT.size() + 1;  // with  ' '
333             if (outCmd->parameters == "-bootloader" || outCmd->parameters == "-recovery" ||
334                 outCmd->parameters == "-flashd") {
335                 outCmd->parameters.erase(outCmd->parameters.begin());
336             }
337         }
338     }
339 
340     // command input
341     // client side:Enter string data formatting conversion to module see internal processing command
String2FormatCommand(const char * inputRaw,int sizeInputRaw,FormatCommand * outCmd)342     string String2FormatCommand(const char *inputRaw, int sizeInputRaw, FormatCommand *outCmd)
343     {
344         string stringError;
345         string input = string(inputRaw, sizeInputRaw);
346         if (!strncmp(input.c_str(), CMDSTR_SOFTWARE_HELP.c_str(), CMDSTR_SOFTWARE_HELP.size())) {
347             outCmd->cmdFlag = CMD_KERNEL_HELP;
348             outCmd->bJumpDo = true;
349             if (strstr(input.c_str(), " verbose")) {
350                 stringError = Verbose();
351             } else {
352                 stringError = Usage();
353             }
354         } else if (!strcmp(input.c_str(), CMDSTR_SOFTWARE_VERSION.c_str())) {
355             outCmd->cmdFlag = CMD_KERNEL_HELP;
356             stringError = Base::GetVersion();
357             outCmd->bJumpDo = true;
358         } else if (!strcmp(input.c_str(), CMDSTR_TARGET_DISCOVER.c_str())) {
359             outCmd->cmdFlag = CMD_KERNEL_TARGET_DISCOVER;
360         } else if (!strncmp(input.c_str(), CMDSTR_LIST_TARGETS.c_str(), CMDSTR_LIST_TARGETS.size())) {
361             outCmd->cmdFlag = CMD_KERNEL_TARGET_LIST;
362             if (strstr(input.c_str(), " -v")) {
363                 outCmd->parameters = "v";
364             }
365         } else if (!strncmp(input.c_str(), CMDSTR_SERVICE_START.c_str(), CMDSTR_SERVICE_START.size())) {
366             outCmd->cmdFlag = CMD_SERVICE_START;
367         } else if (!strncmp(input.c_str(), CMDSTR_CHECK_SERVER.c_str(), CMDSTR_CHECK_SERVER.size())) {
368             outCmd->cmdFlag = CMD_CHECK_SERVER;
369         } else if (!strncmp(input.c_str(), CMDSTR_CHECK_DEVICE.c_str(), CMDSTR_CHECK_DEVICE.size())) {
370             outCmd->parameters = input.c_str() + CMDSTR_CHECK_DEVICE.size() + 1;  // with ' '
371             outCmd->cmdFlag = CMD_CHECK_DEVICE;
372         } else if (!strncmp(input.c_str(), CMDSTR_WAIT_FOR.c_str(), CMDSTR_WAIT_FOR.size())) {
373             outCmd->cmdFlag = CMD_WAIT_FOR;
374         } else if (!strcmp(input.c_str(), CMDSTR_CONNECT_ANY.c_str())) {
375             outCmd->cmdFlag = CMD_KERNEL_TARGET_ANY;
376         } else if (!strncmp(input.c_str(), CMDSTR_CONNECT_TARGET.c_str(), CMDSTR_CONNECT_TARGET.size())) {
377             outCmd->parameters = input.c_str() + CMDSTR_CONNECT_TARGET.size() + 1;  // with ' '
378             stringError = TargetConnect(outCmd);
379         } else if (!strncmp(input.c_str(), (CMDSTR_SHELL_EX).c_str(), (CMDSTR_SHELL_EX).size())) {
380             if (!HostShellOption::FormatParametersToTlv(
381                 input, CMDSTR_SHELL_EX.size() - 1, outCmd->parameters, stringError)) {
382                 outCmd->bJumpDo = true;
383             }
384             outCmd->cmdFlag = CMD_UNITY_EXECUTE_EX;
385         } else if (!strncmp(input.c_str(), (CMDSTR_SHELL + " ").c_str(), CMDSTR_SHELL.size() + 1)) {
386             outCmd->cmdFlag = CMD_UNITY_EXECUTE;
387             outCmd->parameters = input.c_str() + CMDSTR_SHELL.size() + 1;
388         } else if (!strcmp(input.c_str(), CMDSTR_SHELL.c_str())) {
389             outCmd->cmdFlag = CMD_SHELL_INIT;
390         } else if (!strncmp(input.c_str(), CMDSTR_FILE_SEND.c_str(), CMDSTR_FILE_SEND.size()) ||
391                    !strncmp(input.c_str(), CMDSTR_FILE_RECV.c_str(), CMDSTR_FILE_RECV.size())) {
392             outCmd->cmdFlag = CMD_FILE_INIT;
393             outCmd->parameters = input.c_str() + strlen("file ");
394         } else if (!strncmp(input.c_str(), string(CMDSTR_FORWARD_FPORT + " ").c_str(), CMDSTR_FORWARD_FPORT.size() + 1)
395                    || !strncmp(input.c_str(), string(CMDSTR_FORWARD_RPORT + " ").c_str(),
396                                CMDSTR_FORWARD_RPORT.size() + 1)) {
397             stringError = ForwardPort(input.c_str(), outCmd);
398         } else if (!strncmp(input.c_str(), CMDSTR_APP_INSTALL.c_str(), CMDSTR_APP_INSTALL.size())) {
399             outCmd->cmdFlag = CMD_APP_INIT;
400             outCmd->parameters = input;
401         } else if (!strncmp(input.c_str(), CMDSTR_APP_UNINSTALL.c_str(), CMDSTR_APP_UNINSTALL.size())) {
402             outCmd->cmdFlag = CMD_APP_UNINSTALL;
403             outCmd->parameters = input;
404             if (outCmd->parameters.size() > MAX_APP_PARAM_SIZE || outCmd->parameters.size() < MIN_APP_PARAM_SIZE) {
405                 stringError = "Package's path incorrect";
406                 outCmd->bJumpDo = true;
407             }
408         } else if (!strcmp(input.c_str(), CMDSTR_TARGET_MOUNT.c_str())) {
409             outCmd->cmdFlag = CMD_UNITY_REMOUNT;
410         } else if (!strcmp(input.c_str(), CMDSTR_LIST_JDWP.c_str())) {
411             outCmd->cmdFlag = CMD_JDWP_LIST;
412         } else if (!strncmp(input.c_str(), CMDSTR_TRACK_JDWP.c_str(), CMDSTR_TRACK_JDWP.size())) {
413             outCmd->cmdFlag = CMD_JDWP_TRACK;
414             if (strstr(input.c_str(), " -p")) {
415                 outCmd->parameters = "p";
416             } else if (strstr(input.c_str(), " -a")) {
417                 outCmd->parameters = "a";
418             }
419         } else if (!strncmp(input.c_str(), CMDSTR_TARGET_REBOOT.c_str(), CMDSTR_TARGET_REBOOT.size())) {
420             TargetReboot(input.c_str(), outCmd);
421         } else if (!strncmp(input.c_str(), CMDSTR_TARGET_MODE.c_str(), CMDSTR_TARGET_MODE.size())) {
422             stringError = RunMode(input.c_str(), outCmd);
423         } else if (!strncmp(input.c_str(), CMDSTR_HILOG.c_str(), CMDSTR_HILOG.size())) {
424             outCmd->cmdFlag = CMD_UNITY_HILOG;
425             if (strstr(input.c_str(), " -h")) {
426                 outCmd->parameters = "h";
427             }
428         } else if (!strncmp(input.c_str(), CMDSTR_STARTUP_MODE.c_str(), CMDSTR_STARTUP_MODE.size())) {
429             outCmd->cmdFlag = CMD_UNITY_ROOTRUN;
430             if (strstr(input.c_str(), " -r")) {
431                 outCmd->parameters = "r";
432             }
433         } else if (!strncmp(input.c_str(), CMDSTR_APP_SIDELOAD.c_str(), CMDSTR_APP_SIDELOAD.size())) {
434             if (strlen(input.c_str()) == CMDSTR_APP_SIDELOAD.size()) {
435                 stringError = "Incorrect command, please with local path";
436                 outCmd->bJumpDo = true;
437             }
438             outCmd->cmdFlag = CMD_APP_SIDELOAD;
439             outCmd->parameters = input;
440         } else if (!strncmp(input.c_str(), CMDSTR_BUGREPORT.c_str(), CMDSTR_BUGREPORT.size())) {
441             outCmd->cmdFlag = CMD_UNITY_BUGREPORT_INIT;
442             outCmd->parameters = input;
443             if (outCmd->parameters.size() == CMDSTR_BUGREPORT.size() + 1) { // 1 is sizeInputRaw = input.size() + 1
444                 outCmd->parameters = CMDSTR_BUGREPORT + " ";
445             }
446         }
447         // Inner command, protocol uses only
448         else if (!strncmp(input.c_str(), CMDSTR_INNER_ENABLE_KEEPALIVE.c_str(), CMDSTR_INNER_ENABLE_KEEPALIVE.size())) {
449             outCmd->cmdFlag = CMD_KERNEL_ENABLE_KEEPALIVE;
450         } else if (HostUpdater::CheckMatchUpdate(input, *outCmd)) {
451             outCmd->parameters = input;
452         } else {
453             stringError = "Unknown command...";
454             outCmd->bJumpDo = true;
455         }
456 #ifdef HDC_DEBUG
457         WRITE_LOG(LOG_DEBUG, "String2FormatCommand cmdFlag:%d", outCmd->cmdFlag);
458 #endif
459         // nl
460         if (stringError.size()) {
461             stringError += "\n";
462         }
463         return stringError;
464     };
465 }
466 }  // namespace Hdc
467