power: prevent poweroff if partition cloning is in progress 90/276290/2
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 14 Jun 2022 05:34:18 +0000 (14:34 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 14 Jun 2022 07:08:23 +0000 (16:08 +0900)
Change-Id: Ib280523ff8ffd248d6aea7b2ecb324dc0990ae5b
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
include/power-internal.h
src/power-internal.c
src/power.c

index fac6b59..6647d8a 100644 (file)
@@ -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
index 7244368..bd2c461 100644 (file)
@@ -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) {
index cae193b..9776517 100644 (file)
@@ -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),