From c74389c5fc9689d1db53e690a5b03b29bf38f416 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Fri, 6 Nov 2020 15:52:15 +0900 Subject: [PATCH] Remove useless code The semantics of this block are such that restart will only be false if all components of mArguments are null. mArguments is a final array initialized in the constructor of LegacyVpnRunner. The components of the array are never overwritten (though the components of those components are), and at least one of these components will always be non-null (unless somebody calls startLegacyVpnPrivileged with a non-existing type, but that never happens). For safety, this patch also adds a check so that the code will crash early with a clear message if this ever happens. Test: FrameworksNetTests NetworkStackTests Change-Id: I1f13aa08c6f1870c9610185b603af76f97c22bab --- .../java/com/android/server/connectivity/Vpn.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java index 9e43b54817390..8b56a2b64db29 100644 --- a/services/core/java/com/android/server/connectivity/Vpn.java +++ b/services/core/java/com/android/server/connectivity/Vpn.java @@ -25,6 +25,7 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED; import static android.net.RouteInfo.RTN_THROW; import static android.net.RouteInfo.RTN_UNREACHABLE; +import static com.android.internal.util.Preconditions.checkArgument; import static com.android.internal.util.Preconditions.checkNotNull; import android.Manifest; @@ -2759,6 +2760,8 @@ public class Vpn { LegacyVpnRunner(VpnConfig config, String[] racoon, String[] mtpd, VpnProfile profile) { super(TAG); + checkArgument(racoon != null || mtpd != null, "Arguments to racoon and mtpd " + + "must not both be null"); mConfig = config; mDaemons = new String[] {"racoon", "mtpd"}; // TODO: clear arguments from memory once launched @@ -2915,15 +2918,6 @@ public class Vpn { } new File("/data/misc/vpn/abort").delete(); - // Check if we need to restart any of the daemons. - boolean restart = false; - for (String[] arguments : mArguments) { - restart = restart || (arguments != null); - } - if (!restart) { - agentDisconnect(); - return; - } updateState(DetailedState.CONNECTING, "execute"); // Start the daemon with arguments.