61 lines
2.5 KiB
Java
61 lines
2.5 KiB
Java
package com.discord.utilities.contacts;
|
|
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.database.Cursor;
|
|
import android.net.Uri;
|
|
import android.provider.ContactsContract;
|
|
import androidx.core.content.ContextCompat;
|
|
import d0.z.d.m;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
/* compiled from: ContactsProviderUtils.kt */
|
|
public final class ContactsProviderUtils {
|
|
private static final String CONTACTS_PERMISSION = "android.permission.READ_CONTACTS";
|
|
public static final ContactsProviderUtils INSTANCE = new ContactsProviderUtils();
|
|
|
|
private ContactsProviderUtils() {
|
|
}
|
|
|
|
public final Set<String> getAllContactPhoneNumbers(Context context) {
|
|
m.checkNotNullParameter(context, "ctx");
|
|
ContentResolver contentResolver = context.getContentResolver();
|
|
HashSet hashSet = new HashSet();
|
|
Cursor query = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
|
|
if (query != null) {
|
|
while (query.moveToNext()) {
|
|
String string = query.getString(query.getColumnIndex("data4"));
|
|
if (string != null) {
|
|
hashSet.add(string);
|
|
}
|
|
}
|
|
query.close();
|
|
}
|
|
return hashSet;
|
|
}
|
|
|
|
public final String getOwnName(Context context, String str) {
|
|
m.checkNotNullParameter(context, "ctx");
|
|
m.checkNotNullParameter(str, "number");
|
|
ContentResolver contentResolver = context.getContentResolver();
|
|
Uri withAppendedPath = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(str));
|
|
m.checkNotNullExpressionValue(withAppendedPath, "Uri.withAppendedPath(Pho…_URI, Uri.encode(number))");
|
|
Cursor query = contentResolver.query(withAppendedPath, new String[]{"display_name"}, null, null, null);
|
|
if (query != null) {
|
|
m.checkNotNullExpressionValue(query, "contentResolver.query(ur…ull, null) ?: return null");
|
|
while (query.moveToNext()) {
|
|
String string = query.getString(0);
|
|
if (string != null) {
|
|
return string;
|
|
}
|
|
}
|
|
query.close();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public final boolean hasContactPermissions(Context context) {
|
|
m.checkNotNullParameter(context, "ctx");
|
|
return ContextCompat.checkSelfPermission(context, "android.permission.READ_CONTACTS") == 0;
|
|
}
|
|
}
|