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

Commit

Permalink
Display third state for categories not fully restricted
Browse files Browse the repository at this point in the history
Fixes #815
  • Loading branch information
M66B committed Nov 23, 2013
1 parent 3d53c51 commit e6c8ecd
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 79 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Changelog

**Next release**

* ...
* Display third state for categories not fully restricted ([issue](https://github.com/M66B/XPrivacy/issues/815))

**Version 1.10.23 BETA**

Expand Down
80 changes: 32 additions & 48 deletions src/biz/bokhorst/xprivacy/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,16 +540,12 @@ public void onClick(DialogInterface dialog, int which) {
boolean someRestricted = false;
for (int pos = 0; pos < mAppAdapter.getCount(); pos++) {
ApplicationInfoEx xAppInfo = mAppAdapter.getItem(pos);
if (mAppAdapter.getRestrictionName() == null) {
for (boolean restricted : PrivacyManager.getRestricted(getApplicationContext(),
xAppInfo.getUid()))
if (restricted) {
someRestricted = true;
break;
}
} else if (PrivacyManager.getRestricted(null, ActivityMain.this, xAppInfo.getUid(),
mAppAdapter.getRestrictionName(), null, false, false))
someRestricted = true;
for (boolean restricted : PrivacyManager.getRestricted(getApplicationContext(),
xAppInfo.getUid(), mAppAdapter.getRestrictionName()))
if (restricted) {
someRestricted = true;
break;
}
if (someRestricted)
break;
}
Expand Down Expand Up @@ -938,16 +934,12 @@ protected FilterResults performFiltering(CharSequence constraint) {
// Get some restricted
boolean someRestricted = false;
if (fRestricted)
if (mRestrictionName == null) {
for (boolean restricted : PrivacyManager.getRestricted(getApplicationContext(),
xAppInfo.getUid()))
if (restricted) {
someRestricted = true;
break;
}
} else
someRestricted = PrivacyManager.getRestricted(null, getApplicationContext(),
xAppInfo.getUid(), mRestrictionName, null, false, false);
for (boolean restricted : PrivacyManager.getRestricted(getApplicationContext(),
xAppInfo.getUid(), mRestrictionName))
if (restricted) {
someRestricted = true;
break;
}

// Get Android permission
boolean permission = false;
Expand All @@ -968,7 +960,7 @@ else if (PrivacyManager.hasPermission(mContext, xAppInfo.getPackageName(), mRest
if (fSystem)
system = xAppInfo.isSystem();

// Match application
// Apply filters
if ((fName.equals("") ? true : contains) && (fUsed ? used : true) && (fInternet ? internet : true)
&& (fRestricted ? (fRestrictedNot ? !someRestricted : someRestricted) : true)
&& (fPermission ? permission : true) && (fUser ? user : true) && (fSystem ? system : true))
Expand Down Expand Up @@ -1064,17 +1056,10 @@ protected Object doInBackground(Object... params) {
}

// Get all/some restricted
if (mRestrictionName == null)
for (boolean restricted : PrivacyManager.getRestricted(holder.row.getContext(),
xAppInfo.getUid())) {
allRestricted = allRestricted && restricted;
someRestricted = someRestricted || restricted;
}
else {
boolean restricted = PrivacyManager.getRestricted(null, holder.row.getContext(),
xAppInfo.getUid(), mRestrictionName, null, false, false);
allRestricted = restricted;
someRestricted = restricted;
for (boolean restricted : PrivacyManager.getRestricted(holder.row.getContext(), xAppInfo.getUid(),
mRestrictionName)) {
allRestricted = (allRestricted && restricted);
someRestricted = (someRestricted || restricted);
}
}
return null;
Expand Down Expand Up @@ -1147,22 +1132,14 @@ public void onClick(final View view) {
// Get all/some restricted
boolean allRestricted = true;
boolean someRestricted = false;
if (mRestrictionName == null)
for (boolean restricted : PrivacyManager.getRestricted(view.getContext(),
xAppInfo.getUid())) {
allRestricted = allRestricted && restricted;
someRestricted = someRestricted || restricted;
}
else {
boolean restricted = PrivacyManager.getRestricted(null, view.getContext(),
xAppInfo.getUid(), mRestrictionName, null, false, false);
allRestricted = restricted;
someRestricted = restricted;
for (boolean restricted : PrivacyManager.getRestricted(view.getContext(),
xAppInfo.getUid(), mRestrictionName)) {
allRestricted = (allRestricted && restricted);
someRestricted = (someRestricted || restricted);
}

// Process click
someRestricted = !someRestricted;
if (mRestrictionName == null && !someRestricted) {
if (mRestrictionName == null && someRestricted) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
alertDialogBuilder.setTitle(getString(R.string.app_name));
alertDialogBuilder.setMessage(getString(R.string.msg_sure));
Expand All @@ -1188,11 +1165,18 @@ public void onClick(DialogInterface dialog, int which) {
alertDialog.show();
} else {
// Update restriction
if (mRestrictionName != null)
allRestricted = someRestricted;
for (String restrictionName : listRestriction)
PrivacyManager.setRestricted(null, view.getContext(), xAppInfo.getUid(),
restrictionName, null, someRestricted);
restrictionName, null, !someRestricted);

// Update all/some restricted
allRestricted = true;
someRestricted = false;
for (boolean restricted : PrivacyManager.getRestricted(view.getContext(),
xAppInfo.getUid(), mRestrictionName)) {
allRestricted = (allRestricted && restricted);
someRestricted = (someRestricted || restricted);
}

// Update visible state
holder.imgCBName.setImageResource(allRestricted ? R.drawable.checkbox_check
Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/PackageChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onReceive(Context context, Intent intent) {
if (!appInfo.isSystem() && !replacing) {
// Check for existing restrictions
boolean someRestricted = false;
for (boolean restricted : PrivacyManager.getRestricted(context, uid))
for (boolean restricted : PrivacyManager.getRestricted(context, uid, null))
if (restricted) {
someRestricted = true;
break;
Expand Down
6 changes: 3 additions & 3 deletions src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,12 @@ public static void setRestricted(XHook hook, Context context, int uid, String re
PrivacyManager.setRestricted(null, context, uid, restrictionName, md.getMethodName(), false);
}

public static List<Boolean> getRestricted(Context context, int uid) {
public static List<Boolean> getRestricted(Context context, int uid, String restrictionName) {
List<Boolean> listRestricted = new ArrayList<Boolean>();
ContentResolver contentResolver = context.getContentResolver();
if (contentResolver != null) {
Cursor cursor = contentResolver.query(PrivacyProvider.URI_RESTRICTION, null, null,
new String[] { Integer.toString(uid), Boolean.toString(false), null }, null);
Cursor cursor = contentResolver.query(PrivacyProvider.URI_RESTRICTION, null, restrictionName, new String[] {
Integer.toString(uid), Boolean.toString(false), restrictionName == null ? null : "*" }, null);
if (cursor != null)
try {
while (cursor.moveToNext()) {
Expand Down
67 changes: 41 additions & 26 deletions src/biz/bokhorst/xprivacy/PrivacyProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,20 @@ else if (sUriMatcher.match(uri) == TYPE_SETTING)
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if (sUriMatcher.match(uri) == TYPE_RESTRICTION && selectionArgs != null && selectionArgs.length >= 2) {
// Get arguments
final String restrictionName = selection;
final int uid = Integer.parseInt(selectionArgs[0]);
// Query restrictions
String restrictionName = selection;
int uid = Integer.parseInt(selectionArgs[0]);
boolean usage = Boolean.parseBoolean(selectionArgs[1]);
final String methodName = (selectionArgs.length >= 3 ? selectionArgs[2] : null);
String methodName = (selectionArgs.length >= 3 ? selectionArgs[2] : null);

return queryRestrictions(uid, restrictionName, methodName, usage);
} else if (sUriMatcher.match(uri) == TYPE_USAGE && selectionArgs != null && selectionArgs.length >= 1) {
// Return usage
List<String> listRestriction;
if (selection == null)
listRestriction = PrivacyManager.getRestrictions();
else {
listRestriction = new ArrayList<String>();
listRestriction.add(selection);
}
// Query usage
String restrictionName = selection;
int uid = Integer.parseInt(selectionArgs[0]);
String methodName = (selectionArgs.length >= 2 ? selectionArgs[1] : null);

return queryUsage(uid, listRestriction, methodName);
return queryUsage(uid, restrictionName, methodName);
} else if (sUriMatcher.match(uri) == TYPE_SETTING && selectionArgs == null)
return querySettings(selection);

Expand Down Expand Up @@ -168,14 +162,26 @@ private Cursor queryRestrictions(final int uid, final String restrictionName, fi

// Process restrictions
boolean restricted = false;
for (String eRestrictionName : listRestrictionName) {
boolean eRestricted = getRestricted(eRestrictionName, methodName, prefs);
cursor.addRow(new Object[] { uid, eRestrictionName, methodName, Boolean.toString(eRestricted) });
restricted = restricted || eRestricted;
if (methodName != null && methodName.equals("*")) {
for (String eRestrictionName : listRestrictionName) {
boolean eRestricted = getRestricted(eRestrictionName, null, prefs);
cursor.addRow(new Object[] { uid, eRestrictionName, null, Boolean.toString(eRestricted) });
for (PrivacyManager.MethodDescription md : PrivacyManager.getMethods(eRestrictionName)) {
eRestricted = getRestricted(eRestrictionName, md.getMethodName(), prefs);
cursor.addRow(new Object[] { uid, eRestrictionName, md.getMethodName(),
Boolean.toString(eRestricted) });
}
}
} else {
for (String eRestrictionName : listRestrictionName) {
boolean eRestricted = getRestricted(eRestrictionName, methodName, prefs);
cursor.addRow(new Object[] { uid, eRestrictionName, methodName, Boolean.toString(eRestricted) });
restricted = (restricted || eRestricted);
}
}

// Update usage data
if (usage && restrictionName != null && methodName != null) {
if (usage && restrictionName != null && methodName != null && !methodName.equals("*")) {
final boolean isRestricted = restricted;
mExecutor.execute(new Runnable() {
public void run() {
Expand All @@ -201,30 +207,39 @@ private static boolean getRestricted(String restrictionName, String methodName,
return restricted;
}

private Cursor queryUsage(int uid, List<String> listRestriction, String methodName) {
private Cursor queryUsage(int uid, String restrictionName, String methodName) {
MatrixCursor cursor = new MatrixCursor(new String[] { COL_UID, COL_RESTRICTION, COL_METHOD, COL_RESTRICTED,
COL_USED });

List<String> listRestriction;
if (restrictionName == null)
listRestriction = PrivacyManager.getRestrictions();
else {
listRestriction = new ArrayList<String>();
listRestriction.add(restrictionName);
}

if (uid == 0) {
// All
for (String restrictionName : PrivacyManager.getRestrictions()) {
SharedPreferences prefs = getContext().getSharedPreferences(PREF_USAGE + "." + restrictionName,
for (String eRestrictionName : PrivacyManager.getRestrictions()) {
SharedPreferences prefs = getContext().getSharedPreferences(PREF_USAGE + "." + eRestrictionName,
Context.MODE_PRIVATE);
for (String prefName : prefs.getAll().keySet())
if (prefName.startsWith(COL_USED)) {
String[] prefParts = prefName.split("\\.");
int rUid = Integer.parseInt(prefParts[1]);
String rMethodName = prefParts[2];
getUsage(rUid, restrictionName, rMethodName, cursor);
getUsage(rUid, eRestrictionName, rMethodName, cursor);
}
}
} else {
// Selected restrictions/methods
for (String restrictionName : listRestriction)
for (String eRestrictionName : listRestriction)
if (methodName == null)
for (PrivacyManager.MethodDescription md : PrivacyManager.getMethods(restrictionName))
getUsage(uid, restrictionName, md.getMethodName(), cursor);
for (PrivacyManager.MethodDescription md : PrivacyManager.getMethods(eRestrictionName))
getUsage(uid, eRestrictionName, md.getMethodName(), cursor);
else
getUsage(uid, restrictionName, methodName, cursor);
getUsage(uid, eRestrictionName, methodName, cursor);
}
return cursor;
}
Expand Down

0 comments on commit e6c8ecd

Please sign in to comment.