• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 WifiNative mWifiNative;
43     private final ChannelHelper mChannelHelper;
44     private final WificondScannerImpl mWificondScannerDelegate;
45 
HalWifiScannerImpl(Context context, String ifaceName, WifiNative wifiNative, WifiMonitor wifiMonitor, Looper looper, Clock clock)46     public HalWifiScannerImpl(Context context, String ifaceName, WifiNative wifiNative,
47                               WifiMonitor wifiMonitor, Looper looper, Clock clock) {
48         super(ifaceName);
49         mWifiNative = wifiNative;
50         mChannelHelper = new WificondChannelHelper(wifiNative);
51         mWificondScannerDelegate =
52                 new WificondScannerImpl(context, getIfaceName(), wifiNative, wifiMonitor,
53                         mChannelHelper, looper, clock);
54     }
55 
56     @Override
handleMessage(Message msg)57     public boolean handleMessage(Message msg) {
58         Log.w(TAG, "Unknown message received: " + msg.what);
59         return true;
60     }
61 
62     @Override
cleanup()63     public void cleanup() {
64         mWificondScannerDelegate.cleanup();
65     }
66 
67     @Override
getScanCapabilities(WifiNative.ScanCapabilities capabilities)68     public boolean getScanCapabilities(WifiNative.ScanCapabilities capabilities) {
69         return mWifiNative.getBgScanCapabilities(
70                 getIfaceName(), capabilities);
71     }
72 
73     @Override
getChannelHelper()74     public ChannelHelper getChannelHelper() {
75         return mChannelHelper;
76     }
77 
startSingleScan(WifiNative.ScanSettings settings, WifiNative.ScanEventHandler eventHandler)78     public boolean startSingleScan(WifiNative.ScanSettings settings,
79             WifiNative.ScanEventHandler eventHandler) {
80         return mWificondScannerDelegate.startSingleScan(settings, eventHandler);
81     }
82 
83     @Override
getLatestSingleScanResults()84     public WifiScanner.ScanData getLatestSingleScanResults() {
85         return mWificondScannerDelegate.getLatestSingleScanResults();
86     }
87 
88     @Override
startBatchedScan(WifiNative.ScanSettings settings, WifiNative.ScanEventHandler eventHandler)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.startBgScan(
97                 getIfaceName(), settings, eventHandler);
98     }
99 
100     @Override
stopBatchedScan()101     public void stopBatchedScan() {
102         mWifiNative.stopBgScan(getIfaceName());
103     }
104 
105     @Override
pauseBatchedScan()106     public void pauseBatchedScan() {
107         mWifiNative.pauseBgScan(getIfaceName());
108     }
109 
110     @Override
restartBatchedScan()111     public void restartBatchedScan() {
112         mWifiNative.restartBgScan(getIfaceName());
113     }
114 
115     @Override
getLatestBatchedScanResults(boolean flush)116     public WifiScanner.ScanData[] getLatestBatchedScanResults(boolean flush) {
117         return mWifiNative.getBgScanResults(getIfaceName());
118     }
119 
120     @Override
setHwPnoList(WifiNative.PnoSettings settings, WifiNative.PnoEventHandler eventHandler)121     public boolean setHwPnoList(WifiNative.PnoSettings settings,
122             WifiNative.PnoEventHandler eventHandler) {
123         return mWificondScannerDelegate.setHwPnoList(settings, eventHandler);
124     }
125 
126     @Override
resetHwPnoList()127     public boolean resetHwPnoList() {
128         return mWificondScannerDelegate.resetHwPnoList();
129     }
130 
131     @Override
isHwPnoSupported(boolean isConnectedPno)132     public boolean isHwPnoSupported(boolean isConnectedPno) {
133         return mWificondScannerDelegate.isHwPnoSupported(isConnectedPno);
134     }
135 
136     @Override
dump(FileDescriptor fd, PrintWriter pw, String[] args)137     protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
138         mWificondScannerDelegate.dump(fd, pw, args);
139     }
140 }
141