Add new apis to support global alarm 04/52704/9
authorinkyun.kil <inkyun.kil@samsung.com>
Thu, 26 Nov 2015 05:07:20 +0000 (14:07 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Tue, 8 Dec 2015 01:09:44 +0000 (10:09 +0900)
- add api 'alarmmgr_set_global()' and 'alarmmgr_get_global()'
- add privilege check for added method call in alarm-server
- find login user in launching global alarm

Change-Id: I43d22b28d1c36f8817233d4e985027791cb4d1f7

CMakeLists.txt
alarm-manager-registry.c
alarm-manager.c
alarm-service.conf.in
alarm_mgr.xml
include/alarm-internal.h
include/alarm.h
packaging/alarm-manager.spec
src/alarm-lib-stub.c
src/alarm-lib.c

index 98bd72f..e00fb97 100644 (file)
@@ -6,7 +6,7 @@ INCLUDE_DIRECTORIES(
        include
 )
 
-SET(DEPS_PKGS "glib-2.0 dlog aul bundle db-util appsvc pkgmgr-info vconf gio-2.0 gio-unix-2.0 capi-system-device libtzplatform-config")
+SET(DEPS_PKGS "glib-2.0 dlog aul bundle db-util appsvc pkgmgr-info vconf gio-2.0 gio-unix-2.0 capi-system-device libtzplatform-config libsystemd-login")
 
 IF(_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG)
 ADD_DEFINITIONS("-D_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG")
index 1c949b0..aa813aa 100644 (file)
@@ -57,16 +57,17 @@ bool _save_alarms(__alarm_info_t *__alarm_info)
        alarm_mode_t *mode = &alarm_info->mode;
 
        char *query = sqlite3_mprintf("insert into alarmmgr( alarm_id, start,\
-                       end, uid, pid, caller_pkgid, callee_pkgid, app_unique_name, app_service_name, app_service_name_mod, bundle, year,\
+                       end, uid, pid, global, caller_pkgid, callee_pkgid, app_unique_name, app_service_name, app_service_name_mod, bundle, year,\
                        month, day, hour, min, sec, day_of_week, repeat,\
                        alarm_type, reserved_info, dst_service_name, dst_service_name_mod)\
-                       values (%d,%d,%d,%d,%d,%Q,%Q,%Q,%Q,%Q,%Q,%d,%d,%d,%d,%d,%d,%d,%d,\
+                       values (%d,%d,%d,%d,%d,%d,%Q,%Q,%Q,%Q,%Q,%Q,%d,%d,%d,%d,%d,%d,%d,%d,\
                        %d,%d,%Q,%Q)",\
                        __alarm_info->alarm_id,
                        (int)__alarm_info->start,
                        (int)__alarm_info->end,
                        __alarm_info->uid,
                        __alarm_info->pid,
+                       __alarm_info->global,
                        (char *)g_quark_to_string(__alarm_info->quark_caller_pkgid),
                        (char *)g_quark_to_string(__alarm_info->quark_callee_pkgid),
                        (char *)g_quark_to_string(
@@ -111,7 +112,7 @@ bool _update_alarms(__alarm_info_t *__alarm_info)
        alarm_mode_t *mode = &alarm_info->mode;
 
        char *query = sqlite3_mprintf("update alarmmgr set start=%d, end=%d,\
-                       uid=%d, pid=%d, caller_pkgid=%Q, callee_pkgid=%Q, app_unique_name=%Q, app_service_name=%Q, app_service_name_mod=%Q,\
+                       uid=%d, pid=%d, global=%d, caller_pkgid=%Q, callee_pkgid=%Q, app_unique_name=%Q, app_service_name=%Q, app_service_name_mod=%Q,\
                        bundle=%Q, year=%d, month=%d, day=%d, hour=%d, min=%d, sec=%d,\
                        day_of_week=%d, repeat=%d, alarm_type=%d,\
                        reserved_info=%d, dst_service_name=%Q, dst_service_name_mod=%Q\
@@ -120,6 +121,7 @@ bool _update_alarms(__alarm_info_t *__alarm_info)
                        (int)__alarm_info->end,
                        __alarm_info->uid,
                        __alarm_info->pid,
+                       __alarm_info->global,
                        (char *)g_quark_to_string(__alarm_info->quark_caller_pkgid),
                        (char *)g_quark_to_string(__alarm_info->quark_callee_pkgid),
                        (char *)g_quark_to_string(
@@ -215,6 +217,7 @@ bool _load_alarms_from_registry()
                __alarm_info->end = sqlite3_column_int(stmt, col_idx++);
                __alarm_info->uid = sqlite3_column_int(stmt, col_idx++);
                __alarm_info->pid = sqlite3_column_int(stmt, col_idx++);
+               __alarm_info->global = sqlite3_column_int(stmt, col_idx++);
 
                strncpy(caller_pkgid, (const char *)sqlite3_column_text(stmt, col_idx++),
                        MAX_PKG_ID_LEN - 1);
index beabb5d..954f0df 100644 (file)
 #include <poll.h>
 #include <stdint.h>
 
+#include <tzplatform_config.h>
+#include <aul.h>
+#include <bundle.h>
+#include <db-util.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <dlfcn.h>
+#include <pkgmgr-info.h>
+#include <device/display.h>
+#include <systemd/sd-login.h>
+
 #include <glib.h>
 #if !GLIB_CHECK_VERSION (2, 31, 0)
 #include <glib/gmacros.h>
 #include "alarm-internal.h"
 #include "alarm-mgr-stub.h"
 
-#include <tzplatform_config.h>
-#include <aul.h>
-#include <bundle.h>
-#include <db-util.h>
-#include <vconf.h>
-#include <vconf-keys.h>
-#include <dlfcn.h>
-#include <pkgmgr-info.h>
-#include <device/display.h>
 
 #define SIG_TIMER 0x32
 #define WAKEUP_ALARM_APP_ID       "org.tizen.alarm.ALARM"
@@ -724,6 +726,7 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
        __alarm_info->pid = pid;
        __alarm_info->alarm_id = -1;
        __alarm_info->requested_interval = requested_interval;
+       __alarm_info->global = false;
 
        if (!__get_caller_unique_name(pid, app_name, uid)) {
                *error_code = ERR_ALARM_SYSTEM_FAIL;
@@ -861,6 +864,7 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, uid_t
        __alarm_info->method = method;
        __alarm_info->requested_interval = requested_interval;
        __alarm_info->is_ref = is_ref;
+       __alarm_info->global = false;
 
        // Get caller_appid to get caller's package id. There is no callee.
        if (aul_app_get_appid_bypid_for_uid(pid, caller_appid, 256, uid) == AUL_R_OK) {
@@ -1058,6 +1062,24 @@ static bool __alarm_update(uid_t uid, int pid, char *app_service_name, alarm_id_
        return true;
 }
 
+static bool __alarm_set_global_to_db(__alarm_info_t *alarm_info, bool global)
+{
+
+       char *error_message = NULL;
+       char *query = sqlite3_mprintf("update alarmmgr set global=%d where alarm_id=%d",
+                       alarm_info->global, alarm_info->alarm_id);
+
+       if (SQLITE_OK != sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
+               SECURE_LOGE("sqlite3_exec() is failed. query = %s, error message = %s", query, error_message);
+               sqlite3_free(query);
+               return false;
+       }
+
+       sqlite3_free(query);
+       return true;
+}
+
+
 static bool __alarm_delete(uid_t uid, alarm_id_t alarm_id, int *error_code)
 {
        bool result = false;
@@ -1275,6 +1297,34 @@ static int __compare_api_version(int *result, int pid, uid_t uid) {
        return ret;
 }
 
+static int __find_login_user(uid_t *uid)
+{
+       uid_t *uids;
+       int ret, i;
+       char *state;
+
+       ret = sd_get_uids(&uids);
+       if (ret <= 0)
+               return -1;
+
+       for (i = 0; i < ret ; i++) {
+               if (sd_uid_get_state(uids[i], &state) < 0) {
+                       free(uids);
+                       return -1;
+               } else {
+                       if (!strncmp(state, "online", 6)) {
+                               *uid = uids[i];
+                               free(uids);
+                               free(state);
+                               return 0;
+                       }
+               }
+       }
+       free(uids);
+       free(state);
+       return -1;
+}
+
 static void __alarm_expired()
 {
        int ret;
@@ -1286,6 +1336,7 @@ static void __alarm_expired()
        int b_len = 0;
        bundle *b = NULL;
        char *appid = NULL;
+       uid_t target_uid;
 #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
 #endif
@@ -1364,7 +1415,18 @@ static void __alarm_expired()
                                                        ALARM_MGR_EXCEPTION_PRINT("This alarm is ignored\n");
                                                } else if ( !(__alarm_info->alarm_info.alarm_type & ALARM_TYPE_INEXACT) ||
                                                                !__can_skip_expired_cb(__alarm_info->alarm_id) ) {
-                                                       if (appsvc_usr_run_service(b, 0, NULL, NULL, __alarm_info->uid ) < 0) {
+                                                       if (__alarm_info->global) {
+                                                               if (__find_login_user(&target_uid) < 0) {
+                                                                       ALARM_MGR_EXCEPTION_PRINT("Fail to get login user\n");
+                                                                       ret = -1;
+                                                               } else {
+                                                                       ret = appsvc_usr_run_service(b, 0, NULL, NULL, target_uid);
+                                                               }
+                                                       } else {
+                                                               ret = appsvc_usr_run_service(b, 0, NULL, NULL, __alarm_info->uid);
+                                                       }
+
+                                                       if (ret < 0) {
                                                                ALARM_MGR_EXCEPTION_PRINT("Unable to launch app [%s] \n", appid);
                                                        }
                                                        else {
@@ -1460,7 +1522,17 @@ static void __alarm_expired()
                                bundle *kb;
                                kb = bundle_create();
                                bundle_add_str(kb, "__ALARM_MGR_ID", alarm_id_str);
-                               aul_launch_app_for_uid(appid, kb, __alarm_info->uid);   // on_bus_name_owner_changed will be called.
+
+                               if (__alarm_info->global) {
+                                       if (__find_login_user(&target_uid) < 0) {
+                                               ALARM_MGR_EXCEPTION_PRINT("Fail to get login user\n");
+                                       } else {
+                                               aul_launch_app_for_uid(appid, kb, target_uid);  // on_bus_name_owner_changed will be called.
+                                       }
+                               } else {
+                                       aul_launch_app_for_uid(appid, kb, __alarm_info->uid);   // on_bus_name_owner_changed will be called.
+                               }
+
                                bundle_free(kb);
                        } else {
                                // Case #3. The process is alive or was killed && non-app type(daemon)
@@ -2803,6 +2875,7 @@ gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvo
                                                        start_epoch integer,\
                                                        end_epoch integer,\
                                                        pid integer,\
+                                                       global integer,\
                                                        caller_pkgid text,\
                                                        callee_pkgid text,\
                                                        app_unique_name text,\
@@ -2817,6 +2890,7 @@ gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvo
        __alarm_info_t *entry = NULL;
        char *error_message = NULL;
        uid_t uid;
+
        const char *name = g_dbus_method_invocation_get_sender(invoc);
 
        uid = __get_caller_uid(name);
@@ -2865,14 +2939,15 @@ gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvo
                alarm_mode_t *mode = &alarm_info->mode;
 
                char *query = sqlite3_mprintf("insert into alarmmgr_tool( alarm_id, duetime_epoch, duetime, start_epoch,\
-                               end_epoch, pid, caller_pkgid, callee_pkgid, app_unique_name, app_service_name, dst_service_name, day_of_week, repeat, alarm_type)\
-                               values (%d,%d,%Q,%d,%d,%d,%Q,%Q,%Q,%Q,%Q,%d,%d,%d)",
+                               end_epoch, pid, global, caller_pkgid, callee_pkgid, app_unique_name, app_service_name, dst_service_name, day_of_week, repeat, alarm_type)\
+                               values (%d,%d,%Q,%d,%d,%d,%d,%Q,%Q,%Q,%Q,%Q,%d,%d,%d)",
                                entry->alarm_id,
                                (int)entry->due_time,
                                ctime(&(entry->due_time)),
                                (int)entry->start,
                                (int)entry->end,
                                (int)entry->pid,
+                               (bool)entry->global,
                                (char *)g_quark_to_string(entry->quark_caller_pkgid),
                                (char *)g_quark_to_string(entry->quark_callee_pkgid),
                                (char *)g_quark_to_string(entry->quark_app_unique_name),
@@ -2897,6 +2972,100 @@ gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvo
        return true;
 }
 
+gboolean alarm_manager_alarm_set_global(AlarmManager *pObject, GDBusMethodInvocation *invoc,
+                                     alarm_id_t alarm_id, bool global, gpointer user_data)
+{
+       GSList *gs_iter = NULL;
+       __alarm_info_t *entry = NULL;
+       alarm_info_t *alarm_info = NULL;
+       int retval = 0;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       uid_t uid;
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       uid = __get_caller_uid(name);
+
+       SECURE_LOGD("called for uid(%d), alarm_id(%d)\n", uid, alarm_id);
+       for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
+               entry = gs_iter->data;
+               if (entry->uid == uid && entry->alarm_id == alarm_id) {
+                       alarm_info = &(entry->alarm_info);
+                       break;
+               }
+       }
+
+       if (alarm_info == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is not found.", alarm_id);
+               return_code = ERR_ALARM_INVALID_ID;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+       } else {
+               ALARM_MGR_LOG_PRINT("The alarm(%d) is found.", alarm_id);
+
+               char *callee_pkgid = (char *)g_quark_to_string(entry->quark_callee_pkgid);
+               if (strncmp(callee_pkgid, "null", strlen(callee_pkgid)) == 0) {
+                       callee_pkgid = (char *)g_quark_to_string(entry->quark_app_service_name)+6;
+               }
+
+               ALARM_MGR_LOG_PRINT("The alarm pkgid : %s.", callee_pkgid);
+
+               pkgmgrinfo_pkginfo_h handle;
+               retval = pkgmgrinfo_pkginfo_get_pkginfo(callee_pkgid, &handle);
+               if (retval != PMINFO_R_OK) {
+                       ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is not permitted to set global.", alarm_id);
+                       return_code = ERR_ALARM_INVALID_ID; //TODO change error code
+               } else {
+                       bool is_global = 0;
+                       retval = pkgmgrinfo_pkginfo_is_global(handle, &is_global);
+                       if (retval == PMINFO_R_OK && is_global) {
+                               entry->global = global;
+                               if (!__alarm_set_global_to_db(entry, global)) {
+                                       return_code = ERR_ALARM_SYSTEM_FAIL;
+                               }
+                       } else if (retval == PMINFO_R_OK && !is_global) {
+                               return_code = ERR_ALARM_NOT_PERMITTED_APP;
+                       }
+
+               }
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+       }
+
+       return true;
+}
+
+gboolean alarm_manager_alarm_get_global(AlarmManager *pObject, GDBusMethodInvocation *invoc,
+                                     alarm_id_t alarm_id, gpointer user_data)
+{
+       GSList *gs_iter = NULL;
+       __alarm_info_t *entry = NULL;
+       __alarm_info_t *find_item = NULL;
+       int retval = 0;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       bool global = false;
+
+       SECURE_LOGD("called for alarm_id(%d)\n", alarm_id);
+       for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
+               entry = gs_iter->data;
+               if (entry->alarm_id == alarm_id) {
+                       find_item = entry;
+                       break;
+               }
+       }
+
+       if (find_item == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is not found.", alarm_id);
+               return_code = ERR_ALARM_INVALID_ID;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(bi)", global, return_code));
+               return true;
+       }
+
+       global = find_item->global;
+       ALARM_MGR_LOG_PRINT("Is global : %d", global);
+
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(bi)", global, return_code));
+       return true;
+}
+
+
 static void __timer_glib_finalize(GSource *src)
 {
        GSList *fd_list;
@@ -3074,6 +3243,8 @@ static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpoi
        g_signal_connect(interface, "handle_alarm_update", G_CALLBACK(alarm_manager_alarm_update), NULL);
        g_signal_connect(interface, "handle_alarm_get_all_info", G_CALLBACK(alarm_manager_alarm_get_all_info), NULL);
        g_signal_connect(interface, "handle_alarm_set_time_with_propagation_delay", G_CALLBACK(alarm_manager_alarm_set_time_with_propagation_delay), NULL);
+       g_signal_connect(interface, "handle_alarm_set_global", G_CALLBACK(alarm_manager_alarm_set_global), NULL);
+       g_signal_connect(interface, "handle_alarm_get_global", G_CALLBACK(alarm_manager_alarm_get_global), NULL);
 
        guint subsc_id = g_dbus_connection_signal_subscribe(connection, "org.freedesktop.DBus", "org.freedesktop.DBus",
                                                        "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
@@ -3125,6 +3296,7 @@ static bool __initialize_dbus()
                                                end integer,\
                                                uid integer,\
                                                pid integer,\
+                                               global integer,\
                                                caller_pkgid text,\
                                                callee_pkgid text,\
                                                app_unique_name text,\
index aa9df73..6b838c3 100644 (file)
@@ -23,5 +23,7 @@
                <check send_destination="org.tizen.alarm.manager" send_interface="org.tizen.alarm.manager" send_member="alarm_get_appsvc_info" privilege="http://tizen.org/privilege/alarm.get"/>
                <check send_destination="org.tizen.alarm.manager" send_interface="org.tizen.alarm.manager" send_member="alarm_get_info" privilege="http://tizen.org/privilege/alarm.get"/>
                <check send_destination="org.tizen.alarm.manager" send_interface="org.tizen.alarm.manager" send_member="alarm_get_next_duetime" privilege="http://tizen.org/privilege/alarm.get"/>
+               <check send_destination="org.tizen.alarm.manager" send_interface="org.tizen.alarm.manager" send_member="alarm_set_global" privilege="http://tizen.org/privilege/alarm.set"/>
+               <check send_destination="org.tizen.alarm.manager" send_interface="org.tizen.alarm.manager" send_member="alarm_get_global" privilege="http://tizen.org/privilege/alarm.get"/>
        </policy>
 </busconfig>
index 2d362f9..93e1737 100644 (file)
       <arg type="s" name="tzpath_str" direction="in" />
       <arg type="i" name="return_code" direction="out" />
     </method>
+    <method name="alarm_set_global">
+      <arg type="i" name="alarm_id" direction="in" />
+      <arg type="b" name="global" direction="in" />
+      <arg type="i" name="return_code" direction="out" />
+    </method>
+    <method name="alarm_get_global">
+      <arg type="i" name="alarm_id" direction="in" />
+      <arg type="b" name="global" direction="out" />
+      <arg type="i" name="return_code" direction="out" />
+    </method>
     <signal name="alarm_expired">
       <arg type="i" name="alarm_id" />
       <arg type="s" name="app_service_name" />
index 4298c27..87b48b0 100644 (file)
@@ -140,6 +140,8 @@ bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, unsign
 bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code);
 bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref, int method, alarm_id_t *alarm_id, int *error_code);
 bool _send_alarm_set_time(alarm_context_t context, int new_time, int *error_code);
+bool _send_alarm_set_global(alarm_context_t context, int alarm_id, bool global, int *error_code);
+bool _send_alarm_get_global(alarm_context_t context, int alarm_id, bool *global, int *error_code);
 
 /*  alarm manager*/
 typedef struct {
@@ -170,6 +172,7 @@ typedef struct {
        periodic_method_e method;
        long requested_interval;
        int is_ref;
+       bool global;
 } __alarm_info_t;
 
 typedef struct {
index fe34d18..0edd294 100644 (file)
@@ -1404,6 +1404,35 @@ int alarmmgr_set_systime_with_propagation_delay(struct timespec new_time, struct
  */
 int alarmmgr_set_timezone(char *tzpath_str);
 
+/**
+ * This function sets global
+ * @remarks The @a alarm_id must be id of alarm which will launch global application.
+ *          The function returns an error (error code #ERR_ALARM_INVALID_ID) if it is not.
+ * @param      [in]    alarm_id                the id of the alarm
+ * @param      [in]    global          value to set global or not
+ *
+ * @return     @c ALARMMGR_RESULT_SUCCESS on success,
+ *                     otherwise a negative error value
+ * @retval     #ALARMMGR_RESULT_SUCCESS        Successful
+ * @retval     #ERR_ALARM_INVALID_PARAM        Invalid parameter
+ * @retval     #ERR_ALARM_INVALID_ID   Invaild id of the alarm
+ * @retval     #ERR_ALARM_SYSTEM_FAIL          System failure
+ */
+int alarmmgr_set_global(alarm_id_t alarm_id, bool global);
+
+/**
+ * This function gets global
+ * @param      [in]    alarm_id                the id of the alarm
+ * @param      [out]   global  Whether the alarm is global or not
+ *
+ * @return     @c ALARMMGR_RESULT_SUCCESS on success,
+ *                     otherwise a negative error value
+ * @retval     #ALARMMGR_RESULT_SUCCESS        Successful
+ * @retval     #ERR_ALARM_INVALID_PARAM        Invalid parameter
+ * @retval     #ERR_ALARM_INVALID_ID   Invaild id of the alarm
+ * @retval     #ERR_ALARM_SYSTEM_FAIL          System failure
+ */
+int alarmmgr_get_global(const alarm_id_t alarm_id, bool *global);
 
 int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
                                  time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id);
index 5938735..41b12b3 100644 (file)
@@ -23,6 +23,7 @@ BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(gio-unix-2.0)
 BuildRequires: pkgconfig(capi-system-device)
 BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(libsystemd-login)
 BuildRequires: python-xml
 
 %description
index 9234328..81eb4b9 100644 (file)
@@ -614,3 +614,65 @@ bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *er
 
        return true;
 }
+
+bool _send_alarm_set_global(alarm_context_t context, const alarm_id_t alarm_id, bool global, int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+
+       if (!alarm_manager_call_alarm_set_global_sync((AlarmManager *)context.proxy, alarm_id, global, &return_code, NULL, &error)) {
+               /*g_dbus_proxy_call_sync error */
+               /*error_code should be set */
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_global_sync() failed by dbus. return_code[%d][%s]", return_code, error->message);
+               ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code);
+               if (error_code) {
+                       if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                               *error_code = ERR_ALARM_NO_PERMISSION;
+                       else
+                               *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               g_error_free(error);
+               return false;
+       }
+
+       if (return_code != ALARMMGR_RESULT_SUCCESS) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
+
+bool _send_alarm_get_global(alarm_context_t context, const alarm_id_t alarm_id, bool *global, int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+       bool _global;
+
+       if (!alarm_manager_call_alarm_get_global_sync((AlarmManager *)context.proxy, alarm_id, &_global, &return_code, NULL, &error)) {
+               /*g_dbus_proxy_call_sync error */
+               /*error_code should be set */
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_global_sync() failed by dbus. return_code[%d][%s]", return_code, error->message);
+               ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code);
+               if (error_code) {
+                       if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                               *error_code = ERR_ALARM_NO_PERMISSION;
+                       else
+                               *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               g_error_free(error);
+               return false;
+       }
+
+       if (return_code != ALARMMGR_RESULT_SUCCESS) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       *global = _global;
+       return true;
+}
index 887d799..b829fcf 100644 (file)
@@ -1586,3 +1586,35 @@ EXPORT_API int alarmmgr_set_timezone(char *tzpath_str)
        ALARM_MGR_LOG_PRINT("[alarm-lib]: successfully set the timezone(%s) by pid(%d)", tzpath_str, getpid());
        return ALARMMGR_RESULT_SUCCESS;
 }
+
+EXPORT_API int alarmmgr_set_global(const alarm_id_t alarm_id,
+                                       bool global)
+{
+       int error_code;
+       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_set_global() is called.");
+
+       if (!_send_alarm_set_global(alarm_context, alarm_id, global, &error_code)) {
+               return error_code;
+       }
+
+       return ALARMMGR_RESULT_SUCCESS;
+}
+
+
+EXPORT_API int alarmmgr_get_global(const alarm_id_t alarm_id,
+                                       bool *global)
+{
+       bool _global;
+       int error_code;
+
+       if (global == NULL) {
+               return ERR_ALARM_INVALID_PARAM;
+       }
+
+       if (!_send_alarm_get_global(alarm_context, alarm_id, &_global, &error_code)) {
+               return error_code;
+       }
+
+       return ALARMMGR_RESULT_SUCCESS;
+}
+