Refactor sticker-receiver code 44/240844/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Wed, 12 Aug 2020 05:28:30 +0000 (14:28 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Wed, 12 Aug 2020 05:28:30 +0000 (14:28 +0900)
Change-Id: I792ee0ddafc74b9de4773f6ced7aa37ec8840d5c
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
receiver/src/main.cpp

index 06c2c4f..aa196e1 100644 (file)
@@ -198,6 +198,53 @@ cleanup:
         free(type);
 }
 
+static void process_auto_sync()
+{
+    if (is_init_sap()) {
+        STLOGD("continue doing current job");
+        return;
+    }
+
+    if (check_sync_time_condition()) {
+        if (check_battery_condition()) {
+            STLOGD("Starting auto synchronization");
+            initialize_sap();
+            request_sticker_feature();
+            request_auto_sync();
+        }
+        else {
+            STLOGI("The status of battery is low");
+            if (!get_job_progress()) {
+                STLOGD("exit");
+                service_app_exit();
+            }
+        }
+    }
+    else {
+        if (!get_job_progress()) {
+            STLOGD("exit");
+            service_app_exit();
+        }
+    }
+}
+
+static void get_sticker_feature()
+{
+#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE
+    // Check whether oobe has been done
+    int feature_flag = 0;
+    if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0 && feature_flag == 0) {
+        STLOGD("Request to get sticker feature");
+        initialize_sap();
+        request_sticker_feature();
+    }
+    else {
+        if (!is_init_sap())
+            service_app_exit();
+    }
+#endif
+}
+
 static void app_control(app_control_h app_control, void *data)
 {
     /* Handle the launch request. */
@@ -213,85 +260,48 @@ static void app_control(app_control_h app_control, void *data)
 
     // operation
     int ret = app_control_get_operation(app_control, &operation);
-    if (ret == APP_CONTROL_ERROR_NONE) {
-        STLOGD("operation: %s", operation);
+    if (ret != APP_CONTROL_ERROR_NONE) {
+        STLOGW("Failed to get operation. error : %d", ret);
+        return;
+    }
 
-        if (!operation) {
-            goto cleanup;
-        }
+    STLOGD("operation: %s", operation);
 
-        if (strcmp(operation, APP_CONTROL_OPERATION_LAUNCH_ON_EVENT) == 0)
+    if (!operation) {
+        goto cleanup;
+    }
+
+    if (strcmp(operation, APP_CONTROL_OPERATION_LAUNCH_ON_EVENT) == 0)
+    {
+        ret = app_control_get_uri(app_control, &uri);
+        if (ret == APP_CONTROL_ERROR_NONE && uri)
         {
-            ret = app_control_get_uri(app_control, &uri);
-            if (ret == APP_CONTROL_ERROR_NONE && uri)
+            if (strncmp(uri, event_uri, strlen(event_uri) + 1) == 0)
             {
-                if (strncmp(uri, event_uri, strlen(event_uri) + 1) == 0)
+                ret = app_control_get_extra_data(app_control, "battery_charger_status", &event_value);
+                if (ret == APP_CONTROL_ERROR_NONE && event_value)
                 {
-                    ret = app_control_get_extra_data(app_control, "battery_charger_status", &event_value);
-                    if (ret == APP_CONTROL_ERROR_NONE && event_value)
+                    if (string(event_value) == "connected")
                     {
-                        if (string(event_value) == "connected")
-                        {
-                            STLOGI("The charger state is connected");
-                            if (!is_init_sap()) {
-                                if (check_sync_time_condition()) {
-                                    if (check_battery_condition()) {
-                                        STLOGD("Starting auto synchronization");
-                                        initialize_sap();
-                                        request_sticker_feature();
-                                        request_auto_sync();
-                                    }
-                                    else {
-                                        STLOGI("The status of battery is low");
-                                        if (!get_job_progress()) {
-                                            STLOGD("exit");
-                                            service_app_exit();
-                                        }
-                                    }
-                                }
-                                else {
-                                    if (!get_job_progress()) {
-                                        STLOGD("exit");
-                                        service_app_exit();
-                                    }
-                                }
-                            }
-                            else {
-                                STLOGD("continue doing current job");
-                            }
-                        }
-                        free(event_value);
+                        STLOGI("The charger state is connected");
+                        process_auto_sync();
                     }
+                    free(event_value);
                 }
-                free(uri);
             }
-        }
-        else if (strcmp(operation, APP_CONTROL_OPERATION_DEFAULT) == 0) {
-            res = app_control_get_extra_data(app_control, "request", &request);
-            STLOGD("get extra data result : %d, request : %s", res, request);
-            if (APP_CONTROL_ERROR_NONE == res && NULL != request) {
-                process_request(app_control, request);
-            }
-            else {
-                STLOGD("booting");
-#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE
-                // Check whether oobe has been done
-                int feature_flag = 0;
-                if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0 && feature_flag == 0) {
-                    STLOGD("Request to get sticker feature");
-                    initialize_sap();
-                    request_sticker_feature();
-                }
-                else {
-                    if (!is_init_sap())
-                        service_app_exit();
-                }
-            }
-#endif
+            free(uri);
         }
     }
-    else {
-        STLOGW("Failed to get operation. error : %d", ret);
+    else if (strcmp(operation, APP_CONTROL_OPERATION_DEFAULT) == 0) {
+        res = app_control_get_extra_data(app_control, "request", &request);
+        STLOGD("get extra data result : %d, request : %s", res, request);
+        if (APP_CONTROL_ERROR_NONE == res && NULL != request) {
+            process_request(app_control, request);
+        }
+        else {
+            STLOGD("booting");
+            get_sticker_feature();
+        }
     }
 
 cleanup: