11package net .sharksystem .asap .android .wifidirect ;
22
3+ import android .Manifest ;
4+ import android .annotation .SuppressLint ;
35import android .content .BroadcastReceiver ;
46import android .content .Context ;
57import android .content .Intent ;
8+ import android .content .pm .PackageManager ;
69import android .net .NetworkInfo ;
710import android .net .wifi .p2p .WifiP2pDevice ;
811import android .net .wifi .p2p .WifiP2pManager ;
912import android .util .Log ;
1013
14+ import androidx .core .app .ActivityCompat ;
15+
1116class WifiDirectBroadcastReceiver extends BroadcastReceiver {
1217 // https://developer.android.com/guide/topics/connectivity/wifip2p#java
1318
@@ -16,25 +21,26 @@ class WifiDirectBroadcastReceiver extends BroadcastReceiver {
1621 private final Context context ;
1722 private final WifiP2pManager .PeerListListener peerListListener ;
1823 private final WifiP2pManager .ConnectionInfoListener connectionInfoListener ;
19- private final WifiP2PEngine aaspWifiP2PEngine ;
24+ private final WifiP2PEngine asapWifiP2PEngine ;
2025
2126 public WifiDirectBroadcastReceiver (
22- WifiP2PEngine aaspWifiP2PEngine ,
27+ WifiP2PEngine asapWifiP2PEngine ,
2328 WifiP2pManager manager ,
2429 WifiP2pManager .Channel channel ,
2530 Context context ,
2631 WifiP2pManager .PeerListListener peerListListener ,
2732 WifiP2pManager .ConnectionInfoListener connectionInfoListener
2833 ) {
2934 super ();
30- this .aaspWifiP2PEngine = aaspWifiP2PEngine ;
35+ this .asapWifiP2PEngine = asapWifiP2PEngine ;
3136 this .mManager = manager ;
3237 this .mChannel = channel ;
3338 this .context = context ;
3439 this .peerListListener = peerListListener ;
3540 this .connectionInfoListener = connectionInfoListener ;
3641 }
3742
43+ @ SuppressLint ("MissingPermission" )
3844 @ Override
3945 public void onReceive (Context context , Intent intent ) {
4046 // https://developer.android.com/guide/topics/connectivity/wifip2p#java
@@ -49,19 +55,22 @@ public void onReceive(Context context, Intent intent) {
4955 Log .d ("Wifi_BR" , "BL: wifi p2p enabled" );
5056
5157 // discoverPeers peers
52- this .aaspWifiP2PEngine .discoverPeers ();
58+ this .asapWifiP2PEngine .discoverPeers ();
5359 } else {
5460 // Wi-Fi P2P is not enabled
55- Log .d ("Wifi_BR" ,"BL: wifi p2p not enabled" );
61+ Log .d ("Wifi_BR" , "BL: wifi p2p not enabled" );
5662 }
5763
5864 } else if (WifiP2pManager .WIFI_P2P_PEERS_CHANGED_ACTION .equals (action )) {
5965 // Call WifiP2pManager.requestPeers() to get a list of current peers
6066 // that event is a result of a previous discoverPeers peers
6167
6268 Log .d ("Wifi_BR" , "p2p peers changed" );
63- // call for a list of peers
6469 if (mManager != null ) {
70+ if (!this .asapWifiP2PEngine .permissionCheck (Manifest .permission .ACCESS_FINE_LOCATION )) {
71+ return ;
72+ }
73+ // ask for a list of new peers - send to PeerListListener
6574 mManager .requestPeers (mChannel , this .peerListListener );
6675 }
6776
@@ -94,4 +103,8 @@ public void onReceive(Context context, Intent intent) {
94103 // TODO do something useful with that information
95104 }
96105 }
106+
107+ private String getLogStart () {
108+ return this .getClass ().getSimpleName ();
109+ }
97110}
0 commit comments