1 /*
2 * Copyright (C) 2022-2023 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 "daemon_common.h"
16 #include "daemon_updater.h"
17 #include "flashd/flashd.h"
18 #include "updater/updater.h"
19 #include "updater_main.h"
20 #include "utils.h"
21
22 using namespace Hdc;
23 namespace Flashd {
24 int FlashdMain(int argc, char **argv);
25
26 // add flashd mode
27 REGISTER_MODE(Flashd, "updater.flashd.configfs");
28
FlashdMain(int argc,char ** argv)29 int FlashdMain(int argc, char **argv)
30 {
31 Utils::UsSleep(3000 * 1000); // 3000 * 1000 : wait 3s
32 Base::SetLogLevel(LOG_LAST); // debug log print
33 Base::SetLogCache(false);
34 UpdaterInit::GetInstance().InvokeEvent(FLAHSD_PRE_INIT_EVENT);
35
36 std::vector<std::string> args = Updater::Utils::ParseParams(argc, argv);
37 bool enableUsb = false;
38 bool enableTcp = false;
39 WRITE_LOG(LOG_DEBUG, "flashd main run %d", argc);
40 const int size = 64;
41 char modeSet[size] = "";
42 WRITE_LOG(LOG_DEBUG, "Background mode, persist.hdc.mode %s", modeSet);
43 for (std::string arg : args) {
44 if (arg.find("-l") != std::string::npos) {
45 int logLevel = atoi(arg.c_str() + strlen("-l"));
46 if (logLevel < 0 || logLevel > LOG_LAST) {
47 logLevel = LOG_LAST;
48 }
49 Base::SetLogLevel(logLevel);
50 } else if (arg.find("-t") != std::string::npos || strncmp(modeSet, "tcp", 3) == 0) { // 3 tcp
51 enableTcp = true;
52 } else if (arg.find("-u") != std::string::npos) {
53 enableUsb = true;
54 }
55 }
56
57 if (!enableTcp && !enableUsb) {
58 Base::PrintMessage("Both TCP and USB are disable, default enable usb");
59 enableUsb = true;
60 }
61 HdcDaemon daemon(false);
62 daemon.InitMod(enableTcp, enableUsb);
63 #ifndef UPDATER_UT
64 daemon.WorkerPendding();
65 #endif
66 return 0;
67 }
68 }
69