diff options
author | Tyler Gunn <tgunn@google.com> | 2014-06-30 19:57:44 -0700 |
---|---|---|
committer | Tyler Gunn <tgunn@google.com> | 2014-06-30 19:57:44 -0700 |
commit | 778df2417da0c0186862b25519ce65ed633a9b6d (patch) | |
tree | 8ce37261ab90bf1f598d308f1b97079e8117159d /src/com/android/providers | |
parent | 90343852ba1309aa4471cead018d50761a13e131 (diff) | |
download | packages_providers_ContactsProvider-778df2417da0c0186862b25519ce65ed633a9b6d.tar.gz packages_providers_ContactsProvider-778df2417da0c0186862b25519ce65ed633a9b6d.tar.bz2 packages_providers_ContactsProvider-778df2417da0c0186862b25519ce65ed633a9b6d.zip |
Changing call log adapter to normalize phone number where possible.
Bug: 15616526
Change-Id: Id8fe981a622bdea786a48cbadf9ff08289ae3987
Diffstat (limited to 'src/com/android/providers')
-rw-r--r-- | src/com/android/providers/contacts/ContactsDatabaseHelper.java | 60 | ||||
-rw-r--r-- | src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java | 11 |
2 files changed, 70 insertions, 1 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java index 85725312..80348410 100644 --- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java +++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java @@ -114,7 +114,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { * 900-999 L * </pre> */ - static final int DATABASE_VERSION = 902; + static final int DATABASE_VERSION = 903; public interface Tables { public static final String CONTACTS = "contacts"; @@ -2747,6 +2747,11 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { oldVersion = 902; } + if (oldVersion < 903) { + upgradeToVersion903(db); + oldVersion = 903; + } + if (upgradeViewsAndTriggers) { createContactsViews(db); createGroupsView(db); @@ -4056,6 +4061,59 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { db.execSQL("ALTER TABLE calls ADD "+ Calls.SUBSCRIPTION_ID + " TEXT;"); } + /** + * Searches for any calls in the call log with no normalized phone number and attempts to add + * one if the number can be normalized. + * + * @param db The database. + */ + private void upgradeToVersion903(SQLiteDatabase db) { + // Find the calls in the call log with no normalized phone number. + final Cursor c = db.rawQuery( + "SELECT _id, number, countryiso FROM calls " + + " WHERE (normalized_number is null OR normalized_number = '') " + + " AND countryiso != '' AND countryiso is not null " + + " AND number != '' AND number is not null;", + null + ); + + try { + if (c.getCount() == 0) { + return; + } + + db.beginTransaction(); + try { + c.moveToPosition(-1); + while (c.moveToNext()) { + final long callId = c.getLong(0); + final String unNormalizedNumber = c.getString(1); + final String countryIso = c.getString(2); + + // Attempt to get normalized number. + String normalizedNumber = PhoneNumberUtils + .formatNumberToE164(unNormalizedNumber, countryIso); + + if (!TextUtils.isEmpty(normalizedNumber)) { + db.execSQL("UPDATE calls set normalized_number = ? " + + "where _id = ?;", + new String[]{ + normalizedNumber, + String.valueOf(callId), + } + ); + } + } + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } finally { + c.close(); + } + } + public String extractHandleFromEmailAddress(String email) { Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(email); if (tokens.length == 0) { diff --git a/src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java b/src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java index 9e901977..1e232759 100644 --- a/src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java +++ b/src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java @@ -19,6 +19,8 @@ package com.android.providers.contacts; import android.content.ContentValues; import android.content.Context; import android.provider.CallLog.Calls; +import android.telephony.PhoneNumberUtils; +import android.text.TextUtils; import com.android.i18n.phonenumbers.NumberParseException; import com.android.i18n.phonenumbers.PhoneNumberUtil; @@ -74,6 +76,15 @@ import java.util.Set; values.put(Calls.NUMBER_PRESENTATION, Calls.PRESENTATION_UNKNOWN); values.put(Calls.NUMBER, ""); } + + // Check for a normalized number; if not present attempt to determine one now. + if (!values.containsKey(Calls.CACHED_NORMALIZED_NUMBER) && + !TextUtils.isEmpty(number)) { + String normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso); + if (!TextUtils.isEmpty(normalizedNumber)) { + values.put(Calls.CACHED_NORMALIZED_NUMBER, normalizedNumber); + } + } } private String getCurrentCountryIso() { |