Add new apis to set/get noti_template 24/80224/22
authorMyungki Lee <mk5004.lee@samsung.com>
Wed, 17 Aug 2016 04:19:36 +0000 (13:19 +0900)
committerMyungKi Lee <mk5004.lee@samsung.com>
Mon, 22 Aug 2016 06:31:17 +0000 (23:31 -0700)
Change-Id: I0499f225f6c0aee45e4b18b5671866de20ffc4a4
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
include/notification.h
include/notification_error.h
include/notification_internal.h
include/notification_ipc.h
include/notification_noti.h
src/notification.c
src/notification_db.c
src/notification_internal.c
src/notification_ipc.c
src/notification_noti.c

index 008d356e78b4d229b434f1f5f395d8ad61153c9a..bca06e32683a9f7555515e1b7266dbaac689a7f7 100755 (executable)
@@ -1442,6 +1442,82 @@ int notification_set_auto_remove(notification_h noti, bool auto_remove);
  */
 int notification_get_auto_remove(notification_h noti, bool *auto_remove);
 
+/**
+ * @brief Saves a notification template to the notification database.
+ * @details An application can save the created notification as a template for later reuse.
+ *          If the template has the same name as an saved one, the saved template will be overwritten.
+ *          A saved template can be loaded only by the application which saved it.
+ *          All templates are removed when the application package is uninstalled.
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/notification
+ * @remarks The number of templates is limited to 10.
+ *          When you try to add more than 10 templates, #NOTIFICATION_ERROR_MAX_EXCEEDED will be returned.
+ * @param[in] noti Notification handle
+ * @param[in] template_name Template name
+ * @return #NOTIFICATION_ERROR_NONE On success, other value on failure
+ * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #NOTIFICATION_ERROR_IO_ERROR I/O error
+ * @retval #NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #NOTIFICATION_ERROR_PERMISSION_DENIED The Permission denied
+ * @retval #NOTIFICATION_ERROR_MAX_EXCEEDED Max notification count exceeded
+ * @see #notification_h
+ * @see notification_create_from_template()
+ * @par Sample code:
+ * @code
+#include <notification.h>
+...
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       ...
+
+       noti_err = notification_save_as_template(noti, "CALL_ACCEPT");
+       if(noti_err != NOTIFICATION_ERROR_NONE) {
+               return;
+       }
+}
+ * @endcode
+ */
+int notification_save_as_template(notification_h noti, const char *template_name);
+
+/**
+ * @brief Loads a notification template from the notification database.
+ * @details An application can load a saved template and post it.
+ *          An application can load only templates that it has saved.
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/notification
+ * @remarks The returned handle should be destroyed using notification_free().
+ *          The specific error code can be obtained using get_last_result().
+ *          Error codes are described in the Exception section.
+ *          If an invalid template name is given, the result will be set to #NOTIFICATION_ERROR_FROM_DB.
+ * @param[in] template_name Template name
+ * @return Notification handle on success, NULL on failure
+ * @exception #NOTIFICATION_ERROR_NONE Success
+ * @exception #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid input value
+ * @exception #NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @exception #NOTIFICATION_ERROR_PERMISSION_DENIED The application does not have the privilege to call this method
+ * @exception #NOTIFICATION_ERROR_FROM_DB Error from DB query
+ * @see #notification_h
+ * @see notification_save_as_template()
+ * @par Sample code:
+ * @code
+#include <notification.h>
+...
+{
+       notification_h noti = NULL;
+
+       noti = notification_create_from_template("CALL_ACCEPT");
+       if(noti == NULL) {
+               return;
+       }
+       ...
+}
+ * @endcode
+ */
+notification_h notification_create_from_template(const char *template_name);
+
 /**
  * @}
  */
index 4d841a29f1f9794f378532069a329ca2fc595a78..f8e4576cb0083b2f19b536cf4888b4c66f615d16 100644 (file)
@@ -38,12 +38,13 @@ typedef enum _notification_error {
        NOTIFICATION_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,   /**< out of memory */
        NOTIFICATION_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR,     /**< I/O error */
        NOTIFICATION_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+       NOTIFICATION_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Function not implemented (@b Since: @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
        NOTIFICATION_ERROR_FROM_DB = TIZEN_ERROR_NOTIFICATION | 0x01,   /**< Error from DB query */
        NOTIFICATION_ERROR_ALREADY_EXIST_ID = TIZEN_ERROR_NOTIFICATION | 0x02,  /**< Already exist private ID */
        NOTIFICATION_ERROR_FROM_DBUS = TIZEN_ERROR_NOTIFICATION | 0x03, /**< Error from DBus */
        NOTIFICATION_ERROR_NOT_EXIST_ID = TIZEN_ERROR_NOTIFICATION | 0x04,      /**< Not exist private ID */
        NOTIFICATION_ERROR_SERVICE_NOT_READY = TIZEN_ERROR_NOTIFICATION | 0x05, /**< No response from notification service */
-       NOTIFICATION_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Function not implemented (@b Since: @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif) */
+       NOTIFICATION_ERROR_MAX_EXCEEDED = TIZEN_ERROR_NOTIFICATION | 0x06,      /**< Max notification count exceeded (@b Since: 3.0) */
 } notification_error_e;
 
 /**
index 5db7d7fcd19aaaa282e0edb5e40e5abf6f855e21..e7ede7dabf2ffb88e5ef1200c4768dd07d00e461 100644 (file)
@@ -739,6 +739,8 @@ int notification_update_for_uid(notification_h noti, uid_t uid);
 int notification_delete_for_uid(notification_h noti, uid_t uid);
 int notification_delete_all_for_uid(notification_type_e type, uid_t uid);
 notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid);
+notification_h notification_create_from_package_template(const char *pkgname,
+                                       const char *template_name);
 
 /**
  * @}
index 2f16815edfbd8b9ce2fd623072801b9d43a1fd8c..fda5f9586d4a31c9461a52fd47670e88783dcaa8 100755 (executable)
@@ -83,6 +83,12 @@ int notification_ipc_request_load_noti_by_priv_id(notification_h noti,
 int notification_ipc_request_load_noti_detail_list(const char *pkgname,
                int group_id, int priv_id, int count,
                notification_list_h *list, uid_t uid);
+int notification_ipc_request_save_as_template(notification_h noti, const char *template_name);
+int notification_ipc_request_create_from_template(notification_h noti, const char *template_name);
+int notification_ipc_request_create_from_package_template(notification_h noti,
+               const char *pkgname, const char *template_name);
+
+
 
 #ifdef __cplusplus
 }
index 58d6c6f25c5f7376850d1fd642234e3888f5167a..bdef709130da5d1314637613b983736a5c49f887 100644 (file)
@@ -61,6 +61,11 @@ int notification_noti_get_detail_list(const char *pkgname,
                uid_t uid);
 
 int notification_noti_check_tag(notification_h noti);
+int notification_noti_check_count_for_template(notification_h noti, int *count);
+
+int notification_noti_add_template(notification_h noti, char *template_name);
+int notification_noti_get_package_template(notification_h noti, char *pkgname, char *template_name);
+int notification_noti_delete_template(const char *pkgname);
 
 #endif /* __NOTIFICATION_NOTI_H__ */
 
index d1a0f2afac0ba44a5be21550f2f3735d0712681a..1cc9f0426c66cd726d450cf1011d58fe11b85dbb 100755 (executable)
@@ -1502,7 +1502,7 @@ EXPORT_API notification_h notification_create(notification_type_e type)
        return _notification_create(type);
 }
 
-EXPORT_API notification_h  notification_load_by_tag(const char *tag)
+EXPORT_API notification_h notification_load_by_tag(const char *tag)
 {
        return notification_load_by_tag_for_uid(tag, getuid());
 }
@@ -1829,3 +1829,41 @@ EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remo
        return NOTIFICATION_ERROR_NONE;
 }
 
