From 53d2a2c41441d283edf7378dff06687ca0c0fa30 Mon Sep 17 00:00:00 2001 From: James Mattis Date: Fri, 1 Apr 2022 13:12:59 -0700 Subject: [PATCH] Clear test ethernet data when no longer enabled When test interface are no longer tracked in ethernet, clear out associated data. Besides polluting the dumpsys and taking up memory, unexpected results could happen if other CTS tests or the like were to use a test interface which happened to have an existing configuration for it (i.e., the tests could fail). This is more problematic since IP configuration data is written to disc, therefore test data was being persisted across reboots. Bug: 210485380 Bug: 210487893 Test: atest EthernetServiceTests atest CtsNetTestCases Change-Id: If85c625ebbf8da27b226d9ae3651c4fb83a9a8da --- .../server/ethernet/EthernetTracker.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/service-t/src/com/android/server/ethernet/EthernetTracker.java b/service-t/src/com/android/server/ethernet/EthernetTracker.java index c291b3ff66..693d91ab5c 100644 --- a/service-t/src/com/android/server/ethernet/EthernetTracker.java +++ b/service-t/src/com/android/server/ethernet/EthernetTracker.java @@ -29,8 +29,8 @@ import android.content.res.Resources; import android.net.ConnectivityResources; import android.net.EthernetManager; import android.net.IEthernetServiceListener; -import android.net.INetworkInterfaceOutcomeReceiver; import android.net.INetd; +import android.net.INetworkInterfaceOutcomeReceiver; import android.net.ITetheredInterfaceCallback; import android.net.InterfaceConfigurationParcel; import android.net.IpConfiguration; @@ -57,6 +57,7 @@ import com.android.net.module.util.PermissionUtils; import java.io.FileDescriptor; import java.net.InetAddress; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; @@ -389,10 +390,33 @@ public class EthernetTracker { mHandler.post(() -> { mIncludeTestInterfaces = include; updateIfaceMatchRegexp(); + if (!include) { + removeTestData(); + } mHandler.post(() -> trackAvailableInterfaces()); }); } + private void removeTestData() { + removeTestIpData(); + removeTestCapabilityData(); + } + + private void removeTestIpData() { + final Iterator iterator = mIpConfigurations.keySet().iterator(); + while (iterator.hasNext()) { + final String iface = iterator.next(); + if (iface.matches(TEST_IFACE_REGEXP)) { + mConfigStore.write(iface, null); + iterator.remove(); + } + } + } + + private void removeTestCapabilityData() { + mNetworkCapabilities.keySet().removeIf(iface -> iface.matches(TEST_IFACE_REGEXP)); + } + public void requestTetheredInterface(ITetheredInterfaceCallback callback) { mHandler.post(() -> { if (!mTetheredInterfaceRequests.register(callback)) {