[Notification] Added checking for 'system' notifications
authorPiotr Kosko <p.kosko@samsung.com>
Mon, 13 Jul 2015 12:42:18 +0000 (14:42 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Mon, 13 Jul 2015 12:42:25 +0000 (14:42 +0200)
[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 <p.kosko@samsung.com>
src/notification/notification_manager.cc
src/notification/status_notification.cc

index c45a19fe13273453d4fe6def2936981bad93e855..89179a8dcb8b9f28f47af548f6e256fe8b309356 100644 (file)
@@ -16,6 +16,9 @@
 
 #include "notification/notification_manager.h"
 
+#include <fcntl.h>
+#include <unistd.h>
+
 #include <app_control_internal.h>
 #include <device/led.h>
 #include <notification_internal.h>
@@ -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, &noti_priv);
       if (ret != NOTIFICATION_ERROR_NONE) {
index af3d043a9637649bd512d789fe67c5f2d90bb49e..55ddd3acd46611d5998d82a861f483e9643a1b2b 100644 (file)
@@ -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);
 }