Merge "support mock carrier privilege rules and apn"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3cbca39..b0c4158 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -87,11 +87,11 @@
     <protected-broadcast android:name= "android.telephony.action.SIM_APPLICATION_STATE_CHANGED" />
     <protected-broadcast android:name= "android.telephony.action.SIM_SLOT_STATUS_CHANGED" />
     <protected-broadcast android:name= "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED" />
-    <protected-broadcast android:name= "android.telephony.action.SUBSCRIPTION_PRECISE_CARRIER_IDENTITY_CHANGED" />
+    <protected-broadcast android:name= "android.telephony.action.SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED" />
     <protected-broadcast android:name= "android.telephony.action.NETWORK_COUNTRY_CHANGED" />
 
     <!-- For Vendor Debugging in Telephony -->
-    <protected-broadcast android:name="android.telephony.action.DEBUG_EVENT" />
+    <protected-broadcast android:name="android.telephony.action.ANOMALY_REPORTED" />
 
     <uses-permission android:name="android.permission.BROADCAST_STICKY" />
     <uses-permission android:name="android.permission.CALL_PHONE" />
@@ -554,6 +554,7 @@
         <activity android:name="com.android.phone.settings.VoicemailSettingsActivity"
             android:label="@string/voicemail"
             android:configChanges="orientation|screenSize|keyboardHidden|screenLayout"
+            android:screenOrientation="portrait"
             android:theme="@style/DialerSettingsLight">
             <intent-filter >
                 <!-- DO NOT RENAME. There are existing apps which use this string. -->
@@ -577,18 +578,6 @@
             </intent-filter>
         </service>
 
-        <provider
-                android:name="PhoneSearchIndexablesProvider"
-                android:authorities="com.android.phone"
-                android:multiprocess="false"
-                android:grantUriPermissions="true"
-                android:permission="android.permission.READ_SEARCH_INDEXABLES"
-                android:exported="true">
-            <intent-filter>
-                <action android:name="android.content.action.SEARCH_INDEXABLES_PROVIDER" />
-            </intent-filter>
-        </provider>
-
         <receiver
           android:name="com.android.phone.vvm.VvmSmsReceiver"
             android:exported="false"
diff --git a/src/com/android/phone/EmergencyAssistanceHelper.java b/src/com/android/phone/EmergencyAssistanceHelper.java
index a98d81d..b4e4421 100644
--- a/src/com/android/phone/EmergencyAssistanceHelper.java
+++ b/src/com/android/phone/EmergencyAssistanceHelper.java
@@ -17,7 +17,6 @@
 package com.android.phone;
 
 import android.app.role.RoleManager;
