From e24b61801dbf5c1470254e946e1b2f47f9392fda Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Fri, 14 Jul 2017 12:13:53 -0700 Subject: [AWARE] Abort data-path setup if there are no data-interfaces Data-interfaces are currently checked only when the data-path setup process starts. Add checks when actually using data-interface name and abort process if a data-interface is no longer available. Bug: 63702690 Test: unit tests + integration tests passing Change-Id: I922e157228762fc923fd26b350b625724b94ef06 --- .../aware/WifiAwareDataPathStateManagerTest.java | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java index f3927357f..806300423 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java @@ -26,6 +26,7 @@ import static org.mockito.ArgumentMatchers.anyByte; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyShort; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; @@ -290,6 +291,60 @@ public class WifiAwareDataPathStateManagerTest { verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock); } + /** + * Validate that if the data-interfaces are deleted while a data-path is being created, the + * process will terminate. + */ + @Test + public void testDestroyNdiDuringNdpSetupResponder() throws Exception { + final int clientId = 123; + final byte pubSubId = 55; + final int requestorId = 1341234; + final byte[] peerDiscoveryMac = HexEncoding.decode("000102030405".toCharArray(), false); + final int ndpId = 3; + + InOrder inOrder = inOrder(mMockNative, mMockCm, mMockCallback, mMockSessionCallback); + InOrder inOrderM = inOrder(mAwareMetricsMock); + + ArgumentCaptor transactionId = ArgumentCaptor.forClass(Short.class); + + // (0) initialize + DataPathEndPointInfo res = initDataPathEndPoint(clientId, pubSubId, requestorId, + peerDiscoveryMac, inOrder, inOrderM, true); + + // (1) request network + NetworkRequest nr = getSessionNetworkRequest(clientId, res.mSessionId, res.mPeerHandle, + null, null, true); + + Message reqNetworkMsg = Message.obtain(); + reqNetworkMsg.what = NetworkFactory.CMD_REQUEST_NETWORK; + reqNetworkMsg.obj = nr; + reqNetworkMsg.arg1 = 0; + res.mMessenger.send(reqNetworkMsg); + mMockLooper.dispatchAll(); + + // (2) delete interface(s) + mDut.deleteAllDataPathInterfaces(); + mMockLooper.dispatchAll(); + inOrder.verify(mMockNative).deleteAwareNetworkInterface(transactionId.capture(), + anyString()); + mDut.onDeleteDataPathInterfaceResponse(transactionId.getValue(), true, 0); + mMockLooper.dispatchAll(); + + // (3) have responder receive request + mDut.onDataPathRequestNotification(pubSubId, peerDiscoveryMac, ndpId); + mMockLooper.dispatchAll(); + + // (4) verify that responder aborts (i.e. refuses request) + inOrder.verify(mMockNative).respondToDataPathRequest(transactionId.capture(), eq(false), + eq(ndpId), eq(""), eq(null), eq(null), eq(false), any()); + mDut.onRespondToDataPathSetupRequestResponse(transactionId.getValue(), true, 0); + mMockLooper.dispatchAll(); + + // failure if there's further activity + verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock); + } + /* * Initiator tests */ -- cgit v1.2.3