From bee5b3f227db3d68912764c0f86d9948e4dac547 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Fri, 8 May 2020 01:33:13 +0000 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 Original-Change: https://android-review.googlesource.com/1305393 Merged-In: Id7d8bba486bada1a7ba5b0f152d2aa02e407f249 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 119715456f..f7ace06431 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -7134,6 +7134,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 d2b26d3bfd..4397bd4640 100644 --- a/tests/net/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java @@ -5387,8 +5387,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());