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

Commit

Permalink
Display system components as disabled when restricting system compone…
Browse files Browse the repository at this point in the history
…nts is not enabled

Fixes #1744
  • Loading branch information
M66B committed Jun 20, 2014
1 parent 27c9f50 commit 7efd8a7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Changelog
**Next release**

* Fixed updating dangerous functions restrictions when dangerous enabled ([issue](/../../issues/1742))
* Display system components as disabled when restricting system components is not enabled ([issue](/../../issues/1744))

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)

Expand Down
5 changes: 3 additions & 2 deletions src/biz/bokhorst/xprivacy/ActivityApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,8 @@ else if (PrivacyManager.cContacts.equals(restrictionName))

// Check if can be restricted
boolean can = enabled
&& PrivacyManager.canRestrict(rstate.mUid, Process.myUid(), rstate.mRestrictionName, null);
&& PrivacyManager.canRestrict(rstate.mUid, Process.myUid(), rstate.mRestrictionName, null,
true);
holder.llName.setEnabled(can);
holder.tvName.setEnabled(can);
holder.imgCbAsk.setEnabled(can);
Expand Down Expand Up @@ -1586,7 +1587,7 @@ public void onClick(View view) {
// Check if can be restricted
boolean can = enabled
&& PrivacyManager.canRestrict(rstate.mUid, Process.myUid(), rstate.mRestrictionName,
rstate.mMethodName);
rstate.mMethodName, true);
holder.llMethodName.setEnabled(can);
holder.tvMethodName.setEnabled(can);
holder.imgCbMethodAsk.setEnabled(can);
Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ else if (state == STATE_SHARED)
// Display enabled state
boolean can = enabled
&& PrivacyManager.canRestrict(rstate.mUid, Process.myUid(), rstate.mRestrictionName,
rstate.mMethodName);
rstate.mMethodName, true);
holder.tvName.setEnabled(can);
holder.imgCbRestricted.setEnabled(can);
holder.imgCbAsk.setEnabled(can);
Expand Down
12 changes: 9 additions & 3 deletions src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ public static void setRestriction(int uid, String restrictionName, String method
for (String rRestrictionName : listRestriction)
listPRestriction.add(new PRestriction(uid, rRestrictionName, methodName, restricted, asked));

// Make exceptions for dangerous methods
// Make exceptions
if (methodName == null)
for (String rRestrictionName : listRestriction)
for (Hook md : getHooks(rRestrictionName)) {
if (!canRestrict(uid, Process.myUid(), rRestrictionName, md.getName()))
if (!canRestrict(uid, Process.myUid(), rRestrictionName, md.getName(), false))
listPRestriction.add(new PRestriction(uid, rRestrictionName, md.getName(), false, true));
else if (md.isDangerous())
listPRestriction.add(new PRestriction(uid, rRestrictionName, md.getName(), false, md
Expand All @@ -394,12 +394,18 @@ else if (md.isDangerous())
setRestrictionList(listPRestriction);
}

public static boolean canRestrict(int uid, int xuid, String restrictionName, String methodName) {
public static boolean canRestrict(int uid, int xuid, String restrictionName, String methodName, boolean system) {
int _uid = Util.getAppId(uid);
int userId = Util.getUserId(uid);

if (_uid == Process.SYSTEM_UID && PrivacyManager.cIdentification.equals(restrictionName))
return false;

if (system)
if (!isApplication(_uid))
if (!getSettingBool(userId, PrivacyManager.cSettingSystem, false))
return false;

// @formatter:off
if ((_uid == Util.getAppId(xuid)) &&
(((PrivacyManager.cIdentification.equals(restrictionName) &&
Expand Down
24 changes: 13 additions & 11 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,6 @@ public PRestriction getRestriction(final PRestriction restriction, boolean usage
return mresult;
}

// Check if can be restricted
if (!PrivacyManager.canRestrict(restriction.uid, getXUid(), restriction.restrictionName,
restriction.methodName)) {
mresult.asked = true;
return mresult;
}

// Get meta data
Hook hook = null;
if (restriction.methodName != null) {
Expand All @@ -424,9 +417,18 @@ public PRestriction getRestriction(final PRestriction restriction, boolean usage
}

// Check for system component
if (usage && !PrivacyManager.isApplication(restriction.uid))
if (!getSettingBool(userId, PrivacyManager.cSettingSystem, false))
if (!PrivacyManager.isApplication(restriction.uid))
if (!getSettingBool(userId, PrivacyManager.cSettingSystem, false)) {
mresult.asked = true;
return mresult;
}

// Check if can be restricted
if (!PrivacyManager.canRestrict(restriction.uid, getXUid(), restriction.restrictionName,
restriction.methodName, false)) {
mresult.asked = true;
return mresult;
}

// Check if restrictions enabled
if (usage && !getSettingBool(restriction.uid, PrivacyManager.cSettingRestricted, true))
Expand Down Expand Up @@ -1319,7 +1321,7 @@ private boolean onDemandDialog(final Hook hook, final PRestriction restriction,
if (hook != null && !hook.canOnDemand())
return false;
if (!PrivacyManager.canRestrict(restriction.uid, getXUid(), restriction.restrictionName,
restriction.methodName))
restriction.methodName, false))
return false;

// Check if enabled
Expand Down Expand Up @@ -1741,7 +1743,7 @@ private void onDemandChoice(PRestriction restriction, boolean category, boolean
// Clear category on change
for (Hook hook : PrivacyManager.getHooks(restriction.restrictionName))
if (!PrivacyManager.canRestrict(restriction.uid, getXUid(), restriction.restrictionName,
hook.getName())) {
hook.getName(), false)) {
result.methodName = hook.getName();
result.restricted = false;
result.asked = true;
Expand Down

0 comments on commit 7efd8a7

Please sign in to comment.