summaryrefslogtreecommitdiff
path: root/src/notification_noti.c
diff options
context:
space:
mode:
authorMyungki Lee <mk5004.lee@samsung.com>2016-12-16 19:06:53 +0900
committerMyungki Lee <mk5004.lee@samsung.com>2016-12-16 19:06:53 +0900
commit9dd2989caf6f10420c26df483aa89ab57f379da6 (patch)
treeea5f853ceee6c93dfbb22c62c2da3917fca4fc6d /src/notification_noti.c
parent4179f55f5c1a6efc634cdc723f77011b02347038 (diff)
downloadnotification-9dd2989caf6f10420c26df483aa89ab57f379da6.tar.gz
notification-9dd2989caf6f10420c26df483aa89ab57f379da6.tar.bz2
notification-9dd2989caf6f10420c26df483aa89ab57f379da6.zip
Add the check routine for app_enable/disable
- when app disabled, notification will not post. Change-Id: If6bffd5b4e73e5127655270b57c5ec6d1f9e3d78 Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
Diffstat (limited to 'src/notification_noti.c')
-rwxr-xr-xsrc/notification_noti.c88
1 files changed, 78 insertions, 10 deletions
diff --git a/src/notification_noti.c b/src/notification_noti.c
index 635d60b..1bcc46e 100755
--- a/src/notification_noti.c
+++ b/src/notification_noti.c
@@ -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;
}