From: Piotr Kosko
Date: Mon, 13 Jul 2015 12:42:18 +0000 (+0200)
Subject: [Notification] Added checking for 'system' notifications
X-Git-Tag: submit/tizen_tv/20150720.124123^2^2~14^2~1
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ce7e8ad9df387fb55babfcc373e491ce2c882c25;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Notification] Added checking for 'system' notifications
[Feature] Added checking if notification is from application, not from system.
System notifications are not returned with getAll() method.
[Verification] Code compiles without errors.
TCT passrate 100%
Change-Id: I0c1a4a05f3dcfdd551139ffab4ab07efcc1ffc8d
Signed-off-by: Piotr Kosko
---
diff --git a/src/notification/notification_manager.cc b/src/notification/notification_manager.cc
index c45a19fe..89179a8d 100644
--- a/src/notification/notification_manager.cc
+++ b/src/notification/notification_manager.cc
@@ -16,6 +16,9 @@
#include "notification/notification_manager.h"
+#include
+#include
+
#include
#include
#include
@@ -125,6 +128,68 @@ PlatformResult NotificationManager::Get(const picojson::object& args,
return PlatformResult(ErrorCode::NO_ERROR);
}
+bool NotificationPackageEqual(notification_h handle) {
+ LoggerD("Entered");
+ char* package = NULL;
+ char* handle_package = NULL;
+ char cmdline[512] = {0,};
+ char buf[64] = {0,};
+
+ if (notification_get_pkgname(handle, &handle_package))
+ {
+ return false;
+ }
+
+ LoggerD("handle package = %s", handle_package);
+
+ if (app_get_id(&package))
+ {
+
+ int ret = 0;
+ int fd = -1;
+ int pid = getpid();
+
+ snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
+
+ fd = open(buf, O_RDONLY);
+ if (fd < 0) {
+ return false;
+ }
+
+ ret = read(fd, cmdline, sizeof(cmdline) - 1);
+ if (ret <= 0) {
+ close(fd);
+ return false;
+ }
+
+ cmdline[ret] = 0;
+ close(fd);
+
+ if (strlen(cmdline) == strlen(handle_package))
+ {
+ if (!strncmp(cmdline, handle_package, strlen(cmdline)))
+ {
+ return true;
+ }
+ }
+ }
+ else
+ {
+ LoggerD("package = %s", package);
+
+ if (strlen(package) == strlen(handle_package))
+ {
+ if (!strncmp(package, handle_package, strlen(package)))
+ {
+ free(package);
+ return true;
+ }
+ }
+ }
+ free(package);
+ return false;
+}
+
PlatformResult NotificationManager::GetAll(picojson::array& out) {
LoggerD("Enter");
notification_h noti = nullptr;
@@ -145,7 +210,7 @@ PlatformResult NotificationManager::GetAll(picojson::array& out) {
while (noti_list_iter != nullptr) {
noti = notification_list_get_data(noti_list_iter);
- if (noti != nullptr) {
+ if (noti != nullptr && NotificationPackageEqual(noti)) {
int noti_priv = -1;
ret = notification_get_id(noti, NULL, ¬i_priv);
if (ret != NOTIFICATION_ERROR_NONE) {
diff --git a/src/notification/status_notification.cc b/src/notification/status_notification.cc
index af3d043a..55ddd3ac 100644
--- a/src/notification/status_notification.cc
+++ b/src/notification/status_notification.cc
@@ -231,7 +231,6 @@ PlatformResult StatusNotification::GetImage(
return PlatformResult(ErrorCode::UNKNOWN_ERR,
"Get notification image error");
}
-
if (path) {
*image_path = path;
}
@@ -856,17 +855,17 @@ PlatformResult StatusNotification::GetProgressValue(
const std::string& progess_type,
double* progress_value) {
LoggerD("Enter");
- *progress_value = 0.0;
+ double tmp_progress_value = 0.0;
if (progess_type == kProgressTypeByte) {
- if (notification_get_size(noti_handle, progress_value) !=
+ if (notification_get_size(noti_handle, &tmp_progress_value) !=
NOTIFICATION_ERROR_NONE) {
LoggerE("Get notification size error");
return PlatformResult(ErrorCode::UNKNOWN_ERR,
"Get notification size error");
}
} else if (progess_type == kProgressTypePercentage) {
- if (notification_get_progress(noti_handle, progress_value) !=
+ if (notification_get_progress(noti_handle, &tmp_progress_value) !=
NOTIFICATION_ERROR_NONE) {
LoggerE("Get notification progress error");
return PlatformResult(ErrorCode::UNKNOWN_ERR,
@@ -878,8 +877,9 @@ PlatformResult StatusNotification::GetProgressValue(
"Unknown notification progress type");
}
- LOGGER(DEBUG) << "Progress " << progess_type << " = " << *progress_value;
+ LOGGER(DEBUG) << "Progress " << progess_type << " = " << tmp_progress_value;
+ *progress_value = tmp_progress_value;
return PlatformResult(ErrorCode::NO_ERROR);
}