Don't show popups to allowed priviacies 42/162042/4
authorZofia Grzelewska <z.abramowska@samsung.com>
Tue, 28 Nov 2017 15:22:20 +0000 (16:22 +0100)
committerZofia Grzelewska <z.abramowska@samsung.com>
Thu, 30 Nov 2017 12:35:11 +0000 (13:35 +0100)
When one of privacies, to which privilege is mapped,
is already allowed, don't show popup for it. This may
lead to inconsistency - when user chooses deny once,
the policy is not set and user thinks that application
cannot use this privacy, but it is allowed.

Change-Id: Id3509c7b33e6f2e4bf47340e1a2e368946e96ca1

src/common/policy/Policy.h
src/notification-daemon/Logic.cpp

index 5c6723dfd3c00e88fb25927f3287d34f839d44ff..b742a7e0a649cae8b590cf4c5b1e437e338b0730 100644 (file)
@@ -34,6 +34,8 @@ namespace AskUser {
 std::string getOwnAppId();
 void identifyApp(const std::string &client, std::string &appId, std::string &pkgLabel);
 
+Policy calculatePolicyForPrivacy(const std::string &appId, const Privacy &privacy);
+Policy getMinimumPolicy(const std::vector<Policy> &policies);
 Policy getPrivilegePolicy(const std::string &appId, const Privilege &privilege);
 Policy getPrivaciesPolicy(const std::string &appId, const std::vector<Privacy> &privacies);
 
index b0eab3a8e24311c801949c6e2bdb805a2f64a312..33b11b97292faf416cc0241466dd497d9d036479 100644 (file)
@@ -214,7 +214,18 @@ void Logic::popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::
         return;
     }
 
-    Policy policyLevel = getPrivaciesPolicy(conn.appId, privacies);
+    std::vector<Policy> policies;
+
+    std::string removePrivacy = "removeme";
+    for (auto &privacy : privacies) {
+        std::string policy = calculatePolicyForPrivacy(conn.appId, privacy);
+        if (policy == "Allow") {
+            // Remove privacies which are already allowed - we don't need to spam user more with popups
+            privacy = removePrivacy;
+        }
+        policies.push_back(policy);
+    }
+    std::string policyLevel = getMinimumPolicy(policies);
 
     ALOGD("Privilege policy level calculated to : " << policyLevel);
     if (policyLevel == "Allow") {
@@ -232,6 +243,9 @@ void Logic::popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::
         return;
     }
 
+    auto removeIt = std::remove_if(privacies.begin(), privacies.end(), [&](const Privacy &privacy) {return privacy == removePrivacy;});
+    privacies.erase(removeIt, privacies.end());
+
     addEvent(fd, id, privacies);
     processEvents();
 }