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 fac6b5939e59e1560721429d74f28fceeb57c722..6647d8a048af3b2a0160cca99a1de6c25966b74f 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 72443683a7d18d5483cabd5749d95fc7f712a9b9..bd2c461de08c6c0ca557e437afbb6d5580dcb6ba 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 cae193b4f4edbd0ac63c165a0ab93cf0bc3e92fc..9776517e4c213c8df749d18b06ec46958e6fb745 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),