Add multi-user feature 18/73218/12 submit/tizen/20160613.023047
authorHyunho Kang <hhstark.kang@samsung.com>
Fri, 10 Jun 2016 07:09:04 +0000 (16:09 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Mon, 13 Jun 2016 00:35:12 +0000 (09:35 +0900)
Change-Id: Ied3983a098458e1c6ca0a3ad560be732c633b73d
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
22 files changed:
11_notification-add.post [new file with mode: 0644]
CMakeLists.txt
include/notification_internal.h
include/notification_ipc.h
include/notification_list.h
include/notification_noti.h
include/notification_private.h
include/notification_setting.h
include/notification_setting_internal.h
include/notification_setting_service.h
packaging/notification.spec
src/notification.c
src/notification_db.c
src/notification_init.c [new file with mode: 0644]
src/notification_internal.c
src/notification_ipc.c
src/notification_list.c
src/notification_noti.c
src/notification_setting.c
src/notification_setting_service.c
test-app/CMakeLists.txt
test-app/main.c

diff --git a/11_notification-add.post b/11_notification-add.post
new file mode 100644 (file)
index 0000000..a0faef0
--- /dev/null
@@ -0,0 +1 @@
+notification_init --uid $2
\ No newline at end of file
index b27a4e0..9bd1961 100755 (executable)
@@ -10,6 +10,10 @@ SET(VERSION ${MAJOR_VER}.1.0)
 
 ADD_SUBDIRECTORY(test-app)
 
+SET(INIT-SRCS
+       ./src/notification_init.c
+)
+
 SET(SRCS
        ./src/notification.c
        ./src/notification_noti.c
@@ -87,6 +91,9 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${MAJOR_VER})
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS})
 
+ADD_EXECUTABLE(notification_init ${INIT-SRCS})
+TARGET_LINK_LIBRARIES(notification_init ${pkgs_LDFLAGS} notification)
+
 MESSAGE(STATUS "LIB_INSTALL_DIR: " ${LIB_INSTALL_DIR})
 
 CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
@@ -96,3 +103,6 @@ INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_D
 FOREACH(hfile ${HEADERS-DEVEL})
        INSTALL(FILES ${CMAKE_SOURCE_DIR}/${hfile} DESTINATION include/${PROJECT_NAME})
 ENDFOREACH(hfile)
+
+INSTALL(FILES ${CMAKE_BINARY_DIR}/11_notification-add.post DESTINATION ${SYSCONF_INSTALL_DIR}/gumd/useradd.d/)
+INSTALL(TARGETS notification_init DESTINATION bin)
\ No newline at end of file
index e16e443..9a81038 100644 (file)
@@ -29,7 +29,7 @@ extern "C" {
  * @addtogroup NOTIFICATION_INTERNAL
  * @{
  */
-
+#define NOTIFICATION_GLOBAL_UID -1
 #define NOTIFICATION_DISPLAY_APP_HEADS_UP NOTIFICATION_DISPLAY_APP_ACTIVE /* To avoid build error */
 #define NOTIFICATION_ERROR (notification_error_quark())
 GQuark notification_error_quark(void);
@@ -55,6 +55,12 @@ int notification_add_deferred_task(
 int notification_del_deferred_task(
                void (*deferred_task_cb)(void *data));
 
+
+int
+notification_resister_changed_cb_for_uid(
+       void (*changed_cb)(void *data, notification_type_e type),
+       void *user_data, uid_t uid);
+
 /**
  * @brief This function will be removed.
  * @see notification_unresister_changed_cb()
@@ -608,7 +614,10 @@ NOTIFICATION_DEPRECATED_API int notification_get_execute_option(notification_h n
  * @endcode
  */
 int notification_insert(notification_h noti,
-                                        int *priv_id);
+               int *priv_id);
+
+int notification_insert_for_uid(notification_h noti,
+               int *priv_id, uid_t uid);
 
 /**
  * @internal
@@ -643,6 +652,8 @@ int notification_insert(notification_h noti,
  */
 int notification_update_async(notification_h noti,
                void (*result_cb)(int priv_id, int result, void *data), void *user_data);
+int notification_update_async_for_uid(notification_h noti,
+               void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid);
 
 /**
  * @internal
@@ -674,6 +685,9 @@ int notification_update_async(notification_h noti,
 int notification_register_detailed_changed_cb(
                void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
                void *user_data);
+int notification_register_detailed_changed_cb_for_uid(
+               void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
+               void *user_data, uid_t uid);
 
 /**
  * @internal
@@ -711,6 +725,13 @@ int notification_unregister_detailed_changed_cb(
  * @see notification_create()
  */
 int notification_translate_localized_text(notification_h noti);
+int notification_set_uid(notification_h noti, uid_t uid);
+int notification_get_uid(notification_h noti, uid_t *uid);
+int notification_post_for_uid(notification_h noti, uid_t uid);
+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);
 
 /**
  * @}
index 1451a70..e8e2a5c 100755 (executable)
@@ -43,7 +43,7 @@ int notification_ipc_make_system_setting_from_gvariant(
                GVariant *variant);
 
 int notification_dbus_init();
-int notification_ipc_monitor_init(void);
+int notification_ipc_monitor_init(uid_t uid);
 int notification_ipc_monitor_fini(void);
 
 int notification_ipc_is_master_ready(void);
@@ -55,32 +55,32 @@ int notification_ipc_request_update(notification_h noti);
 int notification_ipc_request_update_async(notification_h noti,
                void (*result_cb)(int priv_id, int result, void *data),
                void *user_data);
-int notification_ipc_request_refresh(void);
+int notification_ipc_request_refresh(uid_t uid);
 int notification_ipc_request_delete_multiple(notification_type_e type,
-               char *pkgname);
+               char *pkgname, uid_t uid);
 int notification_ipc_request_delete_single(notification_type_e type,
-               char *pkgname, int priv_id);
-int notification_ipc_update_setting(notification_setting_h setting);
+               char *pkgname, int priv_id, uid_t uid);
+int notification_ipc_update_setting(notification_setting_h setting, uid_t uid);
 int notification_ipc_update_system_setting(
-               notification_system_setting_h system_setting);
+               notification_system_setting_h system_setting, uid_t uid);
 int notification_ipc_request_load_noti_by_tag(notification_h noti,
-               const char *pkgname, const char *tag);
+               const char *pkgname, const char *tag, uid_t uid);
 int notification_ipc_request_load_noti_grouping_list(notification_type_e type,
                int count,
-               notification_list_h *list);
+               notification_list_h *list, uid_t uid);
 int notification_ipc_request_get_setting_array(
-               notification_setting_h *setting_array, int *count);
+               notification_setting_h *setting_array, int *count, uid_t uid);
 int notification_ipc_request_get_setting_by_package_name(
-               const char *package_name, notification_setting_h *setting);
+               const char *package_name, notification_setting_h *setting, uid_t uid);
 int notification_ipc_request_load_system_setting(
-               notification_system_setting_h *setting);
+               notification_system_setting_h *setting, uid_t uid);
 int notification_ipc_request_get_count(notification_type_e type,
-               const char *pkgname, int group_id, int priv_id, int *count);
+               const char *pkgname, int group_id, int priv_id, int *count, uid_t uid);
 int notification_ipc_request_load_noti_by_priv_id(notification_h noti,
-               const char *pkgname, int priv_id);
+               const char *pkgname, int priv_id, uid_t uid);
 int notification_ipc_request_load_noti_detail_list(const char *pkgname,
                int group_id, int priv_id, int count,
-               notification_list_h *list);
+               notification_list_h *list, uid_t uid);
 
 #ifdef __cplusplus
 }
index 6741a66..c54a498 100644 (file)
@@ -72,8 +72,12 @@ typedef struct _notification_list *notification_list_h;
  * @endcode
  */
 int notification_get_list(notification_type_e type,
-                                          int count,
-                                          notification_list_h *list);
+               int count,
+               notification_list_h *list);
+
+int notification_get_list_for_uid(notification_type_e type,
+               int count,
+               notification_list_h *list, uid_t uid);
 
 /**
  * @brief Returns the notification detail list handle of grouping data.
@@ -108,10 +112,17 @@ int notification_get_list(notification_type_e type,
  * @endcode
  */
 int notification_get_detail_list(const char *pkgname,
-                                                 int group_id,
-                                                 int priv_id,
-                                                 int count,
-                                                 notification_list_h *list);
+               int group_id,
+               int priv_id,
+               int count,
+               notification_list_h *list);
+
+int notification_get_detail_list_for_uid(const char *pkgname,
+               int group_id,
+               int priv_id,
+               int count,
+               notification_list_h *list,
+               uid_t uid);
 
 /**
  * @brief Frees a notification list.
index bb774e0..8a42456 100644 (file)
@@ -34,32 +34,29 @@ int notification_noti_insert(notification_h noti);
 
 int notification_noti_update(notification_h noti);
 
-int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid);
+int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid, uid_t uid);
 
-int notification_noti_delete_group_by_group_id(const char *pkgname,
-                                              int group_id, int *num_deleted, int **list_deleted_rowid);
-
-int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id);
-
-int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id);
-int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag);
+int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id, uid_t uid);
+int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag, uid_t uid);
 
 int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id);
-int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes);
+int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes, uid_t uid);
 
 int notification_noti_get_count(notification_type_e type,
-                                                const char *pkgname,
-                                                int group_id, int priv_id,
-                                                int *count);
+               const char *pkgname,
+               int group_id, int priv_id,
+               int *count, uid_t uid);
 
 int notification_noti_get_grouping_list(notification_type_e type,
-                                                        int count,
-                                                        notification_list_h *list);
+               int count,
+               notification_list_h *list,
+               uid_t uid);
 
 int notification_noti_get_detail_list(const char *pkgname,
-                                                      int group_id,
-                                                      int priv_id, int count,
-                                                      notification_list_h *list);
+               int group_id,
+               int priv_id, int count,
+               notification_list_h *list,
+               uid_t uid);
 
 int notification_noti_check_tag(notification_h noti);
 
index 2d292ea..1968469 100644 (file)
@@ -88,6 +88,7 @@ struct _notification {
        char *tag;
        bool ongoing_flag;
        bool auto_remove;
+       uid_t uid;
 };
 
 struct notification_system_setting {
@@ -145,6 +146,7 @@ typedef enum notification_data_type {
        NOTIFICATION_DATA_TYPE_TAG,
        NOTIFICATION_DATA_TYPE_ONGOING_FLAG,
        NOTIFICATION_DATA_TYPE_AUTO_REMOVE,
+       NOTIFICATION_DATA_TYPE_UID,
 } notification_data_type_e;
 
 void notification_call_changed_cb(notification_op *op_list, int op_num);
index 7c19c38..ebd784a 100644 (file)
@@ -35,7 +35,7 @@ int notification_setting_update_setting(notification_setting_h setting);
 
 int notification_setting_free_notification(notification_setting_h setting);
 
-int notification_setting_refresh_setting_table();
+int notification_setting_refresh_setting_table(uid_t uid);
 
 #ifdef __cplusplus
 }
index f8c70a3..a4dfaf2 100644 (file)
@@ -45,8 +45,8 @@ int notification_setting_set_allow_to_notify(notification_setting_h setting, boo
 int notification_setting_get_do_not_disturb_except(notification_setting_h setting, bool *value);
 int notification_setting_set_do_not_disturb_except(notification_setting_h setting, bool value);
 
-int notification_setting_insert_package(const char *package_id);
-int notification_setting_delete_package(const char *package_id);
+int notification_setting_insert_package_for_uid(const char *package_id, uid_t uid);
+int notification_setting_delete_package_for_uid(const char *package_id, uid_t uid);
 
 /* System setting */
 typedef struct notification_system_setting *notification_system_setting_h;
index 7b3a52c..e052c4c 100644 (file)
@@ -26,12 +26,12 @@ extern "C" {
 int notification_setting_db_set(const char *pkgname, const char *property, const char *value);
 int notification_setting_db_get(const char *pkgname, const char *property, char **value);
 
-int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class);
-int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class);
+int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class, uid_t uid);
+int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class, uid_t uid);
 
-int noti_setting_service_get_setting_by_package_name(const char *package_name, notification_setting_h *setting);
-int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count);
-int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting);
+int noti_setting_service_get_setting_by_package_name(const char *package_name, notification_setting_h *setting, uid_t uid);
+int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count, uid_t uid);
+int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting, uid_t uid);
 
 #ifdef __cplusplus
 }
index d248b77..0295744 100755 (executable)
@@ -88,6 +88,9 @@ fi
 %defattr(-,root,root,-)
 %{_libdir}/libnotification.so*
 %{TZ_SYS_SHARE}/license/%{name}
+%attr(755,root,root) %{_sysconfdir}/gumd/useradd.d/11_notification-add.post
+%{_bindir}/notification_init
+#%{_bindir}/notification-test-app
 
 %files devel
 %defattr(-,root,root,-)
