From: Jeon Sang-Heon Date: Wed, 29 Jul 2020 18:19:23 +0000 (+0000) Subject: Modify client controller to prevent unexpected event send X-Git-Tag: submit/tizen/20200807.173049~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d6123448f67bcfd57db04c1bb6ef12c474fb437;p=platform%2Fcore%2Fsystem%2Fupdate-control.git Modify client controller to prevent unexpected event send - Using stack(before method), may can send plug and unplug event to client at the same time - So change it to list and if plug and unplug event set at sametime, remove it. Change-Id: I9dc3a7e56402f15d8a83ab9e72ef2984fad30611 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 716f191..f217ce9 100644 --- a/update-manager/common/common-boot-status-checker.c +++ b/update-manager/common/common-boot-status-checker.c @@ -16,21 +16,21 @@ void common_boot_status_checker_callback(keynode_t *node, void *user_data) if (ret == VCONF_TYPE_INT) { boot_status = vconf_keynode_get_int(node); if (common_boot_status_checker_is_success()) { - _I("Success to get bootstatus : success"); - ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BOOTINGSTATUS, common_boot_status_checker_callback); if (ret == VCONF_OK) _I("Success to remove bootstatus callback"); else _W("vconf_ignore_key_changed for %s failed : %d", VCONFKEY_SYSMAN_BOOTINGSTATUS, ret); - ret = fota_client_controller_process_launch_request(); + _I("Success to get bootstatus success, try process fota event"); + ret = fota_client_controller_process_event(); if (ret < 0) - _E("Failed to process fota client : %d", ret); + _E("Failed to process fota client event : %d", ret); - ret = recovery_client_controller_process_launch_request(); + _RLOGI("Success to get bootstatus success, try process recovery event"); + ret = recovery_client_controller_process_event(); if (ret < 0) - _E("Failed to process recovery client : %d", ret); + _RLOGE("Failed to process recovery client event : %d", ret); } } else { _E("Invalid vconf key type : %d", ret); diff --git a/update-manager/common/common-client-controller.c b/update-manager/common/common-client-controller.c index ad4dab4..5d9499b 100644 --- a/update-manager/common/common-client-controller.c +++ b/update-manager/common/common-client-controller.c @@ -1,6 +1,6 @@ #include "../update-manager.h" -int common_client_controller_launch_req_data(const char* appid, req_data data) +int common_client_controller_launch(const char* appid, const char *key, const char *value) { int ret = 0, status = 0; bundle *bundle_data = NULL; @@ -19,7 +19,7 @@ int common_client_controller_launch_req_data(const char* appid, req_data data) goto launch_destroy; } - ret = aul_svc_add_data(bundle_data, data.key, data.value); + ret = aul_svc_add_data(bundle_data, key, value); if (ret != AUL_R_OK) { _E("aul_svc_add_data failed : %d", ret); status = -1; @@ -41,27 +41,3 @@ launch_destroy: return status; } - -int common_client_controller_generate_req_data(const char *key, const char *value, req_data *data) -{ - char *mem = NULL; - - mem = strndup(key, strlen(key)); - if (mem == NULL) { - _E("Failed to strndup key (%s) : %m", key); - return -1; - } - data->key = mem; - - mem = strndup(value, strlen(value)); - if (mem == NULL) { - _E("Failed to strndup value (%s) : %m", value); - - /* Rollback */ - free(data->key); - return -1; - } - data->value = mem; - - return 0; -} diff --git a/update-manager/fota-status-checker.c b/update-manager/fota-status-checker.c index 48b5194..6018843 100644 --- a/update-manager/fota-status-checker.c +++ b/update-manager/fota-status-checker.c @@ -14,10 +14,10 @@ int fota_status_checker_process() 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_launch_request_with_data(CLIENT_APP_CTRL_REBOOT_KEY, fota_result); + ret = fota_client_controller_add_event(FOTA_EVENT_REBOOT, fota_result); if (ret < 0) { - _E("Failed to add launch request : %d, key : %s, value : %s", - ret, CLIENT_APP_CTRL_REBOOT_KEY, fota_result); + _E("Failed to add fota client event : %d, idx : %d, value : %s", + ret, FOTA_EVENT_REBOOT, fota_result); return -1; } diff --git a/update-manager/fota/fota-client-controller.c b/update-manager/fota/fota-client-controller.c index 78f186f..4271842 100644 --- a/update-manager/fota/fota-client-controller.c +++ b/update-manager/fota/fota-client-controller.c @@ -1,66 +1,85 @@ #include "../update-manager.h" -static req_data fota_req_stack[MAX_STACK_SIZE]; -static int fota_req_top = -1; +static const char* fota_event_keys[FOTA_EVENT_SIZE] = { + CLIENT_APP_CTRL_LOCAL_KEY, + CLIENT_APP_CTRL_UNPLUG_KEY, + CLIENT_APP_CTRL_REBOOT_KEY, +}; +static char *fota_event_values[FOTA_EVENT_SIZE] = { + NULL, + NULL, + NULL, +}; -int fota_client_controller_process_launch_request() +int fota_client_controller_process_event() { - int ret = 0; + int ret = 0, status = 0, idx = 0; char *appid = NULL; appid = fota_client_info_get_appid(); if (appid == NULL) { - _I("Failed to launch client, fota client app id not found, current top : %d", fota_req_top); - return -1; + _I("Failed to launch fota client, not found"); + return 1; } if (!common_boot_status_checker_is_success()) { - _I("Failed to launch client, user session is unset, current top : %d", fota_req_top); - return -1; + _I("Failed to launch fota client, user session is unset"); + return 2; } - while(fota_req_top > -1) { - _I("Success to ready process launch fota client, top : %d, key : %s, value : %s", - fota_req_top, fota_req_stack[fota_req_top].key, fota_req_stack[fota_req_top].value); + for(idx = 0; idx < FOTA_EVENT_SIZE; ++idx) { + 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", + ret, appid, fota_event_keys[idx], fota_event_values[idx]); + status = -1; + continue; + } - ret = common_client_controller_launch_req_data(appid, fota_req_stack[fota_req_top]); - if (ret < 0) { - _E("Common client controller failed at fota"); - return -1; - } - - _I("Success to launch fota client with, key : %s, value : %s", - fota_req_stack[fota_req_top].key, fota_req_stack[fota_req_top].value); + _I("Success to launch fota client, appid: %s, key : %s, value : %s", + appid, fota_event_keys[idx], fota_event_values[idx]); - free(fota_req_stack[fota_req_top].key); - free(fota_req_stack[fota_req_top].value); - fota_req_top--; + free(fota_event_values[idx]); + fota_event_values[idx] = NULL; + } } - return 0; + return status; } -int fota_client_controller_add_launch_request_with_data(const char *key, const char *value) +int fota_client_controller_add_event(fota_event_idx idx, const char *value) { int ret = 0; - if (fota_req_top == MAX_STACK_SIZE - 1) { - _E("Failed to add launch request, Current top : %d", fota_req_top); + if (fota_event_values[idx] != NULL) { + _I("Same fota event has already set, key: %s, value: %s", + fota_event_keys[idx], fota_event_values[idx]); return -1; } - ret = common_client_controller_generate_req_data(key, value, &fota_req_stack[fota_req_top+1]); - if (ret < 0) { - _E("Failed to generate request data : %d", ret); + fota_event_values[idx] = strndup(value, strlen(value)); + if (fota_event_values[idx] == NULL) { + _E("Failed to strndup value (%s) : %m", value); return -1; } + _I("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"); + + free(fota_event_values[FOTA_EVENT_PLUG]); + free(fota_event_values[FOTA_EVENT_UNPLUG]); + + fota_event_values[FOTA_EVENT_PLUG] = NULL; + fota_event_values[FOTA_EVENT_UNPLUG] = NULL; + } - fota_req_top++; - _I("Success to add launch request, top : %d, key : %s, value : %s", - fota_req_top, fota_req_stack[fota_req_top].key, fota_req_stack[fota_req_top].value); - ret = fota_client_controller_process_launch_request(); + ret = fota_client_controller_process_event(); if (ret < 0) { - _E("Failed to process launch client : %d", ret); + _E("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 d2373c9..95cac72 100644 --- a/update-manager/fota/fota-client-info-checker.c +++ b/update-manager/fota/fota-client-info-checker.c @@ -17,10 +17,10 @@ int fota_client_info_checker_callback(pkgmgrinfo_appinfo_h handle, void *user_da return -1; } - _I("Success to find fota client id : %s", fota_client_app_id); - ret = fota_client_controller_process_launch_request(); + _I("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 launch fota client : %d", ret); + _E("Failed to process fota client event : %d", ret); return 0; } diff --git a/update-manager/fota/fota-storage-checker.c b/update-manager/fota/fota-storage-checker.c index 23ffdff..ab528a1 100644 --- a/update-manager/fota/fota-storage-checker.c +++ b/update-manager/fota/fota-storage-checker.c @@ -69,23 +69,24 @@ void fota_storage_checker_plug(int storage_id, const char *mount_path) ret = fota_storage_search_delta_path(mount_path, &delta_path); if (ret != 0) { _E("Failed to find delta path : %d", ret); - goto process_destroy; + goto plug_destroy; } ret = fota_controller_verify_delta(delta_path); if (ret != 0) { _E("Failed to verify delta : %d", ret); - goto process_destroy; + goto plug_destroy; } - ret = fota_client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_LOCAL_KEY, delta_path); + ret = fota_client_controller_add_event(FOTA_EVENT_PLUG, delta_path); if (ret < 0) { - _E("Failed to add launch request : %d, key : %s, value : %s", - ret, CLIENT_APP_CTRL_LOCAL_KEY, delta_path); + _E("Failed to add fota client event : %d, idx : %d, value : %s", + ret, FOTA_EVENT_PLUG, delta_path); + goto plug_destroy; } fota_storage_id = storage_id; -process_destroy: +plug_destroy: g_free(delta_path); } @@ -93,10 +94,10 @@ void fota_storage_checker_unplug(int storage_id, const char *mount_path) { int ret = 0; if (storage_id == fota_storage_id) { - ret = fota_client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_UNPLUG_KEY, mount_path); + ret = fota_client_controller_add_event(FOTA_EVENT_UNPLUG, mount_path); if (ret < 0) { - _E("Failed to add fota launch request : %d, key : %s, value : %s", - ret, CLIENT_APP_CTRL_UNPLUG_KEY, mount_path); + _E("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/recovery/recovery-client-controller.c b/update-manager/recovery/recovery-client-controller.c index 7dd9d01..6692202 100644 --- a/update-manager/recovery/recovery-client-controller.c +++ b/update-manager/recovery/recovery-client-controller.c @@ -1,67 +1,84 @@ #include "recovery-manager.h" #include "../update-manager.h" -static req_data recovery_req_stack[MAX_STACK_SIZE]; -static int recovery_req_top = -1; +static const char* recovery_event_keys[RECOVERY_EVENT_SIZE] = { + RECOVERY_CLIENT_APP_CTRL_PLUG_KEY, + RECOVERY_CLIENT_APP_CTRL_UNPLUG_KEY, +}; +static char *recovery_event_values[RECOVERY_EVENT_SIZE] = { + NULL, + NULL, +}; -int recovery_client_controller_process_launch_request() +int recovery_client_controller_process_event() { - int ret = 0; + int ret = 0, status = 0, idx = 0; char *appid = NULL; appid = recovery_client_info_get_appid(); if (appid == NULL) { - _RLOGI("Failed to launch client, recovery client app id not found, current top : %d", recovery_req_top); - return -1; + _RLOGI("Failed to launch recovery client, not found"); + return 1; } if (!common_boot_status_checker_is_success()) { - _RLOGI("Failed to launch client, user session is unset, current top : %d", recovery_req_top); - return -1; + _RLOGI("Failed to launch recovery client, user session is unset"); + return 2; } - while(recovery_req_top > -1) { - _RLOGI("Success to ready process launch recovery client, top : %d, key : %s, value : %s", - recovery_req_top, recovery_req_stack[recovery_req_top].key, recovery_req_stack[recovery_req_top].value); + for(idx = 0; idx < RECOVERY_EVENT_SIZE; ++idx) { + if (recovery_event_values[idx] != NULL) { + ret = common_client_controller_launch(appid, recovery_event_keys[idx], recovery_event_values[idx]); + if (ret < 0) { + _RLOGE("Failed to launch recovery client : %d, appid: %s, key : %s, value : %s", + ret, appid, recovery_event_keys[idx], recovery_event_values[idx]); + status = -1; + continue; + } - ret = common_client_controller_launch_req_data(appid, recovery_req_stack[recovery_req_top]); - if (ret < 0) { - _RLOGE("Common client controller failed at recovery"); - return -1; - } - - _RLOGI("Success to launch recovery client with, key : %s, value : %s", - recovery_req_stack[recovery_req_top].key, recovery_req_stack[recovery_req_top].value); + _RLOGI("Success to launch recovery client, appid: %s, key : %s, value : %s", + appid, recovery_event_keys[idx], recovery_event_values[idx]); - free(recovery_req_stack[recovery_req_top].key); - free(recovery_req_stack[recovery_req_top].value); - recovery_req_top--; + free(recovery_event_values[idx]); + recovery_event_values[idx] = NULL; + } } - return 0; + return status; } -int recovery_client_controller_add_launch_request_with_data(const char *key, const char *value) +int recovery_client_controller_add_event(recovery_event_idx idx, const char *value) { int ret = 0; - if (recovery_req_top == MAX_STACK_SIZE - 1) { - _RLOGE("Failed to add launch request, Current top : %d", recovery_req_top); + if (recovery_event_values[idx] != NULL) { + _RLOGE("Same recovery event has already set, key: %s, value: %s", + recovery_event_keys[idx], recovery_event_values[idx]); return -1; } - ret = common_client_controller_generate_req_data(key, value, &recovery_req_stack[recovery_req_top+1]); - if (ret < 0) { - _RLOGE("Failed to generate request data : %d", ret); + recovery_event_values[idx] = strndup(value, strlen(value)); + if (recovery_event_values[idx] == NULL) { + _RLOGE("Failed to strndup value (%s) : %m", value); return -1; } + _RLOGI("Success to set recovery client event, key: %s, value: %s", + recovery_event_keys[idx], recovery_event_values[idx]); + + if (recovery_event_values[RECOVERY_EVENT_PLUG] != NULL && + recovery_event_values[RECOVERY_EVENT_UNPLUG] != NULL) { + _RLOGI("Find plug/unplug event set at the same time, so remove them"); + + free(recovery_event_values[RECOVERY_EVENT_PLUG]); + free(recovery_event_values[RECOVERY_EVENT_UNPLUG]); + + recovery_event_values[RECOVERY_EVENT_PLUG] = NULL; + recovery_event_values[RECOVERY_EVENT_UNPLUG] = NULL; + } - recovery_req_top++; - _I("Success to add launch request, top : %d, key : %s, value : %s", - recovery_req_top, recovery_req_stack[recovery_req_top].key, recovery_req_stack[recovery_req_top].value); - ret = recovery_client_controller_process_launch_request(); + ret = recovery_client_controller_process_event(); if (ret < 0) { - _RLOGE("Failed to process launch client : %d", ret); + _RLOGE("Failed to process recovery event : %d", ret); return -1; } diff --git a/update-manager/recovery/recovery-client-info-checker.c b/update-manager/recovery/recovery-client-info-checker.c index 1b99e60..ad20541 100644 --- a/update-manager/recovery/recovery-client-info-checker.c +++ b/update-manager/recovery/recovery-client-info-checker.c @@ -18,10 +18,12 @@ int recovery_client_info_checker_callback(pkgmgrinfo_appinfo_h handle, void *use return -1; } - _RLOGI("Success to find recovery client id : %s", recovery_client_app_id); - ret = recovery_client_controller_process_launch_request(); - if (ret < 0) - _RLOGE("Failed to process launch recovery client : %d", ret); + _RLOGI("Success to find recovery client id : %s, try process recovery event", recovery_client_app_id); + ret = recovery_client_controller_process_event(); + if (ret < 0) { + _RLOGE("Failed to process recovery client event : %d", ret); + return -1; + } return 0; } @@ -33,7 +35,7 @@ int recovery_client_info_checker_init() ret = common_client_info_checker_filter(RECOVERY_CLIENT_METADATA_KEY, RECOVERY_CLIENT_METADATA_VALUE, recovery_client_info_checker_callback); if (ret < 0) { _RLOGE("Failed to set recovery client app filter : %d, key : %s, value : %s", - ret, RECOVERY_CLIENT_METADATA_KEY, RECOVERY_CLIENT_METADATA_KEY); + ret, RECOVERY_CLIENT_METADATA_KEY, RECOVERY_CLIENT_METADATA_VALUE); return -1; } diff --git a/update-manager/recovery/recovery-manager.h b/update-manager/recovery/recovery-manager.h index f3dca9b..8ba8ac3 100644 --- a/update-manager/recovery/recovery-manager.h +++ b/update-manager/recovery/recovery-manager.h @@ -19,9 +19,17 @@ #define RECOVERY_IMAGE_FILE "tizen-recovery.img" +#define RECOVERY_EVENT_SIZE 2 + +/* Enum */ +typedef enum { + RECOVERY_EVENT_PLUG = 0, + RECOVERY_EVENT_UNPLUG = 1 +} recovery_event_idx; + /* Function */ -int recovery_client_controller_process_launch_request(void); -int recovery_client_controller_add_launch_request_with_data(const char *, const char *); +int recovery_client_controller_process_event(void); +int recovery_client_controller_add_event(recovery_event_idx, const char *); int recovery_client_info_checker_init(void); int recovery_client_info_checker_fini(void); diff --git a/update-manager/recovery/recovery-storage-checker.c b/update-manager/recovery/recovery-storage-checker.c index 6b8f810..8aef617 100644 --- a/update-manager/recovery/recovery-storage-checker.c +++ b/update-manager/recovery/recovery-storage-checker.c @@ -28,12 +28,11 @@ void recovery_storage_checker_plug(int storage_id, const char *mount_path) goto plug_destroy; } - _RLOGD("Ready to trigger plug event, try to add launch request key : %s, value : %s", - RECOVERY_CLIENT_APP_CTRL_PLUG_KEY, image_path); - ret = recovery_client_controller_add_launch_request_with_data(RECOVERY_CLIENT_APP_CTRL_PLUG_KEY, image_path); + ret = recovery_client_controller_add_event(RECOVERY_EVENT_PLUG, image_path); if (ret < 0) { - _RLOGE("Failed to add launch request : %d, key : %s, value : %s", - ret, RECOVERY_CLIENT_APP_CTRL_PLUG_KEY, image_path); + _RLOGE("Failed to add recovery client event : %d, idx : %d, value : %s", + ret, RECOVERY_EVENT_PLUG, image_path); + goto plug_destroy; } recovery_storage_id = storage_id; @@ -46,12 +45,10 @@ void recovery_storage_checker_unplug(int storage_id, const char *mount_path) int ret = 0; if (storage_id == recovery_storage_id) { - _RLOGD("Ready to trigger unplug event, try to add launch request key : %s, value : %s", - RECOVERY_CLIENT_APP_CTRL_UNPLUG_KEY, mount_path); - ret = recovery_client_controller_add_launch_request_with_data(RECOVERY_CLIENT_APP_CTRL_UNPLUG_KEY, mount_path); + ret = recovery_client_controller_add_event(RECOVERY_EVENT_UNPLUG, mount_path); if (ret < 0) { - _RLOGE("Failed to add recovery launch request : %d, key : %s, value : %s", - ret, RECOVERY_CLIENT_APP_CTRL_UNPLUG_KEY, mount_path); + _RLOGE("Failed to add recovery client event : %d, idx : %d, value : %s", + ret, RECOVERY_EVENT_UNPLUG, mount_path); } recovery_storage_id = -1; } diff --git a/update-manager/update-manager.h b/update-manager/update-manager.h index f5973da..2392b0a 100644 --- a/update-manager/update-manager.h +++ b/update-manager/update-manager.h @@ -62,6 +62,8 @@ #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 @@ -73,19 +75,20 @@ #define SHARED_DIR "/opt/usr/home/owner/apps_rw" #define SHARED_DATA_DIR "shared/data" -/* Type */ -typedef struct _req_data { - char *key; - char *value; -} req_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_launch_request(void); -int fota_client_controller_add_launch_request_with_data(const char *, const char *); +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); @@ -94,13 +97,11 @@ int common_boot_status_checker_init(void); int common_boot_status_checker_fini(void); bool common_boot_status_checker_is_success(void); -int common_client_controller_launch_req_data(const char*, req_data); -int common_client_controller_generate_req_data(const char *, const char *, req_data *); +int common_client_controller_launch(const char*, const char *, const char *); int common_client_info_checker_get_appid(pkgmgrinfo_appinfo_h, char **); int common_client_info_checker_filter(const char*, const char*, pkgmgrinfo_app_list_cb); - int dbus_manager_init(void); int dbus_manager_fini(void);