From 5120a342ca325aeca24ff2116be3bc8184d0a05d Mon Sep 17 00:00:00 2001 From: Ahmed ElArabawy Date: Wed, 11 Dec 2019 12:58:42 -0800 Subject: [PATCH] Wifi: Handle adding 6GHz band to SoftAP With the support of 6GHz in Android, BAND_ANY is no longer equivalent to 2GHz+5GHz. This commit makes the changes to adapt with this. Bug: 139354972 Test: Manual Change-Id: I29263573fb900a560494a84df5a16ac0e6948f59 --- res/values/arrays.xml | 6 ++-- .../WifiTetherApBandPreferenceController.java | 36 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index eb2b869995a..e6effaec854 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -277,8 +277,8 @@ - 0 1 + 2 @@ -287,8 +287,8 @@ - 0 - -1 + 1 + 3 diff --git a/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java index 78e592c001d..074169572ab 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java +++ b/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java @@ -48,16 +48,17 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen public void updateDisplay() { final SoftApConfiguration config = mWifiManager.getSoftApConfiguration(); if (config == null) { - mBandIndex = 0; - Log.d(TAG, "Updating band index to 0 because no config"); + mBandIndex = SoftApConfiguration.BAND_2GHZ; + Log.d(TAG, "Updating band index to BAND_2GHZ because no config"); } else if (is5GhzBandSupported()) { mBandIndex = validateSelection(config.getBand()); Log.d(TAG, "Updating band index to " + mBandIndex); } else { mWifiManager.setSoftApConfiguration( - new SoftApConfiguration.Builder(config).setBand(0).build()); - mBandIndex = config.getBand(); - Log.d(TAG, "5Ghz not supported, updating band index to " + mBandIndex); + new SoftApConfiguration.Builder(config).setBand(SoftApConfiguration.BAND_2GHZ) + .build()); + mBandIndex = SoftApConfiguration.BAND_2GHZ; + Log.d(TAG, "5Ghz not supported, updating band index to 2GHz"); } ListPreference preference = (ListPreference) mPreference; @@ -74,10 +75,14 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen } String getConfigSummary() { - if (mBandIndex == SoftApConfiguration.BAND_ANY) { - return mContext.getString(R.string.wifi_ap_prefer_5G); + switch (mBandIndex) { + case SoftApConfiguration.BAND_2GHZ: + return mBandSummaries[0]; + case SoftApConfiguration.BAND_5GHZ: + return mBandSummaries[1]; + default: + return mContext.getString(R.string.wifi_ap_prefer_5G); } - return mBandSummaries[mBandIndex]; } @Override @@ -95,19 +100,18 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen } private int validateSelection(int band) { - // Reset the band to 2.4 GHz if we get a weird config back to avoid a crash. - final boolean isDualMode = mWifiManager.isDualModeSupported(); - // unsupported states: - // 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 && SoftApConfiguration.BAND_ANY == band) { + // 1: no dual mode means we can't have multiband - default to 5GHZ + // 2: no 5 GHZ support means we can't have BAND_5GHZ - default to 2GHZ + // 3: With Dual mode support we can't have BAND_5GHZ only - include 2GHZ + if (!isDualMode + && ((band & (SoftApConfiguration.BAND_5GHZ + | SoftApConfiguration.BAND_2GHZ)) != 0)) { 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 SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_2GHZ; } return band;