index 4931239..a7237ac 100755 (executable)
@@ -1484,77 +1484,22 @@ EXPORT_API int notification_get_type(notification_h noti,
 
 EXPORT_API int notification_post(notification_h noti)
 {
-       int ret = 0;
-       int id = 0;
-
-       /* Check noti is vaild data */
-       if (noti == NULL)
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
-       /* Check noti type is valid type */
-       if (noti->type <= NOTIFICATION_TYPE_NONE
-           || noti->type >= NOTIFICATION_TYPE_MAX)
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
-       /* Save insert time */
-       noti->insert_time = time(NULL);
-
-       ret = notification_ipc_request_insert(noti, &id);
-       if (ret != NOTIFICATION_ERROR_NONE)
-               return ret;
-
-       noti->priv_id = id;
-       NOTIFICATION_DBG("from master:%d", id);
-
-       return NOTIFICATION_ERROR_NONE;
+       return notification_post_for_uid(noti, getuid());
 }
 
-
-
 EXPORT_API int notification_update(notification_h noti)
 {
-       int ret = 0;
-
-       /* Check noti is valid data */
-       if (noti != NULL) {
-               /* Update insert time ? */
-               noti->insert_time = time(NULL);
-               ret = notification_ipc_request_update(noti);
-       } else {
-               notification_ipc_request_refresh();
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-       }
-       return ret;
+       return notification_update_for_uid(noti, getuid());
 }
 
 EXPORT_API int notification_delete_all(notification_type_e type)
 {
-       int ret = 0;
-       char *caller_pkgname = NULL;
-
-       if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
-       caller_pkgname = notification_get_pkgname_by_pid();
-
-       ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
-
-       if (caller_pkgname)
-               free(caller_pkgname);
-
-       return ret;
+       return notification_delete_all_for_uid(type, getuid());
 }
 
 EXPORT_API int notification_delete(notification_h noti)
 {
-       int ret = 0;
-
-       if (noti == NULL)
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
-       ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
-
-       return ret;
+       return notification_delete_for_uid(noti, getuid());
 }
 
 static notification_h _notification_create(notification_type_e type)
@@ -1589,7 +1534,6 @@ static notification_h _notification_create(notification_type_e type)
 
        noti->caller_pkgname = notification_get_pkgname_by_pid();
        noti->group_id = NOTIFICATION_GROUP_ID_NONE;
-       noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
        noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
        noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
        noti->led_operation = NOTIFICATION_LED_OP_OFF;
@@ -1660,42 +1604,7 @@ EXPORT_API notification_h notification_create(notification_type_e type)
 
 EXPORT_API notification_h  notification_load_by_tag(const char *tag)
 {
-       int ret = 0;
-       notification_h noti = NULL;
-       char *caller_pkgname = NULL;
-
-       if (tag == NULL) {
-               NOTIFICATION_ERR("Invalid parameter");
-               set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
-               return NULL;
-       }
-
-       caller_pkgname = notification_get_pkgname_by_pid();
-       if (!caller_pkgname) {
-               NOTIFICATION_ERR("Failed to get a package name");
-               set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
-               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);
-               free(caller_pkgname);
-
-               return NULL;
-       }
-
-       ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, (char *)tag);
-       free(caller_pkgname);
-
-       set_last_result(ret);
-       if (ret != NOTIFICATION_ERROR_NONE) {
-               notification_free(noti);
-               return NULL;
-       }
-
-       return noti;
+       return notification_load_by_tag_for_uid(tag, getuid());
 }
 
 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
index fc73cf4..fa55162 100755 (executable)
@@ -39,7 +39,7 @@ create        table if not exists noti_list ( \
                        image_path TEXT, \
                        group_id INTEGER default 0,  \
                        internal_group_id INTEGER default 0,  \
-                       priv_id INTERGER NOT NULL,  \
+                       priv_id INTEGER PRIMARY KEY AUTOINCREMENT,  \
                        title_key TEXT, \
                        b_text TEXT, \
                        b_key TEXT, \
@@ -77,10 +77,9 @@ create       table if not exists noti_list ( \
                        display_applist INTEGER, \
                        progress_size DOUBLE default 0, \
                        progress_percentage DOUBLE default 0, \
-                       rowid INTEGER PRIMARY KEY AUTOINCREMENT, \
                        ongoing_flag INTEGER default 0, \
                        auto_remove INTEGER default 1, \
-                       UNIQUE (caller_pkgname, priv_id)  \
+                       uid INTEGER \
                ); \
                create table if not exists noti_group_data ( \
                        caller_pkgname TEXT NOT NULL, \
@@ -119,20 +118,19 @@ create    table if not exists noti_list ( \
                        UNIQUE (caller_pkgname, priv_id) \
                ); \
                CREATE TABLE IF NOT EXISTS notification_setting ( \
-                       priv_id INTEGER PRIMARY KEY AUTOINCREMENT, \
+                       uid INTEGER, \
                        package_name TEXT NOT NULL, \
                        allow_to_notify INTEGER DEFAULT 1, \
                        do_not_disturb_except INTEGER DEFAULT 0, \
                        visibility_class INTEGER DEFAULT 0, \
-                       UNIQUE (priv_id, package_name) \
+                       UNIQUE (uid, package_name) \
                ); \
                CREATE TABLE IF NOT EXISTS notification_system_setting ( \
-                       priv_id INTERGER PRIMARY KEY, \
+                       uid INTEGER, \
                        do_not_disturb INTEGER DEFAULT 0, \
-                       visibility_class INTEGER DEFAULT 0 \
-               ); \
-               INSERT OR IGNORE INTO notification_system_setting (priv_id, do_not_disturb, visibility_class) VALUES (0, 0, 0); \
-               CREATE UNIQUE INDEX IF NOT EXISTS package_name_idx1 ON notification_setting (package_name);"
+                       visibility_class INTEGER DEFAULT 0, \
+                       UNIQUE (uid) \
+               );"
 
 EXPORT_API int notification_db_init()
 {
@@ -140,6 +138,7 @@ EXPORT_API int notification_db_init()
        sqlite3 *db = NULL;
        char *errmsg = NULL;
        char defname[FILENAME_MAX];
+       char *query = NULL;
        const char *db_path = tzplatform_getenv(TZ_SYS_DB);
        if (db_path == NULL) {
                NOTIFICATION_ERR("fail to get db_path");
@@ -154,8 +153,12 @@ EXPORT_API int notification_db_init()
                NOTIFICATION_ERR("fail to open notification db %d", r);
                return NOTIFICATION_ERROR_IO_ERROR;
        }
+       query = sqlite3_mprintf(CREATE_NOTIFICATION_TABLE, tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+       NOTIFICATION_DBG("@@@ query : %s", query);
 
        r = sqlite3_exec(db, CREATE_NOTIFICATION_TABLE, NULL, NULL, &errmsg);
+       if (query)
+               sqlite3_free(query);
        if (r != SQLITE_OK) {
                NOTIFICATION_ERR("query error(%d)(%s)", r, errmsg);
                sqlite3_free(errmsg);
diff --git a/src/notification_init.c b/src/notification_init.c
new file mode 100644 (file)
index 0000000..c637fde
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+#include <notification_setting.h>
+
+/* For multi-user support */
+#include <tzplatform_config.h>
+
+#define OWNER_ROOT 0
+
+#ifdef _E
+#undef _E
+#endif
+#define _E(fmt, arg...) fprintf(stderr, "[NOTIFICATION_INIT][E][%s,%d] "fmt"\n", \
+               __FUNCTION__, __LINE__, ##arg);
+
+static int _is_authorized()
+{
+       /* pkg_init db should be called by as root privilege. */
+       uid_t uid = getuid();
+
+       if ((uid_t) OWNER_ROOT == uid)
+               return 1;
+       else
+               return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       int ret;
+       uid_t uid = 0;
+
+       if (!_is_authorized()) {
+               _E("You are not an authorized user!");
+               return -1;
+       }
+
+       if (argc > 2)
+               uid = (uid_t)atoi(argv[2]);
+       ret = notification_setting_refresh_setting_table(uid);
+       return ret;
+}
index 2d6b69f..502db5e 100755 (executable)
@@ -84,11 +84,11 @@ void notification_call_changed_cb(notification_op *op_list, int op_num)
        while (noti_cb_list != NULL) {
                if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
                        noti_cb_list->changed_cb(noti_cb_list->data,
-                                                type);
+                                       type);
                }
                if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
                        noti_cb_list->detailed_changed_cb(noti_cb_list->data,
-                                               type, op_list, op_num);
+                                       type, op_list, op_num);
                }
 
                noti_cb_list = noti_cb_list->next;
@@ -113,9 +113,10 @@ EXPORT_API int notification_del_deferred_task(
        return notification_ipc_del_deffered_task(deferred_task_cb);
 }
 
-EXPORT_API int notification_resister_changed_cb(void (*changed_cb)
-                                (void *data, notification_type_e type),
-                                void *user_data)
+
+EXPORT_API int notification_resister_changed_cb_for_uid(
+               void (*changed_cb)(void *data, notification_type_e type),
+               void *user_data, uid_t uid)
 {
        notification_cb_list_s *noti_cb_list_new = NULL;
        notification_cb_list_s *noti_cb_list = NULL;
@@ -124,7 +125,7 @@ EXPORT_API int notification_resister_changed_cb(void (*changed_cb)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
        noti_cb_list_new =
-           (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
+               (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
 
        if (noti_cb_list_new == NULL) {
                NOTIFICATION_ERR("malloc failed");
@@ -152,7 +153,7 @@ EXPORT_API int notification_resister_changed_cb(void (*changed_cb)
                noti_cb_list_new->prev = noti_cb_list;
        }
 
-       if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
+       if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
                notification_unresister_changed_cb(changed_cb);
                return NOTIFICATION_ERROR_IO_ERROR;
        }
@@ -160,8 +161,16 @@ EXPORT_API int notification_resister_changed_cb(void (*changed_cb)
        return NOTIFICATION_ERROR_NONE;
 }
 
-EXPORT_API int notification_unresister_changed_cb(void (*changed_cb)
-                                  (void *data, notification_type_e type))
+EXPORT_API int notification_resister_changed_cb(
+               void (*changed_cb)(void *data, notification_type_e type),
+               void *user_data)
+{
+       return notification_resister_changed_cb_for_uid(
+                       changed_cb, user_data, getuid());
+}
+
+EXPORT_API int notification_unresister_changed_cb(
+               void (*changed_cb)(void *data, notification_type_e type))
 {
        notification_cb_list_s *noti_cb_list = NULL;
        notification_cb_list_s *noti_cb_list_prev = NULL;
@@ -211,8 +220,8 @@ EXPORT_API int notification_unresister_changed_cb(void (*changed_cb)
 }
 
 EXPORT_API int notification_update_progress(notification_h noti,
-                                                            int priv_id,
-                                                            double progress)
+               int priv_id,
+               double progress)
 {
        char *caller_pkgname = NULL;
        int input_priv_id = 0;
@@ -242,7 +251,7 @@ EXPORT_API int notification_update_progress(notification_h noti,
                input_progress = progress;
 
        ret = notification_ongoing_update_progress(caller_pkgname, input_priv_id,
-                                            input_progress);
+                       input_progress);
 
        if (caller_pkgname)
                free(caller_pkgname);
@@ -251,8 +260,8 @@ EXPORT_API int notification_update_progress(notification_h noti,
 }
 
 EXPORT_API int notification_update_size(notification_h noti,
-                                                        int priv_id,
-                                                        double size)
+               int priv_id,
+               double size)
 {
        char *caller_pkgname = NULL;
        int input_priv_id = 0;
@@ -279,7 +288,7 @@ EXPORT_API int notification_update_size(notification_h noti,
                input_size = size;
 
        ret = notification_ongoing_update_size(caller_pkgname, input_priv_id,
-                                        input_size);
+                       input_size);
 
        if (caller_pkgname)
                free(caller_pkgname);
@@ -288,8 +297,8 @@ EXPORT_API int notification_update_size(notification_h noti,
 }
 
 EXPORT_API int notification_update_content(notification_h noti,
-                                                        int priv_id,
-                                                        const char *content)
+               int priv_id,
+               const char *content)
 {
        char *caller_pkgname = NULL;
        int input_priv_id = 0;
@@ -311,7 +320,7 @@ EXPORT_API int notification_update_content(notification_h noti,
                caller_pkgname = strdup(noti->caller_pkgname);
 
        ret = notification_ongoing_update_content(caller_pkgname, input_priv_id,
-                                        content);
+                       content);
 
        if (caller_pkgname)
                free(caller_pkgname);
@@ -322,13 +331,13 @@ EXPORT_API int notification_update_content(notification_h noti,
 /* notification_set_icon will be removed */
 /* LCOV_EXCL_START */
 EXPORT_API int notification_set_icon(notification_h noti,
-                                                     const char *icon_path)
+               const char *icon_path)
 {
        int ret_err = NOTIFICATION_ERROR_NONE;
 
        ret_err =
-           notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
-                                  icon_path);
+               notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
+                               icon_path);
 
        return ret_err;
 }
@@ -337,14 +346,14 @@ EXPORT_API int notification_set_icon(notification_h noti,
 /* notification_get_icon will be removed */
 /* LCOV_EXCL_START */
 EXPORT_API int notification_get_icon(notification_h noti,
-                                                     char **icon_path)
+               char **icon_path)
 {
        int ret_err = NOTIFICATION_ERROR_NONE;
        char *ret_image_path = NULL;
 
        ret_err =
-           notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
-                                  &ret_image_path);
+               notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
+                               &ret_image_path);
 
        if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL)
                *icon_path = ret_image_path;
@@ -400,14 +409,14 @@ EXPORT_API int notification_translate_localized_text(notification_h noti)
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_set_title(notification_h noti,
-                                                      const char *title,
-                                                      const char *loc_title)
+               const char *title,
+               const char *loc_title)
 {
        int noti_err = NOTIFICATION_ERROR_NONE;
 
        noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
-                                        title, loc_title,
-                                        NOTIFICATION_VARIABLE_TYPE_NONE);
+                       title, loc_title,
+                       NOTIFICATION_VARIABLE_TYPE_NONE);
 
        return noti_err;
 }
