Apply app_enable/disable feature 88/182488/2
authorjusung son <jusung07.son@samsung.com>
Mon, 25 Jun 2018 10:57:55 +0000 (19:57 +0900)
committerjusung son <jusung07.son@samsung.com>
Wed, 27 Jun 2018 05:06:05 +0000 (14:06 +0900)
 - App information is stored in the allow_to_display column of the badge_setting table
   The first bit indicates allow information, and the second bit indicates app disable information

Change-Id: Iaa81a4e1d4a520dafc4fa743f94c8c7e465d8095
Signed-off-by: jusung son <jusung07.son@samsung.com>
include/badge_setting_service.h
src/badge_setting_service.c [changed mode: 0644->0755]

index 11d9e03..af0f0e5 100644 (file)
@@ -43,6 +43,8 @@ int badge_setting_insert_package_for_uid(const char *pkgname, uid_t uid);
 int badge_setting_delete_package_for_uid(const char *pkgname, uid_t uid);
 int badge_setting_refresh_setting_table(uid_t uid);
 int badge_db_update_setting(char *pkgname, char *appid, int allow_to_display, uid_t uid);
+int badge_db_update_app_disabled(const char *app_id, bool disabled, uid_t uid);
+int badge_db_update_pkg_disabled(const char *pkg_id, bool disabled, uid_t uid);
 int badge_setting_is_existed_appid(const char *appid, bool *is_existed, uid_t uid);
 int badge_setting_arrange_tables(uid_t uid);
 
old mode 100644 (file)
new mode 100755 (executable)
index 8c5d92e..ce8df22
 
 #define BADGE_PRIVILEGE "http://tizen.org/privilege/notification"
 
