update-manager: Add upgrade state transition to "completed" 76/312676/1 accepted/tizen/unified/20240614.085117 accepted/tizen/unified/dev/20240620.005823 accepted/tizen/unified/x/20240614.160543
authorSangYoun Kwak <sy.kwak@samsung.com>
Wed, 12 Jun 2024 08:55:11 +0000 (17:55 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 13 Jun 2024 02:28:16 +0000 (11:28 +0900)
It should be checked if the upgrade is completed or not when the device
is booted.

To accomplish this, upgrade-complete checking code is added to the
initial function of update-manager daemon.

Upgrade is considered as complete when the conditions below are all met:
 * bootmode is normal
 * upgrade progress state is 100

Change-Id: I4cf09b6328202497025b61119f46353459e001f8
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
update-manager/fota/fota-installer.c
update-manager/fota/fota-manager.h
update-manager/main.c

index 8f597db8d9db42f060f71ef5f556a877e8db589b..8ed8e8df414d99545387c3eb5f376bfb005b297f 100644 (file)
@@ -237,9 +237,10 @@ int execute_upgrade_trigger(struct deltas *deltas, char *mode)
        #undef MAX_ARGS
 }
 
-static int set_upgrade_state(char *next_upgrade_state)
+static int set_upgrade_state_ready(void)
 {
        char current_upgrade_state[128];
+       char *next_upgrade_state = "ready";
        int ret = 0;
 
        ret = hal_device_board_get_upgrade_state(current_upgrade_state,
@@ -277,7 +278,7 @@ int fota_installer_ro_update_and_finish_update(pid_t sender_pid)
                goto execute_destroy;
        }
 
-       ret = set_upgrade_state("ready");
+       ret = set_upgrade_state_ready();
        if (ret < 0) {
                status = ret;
                goto execute_destroy;
@@ -346,7 +347,7 @@ int fota_installer_ro_update(pid_t sender_pid)
                goto execute_destroy;
        }
 
-       ret = set_upgrade_state("ready");
+       ret = set_upgrade_state_ready();
        if (ret < 0) {
                status = ret;
                goto execute_destroy;
@@ -429,3 +430,79 @@ int fota_installer_finish_update(void)
 
        return exec_status > 0 ? -exec_status : exec_status;
 }
+
+static int is_upgrade_completed(void)
+{
+       char boot_mode[128];
+       int upgrde_progress_status = 0;
+       int ret = 0;
+
+       ret = hal_device_board_get_upgrade_progress_status(&upgrde_progress_status);
+       if (ret < 0) {
+               _FLOGE("Failed to get upgrade progress status: %d", ret);
+               return -1;
+       }
+
+       ret = hal_device_board_get_boot_mode(boot_mode, sizeof(boot_mode));
+       if (ret < 0) {
+               _FLOGE("Failed to get boot mode: %d", ret);
+               return -1;
+       }
+
+       if (upgrde_progress_status != 100) {
+               _FLOGI("Upgrade not completed: upgrade progress status is not 100 but %d",
+                               upgrde_progress_status);
+               return 0;
+       }
+
+       if (strncmp(boot_mode, "normal", sizeof(boot_mode)) != 0) {
+               _FLOGI("Boot mode is not normal: %s", boot_mode);
+               return 0;
+       }
+
+       return 1;
+}
+
+int fota_installer_check_and_set_upgrade_state_completed(void)
+{
+       char current_upgrade_state[128];
+       char *next_upgrade_state = "completed";
+       int ret = 0;
+
+       ret = is_upgrade_completed();
+       if (ret < 0) {
+               _FLOGE("Failed to check if upgrade completed.");
+               return -1;
+       }
+
+       if (ret == 0) {
+               _FLOGI("Upgrade is not completed.");
+               return -1;
+       }
+
+       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;
+       }
+
+       if (strncmp(current_upgrade_state, next_upgrade_state,
+                               sizeof(current_upgrade_state)) == 0) {
+               _FLOGI("Upgrade state is already %s.", next_upgrade_state);
+               return 0;
+       }
+
+       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;
+}
index 24ef468a32f21c9d0093cec468d612280efc08e7..b25efb817181aca8a8651827811659709a56b74b 100644 (file)
@@ -58,6 +58,7 @@ char *fota_client_info_get_appid(void);
 int fota_installer_ro_update_and_finish_update(pid_t sender_pid);
 int fota_installer_ro_update(pid_t sender_pid);
 int fota_installer_finish_update(void);
+int fota_installer_check_and_set_upgrade_state_completed(void);
 
 void fota_storage_checker_plug(int, const char *);
 void fota_storage_checker_unplug(int, const char *);
index b17aa13f038a91c1f7058889edc9ce8554bcf463..5fc60a8fa9319d45ea8fdf865cc126758daf6345 100644 (file)
@@ -47,6 +47,10 @@ int main(int argc, char *argv[])
                goto main_destroy;
        }
 
+       ret = fota_installer_check_and_set_upgrade_state_completed();
+       if (ret < 0)
+               _CLOGE("Failed to set upgrade state completed : %d", ret);
+
        g_main_loop_run(mainloop);
 
 main_destroy: