Add Wi-Fi hotspot > Security Settings page

- Restrict low security type when 6 GHz band is selected
  - Disable "WPA2/WPA3-Personal" security type
  - Disable "WPA2-Personal" security type
  - Disable "None" security type

- Automatically updated security type to WPA3 when 6 GHz band is selected
  - Regenerate password when security type is changed from None

Bug: 245258763
Test: manual test
atest -c WifiTetherSettingsTest
atest -c WifiTetherViewModelTest \
         WifiHotspotSecuritySettingsTest \
         WifiHotspotSecurityViewModelTest \
         WifiHotspotRepositoryTest

Change-Id: I31b08795419baed10dc40b876aeec175f6f41e69
This commit is contained in:
Weng Su
2023-04-10 23:31:50 +08:00
parent 211b544ea8
commit 9f80cd2f77
14 changed files with 1019 additions and 28 deletions

View File

@@ -16,11 +16,15 @@
package com.android.settings.wifi.tether;
import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_OPEN;
import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_WPA2_PSK;
import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_WPA3_SAE;
import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION;
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ;
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ_5GHZ;
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_5GHZ;
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_6GHZ;
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_UNKNOWN;
import android.app.Application;
import android.net.wifi.SoftApConfiguration;
@@ -28,7 +32,7 @@ import android.net.wifi.SoftApConfiguration;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations;
import androidx.lifecycle.Observer;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
@@ -45,9 +49,19 @@ import java.util.Map;
public class WifiTetherViewModel extends AndroidViewModel {
private static final String TAG = "WifiTetherViewModel";
protected static Map<Integer, Integer> sSpeedSummaryResMap = new HashMap<>();
static Map<Integer, Integer> sSecuritySummaryResMap = new HashMap<>();
static {
sSecuritySummaryResMap.put(SECURITY_TYPE_WPA3_SAE, R.string.wifi_security_sae);
sSecuritySummaryResMap.put(SECURITY_TYPE_WPA3_SAE_TRANSITION,
R.string.wifi_security_psk_sae);
sSecuritySummaryResMap.put(SECURITY_TYPE_WPA2_PSK, R.string.wifi_security_wpa2);
sSecuritySummaryResMap.put(SECURITY_TYPE_OPEN, R.string.wifi_security_none);
}
static Map<Integer, Integer> sSpeedSummaryResMap = new HashMap<>();
static {
sSpeedSummaryResMap.put(SPEED_UNKNOWN, R.string.summary_placeholder);
sSpeedSummaryResMap.put(SPEED_2GHZ, R.string.wifi_hotspot_speed_summary_2g);
sSpeedSummaryResMap.put(SPEED_5GHZ, R.string.wifi_hotspot_speed_summary_5g);
sSpeedSummaryResMap.put(SPEED_6GHZ, R.string.wifi_hotspot_speed_summary_6g);
@@ -55,18 +69,22 @@ public class WifiTetherViewModel extends AndroidViewModel {
}
protected final WifiHotspotRepository mWifiHotspotRepository;
protected MutableLiveData<Integer> mSecuritySummary;
protected MutableLiveData<Integer> mSpeedSummary;
protected final Observer<Integer> mSecurityTypeObserver = st -> onSecurityTypeChanged(st);
protected final Observer<Integer> mSpeedTypeObserver = st -> onSpeedTypeChanged(st);
public WifiTetherViewModel(@NotNull Application application) {
super(application);
mWifiHotspotRepository = FeatureFactory.getFactory(application).getWifiFeatureProvider()
.getWifiHotspotRepository();
mWifiHotspotRepository.setAutoRefresh(true);
}
@Override
protected void onCleared() {
mWifiHotspotRepository.setAutoRefresh(false);
mWifiHotspotRepository.getSecurityType().removeObserver(mSecurityTypeObserver);
mWifiHotspotRepository.getSpeedType().removeObserver(mSpeedTypeObserver);
}
/**
@@ -85,18 +103,41 @@ public class WifiTetherViewModel extends AndroidViewModel {
mWifiHotspotRepository.refresh();
}
/**
* Gets SecuritySummary LiveData
*/
public LiveData<Integer> getSecuritySummary() {
if (mSecuritySummary == null) {
mSecuritySummary = new MutableLiveData<>();
mWifiHotspotRepository.getSecurityType().observeForever(mSecurityTypeObserver);
}
return mSecuritySummary;
}
protected void onSecurityTypeChanged(int securityType) {
int resId = R.string.summary_placeholder;
if (sSecuritySummaryResMap.containsKey(securityType)) {
resId = sSecuritySummaryResMap.get(securityType);
}
mSecuritySummary.setValue(resId);
}
/**
* Gets SpeedSummary LiveData
*/
public LiveData<Integer> getSpeedSummary() {
if (mSpeedSummary == null) {
mSpeedSummary = new MutableLiveData<>();
mWifiHotspotRepository.getSpeedType().observeForever(this::onSpeedTypeChanged);
mWifiHotspotRepository.getSpeedType().observeForever(mSpeedTypeObserver);
}
return Transformations.distinctUntilChanged(mSpeedSummary);
return mSpeedSummary;
}
protected void onSpeedTypeChanged(Integer speedType) {
mSpeedSummary.setValue(sSpeedSummaryResMap.get(speedType));
int resId = R.string.summary_placeholder;
if (sSpeedSummaryResMap.containsKey(speedType)) {
resId = sSpeedSummaryResMap.get(speedType);
}
mSpeedSummary.setValue(resId);
}
}