• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.p2p;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.net.wifi.p2p.WifiP2pConfig;
22 import android.net.wifi.p2p.WifiP2pDevice;
23 import android.net.wifi.p2p.WifiP2pGroup;
24 import android.net.wifi.p2p.WifiP2pProvDiscEvent;
25 import android.net.wifi.p2p.nsd.WifiP2pServiceResponse;
26 import android.os.Handler;
27 import android.os.Message;
28 import android.util.ArraySet;
29 import android.util.Log;
30 import android.util.SparseArray;
31 
32 import com.android.internal.annotations.VisibleForTesting;
33 import com.android.internal.util.Protocol;
34 import com.android.server.wifi.p2p.WifiP2pServiceImpl.P2pStatus;
35 
36 import java.lang.annotation.Retention;
37 import java.lang.annotation.RetentionPolicy;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.Set;
42 
43 /**
44  * Listens for events from the wpa_supplicant, and passes them on
45  * to the {@link WifiP2pServiceImpl} for handling.
46  */
47 public class WifiP2pMonitor {
48     private static final String TAG = "WifiP2pMonitor";
49 
50     /* Supplicant events reported to a state machine */
51     private static final int BASE = Protocol.BASE_WIFI_MONITOR;
52 
53     /* Connection to supplicant established */
54     public static final int SUP_CONNECTION_EVENT                 = BASE + 1;
55     /* Connection to supplicant lost */
56     public static final int SUP_DISCONNECTION_EVENT              = BASE + 2;
57 
58     /* P2P events */
59     public static final int P2P_DEVICE_FOUND_EVENT               = BASE + 21;
60     public static final int P2P_DEVICE_LOST_EVENT                = BASE + 22;
61     public static final int P2P_GO_NEGOTIATION_REQUEST_EVENT     = BASE + 23;
62     public static final int P2P_GO_NEGOTIATION_SUCCESS_EVENT     = BASE + 25;
63     public static final int P2P_GO_NEGOTIATION_FAILURE_EVENT     = BASE + 26;
64     public static final int P2P_GROUP_FORMATION_SUCCESS_EVENT    = BASE + 27;
65     public static final int P2P_GROUP_FORMATION_FAILURE_EVENT    = BASE + 28;
66     public static final int P2P_GROUP_STARTED_EVENT              = BASE + 29;
67     public static final int P2P_GROUP_REMOVED_EVENT              = BASE + 30;
68     public static final int P2P_INVITATION_RECEIVED_EVENT        = BASE + 31;
69     public static final int P2P_INVITATION_RESULT_EVENT          = BASE + 32;
70     public static final int P2P_PROV_DISC_PBC_REQ_EVENT          = BASE + 33;
71     public static final int P2P_PROV_DISC_PBC_RSP_EVENT          = BASE + 34;
72     public static final int P2P_PROV_DISC_ENTER_PIN_EVENT        = BASE + 35;
73     public static final int P2P_PROV_DISC_SHOW_PIN_EVENT         = BASE + 36;
74     public static final int P2P_FIND_STOPPED_EVENT               = BASE + 37;
75     public static final int P2P_SERV_DISC_RESP_EVENT             = BASE + 38;
76     public static final int P2P_PROV_DISC_FAILURE_EVENT          = BASE + 39;
77     public static final int P2P_FREQUENCY_CHANGED_EVENT          = BASE + 40;
78 
79     /* hostap events */
80     public static final int AP_STA_DISCONNECTED_EVENT            = BASE + 41;
81     public static final int AP_STA_CONNECTED_EVENT               = BASE + 42;
82 
83     /* USD service discovery events */
84     public static final int USD_BASED_SERVICE_DISCOVERY_TERMINATED_EVENT = BASE + 43;
85     public static final int USD_BASED_SERVICE_ADVERTISEMENT_TERMINATED_EVENT = BASE + 44;
86 
87     /* Provision Discovery event with Pairing bootstrapping method */
88     public static final int P2P_PROV_DISC_PAIRING_BOOTSTRAPPING_OPPORTUNISTIC_REQ_EVENT = BASE + 45;
89     public static final int P2P_PROV_DISC_PAIRING_BOOTSTRAPPING_OPPORTUNISTIC_RSP_EVENT = BASE + 46;
90     public static final int P2P_PROV_DISC_ENTER_PAIRING_BOOTSTRAPPING_PIN_OR_PASSPHRASE_EVENT =
91             BASE + 47;
92     public static final int P2P_PROV_DISC_SHOW_PAIRING_BOOTSTRAPPING_PIN_OR_PASSPHRASE_EVENT =
93             BASE + 48;
94 
95     public static final int PROV_DISC_STATUS_SUCCESS             = 0;
96     public static final int PROV_DISC_STATUS_TIMEOUT             = 1;
97     public static final int PROV_DISC_STATUS_REJECTED            = 2;
98     public static final int PROV_DISC_STATUS_TIMEOUT_JOIN        = 3;
99     public static final int PROV_DISC_STATUS_INFO_UNAVAILABLE    = 4;
100     public static final int PROV_DISC_STATUS_UNKNOWN             = 5;
101     @IntDef(prefix = {"PROV_DISC_STATUS_"}, value = {
102             PROV_DISC_STATUS_SUCCESS,
103             PROV_DISC_STATUS_TIMEOUT,
104             PROV_DISC_STATUS_REJECTED,
105             PROV_DISC_STATUS_TIMEOUT_JOIN,
106             PROV_DISC_STATUS_INFO_UNAVAILABLE,
107             PROV_DISC_STATUS_UNKNOWN})
108     @Retention(RetentionPolicy.SOURCE)
109     public @interface P2pProvDiscStatus {
110     }
111 
112     private boolean mVerboseLoggingEnabled = false;
113 
114     /**
115      * Enable verbose logging for all sub modules.
116      */
enableVerboseLogging(boolean verboseEnabled)117     public void enableVerboseLogging(boolean verboseEnabled) {
118         mVerboseLoggingEnabled = verboseEnabled;
119     }
120 
121     private final Map<String, SparseArray<Set<Handler>>> mHandlerMap = new HashMap<>();
122 
123     /**
124      * Registers a callback handler for the provided event.
125      */
registerHandler(String iface, int what, Handler handler)126     public synchronized void registerHandler(String iface, int what, Handler handler) {
127         SparseArray<Set<Handler>> ifaceHandlers = mHandlerMap.get(iface);
128         if (ifaceHandlers == null) {
129             ifaceHandlers = new SparseArray<>();
130             mHandlerMap.put(iface, ifaceHandlers);
131         }
132         Set<Handler> ifaceWhatHandlers = ifaceHandlers.get(what);
133         if (ifaceWhatHandlers == null) {
134             ifaceWhatHandlers = new ArraySet<>();
135             ifaceHandlers.put(what, ifaceWhatHandlers);
136         }
137         ifaceWhatHandlers.add(handler);
138     }
139 
140     private final Map<String, Boolean> mMonitoringMap = new HashMap<>();
isMonitoring(String iface)141     private boolean isMonitoring(String iface) {
142         Boolean val = mMonitoringMap.get(iface);
143         if (val == null) {
144             return false;
145         } else {
146             return val.booleanValue();
147         }
148     }
149 
150     /**
151      * Enable/Disable monitoring for the provided iface.
152      *
153      * @param iface Name of the iface.
154      * @param enabled true to enable, false to disable.
155      */
156     @VisibleForTesting
setMonitoring(String iface, boolean enabled)157     public void setMonitoring(String iface, boolean enabled) {
158         mMonitoringMap.put(iface, enabled);
159     }
160 
161     /**
162      * Start Monitoring for wpa_supplicant events.
163      *
164      * @param iface Name of iface.
165      * TODO: Add unit tests for these once we remove the legacy code.
166      */
startMonitoring(String iface)167     public synchronized void startMonitoring(String iface) {
168         setMonitoring(iface, true);
169         broadcastSupplicantConnectionEvent(iface);
170     }
171 
172     /**
173      * Stop Monitoring for wpa_supplicant events.
174      *
175      * @param iface Name of iface.
176      * TODO: Add unit tests for these once we remove the legacy code.
177      */
stopMonitoring(String iface)178     public synchronized void stopMonitoring(String iface) {
179         if (mVerboseLoggingEnabled) Log.d(TAG, "stopMonitoring(" + iface + ")");
180         setMonitoring(iface, true);
181         broadcastSupplicantDisconnectionEvent(iface);
182         setMonitoring(iface, false);
183     }
184 
185     /**
186      * Similar functions to Handler#sendMessage that send the message to the registered handler
187      * for the given interface and message what.
188      * All of these should be called with the WifiMonitor class lock
189      */
sendMessage(String iface, int what)190     private void sendMessage(String iface, int what) {
191         sendMessage(iface, Message.obtain(null, what));
192     }
193 
sendMessage(String iface, int what, Object obj)194     private void sendMessage(String iface, int what, Object obj) {
195         sendMessage(iface, Message.obtain(null, what, obj));
196     }
197 
sendMessage(String iface, int what, int arg1)198     private void sendMessage(String iface, int what, int arg1) {
199         sendMessage(iface, Message.obtain(null, what, arg1, 0));
200     }
201 
sendMessage(String iface, int what, int arg1, int arg2)202     private void sendMessage(String iface, int what, int arg1, int arg2) {
203         sendMessage(iface, Message.obtain(null, what, arg1, arg2));
204     }
205 
sendMessage(String iface, int what, int arg1, int arg2, Object obj)206     private void sendMessage(String iface, int what, int arg1, int arg2, Object obj) {
207         sendMessage(iface, Message.obtain(null, what, arg1, arg2, obj));
208     }
209 
sendMessage(String iface, Message message)210     private void sendMessage(String iface, Message message) {
211         SparseArray<Set<Handler>> ifaceHandlers = mHandlerMap.get(iface);
212         if (iface != null && ifaceHandlers != null) {
213             if (isMonitoring(iface)) {
214                 Set<Handler> ifaceWhatHandlers = ifaceHandlers.get(message.what);
215                 if (ifaceWhatHandlers != null) {
216                     for (Handler handler : ifaceWhatHandlers) {
217                         if (handler != null) {
218                             sendMessage(handler, Message.obtain(message));
219                         }
220                     }
221                 }
222             } else {
223                 if (mVerboseLoggingEnabled) {
224                     Log.d(TAG, "Dropping event because (" + iface + ") is stopped");
225                 }
226             }
227         } else {
228             if (mVerboseLoggingEnabled) {
229                 Log.d(TAG, "Sending to all monitors because there's no matching iface");
230             }
231             for (Map.Entry<String, SparseArray<Set<Handler>>> entry : mHandlerMap.entrySet()) {
232                 if (isMonitoring(entry.getKey())) {
233                     Set<Handler> ifaceWhatHandlers = entry.getValue().get(message.what);
234                     for (Handler handler : ifaceWhatHandlers) {
235                         if (handler != null) {
236                             sendMessage(handler, Message.obtain(message));
237                         }
238                     }
239                 }
240             }
241         }
242 
243         message.recycle();
244     }
245 
sendMessage(Handler handler, Message message)246     private void sendMessage(Handler handler, Message message) {
247         message.setTarget(handler);
248         message.sendToTarget();
249     }
250 
251     /**
252      * Broadcast the connection to wpa_supplicant event to all the handlers registered for
253      * this event.
254      *
255      * @param iface Name of iface on which this occurred.
256      */
broadcastSupplicantConnectionEvent(String iface)257     public void broadcastSupplicantConnectionEvent(String iface) {
258         sendMessage(iface, SUP_CONNECTION_EVENT);
259     }
260 
261     /**
262      * Broadcast the loss of connection to wpa_supplicant event to all the handlers registered for
263      * this event.
264      *
265      * @param iface Name of iface on which this occurred.
266      */
broadcastSupplicantDisconnectionEvent(String iface)267     public void broadcastSupplicantDisconnectionEvent(String iface) {
268         sendMessage(iface, SUP_DISCONNECTION_EVENT);
269     }
270 
271     /**
272      * Broadcast new p2p device discovered event to all handlers registered for this event.
273      *
274      * @param iface Name of iface on which this occurred.
275      * @param device Device that has been discovered during recent scan.
276      */
broadcastP2pDeviceFound(String iface, WifiP2pDevice device)277     public void broadcastP2pDeviceFound(String iface, WifiP2pDevice device) {
278         if (device != null) {
279             sendMessage(iface, P2P_DEVICE_FOUND_EVENT, device);
280         }
281     }
282 
283     /**
284      * Broadcast p2p device lost event to all handlers registered for this event.
285      *
286      * @param iface Name of iface on which this occurred.
287      * @param device Device that has been lost in recent scan.
288      */
broadcastP2pDeviceLost(String iface, WifiP2pDevice device)289     public void broadcastP2pDeviceLost(String iface, WifiP2pDevice device) {
290         if (device != null) {
291             sendMessage(iface, P2P_DEVICE_LOST_EVENT, device);
292         }
293     }
294 
295     /**
296      * Broadcast scan termination event to all handlers registered for this event.
297      *
298      * @param iface Name of iface on which this occurred.
299      */
broadcastP2pFindStopped(String iface)300     public void broadcastP2pFindStopped(String iface) {
301         sendMessage(iface, P2P_FIND_STOPPED_EVENT);
302     }
303 
304     /**
305      * Broadcast group owner negotiation request event to all handlers registered for this event.
306      *
307      * @param iface Name of iface on which this occurred.
308      * @param config P2p configuration.
309      */
broadcastP2pGoNegotiationRequest(String iface, WifiP2pConfig config)310     public void broadcastP2pGoNegotiationRequest(String iface, WifiP2pConfig config) {
311         if (config != null) {
312             sendMessage(iface, P2P_GO_NEGOTIATION_REQUEST_EVENT, config);
313         }
314     }
315 
316     /**
317      * Broadcast group owner negotiation success event to all handlers registered for this event.
318      *
319      * @param iface Name of iface on which this occurred.
320      */
broadcastP2pGoNegotiationSuccess(String iface)321     public void broadcastP2pGoNegotiationSuccess(String iface) {
322         sendMessage(iface, P2P_GO_NEGOTIATION_SUCCESS_EVENT);
323     }
324 
325     /**
326      * Broadcast group owner negotiation failure event to all handlers registered for this event.
327      *
328      * @param iface Name of iface on which this occurred.
329      * @param reason Failure reason.
330      */
broadcastP2pGoNegotiationFailure(String iface, P2pStatus reason)331     public void broadcastP2pGoNegotiationFailure(String iface, P2pStatus reason) {
332         sendMessage(iface, P2P_GO_NEGOTIATION_FAILURE_EVENT, reason);
333     }
334 
335     /**
336      * Broadcast group formation success event to all handlers registered for this event.
337      *
338      * @param iface Name of iface on which this occurred.
339      */
broadcastP2pGroupFormationSuccess(String iface)340     public void broadcastP2pGroupFormationSuccess(String iface) {
341         sendMessage(iface, P2P_GROUP_FORMATION_SUCCESS_EVENT);
342     }
343 
344     /**
345      * Broadcast group formation failure event to all handlers registered for this event.
346      *
347      * @param iface Name of iface on which this occurred.
348      * @param reason Failure reason.
349      */
broadcastP2pGroupFormationFailure(String iface, String reason)350     public void broadcastP2pGroupFormationFailure(String iface, String reason) {
351         P2pStatus err = P2pStatus.UNKNOWN;
352         if (reason.equals("FREQ_CONFLICT")) {
353             err = P2pStatus.NO_COMMON_CHANNEL;
354         }
355         sendMessage(iface, P2P_GROUP_FORMATION_FAILURE_EVENT, err);
356     }
357 
358     /**
359      * Broadcast group started event to all handlers registered for this event.
360      *
361      * @param iface Name of iface on which this occurred.
362      * @param group Started group.
363      */
broadcastP2pGroupStarted(String iface, WifiP2pGroup group)364     public void broadcastP2pGroupStarted(String iface, WifiP2pGroup group) {
365         if (group != null) {
366             sendMessage(iface, P2P_GROUP_STARTED_EVENT, group);
367         }
368     }
369 
370     /**
371      * Broadcast group removed event to all handlers registered for this event.
372      *
373      * @param iface Name of iface on which this occurred.
374      * @param group Removed group.
375      */
broadcastP2pGroupRemoved(String iface, WifiP2pGroup group)376     public void broadcastP2pGroupRemoved(String iface, WifiP2pGroup group) {
377         if (group != null) {
378             sendMessage(iface, P2P_GROUP_REMOVED_EVENT, group);
379         }
380     }
381 
382     /**
383      * Broadcast invitation received event to all handlers registered for this event.
384      *
385      * @param iface Name of iface on which this occurred.
386      * @param group Group to which invitation has been received.
387      */
broadcastP2pInvitationReceived(String iface, WifiP2pGroup group)388     public void broadcastP2pInvitationReceived(String iface, WifiP2pGroup group) {
389         if (group != null) {
390             sendMessage(iface, P2P_INVITATION_RECEIVED_EVENT, group);
391         }
392     }
393 
394     /**
395      * Broadcast invitation result event to all handlers registered for this event.
396      *
397      * @param iface Name of iface on which this occurred.
398      * @param result Result of invitation.
399      */
broadcastP2pInvitationResult(String iface, P2pStatus result)400     public void broadcastP2pInvitationResult(String iface, P2pStatus result) {
401         sendMessage(iface, P2P_INVITATION_RESULT_EVENT, result);
402     }
403 
404     /**
405      * Broadcast PB discovery request event to all handlers registered for this event.
406      *
407      * @param iface Name of iface on which this occurred.
408      * @param event Provision discovery request event.
409      */
broadcastP2pProvisionDiscoveryPbcRequest(String iface, WifiP2pProvDiscEvent event)410     public void broadcastP2pProvisionDiscoveryPbcRequest(String iface, WifiP2pProvDiscEvent event) {
411         if (event != null) {
412             sendMessage(iface, P2P_PROV_DISC_PBC_REQ_EVENT, event);
413         }
414     }
415 
416     /**
417      * Broadcast PB discovery response event to all handlers registered for this event.
418      *
419      * @param iface Name of iface on which this occurred.
420      * @param event Provision discovery response event.
421      */
broadcastP2pProvisionDiscoveryPbcResponse( String iface, WifiP2pProvDiscEvent event)422     public void broadcastP2pProvisionDiscoveryPbcResponse(
423             String iface, WifiP2pProvDiscEvent event) {
424         if (event != null) {
425             sendMessage(iface, P2P_PROV_DISC_PBC_RSP_EVENT, event);
426         }
427     }
428 
429     /**
430      * Broadcast PIN discovery request event to all handlers registered for this event.
431      *
432      * @param iface Name of iface on which this occurred.
433      * @param event Provision discovery request event.
434      */
broadcastP2pProvisionDiscoveryEnterPin(String iface, WifiP2pProvDiscEvent event)435     public void broadcastP2pProvisionDiscoveryEnterPin(String iface, WifiP2pProvDiscEvent event) {
436         if (event != null) {
437             sendMessage(iface, P2P_PROV_DISC_ENTER_PIN_EVENT, event);
438         }
439     }
440 
441     /**
442      * Broadcast PIN discovery response event to all handlers registered for this event.
443      *
444      * @param iface Name of iface on which this occurred.
445      * @param event Provision discovery response event.
446      */
broadcastP2pProvisionDiscoveryShowPin(String iface, WifiP2pProvDiscEvent event)447     public void broadcastP2pProvisionDiscoveryShowPin(String iface, WifiP2pProvDiscEvent event) {
448         if (event != null) {
449             sendMessage(iface, P2P_PROV_DISC_SHOW_PIN_EVENT, event);
450         }
451     }
452 
453     /**
454      * Broadcast provision discovery request event with requested method opportunistic
455      * bootstrapping to all handlers registered for this event.
456      *
457      * @param iface Name of iface on which this occurred.
458      * @param event Provision discovery request event.
459      */
broadcastP2pProvisionDiscoveryPairingBootstrappingOpportunisticRequest( String iface, WifiP2pProvDiscEvent event)460     public void broadcastP2pProvisionDiscoveryPairingBootstrappingOpportunisticRequest(
461             String iface, WifiP2pProvDiscEvent event) {
462         if (event != null) {
463             sendMessage(iface, P2P_PROV_DISC_PAIRING_BOOTSTRAPPING_OPPORTUNISTIC_REQ_EVENT,
464                     event);
465         }
466     }
467 
468     /**
469      * Broadcast provision discovery response event with requested method opportunistic
470      * bootstrapping to all handlers registered for this event.
471      *
472      * @param iface Name of iface on which this occurred.
473      * @param event Provision discovery response event.
474      */
broadcastP2pProvisionDiscoveryPairingBootstrappingOpportunisticResponse( String iface, WifiP2pProvDiscEvent event)475     public void broadcastP2pProvisionDiscoveryPairingBootstrappingOpportunisticResponse(
476             String iface, WifiP2pProvDiscEvent event) {
477         if (event != null) {
478             sendMessage(iface, P2P_PROV_DISC_PAIRING_BOOTSTRAPPING_OPPORTUNISTIC_RSP_EVENT,
479                     event);
480         }
481     }
482 
483     /**
484      * Broadcast provision discovery event to enter pairing bootstrapping PIN (Keypad pin-code only
485      * method) or Pairing Passphrase (Keypad passphrase method) to all handlers registered for
486      * this event.
487      *
488      * @param iface Name of iface on which this occurred.
489      * @param event Provision discovery request event.
490      */
broadcastP2pProvisionDiscoveryEnterPairingBootstrappingPinOrPassphrase(String iface, WifiP2pProvDiscEvent event)491     public void broadcastP2pProvisionDiscoveryEnterPairingBootstrappingPinOrPassphrase(String iface,
492             WifiP2pProvDiscEvent event) {
493         if (event != null) {
494             sendMessage(iface, P2P_PROV_DISC_ENTER_PAIRING_BOOTSTRAPPING_PIN_OR_PASSPHRASE_EVENT,
495                     event);
496         }
497     }
498 
499     /**
500      * Broadcast provision discovery event to show pairing bootstrapping PIN (Display pin-code only
501      * method) or Passphrase (Display passphrase method) to all handlers registered for this event.
502      *
503      * @param iface Name of iface on which this occurred.
504      * @param event Provision discovery response event.
505      */
broadcastP2pProvisionDiscoveryShowPairingBootstrappingPinOrPassphrase(String iface, WifiP2pProvDiscEvent event)506     public void broadcastP2pProvisionDiscoveryShowPairingBootstrappingPinOrPassphrase(String iface,
507             WifiP2pProvDiscEvent event) {
508         if (event != null) {
509             sendMessage(iface, P2P_PROV_DISC_SHOW_PAIRING_BOOTSTRAPPING_PIN_OR_PASSPHRASE_EVENT,
510                     event);
511         }
512     }
513 
514     /**
515      * Broadcast P2P discovery failure event to all handlers registered for this event.
516      *
517      * @param iface Name of iface on which this occurred.
518      * @param status Indicate the reason of this failure.
519      * @param event The information about the provision discovery.
520      */
broadcastP2pProvisionDiscoveryFailure(@onNull String iface, @P2pProvDiscStatus int status, @NonNull WifiP2pProvDiscEvent event)521     public void broadcastP2pProvisionDiscoveryFailure(@NonNull String iface,
522             @P2pProvDiscStatus int status, @NonNull WifiP2pProvDiscEvent event) {
523         sendMessage(iface, P2P_PROV_DISC_FAILURE_EVENT, status, 0, event);
524     }
525 
526     /**
527      * Broadcast service discovery response event to all handlers registered for this event.
528      *
529      * @param iface Name of iface on which this occurred.
530      * @param services List of discovered services.
531      */
broadcastP2pServiceDiscoveryResponse( String iface, List<WifiP2pServiceResponse> services)532     public void broadcastP2pServiceDiscoveryResponse(
533             String iface, List<WifiP2pServiceResponse> services) {
534         sendMessage(iface, P2P_SERV_DISC_RESP_EVENT, services);
535     }
536 
537     /**
538      * Broadcast AP STA connection event.
539      *
540      * @param iface Name of iface on which this occurred.
541      */
broadcastP2pApStaConnected(String iface, WifiP2pDevice device)542     public void broadcastP2pApStaConnected(String iface, WifiP2pDevice device) {
543         sendMessage(iface, AP_STA_CONNECTED_EVENT, device);
544     }
545 
546     /**
547      * Broadcast AP STA disconnection event.
548      *
549      * @param iface Name of iface on which this occurred.
550      */
broadcastP2pApStaDisconnected(String iface, WifiP2pDevice device)551     public void broadcastP2pApStaDisconnected(String iface, WifiP2pDevice device) {
552         sendMessage(iface, AP_STA_DISCONNECTED_EVENT, device);
553     }
554 
555     /**
556      * Broadcast frequency changed event.
557      *
558      * @param iface Name of iface on which this occurred.
559      * @param frequency New operating frequency.
560      */
broadcastP2pFrequencyChanged(String iface, int frequency)561     public void broadcastP2pFrequencyChanged(String iface,  int frequency) {
562         sendMessage(iface, P2P_FREQUENCY_CHANGED_EVENT, frequency);
563     }
564 
565     /**
566      * Broadcast the termination of USD based service discovery.
567      *
568      * @param iface Name of iface on which this occurred.
569      * @param sessionId Identifier to identify the instance of a service discovery.
570      * @param reasonCode The reason for termination of service discovery.
571      */
broadcastUsdBasedServiceDiscoveryTerminated(@onNull String iface, int sessionId, int reasonCode)572     public void broadcastUsdBasedServiceDiscoveryTerminated(@NonNull String iface,
573             int sessionId, int reasonCode) {
574         sendMessage(iface, USD_BASED_SERVICE_DISCOVERY_TERMINATED_EVENT, sessionId, reasonCode);
575     }
576 
577     /**
578      * Broadcast the termination of USD based service advertisement.
579      *
580      * @param iface Name of iface on which this occurred.
581      * @param sessionId Identifier to identify the instance of a service advertisement.
582      * @param reasonCode The reason for termination of service advertisement.
583      */
broadcastUsdBasedServiceAdvertisementTerminated(@onNull String iface, int sessionId, int reasonCode)584     public void broadcastUsdBasedServiceAdvertisementTerminated(@NonNull String iface,
585             int sessionId, int reasonCode) {
586         sendMessage(iface, USD_BASED_SERVICE_ADVERTISEMENT_TERMINATED_EVENT, sessionId, reasonCode);
587     }
588 }
589