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 the HAL. 26 * Also supporting updating the channel list from the HAL on demand. 27 */ 28public class HalChannelHelper extends KnownBandsChannelHelper { 29 private static final String TAG = "HalChannelHelper"; 30 31 private final WifiNative mWifiNative; 32 33 public HalChannelHelper(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 = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_24_GHZ); 43 if (channels24G == null) Log.e(TAG, "Failed to get channels for 2.4GHz band"); 44 int[] channels5G = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ); 45 if (channels5G == null) Log.e(TAG, "Failed to get channels for 5GHz band"); 46 int[] channelsDfs = mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ_DFS_ONLY); 47 if (channelsDfs == null) Log.e(TAG, "Failed to get channels for 5GHz DFS only band"); 48 if (channels24G == null || channels5G == null || channelsDfs == null) { 49 Log.e(TAG, "Failed to get all channels for band, not updating band channel lists"); 50 } else if (channels24G.length > 0 || channels5G.length > 0 || channelsDfs.length > 0) { 51 setBandChannels(channels24G, channels5G, channelsDfs); 52 } else { 53 Log.e(TAG, "Got zero length for all channel lists"); 54 } 55 } 56} 57