4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
7 * Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
28 #include <sys/types.h>
32 #include "alarm-internal.h"
33 #include "alarm-mgr-stub.h"
34 #include "security-server.h"
36 #define ALARM_SERVICE_NAME "appframework.alarm"
37 #define ALARM_OBJECT_PATH "/appframework/alarm"
38 #define ALARM_INTERFACE_NAME "appframework.alarm"
41 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
42 alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
44 bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref,
45 int method, alarm_id_t *alarm_id, int *error_code);
46 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
47 alarm_id_t *alarm_id, bundle *b,int *error_code);
48 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
50 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
51 alarm_id_t *alarm_id, int *num_of_ids,
53 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
55 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
56 alarm_info_t *alarm_info, int *error_code);
58 char* __get_cookie(int *error_code)
60 char *e_cookie = NULL;
61 char cookie[256] = {0,};
65 size = security_server_get_cookie_size();
66 retval = security_server_request_cookie(cookie, size);
68 ALARM_MGR_EXCEPTION_PRINT("security_server_request_cookie() is failed. retval = %d", retval);
70 *error_code = ERR_ALARM_SYSTEM_FAIL;
75 e_cookie = g_base64_encode((const guchar *)cookie, size);
76 if (e_cookie == NULL) {
77 ALARM_MGR_EXCEPTION_PRINT("g_base64_encode() is failed.");
79 *error_code = ERR_ALARM_SYSTEM_FAIL;
84 ALARM_MGR_LOG_PRINT("Gets the cookie successfully.");
89 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
90 alarm_id_t *alarm_id, bundle *b,
95 char *e_cookie = NULL;
96 bundle_raw *b_data = NULL;
99 if (bundle_encode(b, &b_data, &datalen))
101 ALARM_MGR_EXCEPTION_PRINT("Unable to encode the bundle data\n");
103 *error_code = ERR_ALARM_SYSTEM_FAIL;
108 e_cookie = __get_cookie(error_code);
109 if (e_cookie == NULL) {
110 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
114 if (!alarm_manager_call_alarm_create_appsvc_sync((AlarmManager*)context.proxy, context.pid,
115 alarm_info->start.year,
116 alarm_info->start.month,
117 alarm_info->start.day,
118 alarm_info->start.hour,
119 alarm_info->start.min,
120 alarm_info->start.sec,
121 alarm_info->end.year,
122 alarm_info->end.month,
124 alarm_info->mode.u_interval.day_of_week,
125 alarm_info->mode.repeat,
126 alarm_info->alarm_type,
127 alarm_info->reserved_info,
128 (char *)b_data, e_cookie,
129 alarm_id, &return_code,
131 /* g_dbus_proxy_call_sync error */
132 /* error_code should be set */
133 ALARM_MGR_EXCEPTION_PRINT(
134 "alarm_manager_call_alarm_create_appsvc_sync()failed. alarm_id[%d], return_code[%d].", alarm_id, return_code);
135 ALARM_MGR_EXCEPTION_PRINT("error->message is %s.", error->message);
145 if (return_code != 0) {
147 *error_code = return_code;
156 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
157 alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
160 GError *error = NULL;
162 char *e_cookie = NULL;
164 /*TODO: Dbus bus name validation is must & will be added to avoid alarm-server crash*/
165 if (g_quark_to_string(context.quark_app_service_name) == NULL
166 && strlen(dst_service_name) == 4
167 && strncmp(dst_service_name, "null",4) == 0) {
168 ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n");
170 *error_code = ERR_ALARM_INVALID_PARAM;
175 e_cookie = __get_cookie(error_code);
176 if (e_cookie == NULL) {
177 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
181 if (!alarm_manager_call_alarm_create_sync((AlarmManager*)context.proxy, context.pid,
182 g_quark_to_string(context.quark_app_service_name),
183 g_quark_to_string(context.quark_app_service_name_mod),
184 alarm_info->start.year,
185 alarm_info->start.month,
186 alarm_info->start.day,
187 alarm_info->start.hour,
188 alarm_info->start.min,
189 alarm_info->start.sec,
190 alarm_info->end.year,
191 alarm_info->end.month,
193 alarm_info->mode.u_interval.day_of_week,
194 alarm_info->mode.repeat,
195 alarm_info->alarm_type,
196 alarm_info->reserved_info,
197 dst_service_name, dst_service_name_mod, e_cookie,
198 alarm_id, &return_code,
200 /* g_dbus_proxy_call_sync error error */
201 /* error_code should be set */
202 ALARM_MGR_EXCEPTION_PRINT(
203 "alarm_manager_call_alarm_create_sync()failed. alarm_id[%d], return_code[%d]", alarm_id, return_code);
204 ALARM_MGR_EXCEPTION_PRINT("error->message is %s", error->message);
206 *error_code = ERR_ALARM_SYSTEM_FAIL;
214 if (return_code != 0) {
216 *error_code = return_code;
224 bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref,
225 int method, alarm_id_t *alarm_id, int *error_code)
227 GError *error = NULL;
229 char *e_cookie = NULL;
231 if (g_quark_to_string(context.quark_app_service_name) == NULL) {
232 ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n");
234 *error_code = ERR_ALARM_INVALID_PARAM;
239 e_cookie = __get_cookie(error_code);
240 if (e_cookie == NULL) {
241 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
245 if (!alarm_manager_call_alarm_create_periodic_sync((AlarmManager*)context.proxy,
246 g_quark_to_string(context.quark_app_service_name),
247 g_quark_to_string(context.quark_app_service_name_mod),
248 interval, is_ref, method,
250 alarm_id, &return_code, NULL, &error)) {
251 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_create_periodic_sync()failed. alarm_id[%d], return_code[%d]",
252 alarm_id, return_code);
253 ALARM_MGR_EXCEPTION_PRINT("error->message is %s", error->message);
255 *error_code = ERR_ALARM_SYSTEM_FAIL;
263 if (return_code != 0) {
265 *error_code = return_code;
273 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
275 GError *error = NULL;
278 char *e_cookie = NULL;
279 gchar *b_data = NULL;
282 e_cookie = __get_cookie(error_code);
283 if (e_cookie == NULL) {
284 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
288 if (!alarm_manager_call_alarm_get_appsvc_info_sync
289 ((AlarmManager*)context.proxy, context.pid, alarm_id, e_cookie, &b_data, &return_code, NULL, &error)) {
290 /* g_dbus_proxy_call_sync error */
291 /*error_code should be set */
292 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_appsvc_info_sync() failed. alarm_id[%d], return_code[%d].", alarm_id, return_code);
295 *error_code = ERR_ALARM_SYSTEM_FAIL;
307 if (return_code != 0) {
309 *error_code = return_code;
312 b = bundle_decode((bundle_raw *)b_data, strlen(b_data));
325 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code){
327 GError *error = NULL;
328 char *e_cookie = NULL;
330 e_cookie = __get_cookie(error_code);
331 if (e_cookie == NULL) {
332 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
336 if (!alarm_manager_call_alarm_set_rtc_time_sync
337 ((AlarmManager*)context.proxy, context.pid,
338 time->year, time->month, time->day,
339 time->hour, time->min, time->sec,
340 e_cookie, NULL, NULL, &error)) {
341 /* g_dbus_proxy_call_sync error */
342 /*error_code should be set */
344 *error_code = ERR_ALARM_SYSTEM_FAIL;
356 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
358 GError *error = NULL;
360 char *e_cookie = NULL;
362 e_cookie = __get_cookie(error_code);
363 if (e_cookie == NULL) {
364 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
368 if (!alarm_manager_call_alarm_delete_sync
369 ((AlarmManager*)context.proxy, context.pid, alarm_id, e_cookie, &return_code, NULL, &error)) {
370 /* g_dbus_proxy_call_sync error */
371 /*error_code should be set */
372 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_sync() failed. alarm_id[%d], return_code[%d]", alarm_id, return_code);
374 *error_code = ERR_ALARM_SYSTEM_FAIL;
383 if (return_code != 0) {
385 *error_code = return_code;
393 bool _send_alarm_delete_all(alarm_context_t context, int *error_code)
395 GError *error = NULL;
397 char *e_cookie = NULL;
399 e_cookie = __get_cookie(error_code);
400 if (e_cookie == NULL) {
401 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
405 if (!alarm_manager_call_alarm_delete_all_sync
406 ((AlarmManager*)context.proxy, context.pid, e_cookie, &return_code, NULL, &error)) {
407 /* g_dbus_proxy_call_sync error */
408 /*error_code should be set */
409 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_all_sync() failed. return_code[%d]", return_code);
411 *error_code = ERR_ALARM_SYSTEM_FAIL;
420 if (return_code != 0) {
422 *error_code = return_code;
430 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
431 alarm_id_t *alarm_id, int *num_of_ids,
434 GError *error = NULL;
435 GVariant *alarm_array = NULL;
439 if (!alarm_manager_call_alarm_get_list_of_ids_sync((AlarmManager*)context.proxy,
440 context.pid, maxnum_of_ids, &alarm_array,
441 num_of_ids, &return_code, NULL, &error)) {
442 /* g_dbus_proxy_call_sync error */
443 /*error_code should be set */
444 ALARM_MGR_EXCEPTION_PRINT(
445 "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
447 *error_code = ERR_ALARM_SYSTEM_FAIL;
453 if (return_code != 0) {
455 *error_code = return_code;
461 GVariantIter *iter = NULL;
463 g_variant_get (alarm_array, "ai", &iter);
464 while (g_variant_iter_loop (iter, "i", &alarm_id[i]))
466 ALARM_MGR_LOG_PRINT("alarm_id (%d)", alarm_id[i]);
469 g_variant_iter_free (iter);
471 g_variant_unref(alarm_array);
477 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
480 GError *error = NULL;
481 gint return_code = 0;
482 char *e_cookie = NULL;
484 e_cookie = __get_cookie(error_code);
485 if (e_cookie == NULL) {
486 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
490 if (!alarm_manager_call_alarm_get_number_of_ids_sync((AlarmManager*)context.proxy, context.pid, e_cookie, num_of_ids, &return_code, NULL, &error)) {
491 /* g_dbus_proxy_call_sync error */
492 /* error_code should be set */
493 ALARM_MGR_EXCEPTION_PRINT(
494 "alarm_manager_call_alarm_get_number_of_ids_sync() failed by dbus. return_code[%d], return_code[%s].",
495 return_code, error->message);
498 *error_code = ERR_ALARM_SYSTEM_FAIL;
503 if (return_code != 0) {
505 *error_code = return_code;
513 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
514 alarm_info_t *alarm_info, int *error_code)
516 GError *error = NULL;
518 char *e_cookie = NULL;
520 e_cookie = __get_cookie(error_code);
521 if (e_cookie == NULL) {
522 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
526 if (!alarm_manager_call_alarm_get_info_sync((AlarmManager*)context.proxy,
527 context.pid, alarm_id, e_cookie, &alarm_info->start.year,
528 &alarm_info->start.month, &alarm_info->start.day,
529 &alarm_info->start.hour, &alarm_info->start.min,
530 &alarm_info->start.sec, &alarm_info->end.year,
531 &alarm_info->end.month, &alarm_info->end.day,
532 &alarm_info->mode.u_interval.day_of_week,
533 (gint *)&alarm_info->mode.repeat,
534 &alarm_info->alarm_type, &alarm_info->reserved_info, &return_code, NULL, &error)) {
535 /* g_dbus_proxy_call_sync error */
536 /* error_code should be set */
537 ALARM_MGR_EXCEPTION_PRINT(
538 "alarm_manager_call_alarm_get_info_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
540 *error_code = ERR_ALARM_SYSTEM_FAIL;
548 if (return_code != 0) {
550 *error_code = return_code;
558 bool _send_alarm_get_next_duetime(alarm_context_t context,
559 alarm_id_t alarm_id, time_t* duetime,
562 GError *error = NULL;
564 char *e_cookie = NULL;
566 e_cookie = __get_cookie(error_code);
567 if (e_cookie == NULL) {
568 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
572 if (!alarm_manager_call_alarm_get_next_duetime_sync((AlarmManager*)context.proxy,
573 context.pid, alarm_id, e_cookie, duetime, &return_code, NULL, &error)) {
574 /*g_dbus_proxy_call_sync error */
575 /*error_code should be set */
576 ALARM_MGR_EXCEPTION_PRINT(
577 "alarm_manager_call_alarm_get_next_duetime_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
579 *error_code = ERR_ALARM_SYSTEM_FAIL;
587 if (return_code != 0) {
589 *error_code = return_code;
597 bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *error_code)
599 GError *error = NULL;
601 char *e_cookie = NULL;
603 e_cookie = __get_cookie(error_code);
604 if (e_cookie == NULL) {
605 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
609 if (!alarm_manager_call_alarm_get_all_info_sync((AlarmManager*)context.proxy, context.pid, e_cookie, db_path, &return_code, NULL, &error)) {
610 /*g_dbus_proxy_call_sync error */
611 /*error_code should be set */
612 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_all_info_sync() failed by dbus. return_code[%d][%s]", return_code, error->message);
614 *error_code = ERR_ALARM_SYSTEM_FAIL;
622 if (return_code != ALARMMGR_RESULT_SUCCESS) {
624 *error_code = return_code;
632 bool _send_alarm_set_time(alarm_context_t context, int new_time, int *error_code)
634 GError *error = NULL;
637 if (!alarm_manager_call_alarm_set_time_sync((AlarmManager*)context.proxy, new_time, &return_code, NULL, &error)) {
638 /*g_dbus_proxy_call_sync error */
639 /*error_code should be set */
640 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_time_sync() failed by dbus. return_code[%d][%s]", return_code, error->message);
642 *error_code = ERR_ALARM_SYSTEM_FAIL;
647 if (return_code != ALARMMGR_RESULT_SUCCESS) {
649 *error_code = return_code;
657 bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code)
659 GError *error = NULL;
662 if (!alarm_manager_call_alarm_set_timezone_sync((AlarmManager*)context.proxy, tzpath_str, &return_code, NULL, &error)) {
663 /*g_dbus_proxy_call_sync error */
664 /*error_code should be set */
665 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_timezone_sync() failed by dbus. return_code[%d][%s]", return_code, error->message);
667 *error_code = ERR_ALARM_SYSTEM_FAIL;
672 if (return_code != ALARMMGR_RESULT_SUCCESS) {
674 *error_code = return_code;