From f1c89a691e60f6a7532ffacd78b866c2662b0ee8 Mon Sep 17 00:00:00 2001 From: Jeon Sang-Heon Date: Tue, 28 Jul 2020 18:47:47 +0000 Subject: [PATCH] Add recovery client controller - Move old client controller to common - Add recovery client controller and fota info controller - Plug event : key[recovery-plug] value[image path] - Unplug event : key[recovery-unplug] value[mount path] Change-Id: I587d33059474b91455b1ba9d6e5196e115aa61c9 Signed-off-by: Jeon Sang-Heon --- update-manager/client-controller.c | 120 ------------------ .../common/common-client-controller.c | 67 ++++++++++ .../common/common-client-info-checker.c | 5 - .../common/common-client-status-checker.c | 9 +- update-manager/fota-status-checker.c | 2 +- update-manager/fota/fota-client-controller.c | 68 ++++++++++ .../fota/fota-client-info-checker.c | 7 +- update-manager/fota/fota-storage-checker.c | 6 +- .../recovery/recovery-client-controller.c | 69 ++++++++++ .../recovery/recovery-client-info-checker.c | 5 + update-manager/recovery/recovery-manager.h | 5 + .../recovery/recovery-storage-checker.c | 17 +++ update-manager/update-manager.h | 19 ++- 13 files changed, 262 insertions(+), 137 deletions(-) delete mode 100644 update-manager/client-controller.c create mode 100644 update-manager/common/common-client-controller.c create mode 100644 update-manager/fota/fota-client-controller.c create mode 100644 update-manager/recovery/recovery-client-controller.c diff --git a/update-manager/client-controller.c b/update-manager/client-controller.c deleted file mode 100644 index 355e659..0000000 --- a/update-manager/client-controller.c +++ /dev/null @@ -1,120 +0,0 @@ -#include "update-manager.h" - -typedef struct _request_data { - char *key; - char *value; -} request_data; -static request_data request_stack[MAX_STACK_SIZE]; -static int top = -1; - -int client_controller_process_launch_request() -{ - int ret = 0, status = 0; - char *appid = NULL; - bundle *bundle_data = NULL; - - appid = fota_client_info_get_appid(); - if (appid == NULL) { - _I("Failed to launch client, client app id not found, current top : %d", top); - goto request_destroy; - } - - if (!common_client_status_checker_is_success()) { - _I("Failed to launch client, user session is unset, current top : %d", top); - goto request_destroy; - } - - while (top > -1) { - _I("Success to ready process launch client, top : %d, key : %s, value : %s", - top, request_stack[top].key, request_stack[top].value); - - bundle_data = bundle_create(); - if (bundle_data == NULL) { - _E("bundle_create failed"); - status = -1; - goto request_destroy; - } - - ret = aul_svc_set_operation(bundle_data, AUL_SVC_OPERATION_DEFAULT); - if (ret != AUL_R_OK) { - _E("aul_svc_set_operation failed : %d", ret); - status = -1; - goto request_destroy; - } - - ret = aul_svc_add_data(bundle_data, request_stack[top].key, request_stack[top].value); - if (ret != AUL_R_OK) { - _E("aul_svc_add_data failed : %d", ret); - status = -1; - goto request_destroy; - } - - ret = aul_launch_app_for_uid(appid, bundle_data, OWNER_UID); - if (ret < AUL_R_OK) { - _E("aul_launch_app_for_uid failed : %d", ret); - status = -1; - goto request_destroy; - } - - _I("Success to launch client with, key : %s, value : %s", - request_stack[top].key, request_stack[top].value); - - ret = bundle_free(bundle_data); - if (ret != BUNDLE_ERROR_NONE) - _W("bundle_free failed : %d", ret); - bundle_data = NULL; - - free(request_stack[top].key); - free(request_stack[top].value); - top--; - } - -request_destroy: - if (bundle_data) { - ret = bundle_free(bundle_data); - if (ret != BUNDLE_ERROR_NONE) - _W("bundle_free failed : %d", ret); - } - - return status; -} - -int client_controller_add_launch_request_with_data(const char *key, const char *value) -{ - int ret = 0; - char *mem = NULL; - - if (top == MAX_STACK_SIZE - 1) { - _E("Failed to add launch request, Current top : %d", top); - return -1; - } - - mem = strndup(key, strlen(key)); - if (mem == NULL) { - _E("Failed to strndup key (%s) : %m", key); - return -1; - } - top++; - request_stack[top].key = mem; - - mem = strndup(value, strlen(value)); - if (mem == NULL) { - _E("Failed to strndup value (%s) : %m", value); - - /* Rollback */ - free(request_stack[top].key); - top--; - return -1; - } - request_stack[top].value = mem; - - _I("Success to add launch request, top : %d, key : %s, value : %s", - top, request_stack[top].key, request_stack[top].value); - ret = client_controller_process_launch_request(); - if (ret < 0) { - _E("Failed to process launch client : %d", ret); - return -1; - } - - return 0; -} diff --git a/update-manager/common/common-client-controller.c b/update-manager/common/common-client-controller.c new file mode 100644 index 0000000..ad4dab4 --- /dev/null +++ b/update-manager/common/common-client-controller.c @@ -0,0 +1,67 @@ +#include "../update-manager.h" + +int common_client_controller_launch_req_data(const char* appid, req_data data) +{ + int ret = 0, status = 0; + bundle *bundle_data = NULL; + + bundle_data = bundle_create(); + if (bundle_data == NULL) { + _E("bundle_create failed"); + status = -1; + goto launch_destroy; + } + + ret = aul_svc_set_operation(bundle_data, AUL_SVC_OPERATION_DEFAULT); + if (ret != AUL_R_OK) { + _E("aul_svc_set_operation failed : %d", ret); + status = -1; + goto launch_destroy; + } + + ret = aul_svc_add_data(bundle_data, data.key, data.value); + if (ret != AUL_R_OK) { + _E("aul_svc_add_data failed : %d", ret); + status = -1; + goto launch_destroy; + } + + ret = aul_launch_app_for_uid(appid, bundle_data, OWNER_UID); + if (ret < AUL_R_OK) { + _E("aul_launch_app_for_uid failed : %d", ret); + status = -1; + } + +launch_destroy: + if (bundle_data) { + ret = bundle_free(bundle_data); + if (ret != BUNDLE_ERROR_NONE) + _W("bundle_free failed : %d", ret); + } + + 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/common/common-client-info-checker.c b/update-manager/common/common-client-info-checker.c index 3eb2c46..0c04fb3 100644 --- a/update-manager/common/common-client-info-checker.c +++ b/update-manager/common/common-client-info-checker.c @@ -38,11 +38,6 @@ int common_client_info_checker_callback(pkgmgrinfo_appinfo_h handle, char **app_ goto callback_destroy; } - _I("Success to find client id : %s", *app_id); - ret = client_controller_process_launch_request(); - if (ret < 0) - _E("Failed to process launch fota_client : %d", ret); - callback_destroy: if (appinfo_h) { ret = pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h); diff --git a/update-manager/common/common-client-status-checker.c b/update-manager/common/common-client-status-checker.c index 19bb022..dc5d1ea 100644 --- a/update-manager/common/common-client-status-checker.c +++ b/update-manager/common/common-client-status-checker.c @@ -1,3 +1,4 @@ +#include "../recovery/recovery-manager.h" #include "../update-manager.h" static int boot_status = -1; @@ -23,9 +24,13 @@ void common_client_status_checker_callback(keynode_t *node, void *user_data) else _W("vconf_ignore_key_changed for %s failed : %d", VCONFKEY_SYSMAN_BOOTINGSTATUS, ret); - ret = client_controller_process_launch_request(); + ret = fota_client_controller_process_launch_request(); if (ret < 0) - _E("Failed to process launch client : %d", ret); + _E("Failed to process fota client : %d", ret); + + ret = recovery_client_controller_process_launch_request(); + if (ret < 0) + _E("Failed to process recovery client : %d", ret); } } else { _E("Invalid vconf key type : %d", ret); diff --git a/update-manager/fota-status-checker.c b/update-manager/fota-status-checker.c index 0045334..48b5194 100644 --- a/update-manager/fota-status-checker.c +++ b/update-manager/fota-status-checker.c @@ -14,7 +14,7 @@ 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 = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_REBOOT_KEY, fota_result); + ret = fota_client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_REBOOT_KEY, fota_result); if (ret < 0) { _E("Failed to add launch request : %d, key : %s, value : %s", ret, CLIENT_APP_CTRL_REBOOT_KEY, fota_result); diff --git a/update-manager/fota/fota-client-controller.c b/update-manager/fota/fota-client-controller.c new file mode 100644 index 0000000..2f9b745 --- /dev/null +++ b/update-manager/fota/fota-client-controller.c @@ -0,0 +1,68 @@ +#include "../update-manager.h" + +static req_data fota_req_stack[MAX_STACK_SIZE]; +static int fota_req_top = -1; + +int fota_client_controller_process_launch_request() +{ + int ret = 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; + } + + if (!common_client_status_checker_is_success()) { + _I("Failed to launch client, user session is unset, current top : %d", fota_req_top); + return -1; + } + + 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); + + 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); + + free(fota_req_stack[fota_req_top].key); + free(fota_req_stack[fota_req_top].value); + fota_req_top--; + } + + return 0; +} + +int fota_client_controller_add_launch_request_with_data(const char *key, 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); + 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); + return -1; + } + + 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(); + if (ret < 0) { + _E("Failed to process launch client : %d", ret); + return -1; + } + + return 0; +} \ No newline at end of file diff --git a/update-manager/fota/fota-client-info-checker.c b/update-manager/fota/fota-client-info-checker.c index ec59746..443781f 100644 --- a/update-manager/fota/fota-client-info-checker.c +++ b/update-manager/fota/fota-client-info-checker.c @@ -13,10 +13,15 @@ int fota_client_info_checker_callback(pkgmgrinfo_appinfo_h handle, void *user_da ret = common_client_info_checker_callback(handle, &fota_client_app_id); if (ret < 0) { - _E("Common client info checker callback failed at recovery"); + _E("Common client info checker callback failed at fota"); return -1; } + _I("Success to find fota client id : %s", fota_client_app_id); + ret = fota_client_controller_process_launch_request(); + if (ret < 0) + _E("Failed to process launch fota client : %d", ret); + return 0; } diff --git a/update-manager/fota/fota-storage-checker.c b/update-manager/fota/fota-storage-checker.c index 744ddb8..23ffdff 100644 --- a/update-manager/fota/fota-storage-checker.c +++ b/update-manager/fota/fota-storage-checker.c @@ -78,7 +78,7 @@ void fota_storage_checker_plug(int storage_id, const char *mount_path) goto process_destroy; } - ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_LOCAL_KEY, delta_path); + ret = fota_client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_LOCAL_KEY, delta_path); if (ret < 0) { _E("Failed to add launch request : %d, key : %s, value : %s", ret, CLIENT_APP_CTRL_LOCAL_KEY, delta_path); @@ -93,9 +93,9 @@ void fota_storage_checker_unplug(int storage_id, const char *mount_path) { int ret = 0; if (storage_id == fota_storage_id) { - ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_UNPLUG_KEY, mount_path); + ret = fota_client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_UNPLUG_KEY, mount_path); if (ret < 0) { - _E("Failed to add launch request : %d, key : %s, value : %s", + _E("Failed to add fota launch request : %d, key : %s, value : %s", ret, CLIENT_APP_CTRL_UNPLUG_KEY, mount_path); } fota_storage_id = -1; diff --git a/update-manager/recovery/recovery-client-controller.c b/update-manager/recovery/recovery-client-controller.c new file mode 100644 index 0000000..6121e6d --- /dev/null +++ b/update-manager/recovery/recovery-client-controller.c @@ -0,0 +1,69 @@ +#include "recovery-manager.h" +#include "../update-manager.h" + +static req_data recovery_req_stack[MAX_STACK_SIZE]; +static int recovery_req_top = -1; + +int recovery_client_controller_process_launch_request() +{ + int ret = 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; + } + + if (!common_client_status_checker_is_success()) { + _RLOGI("Failed to launch client, user session is unset, current top : %d", recovery_req_top); + return -1; + } + + 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); + + 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); + + free(recovery_req_stack[recovery_req_top].key); + free(recovery_req_stack[recovery_req_top].value); + recovery_req_top--; + } + + return 0; +} + +int recovery_client_controller_add_launch_request_with_data(const char *key, 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); + 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); + return -1; + } + + 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(); + if (ret < 0) { + _RLOGE("Failed to process launch client : %d", ret); + return -1; + } + + return 0; +} \ No newline at end of file diff --git a/update-manager/recovery/recovery-client-info-checker.c b/update-manager/recovery/recovery-client-info-checker.c index 273a3b6..e886804 100644 --- a/update-manager/recovery/recovery-client-info-checker.c +++ b/update-manager/recovery/recovery-client-info-checker.c @@ -18,6 +18,11 @@ int recovery_client_info_checker_callback(pkgmgrinfo_appinfo_h handle, void *use return -1; } + _I("Success to find recovery client id : %s", recovery_client_app_id); + ret = recovery_client_controller_process_launch_request(); + if (ret < 0) + _E("Failed to process launch recovery client : %d", ret); + return 0; } diff --git a/update-manager/recovery/recovery-manager.h b/update-manager/recovery/recovery-manager.h index 7958105..f3dca9b 100644 --- a/update-manager/recovery/recovery-manager.h +++ b/update-manager/recovery/recovery-manager.h @@ -14,10 +14,15 @@ /* Constant */ #define RECOVERY_CLIENT_METADATA_KEY "tizen-recovery-manager" #define RECOVERY_CLIENT_METADATA_VALUE "client" +#define RECOVERY_CLIENT_APP_CTRL_PLUG_KEY "recovery-plug" +#define RECOVERY_CLIENT_APP_CTRL_UNPLUG_KEY "recovery-unplug" #define RECOVERY_IMAGE_FILE "tizen-recovery.img" /* 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_info_checker_init(void); int recovery_client_info_checker_fini(void); char *recovery_client_info_get_appid(void); diff --git a/update-manager/recovery/recovery-storage-checker.c b/update-manager/recovery/recovery-storage-checker.c index f316446..8687264 100644 --- a/update-manager/recovery/recovery-storage-checker.c +++ b/update-manager/recovery/recovery-storage-checker.c @@ -28,11 +28,28 @@ void recovery_storage_checker_plug(int storage_id, const char *mount_path) goto plug_destroy; } + ret = recovery_client_controller_add_launch_request_with_data(RECOVERY_CLIENT_APP_CTRL_PLUG_KEY, 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); + } + recovery_storage_id = storage_id; + plug_destroy: g_free(image_path); } void recovery_storage_checker_unplug(int storage_id, const char *mount_path) { + int ret = 0; + + if (storage_id == recovery_storage_id) { + ret = recovery_client_controller_add_launch_request_with_data(RECOVERY_CLIENT_APP_CTRL_UNPLUG_KEY, 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); + } + recovery_storage_id = -1; + } recovery_storage_id = -1; } diff --git a/update-manager/update-manager.h b/update-manager/update-manager.h index dccebd2..5fb8d1f 100644 --- a/update-manager/update-manager.h +++ b/update-manager/update-manager.h @@ -73,24 +73,33 @@ #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; + /* Function */ int fota_client_info_checker_init(void); int fota_client_info_checker_fini(void); char *fota_client_info_get_appid(void); -int client_controller_process_launch_request(void); -int client_controller_add_launch_request_with_data(const char *, const char *); +int fota_client_controller_process_launch_request(void); +int fota_client_controller_add_launch_request_with_data(const char *, const char *); int common_storage_checker_init(void); int common_storage_checker_fini(void); -int common_client_status_checker_init(void); -int common_client_status_checker_fini(void); -bool common_client_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_info_checker_callback(pkgmgrinfo_appinfo_h, char **); int common_client_info_checker_init(const char*, const char*, pkgmgrinfo_app_list_cb); +int common_client_status_checker_init(void); +int common_client_status_checker_fini(void); +bool common_client_status_checker_is_success(void); + int dbus_manager_init(void); int dbus_manager_fini(void); -- 2.34.1