Add new api to set/get app label 09/164109/8
authorMyungki Lee <mk5004.lee@samsung.com>
Fri, 15 Dec 2017 09:05:17 +0000 (18:05 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Thu, 21 Dec 2017 05:49:03 +0000 (14:49 +0900)
- Use the existing app_name attribute of noti struct
- Add app_label to the DB

Change-Id: I6996c385a7394fc35deab7d6c972500dc81fb19d
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
include/notification_internal.h
include/notification_private.h
scripts/505.notification_upgrade.sh
src/notification.c
src/notification_db_query.h
src/notification_internal.c
src/notification_ipc.c
src/notification_noti.c

index 216f9ca..d90aaf5 100755 (executable)
@@ -1494,6 +1494,67 @@ int notification_get_extension_event_handler(notification_h noti,
                                        app_control_h *event_handler);
 
 /**
+ * @internal
+ * @brief Sets the label of caller application.
+ * @details It recommends for daemons. For an Application, the label is set when notification create.
+ * @since tizen 5.0
+ * @param[in] noti Notification handle
+ * @param[in] label Label of Caller application
+ * @return NOTIFICATION_ERROR_NONE on success, other value on failure
+ * @retval NOTIFICATION_ERROR_NONE Success
+ * @retval NOTIFICATION_ERROR_INVALID_PARAMETER Invalid input value
+ * @par Sample code:
+ * @code
+#include <notification.h>
+...
+{
+       notification_h noti = NULL;
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       noti = notification_create(NOTIFICATION_TYPE_NOTI);
+       if (noti == NULL) {
+               return;
+       }
+
+       noti_err  = notification_set_app_label(noti, "message");
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               notification_free(noti);
+               return;
+       }
+}
+ * @endcode
+ */
+int notification_set_app_label(notification_h noti, char *label);
+
+/**
+ * @internal
+ * @brief Gets the label of caller application
+ * @details Label may be null if it was not set.
+ * Do not free @a label. It will be freed when notification_free() is called.
+ * @since tizen 5.0
+ * @param[in] noti Notification handle
+ * @param[out] label Label of Caller application
+ * @return NOTIFICATION_ERROR_NONE on success, other value on failure
+ * @retval NOTIFICATION_ERROR_NONE Success
+ * @retval NOTIFICATION_ERROR_INVALID_PARAMETER Invalid input value
+ * @par Sample code:
+ * @code
+#include <notification.h>
+...
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+       char *label = NULL;
+
+       noti_err  = notification_get_app_label(noti, &label);
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               return;
+       }
+}
+ * @endcode
+ */
+int notification_get_app_label(notification_h noti, char **label);
+
+/**
  * @}
  */
 #ifdef __cplusplus
index 95ff378..c0f8c97 100755 (executable)
@@ -85,7 +85,7 @@ struct _notification {
        double progress_percentage;     /* percentage of progress */
 
        char *app_icon_path;    /* Temporary stored app icon path from AIL */
-       char *app_name;         /* Temporary stored app name from AIL */
+       char *app_label;
        char *temp_title;
        char *temp_content;
        char *tag;
@@ -154,7 +154,7 @@ typedef enum notification_data_type {
        NOTIFICATION_DATA_TYPE_PROGRESS_SIZE,
        NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE,
        NOTIFICATION_DATA_TYPE_APP_ICON_PATH,
-       NOTIFICATION_DATA_TYPE_APP_NAME,
+       NOTIFICATION_DATA_TYPE_APP_LABEL,
        NOTIFICATION_DATA_TYPE_TEMP_TITLE,
        NOTIFICATION_DATA_TYPE_TEMP_CONTENT,
        NOTIFICATION_DATA_TYPE_TAG,
index 2b73cc7..90590cd 100644 (file)
@@ -38,6 +38,7 @@ CREATE TABLE noti_list_temp (
        pkg_id TEXT NOT NULL,
        caller_app_id TEXT NOT NULL,
        launch_app_id TEXT,
+       app_label TEXT,
        image_path TEXT,
        priv_image_path TEXT,
        group_id INTEGER default 0,
@@ -159,6 +160,7 @@ CREATE TABLE noti_template_temp (
        pkg_id TEXT NOT NULL,
        caller_app_id TEXT NOT NULL,
        launch_app_id TEXT,
+       app_label TEXT,
        image_path TEXT,
        priv_image_path TEXT,
        group_id INTEGER default 0,
index 0d5ed57..b3f4069 100755 (executable)
@@ -28,6 +28,8 @@
 #include <package_manager.h>
 #include <aul.h>
 #include <tizen.h>
+#include <pkgmgr-info.h>
+#include <pkgmgrinfo_type.h>
 
 #include <notification.h>
 #include <notification_list.h>
@@ -1425,7 +1427,7 @@ EXPORT_API int notification_delete(notification_h noti)
        return notification_delete_for_uid(noti, getuid());
 }
 
-static int _notification_get_app_name(const char *app_id, char **name)
+static int _notification_get_domain_name(const char *app_id, char **name)
 {
        char *name_token = NULL;
 
@@ -1451,8 +1453,10 @@ static notification_h _notification_create(notification_type_e type)
 #define NOTI_PKG_ID_LEN 512
        notification_h noti = NULL;
        package_info_h package_info = NULL;
+       pkgmgrinfo_appinfo_h appinfo = NULL;
        char *domain_name = NULL;
        char *app_root_path = NULL;
+       char *label = NULL;
        char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
        char pkg_id[NOTI_PKG_ID_LEN + 1] = { 0, };
        int err = 0;
@@ -1511,7 +1515,7 @@ static notification_h _notification_create(notification_type_e type)
                        goto out;
                }
 
-               err = _notification_get_app_name(pkg_id, &domain_name);
+               err = _notification_get_domain_name(pkg_id, &domain_name);
                if (err != 0 || domain_name == NULL) {
                        NOTIFICATION_WARN("Failed to get domain_name");
                        err = 0;
@@ -1520,6 +1524,8 @@ static notification_h _notification_create(notification_type_e type)
                        goto out;
                }
 
+               noti->domain = strdup(domain_name);
+
                err = package_info_create(pkg_id, &package_info);
                if (err != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
                        /* LCOV_EXCL_START */
@@ -1539,9 +1545,25 @@ static notification_h _notification_create(notification_type_e type)
                }
 
                snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
-
-               noti->domain = strdup(domain_name);
                noti->dir    = strdup(locale_directory);
+
+               err = pkgmgrinfo_appinfo_get_usr_appinfo(noti->caller_app_id,
+                                       getuid(), &appinfo);
+               if (err != PMINFO_R_OK || appinfo == NULL) {
+                       NOTIFICATION_WARN("Failed to get appinfo err[%d]",
+                                       err, noti->caller_app_id);
+                       err = 0;
+                       goto out;
+               }
+
+               err = pkgmgrinfo_appinfo_get_label(appinfo, &label);
+               if (err != PMINFO_R_OK || label == NULL) {
+                       NOTIFICATION_WARN("Failed to get app_label err[%d]", err);
+                       err = 0;
+                       goto out;
+               }
+
+               noti->app_label = strdup(label);
        }
 
 out:
@@ -1554,6 +1576,9 @@ out:
        if (package_info)
                package_info_destroy(package_info);
 
+       if (appinfo)
+               pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
+
        if (err != 0) {
                notification_free(noti);
                noti = NULL;
@@ -1701,6 +1726,10 @@ EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
        new_noti->event_flag = noti->event_flag;
        new_noti->is_translation = noti->is_translation;
        new_noti->extension_image_size = noti->extension_image_size;
+
+       if (noti->app_label != NULL)
+               new_noti->app_label = strdup(noti->app_label);
+
        new_noti->uid = noti->uid;
 
        *clone = new_noti;
@@ -1782,8 +1811,8 @@ EXPORT_API int notification_free(notification_h noti)
        if (noti->app_icon_path)
                free(noti->app_icon_path);
 
-       if (noti->app_name)
-               free(noti->app_name);
+       if (noti->app_label)
+               free(noti->app_label);
 
        if (noti->temp_title)
                free(noti->temp_title);
index 37cf83c..19a2da5 100755 (executable)
@@ -28,6 +28,7 @@
        "  pkg_id TEXT NOT NULL,\n" \
        "  caller_app_id TEXT NOT NULL,\n" \
        "  launch_app_id TEXT,\n" \
+       "  app_label TEXT,\n" \
        "  image_path TEXT,\n" \
        "  priv_image_path TEXT,\n" \
        "  group_id INTEGER DEFAULT 0,\n" \
        "  pkg_id TEXT NOT NULL,\n" \
        "  caller_app_id TEXT NOT NULL,\n" \
        "  launch_app_id TEXT,\n" \
+       "  app_label TEXT,\n" \
        "  image_path TEXT,\n" \
        "  priv_image_path TEXT,\n" \
        "  group_id INTEGER DEFAULT 0,\n" \
        "  UNIQUE (caller_app_id, template_name));\n"
 
 #define NOTI_LIST_DB_ATTRIBUTES_SELECT \
-       "type, layout, pkg_id, caller_app_id, launch_app_id, image_path, " \
-       "priv_image_path, group_id, priv_id, b_text, b_key, " \
+       "type, layout, pkg_id, caller_app_id, launch_app_id, app_label, "\
+       "image_path, priv_image_path, group_id, priv_id, 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, " \
        "extension_image_size, uid"
 
 #define NOTI_LIST_DB_ATTRIBUTES_INSERT \
-       "type, layout, pkg_id, caller_app_id, launch_app_id, image_path, " \
-       "priv_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, " \
+       "type, layout, pkg_id, caller_app_id, launch_app_id, app_label, " \
+       "image_path, priv_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, " \
        "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " \
        "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " \
        "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " \
-       "? "
+       "?, ? "
 
 #define NOTI_LIST_DB_ATTRIBUTES_UPDATE \
-       "type = ?, layout = ?, launch_app_id = ?, image_path = ?, " \
-       "priv_image_path = ?, b_text = ?, b_key = ?, tag = ?, " \
+       "type = ?, layout = ?, launch_app_id = ?, app_label = ?, " \
+       "image_path = ?, priv_image_path = ?, 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 = ?, " \
        "ongoing_current = ?, ongoing_duration = ?, " \
        "auto_remove = ?, default_button_index = ?, " \
        "hide_timeout = ?, delete_timeout = ?, " \
-       "text_input_max_length = ?, event_flag = ?, extension_image_size = ?"
+       "text_input_max_length = ?, event_flag = ?, extension_image_size = ? "
 
 #define NOTIFICATION_SETTING_DB_ATTRIBUTES \
        "package_name, app_id, allow_to_notify, do_not_disturb_except, "\
index ca82988..2516bc8 100755 (executable)
@@ -2018,3 +2018,26 @@ EXPORT_API int notification_get_all_count(notification_type_e type, int *count)
        return notification_get_all_count_for_uid(type, count, getuid());
 }
 
+EXPORT_API int notification_set_app_label(notification_h noti, char *label)
+{
+       if (noti == NULL || label == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       if (noti->app_label)
+               free(noti->app_label);
+
+       noti->app_label = strdup(label);
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_get_app_label(notification_h noti, char **label)
+{
+       if (noti == NULL || label == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       if (noti->app_label)
+               *label = noti->app_label;
+
+       return NOTIFICATION_ERROR_NONE;
+}
index 78658e9..fd625c6 100755 (executable)
@@ -1980,8 +1980,8 @@ EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h not
 
        if (noti->app_icon_path != NULL)
                g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_ICON_PATH, g_variant_new_string((const gchar *)noti->app_icon_path));
-       if (noti->app_name != NULL)
-               g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_NAME, g_variant_new_string((const gchar *)noti->app_name));
+       if (noti->app_label != NULL)
+               g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_LABEL, g_variant_new_string((const gchar *)noti->app_label));
        if (noti->temp_title != NULL)
                g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_TITLE, g_variant_new_string((const gchar *)noti->temp_title));
        if (noti->temp_content != NULL)
@@ -2087,7 +2087,7 @@ EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
        char *vibration_path = NULL;
        char *priv_vibration_path = NULL;
        char *app_icon_path = NULL;
-       char *app_name = NULL;
+       char *app_label = NULL;
        char *temp_title = NULL;
        char *temp_content = NULL;
        char *tag = NULL;
@@ -2153,7 +2153,7 @@ EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, "d", &noti->progress_size);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, "d", &noti->progress_percentage);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_ICON_PATH, "&s", &app_icon_path);
-       _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_NAME, "&s", &app_name);
+       _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_LABEL, "&s", &app_label);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_TITLE, "&s", &temp_title);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_CONTENT, "&s", &temp_content);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TAG, "&s", &tag);
@@ -2213,7 +2213,7 @@ EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
        noti->vibration_path = _dup_string(vibration_path);
        noti->priv_vibration_path = _dup_string(priv_vibration_path);
        noti->app_icon_path = _dup_string(app_icon_path);