+EXPORT_API int notification_save_as_template(notification_h noti, const char *template_name)
+{
+       if (noti == NULL || template_name == NULL) {
+               NOTIFICATION_ERR("Invalid parameter");
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+       }
+
+       return notification_ipc_request_save_as_template(noti, template_name);
+}
+
+EXPORT_API notification_h notification_create_from_template(const char *template_name)
+{
+       int ret = 0;
+       notification_h noti = NULL;
+
+       if (template_name == NULL) {
+               NOTIFICATION_ERR("Invalid parameter");
+               set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
+               return NULL;
+       }
+
+       noti = (notification_h)calloc(1, sizeof(struct _notification));
+       if (noti == NULL) {
+               NOTIFICATION_ERR("Failed to alloc a new notification");
+               set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
+               return NULL;
+       }
+
+       ret = notification_ipc_request_create_from_template(noti, template_name);
+
+       set_last_result(ret);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               notification_free(noti);
+               return NULL;
+       }
+
+       return noti;
+}
index 0a0e4d7e9336c0308a971a210de2e8b43a454542..9dbd342bddb8af8048dc08ef4eefc84bacea1bcc 100755 (executable)
@@ -138,8 +138,61 @@ create     table if not exists noti_list ( \
                        dnd_end_min INTEGER DEFAULT 0, \
                        lock_screen_content_level INTEGER DEFAULT 0, \
                        UNIQUE (uid) \
+               );\
+               CREATE TABLE IF NOT EXISTS noti_template ( \
+                       type INTEGER NOT NULL, \
+                       layout INTEGER NOT NULL default 0, \
+                       caller_pkgname TEXT NOT NULL, \
+                       launch_pkgname TEXT, \
+                       image_path TEXT, \
+                       group_id INTEGER default 0,  \
+                       internal_group_id INTEGER default 0,  \
+                       priv_id INTEGER PRIMARY KEY AUTOINCREMENT,  \
+                       title_key TEXT, \
+                       b_text TEXT, \
+                       b_key TEXT, \
+                       tag TEXT, \
+                       b_format_args TEXT, \
+                       num_format_args INTEGER default 0, \
+                       text_domain TEXT, \
+                       text_dir TEXT, \
+                       time INTEGER default 0, \
+                       insert_time INTEGER default 0, \
+                       args TEXT, \
+                       group_args TEXT, \
+                       b_execute_option TEXT, \
+                       b_service_responding TEXT, \
+                       b_service_single_launch TEXT, \
+                       b_service_multi_launch TEXT, \
+                       b_event_handler_click_on_button_1 TEXT, \
+                       b_event_handler_click_on_button_2 TEXT, \
+                       b_event_handler_click_on_button_3 TEXT, \
+                       b_event_handler_click_on_button_4 TEXT, \
+                       b_event_handler_click_on_button_5 TEXT, \
+                       b_event_handler_click_on_button_6 TEXT, \
+                       b_event_handler_click_on_icon TEXT, \
+                       b_event_handler_click_on_thumbnail TEXT, \
+                       sound_type INTEGER default 0, \
+                       sound_path TEXT, \
+                       vibration_type INTEGER default 0, \
+                       vibration_path TEXT, \
+                       led_operation INTEGER default 0, \
+                       led_argb INTEGER default 0, \
+                       led_on_ms INTEGER default -1, \
+                       led_off_ms INTEGER default -1, \
+                       flags_for_property INTEGER default 0, \
+                       flag_simmode INTEGER default 0, \
+                       display_applist INTEGER, \
+                       progress_size DOUBLE default 0, \
+                       progress_percentage DOUBLE default 0, \
+                       ongoing_flag INTEGER default 0, \
+                       auto_remove INTEGER default 1, \
+                       uid INTEGER, \
+                       template_name TEXT, \
+                       UNIQUE (caller_pkgname, template_name) \
                );"
 
+
 EXPORT_API int notification_db_init()
 {
        int r;
index 4fbe665aadc271cdb98706be7262250f96ec7344..337066b5e47e9b804571d2dfb68b723631329d19 100755 (executable)
@@ -1281,3 +1281,32 @@ EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_
 
        return noti;
 }