-import android.app.role.RoleManagerCallback;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -50,11 +49,13 @@
      * used for team food.
      */
     public static String getIntentAction(Context context) {
-        if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SAFETY_HUB)) {
-            String action = context.getResources().getString(R.string.config_emergency_app_intent);
-            if (!action.isEmpty()) {
-                return action;
+        String action = context.getResources().getString(R.string.config_emergency_app_intent);
+        if (!action.isEmpty()) {
+            // TODO: remove feature flag and this temporary intent once Emergency app was replaced.
+            if (!FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SAFETY_HUB)) {
+                return "com.android.emergency.action.EMERGENCY_ASSISTANCE";
             }
+            return action;
         }
 
         return TelephonyManager.ACTION_EMERGENCY_ASSISTANCE;
@@ -143,12 +144,8 @@
         try {
             context.getSystemService(RoleManager.class).addRoleHolderAsUser(
                     RoleManager.ROLE_EMERGENCY, pkgName, 0, Process.myUserHandle(),
-                    AsyncTask.THREAD_POOL_EXECUTOR, new RoleManagerCallback() {
-                        @Override
-                        public void onSuccess() {
-                        }
-                        @Override
-                        public void onFailure() {
+                    AsyncTask.THREAD_POOL_EXECUTOR, successful -> {
+                        if (!successful) {
                             Log.e(TAG, "Failed to set emergency default app.");
                         }
                     });
diff --git a/src/com/android/phone/EmergencyDialer.java b/src/com/android/phone/EmergencyDialer.java
index cff27b1..38eb40d 100644
--- a/src/com/android/phone/EmergencyDialer.java
+++ b/src/com/android/phone/EmergencyDialer.java
@@ -851,7 +851,7 @@
             phoneToMakeCall = mShortcutViewConfig.getPhoneInfo();
         } else {
             TelephonyManager tm = getSystemService(TelephonyManager.class);
-            isEmergencyNumber = tm.isCurrentEmergencyNumber(mLastNumber);
+            isEmergencyNumber = tm.isEmergencyNumber(mLastNumber);
         }
 
         if (isEmergencyNumber) {
diff --git a/src/com/android/phone/ImsUtil.java b/src/com/android/phone/ImsUtil.java
index ee23e6f..18fc534 100644
--- a/src/com/android/phone/ImsUtil.java
+++ b/src/com/android/phone/ImsUtil.java
@@ -113,7 +113,7 @@
     public static boolean shouldPromoteWfc(Context context, int phoneId) {
         CarrierConfigManager cfgManager = (CarrierConfigManager) context
                 .getSystemService(Context.CARRIER_CONFIG_SERVICE);
-        if (cfgManager == null || cfgManager.getConfigForSubId(getSubId(phoneId))
+        if (cfgManager == null || !cfgManager.getConfigForSubId(getSubId(phoneId))
                 .getBoolean(CarrierConfigManager.KEY_CARRIER_PROMOTE_WFC_ON_CALL_FAIL_BOOL)) {
             return false;
         }
diff --git a/src/com/android/phone/NetworkSelectSetting.java b/src/com/android/phone/NetworkSelectSetting.java
index d9731be..45478d9 100644
--- a/src/com/android/phone/NetworkSelectSetting.java
+++ b/src/com/android/phone/NetworkSelectSetting.java
@@ -31,7 +31,7 @@
 import android.telephony.CarrierConfigManager;
 import android.telephony.CellIdentity;
 import android.telephony.CellInfo;
-import android.telephony.NetworkRegistrationState;
+import android.telephony.NetworkRegistrationInfo;
 import android.telephony.ServiceState;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
@@ -382,7 +382,7 @@
      * Config the connected network operator preference when the page was created. When user get
      * into this page, the device might or might not have data connection.
      *   - If the device has data:
-     *     1. use {@code ServiceState#getNetworkRegistrationStates()} to get the currently
+     *     1. use {@code ServiceState#getNetworkRegistrationInfoList()} to get the currently
      *        registered cellIdentity, wrap it into a CellInfo;
      *     2. set the signal strength level as strong;
      *     3. use {@link TelephonyManager#getNetworkOperatorName()} to get the title of the
@@ -396,10 +396,11 @@
         if (mTelephonyManager.getDataState() == mTelephonyManager.DATA_CONNECTED) {
             // Try to get the network registration states
             ServiceState ss = mTelephonyManager.getServiceState();
-            List<NetworkRegistrationState> networkList =
-                    ss.getNetworkRegistrationStates(AccessNetworkConstants.TransportType.WWAN);
+            List<NetworkRegistrationInfo> networkList =
+                    ss.getNetworkRegistrationInfoListForTransportType(
+                            AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
             if (networkList == null || networkList.size() == 0) {
-                loge("getNetworkRegistrationStates return null");
+                loge("getNetworkRegistrationInfoList return null");
                 // Remove the connected network operators category
                 removeConnectedNetworkOperatorPreference();
                 return;
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 3d82e74..94cd0f6 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -43,8 +43,8 @@
 import android.preference.PreferenceManager;
 import android.provider.Settings;
 import android.telecom.TelecomManager;
+import android.telephony.AnomalyReporter;
 import android.telephony.CarrierConfigManager;
-import android.telephony.DebugEventReporter;
 import android.telephony.ServiceState;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
@@ -284,8 +284,8 @@
         //   getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
 
         if (mCM == null) {
-            // Initialize DebugEventReporter early so that it can be used
-            DebugEventReporter.initialize(this);
+            // Initialize AnomalyReporter early so that it can be used
+            AnomalyReporter.initialize(this);
 
             // Inject telephony component factory if configured using other jars.
             XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 797a5bd..6f02ae2 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -24,6 +24,7 @@
 import android.app.AppOpsManager;
 import android.app.PendingIntent;
 import android.content.ComponentName;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
@@ -53,6 +54,7 @@
 import android.os.WorkSource;
 import android.preference.PreferenceManager;
 import android.provider.Settings;
+import android.provider.Telephony;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
@@ -138,6 +140,7 @@
 import com.android.internal.telephony.TelephonyPermissions;
 import com.android.internal.telephony.emergency.EmergencyNumberTracker;
 import com.android.internal.telephony.euicc.EuiccConnector;
+import com.android.internal.telephony.ims.ImsResolver;
 import com.android.internal.telephony.metrics.TelephonyMetrics;
 import com.android.internal.telephony.uicc.IccIoResult;
 import com.android.internal.telephony.uicc.IccUtils;
@@ -1299,8 +1302,16 @@
     }
 
     private Phone getPhoneFromRequest(MainThreadRequest request) {
-        return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
-                ? getDefaultPhone() : getPhone(request.subId);
+        if (request.phone != null) {
+            return request.phone;
+        } else {
+            return getPhoneFromSubId(request.subId);
+        }
+    }
+
+    private Phone getPhoneFromSubId(int subId) {
+        return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
+                ? getDefaultPhone() : getPhone(subId);
     }
 
     private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
@@ -3656,13 +3667,43 @@
         return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
     }
 
+    private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
+        int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
+        if (phoneId == -1) {
+            throw new IllegalArgumentException("Given slot index: " + slotIndex
+                    + " does not correspond to an active phone");
+        }
+        return PhoneFactory.getPhone(phoneId);
+    }
+
     @Override
     public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
             int subId, String callingPackage, String aid, int p2) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "iccOpenLogicalChannel");
         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
+        if (DBG) {
+            log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
+        }
+        return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
+                p2);
+    }
 
+
+    @Override
+    public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
+            int slotIndex, String callingPackage, String aid, int p2) {
+        enforceModifyPermission();
+        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
+        if (DBG) {
+            log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
+        }
+        return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
+                callingPackage, aid, p2);
+    }
+
+    private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
+            String callingPackage, String aid, int p2) {
         final long identity = Binder.clearCallingIdentity();
         try {
             if (TextUtils.equals(ISDR_AID, aid)) {
@@ -3677,12 +3718,10 @@
                 }
             }
 
-            if (DBG) {
-                log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
-            }
             IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
-                    CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
-            if (DBG) log("iccOpenLogicalChannel: " + response);
+                    CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
+                    null /* workSource */);
+            if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
             return response;
         } finally {
             Binder.restoreCallingIdentity(identity);
@@ -3693,15 +3732,27 @@
     public boolean iccCloseLogicalChannel(int subId, int channel) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "iccCloseLogicalChannel");
+        if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
+        return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
+    }
 
+    @Override
+    public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
+        enforceModifyPermission();
+        if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
+        return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
+                channel);
+    }
+
+    private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
         final long identity = Binder.clearCallingIdentity();
         try {
-            if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
             if (channel < 0) {
                 return false;
             }
-            Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
-            if (DBG) log("iccCloseLogicalChannel: " + success);
+            Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
+                    null /* workSource */);
+            if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
             return success;
         } finally {
             Binder.restoreCallingIdentity(identity);
@@ -3713,22 +3764,41 @@
             int command, int p1, int p2, int p3, String data) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "iccTransmitApduLogicalChannel");
+        if (DBG) {
+            log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
+                    + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
+                    + p3 + " data=" + data);
+        }
+        return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
+                command, p1, p2, p3, data);
+    }
 
