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.
17 #include <app_common.h>
18 #include <service_app.h>
20 #include <app_alarm.h>
21 #include <device/battery.h>
28 #include "sync_alarm.h"
30 static bool app_create(void *data)
32 /* Hook to take necessary actions before main event loop starts
33 Initialize UI resources and application's data
34 If this function returns true, the main loop of application starts
35 If this function returns false, the application is terminated */
42 static void app_control(app_control_h app_control, void *data)
44 /* Handle the launch request. */
48 char* operation = NULL;
49 char* alarm_data = NULL;
52 int battery_percentage = 0;
53 bool battery_charging = false;
56 int ret = app_control_get_operation(app_control, &operation);
57 if (ret == APP_CONTROL_ERROR_NONE) {
58 LOGD("operation: %s", operation);
60 if (operation && (strncmp(operation, APP_CONTROL_OPERATION_SYNC_ALARM, strlen(APP_CONTROL_OPERATION_SYNC_ALARM)) == 0)) {
61 ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_ALARM_ID, &alarm_data);
62 if (ret != APP_CONTROL_ERROR_NONE) {
63 dlog_print(DLOG_ERROR, LOG_TAG, "Function app_control_get_extra_data() failed.");
67 LOGD("alarm data : %s", alarm_data);
69 int ret = device_battery_is_charging(&battery_charging);
70 if (ret != DEVICE_ERROR_NONE) {
71 LOGW("No sync. Can't get battery charging status");
75 if (!battery_charging) {
76 LOGI("No sync due to no battery charging status");
80 ret = device_battery_get_percent(&battery_percentage);
81 if (ret != DEVICE_ERROR_NONE) {
82 LOGW("No sync. Failed to get battery percent. error : %d", ret);
86 LOGI("battery percent : %d", battery_percentage);
87 if (battery_percentage >= MINIMUM_BATTERY) {
88 request_sticker_data("auto", "arsticker", "input");
89 request_sticker_data("auto", "bitmoji", "input");
92 LOGI("No sync due to insufficient battery");
99 LOGW("Failed to get operation. error : %d", ret);
103 res = app_control_get_extra_data(app_control, "request", &request);
104 if (APP_CONTROL_ERROR_NONE == res && NULL != request) {
105 if (strcmp(request, "sync") == 0) {
106 bool param_error = false;
107 if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE) {
108 LOGE("No given mode");
112 if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE) {
113 LOGE("No given type");
117 LOGI("[sync request] mode : %s, type : %s", mode, type);
122 #ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE
123 int feature_flag = 0;
124 if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0) {
125 if (feature_flag & VCONFKEY_STICKER_FEATURE_AREMOJI)
126 request_sticker_data(mode, "arsticker", type);
128 if (feature_flag & VCONFKEY_STICKER_FEATURE_BITMOJI)
129 request_sticker_data(mode, "bitmoji", type);
131 LOGW("Failed to get value of VCONFKEY_STICKER_SUPPORTED_FEATURE");
133 request_sticker_data(mode, "arsticker", type);
134 request_sticker_data(mode, "bitmoji", type);
138 else if (strcmp(request, "oobe") == 0) {
139 LOGI("[OOBE] register sync alarm");
140 sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL);
141 request_sticker_feature();
145 LOGW("Unknown command : %s", request);
150 if (NULL != operation)
163 static void app_terminate(void *data)
165 /* Release all resources. */
169 int main(int argc, char *argv[])
173 service_app_lifecycle_callback_s event_callback;
174 memset(&event_callback, 0x0, sizeof(service_app_lifecycle_callback_s));
176 event_callback.create = (service_app_create_cb)app_create;
177 event_callback.terminate = (service_app_terminate_cb)app_terminate;
178 event_callback.app_control = (service_app_control_cb)app_control;
180 ret = service_app_main(argc, argv, &event_callback, NULL);
181 if (ret != APP_ERROR_NONE) {
182 LOGE("app_main() is failed. err = %d", ret);