From b6ca71a9fd52c85c8e49a8835ecdf0f8357471c9 Mon Sep 17 00:00:00 2001 From: maxwelb Date: Wed, 7 Feb 2018 14:11:29 -0800 Subject: Handle concurrently deleted rows in all updateSmartDialDatabase cursors Bug: 73074317 Test: Not possible, see above PiperOrigin-RevId: 184893521 Change-Id: Iecb99c658dafa98a2518202c14e67c4494983090 --- .../dialer/database/DialerDatabaseHelper.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/java/com/android/dialer/database/DialerDatabaseHelper.java b/java/com/android/dialer/database/DialerDatabaseHelper.java index 8431a90a7..efff11ecc 100644 --- a/java/com/android/dialer/database/DialerDatabaseHelper.java +++ b/java/com/android/dialer/database/DialerDatabaseHelper.java @@ -375,7 +375,9 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper { do { if (deletedContactCursor.isNull(DeleteContactQuery.DELETED_CONTACT_ID)) { - LogUtil.i("DialerDatabaseHelper.removeDeletedContacts", "null contact id, skipping row"); + LogUtil.i( + "DialerDatabaseHelper.removeDeletedContacts", + "contact_id column null. Row was deleted during iteration, skipping"); continue; } @@ -455,6 +457,13 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper { try { updatedContactCursor.moveToPosition(-1); while (updatedContactCursor.moveToNext()) { + if (updatedContactCursor.isNull(UpdatedContactQuery.UPDATED_CONTACT_ID)) { + LogUtil.i( + "DialerDatabaseHelper.removeUpdatedContacts", + "contact_id column null. Row was deleted during iteration, skipping"); + continue; + } + final Long contactId = updatedContactCursor.getLong(UpdatedContactQuery.UPDATED_CONTACT_ID); db.delete(Tables.SMARTDIAL_TABLE, SmartDialDbColumns.CONTACT_ID + "=" + contactId, null); @@ -529,6 +538,13 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper { while (updatedContactCursor.moveToNext()) { insert.clearBindings(); + if (updatedContactCursor.isNull(PhoneQuery.PHONE_ID)) { + LogUtil.i( + "DialerDatabaseHelper.insertUpdatedContactsAndNumberPrefix", + "_id column null. Row was deleted during iteration, skipping"); + continue; + } + // Handle string columns which can possibly be null first. In the case of certain // null columns (due to malformed rows possibly inserted by third-party apps // or sync adapters), skip the phone number row. @@ -607,6 +623,13 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper { final SQLiteStatement insert = db.compileStatement(sqlInsert); while (nameCursor.moveToNext()) { + if (nameCursor.isNull(columnIndexContactId)) { + LogUtil.i( + "DialerDatabaseHelper.insertNamePrefixes", + "contact_id column null. Row was deleted during iteration, skipping"); + continue; + } + /** Computes a list of prefixes of a given contact name. */ final ArrayList namePrefixes = SmartDialPrefix.generateNamePrefixes(context, nameCursor.getString(columnIndexName)); -- cgit v1.2.3