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
This commit is contained in:
Ahmed ElArabawy
2019-12-11 12:58:42 -08:00
parent 8e25a3a658
commit 5120a342ca
2 changed files with 23 additions and 19 deletions

View File

@@ -277,8 +277,8 @@
<!-- Wi-Fi AP band settings. Either Auto, 2.4GHz or 5GHz. --> <!-- Wi-Fi AP band settings. Either Auto, 2.4GHz or 5GHz. -->
<!-- Note that adding/removing/moving the items will need wifi settings code change. --> <!-- Note that adding/removing/moving the items will need wifi settings code change. -->
<string-array translatable="false" name="wifi_ap_band_config_full"> <string-array translatable="false" name="wifi_ap_band_config_full">
<item>0</item>
<item>1</item> <item>1</item>
<item>2</item>
</string-array> </string-array>
<string-array translatable="false" name="wifi_ap_band_summary_full"> <string-array translatable="false" name="wifi_ap_band_summary_full">
@@ -287,8 +287,8 @@
</string-array> </string-array>
<string-array translatable="false" name="wifi_ap_band_dual_mode"> <string-array translatable="false" name="wifi_ap_band_dual_mode">
<item>0</item> <item>1</item>
<item>-1</item> <item>3</item>
</string-array> </string-array>
<string-array translatable="false" name="wifi_ap_band_dual_mode_summary"> <string-array translatable="false" name="wifi_ap_band_dual_mode_summary">

View File

@@ -48,16 +48,17 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
public void updateDisplay() { public void updateDisplay() {
final SoftApConfiguration config = mWifiManager.getSoftApConfiguration(); final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
if (config == null) { if (config == null) {
mBandIndex = 0; mBandIndex = SoftApConfiguration.BAND_2GHZ;
Log.d(TAG, "Updating band index to 0 because no config"); Log.d(TAG, "Updating band index to BAND_2GHZ because no config");
} else if (is5GhzBandSupported()) { } else if (is5GhzBandSupported()) {
mBandIndex = validateSelection(config.getBand()); mBandIndex = validateSelection(config.getBand());
Log.d(TAG, "Updating band index to " + mBandIndex); Log.d(TAG, "Updating band index to " + mBandIndex);
} else { } else {
mWifiManager.setSoftApConfiguration( mWifiManager.setSoftApConfiguration(
new SoftApConfiguration.Builder(config).setBand(0).build()); new SoftApConfiguration.Builder(config).setBand(SoftApConfiguration.BAND_2GHZ)
mBandIndex = config.getBand(); .build());
Log.d(TAG, "5Ghz not supported, updating band index to " + mBandIndex); mBandIndex = SoftApConfiguration.BAND_2GHZ;
Log.d(TAG, "5Ghz not supported, updating band index to 2GHz");
} }
ListPreference preference = ListPreference preference =
(ListPreference) mPreference; (ListPreference) mPreference;
@@ -74,10 +75,14 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
} }
String getConfigSummary() { String getConfigSummary() {
if (mBandIndex == SoftApConfiguration.BAND_ANY) { switch (mBandIndex) {
return mContext.getString(R.string.wifi_ap_prefer_5G); 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 @Override
@@ -95,19 +100,18 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
} }
private int validateSelection(int band) { 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: // unsupported states:
// 1: no dual mode means we can't have AP_BAND_ANY - default to 5GHZ // 1: no dual mode means we can't have multiband - default to 5GHZ
// 2: no 5 GHZ support means we can't have AP_BAND_5GHZ - default to 2GHZ // 2: no 5 GHZ support means we can't have BAND_5GHZ - default to 2GHZ
// 3: With Dual mode support we can't have AP_BAND_5GHZ - default to ANY // 3: With Dual mode support we can't have BAND_5GHZ only - include 2GHZ
if (!isDualMode && SoftApConfiguration.BAND_ANY == band) { if (!isDualMode
&& ((band & (SoftApConfiguration.BAND_5GHZ
| SoftApConfiguration.BAND_2GHZ)) != 0)) {
return SoftApConfiguration.BAND_5GHZ; return SoftApConfiguration.BAND_5GHZ;
} else if (!is5GhzBandSupported() && SoftApConfiguration.BAND_5GHZ == band) { } else if (!is5GhzBandSupported() && SoftApConfiguration.BAND_5GHZ == band) {
return SoftApConfiguration.BAND_2GHZ; return SoftApConfiguration.BAND_2GHZ;
} else if (isDualMode && SoftApConfiguration.BAND_5GHZ == band) { } else if (isDualMode && SoftApConfiguration.BAND_5GHZ == band) {
return SoftApConfiguration.BAND_ANY; return SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_2GHZ;
} }
return band; return band;