1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.wifi.scanner;
18 
19 import android.net.wifi.WifiScanner;
20 import android.util.Log;
21 
22 import com.android.server.wifi.WifiNative;
23 
24 /**
25  * KnownBandsChannelHelper that uses band to channel mappings retrieved from wificond.
26  * Also supporting updating the channel list from the wificond on demand.
27  */
28 public class WificondChannelHelper extends KnownBandsChannelHelper {
29     private static final String TAG = "WificondChannelHelper";
30 
31     private final WifiNative mWifiNative;
32 
WificondChannelHelper(WifiNative wifiNative)33     public WificondChannelHelper(WifiNative wifiNative) {
34         mWifiNative = wifiNative;
35         final int[] emptyFreqList = new int[0];
36         setBandChannels(emptyFreqList, emptyFreqList, emptyFreqList, emptyFreqList, emptyFreqList);
37         updateChannels();
38     }
39 
40     @Override
updateChannels()41     public void updateChannels() {
42         int[] channels24G =
43                 mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ);
44         if (channels24G == null) Log.e(TAG, "Failed to get channels for 2.4GHz band");
45         int[] channels5G = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ);
46         if (channels5G == null) Log.e(TAG, "Failed to get channels for 5GHz band");
47         int[] channelsDfs =
48                 mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ_DFS_ONLY);
49         if (channelsDfs == null) Log.e(TAG, "Failed to get channels for 5GHz DFS only band");
50         int[] channels6G =
51                 mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_6_GHZ);
52         if (channels6G == null) Log.e(TAG, "Failed to get channels for 6GHz band");
53         int[] channels60G =
54                 mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_60_GHZ);
55         if (channels60G == null) Log.e(TAG, "Failed to get channels for 60GHz band");
56 
57         if (channels24G == null || channels5G == null || channelsDfs == null
58                 || channels6G == null || channels60G == null) {
59             Log.e(TAG, "Failed to get all channels for band, not updating band channel lists");
60         } else if (channels24G.length > 0 || channels5G.length > 0 || channelsDfs.length > 0
61                 || channels6G.length > 0 || channels60G.length > 0) {
62             setBandChannels(channels24G, channels5G, channelsDfs, channels6G, channels60G);
63         } else {
64             Log.e(TAG, "Got zero length for all channel lists");
65         }
66     }
67 }
68