From 0b31edb987c0552b75667e05f0d589937a16f1ad Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Sun, 23 Apr 2017 22:46:41 -0700 Subject: [AWARE] Fix race condition of Aware state machine & HAL The Wi-Fi Aware HAL was started before the Aware state machine was ready. In case where the HAL was able to obtain a handle on the NAN interface it would attempt to enable Aware through the state machine - resulting in an NPE. Added an explicit start method to the Aware HAL which is called in order. Bug: 37613363 Test: unit tests and integration (sl4a) test Change-Id: I66698bd926ca5d4bdb19b3025ed2f26c61028d21 --- .../java/com/android/server/wifi/aware/WifiAwareNativeManager.java | 3 +++ service/java/com/android/server/wifi/aware/WifiAwareService.java | 1 + service/java/com/android/server/wifi/aware/WifiAwareStateManager.java | 4 ---- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/aware/WifiAwareNativeManager.java b/service/java/com/android/server/wifi/aware/WifiAwareNativeManager.java index 22f13851f..f1945808f 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareNativeManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareNativeManager.java @@ -53,6 +53,9 @@ class WifiAwareNativeManager { mWifiAwareStateManager = awareStateManager; mHalDeviceManager = halDeviceManager; mWifiAwareNativeCallback = wifiAwareNativeCallback; + } + + public void start() { mHalDeviceManager.registerStatusListener( new HalDeviceManager.ManagerStatusListener() { @Override diff --git a/service/java/com/android/server/wifi/aware/WifiAwareService.java b/service/java/com/android/server/wifi/aware/WifiAwareService.java index 75efa0296..bd8156e17 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareService.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareService.java @@ -65,6 +65,7 @@ public final class WifiAwareService extends SystemService { HandlerThread awareHandlerThread = wifiInjector.getWifiAwareHandlerThread(); mImpl.start(awareHandlerThread, wifiAwareStateManager); + wifiAwareNativeManager.start(); } else if (phase == SystemService.PHASE_BOOT_COMPLETED) { mImpl.startLate(); } diff --git a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java index 1d00d162d..a35c786ee 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java @@ -391,10 +391,6 @@ public class WifiAwareStateManager { * only happens when a connection is created. */ public void enableUsage() { - if (mSm == null) { - Log.e(TAG, "enableUsage: race condition - called while mSm null!"); - return; - } Message msg = mSm.obtainMessage(MESSAGE_TYPE_COMMAND); msg.arg1 = COMMAND_TYPE_ENABLE_USAGE; mSm.sendMessage(msg); -- cgit v1.2.3