From d5687912833fe6fe90986dd0a3c5e6f40094d0d3 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Thu, 7 May 2020 12:07:03 +0900 Subject: [PATCH] Fix a bug where a spurious capabilities callback is sent. When a VPN connects and it has any underlying network (which means almost always, because it will take the default network if it doesn't declare any), it has default capabilities and will only take the capabilities of its underlying network as part of an update happening after making the network available but before the rematch can take place. This in turn causes the capabilities callback sent as part of the rematch to be spuriously sent. Test: FrameworksNetTests. Also tested together with a followup that adds tests with drive-by coverage for this. Bug: 150570873 Change-Id: Id7d8bba486bada1a7ba5b0f152d2aa02e407f249 --- .../core/java/com/android/server/ConnectivityService.java | 8 ++++++++ .../java/com/android/server/ConnectivityServiceTest.java | 2 -- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 4c55c67b81..7c6dfff14e 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -7095,6 +7095,14 @@ public class ConnectivityService extends IConnectivityManager.Stub networkAgent.networkCapabilities.addCapability(NET_CAPABILITY_FOREGROUND); if (!createNativeNetwork(networkAgent)) return; + if (networkAgent.isVPN()) { + // Initialize the VPN capabilities to their starting values according to the + // underlying networks. This will avoid a spurious callback to + // onCapabilitiesUpdated being sent in updateAllVpnCapabilities below as + // the VPN would switch from its default, blank capabilities to those + // that reflect the capabilities of its underlying networks. + updateAllVpnsCapabilities(); + } networkAgent.created = true; } diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java index aa5c941567..75152e6554 100644 --- a/tests/net/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java @@ -5393,8 +5393,6 @@ public class ConnectivityServiceTest { // Even though the VPN is unvalidated, it becomes the default network for our app. callback.expectAvailableCallbacksUnvalidated(vpnNetworkAgent); - // TODO: this looks like a spurious callback. - callback.expectCallback(CallbackEntry.NETWORK_CAPS_UPDATED, vpnNetworkAgent); callback.assertNoCallback(); assertTrue(vpnNetworkAgent.getScore() > mEthernetNetworkAgent.getScore());