Adds pkg_id field in notification_h 34/131434/4
authorMyungki Lee <mk5004.lee@samsung.com>
Mon, 29 May 2017 09:29:22 +0000 (18:29 +0900)
committerMyungki Lee <mk5004.lee@samsung.com>
Mon, 29 May 2017 09:29:22 +0000 (18:29 +0900)
 When any package is uninstalled, If there are any data related to
 the package, these should be deleted in database.
 Add a field in notification_h to remove the data by package name.

Change-Id: I142f7c845f9d7396801b22087e523f4620cc03ff
Signed-off-by: Seungha Son <seungha.son@samsung.com>
Signed-off-by: Semun Lee <semun.lee@samsung.com>
include/notification_private.h
src/notification.c
src/notification_db.c
src/notification_ipc.c
src/notification_noti.c

index c8747b5..d17d878 100644 (file)
@@ -44,6 +44,7 @@ struct _notification {
        int internal_group_id;  /* Internal Group ID */
        int priv_id;            /* Private ID */
 
+       char *pkg_id;
        char *caller_pkgname;   /* Caller App package name */
        char *launch_pkgname;   /* Launch App package name. It will be from appsvc_set_pkgname */
        bundle *args;           /* Will be removed. */
@@ -110,6 +111,7 @@ typedef enum notification_data_type {
        NOTIFICATION_DATA_TYPE_GROUP_ID,
        NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID,
        NOTIFICATION_DATA_TYPE_PRIV_ID,
+       NOTIFICATION_DATA_TYPE_PKG_ID,
        NOTIFICATION_DATA_TYPE_CALLER_PKGNAME,
        NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME,
        NOTIFICATION_DATA_TYPE_ARGS,
index a581e05..de35c6f 100755 (executable)
@@ -1462,12 +1462,15 @@ static notification_h _notification_create(notification_type_e type)
                goto out;
        }
 
-       if (getuid() >= REGULAR_UID_MIN) {
+       if (getuid() < REGULAR_UID_MIN) {
+               noti->pkg_id = strdup(noti->caller_pkgname);
+       } else {
                err = aul_app_get_pkgid_bypid(getpid(), pkgid, sizeof(pkgid));
                if (err != AUL_R_OK) {
                        NOTIFICATION_ERR("get_pkgid_bypid is failed err[%d]", err);
                        goto out;
                }
+               noti->pkg_id = strdup(pkgid);
 
                err = _notification_get_app_name(pkgid, &domain_name);
                if (err != 0 || domain_name == NULL) {
@@ -1547,6 +1550,9 @@ EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
        new_noti->internal_group_id = noti->internal_group_id;
        new_noti->priv_id = noti->priv_id;
 
+       if (noti->pkg_id != NULL)
+               new_noti->pkg_id = strdup(noti->pkg_id);
+
        if (noti->caller_pkgname != NULL)
                new_noti->caller_pkgname = strdup(noti->caller_pkgname);
        else
@@ -1688,6 +1694,9 @@ EXPORT_API int notification_free(notification_h noti)
        if (noti == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
+       if (noti->pkg_id)
+               free(noti->pkg_id);
+
        if (noti->caller_pkgname)
                free(noti->caller_pkgname);
 
index a2e7c10..d5bee4d 100755 (executable)
@@ -35,6 +35,7 @@ PRAGMA synchronous = FULL; \
 create table if not exists noti_list ( \
                        type INTEGER NOT NULL, \
                        layout INTEGER NOT NULL default 0, \
+                       pkg_id TEXT NOT NULL, \
                        caller_pkgname TEXT NOT NULL, \
                        launch_pkgname TEXT, \
                        image_path TEXT, \
@@ -162,6 +163,7 @@ create      table if not exists noti_list ( \
                CREATE TABLE IF NOT EXISTS noti_template ( \
                        type INTEGER NOT NULL, \
                        layout INTEGER NOT NULL default 0, \
+                       pkg_id TEXT NOT NULL, \
                        caller_pkgname TEXT NOT NULL, \
                        launch_pkgname TEXT, \
                        image_path TEXT, \
index 1629c97..353f779 100755 (executable)
@@ -1743,6 +1743,7 @@ EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h not
        g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ID, g_variant_new_int32(noti->group_id));
        g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, g_variant_new_int32(noti->internal_group_id));
        g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PRIV_ID, g_variant_new_int32(noti->priv_id));
+       g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PKG_ID, g_variant_new_string((const gchar *)noti->pkg_id));
        g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, g_variant_new_string((const gchar *)noti->caller_pkgname));
        g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, g_variant_new_int32(noti->display_applist));
 
@@ -1977,6 +1978,7 @@ EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
        GHashTable *dict;
 
        int i;
+       char *pkg_id = NULL;
        char *caller_pkgname = NULL;
        char *launch_pkgname = NULL;
        bundle_raw *args = NULL;
@@ -2018,6 +2020,7 @@ EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ID, "i", &noti->group_id);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, "i", &noti->internal_group_id);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PRIV_ID, "i", &noti->priv_id);
+       _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PKG_ID, "&s", &pkg_id);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, "&s", &caller_pkgname);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, "&s", &launch_pkgname);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ARGS, "&s", &args);
@@ -2075,6 +2078,7 @@ EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_EXTENSION_IMAGE_SIZE, "i", &noti->extension_image_size);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_UID, "i", &noti->uid);
 
