summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorSticky Chen <sticky.chen@mediatek.com>2019-06-11 13:01:33 +0800
committerRoshan Pius <rpius@google.com>2019-06-11 19:43:55 +0000
commit1d734366a2d46e8de37ece9333ddce2008fa348d (patch)
tree80e1f88cff0102c2d0c8133ff5ce4c7a8df5b20c /service
parent724f5ef108fb3f3aec0ede58b77610000f6bc0c1 (diff)
Handle native event in wifi thread
To prevent deadlocks while processing native callback or death as we're in the midst of performing some state changes, post the native notification to the wifi thread. Bug: 134987917 Test: Performed some basic tests (toggle wifi,softap, etc) Test: atest com.android.server.wifi.HalDeviceManagerTest Change-Id: Id24aa61ae51d254cfc937691475b19977e5c508d (cherry-picked from ed9610cd4f703b8864fb2eb167bbbdce37561724)
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/HalDeviceManager.java48
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java2
2 files changed, 35 insertions, 15 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 =