Merge "Implement createPrefControllers for tether page"
This commit is contained in:
committed by
Android (Google) Code Review
commit
ac03e735df
@@ -99,6 +99,11 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
super.onAttach(context);
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
mTetherChangeReceiver = new TetherChangeReceiver();
|
||||
|
||||
mSSIDPreferenceController = use(WifiTetherSSIDPreferenceController.class);
|
||||
mSecurityPreferenceController = use(WifiTetherSecurityPreferenceController.class);
|
||||
mPasswordPreferenceController = use(WifiTetherPasswordPreferenceController.class);
|
||||
mApBandPreferenceController = use(WifiTetherApBandPreferenceController.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,18 +145,17 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
mSSIDPreferenceController = new WifiTetherSSIDPreferenceController(context, this);
|
||||
mSecurityPreferenceController = new WifiTetherSecurityPreferenceController(context, this);
|
||||
mPasswordPreferenceController = new WifiTetherPasswordPreferenceController(context, this);
|
||||
mApBandPreferenceController = new WifiTetherApBandPreferenceController(context, this);
|
||||
return buildPreferenceControllers(context, this::onTetherConfigUpdated);
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
WifiTetherBasePreferenceController.OnTetherConfigUpdateListener listener) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new WifiTetherSSIDPreferenceController(context, listener));
|
||||
controllers.add(new WifiTetherSecurityPreferenceController(context, listener));
|
||||
controllers.add(new WifiTetherPasswordPreferenceController(context, listener));
|
||||
controllers.add(new WifiTetherApBandPreferenceController(context, listener));
|
||||
|
||||
controllers.add(mSSIDPreferenceController);
|
||||
controllers.add(mSecurityPreferenceController);
|
||||
controllers.add(mPasswordPreferenceController);
|
||||
controllers.add(mApBandPreferenceController);
|
||||
controllers.add(
|
||||
new WifiTetherAutoOffPreferenceController(context, KEY_WIFI_TETHER_AUTO_OFF));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@@ -227,6 +231,12 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
keys.add(KEY_WIFI_TETHER_SCREEN);
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||
Context context) {
|
||||
return buildPreferenceControllers(context, null /* listener */);
|
||||
}
|
||||
};
|
||||
|
||||
@VisibleForTesting
|
||||
|
@@ -52,6 +52,11 @@ public class ShadowWifiManager extends org.robolectric.shadows.ShadowWifiManager
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public boolean isDualModeSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ShadowWifiManager get() {
|
||||
return Shadow.extract(application.getSystemService(WifiManager.class));
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -27,6 +28,7 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowWifiManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -34,12 +36,15 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowWifiManager.class})
|
||||
public class WifiTetherSettingsTest {
|
||||
private static final String[] WIFI_REGEXS = {"wifi_regexs"};
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -55,12 +60,12 @@ public class WifiTetherSettingsTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
doReturn(mConnectivityManager)
|
||||
.when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
doReturn(mUserManager)
|
||||
.when(mContext).getSystemService(Context.USER_SERVICE);
|
||||
doReturn(WIFI_REGEXS).when(mConnectivityManager).getTetherableWifiRegexs();
|
||||
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWifiTetherNonIndexableKeys_tetherAvailable_keysNotReturned() {
|
||||
public void wifiTetherNonIndexableKeys_tetherAvailable_keysNotReturned() {
|
||||
// To let TetherUtil.isTetherAvailable return true, select one of the combinations
|
||||
setupIsTetherAvailable(true);
|
||||
|
||||
@@ -74,7 +79,7 @@ public class WifiTetherSettingsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWifiTetherNonIndexableKeys_tetherNotAvailable_keysReturned() {
|
||||
public void wifiTetherNonIndexableKeys_tetherNotAvailable_keysReturned() {
|
||||
// To let TetherUtil.isTetherAvailable return false, select one of the combinations
|
||||
setupIsTetherAvailable(false);
|
||||
|
||||
@@ -87,6 +92,12 @@ public class WifiTetherSettingsTest {
|
||||
assertThat(niks).contains(WifiTetherSettings.KEY_WIFI_TETHER_NETWORK_AP_BAND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPreferenceControllers_notEmpty() {
|
||||
assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getPreferenceControllers(mContext))
|
||||
.isNotEmpty();
|
||||
}
|
||||
|
||||
private void setupIsTetherAvailable(boolean returnValue) {
|
||||
when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
|
||||
|
||||
|
Reference in New Issue
Block a user