+    @Override
+    public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
+            int command, int p1, int p2, int p3, String data) {
+        enforceModifyPermission();
+        if (DBG) {
+            log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
+                    + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
+                    + p3 + " data=" + data);
+        }
+        return iccTransmitApduLogicalChannelWithPermission(
+                getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
+                data);
+    }
+
+    private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
+            int command, int p1, int p2, int p3, String data) {
         final long identity = Binder.clearCallingIdentity();
         try {
-            if (DBG) {
-                log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
-                        + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
-                        + p3 + " data=" + data);
-            }
-
             if (channel < 0) {
                 return "";
             }
 
             IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
-                    new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
-            if (DBG) log("iccTransmitApduLogicalChannel: " + response);
+                    new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
+                    null /* workSource */);
+            if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
 
             // Append the returned status code to the end of the response payload.
             String s = Integer.toHexString(
@@ -3748,7 +3818,33 @@
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "iccTransmitApduBasicChannel");
         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
+        if (DBG) {
+            log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
+                    + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
+        }
+        return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
+                cla, command, p1, p2, p3, data);
+    }
 
+    @Override
+    public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
+            int command, int p1, int p2, int p3, String data) {
+        enforceModifyPermission();
+        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
+        if (DBG) {
+            log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
+                    + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
+                    + " data=" + data);
+        }
+
+        return iccTransmitApduBasicChannelWithPermission(
+                getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
+                p2, p3, data);
+    }
+
+    // open APDU basic channel assuming the caller has sufficient permissions
+    private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
+            int cla, int command, int p1, int p2, int p3, String data) {
         final long identity = Binder.clearCallingIdentity();
         try {
             if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
@@ -3764,14 +3860,10 @@
                 }
             }
 
-            if (DBG) {
-                log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
-                        + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
-            }
-
             IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
-                    new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
-            if (DBG) log("iccTransmitApduBasicChannel: " + response);
+                    new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
+                    null /* workSource */);
+            if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
 
             // Append the returned status code to the end of the response payload.
             String s = Integer.toHexString(
@@ -4027,7 +4119,12 @@
 
         final long identity = Binder.clearCallingIdentity();
         try {
-            PhoneFactory.getImsResolver().enableIms(slotId);
+            ImsResolver resolver = PhoneFactory.getImsResolver();
+            if (resolver == null) {
+                // may happen if the device does not support IMS.
+                return;
+            }
+            resolver.enableIms(slotId);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
@@ -4042,7 +4139,12 @@
 
         final long identity = Binder.clearCallingIdentity();
         try {
-            PhoneFactory.getImsResolver().disableIms(slotId);
+            ImsResolver resolver = PhoneFactory.getImsResolver();
+            if (resolver == null) {
+                // may happen if the device does not support IMS.
+                return;
+            }
+            resolver.disableIms(slotId);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
@@ -4059,7 +4161,12 @@
 
         final long identity = Binder.clearCallingIdentity();
         try {
-            return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
+            ImsResolver resolver = PhoneFactory.getImsResolver();
+            if (resolver == null) {
+                // may happen if the device does not support IMS.
+                return null;
+            }
+            return resolver.getMmTelFeatureAndListen(slotId, callback);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
@@ -4076,7 +4183,12 @@
 
         final long identity = Binder.clearCallingIdentity();
         try {
-            return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
+            ImsResolver resolver = PhoneFactory.getImsResolver();
+            if (resolver == null) {
+                // may happen if the device does not support IMS.
+                return null;
+            }
+            return resolver.getRcsFeatureAndListen(slotId, callback);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
@@ -4084,14 +4196,19 @@
 
     /**
      * Returns the {@link IImsRegistration} structure associated with the slotId and feature
-     * specified.
+     * specified or null if IMS is not supported on the slot specified.
      */
     public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
         enforceModifyPermission();
 
         final long identity = Binder.clearCallingIdentity();
         try {
-            return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
+            ImsResolver resolver = PhoneFactory.getImsResolver();
+            if (resolver == null) {
+                // may happen if the device does not support IMS.
+                return null;
+            }
+            return resolver.getImsRegistration(slotId, feature);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
@@ -4099,14 +4216,19 @@
 
     /**
      * Returns the {@link IImsConfig} structure associated with the slotId and feature
-     * specified.
+     * specified or null if IMS is not supported on the slot specified.
      */
     public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
         enforceModifyPermission();
 
         final long identity = Binder.clearCallingIdentity();
         try {
-            return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
+            ImsResolver resolver = PhoneFactory.getImsResolver();
+            if (resolver == null) {
+                // may happen if the device does not support IMS.
+                return null;
+            }
+            return resolver.getImsConfig(slotId, feature);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
@@ -4131,8 +4253,13 @@
 
         final long identity = Binder.clearCallingIdentity();
         try {
-            return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
-                    isCarrierImsService, packageName);
+            ImsResolver resolver = PhoneFactory.getImsResolver();
+            if (resolver == null) {
+                // may happen if the device does not support IMS.
+                return false;
+            }
+            return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
+                    packageName);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
@@ -4154,8 +4281,12 @@
 
         final long identity = Binder.clearCallingIdentity();
         try {
-            return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
-                    isCarrierImsService);
+            ImsResolver resolver = PhoneFactory.getImsResolver();
+            if (resolver == null) {
+                // may happen if the device does not support IMS.
+                return "";
+            }
+            return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
@@ -5182,11 +5313,22 @@
                 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
                 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
             }
+            // There has been issues when Sms raw table somehow stores orphan
+            // fragments. They lead to garbled message when new fragments come
+            // in and combined with those stale ones. In case this happens again,
+            // user can reset all network settings which will clean up this table.
+            cleanUpSmsRawTable(getDefaultPhone().getContext());
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
     }
 
+    private void cleanUpSmsRawTable(Context context) {
+        ContentResolver resolver = context.getContentResolver();
+        Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
+        resolver.delete(uri, null, null);
+    }
+
     @Override
     public String getSimLocaleForSubscriber(int subId) {
         enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
@@ -6449,10 +6591,10 @@
     }
 
     @Override
-    public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
+    public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
             String callingPackage) {
         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
-                mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
+                mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
             throw new SecurityException("Requires READ_PHONE_STATE permission.");
         }
         final long identity = Binder.clearCallingIdentity();
@@ -6473,12 +6615,12 @@
     }
 
     @Override
-    public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
+    public boolean isEmergencyNumber(String number, boolean exactMatch) {
         final Phone defaultPhone = getDefaultPhone();
         if (!exactMatch) {
             TelephonyPermissions
                     .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
-                            mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
+                            mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
         }
         final long identity = Binder.clearCallingIdentity();
         try {
diff --git a/src/com/android/phone/PhoneSearchIndexablesProvider.java b/src/com/android/phone/PhoneSearchIndexablesProvider.java
deleted file mode 100644
index 339602d..0000000
--- a/src/com/android/phone/PhoneSearchIndexablesProvider.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-package com.android.phone;
-
-import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
-import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME;
-import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID;
-import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION;
-import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS;
-import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE;
-import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RANK;
-import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID;
-import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
-import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS;
-import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS;
-
-import android.content.Context;
-import android.database.Cursor;
-import android.database.MatrixCursor;
-import android.os.Binder;
-import android.os.UserManager;
-import android.provider.SearchIndexableResource;
-import android.provider.SearchIndexablesContract.RawData;
-import android.provider.SearchIndexablesProvider;
-import android.telephony.euicc.EuiccManager;
-
-import androidx.annotation.VisibleForTesting;
-
-public class PhoneSearchIndexablesProvider extends SearchIndexablesProvider {
-    private static final String TAG = "PhoneSearchIndexablesProvider";
-
-    private static final String ESIM_LIST_PROFILE_KEY = "esim_list_profile";
-    private static final String ENHANCED_4G_LTE_KEY = "enhanced_4g_lte";
-    private static final String WIFI_CALLING_KEY = "wifi_calling_key";
-
-    private UserManager mUserManager;
-
-    private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[] {
-            new SearchIndexableResource(1, R.xml.network_setting_fragment,
-                    MobileNetworkSettings.class.getName(),
-                    R.mipmap.ic_launcher_phone),
-    };
-
-    @Override
-    public boolean onCreate() {
-        mUserManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
-        return true;
-    }
-
-    @Override
-    public Cursor queryXmlResources(String[] projection) {
-        MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS);
-        final int count = INDEXABLE_RES.length;
-        for (int n = 0; n < count; n++) {
-            Object[] ref = new Object[7];
-            ref[COLUMN_INDEX_XML_RES_RANK] = INDEXABLE_RES[n].rank;
-            ref[COLUMN_INDEX_XML_RES_RESID] = INDEXABLE_RES[n].xmlResId;
-            ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = null;
-            ref[COLUMN_INDEX_XML_RES_ICON_RESID] = INDEXABLE_RES[n].iconResId;
-            ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = "android.intent.action.MAIN";
-            ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = "com.android.phone";
-            ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS] = INDEXABLE_RES[n].className;
-            cursor.addRow(ref);
-        }
-        return cursor;
-    }
-
-    @Override
-    public Cursor queryRawData(String[] projection) {
-        MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS);
-        Context context = getContext();
-        String title = context.getString(R.string.carrier_settings_euicc);
-        cursor.newRow()
-                .add(RawData.COLUMN_RANK, 0)
-                .add(RawData.COLUMN_TITLE, title)
-                .add(
-                        RawData.COLUMN_KEYWORDS,
-                        context.getString(R.string.keywords_carrier_settings_euicc))
-                .add(RawData.COLUMN_SCREEN_TITLE, title)
-                .add(RawData.COLUMN_KEY, "esim_list_profile")
-                .add(
-                        RawData.COLUMN_INTENT_ACTION,
-                        EuiccManager.ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS)
-                .add(
-                        RawData.COLUMN_INTENT_TARGET_PACKAGE,
-                        context.getPackageName());
-        return cursor;
-    }
-
-    @Override
-    public Cursor queryNonIndexableKeys(String[] projection) {
-        final long uidToken = Binder.clearCallingIdentity();
-        try {
-            MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS);
-
-            if (!mUserManager.isAdminUser()) {
-                final String[] values = new String[]{"preferred_network_mode_key",
-                        "button_roaming_key", "cdma_lte_data_service_key", "enhanced_4g_lte",
-                        "button_apn_key", "button_carrier_sel_key", "carrier_settings_key",
-                        "cdma_system_select_key", "esim_list_profile", "mobile_data_enable",
-                        "data_usage_summary", "wifi_calling_key", "video_calling_key"};
-                for (String nik : values) {
-                    cursor.addRow(createNonIndexableRow(nik));
-                }
-            } else {
-                if (isEuiccSettingsHidden()) {
-                    cursor.addRow(createNonIndexableRow(ESIM_LIST_PROFILE_KEY));
-                }
-
-                if (isEnhanced4gLteHidden()) {
-                    cursor.addRow(createNonIndexableRow(ENHANCED_4G_LTE_KEY));
-                }
-
-                if (isWifiCallingHidden()) {
-                    cursor.addRow(createNonIndexableRow(WIFI_CALLING_KEY));
-                }
-            }
-
-            // enabled_networks button and preferred_network_mode button share the same title
-            // "Preferred network type"and are mutual exclusive. Thus we remove one from search
-            // result to avoid duplicate search result.
-            // TODO: b/63381516 all hidden buttons should dynamically be removed from search result.
-            cursor.addRow(createNonIndexableRow("enabled_networks_key" /* key */));
-            cursor.addRow(createNonIndexableRow("carrier_settings_euicc_key" /* key */));
-            cursor.addRow(createNonIndexableRow("advanced_options" /* key */));
-            return cursor;
-        } finally {
-            Binder.restoreCallingIdentity(uidToken);
-        }
-    }
-
-    @VisibleForTesting boolean isEuiccSettingsHidden() {
-        return !MobileNetworkSettings.showEuiccSettings(getContext());
-    }
-
-    @VisibleForTesting boolean isEnhanced4gLteHidden() {
-        return MobileNetworkSettings.hideEnhanced4gLteSettings(getContext());
-    }
-
-    boolean isWifiCallingHidden() {
-        return !MobileNetworkSettings.isWifiCallingEnabled(getContext());
-    }
-
-    private Object[] createNonIndexableRow(String key) {
-        final Object[] ref = new Object[NON_INDEXABLES_KEYS_COLUMNS.length];
-        ref[COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE] = key;
-        return ref;
-    }
-}
diff --git a/src/com/android/phone/ShortcutViewUtils.java b/src/com/android/phone/ShortcutViewUtils.java
index 7e24c7a..8e5ab42 100644
--- a/src/com/android/phone/ShortcutViewUtils.java
+++ b/src/com/android/phone/ShortcutViewUtils.java
@@ -303,7 +303,7 @@
     private static Map<Integer, List<EmergencyNumber>> getPromotedEmergencyNumberLists(
             @NonNull TelephonyManager telephonyManager) {
         Map<Integer, List<EmergencyNumber>> allLists =
-                telephonyManager.getCurrentEmergencyNumberList();
+                telephonyManager.getEmergencyNumberList();
         if (allLists == null || allLists.isEmpty()) {
             Log.w(LOG_TAG, "Unable to retrieve emergency number lists!");
             return new ArrayMap<>();
diff --git a/src/com/android/phone/TelephonyShellCommand.java b/src/com/android/phone/TelephonyShellCommand.java
index 956e0e2..a59c9c4 100644
--- a/src/com/android/phone/TelephonyShellCommand.java
+++ b/src/com/android/phone/TelephonyShellCommand.java
@@ -163,10 +163,10 @@
         pw.println("    Add(-a), Clear(-c), Print (-p) or Remove(-r) the emergency number list in"
                 + " the test mode");
         pw.println("      -a <emergency number address>: add an emergency number address for the"
-                + " test mode, only allows '0'-'9', '*', or '#'.");
+                + " test mode, only allows '0'-'9', '*', '#' or '+'.");
         pw.println("      -c: clear the emergency number list in the test mode.");
         pw.println("      -r <emergency number address>: remove an existing emergency number"
-                + " address added by the test mode, only allows '0'-'9', '*', or '#'.");
+                + " address added by the test mode, only allows '0'-'9', '*', '#' or '+'.");
         pw.println("      -p: get the full emergency number list in the test mode.");
     }
 
