Merge "Add SubscriptionManager APIs for satellite communication."
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 38b397a..63973a8 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -161,7 +161,7 @@
     private static final boolean DBG = true;
     private static final boolean VDBG = false; // STOPSHIP if true
 
-    private static final int DATABASE_VERSION = 61 << 16;
+    private static final int DATABASE_VERSION = 62 << 16;
     private static final int URL_UNKNOWN = 0;
     private static final int URL_TELEPHONY = 1;
     private static final int URL_CURRENT = 2;
@@ -587,7 +587,9 @@
                 + SubscriptionManager.USAGE_SETTING_UNKNOWN + ","
                 + Telephony.SimInfo.COLUMN_TP_MESSAGE_REF +
                 "  INTEGER DEFAULT -1,"
-                + Telephony.SimInfo.COLUMN_USER_HANDLE + " INTEGER DEFAULT " + UserHandle.USER_NULL
+                + Telephony.SimInfo.COLUMN_USER_HANDLE + " INTEGER DEFAULT "
+                + UserHandle.USER_NULL + ","
+                + Telephony.SimInfo.COLUMN_SATELLITE_ENABLED + " INTEGER DEFAULT -1"
                 + ");";
     }
 
@@ -1888,6 +1890,21 @@
                 }
                 oldVersion = 61 << 16 | 6;
             }
+
+            if (oldVersion < (62 << 16 | 6)) {
+                try {
+                    // Try to update the siminfo table with new columns.
+                    db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN "
+                            + Telephony.SimInfo.COLUMN_SATELLITE_ENABLED
+                            + "  INTEGER DEFAULT -1;");
+                } catch (SQLiteException e) {
+                    if (DBG) {
+                        log("onUpgrade failed to update " + SIMINFO_TABLE
+                                + " to add satellite enabled. ");
+                    }
+                }
+                oldVersion = 62 << 16 | 6;
+            }
             if (DBG) {
                 log("dbh.onUpgrade:- db=" + db + " oldV=" + oldVersion + " newV=" + newVersion);
             }
@@ -3714,7 +3731,7 @@
                 PersistableBundle backedUpSimInfoEntry, int backupDataFormatVersion,
                 String isoCountryCodeFromDb,
                 List<String> wfcRestoreBlockedCountries) {
-            if (DATABASE_VERSION != 61 << 16) {
+            if (DATABASE_VERSION != 62 << 16) {
                 throw new AssertionError("The database schema has been updated which might make "
                     + "the format of #BACKED_UP_SIM_SPECIFIC_SETTINGS_FILE outdated. Make sure to "
                     + "1) review whether any of the columns in #SIM_INFO_COLUMNS_TO_BACKUP have "
diff --git a/tests/src/com/android/providers/telephony/TelephonyDatabaseHelperTest.java b/tests/src/com/android/providers/telephony/TelephonyDatabaseHelperTest.java
index 406746f..26a3a46 100644
--- a/tests/src/com/android/providers/telephony/TelephonyDatabaseHelperTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyDatabaseHelperTest.java
@@ -459,6 +459,23 @@
         assertEquals(UserHandle.USER_NULL, userHandleVal);
     }
 
+    @Test
+    public void databaseHelperOnUpgrade_hasSatelliteEnabledField() {
+        Log.d(TAG, "databaseHelperOnUpgrade_hasSatelliteEnabledField");
+        // (5 << 16 | 6) is the first upgrade trigger in onUpgrade
+        SQLiteDatabase db = mInMemoryDbHelper.getWritableDatabase();
+        mHelper.onUpgrade(db, (4 << 16), TelephonyProvider.getVersion(mContext));
+
+        // the upgraded db must have
+        // Telephony.SimInfo.COLUMN_SATELLITE_ENABLED
+        Cursor cursor = db.query("siminfo", null, null, null, null, null, null);
+        String[] upgradedColumns = cursor.getColumnNames();
+        Log.d(TAG, "siminfo columns: " + Arrays.toString(upgradedColumns));
+
+        assertTrue(Arrays.asList(upgradedColumns).contains(
+                Telephony.SimInfo.COLUMN_SATELLITE_ENABLED));
+    }
+
     /**
      * Helper for an in memory DB used to test the TelephonyProvider#DatabaseHelper.
      *
diff --git a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
index 7b74f9d..de4c6c5 100644
--- a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
@@ -717,6 +717,7 @@
         final int insertProfileClass = SubscriptionManager.PROFILE_CLASS_DEFAULT;
         final int insertPortIndex = 1;
         final int insertUserHandle = 0;
+        final int insertSatelliteEnabled = 1;
         contentValues.put(SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID, insertSubId);
         contentValues.put(SubscriptionManager.DISPLAY_NAME, insertDisplayName);
         contentValues.put(SubscriptionManager.CARRIER_NAME, insertCarrierName);
@@ -725,6 +726,7 @@
         contentValues.put(SubscriptionManager.PROFILE_CLASS, insertProfileClass);
         contentValues.put(SubscriptionManager.PORT_INDEX, insertPortIndex);
         contentValues.put(SubscriptionManager.USER_HANDLE, insertUserHandle);
+        contentValues.put(SubscriptionManager.SATELLITE_ENABLED, insertSatelliteEnabled);
 
         Log.d(TAG, "testSimTable Inserting contentValues: " + contentValues);
         mContentResolver.insert(SimInfo.CONTENT_URI, contentValues);
@@ -738,6 +740,7 @@
             SubscriptionManager.PROFILE_CLASS,
             SubscriptionManager.PORT_INDEX,
             SubscriptionManager.USER_HANDLE,
+            SubscriptionManager.SATELLITE_ENABLED,
         };
         final String selection = SubscriptionManager.DISPLAY_NAME + "=?";
         String[] selectionArgs = { insertDisplayName };
@@ -756,11 +759,13 @@
         final int resultProfileClass = cursor.getInt(3);
         final int resultPortIndex = cursor.getInt(4);
         final int resultUserHandle = cursor.getInt(5);
+        final int resultSatelliteEnabled = cursor.getInt(6);
         assertEquals(insertSubId, resultSubId);
         assertEquals(insertCarrierName, resultCarrierName);
         assertEquals(insertCardId, resultCardId);
         assertEquals(insertPortIndex, resultPortIndex);
         assertEquals(insertUserHandle, resultUserHandle);
+        assertEquals(insertSatelliteEnabled, resultSatelliteEnabled);
 
         // delete test content
         final String selectionToDelete = SubscriptionManager.DISPLAY_NAME + "=?";