diff --git a/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java index 37da38ec3c7..5a08c58d1f7 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java +++ b/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java @@ -16,6 +16,9 @@ package com.android.settings.wifi.tether; +import static android.net.wifi.WifiConfiguration.AP_BAND_2GHZ; +import static android.net.wifi.WifiConfiguration.AP_BAND_5GHZ; + import android.content.Context; import android.net.wifi.WifiConfiguration; import android.support.v7.preference.ListPreference; @@ -24,9 +27,6 @@ import android.support.v7.preference.PreferenceScreen; import com.android.settings.R; -import static android.net.wifi.WifiConfiguration.AP_BAND_2GHZ; -import static android.net.wifi.WifiConfiguration.AP_BAND_5GHZ; - public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferenceController { private static final String PREF_KEY = "wifi_tether_network_ap_band"; @@ -41,10 +41,14 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen super(context, listener); mBandEntries = mContext.getResources().getStringArray(R.array.wifi_ap_band_config_full); final WifiConfiguration config = mWifiManager.getWifiApConfiguration(); - if (config != null) { + if (config == null) { + mBandIndex = 0; + } else if (is5GhzBandSupported()) { mBandIndex = config.apBand; } else { - mBandIndex = 0; + config.apBand = 0; + mWifiManager.setWifiApConfiguration(config); + mBandIndex = config.apBand; } } @@ -77,10 +81,11 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen } private boolean is5GhzBandSupported() { - if (mBandIndex > 0) { - return true; + final String countryCode = mWifiManager.getCountryCode(); + if (!mWifiManager.isDualBandSupported() || countryCode == null) { + return false; } - return mWifiManager.is5GHzBandSupported(); + return true; } public int getBandIndex() { 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 a7e00ab544e..8f0b143ae02 100644 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java @@ -16,6 +16,12 @@ package com.android.settings.wifi.tether; +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import android.content.Context; import android.net.ConnectivityManager; import android.net.wifi.WifiManager; @@ -35,12 +41,6 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; -import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) public class WifiTetherApBandPreferenceControllerTest { @@ -75,16 +75,30 @@ public class WifiTetherApBandPreferenceControllerTest { @Test public void display_5GhzSupported_shouldDisplayFullList() { - when(mWifiManager.is5GHzBandSupported()).thenReturn(true); + when(mWifiManager.getCountryCode()).thenReturn("US"); + when(mWifiManager.isDualBandSupported()).thenReturn(true); mController.displayPreference(mScreen); assertThat(mListPreference.getEntries().length).isEqualTo(2); } + @Test + public void display_noCountryCode_shouldDisable() { + when(mWifiManager.getCountryCode()).thenReturn(null); + when(mWifiManager.isDualBandSupported()).thenReturn(true); + + mController.displayPreference(mScreen); + + assertThat(mListPreference.getEntries()).isNull(); + assertThat(mListPreference.isEnabled()).isFalse(); + assertThat(mListPreference.getSummary()) + .isEqualTo(RuntimeEnvironment.application.getString(R.string.wifi_ap_choose_2G)); + } + @Test public void display_5GhzNotSupported_shouldDisable() { - when(mWifiManager.is5GHzBandSupported()).thenReturn(false); + when(mWifiManager.isDualBandSupported()).thenReturn(false); mController.displayPreference(mScreen);