@@ -208,7 +208,7 @@
                 String emergencyNumberCmd = getNextArgRequired();
                 if (emergencyNumberCmd == null
                         || !EmergencyNumber.validateEmergencyNumberAddress(emergencyNumberCmd)) {
-                    errPw.println("An emergency number (only allow '0'-'9', '*', or '#') needs"
+                    errPw.println("An emergency number (only allow '0'-'9', '*', '#' or '+') needs"
                             + " to be specified after -a in the command ");
                     return -1;
                 }
@@ -243,7 +243,7 @@
                 String emergencyNumberCmd = getNextArgRequired();
                 if (emergencyNumberCmd == null
                         || !EmergencyNumber.validateEmergencyNumberAddress(emergencyNumberCmd)) {
-                    errPw.println("An emergency number (only allow '0'-'9', '*', or '#') needs"
+                    errPw.println("An emergency number (only allow '0'-'9', '*', '#' or '+') needs"
                             + " to be specified after -r in the command ");
                     return -1;
                 }
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index 969e6ac..21685a3 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -21,6 +21,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.database.ContentObserver;
 import android.graphics.Bitmap;
@@ -115,7 +116,10 @@
             }
 
             try {
-                mMmTelManager = ImsMmTelManager.createForSubscriptionId(getSubId());
+                if (mPhone.getContext().getPackageManager().hasSystemFeature(
+                        PackageManager.FEATURE_TELEPHONY_IMS)) {
+                    mMmTelManager = ImsMmTelManager.createForSubscriptionId(getSubId());
+                }
             } catch (IllegalArgumentException e) {
                 Log.i(this, "Not registering MmTel capabilities listener because the subid '"
                         + getSubId() + "' is invalid: " + e.getMessage());
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 7c09320..632e9ac 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -932,12 +932,6 @@
             try {
                 Phone phone = mOriginalConnection.getCall().getPhone();
 
-                // New behavior for IMS -- don't use the clunky switchHoldingAndActive logic.
-                if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_IMS) {
-                    ImsPhone imsPhone = (ImsPhone) phone;
-                    imsPhone.holdActiveCall();
-                    return;
-                }
                 Call ringingCall = phone.getRingingCall();
 
                 // Although the method says switchHoldingAndActive, it eventually calls a RIL method
@@ -951,6 +945,12 @@
                 // could "fake" hold by silencing the audio and microphone streams for this call
                 // instead of actually putting it on hold.
                 if (ringingCall.getState() != Call.State.WAITING) {
+                    // New behavior for IMS -- don't use the clunky switchHoldingAndActive logic.
+                    if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_IMS) {
+                        ImsPhone imsPhone = (ImsPhone) phone;
+                        imsPhone.holdActiveCall();
+                        return;
+                    }
                     phone.switchHoldingAndActive();
                 }
 
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index 6d7c1f0..2cd62ff 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -239,12 +239,12 @@
 
         @Override
         public boolean isCurrentEmergencyNumber(String number) {
-            return mTelephonyManager.isCurrentEmergencyNumber(number);
+            return mTelephonyManager.isEmergencyNumber(number);
         }
 
         @Override
         public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList() {
-            return mTelephonyManager.getCurrentEmergencyNumberList();
+            return mTelephonyManager.getEmergencyNumberList();
         }
     }
 
diff --git a/testapps/ImsTestService/src/com/android/phone/testapps/imstestapp/ImsRegistrationActivity.java b/testapps/ImsTestService/src/com/android/phone/testapps/imstestapp/ImsRegistrationActivity.java
index 50be698..4ee9355 100644
--- a/testapps/ImsTestService/src/com/android/phone/testapps/imstestapp/ImsRegistrationActivity.java
+++ b/testapps/ImsTestService/src/com/android/phone/testapps/imstestapp/ImsRegistrationActivity.java
@@ -151,8 +151,8 @@
     private static final Map<Integer, String> REG_TECH_STRING = new ArrayMap<>(2);
     static {
         REG_TECH_STRING.put(ImsRegistrationImplBase.REGISTRATION_TECH_NONE, "NONE");
-        REG_TECH_STRING.put(AccessNetworkConstants.TransportType.WWAN, "WWAN");
-        REG_TECH_STRING.put(AccessNetworkConstants.TransportType.WLAN, "WLAN");
+        REG_TECH_STRING.put(AccessNetworkConstants.TRANSPORT_TYPE_WWAN, "WWAN");
+        REG_TECH_STRING.put(AccessNetworkConstants.TRANSPORT_TYPE_WLAN, "WLAN");
     }
 
 
diff --git a/tests/Android.mk b/tests/Android.mk
index 2fde21a..44bf176 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -31,9 +31,9 @@
 LOCAL_INSTRUMENTATION_FOR := TeleService
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
-        android-support-test \
+        androidx.test.rules \
         mockito-target-minus-junit4 \
-        espresso-core \
+        androidx.test.espresso.core \
         truth-prebuilt
 
 LOCAL_COMPATIBILITY_SUITE := device-tests
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 0aa5be2..d434650 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -53,14 +53,14 @@
     <!--
         To run all tests:
             adb shell am instrument -w
-                com.android.phone.tests/android.support.test.runner.AndroidJUnitRunner
+                com.android.phone.tests/androidx.test.runner.AndroidJUnitRunner
 
         To run a single class test:
             adb shell am instrument -e class com.android.phone.unit.FooUnitTest
-                -w com.android.phone.tests/android.support.test.runner.AndroidJUnitRunner
+                -w com.android.phone.tests/androidx.test.runner.AndroidJUnitRunner
 
     -->
-    <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
         android:targetPackage="com.android.phone"
         android:label="Phone application tests." />
 </manifest>
diff --git a/tests/AndroidTest.xml b/tests/AndroidTest.xml
index cf757b4..4188ee2 100644
--- a/tests/AndroidTest.xml
+++ b/tests/AndroidTest.xml
@@ -24,7 +24,7 @@
     <option name="test-tag" value="TeleServiceTests" />
     <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
         <option name="package" value="com.android.phone.tests" />
-        <option name="runner" value="android.support.test.runner.AndroidJUnitRunner" />
+        <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
         <option name="hidden-api-checks" value="false"/>
     </test>
 </configuration>
diff --git a/tests/src/com/android/TelephonyTestBase.java b/tests/src/com/android/TelephonyTestBase.java
index 7b7bef2..d30ae6b 100644
--- a/tests/src/com/android/TelephonyTestBase.java
+++ b/tests/src/com/android/TelephonyTestBase.java
@@ -19,9 +19,10 @@
 import android.content.Context;
 import android.os.Handler;
 import android.os.Looper;
-import android.support.test.InstrumentationRegistry;
 import android.util.Log;
 
+import androidx.test.InstrumentationRegistry;
+
 import org.mockito.MockitoAnnotations;
 
 import java.util.concurrent.CountDownLatch;
diff --git a/tests/src/com/android/phone/CallFeaturesSettingTest.java b/tests/src/com/android/phone/CallFeaturesSettingTest.java
index 816642a..78d68e3 100644
--- a/tests/src/com/android/phone/CallFeaturesSettingTest.java
+++ b/tests/src/com/android/phone/CallFeaturesSettingTest.java
@@ -15,16 +15,16 @@
  */
 package com.android.phone;
 
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
 
 import static org.mockito.Mockito.when;
 
-import android.support.test.filters.FlakyTest;
-import android.support.test.rule.ActivityTestRule;
+import androidx.test.filters.FlakyTest;
+import androidx.test.rule.ActivityTestRule;
 
 import com.android.internal.telephony.IccCard;
 import com.android.internal.telephony.Phone;
diff --git a/tests/src/com/android/phone/CdmaOptionsTest.java b/tests/src/com/android/phone/CdmaOptionsTest.java
index c0c6317..1a1516c 100644
--- a/tests/src/com/android/phone/CdmaOptionsTest.java
+++ b/tests/src/com/android/phone/CdmaOptionsTest.java
@@ -18,9 +18,10 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import android.os.PersistableBundle;
-import android.support.test.runner.AndroidJUnit4;
 import android.telephony.CarrierConfigManager;
 
+import androidx.test.runner.AndroidJUnit4;
+
 import com.android.internal.telephony.PhoneConstants;
 
 import org.junit.Test;
