diff options
3 files changed, 36 insertions, 16 deletions
diff --git a/service/java/com/android/server/wifi/HalDeviceManager.java b/service/java/com/android/server/wifi/HalDeviceManager.java index bb53a6e88..d2ad47f48 100644 --- a/service/java/com/android/server/wifi/HalDeviceManager.java +++ b/service/java/com/android/server/wifi/HalDeviceManager.java @@ -37,6 +37,7 @@ import android.hidl.manager.V1_2.IServiceManager; import android.os.Handler; import android.os.HidlSupport.Mutable; import android.os.HwRemoteBinder; +import android.os.Looper; import android.os.RemoteException; import android.util.Log; import android.util.LongSparseArray; @@ -73,13 +74,19 @@ public class HalDeviceManager { public static final int START_HAL_RETRY_TIMES = 3; private final Clock mClock; + private final Handler mEventHandler; + private WifiDeathRecipient mIWifiDeathRecipient; + private ServiceManagerDeathRecipient mServiceManagerDeathRecipient; // cache the value for supporting vendor HAL or not private boolean mIsVendorHalSupported = false; // public API - public HalDeviceManager(Clock clock) { + public HalDeviceManager(Clock clock, Looper looper) { mClock = clock; + mEventHandler = new Handler(looper); + mIWifiDeathRecipient = new WifiDeathRecipient(); + mServiceManagerDeathRecipient = new ServiceManagerDeathRecipient(); mInterfaceAvailableForRequestListeners.put(IfaceType.STA, new HashMap<>()); mInterfaceAvailableForRequestListeners.put(IfaceType.AP, new HashMap<>()); @@ -631,15 +638,19 @@ public class HalDeviceManager { mRttControllerLifecycleCallbacks.clear(); } - private final HwRemoteBinder.DeathRecipient mServiceManagerDeathRecipient = - cookie -> { + private class ServiceManagerDeathRecipient implements HwRemoteBinder.DeathRecipient { + @Override + public void serviceDied(long cookie) { + mEventHandler.post(() -> { Log.wtf(TAG, "IServiceManager died: cookie=" + cookie); synchronized (mLock) { mServiceManager = null; // theoretically can call initServiceManager again here - but // there's no point since most likely system is going to reboot } - }; + }); + } + } private final IServiceNotification mServiceNotificationCallback = new IServiceNotification.Stub() { @@ -718,8 +729,10 @@ public class HalDeviceManager { } } - private final HwRemoteBinder.DeathRecipient mIWifiDeathRecipient = - cookie -> { + private class WifiDeathRecipient implements HwRemoteBinder.DeathRecipient { + @Override + public void serviceDied(long cookie) { + mEventHandler.post(() -> { Log.e(TAG, "IWifi HAL service died! Have a listener for it ... cookie=" + cookie); synchronized (mLock) { // prevents race condition with surrounding method mWifi = null; @@ -727,7 +740,9 @@ public class HalDeviceManager { teardownInternal(); // don't restart: wait for registration notification } - }; + }); + } + } /** * Initialize IWifi and register death listener and event callback. @@ -1264,21 +1279,26 @@ public class HalDeviceManager { private class WifiEventCallback extends IWifiEventCallback.Stub { @Override public void onStart() throws RemoteException { - if (VDBG) Log.d(TAG, "IWifiEventCallback.onStart"); - // NOP: only happens in reaction to my calls - will handle directly + mEventHandler.post(() -> { + if (VDBG) Log.d(TAG, "IWifiEventCallback.onStart"); + // NOP: only happens in reaction to my calls - will handle directly + }); } @Override public void onStop() throws RemoteException { - if (VDBG) Log.d(TAG, "IWifiEventCallback.onStop"); - // NOP: only happens in reaction to my calls - will handle directly + mEventHandler.post(() -> { + if (VDBG) Log.d(TAG, "IWifiEventCallback.onStop"); + // NOP: only happens in reaction to my calls - will handle directly + }); } @Override public void onFailure(WifiStatus status) throws RemoteException { - Log.e(TAG, "IWifiEventCallback.onFailure: " + statusString(status)); - teardownInternal(); - + mEventHandler.post(() -> { + Log.e(TAG, "IWifiEventCallback.onFailure: " + statusString(status)); + teardownInternal(); + }); // No need to do anything else: listeners may (will) re-start Wi-Fi } } diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 178c98f6d..f33c7cf93 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -202,7 +202,7 @@ public class WifiInjector { mCellularLinkLayerStatsCollector); // Modules interacting with Native. mWifiMonitor = new WifiMonitor(this); - mHalDeviceManager = new HalDeviceManager(mClock); + mHalDeviceManager = new HalDeviceManager(mClock, clientModeImplLooper); mWifiVendorHal = new WifiVendorHal(mHalDeviceManager, mWifiCoreHandlerThread.getLooper()); mSupplicantStaIfaceHal = diff --git a/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java b/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java index bb71e4a26..36da41bd3 100644 --- a/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java @@ -107,7 +107,7 @@ public class HalDeviceManagerTest { private class HalDeviceManagerSpy extends HalDeviceManager { HalDeviceManagerSpy() { - super(mClock); + super(mClock, mTestLooper.getLooper()); } @Override |