Handle no-longer-sticky-in-Q+ WIFI_P2P_CONNECTION_CHANGED_ACTION intent.

This CL ensures that webrtc can work with an already-connected Wi-Fi
Direct network on Android Q.

Bug: None
Change-Id: Icf98c2f029fe0a92f95266310e6304268c2d9c70
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/157504
Reviewed-by: Alex Glaznev <glaznev@webrtc.org>
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29579}
This commit is contained in:
Qingsi Wang
2019-10-18 17:29:29 -07:00
committed by Commit Bot
parent c04792ebef
commit 8e13e6ed3d

View File

@ -540,6 +540,16 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
context.registerReceiver(this, intentFilter);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
// Starting with Android Q (10), WIFI_P2P_CONNECTION_CHANGED_ACTION is no longer sticky.
// This means we have to explicitly request WifiP2pGroup info during initialization in order
// to get this data if we are already connected to a Wi-Fi Direct network.
WifiP2pManager manager =
(WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
WifiP2pManager.Channel channel =
manager.initialize(context, context.getMainLooper(), null /* listener */);
manager.requestGroupInfo(channel, wifiP2pGroup -> { onWifiP2pGroupChange(wifiP2pGroup); });
}
}
// BroadcastReceiver