Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Added allow/deny once for category
Browse files Browse the repository at this point in the history
Closes #1764
  • Loading branch information
M66B committed Jun 27, 2014
1 parent 7f3181f commit 5c11fc5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions src/biz/bokhorst/xprivacy/CRestriction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
});
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5c11fc5

Please sign in to comment.