Add profile class in SubscriptionInfo database
Bug: 116732485
Test: Basic telephony sanity
Change-Id: I04b9d5223e20d7f8f885406e56d8e06a3d6f5975
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 93f513d..a232d6f 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -143,7 +143,7 @@
private static final boolean DBG = true;
private static final boolean VDBG = false; // STOPSHIP if true
- private static final int DATABASE_VERSION = 33 << 16;
+ private static final int DATABASE_VERSION = 34 << 16;
private static final int URL_UNKNOWN = 0;
private static final int URL_TELEPHONY = 1;
private static final int URL_CURRENT = 2;
@@ -386,7 +386,9 @@
+ SubscriptionManager.GROUP_UUID + " TEXT,"
+ SubscriptionManager.IS_METERED + " INTEGER DEFAULT 1,"
+ SubscriptionManager.ISO_COUNTRY_CODE + " TEXT,"
- + SubscriptionManager.CARRIER_ID + " INTEGER DEFAULT -1"
+ + SubscriptionManager.CARRIER_ID + " INTEGER DEFAULT -1,"
+ + SubscriptionManager.PROFILE_CLASS + " INTEGER DEFAULT "
+ + SubscriptionManager.PROFILE_CLASS_DEFAULT
+ ");";
}
@@ -1170,7 +1172,7 @@
}
oldVersion = 30 << 16 | 6;
}
-
+
if (oldVersion < (31 << 16 | 6)) {
try {
// Try to update the siminfo table. It might not be there.
@@ -1213,6 +1215,21 @@
oldVersion = 33 << 16 | 6;
}
+ if (oldVersion < (34 << 16 | 6)) {
+ try {
+ // Try to update the siminfo table. It might not be there.
+ db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " +
+ SubscriptionManager.PROFILE_CLASS + " INTEGER DEFAULT " +
+ SubscriptionManager.PROFILE_CLASS_DEFAULT + ";");
+ } catch (SQLiteException e) {
+ if (DBG) {
+ log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " +
+ "The table will get created in onOpen.");
+ }
+ }
+ oldVersion = 34 << 16 | 6;
+ }
+
if (DBG) {
log("dbh.onUpgrade:- db=" + db + " oldV=" + oldVersion + " newV=" + newVersion);
}
diff --git a/tests/src/com/android/providers/telephony/TelephonyDatabaseHelperTest.java b/tests/src/com/android/providers/telephony/TelephonyDatabaseHelperTest.java
index 6892673..a4f31d9 100644
--- a/tests/src/com/android/providers/telephony/TelephonyDatabaseHelperTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyDatabaseHelperTest.java
@@ -100,6 +100,19 @@
}
@Test
+ public void databaseHelperOnUpgrade_hasProfileClassField() {
+ Log.d(TAG, "databaseHelperOnUpgrade_hasProfileClassField");
+ SQLiteDatabase db = mInMemoryDbHelper.getWritableDatabase();
+ mHelper.onUpgrade(db, (4 << 16), TelephonyProvider.DatabaseHelper.getVersion(mContext));
+
+ // the upgraded db must have the PROFILE_CLASS field
+ Cursor cursor = db.query("siminfo", null, null, null, null, null, null);
+ String[] upgradedColumns = cursor.getColumnNames();
+ Log.d(TAG, "profile class columns: " + Arrays.toString(upgradedColumns));
+ assertTrue(Arrays.asList(upgradedColumns).contains(SubscriptionManager.PROFILE_CLASS));
+ }
+
+ @Test
public void databaseHelperOnUpgrade_columnsMatchNewlyCreatedDb() {
Log.d(TAG, "databaseHelperOnUpgrade_columnsMatchNewlyCreatedDb");
// (5 << 16 | 6) is the first upgrade trigger in onUpgrade
diff --git a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
index 2ca823a..5723227 100644
--- a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
@@ -544,11 +544,13 @@
final String insertCarrierName = "exampleCarrierName";
final String insertIccId = "exampleIccId";
final String insertCardId = "exampleCardId";
+ final int insertProfileClass = SubscriptionManager.PROFILE_CLASS_DEFAULT;
contentValues.put(SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID, insertSubId);
contentValues.put(SubscriptionManager.DISPLAY_NAME, insertDisplayName);
contentValues.put(SubscriptionManager.CARRIER_NAME, insertCarrierName);
contentValues.put(SubscriptionManager.ICC_ID, insertIccId);
contentValues.put(SubscriptionManager.CARD_ID, insertCardId);
+ contentValues.put(SubscriptionManager.PROFILE_CLASS, insertProfileClass);
Log.d(TAG, "testSimTable Inserting contentValues: " + contentValues);
mContentResolver.insert(SubscriptionManager.CONTENT_URI, contentValues);
@@ -559,6 +561,7 @@
SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID,
SubscriptionManager.CARRIER_NAME,
SubscriptionManager.CARD_ID,
+ SubscriptionManager.PROFILE_CLASS,
};
final String selection = SubscriptionManager.DISPLAY_NAME + "=?";
String[] selectionArgs = { insertDisplayName };
@@ -574,9 +577,11 @@
final int resultSubId = cursor.getInt(0);
final String resultCarrierName = cursor.getString(1);
final String resultCardId = cursor.getString(2);
+ final int resultProfileClass = cursor.getInt(3);
assertEquals(insertSubId, resultSubId);
assertEquals(insertCarrierName, resultCarrierName);
assertEquals(insertCardId, resultCardId);
+ assertEquals(insertProfileClass, resultProfileClass);
// delete test content
final String selectionToDelete = SubscriptionManager.DISPLAY_NAME + "=?";