2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include <app_common.h>
17 #include <service_app.h>
19 #include <app_alarm.h>
20 #include <device/battery.h>
25 #include "sync_alarm.h"
27 #define MINIMUM_BATTERY 15
29 static bool app_create(void *data)
31 /* Hook to take necessary actions before main event loop starts
32 Initialize UI resources and application's data
33 If this function returns true, the main loop of application starts
34 If this function returns false, the application is terminated */
41 static void app_control(app_control_h app_control, void *data)
43 /* Handle the launch request. */
47 char* operation = NULL;
48 char* alarm_data = NULL;
53 int ret = app_control_get_operation(app_control, &operation);
54 if (ret == APP_CONTROL_ERROR_NONE) {
55 LOGD("operation: %s", operation);
57 if (operation && (strncmp(operation, APP_CONTROL_OPERATION_SYNC_ALARM, strlen(APP_CONTROL_OPERATION_SYNC_ALARM)) == 0)) {
58 ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_ALARM_ID, &alarm_data);
59 if (ret != APP_CONTROL_ERROR_NONE) {
60 dlog_print(DLOG_ERROR, LOG_TAG, "Function app_control_get_extra_data() failed.");
64 LOGD("alarm data : %s", alarm_data);
66 int battery_percentage = 0;
67 int ret = device_battery_get_percent(&battery_percentage);
68 if (ret == DEVICE_ERROR_NONE) {
69 LOGD("battery percent : %d", battery_percentage);
70 if (battery_percentage >= MINIMUM_BATTERY) {
71 request_sticker_data("auto", "arsticker", "input");
72 request_sticker_data("auto", "bitmoji", "input");
75 LOGD("No sync request due to insufficient battery");
79 LOGW("Failed to get battery percent. error : %d", ret);
86 LOGW("Failed to get operation. error : %d", ret);
90 res = app_control_get_extra_data(app_control, "request", &request);
91 if (APP_CONTROL_ERROR_NONE == res && NULL != request) {
92 if (strcmp(request, "sync") == 0) {
93 bool param_error = false;
94 if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE) {
95 LOGE("No given mode");
99 if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE) {
100 LOGE("No given type");
104 LOGI("[sync request] mode : %s, type : %s", mode, type);
109 request_sticker_data(mode, "arsticker", type);
111 else if (strcmp(request, "oobe") == 0) {
112 LOGI("[OOBE] register sync alarm");
113 sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL);
114 request_sticker_feature();
118 LOGW("Unknown command : %s", request);
123 if (NULL != operation)
136 static void app_terminate(void *data)
138 /* Release all resources. */
142 int main(int argc, char *argv[])
146 service_app_lifecycle_callback_s event_callback;
147 memset(&event_callback, 0x0, sizeof(service_app_lifecycle_callback_s));
149 event_callback.create = (service_app_create_cb)app_create;
150 event_callback.terminate = (service_app_terminate_cb)app_terminate;
151 event_callback.app_control = (service_app_control_cb)app_control;
153 ret = service_app_main(argc, argv, &event_callback, NULL);
154 if (ret != APP_ERROR_NONE) {
155 LOGE("app_main() is failed. err = %d", ret);