diff options
author | Mitchell Wills <mwills@google.com> | 2016-03-17 23:09:00 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-03-17 23:09:00 +0000 |
commit | 71466f8b3cccbc46abad4f5b2d710fb22ce886cb (patch) | |
tree | 1c2b90b3e5d73c158729b39ee9d5b16e2cc0eafa /service | |
parent | a24cf11dc36674056efef38be297eea40cc5761f (diff) | |
parent | 95984d1af44a00183a4b0e0ed61417583096ff90 (diff) |
Merge "Merge MultiClientScheduler and WifiScanningScheduler" into nyc-dev
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiScanningScheduler.java | 157 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiScanningServiceImpl.java | 8 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/scanner/BackgroundScanScheduler.java (renamed from service/java/com/android/server/wifi/MultiClientScheduler.java) | 85 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/scanner/ScanScheduleUtil.java | 86 |
4 files changed, 163 insertions, 173 deletions
diff --git a/service/java/com/android/server/wifi/WifiScanningScheduler.java b/service/java/com/android/server/wifi/WifiScanningScheduler.java index 744afd55c..e69de29bb 100644 --- a/service/java/com/android/server/wifi/WifiScanningScheduler.java +++ b/service/java/com/android/server/wifi/WifiScanningScheduler.java @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2015 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; - -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.net.wifi.ScanResult; -import android.net.wifi.WifiScanner; - -import java.util.Collection; - -/** - * A class to handle scheduling wifi scan requests into a format for the wifi chipsets. - */ -public abstract class WifiScanningScheduler { - - static final int DEFAULT_MAX_BUCKETS = 8; - static final int DEFAULT_MAX_CHANNELS = 32; - // anecdotally, some chipsets will fail without explanation with a higher batch size, and - // there is apparently no way to retrieve the maximum batch size - static final int DEFAULT_MAX_SCANS_TO_BATCH = 10; - static final int DEFAULT_MAX_AP_PER_SCAN = 32; - - private int mMaxBuckets = DEFAULT_MAX_BUCKETS; - private int mMaxChannels = DEFAULT_MAX_CHANNELS; - private int mMaxBatch = DEFAULT_MAX_SCANS_TO_BATCH; - private int mMaxApPerScan = DEFAULT_MAX_AP_PER_SCAN; - - int getMaxBuckets() { - return mMaxBuckets; - } - - void setMaxBuckets(int maxBuckets) { - mMaxBuckets = maxBuckets; - } - - int getMaxChannels() { - return mMaxChannels; - } - - // TODO: find a way to get max channels - void setMaxChannels(int maxChannels) { - mMaxChannels = maxChannels; - } - - int getMaxBatch() { - return mMaxBatch; - } - - // TODO: find a way to get max batch size - void setMaxBatch(int maxBatch) { - mMaxBatch = maxBatch; - } - - int getMaxApPerScan() { - return mMaxApPerScan; - } - - void setMaxApPerScan(int maxApPerScan) { - mMaxApPerScan = maxApPerScan; - } - - /** - * Updates the schedule from the given set of requests. - */ - public abstract void updateSchedule(@NonNull Collection<WifiScanner.ScanSettings> requests); - - /** - * Retrieves the current scanning schedule. - */ - public abstract @NonNull WifiNative.ScanSettings getSchedule(); - - /** - * Returns true if the given scan result should be reported to a listener with the given - * settings. - */ - public abstract boolean shouldReportFullScanResultForSettings( - @NonNull ScanResult result, @NonNull WifiScanner.ScanSettings settings); - - /** - * Returns a filtered version of the scan results from the chip that represents only the data - * requested in the settings. Will return null if the result should not be reported. - */ - public abstract @Nullable WifiScanner.ScanData[] filterResultsForSettings( - @NonNull WifiScanner.ScanData[] results, @NonNull WifiScanner.ScanSettings settings); - - /** - * Compares two ChannelSettings for equality. - */ - public static boolean channelEquals(@Nullable WifiNative.ChannelSettings channel1, - @Nullable WifiNative.ChannelSettings channel2) { - if (channel1 == null || channel2 == null) return false; - if (channel1 == channel2) return true; - - if (channel1.frequency != channel2.frequency) return false; - if (channel1.dwell_time_ms != channel2.dwell_time_ms) return false; - return channel1.passive == channel2.passive; - } - - /** - * Compares two BucketSettings for equality. - */ - public static boolean bucketEquals(@Nullable WifiNative.BucketSettings bucket1, - @Nullable WifiNative.BucketSettings bucket2) { - if (bucket1 == null || bucket2 == null) return false; - if (bucket1 == bucket2) return true; - - if (bucket1.bucket != bucket2.bucket) return false; - if (bucket1.band != bucket2.band) return false; - if (bucket1.period_ms != bucket2.period_ms) return false; - if (bucket1.report_events != bucket2.report_events) return false; - if (bucket1.num_channels != bucket2.num_channels) return false; - for (int c = 0; c < bucket1.num_channels; c++) { - if (!channelEquals(bucket1.channels[c], bucket2.channels[c])) { - return false; - } - } - - return true; - } - - /** - * Compares two ScanSettings for equality. - */ - public static boolean scheduleEquals(@Nullable WifiNative.ScanSettings schedule1, - @Nullable WifiNative.ScanSettings schedule2) { - if (schedule1 == null || schedule2 == null) return false; - if (schedule1 == schedule2) return true; - - if (schedule1.base_period_ms != schedule2.base_period_ms) return false; - if (schedule1.max_ap_per_scan != schedule2.max_ap_per_scan) return false; - if (schedule1.report_threshold_percent != schedule2.report_threshold_percent) return false; - if (schedule1.report_threshold_num_scans != schedule2.report_threshold_num_scans) return false; - if (schedule1.num_buckets != schedule2.num_buckets) return false; - for (int b = 0; b < schedule1.num_buckets; b++) { - if (!bucketEquals(schedule1.buckets[b], schedule2.buckets[b])) { - return false; - } - } - - return true; - } -} diff --git a/service/java/com/android/server/wifi/WifiScanningServiceImpl.java b/service/java/com/android/server/wifi/WifiScanningServiceImpl.java index cbfda4ec3..96a07bdb8 100644 --- a/service/java/com/android/server/wifi/WifiScanningServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiScanningServiceImpl.java @@ -55,8 +55,10 @@ import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.internal.util.WakeupMessage; +import com.android.server.wifi.scanner.BackgroundScanScheduler; import com.android.server.wifi.scanner.ChannelHelper; import com.android.server.wifi.scanner.ChannelHelper.ChannelCollection; +import com.android.server.wifi.scanner.ScanScheduleUtil; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -236,7 +238,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { private final ArrayMap<Messenger, ClientInfo> mClients; private ChannelHelper mChannelHelper; - private WifiScanningScheduler mScheduler; + private BackgroundScanScheduler mScheduler; private WifiNative.ScanSettings mPreviousSchedule; private WifiBackgroundScanStateMachine mBackgroundScanStateMachine; @@ -747,7 +749,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { mChannelHelper = mScannerImpl.getChannelHelper(); } - mScheduler = new MultiClientScheduler(mChannelHelper); + mScheduler = new BackgroundScanScheduler(mChannelHelper); WifiNative.ScanCapabilities capabilities = new WifiNative.ScanCapabilities(); @@ -1297,7 +1299,7 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { mScheduler.updateSchedule(settings); WifiNative.ScanSettings schedule = mScheduler.getSchedule(); - if (WifiScanningScheduler.scheduleEquals(mPreviousSchedule, schedule)) { + if (ScanScheduleUtil.scheduleEquals(mPreviousSchedule, schedule)) { if (DBG) Log.d(TAG, "schedule updated with no change"); return true; } diff --git a/service/java/com/android/server/wifi/MultiClientScheduler.java b/service/java/com/android/server/wifi/scanner/BackgroundScanScheduler.java index 31fbf64e4..1a6569fc8 100644 --- a/service/java/com/android/server/wifi/MultiClientScheduler.java +++ b/service/java/com/android/server/wifi/scanner/BackgroundScanScheduler.java @@ -11,10 +11,10 @@ * 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 + * limitations under the License. */ -package com.android.server.wifi; +package com.android.server.wifi.scanner; import android.annotation.NonNull; import android.annotation.Nullable; @@ -25,7 +25,7 @@ import android.net.wifi.WifiScanner.ScanSettings; import android.util.Rational; import android.util.Slog; -import com.android.server.wifi.scanner.ChannelHelper; +import com.android.server.wifi.WifiNative; import com.android.server.wifi.scanner.ChannelHelper.ChannelCollection; import java.util.ArrayList; @@ -50,11 +50,18 @@ import java.util.List; * * <p>This class is not thread safe.</p> */ -public class MultiClientScheduler extends WifiScanningScheduler { +public class BackgroundScanScheduler { - private static final String TAG = WifiScanningService.TAG; + private static final String TAG = "BackgroundScanScheduler"; private static final boolean DBG = false; + public static final int DEFAULT_MAX_BUCKETS = 8; + public static final int DEFAULT_MAX_CHANNELS = 32; + // anecdotally, some chipsets will fail without explanation with a higher batch size, and + // there is apparently no way to retrieve the maximum batch size + public static final int DEFAULT_MAX_SCANS_TO_BATCH = 10; + public static final int DEFAULT_MAX_AP_PER_SCAN = 32; + /** * Value that all scan periods must be an integer multiple of */ @@ -113,7 +120,7 @@ public class MultiClientScheduler extends WifiScanningScheduler { public int period; public final List<ScanSettings> settings = new ArrayList<>(); - public Bucket(int period) { + Bucket(int period) { this.period = period; } @@ -191,7 +198,7 @@ public class MultiClientScheduler extends WifiScanningScheduler { private final Bucket[] mBuckets; private int mActiveBucketCount = 0; - public BucketList() { + BucketList() { mBuckets = new Bucket[PREDEFINED_BUCKET_PERIODS.length]; } @@ -241,18 +248,59 @@ public class MultiClientScheduler extends WifiScanningScheduler { } } + private int mMaxBuckets = DEFAULT_MAX_BUCKETS; + private int mMaxChannels = DEFAULT_MAX_CHANNELS; + private int mMaxBatch = DEFAULT_MAX_SCANS_TO_BATCH; + private int mMaxApPerScan = DEFAULT_MAX_AP_PER_SCAN; + + public int getMaxBuckets() { + return mMaxBuckets; + } + + public void setMaxBuckets(int maxBuckets) { + mMaxBuckets = maxBuckets; + } + + public int getMaxChannels() { + return mMaxChannels; + } + + // TODO: find a way to get max channels + public void setMaxChannels(int maxChannels) { + mMaxChannels = maxChannels; + } + + public int getMaxBatch() { + return mMaxBatch; + } + + // TODO: find a way to get max batch size + public void setMaxBatch(int maxBatch) { + mMaxBatch = maxBatch; + } + + public int getMaxApPerScan() { + return mMaxApPerScan; + } + + public void setMaxApPerScan(int maxApPerScan) { + mMaxApPerScan = maxApPerScan; + } + private final BucketList mBuckets = new BucketList(); private final ChannelHelper mChannelHelper; private final ChannelCollection mChannelCollection; private WifiNative.ScanSettings mSchedule; - public MultiClientScheduler(ChannelHelper channelHelper) { + public BackgroundScanScheduler(ChannelHelper channelHelper) { mChannelHelper = channelHelper; mChannelCollection = mChannelHelper.createChannelCollection(); mSchedule = createSchedule(Collections.<ScanSettings>emptyList()); } - @Override + /** + * Updates the schedule from the given set of requests. + */ public void updateSchedule(@NonNull Collection<ScanSettings> requests) { // create initial schedule mBuckets.clearAll(); @@ -265,18 +313,26 @@ public class MultiClientScheduler extends WifiScanningScheduler { mSchedule = createSchedule(requests); } - @Override + /** + * Retrieves the current scanning schedule. + */ public @NonNull WifiNative.ScanSettings getSchedule() { return mSchedule; } - @Override + /** + * Returns true if the given scan result should be reported to a listener with the given + * settings. + */ public boolean shouldReportFullScanResultForSettings(@NonNull ScanResult result, @NonNull ScanSettings settings) { return mChannelHelper.settingsContainChannel(settings, result.frequency); } - @Override + /** + * Returns a filtered version of the scan results from the chip that represents only the data + * requested in the settings. Will return null if the result should not be reported. + */ public @Nullable ScanData[] filterResultsForSettings(@NonNull ScanData[] scanDatas, @NonNull ScanSettings settings) { ArrayList<ScanData> filteredScanDatas = new ArrayList<>(scanDatas.length); @@ -379,7 +435,10 @@ public class MultiClientScheduler extends WifiScanningScheduler { return schedule; } - public void addScanToBuckets(ScanSettings settings) { + /** + * Add a scan to the most appropriate bucket, creating the bucket if necessary. + */ + private void addScanToBuckets(ScanSettings settings) { int bucketIndex; if (settings.maxPeriodInMs != 0 diff --git a/service/java/com/android/server/wifi/scanner/ScanScheduleUtil.java b/service/java/com/android/server/wifi/scanner/ScanScheduleUtil.java new file mode 100644 index 000000000..734a190ef --- /dev/null +++ b/service/java/com/android/server/wifi/scanner/ScanScheduleUtil.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2015 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.annotation.Nullable; + +import com.android.server.wifi.WifiNative; + +/** + * A class with utilities for dealing with scan schedules. + */ +public class ScanScheduleUtil { + + /** + * Compares two ChannelSettings for equality. + */ + public static boolean channelEquals(@Nullable WifiNative.ChannelSettings channel1, + @Nullable WifiNative.ChannelSettings channel2) { + if (channel1 == null || channel2 == null) return false; + if (channel1 == channel2) return true; + + if (channel1.frequency != channel2.frequency) return false; + if (channel1.dwell_time_ms != channel2.dwell_time_ms) return false; + return channel1.passive == channel2.passive; + } + + /** + * Compares two BucketSettings for equality. + */ + public static boolean bucketEquals(@Nullable WifiNative.BucketSettings bucket1, + @Nullable WifiNative.BucketSettings bucket2) { + if (bucket1 == null || bucket2 == null) return false; + if (bucket1 == bucket2) return true; + + if (bucket1.bucket != bucket2.bucket) return false; + if (bucket1.band != bucket2.band) return false; + if (bucket1.period_ms != bucket2.period_ms) return false; + if (bucket1.report_events != bucket2.report_events) return false; + if (bucket1.num_channels != bucket2.num_channels) return false; + for (int c = 0; c < bucket1.num_channels; c++) { + if (!channelEquals(bucket1.channels[c], bucket2.channels[c])) { + return false; + } + } + + return true; + } + + /** + * Compares two ScanSettings for equality. + */ + public static boolean scheduleEquals(@Nullable WifiNative.ScanSettings schedule1, + @Nullable WifiNative.ScanSettings schedule2) { + if (schedule1 == null || schedule2 == null) return false; + if (schedule1 == schedule2) return true; + + if (schedule1.base_period_ms != schedule2.base_period_ms) return false; + if (schedule1.max_ap_per_scan != schedule2.max_ap_per_scan) return false; + if (schedule1.report_threshold_percent != schedule2.report_threshold_percent) return false; + if (schedule1.report_threshold_num_scans != schedule2.report_threshold_num_scans) { + return false; + } + if (schedule1.num_buckets != schedule2.num_buckets) return false; + for (int b = 0; b < schedule1.num_buckets; b++) { + if (!bucketEquals(schedule1.buckets[b], schedule2.buckets[b])) { + return false; + } + } + + return true; + } +} |