Update Wifi Tether band selection UI
This CL updates the preference for selecting the enabled tether bands to allow individual selection of multiple bands instead of forcing a single selection. Note that while this makes the UI theoretically support new bands in the future, the wifi backend only supports selecting a single band or all bands which this CL does not address. Test: robotests Bug: 73102003 Change-Id: Ib2d4a2834c5cd11875515d308f7b20bfc8471959
This commit is contained in:
@@ -24,12 +24,13 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.HotspotApBandSelectionPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -42,6 +43,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class WifiTetherApBandPreferenceControllerTest {
|
||||
|
||||
private static final String ALL_BANDS = "2.4 GHz and 5.0 GHz";
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
@@ -54,18 +56,21 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private WifiTetherApBandPreferenceController mController;
|
||||
private ListPreference mListPreference;
|
||||
private HotspotApBandSelectionPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mListPreference = new ListPreference(RuntimeEnvironment.application);
|
||||
mPreference = new HotspotApBandSelectionPreference(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.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mListPreference);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.apBand = WifiConfiguration.AP_BAND_ANY;
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(new WifiConfiguration());
|
||||
|
||||
mController = new WifiTetherApBandPreferenceController(mContext, mListener);
|
||||
}
|
||||
@@ -76,8 +81,9 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
when(mWifiManager.isDualBandSupported()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, -1);
|
||||
|
||||
assertThat(mListPreference.getEntries().length).isEqualTo(3);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,9 +93,8 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mListPreference.getEntries()).isNull();
|
||||
assertThat(mListPreference.isEnabled()).isFalse();
|
||||
assertThat(mListPreference.getSummary())
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(RuntimeEnvironment.application.getString(R.string.wifi_ap_choose_2G));
|
||||
}
|
||||
|
||||
@@ -99,9 +104,8 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mListPreference.getEntries()).isNull();
|
||||
assertThat(mListPreference.isEnabled()).isFalse();
|
||||
assertThat(mListPreference.getSummary())
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(RuntimeEnvironment.application.getString(R.string.wifi_ap_choose_2G));
|
||||
}
|
||||
|
||||
@@ -112,14 +116,17 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
// -1 is WifiConfiguration.AP_BAND_ANY, for 'Auto' option.
|
||||
mController.onPreferenceChange(mListPreference, "-1");
|
||||
mController.onPreferenceChange(mPreference, -1);
|
||||
assertThat(mController.getBandIndex()).isEqualTo(-1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
|
||||
|
||||
mController.onPreferenceChange(mListPreference, "1");
|
||||
mController.onPreferenceChange(mPreference, 1);
|
||||
assertThat(mController.getBandIndex()).isEqualTo(1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo("5.0 GHz");
|
||||
|
||||
mController.onPreferenceChange(mListPreference, "0");
|
||||
mController.onPreferenceChange(mPreference, 0);
|
||||
assertThat(mController.getBandIndex()).isEqualTo(0);
|
||||
assertThat(mPreference.getSummary()).isEqualTo("2.4 GHz");
|
||||
|
||||
verify(mListener, times(3)).onTetherConfigUpdated();
|
||||
}
|
||||
@@ -129,7 +136,7 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
// Set controller band index to 1 and verify is set.
|
||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mListPreference, "1");
|
||||
mController.onPreferenceChange(mPreference, 1);
|
||||
assertThat(mController.getBandIndex()).isEqualTo(1);
|
||||
|
||||
// Disable 5Ghz band
|
||||
|
||||
Reference in New Issue
Block a user