Add check_privilege method. 47/71447/5 accepted/tizen/common/20160526.150334 accepted/tizen/ivi/20160526.094927 accepted/tizen/mobile/20160526.095122 accepted/tizen/tv/20160526.095007 accepted/tizen/wearable/20160526.095040 submit/tizen/20160526.062537
authorseungha.son <seungha.son@samsung.com>
Wed, 25 May 2016 10:38:16 +0000 (19:38 +0900)
committerseungha.son <seungha.son@samsung.com>
Thu, 26 May 2016 06:22:11 +0000 (15:22 +0900)
Add code for check the privilege of async API.

Signed-off-by: seungha.son <seungha.son@samsung.com>
Change-Id: I68a06d36474610d8610a193fd7f724dcd2c11bd8

lib/src/shortcut_manager.c

index b722687..f1506ee 100755 (executable)
@@ -339,7 +339,7 @@ static void _send_message_with_reply_sync_cb(GDBusConnection *connection,
        free(cb_item);
 }
 
-static int _send_async_noti(GVariant *body, struct result_cb_item *cb_item, char *cmd)
+static int _send_async_shortcut(GVariant *body, struct result_cb_item *cb_item, char *cmd)
 {
        GDBusMessage *msg;
        msg = g_dbus_message_new_method_call(
@@ -367,7 +367,7 @@ static int _send_async_noti(GVariant *body, struct result_cb_item *cb_item, char
 
        g_object_unref(msg);
 
-       DbgPrint("_send_async_noti done !!");
+       DbgPrint("_send_async_shortcut done !!");
        return SHORTCUT_ERROR_NONE;
 }
 
@@ -387,6 +387,19 @@ static void _on_name_vanished(GDBusConnection *connection,
        DbgPrint("name vanished : %s", name);
 }
 
+static int _check_privilege(void)
+{
+       GDBusMessage *reply = NULL;
+       int ret = SHORTCUT_ERROR_NONE;
+
+       ret = _send_sync_shortcut(NULL, &reply, "check_privilege");
+
+       if (reply)
+               g_object_unref(reply);
+
+       return ret;
+}
+
 EAPI int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data)
 {
        int ret = _dbus_init();
@@ -452,6 +465,10 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *
                return ret;
        }
 
+       ret = _check_privilege();
+       if (ret != SHORTCUT_ERROR_NONE)
+               return ret;
+
        appid = _shortcut_get_pkgname_by_pid();
        item = malloc(sizeof(struct result_cb_item));
        if (!item) {
@@ -476,7 +493,8 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *
                icon = "";
 
        body = g_variant_new("(ississi)", getpid(), appid, name, type, uri, icon, allow_duplicate);
-       ret = _send_async_noti(body, item, "add_shortcut");
+
+       ret = _send_async_shortcut(body, item, "add_shortcut");
        if (ret != SHORTCUT_ERROR_NONE) {
                free(item);
                item = NULL;
@@ -514,6 +532,10 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si
                return ret;
        }
 
+       ret = _check_privilege();
+       if (ret != SHORTCUT_ERROR_NONE)
+               return ret;
+
        appid = _shortcut_get_pkgname_by_pid();
        item = malloc(sizeof(struct result_cb_item));
        if (!item) {
@@ -529,7 +551,7 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si
        item->data = data;
 
        body = g_variant_new("(ississdi)", getpid(), widget_id, name, size, NULL, icon, period, allow_duplicate);
-       ret = _send_async_noti(body, item, "add_shortcut_widget");
+       ret = _send_async_shortcut(body, item, "add_shortcut_widget");
 
        if (ret != SHORTCUT_ERROR_NONE) {
                free(item);