HalWifiScannerImpl.java revision a8367288377cbaed6371256ca837b7aa22280706
1/* 2 * Copyright (C) 2015 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.content.Context; 20import android.net.wifi.WifiScanner; 21import android.os.Handler; 22import android.os.Looper; 23import android.os.Message; 24import android.util.Log; 25 26import com.android.server.wifi.WifiNative; 27 28/** 29 * WifiScanner implementation that takes advantage of the gscan HAL API 30 * The gscan API is used to perform background scans and wpa_supplicant is used for onehot scans. 31 * @see com.android.server.wifi.scanner.WifiScannerImpl for more details on each method. 32 */ 33public class HalWifiScannerImpl extends WifiScannerImpl implements Handler.Callback { 34 private static final String TAG = "HalWifiScannerImpl"; 35 private static final boolean DBG = false; 36 37 private final WifiNative mWifiNative; 38 private final ChannelHelper mChannelHelper; 39 private final SupplicantWifiScannerImpl mSupplicantScannerDelegate; 40 private final boolean mHalBasedPnoSupported; 41 42 public HalWifiScannerImpl(Context context, WifiNative wifiNative, Looper looper) { 43 mWifiNative = wifiNative; 44 mChannelHelper = new HalChannelHelper(wifiNative); 45 mSupplicantScannerDelegate = 46 new SupplicantWifiScannerImpl(context, wifiNative, mChannelHelper, looper); 47 48 // Check if ePNO is supported by the HAL. 49 int halFeatureSet = mWifiNative.getSupportedFeatureSet(); 50 mHalBasedPnoSupported = false; 51 /* TODO(b/27877781): Swith ePNO on 52 mHalBasedPnoSupported = 53 ((halFeatureSet & WifiManager.WIFI_FEATURE_HAL_EPNO) 54 == WifiManager.WIFI_FEATURE_HAL_EPNO); */ 55 } 56 57 @Override 58 public boolean handleMessage(Message msg) { 59 Log.w(TAG, "Unknown message received: " + msg.what); 60 return true; 61 } 62 63 @Override 64 public void cleanup() { 65 mSupplicantScannerDelegate.cleanup(); 66 } 67 68 @Override 69 public boolean getScanCapabilities(WifiNative.ScanCapabilities capabilities) { 70 return mWifiNative.getScanCapabilities(capabilities); 71 } 72 73 @Override 74 public ChannelHelper getChannelHelper() { 75 return mChannelHelper; 76 } 77 78 public boolean startSingleScan(WifiNative.ScanSettings settings, 79 WifiNative.ScanEventHandler eventHandler) { 80 return mSupplicantScannerDelegate.startSingleScan(settings, eventHandler); 81 } 82 83 @Override 84 public WifiScanner.ScanData getLatestSingleScanResults() { 85 return mSupplicantScannerDelegate.getLatestSingleScanResults(); 86 } 87 88 @Override 89 public boolean startBatchedScan(WifiNative.ScanSettings settings, 90 WifiNative.ScanEventHandler eventHandler) { 91 if (settings == null || eventHandler == null) { 92 Log.w(TAG, "Invalid arguments for startBatched: settings=" + settings 93 + ",eventHandler=" + eventHandler); 94 return false; 95 } 96 return mWifiNative.startScan(settings, eventHandler); 97 } 98 99 @Override 100 public void stopBatchedScan() { 101 mWifiNative.stopScan(); 102 } 103 104 @Override 105 public void pauseBatchedScan() { 106 mWifiNative.pauseScan(); 107 } 108 109 @Override 110 public void restartBatchedScan() { 111 mWifiNative.restartScan(); 112 } 113 114 @Override 115 public WifiScanner.ScanData[] getLatestBatchedScanResults(boolean flush) { 116 return mWifiNative.getScanResults(flush); 117 } 118 119 @Override 120 public boolean setHwPnoList(WifiNative.PnoSettings settings, 121 WifiNative.PnoEventHandler eventHandler) { 122 if (mHalBasedPnoSupported) { 123 return mWifiNative.setPnoList(settings, eventHandler); 124 } else { 125 return mSupplicantScannerDelegate.setHwPnoList(settings, eventHandler); 126 } 127 } 128 129 @Override 130 public boolean resetHwPnoList() { 131 if (mHalBasedPnoSupported) { 132 return mWifiNative.resetPnoList(); 133 } else { 134 return mSupplicantScannerDelegate.resetHwPnoList(); 135 } 136 } 137 138 @Override 139 public boolean isHwPnoSupported(boolean isConnectedPno) { 140 if (mHalBasedPnoSupported) { 141 return true; 142 } else { 143 return mSupplicantScannerDelegate.isHwPnoSupported(isConnectedPno); 144 } 145 } 146 147 @Override 148 public boolean shouldScheduleBackgroundScanForHwPno() { 149 if (mHalBasedPnoSupported) { 150 return true; 151 } else { 152 return mSupplicantScannerDelegate.shouldScheduleBackgroundScanForHwPno(); 153 } 154 } 155 156 @Override 157 public boolean setHotlist(WifiScanner.HotlistSettings settings, 158 WifiNative.HotlistEventHandler eventHandler) { 159 return mWifiNative.setHotlist(settings, eventHandler); 160 } 161 162 @Override 163 public void resetHotlist() { 164 mWifiNative.resetHotlist(); 165 } 166 167 @Override 168 public boolean trackSignificantWifiChange(WifiScanner.WifiChangeSettings settings, 169 WifiNative.SignificantWifiChangeEventHandler handler) { 170 return mWifiNative.trackSignificantWifiChange(settings, handler); 171 } 172 173 @Override 174 public void untrackSignificantWifiChange() { 175 mWifiNative.untrackSignificantWifiChange(); 176 } 177} 178