Merge "Revert "Add Hotspot WPA3 Settings""
This commit is contained in:
committed by
Android (Google) Code Review
commit
6653b25aaa
@@ -355,7 +355,7 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
||||
@Override
|
||||
public void onTetherConfigUpdated(AbstractPreferenceController controller) {
|
||||
final SoftApConfiguration config = buildNewConfig();
|
||||
mPasswordPreferenceController.setSecurityType(config.getSecurityType());
|
||||
mPasswordPreferenceController.updateVisibility(config.getSecurityType());
|
||||
mWifiManager.setSoftApConfiguration(config);
|
||||
|
||||
if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED) {
|
||||
|
@@ -56,12 +56,12 @@ public class WifiUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the hotspot password is valid.
|
||||
* Check if the WPA2-PSK hotspot password is valid.
|
||||
*/
|
||||
public static boolean isHotspotPasswordValid(String password, int securityType) {
|
||||
public static boolean isHotspotWpa2PasswordValid(String password) {
|
||||
final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
|
||||
try {
|
||||
configBuilder.setPassphrase(password, securityType);
|
||||
configBuilder.setPassphrase(password, SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -301,11 +301,7 @@ public class WifiDppUtils {
|
||||
|
||||
final String ssid = removeFirstAndLastDoubleQuotes(softApConfiguration.getSsid());
|
||||
String security;
|
||||
final int securityType = softApConfiguration.getSecurityType();
|
||||
if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE) {
|
||||
security = WifiQrCode.SECURITY_SAE;
|
||||
} else if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK
|
||||
|| securityType == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION) {
|
||||
if (softApConfiguration.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK) {
|
||||
security = WifiQrCode.SECURITY_WPA_PSK;
|
||||
} else {
|
||||
security = WifiQrCode.SECURITY_NO_PASSWORD;
|
||||
@@ -435,11 +431,11 @@ public class WifiDppUtils {
|
||||
|
||||
private static boolean isSupportHotspotConfiguratorQrCodeGenerator(
|
||||
SoftApConfiguration softApConfiguration) {
|
||||
final int securityType = softApConfiguration.getSecurityType();
|
||||
return securityType == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE
|
||||
|| securityType == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION
|
||||
|| securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK
|
||||
|| securityType == SoftApConfiguration.SECURITY_TYPE_OPEN;
|
||||
// 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 softApConfiguration.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK
|
||||
|| softApConfiguration.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_OPEN;
|
||||
}
|
||||
|
||||
private static boolean isSupportWifiDpp(Context context, int wifiEntrySecurity) {
|
||||
|
@@ -43,7 +43,6 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
||||
private static final String PREF_KEY = "wifi_tether_network_password";
|
||||
|
||||
private String mPassword;
|
||||
private int mSecurityType;
|
||||
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
@@ -69,13 +68,13 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
|
||||
if (config.getSecurityType() != SoftApConfiguration.SECURITY_TYPE_OPEN
|
||||
&& TextUtils.isEmpty(config.getPassphrase())) {
|
||||
if (config == null
|
||||
|| (config.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK
|
||||
&& TextUtils.isEmpty(config.getPassphrase()))) {
|
||||
mPassword = generateRandomPassword();
|
||||
} else {
|
||||
mPassword = config.getPassphrase();
|
||||
}
|
||||
mSecurityType = config.getSecurityType();
|
||||
((ValidatedEditTextPreference) mPreference).setValidator(this);
|
||||
((ValidatedEditTextPreference) mPreference).setIsPassword(true);
|
||||
((ValidatedEditTextPreference) mPreference).setIsSummaryPassword(true);
|
||||
@@ -106,21 +105,20 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
||||
// don't actually overwrite unless we get a new config in case it was accidentally toggled.
|
||||
if (securityType == SoftApConfiguration.SECURITY_TYPE_OPEN) {
|
||||
return "";
|
||||
} else if (!WifiUtils.isHotspotPasswordValid(mPassword, securityType)) {
|
||||
} else if (!isTextValid(mPassword)) {
|
||||
mPassword = generateRandomPassword();
|
||||
updatePasswordDisplay((EditTextPreference) mPreference);
|
||||
}
|
||||
return mPassword;
|
||||
}
|
||||
|
||||
public void setSecurityType(int securityType) {
|
||||
mSecurityType = securityType;
|
||||
public void updateVisibility(int securityType) {
|
||||
mPreference.setVisible(securityType != SoftApConfiguration.SECURITY_TYPE_OPEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTextValid(String value) {
|
||||
return WifiUtils.isHotspotPasswordValid(value, mSecurityType);
|
||||
return WifiUtils.isHotspotWpa2PasswordValid(value);
|
||||
}
|
||||
|
||||
private static String generateRandomPassword() {
|
||||
|
@@ -1,62 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.net.wifi.SoftApCapability;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class WifiTetherSecurityPreferenceController extends WifiTetherBasePreferenceController
|
||||
implements WifiManager.SoftApCallback {
|
||||
public class WifiTetherSecurityPreferenceController extends WifiTetherBasePreferenceController {
|
||||
|
||||
private static final String PREF_KEY = "wifi_tether_security";
|
||||
|
||||
private Map<Integer, String> mSecurityMap = new LinkedHashMap<Integer, String>();
|
||||
private final String[] mSecurityEntries;
|
||||
private int mSecurityValue;
|
||||
@VisibleForTesting
|
||||
boolean mIsWpa3Supported = true;
|
||||
|
||||
public WifiTetherSecurityPreferenceController(Context context,
|
||||
OnTetherConfigUpdateListener listener) {
|
||||
super(context, listener);
|
||||
final String[] securityNames = mContext.getResources().getStringArray(
|
||||
R.array.wifi_tether_security);
|
||||
final String[] securityValues = mContext.getResources().getStringArray(
|
||||
R.array.wifi_tether_security_values);
|
||||
for (int i = 0; i < securityNames.length; i++) {
|
||||
mSecurityMap.put(Integer.parseInt(securityValues[i]), securityNames[i]);
|
||||
}
|
||||
mWifiManager.registerSoftApCallback(context.getMainExecutor(), this);
|
||||
mSecurityEntries = mContext.getResources().getStringArray(R.array.wifi_tether_security);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,48 +33,35 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
final ListPreference preference = (ListPreference) mPreference;
|
||||
// If the device is not support WPA3 then remove the WPA3 options.
|
||||
if (!mIsWpa3Supported && mSecurityMap.keySet()
|
||||
.removeIf(key -> key > SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)) {
|
||||
preference.setEntries(mSecurityMap.values().stream().toArray(CharSequence[]::new));
|
||||
preference.setEntryValues(mSecurityMap.keySet().stream().map(Integer::toBinaryString)
|
||||
.toArray(CharSequence[]::new));
|
||||
final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
|
||||
if (config != null && config.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_OPEN) {
|
||||
mSecurityValue = SoftApConfiguration.SECURITY_TYPE_OPEN;
|
||||
} else {
|
||||
mSecurityValue = SoftApConfiguration.SECURITY_TYPE_WPA2_PSK;
|
||||
}
|
||||
|
||||
final int securityType = mWifiManager.getSoftApConfiguration().getSecurityType();
|
||||
mSecurityValue = mSecurityMap.get(securityType) != null
|
||||
? securityType : SoftApConfiguration.SECURITY_TYPE_WPA2_PSK;
|
||||
|
||||
preference.setSummary(mSecurityMap.get(mSecurityValue));
|
||||
final ListPreference preference = (ListPreference) mPreference;
|
||||
preference.setSummary(getSummaryForSecurityType(mSecurityValue));
|
||||
preference.setValue(String.valueOf(mSecurityValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
mSecurityValue = Integer.parseInt((String) newValue);
|
||||
preference.setSummary(mSecurityMap.get(mSecurityValue));
|
||||
if (mListener != null) {
|
||||
mListener.onTetherConfigUpdated(this);
|
||||
}
|
||||
preference.setSummary(getSummaryForSecurityType(mSecurityValue));
|
||||
mListener.onTetherConfigUpdated(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCapabilityChanged(@NonNull SoftApCapability softApCapability) {
|
||||
final boolean isWpa3Supported =
|
||||
softApCapability.areFeaturesSupported(SoftApCapability.SOFTAP_FEATURE_WPA3_SAE);
|
||||
if (!isWpa3Supported) {
|
||||
Log.i(PREF_KEY, "WPA3 SAE is not supported on this device");
|
||||
}
|
||||
if (mIsWpa3Supported != isWpa3Supported) {
|
||||
mIsWpa3Supported = isWpa3Supported;
|
||||
updateDisplay();
|
||||
}
|
||||
mWifiManager.unregisterSoftApCallback(this);
|
||||
}
|
||||
|
||||
public int getSecurityType() {
|
||||
return mSecurityValue;
|
||||
}
|
||||
|
||||
private String getSummaryForSecurityType(int securityType) {
|
||||
if (securityType == SoftApConfiguration.SECURITY_TYPE_OPEN) {
|
||||
return mSecurityEntries[1];
|
||||
}
|
||||
// WPA2 PSK
|
||||
return mSecurityEntries[0];
|
||||
}
|
||||
}
|
||||
|
@@ -192,7 +192,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
@Override
|
||||
public void onTetherConfigUpdated(AbstractPreferenceController context) {
|
||||
final SoftApConfiguration config = buildNewConfig();
|
||||
mPasswordPreferenceController.setSecurityType(config.getSecurityType());
|
||||
mPasswordPreferenceController.updateVisibility(config.getSecurityType());
|
||||
|
||||
/**
|
||||
* if soft AP is stopped, bring up
|
||||
@@ -216,10 +216,10 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
|
||||
final int securityType = mSecurityPreferenceController.getSecurityType();
|
||||
configBuilder.setSsid(mSSIDPreferenceController.getSSID());
|
||||
if (securityType != SoftApConfiguration.SECURITY_TYPE_OPEN) {
|
||||
if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK) {
|
||||
configBuilder.setPassphrase(
|
||||
mPasswordPreferenceController.getPasswordValidated(securityType),
|
||||
securityType);
|
||||
SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
||||
}
|
||||
configBuilder.setBand(mApBandPreferenceController.getBandIndex());
|
||||
return configBuilder.build();
|
||||
|
Reference in New Issue
Block a user