From: SangYoun Kwak Date: Fri, 14 Jun 2024 06:17:36 +0000 (+0900) Subject: update-manager: Add upgrade state transition to "completed" X-Git-Tag: accepted/tizen/8.0/unified/20240618.013448^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d3e95e68bbc8b92a97fc2cd7d14cb7a585e59b34;p=platform%2Fcore%2Fsystem%2Fupdate-control.git update-manager: Add upgrade state transition to "completed" 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: I97ff92846e3ceefbe497bc6f0617efb667156ad5 Signed-off-by: SangYoun Kwak --- diff --git a/update-manager/fota/fota-installer.c b/update-manager/fota/fota-installer.c index 1306bb0..fe3e054 100644 --- a/update-manager/fota/fota-installer.c +++ b/update-manager/fota/fota-installer.c @@ -220,3 +220,79 @@ execute_destroy: return 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; +} diff --git a/update-manager/fota/fota-manager.h b/update-manager/fota/fota-manager.h index 9f271e1..d492de1 100644 --- a/update-manager/fota/fota-manager.h +++ b/update-manager/fota/fota-manager.h @@ -49,6 +49,7 @@ int fota_client_info_checker_fini(void); char *fota_client_info_get_appid(void); int fota_installer_execute(pid_t pid); +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 *); diff --git a/update-manager/main.c b/update-manager/main.c index b17aa13..5fc60a8 100644 --- a/update-manager/main.c +++ b/update-manager/main.c @@ -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: