blob: b2eeada710b6cca31f6b6c0dce6c7b103a80d0f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/*
* 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.ArraySet;
import com.android.server.wifi.WifiNative;
import java.util.Set;
/**
* ChannelHelper that offers channel manipulation utilities when the channels in a band are not
* known. Operations performed may simplify any band to include all channels.
*/
public class NoBandChannelHelper extends ChannelHelper {
/**
* 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
* specifies a band instead of a list of channels.
*/
private static final int ALL_BAND_CHANNEL_COUNT_ESTIMATE = 36;
@Override
public boolean settingsContainChannel(WifiScanner.ScanSettings settings, int channel) {
if (settings.band == WifiScanner.WIFI_BAND_UNSPECIFIED) {
for (int i = 0; i < settings.channels.length; ++i) {
if (settings.channels[i].frequency == channel) {
return true;
}
}
return false;
} else {
return true;
}
}
@Override
public WifiScanner.ChannelSpec[] getAvailableScanChannels(int band) {
return NO_CHANNELS; // not supported
}
@Override
public int estimateScanDuration(WifiScanner.ScanSettings settings) {
if (settings.band == WifiScanner.WIFI_BAND_UNSPECIFIED) {
return settings.channels.length * SCAN_PERIOD_PER_CHANNEL_MS;
} else {
return ALL_BAND_CHANNEL_COUNT_ESTIMATE * SCAN_PERIOD_PER_CHANNEL_MS;
}
}
/**
* ChannelCollection that merges channels without knowing which channels are in each band. In
* order to do this if any band is added or the maxChannels is exceeded then all channels will
* be included.
*/
public class NoBandChannelCollection extends ChannelCollection {
private final ArraySet<Integer> mChannels = new ArraySet<Integer>();
private boolean mAllChannels = false;
@Override
public void addChannel(int frequency) {
mChannels.add(frequency);
}
@Override
public void addBand(int band) {
if (band != WifiScanner.WIFI_BAND_UNSPECIFIED) {
mAllChannels = true;
}
}
@Override
public boolean containsChannel(int channel) {
return mAllChannels || mChannels.contains(channel);
}
@Override
public boolean containsBand(int band) {
if (band != WifiScanner.WIFI_BAND_UNSPECIFIED) {
return mAllChannels;
}
return false;
}
@Override
public boolean partiallyContainsBand(int band) {
// We don't need to partially collapse settings in wificond scanner because we
// don't have any limitation on the number of channels that can be scanned. We also
// don't currently keep track of bands very well in NoBandChannelHelper.
return false;
}
@Override
public boolean isEmpty() {
return !mAllChannels && mChannels.isEmpty();
}
@Override
public boolean isAllChannels() {
return mAllChannels;
}
@Override
public void clear() {
mAllChannels = false;
mChannels.clear();
}
@Override
public Set<Integer> getMissingChannelsFromBand(int band) {
// We don't need to partially collapse settings in wificond scanner because we
// don't have any limitation on the number of channels that can be scanned. We also
// don't currently keep track of bands very well in NoBandChannelHelper.
return new ArraySet<Integer>();
}
@Override
public Set<Integer> getContainingChannelsFromBand(int band) {
// We don't need to partially collapse settings in wificond scanner because we
// don't have any limitation on the number of channels that can be scanned. We also
// don't currently keep track of bands very well in NoBandChannelHelper.
return new ArraySet<Integer>();
}
@Override
public Set<Integer> getChannelSet() {
if (!isEmpty() && !mAllChannels) {
return mChannels;
} else {
return new ArraySet<>();
}
}
@Override
public void fillBucketSettings(WifiNative.BucketSettings bucketSettings, int maxChannels) {
if (mAllChannels || mChannels.size() > maxChannels) {
bucketSettings.band = WifiScanner.WIFI_BAND_BOTH_WITH_DFS;
bucketSettings.num_channels = 0;
bucketSettings.channels = null;
} else {
bucketSettings.band = WifiScanner.WIFI_BAND_UNSPECIFIED;
bucketSettings.num_channels = mChannels.size();
bucketSettings.channels = new WifiNative.ChannelSettings[mChannels.size()];
for (int i = 0; i < mChannels.size(); ++i) {
WifiNative.ChannelSettings channelSettings = new WifiNative.ChannelSettings();
channelSettings.frequency = mChannels.valueAt(i);
bucketSettings.channels[i] = channelSettings;
}
}
}
@Override
public Set<Integer> getScanFreqs() {
if (mAllChannels) {
return null;
} else {
return new ArraySet<Integer>(mChannels);
}
}
}
@Override
public ChannelCollection createChannelCollection() {
return new NoBandChannelCollection();
}
}
|