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