diff options
author | maxwelb <maxwelb@google.com> | 2018-01-23 11:23:01 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-23 13:08:11 -0800 |
commit | 3e35e4c85224bffdeb9e5649b439cf16d4c66bc2 (patch) | |
tree | f6dfaebd45891d545c188c1ec2b51031355860a7 | |
parent | 602563008ae1c0acc873fd183ce298e199949677 (diff) |
Attempt to work around sqlite database cursor window issue
Bug: 72320869
Test: DialerDatabaseHelperTest
PiperOrigin-RevId: 182964251
Change-Id: Ie6539ce27bcbd97b093a47e1f5882770fc345e59
-rw-r--r-- | java/com/android/dialer/database/DialerDatabaseHelper.java | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/java/com/android/dialer/database/DialerDatabaseHelper.java b/java/com/android/dialer/database/DialerDatabaseHelper.java index bc70fa46f..18c61342d 100644 --- a/java/com/android/dialer/database/DialerDatabaseHelper.java +++ b/java/com/android/dialer/database/DialerDatabaseHelper.java @@ -41,6 +41,7 @@ import com.android.contacts.common.util.StopWatch; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; import com.android.dialer.common.concurrent.DialerExecutorComponent; +import com.android.dialer.common.database.Selection; import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; import com.android.dialer.smartdial.util.SmartDialNameMatcher; import com.android.dialer.smartdial.util.SmartDialPrefix; @@ -351,24 +352,40 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper { * other apps since last update. * * @param db Database to operate on. - * @param deletedContactCursor Cursor containing rows of deleted contacts + * @param lastUpdatedTimeMillis the last time at which an update to the smart dial database was + * run. */ - @VisibleForTesting - void removeDeletedContacts(SQLiteDatabase db, Cursor deletedContactCursor) { + private void removeDeletedContacts(SQLiteDatabase db, String lastUpdatedTimeMillis) { + Cursor deletedContactCursor = getDeletedContactCursor(lastUpdatedTimeMillis); + if (deletedContactCursor == null) { return; } db.beginTransaction(); try { - while (deletedContactCursor.moveToNext()) { - final Long deleteContactId = - deletedContactCursor.getLong(DeleteContactQuery.DELETED_CONTACT_ID); - db.delete( - Tables.SMARTDIAL_TABLE, SmartDialDbColumns.CONTACT_ID + "=" + deleteContactId, null); - db.delete(Tables.PREFIX_TABLE, PrefixColumns.CONTACT_ID + "=" + deleteContactId, null); + if (!deletedContactCursor.moveToFirst()) { + return; } + do { + 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(); @@ -633,7 +650,7 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper { } /** Removes contacts that have been deleted. */ - removeDeletedContacts(db, getDeletedContactCursor(lastUpdateMillis)); + removeDeletedContacts(db, lastUpdateMillis); removePotentiallyCorruptedContacts(db, lastUpdateMillis); if (DEBUG) { |