1
2/*
3 * Copyright (c) 2022 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "init_hook.h"
18#include "init_utils.h"
19#include "plugin_adapter.h"
20#include "securec.h"
21
22/**
23系统参数转化规则
24    1,ohos.ctl.start.{start|stop} = servicename
25        转化后系统参数,用来进行dac/mac校验
26            ohos.servicectrl.{servicename}
27        对应的处理命令
28            start
29    2,ohos.startup.powerctrl = reboot,[bootcharge | shutdown | flashd | updater]
30        转化后系统参数,用来进行dac/mac校验
31            ohos.servicectrl.reboot.[bootcharge | shutdown | flashd | updater]
32        对应的处理命令
33            reboot.[bootcharge | shutdown | flashd | updater]
34    3,ohos.servicectrl.{cmdName} = {arg}
35        转化后系统参数,用来进行dac/mac校验
36            ohos.servicectrl.{cmd}
37        对应的处理命令
38            cmd
39    4,普通系统参数,根据定义的ParamCmdInfo进行处理
40        {xxxx.xxxx.xxxx, xxxx.xxxx.xxxx, cmdname}
41        例如:
42            xxxx.xxxx.xxxx = {args}
43            转化后系统参数,用来进行dac/mac校验
44                xxxx.xxxx.xxxx.{args}
45            对应的处理命令
46                cmdname
47            命令输入参数(跳过replace部分的剩余值)
48                xxxx.xxxx.xxxx.{args} + strlen(name)
49*/
50
51const ParamCmdInfo *GetServiceStartCtrl(size_t *size)
52{
53    static const ParamCmdInfo ctrlParam[] = {
54        {"ohos.ctl.start", "start", "start "},
55        {"ohos.ctl.stop", "stop", "stop "},
56    };
57    *size = ARRAY_LENGTH(ctrlParam);
58    return ctrlParam;
59}
60
61const ParamCmdInfo *GetServiceCtl(size_t *size)
62{
63    static const ParamCmdInfo installParam[] = {
64        {"ohos.servicectrl.install", "install", "install" },
65        {"ohos.servicectrl.uninstall", "uninstall", "uninstall" },
66        {"ohos.servicectrl.bootchart", "bootchart", "bootchart" },
67        {"ohos.servicectrl.init_trace", "init_trace", "init_trace" },
68        {"ohos.servicectrl.timer_start", "timer_start", "timer_start " },
69        {"ohos.servicectrl.timer_stop", "timer_stop", "timer_stop" },
70        {"ohos.servicectrl.cmd", "cmd", "initcmd"},
71    };
72    *size = ARRAY_LENGTH(installParam);
73    return installParam;
74}
75
76#ifdef OHOS_LITE
77const ParamCmdInfo *GetStartupPowerCtl(size_t *size)
78{
79    static const ParamCmdInfo powerCtrlArg[] = {
80        {"reboot,shutdown", "reboot.shutdown", "reboot.shutdown"},
81        {"reboot,updater", "reboot.updater", "reboot.updater"},
82        {"reboot,flashd", "reboot.flashd", "reboot.flashd"},
83        {"reboot,charge", "reboot.charge", "reboot.charge"},
84        {"reboot", "reboot", "reboot"},
85    };
86    *size = ARRAY_LENGTH(powerCtrlArg);
87    return powerCtrlArg;
88}
89#endif
90
91const ParamCmdInfo *GetOtherSpecial(size_t *size)
92{
93    static const ParamCmdInfo other[] = {
94        {"bootevent.", "bootevent.", "bootevent"},
95        {"persist.init.debug.", "persist.init.debug.", "setloglevel"},
96        // for hitrace start, need interrupt init trace
97        {"debug.hitrace.enable.state", "debug.hitrace.enable.state.", "init_trace"},
98    };
99    *size = ARRAY_LENGTH(other);
100    return other;
101}
102