fota: Modify upgrade checking function more readable 20/314720/3
authorSangYoun Kwak <sy.kwak@samsung.com>
Wed, 17 Jul 2024 10:10:17 +0000 (19:10 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Mon, 22 Jul 2024 03:46:02 +0000 (12:46 +0900)
Previously, the function is_upgrade_completed() gets no argument and
returns -1 if error, 0 if upgrade is not completed, 1 if upgrade is
completed. This might confusing since the return value does two role:
indicating error and upgrade completion.

To increase the readability, the return value is only shows if function
call is succeed or not and upgrade completion is returned using bool
type parameter "upgrade_completed".

Also, the behavior of function is changed to 'get boolean value about
upgrade is done or not', so the name of this function is changed to
get_upgrade_completed.

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

index 99d64547b21f68eb98ab5dc55e52d812c2ddc1e5..b59693bbe7ffcacfdac0e7699d2370f395701c8b 100644 (file)
@@ -462,7 +462,7 @@ int fota_installer_finish_update(void)
        return exec_status > 0 ? -exec_status : exec_status;
 }
 
-static int is_upgrade_completed(void)
+static int get_upgrade_completed(bool *upgrade_completed)
 {
        char boot_mode[128];
        int upgrde_progress_status = 0;
@@ -483,15 +483,19 @@ static int is_upgrade_completed(void)
        if (upgrde_progress_status != 100) {
                _FLOGI("Upgrade not completed: upgrade progress status is not 100 but %d",
                                upgrde_progress_status);
+               *upgrade_completed = false;
                return 0;
        }
 
        if (strncmp(boot_mode, "normal", sizeof(boot_mode)) != 0) {
                _FLOGI("Boot mode is not normal: %s", boot_mode);
+               *upgrade_completed = false;
                return 0;
        }
 
-       return 1;
+       *upgrade_completed = true;
+
+       return 0;
 }
 
 int fota_installer_check_and_set_upgrade_state_completed(void)
@@ -499,14 +503,15 @@ int fota_installer_check_and_set_upgrade_state_completed(void)
        char current_upgrade_state[128];
        char *next_upgrade_state = "completed";
        int ret = 0;
+       bool upgrade_completed = false;
 
-       ret = is_upgrade_completed();
-       if (ret < 0) {
+       ret = get_upgrade_completed(&upgrade_completed);
+       if (ret != 0) {
                _FLOGE("Failed to check if upgrade completed.");
                return -1;
        }
 
-       if (ret == 0) {
+       if (!upgrade_completed) {
                _FLOGI("Upgrade is not completed.");
                return 0;
        }