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

Commit

Permalink
If LBE Security Master is enabled, only applications can be restricted
Browse files Browse the repository at this point in the history
Refs #1231
  • Loading branch information
M66B committed Feb 2, 2014
1 parent 293c84c commit db2c104
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Test and beta releases will have experimental functions enabled by default.
* Support for multi SIM IPC restrictions (Huawei and maybe others)
* Added *act on category* check box to restricting on demand prompt, thanks @[jpeg729](https://github.com/jpeg729)
* On demand restricting default enabled (there is a new main setting to disable it)
* If LBE Security Master is enabled, only applications can be restricted ([issue](https://github.com/M66B/XPrivacy/issues/1231))
* Fixed randomize on access not sticking for latitude and longitude
* Updated German translation
* Updated Slovak translation
Expand Down
29 changes: 12 additions & 17 deletions src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static boolean getRestriction(final XHook hook, int uid, String restricti
} else if (getHooks(restrictionName).indexOf(new Hook(restrictionName, methodName)) < 0)
Util.log(hook, Log.WARN, "Unknown method=" + methodName);

if (uid == Process.SYSTEM_UID && Util.hasLBE())
if (!isApplication(uid) && Util.hasLBE())
return false;

// Check cache
Expand Down Expand Up @@ -322,21 +322,19 @@ public static boolean setRestriction(XHook hook, int uid, String restrictionName
}

// Make exceptions for dangerous methods
boolean dangerous = PrivacyManager.getSettingBool(hook, 0, PrivacyManager.cSettingDangerous, false, false);
boolean dangerous = getSettingBool(hook, 0, cSettingDangerous, false, false);
if (methodName == null)
if (restricted && !dangerous) {
for (Hook md : getHooks(restrictionName))
if (md.isDangerous())
PrivacyManager.setRestriction(hook, uid, restrictionName, md.getName(), dangerous, asked);
setRestriction(hook, uid, restrictionName, md.getName(), dangerous, asked);
}

// Mark state as changed
PrivacyManager
.setSetting(hook, uid, PrivacyManager.cSettingState, Integer.toString(ActivityMain.STATE_CHANGED));
setSetting(hook, uid, cSettingState, Integer.toString(ActivityMain.STATE_CHANGED));

// Update modification time
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingModifyTime,
Long.toString(System.currentTimeMillis()));
setSetting(null, uid, cSettingModifyTime, Long.toString(System.currentTimeMillis()));

// Check if restart required
return shouldRestart(restrictionName, methodName, restricted);
Expand Down Expand Up @@ -368,7 +366,7 @@ public static List<ParcelableRestriction> getRestrictionList(int uid, String res
}

public static boolean shouldRestart(String restrictionName, String methodName, boolean restricted) {
boolean dangerous = PrivacyManager.getSettingBool(null, 0, PrivacyManager.cSettingDangerous, false, false);
boolean dangerous = getSettingBool(null, 0, cSettingDangerous, false, false);
if (methodName == null) {
for (Hook md : getHooks(restrictionName))
if (md.isRestartRequired() && !(restricted && !dangerous && md.isDangerous()))
Expand Down Expand Up @@ -402,12 +400,10 @@ public static boolean deleteRestrictions(int uid) {
}

// Mark as new/changed
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingState,
Integer.toString(ActivityMain.STATE_ATTENTION));
setSetting(null, uid, cSettingState, Integer.toString(ActivityMain.STATE_ATTENTION));

// Change app modification time
PrivacyManager.setSetting(null, uid, PrivacyManager.cSettingModifyTime,
Long.toString(System.currentTimeMillis()));
setSetting(null, uid, cSettingModifyTime, Long.toString(System.currentTimeMillis()));

return restart;
}
Expand All @@ -418,7 +414,7 @@ public static long getUsed(int uid, String restrictionName, String methodName) {
try {
List<ParcelableRestriction> listRestriction = new ArrayList<ParcelableRestriction>();
if (restrictionName == null)
for (String sRestrictionName : PrivacyManager.getRestrictions())
for (String sRestrictionName : getRestrictions())
listRestriction.add(new ParcelableRestriction(uid, sRestrictionName, methodName, false));
else
listRestriction.add(new ParcelableRestriction(uid, restrictionName, methodName, false));
Expand Down Expand Up @@ -470,7 +466,7 @@ public static String getSetting(XHook hook, int uid, String name, String default
long start = System.currentTimeMillis();
String value = null;

if (uid == Process.SYSTEM_UID && Util.hasLBE())
if (!isApplication(uid) && Util.hasLBE())
return defaultValue;

// Check cache
Expand Down Expand Up @@ -516,7 +512,7 @@ public static String getSetting(XHook hook, int uid, String name, String default
}

long ms = System.currentTimeMillis() - start;
if (!willExpire && !PrivacyManager.cSettingLog.equals(name))
if (!willExpire && !cSettingLog.equals(name))
if (ms > 1)
Util.log(hook, Log.INFO, String.format("get setting uid=%d %s=%s%s %d ms", uid, name, value,
(cached ? " (cached)" : ""), ms));
Expand Down Expand Up @@ -910,8 +906,7 @@ public static boolean hasPermission(Context context, ApplicationInfoEx appInfo,
if (mPermissionRestrictionCache.get(uid) == null)
mPermissionRestrictionCache.append(uid, new HashMap<String, Boolean>());
if (!mPermissionRestrictionCache.get(uid).containsKey(restrictionName)) {
boolean permission = hasPermission(context, appInfo.getPackageName(),
PrivacyManager.getPermissions(restrictionName));
boolean permission = hasPermission(context, appInfo.getPackageName(), getPermissions(restrictionName));
mPermissionRestrictionCache.get(uid).put(restrictionName, permission);
}
return mPermissionRestrictionCache.get(uid).get(restrictionName);
Expand Down

0 comments on commit db2c104

Please sign in to comment.