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 17package com.android.server.wifi.scanner; 18 19import android.net.wifi.WifiScanner; 20import android.util.Log; 21 22import 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 */ 28public class WificondChannelHelper extends KnownBandsChannelHelper { 29 private static final String TAG = "WificondChannelHelper"; 30 31 private final WifiNative mWifiNative; 32 33 public WificondChannelHelper(WifiNative wifiNative) { 34 mWifiNative = wifiNative; 35 final int[] emptyFreqList = new int[0]; 36 setBandChannels(emptyFreqList, emptyFreqList, emptyFreqList); 37 updateChannels(); 38 } 39 40 @Override 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 if (channels24G == null || channels5G == null || channelsDfs == null) { 51 Log.e(TAG, "Failed to get all channels for band, not updating band channel lists"); 52 } else if (channels24G.length > 0 || channels5G.length > 0 || channelsDfs.length > 0) { 53 setBandChannels(channels24G, channels5G, channelsDfs); 54 } else { 55 Log.e(TAG, "Got zero length for all channel lists"); 56 } 57 } 58} 59