diff options
author | Santos Cordon <santoscordon@google.com> | 2015-02-11 22:21:00 -0800 |
---|---|---|
committer | Etan Cohen <etancohen@google.com> | 2015-03-02 11:00:46 -0800 |
commit | 468fc189050b234fa8df7f62af0f7987517ffc35 (patch) | |
tree | c0f263695108f6a4600da64869e7b9b71d76efc5 /src/com | |
parent | 6522ca932caf4a4921115a2a3d13068c2357084c (diff) | |
download | packages_providers_ContactsProvider-468fc189050b234fa8df7f62af0f7987517ffc35.zip packages_providers_ContactsProvider-468fc189050b234fa8df7f62af0f7987517ffc35.tar.gz packages_providers_ContactsProvider-468fc189050b234fa8df7f62af0f7987517ffc35.tar.bz2 |
Upgrade calllog DB to use ICC ID & source_phone_number.
To accomodate backup and restore of the call log, we have to convert the
existing sub-ID to an ICC ID. Also, add the source_phone_number to the
list of call log columns.
The ICC ID improves backup and restore because it is persistent across
different devices where a sub ID is not. If the user completely changes
their SIM card, the source_phone_number will be helpful in identifying
that scenario if the user kept their old phone.
Change-Id: Ib35e25216691e580b5ea539929ff16b2e3d30b88
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/providers/contacts/CallLogProvider.java | 1 | ||||
-rw-r--r-- | src/com/android/providers/contacts/ContactsDatabaseHelper.java | 45 |
2 files changed, 44 insertions, 2 deletions
diff --git a/src/com/android/providers/contacts/CallLogProvider.java b/src/com/android/providers/contacts/CallLogProvider.java index d4339b0..6bf913e 100644 --- a/src/com/android/providers/contacts/CallLogProvider.java +++ b/src/com/android/providers/contacts/CallLogProvider.java @@ -108,6 +108,7 @@ public class CallLogProvider extends ContentProvider { sCallsProjectionMap.put(Calls.FEATURES, Calls.FEATURES); sCallsProjectionMap.put(Calls.PHONE_ACCOUNT_COMPONENT_NAME, Calls.PHONE_ACCOUNT_COMPONENT_NAME); sCallsProjectionMap.put(Calls.PHONE_ACCOUNT_ID, Calls.PHONE_ACCOUNT_ID); + sCallsProjectionMap.put(Calls.PHONE_ACCOUNT_ADDRESS, Calls.PHONE_ACCOUNT_ADDRESS); sCallsProjectionMap.put(Calls.NEW, Calls.NEW); sCallsProjectionMap.put(Calls.VOICEMAIL_URI, Calls.VOICEMAIL_URI); sCallsProjectionMap.put(Calls.TRANSCRIPTION, Calls.TRANSCRIPTION); diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java index e1a47cb..5fad661 100644 --- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java +++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java @@ -16,6 +16,7 @@ T * Copyright (C) 2009 The Android Open Source Project package com.android.providers.contacts; +import android.content.ComponentName; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; @@ -73,6 +74,8 @@ import android.provider.ContactsContract.StreamItems; import android.provider.VoicemailContract; import android.provider.VoicemailContract.Voicemails; import android.telephony.PhoneNumberUtils; +import android.telephony.SubscriptionInfo; +import android.telephony.SubscriptionManager; import android.text.TextUtils; import android.text.util.Rfc822Token; import android.text.util.Rfc822Tokenizer; @@ -84,11 +87,11 @@ import com.android.providers.contacts.database.ContactsTableUtil; import com.android.providers.contacts.database.DeletedContactsTableUtil; import com.android.providers.contacts.database.MoreDatabaseUtils; import com.android.providers.contacts.util.NeededForTesting; - import com.google.android.collect.Sets; import com.google.common.annotations.VisibleForTesting; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -117,9 +120,10 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { * 700-799 Jelly Bean * 800-899 Kitkat * 900-999 L + * 1000-1099 M * </pre> */ - static final int DATABASE_VERSION = 910; + static final int DATABASE_VERSION = 1000; public interface Tables { public static final String CONTACTS = "contacts"; @@ -1481,6 +1485,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { Calls.FEATURES + " INTEGER NOT NULL DEFAULT 0," + Calls.PHONE_ACCOUNT_COMPONENT_NAME + " TEXT," + Calls.PHONE_ACCOUNT_ID + " TEXT," + + Calls.PHONE_ACCOUNT_ADDRESS + " TEXT," + Calls.SUB_ID + " INTEGER DEFAULT -1," + Calls.NEW + " INTEGER," + Calls.CACHED_NAME + " TEXT," + @@ -2803,6 +2808,11 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { oldVersion = 910; } + if (oldVersion < 1000) { + upgradeToVersion1000(db); + oldVersion = 1000; + } + if (upgradeViewsAndTriggers) { createContactsViews(db); createGroupsView(db); @@ -4230,6 +4240,37 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { } } + public void upgradeToVersion1000(SQLiteDatabase db) { + db.execSQL("ALTER TABLE calls ADD phone_account_address TEXT;"); + + // After version 1000, we are using the ICC ID as the phone-account ID. This code updates + // any existing telephony connection-service calllog entries to the ICC ID from the + // previously used subscription ID. + // TODO: This is inconsistent, depending on the initialization state of SubscriptionManager. + // Sometimes it returns zero subscriptions. May want to move this upgrade to run after + // ON_BOOT_COMPLETE instead of PRE_BOOT_COMPLETE. + SubscriptionManager sm = SubscriptionManager.from(mContext); + if (sm != null) { + Log.i(TAG, "count: " + sm.getAllSubscriptionInfoCount()); + for (SubscriptionInfo info : sm.getAllSubscriptionInfoList()) { + String iccId = info.getIccId(); + int subId = info.getSubscriptionId(); + if (!TextUtils.isEmpty(iccId) && + subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { + StringBuilder sb = new StringBuilder(); + sb.append("UPDATE calls SET subscription_id="); + DatabaseUtils.appendEscapedSQLString(sb, iccId); + sb.append(" WHERE subscription_id="); + sb.append(subId); + sb.append(" AND subscription_component_name='com.android.phone/" + + "com.android.services.telephony.TelephonyConnectionService';"); + + db.execSQL(sb.toString()); + } + } + } + } + public String extractHandleFromEmailAddress(String email) { Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(email); if (tokens.length == 0) { |