diff options
author | Youngjae Cho <y0.cho@samsung.com> | 2022-06-14 14:34:18 +0900 |
---|---|---|
committer | Youngjae Cho <y0.cho@samsung.com> | 2022-06-14 16:08:23 +0900 |
commit | 49dbce56deddd42bf2b23af710c17be9e1a0961f (patch) | |
tree | 1e3b2adee605074bd170a7204f8bbd541ead7814 | |
parent | e7fe520d0cc8bedba4241fe7ed7398565cfe9159 (diff) | |
download | device-49dbce56deddd42bf2b23af710c17be9e1a0961f.tar.gz device-49dbce56deddd42bf2b23af710c17be9e1a0961f.tar.bz2 device-49dbce56deddd42bf2b23af710c17be9e1a0961f.zip |
power: prevent poweroff if partition cloning is in progress
Change-Id: Ib280523ff8ffd248d6aea7b2ecb324dc0990ae5b
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
-rw-r--r-- | include/power-internal.h | 14 | ||||
-rw-r--r-- | src/power-internal.c | 12 | ||||
-rw-r--r-- | src/power.c | 10 |
3 files changed, 36 insertions, 0 deletions
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 <glib.h> #include <gio/gio.h> +#include <hal/device/hal-board.h> + #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), |