From 906e6f369c7525f361f772025b20e73847958145 Mon Sep 17 00:00:00 2001 From: ShiJie Date: Sat, 15 Jan 2022 14:11:32 +0800 Subject: [PATCH] DoReboot Signed-off-by: ShiJie Change-Id: I41368cbaf06cc1e44526cb893217f8aa2224637c --- .../native/include/power_mgr_client.h | 4 +-- interfaces/kits/js/@ohos.power.d.ts | 2 +- .../actions/default/device_power_action.cpp | 27 ++++++++++--------- .../src/actions/default/device_power_action.h | 3 +++ services/native/src/power_mgr_service.cpp | 4 +-- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/interfaces/innerkits/native/include/power_mgr_client.h b/interfaces/innerkits/native/include/power_mgr_client.h index d62d45a0..6a4c0f46 100644 --- a/interfaces/innerkits/native/include/power_mgr_client.h +++ b/interfaces/innerkits/native/include/power_mgr_client.h @@ -35,14 +35,14 @@ public: /** * Reboot the device. * - * @param reason The reason for rebooting the device. + * @param reason The reason for rebooting the device. e.g.updater */ void RebootDevice(const std::string& reason); /** * Shut down the device. * - * @param reason The reason for shutting down the device. e.g.recovery. + * @param reason The reason for shutting down the device. * */ void ShutDownDevice(const std::string& reason); diff --git a/interfaces/kits/js/@ohos.power.d.ts b/interfaces/kits/js/@ohos.power.d.ts index 9d1d90d1..8b2ddced 100644 --- a/interfaces/kits/js/@ohos.power.d.ts +++ b/interfaces/kits/js/@ohos.power.d.ts @@ -39,7 +39,7 @@ declare namespace power { * *

This method requires the ohos.permission.REBOOT permission. * - * @param reason Indicates the restart reason. For example, "recovery" indicates entering the recovery mode + * @param reason Indicates the restart reason. For example, "updater" indicates entering the updater mode * after the restart. If the parameter is not specified, the system enters the normal mode after the restart. * @since 7 */ diff --git a/services/native/src/actions/default/device_power_action.cpp b/services/native/src/actions/default/device_power_action.cpp index c904f197..7759d9d0 100644 --- a/services/native/src/actions/default/device_power_action.cpp +++ b/services/native/src/actions/default/device_power_action.cpp @@ -25,28 +25,31 @@ #include "hilog_wrapper.h" #include "init_reboot.h" +namespace { +const std::string UPDATER_CMD = "updater"; +const std::string REBOOT_CMD = ""; +const std::string SHUTDOWN_CMD = "shutdown"; +const std::string FLASH_CMD = "flash"; +} + namespace OHOS { namespace PowerMgr { void DevicePowerAction::Reboot(const std::string& reason) { - int32_t propertyMaxSize = PROPERTY_MAX_SIZE; - char updateCmd[propertyMaxSize]; - if (snprintf_s(updateCmd, propertyMaxSize, propertyMaxSize - 1, "reboot,%s", reason.c_str()) == 0) { - return; - } + std::string rebootReason = Updater(reason); POWER_HILOGI(MODULE_SERVICE, "Reboot executing."); - DoReboot(updateCmd); + DoReboot(rebootReason.c_str()); } void DevicePowerAction::Shutdown(const std::string& reason) { - int32_t propertyMaxSize = PROPERTY_MAX_SIZE; - char updateCmd[propertyMaxSize]; - if (snprintf_s(updateCmd, propertyMaxSize, propertyMaxSize - 1, "shutdown,%s", reason.c_str()) == 0) { - return; - } POWER_HILOGI(MODULE_SERVICE, "Shutdown executing."); - DoReboot(updateCmd); + DoReboot(SHUTDOWN_CMD.c_str()); +} + +std::string DevicePowerAction::Updater(const std::string& reason) +{ + return (reason.find(UPDATER_CMD) != std::string::npos) ? UPDATER_CMD : REBOOT_CMD; } } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/src/actions/default/device_power_action.h b/services/native/src/actions/default/device_power_action.h index 1e862469..43a99418 100644 --- a/services/native/src/actions/default/device_power_action.h +++ b/services/native/src/actions/default/device_power_action.h @@ -27,6 +27,9 @@ public: int PROPERTY_MAX_SIZE = 92; void Reboot(const std::string& reason) override; void Shutdown(const std::string& reason) override; + +private: + std::string Updater(const std::string& reason); }; } // namespace PowerMgr } // namespace OHOS diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index 3ca7654d..0c2049c0 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -151,8 +151,8 @@ void PowerMgrService::RebootDevice(const std::string& reason) std::lock_guard lock(mutex_); pid_t pid = IPCSkeleton::GetCallingPid(); auto uid = IPCSkeleton::GetCallingUid(); - if (reason.find("recovery") != std::string::npos) { - if (!Permission::CheckCallingPermission("ohos.permission.REBOOT_RECOVERY")) { + if (reason.find("updater") != std::string::npos) { + if (!Permission::CheckCallingPermission("ohos.permission.REBOOT_UPDATER")) { POWER_HILOGE(MODULE_SERVICE, "%{public}s Request failed, %{public}d permission check fail", __func__, pid); -- Gitee