Add recovery client controller 14/239814/11
authorJeon Sang-Heon <sh95.jeon@samsung.com>
Tue, 28 Jul 2020 18:47:47 +0000 (18:47 +0000)
committerJeon Sang-Heon <sh95.jeon@samsung.com>
Fri, 7 Aug 2020 17:25:03 +0000 (17:25 +0000)
- 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 <sh95.jeon@samsung.com>
13 files changed:
update-manager/client-controller.c [deleted file]
update-manager/common/common-client-controller.c [new file with mode: 0644]
update-manager/common/common-client-info-checker.c
update-manager/common/common-client-status-checker.c
update-manager/fota-status-checker.c
update-manager/fota/fota-client-controller.c [new file with mode: 0644]
update-manager/fota/fota-client-info-checker.c
update-manager/fota/fota-storage-checker.c
update-manager/recovery/recovery-client-controller.c [new file with mode: 0644]
update-manager/recovery/recovery-client-info-checker.c
update-manager/recovery/recovery-manager.h
update-manager/recovery/recovery-storage-checker.c
update-manager/update-manager.h

diff --git a/update-manager/client-controller.c b/update-manager/client-controller.c
deleted file mode 100644 (file)
index 355e659..0000000
+++ /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 (file)
index 0000000..ad4dab4
--- /dev/null
@@ -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;
+}
index 3eb2c460db93b7ce37b58670fac963e1fdb8db49..0c04fb38d8752e36b44ef5570e403e7bb92055b1 100644 (file)
@@ -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);
index 19bb02238a84e541199b5aa7c28adc78ac480185..dc5d1ea81aeec32ebaffbe208e6e2a1e4f9e1714 100644 (file)
@@ -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);
index 00453348b25984814b610eba559193964d278581..48b51947dc13734a013061b30f5b68d5deb5f43c 100644 (file)
@@ -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 (file)
index 0000000..2f9b745
--- /dev/null
@@ -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
index ec5974647a6d95b3823f7186c3dcd5e0c9778b22..443781f81e2a6b218426136ec3139623f4b64a85 100644 (file)
@@ -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;
 }
 
index 744ddb8d4b5ff93a9b3e782ea7666f7383231245..23ffdff3505f5942bc9ae79d34b50c2c0261025b 100644 (file)
@@ -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 (file)
index 0000000..6121e6d
--- /dev/null
@@ -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
index 273a3b65d4cde9c3dbc87620289bacdb95a16e66..e8868043f989e8176801e66bed4b87793541aafc 100644 (file)
@@ -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;
 }
 
index 7958105a80a656d5673b56531ed92ed1ec2c47ad..f3dca9b97f3679428ba06130b4c050e0617a30a4 100644 (file)
 /* 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);
index f316446db5251d60254ea384ce0a94e850b77ca8..868726470e0f1974a9d8f37ea88708afa301673e 100644 (file)
@@ -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;
 }
index dccebd2d119c00904dce75d07bb54d89020bf095..5fb8d1f6c03148915ef40412da821581c0fc95e1 100644 (file)
 #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);