use of com.android.dialer.common.database.Selection in project android_packages_apps_Dialer by LineageOS.
the class SystemBlockedNumberPhoneLookup method queryNumbers.
@WorkerThread
private ImmutableMap<DialerPhoneNumber, SystemBlockedNumberInfo> queryNumbers(ImmutableSet<DialerPhoneNumber> numbers) {
Assert.isWorkerThread();
PartitionedNumbers partitionedNumbers = new PartitionedNumbers(numbers);
Set<DialerPhoneNumber> blockedNumbers = new ArraySet<>();
Selection normalizedSelection = Selection.column(BlockedNumbers.COLUMN_E164_NUMBER).in(partitionedNumbers.validE164Numbers());
try (Cursor cursor = appContext.getContentResolver().query(BlockedNumbers.CONTENT_URI, new String[] { BlockedNumbers.COLUMN_E164_NUMBER }, normalizedSelection.getSelection(), normalizedSelection.getSelectionArgs(), null)) {
while (cursor != null && cursor.moveToNext()) {
blockedNumbers.addAll(partitionedNumbers.dialerPhoneNumbersForValidE164(cursor.getString(0)));
}
}
Selection rawSelection = Selection.column(BlockedNumbers.COLUMN_ORIGINAL_NUMBER).in(partitionedNumbers.invalidNumbers());
try (Cursor cursor = appContext.getContentResolver().query(BlockedNumbers.CONTENT_URI, new String[] { BlockedNumbers.COLUMN_ORIGINAL_NUMBER }, rawSelection.getSelection(), rawSelection.getSelectionArgs(), null)) {
while (cursor != null && cursor.moveToNext()) {
blockedNumbers.addAll(partitionedNumbers.dialerPhoneNumbersForInvalid(cursor.getString(0)));
}
}
ImmutableMap.Builder<DialerPhoneNumber, SystemBlockedNumberInfo> result = ImmutableMap.builder();
for (DialerPhoneNumber number : numbers) {
result.put(number, SystemBlockedNumberInfo.newBuilder().setBlockedState(blockedNumbers.contains(number) ? BlockedState.BLOCKED : BlockedState.NOT_BLOCKED).build());
}
return result.build();
}
use of com.android.dialer.common.database.Selection in project android_packages_apps_Dialer by LineageOS.
the class CnapPhoneLookup method lookup.
/**
* CNAP info cannot be retrieved when all we have is a number. The best we can do is returning the
* existing info in {@link PhoneLookupHistory}.
*/
@Override
public ListenableFuture<CnapInfo> lookup(DialerPhoneNumber dialerPhoneNumber) {
return backgroundExecutorService.submit(() -> {
Selection selection = Selection.builder().and(Selection.column(PhoneLookupHistory.NORMALIZED_NUMBER).is("=", dialerPhoneNumber.getNormalizedNumber())).build();
try (Cursor cursor = appContext.getContentResolver().query(PhoneLookupHistory.CONTENT_URI, new String[] { PhoneLookupHistory.PHONE_LOOKUP_INFO }, selection.getSelection(), selection.getSelectionArgs(), /* sortOrder = */
null)) {
if (cursor == null) {
LogUtil.e("CnapPhoneLookup.lookup", "null cursor");
return CnapInfo.getDefaultInstance();
}
if (!cursor.moveToFirst()) {
LogUtil.i("CnapPhoneLookup.lookup", "empty cursor");
return CnapInfo.getDefaultInstance();
}
// At ths point, we expect only one row in the cursor as
// PhoneLookupHistory.NORMALIZED_NUMBER is the primary key of table PhoneLookupHistory.
Assert.checkState(cursor.getCount() == 1);
int phoneLookupInfoColumn = cursor.getColumnIndexOrThrow(PhoneLookupHistory.PHONE_LOOKUP_INFO);
PhoneLookupInfo phoneLookupInfo;
try {
phoneLookupInfo = PhoneLookupInfo.parseFrom(cursor.getBlob(phoneLookupInfoColumn));
} catch (InvalidProtocolBufferException e) {
throw new IllegalStateException(e);
}
return phoneLookupInfo.getCnapInfo();
}
});
}
use of com.android.dialer.common.database.Selection in project android_packages_apps_Dialer by LineageOS.
the class SpeedDialUiItemMutator method getStarredContacts.
@WorkerThread
private List<SpeedDialUiItem> getStarredContacts() {
Trace.beginSection("getStrequentContacts");
Assert.isWorkerThread();
Set<String> contactIds = new ArraySet<>();
// Fetch the contact ids of all starred contacts
Uri strequentUri = Contacts.CONTENT_STREQUENT_URI.buildUpon().appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true").build();
Selection selection = Selection.column(Phone.STARRED).is("=", 1);
try (Cursor cursor = appContext.getContentResolver().query(strequentUri, new String[] { Phone.CONTACT_ID }, selection.getSelection(), selection.getSelectionArgs(), null)) {
if (cursor == null) {
LogUtil.e("SpeedDialUiItemMutator.getStarredContacts", "null cursor");
Trace.endSection();
return new ArrayList<>();
}
if (cursor.getCount() == 0) {
Trace.endSection();
return new ArrayList<>();
}
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
contactIds.add(Long.toString(cursor.getLong(0)));
}
}
// Build SpeedDialUiItems from those contact ids
selection = Selection.builder().and(Selection.column(Phone.CONTACT_ID).in(contactIds)).build();
try (Cursor cursor = appContext.getContentResolver().query(Phone.CONTENT_URI, SpeedDialUiItem.getPhoneProjection(isPrimaryDisplayNameOrder()), selection.getSelection(), selection.getSelectionArgs(), null)) {
List<SpeedDialUiItem> contacts = new ArrayList<>();
if (cursor == null) {
LogUtil.e("SpeedDialUiItemMutator.getStrequentContacts", "null cursor");
Trace.endSection();
return new ArrayList<>();
}
if (cursor.getCount() == 0) {
Trace.endSection();
return contacts;
}
for (cursor.moveToFirst(); !cursor.isAfterLast(); ) /* Iterate in the loop */
{
contacts.add(SpeedDialUiItem.fromCursor(appContext.getResources(), cursor, CallUtil.isVideoEnabled(appContext)));
}
Trace.endSection();
return contacts;
}
}
use of com.android.dialer.common.database.Selection in project android_packages_apps_Dialer by LineageOS.
the class SpeedDialUiItemMutator method getSpeedDialUiItemsFromEntries.
/**
* Returns a map of SpeedDialEntries to their corresponding SpeedDialUiItems. Mappings to null
* elements imply that the contact was deleted.
*/
@WorkerThread
private Map<SpeedDialEntry, SpeedDialUiItem> getSpeedDialUiItemsFromEntries(List<SpeedDialEntry> entries) {
Trace.beginSection("getSpeedDialUiItemsFromEntries");
Assert.isWorkerThread();
// Fetch the contact ids from the SpeedDialEntries
Set<String> contactIds = new ArraySet<>();
entries.forEach(entry -> contactIds.add(Long.toString(entry.contactId())));
if (contactIds.isEmpty()) {
Trace.endSection();
return new ArrayMap<>();
}
// Build SpeedDialUiItems from those contact ids and map them to their entries
Selection selection = Selection.builder().and(Selection.column(Phone.CONTACT_ID).in(contactIds)).build();
try (Cursor cursor = appContext.getContentResolver().query(Phone.CONTENT_URI, SpeedDialUiItem.getPhoneProjection(isPrimaryDisplayNameOrder()), selection.getSelection(), selection.getSelectionArgs(), null)) {
Map<SpeedDialEntry, SpeedDialUiItem> map = new ArrayMap<>();
for (cursor.moveToFirst(); !cursor.isAfterLast(); ) /* Iterate in the loop */
{
SpeedDialUiItem item = SpeedDialUiItem.fromCursor(appContext.getResources(), cursor, CallUtil.isVideoEnabled(appContext));
for (SpeedDialEntry entry : entries) {
if (entry.contactId() == item.contactId()) {
// Update the id and pinned position to match it's corresponding SpeedDialEntry.
SpeedDialUiItem.Builder entrySpeedDialItem = item.toBuilder().setSpeedDialEntryId(entry.id()).setPinnedPosition(entry.pinnedPosition());
// Preserve the default channel if it didn't change/still exists
Channel defaultChannel = entry.defaultChannel();
if (defaultChannel != null) {
if (item.channels().contains(defaultChannel) || isValidDuoDefaultChannel(item.channels(), defaultChannel)) {
entrySpeedDialItem.setDefaultChannel(defaultChannel);
}
}
// It's impossible for two contacts to exist with the same contact id, so if this entry
// was previously matched to a SpeedDialUiItem and is being matched again, something
// went horribly wrong.
Assert.checkArgument(map.put(entry, entrySpeedDialItem.build()) == null, "Each SpeedDialEntry only has one correct SpeedDialUiItem");
}
}
}
// Contact must have been deleted
for (SpeedDialEntry entry : entries) {
map.putIfAbsent(entry, null);
}
Trace.endSection();
return map;
}
}
use of com.android.dialer.common.database.Selection in project android_packages_apps_Dialer by LineageOS.
the class SpeedDialEntryDatabaseHelper method delete.
private void delete(SQLiteDatabase writeableDatabase, ImmutableList<Long> ids) {
List<String> idStrings = new ArrayList<>();
for (Long id : ids) {
idStrings.add(Long.toString(id));
}
Selection selection = Selection.builder().and(Selection.column(ID).in(idStrings)).build();
int count = writeableDatabase.delete(TABLE_NAME, selection.getSelection(), selection.getSelectionArgs());
if (count != ids.size()) {
throw Assert.createUnsupportedOperationFailException("Attempted to delete an undetermined number of rows: " + count);
}
}
Aggregations