summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-12-11 15:54:38 -0800
committerJay Shrauner <shrauner@google.com>2014-03-01 17:59:55 +0000
commitac00bf7fb06586574bef65bab0ba536989a7b4cd (patch)
tree477e8c4d14a7a184f19c2aab2c25867271c2da88
parentb0b153f5fe5833d1a3b102e93e6e27481a90e4f7 (diff)
Fix NPE in DialerDatabaseHelper for null phone numbers
Bug: 12006585 Change-Id: Iaed732806cbb8fb0301596162102e81ab8ec6024 (cherry picked from commit 1ef2b4a896e301b9e81aee073e58e35216128b2e)
-rw-r--r--src/com/android/dialer/database/DialerDatabaseHelper.java29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/com/android/dialer/database/DialerDatabaseHelper.java b/src/com/android/dialer/database/DialerDatabaseHelper.java
index b9e4b9a90..852b7c1b2 100644
--- a/src/com/android/dialer/database/DialerDatabaseHelper.java
+++ b/src/com/android/dialer/database/DialerDatabaseHelper.java
@@ -628,10 +628,26 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
updatedContactCursor.moveToPosition(-1);
while (updatedContactCursor.moveToNext()) {
- insert.bindLong(1, updatedContactCursor.getLong(PhoneQuery.PHONE_ID));
- insert.bindString(2, updatedContactCursor.getString(PhoneQuery.PHONE_NUMBER));
- insert.bindLong(3, updatedContactCursor.getLong(PhoneQuery.PHONE_CONTACT_ID));
- insert.bindString(4, updatedContactCursor.getString(PhoneQuery.PHONE_LOOKUP_KEY));
+ insert.clearBindings();
+
+ // 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.
+ final String number = updatedContactCursor.getString(PhoneQuery.PHONE_NUMBER);
+ if (TextUtils.isEmpty(number)) {
+ continue;
+ } else {
+ insert.bindString(2, number);
+ }
+
+ final String lookupKey = updatedContactCursor.getString(
+ PhoneQuery.PHONE_LOOKUP_KEY);
+ if (TextUtils.isEmpty(lookupKey)) {
+ continue;
+ } else {
+ insert.bindString(4, lookupKey);
+ }
+
final String displayName = updatedContactCursor.getString(
PhoneQuery.PHONE_DISPLAY_NAME);
if (displayName == null) {
@@ -639,6 +655,9 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
} else {
insert.bindString(5, displayName);
}
+
+ insert.bindLong(1, updatedContactCursor.getLong(PhoneQuery.PHONE_ID));
+ insert.bindLong(3, updatedContactCursor.getLong(PhoneQuery.PHONE_CONTACT_ID));
insert.bindLong(6, updatedContactCursor.getLong(PhoneQuery.PHONE_PHOTO_ID));
insert.bindLong(7, updatedContactCursor.getLong(PhoneQuery.PHONE_LAST_TIME_USED));
insert.bindLong(8, updatedContactCursor.getInt(PhoneQuery.PHONE_TIMES_USED));
@@ -648,8 +667,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
insert.bindLong(12, updatedContactCursor.getInt(PhoneQuery.PHONE_IS_PRIMARY));
insert.bindLong(13, currentMillis);
insert.executeInsert();
- insert.clearBindings();
-
final String contactPhoneNumber =
updatedContactCursor.getString(PhoneQuery.PHONE_NUMBER);
final ArrayList<String> numberPrefixes =