Adding subscription group owner.

Define owner of a subscription group. Such that when subscriptions are
being added into or removed from a group, as long as callingPackage is
the group owner, it can skip carrier permission check of subscriptions
in the group.

This is necessary when a subscription is being added into a
group that contains inactive subscription, which mean its carrier
privilege can't be verified.

Bug: 131854492
Test: cts, unittest, TelephonyManagerTestApp
Change-Id: I365cca6302ca1ad830751bbfeb4d8d6d76d4e32c
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index c089f02..43b9aea 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -147,7 +147,7 @@
     private static final boolean DBG = true;
     private static final boolean VDBG = false; // STOPSHIP if true
 
-    private static final int DATABASE_VERSION = 38 << 16;
+    private static final int DATABASE_VERSION = 39 << 16;
     private static final int URL_UNKNOWN = 0;
     private static final int URL_TELEPHONY = 1;
     private static final int URL_CURRENT = 2;
@@ -399,7 +399,8 @@
                 + SubscriptionManager.PROFILE_CLASS_DEFAULT + ","
                 + SubscriptionManager.SUBSCRIPTION_TYPE + " INTEGER DEFAULT "
                 + SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM + ","
-                + SubscriptionManager.WHITE_LISTED_APN_DATA + " INTEGER DEFAULT 0"
+                + SubscriptionManager.WHITE_LISTED_APN_DATA + " INTEGER DEFAULT 0,"
+                + SubscriptionManager.GROUP_OWNER + " TEXT"
                 + ");";
     }
 
@@ -1304,6 +1305,20 @@
                 oldVersion = 38 << 16 | 6;
             }
 
+            if (oldVersion < (39 << 16 | 6)) {
+                try {
+                    // Try to update the siminfo table. It might not be there.
+                    db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN "
+                            + SubscriptionManager.GROUP_OWNER + " TEXT;");
+                } catch (SQLiteException e) {
+                    if (DBG) {
+                        log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " +
+                                "The table will get created in onOpen.");
+                    }
+                }
+                oldVersion = 39 << 16 | 6;
+            }
+
             if (DBG) {
                 log("dbh.onUpgrade:- db=" + db + " oldV=" + oldVersion + " newV=" + newVersion);
             }