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_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
45 alarm_id_t *alarm_id, bundle *b,int *error_code);
46 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
48 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
49 alarm_id_t *alarm_id, int *num_of_ids,
51 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
53 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
54 alarm_info_t *alarm_info, int *error_code);
56 char* __get_cookie(int *error_code)
58 char *e_cookie = NULL;
59 char cookie[256] = {0,};
63 size = security_server_get_cookie_size();
64 retval = security_server_request_cookie(cookie, size);
66 ALARM_MGR_EXCEPTION_PRINT("security_server_request_cookie() is failed. retval = %d", retval);
68 *error_code = ERR_ALARM_SYSTEM_FAIL;
73 e_cookie = g_base64_encode((const guchar *)cookie, size);
74 if (e_cookie == NULL) {
75 ALARM_MGR_EXCEPTION_PRINT("g_base64_encode() is failed.");
77 *error_code = ERR_ALARM_SYSTEM_FAIL;
82 ALARM_MGR_LOG_PRINT("Gets the cookie successfully.");
87 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
88 alarm_id_t *alarm_id, bundle *b,
93 char *e_cookie = NULL;
94 bundle_raw *b_data = NULL;
97 if (bundle_encode(b, &b_data, &datalen))
99 ALARM_MGR_EXCEPTION_PRINT("Unable to encode the bundle data\n");
101 *error_code = ERR_ALARM_SYSTEM_FAIL;
106 e_cookie = __get_cookie(error_code);
107 if (e_cookie == NULL) {
108 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
112 if (!alarm_manager_call_alarm_create_appsvc_sync((AlarmManager*)context.proxy, context.pid,
113 alarm_info->start.year,
114 alarm_info->start.month,
115 alarm_info->start.day,
116 alarm_info->start.hour,
117 alarm_info->start.min,
118 alarm_info->start.sec,
119 alarm_info->end.year,
120 alarm_info->end.month,
122 alarm_info->mode.u_interval.day_of_week,
123 alarm_info->mode.repeat,
124 alarm_info->alarm_type,
125 alarm_info->reserved_info,
126 (char *)b_data, e_cookie,
127 alarm_id, &return_code,
129 /* g_dbus_proxy_call_sync error */
130 /* error_code should be set */
131 ALARM_MGR_EXCEPTION_PRINT(
132 "alarm_manager_call_alarm_create_appsvc_sync()failed. alarm_id[%d], return_code[%d].", alarm_id, return_code);
133 ALARM_MGR_EXCEPTION_PRINT("error->message is %s.", error->message);
143 if (return_code != 0) {
145 *error_code = return_code;
154 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
155 alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
158 GError *error = NULL;
160 char *e_cookie = NULL;
162 /*TODO: Dbus bus name validation is must & will be added to avoid alarm-server crash*/
163 if (g_quark_to_string(context.quark_app_service_name) == NULL
164 && strlen(dst_service_name) == 4
165 && strncmp(dst_service_name, "null",4) == 0) {
166 ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n");
168 *error_code = ERR_ALARM_INVALID_PARAM;
173 e_cookie = __get_cookie(error_code);
174 if (e_cookie == NULL) {
175 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
179 if (!alarm_manager_call_alarm_create_sync((AlarmManager*)context.proxy, context.pid,
180 g_quark_to_string(context.quark_app_service_name),
181 g_quark_to_string(context.quark_app_service_name_mod),
182 alarm_info->start.year,
183 alarm_info->start.month,
184 alarm_info->start.day,
185 alarm_info->start.hour,
186 alarm_info->start.min,
187 alarm_info->start.sec,
188 alarm_info->end.year,
189 alarm_info->end.month,
191 alarm_info->mode.u_interval.day_of_week,
192 alarm_info->mode.repeat,
193 alarm_info->alarm_type,
194 alarm_info->reserved_info,
195 dst_service_name, dst_service_name_mod, e_cookie,
196 alarm_id, &return_code,
198 /* g_dbus_proxy_call_sync error error */
199 /* error_code should be set */
200 ALARM_MGR_EXCEPTION_PRINT(
201 "alarm_manager_call_alarm_create_sync()failed. alarm_id[%d], return_code[%d]", alarm_id, return_code);
202 ALARM_MGR_EXCEPTION_PRINT("error->message is %s", error->message);
204 *error_code = ERR_ALARM_SYSTEM_FAIL;
212 if (return_code != 0) {
214 *error_code = return_code;
221 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
223 GError *error = NULL;
226 char *e_cookie = NULL;
227 gchar *b_data = NULL;
230 e_cookie = __get_cookie(error_code);
231 if (e_cookie == NULL) {
232 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
236 if (!alarm_manager_call_alarm_get_appsvc_info_sync
237 ((AlarmManager*)context.proxy, context.pid, alarm_id, e_cookie, &b_data, &return_code, NULL, &error)) {
238 /* g_dbus_proxy_call_sync error */
239 /*error_code should be set */
240 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_appsvc_info_sync() failed. alarm_id[%d], return_code[%d].", alarm_id, return_code);
243 *error_code = ERR_ALARM_SYSTEM_FAIL;
255 if (return_code != 0) {
257 *error_code = return_code;
260 b = bundle_decode((bundle_raw *)b_data, len);
273 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code){
275 GError *error = NULL;
277 char *e_cookie = NULL;
279 e_cookie = __get_cookie(error_code);
280 if (e_cookie == NULL) {
281 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
285 if (!alarm_manager_call_alarm_set_rtc_time_sync
286 ((AlarmManager*)context.proxy, context.pid,
287 time->year, time->month, time->day,
288 time->hour, time->min, time->sec,
289 e_cookie, NULL, NULL, &error)) {
290 /* g_dbus_proxy_call_sync error */
291 /*error_code should be set */
292 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_rtc_time() failed. return_code[%d]\n", return_code);
294 *error_code = ERR_ALARM_SYSTEM_FAIL;
303 if (return_code != 0) {
305 *error_code = return_code;
313 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
315 GError *error = NULL;
317 char *e_cookie = NULL;
319 e_cookie = __get_cookie(error_code);
320 if (e_cookie == NULL) {
321 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
325 if (!alarm_manager_call_alarm_delete_sync
326 ((AlarmManager*)context.proxy, context.pid, alarm_id, e_cookie, &return_code, NULL, &error)) {
327 /* g_dbus_proxy_call_sync error */
328 /*error_code should be set */
329 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_sync() failed. alarm_id[%d], return_code[%d]", alarm_id, return_code);
331 *error_code = ERR_ALARM_SYSTEM_FAIL;
340 if (return_code != 0) {
342 *error_code = return_code;
350 bool _send_alarm_delete_all(alarm_context_t context, int *error_code)
352 GError *error = NULL;
354 char *e_cookie = NULL;
356 e_cookie = __get_cookie(error_code);
357 if (e_cookie == NULL) {
358 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
362 if (!alarm_manager_call_alarm_delete_all_sync
363 ((AlarmManager*)context.proxy, context.pid, e_cookie, &return_code, NULL, &error)) {
364 /* g_dbus_proxy_call_sync error */
365 /*error_code should be set */
366 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_all_sync() failed. return_code[%d]", return_code);
368 *error_code = ERR_ALARM_SYSTEM_FAIL;
377 if (return_code != 0) {
379 *error_code = return_code;
387 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
388 alarm_id_t *alarm_id, int *num_of_ids,
391 GError *error = NULL;
392 GVariant *alarm_array = NULL;
396 if (!alarm_manager_call_alarm_get_list_of_ids_sync((AlarmManager*)context.proxy,
397 context.pid, maxnum_of_ids, &alarm_array,
398 num_of_ids, &return_code, NULL, &error)) {
399 /* g_dbus_proxy_call_sync error */
400 /*error_code should be set */
401 ALARM_MGR_EXCEPTION_PRINT(
402 "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
404 *error_code = ERR_ALARM_SYSTEM_FAIL;
410 if (return_code != 0) {
412 *error_code = return_code;
418 GVariantIter *iter = NULL;
420 g_variant_get (alarm_array, "ai", &iter);
421 while (g_variant_iter_loop (iter, "i", &alarm_id[i]))
423 ALARM_MGR_LOG_PRINT("alarm_id (%d)", alarm_id[i]);
426 g_variant_iter_free (iter);
428 g_variant_unref(alarm_array);
434 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
437 GError *error = NULL;
438 gint return_code = 0;
439 char *e_cookie = NULL;
441 e_cookie = __get_cookie(error_code);
442 if (e_cookie == NULL) {
443 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
447 if (!alarm_manager_call_alarm_get_number_of_ids_sync((AlarmManager*)context.proxy, context.pid, e_cookie, num_of_ids, &return_code, NULL, &error)) {
448 /* g_dbus_proxy_call_sync error */
449 /* error_code should be set */
450 ALARM_MGR_EXCEPTION_PRINT(
451 "alarm_manager_call_alarm_get_number_of_ids_sync() failed by dbus. return_code[%d], return_code[%s].",
452 return_code, error->message);
455 *error_code = ERR_ALARM_SYSTEM_FAIL;
460 if (return_code != 0) {
462 *error_code = return_code;
470 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
471 alarm_info_t *alarm_info, int *error_code)
473 GError *error = NULL;
475 char *e_cookie = NULL;
477 e_cookie = __get_cookie(error_code);
478 if (e_cookie == NULL) {
479 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
483 if (!alarm_manager_call_alarm_get_info_sync((AlarmManager*)context.proxy,
484 context.pid, alarm_id, e_cookie, &alarm_info->start.year,
485 &alarm_info->start.month, &alarm_info->start.day,
486 &alarm_info->start.hour, &alarm_info->start.min,
487 &alarm_info->start.sec, &alarm_info->end.year,
488 &alarm_info->end.month, &alarm_info->end.day,
489 &alarm_info->mode.u_interval.day_of_week,
490 (gint *)&alarm_info->mode.repeat,
491 &alarm_info->alarm_type, &alarm_info->reserved_info, &return_code, NULL, &error)) {
492 /* g_dbus_proxy_call_sync error */
493 /* error_code should be set */
494 ALARM_MGR_EXCEPTION_PRINT(
495 "alarm_manager_call_alarm_get_info_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
497 *error_code = ERR_ALARM_SYSTEM_FAIL;
505 if (return_code != 0) {
507 *error_code = return_code;
515 bool _send_alarm_get_next_duetime(alarm_context_t context,
516 alarm_id_t alarm_id, time_t* duetime,
519 GError *error = NULL;
521 char *e_cookie = NULL;
523 e_cookie = __get_cookie(error_code);
524 if (e_cookie == NULL) {
525 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
529 if (!alarm_manager_call_alarm_get_next_duetime_sync((AlarmManager*)context.proxy,
530 context.pid, alarm_id, e_cookie, duetime, &return_code, NULL, &error)) {
531 /*g_dbus_proxy_call_sync error */
532 /*error_code should be set */
533 ALARM_MGR_EXCEPTION_PRINT(
534 "alarm_manager_call_alarm_get_next_duetime_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
536 *error_code = ERR_ALARM_SYSTEM_FAIL;
544 if (return_code != 0) {
546 *error_code = return_code;
554 bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *error_code)
556 GError *error = NULL;
558 char *e_cookie = NULL;
560 e_cookie = __get_cookie(error_code);
561 if (e_cookie == NULL) {
562 ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
566 if (!alarm_manager_call_alarm_get_all_info_sync((AlarmManager*)context.proxy, context.pid, e_cookie, db_path, &return_code, NULL, &error)) {
567 /*g_dbus_proxy_call_sync error */
568 /*error_code should be set */
569 ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_all_info_sync() failed by dbus. return_code[%d][%s]", return_code, error->message);
571 *error_code = ERR_ALARM_SYSTEM_FAIL;
579 if (return_code != ALARMMGR_RESULT_SUCCESS) {
581 *error_code = return_code;