From d65e37e8a8c52f4c626dc0131e054f1b156c08d7 Mon Sep 17 00:00:00 2001 From: Quang Luong Date: Tue, 4 Jun 2024 07:30:17 +0000 Subject: [PATCH] Change hotspot security to WPA3-Transition when switching from 6GHz When changing hotspot to 6GHz, we auto-set the security to WPA3-SAE. However, we don't do the reverse when changing out of 6GHz, which may cause legacy devices to be unable to connect. Instead, always revert back to WPA3-Transition when switching out of 6GHz. Bug: 323764310 Test: manual Change-Id: I06b1e97f452da86a693812a6620c251ff5d0e932 --- .../repository/WifiHotspotRepository.java | 26 ++++++++++++------- .../repository/WifiHotspotRepositoryTest.java | 2 ++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/wifi/repository/WifiHotspotRepository.java b/src/com/android/settings/wifi/repository/WifiHotspotRepository.java index e78773ee0e8..7a001caedc6 100644 --- a/src/com/android/settings/wifi/repository/WifiHotspotRepository.java +++ b/src/com/android/settings/wifi/repository/WifiHotspotRepository.java @@ -22,6 +22,7 @@ import static android.net.wifi.SoftApConfiguration.BAND_5GHZ; import static android.net.wifi.SoftApConfiguration.BAND_6GHZ; import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_OPEN; import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_WPA3_SAE; +import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION; import static android.net.wifi.WifiAvailableChannel.OP_MODE_SAP; import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED; import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED; @@ -343,16 +344,23 @@ public class WifiHotspotRepository { log("setSpeedType(), setPassphrase(SECURITY_TYPE_WPA3_SAE)"); configBuilder.setPassphrase(generatePassword(config), SECURITY_TYPE_WPA3_SAE); } - } else if (speedType == SPEED_5GHZ) { - log("setSpeedType(), setBand(BAND_2GHZ_5GHZ)"); - configBuilder.setBand(BAND_2GHZ_5GHZ); - } else if (mIsDualBand) { - log("setSpeedType(), setBands(BAND_2GHZ + BAND_2GHZ_5GHZ)"); - int[] bands = {BAND_2GHZ, BAND_2GHZ_5GHZ}; - configBuilder.setBands(bands); } else { - log("setSpeedType(), setBand(BAND_2GHZ)"); - configBuilder.setBand(BAND_2GHZ); + if (speedType == SPEED_5GHZ) { + log("setSpeedType(), setBand(BAND_2GHZ_5GHZ)"); + configBuilder.setBand(BAND_2GHZ_5GHZ); + } else if (mIsDualBand) { + log("setSpeedType(), setBands(BAND_2GHZ + BAND_2GHZ_5GHZ)"); + int[] bands = {BAND_2GHZ, BAND_2GHZ_5GHZ}; + configBuilder.setBands(bands); + } else { + log("setSpeedType(), setBand(BAND_2GHZ)"); + configBuilder.setBand(BAND_2GHZ); + } + // Set the security type back to WPA2/WPA3 if we're moving from 6GHz to something else. + if ((config.getBand() & BAND_6GHZ) != 0) { + configBuilder.setPassphrase( + generatePassword(config), SECURITY_TYPE_WPA3_SAE_TRANSITION); + } } setSoftApConfiguration(configBuilder.build()); } diff --git a/tests/unit/src/com/android/settings/wifi/repository/WifiHotspotRepositoryTest.java b/tests/unit/src/com/android/settings/wifi/repository/WifiHotspotRepositoryTest.java index 20b30754fac..a97b1a04e68 100644 --- a/tests/unit/src/com/android/settings/wifi/repository/WifiHotspotRepositoryTest.java +++ b/tests/unit/src/com/android/settings/wifi/repository/WifiHotspotRepositoryTest.java @@ -497,6 +497,8 @@ public class WifiHotspotRepositoryTest { SparseIntArray channels = mSoftApConfigCaptor.getValue().getChannels(); assertThat(channels.get(BAND_2GHZ, CHANNEL_NOT_FOUND)).isNotEqualTo(CHANNEL_NOT_FOUND); assertThat(channels.get(BAND_2GHZ_5GHZ, CHANNEL_NOT_FOUND)).isNotEqualTo(CHANNEL_NOT_FOUND); + assertThat(mSoftApConfigCaptor.getValue().getSecurityType()) + .isEqualTo(SECURITY_TYPE_WPA3_SAE_TRANSITION); } @Test