diff options
-rw-r--r-- | service/java/com/android/server/wifi/util/ApConfigUtil.java | 74 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java | 21 |
2 files changed, 43 insertions, 52 deletions
diff --git a/service/java/com/android/server/wifi/util/ApConfigUtil.java b/service/java/com/android/server/wifi/util/ApConfigUtil.java index b8d371119..552231ed2 100644 --- a/service/java/com/android/server/wifi/util/ApConfigUtil.java +++ b/service/java/com/android/server/wifi/util/ApConfigUtil.java @@ -326,72 +326,42 @@ public class ApConfigUtil { return -1; } - int totalChannelCount = 0; - int size2gList = 0; - int size5gList = 0; - int size6gList = 0; - List<Integer> allowed2gFreqList = null; - List<Integer> allowed5gFreqList = null; - List<Integer> allowed6gFreqList = null; + List<Integer> allowedFreqList = null; - if ((apBand & SoftApConfiguration.BAND_2GHZ) != 0) { - allowed2gFreqList = getAvailableChannelFreqsForBand(SoftApConfiguration.BAND_2GHZ, - wifiNative, resources); - if (allowed2gFreqList != null) { - size2gList = allowed2gFreqList.size(); - totalChannelCount += size2gList; - } - } - if ((apBand & SoftApConfiguration.BAND_5GHZ) != 0) { - allowed5gFreqList = getAvailableChannelFreqsForBand(SoftApConfiguration.BAND_5GHZ, - wifiNative, resources); - if (allowed5gFreqList != null) { - size5gList = allowed5gFreqList.size(); - totalChannelCount += size5gList; - } - } if ((apBand & SoftApConfiguration.BAND_6GHZ) != 0) { - allowed6gFreqList = getAvailableChannelFreqsForBand(SoftApConfiguration.BAND_6GHZ, + allowedFreqList = getAvailableChannelFreqsForBand(SoftApConfiguration.BAND_6GHZ, wifiNative, resources); - if (allowed6gFreqList != null) { - size6gList = allowed6gFreqList.size(); - totalChannelCount += size6gList; + if (allowedFreqList != null && allowedFreqList.size() > 0) { + return allowedFreqList.get(sRandom.nextInt(allowedFreqList.size())).intValue(); } } - if (totalChannelCount == 0) { - // If the default AP band is allowed, just use the default channel - if (containsBand(apBand, DEFAULT_AP_BAND)) { - Log.d(TAG, "Allowed channel list not specified, selecting default channel"); - /* Use default channel. */ - return convertChannelToFrequency(DEFAULT_AP_CHANNEL, - DEFAULT_AP_BAND); - } else { - Log.e(TAG, "No available channels"); - return -1; + if ((apBand & SoftApConfiguration.BAND_5GHZ) != 0) { + allowedFreqList = getAvailableChannelFreqsForBand(SoftApConfiguration.BAND_5GHZ, + wifiNative, resources); + if (allowedFreqList != null && allowedFreqList.size() > 0) { + return allowedFreqList.get(sRandom.nextInt(allowedFreqList.size())).intValue(); } } - // Pick a channel - int selectedChannelIndex = sRandom.nextInt(totalChannelCount); - - if (size2gList != 0) { - if (selectedChannelIndex < size2gList) { - return allowed2gFreqList.get(selectedChannelIndex).intValue(); - } else { - selectedChannelIndex -= size2gList; + if ((apBand & SoftApConfiguration.BAND_2GHZ) != 0) { + allowedFreqList = getAvailableChannelFreqsForBand(SoftApConfiguration.BAND_2GHZ, + wifiNative, resources); + if (allowedFreqList != null && allowedFreqList.size() > 0) { + return allowedFreqList.get(sRandom.nextInt(allowedFreqList.size())).intValue(); } } - if (size5gList != 0) { - if (selectedChannelIndex < size5gList) { - return allowed5gFreqList.get(selectedChannelIndex).intValue(); - } else { - selectedChannelIndex -= size5gList; - } + // If the default AP band is allowed, just use the default channel + if (containsBand(apBand, DEFAULT_AP_BAND)) { + Log.e(TAG, "Allowed channel list not specified, selecting default channel"); + /* Use default channel. */ + return convertChannelToFrequency(DEFAULT_AP_CHANNEL, + DEFAULT_AP_BAND); } - return allowed6gFreqList.get(selectedChannelIndex).intValue(); + Log.e(TAG, "No available channels"); + return -1; } /** diff --git a/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java index 19952c48e..dafc69603 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java @@ -341,6 +341,27 @@ public class ApConfigUtilTest extends WifiBaseTest { } /** + * Verify chooseApChannel will select high band channel. + */ + @Test + public void chooseApChannelWillHighBandPrefer() throws Exception { + when(mResources.getString(R.string.config_wifiSoftap2gChannelList)) + .thenReturn("1, 6, 11"); + when(mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ)) + .thenReturn(ALLOWED_2G_FREQS); // ch#11 + when(mResources.getString(R.string.config_wifiSoftap5gChannelList)) + .thenReturn("149, 153"); + when(mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ)) + .thenReturn(ALLOWED_5G_FREQS); //ch# 149, 153 + + int freq = ApConfigUtil.chooseApChannel( + SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ, + mWifiNative, mResources); + assertTrue(ArrayUtils.contains(ALLOWED_5G_FREQS, freq)); + } + + + /** * Verify default band and channel is used when HAL support is * not available. */ |