diff options
author | jusung son <jusung07.son@samsung.com> | 2018-06-25 19:57:55 +0900 |
---|---|---|
committer | jusung son <jusung07.son@samsung.com> | 2018-06-27 08:33:29 +0000 |
commit | 3ba37f04e194951d7f7609ae27c0c54bf6b37063 (patch) | |
tree | 91bbc1758f8f7aebeac75978e504811e38dc8847 | |
parent | 99a9e87264d7697121258025aaee65c9d4775903 (diff) | |
download | badge-3ba37f04e194951d7f7609ae27c0c54bf6b37063.tar.gz badge-3ba37f04e194951d7f7609ae27c0c54bf6b37063.tar.bz2 badge-3ba37f04e194951d7f7609ae27c0c54bf6b37063.zip |
Apply app_enable/disable feature
- 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>
(cherry picked from commit d33282248a6a2b48570d86e75ca666339032dd1b)
-rw-r--r-- | include/badge_setting_service.h | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | src/badge_setting_service.c | 152 |
2 files changed, 150 insertions, 4 deletions
diff --git a/include/badge_setting_service.h b/include/badge_setting_service.h index 11d9e03..af0f0e5 100644 --- a/include/badge_setting_service.h +++ b/include/badge_setting_service.h @@ -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); diff --git a/src/badge_setting_service.c b/src/badge_setting_service.c index e1efbd6..b559f9d 100644..100755 --- a/src/badge_setting_service.c +++ b/src/badge_setting_service.c @@ -30,6 +30,15 @@ #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; |