Merge "Use registerSystemDefaultNetworkCallback to listen underlying network" am: 817021b9b7 am: a196c820e8 am: 433eeb633b

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2183584

Change-Id: I476141b4dcbea2e0148b28475d1162db04a510c4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Lucas Lin
2022-09-15 10:29:48 +00:00
committed by Automerger Merge Worker

View File

@@ -99,6 +99,7 @@ import android.os.Build.VERSION_CODES;
import android.os.Bundle; import android.os.Bundle;
import android.os.CancellationSignal; import android.os.CancellationSignal;
import android.os.FileUtils; import android.os.FileUtils;
import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.INetworkManagementService; import android.os.INetworkManagementService;
import android.os.Looper; import android.os.Looper;
@@ -2784,26 +2785,18 @@ public class Vpn {
// When restricted to test networks, select any network with TRANSPORT_TEST. Since the // When restricted to test networks, select any network with TRANSPORT_TEST. Since the
// creator of the profile and the test network creator both have MANAGE_TEST_NETWORKS, // creator of the profile and the test network creator both have MANAGE_TEST_NETWORKS,
// this is considered safe. // this is considered safe.
final NetworkRequest req;
if (mProfile.isRestrictedToTestNetworks()) { if (mProfile.isRestrictedToTestNetworks()) {
req = new NetworkRequest.Builder() final NetworkRequest req = new NetworkRequest.Builder()
.clearCapabilities() .clearCapabilities()
.addTransportType(NetworkCapabilities.TRANSPORT_TEST) .addTransportType(NetworkCapabilities.TRANSPORT_TEST)
.addCapability(NET_CAPABILITY_NOT_VPN) .addCapability(NET_CAPABILITY_NOT_VPN)
.build(); .build();
mConnectivityManager.requestNetwork(req, mNetworkCallback);
} else { } else {
// Basically, the request here is referring to the default request which is defined mConnectivityManager.registerSystemDefaultNetworkCallback(mNetworkCallback,
// in ConnectivityService. Ideally, ConnectivityManager should provide an new API new Handler(mLooper));
// which can provide the status of physical network even though there is a virtual
// network. b/147280869 is used for tracking the new API.
// TODO: Use the new API to register default physical network.
req = new NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build();
} }
mConnectivityManager.requestNetwork(req, mNetworkCallback);
} }
private boolean isActiveNetwork(@Nullable Network network) { private boolean isActiveNetwork(@Nullable Network network) {