diff --git a/tests/src/com/android/phone/PhoneSearchIndexablesProviderTest.java b/tests/src/com/android/phone/PhoneSearchIndexablesProviderTest.java
deleted file mode 100644
index 34e3937..0000000
--- a/tests/src/com/android/phone/PhoneSearchIndexablesProviderTest.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-package com.android.phone;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.when;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.ProviderInfo;
-import android.content.res.Resources;
-import android.database.Cursor;
-import android.os.UserManager;
-import android.provider.SearchIndexablesContract;
-import android.provider.Settings;
-import android.support.test.runner.AndroidJUnit4;
-import android.telephony.euicc.EuiccManager;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-/** Unit tests for {@link PhoneSearchIndexablesProvider}. */
-@RunWith(AndroidJUnit4.class)
-public final class PhoneSearchIndexablesProviderTest {
-    private PhoneSearchIndexablesTestProvider mProvider;
-    @Mock private ApplicationInfo mApplicationInfo;
-    @Mock private Context mContext;
-    @Mock private Resources mResources;
-    @Mock private UserManager mUserManager;
-    @Mock private EuiccManager mEuiccManager;
-    @Mock private ContentResolver mCr;
-
-    private class PhoneSearchIndexablesTestProvider extends PhoneSearchIndexablesProvider {
-        private boolean mIsEuiccSettingsHidden = false;
-        private boolean mIsEnhanced4gLteHidden = false;
-        private boolean mIsWifiCallingHidden = false;
-
-        @Override boolean isEuiccSettingsHidden() {
-            return mIsEuiccSettingsHidden;
-        }
-
-        @Override boolean isEnhanced4gLteHidden() {
-            return mIsEnhanced4gLteHidden;
-        }
-
-        @Override boolean isWifiCallingHidden() {
-            return mIsWifiCallingHidden;
-        }
-
-        public void setIsEuiccSettingsHidden(boolean isEuiccSettingsHidden) {
-            mIsEuiccSettingsHidden = isEuiccSettingsHidden;
-        }
-
-        public void setIsEnhanced4gLteHidden(boolean isEnhanced4gLteHidden) {
-            mIsEnhanced4gLteHidden = isEnhanced4gLteHidden;
-        }
-
-        public void setIsWifiCallingHidden(boolean isWifiCallingHidden) {
-            mIsWifiCallingHidden = isWifiCallingHidden;
-        }
-    }
-
-    @Before
-    public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        when(mResources.getString(com.android.phone.R.string.carrier_settings_euicc))
-                .thenReturn("");
-        when(mResources.getString(com.android.phone.R.string.keywords_carrier_settings_euicc))
-                .thenReturn("");
-
-        when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
-        when(mContext.getSystemService(Context.EUICC_SERVICE)).thenReturn(mEuiccManager);
-        when(mContext.getResources()).thenReturn(mResources);
-        when(mContext.getApplicationInfo()).thenReturn(mApplicationInfo);
-        when(mContext.getPackageName()).thenReturn("PhoneSearchIndexablesProviderTest");
-        when(mContext.getContentResolver()).thenReturn(mCr);
-        when(mCr.getPackageName()).thenReturn("com.android.phone");
-
-        final ProviderInfo providerInfo = new ProviderInfo();
-        providerInfo.authority = Settings.AUTHORITY;
-        providerInfo.exported = true;
-        providerInfo.grantUriPermissions = true;
-        providerInfo.readPermission = android.Manifest.permission.READ_SEARCH_INDEXABLES;
-        mProvider = new PhoneSearchIndexablesTestProvider();
-        mProvider.attachInfo(mContext, providerInfo);
-    }
-
-    @Test
-    public void testQueryRawData() {
-        when(mUserManager.isAdminUser()).thenReturn(true);
-        when(mEuiccManager.isEnabled()).thenReturn(true);
-        Settings.Global.putInt(mCr, Settings.Global.EUICC_PROVISIONED, 1);
-        Settings.Global.getInt(mCr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
-
-        Cursor cursor = mProvider.queryRawData(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS);
-        assertThat(cursor.getColumnNames()).isEqualTo(
-                SearchIndexablesContract.INDEXABLES_RAW_COLUMNS);
-        assertThat(cursor.getCount()).isEqualTo(1);
-        cursor.moveToNext();
-        assertThat(cursor.getString(SearchIndexablesContract.COLUMN_INDEX_RAW_KEY))
-                .isEqualTo("esim_list_profile");
-    }
-
-    @Test
-    public void testQueryNonIndexableKeys() {
-        mProvider.setIsEnhanced4gLteHidden(false /* isEnhanced4gLteHidden */);
-        mProvider.setIsEuiccSettingsHidden(false /* isEuiccSettingsHiden */);
-        when(mUserManager.isAdminUser()).thenReturn(false);
-        Cursor cursor;
-        cursor = mProvider.queryNonIndexableKeys(
-                SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS);
-        assertThat(cursor.getColumnNames()).isEqualTo(
-                SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS);
-        assertThat(cursor.getCount()).isEqualTo(16);
-
-        when(mUserManager.isAdminUser()).thenReturn(true);
-        cursor = mProvider
-                .queryNonIndexableKeys(SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS);
-        assertThat(cursor.getCount()).isEqualTo(3);
-
-        mProvider.setIsEuiccSettingsHidden(true /* isEuiccSettingsHidden */);
-        cursor = mProvider
-                .queryNonIndexableKeys(SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS);
-        assertThat(cursor.getCount()).isEqualTo(4);
-
-        mProvider.setIsEnhanced4gLteHidden(true /* isEnhanced4gLteHidden */);
-        cursor = mProvider
-                .queryNonIndexableKeys(SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS);
-        assertThat(cursor.getCount()).isEqualTo(5);
-
-        mProvider.setIsWifiCallingHidden(true /* isWifiCallingHidden */);
-        cursor = mProvider
-                .queryNonIndexableKeys(SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS);
-        assertThat(cursor.getCount()).isEqualTo(6);
-    }
-}
diff --git a/tests/src/com/android/phone/RoamingDialogFragmentTest.java b/tests/src/com/android/phone/RoamingDialogFragmentTest.java
index 62633e0..a9b32ea 100644
--- a/tests/src/com/android/phone/RoamingDialogFragmentTest.java
+++ b/tests/src/com/android/phone/RoamingDialogFragmentTest.java
@@ -15,31 +15,34 @@
  */
 package com.android.phone;
 
+import static androidx.test.espresso.Espresso.onData;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.action.ViewActions.click;
+import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
+import static androidx.test.espresso.matcher.ViewMatchers.isChecked;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
+
+import static com.google.common.truth.Truth.assertThat;
+
 import android.app.Activity;
 import android.content.pm.ActivityInfo;
 import android.provider.Settings.Global;
 import android.provider.Settings.SettingNotFoundException;
