#include <glib.h>
#include <gio/gio.h>
+#include <hal/device/hal-board.h>
+
#include "device-error.h"
/**
*/
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
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) {
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);
{
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),