diff options
author | Mitchell Wills <mwills@google.com> | 2016-02-29 10:59:24 -0800 |
---|---|---|
committer | Mitchell Wills <mwills@google.com> | 2016-03-01 09:50:43 -0800 |
commit | e6d8fa5fb50afdfc04922f7f87c2cac08db5bbec (patch) | |
tree | f39af8165f34dccbed5143950eb37ef9f15df08c | |
parent | 3fff931f15b78dc75376506d98782393452d4c56 (diff) |
Update scan band channels when needed
The involves adding an ability to channel helper to trigger a channel
list update.
Bug: 27381346
Change-Id: I7908018ff8136b9ce7880d5090bbe9e6fb63405d
11 files changed, 109 insertions, 42 deletions
diff --git a/service/java/com/android/server/wifi/HalWifiScannerImpl.java b/service/java/com/android/server/wifi/HalWifiScannerImpl.java index b892f2d54..90a54f09f 100644 --- a/service/java/com/android/server/wifi/HalWifiScannerImpl.java +++ b/service/java/com/android/server/wifi/HalWifiScannerImpl.java @@ -25,8 +25,7 @@ import android.util.Log; import com.android.server.wifi.scanner.ChannelHelper; import com.android.server.wifi.scanner.ChannelHelper.ChannelCollection; -import com.android.server.wifi.scanner.KnownBandsChannelHelper; -import com.android.server.wifi.scanner.NoBandChannelHelper; +import com.android.server.wifi.scanner.HalChannelHelper; import java.util.Arrays; import java.util.List; @@ -53,32 +52,7 @@ public class HalWifiScannerImpl extends WifiScannerImpl implements Handler.Callb mWifiNative = wifiNative; mEventHandler = new Handler(looper, this); - // TODO(b/27324226) Remove this retry loop - // Sometimes angler returns an empty channel list the first time the channel list is queried - int[] channels24G = new int[0]; - int[] channels5G = new int[0]; - int[] channelsDfs = new int[0]; - ChannelHelper channelHelper = null; - for (int i = 0; i < 4; ++i) { - channels24G = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ); - if (channels24G == null) Log.e(TAG, "Failed to get channels for 2.4GHz band"); - channels5G = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ); - if (channels5G == null) Log.e(TAG, "Failed to get channels for 5GHz band"); - channelsDfs = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ_DFS_ONLY); - if (channelsDfs == null) Log.e(TAG, "Failed to get channels for 5GHz DFS only band"); - if (channels24G == null || channels5G == null || channelsDfs == null) { - Log.e(TAG, "Falling back to NoBandChannelHelper"); - channelHelper = new NoBandChannelHelper(); - break; - } else if (channels24G.length > 0 || channels5G.length > 0 || channelsDfs.length > 0) { - channelHelper = new KnownBandsChannelHelper(channels24G, channels5G, channelsDfs); - } - try { Thread.sleep(50); } catch (Exception e) {} - } - if (channelHelper == null) { - channelHelper = new KnownBandsChannelHelper(channels24G, channels5G, channelsDfs); - } - mChannelHelper = channelHelper; + mChannelHelper = new HalChannelHelper(wifiNative); // We can't enable these until WifiStateMachine switches to using WifiScanner because // WifiMonitor only supports sending results to one listener diff --git a/service/java/com/android/server/wifi/WifiScanningServiceImpl.java b/service/java/com/android/server/wifi/WifiScanningServiceImpl.java index efc64e86c..75f2cc229 100644 --- a/service/java/com/android/server/wifi/WifiScanningServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiScanningServiceImpl.java @@ -99,6 +99,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { @Override public Bundle getAvailableChannels(int band) { + mChannelHelper.updateChannels(); ChannelSpec[] channelSpecs = mChannelHelper.getAvailableScanChannels(band); ArrayList<Integer> list = new ArrayList<Integer>(channelSpecs.length); for (ChannelSpec channelSpec : channelSpecs) { @@ -843,6 +844,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { } private boolean updateSchedule() { + mChannelHelper.updateChannels(); ArrayList<ScanSettings> settings = new ArrayList<>(); for (ClientInfo client : mClients.values()) { settings.addAll(client.getScanSettings()); diff --git a/service/java/com/android/server/wifi/scanner/ChannelHelper.java b/service/java/com/android/server/wifi/scanner/ChannelHelper.java index 0de1ca5e0..e6042c4b1 100644 --- a/service/java/com/android/server/wifi/scanner/ChannelHelper.java +++ b/service/java/com/android/server/wifi/scanner/ChannelHelper.java @@ -36,6 +36,8 @@ public abstract class ChannelHelper { */ public static final int SCAN_PERIOD_PER_CHANNEL_MS = 200; + protected static final WifiScanner.ChannelSpec[] NO_CHANNELS = new WifiScanner.ChannelSpec[0]; + /** * Create a new collection that can be used to store channels */ @@ -58,6 +60,17 @@ public abstract class ChannelHelper { public abstract int estimateScanDuration(WifiScanner.ScanSettings settings); /** + * Update the channel information that this object has. The source of the update is + * implementation dependent and may result in no change. Warning the behavior of a + * ChannelCollection created using {@link #createChannelCollection createChannelCollection} is + * undefined after calling this method until the {@link ChannelColleciton#clear() clear} method + * is called on it. + */ + public void updateChannels() { + // default implementation does nothing + } + + /** * Object that supports accumulation of channels and bands */ public abstract class ChannelCollection { diff --git a/service/java/com/android/server/wifi/scanner/HalChannelHelper.java b/service/java/com/android/server/wifi/scanner/HalChannelHelper.java new file mode 100644 index 000000000..83f4195f9 --- /dev/null +++ b/service/java/com/android/server/wifi/scanner/HalChannelHelper.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi.scanner; + +import android.net.wifi.WifiScanner; +import android.util.Log; + +import com.android.server.wifi.WifiNative; + +/** + * KnownBandsChannelHelper that uses band to channel mappings retrieved from the HAL. + * Also supporting updating the channel list from the HAL on demand. + */ +public class HalChannelHelper extends KnownBandsChannelHelper { + private static final String TAG = "HalChannelHelper"; + + private final WifiNative mWifiNative; + + public HalChannelHelper(WifiNative wifiNative) { + mWifiNative = wifiNative; + final int[] emptyFreqList = new int[0]; + setBandChannels(emptyFreqList, emptyFreqList, emptyFreqList); + updateChannels(); + } + + @Override + public void updateChannels() { + int[] channels24G = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ); + if (channels24G == null) Log.e(TAG, "Failed to get channels for 2.4GHz band"); + int[] channels5G = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ); + if (channels5G == null) Log.e(TAG, "Failed to get channels for 5GHz band"); + int[] channelsDfs = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ_DFS_ONLY); + if (channelsDfs == null) Log.e(TAG, "Failed to get channels for 5GHz DFS only band"); + if (channels24G == null || channels5G == null || channelsDfs == null) { + Log.e(TAG, "Failed to get all channels for band, not updating band channel lists"); + } else if (channels24G.length > 0 || channels5G.length > 0 || channelsDfs.length > 0) { + setBandChannels(channels24G, channels5G, channelsDfs); + } + + } +} diff --git a/service/java/com/android/server/wifi/scanner/KnownBandsChannelHelper.java b/service/java/com/android/server/wifi/scanner/KnownBandsChannelHelper.java index 96dbeeaa6..3214cf2d1 100644 --- a/service/java/com/android/server/wifi/scanner/KnownBandsChannelHelper.java +++ b/service/java/com/android/server/wifi/scanner/KnownBandsChannelHelper.java @@ -29,11 +29,9 @@ import java.util.Set; */ public class KnownBandsChannelHelper extends ChannelHelper { - private static final WifiScanner.ChannelSpec[] NO_CHANNELS = new WifiScanner.ChannelSpec[0]; - private WifiScanner.ChannelSpec[][] mBandsToChannels; - public KnownBandsChannelHelper(int[] channels2G, int[] channels5G, int[] channelsDfs) { + protected void setBandChannels(int[] channels2G, int[] channels5G, int[] channelsDfs) { mBandsToChannels = new WifiScanner.ChannelSpec[8][]; mBandsToChannels[0] = NO_CHANNELS; diff --git a/service/java/com/android/server/wifi/scanner/NoBandChannelHelper.java b/service/java/com/android/server/wifi/scanner/NoBandChannelHelper.java index ea1f999ce..4528a53a6 100644 --- a/service/java/com/android/server/wifi/scanner/NoBandChannelHelper.java +++ b/service/java/com/android/server/wifi/scanner/NoBandChannelHelper.java @@ -29,8 +29,6 @@ import java.util.Set; */ public class NoBandChannelHelper extends ChannelHelper { - private static final WifiScanner.ChannelSpec[] NO_CHANNELS = new WifiScanner.ChannelSpec[0]; - /** * These parameters are used to estimate the scan duration. * This is a guess at the number of channels the device supports for use when a ScanSettings diff --git a/service/java/com/android/server/wifi/scanner/PresetKnownBandsChannelHelper.java b/service/java/com/android/server/wifi/scanner/PresetKnownBandsChannelHelper.java new file mode 100644 index 000000000..2bc8b19bd --- /dev/null +++ b/service/java/com/android/server/wifi/scanner/PresetKnownBandsChannelHelper.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi.scanner; + +/** + * KnownBandsChannelHelper that uses a supplied list of band to channels mappings. + */ +public class PresetKnownBandsChannelHelper extends KnownBandsChannelHelper { + public PresetKnownBandsChannelHelper(int[] channels2G, int[] channels5G, int[] channelsDfs) { + setBandChannels(channels2G, channels5G, channelsDfs); + } +} diff --git a/tests/wifitests/src/com/android/server/wifi/MultiClientSchedulerFilterTest.java b/tests/wifitests/src/com/android/server/wifi/MultiClientSchedulerFilterTest.java index 8f6e8fbba..3c539ed8f 100644 --- a/tests/wifitests/src/com/android/server/wifi/MultiClientSchedulerFilterTest.java +++ b/tests/wifitests/src/com/android/server/wifi/MultiClientSchedulerFilterTest.java @@ -34,7 +34,7 @@ import android.net.wifi.WifiScanner.ScanSettings; import android.test.suitebuilder.annotation.SmallTest; import com.android.server.wifi.scanner.ChannelHelper; -import com.android.server.wifi.scanner.KnownBandsChannelHelper; +import com.android.server.wifi.scanner.PresetKnownBandsChannelHelper; import org.junit.After; import org.junit.Before; @@ -58,7 +58,7 @@ public class MultiClientSchedulerFilterTest { @Before public void setUp() throws Exception { - ChannelHelper channelHelper = new KnownBandsChannelHelper( + ChannelHelper channelHelper = new PresetKnownBandsChannelHelper( new int[]{2400, 2450}, new int[]{5150, 5175}, new int[]{5600, 5650}); diff --git a/tests/wifitests/src/com/android/server/wifi/MultiClientSchedulerTest.java b/tests/wifitests/src/com/android/server/wifi/MultiClientSchedulerTest.java index 45de55960..f0e8e95b8 100644 --- a/tests/wifitests/src/com/android/server/wifi/MultiClientSchedulerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/MultiClientSchedulerTest.java @@ -31,6 +31,7 @@ import android.test.suitebuilder.annotation.SmallTest; import com.android.server.wifi.WifiNative.BucketSettings; import com.android.server.wifi.scanner.KnownBandsChannelHelper; import com.android.server.wifi.scanner.KnownBandsChannelHelper.KnownBandsChannelCollection; +import com.android.server.wifi.scanner.PresetKnownBandsChannelHelper; import org.junit.After; import org.junit.Before; @@ -58,7 +59,7 @@ public class MultiClientSchedulerTest { @Before public void setUp() throws Exception { - mChannelHelper = new KnownBandsChannelHelper( + mChannelHelper = new PresetKnownBandsChannelHelper( new int[]{2400, 2450}, new int[]{5150, 5175}, new int[]{5600, 5650, 5660}); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScanningServiceTest.java index 870455df9..853c895bd 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiScanningServiceTest.java @@ -45,7 +45,7 @@ import com.android.internal.app.IBatteryStats; import com.android.internal.util.Protocol; import com.android.server.wifi.MockAnswerUtil.AnswerWithArguments; import com.android.server.wifi.scanner.ChannelHelper; -import com.android.server.wifi.scanner.KnownBandsChannelHelper; +import com.android.server.wifi.scanner.PresetKnownBandsChannelHelper; import org.junit.After; import org.junit.Before; @@ -73,7 +73,7 @@ public class WifiScanningServiceTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - ChannelHelper channelHelper = new KnownBandsChannelHelper( + ChannelHelper channelHelper = new PresetKnownBandsChannelHelper( new int[]{2400, 2450}, new int[]{5150, 5175}, new int[]{5600, 5650, 5660}); diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/KnownBandsChannelHelperTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/KnownBandsChannelHelperTest.java index 550fe41f0..0fec0ff29 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/KnownBandsChannelHelperTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/KnownBandsChannelHelperTest.java @@ -65,7 +65,7 @@ public class KnownBandsChannelHelperTest { */ @Before public void setUp() throws Exception { - mChannelHelper = new KnownBandsChannelHelper( + mChannelHelper = new PresetKnownBandsChannelHelper( CHANNELS_24_GHZ, CHANNELS_5_GHZ, CHANNELS_DFS); @@ -109,7 +109,7 @@ public class KnownBandsChannelHelperTest { */ @Before public void setUp() throws Exception { - mChannelHelper = new KnownBandsChannelHelper( + mChannelHelper = new PresetKnownBandsChannelHelper( CHANNELS_24_GHZ, CHANNELS_5_GHZ, CHANNELS_DFS); @@ -191,7 +191,7 @@ public class KnownBandsChannelHelperTest { */ @Before public void setUp() throws Exception { - mChannelHelper = new KnownBandsChannelHelper( + mChannelHelper = new PresetKnownBandsChannelHelper( CHANNELS_24_GHZ, CHANNELS_5_GHZ, CHANNELS_DFS); @@ -265,7 +265,7 @@ public class KnownBandsChannelHelperTest { */ @Before public void setUp() throws Exception { - KnownBandsChannelHelper channelHelper = new KnownBandsChannelHelper( + KnownBandsChannelHelper channelHelper = new PresetKnownBandsChannelHelper( CHANNELS_24_GHZ, CHANNELS_5_GHZ, CHANNELS_DFS); |