diff --git a/interfaces/innerkits/native/include/power_mgr_client.h b/interfaces/innerkits/native/include/power_mgr_client.h index d62d45a0501a47335e278f76123e09a2f069d24b..6a4c0f46f1cbc84c9b4d529232ffe67a3ab8c06b 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 9d1d90d18872c0fcf15700cfb5148b86a1399717..8b2ddced8f1c9c614f7ad6ad3b153e85574440af 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 c904f197cd94b2bce80a164911c214c2764b9e99..7759d9d0b343217ecf65578edc8de0ad6384da94 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 1e862469c03390c4db7b6fb4f33c43b85a3e626f..43a99418969c624254e8e787c9309221edc42579 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 3ca7654d07f99c6b7dbc948e207184661ff96c48..0c2049c08da7682f1f4a4619951daff8060f04a3 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);