Merge "Updates to NLS notif type filtering" into sc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9dd44ef..5abba1f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5316,7 +5316,7 @@
     <string name="daltonizer_mode_tritanomaly_summary">Blue-yellow</string>
 
     <!-- Title for the accessibility preference and switch of the Reduce Brightness feature. [CHAR LIMIT=NONE] -->
-    <string name="reduce_bright_colors_preference_title">Reduce Brightness</string>
+    <string name="reduce_bright_colors_preference_title">Reduce brightness</string>
     <!-- Summary for the accessibility preference to configure Reduce Brightness feature. [CHAR LIMIT=NONE] -->
     <string name="reduce_bright_colors_preference_summary" product="default">Make screen darker than your phone\u2019s minimum brightness</string>
     <!-- Summary for the accessibility preference to configure Reduce Brightness feature. [CHAR LIMIT=NONE] -->
@@ -12106,7 +12106,7 @@
     <string name="carrier_settings_euicc">Carrier</string>
     <!-- Mobile network settings screen, a string showing the version of carrier settings for this
          subscription [CHAR LIMIT=NONE] -->
-    <string name="carrier_settings_version">Settings version</string>
+    <string name="carrier_settings_version">Carrier settings version</string>
 
     <!-- Mobile network settings screen, name for call settings category [CHAR LIMIT=NONE] -->
     <string name="call_category">Calling</string>
diff --git a/res/xml/network_provider_calls_sms.xml b/res/xml/network_provider_calls_sms.xml
index 0b390b5..2281f48 100644
--- a/res/xml/network_provider_calls_sms.xml
+++ b/res/xml/network_provider_calls_sms.xml
@@ -51,12 +51,4 @@
         settings:controller="com.android.settings.network.telephony.NetworkProviderBackupCallingPreferenceController"
         settings:allowDividerAbove="true"
         />
-
-    <com.android.settingslib.widget.FooterPreference
-        android:key="provider_model_calls_sms_footer"
-        android:title="@string/calls_sms_footnote"
-        android:selectable="false"
-        settings:allowDividerAbove="true"
-        settings:searchable="false"
-        settings:controller="com.android.settings.network.telephony.NetworkProviderWfcFooterPreferenceController"/>
 </PreferenceScreen>
diff --git a/src/com/android/settings/AllInOneTetherSettings.java b/src/com/android/settings/AllInOneTetherSettings.java
index 34d723f..d41c07b 100644
--- a/src/com/android/settings/AllInOneTetherSettings.java
+++ b/src/com/android/settings/AllInOneTetherSettings.java
@@ -16,8 +16,8 @@
 
 package com.android.settings;
 
-import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED;
 import static android.net.ConnectivityManager.TETHERING_WIFI;
+import static android.net.TetheringManager.ACTION_TETHER_STATE_CHANGED;
 import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
 
 import android.app.settings.SettingsEnums;
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 48dd218..6d98f36 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -167,8 +167,8 @@
         mEm = (EthernetManager) getSystemService(Context.ETHERNET_SERVICE);
         mTm = (TetheringManager) getSystemService(Context.TETHERING_SERVICE);
 
-        mUsbRegexs = mCm.getTetherableUsbRegexs();
-        mBluetoothRegexs = mCm.getTetherableBluetoothRegexs();
+        mUsbRegexs = mTm.getTetherableUsbRegexs();
+        mBluetoothRegexs = mTm.getTetherableBluetoothRegexs();
         mEthernetRegex = getContext().getResources().getString(
                 com.android.internal.R.string.config_ethernet_iface_regex);
 
@@ -251,14 +251,14 @@
         public void onReceive(Context content, Intent intent) {
             String action = intent.getAction();
             // TODO: stop using ACTION_TETHER_STATE_CHANGED and use mTetheringEventCallback instead.
-            if (action.equals(ConnectivityManager.ACTION_TETHER_STATE_CHANGED)) {
+            if (action.equals(TetheringManager.ACTION_TETHER_STATE_CHANGED)) {
                 // TODO - this should understand the interface types
                 ArrayList<String> available = intent.getStringArrayListExtra(
-                        ConnectivityManager.EXTRA_AVAILABLE_TETHER);
+                        TetheringManager.EXTRA_AVAILABLE_TETHER);
                 ArrayList<String> active = intent.getStringArrayListExtra(
-                        ConnectivityManager.EXTRA_ACTIVE_TETHER);
+                        TetheringManager.EXTRA_ACTIVE_TETHER);
                 ArrayList<String> errored = intent.getStringArrayListExtra(
-                        ConnectivityManager.EXTRA_ERRORED_TETHER);
+                        TetheringManager.EXTRA_ERRORED_TETHER);
                 updateState(available.toArray(new String[available.size()]),
                         active.toArray(new String[active.size()]),
                         errored.toArray(new String[errored.size()]));
@@ -345,7 +345,7 @@
         final Activity activity = getActivity();
 
         mTetherChangeReceiver = new TetherChangeReceiver();
-        IntentFilter filter = new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
+        IntentFilter filter = new IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED);
         final Intent intent = activity.registerReceiver(mTetherChangeReceiver, filter);
 
         filter = new IntentFilter();
