From 49dbce56deddd42bf2b23af710c17be9e1a0961f Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 14 Jun 2022 14:34:18 +0900 Subject: [PATCH] power: prevent poweroff if partition cloning is in progress Change-Id: Ib280523ff8ffd248d6aea7b2ecb324dc0990ae5b Signed-off-by: Youngjae Cho --- include/power-internal.h | 14 ++++++++++++++ src/power-internal.c | 12 ++++++++++++ src/power.c | 10 ++++++++++ 3 files changed, 36 insertions(+) diff --git a/include/power-internal.h b/include/power-internal.h index fac6b59..6647d8a 100644 --- a/include/power-internal.h +++ b/include/power-internal.h @@ -25,6 +25,8 @@ extern "C" { #include #include +#include + #include "device-error.h" /** @@ -129,6 +131,18 @@ typedef void (*change_state_callback) (uint64_t state, int retval, void *user_da */ int device_power_change_state(uint64_t state, int timeout_sec, change_state_callback cb, void *user_data); +/** + * Return 0 if cloning partition is in progress. + */ +static inline int device_power_check_reboot_allowed(void) +{ + int retval, cloned; + + retval = hal_device_board_get_partition_ab_cloned(&cloned); + + return (retval != 0 || cloned != 0); +} + #ifdef __cplusplus } #endif diff --git a/src/power-internal.c b/src/power-internal.c index 7244368..bd2c461 100644 --- a/src/power-internal.c +++ b/src/power-internal.c @@ -255,6 +255,18 @@ int device_power_change_state(uint64_t state, int timeout_sec, change_state_call GDBusConnection *connection; struct change_state_handler *h = NULL; + if (!device_power_check_reboot_allowed()) { + if (state == POWER_STATE_POWEROFF) { + _E("Failed to Poweroff due to partition cloning."); + return DEVICE_ERROR_OPERATION_FAILED; + } + + if (state == POWER_STATE_REBOOT) { + _E("Failed to Reboot due to partition cloning."); + return DEVICE_ERROR_OPERATION_FAILED; + } + } + if (cb) { h = (struct change_state_handler *) calloc(1, sizeof(struct change_state_handler)); if (!h) { diff --git a/src/power.c b/src/power.c index cae193b..9776517 100644 --- a/src/power.c +++ b/src/power.c @@ -562,6 +562,11 @@ int device_power_reboot(const char *reason) GVariant *param; int ret_dbus; + if (!device_power_check_reboot_allowed()) { + _E("Failed to Reboot due to partition cloning."); + return DEVICE_ERROR_OPERATION_FAILED; + } + if (reason) { method = METHOD_POWEROFF_WITH_OPTION; param = g_variant_new("(ss)", TYPE_REBOOT, reason); @@ -583,6 +588,11 @@ int device_power_poweroff(void) { int ret_dbus; + if (!device_power_check_reboot_allowed()) { + _E("Failed to Poweroff due to partition cloning."); + return DEVICE_ERROR_OPERATION_FAILED; + } + ret_dbus = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, METHOD_POWEROFF, g_variant_new("(s)", TYPE_POWEROFF), -- 2.7.4