summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/contacts/ContactsDatabaseHelper.java
diff options
context:
space:
mode:
authorSantos Cordon <santoscordon@google.com>2015-02-11 22:21:00 -0800
committerSantos Cordon <santoscordon@google.com>2015-02-19 23:42:50 -0800
commit423f9bc8fed50e2caacd6f99f3160494f15c0a67 (patch)
tree311498ccba2fa39497934d94716ad8aea3bbee1d /src/com/android/providers/contacts/ContactsDatabaseHelper.java
parentddd1e137585848bc58823e4f6e997ccf61b1b244 (diff)
downloadpackages_providers_ContactsProvider-423f9bc8fed50e2caacd6f99f3160494f15c0a67.zip
packages_providers_ContactsProvider-423f9bc8fed50e2caacd6f99f3160494f15c0a67.tar.gz
packages_providers_ContactsProvider-423f9bc8fed50e2caacd6f99f3160494f15c0a67.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/android/providers/contacts/ContactsDatabaseHelper.java')
-rw-r--r--src/com/android/providers/contacts/ContactsDatabaseHelper.java43
1 files changed, 41 insertions, 2 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index e4688ee..fc4d343 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -16,6 +16,7 @@
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,7 +87,6 @@ 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;
@@ -119,7 +121,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
* 1000-1100 M
* </pre>
*/
- static final int DATABASE_VERSION = 1002;
+ static final int DATABASE_VERSION = 1003;
public interface Tables {
public static final String CONTACTS = "contacts";
@@ -1516,6 +1518,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," +
@@ -2873,6 +2876,11 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
oldVersion = 1002;
}
+ if (oldVersion < 1003) {
+ upgradeToVersion1003(db);
+ oldVersion = 1003;
+ }
+
if (upgradeViewsAndTriggers) {
createContactsViews(db);
createGroupsView(db);
@@ -4335,6 +4343,37 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
"expiration INTEGER NOT NULL DEFAULT 0);");
}
+ public void upgradeToVersion1003(SQLiteDatabase db) {
+ db.execSQL("ALTER TABLE calls ADD phone_account_address TEXT;");
+
+ // After version 1003, 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) {