@@ -367,11 +367,10 @@
     }
 
     private void updateState() {
-        final ConnectivityManager cm =
-                (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
-        final String[] available = cm.getTetherableIfaces();
-        final String[] tethered = cm.getTetheredIfaces();
-        final String[] errored = cm.getTetheringErroredIfaces();
+        final TetheringManager tm = getContext().getSystemService(TetheringManager.class);
+        final String[] available = tm.getTetherableIfaces();
+        final String[] tethered = tm.getTetheredIfaces();
+        final String[] errored = tm.getTetheringErroredIfaces();
         updateState(available, tethered, errored);
     }
 
@@ -391,7 +390,7 @@
             for (String regex : mUsbRegexs) {
                 if (s.matches(regex)) {
                     if (usbError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
-                        usbError = mCm.getLastTetherError(s);
+                        usbError = mTm.getLastTetherError(s);
                     }
                 }
             }
@@ -558,8 +557,8 @@
                 @Override
                 public List<String> getNonIndexableKeys(Context context) {
                     final List<String> keys = super.getNonIndexableKeys(context);
-                    final ConnectivityManager cm =
-                            context.getSystemService(ConnectivityManager.class);
+                    final TetheringManager tm =
+                            context.getSystemService(TetheringManager.class);
 
                     if (!TetherUtil.isTetherAvailable(context)) {
                         keys.add(KEY_TETHER_PREFS_SCREEN);
@@ -567,13 +566,13 @@
                     }
 
                     final boolean usbAvailable =
-                            cm.getTetherableUsbRegexs().length != 0;
+                            tm.getTetherableUsbRegexs().length != 0;
                     if (!usbAvailable || Utils.isMonkeyRunning()) {
                         keys.add(KEY_USB_TETHER_SETTINGS);
                     }
 
                     final boolean bluetoothAvailable =
-                            cm.getTetherableBluetoothRegexs().length != 0;
+                            tm.getTetherableBluetoothRegexs().length != 0;
                     if (!bluetoothAvailable) {
                         keys.add(KEY_ENABLE_BLUETOOTH_TETHERING);
                     }
diff --git a/src/com/android/settings/UserCredentialsSettings.java b/src/com/android/settings/UserCredentialsSettings.java
index d322819..5f72ca5 100644
--- a/src/com/android/settings/UserCredentialsSettings.java
+++ b/src/com/android/settings/UserCredentialsSettings.java
@@ -34,9 +34,9 @@
 import android.security.IKeyChainService;
 import android.security.KeyChain;
 import android.security.KeyChain.KeyChainConnection;
-import android.security.KeyStore;
-import android.security.keymaster.KeyCharacteristics;
-import android.security.keymaster.KeymasterDefs;
+import android.security.keystore.AndroidKeyStoreProvider;
+import android.security.keystore.KeyProperties;
+import android.security.keystore2.AndroidKeyStoreLoadStoreParameter;
 import android.util.Log;
 import android.util.SparseArray;
 import android.view.LayoutInflater;
@@ -55,13 +55,21 @@
 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 import com.android.settingslib.RestrictedLockUtilsInternal;
 
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
 import java.security.UnrecoverableKeyException;
+import java.security.cert.Certificate;
 import java.util.ArrayList;
 import java.util.EnumSet;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
+import javax.crypto.SecretKey;
+
 public class UserCredentialsSettings extends SettingsPreferenceFragment
         implements View.OnClickListener {
     private static final String TAG = "UserCredentialsSettings";
@@ -201,21 +209,19 @@
             }
 
             private void deleteWifiCredential(final Credential credential) {
-                final KeyStore keyStore = KeyStore.getInstance();
-                final EnumSet<Credential.Type> storedTypes = credential.getStoredTypes();
-
-                // Remove all Wi-Fi credentials
-                if (storedTypes.contains(Credential.Type.USER_KEY)) {
-                    keyStore.delete(Credentials.USER_PRIVATE_KEY + credential.getAlias(),
-                            Process.WIFI_UID);
-                }
-                if (storedTypes.contains(Credential.Type.USER_CERTIFICATE)) {
-                    keyStore.delete(Credentials.USER_CERTIFICATE + credential.getAlias(),
-                            Process.WIFI_UID);
-                }
-                if (storedTypes.contains(Credential.Type.CA_CERTIFICATE)) {
-                    keyStore.delete(Credentials.CA_CERTIFICATE + credential.getAlias(),
-                            Process.WIFI_UID);
+                try {
+                    KeyStore keyStore = null;
+                    if (AndroidKeyStoreProvider.isKeystore2Enabled()) {
+                        keyStore = KeyStore.getInstance("AndroidKeyStore");
+                        keyStore.load(
+                                new AndroidKeyStoreLoadStoreParameter(
+                                        KeyProperties.NAMESPACE_WIFI));
+                    } else {
+                        keyStore = AndroidKeyStoreProvider.getKeyStoreForUid(Process.WIFI_UID);
+                    }
+                    keyStore.deleteEntry(credential.getAlias());
+                } catch (Exception e) {
+                    throw new RuntimeException("Failed to delete keys from keystore.");
                 }
             }
 
@@ -266,73 +272,103 @@
          */
         @Override
         protected List<Credential> doInBackground(Void... params) {
-            final KeyStore keyStore = KeyStore.getInstance();
-
             // Certificates can be installed into SYSTEM_UID or WIFI_UID through CertInstaller.
             final int myUserId = UserHandle.myUserId();
             final int systemUid = UserHandle.getUid(myUserId, Process.SYSTEM_UID);
             final int wifiUid = UserHandle.getUid(myUserId, Process.WIFI_UID);
 
-            List<Credential> credentials = new ArrayList<>();
-            credentials.addAll(getCredentialsForUid(keyStore, systemUid).values());
-            credentials.addAll(getCredentialsForUid(keyStore, wifiUid).values());
-            return credentials;
-        }
+            try {
+                KeyStore processKeystore = KeyStore.getInstance("AndroidKeyStore");
+                processKeystore.load(null);
+                KeyStore wifiKeystore = null;
+                if (myUserId == 0) {
+                    // Only the primary user may see wifi configurations.
+                    if (AndroidKeyStoreProvider.isKeystore2Enabled()) {
+                        wifiKeystore = KeyStore.getInstance("AndroidKeyStore");
+                        wifiKeystore.load(new AndroidKeyStoreLoadStoreParameter(
+                                KeyProperties.NAMESPACE_WIFI));
+                    } else {
+                        wifiKeystore = AndroidKeyStoreProvider.getKeyStoreForUid(Process.WIFI_UID);
+                    }
+                }
 
-        private boolean isAsymmetric(KeyStore keyStore, String alias, int uid)
-            throws UnrecoverableKeyException {
-                KeyCharacteristics keyCharacteristics = new KeyCharacteristics();
-                int errorCode = keyStore.getKeyCharacteristics(alias, null, null, uid,
-                        keyCharacteristics);
-                if (errorCode != KeyStore.NO_ERROR) {
-                    throw (UnrecoverableKeyException)
-                            new UnrecoverableKeyException("Failed to obtain information about key")
-                                    .initCause(KeyStore.getKeyStoreException(errorCode));
+                List<Credential> credentials = new ArrayList<>();
+                credentials.addAll(getCredentialsForUid(processKeystore, systemUid).values());
+                if (wifiKeystore != null) {
+                    credentials.addAll(getCredentialsForUid(wifiKeystore, wifiUid).values());
                 }
-                Integer keymasterAlgorithm = keyCharacteristics.getEnum(
-                        KeymasterDefs.KM_TAG_ALGORITHM);
-                if (keymasterAlgorithm == null) {
-                    throw new UnrecoverableKeyException("Key algorithm unknown");
-                }
-                return keymasterAlgorithm == KeymasterDefs.KM_ALGORITHM_RSA ||
-                        keymasterAlgorithm == KeymasterDefs.KM_ALGORITHM_EC;
+                return credentials;
+            } catch (Exception e) {
+                throw new RuntimeException("Failed to load credentials from Keystore.", e);
+            }
         }
 
         private SortedMap<String, Credential> getCredentialsForUid(KeyStore keyStore, int uid) {
-            final SortedMap<String, Credential> aliasMap = new TreeMap<>();
-            for (final Credential.Type type : Credential.Type.values()) {
-                for (final String prefix : type.prefix) {
-                    for (final String alias : keyStore.list(prefix, uid)) {
-                        if (UserHandle.getAppId(uid) == Process.SYSTEM_UID) {
+            try {
+                final SortedMap<String, Credential> aliasMap = new TreeMap<>();
+                boolean isSystem = UserHandle.getAppId(uid) == Process.SYSTEM_UID;
+                Enumeration<String> aliases = keyStore.aliases();
+                while (aliases.hasMoreElements()) {
+                    String alias = aliases.nextElement();
+                    Credential c = new Credential(alias, uid);
+                    Key key = null;
+                    try {
+                        key = keyStore.getKey(alias, null);
+                    } catch (NoSuchAlgorithmException | UnrecoverableKeyException e) {
+                        Log.e(TAG, "Error tying to retrieve key: " + alias, e);
+                        continue;
+                    }
+                    if (key != null) {
+                        // So we have a key
+                        if (key instanceof SecretKey) {
+                            // We don't display any symmetric key entries.
+                            continue;
+                        }
+                        if (isSystem) {
                             // Do not show work profile keys in user credentials
                             if (alias.startsWith(LockPatternUtils.PROFILE_KEY_NAME_ENCRYPT) ||
                                     alias.startsWith(LockPatternUtils.PROFILE_KEY_NAME_DECRYPT)) {
                                 continue;
                             }
                             // Do not show synthetic password keys in user credential
+                            // We should never reach this point because the synthetic password key
+                            // is symmetric.
                             if (alias.startsWith(LockPatternUtils.SYNTHETIC_PASSWORD_KEY_PREFIX)) {
                                 continue;
                             }
                         }
-                        try {
-                            if (type == Credential.Type.USER_KEY &&
-                                    !isAsymmetric(keyStore, prefix + alias, uid)) {
-                                continue;
+                        // At this point we have determined that we have an asymmetric key.
+                        // so we have at least a USER_KEY and USER_CERTIFICATE.
+                        c.storedTypes.add(Credential.Type.USER_KEY);
+
+                        Certificate[] certs =  keyStore.getCertificateChain(alias);
+                        if (certs != null) {
+                            c.storedTypes.add(Credential.Type.USER_CERTIFICATE);
+                            if (certs.length > 1) {
+                                c.storedTypes.add(Credential.Type.CA_CERTIFICATE);
                             }
-                        } catch (UnrecoverableKeyException e) {
-                            Log.e(TAG, "Unable to determine algorithm of key: " + prefix + alias, e);
-                            continue;
                         }
-                        Credential c = aliasMap.get(alias);
-                        if (c == null) {
-                            c = new Credential(alias, uid);
-                            aliasMap.put(alias, c);
+                    } else {
+                        // So there is no key but we have an alias. This must mean that we have
+                        // some certificate.
+                        if (keyStore.isCertificateEntry(alias)) {
+                            c.storedTypes.add(Credential.Type.CA_CERTIFICATE);
+                        } else {
+                            // This is a weired inconsistent case that should not exist.
+                            // Pure trusted certificate entries should be stored in CA_CERTIFICATE,
+                            // but if isCErtificateEntry returns null this means that only the
+                            // USER_CERTIFICATE is populated which should never be the case without
+                            // a private key. It can still be retrieved with
+                            // keystore.getCertificate().
+                            c.storedTypes.add(Credential.Type.USER_CERTIFICATE);
                         }
-                        c.storedTypes.add(type);
                     }
+                    aliasMap.put(alias, c);
                 }
+                return aliasMap;
+            } catch (KeyStoreException e) {
+                throw new RuntimeException("Failed to load credential from Android Keystore.", e);
             }
-            return aliasMap;
         }
 
         @Override
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
index dcaeffe..aacf41f 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
@@ -297,6 +297,7 @@
             preference.setEnabled(false);
             preference.setKey(KEY_BOTTOM_PREFERENCE);
             preference.setOrder(ORDINAL);
+            preference.setSelectable(false);
             mProfilesContainer.addPreference(preference);
         }
     }
diff --git a/src/com/android/settings/datausage/OWNERS b/src/com/android/settings/datausage/OWNERS
index 49449ec..1ec66b3 100644
--- a/src/com/android/settings/datausage/OWNERS
+++ b/src/com/android/settings/datausage/OWNERS
@@ -1,5 +1,6 @@
 # Default reviewers for this and subdirectories.
 andychou@google.com
-goldmanj@google.com
 bonianchen@google.com
+goldmanj@google.com
+songferngwang@google.com
 wengsu@google.com
diff --git a/src/com/android/settings/deviceinfo/OWNERS b/src/com/android/settings/deviceinfo/OWNERS
index e6569f4..68cee36 100644
--- a/src/com/android/settings/deviceinfo/OWNERS
+++ b/src/com/android/settings/deviceinfo/OWNERS
@@ -1,7 +1,8 @@
 # Default reviewers for this and subdirectories.
+allenwtsu@google.com
 andychou@google.com
 bonianchen@google.com
 goldmanj@google.com
-allenwtsu@google.com
+songferngwang@google.com
 
 # Emergency approvers in case the above are not available
diff --git a/src/com/android/settings/network/BluetoothTetherPreferenceController.java b/src/com/android/settings/network/BluetoothTetherPreferenceController.java
index ab507da..96d39e3 100644
--- a/src/com/android/settings/network/BluetoothTetherPreferenceController.java
+++ b/src/com/android/settings/network/BluetoothTetherPreferenceController.java
@@ -70,7 +70,7 @@
 
     @Override
     public boolean shouldShow() {
-        final String[] bluetoothRegexs = mCm.getTetherableBluetoothRegexs();
+        final String[] bluetoothRegexs = mTm.getTetherableBluetoothRegexs();
         return bluetoothRegexs != null && bluetoothRegexs.length != 0;
     }
 
diff --git a/src/com/android/settings/network/EthernetTetherPreferenceController.java b/src/com/android/settings/network/EthernetTetherPreferenceController.java
index 19c410d..06cd6a7 100644
--- a/src/com/android/settings/network/EthernetTetherPreferenceController.java
+++ b/src/com/android/settings/network/EthernetTetherPreferenceController.java
@@ -65,7 +65,7 @@
 
     @Override
     public boolean shouldEnable() {
-        String[] available = mCm.getTetherableIfaces();
+        String[] available = mTm.getTetherableIfaces();
         for (String s : available) {
             if (s.matches(mEthernetRegex)) {
                 return true;
diff --git a/src/com/android/settings/network/NetworkProviderCallsSmsFragment.java b/src/com/android/settings/network/NetworkProviderCallsSmsFragment.java
index a811978..fcb8345 100644
--- a/src/com/android/settings/network/NetworkProviderCallsSmsFragment.java
+++ b/src/com/android/settings/network/NetworkProviderCallsSmsFragment.java
@@ -27,7 +27,6 @@
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.network.telephony.CallsDefaultSubscriptionController;
 import com.android.settings.network.telephony.NetworkProviderBackupCallingPreferenceController;
-import com.android.settings.network.telephony.NetworkProviderWfcFooterPreferenceController;
 import com.android.settings.network.telephony.NetworkProviderWifiCallingPreferenceController;
 import com.android.settings.network.telephony.SmsDefaultSubscriptionController;
 import com.android.settings.search.BaseSearchIndexProvider;
@@ -46,8 +45,6 @@
     @VisibleForTesting
     static final String KEY_PREFERENCE_CATEGORY_BACKUP_CALLING =
             "provider_model_backup_calling_category";
-    static final String KEY_PREFERENCE_CATEGORY_WFC_FOOTER =
-            "provider_model_calls_sms_footer";
 
     @VisibleForTesting
     static final String KEY_PREFERENCE_CALLS= "provider_model_calls_preference";
@@ -74,12 +71,6 @@
         backupCallingPrefCtrl.init(getSettingsLifecycle());
         controllers.add(backupCallingPrefCtrl);
 
-        NetworkProviderWfcFooterPreferenceController wfcFooterPreferenceController =
-                new NetworkProviderWfcFooterPreferenceController(context,
-                        KEY_PREFERENCE_CATEGORY_WFC_FOOTER);
-        wfcFooterPreferenceController.init(getSettingsLifecycle());
-        controllers.add(wfcFooterPreferenceController);
-
         return controllers;
     }
 
diff --git a/src/com/android/settings/network/TetherBasePreferenceController.java b/src/com/android/settings/network/TetherBasePreferenceController.java
index 1919770..822aa72 100644
--- a/src/com/android/settings/network/TetherBasePreferenceController.java
+++ b/src/com/android/settings/network/TetherBasePreferenceController.java
@@ -17,7 +17,7 @@
 package com.android.settings.network;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 
 import androidx.lifecycle.Lifecycle;
 import androidx.lifecycle.LifecycleObserver;
@@ -33,7 +33,7 @@
         TetherEnabler.OnTetherStateUpdateListener {
 
     private static final String TAG = "TetherBasePreferenceController";
-    final ConnectivityManager mCm;
+    final TetheringManager mTm;
     private final DataSaverBackend mDataSaverBackend;
 
     private TetherEnabler mTetherEnabler;
@@ -43,7 +43,7 @@
 
     TetherBasePreferenceController(Context context, String preferenceKey) {
         super(context, preferenceKey);
-        mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+        mTm = context.getSystemService(TetheringManager.class);
         mDataSaverBackend = new DataSaverBackend(context);
         mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
     }
diff --git a/src/com/android/settings/network/TetherEnabler.java b/src/com/android/settings/network/TetherEnabler.java
index 6ab4cb2..ef031f6 100644
--- a/src/com/android/settings/network/TetherEnabler.java
+++ b/src/com/android/settings/network/TetherEnabler.java
@@ -147,7 +147,7 @@
         mSwitchWidgetController.setListener(this);
         mSwitchWidgetController.startListening();
         final IntentFilter filter = new IntentFilter(
-                ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
+                TetheringManager.ACTION_TETHER_STATE_CHANGED);
         filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
         filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
         mContext.registerReceiver(mTetherChangeReceiver, filter);
@@ -222,7 +222,7 @@
     int getTetheringState(@Nullable String[] tethered) {
         int tetherState = TETHERING_OFF;
         if (tethered == null) {
-            tethered = mConnectivityManager.getTetheredIfaces();
+            tethered = mTetheringManager.getTetheredIfaces();
         }
 
         if (mWifiManager.isWifiApEnabled()) {
@@ -239,7 +239,7 @@
             }
         }
 
-        String[] usbRegexs = mConnectivityManager.getTetherableUsbRegexs();
+        String[] usbRegexs = mTetheringManager.getTetherableUsbRegexs();
         for (String s : tethered) {
             for (String regex : usbRegexs) {
                 if (s.matches(regex)) {
diff --git a/src/com/android/settings/network/TetherPreferenceController.java b/src/com/android/settings/network/TetherPreferenceController.java
index 2409544..8df0ac1 100644
--- a/src/com/android/settings/network/TetherPreferenceController.java
+++ b/src/com/android/settings/network/TetherPreferenceController.java
@@ -28,6 +28,7 @@
 import android.content.IntentFilter;
 import android.database.ContentObserver;
 import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
@@ -62,6 +63,7 @@
     private final AtomicReference<BluetoothPan> mBluetoothPan;
     private final ConnectivityManager mConnectivityManager;
     private final BluetoothAdapter mBluetoothAdapter;
+    private final TetheringManager mTetheringManager;
     @VisibleForTesting
     final BluetoothProfile.ServiceListener mBtProfileServiceListener =
             new android.bluetooth.BluetoothProfile.ServiceListener() {
@@ -86,6 +88,7 @@
         mBluetoothPan = new AtomicReference<>();
         mConnectivityManager = null;
         mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+        mTetheringManager = null;
     }
 
     public TetherPreferenceController(Context context, Lifecycle lifecycle) {
@@ -95,6 +98,7 @@
         mConnectivityManager =
                 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+        mTetheringManager = context.getSystemService(TetheringManager.class);
         if (lifecycle != null) {
             lifecycle.addObserver(this);
         }
@@ -144,7 +148,7 @@
             mTetherReceiver = new TetherBroadcastReceiver();
         }
         mContext.registerReceiver(
-                mTetherReceiver, new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
+                mTetherReceiver, new IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED));
         mContext.getContentResolver()
                 .registerContentObserver(mAirplaneModeObserver.uri, false, mAirplaneModeObserver);
     }
@@ -178,9 +182,9 @@
             // Preference is not ready yet.
             return;
         }
-        String[] allTethered = mConnectivityManager.getTetheredIfaces();
-        String[] wifiTetherRegex = mConnectivityManager.getTetherableWifiRegexs();
-        String[] bluetoothRegex = mConnectivityManager.getTetherableBluetoothRegexs();
+        String[] allTethered = mTetheringManager.getTetheredIfaces();
+        String[] wifiTetherRegex = mTetheringManager.getTetherableWifiRegexs();
+        String[] bluetoothRegex = mTetheringManager.getTetherableBluetoothRegexs();
 
         boolean hotSpotOn = false;
         boolean tetherOn = false;
@@ -211,7 +215,7 @@
                 && bluetoothRegex != null && bluetoothRegex.length > 0
                 && mBluetoothAdapter != null
                 && mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
-            // Check bluetooth state. It's not included in mConnectivityManager.getTetheredIfaces.
+            // Check bluetooth state. It's not included in mTetheringManager.getTetheredIfaces.
             final BluetoothPan pan = mBluetoothPan.get();
             tetherOn = pan != null && pan.isTetheringOn();
         }
diff --git a/src/com/android/settings/network/UsbTetherPreferenceController.java b/src/com/android/settings/network/UsbTetherPreferenceController.java
index 7cf1ddf..7a5cc21 100644
--- a/src/com/android/settings/network/UsbTetherPreferenceController.java
+++ b/src/com/android/settings/network/UsbTetherPreferenceController.java
@@ -68,7 +68,7 @@
 
     @Override
     public boolean shouldShow() {
-        String[] usbRegexs = mCm.getTetherableUsbRegexs();
+        String[] usbRegexs = mTm.getTetherableUsbRegexs();
         return  usbRegexs != null && usbRegexs.length != 0 && !Utils.isMonkeyRunning();
     }
 
diff --git a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
index 38e831b..783f78f 100644
--- a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
+++ b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
@@ -68,7 +68,7 @@
 
     @Override
     public boolean shouldShow() {
-        final String[] wifiRegexs = mCm.getTetherableWifiRegexs();
+        final String[] wifiRegexs = mTm.getTetherableWifiRegexs();
         return wifiRegexs != null && wifiRegexs.length != 0 && !Utils.isMonkeyRunning()
                 && getTetheringStateOfOtherInterfaces() != TetherEnabler.TETHERING_OFF;
     }
diff --git a/src/com/android/settings/network/telephony/NetworkProviderWfcFooterPreferenceController.java b/src/com/android/settings/network/telephony/NetworkProviderWfcFooterPreferenceController.java
deleted file mode 100644
index 166094d..0000000
--- a/src/com/android/settings/network/telephony/NetworkProviderWfcFooterPreferenceController.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.android.settings.network.telephony;
-
-import android.content.Context;
-import android.content.Intent;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-
-import androidx.preference.Preference;
-
-import com.android.settings.R;
-import com.android.settings.core.BasePreferenceController;
-import com.android.settings.network.SubscriptionUtil;
-import com.android.settings.utils.AnnotationSpan;
-import com.android.settingslib.HelpUtils;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-
-import java.util.List;
-
-public class NetworkProviderWfcFooterPreferenceController extends BasePreferenceController
-        implements LifecycleObserver {
-
-    /**
-     * Constructor.
-     */
-    public NetworkProviderWfcFooterPreferenceController(Context context, String preferenceKey) {
-        super(context, preferenceKey);
-    }
-
-    /**
-     * Initialize the binding with Lifecycle
-     *
-     * @param lifecycle Lifecycle of UI which owns this Preference
-     */
-    public void init(Lifecycle lifecycle) {
-        lifecycle.addObserver(this);
-    }
-
-    @Override
-    public void updateState(Preference preference) {
-        super.updateState(preference);
-
-        if (preference != null) {
-            // This is necessary to ensure that setting the title to the spannable string returned
-            // by getFooterText will be accepted.  Internally, setTitle does an equality check on
-            // the spannable string being set to the text already set on the preference.  That
-            // equality check apparently only takes into account the raw text and not and spannables
-            // that are part of the text.  So we clear the title before applying the spannable
-            // footer to ensure it is accepted.
-            preference.setTitle("");
-            preference.setTitle(getFooterText());
-        }
-    }
-
-    private CharSequence getFooterText() {
-        final Intent helpIntent = HelpUtils.getHelpIntent(mContext,
-                mContext.getString(R.string.help_uri_wifi_calling),
-                mContext.getClass().getName());
-        final AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan.LinkInfo(mContext,
-                "url", helpIntent);
-
-        return AnnotationSpan.linkify(mContext.getText(R.string.calls_sms_footnote), linkInfo);
-    }
-
-    @Override
-    public int getAvailabilityStatus() {
-        final SubscriptionManager subscriptionManager =
-                mContext.getSystemService(SubscriptionManager.class);
-        final List<SubscriptionInfo> subscriptions = SubscriptionUtil.getActiveSubscriptions(
-                subscriptionManager);
-        if (subscriptions.size() >= 1) {
-            return AVAILABLE;
-        } else {
-            return CONDITIONALLY_UNAVAILABLE;
-        }
-    }
-}
diff --git a/src/com/android/settings/security/CredentialStorage.java b/src/com/android/settings/security/CredentialStorage.java
index 53a1a59..be42850 100644
--- a/src/com/android/settings/security/CredentialStorage.java
+++ b/src/com/android/settings/security/CredentialStorage.java
@@ -64,7 +64,6 @@
 
     private static final int CONFIRM_CLEAR_SYSTEM_CREDENTIAL_REQUEST = 1;
 
-    private final KeyStore mKeyStore = KeyStore.getInstance();
     private LockPatternUtils mUtils;
 
     /**
diff --git a/src/com/android/settings/security/ResetCredentialsPreferenceController.java b/src/com/android/settings/security/ResetCredentialsPreferenceController.java
index 0700b46..48e7f84 100644
--- a/src/com/android/settings/security/ResetCredentialsPreferenceController.java
+++ b/src/com/android/settings/security/ResetCredentialsPreferenceController.java
@@ -18,7 +18,6 @@
 
 import android.content.Context;
 import android.os.UserManager;
-import android.security.KeyStore;
 
 import androidx.preference.PreferenceScreen;
 
@@ -27,6 +26,9 @@
 import com.android.settingslib.core.lifecycle.LifecycleObserver;
 import com.android.settingslib.core.lifecycle.events.OnResume;
 
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+
 public class ResetCredentialsPreferenceController extends RestrictedEncryptionPreferenceController
         implements LifecycleObserver, OnResume {
 
@@ -38,7 +40,13 @@
 
     public ResetCredentialsPreferenceController(Context context, Lifecycle lifecycle) {
         super(context, UserManager.DISALLOW_CONFIG_CREDENTIALS);
-        mKeyStore = KeyStore.getInstance();
+        KeyStore keyStore = null;
+        try {
+            keyStore = KeyStore.getInstance("AndroidKeyStore");
+            keyStore.load(null);
+        } catch (Exception e) {
+        }
+        mKeyStore = keyStore;
         if (lifecycle != null) {
             lifecycle.addObserver(this);
         }
@@ -58,7 +66,15 @@
     @Override
     public void onResume() {
         if (mPreference != null && !mPreference.isDisabledByAdmin()) {
-            mPreference.setEnabled(!mKeyStore.isEmpty());
+            boolean isEnabled = false;
+            try {
+                if (mKeyStore != null) {
+                    isEnabled = mKeyStore.aliases().hasMoreElements();
+                }
+            } catch (KeyStoreException e) {
+                // If access to keystore fails, treat as disabled.
+            }
+            mPreference.setEnabled(isEnabled);
         }
     }
 }
diff --git a/src/com/android/settings/sim/OWNERS b/src/com/android/settings/sim/OWNERS
index e6569f4..68cee36 100644
--- a/src/com/android/settings/sim/OWNERS
+++ b/src/com/android/settings/sim/OWNERS
@@ -1,7 +1,8 @@
 # Default reviewers for this and subdirectories.
+allenwtsu@google.com
 andychou@google.com
 bonianchen@google.com
 goldmanj@google.com
-allenwtsu@google.com
+songferngwang@google.com
 
 # Emergency approvers in case the above are not available
diff --git a/src/com/android/settings/utils/AndroidKeystoreAliasLoader.java b/src/com/android/settings/utils/AndroidKeystoreAliasLoader.java
new file mode 100644
index 0000000..a4af7aa
--- /dev/null
+++ b/src/com/android/settings/utils/AndroidKeystoreAliasLoader.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2021 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.settings.utils;
+
+import android.os.Process;
+import android.security.keystore.AndroidKeyStoreProvider;
+import android.security.keystore.KeyProperties;
+import android.security.keystore2.AndroidKeyStoreLoadStoreParameter;
+import android.util.Log;
+
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.UnrecoverableKeyException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+
+/**
+ * This class provides a portable and unified way to load the content of AndroidKeyStore through
+ * public API.
+ * @hide
+ */
+public class AndroidKeystoreAliasLoader {
+    private static final String TAG = "SettingsKeystoreUtils";
+
+    private final Collection<String> mKeyCertAliases;
+    private final Collection<String> mCaCertAliases;
+    /**
+     * This Constructor loads all aliases of asymmetric keys pairs and certificates in the
+     * AndroidKeyStore within the given namespace.
+     * Viable namespaces are {@link KeyProperties#NAMESPACE_WIFI},
+     * {@link KeyProperties#NAMESPACE_APPLICATION}, or null. The latter two are equivalent in
+     * that they will load the keystore content of the app's own namespace. In case of settings,
+     * this is the namespace of the AID_SYSTEM.
+     *
+     * @param namespace {@link KeyProperties#NAMESPACE_WIFI},
+     *                  {@link KeyProperties#NAMESPACE_APPLICATION}, or null
+     * @hide
+     */
+    public AndroidKeystoreAliasLoader(Integer namespace) {
+        mKeyCertAliases = new ArrayList<>();
+        mCaCertAliases = new ArrayList<>();
+        KeyStore keyStore = null;
+        final Enumeration<String> aliases;
+        try {
+            if (namespace != null && namespace != KeyProperties.NAMESPACE_APPLICATION) {
+                if (AndroidKeyStoreProvider.isKeystore2Enabled()) {
+                    keyStore = KeyStore.getInstance("AndroidKeyStore");
+                    keyStore.load(new AndroidKeyStoreLoadStoreParameter(namespace));
+                } else {
+                    // In the legacy case we pass in the WIFI UID because that is the only
+                    // possible special namespace that existed as of this writing,
+                    // and new namespaces must only be added using the new mechanism.
+                    keyStore = AndroidKeyStoreProvider.getKeyStoreForUid(Process.WIFI_UID);
+                }
+            } else {
+                keyStore = KeyStore.getInstance("AndroidKeyStore");
+                keyStore.load(null);
+            }
+            aliases = keyStore.aliases();
+        } catch (Exception e) {
+            Log.e(TAG, "Failed to open Android Keystore.", e);
+            // Will return empty lists.
+            return;
+        }
+
+
+        while (aliases.hasMoreElements()) {
+            String alias = aliases.nextElement();
+            try {
+                Key key = keyStore.getKey(alias, null);
+                if (key != null) {
+                    if (key instanceof PrivateKey) {
+                        mKeyCertAliases.add(alias);
+                    }
+                } else {
+                    if (keyStore.getCertificate(alias) != null) {
+                        mCaCertAliases.add(alias);
+                    }
+                }
+            } catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException e) {
+                Log.e(TAG, "Failed to load alias: "
+                        + alias + " from Android Keystore. Ignoring.", e);
+            }
+        }
+    }
+
+    /**
+     * Returns the aliases of the key pairs and certificates stored in the Android KeyStore at the
+     * time the constructor was called.
+     * @return Collection of keystore aliases.
+     * @hide
+     */
+    public Collection<String> getKeyCertAliases() {
+        return mKeyCertAliases;
+    }
+
+    /**
+     * Returns the aliases of the trusted certificates stored in the Android KeyStore at the
+     * time the constructor was called.
+     * @return Collection of keystore aliases.
+     * @hide
+     */
+    public Collection<String> getCaCertAliases() {
+        return mCaCertAliases;
+    }
+}
diff --git a/src/com/android/settings/wifi/OWNERS b/src/com/android/settings/wifi/OWNERS
index 5e20fd5..d15cd78 100644
--- a/src/com/android/settings/wifi/OWNERS
+++ b/src/com/android/settings/wifi/OWNERS
@@ -2,4 +2,5 @@
 andychou@google.com
 arcwang@google.com
 goldmanj@google.com
+songferngwang@google.com
 wengsu@google.com
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 3c95e91..b2eca78 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -34,8 +34,7 @@
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.os.IBinder;
-import android.security.Credentials;
-import android.security.KeyStore;
+import android.security.keystore.KeyProperties;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.text.Editable;
@@ -72,6 +71,7 @@
 import com.android.settings.ProxySelector;
 import com.android.settings.R;
 import com.android.settings.network.SubscriptionUtil;
+import com.android.settings.utils.AndroidKeystoreAliasLoader;
 import com.android.settings.wifi.dpp.WifiDppUtils;
 import com.android.settingslib.Utils;
 import com.android.settingslib.utils.ThreadUtils;
@@ -80,7 +80,7 @@
 import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -1031,15 +1031,17 @@
         if (refreshCertificates) {
             loadSims();
 
+            final AndroidKeystoreAliasLoader androidKeystoreAliasLoader =
+                    getAndroidKeystoreAliasLoader();
             loadCertificates(
                     mEapCaCertSpinner,
-                    Credentials.CA_CERTIFICATE,
+                    androidKeystoreAliasLoader.getCaCertAliases(),
                     null /* noCertificateString */,
                     false /* showMultipleCerts */,
                     true /* showUsePreinstalledCertOption */);
             loadCertificates(
                     mEapUserCertSpinner,
-                    Credentials.USER_PRIVATE_KEY,
+                    androidKeystoreAliasLoader.getKeyCertAliases(),
                     mDoNotProvideEapUserCertString,
                     false /* showMultipleCerts */,
                     false /* showUsePreinstalledCertOption */);
@@ -1122,10 +1124,13 @@
                 } else if (caCerts.length == 1) {
                     setSelection(mEapCaCertSpinner, caCerts[0]);
                 } else {
+                    final AndroidKeystoreAliasLoader androidKeystoreAliasLoader =
+                            getAndroidKeystoreAliasLoader();
+
                     // Reload the cert spinner with an extra "multiple certificates added" item.
                     loadCertificates(
                             mEapCaCertSpinner,
-                            Credentials.CA_CERTIFICATE,
+                            androidKeystoreAliasLoader.getCaCertAliases(),
                             null /* noCertificateString */,
                             true /* showMultipleCerts */,
                             true /* showUsePreinstalledCertOption */);
@@ -1444,8 +1449,8 @@
     }
 
     @VisibleForTesting
-    KeyStore getKeyStore() {
-        return KeyStore.getInstance();
+    AndroidKeystoreAliasLoader getAndroidKeystoreAliasLoader() {
+        return new AndroidKeystoreAliasLoader(KeyProperties.NAMESPACE_WIFI);
     }
 
     @VisibleForTesting
@@ -1489,7 +1494,7 @@
     @VisibleForTesting
     void loadCertificates(
             Spinner spinner,
-            String prefix,
+            Collection<String> choices,
             String noCertificateString,
             boolean showMultipleCerts,
             boolean showUsePreinstalledCertOption) {
@@ -1504,14 +1509,8 @@
             certs.add(mUseSystemCertsString);
         }
 
-        String[] certificateNames = null;
-        try {
-            certificateNames = getKeyStore().list(prefix, android.os.Process.WIFI_UID);
-        } catch (Exception e) {
-            Log.e(TAG, "can't get the certificate list from KeyStore");
-        }
-        if (certificateNames != null && certificateNames.length != 0) {
-            certs.addAll(Arrays.stream(certificateNames)
+        if (choices != null && choices.size() != 0) {
+            certs.addAll(choices.stream()
                     .filter(certificateName -> {
                         for (String undesired : UNDESIRED_CERTIFICATES) {
                             if (certificateName.startsWith(undesired)) {
diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java
index 5933d6f..b4e26a6 100644
--- a/src/com/android/settings/wifi/WifiConfigController2.java
+++ b/src/com/android/settings/wifi/WifiConfigController2.java
@@ -32,8 +32,7 @@
 import android.net.wifi.WifiEnterpriseConfig.Phase2;
 import android.net.wifi.WifiManager;
 import android.os.IBinder;
-import android.security.Credentials;
-import android.security.KeyStore;
+import android.security.keystore.KeyProperties;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.text.Editable;
@@ -70,6 +69,7 @@
 import com.android.settings.ProxySelector;
 import com.android.settings.R;
 import com.android.settings.network.SubscriptionUtil;
+import com.android.settings.utils.AndroidKeystoreAliasLoader;
 import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
 import com.android.settings.wifi.dpp.WifiDppUtils;
 import com.android.settingslib.Utils;
@@ -80,7 +80,7 @@
 import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -994,15 +994,17 @@
         if (refreshCertificates) {
             loadSims();
 
+            final AndroidKeystoreAliasLoader androidKeystoreAliasLoader =
+                    getAndroidKeystoreAliasLoader();
             loadCertificates(
                     mEapCaCertSpinner,
-                    Credentials.CA_CERTIFICATE,
+                    androidKeystoreAliasLoader.getCaCertAliases(),
                     null /* noCertificateString */,
                     false /* showMultipleCerts */,
                     true /* showUsePreinstalledCertOption */);
             loadCertificates(
                     mEapUserCertSpinner,
-                    Credentials.USER_PRIVATE_KEY,
+                    androidKeystoreAliasLoader.getKeyCertAliases(),
                     mDoNotProvideEapUserCertString,
                     false /* showMultipleCerts */,
                     false /* showUsePreinstalledCertOption */);
@@ -1087,9 +1089,11 @@
                     setSelection(mEapCaCertSpinner, caCerts[0]);
                 } else {
                     // Reload the cert spinner with an extra "multiple certificates added" item.
+                    final AndroidKeystoreAliasLoader androidKeystoreAliasLoader =
+                            getAndroidKeystoreAliasLoader();
                     loadCertificates(
                             mEapCaCertSpinner,
-                            Credentials.CA_CERTIFICATE,
+                            androidKeystoreAliasLoader.getCaCertAliases(),
                             null /* noCertificateString */,
                             true /* showMultipleCerts */,
                             true /* showUsePreinstalledCertOption */);
@@ -1408,8 +1412,8 @@
     }
 
     @VisibleForTesting
-    KeyStore getKeyStore() {
-        return KeyStore.getInstance();
+    AndroidKeystoreAliasLoader getAndroidKeystoreAliasLoader() {
+        return new AndroidKeystoreAliasLoader(KeyProperties.NAMESPACE_WIFI);
     }
 
     @VisibleForTesting
@@ -1453,7 +1457,7 @@
     @VisibleForTesting
     void loadCertificates(
             Spinner spinner,
-            String prefix,
+            Collection<String> choices,
             String noCertificateString,
             boolean showMultipleCerts,
             boolean showUsePreinstalledCertOption) {
@@ -1468,14 +1472,8 @@
             certs.add(mUseSystemCertsString);
         }
 
-        String[] certificateNames = null;
-        try {
-            certificateNames = getKeyStore().list(prefix, android.os.Process.WIFI_UID);
-        } catch (Exception e) {
-            Log.e(TAG, "can't get the certificate list from KeyStore");
-        }
-        if (certificateNames != null && certificateNames.length != 0) {
-            certs.addAll(Arrays.stream(certificateNames)
+        if (choices != null && choices.size() != 0) {
+            certs.addAll(choices.stream()
                     .filter(certificateName -> {
                         for (String undesired : UNDESIRED_CERTIFICATES) {
                             if (certificateName.startsWith(undesired)) {
diff --git a/src/com/android/settings/wifi/tether/WifiTetherBasePreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherBasePreferenceController.java
index 7ba0216..46da097 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherBasePreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherBasePreferenceController.java
@@ -17,7 +17,7 @@
 package com.android.settings.wifi.tether;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.WifiManager;
 
 import androidx.preference.Preference;
@@ -36,7 +36,7 @@
 
     protected final WifiManager mWifiManager;
     protected final String[] mWifiRegexs;
-    protected final ConnectivityManager mCm;
+    protected final TetheringManager mTm;
     protected final OnTetherConfigUpdateListener mListener;
 
     protected Preference mPreference;
@@ -46,8 +46,8 @@
         super(context);
         mListener = listener;
         mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
-        mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
-        mWifiRegexs = mCm.getTetherableWifiRegexs();
+        mTm = (TetheringManager) context.getSystemService(Context.TETHERING_SERVICE);
+        mWifiRegexs = mTm.getTetherableWifiRegexs();
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
index 5049002..70b6a45 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
@@ -18,7 +18,7 @@
 
 import android.annotation.NonNull;
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiClient;
 import android.net.wifi.WifiManager;
@@ -44,7 +44,7 @@
 
     private static final String WIFI_TETHER_SETTINGS = "wifi_tether";
 
-    private final ConnectivityManager mConnectivityManager;
+    private final TetheringManager mTetheringManager;
     private final String[] mWifiRegexs;
     private final WifiManager mWifiManager;
     private final Lifecycle mLifecycle;
@@ -62,10 +62,9 @@
     WifiTetherPreferenceController(Context context, Lifecycle lifecycle,
             boolean initSoftApManager) {
         super(context);
-        mConnectivityManager =
-                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+        mTetheringManager = context.getSystemService(TetheringManager.class);
         mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
-        mWifiRegexs = mConnectivityManager.getTetherableWifiRegexs();
+        mWifiRegexs = mTetheringManager.getTetherableWifiRegexs();
         mLifecycle = lifecycle;
         if (lifecycle != null) {
             lifecycle.addObserver(this);
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
index 0529b7a..939f077 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
@@ -16,7 +16,7 @@
 
 package com.android.settings.wifi.tether;
 
-import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED;
+import static android.net.TetheringManager.ACTION_TETHER_STATE_CHANGED;
 import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
 
 import android.app.settings.SettingsEnums;
diff --git a/tests/componenttests/Android.bp b/tests/componenttests/Android.bp
index 77932ef..44158c7 100644
--- a/tests/componenttests/Android.bp
+++ b/tests/componenttests/Android.bp
@@ -1,6 +1,15 @@
 //############################################################
 // Settings Component test target.                           #
 //############################################################
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "packages_apps_Settings_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["packages_apps_Settings_license"],
+}
+
 android_test {
     name: "SettingsComponentTests",
     certificate: "platform",
diff --git a/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java b/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
index c9a8c44..cd33663 100644
--- a/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
@@ -33,6 +33,7 @@
 
 import android.content.Context;
 import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -74,6 +75,8 @@
     @Mock
     private ConnectivityManager mConnectivityManager;
     @Mock
+    private TetheringManager mTetheringManager;
+    @Mock
     private UserManager mUserManager;
     @Mock
     private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
@@ -89,10 +92,12 @@
         MockitoAnnotations.initMocks(this);
         doReturn(mConnectivityManager)
                 .when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
-        doReturn(WIFI_REGEXS).when(mConnectivityManager).getTetherableWifiRegexs();
-        doReturn(USB_REGEXS).when(mConnectivityManager).getTetherableUsbRegexs();
-        doReturn(BT_REGEXS).when(mConnectivityManager).getTetherableBluetoothRegexs();
-        doReturn(ETHERNET_REGEXS).when(mConnectivityManager).getTetherableIfaces();
+        doReturn(mTetheringManager)
+                .when(mContext).getSystemService(Context.TETHERING_SERVICE);
+        doReturn(WIFI_REGEXS).when(mTetheringManager).getTetherableWifiRegexs();
+        doReturn(USB_REGEXS).when(mTetheringManager).getTetherableUsbRegexs();
+        doReturn(BT_REGEXS).when(mTetheringManager).getTetherableBluetoothRegexs();
+        doReturn(ETHERNET_REGEXS).when(mTetheringManager).getTetherableIfaces();
         doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
         // Assume the feature is enabled for most test cases.
         FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, true);
diff --git a/tests/robotests/src/com/android/settings/TetherSettingsTest.java b/tests/robotests/src/com/android/settings/TetherSettingsTest.java
index f217e21..0948cfa 100644
--- a/tests/robotests/src/com/android/settings/TetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/TetherSettingsTest.java
@@ -34,6 +34,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.WifiManager;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -66,6 +67,8 @@
     private ConnectivityManager mConnectivityManager;
     @Mock
     private UserManager mUserManager;
+    @Mock
+    private TetheringManager mTetheringManager;
 
     @Before
     public void setUp() {
@@ -76,11 +79,13 @@
                 .when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
         doReturn(mUserManager)
                 .when(mContext).getSystemService(Context.USER_SERVICE);
+        doReturn(mTetheringManager)
+                .when(mContext).getSystemService(Context.TETHERING_SERVICE);
 
         setupIsTetherAvailable(true);
 
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
     }
 
     @Test
@@ -110,7 +115,7 @@
 
     @Test
     public void testTetherNonIndexableKeys_usbNotAvailable_usbKeyReturned() {
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
 
         final List<String> niks =
             TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
@@ -123,7 +128,7 @@
         FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
         // We can ignore the condition of Utils.isMonkeyRunning()
         // In normal case, monkey and robotest should not execute at the same time
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[]{"fakeRegex"});
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{"fakeRegex"});
 
         final List<String> niks =
             TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
@@ -133,7 +138,7 @@
 
     @Test
     public void testTetherNonIndexableKeys_bluetoothNotAvailable_bluetoothKeyReturned() {
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
 
         final List<String> niks =
             TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
@@ -144,7 +149,7 @@
     @Test
     public void testTetherNonIndexableKeys_bluetoothAvailable_bluetoothKeyNotReturned() {
         FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
-        when(mConnectivityManager.getTetherableBluetoothRegexs())
+        when(mTetheringManager.getTetherableBluetoothRegexs())
                 .thenReturn(new String[]{"fakeRegex"});
 
         final List<String> niks =
@@ -235,11 +240,11 @@
     }
 
     private void updateOnlyBluetoothState(TetherSettings tetherSettings) {
-        doReturn(mConnectivityManager).when(tetherSettings)
-            .getSystemService(Context.CONNECTIVITY_SERVICE);
-        when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
-        when(mConnectivityManager.getTetheringErroredIfaces()).thenReturn(new String[0]);
+        doReturn(mTetheringManager).when(tetherSettings)
+            .getSystemService(Context.TETHERING_SERVICE);
+        when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetheringErroredIfaces()).thenReturn(new String[0]);
         doNothing().when(tetherSettings).updateUsbState(any(String[].class), any(String[].class),
                 any(String[].class));
         doNothing().when(tetherSettings).updateEthernetState(any(String[].class),
diff --git a/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java
index 3b1f008..d3a3129 100644
--- a/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java
@@ -26,7 +26,6 @@
 
 import android.bluetooth.BluetoothAdapter;
 import android.content.Context;
-import android.net.ConnectivityManager;
 import android.net.TetheringManager;
 
 import androidx.preference.SwitchPreference;
@@ -44,7 +43,7 @@
 public class BluetoothTetherPreferenceControllerTest {
 
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private TetherEnabler mTetherEnabler;
 
@@ -58,9 +57,8 @@
 
         mContext = spy(ApplicationProvider.getApplicationContext());
         mSwitchPreference = spy(SwitchPreference.class);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
-                mConnectivityManager);
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
         mController = new BluetoothTetherPreferenceController(mContext, "BLUETOOTH");
         mController.setTetherEnabler(mTetherEnabler);
         ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
@@ -98,7 +96,7 @@
 
     @Test
     public void shouldShow_noBluetoothTetherable() {
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
         assertThat(mController.isAvailable()).isFalse();
     }
 
diff --git a/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
index d2e53b8..b269b05 100644
--- a/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
@@ -25,7 +25,6 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
 import android.net.EthernetManager;
 import android.net.TetheringManager;
 
@@ -49,7 +48,7 @@
     public MockitoRule mocks = MockitoJUnit.rule();
 
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private EthernetManager mEthernetManager;
     @Mock
@@ -64,9 +63,8 @@
     public void setUp() {
         mContext = spy(ApplicationProvider.getApplicationContext());
         mPreference = spy(SwitchPreference.class);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
-        when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[]{ETHERNET_REGEX});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[]{ETHERNET_REGEX});
         when(mContext.getSystemService(Context.ETHERNET_SERVICE)).thenReturn(mEthernetManager);
         mController = new EthernetTetherPreferenceController(mContext, "ethernet");
         mController.setTetherEnabler(mTetherEnabler);
@@ -105,7 +103,7 @@
 
     @Test
     public void shouldEnable_noTetherable() {
-        when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
         assertThat(mController.shouldEnable()).isFalse();
     }
 
diff --git a/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java b/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
index 87806be..bb4b0c4 100644
--- a/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
@@ -101,9 +101,9 @@
         when(context.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
         when(context.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(
                 mNetworkPolicyManager);
-        when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
         panReference.set(mBluetoothPan);
         mEnabler = spy(new TetherEnabler(context, mSwitchWidgetController, panReference));
         ReflectionHelpers.setField(mEnabler, "mBluetoothAdapter", mBluetoothAdapter);
@@ -111,8 +111,8 @@
 
     @Test
     public void lifecycle_onStart_setCheckedCorrectly() {
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(USB_TETHERED);
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(USB_TETHERED);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
 
         mEnabler.onStart();
         assertThat(mSwitchBar.isChecked()).isTrue();
@@ -150,7 +150,7 @@
         mEnabler.onStart();
         mEnabler.startTethering(TetheringManager.TETHERING_WIFI);
 
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[0]);
         mEnabler.mOnStartTetheringCallback.onTetheringFailed();
 
         assertThat(mSwitchBar.isChecked()).isFalse();
@@ -255,8 +255,8 @@
 
     @Test
     public void updateState_shouldEnableSwitchBarTethering() {
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(USB_TETHERED);
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(USB_TETHERED);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
 
         mSwitchWidgetController.setListener(mEnabler);
         mSwitchWidgetController.startListening();
diff --git a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
index 3958589..4824eb2 100644
--- a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
@@ -33,6 +33,7 @@
 import android.content.IntentFilter;
 import android.database.ContentObserver;
 import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.provider.Settings;
 
 import androidx.preference.Preference;
@@ -56,7 +57,7 @@
     @Mock
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private BluetoothAdapter mBluetoothAdapter;
     @Mock
@@ -69,7 +70,7 @@
         MockitoAnnotations.initMocks(this);
         mController = spy(TetherPreferenceController.class);
         ReflectionHelpers.setField(mController, "mContext", mContext);
-        ReflectionHelpers.setField(mController, "mConnectivityManager", mConnectivityManager);
+        ReflectionHelpers.setField(mController, "mTetheringManager", mTetheringManager);
         ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
         ReflectionHelpers.setField(mController, "mPreference", mPreference);
     }
@@ -106,16 +107,16 @@
     }
 
     @Test
-    public void updateSummary_noPreference_noInteractionWithConnectivityManager() {
+    public void updateSummary_noPreference_noInteractionWithTetheringManager() {
         ReflectionHelpers.setField(mController, "mPreference", null);
         mController.updateSummary();
-        verifyNoMoreInteractions(mConnectivityManager);
+        verifyNoMoreInteractions(mTetheringManager);
     }
 
     @Test
     public void updateSummary_wifiTethered_shouldShowHotspotMessage() {
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"123"});
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"123"});
 
         mController.updateSummary();
         verify(mPreference).setSummary(R.string.tether_settings_summary_hotspot_on_tether_off);
@@ -123,8 +124,8 @@
 
     @Test
     public void updateSummary_btThetherOn_shouldShowTetherMessage() {
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
 
         mController.updateSummary();
         verify(mPreference).setSummary(R.string.tether_settings_summary_hotspot_off_tether_on);
@@ -132,8 +133,8 @@
 
     @Test
     public void updateSummary_tetherOff_shouldShowTetherOffMessage() {
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
 
         mController.updateSummary();
         verify(mPreference).setSummary(R.string.switch_off_text);
@@ -141,9 +142,9 @@
 
     @Test
     public void updateSummary_wifiBtTetherOn_shouldShowHotspotAndTetherMessage() {
-        when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[]{"123", "456"});
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
-        when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"23"});
+        when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[]{"123", "456"});
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
+        when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"23"});
 
         mController.updateSummary();
         verify(mPreference).setSummary(R.string.tether_settings_summary_hotspot_on_tether_on);
diff --git a/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java
index 066084e..e02da90 100644
--- a/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java
@@ -25,7 +25,6 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
 import android.net.TetheringManager;
 
 import androidx.preference.SwitchPreference;
@@ -43,7 +42,7 @@
 public class UsbTetherPreferenceControllerTest {
 
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private TetherEnabler mTetherEnabler;
 
@@ -56,9 +55,8 @@
         MockitoAnnotations.initMocks(this);
 
         mContext = spy(ApplicationProvider.getApplicationContext());
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
-                mConnectivityManager);
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
         mController = new UsbTetherPreferenceController(mContext, "USB");
         mController.setTetherEnabler(mTetherEnabler);
         mSwitchPreference = spy(SwitchPreference.class);
@@ -94,7 +92,7 @@
 
     @Test
     public void shouldShow_noTetherableUsb() {
-        when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
         assertThat(mController.shouldShow()).isFalse();
     }
 
diff --git a/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java
index 1d2042c..a82a71f 100644
--- a/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java
@@ -28,7 +28,7 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 
 import androidx.preference.PreferenceScreen;
 import androidx.preference.SwitchPreference;
@@ -77,7 +77,7 @@
     }
 
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private PreferenceScreen mPreferenceScreen;
     @Mock
@@ -100,9 +100,8 @@
 
         mContext = spy(ApplicationProvider.getApplicationContext());
         mPreference = spy(SwitchPreference.class);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
-                mConnectivityManager);
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
         mController = new WifiTetherDisablePreferenceController(mContext, WIFI_TETHER_DISABLE_KEY);
         mController.setTetherEnabler(mTetherEnabler);
         ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
@@ -112,7 +111,7 @@
 
     @Test
     public void shouldShow_noTetherableWifi() {
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
         assertThat(mController.shouldShow()).isFalse();
     }
 
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
index 22e18bb..d227ac1 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
@@ -18,9 +18,6 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
-import static org.mockito.Mockito.anyInt;
-import static org.mockito.Mockito.anyString;
-import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.robolectric.Shadows.shadowOf;
@@ -33,9 +30,6 @@
 import android.net.wifi.WifiEnterpriseConfig.Eap;
 import android.net.wifi.WifiEnterpriseConfig.Phase2;
 import android.net.wifi.WifiManager;
-import android.os.ServiceSpecificException;
-import android.security.Credentials;
-import android.security.KeyStore;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
@@ -51,9 +45,12 @@
 import com.android.settings.R;
 import com.android.settings.network.SubscriptionUtil;
 import com.android.settings.testutils.shadow.ShadowConnectivityManager;
+import com.android.settings.utils.AndroidKeystoreAliasLoader;
 import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
 import com.android.wifitrackerlib.WifiEntry;
 
+import com.google.common.collect.ImmutableList;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -79,7 +76,7 @@
     @Mock
     private WifiEntry mWifiEntry;
     @Mock
-    private KeyStore mKeyStore;
+    private AndroidKeystoreAliasLoader mAndroidKeystoreAliasLoader;
     private View mView;
     private Spinner mHiddenSettingsSpinner;
     private Spinner mEapCaCertSpinner;
@@ -286,27 +283,11 @@
     }
 
     @Test
-    public void loadCertificates_keyStoreListFail_shouldNotCrash() {
-        // Set up
-        when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
-        when(mKeyStore.list(anyString()))
-            .thenThrow(new ServiceSpecificException(-1, "permission error"));
-
-        mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
-              WifiConfigUiBase2.MODE_CONNECT);
-
-        // Verify that the EAP method menu is visible.
-        assertThat(mView.findViewById(R.id.eap).getVisibility()).isEqualTo(View.VISIBLE);
-        // No Crash
-    }
-
-    @Test
     public void loadCertificates_undesiredCertificates_shouldNotLoadUndesiredCertificates() {
         final Spinner spinner = new Spinner(mContext);
-        when(mKeyStore.list(anyString())).thenReturn(WifiConfigController2.UNDESIRED_CERTIFICATES);
 
         mController.loadCertificates(spinner,
-                "prefix",
+                Arrays.asList(WifiConfigController.UNDESIRED_CERTIFICATES),
                 "doNotProvideEapUserCertString",
                 false /* showMultipleCerts */,
                 false /* showUsePreinstalledCertOption */);
@@ -432,8 +413,8 @@
         }
 
         @Override
-        KeyStore getKeyStore() {
-            return mKeyStore;
+        AndroidKeystoreAliasLoader getAndroidKeystoreAliasLoader() {
+            return mAndroidKeystoreAliasLoader;
         }
     }
 
@@ -882,6 +863,7 @@
             String savedUserCertificate) {
         final WifiConfiguration mockWifiConfig = mock(WifiConfiguration.class);
         final WifiEnterpriseConfig mockWifiEnterpriseConfig = mock(WifiEnterpriseConfig.class);
+
         mockWifiConfig.enterpriseConfig = mockWifiEnterpriseConfig;
         when(mWifiEntry.isSaved()).thenReturn(true);
         when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
@@ -892,15 +874,15 @@
             String[] savedCaCertificates = new String[]{savedCaCertificate};
             when(mockWifiEnterpriseConfig.getCaCertificateAliases())
                     .thenReturn(savedCaCertificates);
-            when(mKeyStore.list(eq(Credentials.CA_CERTIFICATE), anyInt()))
-                    .thenReturn(savedCaCertificates);
+            when(mAndroidKeystoreAliasLoader.getCaCertAliases())
+                    .thenReturn(ImmutableList.of(savedCaCertificate));
         }
         if (savedUserCertificate != null) {
             String[] savedUserCertificates = new String[]{savedUserCertificate};
             when(mockWifiEnterpriseConfig.getClientCertificateAlias())
                     .thenReturn(savedUserCertificate);
-            when(mKeyStore.list(eq(Credentials.USER_PRIVATE_KEY), anyInt()))
-                    .thenReturn(savedUserCertificates);
+            when(mAndroidKeystoreAliasLoader.getKeyCertAliases())
+                    .thenReturn(ImmutableList.of(savedUserCertificate));
         }
 
         mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
index 455e9f1..80543ec 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
@@ -21,7 +21,6 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
-import static org.mockito.Mockito.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.robolectric.Shadows.shadowOf;
@@ -34,8 +33,6 @@
 import android.net.wifi.WifiEnterpriseConfig.Eap;
 import android.net.wifi.WifiEnterpriseConfig.Phase2;
 import android.net.wifi.WifiManager;
-import android.os.ServiceSpecificException;
-import android.security.KeyStore;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
@@ -77,8 +74,6 @@
     private Context mContext;
     @Mock
     private AccessPoint mAccessPoint;
-    @Mock
-    private KeyStore mKeyStore;
     private View mView;
     private Spinner mHiddenSettingsSpinner;
     private ShadowSubscriptionManager mShadowSubscriptionManager;
@@ -267,27 +262,11 @@
     }
 
     @Test
-    public void loadCertificates_keyStoreListFail_shouldNotCrash() {
-        // Set up
-        when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
-        when(mKeyStore.list(anyString()))
-            .thenThrow(new ServiceSpecificException(-1, "permission error"));
-
-        mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
-              WifiConfigUiBase.MODE_CONNECT);
-
-        // Verify that the EAP method menu is visible.
-        assertThat(mView.findViewById(R.id.eap).getVisibility()).isEqualTo(View.VISIBLE);
-        // No Crash
-    }
-
-    @Test
     public void loadCertificates_undesiredCertificates_shouldNotLoadUndesiredCertificates() {
         final Spinner spinner = new Spinner(mContext);
-        when(mKeyStore.list(anyString())).thenReturn(WifiConfigController.UNDESIRED_CERTIFICATES);
 
         mController.loadCertificates(spinner,
-                "prefix",
+                Arrays.asList(WifiConfigController.UNDESIRED_CERTIFICATES),
                 "doNotProvideEapUserCertString",
                 false /* showMultipleCerts */,
                 false /* showUsePreinstalledCertOption */);
@@ -412,8 +391,6 @@
             super(parent, view, accessPoint, mode, wifiManager);
         }
 
-        @Override
-        KeyStore getKeyStore() { return mKeyStore; }
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java
index e639b67..d777a59 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java
@@ -25,7 +25,7 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiManager;
 
@@ -57,7 +57,7 @@
 
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -74,9 +74,8 @@
         mContext = spy(RuntimeEnvironment.application);
         mPreference = new ListPreference(RuntimeEnvironment.application);
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
         when(mWifiManager.getSoftApConfiguration()).thenReturn(
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java
index b0ed862..25ad730 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherFooterPreferenceControllerTest.java
@@ -22,7 +22,7 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.WifiManager;
 
 import androidx.preference.PreferenceScreen;
@@ -43,7 +43,7 @@
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -58,9 +58,8 @@
         MockitoAnnotations.initMocks(this);
 
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         mController = new WifiTetherFooterPreferenceController(mContext);
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
     }
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java
index 7835f7e..8f8477f 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceControllerTest.java
@@ -26,7 +26,7 @@
 
 import android.app.settings.SettingsEnums;
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiManager;
 
@@ -53,7 +53,7 @@
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -77,9 +77,8 @@
 
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
         when(mWifiManager.getSoftApConfiguration()).thenReturn(mConfig);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
 
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
index 920582f..23bb0db 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
@@ -23,7 +23,7 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiManager;
 
@@ -56,7 +56,7 @@
 
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -77,14 +77,13 @@
         mLifecycle = new Lifecycle(mLifecycleOwner);
         FakeFeatureFactory.setupForTest();
         mPreference = new PrimarySwitchPreference(RuntimeEnvironment.application);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
         mSoftApConfiguration = new SoftApConfiguration.Builder().setSsid(SSID).build();
         when(mWifiManager.getSoftApConfiguration()).thenReturn(mSoftApConfiguration);
 
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         mController = new WifiTetherPreferenceController(mContext, mLifecycle,
                 false /* initSoftApManager */);
         mController.displayPreference(mScreen);
@@ -92,7 +91,7 @@
 
     @Test
     public void isAvailable_noTetherRegex_shouldReturnFalse() {
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{});
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{});
         mController = new WifiTetherPreferenceController(mContext, mLifecycle,
                 false /* initSoftApManager */);
 
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java
index a6a9dda..147cd64 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceControllerTest.java
@@ -26,7 +26,7 @@
 
 import android.app.settings.SettingsEnums;
 import android.content.Context;
-import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiManager;
 
@@ -49,7 +49,7 @@
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
     @Mock
-    private ConnectivityManager mConnectivityManager;
+    private TetheringManager mTetheringManager;
     @Mock
     private WifiManager mWifiManager;
     @Mock
@@ -68,9 +68,8 @@
         mPreference = new WifiTetherSsidPreference(RuntimeEnvironment.application);
 
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
-        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
-                .thenReturn(mConnectivityManager);
-        when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
+        when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
         when(mScreen.findPreference(anyString())).thenReturn(mPreference);
         mController = new WifiTetherSSIDPreferenceController(mContext, mListener,
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
index b41616b..a241296 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -30,6 +30,7 @@
 import android.content.Context;
 import android.content.res.Resources;
 import android.net.ConnectivityManager;
+import android.net.TetheringManager;
 import android.os.Bundle;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -70,6 +71,8 @@
     private ConnectivityManager mConnectivityManager;
     @Mock
     private UserManager mUserManager;
+    @Mock
+    private TetheringManager mTetheringManager;
 
     @Before
     public void setUp() {
@@ -78,7 +81,8 @@
         MockitoAnnotations.initMocks(this);
         doReturn(mConnectivityManager)
                 .when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
-        doReturn(WIFI_REGEXS).when(mConnectivityManager).getTetherableWifiRegexs();
+        doReturn(mTetheringManager).when(mContext).getSystemService(Context.TETHERING_SERVICE);
+        doReturn(WIFI_REGEXS).when(mTetheringManager).getTetherableWifiRegexs();
         doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
 
         mWifiTetherSettings = new WifiTetherSettings();