@@ -415,15 +424,15 @@ EXPORT_API int notification_set_title(notification_h noti,
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_get_title(notification_h noti,
-                                                      char **title,
-                                                      char **loc_title)
+               char **title,
+               char **loc_title)
 {
        int noti_err = NOTIFICATION_ERROR_NONE;
        char *ret_text = NULL;
 
        noti_err =
-           notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
-                                 &ret_text);
+               notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
+                               &ret_text);
 
        if (title != NULL)
                *title = ret_text;
@@ -437,14 +446,14 @@ EXPORT_API int notification_get_title(notification_h noti,
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_set_content(notification_h noti,
-                                                        const char *content,
-                                                        const char *loc_content)
+               const char *content,
+               const char *loc_content)
 {
        int noti_err = NOTIFICATION_ERROR_NONE;
 
        noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
-                                        content, loc_content,
-                                        NOTIFICATION_VARIABLE_TYPE_NONE);
+                       content, loc_content,
+                       NOTIFICATION_VARIABLE_TYPE_NONE);
 
        return noti_err;
 }
@@ -452,15 +461,15 @@ EXPORT_API int notification_set_content(notification_h noti,
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_get_content(notification_h noti,
-                                                        char **content,
-                                                        char **loc_content)
+               char **content,
+               char **loc_content)
 {
        int noti_err = NOTIFICATION_ERROR_NONE;
        char *ret_text = NULL;
 
        noti_err =
-           notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
-                                 &ret_text);
+               notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
+                               &ret_text);
 
        if (content != NULL)
                *content = ret_text;
