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

Commit

Permalink
Applying template will not apply to disabled restrictions anymore
Browse files Browse the repository at this point in the history
Fixes #1747
  • Loading branch information
M66B committed Jun 24, 2014
1 parent d78b961 commit c8a1ab7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Changelog
* Removed enabling on demand restricting on update
* You can use [PlayPermissionsExposed](http://forum.xda-developers.com/xposed/modules/playpermissionsexposed-fix-play-store-t2783076) instead
* Fixed template functions exceptions being display after 15 seconds
* Applying template will not apply to disabled restrictions anymore ([issue](/../../issues/1747))
* Updated Slovak translation

**Please send the support info when asked for**
Expand Down
63 changes: 39 additions & 24 deletions src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ public static void applyTemplate(int uid, String templateName, String restrictio
boolean hasOndemand = false;
List<PRestriction> listPRestriction = new ArrayList<PRestriction>();
for (String rRestrictionName : listRestriction) {
// Cleanup
if (clear)
deleteRestrictions(uid, rRestrictionName, false);

Expand All @@ -545,45 +546,59 @@ public static void applyTemplate(int uid, String templateName, String restrictio
boolean parentRestricted = parentValue.contains("true");
boolean parentAsked = (!ondemand || parentValue.contains("asked"));
hasOndemand = hasOndemand || !parentAsked;

// Merge
PRestriction parentMerge;
if (clear)
parentMerge = new PRestriction(uid, rRestrictionName, null, parentRestricted, parentAsked);
else
parentMerge = getRestrictionEx(uid, rRestrictionName, null);
listPRestriction.add(new PRestriction(uid, rRestrictionName, null, parentMerge.restricted
|| parentRestricted, parentMerge.asked && parentAsked));

// Apply
if (canRestrict(uid, Process.myUid(), rRestrictionName, null, true))
listPRestriction.add(new PRestriction(uid, rRestrictionName, null, parentMerge.restricted
|| parentRestricted, parentMerge.asked && parentAsked));

// Childs
if (methods)
for (Hook hook : getHooks(rRestrictionName)) {
String settingName = rRestrictionName + "." + hook.getName();
String childValue = getSetting(userId, templateName, settingName, null);
if (childValue == null)
childValue = Boolean.toString(parentRestricted && !hook.isDangerous())
+ (parentAsked || (hook.isDangerous() && hook.whitelist() == null) ? "+asked" : "+ask");
boolean restricted = childValue.contains("true");
boolean asked = (!ondemand || childValue.contains("asked"));
PRestriction childMerge;
if (clear)
childMerge = new PRestriction(uid, rRestrictionName, hook.getName(), parentRestricted
&& restricted, parentAsked || asked);
else
childMerge = getRestrictionEx(uid, rRestrictionName, hook.getName());
if ((parentRestricted && !restricted) || (!parentAsked && asked) || hook.isDangerous() || !clear) {
PRestriction child = new PRestriction(uid, rRestrictionName, hook.getName(),
(parentRestricted && restricted) || childMerge.restricted, (parentAsked || asked)
&& childMerge.asked);
listPRestriction.add(child);
for (Hook hook : getHooks(rRestrictionName))
if (canRestrict(uid, Process.myUid(), rRestrictionName, hook.getName(), true)) {
// Child
String settingName = rRestrictionName + "." + hook.getName();
String childValue = getSetting(userId, templateName, settingName, null);
if (childValue == null)
childValue = Boolean.toString(parentRestricted && !hook.isDangerous())
+ (parentAsked || (hook.isDangerous() && hook.whitelist() == null) ? "+asked"
: "+ask");
boolean restricted = childValue.contains("true");
boolean asked = (!ondemand || childValue.contains("asked"));

// Merge
PRestriction childMerge;
if (clear)
childMerge = new PRestriction(uid, rRestrictionName, hook.getName(), parentRestricted
&& restricted, parentAsked || asked);
else
childMerge = getRestrictionEx(uid, rRestrictionName, hook.getName());

// APply
if ((parentRestricted && !restricted) || (!parentAsked && asked) || hook.isDangerous()
|| !clear) {
PRestriction child = new PRestriction(uid, rRestrictionName, hook.getName(),
(parentRestricted && restricted) || childMerge.restricted, (parentAsked || asked)
&& childMerge.asked);
listPRestriction.add(child);
}
}
}
}

// Apply result
setRestrictionList(listPRestriction);
if (hasOndemand)
PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(true));
}

// White listing
// TODO: add specialized get to privacy service
// White/black listing

public static Map<String, TreeMap<String, Boolean>> listWhitelisted(int uid, String type) {
checkCaller();
Expand Down

0 comments on commit c8a1ab7

Please sign in to comment.