Merge "[Settings] Avoid from EUICC access blocking main thread"
diff --git a/res/drawable-hdpi/ic_network_signal_0.png b/res/drawable-hdpi/ic_network_signal_0.png
deleted file mode 100644
index 1629ae6..0000000
--- a/res/drawable-hdpi/ic_network_signal_0.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/ic_network_signal_1.png b/res/drawable-hdpi/ic_network_signal_1.png
deleted file mode 100644
index 162ade2..0000000
--- a/res/drawable-hdpi/ic_network_signal_1.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/ic_network_signal_2.png b/res/drawable-hdpi/ic_network_signal_2.png
deleted file mode 100644
index d91273c..0000000
--- a/res/drawable-hdpi/ic_network_signal_2.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/ic_network_signal_3.png b/res/drawable-hdpi/ic_network_signal_3.png
deleted file mode 100644
index 5634bc9..0000000
--- a/res/drawable-hdpi/ic_network_signal_3.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/ic_network_signal_4.png b/res/drawable-hdpi/ic_network_signal_4.png
deleted file mode 100644
index 0588950..0000000
--- a/res/drawable-hdpi/ic_network_signal_4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/ic_sim_card_alert_white_48dp.png b/res/drawable-hdpi/ic_sim_card_alert_white_48dp.png
deleted file mode 100644
index c8fbf42..0000000
--- a/res/drawable-hdpi/ic_sim_card_alert_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-hdpi/ic_network_signal_0.png b/res/drawable-ldrtl-hdpi/ic_network_signal_0.png
deleted file mode 100644
index 54e7af9..0000000
--- a/res/drawable-ldrtl-hdpi/ic_network_signal_0.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-hdpi/ic_network_signal_1.png b/res/drawable-ldrtl-hdpi/ic_network_signal_1.png
deleted file mode 100644
index de959d5..0000000
--- a/res/drawable-ldrtl-hdpi/ic_network_signal_1.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-hdpi/ic_network_signal_2.png b/res/drawable-ldrtl-hdpi/ic_network_signal_2.png
deleted file mode 100644
index 097b9fb..0000000
--- a/res/drawable-ldrtl-hdpi/ic_network_signal_2.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-hdpi/ic_network_signal_3.png b/res/drawable-ldrtl-hdpi/ic_network_signal_3.png
deleted file mode 100644
index 11cb40b..0000000
--- a/res/drawable-ldrtl-hdpi/ic_network_signal_3.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-hdpi/ic_network_signal_4.png b/res/drawable-ldrtl-hdpi/ic_network_signal_4.png
deleted file mode 100644
index d741ffc..0000000
--- a/res/drawable-ldrtl-hdpi/ic_network_signal_4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-mdpi/ic_network_signal_0.png b/res/drawable-ldrtl-mdpi/ic_network_signal_0.png
deleted file mode 100644
index 4cac9ed..0000000
--- a/res/drawable-ldrtl-mdpi/ic_network_signal_0.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-mdpi/ic_network_signal_1.png b/res/drawable-ldrtl-mdpi/ic_network_signal_1.png
deleted file mode 100644
index 9323a13..0000000
--- a/res/drawable-ldrtl-mdpi/ic_network_signal_1.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-mdpi/ic_network_signal_2.png b/res/drawable-ldrtl-mdpi/ic_network_signal_2.png
deleted file mode 100644
index e2f38a9..0000000
--- a/res/drawable-ldrtl-mdpi/ic_network_signal_2.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-mdpi/ic_network_signal_3.png b/res/drawable-ldrtl-mdpi/ic_network_signal_3.png
deleted file mode 100644
index b565289..0000000
--- a/res/drawable-ldrtl-mdpi/ic_network_signal_3.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-mdpi/ic_network_signal_4.png b/res/drawable-ldrtl-mdpi/ic_network_signal_4.png
deleted file mode 100644
index f63a426..0000000
--- a/res/drawable-ldrtl-mdpi/ic_network_signal_4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-xhdpi/ic_network_signal_0.png b/res/drawable-ldrtl-xhdpi/ic_network_signal_0.png
deleted file mode 100644
index e4ec015..0000000
--- a/res/drawable-ldrtl-xhdpi/ic_network_signal_0.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-xhdpi/ic_network_signal_1.png b/res/drawable-ldrtl-xhdpi/ic_network_signal_1.png
deleted file mode 100644
index 712685a..0000000
--- a/res/drawable-ldrtl-xhdpi/ic_network_signal_1.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-xhdpi/ic_network_signal_2.png b/res/drawable-ldrtl-xhdpi/ic_network_signal_2.png
deleted file mode 100644
index 99fe1ac..0000000
--- a/res/drawable-ldrtl-xhdpi/ic_network_signal_2.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-xhdpi/ic_network_signal_3.png b/res/drawable-ldrtl-xhdpi/ic_network_signal_3.png
deleted file mode 100644
index 4ac2f10..0000000
--- a/res/drawable-ldrtl-xhdpi/ic_network_signal_3.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-xhdpi/ic_network_signal_4.png b/res/drawable-ldrtl-xhdpi/ic_network_signal_4.png
deleted file mode 100644
index 34608f1..0000000
--- a/res/drawable-ldrtl-xhdpi/ic_network_signal_4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_network_signal_0.png b/res/drawable-mdpi/ic_network_signal_0.png
deleted file mode 100644
index a1b8431..0000000
--- a/res/drawable-mdpi/ic_network_signal_0.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_network_signal_1.png b/res/drawable-mdpi/ic_network_signal_1.png
deleted file mode 100644
index cc6179d..0000000
--- a/res/drawable-mdpi/ic_network_signal_1.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_network_signal_2.png b/res/drawable-mdpi/ic_network_signal_2.png
deleted file mode 100644
index 1373fb6..0000000
--- a/res/drawable-mdpi/ic_network_signal_2.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_network_signal_3.png b/res/drawable-mdpi/ic_network_signal_3.png
deleted file mode 100644
index 14468eb..0000000
--- a/res/drawable-mdpi/ic_network_signal_3.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_network_signal_4.png b/res/drawable-mdpi/ic_network_signal_4.png
deleted file mode 100644
index 43cdf26..0000000
--- a/res/drawable-mdpi/ic_network_signal_4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_sim_card_alert_white_48dp.png b/res/drawable-mdpi/ic_sim_card_alert_white_48dp.png
deleted file mode 100644
index 18cd7f9..0000000
--- a/res/drawable-mdpi/ic_sim_card_alert_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/ic_network_signal_0.png b/res/drawable-xhdpi/ic_network_signal_0.png
deleted file mode 100644
index b609ecf..0000000
--- a/res/drawable-xhdpi/ic_network_signal_0.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/ic_network_signal_1.png b/res/drawable-xhdpi/ic_network_signal_1.png
deleted file mode 100644
index 854921f..0000000
--- a/res/drawable-xhdpi/ic_network_signal_1.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/ic_network_signal_2.png b/res/drawable-xhdpi/ic_network_signal_2.png
deleted file mode 100644
index 3db4ce6..0000000
--- a/res/drawable-xhdpi/ic_network_signal_2.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/ic_network_signal_3.png b/res/drawable-xhdpi/ic_network_signal_3.png
deleted file mode 100644
index 18003e5..0000000
--- a/res/drawable-xhdpi/ic_network_signal_3.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/ic_network_signal_4.png b/res/drawable-xhdpi/ic_network_signal_4.png
deleted file mode 100644
index 304108f..0000000
--- a/res/drawable-xhdpi/ic_network_signal_4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/ic_sim_card_alert_white_48dp.png b/res/drawable-xhdpi/ic_sim_card_alert_white_48dp.png
deleted file mode 100644
index 6d983b7..0000000
--- a/res/drawable-xhdpi/ic_sim_card_alert_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_network_signal_4.png b/res/drawable-xxhdpi/ic_network_signal_4.png
deleted file mode 100644
index dafe7c4..0000000
--- a/res/drawable-xxhdpi/ic_network_signal_4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_sim_card_alert_white_48dp.png b/res/drawable-xxhdpi/ic_sim_card_alert_white_48dp.png
deleted file mode 100644
index 6c8dd1f..0000000
--- a/res/drawable-xxhdpi/ic_sim_card_alert_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_network_signal_4.png b/res/drawable-xxxhdpi/ic_network_signal_4.png
deleted file mode 100644
index 622cc4c..0000000
--- a/res/drawable-xxxhdpi/ic_network_signal_4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_sim_card_alert_white_48dp.png b/res/drawable-xxxhdpi/ic_sim_card_alert_white_48dp.png
deleted file mode 100644
index e8b6667..0000000
--- a/res/drawable-xxxhdpi/ic_sim_card_alert_white_48dp.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable/ic_sim_alert.xml b/res/drawable/ic_sim_alert.xml
new file mode 100644
index 0000000..ed9aa43
--- /dev/null
+++ b/res/drawable/ic_sim_alert.xml
@@ -0,0 +1,27 @@
+<!--
+  Copyright (C) 2019 The Android Open Source Project
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24">
+    <path
+        android:pathData="m4.8578,21.8264c-0.2247,-0.137 -0.5206,-0.4329 -0.6575,-0.6575 -0.2399,-0.3935 -0.2491,-0.6433 -0.2495,-6.7995l-0.0005,-6.391 2.9757,-2.9776 2.9757,-2.9776 4.3876,0.0005c4.1571,0.0004 4.4091,0.0135 4.7961,0.2495 0.2247,0.137 0.5206,0.4329 0.6575,0.6575 0.2422,0.3972 0.2491,0.6479 0.2491,9.1192 0,8.4712 -0.007,8.7219 -0.2491,9.1191 -0.137,0.2247 -0.4329,0.5206 -0.6575,0.6575 -0.3942,0.2403 -0.6436,0.2491 -7.1138,0.2491 -6.4703,0 -6.7197,-0.009 -7.1138,-0.2491zM12.9743,16.0604v-1.0027h-1.0027,-1.0027v1.0027,1.0027h1.0027,1.0027zM12.9743,10.5457L12.9743,8.039h-1.0027,-1.0027v2.5067,2.5067h1.0027,1.0027z"
+        android:strokeWidth="0.12533334"
+        android:fillColor="#ffffff"/>
+</vector>
+
diff --git a/res/drawable/signal.xml b/res/drawable/signal.xml
deleted file mode 100644
index f315600..0000000
--- a/res/drawable/signal.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<level-list xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:maxLevel="0" android:drawable="@drawable/ic_network_signal_0" />
-    <item android:maxLevel="1" android:drawable="@drawable/ic_network_signal_1" />
-    <item android:maxLevel="2" android:drawable="@drawable/ic_network_signal_2" />
-    <item android:maxLevel="3" android:drawable="@drawable/ic_network_signal_3" />
-    <item android:maxLevel="4" android:drawable="@drawable/ic_network_signal_4" />
-</level-list>
-
diff --git a/src/com/android/settings/accounts/AccountTypePreferenceLoader.java b/src/com/android/settings/accounts/AccountTypePreferenceLoader.java
index d32b630..c639d1d 100644
--- a/src/com/android/settings/accounts/AccountTypePreferenceLoader.java
+++ b/src/com/android/settings/accounts/AccountTypePreferenceLoader.java
@@ -197,14 +197,7 @@
         ActivityInfo resolvedActivityInfo = resolveInfo.activityInfo;
         ApplicationInfo resolvedAppInfo = resolvedActivityInfo.applicationInfo;
         try {
-            if (resolvedActivityInfo.exported) {
-                if (resolvedActivityInfo.permission == null) {
-                    return true; // exported activity without permission.
-                } else if (pm.checkPermission(resolvedActivityInfo.permission,
-                    authDesc.packageName) == PackageManager.PERMISSION_GRANTED) {
-                    return true;
-                }
-            }
+            // Allows to launch only authenticator owned activities.
             ApplicationInfo authenticatorAppInf = pm.getApplicationInfo(authDesc.packageName, 0);
             return resolvedAppInfo.uid == authenticatorAppInf.uid;
         } catch (NameNotFoundException e) {
diff --git a/src/com/android/settings/datausage/DataUsageUtils.java b/src/com/android/settings/datausage/DataUsageUtils.java
index 433d1ed..02bfda8 100644
--- a/src/com/android/settings/datausage/DataUsageUtils.java
+++ b/src/com/android/settings/datausage/DataUsageUtils.java
@@ -33,6 +33,8 @@
 import android.text.format.Formatter.BytesResult;
 import android.util.Log;
 
+import com.android.settings.network.ProxySubscriptionManager;
+
 import java.util.List;
 
 /**
@@ -107,8 +109,8 @@
             return SystemProperties.get(DataUsageUtils.TEST_RADIOS_PROP).contains("mobile");
         }
         final List<SubscriptionInfo> subInfoList =
-                context.getSystemService(SubscriptionManager.class)
-                .getActiveSubscriptionInfoList();
+                ProxySubscriptionManager.getInstance(context)
+                .getActiveSubscriptionsInfo();
         // No activated Subscriptions
         if (subInfoList == null) {
             if (LOGD) {
@@ -150,6 +152,14 @@
     }
 
     public static boolean hasSim(Context context) {
+        // Access cache within ProxySubscriptionManager to speed up
+        final List<SubscriptionInfo> subInfoList =
+                ProxySubscriptionManager.getInstance(context)
+                .getActiveSubscriptionsInfo();
+        if ((subInfoList != null) && (subInfoList.size() > 0)) {
+            return true;
+        }
+
         TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class);
         final int simState = telephonyManager.getSimState();
         // Note that pulling the SIM card returns UNKNOWN, not ABSENT.
@@ -162,20 +172,20 @@
      * SubscriptionManager#INVALID_SUBSCRIPTION_ID
      */
     public static int getDefaultSubscriptionId(Context context) {
-        final SubscriptionManager subscriptionMgr =
-                context.getSystemService(SubscriptionManager.class);
-
         // default data subscription is first choice
-        final int dataSubId = subscriptionMgr.getDefaultDataSubscriptionId();
+        final int dataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
         if (SubscriptionManager.isValidSubscriptionId(dataSubId)) {
             return dataSubId;
         }
 
+        final ProxySubscriptionManager proxySubscriptionMgr =
+                ProxySubscriptionManager.getInstance(context);
+
         // any active subscription is second choice
-        List<SubscriptionInfo> subList = subscriptionMgr.getActiveSubscriptionInfoList();
+        List<SubscriptionInfo> subList = proxySubscriptionMgr.getActiveSubscriptionsInfo();
         if ((subList == null) || (subList.size() <= 0)) {
             // any subscription is third choice
-            subList = subscriptionMgr.getAvailableSubscriptionInfoList();
+            subList = proxySubscriptionMgr.getAccessibleSubscriptionsInfo();
         }
         if ((subList == null) || (subList.size() <= 0)) {
             return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
index 7951b07..370bdfb 100644
--- a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
+++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
@@ -23,6 +23,8 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
 import android.content.res.Resources;
 import android.os.IBinder;
 import android.os.PersistableBundle;
@@ -70,8 +72,6 @@
 
     private final static String TAG = "SimStatusDialogCtrl";
 
-    private static final String CELL_BROADCAST_SERVICE_PACKAGE = "com.android.cellbroadcastservice";
-
     @VisibleForTesting
     final static int NETWORK_PROVIDER_VALUE_ID = R.id.operator_name_value;
     @VisibleForTesting
@@ -360,7 +360,9 @@
     private void bindCellBroadcastService() {
         mCellBroadcastServiceConnection = new CellBroadcastServiceConnection();
         Intent intent = new Intent(CellBroadcastService.CELL_BROADCAST_SERVICE_INTERFACE);
-        intent.setPackage(CELL_BROADCAST_SERVICE_PACKAGE);
+        String cbsPackage = getCellBroadcastServicePackage();
+        if (TextUtils.isEmpty(cbsPackage)) return;
+        intent.setPackage(cbsPackage);
         if (mCellBroadcastServiceConnection != null
                 && mCellBroadcastServiceConnection.getService() == null) {
             if (!mContext.bindService(intent, mCellBroadcastServiceConnection,
@@ -372,6 +374,38 @@
         }
     }
 
+    /** Returns the package name of the cell broadcast service, or null if there is none. */
+    private String getCellBroadcastServicePackage() {
+        PackageManager packageManager = mContext.getPackageManager();
+        List<ResolveInfo> cbsPackages = packageManager.queryIntentServices(
+                new Intent(CellBroadcastService.CELL_BROADCAST_SERVICE_INTERFACE),
+                PackageManager.MATCH_SYSTEM_ONLY);
+        if (cbsPackages.size() != 1) {
+            Log.e(TAG, "getCellBroadcastServicePackageName: found " + cbsPackages.size()
+                    + " CBS packages");
+        }
+        for (ResolveInfo info : cbsPackages) {
+            if (info.serviceInfo == null) continue;
+            String packageName = info.serviceInfo.packageName;
+            if (!TextUtils.isEmpty(packageName)) {
+                if (packageManager.checkPermission(
+                        android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
+                        packageName) == PackageManager.PERMISSION_GRANTED) {
+                    Log.d(TAG, "getCellBroadcastServicePackageName: " + packageName);
+                    return packageName;
+                } else {
+                    Log.e(TAG, "getCellBroadcastServicePackageName: " + packageName
+                            + " does not have READ_PRIVILEGED_PHONE_STATE permission");
+                }
+            } else {
+                Log.e(TAG, "getCellBroadcastServicePackageName: found a CBS package but "
+                        + "packageName is null/empty");
+            }
+        }
+        Log.e(TAG, "getCellBroadcastServicePackageName: package name not found");
+        return null;
+    }
+
     private void updateLatestAreaInfo() {
         mShowLatestAreaInfo = Resources.getSystem().getBoolean(
                 com.android.internal.R.bool.config_showAreaUpdateInfoSettings)
diff --git a/src/com/android/settings/network/ActiveSubsciptionsListener.java b/src/com/android/settings/network/ActiveSubsciptionsListener.java
index 99dfd55..3d15025 100644
--- a/src/com/android/settings/network/ActiveSubsciptionsListener.java
+++ b/src/com/android/settings/network/ActiveSubsciptionsListener.java
@@ -73,6 +73,7 @@
      * @param context {@code Context} of this listener
      */
     public ActiveSubsciptionsListener(Looper looper, Context context) {
+        super(looper);
         mLooper = looper;
         mContext = context;
 
diff --git a/src/com/android/settings/network/ProxySubscriptionManager.java b/src/com/android/settings/network/ProxySubscriptionManager.java
index 0306b55..a89cc83 100644
--- a/src/com/android/settings/network/ProxySubscriptionManager.java
+++ b/src/com/android/settings/network/ProxySubscriptionManager.java
@@ -72,7 +72,7 @@
     private static ProxySubscriptionManager sSingleton;
 
     private ProxySubscriptionManager(Context context) {
-        final Looper looper = Looper.getMainLooper();
+        final Looper looper = context.getMainLooper();
 
         mActiveSubscriptionsListeners =
                 new ArrayList<OnActiveSubscriptionChangedListener>();
diff --git a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
index 9eb5f8c..650890e 100644
--- a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
@@ -19,10 +19,21 @@
 import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
 import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
 
+import android.content.ComponentName;
 import android.content.Context;
+import android.telecom.PhoneAccount;
+import android.telecom.PhoneAccountHandle;
+import android.telecom.TelecomManager;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
 import com.android.settings.R;
 import com.android.settings.core.BasePreferenceController;
 import com.android.settings.network.SubscriptionUtil;
@@ -31,13 +42,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.LifecycleObserver;
-import androidx.lifecycle.OnLifecycleEvent;
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
 /**
  * This implements common controller functionality for a Preference letting the user see/change
  * what mobile network subscription is used by default for some service controlled by the
@@ -51,10 +55,17 @@
     protected SubscriptionsChangeListener mChangeListener;
     protected ListPreference mPreference;
     protected SubscriptionManager mManager;
+    protected TelecomManager mTelecomManager;
+
+    private static final String EMERGENCY_ACCOUNT_HANDLE_ID = "E";
+    private static final ComponentName PSTN_CONNECTION_SERVICE_COMPONENT =
+            new ComponentName("com.android.phone",
+                    "com.android.services.telephony.TelephonyConnectionService");
 
     public DefaultSubscriptionController(Context context, String preferenceKey) {
         super(context, preferenceKey);
         mManager = context.getSystemService(SubscriptionManager.class);
+        mTelecomManager = mContext.getSystemService(TelecomManager.class);
         mChangeListener = new SubscriptionsChangeListener(context, this);
     }
 
@@ -103,8 +114,14 @@
 
     @Override
     public CharSequence getSummary() {
+        final PhoneAccountHandle handle = getDefaultCallingAccountHandle();
+        if ((handle != null) && (!isCallingAccountBindToSubscription(handle))) {
+            // display VoIP account in summary when configured through settings within dialer
+            return getLabelFromCallingAccount(handle);
+        }
         final SubscriptionInfo info = getDefaultSubscriptionInfo();
         if (info != null) {
+            // display subscription based account
             return info.getDisplayName();
         } else {
             return mContext.getString(R.string.calls_and_sms_ask_every_time);
@@ -161,6 +178,56 @@
         }
     }
 
+    /**
+     * Get default calling account
+     *
+     * @return current calling account {@link PhoneAccountHandle}
+     */
+    public PhoneAccountHandle getDefaultCallingAccountHandle() {
+        final PhoneAccountHandle currentSelectPhoneAccount =
+                mTelecomManager.getUserSelectedOutgoingPhoneAccount();
+        if (currentSelectPhoneAccount == null) {
+            return null;
+        }
+        final List<PhoneAccountHandle> accountHandles =
+                mTelecomManager.getCallCapablePhoneAccounts(false);
+        final PhoneAccountHandle emergencyAccountHandle = new PhoneAccountHandle(
+                PSTN_CONNECTION_SERVICE_COMPONENT, EMERGENCY_ACCOUNT_HANDLE_ID);
+        if (currentSelectPhoneAccount.equals(emergencyAccountHandle)) {
+            return null;
+        }
+        for (PhoneAccountHandle handle : accountHandles) {
+            if (currentSelectPhoneAccount.equals(handle)) {
+                return currentSelectPhoneAccount;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Check if calling account bind to subscription
+     *
+     * @param handle {@link PhoneAccountHandle} for specific calling account
+     */
+    public boolean isCallingAccountBindToSubscription(PhoneAccountHandle handle) {
+        return mTelecomManager.getPhoneAccount(handle)
+                .hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION);
+    }
+
+    /**
+     * Get label from calling account
+     *
+     * @param handle to get label from {@link PhoneAccountHandle}
+     * @return label of calling account
+     */
+    public CharSequence getLabelFromCallingAccount(PhoneAccountHandle handle) {
+        CharSequence label = mTelecomManager.getPhoneAccount(handle).getLabel();
+        if (label != null) {
+            label = mContext.getPackageManager().getUserBadgedLabel(label, handle.getUserHandle());
+        }
+        return (label != null) ? label : "";
+    }
+
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         final int subscriptionId = Integer.parseInt((String) newValue);
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java
index 02396dd..d04653c 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java
@@ -83,7 +83,7 @@
         mSwitchBar.addOnSwitchChangeListener((switchView, isChecked) -> {
             // TODO b/135222940: re-evaluate whether to use
             // mSubscriptionManager#isSubscriptionEnabled
-            if (mSubscriptionManager.isActiveSubId(mSubId) != isChecked
+            if (mSubscriptionManager.isActiveSubscriptionId(mSubId) != isChecked
                     && (!mSubscriptionManager.setSubscriptionEnabled(mSubId, isChecked))) {
                 mSwitchBar.setChecked(!isChecked);
             }
@@ -110,9 +110,7 @@
             mSwitchBar.hide();
         } else {
             mSwitchBar.show();
-            // TODO b/135222940: re-evaluate whether to use
-            // mSubscriptionManager#isSubscriptionEnabled
-            mSwitchBar.setChecked(mSubscriptionManager.isActiveSubId(mSubId));
+            mSwitchBar.setChecked(mSubscriptionManager.isActiveSubscriptionId(mSubId));
         }
     }
 
diff --git a/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java b/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
index 96ed771..cf544ab 100644
--- a/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
@@ -17,6 +17,7 @@
 package com.android.settings.network.telephony;
 
 import android.content.Context;
+import android.telecom.PhoneAccountHandle;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 
@@ -40,4 +41,10 @@
     protected void setDefaultSubscription(int subscriptionId) {
         mManager.setDefaultSmsSubId(subscriptionId);
     }
+
+    @Override
+    public PhoneAccountHandle getDefaultCallingAccountHandle() {
+        // Not supporting calling account override by VoIP
+        return null;
+    }
 }
diff --git a/src/com/android/settings/sim/SimSelectNotification.java b/src/com/android/settings/sim/SimSelectNotification.java
index fbf766c..ae36f35 100644
--- a/src/com/android/settings/sim/SimSelectNotification.java
+++ b/src/com/android/settings/sim/SimSelectNotification.java
@@ -103,7 +103,7 @@
 
         SubscriptionManager subscriptionManager = ((SubscriptionManager) context.getSystemService(
                 Context.TELEPHONY_SUBSCRIPTION_SERVICE));
-        if (!subscriptionManager.isActiveSubId(subId)) {
+        if (!subscriptionManager.isActiveSubscriptionId(subId)) {
             Log.w(TAG, "onEnableMmsDataRequest invalid sub ID " + subId);
             return;
         }
@@ -203,7 +203,7 @@
 
         Notification.Builder builder =
                 new Notification.Builder(context, SIM_SELECT_NOTIFICATION_CHANNEL)
-                .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp)
+                .setSmallIcon(R.drawable.ic_sim_alert)
                 .setColor(context.getColor(R.color.sim_noitification))
                 .setContentTitle(resources.getText(R.string.sim_notification_title))
                 .setContentText(resources.getText(R.string.sim_notification_summary))
@@ -283,7 +283,7 @@
 
         Notification.Builder builder =
                 new Notification.Builder(context, SIM_WARNING_NOTIFICATION_CHANNEL)
-                        .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp)
+                        .setSmallIcon(R.drawable.ic_sim_alert)
                         .setColor(context.getColor(R.color.sim_noitification))
                         .setContentTitle(resources.getText(
                                 R.string.sim_combination_warning_notification_title))
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java
index ccf345f..fb06e19 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java
@@ -109,7 +109,7 @@
 
     @Test
     public void displayPreference_oneEnabledSubscription_switchBarNotHidden() {
-        doReturn(true).when(mSubscriptionManager).isActiveSubId(mSubId);
+        doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(mSubId);
         SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription));
         mController.displayPreference(mScreen);
         assertThat(mSwitchBar.isShowing()).isTrue();
@@ -117,7 +117,7 @@
 
     @Test
     public void displayPreference_oneDisabledSubscription_switchBarNotHidden() {
-        doReturn(false).when(mSubscriptionManager).isActiveSubId(mSubId);
+        doReturn(false).when(mSubscriptionManager).isActiveSubscriptionId(mSubId);
         SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription));
         mController.displayPreference(mScreen);
         assertThat(mSwitchBar.isShowing()).isTrue();
@@ -125,7 +125,7 @@
 
     @Test
     public void displayPreference_subscriptionEnabled_switchIsOn() {
-        when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true);
+        when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true);
         mController.displayPreference(mScreen);
         assertThat(mSwitchBar.isShowing()).isTrue();
         assertThat(mSwitchBar.isChecked()).isTrue();
@@ -133,7 +133,7 @@
 
     @Test
     public void displayPreference_subscriptionDisabled_switchIsOff() {
-        when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(false);
+        when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(false);
         mController.displayPreference(mScreen);
         assertThat(mSwitchBar.isShowing()).isTrue();
         assertThat(mSwitchBar.isChecked()).isFalse();
@@ -141,7 +141,7 @@
 
     @Test
     public void switchChangeListener_fromEnabledToDisabled_setSubscriptionEnabledCalledCorrectly() {
-        when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true);
+        when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true);
         mController.displayPreference(mScreen);
         assertThat(mSwitchBar.isShowing()).isTrue();
         assertThat(mSwitchBar.isChecked()).isTrue();
@@ -153,7 +153,7 @@
     public void switchChangeListener_fromEnabledToDisabled_setSubscriptionEnabledFailed() {
         when(mSubscriptionManager.setSubscriptionEnabled(eq(mSubId), anyBoolean()))
                 .thenReturn(false);
-        when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true);
+        when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true);
         mController.displayPreference(mScreen);
         assertThat(mSwitchBar.isShowing()).isTrue();
         assertThat(mSwitchBar.isChecked()).isTrue();
@@ -164,7 +164,7 @@
 
     @Test
     public void switchChangeListener_fromDisabledToEnabled_setSubscriptionEnabledCalledCorrectly() {
-        when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(false);
+        when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(false);
         mController.displayPreference(mScreen);
         assertThat(mSwitchBar.isShowing()).isTrue();
         assertThat(mSwitchBar.isChecked()).isFalse();
diff --git a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
index 9b53636..8f861eb 100644
--- a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
+++ b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
@@ -117,7 +117,7 @@
 
         when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
         when(mTelephonyManager.isDataEnabledForApn(TYPE_MMS)).thenReturn(false);
-        when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true);
+        when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true);
         when(mSubscriptionManager.getActiveSubscriptionInfo(mSubId)).thenReturn(mSubInfo);
         when(mSubInfo.getDisplayName()).thenReturn(mFakeDisplayName);
         when(mContext.getResources()).thenReturn(mResources);