From e949039081b08626590be9783c85f358955e1b82 Mon Sep 17 00:00:00 2001 From: Christopher Wiley Date: Thu, 26 May 2016 15:57:29 -0700 Subject: [PATCH] Use an ArrayMap instead of HashMap to track tether interfaces ( cherry-pick of 36f6f4e394750e4989d78f38a31ab8f2f66c07f7 ) Since the number of tetherable interfaces should be small (e.g. <10), the computational cost of a looking up objects in an ArrayMap is negligible, and the memory required is less than a HashMap. While here, remove some unused imports. Change-Id: I3fb7091cfb93697d2fc6388b843d60f7e8e7e1a6 Test: Compiles. --- .../java/com/android/server/connectivity/Tethering.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java index 05823b5f4295a..40d17edc5a662 100644 --- a/services/core/java/com/android/server/connectivity/Tethering.java +++ b/services/core/java/com/android/server/connectivity/Tethering.java @@ -34,8 +34,6 @@ import android.hardware.usb.UsbManager; import android.net.ConnectivityManager; import android.net.ConnectivityManager.NetworkCallback; import android.net.INetworkStatsService; -import android.net.InterfaceConfiguration; -import android.net.LinkAddress; import android.net.LinkProperties; import android.net.Network; import android.net.NetworkCapabilities; @@ -58,12 +56,12 @@ import android.provider.Settings; import android.telephony.CarrierConfigManager; import android.telephony.TelephonyManager; import android.text.TextUtils; +import android.util.ArrayMap; import android.util.Log; import android.util.SparseArray; import com.android.internal.telephony.IccCardConstants; import com.android.internal.telephony.TelephonyIntents; -import com.android.internal.util.IState; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.MessageUtils; import com.android.internal.util.Protocol; @@ -83,6 +81,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -127,7 +126,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private final INetworkStatsService mStatsService; private final Looper mLooper; - private HashMap mIfaces; // all tethered/tetherable ifaces + private Map mIfaces; // all tethered/tetherable ifaces private BroadcastReceiver mStateReceiver; @@ -172,7 +171,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering mPublicSync = new Object(); - mIfaces = new HashMap(); + mIfaces = new ArrayMap(); // make our own thread so we don't anr the system mLooper = IoThread.get().getLooper();