From fe76ae66291b1d230c3568b5c04ce8b82e7978be Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 22 Feb 2014 09:49:25 +0100 Subject: [PATCH] Do not notify if on demand (2) Resf #1417 --- src/biz/bokhorst/xprivacy/PrivacyService.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/biz/bokhorst/xprivacy/PrivacyService.java b/src/biz/bokhorst/xprivacy/PrivacyService.java index 0596363b2..ba2796e99 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyService.java +++ b/src/biz/bokhorst/xprivacy/PrivacyService.java @@ -572,13 +572,13 @@ public PRestriction getRestriction(final PRestriction restriction, boolean usage } // Ask to restrict + boolean ondemand = false; if (!mresult.asked && usage && PrivacyManager.isApplication(restriction.uid)) - onDemandDialog(hook, restriction, mresult); - else { - // Notify user - if (mresult.restricted && hook != null && hook.shouldNotify()) - notifyRestricted(restriction); - } + ondemand = onDemandDialog(hook, restriction, mresult); + + // Notify user + if (!ondemand && mresult.restricted && usage && hook != null && hook.shouldNotify()) + notifyRestricted(restriction); // Log usage if (usage && hook != null && hook.hasUsageData()) @@ -1141,32 +1141,32 @@ public void dump(int uid) throws RemoteException { // Helper methods - private void onDemandDialog(final Hook hook, final PRestriction restriction, final PRestriction result) { + private boolean onDemandDialog(final Hook hook, final PRestriction restriction, final PRestriction result) { // Neither category nor method is restricted and asked for try { // Without handler nothing can be done if (mHandler == null) - return; + return false; // Check for exceptions if (hook != null && !hook.canOnDemand()) - return; + return false; // Check if enabled if (!getSettingBool(0, PrivacyManager.cSettingOnDemand, true)) - return; + return false; if (!getSettingBool(restriction.uid, PrivacyManager.cSettingOnDemand, false)) - return; + return false; // Skip dangerous methods final boolean dangerous = getSettingBool(0, PrivacyManager.cSettingDangerous, false); if (!dangerous && hook != null && hook.isDangerous()) - return; + return false; // Get am context final Context context = getContext(); if (context == null) - return; + return false; long token = 0; try { @@ -1177,7 +1177,7 @@ private void onDemandDialog(final Hook hook, final PRestriction restriction, fin // Check if system application if (!dangerous && appInfo.isSystem()) - return; + return false; // Go ask Util.log(null, Log.WARN, "On demand " + restriction); @@ -1185,7 +1185,7 @@ private void onDemandDialog(final Hook hook, final PRestriction restriction, fin try { // Check if activity manager agrees if (!XActivityManagerService.canOnDemand()) - return; + return false; Util.log(null, Log.WARN, "On demanding " + restriction); @@ -1195,13 +1195,13 @@ private void onDemandDialog(final Hook hook, final PRestriction restriction, fin if (mRestrictionCache.containsKey(key)) if (mRestrictionCache.get(key).asked) { Util.log(null, Log.WARN, "Already asked " + restriction); - return; + return false; } } synchronized (mAskedOnceCache) { if (mAskedOnceCache.containsKey(key) && !mAskedOnceCache.get(key).isExpired()) { Util.log(null, Log.WARN, "Already asked once " + restriction); - return; + return false; } } if (hook != null && hook.whitelist() != null) { @@ -1209,7 +1209,7 @@ private void onDemandDialog(final Hook hook, final PRestriction restriction, fin synchronized (mSettingCache) { if (mSettingCache.containsKey(skey)) { Util.log(null, Log.WARN, "Already asked " + skey); - return; + return false; } } } @@ -1282,6 +1282,8 @@ public void run() { } catch (Throwable ex) { Util.bug(null, ex); } + + return true; } final class AlertDialogHolder {