Add API level check for the use of ConnectivityManager.getActiveNetwork.
This method is added in API level 23, and is currently used in NetworkMonitorAutoDetect to determine the underlying type of a VPN network. Bug: webrtc:9811 Change-Id: I7277cd9adb5b3d3d9b116f667bf533352f9b3bdf Reviewed-on: https://webrtc-review.googlesource.com/c/103560 Reviewed-by: Alex Glaznev <glaznev@webrtc.org> Commit-Queue: Qingsi Wang <qingsi@google.com> Cr-Commit-Position: refs/heads/master@{#24961}
This commit is contained in:
@ -289,17 +289,21 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
||||
//
|
||||
// Note that getActiveNetwork and getActiveNetworkInfo return null if no default network is
|
||||
// currently active.
|
||||
if (networkInfo.getType() == ConnectivityManager.TYPE_VPN
|
||||
&& network.equals(connectivityManager.getActiveNetwork())) {
|
||||
// If a VPN network is in place, we can find the underlying network type via querying the
|
||||
// active network info thanks to
|
||||
// https://android.googlesource.com/platform/frameworks/base/+/d6a7980d
|
||||
NetworkInfo underlyingActiveNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
||||
// We use the NetworkInfo of the underlying network if it is not of TYPE_VPN itself.
|
||||
if (underlyingActiveNetworkInfo.getType() != ConnectivityManager.TYPE_VPN) {
|
||||
return new NetworkState(networkInfo.isConnected(), ConnectivityManager.TYPE_VPN, -1,
|
||||
underlyingActiveNetworkInfo.getType(), underlyingActiveNetworkInfo.getSubtype());
|
||||
if (networkInfo.getType() == ConnectivityManager.TYPE_VPN) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& network.equals(connectivityManager.getActiveNetwork())) {
|
||||
// If a VPN network is in place, we can find the underlying network type via querying the
|
||||
// active network info thanks to
|
||||
// https://android.googlesource.com/platform/frameworks/base/+/d6a7980d
|
||||
NetworkInfo underlyingActiveNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
||||
// We use the NetworkInfo of the underlying network if it is not of TYPE_VPN itself.
|
||||
if (underlyingActiveNetworkInfo.getType() != ConnectivityManager.TYPE_VPN) {
|
||||
return new NetworkState(networkInfo.isConnected(), ConnectivityManager.TYPE_VPN, -1,
|
||||
underlyingActiveNetworkInfo.getType(), underlyingActiveNetworkInfo.getSubtype());
|
||||
}
|
||||
}
|
||||
return new NetworkState(
|
||||
networkInfo.isConnected(), ConnectivityManager.TYPE_VPN, -1, -1, -1);
|
||||
}
|
||||
|
||||
return getNetworkState(networkInfo);
|
||||
|
||||
Reference in New Issue
Block a user