Check battery charging status for sync condition 01/228301/7
authorJihoon Kim <jihoon48.kim@samsung.com>
Fri, 20 Mar 2020 06:36:15 +0000 (15:36 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Fri, 20 Mar 2020 07:34:48 +0000 (16:34 +0900)
Change-Id: I07450a60edef785e197bac03f85d3f13855465b8
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
receiver/src/main.cpp

index 9968b91..7a5e20d 100644 (file)
@@ -48,6 +48,8 @@ static void app_control(app_control_h app_control, void *data)
     char* alarm_data = NULL;
 
     int res;
+    int battery_percentage = 0;
+    bool battery_charging = false;
 
     // operation
     int ret = app_control_get_operation(app_control, &operation);
@@ -63,20 +65,30 @@ static void app_control(app_control_h app_control, void *data)
 
             LOGD("alarm data : %s", alarm_data);
 
-            int battery_percentage = 0;
-            int ret = device_battery_get_percent(&battery_percentage);
-            if (ret == DEVICE_ERROR_NONE) {
-                LOGD("battery percent : %d", battery_percentage);
-                if (battery_percentage >= MINIMUM_BATTERY) {
-                    request_sticker_data("auto", "arsticker", "input");
-                    request_sticker_data("auto", "bitmoji", "input");
-                }
-                else {
-                    LOGD("No sync request due to insufficient battery");
-                }
+            int ret = device_battery_is_charging(&battery_charging);
+            if (ret != DEVICE_ERROR_NONE) {
+                LOGW("No sync. Can't get battery charging status");
+                goto cleanup;
+            }
+
+            if (!battery_charging) {
+                LOGI("No sync due to no battery charging status");
+                goto cleanup;
+            }
+
+            ret = device_battery_get_percent(&battery_percentage);
+            if (ret != DEVICE_ERROR_NONE) {
+                LOGW("No sync. Failed to get battery percent. error : %d", ret);
+                goto cleanup;
+            }
+
+            LOGI("battery percent : %d", battery_percentage);
+            if (battery_percentage >= MINIMUM_BATTERY) {
+                request_sticker_data("auto", "arsticker", "input");
+                request_sticker_data("auto", "bitmoji", "input");
             }
             else {
-               LOGW("Failed to get battery percent. error : %d", ret);
+                LOGI("No sync due to insufficient battery");
             }
 
             goto cleanup;