Wifi Setting: Use SoftApConfiguration for Tether Setting
Bug: 145578449 Test: Manual Test: make RunSettingsRoboTests ROBOTEST_FILTER=CodeInspectionTest Change-Id: I02b4dcbb7b6e29b67ecc7356200f3fc3a1007562
This commit is contained in:
@@ -229,7 +229,7 @@
|
||||
<!-- Values for security type for wireless tether -->
|
||||
<string-array name="wifi_tether_security_values" translatable="false">
|
||||
<!-- Do not translate. -->
|
||||
<item>4</item>
|
||||
<item>1</item>
|
||||
<!-- Do not translate. -->
|
||||
<item>0</item>
|
||||
</string-array>
|
||||
|
@@ -18,7 +18,7 @@ package com.android.settings.deviceinfo;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -160,10 +160,10 @@ public class DeviceNamePreferenceController extends BasePreferenceController
|
||||
}
|
||||
|
||||
private void setTetherSsidName(String deviceName) {
|
||||
final WifiConfiguration config = mWifiManager.getWifiApConfiguration();
|
||||
config.SSID = deviceName;
|
||||
final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
|
||||
// TODO: If tether is running, turn off the AP and restart it after setting config.
|
||||
mWifiManager.setWifiApConfiguration(config);
|
||||
mWifiManager.setSoftApConfiguration(
|
||||
new SoftApConfiguration.Builder(config).setSsid(deviceName).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,4 +181,4 @@ public class DeviceNamePreferenceController extends BasePreferenceController
|
||||
public interface DeviceNamePreferenceHost {
|
||||
void showDeviceNameWarningDialog(String deviceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -114,13 +114,12 @@ public class HotspotConditionController implements ConditionalCardController {
|
||||
}
|
||||
|
||||
private CharSequence getSsid() {
|
||||
WifiConfiguration wifiConfig = mWifiManager.getWifiApConfiguration();
|
||||
if (wifiConfig == null) {
|
||||
final SoftApConfiguration softApConfig = mWifiManager.getSoftApConfiguration();
|
||||
if (softApConfig == null) {
|
||||
// Should never happen.
|
||||
return "";
|
||||
} else {
|
||||
return wifiConfig.SSID;
|
||||
}
|
||||
return softApConfig.getSsid();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver {
|
||||
|
@@ -20,8 +20,9 @@ import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.biometrics.BiometricPrompt;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.Handler;
|
||||
@@ -31,12 +32,10 @@ import android.os.Vibrator;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Here are the items shared by both WifiDppConfiguratorActivity & WifiDppEnrolleeActivity
|
||||
@@ -248,19 +247,42 @@ public class WifiDppUtils {
|
||||
*
|
||||
* @param context The context to use for the content resolver
|
||||
* @param wifiManager An instance of {@link WifiManager}
|
||||
* @param wifiConfiguration {@link WifiConfiguration} of the Wi-Fi hotspot
|
||||
* @param softApConfiguration {@link SoftApConfiguration} of the Wi-Fi hotspot
|
||||
* @return Intent for launching QR code generator
|
||||
*/
|
||||
public static Intent getHotspotConfiguratorIntentOrNull(Context context,
|
||||
WifiManager wifiManager, WifiConfiguration wifiConfiguration) {
|
||||
WifiManager wifiManager, SoftApConfiguration softApConfiguration) {
|
||||
final Intent intent = new Intent(context, WifiDppConfiguratorActivity.class);
|
||||
if (isSupportHotspotConfiguratorQrCodeGenerator(wifiConfiguration)) {
|
||||
if (isSupportHotspotConfiguratorQrCodeGenerator(softApConfiguration)) {
|
||||
intent.setAction(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
setConfiguratorIntentExtra(intent, wifiManager, wifiConfiguration);
|
||||
final String ssid = removeFirstAndLastDoubleQuotes(softApConfiguration.getSsid());
|
||||
String security;
|
||||
if (softApConfiguration.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK) {
|
||||
security = WifiQrCode.SECURITY_WPA_PSK;
|
||||
} else {
|
||||
security = WifiQrCode.SECURITY_NO_PASSWORD;
|
||||
}
|
||||
|
||||
// When the value of this key is read, the actual key is not returned, just a "*".
|
||||
// Call privileged system API to obtain actual key.
|
||||
final String preSharedKey = removeFirstAndLastDoubleQuotes(
|
||||
softApConfiguration.getWpa2Passphrase());
|
||||
|
||||
if (!TextUtils.isEmpty(ssid)) {
|
||||
intent.putExtra(EXTRA_WIFI_SSID, ssid);
|
||||
}
|
||||
if (!TextUtils.isEmpty(security)) {
|
||||
intent.putExtra(EXTRA_WIFI_SECURITY, security);
|
||||
}
|
||||
if (!TextUtils.isEmpty(preSharedKey)) {
|
||||
intent.putExtra(EXTRA_WIFI_PRE_SHARED_KEY, preSharedKey);
|
||||
}
|
||||
intent.putExtra(EXTRA_WIFI_HIDDEN_SSID, softApConfiguration.isHiddenSsid());
|
||||
|
||||
|
||||
intent.putExtra(EXTRA_WIFI_NETWORK_ID, WifiConfiguration.INVALID_NETWORK_ID);
|
||||
intent.putExtra(EXTRA_IS_HOTSPOT, true);
|
||||
@@ -383,12 +405,12 @@ public class WifiDppUtils {
|
||||
}
|
||||
|
||||
private static boolean isSupportHotspotConfiguratorQrCodeGenerator(
|
||||
WifiConfiguration wifiConfiguration) {
|
||||
SoftApConfiguration softApConfiguration) {
|
||||
// QR code generator produces QR code with ZXing's Wi-Fi network config format,
|
||||
// it supports PSK and WEP and non security
|
||||
// KeyMgmt.NONE is for WEP or non security
|
||||
return wifiConfiguration.allowedKeyManagement.get(KeyMgmt.WPA2_PSK) ||
|
||||
wifiConfiguration.allowedKeyManagement.get(KeyMgmt.NONE);
|
||||
return softApConfiguration.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK
|
||||
|| softApConfiguration.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_OPEN;
|
||||
}
|
||||
|
||||
private static boolean isSupportWifiDpp(Context context, int accesspointSecurity) {
|
||||
|
@@ -18,7 +18,7 @@ package com.android.settings.wifi.tether;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -46,17 +46,17 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
final WifiConfiguration config = mWifiManager.getWifiApConfiguration();
|
||||
final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
|
||||
if (config == null) {
|
||||
mBandIndex = 0;
|
||||
Log.d(TAG, "Updating band index to 0 because no config");
|
||||
} else if (is5GhzBandSupported()) {
|
||||
mBandIndex = validateSelection(config.apBand);
|
||||
mBandIndex = validateSelection(config.getBand());
|
||||
Log.d(TAG, "Updating band index to " + mBandIndex);
|
||||
} else {
|
||||
config.apBand = 0;
|
||||
mWifiManager.setWifiApConfiguration(config);
|
||||
mBandIndex = config.apBand;
|
||||
mWifiManager.setSoftApConfiguration(
|
||||
new SoftApConfiguration.Builder(config).setBand(0).build());
|
||||
mBandIndex = config.getBand();
|
||||
Log.d(TAG, "5Ghz not supported, updating band index to " + mBandIndex);
|
||||
}
|
||||
ListPreference preference =
|
||||
@@ -68,13 +68,13 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
|
||||
preference.setEnabled(false);
|
||||
preference.setSummary(R.string.wifi_ap_choose_2G);
|
||||
} else {
|
||||
preference.setValue(Integer.toString(config.apBand));
|
||||
preference.setValue(Integer.toString(config.getBand()));
|
||||
preference.setSummary(getConfigSummary());
|
||||
}
|
||||
}
|
||||
|
||||
String getConfigSummary() {
|
||||
if (mBandIndex == WifiConfiguration.AP_BAND_ANY) {
|
||||
if (mBandIndex == SoftApConfiguration.BAND_ANY) {
|
||||
return mContext.getString(R.string.wifi_ap_prefer_5G);
|
||||
}
|
||||
return mBandSummaries[mBandIndex];
|
||||
@@ -102,12 +102,12 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
|
||||
// 1: no dual mode means we can't have AP_BAND_ANY - default to 5GHZ
|
||||
// 2: no 5 GHZ support means we can't have AP_BAND_5GHZ - default to 2GHZ
|
||||
// 3: With Dual mode support we can't have AP_BAND_5GHZ - default to ANY
|
||||
if (!isDualMode && WifiConfiguration.AP_BAND_ANY == band) {
|
||||
return WifiConfiguration.AP_BAND_5GHZ;
|
||||
} else if (!is5GhzBandSupported() && WifiConfiguration.AP_BAND_5GHZ == band) {
|
||||
return WifiConfiguration.AP_BAND_2GHZ;
|
||||
} else if (isDualMode && WifiConfiguration.AP_BAND_5GHZ == band) {
|
||||
return WifiConfiguration.AP_BAND_ANY;
|
||||
if (!isDualMode && SoftApConfiguration.BAND_ANY == band) {
|
||||
return SoftApConfiguration.BAND_5GHZ;
|
||||
} else if (!is5GhzBandSupported() && SoftApConfiguration.BAND_5GHZ == band) {
|
||||
return SoftApConfiguration.BAND_2GHZ;
|
||||
} else if (isDualMode && SoftApConfiguration.BAND_5GHZ == band) {
|
||||
return SoftApConfiguration.BAND_ANY;
|
||||
}
|
||||
|
||||
return band;
|
||||
|
@@ -17,7 +17,7 @@
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.EditTextPreference;
|
||||
@@ -48,12 +48,13 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
final WifiConfiguration config = mWifiManager.getWifiApConfiguration();
|
||||
if (config == null || (config.getAuthType() == WifiConfiguration.KeyMgmt.WPA2_PSK
|
||||
&& TextUtils.isEmpty(config.preSharedKey))) {
|
||||
final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
|
||||
if (config == null
|
||||
|| (config.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK
|
||||
&& TextUtils.isEmpty(config.getWpa2Passphrase()))) {
|
||||
mPassword = generateRandomPassword();
|
||||
} else {
|
||||
mPassword = config.preSharedKey;
|
||||
mPassword = config.getWpa2Passphrase();
|
||||
}
|
||||
((ValidatedEditTextPreference) mPreference).setValidator(this);
|
||||
((ValidatedEditTextPreference) mPreference).setIsPassword(true);
|
||||
@@ -79,7 +80,7 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
||||
*/
|
||||
public String getPasswordValidated(int securityType) {
|
||||
// don't actually overwrite unless we get a new config in case it was accidentally toggled.
|
||||
if (securityType == WifiConfiguration.KeyMgmt.NONE) {
|
||||
if (securityType == SoftApConfiguration.SECURITY_TYPE_OPEN) {
|
||||
return "";
|
||||
} else if (!isTextValid(mPassword)) {
|
||||
mPassword = generateRandomPassword();
|
||||
@@ -89,7 +90,7 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
||||
}
|
||||
|
||||
public void updateVisibility(int securityType) {
|
||||
mPreference.setVisible(securityType != WifiConfiguration.KeyMgmt.NONE);
|
||||
mPreference.setVisible(securityType != SoftApConfiguration.SECURITY_TYPE_OPEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -19,8 +19,8 @@ package com.android.settings.wifi.tether;
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiClient;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.text.BidiFormatter;
|
||||
|
||||
@@ -147,8 +147,8 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||
mPreference.setSummary(R.string.wifi_tether_starting);
|
||||
break;
|
||||
case WifiManager.WIFI_AP_STATE_ENABLED:
|
||||
WifiConfiguration wifiConfig = mWifiManager.getWifiApConfiguration();
|
||||
updateConfigSummary(wifiConfig);
|
||||
final SoftApConfiguration softApConfig = mWifiManager.getSoftApConfiguration();
|
||||
updateConfigSummary(softApConfig);
|
||||
break;
|
||||
case WifiManager.WIFI_AP_STATE_DISABLING:
|
||||
mPreference.setSummary(R.string.wifi_tether_stopping);
|
||||
@@ -165,12 +165,12 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfigSummary(@NonNull WifiConfiguration wifiConfig) {
|
||||
if (wifiConfig == null) {
|
||||
private void updateConfigSummary(@NonNull SoftApConfiguration softApConfig) {
|
||||
if (softApConfig == null) {
|
||||
// Should never happen.
|
||||
return;
|
||||
}
|
||||
mPreference.setSummary(mContext.getString(R.string.wifi_tether_enabled_subtext,
|
||||
BidiFormatter.getInstance().unicodeWrap(wifiConfig.SSID)));
|
||||
BidiFormatter.getInstance().unicodeWrap(softApConfig.getSsid())));
|
||||
}
|
||||
}
|
||||
|
@@ -19,19 +19,16 @@ package com.android.settings.wifi.tether;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.EditTextPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
import com.android.settings.wifi.dpp.WifiDppUtils;
|
||||
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreferenceController
|
||||
@@ -62,9 +59,9 @@ public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreference
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
final WifiConfiguration config = mWifiManager.getWifiApConfiguration();
|
||||
final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
|
||||
if (config != null) {
|
||||
mSSID = config.SSID;
|
||||
mSSID = config.getSsid();
|
||||
} else {
|
||||
mSSID = DEFAULT_SSID;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
@@ -28,12 +28,11 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
final WifiConfiguration config = mWifiManager.getWifiApConfiguration();
|
||||
if (config != null && config.getAuthType() == WifiConfiguration.KeyMgmt.NONE) {
|
||||
mSecurityValue = WifiConfiguration.KeyMgmt.NONE;
|
||||
|
||||
final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
|
||||
if (config != null && config.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_OPEN) {
|
||||
mSecurityValue = SoftApConfiguration.SECURITY_TYPE_OPEN;
|
||||
} else {
|
||||
mSecurityValue = WifiConfiguration.KeyMgmt.WPA2_PSK;
|
||||
mSecurityValue = SoftApConfiguration.SECURITY_TYPE_WPA2_PSK;
|
||||
}
|
||||
|
||||
final ListPreference preference = (ListPreference) mPreference;
|
||||
@@ -54,7 +53,7 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
|
||||
}
|
||||
|
||||
private String getSummaryForSecurityType(int securityType) {
|
||||
if (securityType == WifiConfiguration.KeyMgmt.NONE) {
|
||||
if (securityType == SoftApConfiguration.SECURITY_TYPE_OPEN) {
|
||||
return mSecurityEntries[1];
|
||||
}
|
||||
// WPA2 PSK
|
||||
|
@@ -24,14 +24,15 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||
@@ -41,8 +42,8 @@ import com.android.settings.widget.SwitchBarController;
|
||||
import com.android.settingslib.TetherUtil;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
@@ -187,8 +188,8 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
|
||||
@Override
|
||||
public void onTetherConfigUpdated(AbstractPreferenceController context) {
|
||||
final WifiConfiguration config = buildNewConfig();
|
||||
mPasswordPreferenceController.updateVisibility(config.getAuthType());
|
||||
final SoftApConfiguration config = buildNewConfig();
|
||||
mPasswordPreferenceController.updateVisibility(config.getSecurityType());
|
||||
|
||||
/**
|
||||
* if soft AP is stopped, bring up
|
||||
@@ -201,23 +202,23 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
mRestartWifiApAfterConfigChange = true;
|
||||
mSwitchBarController.stopTether();
|
||||
}
|
||||
mWifiManager.setWifiApConfiguration(config);
|
||||
mWifiManager.setSoftApConfiguration(config);
|
||||
|
||||
if (context instanceof WifiTetherSecurityPreferenceController) {
|
||||
reConfigInitialExpandedChildCount();
|
||||
}
|
||||
}
|
||||
|
||||
private WifiConfiguration buildNewConfig() {
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
private SoftApConfiguration buildNewConfig() {
|
||||
final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
|
||||
final int securityType = mSecurityPreferenceController.getSecurityType();
|
||||
|
||||
config.SSID = mSSIDPreferenceController.getSSID();
|
||||
config.allowedKeyManagement.set(securityType);
|
||||
config.preSharedKey = mPasswordPreferenceController.getPasswordValidated(securityType);
|
||||
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
|
||||
config.apBand = mApBandPreferenceController.getBandIndex();
|
||||
return config;
|
||||
configBuilder.setSsid(mSSIDPreferenceController.getSSID());
|
||||
if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK) {
|
||||
configBuilder.setWpa2Passphrase(
|
||||
mPasswordPreferenceController.getPasswordValidated(securityType));
|
||||
}
|
||||
configBuilder.setBand(mApBandPreferenceController.getBandIndex());
|
||||
return configBuilder.build();
|
||||
}
|
||||
|
||||
private void startTether() {
|
||||
@@ -286,7 +287,8 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
|
||||
private void reConfigInitialExpandedChildCount() {
|
||||
final PreferenceGroup screen = getPreferenceScreen();
|
||||
if (mSecurityPreferenceController.getSecurityType() == WifiConfiguration.KeyMgmt.NONE) {
|
||||
if (mSecurityPreferenceController.getSecurityType()
|
||||
== SoftApConfiguration.SECURITY_TYPE_OPEN) {
|
||||
screen.setInitialExpandedChildrenCount(EXPANDED_CHILD_COUNT_WITH_SECURITY_NON);
|
||||
return;
|
||||
}
|
||||
@@ -299,7 +301,8 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
return EXPANDED_CHILD_COUNT_DEFAULT;
|
||||
}
|
||||
|
||||
return (mSecurityPreferenceController.getSecurityType() == WifiConfiguration.KeyMgmt.NONE) ?
|
||||
EXPANDED_CHILD_COUNT_WITH_SECURITY_NON : EXPANDED_CHILD_COUNT_DEFAULT;
|
||||
return (mSecurityPreferenceController.getSecurityType()
|
||||
== SoftApConfiguration.SECURITY_TYPE_OPEN)
|
||||
? EXPANDED_CHILD_COUNT_WITH_SECURITY_NON : EXPANDED_CHILD_COUNT_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
@@ -71,9 +71,9 @@ public class DeviceNamePreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreference = new ValidatedEditTextPreference(mContext);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
final WifiConfiguration configuration = new WifiConfiguration();
|
||||
configuration.SSID = "test-ap";
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(configuration);
|
||||
final SoftApConfiguration configuration =
|
||||
new SoftApConfiguration.Builder().setSsid("test-ap").build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(configuration);
|
||||
|
||||
mController = new DeviceNamePreferenceController(mContext, "test_key");
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
@@ -137,9 +137,10 @@ public class DeviceNamePreferenceControllerTest {
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, TESTING_STRING);
|
||||
|
||||
ArgumentCaptor<WifiConfiguration> captor = ArgumentCaptor.forClass(WifiConfiguration.class);
|
||||
verify(mWifiManager).setWifiApConfiguration(captor.capture());
|
||||
assertThat(captor.getValue().SSID).isEqualTo(TESTING_STRING);
|
||||
ArgumentCaptor<SoftApConfiguration> captor =
|
||||
ArgumentCaptor.forClass(SoftApConfiguration.class);
|
||||
verify(mWifiManager).setSoftApConfiguration(captor.capture());
|
||||
assertThat(captor.getValue().getSsid()).isEqualTo(TESTING_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -19,7 +19,7 @@ package com.android.settings.homepage.contextualcards.conditional;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||
@@ -53,7 +53,7 @@ public class HotspotConditionControllerTest {
|
||||
|
||||
@Test
|
||||
public void buildContextualCard_hasWifiAp_shouldHaveWifiApSsid() {
|
||||
setupWifiApConfiguration();
|
||||
setupSoftApConfiguration();
|
||||
|
||||
final ContextualCard card = mController.buildContextualCard();
|
||||
|
||||
@@ -67,9 +67,9 @@ public class HotspotConditionControllerTest {
|
||||
assertThat(card.getSummaryText()).isEqualTo("");
|
||||
}
|
||||
|
||||
private void setupWifiApConfiguration() {
|
||||
final WifiConfiguration wifiApConfig = new WifiConfiguration();
|
||||
wifiApConfig.SSID = WIFI_AP_SSID;
|
||||
mContext.getSystemService(WifiManager.class).setWifiApConfiguration(wifiApConfig);
|
||||
private void setupSoftApConfiguration() {
|
||||
final SoftApConfiguration wifiApConfig = new SoftApConfiguration.Builder()
|
||||
.setSsid(WIFI_AP_SSID).build();
|
||||
mContext.getSystemService(WifiManager.class).setSoftApConfiguration(wifiApConfig);
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.testutils.shadow;
|
||||
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.hotspot2.PasspointConfiguration;
|
||||
@@ -37,16 +38,16 @@ public class ShadowWifiManager extends org.robolectric.shadows.ShadowWifiManager
|
||||
private List<PasspointConfiguration> mPasspointConfiguration;
|
||||
|
||||
public WifiConfiguration savedWifiConfig;
|
||||
private WifiConfiguration mSavedApConfig;
|
||||
private SoftApConfiguration mSavedApConfig;
|
||||
|
||||
@Implementation
|
||||
protected WifiConfiguration getWifiApConfiguration() {
|
||||
protected SoftApConfiguration getSoftApConfiguration() {
|
||||
return mSavedApConfig;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected boolean setWifiApConfiguration(WifiConfiguration wifiConfig) {
|
||||
mSavedApConfig = wifiConfig;
|
||||
protected boolean setSoftApConfiguration(SoftApConfiguration softApConfig) {
|
||||
mSavedApConfig = softApConfig;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -26,7 +26,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
@@ -72,9 +72,8 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
|
||||
when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.apBand = WifiConfiguration.AP_BAND_ANY;
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(new WifiConfiguration());
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(
|
||||
new SoftApConfiguration.Builder().build());
|
||||
when(mWifiManager.isDualModeSupported()).thenReturn(false);
|
||||
|
||||
mController = new WifiTetherApBandPreferenceController(mContext, mListener);
|
||||
@@ -123,7 +122,7 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
// -1 is WifiConfiguration.AP_BAND_ANY, for 'Auto' option. This should be prevented from
|
||||
// -1 is SoftApConfiguration.BAND_ANY, for 'Auto' option. This should be prevented from
|
||||
// being set since it is invalid for this configuration
|
||||
mController.onPreferenceChange(mPreference, "-1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(1);
|
||||
@@ -151,7 +150,7 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
// -1 is WifiConfiguration.AP_BAND_ANY, for 'Auto' option.
|
||||
// -1 is SoftApConfiguration.BAND_ANY, for 'Auto' option.
|
||||
mController.onPreferenceChange(mPreference, "-1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(-1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
|
||||
|
@@ -25,7 +25,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -59,18 +59,17 @@ public class WifiTetherPasswordPreferenceControllerTest {
|
||||
|
||||
private WifiTetherPasswordPreferenceController mController;
|
||||
private ValidatedEditTextPreference mPreference;
|
||||
private WifiConfiguration mConfig;
|
||||
private SoftApConfiguration mConfig;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mPreference = new ValidatedEditTextPreference(RuntimeEnvironment.application);
|
||||
mConfig = new WifiConfiguration();
|
||||
mConfig.SSID = "test_1234";
|
||||
mConfig.preSharedKey = "test_password";
|
||||
mConfig = new SoftApConfiguration.Builder().setSsid("test_1234")
|
||||
.setWpa2Passphrase("test_password").build();
|
||||
|
||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(mConfig);
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(mConfig);
|
||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
|
||||
@@ -84,19 +83,19 @@ public class WifiTetherPasswordPreferenceControllerTest {
|
||||
public void displayPreference_shouldStylePreference() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getText()).isEqualTo(mConfig.preSharedKey);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mConfig.preSharedKey);
|
||||
assertThat(mPreference.getText()).isEqualTo(mConfig.getWpa2Passphrase());
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mConfig.getWpa2Passphrase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changePreference_shouldUpdateValue() {
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, VALID_PASS);
|
||||
assertThat(mController.getPasswordValidated(WifiConfiguration.KeyMgmt.WPA2_PSK))
|
||||
assertThat(mController.getPasswordValidated(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK))
|
||||
.isEqualTo(VALID_PASS);
|
||||
|
||||
mController.onPreferenceChange(mPreference, VALID_PASS2);
|
||||
assertThat(mController.getPasswordValidated(WifiConfiguration.KeyMgmt.WPA2_PSK))
|
||||
assertThat(mController.getPasswordValidated(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK))
|
||||
.isEqualTo(VALID_PASS2);
|
||||
|
||||
verify(mListener, times(2)).onTetherConfigUpdated(mController);
|
||||
@@ -107,19 +106,19 @@ public class WifiTetherPasswordPreferenceControllerTest {
|
||||
// Set controller password to anything and verify is set.
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, VALID_PASS);
|
||||
assertThat(mController.getPasswordValidated(WifiConfiguration.KeyMgmt.WPA2_PSK))
|
||||
assertThat(mController.getPasswordValidated(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK))
|
||||
.isEqualTo(VALID_PASS);
|
||||
|
||||
// Create a new config using different password
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.preSharedKey = VALID_PASS2;
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(config);
|
||||
final SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setWpa2Passphrase(VALID_PASS2).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
|
||||
// Call updateDisplay and verify it's changed.
|
||||
mController.updateDisplay();
|
||||
assertThat(mController.getPasswordValidated(WifiConfiguration.KeyMgmt.WPA2_PSK))
|
||||
.isEqualTo(config.preSharedKey);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(config.preSharedKey);
|
||||
assertThat(mController.getPasswordValidated(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK))
|
||||
.isEqualTo(config.getWpa2Passphrase());
|
||||
assertThat(mPreference.getSummary()).isEqualTo(config.getWpa2Passphrase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,13 +126,13 @@ public class WifiTetherPasswordPreferenceControllerTest {
|
||||
// Set controller password to anything and verify is set.
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, VALID_PASS);
|
||||
assertThat(mController.getPasswordValidated(WifiConfiguration.KeyMgmt.WPA2_PSK))
|
||||
assertThat(mController.getPasswordValidated(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK))
|
||||
.isEqualTo(VALID_PASS);
|
||||
|
||||
// Create a new config using different password
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.preSharedKey = VALID_PASS2;
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(config);
|
||||
final SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setWpa2Passphrase(VALID_PASS2).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
|
||||
// Call updateDisplay and verify it's changed.
|
||||
mController.updateDisplay();
|
||||
|
@@ -19,18 +19,13 @@ package com.android.settings.wifi.tether;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -49,7 +44,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
@@ -67,8 +61,7 @@ public class WifiTetherPreferenceControllerTest {
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
private SoftApConfiguration mSoftApConfiguration;
|
||||
|
||||
private WifiTetherPreferenceController mController;
|
||||
private Lifecycle mLifecycle;
|
||||
@@ -88,8 +81,8 @@ public class WifiTetherPreferenceControllerTest {
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(mWifiConfiguration);
|
||||
mWifiConfiguration.SSID = SSID;
|
||||
mSoftApConfiguration = new SoftApConfiguration.Builder().setSsid(SSID).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(mSoftApConfiguration);
|
||||
|
||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
|
||||
mController = new WifiTetherPreferenceController(mContext, mLifecycle,
|
||||
|
@@ -25,14 +25,11 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -76,7 +73,7 @@ public class WifiTetherSSIDPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void displayPreference_noWifiConfig_shouldDisplayDefaultSSID() {
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(null);
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(null);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mController.getSSID())
|
||||
@@ -85,12 +82,12 @@ public class WifiTetherSSIDPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void displayPreference_hasCustomWifiConfig_shouldDisplayCustomSSID() {
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.SSID = "test_1234";
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(config);
|
||||
final SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setSsid("test_1234").build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mController.getSSID()).isEqualTo(config.SSID);
|
||||
assertThat(mController.getSSID()).isEqualTo(config.getSsid());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,23 +110,22 @@ public class WifiTetherSSIDPreferenceControllerTest {
|
||||
assertThat(mController.getSSID()).isEqualTo("1");
|
||||
|
||||
// Create a new config using different SSID
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.SSID = "test_1234";
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(config);
|
||||
final SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setSsid("test_1234").build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
|
||||
// Call updateDisplay and verify it's changed.
|
||||
mController.updateDisplay();
|
||||
assertThat(mController.getSSID()).isEqualTo(config.SSID);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(config.SSID);
|
||||
assertThat(mController.getSSID()).isEqualTo(config.getSsid());
|
||||
assertThat(mPreference.getSummary()).isEqualTo(config.getSsid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_wifiApDisabled_shouldHideQrCodeIcon() {
|
||||
when(mWifiManager.isWifiApEnabled()).thenReturn(false);
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.SSID = "test_1234";
|
||||
config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(config);
|
||||
final SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setSsid("test_1234").setWpa2Passphrase("test_password").build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mController.isQrCodeButtonAvailable()).isEqualTo(false);
|
||||
@@ -138,10 +134,9 @@ public class WifiTetherSSIDPreferenceControllerTest {
|
||||
@Test
|
||||
public void displayPreference_wifiApEnabled_shouldShowQrCodeIcon() {
|
||||
when(mWifiManager.isWifiApEnabled()).thenReturn(true);
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.SSID = "test_1234";
|
||||
config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(config);
|
||||
final SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setSsid("test_1234").setWpa2Passphrase("test_password").build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mController.isQrCodeButtonAvailable()).isEqualTo(true);
|
||||
|
@@ -8,7 +8,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
@@ -25,8 +25,9 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiTetherSecurityPreferenceControllerTest {
|
||||
|
||||
private static final String WPA2_PSK = String.valueOf(WifiConfiguration.KeyMgmt.WPA2_PSK);
|
||||
private static final String NONE = String.valueOf(WifiConfiguration.KeyMgmt.NONE);
|
||||
private static final String WPA2_PSK =
|
||||
String.valueOf(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
||||
private static final String NONE = String.valueOf(SoftApConfiguration.SECURITY_TYPE_OPEN);
|
||||
@Mock
|
||||
private WifiTetherBasePreferenceController.OnTetherConfigUpdateListener mListener;
|
||||
private Context mContext;
|
||||
@@ -38,19 +39,17 @@ public class WifiTetherSecurityPreferenceControllerTest {
|
||||
private PreferenceScreen mScreen;
|
||||
private WifiTetherSecurityPreferenceController mController;
|
||||
private ListPreference mPreference;
|
||||
private WifiConfiguration mConfig;
|
||||
private SoftApConfiguration mConfig;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mConfig = new WifiConfiguration();
|
||||
mConfig.SSID = "test_1234";
|
||||
mConfig.preSharedKey = "test_password";
|
||||
mConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
|
||||
mConfig = new SoftApConfiguration.Builder().setSsid("test_1234")
|
||||
.setWpa2Passphrase("test_password").build();
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
|
||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(mConfig);
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(mConfig);
|
||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
|
||||
@@ -64,35 +63,41 @@ public class WifiTetherSecurityPreferenceControllerTest {
|
||||
@Test
|
||||
public void onPreferenceChange_securityValueUpdated() {
|
||||
mController.onPreferenceChange(mPreference, WPA2_PSK);
|
||||
assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.WPA2_PSK);
|
||||
assertThat(mController.getSecurityType()).isEqualTo(
|
||||
SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal");
|
||||
|
||||
mController.onPreferenceChange(mPreference, NONE);
|
||||
assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.NONE);
|
||||
assertThat(mController.getSecurityType()).isEqualTo(
|
||||
SoftApConfiguration.SECURITY_TYPE_OPEN);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("None");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDisplay_preferenceUpdated() {
|
||||
// test defaulting to WPA2-Personal on new config
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(null);
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(null);
|
||||
mController.updateDisplay();
|
||||
assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.WPA2_PSK);
|
||||
assertThat(mController.getSecurityType()).isEqualTo(
|
||||
SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal");
|
||||
|
||||
// test open tether network
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(mConfig);
|
||||
mConfig.allowedKeyManagement.clear();
|
||||
mConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder(mConfig)
|
||||
.setWpa2Passphrase(null).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
mController.updateDisplay();
|
||||
assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.NONE);
|
||||
assertThat(mController.getSecurityType()).isEqualTo(
|
||||
SoftApConfiguration.SECURITY_TYPE_OPEN);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("None");
|
||||
|
||||
// test WPA2-Personal tether network
|
||||
mConfig.allowedKeyManagement.clear();
|
||||
mConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
|
||||
SoftApConfiguration config2 = new SoftApConfiguration.Builder(mConfig)
|
||||
.setWpa2Passphrase("test_password").build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config2);
|
||||
mController.updateDisplay();
|
||||
assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.WPA2_PSK);
|
||||
assertThat(mController.getSecurityType()).isEqualTo(
|
||||
SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user