Add methods to handle noti_template 25/80225/13 accepted/tizen/common/20160823.132637 accepted/tizen/ivi/20160824.021623 accepted/tizen/mobile/20160824.021501 accepted/tizen/tv/20160824.021541 accepted/tizen/wearable/20160824.021648 submit/tizen/20160822.060113
authorMyungki Lee <mk5004.lee@samsung.com>
Wed, 3 Aug 2016 07:12:11 +0000 (16:12 +0900)
committerMyungKi Lee <mk5004.lee@samsung.com>
Tue, 16 Aug 2016 01:56:47 +0000 (18:56 -0700)
Change-Id: Ie2237343537633dcb6b023f7c9e2f9d5319772dc
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
data-provider-master.conf.in
include/notification_service.h
include/service_common.h
src/notification_service.c
src/service_common.c

index 8651511..742f584 100644 (file)
@@ -14,6 +14,8 @@
                <check send_destination="org.tizen.data_provider_service" send_interface="org.tizen.data_provider_noti_service" send_member="del_noti_single" privilege="http://tizen.org/privilege/notification"/>
                <check send_destination="org.tizen.data_provider_service" send_interface="org.tizen.data_provider_noti_service" send_member="del_noti_multiple" privilege="http://tizen.org/privilege/notification"/>
                <check send_destination="org.tizen.data_provider_service" send_interface="org.tizen.data_provider_noti_service" send_member="load_noti_by_tag" privilege="http://tizen.org/privilege/notification"/>
+               <check send_destination="org.tizen.data_provider_service" send_interface="org.tizen.data_provider_noti_service" send_member="save_as_template" privilege="http://tizen.org/privilege/notification"/>
+               <check send_destination="org.tizen.data_provider_service" send_interface="org.tizen.data_provider_noti_service" send_member="create_from_template" privilege="http://tizen.org/privilege/notification"/>
                <check send_destination="org.tizen.data_provider_service" send_interface="org.tizen.data_provider_badge_service" privilege="http://tizen.org/privilege/notification"/>
                <check send_destination="org.tizen.data_provider_service" send_interface="org.tizen.data_provider_shortcut_service" privilege="http://tizen.org/privilege/shortcut"/>
        </policy>
