1 #include <app_common.h>
2 #include <service_app.h>
5 #include <device/battery.h>
10 #include "sync_alarm.h"
12 #define MINIMUM_BATTERY 15
14 static bool app_create(void *data)
16 /* Hook to take necessary actions before main event loop starts
17 Initialize UI resources and application's data
18 If this function returns true, the main loop of application starts
19 If this function returns false, the application is terminated */
26 static void app_control(app_control_h app_control, void *data)
28 /* Handle the launch request. */
31 char* category = NULL;
33 char* operation = NULL;
34 char* alarm_data = NULL;
39 int ret = app_control_get_operation(app_control, &operation);
40 if (ret == APP_CONTROL_ERROR_NONE) {
41 LOGD("operation: %s", operation);
43 if (operation && (strncmp(operation, APP_CONTROL_OPERATION_SYNC_ALARM, strlen(APP_CONTROL_OPERATION_SYNC_ALARM)) == 0)) {
44 ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_ALARM_ID, &alarm_data);
45 if (ret != APP_CONTROL_ERROR_NONE) {
46 dlog_print(DLOG_ERROR, LOG_TAG, "Function app_control_get_extra_data() failed.");
50 LOGD("alarm data : %s", alarm_data);
52 int battery_percentage = 0;
53 int ret = device_battery_get_percent(&battery_percentage);
54 if (ret == DEVICE_ERROR_NONE) {
55 LOGD("battery percent : %d", battery_percentage);
56 if (battery_percentage >= MINIMUM_BATTERY) {
57 request_sticker_data("auto", "arsticker", "input");
58 request_sticker_data("auto", "bitmoji", "input");
61 LOGD("No sync request due to insufficient battery");
65 LOGW("Failed to get battery percent. error : %d", ret);
72 LOGW("Failed to get operation. error : %d", ret);
76 res = app_control_get_extra_data(app_control, "request", &request);
77 if (APP_CONTROL_ERROR_NONE == res && NULL != request) {
78 if (strcmp(request, "sync") == 0) {
79 bool param_error = false;
80 if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE) {
81 LOGE("No given mode");
85 if (app_control_get_extra_data(app_control, "category", &category) != APP_CONTROL_ERROR_NONE) {
86 LOGE("No given category");
90 if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE) {
91 LOGE("No given type");
95 LOGI("[sync request] mode : %s, category : %s, type : %s", mode, category, type);
99 if (mode && category && type)
100 request_sticker_data(mode, category, type);
104 LOGW("Unknown command : %s", request);
109 if (NULL != operation)
118 if (NULL != category)
125 static void app_terminate(void *data)
127 /* Release all resources. */
131 int main(int argc, char *argv[])
135 service_app_lifecycle_callback_s event_callback;
136 memset(&event_callback, 0x0, sizeof(service_app_lifecycle_callback_s));
138 event_callback.create = (service_app_create_cb)app_create;
139 event_callback.terminate = (service_app_terminate_cb)app_terminate;
140 event_callback.app_control = (service_app_control_cb)app_control;
142 ret = service_app_main(argc, argv, &event_callback, NULL);
143 if (ret != APP_ERROR_NONE) {
144 LOGE("app_main() is failed. err = %d", ret);