[Xposed Framework Development] jmarques00:
Hello,

I'm currently working with Xposed and i need to restrict access of contacts to applications installed on smartphone i allready tried some codes but not working anyone can help me?

try {

// final Class<?> cResolver = findClass("android.content.ContentResolver",lpparam.classLoader);

//android.content.ContentProviderClient

final Class<?> cResolver = findClass("android.content.ContentResolver",lpparam.classLoader);

XposedBridge.log("<--------ENTROUUUUUUUUUUUUUU COntentResolver----------->: " + lpparam.packageName);

XposedBridge.hookAllMethods(cResolver, "query", new XC_MethodHook() {

[MENTION=5448622]Suppress[/MENTION]Lint("DefaultLocale")

protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

XposedBridge.log(" Hooked method: " + param.method);

XposedBridge.log(" uri=" + param.args[0]);

String uri = ((Uri) param.args[0]).toString().toLowerCase();

String[] projection = (param.args[1] instanceof String[] ? (String[]) param.args[1] :null);

if (uri.startsWith("content://com.android.contacts/contacts/name_phone_or_email")) {

} else if (uri.startsWith("content://com.android.contacts/") && !uri.equals("content://com.android.contacts/")) {

XposedBridge.log("JOAAAAAAAAAAAAAAAOOOOOOOOOOOOOOOOOOOO 111111111111111111");

String[] components = uri.replace("content://com.android.", "").split("/");

String methodName = components[0] + "/" + components[1].split("\\?")[0];

if (methodName.equals("contacts/contacts") || methodName.equals("contacts/data") || methodName.equals("contacts/phone_lookup") || methodName.equals("contacts/raw_contacts")){

XposedBridge.log("JOAAAAAAAAAAAAAAAOOOOOOOOOOOOOOOOOOOO 22222222222222");

int urlid = -1;

if ((methodName.equals("contacts/contacts") || methodName.equals("contacts/phone_lookup")) && components.length > 2 && TextUtils.isDigitsOnly(components[2])){

urlid = Integer.parseInt(components[2]);

boolean added = false;

if (projection != null && urlid < 0) {

List<String> listProjection = new ArrayList<String>();

listProjection.addAll(Arrays.asList(projection));

String cid = getIdForUri(uri);

if (cid != null && !listProjection.contains(cid)) {

XposedBridge.log("ENTROUU nesta merda do CID");

added = true;

listProjection.add(cid);

}

param.args[1] = listProjection.toArray(new String[0]);

}

if (added)

XposedBridge.log("ENTROUU nesta merda do added");

param.setObjectExtra("column_added", added);

}

}

}

}

[MENTION=5448622]Suppress[/MENTION]Lint("DefaultLocale")

protected void afterHookedMethod(MethodHookParam param) throws Throwable {

if (param.args.length > 1 && param.args[0] instanceof Uri && param.getResult() != null) {

String uri = ((Uri) param.args[0]).toString().toLowerCase();

String[] projection = (param.args[1] instanceof String[] ? (String[]) param.args[1] : null);

String selection = (param.args[2] instanceof String ? (String) param.args[2] : null);

Cursor cursor = (Cursor) param.getResult();

if (uri.startsWith("content://com.android.contacts/")&& !uri.equals("content://com.android.contacts/")) {

// Contacts provider: allow selected contacts

String[] components = uri.replace("content://com.android.", "").split("/");

String methodName = components[0] + "/" + components[1].split("\\?")[0];

if (methodName.equals("contacts/contacts") || methodName.equals("contacts/data") || methodName.equals("contacts/phone_lookup") || methodName.equals("contacts/raw_contacts")) {

int urlid = -1;

if ((methodName.equals("contacts/contacts") || methodName.equals("contacts/phone_lookup")) && components.length > 2 && TextUtils.isDigitsOnly(components[2])){

urlid = Integer.parseInt(components[2]);

}

// Modify column names back

Object column_added = param.getObjectExtra("column_added");

boolean added = (column_added == null ? false : (Boolean) param.getObjectExtra("column_added"));

List<String> listColumn = new ArrayList<String>();

listColumn.addAll(Arrays.asList(cursor.getColumnNames()));

if (added) listColumn.remove(listColumn.size() - 1);

MatrixCursor result = new MatrixCursor(listColumn.toArray(new String[0]));

// Filter rows

String cid = getIdForUri(uri);

int iid = (cid == null ? -1 : cursor.getColumnIndex(cid));

if (iid >= 0 || urlid >= 0)

while (cursor.moveToNext()) {

copyColumns(cursor, result, listColumn.size());

}

else{

XposedBridge.log("ENTROUUUU NO ELSE");

XposedBridge.log("ID missing URI=" + uri + " added=" + added + "/" + cid

+ " columns=" + TextUtils.join(",", cursor.getColumnNames()) + " projection="

+ (projection == null ? "null" : TextUtils.join(",", projection)) + " selection="

+ selection);

}

result.respond(cursor.getExtras());

param.setResult(result);

cursor.close();

}else{

methodName = null;

if (uri.startsWith("content://com.android.contacts/profile"))

methodName = "contacts/profile";

else

methodName = "ContactsProvider2"; // fall-back

if (methodName != null){

// Return empty cursor

MatrixCursor result = new MatrixCursor(cursor.getColumnNames());

result.respond(cursor.getExtras());

XposedBridge.log(cursor.getExtras().toString());

param.setResult(result);

cursor.close();

}

}

}

}

}

});

} catch (Throwable t) {

throw t;

}