From 9e2c6d828db363fee629205d3df8281aab7c69a6 Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Wed, 8 Jan 2025 00:30:15 +0000 Subject: Do not get looper during initialize Only get the looper when we need it Flag: EXEMPT refactor Bug: 385840659 Test: atest android.net.wifi Change-Id: If16c3a72b3bc4d4d62505706fd8ba4aa9a349eef --- .../android/net/wifi/WifiFrameworkInitializer.java | 34 ++-------------------- framework/java/android/net/wifi/WifiManager.java | 11 +++---- framework/java/android/net/wifi/WifiScanner.java | 6 +--- 3 files changed, 7 insertions(+), 44 deletions(-) (limited to 'framework/java') diff --git a/framework/java/android/net/wifi/WifiFrameworkInitializer.java b/framework/java/android/net/wifi/WifiFrameworkInitializer.java index 4c700c0f11..e942d74f74 100644 --- a/framework/java/android/net/wifi/WifiFrameworkInitializer.java +++ b/framework/java/android/net/wifi/WifiFrameworkInitializer.java @@ -29,10 +29,6 @@ import android.net.wifi.rtt.WifiRttManager; import android.net.wifi.usd.IUsdManager; import android.net.wifi.usd.UsdManager; import android.net.wifi.util.Environment; -import android.os.HandlerThread; -import android.os.Looper; - -import androidx.annotation.VisibleForTesting; /** * Class for performing registration for all Wifi services. @@ -41,32 +37,6 @@ import androidx.annotation.VisibleForTesting; */ @SystemApi public class WifiFrameworkInitializer { - - /** - * A class implementing the lazy holder idiom: the unique static instance - * of {@link #INSTANCE} is instantiated in a thread-safe way (guaranteed by - * the language specs) the first time that NoPreloadHolder is referenced in getInstanceLooper(). - * - * This is necessary because we can't spawn a new thread in {@link #registerServiceWrappers()}. - * {@link #registerServiceWrappers()} is called during the Zygote phase, which disallows - * spawning new threads. Naming the class "NoPreloadHolder" ensures that the classloader will - * not preload this class, inadvertently spawning the thread too early. - */ - private static class NoPreloadHolder { - private static final HandlerThread INSTANCE = createInstance(); - - private static HandlerThread createInstance() { - HandlerThread thread = new HandlerThread("WifiManagerThread"); - thread.start(); - return thread; - } - } - /** @hide */ - @VisibleForTesting - public static Looper getInstanceLooper() { - return NoPreloadHolder.INSTANCE.getLooper(); - } - private WifiFrameworkInitializer() {} /** @@ -86,7 +56,7 @@ public class WifiFrameworkInitializer { return null; } IWifiManager service = IWifiManager.Stub.asInterface(serviceBinder); - return new WifiManager(context, service, getInstanceLooper()); + return new WifiManager(context, service); } ); SystemServiceRegistry.registerContextAwareService( @@ -122,7 +92,7 @@ public class WifiFrameworkInitializer { return null; } IWifiScanner service = IWifiScanner.Stub.asInterface(serviceBinder); - return new WifiScanner(context, service, getInstanceLooper()); + return new WifiScanner(context, service); } ); SystemServiceRegistry.registerContextAwareService( diff --git a/framework/java/android/net/wifi/WifiManager.java b/framework/java/android/net/wifi/WifiManager.java index 121ee0374a..52836c2940 100644 --- a/framework/java/android/net/wifi/WifiManager.java +++ b/framework/java/android/net/wifi/WifiManager.java @@ -2217,15 +2217,12 @@ public class WifiManager { * * @param context the application context * @param service the Binder interface - * @param looper the Looper used to deliver callbacks * @hide - hide this because it takes in a parameter of type IWifiManager, which * is a system private class. */ - public WifiManager(@NonNull Context context, @NonNull IWifiManager service, - @NonNull Looper looper) { + public WifiManager(@NonNull Context context, @NonNull IWifiManager service) { mContext = context; mService = service; - mLooper = looper; mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion; updateVerboseLoggingEnabledFromService(); } @@ -7560,7 +7557,7 @@ public class WifiManager { @Nullable ActionListener listener) { ActionListenerProxy listenerProxy = null; if (listener != null) { - listenerProxy = new ActionListenerProxy("connect", mLooper, listener); + listenerProxy = new ActionListenerProxy("connect", mContext.getMainLooper(), listener); } try { Bundle extras = new Bundle(); @@ -7709,7 +7706,7 @@ public class WifiManager { if (config == null) throw new IllegalArgumentException("config cannot be null"); ActionListenerProxy listenerProxy = null; if (listener != null) { - listenerProxy = new ActionListenerProxy("save", mLooper, listener); + listenerProxy = new ActionListenerProxy("save", mContext.getMainLooper(), listener); } try { mService.save(config, listenerProxy, mContext.getOpPackageName()); @@ -7747,7 +7744,7 @@ public class WifiManager { if (netId < 0) throw new IllegalArgumentException("Network id cannot be negative"); ActionListenerProxy listenerProxy = null; if (listener != null) { - listenerProxy = new ActionListenerProxy("forget", mLooper, listener); + listenerProxy = new ActionListenerProxy("forget", mContext.getMainLooper(), listener); } try { mService.forget(netId, listenerProxy); diff --git a/framework/java/android/net/wifi/WifiScanner.java b/framework/java/android/net/wifi/WifiScanner.java index 1dffa8a3c7..fd9676e0e4 100644 --- a/framework/java/android/net/wifi/WifiScanner.java +++ b/framework/java/android/net/wifi/WifiScanner.java @@ -34,7 +34,6 @@ import android.content.Context; import android.os.Binder; import android.os.Build; import android.os.Bundle; -import android.os.Looper; import android.os.Parcel; import android.os.Parcelable; import android.os.Process; @@ -2022,12 +2021,9 @@ public class WifiScanner { * * @param context the application context * @param service the Binder interface for {@link Context#WIFI_SCANNING_SERVICE} - * @param looper the Looper used to deliver callbacks - * * @hide */ - public WifiScanner(@NonNull Context context, @NonNull IWifiScanner service, - @NonNull Looper looper) { + public WifiScanner(@NonNull Context context, @NonNull IWifiScanner service) { mContext = context; mService = service; } -- cgit v1.2.3-59-g8ed1b