Merge "Fix UwbPreferenceControllerTest"
diff --git a/res/values/config.xml b/res/values/config.xml
index 29de56f..4b725b1 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -318,6 +318,9 @@
     surface in search results or not.-->
     <bool name="config_show_wifi_settings">true</bool>
 
+    <!-- Whether Wi-Fi hotspot settings should be shown or not. -->
+    <bool name="config_show_wifi_hotspot_settings">true</bool>
+
     <!-- Whether toggle_airplane is available or not. -->
     <bool name="config_show_toggle_airplane">true</bool>
 
diff --git a/src/com/android/settings/slices/CustomSliceRegistry.java b/src/com/android/settings/slices/CustomSliceRegistry.java
index 569a0ea..1cc3276 100644
--- a/src/com/android/settings/slices/CustomSliceRegistry.java
+++ b/src/com/android/settings/slices/CustomSliceRegistry.java
@@ -315,37 +315,28 @@
             .appendPath("always_on_display")
             .build();
 
-    /**
-     * Backing Uri for the Turn on Wi-Fi Slice.
-     */
-    public static final Uri TURN_ON_WIFI_SLICE_URI = new Uri.Builder()
-            .scheme(ContentResolver.SCHEME_CONTENT)
-            .authority(SettingsSliceProvider.SLICE_AUTHORITY)
-            .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
-            .appendPath("turn_on_wifi")
-            .build();
-
     @VisibleForTesting
     static final Map<Uri, Class<? extends CustomSliceable>> sUriToSlice;
 
     static {
         sUriToSlice = new ArrayMap<>();
-
-        sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class);
-        sUriToSlice.put(BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class);
-        sUriToSlice.put(CONTEXTUAL_ADAPTIVE_SLEEP_URI, ContextualAdaptiveSleepSlice.class);
-        sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class);
-        sUriToSlice.put(FACE_ENROLL_SLICE_URI, FaceSetupSlice.class);
         sUriToSlice.put(FLASHLIGHT_SLICE_URI, FlashlightSlice.class);
         sUriToSlice.put(LOCATION_SLICE_URI, LocationSlice.class);
-        sUriToSlice.put(LOW_STORAGE_SLICE_URI, LowStorageSlice.class);
-        sUriToSlice.put(MEDIA_OUTPUT_INDICATOR_SLICE_URI, MediaOutputIndicatorSlice.class);
         sUriToSlice.put(MOBILE_DATA_SLICE_URI, MobileDataSlice.class);
         sUriToSlice.put(PROVIDER_MODEL_SLICE_URI, ProviderModelSlice.class);
         sUriToSlice.put(WIFI_SLICE_URI, WifiSlice.class);
         sUriToSlice.put(DARK_THEME_SLICE_URI, DarkThemeSlice.class);
-        sUriToSlice.put(REMOTE_MEDIA_SLICE_URI, RemoteMediaSlice.class);
         sUriToSlice.put(ALWAYS_ON_SLICE_URI, AlwaysOnDisplaySlice.class);
