From 79887ad83e097dca9aa58a5886ed84c1702edc61 Mon Sep 17 00:00:00 2001 From: jusung son Date: Mon, 25 Jun 2018 20:16:43 +0900 Subject: [PATCH] Add API for app_enable/disable - notification_setting_db_update_pkg_disabled Change-Id: Ie1352f65cd4216661cafa8a81c78cbbeb6321f04 Signed-off-by: jusung son (cherry picked from commit 37aaad297caa4aa3116a63a3149628ae7dbc1179) --- include/notification_setting_service.h | 2 ++ src/notification_setting_service.c | 49 ++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) mode change 100644 => 100755 include/notification_setting_service.h diff --git a/include/notification_setting_service.h b/include/notification_setting_service.h old mode 100644 new mode 100755 index d948808..f5a1947 --- a/include/notification_setting_service.h +++ b/include/notification_setting_service.h @@ -45,6 +45,8 @@ int notification_get_dnd_and_allow_to_notify(const char *app_id, int *do_not_dis 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 *app_id, bool value, uid_t uid); +int notification_setting_db_update_pkg_disabled(const char *pkg_id, bool value, uid_t uid); + #ifdef __cplusplus } #endif diff --git a/src/notification_setting_service.c b/src/notification_setting_service.c index 6445686..46a1730 100644 --- a/src/notification_setting_service.c +++ b/src/notification_setting_service.c @@ -854,6 +854,7 @@ int notification_setting_db_update_app_disabled(const char *app_id, bool value, sqlite3 *db = NULL; char *query = NULL; int ret = NOTIFICATION_ERROR_NONE; + int num_changes = 0; if (app_id == NULL) return NOTIFICATION_ERROR_INVALID_PARAMETER; @@ -862,7 +863,7 @@ int notification_setting_db_update_app_disabled(const char *app_id, bool value, if (!db) return get_last_result(); - query = sqlite3_mprintf("UPDATE %s SET app_disabled= %d " + query = sqlite3_mprintf("UPDATE %s SET app_disabled= %d " \ "WHERE app_id = %Q AND uid = %d", NOTIFICATION_SETTING_DB_TABLE, value, app_id, uid); @@ -872,7 +873,50 @@ int notification_setting_db_update_app_disabled(const char *app_id, bool value, goto out; } - ret = notification_db_exec(db, query, NULL); + ret = notification_db_exec(db, query, &num_changes); + if (ret == NOTIFICATION_ERROR_NONE && num_changes <= 0) + ret = NOTIFICATION_ERROR_NOT_EXIST_ID; + +out: + if (query) + sqlite3_free(query); + + if (db) + notification_db_close(&db); + + return ret; +} +/* LCOV_EXCL_STOP */ + +/* LCOV_EXCL_START */ +EXPORT_API +int notification_setting_db_update_pkg_disabled(const char *pkg_id, bool value, uid_t uid) +{ + sqlite3 *db = NULL; + char *query = NULL; + int ret = NOTIFICATION_ERROR_NONE; + int num_changes = 0; + + if (pkg_id == NULL) + return NOTIFICATION_ERROR_INVALID_PARAMETER; + + db = notification_db_open(DBPATH); + if (!db) + return get_last_result(); + + query = sqlite3_mprintf("UPDATE %s SET app_disabled= %d " \ + "WHERE package_name = %Q AND uid = %d", + NOTIFICATION_SETTING_DB_TABLE, value, + pkg_id, uid); + if (query == NULL) { + NOTIFICATION_ERR("Failed to alloc memory"); /* LCOV_EXCL_LINE */ + ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; + goto out; + } + + ret = notification_db_exec(db, query, &num_changes); + if (ret == NOTIFICATION_ERROR_NONE && num_changes <= 0) + ret = NOTIFICATION_ERROR_NOT_EXIST_ID; out: if (query) @@ -884,3 +928,4 @@ out: return ret; } /* LCOV_EXCL_STOP */ + -- 2.7.4