• 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.ScanResult;
21 import android.net.wifi.WifiScanner;
22 import android.os.Looper;
23 
24 import com.android.server.wifi.Clock;
25 import com.android.server.wifi.WifiNative;
26 
27 import java.util.Comparator;
28 
29 /**
30  * Defines the interface to the Wifi hardware required for the WifiScanner API
31  */
32 public abstract class WifiScannerImpl {
33 
34     /**
35      * A factory that create a {@link com.android.server.wifi.scanner.WifiScannerImpl}
36      */
37     public static interface WifiScannerImplFactory {
create(Context context, Looper looper, Clock clock)38         WifiScannerImpl create(Context context, Looper looper, Clock clock);
39     }
40 
41     /**
42      * Factory that create the implementation that is most appropriate for the system.
43      * This factory should only ever be used once.
44      */
45     public static final WifiScannerImplFactory DEFAULT_FACTORY = new WifiScannerImplFactory() {
46             public WifiScannerImpl create(Context context, Looper looper, Clock clock) {
47                 WifiNative wifiNative = WifiNative.getWlanNativeInterface();
48                 if (wifiNative.getScanCapabilities(new WifiNative.ScanCapabilities())) {
49                     return new HalWifiScannerImpl(context, wifiNative, looper, clock);
50                 } else {
51                     return new SupplicantWifiScannerImpl(context, wifiNative, looper, clock);
52                 }
53             }
54         };
55 
56     /**
57      * A comparator that implements the sort order that is expected for scan results
58      */
59     protected static final Comparator<ScanResult> SCAN_RESULT_SORT_COMPARATOR =
60             new Comparator<ScanResult>() {
61         public int compare(ScanResult r1, ScanResult r2) {
62             return r2.level - r1.level;
63         }
64     };
65 
66     /**
67      * Cleanup any ongoing operations. This may be called when the driver is unloaded.
68      * There is no expectation that failure events are returned for ongoing operations.
69      */
cleanup()70     public abstract void cleanup();
71 
72     /**
73      * Get the supported scan capabilities.
74      *
75      * @param capabilities Object that will be filled with the supported capabilities if successful
76      * @return true if the scan capabilities were retrieved successfully
77      */
getScanCapabilities(WifiNative.ScanCapabilities capabilities)78     public abstract boolean getScanCapabilities(WifiNative.ScanCapabilities capabilities);
79 
80     /**
81      * Get a ChannelHelper that can be used to perform operations on scan channels
82      */
getChannelHelper()83     public abstract ChannelHelper getChannelHelper();
84 
85     /**
86      * Start a one time scan. This method should only be called when there is no scan going on
87      * (after a callback indicating that the previous scan succeeded/failed).
88      * @return if the scan paramaters are valid
89      * Note this may return true even if the parameters are not accepted by the chip because the
90      * scan may be scheduled async.
91      */
startSingleScan(WifiNative.ScanSettings settings, WifiNative.ScanEventHandler eventHandler)92     public abstract boolean startSingleScan(WifiNative.ScanSettings settings,
93             WifiNative.ScanEventHandler eventHandler);
94     /**
95      * Get the scan results of the most recent single scan. This should be called immediately when
96      * the scan success callback is receieved.
97      */
getLatestSingleScanResults()98     public abstract WifiScanner.ScanData getLatestSingleScanResults();
99 
100     /**
101      * Start a background scan. Calling this method while a background scan is already in process
102      * will interrupt the previous scan settings and replace it with the new ones.
103      * @return if the scan paramaters are valid
104      * Note this may return true even if the parameters are not accepted by the chip because the
105      * scan may be scheduled async.
106      */
startBatchedScan(WifiNative.ScanSettings settings, WifiNative.ScanEventHandler eventHandler)107     public abstract boolean startBatchedScan(WifiNative.ScanSettings settings,
108             WifiNative.ScanEventHandler eventHandler);
109     /**
110      * Stop the currently active background scan
111      */
stopBatchedScan()112     public abstract void stopBatchedScan();
113 
114     /**
115      * Pause the currently active background scan
116      */
pauseBatchedScan()117     public abstract void pauseBatchedScan();
118 
119     /**
120      * Restart the currently paused background scan
121      */
restartBatchedScan()122     public abstract void restartBatchedScan();
123 
124     /**
125      * Get the latest cached scan results from the last scan event. This should be called
126      * immediately when the scan success callback is receieved.
127      */
getLatestBatchedScanResults(boolean flush)128     public abstract WifiScanner.ScanData[] getLatestBatchedScanResults(boolean flush);
129 
130     /**
131      * Set PNO list to start PNO background scan.
132      * @param settings PNO settings for this scan.
133      * @param eventHandler Event handler for notifying the scan results.
134      * @return true if success, false otherwise
135      */
setHwPnoList(WifiNative.PnoSettings settings, WifiNative.PnoEventHandler eventHandler)136     public abstract boolean setHwPnoList(WifiNative.PnoSettings settings,
137             WifiNative.PnoEventHandler eventHandler);
138 
139     /**
140      * Reset PNO list to terminate PNO background scan.
141      * @return true if success, false otherwise
142      */
resetHwPnoList()143     public abstract boolean resetHwPnoList();
144 
145     /**
146      * This returns whether HW PNO is supported or not.
147      * @param isConnectedPno Whether this is connected PNO vs disconnected PNO.
148      * @return true if HW PNO is supported, false otherwise.
149      */
isHwPnoSupported(boolean isConnectedPno)150     public abstract boolean isHwPnoSupported(boolean isConnectedPno);
151 
152     /**
153      * This returns whether a background scan should be running for HW PNO scan or not.
154      * @return true if background scan needs to be started, false otherwise.
155      */
shouldScheduleBackgroundScanForHwPno()156     public abstract boolean shouldScheduleBackgroundScanForHwPno();
157 
158     /**
159      * Set a new hotlist
160      */
setHotlist(WifiScanner.HotlistSettings settings, WifiNative.HotlistEventHandler eventHandler)161     public abstract boolean setHotlist(WifiScanner.HotlistSettings settings,
162             WifiNative.HotlistEventHandler eventHandler);
163 
164     /**
165      * Reset any active hotlist
166      */
resetHotlist()167     public abstract void resetHotlist();
168 
169     /**
170      * Start tracking significant wifi changes
171      */
trackSignificantWifiChange(WifiScanner.WifiChangeSettings settings, WifiNative.SignificantWifiChangeEventHandler handler)172     public abstract boolean trackSignificantWifiChange(WifiScanner.WifiChangeSettings settings,
173             WifiNative.SignificantWifiChangeEventHandler handler);
174 
175     /**
176      * Stop tracking significant wifi changes
177      */
untrackSignificantWifiChange()178     public abstract void untrackSignificantWifiChange();
179 }
180