From: Jeon Sang-Heon Date: Thu, 30 Jul 2020 16:01:02 +0000 (+0000) Subject: Move fota status and info checker into fota directory X-Git-Tag: submit/tizen/20200807.173049~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F06%2F239906%2F11;p=platform%2Fcore%2Fsystem%2Fupdate-control.git Move fota status and info checker into fota directory - Change some log message to fota related tag - Move fota related file to fota directory - Minor change for variable, constant, method name Change-Id: Ifbe582164919439a1481ecb41a82bfbe11fe7d31 Signed-off-by: Jeon Sang-Heon --- diff --git a/update-manager/common/common-boot-status-checker.c b/update-manager/common/common-boot-status-checker.c index f217ce9..13f8e36 100644 --- a/update-manager/common/common-boot-status-checker.c +++ b/update-manager/common/common-boot-status-checker.c @@ -1,4 +1,5 @@ #include "../recovery/recovery-manager.h" +#include "../fota/fota-manager.h" #include "../update-manager.h" static int boot_status = -1; diff --git a/update-manager/common/common-storage-checker.c b/update-manager/common/common-storage-checker.c index 4da4920..7e16a79 100644 --- a/update-manager/common/common-storage-checker.c +++ b/update-manager/common/common-storage-checker.c @@ -1,4 +1,5 @@ #include "../recovery/recovery-manager.h" +#include "../fota/fota-manager.h" #include "../update-manager.h" void common_storage_checker_callback(int storage_id, storage_dev_e dev, storage_state_e state, const char *fstype, diff --git a/update-manager/fota-controller.c b/update-manager/fota-controller.c index 6d1b1cc..4cea23a 100644 --- a/update-manager/fota-controller.c +++ b/update-manager/fota-controller.c @@ -1,3 +1,4 @@ +#include "fota/fota-manager.h" #include "update-manager.h" int fota_controller_verify_delta(const char *delta_path) @@ -16,7 +17,7 @@ int fota_controller_verify_delta(const char *delta_path) goto verify_destroy; } - build_id = fota_info_get_build_id(); + build_id = fota_info_get_build_string(); if (build_id == NULL) { _E("Failed to get current build id"); status = -1; diff --git a/update-manager/fota-info-checker.c b/update-manager/fota-info-checker.c deleted file mode 100644 index 9a22923..0000000 --- a/update-manager/fota-info-checker.c +++ /dev/null @@ -1,47 +0,0 @@ -#include "update-manager.h" - -static char *build_id = NULL; -static char *platform_version = NULL; - -char *fota_info_get_build_id() -{ - return build_id; -} - -char *fota_info_get_platform_version() -{ - return platform_version; -} - -int fota_info_checker_init() -{ - int ret = 0; - - _I("Start process to get fota information"); - ret = system_info_get_platform_string(BUILD_ID_KEY, &build_id); - if (ret != SYSTEM_INFO_ERROR_NONE) { - _E("system_info_get_platform_string failed : %d", ret); - return -1; - } - - ret = system_info_get_platform_string(PLATFORM_VERSION_KEY, &platform_version); - if (ret != SYSTEM_INFO_ERROR_NONE) { - _E("system_info_get_platform_string failed : %d", ret); - return -1; - } - - _I("Success to get fota information, platform : %s, build_id : %s", - platform_version, build_id); - return 0; -} - -int fota_info_checker_fini() -{ - if (build_id) - free(build_id); - - if (platform_version) - free(platform_version); - - return 0; -} \ No newline at end of file diff --git a/update-manager/fota-status-checker.c b/update-manager/fota-status-checker.c deleted file mode 100644 index 6018843..0000000 --- a/update-manager/fota-status-checker.c +++ /dev/null @@ -1,78 +0,0 @@ -#include "update-manager.h" - -static char *fota_result = NULL; - -char *fota_status_get_result() -{ - return fota_result; -} - -int fota_status_checker_process() -{ - int ret = 0; - - if (g_file_test(STATUS_FLAG_PATH, G_FILE_TEST_EXISTS)) { - _I("This boot is triggered with fota, start process to send result to client"); - - ret = fota_client_controller_add_event(FOTA_EVENT_REBOOT, fota_result); - if (ret < 0) { - _E("Failed to add fota client event : %d, idx : %d, value : %s", - ret, FOTA_EVENT_REBOOT, fota_result); - return -1; - } - - ret = remove(STATUS_FLAG_PATH); - if (ret != 0) { - _E("Failed to remove fota flag : %m"); - return -1; - } - - _I("Success to process boot triggered with fota"); - } else { - _I("This boot isn't triggered with fota"); - } - - return 0; -} - -int fota_status_checker_init() -{ - int ret = 0; - char buf[MAX_BUFFER_SIZE] = {0, }; - - if (g_file_test(STATUS_RESULT_PATH, G_FILE_TEST_EXISTS)) { - _I("This boot have fota status, start process to get fota result"); - - ret = util_file_read_line(STATUS_RESULT_PATH, buf); - if (ret < 0) { - _E("Failed to read fota result : %d", ret); - return -1; - } - - fota_result = strndup(buf, strlen(buf)); - if (fota_result == NULL) { - _E("Failed to strndup value (%s) : %m", buf); - return -1; - } - - _I("Success to read fota result : %s", fota_result); - - ret = fota_status_checker_process(); - if (ret < 0) { - _E("Failed to process fota reboot result : %d", ret); - return -1; - } - } else { - _I("This boot doesn't have fota result"); - } - - return 0; -} - -int fota_status_checker_fini() -{ - if (fota_result) - free(fota_result); - - return 0; -} diff --git a/update-manager/fota/fota-client-controller.c b/update-manager/fota/fota-client-controller.c index 4271842..6207a4b 100644 --- a/update-manager/fota/fota-client-controller.c +++ b/update-manager/fota/fota-client-controller.c @@ -1,9 +1,10 @@ #include "../update-manager.h" +#include "fota-manager.h" static const char* fota_event_keys[FOTA_EVENT_SIZE] = { - CLIENT_APP_CTRL_LOCAL_KEY, - CLIENT_APP_CTRL_UNPLUG_KEY, - CLIENT_APP_CTRL_REBOOT_KEY, + FOTA_CLIENT_APP_CTRL_PLUG_KEY, + FOTA_CLIENT_APP_CTRL_UNPLUG_KEY, + FOTA_CLIENT_APP_CTRL_REBOOT_KEY, }; static char *fota_event_values[FOTA_EVENT_SIZE] = { NULL, @@ -18,12 +19,12 @@ int fota_client_controller_process_event() appid = fota_client_info_get_appid(); if (appid == NULL) { - _I("Failed to launch fota client, not found"); + _FLOGI("Failed to launch fota client, not found"); return 1; } if (!common_boot_status_checker_is_success()) { - _I("Failed to launch fota client, user session is unset"); + _FLOGI("Failed to launch fota client, user session is unset"); return 2; } @@ -31,13 +32,13 @@ int fota_client_controller_process_event() if (fota_event_values[idx] != NULL) { ret = common_client_controller_launch(appid, fota_event_keys[idx], fota_event_values[idx]); if (ret < 0) { - _E("Failed to launch fota client : %d, appid: %s, key : %s, value : %s", + _FLOGE("Failed to launch fota client : %d, appid: %s, key : %s, value : %s", ret, appid, fota_event_keys[idx], fota_event_values[idx]); status = -1; continue; } - _I("Success to launch fota client, appid: %s, key : %s, value : %s", + _FLOGI("Success to launch fota client, appid: %s, key : %s, value : %s", appid, fota_event_keys[idx], fota_event_values[idx]); free(fota_event_values[idx]); @@ -53,22 +54,22 @@ int fota_client_controller_add_event(fota_event_idx idx, const char *value) int ret = 0; if (fota_event_values[idx] != NULL) { - _I("Same fota event has already set, key: %s, value: %s", + _FLOGI("Same fota event has already set, key: %s, value: %s", fota_event_keys[idx], fota_event_values[idx]); return -1; } fota_event_values[idx] = strndup(value, strlen(value)); if (fota_event_values[idx] == NULL) { - _E("Failed to strndup value (%s) : %m", value); + _FLOGE("Failed to strndup value (%s) : %m", value); return -1; } - _I("Success to set fota client event, key: %s, value: %s", + _FLOGI("Success to set fota client event, key: %s, value: %s", fota_event_keys[idx], fota_event_values[idx]); if (fota_event_values[FOTA_EVENT_PLUG] != NULL && fota_event_values[FOTA_EVENT_UNPLUG] != NULL) { - _I("Find fota plug/unplug event set at the same time, so remove them"); + _FLOGI("Find fota plug/unplug event set at the same time, so remove them"); free(fota_event_values[FOTA_EVENT_PLUG]); free(fota_event_values[FOTA_EVENT_UNPLUG]); @@ -79,7 +80,7 @@ int fota_client_controller_add_event(fota_event_idx idx, const char *value) ret = fota_client_controller_process_event(); if (ret < 0) { - _E("Failed to process fota event : %d", ret); + _FLOGE("Failed to process fota event : %d", ret); return -1; } diff --git a/update-manager/fota/fota-client-info-checker.c b/update-manager/fota/fota-client-info-checker.c index 95cac72..1f657d5 100644 --- a/update-manager/fota/fota-client-info-checker.c +++ b/update-manager/fota/fota-client-info-checker.c @@ -1,4 +1,5 @@ #include "../update-manager.h" +#include "fota-manager.h" static char *fota_client_app_id = NULL; @@ -13,14 +14,14 @@ int fota_client_info_checker_callback(pkgmgrinfo_appinfo_h handle, void *user_da ret = common_client_info_checker_get_appid(handle, &fota_client_app_id); if (ret < 0) { - _E("Failed to get fota app id from handle : %d", ret); + _FLOGE("Failed to get fota app id from handle : %d", ret); return -1; } - _I("Success to find fota client id : %s, try process fota event", fota_client_app_id); + _FLOGI("Success to find fota client id : %s, try process fota event", fota_client_app_id); ret = fota_client_controller_process_event(); if (ret < 0) - _E("Failed to process fota client event : %d", ret); + _FLOGE("Failed to process fota client event : %d", ret); return 0; } @@ -31,7 +32,7 @@ int fota_client_info_checker_init() ret = common_client_info_checker_filter(FOTA_CLIENT_METADATA_KEY, FOTA_CLIENT_METADATA_VALUE, fota_client_info_checker_callback); if (ret < 0) { - _E("Failed to set fota client app filter : %d, key : %s, value : %s", + _FLOGE("Failed to set fota client app filter : %d, key : %s, value : %s", ret, FOTA_CLIENT_METADATA_KEY, FOTA_CLIENT_METADATA_VALUE); return -1; } diff --git a/update-manager/fota/fota-info-checker.c b/update-manager/fota/fota-info-checker.c new file mode 100644 index 0000000..380fddf --- /dev/null +++ b/update-manager/fota/fota-info-checker.c @@ -0,0 +1,48 @@ +#include "fota-manager.h" +#include "../update-manager.h" + +static char *build_string = NULL; +static char *platform_version = NULL; + +char *fota_info_get_build_string() +{ + return build_string; +} + +char *fota_info_get_platform_version() +{ + return platform_version; +} + +int fota_info_checker_init() +{ + int ret = 0; + + _FLOGI("Start process to get fota information"); + ret = system_info_get_platform_string(SYSTEM_INFO_BUILD_STRING, &build_string); + if (ret != SYSTEM_INFO_ERROR_NONE) { + _FLOGE("system_info_get_platform_string failed : %d", ret); + return -1; + } + + ret = system_info_get_platform_string(SYSTEM_INFO_PLATFORM_VERSION, &platform_version); + if (ret != SYSTEM_INFO_ERROR_NONE) { + _FLOGE("system_info_get_platform_string failed : %d", ret); + return -1; + } + + _FLOGI("Success to get fota information, platform : %s, build_string : %s", + platform_version, build_string); + return 0; +} + +int fota_info_checker_fini() +{ + if (build_string) + free(build_string); + + if (platform_version) + free(platform_version); + + return 0; +} \ No newline at end of file diff --git a/update-manager/fota/fota-manager.h b/update-manager/fota/fota-manager.h index e69de29..a279fbd 100644 --- a/update-manager/fota/fota-manager.h +++ b/update-manager/fota/fota-manager.h @@ -0,0 +1,54 @@ +#ifndef __FOTA_MANAGER_H__ +#define __FOTA_MANAGER_H__ + +#include +#include + +/* Log */ +#define FOTA_LOG_TAG "FOTA_MANAGER" + +#define _FLOGD(fmt, arg...) SLOG(LOG_INFO, FOTA_LOG_TAG, fmt, ##arg) +#define _FLOGI(fmt, arg...) SLOG(LOG_INFO, FOTA_LOG_TAG, fmt, ##arg) +#define _FLOGW(fmt, arg...) SLOG(LOG_WARN, FOTA_LOG_TAG, fmt, ##arg) +#define _FLOGE(fmt, arg...) SLOG(LOG_ERROR, FOTA_LOG_TAG, fmt, ##arg) + +/* Constant */ +#define FOTA_CLIENT_METADATA_KEY "tizen-fota-manager" +#define FOTA_CLIENT_METADATA_VALUE "client" +#define FOTA_CLIENT_APP_CTRL_PLUG_KEY "fota-plug" +#define FOTA_CLIENT_APP_CTRL_UNPLUG_KEY "fota-unplug" +#define FOTA_CLIENT_APP_CTRL_REBOOT_KEY "fota-reboot" + +#define SYSTEM_INFO_BUILD_STRING "tizen.org/system/build.string" +#define SYSTEM_INFO_PLATFORM_VERSION "tizen.org/feature/platform.version" + +#define FOTA_EVENT_SIZE 3 + +/* Enum */ +typedef enum { + FOTA_EVENT_PLUG = 0, + FOTA_EVENT_UNPLUG = 1, + FOTA_EVENT_REBOOT = 2 +} fota_event_idx; + +/* Function */ +int fota_client_controller_process_event(void); +int fota_client_controller_add_event(fota_event_idx, const char *); + +int fota_client_info_checker_init(void); +int fota_client_info_checker_fini(void); +char *fota_client_info_get_appid(void); + +int fota_info_checker_init(void); +int fota_info_checker_fini(void); +char *fota_info_get_build_string(void); +char *fota_info_get_platform_version(void); + +int fota_status_checker_init(void); +int fota_status_checker_fini(void); +char *fota_status_get_result(void); + +void fota_storage_checker_plug(int, const char *); +void fota_storage_checker_unplug(int, const char *); + +#endif /* __FOTA_MANAGER_H__ */ diff --git a/update-manager/fota/fota-status-checker.c b/update-manager/fota/fota-status-checker.c new file mode 100644 index 0000000..c4e8409 --- /dev/null +++ b/update-manager/fota/fota-status-checker.c @@ -0,0 +1,61 @@ +#include "fota-manager.h" +#include "../update-manager.h" + +static char *fota_result = NULL; + +char *fota_status_get_result() +{ + return fota_result; +} + +int fota_status_checker_init() +{ + int ret = 0; + char buf[MAX_BUFFER_SIZE] = {0, }; + + if (!g_file_test(STATUS_RESULT_PATH, G_FILE_TEST_EXISTS)) { + _FLOGI("This boot doesn't have fota result"); + return 0; + } + + ret = util_file_read_line(STATUS_RESULT_PATH, buf); + if (ret < 0) { + _FLOGE("Failed to read fota result : %d", ret); + return -1; + } + + fota_result = strndup(buf, strlen(buf)); + if (fota_result == NULL) { + _FLOGE("Failed to strndup value (%s) : %m", buf); + return -1; + } + + _FLOGI("Success to read fota result : %s", fota_result); + if (!g_file_test(STATUS_FLAG_PATH, G_FILE_TEST_EXISTS)) { + _FLOGI("This boot isn't triggered with fota"); + return 0; + } + + ret = fota_client_controller_add_event(FOTA_EVENT_REBOOT, fota_result); + if (ret < 0) { + _FLOGE("Failed to add fota client event : %d, idx : %d, value : %s", + ret, FOTA_EVENT_REBOOT, fota_result); + return -1; + } + + ret = remove(STATUS_FLAG_PATH); + if (ret != 0) { + _FLOGE("Failed to remove fota flag : %d, %m", ret); + return -1; + } + + return 0; +} + +int fota_status_checker_fini() +{ + if (fota_result) + free(fota_result); + + return 0; +} diff --git a/update-manager/fota/fota-storage-checker.c b/update-manager/fota/fota-storage-checker.c index ab528a1..ed04d7d 100644 --- a/update-manager/fota/fota-storage-checker.c +++ b/update-manager/fota/fota-storage-checker.c @@ -1,4 +1,5 @@ #include "../update-manager.h" +#include "fota-manager.h" static int fota_storage_id = -1; @@ -15,15 +16,15 @@ int fota_storage_search_delta_path(const char *mount_path, gchar **delta_path) mount = g_file_new_for_path(mount_path); enumerator = g_file_enumerate_children(mount, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error); if (enumerator == NULL) { - _E("Failed to get enumerator : %s", error->message); + _FLOGE("Failed to get enumerator : %s", error->message); g_clear_error(&error); status = -1; goto search_destroy; } - build_id = fota_info_get_build_id(); + build_id = fota_info_get_build_string(); if (build_id == NULL) { - _E("Failed to get build id"); + _FLOGE("Failed to get build id"); status = -1; goto search_destroy; } @@ -42,9 +43,9 @@ int fota_storage_search_delta_path(const char *mount_path, gchar **delta_path) } if (*delta_path != NULL) { - _I("Success to find delta path : %s", *delta_path); + _FLOGI("Success to find delta path : %s", *delta_path); } else { - _I("Failed to find delta path with prefix %s", build_id); + _FLOGI("Failed to find delta path with prefix %s", build_id); status = 1; } @@ -65,22 +66,22 @@ void fota_storage_checker_plug(int storage_id, const char *mount_path) int ret = 0; gchar *delta_path = NULL; - _I("Storage mounted with %s, start process to check local delta", mount_path); + _FLOGI("Storage mounted with %s, start process to check local delta", mount_path); ret = fota_storage_search_delta_path(mount_path, &delta_path); if (ret != 0) { - _E("Failed to find delta path : %d", ret); + _FLOGE("Failed to find delta path : %d", ret); goto plug_destroy; } ret = fota_controller_verify_delta(delta_path); if (ret != 0) { - _E("Failed to verify delta : %d", ret); + _FLOGE("Failed to verify delta : %d", ret); goto plug_destroy; } ret = fota_client_controller_add_event(FOTA_EVENT_PLUG, delta_path); if (ret < 0) { - _E("Failed to add fota client event : %d, idx : %d, value : %s", + _FLOGE("Failed to add fota client event : %d, idx : %d, value : %s", ret, FOTA_EVENT_PLUG, delta_path); goto plug_destroy; } @@ -96,7 +97,7 @@ void fota_storage_checker_unplug(int storage_id, const char *mount_path) if (storage_id == fota_storage_id) { ret = fota_client_controller_add_event(FOTA_EVENT_UNPLUG, mount_path); if (ret < 0) { - _E("Failed to add fota client event : %d, idx : %d, value : %s", + _FLOGE("Failed to add fota client event : %d, idx : %d, value : %s", ret, FOTA_EVENT_UNPLUG, mount_path); } fota_storage_id = -1; diff --git a/update-manager/main.c b/update-manager/main.c index 368a3b4..2543da8 100644 --- a/update-manager/main.c +++ b/update-manager/main.c @@ -1,4 +1,5 @@ #include "recovery/recovery-manager.h" +#include "fota/fota-manager.h" #include "update-manager.h" int main(int argc, char *argv[]) diff --git a/update-manager/update-manager.h b/update-manager/update-manager.h index 2392b0a..88e2110 100644 --- a/update-manager/update-manager.h +++ b/update-manager/update-manager.h @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -31,27 +30,17 @@ /* Common */ #define MAX_BUFFER_SIZE 256 -#define MAX_STACK_SIZE 5 #define OWNER_UID 5001 /* Dbus */ #define INTERFACE_NAME "org.tizen.update.manager" #define NODE_NAME "/org/tizen/update/manager" -/* Client */ -#define FOTA_CLIENT_METADATA_KEY "tizen-update-manager" -#define FOTA_CLIENT_METADATA_VALUE "client" -#define CLIENT_APP_CTRL_LOCAL_KEY "fota-local" -#define CLIENT_APP_CTRL_UNPLUG_KEY "fota-unplug" -#define CLIENT_APP_CTRL_REBOOT_KEY "fota-reboot" - /* Update */ -#define PLATFORM_VERSION_KEY "tizen.org/feature/platform.version" #define PLATFORM_VERSION_DIR "/opt/etc" #define PLATFORM_VERSION_FILE "version" #define PLATFORM_VERSION_PATH PLATFORM_VERSION_DIR "/" PLATFORM_VERSION_FILE -#define BUILD_ID_KEY "tizen.org/system/build.string" #define BUILD_ID_DIR "/tmp" #define BUILD_ID_FILE "build_id.txt" #define BUILD_ID_PATH BUILD_ID_DIR "/" BUILD_ID_FILE @@ -62,8 +51,6 @@ #define FOTA_DELTA_PATH FOTA_DIR "/" FOTA_DELTA_FILE #define FOTA_DELTA_UA_FILE "delta.ua" -#define FOTA_EVENT_SIZE 3 - #define STATUS_DIR "/opt/data/update" #define STATUS_FLAG_FILE "is-first-boot-after-fota" #define STATUS_FLAG_PATH STATUS_DIR "/" STATUS_FLAG_FILE @@ -75,21 +62,7 @@ #define SHARED_DIR "/opt/usr/home/owner/apps_rw" #define SHARED_DATA_DIR "shared/data" -/* Enum */ -typedef enum { - FOTA_EVENT_PLUG = 0, - FOTA_EVENT_UNPLUG = 1, - FOTA_EVENT_REBOOT = 2 -} fota_event_idx; - /* Function */ -int fota_client_info_checker_init(void); -int fota_client_info_checker_fini(void); -char *fota_client_info_get_appid(void); - -int fota_client_controller_process_event(void); -int fota_client_controller_add_event(fota_event_idx, const char *); - int common_storage_checker_init(void); int common_storage_checker_fini(void); @@ -105,22 +78,10 @@ int common_client_info_checker_filter(const char*, const char*, pkgmgrinfo_app_l int dbus_manager_init(void); int dbus_manager_fini(void); -int fota_info_checker_init(void); -int fota_info_checker_fini(void); -char *fota_info_get_build_id(void); -char *fota_info_get_platform_version(void); - -int fota_status_checker_init(void); -int fota_status_checker_fini(void); -char *fota_status_get_result(void); - int fota_controller_verify_delta(const char *); int fota_controller_install(void); int fota_controller_result(void); -void fota_storage_checker_plug(int, const char *); -void fota_storage_checker_unplug(int, const char *); - int util_file_mkdir(const char *); int util_file_read_line(const char *, char []); int util_file_write_line(const char *, const char *);