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 "daemon_common.h"
16 #include "daemon_updater.h"
17 #include "flashd/flashd.h"
18 #include "updater/updater.h"
19
20 using namespace Hdc;
21 namespace flashd {
flashd_main(int argc,char ** argv)22 int flashd_main(int argc, char **argv)
23 {
24 Base::SetLogLevel(LOG_LAST); // debug log print
25 std::vector<std::string> args = updater::ParseParams(argc, argv);
26 bool enableUsb = false;
27 bool enableTcp = false;
28 WRITE_LOG(LOG_DEBUG, "flashd main run %d", argc);
29 const int size = 64;
30 char modeSet[size] = "";
31 Base::GetHdcProperty("persist.hdc.mode", modeSet, size);
32 WRITE_LOG(LOG_DEBUG, "Background mode, persist.hdc.mode %s", modeSet);
33 for (std::string arg : args) {
34 if (arg.find("-l") != std::string::npos) {
35 int logLevel = atoi(arg.c_str() + strlen("-l"));
36 FLASHDAEMON_CHECK(!(logLevel < 0 || logLevel > LOG_LAST),
37 logLevel = LOG_LAST, "Loglevel error %d", logLevel);
38 Base::SetLogLevel(logLevel);
39 } else if (arg.find("-t") != std::string::npos || strncmp(modeSet, "tcp", 3) == 0) { // 3 tcp
40 enableTcp = true;
41 } else if (arg.find("-u") != std::string::npos) {
42 enableUsb = true;
43 }
44 }
45
46 if (!enableTcp && !enableUsb) {
47 Base::PrintMessage("Both TCP and USB are disable, default enable usb");
48 enableUsb = true;
49 }
50 HdcDaemon daemon(false);
51 daemon.InitMod(enableTcp, enableUsb);
52 #ifndef UPDATER_UT
53 daemon.WorkerPendding();
54 #endif
55 return 0;
56 }
57 }
58