1 /*
2 * Copyright (C) 2021-2022 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 #include "device_power_action.h"
17
18 #include <string>
19 #include "init_reboot.h"
20 #include "power_ext_intf_wrapper.h"
21 #include "power_log.h"
22
23 namespace {
24 const std::string UPDATER_CMD = "updater";
25 const std::string REBOOT_CMD = "";
26 const std::string SHUTDOWN_CMD = "shutdown";
27 }
28
29 namespace OHOS {
30 namespace PowerMgr {
Reboot(const std::string & reason)31 void DevicePowerAction::Reboot(const std::string& reason)
32 {
33 std::string rebootCmd;
34 auto ret = PowerExtIntfWrapper::Instance().GetRebootCommand(reason, rebootCmd);
35 if (ret != PowerExtIntfWrapper::ErrCode::ERR_OK) {
36 rebootCmd = Updater(reason);
37 }
38 POWER_HILOGI(FEATURE_SHUTDOWN, "Reboot command: %{public}s", rebootCmd.c_str());
39 DoRebootExt(rebootCmd.c_str(), reason.c_str());
40 }
41
Shutdown(const std::string & reason)42 void DevicePowerAction::Shutdown(const std::string& reason)
43 {
44 POWER_HILOGI(FEATURE_SHUTDOWN, "Shutdown executing");
45 DoRebootExt(SHUTDOWN_CMD.c_str(), reason.c_str());
46 }
47
Updater(const std::string & reason)48 std::string DevicePowerAction::Updater(const std::string& reason)
49 {
50 return (reason.find(UPDATER_CMD) != std::string::npos) ? UPDATER_CMD : REBOOT_CMD;
51 }
52 } // namespace PowerMgr
53 } // namespace OHOS
54