-import android.support.test.espresso.matcher.PreferenceMatchers;
-import android.support.test.rule.ActivityTestRule;
-import android.support.test.filters.FlakyTest;
-import com.google.common.truth.Truth;
+
+import androidx.test.espresso.matcher.PreferenceMatchers;
+import androidx.test.filters.FlakyTest;
+import androidx.test.rule.ActivityTestRule;
+
 import junit.framework.AssertionFailedError;
+
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
-import static android.support.test.espresso.Espresso.onData;
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.action.ViewActions.click;
-import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
-import static android.support.test.espresso.matcher.ViewMatchers.isChecked;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
-import static com.google.common.truth.Truth.assertThat;
-
 /**
  * Espresso tests to check some properties of the dialog that appears when a user
  * tries to turn on data roaming.
diff --git a/tests/src/com/android/phone/ecc/EccDataTest.java b/tests/src/com/android/phone/ecc/EccDataTest.java
index 8f4abc5..911d3c5 100644
--- a/tests/src/com/android/phone/ecc/EccDataTest.java
+++ b/tests/src/com/android/phone/ecc/EccDataTest.java
@@ -18,8 +18,8 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
+import androidx.test.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
 
 import com.android.TelephonyTestBase;
 import com.android.phone.ecc.nano.ProtobufEccData;
diff --git a/tests/src/com/android/phone/euicc/EuiccUiDispatcherActivityTest.java b/tests/src/com/android/phone/euicc/EuiccUiDispatcherActivityTest.java
index 57df097..b8f2ec1 100644
--- a/tests/src/com/android/phone/euicc/EuiccUiDispatcherActivityTest.java
+++ b/tests/src/com/android/phone/euicc/EuiccUiDispatcherActivityTest.java
@@ -23,10 +23,11 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
 import android.telephony.euicc.EuiccManager;
 
+import androidx.test.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
diff --git a/tests/src/com/android/phone/tests/CallForwardInfoTest.java b/tests/src/com/android/phone/tests/CallForwardInfoTest.java
index acf5955..064a06e 100644
--- a/tests/src/com/android/phone/tests/CallForwardInfoTest.java
+++ b/tests/src/com/android/phone/tests/CallForwardInfoTest.java
@@ -16,17 +16,18 @@
 
 package com.android.phone.tests;
 
-import android.support.test.runner.AndroidJUnit4;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
 import android.telephony.PhoneNumberUtils;
 
+import androidx.test.runner.AndroidJUnit4;
+
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import java.util.Locale;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
 /**
  * Tests Related to CallForwardInfoTest
  */
diff --git a/tests/src/com/android/services/telephony/ConferenceParticipantConnectionTest.java b/tests/src/com/android/services/telephony/ConferenceParticipantConnectionTest.java
index 73fe0af..f404945 100644
--- a/tests/src/com/android/services/telephony/ConferenceParticipantConnectionTest.java
+++ b/tests/src/com/android/services/telephony/ConferenceParticipantConnectionTest.java
@@ -16,17 +16,17 @@
 
 package com.android.services.telephony;
 
+import static com.android.services.telephony.ConferenceParticipantConnection.getParticipantAddress;
+
+import static org.junit.Assert.assertEquals;
+
 import android.net.Uri;
-import android.support.test.runner.AndroidJUnit4;
-import android.telecom.Conference;
-import android.telecom.ConferenceParticipant;
+
+import androidx.test.runner.AndroidJUnit4;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import static com.android.services.telephony.ConferenceParticipantConnection.getParticipantAddress;
-import static org.junit.Assert.assertEquals;
-
 /**
  * Tests proper parsing of conference event package participant addresses.
  */
diff --git a/tests/src/com/android/services/telephony/HoldTrackerTest.java b/tests/src/com/android/services/telephony/HoldTrackerTest.java
index 0db10e4..772a1a2 100644
--- a/tests/src/com/android/services/telephony/HoldTrackerTest.java
+++ b/tests/src/com/android/services/telephony/HoldTrackerTest.java
@@ -20,9 +20,10 @@
 import static junit.framework.Assert.assertTrue;
 
 import android.content.ComponentName;
-import android.support.test.runner.AndroidJUnit4;
 import android.telecom.PhoneAccountHandle;
 
+import androidx.test.runner.AndroidJUnit4;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
diff --git a/tests/src/com/android/services/telephony/RadioOnStateListenerTest.java b/tests/src/com/android/services/telephony/RadioOnStateListenerTest.java
index d9de2e8..8b46bf0 100644
--- a/tests/src/com/android/services/telephony/RadioOnStateListenerTest.java
+++ b/tests/src/com/android/services/telephony/RadioOnStateListenerTest.java
@@ -28,10 +28,11 @@
 
 import android.os.AsyncResult;
 import android.os.Handler;
-import android.support.test.runner.AndroidJUnit4;
 import android.telephony.ServiceState;
 import android.test.suitebuilder.annotation.SmallTest;
 
+import androidx.test.runner.AndroidJUnit4;
+
 import com.android.TelephonyTestBase;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
diff --git a/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java b/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
index a18adb8..1329a77 100644
--- a/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
+++ b/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
@@ -32,8 +32,6 @@
 import android.os.AsyncResult;
 import android.os.Bundle;
 import android.os.Handler;
-import android.support.test.filters.FlakyTest;
-import android.support.test.runner.AndroidJUnit4;
 import android.telecom.DisconnectCause;
 import android.telecom.TelecomManager;
 import android.telephony.RadioAccessFamily;
@@ -41,6 +39,9 @@
 import android.telephony.TelephonyManager;
 import android.test.suitebuilder.annotation.SmallTest;
 
+import androidx.test.filters.FlakyTest;
+import androidx.test.runner.AndroidJUnit4;
+
 import com.android.TelephonyTestBase;
 import com.android.internal.telephony.CallStateException;
 import com.android.internal.telephony.Connection;