From 1711409f11610d2d646036306ec8de4fb2f69712 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Fri, 21 Apr 2017 18:48:31 -0700 Subject: Clean up after RTT operations finished. (2/2) Uses a single callback for RTT event. Bug: 36185358 Test: Manual with RTT app. Change-Id: I2840aafd39ae23427a069d689ff36f84eea00d33 --- .../com/android/server/wifi/WifiVendorHal.java | 39 +++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiVendorHal.java b/service/java/com/android/server/wifi/WifiVendorHal.java index 59c0e9200..31c000c59 100644 --- a/service/java/com/android/server/wifi/WifiVendorHal.java +++ b/service/java/com/android/server/wifi/WifiVendorHal.java @@ -207,6 +207,8 @@ public class WifiVendorHal { private final Looper mLooper; private final IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback; private final IWifiChipEventCallback mIWifiChipEventCallback; + private final RttEventCallback mRttEventCallback; + public WifiVendorHal(HalDeviceManager halDeviceManager, Looper looper) { @@ -215,6 +217,7 @@ public class WifiVendorHal { mHalDeviceManagerStatusCallbacks = new HalDeviceManagerStatusListener(); mIWifiStaIfaceEventCallback = new StaIfaceEventCallback(); mIWifiChipEventCallback = new ChipEventCallback(); + mRttEventCallback = new RttEventCallback(); } // TODO(mplass): figure out where we need locking in hidl world. b/33383725 @@ -290,6 +293,9 @@ public class WifiVendorHal { if (mIWifiRttController == null) { return startFailedTo("create RTT controller"); } + if (!registerRttEventCallback()) { + return startFailedTo("register RTT iface callback"); + } enableLinkLayerStats(); } else { mIWifiApIface = mHalDeviceManager.createApIface(null, null); @@ -359,6 +365,22 @@ public class WifiVendorHal { } } + /** + * Registers RTT event callback. Returns whether the registration is successful. + */ + private boolean registerRttEventCallback() { + synchronized (sLock) { + if (mIWifiRttController == null) return boolResult(false); + try { + WifiStatus status = mIWifiRttController.registerEventCallback(mRttEventCallback); + return ok(status); + } catch (RemoteException e) { + handleRemoteException(e); + return false; + } + } + } + /** * Stops the HAL */ @@ -881,19 +903,13 @@ public class WifiVendorHal { private int mRttCmdIdNext = 1; // used to generate new command ids private int mRttCmdId; // id of currently active request - private RttEventCallback mRttEventCallback; // currently active RTT callback + // Event handler for current active RTT request. + private WifiNative.RttEventHandler mRttEventHandler; /** * Receives a callback from the Hal and passes it along to our client using RttEventHandler */ private class RttEventCallback extends IWifiRttControllerEventCallback.Stub { - WifiNative.RttEventHandler mRttEventHandler; - int mRttCmdId; - - RttEventCallback(int cmdId, WifiNative.RttEventHandler rttEventHandler) { - mRttCmdId = cmdId; - mRttEventHandler = rttEventHandler; - } @Override public void onResults(int cmdId, java.util.ArrayList results) { @@ -901,6 +917,8 @@ public class WifiVendorHal { synchronized (sLock) { if (cmdId != mRttCmdId || mRttEventHandler == null) return; eventHandler = mRttEventHandler; + // Reset the command id for RTT operations in WifiVendorHal. + WifiVendorHal.this.mRttCmdId = 0; } RttManager.RttResult[] rtt = new RttManager.RttResult[results.size()]; for (int i = 0; i < rtt.length; i++) { @@ -1211,13 +1229,10 @@ public class WifiVendorHal { if (mIWifiRttController == null) return boolResult(false); if (mRttCmdId != 0) return boolResult(false); mRttCmdId = mRttCmdIdNext++; + mRttEventHandler = handler; if (mRttCmdIdNext <= 0) mRttCmdIdNext = 1; try { - mRttEventCallback = new RttEventCallback(mRttCmdId, handler); WifiStatus status = mIWifiRttController.rangeRequest(mRttCmdId, rttConfigs); - if (ok(status)) { - status = mIWifiRttController.registerEventCallback(mRttEventCallback); - } if (ok(status)) return true; mRttCmdId = 0; return false; -- cgit v1.2.3