use of com.android.dialer.common.database.Selection in project android_packages_apps_Dialer by LineageOS.
the class ClearMissedCalls method markRead.
/**
* Marks all provided system call log IDs as read, or if the provided collection is empty, marks
* all calls as read.
*/
@SuppressLint("MissingPermission")
private ListenableFuture<Void> markRead(Collection<Long> ids) {
return backgroundExecutor.submit(() -> {
if (!UserManagerCompat.isUserUnlocked(appContext)) {
LogUtil.e("ClearMissedCalls.markRead", "locked");
return null;
}
if (!PermissionsUtil.hasCallLogWritePermissions(appContext)) {
LogUtil.e("ClearMissedCalls.markRead", "no permission");
return null;
}
ContentValues values = new ContentValues();
values.put(Calls.IS_READ, 1);
Selection.Builder selectionBuilder = Selection.builder().and(Selection.column(Calls.IS_READ).is("=", 0).buildUpon().or(Selection.column(Calls.IS_READ).is("IS NULL")).build()).and(Selection.column(Calls.TYPE).is("=", Calls.MISSED_TYPE));
if (!ids.isEmpty()) {
selectionBuilder.and(Selection.column(Calls._ID).in(toStrings(ids)));
}
Selection selection = selectionBuilder.build();
appContext.getContentResolver().update(Calls.CONTENT_URI, values, selection.getSelection(), selection.getSelectionArgs());
return null;
});
}
use of com.android.dialer.common.database.Selection in project android_packages_apps_Dialer by LineageOS.
the class RttTranscriptUtil method checkRttTranscriptAvailability.
@WorkerThread
private static ImmutableSet<String> checkRttTranscriptAvailability(Context context, ImmutableSet<String> transcriptIds) {
Assert.isWorkerThread();
RttTranscriptDatabaseHelper databaseHelper = new RttTranscriptDatabaseHelper(context);
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
Selection selection = Selection.builder().and(Selection.column(RttTranscriptColumn.TRANSCRIPT_ID).in(transcriptIds)).build();
try (Cursor cursor = databaseHelper.getReadableDatabase().query(RttTranscriptDatabaseHelper.TABLE, new String[] { RttTranscriptColumn.TRANSCRIPT_ID }, selection.getSelection(), selection.getSelectionArgs(), null, null, null)) {
if (cursor != null) {
while (cursor.moveToNext()) {
builder.add(cursor.getString(0));
}
}
}
databaseHelper.close();
return builder.build();
}
use of com.android.dialer.common.database.Selection in project android_packages_apps_Dialer by LineageOS.
the class MissingPermissionsOperations method isDirtyForMissingPermissions.
/**
* Returns true if there is any CP2 data for the specified numbers in PhoneLookupHistory, because
* that data needs to be cleared.
*
* <p>Note: This might be a little slow for users without contacts permissions, but we don't
* expect this to often be the case. If necessary, a shared pref could be used to track the
* permission state as an optimization.
*/
ListenableFuture<Boolean> isDirtyForMissingPermissions(ImmutableSet<DialerPhoneNumber> phoneNumbers, Predicate<PhoneLookupInfo> phoneLookupInfoIsDirtyFn) {
return backgroundExecutor.submit(() -> {
// Note: This loses country info when number is not valid.
String[] normalizedNumbers = phoneNumbers.stream().map(DialerPhoneNumber::getNormalizedNumber).toArray(String[]::new);
Selection selection = Selection.builder().and(Selection.column(PhoneLookupHistory.NORMALIZED_NUMBER).in(normalizedNumbers)).build();
try (Cursor cursor = appContext.getContentResolver().query(PhoneLookupHistory.CONTENT_URI, new String[] { PhoneLookupHistory.PHONE_LOOKUP_INFO }, selection.getSelection(), selection.getSelectionArgs(), null)) {
if (cursor == null) {
LogUtil.w("MissingPermissionsOperations.isDirtyForMissingPermissions", "null cursor");
return false;
}
if (cursor.moveToFirst()) {
int phoneLookupInfoColumn = cursor.getColumnIndexOrThrow(PhoneLookupHistory.PHONE_LOOKUP_INFO);
do {
PhoneLookupInfo phoneLookupInfo;
try {
phoneLookupInfo = PhoneLookupInfo.parseFrom(cursor.getBlob(phoneLookupInfoColumn));
} catch (InvalidProtocolBufferException e) {
throw new IllegalStateException(e);
}
if (phoneLookupInfoIsDirtyFn.test(phoneLookupInfo)) {
return true;
}
} while (cursor.moveToNext());
}
}
return false;
});
}
use of com.android.dialer.common.database.Selection in project android_packages_apps_Dialer by LineageOS.
the class DialerDatabaseHelper method removeDeletedContacts.
/**
* Removes rows in the smartdial database that matches the contacts that have been deleted by
* other apps since last update.
*
* @param db Database to operate on.
* @param lastUpdatedTimeMillis the last time at which an update to the smart dial database was
* run.
*/
private void removeDeletedContacts(SQLiteDatabase db, String lastUpdatedTimeMillis) {
Cursor deletedContactCursor = getDeletedContactCursor(lastUpdatedTimeMillis);
if (deletedContactCursor == null) {
return;
}
db.beginTransaction();
try {
if (!deletedContactCursor.moveToFirst()) {
return;
}
do {
if (deletedContactCursor.isNull(DeleteContactQuery.DELETED_CONTACT_ID)) {
LogUtil.i("DialerDatabaseHelper.removeDeletedContacts", "contact_id column null. Row was deleted during iteration, skipping");
continue;
}
long deleteContactId = deletedContactCursor.getLong(DeleteContactQuery.DELETED_CONTACT_ID);
Selection smartDialSelection = Selection.column(SmartDialDbColumns.CONTACT_ID).is("=", deleteContactId);
db.delete(Tables.SMARTDIAL_TABLE, smartDialSelection.getSelection(), smartDialSelection.getSelectionArgs());
Selection prefixSelection = Selection.column(PrefixColumns.CONTACT_ID).is("=", deleteContactId);
db.delete(Tables.PREFIX_TABLE, prefixSelection.getSelection(), prefixSelection.getSelectionArgs());
} while (deletedContactCursor.moveToNext());
db.setTransactionSuccessful();
} finally {
deletedContactCursor.close();
db.endTransaction();
}
}
use of com.android.dialer.common.database.Selection in project android_packages_apps_Dialer by LineageOS.
the class HighResolutionPhotoRequesterImpl method getGoogleRawContactIds.
private List<Long> getGoogleRawContactIds(long contactId) throws RequestFailedException {
List<Long> result = new ArrayList<>();
Selection selection = Selection.column(RawContacts.CONTACT_ID).is("=", contactId).buildUpon().and(Selection.column(RawContacts.ACCOUNT_TYPE).is("=", "com.google")).build();
try (Cursor cursor = appContext.getContentResolver().query(RawContacts.CONTENT_URI, new String[] { RawContacts._ID, RawContacts.ACCOUNT_TYPE }, selection.getSelection(), selection.getSelectionArgs(), null)) {
if (cursor == null) {
throw new RequestFailedException("null cursor from raw contact IDs");
}
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
result.add(cursor.getLong(0));
}
}
return result;
}
Aggregations