+
+EXPORT_API notification_h notification_create_from_package_template(const char *pkgname, const char *template_name)
+{
+       int ret = 0;
+       notification_h noti = NULL;
+
+       if (pkgname == NULL || template_name == NULL) {
+               NOTIFICATION_ERR("Invalid parameter");
+               set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
+               return NULL;
+       }
+
+       noti = (notification_h)calloc(1, sizeof(struct _notification));
+       if (noti == NULL) {
+               NOTIFICATION_ERR("Failed to alloc a new notification");
+               set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
+               return NULL;
+       }
+
+       ret = notification_ipc_request_create_from_package_template(noti, pkgname, template_name);
+
+       set_last_result(ret);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               notification_free(noti);
+               return NULL;
+       }
+
+       return noti;
+}
index ba91a6c0d333b7d2799f0e5d34dbcb6434a8bdc2..1dddb1636deadccb413103f89dccf66c73002459 100755 (executable)
@@ -1321,6 +1321,108 @@ int notification_ipc_update_system_setting(notification_system_setting_h system_
        return result;
 }
 
+int notification_ipc_request_save_as_template(notification_h noti, const char *template_name)
+{
+       int result;
+       GDBusMessage *reply = NULL;
+       GVariant *body;
+
+       result = _dbus_init();
+       if (result != NOTIFICATION_ERROR_NONE) {
+               NOTIFICATION_ERR("Can't init dbus %d", result);
+               return result;
+       }
+
+       body = notification_ipc_make_gvariant_from_noti(noti, false);
+       if (body == NULL) {
+               NOTIFICATION_ERR("cannot make gvariant");
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       result = _send_sync_noti(g_variant_new("(vs)", body, template_name), &reply, "save_as_template");
+
+       if (reply)
+               g_object_unref(reply);
+
+       NOTIFICATION_DBG("notification_ipc_request_save_as_template [result: %d]", result);
+       return result;
+}
+
+int notification_ipc_request_create_from_template(notification_h noti, const char *template_name)
+{
+       int result;
+       GDBusMessage *reply = NULL;
+       GVariant *body;
+       GVariant *reply_body;
+       GVariant *noti_body;
+
+       if (!template_name)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       result = _dbus_init();
+       if (result != NOTIFICATION_ERROR_NONE) {
+               NOTIFICATION_ERR("Can't init dbus %d", result);
+               return result;
+       }
+
+       body = g_variant_new("(s)", template_name);
+
+       result = _send_sync_noti(body, &reply, "create_from_template");
+       if (result == NOTIFICATION_ERROR_NONE) {
+               reply_body = g_dbus_message_get_body(reply);
+               g_variant_get(reply_body, "(v)", &noti_body);
+
+               notification_ipc_make_noti_from_gvariant(noti, noti_body);
+               g_variant_unref(noti_body);
+               _print_noti(noti);
+
+       }
+
+       if (reply)
+               g_object_unref(reply);
+
+       NOTIFICATION_DBG("notification_ipc_request_create_from_template done [result: %d]", result);
+
+       return result;
+}
+
+int notification_ipc_request_create_from_package_template(notification_h noti, const char *pkgname, const char *template_name)
+{
+       int result;
+       GDBusMessage *reply = NULL;
+       GVariant *body;
+       GVariant *reply_body;
+       GVariant *noti_body;
+
+       if (pkgname == NULL || template_name == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       result = _dbus_init();
+       if (result != NOTIFICATION_ERROR_NONE) {
+               NOTIFICATION_ERR("Can't init dbus %d", result);
+               return result;
+       }
+
+       body = g_variant_new("(ss)", pkgname, template_name);
+
+       result = _send_sync_noti(body, &reply, "create_from_package_template");
+       if (result == NOTIFICATION_ERROR_NONE) {
+               reply_body = g_dbus_message_get_body(reply);
+               g_variant_get(reply_body, "(v)", &noti_body);
+
+               notification_ipc_make_noti_from_gvariant(noti, noti_body);
+               g_variant_unref(noti_body);
+               _print_noti(noti);
+       }
+
+       if (reply)
+               g_object_unref(reply);
+
+       NOTIFICATION_DBG("notification_ipc_request_create_from_package_template [result: %d]", result);
+
+       return result;
+}
+
 EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti, bool translate)
 {
        NOTIFICATION_DBG("make gvariant from noti");
index 1b6b8541b0f109299197dc6af92163e59288655f..e413268c6d6ef81214c6f58e6e0118cbf2172c41 100755 (executable)
@@ -991,7 +991,7 @@ EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, char *pkgna
                query = sqlite3_mprintf("%s where caller_pkgname = '%s' and priv_id = %d and uid = %d",
                                base_query, pkgname, priv_id, uid);
        else
-               query = sqlite3_mprintf("%s where priv_id = %d and uid = %d", base_query,  priv_id, uid);
+               query = sqlite3_mprintf("%s where priv_id = %d and uid = %d", base_query, priv_id, uid);
 
        if (query == NULL) {
                ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
@@ -1029,7 +1029,7 @@ err:
 }
 /* LCOV_EXCL_STOP */
 
-EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, chartag, uid_t uid)
+EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char *tag, uid_t uid)
 {
        int ret = 0;
        sqlite3 *db = NULL;
@@ -1771,3 +1771,413 @@ err:
        return ret;
 }
 
