diff options
author | Etan Cohen <etancohen@google.com> | 2018-08-01 23:02:50 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-08-01 23:02:50 +0000 |
commit | 4abb52b9125356b97adda4e430188b8a976fdc6c (patch) | |
tree | 4ae4af785675249bcd912ccc2f1255b6039e6313 | |
parent | 4fc8cdcbb46c788d3e55e23b8cd1dbe061369bc8 (diff) | |
parent | 0ebd13f268eaca16e396089983475674620632f3 (diff) |
Merge "[RTT] Recreate RTT controller when HAL indicates it is invalid" into pi-dev
-rw-r--r-- | service/java/com/android/server/wifi/rtt/RttNative.java | 18 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java | 84 |
2 files changed, 101 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/rtt/RttNative.java b/service/java/com/android/server/wifi/rtt/RttNative.java index accd1a2f8..34fd2e3e7 100644 --- a/service/java/com/android/server/wifi/rtt/RttNative.java +++ b/service/java/com/android/server/wifi/rtt/RttNative.java @@ -166,6 +166,11 @@ public class RttNative extends IWifiRttControllerEventCallback.Stub { */ public boolean rangeRequest(int cmdId, RangingRequest request, boolean isCalledFromPrivilegedContext) { + return rangeRequestInternal(cmdId, request, isCalledFromPrivilegedContext, true); + } + + private boolean rangeRequestInternal(int cmdId, RangingRequest request, + boolean isCalledFromPrivilegedContext, boolean tryToReinitIfNecessary) { if (mDbg) { Log.v(TAG, "rangeRequest: cmdId=" + cmdId + ", # of requests=" + request.mRttPeers.size()); @@ -175,6 +180,11 @@ public class RttNative extends IWifiRttControllerEventCallback.Stub { synchronized (mLock) { if (!isReady()) { Log.e(TAG, "rangeRequest: RttController is null"); + if (tryToReinitIfNecessary) { + updateController(); + return rangeRequestInternal(cmdId, request, isCalledFromPrivilegedContext, + false); + } return false; } @@ -192,6 +202,14 @@ public class RttNative extends IWifiRttControllerEventCallback.Stub { try { WifiStatus status = mIWifiRttController.rangeRequest(cmdId, rttConfig); + if (status.code == WifiStatusCode.ERROR_WIFI_RTT_CONTROLLER_INVALID + && tryToReinitIfNecessary) { + Log.d(TAG, "rangeRequest: RTT controller invalidated from under us - reinit!"); + mIWifiRttController = null; + updateController(); + return rangeRequestInternal(cmdId, request, isCalledFromPrivilegedContext, + false); + } if (status.code != WifiStatusCode.SUCCESS) { Log.e(TAG, "rangeRequest: cannot issue range request -- code=" + status.code); return false; diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java index 3f5aa5f2d..7bbe6bb79 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -50,10 +51,13 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ErrorCollector; import org.mockito.ArgumentCaptor; +import org.mockito.InOrder; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -62,6 +66,7 @@ import java.util.List; public class RttNativeTest { private RttNative mDut; private WifiStatus mStatusSuccess; + private WifiStatus mStatusRttControllerInvalid; private ArgumentCaptor<ArrayList> mRttConfigCaptor = ArgumentCaptor.forClass(ArrayList.class); private ArgumentCaptor<List> mRttResultCaptor = ArgumentCaptor.forClass(List.class); @@ -97,6 +102,9 @@ public class RttNativeTest { when(mockRttController.rangeCancel(anyInt(), any(ArrayList.class))).thenReturn( mStatusSuccess); + mStatusRttControllerInvalid = new WifiStatus(); + mStatusRttControllerInvalid.code = WifiStatusCode.ERROR_WIFI_RTT_CONTROLLER_INVALID; + mDut = new RttNative(mockRttServiceImpl, mockHalDeviceManager); mDut.start(null); verify(mockHalDeviceManager).registerStatusListener(mHdmStatusListener.capture(), any()); @@ -324,15 +332,18 @@ public class RttNativeTest { int cmdId = 55; RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); + InOrder order = inOrder(mockRttServiceImpl); + // (1) configure Wi-Fi down and send a status change indication when(mockHalDeviceManager.isStarted()).thenReturn(false); mHdmStatusListener.getValue().onStatusChanged(); - verify(mockRttServiceImpl).disable(); + order.verify(mockRttServiceImpl).disable(); assertFalse(mDut.isReady()); // (2) issue range request mDut.rangeRequest(cmdId, request, true); + order.verify(mockRttServiceImpl).disable(); // due to re-init attempt verifyNoMoreInteractions(mockRttServiceImpl, mockRttController); } @@ -436,6 +447,77 @@ public class RttNativeTest { } } + /** + * Validate correct re-initialization when the RTT Controller is invalid (which can happen + * due to mode change in the HAL). Expect a re-initialization and a rerun of the range request. + */ + @Test + public void testRangeRequestInvalidRttControllerOnce() throws Exception { + int cmdId = 55; + RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); + + InOrder inOrder = Mockito.inOrder(mockRttController); + + // configure failure then success + when(mockRttController.rangeRequest(anyInt(), any(ArrayList.class))).thenReturn( + mStatusRttControllerInvalid).thenReturn(mStatusSuccess); + + // issue range request + boolean result = mDut.rangeRequest(cmdId, request, true); + assertTrue("rangeRequest should succeeed", result); + + // verify HAL call + inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture()); + ArrayList<RttConfig> halRequest1 = mRttConfigCaptor.getValue(); + + // verify re-initialization (i.e. callback re-registered) + inOrder.verify(mockRttController).registerEventCallback(any()); + + // verify HAL call + inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture()); + ArrayList<RttConfig> halRequest2 = mRttConfigCaptor.getValue(); + + assertTrue("HAL parameters different between calls!", + Arrays.equals(halRequest1.toArray(), halRequest2.toArray())); + verifyNoMoreInteractions(mockRttController); + } + + /** + * Validate correct re-initialization when the RTT Controller is invalid (which can happen + * due to mode change in the HAL). Expect a re-initialization and a rerun of the range request - + * but only once (no infinite loop). + */ + @Test + public void testRangeRequestInvalidRttControllerForever() throws Exception { + int cmdId = 55; + RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0); + + InOrder inOrder = Mockito.inOrder(mockRttController); + + // configure failure + when(mockRttController.rangeRequest(anyInt(), any(ArrayList.class))).thenReturn( + mStatusRttControllerInvalid); + + // issue range request + boolean result = mDut.rangeRequest(cmdId, request, true); + assertFalse("rangeRequest should fail", result); + + // verify HAL call + inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture()); + ArrayList<RttConfig> halRequest1 = mRttConfigCaptor.getValue(); + + // verify re-initialization (i.e. callback re-registered) + inOrder.verify(mockRttController).registerEventCallback(any()); + + // verify HAL call + inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture()); + ArrayList<RttConfig> halRequest2 = mRttConfigCaptor.getValue(); + + assertTrue("HAL parameters different between calls!", + Arrays.equals(halRequest1.toArray(), halRequest2.toArray())); + verifyNoMoreInteractions(mockRttController); + } + // Utilities /** |