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

Commit

Permalink
Fixed on demand category once for functions with parameters
Browse files Browse the repository at this point in the history
Refs #1764
  • Loading branch information
M66B committed Jun 28, 2014
1 parent b3c15d2 commit 3b04ba7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/biz/bokhorst/xprivacy/CRestriction.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public void setMethodName(String methodName) {
mMethodName = methodName;
}

public void setExtra(String extra) {
mExtra = extra;
}

public boolean isSameMethod(PRestriction restriction) {
// @formatter:off
return (restriction.uid == mUid
Expand Down
40 changes: 21 additions & 19 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1389,21 +1389,32 @@ private boolean onDemandDialog(final Hook hook, final PRestriction restriction,
Util.log(null, Log.WARN, "On demanding " + restriction);

// Check if not asked before
CRestriction key = new CRestriction(restriction, restriction.extra);
CRestriction mkey = new CRestriction(restriction, restriction.extra);
synchronized (mRestrictionCache) {
if (mRestrictionCache.containsKey(key))
if (mRestrictionCache.get(key).asked) {
if (mRestrictionCache.containsKey(mkey))
if (mRestrictionCache.get(mkey).asked) {
Util.log(null, Log.WARN, "Already asked " + restriction);
result.restricted = mRestrictionCache.get(key).restricted;
result.restricted = mRestrictionCache.get(mkey).restricted;
result.asked = true;
return false;
}
}

synchronized (mAskedOnceCache) {
if (mAskedOnceCache.containsKey(key) && !mAskedOnceCache.get(key).isExpired()) {
if (mAskedOnceCache.containsKey(mkey) && !mAskedOnceCache.get(mkey).isExpired()) {
Util.log(null, Log.WARN, "Already asked once " + restriction);
result.restricted = mAskedOnceCache.get(key).restricted;
result.restricted = mAskedOnceCache.get(mkey).restricted;
result.asked = true;
return false;
}
}

CRestriction ckey = new CRestriction(restriction, null);
ckey.setMethodName(null);
synchronized (mAskedOnceCache) {
if (mAskedOnceCache.containsKey(ckey) && !mAskedOnceCache.get(ckey).isExpired()) {
Util.log(null, Log.WARN, "Already asked once category " + restriction);
result.restricted = mAskedOnceCache.get(ckey).restricted;
result.asked = true;
return false;
}
Expand Down Expand Up @@ -1748,24 +1759,15 @@ private void onDemandOnce(final PRestriction restriction, boolean category, fina
result.time = new Date().getTime() + PrivacyManager.cRestrictionCacheTimeoutMs;

CRestriction key = new CRestriction(result, restriction.extra);
if (category) {
key.setMethodName(null);
key.setExtra(null);
}
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 3b04ba7

Please sign in to comment.