+EXPORT_API int notification_noti_check_count_for_template(notification_h noti, int *count)
+{
+       int result = 0;
+       int ret = NOTIFICATION_ERROR_NONE;
+       sqlite3 *db;
+       sqlite3_stmt *stmt = NULL;
+
+       if (noti == NULL || count == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
+
+       ret = sqlite3_prepare_v2(db, "SELECT COUNT(caller_pkgname) FROM noti_template WHERE caller_pkgname = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+               if (db)
+                       notification_db_close(&db);
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+               goto err;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW)
+               result = sqlite3_column_int(stmt, 0);
+       else
+               result = 0;
+
+       *count = result;
+
+       sqlite3_finalize(stmt);
+err:
+       if (db)
+               notification_db_close(&db);
+
+       return ret;
+}
+
+static int _template_query_create(notification_h noti, char *template_name, char **query)
+{
+       int i = 0;
+       int b_encode_len = 0;
+       char *args = NULL;
+       char *group_args = NULL;
+       char *b_image_path = NULL;
+       char *b_execute_option = NULL;
+       char *b_service_responding = NULL;
+       char *b_service_single_launch = NULL;
+       char *b_service_multi_launch = NULL;
+       char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
+       char *b_text = NULL;
+       char *b_key = NULL;
+       char *b_format_args = NULL;
+       int flag_simmode = 0;
+
+       if (query == NULL || template_name == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       /* Decode bundle to insert DB */
+       if (noti->args)
+               bundle_encode(noti->args, (bundle_raw **)&args, &b_encode_len);
+
+       if (noti->group_args)
+               bundle_encode(noti->group_args, (bundle_raw **)&group_args,
+                             &b_encode_len);
+
+       if (noti->b_execute_option)
+               bundle_encode(noti->b_execute_option,
+                             (bundle_raw **)&b_execute_option, &b_encode_len);
+
+       if (noti->b_service_responding)
+               bundle_encode(noti->b_service_responding,
+                             (bundle_raw **)&b_service_responding, &b_encode_len);
+
+       if (noti->b_service_single_launch)
+               bundle_encode(noti->b_service_single_launch,
+                             (bundle_raw **)&b_service_single_launch, &b_encode_len);
+
+       if (noti->b_service_multi_launch)
+               bundle_encode(noti->b_service_multi_launch,
+                             (bundle_raw **)&b_service_multi_launch, &b_encode_len);
+
+
+       for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
+               if (noti->b_event_handler[i])
+                       bundle_encode(noti->b_event_handler[i],
+                                       (bundle_raw **)&b_event_handler[i], &b_encode_len);
+       }
+
+       if (noti->b_text)
+               bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
+
+       if (noti->b_key)
+               bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
+
+       if (noti->b_format_args)
+               bundle_encode(noti->b_format_args,
+                             (bundle_raw **)&b_format_args, &b_encode_len);
+
+       if (noti->b_image_path)
+               bundle_encode(noti->b_image_path,
+                             (bundle_raw **)&b_image_path, &b_encode_len);
+
+       /* Check only simmode property is enable */
+       if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
+               flag_simmode = 1;
+
+       *query = sqlite3_mprintf("INSERT OR REPLACE INTO noti_template ("
+               "type, "
+               "layout, "
+               "caller_pkgname, launch_pkgname, "
+               "image_path, "
+               "group_id, internal_group_id,"
+               "title_key, "
+               "b_text, b_key, tag, b_format_args, num_format_args, "
+               "text_domain, text_dir, "
+               "time, insert_time, "
+               "args, group_args, "
+               "b_execute_option, "
+               "b_service_responding, b_service_single_launch, b_service_multi_launch, "
+               "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
+               "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
+               "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
+               "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
+               "flags_for_property, flag_simmode, display_applist, "
+               "progress_size, progress_percentage, ongoing_flag, auto_remove, uid, template_name) values ("
+               "%d, "
+               "%d, "
+               "'%s', '%s', "
+               "'%s', "
+               "%d, %d,"
+               "$title_key, "
+               "'%s', '%s', $tag, '%s', %d, "
+               "'%s', '%s', "
+               "%d, %d, "
+               "'%s', '%s', "
+               "'%s', "
+               "'%s', '%s', '%s', "
+               "'%s', '%s', '%s', "
+               "'%s', '%s', '%s', "
+               "'%s', '%s', "
+               "%d, '%s', %d, '%s', %d, %d, %d, %d,"
+               "%d, %d, %d, "
+               "$progress_size, $progress_percentage, %d, %d, %d, '%s')",
+               noti->type,
+               noti->layout,
+               NOTIFICATION_CHECK_STR(noti->caller_pkgname),
+               NOTIFICATION_CHECK_STR(noti->launch_pkgname),
+               NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
+               noti->internal_group_id,
+               NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
+               NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
+               NOTIFICATION_CHECK_STR(noti->domain),
+               NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
+               (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
+               NOTIFICATION_CHECK_STR(group_args),
+               NOTIFICATION_CHECK_STR(b_execute_option),
+               NOTIFICATION_CHECK_STR(b_service_responding),
+               NOTIFICATION_CHECK_STR(b_service_single_launch),
+               NOTIFICATION_CHECK_STR(b_service_multi_launch),
+               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
+               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
+               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
+               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
+               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
+               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
+               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
+               NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
+               noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
+               noti->vibration_type,
+               NOTIFICATION_CHECK_STR(noti->vibration_path),
+               noti->led_operation,
+               noti->led_argb,
+               noti->led_on_ms,
+               noti->led_off_ms,
+               noti->flags_for_property, flag_simmode, noti->display_applist,
+               noti->ongoing_flag,
+               noti->auto_remove,
+               noti->uid,
+               template_name);
+
+       /* Free decoded data */
+       if (args)
+               free(args);
+
+       if (group_args)
+               free(group_args);
+
+       if (b_execute_option)
+               free(b_execute_option);
+
+       if (b_service_responding)
+               free(b_service_responding);
+
+       if (b_service_single_launch)
+               free(b_service_single_launch);
+
+       if (b_service_multi_launch)
+               free(b_service_multi_launch);
+
+       if (b_text)
+               free(b_text);
+
+       if (b_key)
+               free(b_key);
+
+       if (b_format_args)
+               free(b_format_args);
+
+       if (b_image_path)
+               free(b_image_path);
+
+       if (*query == NULL)
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_noti_add_template(notification_h noti, char *template_name)
+{
+       int ret = 0;
+       sqlite3 *db = NULL;
+       sqlite3_stmt *stmt = NULL;
+       char *query = NULL;
+       char buf_key[32] = { 0, };
+       char *title_key = NULL;
+
+       if (noti == NULL || template_name == NULL) {
+               NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+       }
+
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
+
+       /* Initialize private ID */
+       noti->group_id = NOTIFICATION_GROUP_ID_NONE;
+       noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
+
+       ret = _template_query_create(noti, template_name, &query);
+       if (ret != NOTIFICATION_ERROR_NONE)
+               goto err;
+
+       ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               NOTIFICATION_ERR("Insert Query : %s", query);
+               NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
+                                sqlite3_errmsg(db));
+               ret = NOTIFICATION_ERROR_FROM_DB;
+               goto err;
+       }
+
+       /* Get title key */
+       if (noti->b_key != NULL) {
+               snprintf(buf_key, sizeof(buf_key), "%d",
+                        NOTIFICATION_TEXT_TYPE_TITLE);
+
+               bundle_get_str(noti->b_key, buf_key, &title_key);
+       }
+
+       if (title_key == NULL && noti->b_text != NULL) {
+               snprintf(buf_key, sizeof(buf_key), "%d",
+                        NOTIFICATION_TEXT_TYPE_TITLE);
+
+               bundle_get_str(noti->b_text, buf_key, &title_key);
+       }
+
+       if (title_key == NULL)
+               title_key = noti->caller_pkgname;
+
+       /* Bind query */
+       ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
+               goto err;
+       }
+       ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
+               goto err;
+       }
+       ret = _notification_noti_bind_query_double(stmt, "$progress_size", noti->progress_size);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
+               goto err;
+       }
+       ret = _notification_noti_bind_query_double(stmt, "$progress_percentage", noti->progress_percentage);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
+               goto err;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_OK || ret == SQLITE_DONE) {
+               noti->priv_id = (int)sqlite3_last_insert_rowid(db);
+
+               if (_notification_noti_update_priv_id(db, noti->priv_id) == 0)
+                       ret = NOTIFICATION_ERROR_NONE;
+               else
+                       ret = NOTIFICATION_ERROR_FROM_DB;
+
+       } else {
+               ret = NOTIFICATION_ERROR_FROM_DB;
+       }
+err:
+       if (stmt)
+               sqlite3_finalize(stmt);
+
+       if (db)
+               notification_db_close(&db);
+
+       if (query)
+               sqlite3_free(query);
+
+       return ret;
+}
+
+EXPORT_API int notification_noti_get_package_template(notification_h noti, char *pkgname, char *template_name)
+{
+       int ret = 0;
+       sqlite3 *db = NULL;
+       sqlite3_stmt *stmt = NULL;
+
+       if (noti == NULL || pkgname == NULL || template_name == NULL) {
+               NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+       }
+
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
+
+       ret = sqlite3_prepare_v2(db, "select "
+               "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
+               "tag, b_text, b_key, b_format_args, num_format_args, "
+               "text_domain, text_dir, time, insert_time, args, group_args, "
+               "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
+               "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
+               "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
+               "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
+               "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
+               "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
+               "from noti_template where caller_pkgname = ? and template_name = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1,  pkgname, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+               goto err;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2,  template_name, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+               goto err;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW) {
+               _notification_noti_populate_from_stmt(stmt, noti);
+               ret = NOTIFICATION_ERROR_NONE;
+       } else {
+               NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB");
+               ret = NOTIFICATION_ERROR_FROM_DB;
+       }
+
+err:
+
+       if (stmt)
+               sqlite3_finalize(stmt);
+
+       if (db != NULL)
+               notification_db_close(&db);
+
+       return ret;
+}
+
+EXPORT_API int notification_noti_delete_template(const char *pkgname)
+{
+       sqlite3 *db = NULL;
+       char query[NOTIFICATION_QUERY_MAX] = { 0, };
+       int ret;
+
+       if (pkgname == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       db = notification_db_open(DBPATH);
+       if (!db)
+               return get_last_result();
+
+       snprintf(query, sizeof(query), "delete from noti_template "
+                "where caller_pkgname = '%s'", pkgname);
+
+       ret = notification_db_exec(db, query, NULL);
+
+       if (db)
+               notification_db_close(&db);
+
+       return ret;
+}