Merge "Remove "Hotspot" key from settings search if not needed" into tm-qpr-dev
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 012996b..18c7855 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -20,6 +20,7 @@
import static android.net.ConnectivityManager.TETHERING_USB;
import static android.net.TetheringManager.TETHERING_ETHERNET;
+import static com.android.settings.wifi.WifiUtils.canShowWifiHotspot;
import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfUsbDataSignalingIsDisabled;
import android.app.Activity;
@@ -589,6 +590,9 @@
if (!TetherUtil.isTetherAvailable(context)) {
keys.add(KEY_TETHER_PREFS_SCREEN);
+ }
+
+ if (!canShowWifiHotspot(context) || !TetherUtil.isTetherAvailable(context)) {
keys.add(KEY_WIFI_TETHER);
}
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
index 1ff7746..a7ce16f 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
@@ -41,6 +41,7 @@
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SettingsMainSwitchBar;
+import com.android.settings.wifi.WifiUtils;
import com.android.settingslib.TetherUtil;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable;
@@ -292,12 +293,12 @@
@Override
protected boolean isPageSearchEnabled(Context context) {
+ if (context == null || !WifiUtils.canShowWifiHotspot(context)) return false;
return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
}
@Override
- public List<AbstractPreferenceController> createPreferenceControllers(
- Context context) {
+ public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, null /* listener */);
}
}
diff --git a/tests/robotests/src/com/android/settings/TetherSettingsTest.java b/tests/robotests/src/com/android/settings/TetherSettingsTest.java
index 71cb9d2..79814b3 100644
--- a/tests/robotests/src/com/android/settings/TetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/TetherSettingsTest.java
@@ -20,6 +20,8 @@
import static android.content.Intent.ACTION_MEDIA_UNSHARED;
import static android.hardware.usb.UsbManager.ACTION_USB_STATE;
+import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -93,6 +95,7 @@
any(String.class), anyInt(), any(UserHandle.class));
setupIsTetherAvailable(true);
+ setCanShowWifiHotspotCached(true);
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
@@ -124,6 +127,16 @@
}
@Test
+ public void getNonIndexableKeys_canNotShowWifiHotspot_containsWifiTether() {
+ setCanShowWifiHotspotCached(false);
+ setupIsTetherAvailable(true);
+
+ List<String> keys = TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
+
+ assertThat(keys).contains(TetherSettings.KEY_WIFI_TETHER);
+ }
+
+ @Test
public void testTetherNonIndexableKeys_usbNotAvailable_usbKeyReturned() {
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
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 6d3b879..7f8a06d 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -37,6 +37,7 @@
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserManager;
+import android.util.FeatureFlagUtils;
import android.widget.TextView;
import androidx.fragment.app.FragmentActivity;
@@ -44,6 +45,7 @@
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
+import com.android.settings.core.FeatureFlags;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowFragment;
@@ -93,6 +95,7 @@
@Before
public void setUp() {
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
setCanShowWifiHotspotCached(true);
doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
doReturn(mConnectivityManager)
@@ -218,6 +221,22 @@
assertThat(keys).contains(WifiTetherSettings.KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
}
+ @Test
+ public void isPageSearchEnabled_canShowWifiHotspot_returnTrue() {
+ setCanShowWifiHotspotCached(true);
+
+ assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.isPageSearchEnabled(mContext))
+ .isTrue();
+ }
+
+ @Test
+ public void isPageSearchEnabled_canNotShowWifiHotspot_returnFalse() {
+ setCanShowWifiHotspotCached(false);
+
+ assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.isPageSearchEnabled(mContext))
+ .isFalse();
+ }
+
private void spyWifiTetherSettings() {
mWifiTetherSettings = spy(new WifiTetherSettings(mWifiRestriction));
final FragmentActivity activity = mock(FragmentActivity.class);