diff --git a/CHANGELOG.md b/CHANGELOG.md index 39f9c9f7d..1a4ec80b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Changelog **Next release** * Fixed returning wrong restriction sometimes for repeated on demand restricting +* Added allow/deny once for category ([issue](/../../issues/1764)) [Open issues](https://github.com/M66B/XPrivacy/issues?state=open) diff --git a/src/biz/bokhorst/xprivacy/CRestriction.java b/src/biz/bokhorst/xprivacy/CRestriction.java index f8c1d7307..72c8b65d1 100644 --- a/src/biz/bokhorst/xprivacy/CRestriction.java +++ b/src/biz/bokhorst/xprivacy/CRestriction.java @@ -43,6 +43,10 @@ public int getUid() { return mUid; } + public void setMethodName(String methodName) { + mMethodName = methodName; + } + public boolean isSameMethod(PRestriction restriction) { // @formatter:off return (restriction.uid == mUid diff --git a/src/biz/bokhorst/xprivacy/PrivacyService.java b/src/biz/bokhorst/xprivacy/PrivacyService.java index 658764d00..814b2f476 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyService.java +++ b/src/biz/bokhorst/xprivacy/PrivacyService.java @@ -1585,7 +1585,6 @@ private View getOnDemandView(final PRestriction restriction, final Hook hook, Ap @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { - cbOnce.setChecked(false); cbWhitelist.setChecked(false); cbWhitelistExtra1.setChecked(false); cbWhitelistExtra2.setChecked(false); @@ -1596,7 +1595,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { - cbCategory.setChecked(false); cbWhitelist.setChecked(false); cbWhitelistExtra1.setChecked(false); cbWhitelistExtra2.setChecked(false); @@ -1653,7 +1651,7 @@ else if (cbWhitelistExtra1.isChecked()) else if (cbWhitelistExtra2.isChecked()) onDemandWhitelist(restriction, getXExtra(restriction, hook)[1], result, hook); else if (cbOnce.isChecked()) - onDemandOnce(restriction, result); + onDemandOnce(restriction, cbCategory.isChecked(), result); else onDemandChoice(restriction, cbCategory.isChecked(), false); latch.countDown(); @@ -1665,7 +1663,7 @@ else if (cbOnce.isChecked()) public void onClick(View v) { // Deny once result.restricted = true; - onDemandOnce(restriction, result); + onDemandOnce(restriction, false, result); latch.countDown(); } }); @@ -1686,7 +1684,7 @@ else if (cbWhitelistExtra1.isChecked()) else if (cbWhitelistExtra2.isChecked()) onDemandWhitelist(restriction, getXExtra(restriction, hook)[1], result, hook); else if (cbOnce.isChecked()) - onDemandOnce(restriction, result); + onDemandOnce(restriction, cbCategory.isChecked(), result); else onDemandChoice(restriction, cbCategory.isChecked(), true); latch.countDown(); @@ -1737,17 +1735,31 @@ private void onDemandWhitelist(final PRestriction restriction, String xextra, fi } } - private void onDemandOnce(final PRestriction restriction, final PRestriction result) { - Util.log(null, Log.WARN, (result.restricted ? "Deny" : "Allow") + " once " + restriction); + private void onDemandOnce(final PRestriction restriction, boolean category, final PRestriction result) { + Util.log(null, Log.WARN, (result.restricted ? "Deny" : "Allow") + " once " + restriction + " category=" + + category); result.time = new Date().getTime() + PrivacyManager.cRestrictionCacheTimeoutMs; - CRestriction key = new CRestriction(restriction, restriction.extra); + CRestriction key = new CRestriction(result, restriction.extra); synchronized (mAskedOnceCache) { if (mAskedOnceCache.containsKey(key)) mAskedOnceCache.remove(key); mAskedOnceCache.put(key, key); } + + if (category) { + for (Hook hook : PrivacyManager.getHooks(restriction.restrictionName)) + if (!restriction.methodName.equals(hook.getName())) { + CRestriction mkey = new CRestriction(result, null); + mkey.setMethodName(hook.getName()); + synchronized (mAskedOnceCache) { + if (mAskedOnceCache.containsKey(mkey)) + mAskedOnceCache.remove(mkey); + mAskedOnceCache.put(mkey, mkey); + } + } + } } private void onDemandChoice(PRestriction restriction, boolean category, boolean restrict) {