@@ -472,8 +481,8 @@ EXPORT_API int notification_get_content(notification_h noti,
 
 #if 0
        ret =
-           vconf_get_bool
-           (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
+               vconf_get_bool
+               (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
 
        if (ret == -1 || boolval == 0) {
                if (content != NULL && noti->default_content != NULL)
@@ -488,7 +497,7 @@ EXPORT_API int notification_get_content(notification_h noti,
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_set_application(notification_h noti,
-                                                            const char *pkgname)
+               const char *pkgname)
 {
        if (noti == NULL || pkgname == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -504,7 +513,7 @@ EXPORT_API int notification_set_application(notification_h noti,
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_get_application(notification_h noti,
-                                                            char **pkgname)
+               char **pkgname)
 {
        if (noti == NULL || pkgname == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -544,8 +553,8 @@ EXPORT_API int notification_set_args(notification_h noti, bundle *args,
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_get_args(notification_h noti,
-                                                     bundle **args,
-                                                     bundle **group_args)
+               bundle **args,
+               bundle **group_args)
 {
        if (noti == NULL || args == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -563,8 +572,8 @@ EXPORT_API int notification_get_args(notification_h noti,
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
-EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
-                              notification_list_h *list)
+int notification_get_grouping_list_for_uid(notification_type_e type, int count,
+               notification_list_h *list, uid_t uid)
 {
        notification_list_h get_list = NULL;
        int ret = 0;
@@ -572,7 +581,7 @@ EXPORT_API int notification_get_grouping_list(notification_type_e type, int coun
        if (list == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       ret = notification_noti_get_grouping_list(type, count, &get_list);
+       ret = notification_noti_get_grouping_list(type, count, &get_list, uid);
        if (ret != NOTIFICATION_ERROR_NONE)
                return ret;
 
@@ -580,12 +589,18 @@ EXPORT_API int notification_get_grouping_list(notification_type_e type, int coun
 
        return NOTIFICATION_ERROR_NONE;
 }
+
+EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
+               notification_list_h *list)
+{
+       return notification_get_grouping_list_for_uid(type, count, list, getuid());
+}
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
-                                                                     notification_type_e type,
-                                                                     int group_id)
+               notification_type_e type,
+               int group_id)
 {
        int ret = 0;
        char *caller_pkgname = NULL;
@@ -595,7 +610,7 @@ EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
        else
                caller_pkgname = strdup(pkgname);
 
-       ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
+       ret = notification_ipc_request_delete_multiple(type, caller_pkgname, getuid());
 
        if (caller_pkgname)
                free(caller_pkgname);
@@ -605,9 +620,9 @@ EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
-EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
-                                                                    notification_type_e type,
-                                                                    int priv_id)
+int notification_delete_group_by_priv_id_for_uid(const char *pkgname,
+               notification_type_e type,
+               int priv_id, uid_t uid)
 {
        int ret = 0;
        char *caller_pkgname = NULL;
@@ -617,7 +632,7 @@ EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
        else
                caller_pkgname = strdup(pkgname);
 
-       ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
+       ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
 
        if (caller_pkgname)
                free(caller_pkgname);
@@ -627,10 +642,18 @@ EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
-EXPORT_API int notification_get_count(notification_type_e type,
-                                                      const char *pkgname,
-                                                      int group_id,
-                                                      int priv_id, int *count)
+EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
+               notification_type_e type,
+               int priv_id)
+{
+       return notification_delete_group_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
+}
+
+int notification_get_count_for_uid(notification_type_e type,
+               const char *pkgname,
+               int group_id,
+               int priv_id, int *count,
+               uid_t uid)
 {
        int ret = 0;
        char *caller_pkgname = NULL;
@@ -648,7 +671,8 @@ EXPORT_API int notification_get_count(notification_type_e type,
                        caller_pkgname,
                        group_id,
                        priv_id,
-                       count);
+                       count,
+                       uid);
 
        if (caller_pkgname)
                free(caller_pkgname);
@@ -658,22 +682,35 @@ EXPORT_API int notification_get_count(notification_type_e type,
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
-EXPORT_API int notification_clear(notification_type_e type)
+EXPORT_API int notification_get_count(notification_type_e type,
+               const char *pkgname,
+               int group_id,
+               int priv_id, int *count)
+{
+       return notification_get_count_for_uid(type, pkgname, group_id, priv_id, count, getuid());
+}
+
+int notification_clear_for_uid(notification_type_e type, uid_t uid)
 {
        int ret = 0;
 
        if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       ret = notification_ipc_request_delete_multiple(type, NULL);
+       ret = notification_ipc_request_delete_multiple(type, NULL, uid);
 
        return ret;
 }
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
+EXPORT_API int notification_clear(notification_type_e type)
+{
+       return notification_clear_for_uid(type, getuid());
+}
+
 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
-                                                      void *data)
+               void *data)
 {
        if (noti_op == NULL || data == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
@@ -705,7 +742,7 @@ EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_o
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_set_pkgname(notification_h noti,
-                                                        const char *pkgname)
+               const char *pkgname)
 {
        /* check noti and pkgname are valid data */
        if (noti == NULL || pkgname == NULL)
@@ -724,8 +761,8 @@ EXPORT_API int notification_set_pkgname(notification_h noti,
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
-EXPORT_API int notification_delete_all_by_type(const char *pkgname,
-                                                               notification_type_e type)
+int notification_delete_all_by_type_for_uid(const char *pkgname,
+               notification_type_e type, uid_t uid)
 {
        int ret = 0;
        char *caller_pkgname = NULL;
@@ -738,7 +775,7 @@ EXPORT_API int notification_delete_all_by_type(const char *pkgname,
        else
                caller_pkgname = strdup(pkgname);
 
-       ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
+       ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
 
        if (caller_pkgname)
                free(caller_pkgname);
@@ -748,9 +785,16 @@ EXPORT_API int notification_delete_all_by_type(const char *pkgname,
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
-EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
-                                                              notification_type_e type,
-                                                              int priv_id)
+EXPORT_API int notification_delete_all_by_type(const char *pkgname,
+               notification_type_e type)
+{
+       return notification_delete_all_by_type_for_uid(pkgname, type, getuid());
+}
+
+int notification_delete_by_priv_id_for_uid(const char *pkgname,
+               notification_type_e type,
+               int priv_id,
+               uid_t uid)
 {
        int ret = 0;
        char *caller_pkgname = NULL;
@@ -763,7 +807,7 @@ EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
        else
                caller_pkgname = strdup(pkgname);
 
-       ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
+       ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
 
        if (caller_pkgname)
                free(caller_pkgname);
@@ -773,11 +817,18 @@ EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
+EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
+               notification_type_e type,
+               int priv_id)
+{
+       return notification_delete_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
+}
+
 EXPORT_API int notification_set_execute_option(notification_h noti,
-                                                               notification_execute_type_e type,
-                                                               const char *text,
-                                                               const char *key,
-                                                               bundle *service_handle)
+               notification_execute_type_e type,
+               const char *text,
+               const char *key,
+               bundle *service_handle)
 {
        char buf_key[32] = { 0, };
        char *ret_val = NULL;
@@ -787,7 +838,7 @@ EXPORT_API int notification_set_execute_option(notification_h noti,
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
        if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
-           || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
+                       || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
        /* Create execute option bundle if does not exist */
@@ -873,7 +924,7 @@ EXPORT_API int notification_set_execute_option(notification_h noti,
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_get_id(notification_h noti,
-                                                   int *group_id, int *priv_id)
+               int *group_id, int *priv_id)
 {
        /* check noti is valid data */
        if (noti == NULL)
@@ -898,8 +949,8 @@ EXPORT_API int notification_get_id(notification_h noti,
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
-EXPORT_API notification_h notification_load(char *pkgname,
-                                                     int priv_id)
+notification_h notification_load_for_uid(char *pkgname,
+               int priv_id, uid_t uid)
 {
        int ret = 0;
        notification_h noti = NULL;
@@ -910,7 +961,7 @@ EXPORT_API notification_h notification_load(char *pkgname,
                return NULL;
        }
 
-       ret = notification_ipc_request_load_noti_by_priv_id(noti, pkgname, priv_id);
+       ret = notification_ipc_request_load_noti_by_priv_id(noti, pkgname, priv_id, uid);
        if (ret != NOTIFICATION_ERROR_NONE) {
                notification_free(noti);
                return NULL;
@@ -920,30 +971,29 @@ EXPORT_API notification_h notification_load(char *pkgname,
 }
 /* LCOV_EXCL_STOP */
 
+EXPORT_API notification_h notification_load(char *pkgname,
+               int priv_id)
+{
+       return notification_load_for_uid(pkgname, priv_id, getuid());
+}
+
+/* LCOV_EXCL_START */
 EXPORT_API notification_h notification_new(notification_type_e type,
-                                          int group_id, int priv_id)
+               int group_id, int priv_id)
 {
-       return notification_create(type); //LCOV_EXCL_LINE
+       return notification_create(type);
 }
 
 static void _notification_get_text_domain(notification_h noti)
 {
-/*
-       if (noti->domain != NULL) {
-
-       }
-
-       if (noti->dir != NULL) {
-
-       }
-*/
 }
+/* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
 EXPORT_API int notification_get_execute_option(notification_h noti,
-                                                               notification_execute_type_e type,
-                                                               const char **text,
-                                                               bundle **service_handle)
+               notification_execute_type_e type,
+               const char **text,
+               bundle **service_handle)
 {
        char buf_key[32] = { 0, };
        char *ret_val = NULL;
@@ -954,7 +1004,7 @@ EXPORT_API int notification_get_execute_option(notification_h noti,
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
        if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
-           || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
+                       || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
 
@@ -973,7 +1023,7 @@ EXPORT_API int notification_get_execute_option(notification_h noti,
        }
 
        if (b != NULL) {
-       /* Return text */
+               /* Return text */
                if (text != NULL) {
                        /*  Get text domain and dir */
                        if (noti->domain == NULL || noti->dir == NULL)
@@ -985,7 +1035,7 @@ EXPORT_API int notification_get_execute_option(notification_h noti,
                        /* Check key key exist */
                        bundle_get_str(b, buf_key, &ret_val);
                        if (ret_val != NULL && noti->domain != NULL
-                           && noti->dir != NULL) {
+                                       && noti->dir != NULL) {
                                /* Get application string */
                                bindtextdomain(noti->domain, noti->dir);
 
@@ -1000,7 +1050,7 @@ EXPORT_API int notification_get_execute_option(notification_h noti,
                        } else {
                                /* Get basic text */
                                snprintf(buf_key, sizeof(buf_key), "text%d",
-                                        type);
+                                               type);
 
                                bundle_get_str(b, buf_key, &ret_val);
 
@@ -1016,8 +1066,8 @@ EXPORT_API int notification_get_execute_option(notification_h noti,
 }
 /* LCOV_EXCL_STOP */
 
-EXPORT_API int notification_insert(notification_h noti,
-                                                   int *priv_id)
+EXPORT_API int notification_insert_for_uid(notification_h noti,
+               int *priv_id, uid_t uid)
 {
        int ret = 0;
        int id = 0;
@@ -1028,9 +1078,10 @@ EXPORT_API int notification_insert(notification_h noti,
 
        /* Check noti type is valid type */
        if (noti->type <= NOTIFICATION_TYPE_NONE
-           || noti->type >= NOTIFICATION_TYPE_MAX)
+                       || noti->type >= NOTIFICATION_TYPE_MAX)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
+       noti->uid = uid;
        /* Save insert time */
        noti->insert_time = time(NULL);
        ret = notification_ipc_request_insert(noti, &id);
@@ -1047,14 +1098,20 @@ EXPORT_API int notification_insert(notification_h noti,
        return NOTIFICATION_ERROR_NONE;
 }
 
-EXPORT_API int notification_update_async(notification_h noti,
-               void (*result_cb)(int priv_id, int result, void *data), void *user_data)
+EXPORT_API int notification_insert(notification_h noti,
+               int *priv_id)
 {
-       int ret = 0;
+       return notification_insert_for_uid(noti, priv_id, getuid());
+}
 
+EXPORT_API int notification_update_async_for_uid(notification_h noti,
+               void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
+{
+       int ret = 0;
        if (noti == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
+       noti->uid = uid;
        /* Update insert time ? */
        noti->insert_time = time(NULL);
        ret = notification_ipc_request_update_async(noti, result_cb, user_data);
@@ -1062,9 +1119,15 @@ EXPORT_API int notification_update_async(notification_h noti,
        return ret;
 }
 
-EXPORT_API int notification_register_detailed_changed_cb(
+EXPORT_API int notification_update_async(notification_h noti,
+               void (*result_cb)(int priv_id, int result, void *data), void *user_data)
+{
+       return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
+}
+
+EXPORT_API int notification_register_detailed_changed_cb_for_uid(
                void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
-               void *user_data)
+               void *user_data, uid_t uid)
 {
        notification_cb_list_s *noti_cb_list_new = NULL;
        notification_cb_list_s *noti_cb_list = NULL;
@@ -1072,11 +1135,11 @@ EXPORT_API int notification_register_detailed_changed_cb(
        if (detailed_changed_cb == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE)
+       if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE)
                return NOTIFICATION_ERROR_IO_ERROR;
 
        noti_cb_list_new =
-           (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
+               (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
 
        if (noti_cb_list_new == NULL) {
                NOTIFICATION_ERR("malloc failed");
@@ -1106,6 +1169,13 @@ EXPORT_API int notification_register_detailed_changed_cb(
        return NOTIFICATION_ERROR_NONE;
 }
 
+EXPORT_API int notification_register_detailed_changed_cb(
+               void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
+               void *user_data)
+{
+       return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
+}
+
 EXPORT_API int notification_unregister_detailed_changed_cb(
                void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
                void *user_data)
@@ -1163,3 +1233,138 @@ EXPORT_API int notification_is_service_ready(void)
        return notification_ipc_is_master_ready();
 }
 
+EXPORT_API int notification_set_uid(notification_h noti,
+               uid_t uid)
+{
+       if (noti == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       noti->uid = uid;
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_get_uid(notification_h noti,
+               uid_t *uid)
+{
+       if (noti == NULL || uid == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       *uid = noti->uid;
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
+{
+       int ret = 0;
+       int id = 0;
+
+       /* Check noti is vaild data */
+       if (noti == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       /* Check noti type is valid type */
+       if (noti->type <= NOTIFICATION_TYPE_NONE
+                       || noti->type >= NOTIFICATION_TYPE_MAX)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       /* Save insert time */
+       noti->insert_time = time(NULL);
+       noti->uid = uid;
+
+       ret = notification_ipc_request_insert(noti, &id);
+       if (ret != NOTIFICATION_ERROR_NONE)
+               return ret;
+
+       noti->priv_id = id;
+       NOTIFICATION_DBG("from master:%d", id);
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
+{
+       int ret;
+
+       /* Check noti is valid data */
+       if (noti != NULL) {
+               noti->uid = uid;
+               /* Update insert time ? */
+               noti->insert_time = time(NULL);
+               ret = notification_ipc_request_update(noti);
+       } else {
+               notification_ipc_request_refresh(uid);
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+       }
+
+       return ret;
+}
+
+EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
+{
+       int ret = 0;
+
+       if (noti == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id, uid);
+
+       return ret;
+}
+
+EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
+{
+       int ret = 0;
+       char *caller_pkgname = NULL;
+
+       if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       caller_pkgname = notification_get_pkgname_by_pid();
+
+       ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
+
+       if (caller_pkgname)
+               free(caller_pkgname);
+
+       return ret;
+}
+
+EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
+{
+       int ret = 0;
+       notification_h noti = NULL;
+       char *caller_pkgname = NULL;
+
+       if (tag == NULL) {
+               NOTIFICATION_ERR("Invalid parameter");
+               set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
+               return NULL;
+       }
+
+       caller_pkgname = notification_get_pkgname_by_pid();
+       if (!caller_pkgname) {
+               NOTIFICATION_ERR("Failed to get a package name");
+               set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
+               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);
+               free(caller_pkgname);
+
+               return NULL;
+       }
+
+       ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, (char *)tag, uid);
+       free(caller_pkgname);
+
+       set_last_result(ret);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               notification_free(noti);
+               return NULL;
+       }
+
+       return noti;
+}
index e1e035e..115c4d2 100755 (executable)
@@ -63,7 +63,7 @@ struct _task_list {
 
 static task_list *g_task_list;
 
-static int _ipc_monitor_register(void);
+static int _ipc_monitor_register(uid_t uid);
 static int _ipc_monitor_deregister(void);
 static void _do_deffered_task(void);
 
@@ -664,7 +664,6 @@ int notification_ipc_request_insert(notification_h noti, int *priv_id)
        }
 
        /* Initialize private ID */
-       noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
        noti->group_id = NOTIFICATION_GROUP_ID_NONE;
        noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
 
@@ -767,7 +766,7 @@ int notification_ipc_request_update_async(notification_h noti,
        return result;
 }
 
-int notification_ipc_request_refresh(void)
+int notification_ipc_request_refresh(uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -779,7 +778,7 @@ int notification_ipc_request_refresh(void)
                return result;
        }
 
-       body = g_variant_new("(i)", NOTIFICATION_OP_REFRESH);
+       body = g_variant_new("(i)", uid);
        result = _send_sync_noti(body, &reply, "refresh_noti");
 
        if (reply)
@@ -789,7 +788,7 @@ int notification_ipc_request_refresh(void)
        return result;
 }
 
-int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id)
+int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id, uid_t uid)
 {
        int result;
        int id;
@@ -803,7 +802,7 @@ int notification_ipc_request_delete_single(notification_type_e type, char *pkgna
                return result;
        }
 
-       body = g_variant_new("(si)", pkgname, priv_id);
+       body = g_variant_new("(sii)", pkgname, priv_id, uid);
        result = _send_sync_noti(body, &reply, "del_noti_single");
 
        if (result == NOTIFICATION_ERROR_NONE) {
@@ -818,7 +817,7 @@ int notification_ipc_request_delete_single(notification_type_e type, char *pkgna
        return result;
 }
 
-int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname)
+int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname, uid_t uid)
 {
        int result;
        int num_deleted;
@@ -835,7 +834,7 @@ int notification_ipc_request_delete_multiple(notification_type_e type, char *pkg
        if (!pkgname)
                pkgname = "";
 
-       body = g_variant_new("(si)", pkgname, type);
+       body = g_variant_new("(sii)", pkgname, type, uid);
        result = _send_sync_noti(body, &reply, "del_noti_multiple");
 
        if (result == NOTIFICATION_ERROR_NONE) {
@@ -850,7 +849,7 @@ int notification_ipc_request_delete_multiple(notification_type_e type, char *pkg
        return result;
 }
 
-int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag)
+int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag, uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -867,7 +866,7 @@ int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *p
        if (!pkgname)
                pkgname = "";
 
-       body = g_variant_new("(ss)", pkgname, tag);
+       body = g_variant_new("(ssi)", pkgname, tag, uid);
        result = _send_sync_noti(body, &reply, "load_noti_by_tag");
 
        if (result == NOTIFICATION_ERROR_NONE) {
@@ -887,7 +886,7 @@ int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *p
        return result;
 }
 
-int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const char *pkgname, int priv_id)
+int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const char *pkgname, int priv_id, uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -904,7 +903,7 @@ int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const cha
        if (!pkgname)
                pkgname = "";
 
-       body = g_variant_new("(si)", pkgname, priv_id);
+       body = g_variant_new("(sii)", pkgname, priv_id, uid);
        result = _send_sync_noti(body, &reply, "load_noti_by_priv_id");
 
        if (result == NOTIFICATION_ERROR_NONE) {
@@ -924,7 +923,7 @@ int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const cha
 }
 
 int notification_ipc_request_get_count(notification_type_e type,
-                   const char *pkgname, int group_id, int priv_id, int *count)
+                   const char *pkgname, int group_id, int priv_id, int *count, uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -941,7 +940,7 @@ int notification_ipc_request_get_count(notification_type_e type,
        if (!pkgname)
                pkgname = "";
 
-       body = g_variant_new("(isii)", type, pkgname, group_id, priv_id);
+       body = g_variant_new("(isiii)", type, pkgname, group_id, priv_id, uid);
        result = _send_sync_noti(body, &reply, "get_noti_count");
 
        if (result == NOTIFICATION_ERROR_NONE) {
@@ -960,7 +959,7 @@ int notification_ipc_request_get_count(notification_type_e type,
 }
 
 int notification_ipc_request_load_noti_grouping_list(notification_type_e type, int count,
-               notification_list_h *list)
+               notification_list_h *list, uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -977,7 +976,7 @@ int notification_ipc_request_load_noti_grouping_list(notification_type_e type, i
                return result;
        }
 
-       body = g_variant_new("(ii)", type, count);
+       body = g_variant_new("(iii)", type, count, uid);
        result = _send_sync_noti(body, &reply, "load_noti_grouping_list");
 
        if (result == NOTIFICATION_ERROR_NONE) {
@@ -988,7 +987,6 @@ int notification_ipc_request_load_noti_grouping_list(notification_type_e type, i
                        noti = notification_create(NOTIFICATION_TYPE_NOTI);
                        g_variant_get(iter_body, "(v)", &noti_body);
                        notification_ipc_make_noti_from_gvariant(noti, noti_body);
-                       _print_noti(noti);
                        *list = notification_list_append(*list, noti);
                }
                g_variant_iter_free(iter);
@@ -1005,7 +1003,8 @@ int notification_ipc_request_load_noti_detail_list(const char *pkgname,
                int group_id,
                int priv_id,
                int count,
-               notification_list_h *list)
+               notification_list_h *list,
+               uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -1022,7 +1021,7 @@ int notification_ipc_request_load_noti_detail_list(const char *pkgname,
                return result;
        }
 
-       body = g_variant_new("(siii)", pkgname, group_id, priv_id, count);
+       body = g_variant_new("(siiii)", pkgname, group_id, priv_id, count, uid);
        result = _send_sync_noti(body, &reply, "load_noti_detail_list");
 
        if (result == NOTIFICATION_ERROR_NONE) {
@@ -1033,7 +1032,6 @@ int notification_ipc_request_load_noti_detail_list(const char *pkgname,
                        noti = notification_create(NOTIFICATION_TYPE_NOTI);
                        g_variant_get(iter_body, "(v)", &noti_body);
                        notification_ipc_make_noti_from_gvariant(noti, noti_body);
-                       _print_noti(noti);
                        *list = notification_list_append(*list, noti);
                }
                g_variant_iter_free(iter);
@@ -1048,7 +1046,8 @@ int notification_ipc_request_load_noti_detail_list(const char *pkgname,
 
 int notification_ipc_request_get_setting_array(
                notification_setting_h *setting_array,
-               int *count)
+               int *count,
+               uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -1066,7 +1065,7 @@ int notification_ipc_request_get_setting_array(
                return result;
        }
 
-       result = _send_sync_noti(NULL, &reply, "get_setting_array");
+       result = _send_sync_noti(g_variant_new("(i)", uid), &reply, "get_setting_array");
 
        if (result == NOTIFICATION_ERROR_NONE) {
                reply_body = g_dbus_message_get_body(reply);
@@ -1101,7 +1100,7 @@ int notification_ipc_request_get_setting_array(
 }
 
 int notification_ipc_request_get_setting_by_package_name(
-               const char *package_name, notification_setting_h *setting)
+               const char *package_name, notification_setting_h *setting, uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -1116,7 +1115,7 @@ int notification_ipc_request_get_setting_by_package_name(
                return result;
        }
 
-       body = g_variant_new("(s)", package_name);
+       body = g_variant_new("(si)", package_name, uid);
        result = _send_sync_noti(body, &reply, "get_setting_by_package_name");
 
        if (result == NOTIFICATION_ERROR_NONE) {
@@ -1143,7 +1142,7 @@ int notification_ipc_request_get_setting_by_package_name(
        return result;
 }
 
-int notification_ipc_request_load_system_setting(notification_system_setting_h *setting)
+int notification_ipc_request_load_system_setting(notification_system_setting_h *setting, uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -1157,7 +1156,7 @@ int notification_ipc_request_load_system_setting(notification_system_setting_h *
                return result;
        }
 
-       result = _send_sync_noti(NULL, &reply, "load_system_setting");
+       result = _send_sync_noti(g_variant_new("(i)", uid), &reply, "load_system_setting");
 
        if (result == NOTIFICATION_ERROR_NONE) {
                reply_body = g_dbus_message_get_body(reply);
@@ -1182,7 +1181,7 @@ int notification_ipc_request_load_system_setting(notification_system_setting_h *
        return result;
 }
 
-int notification_ipc_update_setting(notification_setting_h setting)
+int notification_ipc_update_setting(notification_setting_h setting, uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -1194,11 +1193,12 @@ int notification_ipc_update_setting(notification_setting_h setting)
                return result;
        }
 
-       body = g_variant_new("(siii)",
+       body = g_variant_new("(siiii)",
                        setting->package_name,
                        (int)(setting->allow_to_notify),
                        (int)(setting->do_not_disturb_except),
-                       (int)(setting->visibility_class));
+                       (int)(setting->visibility_class),
+                       uid);
 
        result = _send_sync_noti(body, &reply, "update_noti_setting");
 
@@ -1209,7 +1209,7 @@ int notification_ipc_update_setting(notification_setting_h setting)
        return result;
 }
 
-int notification_ipc_update_system_setting(notification_system_setting_h system_setting)
+int notification_ipc_update_system_setting(notification_system_setting_h system_setting, uid_t uid)
 {
        int result;
        GDBusMessage *reply = NULL;
@@ -1221,9 +1221,10 @@ int notification_ipc_update_system_setting(notification_system_setting_h system_
                return result;
        }
 
-       body = g_variant_new("(ii)",
+       body = g_variant_new("(iii)",
                        (int)(system_setting->do_not_disturb),
-                       (int)(system_setting->visibility_class));
+                       (int)(system_setting->visibility_class),
+                       uid);
 
        result = _send_sync_noti(body, &reply, "update_noti_sys_setting");
 
@@ -1428,6 +1429,7 @@ EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h not
        g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ONGOING_FLAG, g_variant_new_int32(noti->ongoing_flag));
 
        g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_AUTO_REMOVE, g_variant_new_int32(noti->auto_remove));
+       g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_UID, g_variant_new_int32(noti->uid));
 
        result_body = g_variant_builder_end(&builder);
        body = g_variant_new("(v)", result_body);
@@ -1574,6 +1576,7 @@ EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TAG, "&s", &tag);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ONGOING_FLAG, "i", &noti->ongoing_flag);
        _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_AUTO_REMOVE, "i", &noti->auto_remove);
+       _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_UID, "i", &noti->uid);
 
        noti->caller_pkgname = _dup_string(caller_pkgname);
        noti->launch_pkgname = _dup_string(launch_pkgname);
@@ -1691,14 +1694,14 @@ EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_s
        return NOTIFICATION_ERROR_NONE;
 }
 
-static int _send_service_register()
+static int _send_service_register(uid_t uid)
 {
        NOTIFICATION_DBG("service register");
        GDBusMessage *reply = NULL;
        int result;
        notification_op *noti_op = NULL;
 
-       result = _send_sync_noti(NULL, &reply, "noti_service_register");
+       result = _send_sync_noti(g_variant_new("(i)", uid), &reply, "noti_service_register");
 
        if (reply)
                g_object_unref(reply);
@@ -1713,11 +1716,11 @@ static int _send_service_register()
        return result;
 }
 
-static int _ipc_monitor_register(void)
+static int _ipc_monitor_register(uid_t uid)
 {
        NOTIFICATION_ERR("register a service\n");
 
-       return  _send_service_register();
+       return  _send_service_register(uid);
 }
 
 static void _on_name_appeared(GDBusConnection *connection,
@@ -1725,9 +1728,10 @@ static void _on_name_appeared(GDBusConnection *connection,
                const gchar     *name_owner,
                gpointer         user_data)
 {
-       NOTIFICATION_DBG("name appeared : %s", name);
+       int uid = GPOINTER_TO_INT(user_data);
+       NOTIFICATION_DBG("name appeared [%d] : %s", uid, name);
        is_master_started = 1;
-       _ipc_monitor_register();
+       _ipc_monitor_register(uid);
 
        /* TODO: dbus activation isn't enough ? */
        _do_deffered_task();
@@ -1737,11 +1741,12 @@ static void _on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
                gpointer         user_data)
 {
-       NOTIFICATION_DBG("name vanished : %s", name);
+       int uid = GPOINTER_TO_INT(user_data);
+       NOTIFICATION_DBG("name vanished [%d] : %s", uid, name);
        is_master_started = 0;
 }
 
-int notification_ipc_monitor_init(void)
+int notification_ipc_monitor_init(uid_t uid)
 {
        int ret;
 
@@ -1757,20 +1762,21 @@ int notification_ipc_monitor_init(void)
                return ret;
        }
 
-       ret = _ipc_monitor_register();
+       ret = _ipc_monitor_register(uid);
        if (ret != NOTIFICATION_ERROR_NONE) {
                NOTIFICATION_ERR("Can't init ipc_monitor_register %d", ret);
                return ret;
        }
 
        if (provider_monitor_id == 0) {
+
                provider_monitor_id = g_bus_watch_name_on_connection(
                                _gdbus_conn,
                                PROVIDER_BUS_NAME,
                                G_BUS_NAME_WATCHER_FLAGS_NONE,
                                _on_name_appeared,
                                _on_name_vanished,
-                               NULL,
+                               GINT_TO_POINTER((int)uid),
                                NULL);
 
                if (provider_monitor_id == 0) {
index 1012732..5110136 100755 (executable)
@@ -138,7 +138,7 @@ EXPORT_API notification_h notification_list_get_data(notification_list_h list)
 }
 
 EXPORT_API notification_list_h notification_list_append(notification_list_h list,
-                                                       notification_h noti)
+               notification_h noti)
 {
        notification_list_h new_list = NULL;
        notification_list_h cur_list = NULL;
@@ -180,7 +180,7 @@ EXPORT_API notification_list_h notification_list_append(notification_list_h list
 }
 
 EXPORT_API notification_list_h notification_list_remove(notification_list_h list,
-                                                       notification_h noti)
+               notification_h noti)
 {
        notification_list_h cur_list = NULL;
        notification_list_h prev_list = NULL;
@@ -220,9 +220,9 @@ EXPORT_API notification_list_h notification_list_remove(notification_list_h list
        return NULL;
 }
 
-EXPORT_API int notification_get_list(notification_type_e type,
-                                                     int count,
-                                                     notification_list_h *list)
+EXPORT_API int notification_get_list_for_uid(notification_type_e type,
+               int count,
+               notification_list_h *list, uid_t uid)
 {
        notification_list_h get_list = NULL;
        int ret = 0;
@@ -230,7 +230,7 @@ EXPORT_API int notification_get_list(notification_type_e type,
        if (list == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       ret = notification_ipc_request_load_noti_grouping_list(type, count, &get_list);
+       ret = notification_ipc_request_load_noti_grouping_list(type, count, &get_list, uid);
        if (ret != NOTIFICATION_ERROR_NONE)
                return ret;
 
@@ -240,11 +240,19 @@ EXPORT_API int notification_get_list(notification_type_e type,
        return NOTIFICATION_ERROR_NONE;
 }
 
-EXPORT_API int notification_get_detail_list(const char *pkgname,
-                                                            int group_id,
-                                                            int priv_id,
-                                                            int count,
-                                                            notification_list_h *list)
+EXPORT_API int notification_get_list(notification_type_e type,
+               int count,
+               notification_list_h *list)
+{
+       return notification_get_list_for_uid(type, count, list, getuid());
+}
+
+EXPORT_API int notification_get_detail_list_for_uid(const char *pkgname,
+               int group_id,
+               int priv_id,
+               int count,
+               notification_list_h *list,
+               uid_t uid)
 {
        notification_list_h get_list = NULL;
        int ret = 0;
@@ -252,9 +260,8 @@ EXPORT_API int notification_get_detail_list(const char *pkgname,
        if (list == NULL || pkgname == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       ret =
-           notification_ipc_request_load_noti_detail_list(pkgname, group_id, priv_id, count,
-                                             &get_list);
+       ret = notification_ipc_request_load_noti_detail_list(pkgname, group_id, priv_id, count,
+                       &get_list, uid);
        if (ret != NOTIFICATION_ERROR_NONE)
                return ret;
 
@@ -264,6 +271,16 @@ EXPORT_API int notification_get_detail_list(const char *pkgname,
        return NOTIFICATION_ERROR_NONE;
 }
 
+EXPORT_API int notification_get_detail_list(const char *pkgname,
+               int group_id,
+               int priv_id,
+               int count,
+               notification_list_h *list)
+{
+       return notification_get_detail_list_for_uid(pkgname, group_id,
+                       priv_id, count, list, getuid());
+}
+
 EXPORT_API int notification_free_list(notification_list_h list)
 {
        notification_list_h cur_list = NULL;
index 362e894..177d355 100755 (executable)
@@ -23,6 +23,7 @@
 #include <package_manager.h>
 
 #include <notification.h>
+#include <notification_internal.h>
 #include <notification_db.h>
 #include <notification_list.h>
 #include <notification_noti.h>
@@ -249,7 +250,7 @@ static int _insertion_query_create(notification_h noti, char **query)
                "layout, "
                "caller_pkgname, launch_pkgname, "
                "image_path, "
-               "group_id, internal_group_id, priv_id, "
+               "group_id, internal_group_id,"
                "title_key, "
                "b_text, b_key, tag, b_format_args, num_format_args, "
                "text_domain, text_dir, "
@@ -262,12 +263,12 @@ static int _insertion_query_create(notification_h noti, char **query)
                "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) values ("
+               "progress_size, progress_percentage, ongoing_flag, auto_remove, uid) values ("
                "%d, "
                "%d, "
                "'%s', '%s', "
                "'%s', "
-               "%d, %d, %d, "
+               "%d, %d,"
                "$title_key, "
                "'%s', '%s', $tag, '%s', %d, "
                "'%s', '%s', "
@@ -280,13 +281,13 @@ static int _insertion_query_create(notification_h noti, char **query)
                "'%s', '%s', "
                "%d, '%s', %d, '%s', %d, %d, %d, %d,"
                "%d, %d, %d, "
-               "$progress_size, $progress_percentage, %d, %d)",
+               "$progress_size, $progress_percentage, %d, %d, %d)",
                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, noti->priv_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),
@@ -314,7 +315,8 @@ static int _insertion_query_create(notification_h noti, char **query)
                noti->led_off_ms,
                noti->flags_for_property, flag_simmode, noti->display_applist,
                noti->ongoing_flag,
-               noti->auto_remove);
+               noti->auto_remove,
+               noti->uid);
 
        /* Free decoded data */
        if (args)
@@ -728,14 +730,14 @@ out:
        return err;
 }
 
-static bool _is_allowed_to_notify(const char *caller_package_name)
+static bool _is_allowed_to_notify(const char *caller_package_name, uid_t uid)
 {
        notification_setting_h setting = NULL;
        int err;
        char *package_id = NULL;
        bool ret = true;
 
-       err = noti_setting_service_get_setting_by_package_name(caller_package_name, &setting);
+       err = noti_setting_service_get_setting_by_package_name(caller_package_name, &setting, uid);
        if (err != NOTIFICATION_ERROR_NONE) {
                /* Retry with package id */
                err = _get_package_id_by_app_id(caller_package_name, &package_id);
@@ -744,7 +746,7 @@ static bool _is_allowed_to_notify(const char *caller_package_name)
                        NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
                        goto out;
                } else {
-                       err = noti_setting_service_get_setting_by_package_name(package_id, &setting);
+                       err = noti_setting_service_get_setting_by_package_name(package_id, &setting, uid);
                        if (err != NOTIFICATION_ERROR_NONE) {
                                NOTIFICATION_ERR("noti_setting_service_get_setting_by_package_name failed [%d]", err);
                                goto out;
@@ -787,7 +789,7 @@ static int _handle_do_not_disturb_option(notification_h noti)
        }
 
        /* Get system setting */
-       if ((err = noti_system_setting_load_system_setting(&system_setting)) != NOTIFICATION_ERROR_NONE) {
+       if ((err = noti_system_setting_load_system_setting(&system_setting, noti->uid)) != NOTIFICATION_ERROR_NONE) {
                NOTIFICATION_ERR("noti_system_setting_load_system_setting failed [%d]", err);
                goto out;
        }
@@ -801,7 +803,7 @@ static int _handle_do_not_disturb_option(notification_h noti)
 
        if (do_not_disturb) {
                /* Check exception option of the caller package */
-               err = noti_setting_service_get_setting_by_package_name(noti->caller_pkgname, &setting);
+               err = noti_setting_service_get_setting_by_package_name(noti->caller_pkgname, &setting, noti->uid);
 
                if (err != NOTIFICATION_ERROR_NONE) {
                        /* Retry with package id */
@@ -811,7 +813,7 @@ static int _handle_do_not_disturb_option(notification_h noti)
                                NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
                                goto out;
                        } else {
-                               err = noti_setting_service_get_setting_by_package_name(package_id, &setting);
+                               err = noti_setting_service_get_setting_by_package_name(package_id, &setting, noti->uid);
                                if (err != NOTIFICATION_ERROR_NONE) {
                                        NOTIFICATION_ERR("noti_setting_service_get_setting_by_package_name failed [%d]", err);
                                        goto out;
@@ -868,7 +870,7 @@ EXPORT_API int notification_noti_insert(notification_h noti)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
 
-       if (_is_allowed_to_notify((const char *)noti->caller_pkgname) == false) {
+       if (_is_allowed_to_notify((const char *)noti->caller_pkgname, noti->uid) == false) {
                NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
                return NOTIFICATION_ERROR_PERMISSION_DENIED;
        }
@@ -883,7 +885,6 @@ EXPORT_API int notification_noti_insert(notification_h noti)
                return get_last_result();
 
        /* Initialize private ID */
-       noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
        noti->group_id = NOTIFICATION_GROUP_ID_NONE;
        noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
 
@@ -967,7 +968,7 @@ err:
        return ret;
 }
 
-EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id)
+EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id, uid_t uid)
 {
        int ret = 0;
        char *query = NULL;
@@ -997,10 +998,10 @@ EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, char *pkgna
                         "from noti_list ";
 
        if (pkgname != NULL && strlen(pkgname) != 0)
-               query = sqlite3_mprintf("%s where caller_pkgname = '%s' and priv_id = %d",
-                               base_query, pkgname, priv_id);
+               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", base_query,  priv_id);
+               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;
@@ -1038,7 +1039,7 @@ err:
        return ret;
 }
 
-EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag)
+EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag, uid_t uid)
 {
        int ret = 0;
        sqlite3 *db = NULL;
@@ -1065,7 +1066,7 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname,
                         "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_list where caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
+                        "from noti_list where caller_pkgname = ? and tag = ? and uid = ?", -1, &stmt, NULL);
                if (ret != SQLITE_OK) {
                        NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
                        return NOTIFICATION_ERROR_OUT_OF_MEMORY;
@@ -1082,6 +1083,13 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname,
                        NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
                        goto err;
                }
+
+               ret = sqlite3_bind_int(stmt, 3, uid);
+               if (ret != SQLITE_OK) {
+                       NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+                       goto err;
+               }
+
        } else {
                ret = sqlite3_prepare_v2(db, "select "
                         "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
@@ -1093,7 +1101,7 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname,
                         "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_list where  tag = ?", -1, &stmt, NULL);
+                        "from noti_list where  tag = ? and uid = ?", -1, &stmt, NULL);
                if (ret != SQLITE_OK) {
                        NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
                        return NOTIFICATION_ERROR_OUT_OF_MEMORY;
@@ -1104,6 +1112,12 @@ EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname,
                        NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
                        goto err;
                }
+
+               ret = sqlite3_bind_int(stmt, 2, uid);
+               if (ret != SQLITE_OK) {
+                       NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
+                       goto err;
+               }
        }
 
        ret = sqlite3_step(stmt);
@@ -1138,7 +1152,7 @@ EXPORT_API int notification_noti_update(notification_h noti)
        if (!db)
                return get_last_result();
 
-       if (_is_allowed_to_notify((const char *)noti->caller_pkgname) == false) {
+       if (_is_allowed_to_notify((const char *)noti->caller_pkgname, noti->uid) == false) {
                NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
                return NOTIFICATION_ERROR_PERMISSION_DENIED;
        }
@@ -1205,7 +1219,7 @@ err:
        return ret;
 }
 
-EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
+EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid, uid_t uid)
 {
        int ret = NOTIFICATION_ERROR_NONE;
        int ret_tmp = NOTIFICATION_ERROR_NONE;
@@ -1226,16 +1240,16 @@ EXPORT_API int notification_noti_delete_all(notification_type_e type, const char
        if (pkgname == NULL || strlen(pkgname) == 0) {
                if (type != NOTIFICATION_TYPE_NONE)
                        snprintf(query_where, sizeof(query_where),
-                                "where type = %d ", type);
+                                "where type = %d and uid = %d", type, uid);
 
        } else {
                if (type == NOTIFICATION_TYPE_NONE)
                        snprintf(query_where, sizeof(query_where),
-                                "where caller_pkgname = '%s' ", pkgname);
+                                "where caller_pkgname = '%s' and uid = %d", pkgname, uid);
                else
                        snprintf(query_where, sizeof(query_where),
-                                "where caller_pkgname = '%s' and type = %d ",
-                                pkgname, type);
+                                "where caller_pkgname = '%s' and type = %d and uid = %d",
+                                pkgname, type, uid);
 
        }
 
@@ -1337,153 +1351,6 @@ err:
        return ret;
 }
 
-int notification_noti_delete_group_by_group_id(const char *pkgname,
-                                              int group_id, int *num_deleted, int **list_deleted_rowid)
-{
-       int ret = NOTIFICATION_ERROR_NONE;
-       int ret_tmp = NOTIFICATION_ERROR_NONE;
-       sqlite3 *db = NULL;
-       int i = 0, data_cnt = 0;
-       sqlite3_stmt *stmt = NULL;
-       char buf[128] = { 0, };
-       char query[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
-       char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
-
-       /* Check pkgname is valid */
-       if (pkgname == NULL)
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
-       snprintf(query_where, sizeof(query_where),
-                       "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
-
-       /* Open DB */
-       db = notification_db_open(DBPATH);
-       if (!db)
-               return get_last_result();
-
-       if (num_deleted != NULL)
-               *num_deleted = 0;
-
-       if (list_deleted_rowid != NULL) {
-               *list_deleted_rowid = NULL;
-               snprintf(query, sizeof(query),
-                               "select priv_id from noti_list %s ", query_where);
-
-               ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
-               if (ret != SQLITE_OK) {
-                       NOTIFICATION_ERR("Select Query : %s", query);
-                       NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
-                                        sqlite3_errmsg(db));
-
-                       ret = NOTIFICATION_ERROR_FROM_DB;
-                       goto err;
-               }
-
-               while (sqlite3_step(stmt) == SQLITE_ROW) {
-                       if (data_cnt % 8 == 0) {
-                               int *tmp;
-                               tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
-                               if (tmp) {
-                                       *list_deleted_rowid = tmp;
-                               } else {
-                                       free(*list_deleted_rowid);
-                                       *list_deleted_rowid = NULL;
-                                       ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
-                                       goto err;
-                               }
-                       }
-                       *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
-                       data_cnt++;
-               }
-
-               if (stmt) {
-                       sqlite3_finalize(stmt);
-                       stmt = NULL;
-               }
-
-               if (data_cnt > 0) {
-                       query_where[0] = '\0';
-                       snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
-                       for (i = 0; i < data_cnt ; i++) {
-                               if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
-                                       snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
-                                       ret_tmp = notification_db_exec(db, query, NULL);
-                                       query_where[0] = '\0';
-                                       if (ret == NOTIFICATION_ERROR_NONE)
-                                               ret = ret_tmp;
-                               }
-                               snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
-                               strncat(query_where, buf, sizeof(query_where) - strlen(query_where) - 1);
-                       }
-                       if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0)) {
-                               snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
-                               ret_tmp = notification_db_exec(db, query, NULL);
-                               if (ret == NOTIFICATION_ERROR_NONE)
-                                       ret = ret_tmp;
-                       }
-               } else {
-                       free(*list_deleted_rowid);
-                       *list_deleted_rowid = NULL;
-               }
-
-               if (num_deleted != NULL)
-                       *num_deleted = data_cnt;
-
-       } else {
-               /* Make query */
-               snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
-
-               /* execute DB */
-               ret = notification_db_exec(db, query, NULL);
-       }
-
-err:
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       /* Close DB */
-       if (db)
-               notification_db_close(&db);
-
-       return ret;
-}
-
-int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
-{
-       sqlite3 *db = NULL;
-       char query[NOTIFICATION_QUERY_MAX] = { 0, };
-       int internal_group_id = 0;
-       int ret;
-
-       /* Check pkgname is valid */
-       if (pkgname == NULL)
-               return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
-       /* Open DB */
-       db = notification_db_open(DBPATH);
-       if (!db)
-               return get_last_result();
-
-       /* Get internal group id using priv id */
-       internal_group_id =
-           _notification_noti_get_internal_group_id_by_priv_id(pkgname,
-                                                               priv_id, db);
-
-       /* Make query */
-       snprintf(query, sizeof(query), "delete from noti_list "
-                "where caller_pkgname = '%s' and internal_group_id = %d",
-                pkgname, internal_group_id);
-
-       /* execute DB */
-       ret = notification_db_exec(db, query, NULL);
-
-       /* Close DB */
-       notification_db_close(&db);
-
-       return ret;
-}
-
 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
 {
        sqlite3 *db = NULL;
@@ -1514,7 +1381,7 @@ EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv
        return ret;
 }
 
-EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes)
+EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes, uid_t uid)
 {
        sqlite3 *db = NULL;
        char query[NOTIFICATION_QUERY_MAX] = {0, };
@@ -1531,8 +1398,8 @@ EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgna
 
        /* Make query */
        snprintf(query, sizeof(query), "delete from noti_list "
-                "where caller_pkgname = '%s' and priv_id = %d", pkgname,
-                priv_id);
+                "where caller_pkgname = '%s' and priv_id = %d and uid = %d", pkgname,
+                priv_id, uid);
        NOTIFICATION_DBG("%s", query);
 
        /* execute DB */
@@ -1548,10 +1415,11 @@ EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgna
        return ret;
 }
 
+/* todo refactoring */
 EXPORT_API int notification_noti_get_count(notification_type_e type,
                                                 const char *pkgname,
                                                 int group_id, int priv_id,
-                                                int *count)
+                                                int *count, uid_t uid)
 {
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
@@ -1562,7 +1430,6 @@ EXPORT_API int notification_noti_get_count(notification_type_e type,
 
        int ret = 0, get_count = 0, internal_group_id = 0;
        int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
-       int flag_where = 0;
        int flag_where_more = 0;
        int ret_vconf = 0;
 
@@ -1582,35 +1449,32 @@ EXPORT_API int notification_noti_get_count(notification_type_e type,
                if (group_id == NOTIFICATION_GROUP_ID_NONE) {
                        if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
                                snprintf(query_where, sizeof(query_where),
-                                        "where caller_pkgname = '%s' ",
-                                        pkgname);
-                               flag_where = 1;
+                                        "where caller_pkgname = '%s' and uid = %d ",
+                                        pkgname, uid);
                        } else {
                                internal_group_id =
                                    _notification_noti_get_internal_group_id_by_priv_id
                                    (pkgname, priv_id, db);
                                snprintf(query_where, sizeof(query_where),
-                                        "where caller_pkgname = '%s' and internal_group_id = %d ",
-                                        pkgname, internal_group_id);
-                               flag_where = 1;
+                                        "where caller_pkgname = '%s' and internal_group_id = %d and uid = %d ",
+                                        pkgname, internal_group_id, uid);
                        }
                } else {
                        if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
                                snprintf(query_where, sizeof(query_where),
-                                        "where caller_pkgname = '%s' and group_id = %d ",
-                                        pkgname, group_id);
-                               flag_where = 1;
+                                        "where caller_pkgname = '%s' and group_id = %d and uid = %d ",
+                                        pkgname, group_id, uid);
                        } else {
                                internal_group_id =
                                    _notification_noti_get_internal_group_id_by_priv_id
                                    (pkgname, priv_id, db);
                                snprintf(query_where, sizeof(query_where),
-                                        "where caller_pkgname = '%s' and internal_group_id = %d ",
-                                        pkgname, internal_group_id);
-                               flag_where = 1;
+                                        "where caller_pkgname = '%s' and internal_group_id = %d and uid = %d ",
+                                        pkgname, internal_group_id, uid);
                        }
                }
-
+       } else {
+               snprintf(query_where, sizeof(query_where), "where uid = %d", uid);
        }
 
        if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
@@ -1631,22 +1495,12 @@ EXPORT_API int notification_noti_get_count(notification_type_e type,
                }
        }
 
-       if (flag_where == 1) {
-               if (flag_where_more == 1) {
-                       snprintf(query, sizeof(query), "%s %s and %s",
-                                query_base, query_where, query_where_more);
-               } else {
-                       snprintf(query, sizeof(query), "%s %s", query_base,
-                                query_where);
-               }
-
+       if (flag_where_more == 1) {
+               snprintf(query, sizeof(query), "%s %s and %s",
+                        query_base, query_where, query_where_more);
        } else {
-               if (flag_where_more == 1) {
-                       snprintf(query, sizeof(query), "%s where %s",
-                                query_base, query_where_more);
-               } else {
-                       snprintf(query, sizeof(query), "%s", query_base);
-               }
+               snprintf(query, sizeof(query), "%s %s", query_base,
+                        query_where);
        }
 
        ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
@@ -1681,13 +1535,14 @@ err:
 
 EXPORT_API int notification_noti_get_grouping_list(notification_type_e type,
                                                         int count,
-                                                        notification_list_h *
-                                                        list)
+                                                        notification_list_h *list,
+                                                        uid_t uid)
 {
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
        char query[NOTIFICATION_QUERY_MAX] = { 0, };
        char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
+       char query_uid[NOTIFICATION_QUERY_MAX] = { 0, };
        char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
 
        int ret = 0;
@@ -1715,25 +1570,28 @@ EXPORT_API int notification_noti_get_grouping_list(notification_type_e type,
                 "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_list ");
+                "from noti_list where 1 > 0 ");
 
        if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
                if (type != NOTIFICATION_TYPE_NONE)
                        snprintf(query_where, sizeof(query_where),
-                                "where type = %d ", type);
+                                " and type = %d ", type);
        } else {
                if (type != NOTIFICATION_TYPE_NONE)
                        snprintf(query_where, sizeof(query_where),
-                                "where type = %d and flag_simmode = 0 ", type);
+                                " and type = %d and flag_simmode = 0 ", type);
                else
                        snprintf(query_where, sizeof(query_where),
-                                "where flag_simmode = 0 ");
+                                " and flag_simmode = 0 ");
        }
 
+       if (uid != NOTIFICATION_GLOBAL_UID)
+               snprintf(query_uid, sizeof(query_uid), " and uid = %d ", uid);
+
        snprintf(query, sizeof(query),
-                "%s %s "
+                "%s %s %s "
                 "group by internal_group_id "
-                "order by rowid desc, time desc", query_base, query_where);
+                "order by rowid desc, time desc", query_base, query_where, query_uid);
 
        ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
@@ -1774,14 +1632,14 @@ err:
 
        if (get_list != NULL)
                *list = notification_list_get_head(get_list);
-
        return ret;
 }
 
 EXPORT_API int notification_noti_get_detail_list(const char *pkgname,
                                                       int group_id,
                                                       int priv_id, int count,
-                                                      notification_list_h *list)
+                                                      notification_list_h *list,
+                                                      uid_t uid)
 {
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
@@ -1820,10 +1678,10 @@ EXPORT_API int notification_noti_get_detail_list(const char *pkgname,
        if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
                if (status == VCONFKEY_TELEPHONY_SIM_INSERTED)
                        snprintf(query_where, sizeof(query_where),
-                                "where  caller_pkgname = '%s' ", pkgname);
+                                "where  caller_pkgname = '%s' and uid = %d ", pkgname, uid);
                else
                        snprintf(query_where, sizeof(query_where),
-                                "where  caller_pkgname = '%s' and flag_simmode = 0 ", pkgname);
+                                "where  caller_pkgname = '%s' and flag_simmode = 0 and uid = %d ", pkgname, uid);
 
        } else {
                internal_group_id =
@@ -1832,12 +1690,12 @@ EXPORT_API int notification_noti_get_detail_list(const char *pkgname,
 
                if (status == VCONFKEY_TELEPHONY_SIM_INSERTED)
                        snprintf(query_where, sizeof(query_where),
-                                "where  caller_pkgname = '%s' and internal_group_id = %d ",
-                                pkgname, internal_group_id);
+                                "where  caller_pkgname = '%s' and internal_group_id = %d and uid = %d ",
+                                pkgname, internal_group_id, uid);
                else
                        snprintf(query_where, sizeof(query_where),
-                                "where  caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
-                                pkgname, internal_group_id);
+                                "where  caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 and uid = %d ",
+                                pkgname, internal_group_id, uid);
        }
 
        snprintf(query, sizeof(query),
index a90274f..c07015c 100755 (executable)
 
 #define NOTIFICATION_PRIVILEGE "http://tizen.org/privilege/notification"
 
-EXPORT_API int notification_setting_get_setting_array(notification_setting_h *setting_array, int *count)
+typedef struct {
+       uid_t uid;
+       sqlite3 *db;
+} setting_local_info;
+
+EXPORT_API int notification_setting_get_setting_array_for_uid(notification_setting_h *setting_array, int *count, uid_t uid)
 {
        int ret = NOTIFICATION_ERROR_NONE;
        if (setting_array == NULL || count == NULL) {
                NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
-       ret = notification_ipc_request_get_setting_array(setting_array, count);
+       ret = notification_ipc_request_get_setting_array(setting_array, count, uid);
        return ret;
 }
 
-EXPORT_API int notification_setting_get_setting_by_package_name(const char *package_name, notification_setting_h *setting)
+EXPORT_API int notification_setting_get_setting_array(notification_setting_h *setting_array, int *count)
+{
+       return notification_setting_get_setting_array_for_uid(setting_array, count, getuid());
+}
+
+EXPORT_API int notification_setting_get_setting_by_package_name_for_uid(const char *package_name, notification_setting_h *setting, uid_t uid)
 {
        int ret = NOTIFICATION_ERROR_NONE;
        if (package_name == NULL || setting == NULL) {
                NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
-       ret = notification_ipc_request_get_setting_by_package_name(package_name, setting);
+       ret = notification_ipc_request_get_setting_by_package_name(package_name, setting, uid);
        return ret;
 }
 
+EXPORT_API int notification_setting_get_setting_by_package_name(const char *package_name, notification_setting_h *setting)
+{
+       return notification_setting_get_setting_by_package_name_for_uid(package_name, setting, getuid());
+}
+
 EXPORT_API int notification_setting_get_setting(notification_setting_h *setting)
 {
        int ret;
@@ -219,7 +234,7 @@ out:
        return err;
 }
 
-EXPORT_API int notification_setting_update_setting(notification_setting_h setting)
+EXPORT_API int notification_setting_update_setting_for_uid(notification_setting_h setting, uid_t uid)
 {
        int err = NOTIFICATION_ERROR_NONE;
 
@@ -229,7 +244,7 @@ EXPORT_API int notification_setting_update_setting(notification_setting_h settin
                goto out;
        }
 
-       err = notification_ipc_update_setting(setting);
+       err = notification_ipc_update_setting(setting, uid);
        if (err != NOTIFICATION_ERROR_NONE) {
                NOTIFICATION_ERR("notification_setting_update_setting returns[%d]\n", err);
                goto out;
@@ -239,6 +254,11 @@ out:
        return err;
 }
 
+EXPORT_API int notification_setting_update_setting(notification_setting_h setting)
+{
+       return notification_setting_update_setting_for_uid(setting, getuid());
+}
+
 EXPORT_API int notification_setting_free_notification(notification_setting_h setting)
 {
        int err = NOTIFICATION_ERROR_NONE;
@@ -259,7 +279,7 @@ out:
        return err;
 }
 
-EXPORT_API int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class)
+EXPORT_API int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class, uid_t uid)
 {
        int err = NOTIFICATION_ERROR_NONE;
        sqlite3 *db = NULL;
@@ -276,8 +296,8 @@ EXPORT_API int notification_setting_db_update(const char *package_name, int allo
        }
 
        sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_notify = %d, do_not_disturb_except = %d, visibility_class = %d " \
-                       "WHERE package_name = %Q",
-                       NOTIFICATION_SETTING_DB_TABLE, allow_to_notify, do_not_disturb_except, visibility_class, package_name);
+                       "WHERE package_name = %Q AND uid = %d",
+                       NOTIFICATION_SETTING_DB_TABLE, allow_to_notify, do_not_disturb_except, visibility_class, package_name, uid);
        if (!sqlbuf) {
                NOTIFICATION_ERR("fail to alloc query");
                err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
@@ -297,14 +317,14 @@ return_close_db:
        return err;
 }
 
-static bool _is_package_in_setting_table(sqlite3 *db, const char *package_name)
+static bool _is_package_in_setting_table(sqlite3 *db, const char *package_name, uid_t uid)
 {
        sqlite3_stmt *db_statement = NULL;
        int sqlite3_ret = SQLITE_OK;
        bool err = true;
        int field_index = 1;
 
-       sqlite3_ret = sqlite3_prepare_v2(db, "SELECT package_name FROM notification_setting WHERE package_name = ?", -1, &db_statement, NULL);
+       sqlite3_ret = sqlite3_prepare_v2(db, "SELECT package_name FROM notification_setting WHERE uid = ? AND package_name = ?", -1, &db_statement, NULL);
 
        if (sqlite3_ret != SQLITE_OK) {
                NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db));
@@ -312,6 +332,7 @@ static bool _is_package_in_setting_table(sqlite3 *db, const char *package_name)
                goto out;
        }
 
+       sqlite3_bind_int(db_statement, field_index++, uid);
        sqlite3_bind_text(db_statement, field_index++, package_name, -1, SQLITE_TRANSIENT);
 
        sqlite3_ret = sqlite3_step(db_statement);
@@ -336,7 +357,8 @@ out:
 
 static int foreach_package_info_callback(const pkgmgrinfo_pkginfo_h package_info, void *user_data)
 {
-       sqlite3 *db = user_data;
+       setting_local_info *info = (setting_local_info *)user_data;
+       sqlite3 *db = info->db;
        sqlite3_stmt *db_statement = NULL;
        char *package_name = NULL;
        int pkgmgr_ret = PACKAGE_MANAGER_ERROR_NONE;
@@ -350,14 +372,13 @@ static int foreach_package_info_callback(const pkgmgrinfo_pkginfo_h package_info
                goto out;
        }
 
-       if (_is_package_in_setting_table(db, package_name) == true) {
-               NOTIFICATION_INFO("[%s] is exist", package_name);
+       if (_is_package_in_setting_table(db, package_name, info->uid) == true) {
+               NOTIFICATION_INFO("uid %d [%s] is exist", info->uid, package_name);
                goto out;
        }
 
-       NOTIFICATION_INFO("[%s] will be inserted", package_name);
-
-       sqlite3_ret = sqlite3_prepare_v2(db, "INSERT INTO notification_setting (package_name) VALUES (?) ", -1, &db_statement, NULL);
+       NOTIFICATION_INFO("uid %d [%s] will be inserted", info->uid, package_name);
+       sqlite3_ret = sqlite3_prepare_v2(db, "INSERT INTO notification_setting (uid, package_name) VALUES (?, ?) ", -1, &db_statement, NULL);
 
        if (sqlite3_ret != SQLITE_OK) {
                NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db));
@@ -365,6 +386,7 @@ static int foreach_package_info_callback(const pkgmgrinfo_pkginfo_h package_info
                goto out;
        }
 
+       sqlite3_bind_int(db_statement, field_index++, info->uid);
        sqlite3_bind_text(db_statement, field_index++, package_name, -1, SQLITE_TRANSIENT);
 
        sqlite3_ret = sqlite3_step(db_statement);
@@ -384,14 +406,16 @@ out:
        return err;
 }
 
-EXPORT_API int notification_setting_refresh_setting_table()
+EXPORT_API int notification_setting_refresh_setting_table(uid_t uid)
 {
        int err = NOTIFICATION_ERROR_NONE;
        sqlite3 *db = NULL;
        int sqlite3_ret = SQLITE_OK;
        int pkgmgr_ret = PACKAGE_MANAGER_ERROR_NONE;
        pkgmgrinfo_pkginfo_filter_h filter;
+       setting_local_info info;
 
+       NOTIFICATION_ERR("refresh seeting table [%d]", uid);
        sqlite3_ret = db_util_open(DBPATH, &db, 0);
 
        if (sqlite3_ret != SQLITE_OK || db == NULL) {
@@ -416,11 +440,9 @@ EXPORT_API int notification_setting_refresh_setting_table()
                goto out;
        }
 
-       /*
-        * DEFAULT_UID is owner's uid(5001)
-        * currently this api do not support multi-user.
-       */
-       pkgmgr_ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(filter, foreach_package_info_callback, db, tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+       info.db = db;
+       info.uid = uid;
+       pkgmgr_ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(filter, foreach_package_info_callback, &info, uid);
        if (pkgmgr_ret != PMINFO_R_OK) {
                NOTIFICATION_ERR("pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo failed [%d]", pkgmgr_ret);
                err = NOTIFICATION_ERROR_FROM_DB;
@@ -452,7 +474,7 @@ typedef enum {
        OPERATION_TYPE_DELETE_RECORD = 1,
 } notification_setting_operation_type;
 
-static int _notification_setting_alter_package_list(notification_setting_operation_type operation_type, const char *package_name)
+static int _notification_setting_alter_package_list(notification_setting_operation_type operation_type, const char *package_name, uid_t uid)
 {
        sqlite3 *db = NULL;
        sqlite3_stmt *db_statement = NULL;
@@ -471,7 +493,7 @@ static int _notification_setting_alter_package_list(notification_setting_operati
 
        sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
 
-       is_package_in_setting_table = _is_package_in_setting_table(db, package_name);
+       is_package_in_setting_table = _is_package_in_setting_table(db, package_name, uid);
 
        switch (operation_type) {
        case OPERATION_TYPE_INSERT_RECORD:
@@ -480,7 +502,7 @@ static int _notification_setting_alter_package_list(notification_setting_operati
                        goto out;
                }
                NOTIFICATION_INFO("[%s] will be inserted", package_name);
-               sqlite3_ret = sqlite3_prepare_v2(db, "INSERT INTO notification_setting (package_name) VALUES (?) ", -1, &db_statement, NULL);
+               sqlite3_ret = sqlite3_prepare_v2(db, "INSERT INTO notification_setting (uid, package_name) VALUES (?, ?) ", -1, &db_statement, NULL);
                break;
 
        case OPERATION_TYPE_DELETE_RECORD:
@@ -489,7 +511,7 @@ static int _notification_setting_alter_package_list(notification_setting_operati
                        goto out;
                }
                NOTIFICATION_INFO("[%s] will be removed", package_name);
-               sqlite3_ret = sqlite3_prepare_v2(db, "DELETE FROM notification_setting WHERE package_name = ? ", -1, &db_statement, NULL);
+               sqlite3_ret = sqlite3_prepare_v2(db, "DELETE FROM notification_setting WHERE uid = ? AND package_name = ? ", -1, &db_statement, NULL);
                break;
        default:
                break;
@@ -501,6 +523,7 @@ static int _notification_setting_alter_package_list(notification_setting_operati
                goto out;
        }
 
+       sqlite3_bind_int(db_statement, field_index++, uid);
        sqlite3_bind_text(db_statement, field_index++, package_name, -1, SQLITE_TRANSIENT);
 
        sqlite3_ret = sqlite3_step(db_statement);
@@ -542,63 +565,39 @@ bool privilege_info_cb(const char *privilege_name, void *user_data)
        return true;
 }
 
-static bool _has_privilege(const char *package_id)
-{
-       bool found = false;
-       int error_from_package_info = PACKAGE_MANAGER_ERROR_NONE;
-       package_info_h package_info = NULL;
-
-       error_from_package_info = package_info_create(package_id, &package_info);
-       if (error_from_package_info != PACKAGE_MANAGER_ERROR_NONE) {
-               NOTIFICATION_ERR("package_info_create failed [%d]", error_from_package_info);
-               goto out;
-       }
-
-       error_from_package_info = package_info_foreach_privilege_info(package_info, privilege_info_cb, &found);
-
-       if (error_from_package_info != PACKAGE_MANAGER_ERROR_NONE) {
-               NOTIFICATION_ERR("package_info_foreach_privilege_info failed [%d]", error_from_package_info);
-               goto out;
-       }
-
-out:
-
-       if (package_info)
-               package_info_destroy(package_info);
-
-       return found;
-}
-
-EXPORT_API int notification_setting_insert_package(const char *package_id)
+EXPORT_API int notification_setting_insert_package_for_uid(const char *package_id, uid_t uid)
 {
        int err = NOTIFICATION_ERROR_NONE;
-
-       if (_has_privilege(package_id) == true)
-               err = _notification_setting_alter_package_list(OPERATION_TYPE_INSERT_RECORD, package_id);
+       err = _notification_setting_alter_package_list(OPERATION_TYPE_INSERT_RECORD, package_id, uid);
 
        return err;
 }
 
-EXPORT_API int notification_setting_delete_package(const char *package_id)
+EXPORT_API int notification_setting_delete_package_for_uid(const char *package_id, uid_t uid)
 {
-       return _notification_setting_alter_package_list(OPERATION_TYPE_DELETE_RECORD, package_id);
+       return _notification_setting_alter_package_list(OPERATION_TYPE_DELETE_RECORD, package_id, uid);
 }
 
 /* system setting --------------------------------*/
 
-EXPORT_API int notification_system_setting_load_system_setting(notification_system_setting_h *system_setting)
+EXPORT_API int notification_system_setting_load_system_setting_for_uid(notification_system_setting_h *system_setting, uid_t uid)
 {
        int ret = NOTIFICATION_ERROR_NONE;
        if (system_setting == NULL) {
                NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
-       ret = notification_ipc_request_load_system_setting(system_setting);
+       ret = notification_ipc_request_load_system_setting(system_setting, uid);
 
        return ret;
 }
 
-EXPORT_API int notification_system_setting_update_system_setting(notification_system_setting_h system_setting)
+EXPORT_API int notification_system_setting_load_system_setting(notification_system_setting_h *system_setting)
+{
+       return notification_system_setting_load_system_setting_for_uid(system_setting, getuid());
+}
+
+EXPORT_API int notification_system_setting_update_system_setting_for_uid(notification_system_setting_h system_setting, uid_t uid)
 {
        int err = NOTIFICATION_ERROR_NONE;
 
@@ -608,7 +607,7 @@ EXPORT_API int notification_system_setting_update_system_setting(notification_sy
                goto out;
        }
 
-       err = notification_ipc_update_system_setting(system_setting);
+       err = notification_ipc_update_system_setting(system_setting, uid);
        if (err != NOTIFICATION_ERROR_NONE) {
                NOTIFICATION_ERR("notification_ipc_update_system_setting returns[%d]\n", err);
                goto out;
@@ -618,6 +617,11 @@ out:
        return err;
 }
 
+EXPORT_API int notification_system_setting_update_system_setting(notification_system_setting_h system_setting)
+{
+       return notification_system_setting_update_system_setting_for_uid(system_setting, getuid());
+}
+
 EXPORT_API int notification_system_setting_free_system_setting(notification_system_setting_h system_setting)
 {
        int err = NOTIFICATION_ERROR_NONE;
@@ -706,7 +710,7 @@ out:
 }
 
 
-EXPORT_API int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class)
+EXPORT_API int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class, uid_t uid)
 {
        int err = NOTIFICATION_ERROR_NONE;
        int sqlret;
@@ -724,7 +728,7 @@ EXPORT_API int notification_setting_db_update_system_setting(int do_not_disturb,
 
        sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
 
-       sqlret = sqlite3_prepare_v2(db, "UPDATE notification_system_setting SET do_not_disturb = ?, visibility_class = ?;", -1, &db_statement, NULL);
+       sqlret = sqlite3_prepare_v2(db, "INSERT OR REPLACE notification_system_setting SET do_not_disturb = ?, visibility_class = ? WHERE uid = ?;", -1, &db_statement, NULL);
 
        if (sqlret != SQLITE_OK) {
                NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret, sqlite3_errmsg(db));
@@ -734,6 +738,7 @@ EXPORT_API int notification_setting_db_update_system_setting(int do_not_disturb,
 
        sqlite3_bind_int(db_statement, field_index++, do_not_disturb);
        sqlite3_bind_int(db_statement, field_index++, visibility_class);
+       sqlite3_bind_int(db_statement, field_index++, uid);
 
        sqlret = sqlite3_step(db_statement);
 
index 478ca28..c72ba2d 100644 (file)
@@ -83,7 +83,7 @@ out:
        return ret;
 }
 
-EXPORT_API int noti_setting_service_get_setting_by_package_name(const char *package_name, notification_setting_h *setting)
+EXPORT_API int noti_setting_service_get_setting_by_package_name(const char *package_name, notification_setting_h *setting, uid_t uid)
 {
        int err = NOTIFICATION_ERROR_NONE;
        sqlite3 *local_db_handle = NULL;
@@ -112,7 +112,7 @@ EXPORT_API int noti_setting_service_get_setting_by_package_name(const char *pack
 
        sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class "
                        "FROM %s "
-                       "WHERE package_name = %Q ", NOTIFICATION_SETTING_DB_TABLE, package_name);
+                       "WHERE package_name = %Q AND uid = %d", NOTIFICATION_SETTING_DB_TABLE, package_name, uid);
 
        if (!sql_query) {
                NOTIFICATION_ERR("fail to alloc query");
@@ -171,7 +171,7 @@ out:
 
 
 
-EXPORT_API int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count)
+EXPORT_API int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count, uid_t uid)
 {
        int err = NOTIFICATION_ERROR_NONE;
        sqlite3 *local_db_handle = NULL;
@@ -199,8 +199,8 @@ EXPORT_API int noti_setting_get_setting_array(notification_setting_h *setting_ar
        }
 
        sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class "
-                       "FROM %s "
-                       "ORDER BY package_name", NOTIFICATION_SETTING_DB_TABLE);
+                       "FROM %s WHERE uid = %d "
+                       "ORDER BY package_name", NOTIFICATION_SETTING_DB_TABLE, uid);
 
        if (!sql_query) {
                NOTIFICATION_ERR("fail to alloc query");
@@ -258,7 +258,7 @@ out:
 }
 
 
-EXPORT_API int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting)
+EXPORT_API int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting, uid_t uid)
 {
        int err = NOTIFICATION_ERROR_NONE;
        sqlite3 *local_db_handle = NULL;
@@ -285,7 +285,7 @@ EXPORT_API int noti_system_setting_load_system_setting(notification_system_setti
        }
 
        sql_query = sqlite3_mprintf("SELECT do_not_disturb, visibility_class "
-                       "FROM %s ", NOTIFICATION_SYSTEM_SETTING_DB_TABLE);
+                       "FROM %s WHERE uid = %d", NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
 
        if (!sql_query) {
                NOTIFICATION_ERR("fail to alloc query");
@@ -301,29 +301,25 @@ EXPORT_API int noti_system_setting_load_system_setting(notification_system_setti
                goto out;
        }
 
-       if (!row_count) {
-               NOTIFICATION_DBG("No setting found...");
-               err = NOTIFICATION_ERROR_NOT_EXIST_ID;
-               goto out;
-       }
-
        NOTIFICATION_DBG("row_count [%d] column_count [%d]", row_count, column_count);
-
-       row_count = 1;
-
        if (!(result_system_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting)))) {
                NOTIFICATION_ERR("malloc failed...");
                err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
                goto out;
        }
 
-       col_index = column_count;
-
-       _get_table_field_data_int(query_result, (int *)&(result_system_setting->do_not_disturb), col_index++);
-       _get_table_field_data_int(query_result, &(result_system_setting->visibility_class), col_index++);
+       /* no system setting record. allow everyting */
+       if (!row_count) {
+               NOTIFICATION_DBG("No setting found...");
+               result_system_setting->do_not_disturb = 0;
+               result_system_setting->visibility_class = 0;
+       } else {
+               col_index = column_count;
+               _get_table_field_data_int(query_result, (int *)&(result_system_setting->do_not_disturb), col_index++);
+               _get_table_field_data_int(query_result, &(result_system_setting->visibility_class), col_index++);
+       }
 
        *system_setting = result_system_setting;
-
 out:
        if (query_result)
                        sqlite3_free_table(query_result);
index aa9ab6c..f99b409 100644 (file)
@@ -40,5 +40,5 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 ADD_EXECUTABLE(notification-test-app ${TEST-APP-SRCS})
 TARGET_LINK_LIBRARIES(notification-test-app ${test_app_pkgs_LDFLAGS} notification)
 
-# INSTALL(TARGETS notification-test-app DESTINATION bin)
+#INSTALL(TARGETS notification-test-app DESTINATION bin)
 
index 35f28ee..3f6e04d 100755 (executable)
@@ -154,6 +154,7 @@ void testapp_show_menu(testapp_menu_type_e menu)
                testapp_print(" 7.  Post a notification with domain text\n");
                testapp_print(" 8.  Load by tag\n");
                testapp_print(" 9.  Get list\n");
+               testapp_print(" 10. Post noti to 5002 \n");
                testapp_print("------------------------------------------\n");
                break;
        case TESTAPP_MENU_TYPE_SETTING_TEST_MENU:
@@ -172,6 +173,49 @@ void testapp_show_menu(testapp_menu_type_e menu)
 }
 /* Common { ------------------------------------------------------------------*/
 
+
+static int testapp_add_a_notification_to_bob()
+{
+       notification_h noti_handle = NULL;
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
+
+       if (noti_handle == NULL) {
+               testapp_print("notification_create failed");
+               goto FINISH_OFF;
+       }
+
+       noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
+       noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
+       noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "3", "3", NOTIFICATION_VARIABLE_TYPE_NONE);
+       noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_1, "I'm Info 1", "INFO_1", NOTIFICATION_VARIABLE_TYPE_NONE);
+       noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, "I'm Info Sub 1", "INFO_SUB_1", NOTIFICATION_VARIABLE_TYPE_NONE);
+       noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_2, "I'm Info 2", "INFO_2", NOTIFICATION_VARIABLE_TYPE_NONE);
+       noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, "I'm Info Sub 2", "INFO_SUB_2", NOTIFICATION_VARIABLE_TYPE_NONE);
+       noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_3, "I'm Info 3", "INFO_3", NOTIFICATION_VARIABLE_TYPE_NONE);
+       noti_err  = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_SUB_3, "I'm Info Sub 3", "INFO_SUB_3", NOTIFICATION_VARIABLE_TYPE_NONE);
+
+       noti_err  = notification_set_ongoing_flag(noti_handle, true);
+       noti_err  = notification_set_auto_remove(noti_handle, false);
+
+       noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR | NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER);
+
+       noti_err  = notification_post_for_uid(noti_handle, 5002);
+
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               testapp_print("notification_post failed[%d]", noti_err);
+               goto FINISH_OFF;
+       }
+
+FINISH_OFF:
+       if (noti_handle)
+               notification_free(noti_handle);
+
+       return noti_err;
+}
+
+
 static int testapp_add_a_notification()
 {
        notification_h noti_handle = NULL;
@@ -587,6 +631,9 @@ static gboolean testapp_interpret_command_basic_test(int selected_number)
        case 9:
                testapp_test_get_list();
                break;
+       case 10:
+               testapp_add_a_notification_to_bob();
+               break;
 
        case 0:
                go_to_loop = FALSE;
@@ -711,7 +758,7 @@ out:
 static int testapp_test_refresh_setting_table()
 {
        int err = NOTIFICATION_ERROR_NONE;
-       err = notification_setting_refresh_setting_table();
+       err = notification_setting_refresh_setting_table(tzplatform_getuid(TZ_SYS_DEFAULT_USER));
 
        if (err != NOTIFICATION_ERROR_NONE) {
                testapp_print("notification_setting_refresh_setting_table failed [%d]\n", err);