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.Clock; 27import com.android.server.wifi.WifiMonitor; 28import com.android.server.wifi.WifiNative; 29 30/** 31 * WifiScanner implementation that takes advantage of the gscan HAL API 32 * The gscan API is used to perform background scans and wificond is used for oneshot scans. 33 * @see com.android.server.wifi.scanner.WifiScannerImpl for more details on each method. 34 */ 35public class HalWifiScannerImpl extends WifiScannerImpl implements Handler.Callback { 36 private static final String TAG = "HalWifiScannerImpl"; 37 private static final boolean DBG = false; 38 39 private final WifiNative mWifiNative; 40 private final ChannelHelper mChannelHelper; 41 private final WificondScannerImpl mWificondScannerDelegate; 42 private final boolean mHalBasedPnoSupported; 43 44 public HalWifiScannerImpl(Context context, WifiNative wifiNative, WifiMonitor wifiMonitor, 45 Looper looper, Clock clock) { 46 mWifiNative = wifiNative; 47 mChannelHelper = new HalChannelHelper(wifiNative); 48 mWificondScannerDelegate = 49 new WificondScannerImpl(context, wifiNative, wifiMonitor, mChannelHelper, 50 looper, clock); 51 52 // We are not going to support HAL ePNO currently. 53 mHalBasedPnoSupported = false; 54 } 55 56 @Override 57 public boolean handleMessage(Message msg) { 58 Log.w(TAG, "Unknown message received: " + msg.what); 59 return true; 60 } 61 62 @Override 63 public void cleanup() { 64 mWificondScannerDelegate.cleanup(); 65 } 66 67 @Override 68 public boolean getScanCapabilities(WifiNative.ScanCapabilities capabilities) { 69 return mWifiNative.getBgScanCapabilities(capabilities); 70 } 71 72 @Override 73 public ChannelHelper getChannelHelper() { 74 return mChannelHelper; 75 } 76 77 public boolean startSingleScan(WifiNative.ScanSettings settings, 78 WifiNative.ScanEventHandler eventHandler) { 79 return mWificondScannerDelegate.startSingleScan(settings, eventHandler); 80 } 81 82 @Override 83 public WifiScanner.ScanData getLatestSingleScanResults() { 84 return mWificondScannerDelegate.getLatestSingleScanResults(); 85 } 86 87 @Override 88 public boolean startBatchedScan(WifiNative.ScanSettings settings, 89 WifiNative.ScanEventHandler eventHandler) { 90 if (settings == null || eventHandler == null) { 91 Log.w(TAG, "Invalid arguments for startBatched: settings=" + settings 92 + ",eventHandler=" + eventHandler); 93 return false; 94 } 95 return mWifiNative.startBgScan(settings, eventHandler); 96 } 97 98 @Override 99 public void stopBatchedScan() { 100 mWifiNative.stopBgScan(); 101 } 102 103 @Override 104 public void pauseBatchedScan() { 105 mWifiNative.pauseBgScan(); 106 } 107 108 @Override 109 public void restartBatchedScan() { 110 mWifiNative.restartBgScan(); 111 } 112 113 @Override 114 public WifiScanner.ScanData[] getLatestBatchedScanResults(boolean flush) { 115 return mWifiNative.getBgScanResults(); 116 } 117 118 @Override 119 public boolean setHwPnoList(WifiNative.PnoSettings settings, 120 WifiNative.PnoEventHandler eventHandler) { 121 if (mHalBasedPnoSupported) { 122 return mWifiNative.setPnoList(settings, eventHandler); 123 } else { 124 return mWificondScannerDelegate.setHwPnoList(settings, eventHandler); 125 } 126 } 127 128 @Override 129 public boolean resetHwPnoList() { 130 if (mHalBasedPnoSupported) { 131 return mWifiNative.resetPnoList(); 132 } else { 133 return mWificondScannerDelegate.resetHwPnoList(); 134 } 135 } 136 137 @Override 138 public boolean isHwPnoSupported(boolean isConnectedPno) { 139 if (mHalBasedPnoSupported) { 140 return true; 141 } else { 142 return mWificondScannerDelegate.isHwPnoSupported(isConnectedPno); 143 } 144 } 145 146 @Override 147 public boolean shouldScheduleBackgroundScanForHwPno() { 148 if (mHalBasedPnoSupported) { 149 return true; 150 } else { 151 return mWificondScannerDelegate.shouldScheduleBackgroundScanForHwPno(); 152 } 153 } 154} 155