Allow adding remote sub only if FEATURE_AUTOMOTIVE is supported.

Adding a remote can increase the number of active subs beyond
what is supported, and in any case it should not be allowed
on devices that don't support it. Currently only automotive
devices support it.

Test: manual
Bug: 197327688
Change-Id: I7e583784f5672e20e6ee4a6013698554daf91a22
diff --git a/src/java/com/android/internal/telephony/SubscriptionController.java b/src/java/com/android/internal/telephony/SubscriptionController.java
index f03070f..deb5240 100644
--- a/src/java/com/android/internal/telephony/SubscriptionController.java
+++ b/src/java/com/android/internal/telephony/SubscriptionController.java
@@ -31,6 +31,7 @@
 import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.database.ContentObserver;
 import android.database.Cursor;
 import android.graphics.Bitmap;
@@ -95,7 +96,6 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * Implementation of the ISub interface.
@@ -1334,6 +1334,12 @@
             String selection = SubscriptionManager.ICC_ID + "=?";
             String[] args;
             if (isSubscriptionForRemoteSim(subscriptionType)) {
+                PackageManager packageManager = mContext.getPackageManager();
+                if (!packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {
+                    logel("[addSubInfo] Remote SIM can only be added when FEATURE_AUTOMOTIVE"
+                            + " is supported");
+                    return -1;
+                }
                 selection += " AND " + SubscriptionManager.SUBSCRIPTION_TYPE + "=?";
                 args = new String[]{uniqueId, Integer.toString(subscriptionType)};
             } else {
diff --git a/tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java
index b79b317..a0a19bc 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java
@@ -765,6 +765,7 @@
     @Test @SmallTest
     public void testInsertRemoteSim() {
         makeThisDeviceMultiSimCapable();
+        mContextFixture.addSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
 
         // verify there are no sim's in the system.
         assertEquals(0, mSubscriptionControllerUT.getAllSubInfoCount(mCallingPackage,
@@ -853,6 +854,7 @@
     @Test @SmallTest
     public void testInsertMultipleRemoteSims() {
         makeThisDeviceMultiSimCapable();
+        mContextFixture.addSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
 
         // verify that there are no subscription info records
         assertEquals(0, mSubscriptionControllerUT.getAllSubInfoCount(mCallingPackage,