use of android.database.MatrixCursor in project XPrivacy by M66B.
the class PrivacyProvider method queryUsage.
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 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 = prefName.substring(prefParts[0].length() + 1 + prefParts[1].length() + 1);
getUsage(rUid, eRestrictionName, rMethodName, cursor);
}
}
} else {
// Selected restrictions/methods
for (String eRestrictionName : listRestriction) if (methodName == null)
for (Hook md : PrivacyManager.getHooks(eRestrictionName, null)) getUsage(uid, eRestrictionName, md.getName(), cursor);
else
getUsage(uid, eRestrictionName, methodName, cursor);
}
return cursor;
}
use of android.database.MatrixCursor in project XPrivacy by M66B.
the class PrivacyProvider method querySettings.
private Cursor querySettings(String name) {
SharedPreferences prefs = getContext().getSharedPreferences(PREF_SETTINGS, Context.MODE_WORLD_READABLE);
MatrixCursor cursor = new MatrixCursor(new String[] { COL_SETTING, COL_VALUE });
if (name == null)
for (String settingKey : prefs.getAll().keySet()) try {
cursor.addRow(new Object[] { getSettingName(settingKey), prefs.getString(settingKey, null) });
} catch (Throwable ex) {
// Legacy boolean
}
else
cursor.addRow(new Object[] { name, prefs.getString(getSettingPref(name), null) });
return cursor;
}
use of android.database.MatrixCursor in project XPrivacy by M66B.
the class XContentResolver method handleUriAfter.
@SuppressLint("DefaultLocale")
private void handleUriAfter(XParam param) throws Throwable {
// Check URI
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://applications")) {
// Applications provider: allow selected applications
if (isRestrictedExtra(param, PrivacyManager.cSystem, "ApplicationsProvider", uri)) {
MatrixCursor result = new MatrixCursor(cursor.getColumnNames());
while (cursor.moveToNext()) {
int colPackage = cursor.getColumnIndex("package");
String packageName = (colPackage < 0 ? null : cursor.getString(colPackage));
if (packageName != null && XPackageManager.isPackageAllowed(0, packageName))
copyColumns(cursor, result);
}
result.respond(cursor.getExtras());
param.setResult(result);
cursor.close();
}
} else if (uri.startsWith("content://com.google.android.gsf.gservices")) {
// Google services provider: block only android_id
if (param.args.length > 3 && param.args[3] != null) {
List<String> listSelection = Arrays.asList((String[]) param.args[3]);
if (listSelection.contains("android_id"))
if (isRestrictedExtra(param, PrivacyManager.cIdentification, "GservicesProvider", uri)) {
int ikey = cursor.getColumnIndex("key");
int ivalue = cursor.getColumnIndex("value");
if (ikey == 0 && ivalue == 1 && cursor.getColumnCount() == 2) {
MatrixCursor result = new MatrixCursor(cursor.getColumnNames());
while (cursor.moveToNext()) {
if ("android_id".equals(cursor.getString(ikey)) && cursor.getString(ivalue) != null)
result.addRow(new Object[] { "android_id", PrivacyManager.getDefacedProp(Binder.getCallingUid(), "GSF_ID") });
else
copyColumns(cursor, result);
}
result.respond(cursor.getExtras());
param.setResult(result);
cursor.close();
} else
Util.log(this, Log.ERROR, "Unexpected result uri=" + uri + " columns=" + cursor.getColumnNames());
}
}
} else if (uri.startsWith("content://com.android.contacts/contacts/name_phone_or_email")) {
// Do nothing
} else 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")) {
if (isRestrictedExtra(param, PrivacyManager.cContacts, methodName, uri)) {
// Get ID from URL if any
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);
// Get blacklist setting
int uid = Binder.getCallingUid();
boolean blacklist = PrivacyManager.getSettingBool(-uid, PrivacyManager.cSettingBlacklist, false);
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()) {
// Check if allowed
long id = (urlid >= 0 ? urlid : cursor.getLong(iid));
boolean allowed = PrivacyManager.getSettingBool(-uid, Meta.cTypeContact, Long.toString(id), false);
if (blacklist)
allowed = !allowed;
if (allowed)
copyColumns(cursor, result, listColumn.size());
}
else
Util.log(this, Log.WARN, "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
// fall-back
methodName = "ContactsProvider2";
if (methodName != null)
if (isRestrictedExtra(param, PrivacyManager.cContacts, methodName, uri)) {
// Return empty cursor
MatrixCursor result = new MatrixCursor(cursor.getColumnNames());
result.respond(cursor.getExtras());
param.setResult(result);
cursor.close();
}
}
} else {
// Other uri restrictions
String restrictionName = null;
String methodName = null;
if (uri.startsWith("content://browser")) {
restrictionName = PrivacyManager.cBrowser;
methodName = "BrowserProvider2";
} else if (uri.startsWith("content://com.android.calendar")) {
restrictionName = PrivacyManager.cCalendar;
methodName = "CalendarProvider2";
} else if (uri.startsWith("content://call_log")) {
restrictionName = PrivacyManager.cCalling;
methodName = "CallLogProvider";
} else if (uri.startsWith("content://contacts/people")) {
restrictionName = PrivacyManager.cContacts;
methodName = "contacts/people";
} else if (uri.startsWith("content://downloads")) {
restrictionName = PrivacyManager.cBrowser;
methodName = "Downloads";
} else if (uri.startsWith("content://com.android.email.provider")) {
restrictionName = PrivacyManager.cEMail;
methodName = "EMailProvider";
} else if (uri.startsWith("content://com.google.android.gm")) {
restrictionName = PrivacyManager.cEMail;
methodName = "GMailProvider";
} else if (uri.startsWith("content://icc")) {
restrictionName = PrivacyManager.cContacts;
methodName = "IccProvider";
} else if (uri.startsWith("content://mms")) {
restrictionName = PrivacyManager.cMessages;
methodName = "MmsProvider";
} else if (uri.startsWith("content://mms-sms")) {
restrictionName = PrivacyManager.cMessages;
methodName = "MmsSmsProvider";
} else if (uri.startsWith("content://sms")) {
restrictionName = PrivacyManager.cMessages;
methodName = "SmsProvider";
} else if (uri.startsWith("content://telephony")) {
restrictionName = PrivacyManager.cPhone;
methodName = "TelephonyProvider";
} else if (uri.startsWith("content://user_dictionary")) {
restrictionName = PrivacyManager.cDictionary;
methodName = "UserDictionary";
} else if (uri.startsWith("content://com.android.voicemail")) {
restrictionName = PrivacyManager.cMessages;
methodName = "VoicemailContentProvider";
}
// Check if know / restricted
if (restrictionName != null && methodName != null) {
if (isRestrictedExtra(param, restrictionName, methodName, uri)) {
// Return empty cursor
MatrixCursor result = new MatrixCursor(cursor.getColumnNames());
result.respond(cursor.getExtras());
param.setResult(result);
cursor.close();
}
}
}
}
}
use of android.database.MatrixCursor in project Signal-Android by WhisperSystems.
the class ContactsCursorLoader method loadInBackground.
@Override
public Cursor loadInBackground() {
ContactsDatabase contactsDatabase = DatabaseFactory.getContactsDatabase(getContext());
ArrayList<Cursor> cursorList = new ArrayList<>(3);
if (mode != MODE_OTHER_ONLY) {
cursorList.add(contactsDatabase.queryTextSecureContacts(filter));
}
if (mode == MODE_ALL) {
cursorList.add(contactsDatabase.querySystemContacts(filter));
} else if (mode == MODE_OTHER_ONLY) {
cursorList.add(filterNonPushContacts(contactsDatabase.querySystemContacts(filter)));
}
if (!TextUtils.isEmpty(filter) && NumberUtil.isValidSmsOrEmail(filter)) {
MatrixCursor newNumberCursor = new MatrixCursor(new String[] { ContactsDatabase.ID_COLUMN, ContactsDatabase.NAME_COLUMN, ContactsDatabase.NUMBER_COLUMN, ContactsDatabase.NUMBER_TYPE_COLUMN, ContactsDatabase.LABEL_COLUMN, ContactsDatabase.CONTACT_TYPE_COLUMN }, 1);
newNumberCursor.addRow(new Object[] { -1L, getContext().getString(R.string.contact_selection_list__unknown_contact), filter, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM, "⇢", ContactsDatabase.NEW_TYPE });
cursorList.add(newNumberCursor);
}
return new MergeCursor(cursorList.toArray(new Cursor[0]));
}
use of android.database.MatrixCursor in project Signal-Android by WhisperSystems.
the class ContactsCursorLoader method filterNonPushContacts.
@NonNull
private Cursor filterNonPushContacts(@NonNull Cursor cursor) {
try {
final long startMillis = System.currentTimeMillis();
final MatrixCursor matrix = new MatrixCursor(new String[] { ContactsDatabase.ID_COLUMN, ContactsDatabase.NAME_COLUMN, ContactsDatabase.NUMBER_COLUMN, ContactsDatabase.NUMBER_TYPE_COLUMN, ContactsDatabase.LABEL_COLUMN, ContactsDatabase.CONTACT_TYPE_COLUMN });
while (cursor.moveToNext()) {
final String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_COLUMN));
final Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), number, true);
if (DirectoryHelper.getUserCapabilities(getContext(), recipients).getTextCapability() != Capability.SUPPORTED) {
matrix.addRow(new Object[] { cursor.getLong(cursor.getColumnIndexOrThrow(ContactsDatabase.ID_COLUMN)), cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN)), number, cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_TYPE_COLUMN)), cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.LABEL_COLUMN)), ContactsDatabase.NORMAL_TYPE });
}
}
Log.w(TAG, "filterNonPushContacts() -> " + (System.currentTimeMillis() - startMillis) + "ms");
return matrix;
} finally {
cursor.close();
}
}
Aggregations