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 17 package com.android.server.wifi.scanner; 18 19 import android.content.Context; 20 import android.net.wifi.WifiScanner; 21 import android.os.Handler; 22 import android.os.Looper; 23 import android.os.Message; 24 import android.util.Log; 25 26 import com.android.server.wifi.Clock; 27 import com.android.server.wifi.WifiMonitor; 28 import com.android.server.wifi.WifiNative; 29 30 import java.io.FileDescriptor; 31 import java.io.PrintWriter; 32 33 /** 34 * WifiScanner implementation that takes advantage of the gscan HAL API 35 * The gscan API is used to perform background scans and wificond is used for oneshot scans. 36 * @see com.android.server.wifi.scanner.WifiScannerImpl for more details on each method. 37 */ 38 public class HalWifiScannerImpl extends WifiScannerImpl implements Handler.Callback { 39 private static final String TAG = "HalWifiScannerImpl"; 40 private static final boolean DBG = false; 41 42 private final String mIfaceName; 43 private final WifiNative mWifiNative; 44 private final ChannelHelper mChannelHelper; 45 private final WificondScannerImpl mWificondScannerDelegate; 46 47 public HalWifiScannerImpl(Context context, String ifaceName, WifiNative wifiNative, 48 WifiMonitor wifiMonitor, Looper looper, Clock clock) { 49 mIfaceName = ifaceName; 50 mWifiNative = wifiNative; 51 mChannelHelper = new WificondChannelHelper(wifiNative); 52 mWificondScannerDelegate = 53 new WificondScannerImpl(context, mIfaceName, wifiNative, wifiMonitor, 54 mChannelHelper, looper, clock); 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 mWificondScannerDelegate.cleanup(); 66 } 67 68 @Override 69 public boolean getScanCapabilities(WifiNative.ScanCapabilities capabilities) { 70 return mWifiNative.getBgScanCapabilities( 71 mIfaceName, capabilities); 72 } 73 74 @Override 75 public ChannelHelper getChannelHelper() { 76 return mChannelHelper; 77 } 78 79 public boolean startSingleScan(WifiNative.ScanSettings settings, 80 WifiNative.ScanEventHandler eventHandler) { 81 return mWificondScannerDelegate.startSingleScan(settings, eventHandler); 82 } 83 84 @Override 85 public WifiScanner.ScanData getLatestSingleScanResults() { 86 return mWificondScannerDelegate.getLatestSingleScanResults(); 87 } 88 89 @Override 90 public boolean startBatchedScan(WifiNative.ScanSettings settings, 91 WifiNative.ScanEventHandler eventHandler) { 92 if (settings == null || eventHandler == null) { 93 Log.w(TAG, "Invalid arguments for startBatched: settings=" + settings 94 + ",eventHandler=" + eventHandler); 95 return false; 96 } 97 return mWifiNative.startBgScan( 98 mIfaceName, settings, eventHandler); 99 } 100 101 @Override 102 public void stopBatchedScan() { 103 mWifiNative.stopBgScan(mIfaceName); 104 } 105 106 @Override 107 public void pauseBatchedScan() { 108 mWifiNative.pauseBgScan(mIfaceName); 109 } 110 111 @Override 112 public void restartBatchedScan() { 113 mWifiNative.restartBgScan(mIfaceName); 114 } 115 116 @Override 117 public WifiScanner.ScanData[] getLatestBatchedScanResults(boolean flush) { 118 return mWifiNative.getBgScanResults(mIfaceName); 119 } 120 121 @Override 122 public boolean setHwPnoList(WifiNative.PnoSettings settings, 123 WifiNative.PnoEventHandler eventHandler) { 124 return mWificondScannerDelegate.setHwPnoList(settings, eventHandler); 125 } 126 127 @Override 128 public boolean resetHwPnoList() { 129 return mWificondScannerDelegate.resetHwPnoList(); 130 } 131 132 @Override 133 public boolean isHwPnoSupported(boolean isConnectedPno) { 134 return mWificondScannerDelegate.isHwPnoSupported(isConnectedPno); 135 } 136 137 @Override 138 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 139 mWificondScannerDelegate.dump(fd, pw, args); 140 } 141 } 142