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 const std::string FLASH_CMD = "flash";
28 }
29
30 namespace OHOS {
31 namespace PowerMgr {
Reboot(const std::string & reason)32 void DevicePowerAction::Reboot(const std::string& reason)
33 {
34 std::string rebootCmd;
35 auto ret = PowerExtIntfWrapper::Instance().GetRebootCommand(reason, rebootCmd);
36 if (ret != PowerExtIntfWrapper::ErrCode::ERR_OK) {
37 rebootCmd = Updater(reason);
38 }
39 POWER_HILOGI(FEATURE_SHUTDOWN, "Reboot command: %{public}s", rebootCmd.c_str());
40 DoRebootExt(rebootCmd.c_str(), reason.c_str());
41 }
42
Shutdown(const std::string & reason)43 void DevicePowerAction::Shutdown(const std::string& reason)
44 {
45 POWER_HILOGI(FEATURE_SHUTDOWN, "Shutdown executing");
46 DoRebootExt(SHUTDOWN_CMD.c_str(), reason.c_str());
47 }
48
Updater(const std::string & reason)49 std::string DevicePowerAction::Updater(const std::string& reason)
50 {
51 return (reason.find(UPDATER_CMD) != std::string::npos) ? UPDATER_CMD : REBOOT_CMD;
52 }
53 } // namespace PowerMgr
54 } // namespace OHOS
55