index 1ba4d00..bb15042 100755 (executable)
@@ -36,6 +36,9 @@ int notification_load_detail_list(GVariant *parameters, GVariant **reply_body, u
 int notification_get_setting_array(GVariant *parameters, GVariant **reply_body, uid_t uid);
 int notification_get_setting_by_package_name(GVariant *parameters, GVariant **reply_body, uid_t uid);
 int notification_load_system_setting(GVariant *parameters, GVariant **reply_body, uid_t uid);
+int notification_add_noti_template(GVariant *parameters, GVariant **reply_body, uid_t uid);
+int notification_get_noti_template(GVariant *parameters, GVariant **reply_body, pid_t pid, uid_t uid);
+int notification_get_noti_package_template(GVariant *parameters, GVariant **reply_body, uid_t uid);
 int notification_register_dbus_interface();
 
 /* End of a file */
index 5cafa69..0b3af0d 100755 (executable)
@@ -58,6 +58,7 @@ int service_register(GVariant *parameters, GVariant **reply_body, const gchar *s
 GDBusConnection *service_common_get_connection();
 int service_common_register_dbus_interface(char *introspection_xml, GDBusInterfaceVTable interface_vtable);
 uid_t get_sender_uid(const char *sender_name);
+pid_t get_sender_pid(const char *sender_name);
 void free_monitoring_list(gpointer data);
 
 /* End of a file */
index 1259cc3..ca60f1a 100755 (executable)
@@ -24,6 +24,7 @@
 #include <notification.h>
 #include <gio/gio.h>
 #include <alarm.h>
+#include <aul.h>
 
 #include "pkgmgr.h"
 #include "service_common.h"
@@ -37,6 +38,8 @@
 #include <notification_db.h>
 
 #define PROVIDER_NOTI_INTERFACE_NAME "org.tizen.data_provider_noti_service"
+#define NOTI_TEMPLATE_LIMIT 10
+#define BUF_LEN 256
 
 typedef struct _dnd_alarm_id dnd_alarm_id_s;
 
@@ -90,7 +93,8 @@ static void _noti_dbus_method_call_handler(GDBusConnection *conn,
 
        GVariant *reply_body = NULL;
        int ret = NOTIFICATION_ERROR_INVALID_OPERATION;
-       int uid = get_sender_uid(sender);
+       uid_t uid = get_sender_uid(sender);
+       pid_t pid = get_sender_pid(sender);
 
        if (g_strcmp0(method_name, "noti_service_register") == 0)
                ret = service_register(parameters, &reply_body, sender,
@@ -125,6 +129,12 @@ static void _noti_dbus_method_call_handler(GDBusConnection *conn,
                ret = notification_get_setting_by_package_name(parameters, &reply_body, uid);
        else if (g_strcmp0(method_name, "load_system_setting") == 0)
                ret = notification_load_system_setting(parameters, &reply_body, uid);
+       else if (g_strcmp0(method_name, "save_as_template") == 0)
+               ret = notification_add_noti_template(parameters, &reply_body, uid);
+       else if (g_strcmp0(method_name, "create_from_template") == 0)
+               ret = notification_get_noti_template(parameters, &reply_body, pid, uid);
+       else if (g_strcmp0(method_name, "create_from_package_template") == 0)
+               ret = notification_get_noti_package_template(parameters, &reply_body, uid);
 
        if (ret == NOTIFICATION_ERROR_NONE) {
                DbgPrint("notification service success : %d", ret);
@@ -261,6 +271,22 @@ int notification_register_dbus_interface()
                        "          <arg type='v' name='setting' direction='out'/>"
                        "        </method>"
 
+                       "        <method name='save_as_template'>"
+                       "          <arg type='v' name='noti' direction='in'/>"
+                       "          <arg type='s' name='name' direction='in'/>"
+                       "        </method>"
+
+                       "        <method name='create_from_template'>"
+                       "          <arg type='s' name='name' direction='in'/>"
+                       "          <arg type='v' name='noti' direction='out'/>"
+                       "        </method>"
+
+                       "        <method name='create_from_package_template'>"
+                       "          <arg type='s' name='appid' direction='in'/>"
+                       "          <arg type='s' name='name' direction='in'/>"
+                       "          <arg type='v' name='noti' direction='out'/>"
+                       "        </method>"
+
                        "        <method name='post_toast'>"
                        "        </method>"
                        "  </interface>"
@@ -889,6 +915,7 @@ int notification_del_noti_multiple(GVariant *parameters, GVariant **reply_body,
                ErrPrint("cannot make reply_body");
                return NOTIFICATION_ERROR_OUT_OF_MEMORY;
        }
+
        DbgPrint("_del_noti_multiple done !!");
        return ret;
 }
@@ -1245,6 +1272,114 @@ int notification_update_noti_sys_setting(GVariant *parameters, GVariant **reply_
        return ret;
 }
 
+int notification_add_noti_template(GVariant *parameters, GVariant **reply_body, uid_t uid)
+{
+       notification_h noti;
+       int ret;
+       GVariant *body = NULL;
+       GVariant *coupled_body = NULL;
+       char *template_name = NULL;
+       int count = 0;
+
+       noti = notification_create(NOTIFICATION_TYPE_NOTI);
+       if (noti != NULL) {
+               g_variant_get(parameters, "(v&s)", &coupled_body, &template_name);
+               g_variant_get(coupled_body, "(v)", &body);
+
+               ret = notification_ipc_make_noti_from_gvariant(noti, body);
+               g_variant_unref(coupled_body);
+               g_variant_unref(body);
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       ErrPrint("failed to make a notification:%d\n", ret);
+                       return ret;
+               }
+
+               ret = notification_noti_check_count_for_template(noti, &count);
+               if (count > NOTI_TEMPLATE_LIMIT)
+                       return NOTIFICATION_ERROR_MAX_EXCEEDED;
+
+               ret = notification_noti_add_template(noti, template_name);
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       ErrPrint("failed to add a notification:%d\n", ret);
+                       return ret;
+               }
+       } else {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       return ret;
+}
+
+int notification_get_noti_template(GVariant *parameters, GVariant **reply_body, pid_t pid, uid_t uid)
+{
+       int ret;
+       char appid[BUF_LEN] = {0, };
+       char *template_name = NULL;
+       notification_h noti;
+
+       noti = notification_create(NOTIFICATION_TYPE_NOTI);
+       if (noti != NULL) {
+               g_variant_get(parameters, "(&s)", &template_name);
+
+               ret = aul_app_get_appid_bypid_for_uid(pid, appid, sizeof(appid), uid);
+               if (ret != AUL_R_OK) {
+                       ErrPrint("failed to get appid:%d", ret);
+                       return ret;
+               }
+
+               ret = notification_noti_get_package_template(noti, appid, template_name);
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       DbgPrint("failed to get template:%d", ret);
+                       return ret;
+               }
+
+               *reply_body = notification_ipc_make_gvariant_from_noti(noti, false);
+               notification_free(noti);
+
+               if (*reply_body == NULL) {
+                       ErrPrint("cannot make reply_body");
+                       return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               }
+       } else {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       DbgPrint("_get_noti_template done !!");
+       return ret;
+}
+
+int notification_get_noti_package_template(GVariant *parameters, GVariant **reply_body, uid_t uid)
+{
+       int ret;
+       char *pkgname = NULL;
+       char *template_name = NULL;
+       notification_h noti;
+
+       noti = notification_create(NOTIFICATION_TYPE_NOTI);
+       if (noti != NULL) {
+               g_variant_get(parameters, "(&s&s)", &pkgname, &template_name);
+
+               ret = notification_noti_get_package_template(noti, pkgname, template_name);
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       DbgPrint("failed to get template:%d", ret);
+                       return ret;
+               }
+
+               *reply_body = notification_ipc_make_gvariant_from_noti(noti, false);
+               notification_free(noti);
+
+               if (*reply_body == NULL) {
+                       ErrPrint("cannot make reply_body");
+                       return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               }
+       } else {
+               ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       DbgPrint("_get_noti_package_template done !!");
+       return ret;
+}
+
 static void _notification_data_init(void)
 {
        int property = 0;
@@ -1287,6 +1422,7 @@ static int _package_install_cb(uid_t uid, const char *pkgname, enum pkgmgr_statu
 static int _package_uninstall_cb(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value, void *data)
 {
        notification_setting_delete_package_for_uid(pkgname, uid);
+       notification_noti_delete_template(pkgname);
        return 0;
 }
 
index 8bb23ab..e1e044c 100755 (executable)
@@ -111,6 +111,45 @@ out:
        return uid;
 }
 
+pid_t get_sender_pid(const char *sender_name)
+{
+       GDBusMessage *msg = NULL;
+       GDBusMessage *reply = NULL;
+       GError *err = NULL;
+       GVariant *body;
+       pid_t pid = 0;
+
+       msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus",
+                       "org.freedesktop.DBus", "GetConnectionUnixProcessID");
+       if (!msg) {
+               LOGE("Can't allocate new method call");
+               goto out;
+       }
+
+       g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
+       reply = g_dbus_connection_send_message_with_reply_sync(_gdbus_conn, msg,
+                       G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
+
+       if (!reply) {
+               if (err != NULL) {
+                       LOGE("Failed to get uid [%s]", err->message);
+                       g_error_free(err);
+               }
+               goto out;
+       }
+
+       body = g_dbus_message_get_body(reply);
+       g_variant_get(body, "(u)", &pid);
+
+out:
+       if (msg)
+               g_object_unref(msg);
+       if (reply)
+               g_object_unref(reply);
+
+       return pid;
+}
+
 int send_notify(GVariant *body, char *cmd, GList *monitoring_app_list, char *interface_name)
 {
        GError *err = NULL;