-       noti->app_name = _dup_string(app_name);
+       noti->app_label = _dup_string(app_label);
        noti->temp_title = _dup_string(temp_title);
        noti->temp_content = _dup_string(temp_content);
        noti->tag = _dup_string(tag);
index 8706df6..d76b517 100755 (executable)
@@ -69,6 +69,7 @@ static void __notification_noti_populate_from_stmt(sqlite3_stmt *stmt, notificat
        __free_and_set((void **)&(noti->pkg_id), notification_db_column_text(stmt, col++));
        __free_and_set((void **)&(noti->caller_app_id), notification_db_column_text(stmt, col++));
        __free_and_set((void **)&(noti->launch_app_id), notification_db_column_text(stmt, col++));
+       __free_and_set((void **)&(noti->app_label), notification_db_column_text(stmt, col++));
        noti->b_image_path = notification_db_column_bundle(stmt, col++);
        noti->b_priv_image_path = notification_db_column_bundle(stmt, col++);
        noti->group_id = sqlite3_column_int(stmt, col++);
@@ -127,7 +128,6 @@ static void __notification_noti_populate_from_stmt(sqlite3_stmt *stmt, notificat
        noti->uid = sqlite3_column_int(stmt, col++);
 
        noti->app_icon_path = NULL;
-       noti->app_name = NULL;
        noti->temp_title = NULL;
        noti->temp_content = NULL;
 }
@@ -329,6 +329,7 @@ static int _create_insertion_query(sqlite3 *db, notification_h noti, sqlite3_stm
        __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->pkg_id), ret, out);
        __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->caller_app_id), ret, out);
        __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->launch_app_id), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->app_label), ret, out);
        __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_image_path), ret, out);
        __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_priv_image_path), ret, out);
        __BIND_INT(db, stmt, idx++, noti->group_id, ret, out);
@@ -488,6 +489,7 @@ static int _create_update_query(sqlite3 *db, notification_h noti, sqlite3_stmt *
        __BIND_INT(db, stmt, idx++, noti->type, ret, out);
        __BIND_INT(db, stmt, idx++, noti->layout, ret, out);
        __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->launch_app_id), ret, out);
+       __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(noti->app_label), ret, out);
        __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_image_path), ret, out);
        __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_priv_image_path), ret, out);
        __BIND_TEXT(db, stmt, idx++, NOTIFICATION_CHECK_STR(b_text), ret, out);