From ee38c65d579f5363f2ffd63e850582350233d0e4 Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Fri, 25 May 2018 09:23:51 -0700 Subject: WifiApConfigStore: convert 5GHZ to ANY for dual mode devices When setting or getting an ap config, check for necessary apband conversions. For some devices, apBand options are limited to 2.4(only) and ANY. A second class of devices are limited to 2.4(only) and 5(only). Single band devices are still limited to 2.4(only). Bug: 80251951 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: manually confirmed configs are converted for different device types Change-Id: I14150f0e890696e12ef04f402c0d8afad09e984e --- .../com/android/server/wifi/WifiApConfigStore.java | 50 +++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java index e8ad74885..109c0a7af 100644 --- a/service/java/com/android/server/wifi/WifiApConfigStore.java +++ b/service/java/com/android/server/wifi/WifiApConfigStore.java @@ -63,6 +63,9 @@ public class WifiApConfigStore { @VisibleForTesting static final int PSK_MAX_LEN = 63; + @VisibleForTesting + static final int AP_CHANNEL_DEFAULT = 0; + private WifiConfiguration mWifiApConfig = null; private ArrayList mAllowed2GChannel = null; @@ -70,6 +73,7 @@ public class WifiApConfigStore { private final Context mContext; private final String mApConfigFile; private final BackupManagerProxy mBackupManagerProxy; + private boolean mRequiresApBandConversion = false; WifiApConfigStore(Context context, BackupManagerProxy backupManagerProxy) { this(context, backupManagerProxy, DEFAULT_AP_CONFIG_FILE); @@ -94,6 +98,9 @@ public class WifiApConfigStore { } } + mRequiresApBandConversion = mContext.getResources().getBoolean( + R.bool.config_wifi_convert_apband_5ghz_to_any); + /* Load AP configuration from persistent storage. */ mWifiApConfig = loadApConfiguration(mApConfigFile); if (mWifiApConfig == null) { @@ -110,6 +117,12 @@ public class WifiApConfigStore { * Return the current soft access point configuration. */ public synchronized WifiConfiguration getApConfiguration() { + WifiConfiguration config = apBandCheckConvert(mWifiApConfig); + if (mWifiApConfig != config) { + Log.d(TAG, "persisted config was converted, need to resave it"); + mWifiApConfig = config; + persistConfigAndTriggerBackupManagerProxy(mWifiApConfig); + } return mWifiApConfig; } @@ -123,18 +136,45 @@ public class WifiApConfigStore { if (config == null) { mWifiApConfig = getDefaultApConfiguration(); } else { - mWifiApConfig = config; + mWifiApConfig = apBandCheckConvert(config); } - writeApConfiguration(mApConfigFile, mWifiApConfig); - - // Stage the backup of the SettingsProvider package which backs this up - mBackupManagerProxy.notifyDataChanged(); + persistConfigAndTriggerBackupManagerProxy(mWifiApConfig); } public ArrayList getAllowed2GChannel() { return mAllowed2GChannel; } + private WifiConfiguration apBandCheckConvert(WifiConfiguration config) { + if (mRequiresApBandConversion) { + // some devices are unable to support 5GHz only operation, check for 5GHz and + // move to ANY if apBand conversion is required. + if (config.apBand == WifiConfiguration.AP_BAND_5GHZ) { + Log.w(TAG, "Supplied ap config band was 5GHz only, converting to ANY"); + WifiConfiguration convertedConfig = new WifiConfiguration(config); + convertedConfig.apBand = WifiConfiguration.AP_BAND_ANY; + convertedConfig.apChannel = AP_CHANNEL_DEFAULT; + return convertedConfig; + } + } else { + // this is a single mode device, we do not support ANY. Convert all ANY to 5GHz + if (config.apBand == WifiConfiguration.AP_BAND_ANY) { + Log.w(TAG, "Supplied ap config band was ANY, converting to 5GHz"); + WifiConfiguration convertedConfig = new WifiConfiguration(config); + convertedConfig.apBand = WifiConfiguration.AP_BAND_5GHZ; + convertedConfig.apChannel = AP_CHANNEL_DEFAULT; + return convertedConfig; + } + } + return config; + } + + private void persistConfigAndTriggerBackupManagerProxy(WifiConfiguration config) { + writeApConfiguration(mApConfigFile, mWifiApConfig); + // Stage the backup of the SettingsProvider package which backs this up + mBackupManagerProxy.notifyDataChanged(); + } + /** * Load AP configuration from persistent storage. */ -- cgit v1.2.3