From 1f4db552bd5ee0cb2fe91918b9e6dd9b34eb8d7f Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 12 Feb 2021 10:14:01 +0900 Subject: [PATCH] Minor fixes to LockdownVpnTracker. 1. Remove the legacy network type. This is only used for logging. - Replace the logcat logging with the display transport - Remove the EventLogTags logging, since it's likely not actually used by anyone. 2. Remove code that checks for NetworkInfo objects in state FAILED, since LockdownVpnTracker can never have received any such NetworkInfo from ConnectivityService since lollipop. Bug: 173331190 Test: passes existing tests in ConnectivityServiceTest Change-Id: I66ed71e51ba18b95862f3a0a5df2775eecea501e --- .../com/android/server/ConnectivityService.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index d744d34085..94bc44bdf2 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -746,7 +746,7 @@ public class ConnectivityService extends IConnectivityManager.Stub + Arrays.toString(vpnNai.declaredUnderlyingNetworks)); return; } - final NetworkAgentInfo underlyingNai = mService.getNetworkAgentInfoForNetwork( + final NetworkAgentInfo underlyingNai = mService.getNetworkAgentInfoForNetwork( vpnNai.declaredUnderlyingNetworks[0]); if (underlyingNai == null) return; @@ -4824,12 +4824,15 @@ public class ConnectivityService extends IConnectivityManager.Stub if (!mLockdownEnabled) { return null; } - // The legacy lockdown VPN always only applies to UID 0. + // The legacy lockdown VPN always only applies to userId 0. final NetworkAgentInfo nai = getVpnForUid(Process.FIRST_APPLICATION_UID); if (nai == null || !isLegacyLockdownNai(nai)) return null; // The legacy lockdown VPN must always have exactly one underlying network. - if (nai.declaredUnderlyingNetworks == null || nai.declaredUnderlyingNetworks.length != 1) { + // This code may run on any thread and declaredUnderlyingNetworks may change, so store it in + // a local variable. There is no need to make a copy because its contents cannot change. + final Network[] underlying = nai.declaredUnderlyingNetworks; + if (underlying == null || underlying.length != 1) { return null; } @@ -4839,8 +4842,7 @@ public class ConnectivityService extends IConnectivityManager.Stub // Report that the VPN is not connected, so when the state of NetworkInfo objects // overwritten by getLegacyLockdownState will be set to CONNECTING and not CONNECTED. final NetworkAgentInfo defaultNetwork = getDefaultNetwork(); - if (defaultNetwork == null - || !defaultNetwork.network.equals(nai.declaredUnderlyingNetworks[0])) { + if (defaultNetwork == null || !defaultNetwork.network.equals(underlying[0])) { return null; } @@ -4899,6 +4901,9 @@ public class ConnectivityService extends IConnectivityManager.Stub private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { + // TODO: make BroadcastInterceptingContext use the Handler passed in to registerReceiver + // and put this back. + // ensureRunningOnConnectivityServiceThread(); final String action = intent.getAction(); final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);