summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java19
-rw-r--r--tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java55
2 files changed, 72 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
index 558274c8d..04bf2e009 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
@@ -342,9 +342,17 @@ public class WifiAwareDataPathStateManager {
return null;
}
+ nnri.interfaceName = selectInterfaceForRequest(nnri);
+ if (nnri.interfaceName == null) {
+ Log.w(TAG,
+ "onDataPathRequest: request " + networkSpecifier + " no interface available");
+ mMgr.respondToDataPathRequest(false, ndpId, "", null, null, false);
+ mNetworkRequestsCache.remove(networkSpecifier);
+ return null;
+ }
+
nnri.state = AwareNetworkRequestInformation.STATE_RESPONDER_WAIT_FOR_RESPOND_RESPONSE;
nnri.ndpId = ndpId;
- nnri.interfaceName = selectInterfaceForRequest(nnri);
nnri.startTimestamp = SystemClock.elapsedRealtime();
mMgr.respondToDataPathRequest(true, ndpId, nnri.interfaceName, nnri.networkSpecifier.pmk,
nnri.networkSpecifier.passphrase, nnri.networkSpecifier.isOutOfBand());
@@ -681,6 +689,13 @@ public class WifiAwareDataPathStateManager {
}
nnri.interfaceName = selectInterfaceForRequest(nnri);
+ if (nnri.interfaceName == null) {
+ Log.w(TAG, "needNetworkFor: request " + networkSpecifier
+ + " no interface available");
+ mNetworkRequestsCache.remove(networkSpecifier);
+ return;
+ }
+
mMgr.initiateDataPathSetup(networkSpecifier, nnri.peerInstanceId,
NanDataPathChannelCfg.CHANNEL_NOT_REQUESTED, selectChannelForRequest(nnri),
nnri.peerDiscoveryMac, nnri.interfaceName, nnri.networkSpecifier.pmk,
@@ -819,7 +834,7 @@ public class WifiAwareDataPathStateManager {
Log.e(TAG, "selectInterfaceForRequest: req=" + req + " - but no interfaces available!");
- return "";
+ return null;
}
/**
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<Short> 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
*/