Add the check routine for app_enable/disable 51/102051/11
authorMyungki Lee <mk5004.lee@samsung.com>
Fri, 16 Dec 2016 10:06:53 +0000 (19:06 +0900)
committerMyungki Lee <mk5004.lee@samsung.com>
Fri, 16 Dec 2016 10:06:53 +0000 (19:06 +0900)
- when app disabled, notification will not post.

Change-Id: If6bffd5b4e73e5127655270b57c5ec6d1f9e3d78
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
include/notification_setting_internal.h
include/notification_setting_service.h
scripts/505.notification_upgrade.sh
src/notification_db.c
src/notification_ipc.c
src/notification_noti.c
src/notification_setting.c
src/notification_setting_service.c
test-app/main.c

index fcc9df61eef8e4a96be9faacedba52848d315428..7fd9c98df9b41321080880a8e24eb6d7c2ca6481 100644 (file)
@@ -83,11 +83,12 @@ typedef enum notification_dnd_allowed_calls {
 struct notification_setting {
        char *package_name;
        char *appid;
-       bool  allow_to_notify;
-       bool  do_not_disturb_except;
-       bool  pop_up_notification;
-       int   visibility_class;
+       bool allow_to_notify;
+       bool do_not_disturb_except;
+       bool pop_up_notification;
+       int visibility_class;
        lock_screen_content_level_e lock_screen_content_level;
+       bool app_disabled;
 };
 
 /* System setting */
@@ -558,6 +559,40 @@ int notification_setting_get_lock_screen_content(notification_setting_h setting,
  */
 int notification_setting_set_lock_screen_content(notification_setting_h setting, lock_screen_content_level_e level);
 
+/*
+ * @internal
+ * @brief Gets The value that determines whether the app is disabled
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/notification
+ * @param[in] setting   The notification system setting handle
+ * @param[out] value    The value that determines whether the app is disabled
+ * @return #NOTIFICATION_ERROR_NONE on success,
+ *         otherwise any other value on failure
+ * @retval #NOTIFICATION_ERROR_NONE         Success
+ * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @par sample code:
+ * @code
+#include <notification_setting_internal.h>
+{
+       int err = 0;
+       bool value = true;
+       notification_system_setting_h setting = NULL;
+
+       err = notification_setting_get_setting(&setting);
+       if (err != NOTIFICATION_ERROR_NONE)
+               return;
+
+       err = notification_setting_get_app_disabled(setting, &value);
+       if (err != NOTIFICATION_ERROR_NONE)
+               return;
+
+       return 0;
+}
+ * @endcode
+ */
+int notification_setting_get_app_disabled(notification_setting_h setting, bool *value);
+
 /*
  * @internal
  * @brief Gets the notification system setting handle.
index b14614138e630fd4b9c33552210513ecc7c324c0..fdf15bb5c21cb9752c6b735c2f1ead162c61457f 100644 (file)
@@ -44,6 +44,7 @@ int notification_system_setting_get_dnd_schedule_enabled_uid(uid_t **uids, int *
 int notification_get_dnd_and_allow_to_notify(const char *appid, int *do_not_disturb, int *do_not_disturb_except, int *allow_to_notify, uid_t uid);
 int notification_system_setting_load_dnd_allow_exception(dnd_allow_exception_h *dnd_allow_exception, int *count, uid_t uid);
 int notification_system_setting_update_dnd_allow_exception(int type, int value, uid_t uid);
+int notification_setting_db_update_app_disabled(const char *appid, bool value, uid_t uid);
 #ifdef __cplusplus
 }
 #endif
index 17ea26ca5cf216e92c42bda41f3b25f6d29be5a2..f57d2ff842ac9b5c938cbc239effecfeb0b74282 100644 (file)
@@ -79,6 +79,7 @@ CREATE TABLE notification_setting (
        visibility_class INTEGER DEFAULT 0,
        pop_up_notification INTEGER DEFAULT 1,
        lock_screen_content_level INTEGER DEFAULT 0,
+       app_disabled INTEGER DEFAULT 0,
        UNIQUE (uid, package_name, appid)
 );
 
index ea002ff24721bb3d7d31601427f2b24344658d5d..d9c07912bfb47695349f3ae1b5390d9067939a53 100755 (executable)
@@ -135,6 +135,7 @@ create      table if not exists noti_list ( \
                        visibility_class INTEGER DEFAULT 0, \
                        pop_up_notification INTEGER DEFAULT 1, \
                        lock_screen_content_level INTEGER DEFAULT 0, \
+                       app_disabled INTEGER DEFAULT 0, \
                        UNIQUE (uid, package_name, appid) \
                ); \
                CREATE TABLE IF NOT EXISTS notification_system_setting ( \
index f17badfec19635dd5bca1c3a57897f9d52863dad..c568ff1ac0fa0ead773f4a2756f71f9a7ca3f5ca 100755 (executable)
@@ -1397,7 +1397,7 @@ int notification_ipc_update_setting(notification_setting_h setting, uid_t uid)
                return result;
        }
 
-       body = g_variant_new("(ssiiiiii)",
+       body = g_variant_new("(ssiiiiiii)",
                        setting->package_name,
                        setting->appid,
                        (int)(setting->allow_to_notify),
@@ -1405,6 +1405,7 @@ int notification_ipc_update_setting(notification_setting_h setting, uid_t uid)
                        (int)(setting->visibility_class),
                        (int)(setting->pop_up_notification),
                        (int)(setting->lock_screen_content_level),
+                       (int)(setting->app_disabled),
                        uid);
 
        result = _send_sync_noti(body, &reply, "update_noti_setting");
@@ -2091,14 +2092,15 @@ EXPORT_API GVariant *notification_ipc_make_gvariant_from_setting(struct notifica
 {
        GVariant *body = NULL;
 
-       body = g_variant_new("(ssiiiii)",
+       body = g_variant_new("(ssiiiiii)",
                        noti_setting->package_name,
                        noti_setting->appid,
                        noti_setting->allow_to_notify,
                        noti_setting->do_not_disturb_except,
                        noti_setting->visibility_class,
                        noti_setting->pop_up_notification,
-                       noti_setting->lock_screen_content_level);
+                       noti_setting->lock_screen_content_level,
+                       noti_setting->app_disabled);
 
        return body;
 }
@@ -2114,20 +2116,22 @@ EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_s
        int visibility_class;
        int pop_up_notification;
        int lock_screen_content_level;
+       int app_disabled;
 
        if (noti_setting == NULL || variant == NULL) {
                NOTIFICATION_ERR("invalid data");
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
        }
        g_variant_get(variant,
-                       "(&s&siiiii)",
+                       "(&s&siiiiii)",
                        &pkgname,
                        &appid,
                        &allow_to_notify,
                        &do_not_disturb_except,
                        &visibility_class,
                        &pop_up_notification,
-                       &lock_screen_content_level);
+                       &lock_screen_content_level,
+                       &app_disabled);
 
        NOTIFICATION_DBG("setting from variant %s !!", pkgname);
 
@@ -2138,6 +2142,7 @@ EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_s
        noti_setting->visibility_class = visibility_class;
        noti_setting->pop_up_notification = pop_up_notification;
        noti_setting->lock_screen_content_level = lock_screen_content_level;
+       noti_setting->app_disabled = app_disabled;
 
        NOTIFICATION_DBG("setting from variant %s, %s",
                        noti_setting->package_name, pkgname);
index 635d60b495829a74f8056e97b541398e01057d47..1bcc46ee586119fa2612b6aa8b5a8a3800cc4767 100755 (executable)
@@ -21,6 +21,7 @@
 #include <vconf.h>
 #include <pkgmgr-info.h>
 #include <package_manager.h>
+#include <app_control_internal.h>
 
 #include <notification.h>
 #include <notification_internal.h>
@@ -706,26 +707,88 @@ err:
        return ret;
 }
 
-static bool _is_allowed_to_notify(const char *appid, uid_t uid)
+static int __get_setting_from_app_control(notification_h noti, notification_setting_h *setting)
+{
+       notification_setting_h setting_new = NULL;
+       app_control_h app_control = NULL;
+       bundle *b = NULL;
+       char *app_id = NULL;
+       int ret;
+
+       ret = notification_get_execute_option(noti,
+                               NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
+                               NULL,
+                               &b);
+       if (ret != NOTIFICATION_ERROR_NONE || b == NULL) {
+               NOTIFICATION_ERR("notification_get_execute_option failed [%x]", ret);
+               return ret;
+       }
+
+       ret = app_control_create(&app_control);
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               NOTIFICATION_ERR("app_control_create failed [%x]", ret);
+               goto out;
+       }
+
+       ret = app_control_import_from_bundle(app_control, b);
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               NOTIFICATION_ERR("app_control_import_from_bundle failed [%x]", ret);
+               goto out;
+       }
+
+       ret = app_control_get_app_id(app_control, &app_id);
+       if (ret != APP_CONTROL_ERROR_NONE || app_id == NULL) {
+               NOTIFICATION_ERR("app_control_get_app_id failed [%x]", ret);
+               goto out;
+       }
+
+       ret = noti_setting_service_get_setting_by_appid(app_id, &setting_new, noti->uid);
+       if (ret != APP_CONTROL_ERROR_NONE || setting == NULL) {
+               NOTIFICATION_ERR("noti_setting_service_get_setting_by_appid failed [%x]", ret);
+               goto out;
+       }
+
+       *setting = setting_new;
+
+out:
+       if (app_id)
+               free(app_id);
+
+       if (app_control)
+               app_control_destroy(app_control);
+
+       return ret;
+}
+
+static bool _is_allowed_to_notify(notification_h noti)
 {
        notification_setting_h setting = NULL;
-       int err;
+       bool allow_to_notify = true;
+       bool app_disabled = false;
        bool ret = true;
+       int err;
 
-       err = noti_setting_service_get_setting_by_appid(appid, &setting, uid);
+       err = noti_setting_service_get_setting_by_appid(noti->caller_pkgname, &setting, noti->uid);
        if (err != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("noti_setting_service_get_setting_by_appid failed [%d]", err);
+               err = __get_setting_from_app_control(noti, &setting);
+               if (err != NOTIFICATION_ERROR_NONE)
+                       return ret;
+       }
+
+       err = notification_setting_get_allow_to_notify(setting, &allow_to_notify);
+       if (err != NOTIFICATION_ERROR_NONE) {
+               NOTIFICATION_ERR("get_allow_to_notify failed [%x]", err);
                goto out;
        }
 
-       err = notification_setting_get_allow_to_notify(setting, &ret);
+       err = notification_setting_get_app_disabled(setting, &app_disabled);
        if (err != NOTIFICATION_ERROR_NONE) {
-               NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
+               NOTIFICATION_ERR("get_app_disabled failed [%x]", err);
                goto out;
        }
 
-       if (ret != true)
-               NOTIFICATION_DBG("[%s] is not allowed to notify", appid);
+       if (!allow_to_notify || app_disabled)
+               ret = false;
 
 out:
        if (setting)
@@ -862,7 +925,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, noti->uid) == false) {
+       if (_is_allowed_to_notify(noti) == false) {
                NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
                return NOTIFICATION_ERROR_PERMISSION_DENIED;
        }
@@ -1144,11 +1207,16 @@ EXPORT_API int notification_noti_update(notification_h noti)
        sqlite3_stmt *stmt = NULL;
        char *query = NULL;
 
+       if (noti == NULL) {
+               NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+       }
+
        db = notification_db_open(DBPATH);
        if (!db)
                return get_last_result();
 
-       if (_is_allowed_to_notify((const char *)noti->caller_pkgname, noti->uid) == false) {
+       if (_is_allowed_to_notify(noti) == false) {
                NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
                return NOTIFICATION_ERROR_PERMISSION_DENIED;
        }
index 488c649e61f1e23fb54ccce98a7761bdaf4ff42e..aa2df98ef72e95ea5e399b2aa96e929c08a5e40d 100755 (executable)
@@ -236,6 +236,7 @@ EXPORT_API int notification_setting_get_lock_screen_content(notification_setting
        }
 
        *level = setting->lock_screen_content_level;
+
        return NOTIFICATION_ERROR_NONE;
 }
 
@@ -247,6 +248,19 @@ EXPORT_API int notification_setting_set_lock_screen_content(notification_setting
        }
 
        setting->lock_screen_content_level = level;
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_setting_get_app_disabled(notification_setting_h setting, bool *value)
+{
+       if (setting == NULL || value == NULL) {
+               NOTIFICATION_ERR("Invalid parameter");
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+       }
+
+       *value = setting->app_disabled;
+
        return NOTIFICATION_ERROR_NONE;
 }
 
index 9c596ee6eb3c3e3b185c152119ec6a1bd38fdde4..4f41768773689f24494535daf910d36a953bca78 100644 (file)
@@ -119,7 +119,7 @@ int noti_setting_service_get_setting_by_appid(const char *appid, notification_se
        }
 
        sql_query = sqlite3_mprintf("SELECT package_name, appid, allow_to_notify, do_not_disturb_except, visibility_class, "
-                                   "pop_up_notification, lock_screen_content_level FROM %s "
+                                   "pop_up_notification, lock_screen_content_level, app_disabled FROM %s "
                                    "WHERE appid = %Q AND uid = %d", NOTIFICATION_SETTING_DB_TABLE, appid, uid);
 
        if (!sql_query) {
@@ -160,6 +160,7 @@ int noti_setting_service_get_setting_by_appid(const char *appid, notification_se
        _get_table_field_data_int(query_result, &(result_setting_array[i].visibility_class), col_index++);
        _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].pop_up_notification), col_index++);
        _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].lock_screen_content_level), col_index++);
+       _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].app_disabled), col_index++);
 
        *setting = result_setting_array;
 
@@ -208,8 +209,8 @@ int noti_setting_get_setting_array(notification_setting_h *setting_array, int *c
        }
 
        sql_query = sqlite3_mprintf("SELECT package_name, appid, allow_to_notify, do_not_disturb_except, visibility_class, "
-                                   "pop_up_notification, lock_screen_content_level FROM %s WHERE uid = %d "
-                                   "ORDER BY package_name, appid ", NOTIFICATION_SETTING_DB_TABLE, uid);
+                                   "pop_up_notification, lock_screen_content_level, app_disabled FROM %s WHERE uid = %d AND app_disabled = %d "
+                                   "ORDER BY package_name, appid ", NOTIFICATION_SETTING_DB_TABLE, uid, 0);
 
        if (!sql_query) {
                NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
@@ -248,6 +249,7 @@ int noti_setting_get_setting_array(notification_setting_h *setting_array, int *c
                _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].visibility_class), col_index++);
                _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].pop_up_notification), col_index++);
                _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].lock_screen_content_level), col_index++);
+               _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].app_disabled), col_index++);
        }
 
        *setting_array = result_setting_array;
@@ -858,3 +860,40 @@ out:
        return ret;
 }
 
+EXPORT_API int notification_setting_db_update_app_disabled(const char *appid, bool value, uid_t uid)
+{
+       int err = NOTIFICATION_ERROR_NONE;
+       int sqlret;
+       sqlite3 *db = NULL;
+       char *sqlbuf = NULL;
+
+       if (appid == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       sqlret = db_util_open(DBPATH, &db, 0);
+       if (sqlret != SQLITE_OK || db == NULL) {
+               NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
+               return NOTIFICATION_ERROR_FROM_DB;
+       }
+
+       sqlbuf = sqlite3_mprintf("UPDATE notification_setting SET " \
+                       "app_disabled = %d WHERE appid = %Q AND uid = %d",
+                       value, appid, uid);
+       if (!sqlbuf) {
+               NOTIFICATION_ERR("fail to alloc query");
+               err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               goto return_close_db;
+       }
+
+       err = notification_db_exec(db, sqlbuf, NULL);
+
+return_close_db:
+       if (sqlbuf)
+               sqlite3_free(sqlbuf);
+
+       sqlret = db_util_close(db);
+       if (sqlret != SQLITE_OK)
+               NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
+
+       return err;
+}
index 4eb26adeb41ccbf6281bac42531c9ad8f7d0f6e0..47b3505b9dc671633895be4381ddcadf69338c52 100755 (executable)
@@ -709,7 +709,7 @@ static int testapp_test_update_setting()
        int err = NOTIFICATION_ERROR_NONE;
        notification_setting_h setting = NULL;
 
-       err = notification_setting_get_setting_by_package_name("org.tizen.internet", &setting);
+       err = notification_setting_get_setting_by_package_name("org.tizen.browser", &setting);
 
        if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
                testapp_print("notification_setting_get_setting_by_package_name failed [%d]", err);