Merge "Revert back to isDualBandSupported() for Wifi tethering." into oc-mr1-dev

am: b975e352a2

Change-Id: I883ab8568ae0393e86de770af08cf7779f18b595
This commit is contained in:
Rebecca Silberstein
2017-09-13 08:38:14 +00:00
committed by android-build-merger
2 changed files with 35 additions and 16 deletions

View File

@@ -16,6 +16,9 @@
package com.android.settings.wifi.tether; 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.content.Context;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.support.v7.preference.ListPreference; import android.support.v7.preference.ListPreference;
@@ -24,9 +27,6 @@ import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R; 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 { public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferenceController {
private static final String PREF_KEY = "wifi_tether_network_ap_band"; private static final String PREF_KEY = "wifi_tether_network_ap_band";
@@ -41,10 +41,14 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
super(context, listener); super(context, listener);
mBandEntries = mContext.getResources().getStringArray(R.array.wifi_ap_band_config_full); mBandEntries = mContext.getResources().getStringArray(R.array.wifi_ap_band_config_full);
final WifiConfiguration config = mWifiManager.getWifiApConfiguration(); final WifiConfiguration config = mWifiManager.getWifiApConfiguration();
if (config != null) { if (config == null) {
mBandIndex = 0;
} else if (is5GhzBandSupported()) {
mBandIndex = config.apBand; mBandIndex = config.apBand;
} else { } else {
mBandIndex = 0; config.apBand = 0;
mWifiManager.setWifiApConfiguration(config);
mBandIndex = config.apBand;
} }
} }
@@ -77,10 +81,11 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
} }
private boolean is5GhzBandSupported() { private boolean is5GhzBandSupported() {
if (mBandIndex > 0) { final String countryCode = mWifiManager.getCountryCode();
return true; if (!mWifiManager.isDualBandSupported() || countryCode == null) {
return false;
} }
return mWifiManager.is5GHzBandSupported(); return true;
} }
public int getBandIndex() { public int getBandIndex() {

View File

@@ -16,6 +16,12 @@
package com.android.settings.wifi.tether; 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.content.Context;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
@@ -35,12 +41,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; 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) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class WifiTetherApBandPreferenceControllerTest { public class WifiTetherApBandPreferenceControllerTest {
@@ -75,16 +75,30 @@ public class WifiTetherApBandPreferenceControllerTest {
@Test @Test
public void display_5GhzSupported_shouldDisplayFullList() { public void display_5GhzSupported_shouldDisplayFullList() {
when(mWifiManager.is5GHzBandSupported()).thenReturn(true); when(mWifiManager.getCountryCode()).thenReturn("US");
when(mWifiManager.isDualBandSupported()).thenReturn(true);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
assertThat(mListPreference.getEntries().length).isEqualTo(2); 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 @Test
public void display_5GhzNotSupported_shouldDisable() { public void display_5GhzNotSupported_shouldDisable() {
when(mWifiManager.is5GHzBandSupported()).thenReturn(false); when(mWifiManager.isDualBandSupported()).thenReturn(false);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);