+        sUriToSlice.put(MEDIA_OUTPUT_INDICATOR_SLICE_URI, MediaOutputIndicatorSlice.class);
+        sUriToSlice.put(REMOTE_MEDIA_SLICE_URI, RemoteMediaSlice.class);
+
+        // Slices for contextual card.
+        sUriToSlice.put(FACE_ENROLL_SLICE_URI, FaceSetupSlice.class);
+        sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class);
+        sUriToSlice.put(CONTEXTUAL_ADAPTIVE_SLEEP_URI, ContextualAdaptiveSleepSlice.class);
+        sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class);
+        sUriToSlice.put(LOW_STORAGE_SLICE_URI, LowStorageSlice.class);
+        sUriToSlice.put(BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class);
     }
 
     public static Class<? extends CustomSliceable> getSliceClassByUri(Uri uri) {
diff --git a/src/com/android/settings/spa/app/appinfo/AppButtonRepository.kt b/src/com/android/settings/spa/app/appinfo/AppButtonRepository.kt
index 3890e32..2383ddb 100644
--- a/src/com/android/settings/spa/app/appinfo/AppButtonRepository.kt
+++ b/src/com/android/settings/spa/app/appinfo/AppButtonRepository.kt
@@ -60,13 +60,12 @@
         val homePackages = mutableSetOf<String>()
         val homeActivities = ArrayList<ResolveInfo>()
         val currentDefaultHome = packageManager.getHomeActivities(homeActivities)
-        homeActivities.map { it.activityInfo }.forEach {
-            homePackages.add(it.packageName)
+        homeActivities.mapNotNull { it.activityInfo }.forEach { activityInfo ->
+            homePackages.add(activityInfo.packageName)
             // Also make sure to include anything proxying for the home app
-            val metaPackageName = it.metaData?.getString(ActivityManager.META_HOME_ALTERNATE)
-            if (metaPackageName != null && signaturesMatch(metaPackageName, it.packageName)) {
-                homePackages.add(metaPackageName)
-            }
+            activityInfo.metaData?.getString(ActivityManager.META_HOME_ALTERNATE)
+                ?.takeIf { signaturesMatch(it, activityInfo.packageName) }
+                ?.let { homePackages.add(it) }
         }
         return HomePackages(homePackages, currentDefaultHome)
     }
diff --git a/src/com/android/settings/spa/app/appinfo/AppInfoSettings.kt b/src/com/android/settings/spa/app/appinfo/AppInfoSettings.kt
index 8235101..82fdc84 100644
--- a/src/com/android/settings/spa/app/appinfo/AppInfoSettings.kt
+++ b/src/com/android/settings/spa/app/appinfo/AppInfoSettings.kt
@@ -92,7 +92,12 @@
 
         AppPermissionPreference(app)
         AppStoragePreference(app)
+        // TODO: instant_app_launch_supported_domain_urls
+        // TODO: data_settings
         AppTimeSpentPreference(app)
+        // TODO: battery
+        // TODO: app_language_setting
+        AppOpenByDefaultPreference(app)
 
         Category(title = stringResource(R.string.advanced_apps)) {
             DisplayOverOtherAppsAppListProvider.InfoPageEntryItem(app)
diff --git a/src/com/android/settings/spa/app/appinfo/AppInstallButton.kt b/src/com/android/settings/spa/app/appinfo/AppInstallButton.kt
index a3ddfab..4ff2461 100644
--- a/src/com/android/settings/spa/app/appinfo/AppInstallButton.kt
+++ b/src/com/android/settings/spa/app/appinfo/AppInstallButton.kt
@@ -33,7 +33,7 @@
         val app = packageInfo.applicationInfo
         if (!app.isInstantApp) return null
 
-        return AppStoreUtil.getAppStoreLink(packageInfoPresenter.contextAsUser, app.packageName)
+        return AppStoreUtil.getAppStoreLink(packageInfoPresenter.userContext, app.packageName)
             ?.let { intent -> installButton(intent, app) }
     }
 
diff --git a/src/com/android/settings/spa/app/appinfo/AppOpenByDefaultPreference.kt b/src/com/android/settings/spa/app/appinfo/AppOpenByDefaultPreference.kt
new file mode 100644
index 0000000..936dee6
--- /dev/null
+++ b/src/com/android/settings/spa/app/appinfo/AppOpenByDefaultPreference.kt
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2022 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.spa.app.appinfo
+
+import android.app.settings.SettingsEnums
+import android.content.Context
+import android.content.pm.ApplicationInfo
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.livedata.observeAsState
+import androidx.compose.runtime.remember
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.res.stringResource
+import androidx.lifecycle.liveData
+import com.android.settings.R
+import com.android.settings.applications.appinfo.AppInfoDashboardFragment
+import com.android.settings.applications.intentpicker.AppLaunchSettings
+import com.android.settings.applications.intentpicker.IntentPickerUtils
+import com.android.settingslib.applications.AppUtils
+import com.android.settingslib.spa.framework.compose.stateOf
+import com.android.settingslib.spa.widget.preference.Preference
+import com.android.settingslib.spa.widget.preference.PreferenceModel
+import com.android.settingslib.spaprivileged.framework.common.asUser
+import com.android.settingslib.spaprivileged.framework.common.domainVerificationManager
+import com.android.settingslib.spaprivileged.model.app.hasFlag
+import com.android.settingslib.spaprivileged.model.app.userHandle
+import com.android.settingslib.spaprivileged.model.app.userId
+import kotlinx.coroutines.Dispatchers
+
+@Composable
+fun AppOpenByDefaultPreference(app: ApplicationInfo) {
+    val context = LocalContext.current
+    val presenter = remember { AppOpenByDefaultPresenter(context, app) }
+    if (!presenter.isAvailable()) return
+
+    Preference(object : PreferenceModel {
+        override val title = stringResource(R.string.launch_by_default)
+        override val summary = presenter.summaryLiveData.observeAsState(
+            initial = stringResource(R.string.summary_placeholder),
+        )
+        override val enabled = stateOf(presenter.isEnabled())
+        override val onClick = presenter::startActivity
+    })
+}
+
+private class AppOpenByDefaultPresenter(
+    private val context: Context,
+    private val app: ApplicationInfo,
+) {
+    private val domainVerificationManager = context.asUser(app.userHandle).domainVerificationManager
+
+    fun isAvailable() =
+        !app.isInstantApp && !AppUtils.isBrowserApp(context, app.packageName, app.userId)
+
+    fun isEnabled() = app.hasFlag(ApplicationInfo.FLAG_INSTALLED) && app.enabled
+
+    val summaryLiveData = liveData(Dispatchers.IO) {
+        emit(context.getString(when {
+            isLinkHandlingAllowed() -> R.string.app_link_open_always
+            else -> R.string.app_link_open_never
+        }))
+    }
+
+    fun isLinkHandlingAllowed(): Boolean {
+        val userState = IntentPickerUtils.getDomainVerificationUserState(
+            domainVerificationManager, app.packageName
+        )
+        return userState?.isLinkHandlingAllowed ?: false
+    }
+
+    fun startActivity() {
+        AppInfoDashboardFragment.startAppInfoFragment(
+            AppLaunchSettings::class.java,
+            app,
+            context,
+            SettingsEnums.APPLICATIONS_INSTALLED_APP_DETAILS,
+        )
+    }
+}
diff --git a/src/com/android/settings/spa/app/appinfo/AppPermissionSummary.kt b/src/com/android/settings/spa/app/appinfo/AppPermissionSummary.kt
index 9c5f673..f73c35a 100644
--- a/src/com/android/settings/spa/app/appinfo/AppPermissionSummary.kt
+++ b/src/com/android/settings/spa/app/appinfo/AppPermissionSummary.kt
@@ -24,6 +24,7 @@
 import com.android.settings.R
 import com.android.settingslib.applications.PermissionsSummaryHelper
 import com.android.settingslib.applications.PermissionsSummaryHelper.PermissionsResultCallback
+import com.android.settingslib.spaprivileged.framework.common.asUser
 import com.android.settingslib.spaprivileged.model.app.userHandle
 
 data class AppPermissionSummaryState(
@@ -35,8 +36,8 @@
     private val context: Context,
     private val app: ApplicationInfo,
 ) : LiveData<AppPermissionSummaryState>() {
-    private val contextAsUser = context.createContextAsUser(app.userHandle, 0)
-    private val packageManager = contextAsUser.packageManager
+    private val userContext = context.asUser(app.userHandle)
+    private val packageManager = userContext.packageManager
 
     private val onPermissionsChangedListener = OnPermissionsChangedListener { uid ->
         if (uid == app.uid) update()
@@ -53,7 +54,7 @@
 
     private fun update() {
         PermissionsSummaryHelper.getPermissionSummary(
-            contextAsUser, app.packageName, permissionsCallback
+            userContext, app.packageName, permissionsCallback
         )
     }
 
diff --git a/src/com/android/settings/spa/app/appinfo/PackageInfoPresenter.kt b/src/com/android/settings/spa/app/appinfo/PackageInfoPresenter.kt
index 2f5dda1..050c048 100644
--- a/src/com/android/settings/spa/app/appinfo/PackageInfoPresenter.kt
+++ b/src/com/android/settings/spa/app/appinfo/PackageInfoPresenter.kt
@@ -29,6 +29,7 @@
 import androidx.compose.runtime.Composable
 import com.android.settings.overlay.FeatureFactory
 import com.android.settingslib.spa.framework.compose.LocalNavController
+import com.android.settingslib.spaprivileged.framework.common.asUser
 import com.android.settingslib.spaprivileged.framework.compose.DisposableBroadcastReceiverAsUser
 import com.android.settingslib.spaprivileged.model.app.PackageManagers
 import kotlinx.coroutines.CoroutineScope
@@ -49,8 +50,8 @@
     private val coroutineScope: CoroutineScope,
 ) {
     private val metricsFeatureProvider = FeatureFactory.getFactory(context).metricsFeatureProvider
-    val contextAsUser by lazy { context.createContextAsUser(UserHandle.of(userId), 0) }
-    val packageManagerAsUser: PackageManager by lazy { contextAsUser.packageManager }
+    val userContext by lazy { context.asUser(UserHandle.of(userId)) }
+    val packageManagerAsUser: PackageManager by lazy { userContext.packageManager }
     private val _flow: MutableStateFlow<PackageInfo?> = MutableStateFlow(null)
 
     val flow: StateFlow<PackageInfo?> = _flow
diff --git a/src/com/android/settings/wifi/WifiUtils.java b/src/com/android/settings/wifi/WifiUtils.java
index 4b94c81..a9010ac 100644
--- a/src/com/android/settings/wifi/WifiUtils.java
+++ b/src/com/android/settings/wifi/WifiUtils.java
@@ -22,14 +22,20 @@
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.net.NetworkCapabilities;
+import android.net.TetheringManager;
 import android.net.wifi.ScanResult;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.provider.Settings;
 import android.text.TextUtils;
+import android.util.Log;
 
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settings.R;
 import com.android.settings.Utils;
 import com.android.wifitrackerlib.WifiEntry;
 
@@ -38,12 +44,16 @@
 /** A utility class for Wi-Fi functions. */
 public class WifiUtils extends com.android.settingslib.wifi.WifiUtils {
 
+    static final String TAG = "WifiUtils";
+
     private static final int SSID_ASCII_MIN_LENGTH = 1;
     private static final int SSID_ASCII_MAX_LENGTH = 32;
 
     private static final int PSK_PASSPHRASE_ASCII_MIN_LENGTH = 8;
     private static final int PSK_PASSPHRASE_ASCII_MAX_LENGTH = 63;
 
+    private static Boolean sCanShowWifiHotspotCached;
+
     public static boolean isSSIDTooLong(String ssid) {
         if (TextUtils.isEmpty(ssid)) {
             return false;
@@ -240,4 +250,62 @@
 
         return WifiEntry.SECURITY_NONE;
     }
+
+    /**
+     * Check if Wi-Fi hotspot settings can be displayed.
+     *
+     * @param context Context of caller
+     * @return true if Wi-Fi hotspot settings can be displayed
+     */
+    public static boolean checkShowWifiHotspot(Context context) {
+        if (context == null) return false;
+
+        boolean showWifiHotspotSettings =
+                context.getResources().getBoolean(R.bool.config_show_wifi_hotspot_settings);
+        if (!showWifiHotspotSettings) {
+            Log.w(TAG, "config_show_wifi_hotspot_settings:false");
+            return false;
+        }
+
+        WifiManager wifiManager = context.getSystemService(WifiManager.class);
+        if (wifiManager == null) {
+            Log.e(TAG, "WifiManager is null");
+            return false;
+        }
+
+        TetheringManager tetheringManager = context.getSystemService(TetheringManager.class);
+        if (tetheringManager == null) {
+            Log.e(TAG, "TetheringManager is null");
+            return false;
+        }
+        String[] wifiRegexs = tetheringManager.getTetherableWifiRegexs();
+        if (wifiRegexs == null || wifiRegexs.length == 0) {
+            Log.w(TAG, "TetherableWifiRegexs is empty");
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Return the cached result to see if Wi-Fi hotspot settings can be displayed.
+     *
+     * @param context Context of caller
+     * @return true if Wi-Fi hotspot settings can be displayed
+     */
+    public static boolean canShowWifiHotspot(Context context) {
+        if (sCanShowWifiHotspotCached == null) {
+            sCanShowWifiHotspotCached = checkShowWifiHotspot(context);
+        }
+        return sCanShowWifiHotspotCached;
+    }
+
+    /**
+     * Sets the sCanShowWifiHotspotCached for testing purposes.
+     *
+     * @param cached Cached value for #canShowWifiHotspot()
+     */
+    @VisibleForTesting
+    public static void setCanShowWifiHotspotCached(Boolean cached) {
+        sCanShowWifiHotspotCached = cached;
+    }
 }
diff --git a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
index c0ac159..49b437e 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
@@ -16,9 +16,10 @@
 
 package com.android.settings.wifi.tether;
 
+import static com.android.settings.wifi.WifiUtils.canShowWifiHotspot;
+
 import android.annotation.NonNull;
 import android.content.Context;
-import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiClient;
 import android.net.wifi.WifiManager;
@@ -46,7 +47,6 @@
 
     private static final String WIFI_TETHER_SETTINGS = "wifi_tether";
 
-    private boolean mIsWifiTetherable;
     private WifiManager mWifiManager;
     private boolean mIsWifiTetheringAllow;
     private int mSoftApState;
@@ -59,7 +59,6 @@
         // TODO(b/246537032):Use fragment context to WifiManager service will caused memory leak
         this(context, lifecycle,
                 context.getApplicationContext().getSystemService(WifiManager.class),
-                context.getSystemService(TetheringManager.class),
                 true /* initSoftApManager */,
                 WifiEnterpriseRestrictionUtils.isWifiTetheringAllowed(context));
     }
@@ -69,15 +68,9 @@
             Context context,
             Lifecycle lifecycle,
             WifiManager wifiManager,
-            TetheringManager tetheringManager,
             boolean initSoftApManager,
             boolean isWifiTetheringAllow) {
         super(context);
-        final String[] wifiRegexs = tetheringManager.getTetherableWifiRegexs();
-        if (wifiRegexs != null && wifiRegexs.length != 0) {
-            mIsWifiTetherable = true;
-        }
-
         mIsWifiTetheringAllow = isWifiTetheringAllow;
         if (!isWifiTetheringAllow) return;
 
@@ -93,7 +86,7 @@
 
     @Override
     public boolean isAvailable() {
-        return mIsWifiTetherable && !Utils.isMonkeyRunning();
+        return canShowWifiHotspot(mContext) && !Utils.isMonkeyRunning();
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
index 5b9ce42..bee265e 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
@@ -18,6 +18,8 @@
 
 import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
 
+import static com.android.settings.wifi.WifiUtils.canShowWifiHotspot;
+
 import android.app.settings.SettingsEnums;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -108,6 +110,13 @@
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
+        if (!canShowWifiHotspot(getContext())) {
+            Log.e(TAG, "can not launch Wi-Fi hotspot settings"
+                    + " because the config is not set to show.");
+            finish();
+            return;
+        }
+
         setIfOnlyAvailableForAdmins(true);
         mUnavailable = isUiRestricted() || !mWifiRestriction.isHotspotAvailable(getContext());
     }
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 e8ee7c3..bc6053b 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
@@ -16,13 +16,14 @@
 
 package com.android.settings.wifi.tether;
 
+import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
+
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiManager;
 
@@ -62,8 +63,6 @@
     @Mock
     private Lifecycle mLifecycle;
     @Mock
-    private TetheringManager mTetheringManager;
-    @Mock
     private WifiManager mWifiManager;
     @Mock
     private PreferenceScreen mScreen;
@@ -74,38 +73,37 @@
 
     @Before
     public void setUp() {
+        setCanShowWifiHotspotCached(true);
         FakeFeatureFactory.setupForTest();
         mPreference = new PrimarySwitchPreference(mContext);
-        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(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
         mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
-                mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
+                false /* initSoftApManager */, true /* isWifiTetheringAllow */);
         mController.displayPreference(mScreen);
     }
 
     @Test
-    public void isAvailable_noTetherRegex_shouldReturnFalse() {
-        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{});
-        mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
-                mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
+    public void isAvailable_canNotShowWifiHotspot_shouldReturnFalse() {
+        setCanShowWifiHotspotCached(false);
 
         assertThat(mController.isAvailable()).isFalse();
     }
 
     @Test
-    public void isAvailable_hasTetherRegex_shouldReturnTrue() {
+    public void isAvailable_canShowWifiHostspot_shouldReturnTrue() {
+        setCanShowWifiHotspotCached(true);
+
         assertThat(mController.isAvailable()).isTrue();
     }
 
     @Test
     public void displayPreference_wifiTetheringNotAllowed_shouldDisable() {
         mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
-                mTetheringManager, false /* initSoftApManager */, false /* isWifiTetheringAllow */);
+                false /* initSoftApManager */, false /* isWifiTetheringAllow */);
 
         mController.displayPreference(mScreen);
 
@@ -116,7 +114,7 @@
     @Test
     public void displayPreference_wifiTetheringAllowed_shouldEnable() {
         mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
-                mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
+                false /* initSoftApManager */, true /* isWifiTetheringAllow */);
 
         mController.displayPreference(mScreen);
 
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 d19bc90..6d3b879 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.wifi.tether;
 
+import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
+
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.ArgumentMatchers.any;
@@ -42,6 +44,7 @@
 import androidx.test.core.app.ApplicationProvider;
 
 import com.android.settings.R;
+import com.android.settings.dashboard.RestrictedDashboardFragment;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.shadow.ShadowFragment;
 
@@ -55,6 +58,8 @@
 import org.mockito.junit.MockitoRule;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
 import org.robolectric.util.ReflectionHelpers;
 
 import java.util.List;
@@ -88,6 +93,7 @@
 
     @Before
     public void setUp() {
+        setCanShowWifiHotspotCached(true);
         doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
         doReturn(mConnectivityManager)
                 .when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -101,6 +107,17 @@
     }
 
     @Test
+    @Config(shadows = ShadowRestrictedDashboardFragment.class)
+    public void onCreate_canNotShowWifiHotspot_shouldFinish() {
+        setCanShowWifiHotspotCached(false);
+        mWifiTetherSettings = spy(new WifiTetherSettings(mWifiRestriction));
+
+        mWifiTetherSettings.onCreate(null);
+
+        verify(mWifiTetherSettings).finish();
+    }
+
+    @Test
     @Config(shadows = ShadowFragment.class)
     public void onStart_uiIsRestricted_removeAllPreferences() {
         spyWifiTetherSettings();
@@ -219,4 +236,13 @@
 
         mWifiTetherSettings.onCreate(Bundle.EMPTY);
     }
+
+    @Implements(RestrictedDashboardFragment.class)
+    public static final class ShadowRestrictedDashboardFragment {
+
+        @Implementation
+        public void onCreate(Bundle icicle) {
+            // do nothing
+        }
+    }
 }
diff --git a/tests/spa_unit/Android.bp b/tests/spa_unit/Android.bp
index ed83ab2..9126c55 100644
--- a/tests/spa_unit/Android.bp
+++ b/tests/spa_unit/Android.bp
@@ -35,9 +35,12 @@
         "androidx.compose.ui_ui-test-manifest",
         "androidx.test.ext.junit",
         "androidx.test.runner",
-        "mockito-target-minus-junit4",
+        "mockito-target-inline-minus-junit4",
         "truth-prebuilt",
     ],
+    jni_libs: [
+        "libdexmakerjvmtiagent",
+    ],
     kotlincflags: [
         "-Xjvm-default=all",
         "-opt-in=kotlin.RequiresOptIn",
diff --git a/tests/spa_unit/AndroidManifest.xml b/tests/spa_unit/AndroidManifest.xml
index 5cf8ffd..be16de3 100644
--- a/tests/spa_unit/AndroidManifest.xml
+++ b/tests/spa_unit/AndroidManifest.xml
@@ -19,7 +19,7 @@
           xmlns:tools="http://schemas.android.com/tools"
           package="com.android.settings.tests.spa_unit">
 
-    <application>
+    <application android:debuggable="true">
         <provider android:name="com.android.settings.slices.SettingsSliceProvider"
                   android:authorities="${applicationId}.slices"
                   tools:replace="android:authorities"/>
diff --git a/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppButtonRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppButtonRepositoryTest.kt
new file mode 100644
index 0000000..4e1b1b6
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppButtonRepositoryTest.kt
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2022 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.spa.app.appinfo
+
+import android.app.ActivityManager
+import android.content.ComponentName
+import android.content.Context
+import android.content.pm.ActivityInfo
+import android.content.pm.PackageManager
+import android.content.pm.ResolveInfo
+import androidx.core.os.bundleOf
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mock
+import org.mockito.Mockito.any
+import org.mockito.Spy
+import org.mockito.junit.MockitoJUnit
+import org.mockito.junit.MockitoRule
+import org.mockito.Mockito.`when` as whenever
+
+@RunWith(AndroidJUnit4::class)
+class AppButtonRepositoryTest {
+
+    @JvmField
+    @Rule
+    val mockito: MockitoRule = MockitoJUnit.rule()
+
+    @Spy
+    private val context: Context = ApplicationProvider.getApplicationContext()
+
+    @Mock
+    private lateinit var packageManager: PackageManager
+
+    private lateinit var appButtonRepository: AppButtonRepository
+
+    @Before
+    fun setUp() {
+        whenever(context.packageManager).thenReturn(packageManager)
+
+        appButtonRepository = AppButtonRepository(context)
+    }
+
+    private fun mockGetHomeActivities(
+        homeActivities: List<ResolveInfo>,
+        currentDefaultHome: ComponentName? = null,
+    ) {
+        whenever(packageManager.getHomeActivities(any())).then {
+            @Suppress("UNCHECKED_CAST")
+            (it.arguments[0] as ArrayList<ResolveInfo>).addAll(homeActivities)
+            currentDefaultHome
+        }
+    }
+
+    @Test
+    fun getHomePackageInfo_empty() {
+        mockGetHomeActivities(homeActivities = emptyList())
+
+        val homePackageInfo = appButtonRepository.getHomePackageInfo()
+
+        assertThat(homePackageInfo.homePackages).isEmpty()
+        assertThat(homePackageInfo.currentDefaultHome).isNull()
+    }
+
+    @Test
+    fun getHomePackageInfo_noActivityInfo() {
+        mockGetHomeActivities(homeActivities = listOf(ResolveInfo()))
+
+        val homePackageInfo = appButtonRepository.getHomePackageInfo()
+
+        assertThat(homePackageInfo.homePackages).isEmpty()
+        assertThat(homePackageInfo.currentDefaultHome).isNull()
+    }
+
+    @Test
+    fun getHomePackageInfo_oneHome() {
+        mockGetHomeActivities(
+            homeActivities = listOf(RESOLVE_INFO),
+            currentDefaultHome = COMPONENT_NAME,
+        )
+
+        val homePackageInfo = appButtonRepository.getHomePackageInfo()
+
+        assertThat(homePackageInfo.homePackages).containsExactly(PACKAGE_NAME)
+        assertThat(homePackageInfo.currentDefaultHome).isSameInstanceAs(COMPONENT_NAME)
+    }
+
+    @Test
+    fun getHomePackageInfo_homeAlternateSignatureMatch() {
+        mockGetHomeActivities(homeActivities = listOf(RESOLVE_INFO_WITH_ALTERNATE))
+        whenever(packageManager.checkSignatures(PACKAGE_NAME_ALTERNATE, PACKAGE_NAME))
+            .thenReturn(PackageManager.SIGNATURE_MATCH)
+
+        val homePackageInfo = appButtonRepository.getHomePackageInfo()
+
+        assertThat(homePackageInfo.homePackages).containsExactly(
+            PACKAGE_NAME, PACKAGE_NAME_ALTERNATE
+        )
+    }
+
+    @Test
+    fun getHomePackageInfo_homeAlternateSignatureNoMatch() {
+        mockGetHomeActivities(homeActivities = listOf(RESOLVE_INFO_WITH_ALTERNATE))
+        whenever(packageManager.checkSignatures(PACKAGE_NAME_ALTERNATE, PACKAGE_NAME))
+            .thenReturn(PackageManager.SIGNATURE_NO_MATCH)
+
+        val homePackageInfo = appButtonRepository.getHomePackageInfo()
+
+        assertThat(homePackageInfo.homePackages).containsExactly(PACKAGE_NAME)
+    }
+
+    private companion object {
+        const val PACKAGE_NAME = "packageName"
+        const val PACKAGE_NAME_ALTERNATE = "packageName.alternate"
+        const val ACTIVITY_NAME = "activityName"
+        val COMPONENT_NAME = ComponentName(PACKAGE_NAME, ACTIVITY_NAME)
+        val RESOLVE_INFO = ResolveInfo().apply {
+            activityInfo = ActivityInfo().apply {
+                packageName = PACKAGE_NAME
+            }
+        }
+        val RESOLVE_INFO_WITH_ALTERNATE = ResolveInfo().apply {
+            activityInfo = ActivityInfo().apply {
+                packageName = PACKAGE_NAME
+                metaData = bundleOf(
+                    ActivityManager.META_HOME_ALTERNATE to PACKAGE_NAME_ALTERNATE,
+                )
+            }
+        }
+    }
+}
diff --git a/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppOpenByDefaultPreferenceTest.kt b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppOpenByDefaultPreferenceTest.kt
new file mode 100644
index 0000000..a402a02
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppOpenByDefaultPreferenceTest.kt
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2022 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.spa.app.appinfo
+
+import android.content.Context
+import android.content.pm.ActivityInfo
+import android.content.pm.ApplicationInfo
+import android.content.pm.PackageManager
+import android.content.pm.ResolveInfo
+import android.content.pm.verify.domain.DomainVerificationManager
+import android.content.pm.verify.domain.DomainVerificationUserState
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.test.assertIsDisplayed
+import androidx.compose.ui.test.assertIsEnabled
+import androidx.compose.ui.test.assertIsNotDisplayed
+import androidx.compose.ui.test.assertIsNotEnabled
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.compose.ui.test.onNodeWithText
+import androidx.compose.ui.test.onRoot
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.R
+import com.android.settingslib.spaprivileged.framework.common.domainVerificationManager
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mock
+import org.mockito.Mockito.any
+import org.mockito.Mockito.anyInt
+import org.mockito.Mockito.doReturn
+import org.mockito.Spy
+import org.mockito.junit.MockitoJUnit
+import org.mockito.junit.MockitoRule
+import org.mockito.Mockito.`when` as whenever
+
+@RunWith(AndroidJUnit4::class)
+class AppOpenByDefaultPreferenceTest {
+    @JvmField
+    @Rule
+    val mockito: MockitoRule = MockitoJUnit.rule()
+
+    @get:Rule
+    val composeTestRule = createComposeRule()
+
+    @Spy
+    private val context: Context = ApplicationProvider.getApplicationContext()
+
+    @Mock
+    private lateinit var packageManager: PackageManager
+
+    @Mock
+    private lateinit var domainVerificationManager: DomainVerificationManager
+
+    @Mock
+    private lateinit var allowedUserState: DomainVerificationUserState
+
+    @Mock
+    private lateinit var notAllowedUserState: DomainVerificationUserState
+
+    @Before
+    fun setUp() {
+        whenever(context.packageManager).thenReturn(packageManager)
+        doReturn(context).`when`(context).createContextAsUser(any(), anyInt())
+        whenever(context.domainVerificationManager).thenReturn(domainVerificationManager)
+        whenever(allowedUserState.isLinkHandlingAllowed).thenReturn(true)
+        whenever(notAllowedUserState.isLinkHandlingAllowed).thenReturn(false)
+    }
+
+    @Test
+    fun instantApp_notDisplay() {
+        val instantApp = ApplicationInfo().apply {
+            packageName = PACKAGE_NAME
+            privateFlags = ApplicationInfo.PRIVATE_FLAG_INSTANT
+        }
+
+        composeTestRule.setContent {
+            CompositionLocalProvider(LocalContext provides context) {
+                AppOpenByDefaultPreference(instantApp)
+            }
+        }
+
+        composeTestRule.onRoot().assertIsNotDisplayed()
+    }
+
+    @Test
+    fun browserApp_notDisplay() {
+        val browserApp = ApplicationInfo().apply {
+            packageName = PACKAGE_NAME
+            privateFlags = ApplicationInfo.PRIVATE_FLAG_INSTANT
+        }
+        val resolveInfo = ResolveInfo().apply {
+            activityInfo = ActivityInfo()
+            handleAllWebDataURI = true
+        }
+        whenever(packageManager.queryIntentActivitiesAsUser(any(), anyInt(), anyInt()))
+            .thenReturn(listOf(resolveInfo))
+
+        composeTestRule.setContent {
+            CompositionLocalProvider(LocalContext provides context) {
+                AppOpenByDefaultPreference(browserApp)
+            }
+        }
+
+        composeTestRule.onRoot().assertIsNotDisplayed()
+    }
+
+    @Test
+    fun allowedUserState_alwaysOpen() {
+        whenever(domainVerificationManager.getDomainVerificationUserState(PACKAGE_NAME))
+            .thenReturn(allowedUserState)
+
+        composeTestRule.setContent {
+            CompositionLocalProvider(LocalContext provides context) {
+                AppOpenByDefaultPreference(INSTALLED_ENABLED_APP)
+            }
+        }
+
+        composeTestRule.onNodeWithText(context.getString(R.string.launch_by_default))
+            .assertIsDisplayed()
+            .assertIsEnabled()
+        composeTestRule.onNodeWithText(context.getString(R.string.app_link_open_always))
+            .assertIsDisplayed()
+    }
+
+    @Test
+    fun notAllowedUserState_neverOpen() {
+        whenever(domainVerificationManager.getDomainVerificationUserState(PACKAGE_NAME))
+            .thenReturn(notAllowedUserState)
+
+        composeTestRule.setContent {
+            CompositionLocalProvider(LocalContext provides context) {
+                AppOpenByDefaultPreference(INSTALLED_ENABLED_APP)
+            }
+        }
+
+        composeTestRule.onNodeWithText(context.getString(R.string.launch_by_default))
+            .assertIsDisplayed()
+            .assertIsEnabled()
+        composeTestRule.onNodeWithText(context.getString(R.string.app_link_open_never))
+            .assertIsDisplayed()
+    }
+
+    @Test
+    fun notInstalledApp_disabled() {
+        val notInstalledApp = ApplicationInfo().apply {
+            packageName = PACKAGE_NAME
+        }
+
+        composeTestRule.setContent {
+            CompositionLocalProvider(LocalContext provides context) {
+                AppOpenByDefaultPreference(notInstalledApp)
+            }
+        }
+
+        composeTestRule.onNodeWithText(context.getString(R.string.launch_by_default))
+            .assertIsNotEnabled()
+    }
+
+    @Test
+    fun notEnabledApp_disabled() {
+        val notEnabledApp = ApplicationInfo().apply {
+            packageName = PACKAGE_NAME
+            flags = ApplicationInfo.FLAG_INSTALLED
+            enabled = false
+        }
+
+        composeTestRule.setContent {
+            CompositionLocalProvider(LocalContext provides context) {
+                AppOpenByDefaultPreference(notEnabledApp)
+            }
+        }
+
+        composeTestRule.onNodeWithText(context.getString(R.string.launch_by_default))
+            .assertIsNotEnabled()
+    }
+
+    private companion object {
+        const val PACKAGE_NAME = "package name"
+
+        val INSTALLED_ENABLED_APP = ApplicationInfo().apply {
+            packageName = PACKAGE_NAME
+            flags = ApplicationInfo.FLAG_INSTALLED
+            enabled = true
+        }
+    }
+}
diff --git a/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppStoragePreferenceTest.kt b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppStoragePreferenceTest.kt
index 39c3413..47f553b 100644
--- a/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppStoragePreferenceTest.kt
+++ b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppStoragePreferenceTest.kt
@@ -68,12 +68,12 @@
     }
 
     @Test
-    fun uninstalledApp_notDisplayed() {
-        val uninstalledApp = ApplicationInfo()
+    fun notInstalledApp_notDisplayed() {
+        val notInstalledApp = ApplicationInfo()
 
         composeTestRule.setContent {
             CompositionLocalProvider(LocalContext provides context) {
-                AppStoragePreference(uninstalledApp)
+                AppStoragePreference(notInstalledApp)
             }
         }
 
diff --git a/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppTimeSpentPreferenceTest.kt b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppTimeSpentPreferenceTest.kt
index 1842b83..e3fcdd9 100644
--- a/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppTimeSpentPreferenceTest.kt
+++ b/tests/spa_unit/src/com/android/settings/spa/app/appinfo/AppTimeSpentPreferenceTest.kt
@@ -120,15 +120,15 @@
     }
 
     @Test
-    fun uninstalledApp_disabled() {
+    fun notInstalledApp_disabled() {
         mockActivitiesQueryResult(listOf(MATCHED_RESOLVE_INFO))
-        val uninstalledApp = ApplicationInfo().apply {
+        val notInstalledApp = ApplicationInfo().apply {
             packageName = PACKAGE_NAME
         }
 
         composeTestRule.setContent {
             CompositionLocalProvider(LocalContext provides context) {
-                AppTimeSpentPreference(uninstalledApp)
+                AppTimeSpentPreference(notInstalledApp)
             }
         }
 
diff --git a/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java b/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
index 1a5e852..2826310 100644
--- a/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
+++ b/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java
@@ -21,19 +21,53 @@
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import android.content.Context;
+import android.content.res.Resources;
+import android.net.TetheringManager;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
 
+import androidx.test.core.app.ApplicationProvider;
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 
+import com.android.settings.R;
 import com.android.wifitrackerlib.WifiEntry;
 
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
 
 @RunWith(AndroidJUnit4.class)
 public class WifiUtilsTest {
 
+    static final String[] WIFI_REGEXS = {"wifi_regexs"};
+
+    @Rule
+    public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+    @Spy
+    Context mContext = ApplicationProvider.getApplicationContext();
+    @Mock
+    Resources mResources;
+    @Mock
+    WifiManager mWifiManager;
+    @Mock
+    TetheringManager mTetheringManager;
+
+    @Before
+    public void setUp() {
+        when(mContext.getResources()).thenReturn(mResources);
+        when(mResources.getBoolean(R.bool.config_show_wifi_hotspot_settings)).thenReturn(true);
+        when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
+        when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(WIFI_REGEXS);
+    }
+
     @Test
     public void testSSID() {
         assertThat(WifiUtils.isSSIDTooLong("123")).isFalse();
@@ -108,4 +142,53 @@
         WifiConfiguration config = WifiUtils.getWifiConfig(null /* wifiEntry */,
                 null /* scanResult */);
     }
+
+    @Test
+    public void checkShowWifiHotspot_allReady_returnTrue() {
+        assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isTrue();
+    }
+
+    @Test
+    public void checkShowWifiHotspot_contextIsNull_returnFalse() {
+        assertThat(WifiUtils.checkShowWifiHotspot(null)).isFalse();
+    }
+
+    @Test
+    public void checkShowWifiHotspot_configIsNotShow_returnFalse() {
+        when(mResources.getBoolean(R.bool.config_show_wifi_hotspot_settings)).thenReturn(false);
+
+        assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
+    }
+
+    @Test
+    public void checkShowWifiHotspot_wifiManagerIsNull_returnFalse() {
+        when(mContext.getSystemService(WifiManager.class)).thenReturn(null);
+
+        assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
+    }
+
+    @Test
+    public void checkShowWifiHotspot_tetheringManagerIsNull_returnFalse() {
+        when(mContext.getSystemService(TetheringManager.class)).thenReturn(null);
+
+        assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
+    }
+
+    @Test
+    public void checkShowWifiHotspot_wifiRegexsIsEmpty_returnFalse() {
+        when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(null);
+
+        assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
+    }
+
+    @Test
+    public void canShowWifiHotspot_cachedIsReady_returnCached() {
+        WifiUtils.setCanShowWifiHotspotCached(true);
+
+        assertThat(WifiUtils.canShowWifiHotspot(null)).isTrue();
+
+        WifiUtils.setCanShowWifiHotspotCached(false);
+
+        assertThat(WifiUtils.canShowWifiHotspot(null)).isFalse();
+    }
 }