Add upgrade state transition to 'ready' state 75/312675/1
authorSangYoun Kwak <sy.kwak@samsung.com>
Wed, 12 Jun 2024 08:07:03 +0000 (17:07 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Wed, 12 Jun 2024 08:13:44 +0000 (17:13 +0900)
The start of upgrade is 'ro upgrade' so when the 'ro upgrade' starts,
the 'upgrade state' should be transit to the 'ready' state.

Change-Id: Ia3311216d22a8be7cb98db5e71f69c5e377044cb
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
update-manager/CMakeLists.txt
update-manager/fota/fota-installer.c

index 2d9d750a56d8bcd718b14eb50db5f8123ec3a1fd..16d260518dcdd855aa568c18c86789748147ec4c 100644 (file)
@@ -19,7 +19,9 @@ SET(PKG_MODULES
        storage
        vconf
        zlib
+       hal-api-device
 )
+
 INCLUDE(FindPkgConfig)
 pkg_check_modules(${PKG_NAME} REQUIRED ${PKG_MODULES})
 
index 73d88ba67ae59c73ec47237a16c89e69a9419b02..8f597db8d9db42f060f71ef5f556a877e8db589b 100644 (file)
@@ -2,6 +2,9 @@
 #include <alloca.h>
 #include <linux/limits.h>
 #include <stdlib.h>
+
+#include <hal/hal-device-board.h>
+
 #include "../common/common.h"
 #include "fota-manager.h"
 
@@ -234,6 +237,32 @@ int execute_upgrade_trigger(struct deltas *deltas, char *mode)
        #undef MAX_ARGS
 }
 
+static int set_upgrade_state(char *next_upgrade_state)
+{
+       char current_upgrade_state[128];
+       int ret = 0;
+
+       ret = hal_device_board_get_upgrade_state(current_upgrade_state,
+                                               sizeof(current_upgrade_state));
+       if (ret < 0) {
+               _FLOGE("Failed to get upgrade state: %d", ret);
+               return -1;
+       }
+
+       ret = hal_device_board_set_upgrade_state(current_upgrade_state,
+                                               next_upgrade_state);
+       if (ret < 0) {
+               _FLOGE("Failed to set upgrade state %s -> %s: %d",
+                               current_upgrade_state, next_upgrade_state, ret);
+               return -1;
+       }
+
+       _FLOGI("Succeed to set upgrade state %s -> %s", current_upgrade_state,
+                                                       next_upgrade_state);
+
+       return 0;
+}
+
 int fota_installer_ro_update_and_finish_update(pid_t sender_pid)
 {
        int ret = 0, status = 0, exec_status = 0;
@@ -248,6 +277,12 @@ int fota_installer_ro_update_and_finish_update(pid_t sender_pid)
                goto execute_destroy;
        }
 
+       ret = set_upgrade_state("ready");
+       if (ret < 0) {
+               status = ret;
+               goto execute_destroy;
+       }
+
        /* All basic checks succeeded, following is what happens next: We
         * double-fork() the process and run actual upgrade script in the child
         * process. We do this so that we can at least inform API client that
@@ -311,6 +346,12 @@ int fota_installer_ro_update(pid_t sender_pid)
                goto execute_destroy;
        }
 
+       ret = set_upgrade_state("ready");
+       if (ret < 0) {
+               status = ret;
+               goto execute_destroy;
+       }
+
        /*
        * This is supposed to bo called asynchronously, so we do
        * care if and when the script finishes.