• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_log.h"
21 
22 namespace {
23 const std::string UPDATER_CMD = "updater";
24 const std::string REBOOT_CMD = "";
25 const std::string SHUTDOWN_CMD = "shutdown";
26 const std::string FLASH_CMD = "flash";
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 rebootReason = Updater(reason);
34     POWER_HILOGI(FEATURE_SHUTDOWN, "Reboot executing");
35     DoReboot(rebootReason.c_str());
36 }
37 
Shutdown(const std::string & reason)38 void DevicePowerAction::Shutdown(const std::string& reason)
39 {
40     POWER_HILOGI(FEATURE_SHUTDOWN, "Shutdown executing");
41     DoReboot(SHUTDOWN_CMD.c_str());
42 }
43 
Updater(const std::string & reason)44 std::string DevicePowerAction::Updater(const std::string& reason)
45 {
46     return (reason.find(UPDATER_CMD) != std::string::npos) ? UPDATER_CMD : REBOOT_CMD;
47 }
48 } // namespace PowerMgr
49 } // namespace OHOS
50