+#define BAGDE_ALLOW_TO_DISPLAY_BIT 0x1
+#define BAGDE_APP_DISABLE_BIT 0x2
+
+#define BAGDE_APP_ENABLE 0x0
+#define BAGDE_APP_DISABLE 0x2
+
+#define BAGDE_NOT_ALLOW_TO_DISPLAY 0x0
+#define BAGDE_ALLOW_TO_DISPLAY 0x1
+
 typedef struct {
        uid_t uid;
        sqlite3 *db;
@@ -103,6 +112,7 @@ EXPORT_API int badge_db_get_setting_by_appid(const char *appid, badge_setting_h
        char **query_result = NULL;
        badge_setting_h result_setting;
        sqlite3 *db = NULL;
+       int atd;
 
        if (appid == NULL)
                return BADGE_ERROR_INVALID_PARAMETER;
@@ -158,7 +168,14 @@ EXPORT_API int badge_db_get_setting_by_appid(const char *appid, badge_setting_h
 
        _get_table_field_data_string(query_result, &(result_setting[0].pkgname), 1, col_index++);
        _get_table_field_data_string(query_result, &(result_setting[0].appid), 1, col_index++);
-       _get_table_field_data_int(query_result, (int *)&(result_setting[0].allow_to_display), col_index++);
+       _get_table_field_data_int(query_result, &atd, col_index++);
+
+       if (atd & BAGDE_APP_DISABLE_BIT)
+               result_setting[0].allow_to_display = BAGDE_NOT_ALLOW_TO_DISPLAY;
+       else if (atd & BAGDE_ALLOW_TO_DISPLAY_BIT)
+               result_setting[0].allow_to_display = BAGDE_ALLOW_TO_DISPLAY;
+       else
+               result_setting[0].allow_to_display = BAGDE_NOT_ALLOW_TO_DISPLAY;
 
        *setting = result_setting;
 
@@ -196,10 +213,13 @@ EXPORT_API int badge_db_update_setting(char *pkgname, char *appid, int allow_to_
                /* LCOV_EXCL_STOP */
        }
 
-       sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_display = %d " \
+       /* Only the first bit is updated.
+               (The first bit indicates allow information, and the second bit indicates app disable information.)
+       */
+       sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_display = (allow_to_display & ~%d ) | %d " \
                                "WHERE pkgname = %Q AND appid = %Q " \
                                "AND uid = %d;",
-                               BADGE_SETTING_DB_TABLE, allow_to_display,
+                               BADGE_SETTING_DB_TABLE, BAGDE_ALLOW_TO_DISPLAY_BIT, allow_to_display,
                                pkgname, appid, uid);
 
        if (!sqlbuf) {
@@ -234,6 +254,7 @@ EXPORT_API int badge_db_get_allow_to_display_by_appid(char *appid, int *allow_to
        char *sql_query = NULL;
        char **query_result = NULL;
        sqlite3 *db = NULL;
+       int atd;
 
        if (appid == NULL)
                return BADGE_ERROR_INVALID_PARAMETER;
@@ -278,7 +299,14 @@ EXPORT_API int badge_db_get_allow_to_display_by_appid(char *appid, int *allow_to
 
        col_index = col_count;
 
-       _get_table_field_data_int(query_result, (int *)allow_to_display, col_index++);
+       _get_table_field_data_int(query_result, &atd, col_index++);
+
+       if (atd & BAGDE_APP_DISABLE_BIT)
+               *allow_to_display = BAGDE_NOT_ALLOW_TO_DISPLAY;
+       else if (atd & BAGDE_ALLOW_TO_DISPLAY_BIT)
+               *allow_to_display = BAGDE_ALLOW_TO_DISPLAY;
+       else
+               *allow_to_display = BAGDE_NOT_ALLOW_TO_DISPLAY;
 
 out:
        if (query_result)
@@ -294,6 +322,122 @@ out:
        return ret;
 }
 
+EXPORT_API int badge_db_update_app_disabled(const char *app_id, bool disabled, uid_t uid)
+{
+       int ret = BADGE_ERROR_NONE;
+       sqlite3 *db = NULL;
+       char *sqlbuf = NULL;
+       int sql_ret;
+       int num_changes = 0;
+       int flag;
+
+       if (app_id == NULL) {
+               ERR("Invalid app id");
+               return BADGE_ERROR_INVALID_PARAMETER;
+       }
+
+       sql_ret = db_util_open(BADGE_DB_PATH, &db, 0);
+       if (sql_ret != SQLITE_OK || db == NULL) {
+               /* LCOV_EXCL_START */
+               ERR("db_util_open failed [%s][%d]", BADGE_DB_PATH, sql_ret);
+               return BADGE_ERROR_FROM_DB;
+               /* LCOV_EXCL_STOP */
+       }
+
+       if (disabled)
+               flag = BAGDE_APP_DISABLE;
+       else
+               flag = BAGDE_APP_ENABLE;
+
+       /* Only the second bit is updated.
+               (The first bit indicates allow information, and the second bit indicates app disable information.)
+       */
+       sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_display = (allow_to_display & ~%d ) | %d " \
+                               "WHERE appid = %Q " \
+                               "AND uid = %d;",
+                               BADGE_SETTING_DB_TABLE, BAGDE_APP_DISABLE_BIT, flag, app_id, uid);
+       if (!sqlbuf) {
+               /* LCOV_EXCL_START */
+               ERR("Failed to alloc query");
+               ret = BADGE_ERROR_FROM_DB;
+               goto out;
+               /* LCOV_EXCL_STOP */
+       }
+
+       ret = badge_db_exec(db, sqlbuf, &num_changes);
+       if (ret == BADGE_ERROR_NONE && num_changes <= 0)
+               ret = BADGE_ERROR_NOT_EXIST;
+
+out:
+       if (sqlbuf)
+               sqlite3_free(sqlbuf);
+       if (db) {
+               sql_ret = db_util_close(db);
+               if (sql_ret != SQLITE_OK)
+                       WARN("Failed to db_util_close");
+       }
+
+       return ret;
+}
+
+EXPORT_API int badge_db_update_pkg_disabled(const char *pkg_id, bool disabled, uid_t uid)
+{
+       int ret = BADGE_ERROR_NONE;
+       sqlite3 *db = NULL;
+       char *sqlbuf = NULL;
+       int sql_ret;
+       int num_changes = 0;
+       int flag;
+
+       if (pkg_id == NULL) {
+               ERR("Invalid pkg id");
+               return BADGE_ERROR_INVALID_PARAMETER;
+       }
+
+       sql_ret = db_util_open(BADGE_DB_PATH, &db, 0);
+       if (sql_ret != SQLITE_OK || db == NULL) {
+               /* LCOV_EXCL_START */
+               ERR("db_util_open failed [%s][%d]", BADGE_DB_PATH, sql_ret);
+               return BADGE_ERROR_FROM_DB;
+               /* LCOV_EXCL_STOP */
+       }
+
+       if (disabled)
+               flag = BAGDE_APP_DISABLE;
+       else
+               flag = BAGDE_APP_ENABLE;
+
+       /* Only the second bit is updated.
+               (The first bit indicates allow information, and the second bit indicates app disable information.)
+       */
+       sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_display = (allow_to_display & ~%d ) | %d " \
+                               "WHERE pkgname = %Q " \
+                               "AND uid = %d;",
+                               BADGE_SETTING_DB_TABLE, BAGDE_APP_DISABLE_BIT, flag, pkg_id, uid);
+       if (!sqlbuf) {
+               /* LCOV_EXCL_START */
+               ERR("Failed to alloc query");
+               ret = BADGE_ERROR_FROM_DB;
+               goto out;
+               /* LCOV_EXCL_STOP */
+       }
+
+       ret = badge_db_exec(db, sqlbuf, &num_changes);
+       if (ret == BADGE_ERROR_NONE && num_changes <= 0)
+               ret = BADGE_ERROR_NOT_EXIST;
+
+out:
+       if (sqlbuf)
+               sqlite3_free(sqlbuf);
+       if (db) {
+               sql_ret = db_util_close(db);
+               if (sql_ret != SQLITE_OK)
+                       WARN("Failed to db_util_close");
+       }
+
+       return ret;
+}
+
 EXPORT_API int badge_setting_is_existed_appid(const char *appid, bool *is_existed, uid_t uid)
 {
        int ret = BADGE_ERROR_NONE;