+       noti->pkg_id = _dup_string(pkg_id);
        noti->caller_pkgname = _dup_string(caller_pkgname);
        noti->launch_pkgname = _dup_string(launch_pkgname);
        noti->args = _create_bundle_from_bundle_raw(args);
index f065565..449de3c 100755 (executable)
@@ -248,7 +248,7 @@ static int _insertion_query_create(notification_h noti, char **query)
        *query = sqlite3_mprintf("INSERT INTO noti_list ("
                "type, "
                "layout, "
-               "caller_pkgname, launch_pkgname, "
+               "pkg_id, caller_pkgname, launch_pkgname, "
                "image_path, "
                "group_id, internal_group_id,"
                "title_key, "
@@ -269,7 +269,7 @@ static int _insertion_query_create(notification_h noti, char **query)
                "text_input_max_length, event_flag, extension_image_size, uid) values ("
                "%d, "
                "%d, "
-               "'%s', '%s', "
+               "'%s', '%s', '%s', "
                "'%s', "
                "%d, %d,"
                "$title_key, "
@@ -289,6 +289,7 @@ static int _insertion_query_create(notification_h noti, char **query)
                "%d, %d, %d, %d, %d, %d, %d)",
                noti->type,
                noti->layout,
+               NOTIFICATION_CHECK_STR(noti->pkg_id),
                NOTIFICATION_CHECK_STR(noti->caller_pkgname),
                NOTIFICATION_CHECK_STR(noti->launch_pkgname),
                NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
@@ -566,6 +567,7 @@ static void _notification_noti_populate_from_stmt(sqlite3_stmt *stmt, notificati
 
        noti->type = sqlite3_column_int(stmt, col++);
        noti->layout = sqlite3_column_int(stmt, col++);
+       __free_and_set((void **)&(noti->pkg_id), notification_db_column_text(stmt, col++));
        __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++));
        __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++));
        noti->b_image_path = notification_db_column_bundle(stmt, col++);
@@ -596,7 +598,6 @@ static void _notification_noti_populate_from_stmt(sqlite3_stmt *stmt, notificati
        for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++)
                noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
 
-
        noti->sound_type = sqlite3_column_int(stmt, col++);
        __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
        noti->vibration_type = sqlite3_column_int(stmt, col++);
@@ -1035,7 +1036,7 @@ EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, int priv_id
                return get_last_result();
 
        char *base_query = "select "
-                        "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
+                        "type, layout, pkg_id, 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, "
@@ -1103,7 +1104,7 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname,
 
        if (pkgname != NULL && strlen(pkgname) != 0) {
                ret = sqlite3_prepare_v2(db, "select "
-                        "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
+                        "type, layout, pkg_id, 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, "
@@ -1141,7 +1142,7 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname,
 
        } else {
                ret = sqlite3_prepare_v2(db, "select "
-                        "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
+                        "type, layout, pkg_id, 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, "
@@ -1603,7 +1604,7 @@ EXPORT_API int notification_noti_get_grouping_list(notification_type_e type,
        ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
 
        snprintf(query_base, sizeof(query_base), "select "
-                "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
+                "type, layout, pkg_id, 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, "
@@ -1705,7 +1706,7 @@ EXPORT_API int notification_noti_get_detail_list(const char *pkgname,
        ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
 
        snprintf(query_base, sizeof(query_base), "select "
-                "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
+                "type, layout, pkg_id, 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, "
@@ -1962,7 +1963,7 @@ static int _template_query_create(notification_h noti, char *template_name, char
        *query = sqlite3_mprintf("INSERT OR REPLACE INTO noti_template ("
                "type, "
                "layout, "
-               "caller_pkgname, launch_pkgname, "
+               "pkg_id, caller_pkgname, launch_pkgname, "
                "image_path, "
                "group_id, internal_group_id,"
                "title_key, "
@@ -1982,7 +1983,7 @@ static int _template_query_create(notification_h noti, char *template_name, char
                "event_flag, extension_image_size, uid, template_name) values ("
                "%d, "
                "%d, "
-               "'%s', '%s', "
+               "'%s', '%s', '%s', "
                "'%s', "
                "%d, %d,"
                "$title_key, "
@@ -2002,6 +2003,7 @@ static int _template_query_create(notification_h noti, char *template_name, char
                "%d, %d, %d, '%s')",
                noti->type,
                noti->layout,
+               NOTIFICATION_CHECK_STR(noti->pkg_id),
                NOTIFICATION_CHECK_STR(noti->caller_pkgname),
                NOTIFICATION_CHECK_STR(noti->launch_pkgname),
                NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
@@ -2199,7 +2201,7 @@ EXPORT_API int notification_noti_get_package_template(notification_h noti, char
                return get_last_result();
 
        ret = sqlite3_prepare_v2(db, "select "
-               "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
+               "type, layout, pkg_id, 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, "
@@ -2262,7 +2264,7 @@ EXPORT_API int notification_noti_delete_template(const char *pkgname)
                return get_last_result();
 
        snprintf(query, sizeof(query), "delete from noti_template "
-                "where caller_pkgname = '%s'", pkgname);
+                "where pkg_id = '%s'", pkgname);
 
        ret = notification_db_exec(db, query, NULL);