diff --git a/CHANGELOG.md b/CHANGELOG.md index bbd705a76..7595d5aa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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** diff --git a/src/biz/bokhorst/xprivacy/PrivacyManager.java b/src/biz/bokhorst/xprivacy/PrivacyManager.java index 762f061c8..19054f5c4 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyManager.java +++ b/src/biz/bokhorst/xprivacy/PrivacyManager.java @@ -536,6 +536,7 @@ public static void applyTemplate(int uid, String templateName, String restrictio boolean hasOndemand = false; List listPRestriction = new ArrayList(); for (String rRestrictionName : listRestriction) { + // Cleanup if (clear) deleteRestrictions(uid, rRestrictionName, false); @@ -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> listWhitelisted(int uid, String type) { checkCaller();