Save fota result to fota status checker 56/237756/2
authorJeon Sang-Heon <sh95.jeon@samsung.com>
Fri, 3 Jul 2020 17:02:30 +0000 (17:02 +0000)
committerJeon Sang-Heon <sh95.jeon@samsung.com>
Mon, 6 Jul 2020 10:40:14 +0000 (10:40 +0000)
- To reuse fota upgrade result, save result to fota status checker

Change-Id: I54b856159d52e5b770973ec10ed146012617bd26
Signed-off-by: Jeon Sang-Heon <sh95.jeon@samsung.com>
update-manager/fota-status-checker.c
update-manager/main.c
update-manager/update-manager.h

index 8536739e618ab08c27caebda0920a4837dffc2db..7091ba5136041f0c2820a511497b34fb44008511 100644 (file)
@@ -1,25 +1,23 @@
 #include "update-manager.h"
 
-int fota_status_checker_init()
+static char *fota_result = NULL;
+
+char *fota_status_get_result()
+{
+       return fota_result;
+}
+
+int fota_status_checker_process()
 {
        int ret = 0;
-       char buf[MAX_BUFFER_SIZE] = {0,};
-       bool exist = false;
 
-       exist = g_file_test(STATUS_FLAG_PATH, G_FILE_TEST_EXISTS) && g_file_test(STATUS_RESULT_PATH, G_FILE_TEST_EXISTS);
-       if (exist) {
+       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 = util_file_read_line(STATUS_RESULT_PATH, buf);
-               if (ret < 0) {
-                       _E("Failed to read fota result : %d", ret);
-                       return -1;
-               }
-
-               ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_REBOOT_KEY, buf);
+               ret = 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, buf);
+                          ret, CLIENT_APP_CTRL_REBOOT_KEY, fota_result);
                        return -1;
                }
 
@@ -36,3 +34,45 @@ int fota_status_checker_init()
 
        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;
+}
\ No newline at end of file
index 61b0ee0c7d09f9b68ceedbc9a028001cf1f4d0e0..0d0fafd47e7a61aad97e56f6866f0567e10d80cd 100644 (file)
@@ -70,6 +70,10 @@ main_destroy:
        if (ret < 0)
                _W("Failed to finalize fota storage checker : %d", ret);
 
+       ret = fota_status_checker_fini();
+       if (ret < 0)
+               _E("Failed to finalize fota status checker : %d", ret);
+
        ret = fota_controller_fini();
        if (ret < 0)
                _W("Failed to finalize fota controller : %d", ret);
index c0ac2a2db07416ac4edf4bc190bce417de909bc1..d99b6acd5892e3354b5c0e7026326e1939e3c1e8 100644 (file)
@@ -93,6 +93,8 @@ int fota_storage_checker_init(void);
 int fota_storage_checker_fini(void);
 
 int fota_status_checker_init(void);
+int fota_status_checker_fini(void);
+char *fota_status_get_result(void);
 
 int fota_controller_init(void);
 int fota_controller_fini(void);