summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEtan Cohen <etancohen@google.com>2019-01-02 11:22:35 -0800
committerEtan Cohen <etancohen@google.com>2019-02-25 23:18:31 -0800
commit7ed8dfa27407867e22339ea93c385ba301a0c25b (patch)
tree9cb4d2bb3a8d944a2059c6a53195ef49c194b096
parentac1dae1101d6071719b1d1c014250a5916c475f7 (diff)
downloadandroid_frameworks_opt_net_wifi-7ed8dfa27407867e22339ea93c385ba301a0c25b.tar.gz
android_frameworks_opt_net_wifi-7ed8dfa27407867e22339ea93c385ba301a0c25b.tar.bz2
android_frameworks_opt_net_wifi-7ed8dfa27407867e22339ea93c385ba301a0c25b.zip
[AWARE] Add support for "instant request failures"
If the factory knows that the request cannot be fulfilled then declare that to connectivity service (which would result in an onUnavailable callback). Happens on: firmware failures, notes: - The firmware does retry messages, even if we add framework retries in the future, at some point we'll have to give up. - Framework-level retries aren't trivial since the peer also has to be reset. Bug: 31382922 Test: atest com.android.server.wifi.aware Test: act.py DataPathTest:test_multiple_identical_networks Test: act.py DataPathTest:test_multiple_ndi_passphrases Test: act.py DataPathTest:test_ib_responder_any_usage Test: act.py ThroughputTest:test_iperf_max_ndi_aware_only_passphrases Test: atest SingleDeviceTest (CTS: modified for new API!) Change-Id: I02b7d1597ee086def405b2d2be98b4b0d2e7d4cd
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java23
-rw-r--r--tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java65
2 files changed, 75 insertions, 13 deletions
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
index e9650715d..e641106a7 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
@@ -282,6 +282,7 @@ public class WifiAwareDataPathStateManager {
Log.w(TAG, "onDataPathInitiateSuccess: network request in incorrect state: state="
+ nnri.state);
mNetworkRequestsCache.remove(networkSpecifier);
+ mNetworkFactory.letAppKnowThatRequestsAreUnavailable(nnri);
mMgr.endDataPath(ndpId);
return;
}
@@ -309,6 +310,7 @@ public class WifiAwareDataPathStateManager {
+ networkSpecifier);
return;
}
+ mNetworkFactory.letAppKnowThatRequestsAreUnavailable(nnri);
if (nnri.state
!= AwareNetworkRequestInformation.STATE_INITIATOR_WAIT_FOR_REQUEST_RESPONSE) {
@@ -420,6 +422,7 @@ public class WifiAwareDataPathStateManager {
"onDataPathRequest: request " + networkSpecifier + " no interface available");
mMgr.respondToDataPathRequest(false, ndpId, "", null, null, null, false);
mNetworkRequestsCache.remove(networkSpecifier);
+ mNetworkFactory.letAppKnowThatRequestsAreUnavailable(nnri);
return null;
}
@@ -472,6 +475,7 @@ public class WifiAwareDataPathStateManager {
+ " failed responding");
mMgr.endDataPath(ndpId);
mNetworkRequestsCache.remove(networkSpecifier);
+ mNetworkFactory.letAppKnowThatRequestsAreUnavailable(nnri);
mAwareMetrics.recordNdpStatus(reasonOnFailure, networkSpecifier.isOutOfBand(),
nnri.startTimestamp);
return;
@@ -483,6 +487,7 @@ public class WifiAwareDataPathStateManager {
+ " is incorrect state=" + nnri.state);
mMgr.endDataPath(ndpId);
mNetworkRequestsCache.remove(networkSpecifier);
+ mNetworkFactory.letAppKnowThatRequestsAreUnavailable(nnri);
return;
}
@@ -533,6 +538,7 @@ public class WifiAwareDataPathStateManager {
if (nnri.state != AwareNetworkRequestInformation.STATE_WAIT_FOR_CONFIRM) {
Log.w(TAG, "onDataPathConfirm: invalid state=" + nnri.state);
mNetworkRequestsCache.remove(networkSpecifier);
+ mNetworkFactory.letAppKnowThatRequestsAreUnavailable(nnri);
if (accept) {
mMgr.endDataPath(ndpId);
}
@@ -647,6 +653,7 @@ public class WifiAwareDataPathStateManager {
+ " rejected - reason=" + reason);
}
mNetworkRequestsCache.remove(networkSpecifier);
+ mNetworkFactory.letAppKnowThatRequestsAreUnavailable(nnri);
mAwareMetrics.recordNdpStatus(reason, networkSpecifier.isOutOfBand(),
nnri.startTimestamp);
}
@@ -745,6 +752,7 @@ public class WifiAwareDataPathStateManager {
}
mAwareMetrics.recordNdpStatus(NanStatusType.INTERNAL_FAILURE,
nnri.networkSpecifier.isOutOfBand(), nnri.startTimestamp);
+ mNetworkFactory.letAppKnowThatRequestsAreUnavailable(nnri);
mMgr.endDataPath(nnri.ndpId);
nnri.state = AwareNetworkRequestInformation.STATE_TERMINATING;
@@ -823,6 +831,7 @@ public class WifiAwareDataPathStateManager {
if (nnri == null) {
Log.e(TAG, "WifiAwareNetworkFactory.acceptRequest: request=" + request
+ " - can't parse network specifier");
+ releaseRequestAsUnfulfillableByAnyFactory(request);
return false;
}
@@ -886,6 +895,7 @@ public class WifiAwareDataPathStateManager {
Log.w(TAG, "needNetworkFor: request " + networkSpecifier
+ " no interface available");
mNetworkRequestsCache.remove(networkSpecifier);
+ letAppKnowThatRequestsAreUnavailable(nnri);
return;
}
@@ -950,6 +960,9 @@ public class WifiAwareDataPathStateManager {
nnri.state = AwareNetworkRequestInformation.STATE_TERMINATING;
} else {
mNetworkRequestsCache.remove(networkSpecifier);
+ if (nnri.networkAgent != null) {
+ letAppKnowThatRequestsAreUnavailable(nnri);
+ }
}
} else {
if (VDBG) {
@@ -958,6 +971,12 @@ public class WifiAwareDataPathStateManager {
}
}
}
+
+ void letAppKnowThatRequestsAreUnavailable(AwareNetworkRequestInformation nnri) {
+ for (NetworkRequest nr : nnri.equivalentRequests) {
+ releaseRequestAsUnfulfillableByAnyFactory(nr);
+ }
+ }
}
private class WifiAwareNetworkAgent extends NetworkAgent {
@@ -1017,7 +1036,9 @@ public class WifiAwareDataPathStateManager {
}
}
- if (nnri.networkAgent != null) {
+ if (nnri.networkAgent == null) {
+ mNetworkFactory.letAppKnowThatRequestsAreUnavailable(nnri);
+ } else {
nnri.networkAgent.reconfigureAgentAsDisconnected();
}
}
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 069e8655b..e7a61e575 100644
--- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java
@@ -29,6 +29,7 @@ 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.atLeastOnce;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -74,6 +75,7 @@ import android.os.Messenger;
import android.os.PowerManager;
import android.os.Process;
import android.os.test.TestLooper;
+import android.util.Pair;
import androidx.test.filters.SmallTest;
@@ -299,7 +301,8 @@ public class WifiAwareDataPathStateManagerTest {
res.mMessenger.send(reqNetworkMsg);
mMockLooper.dispatchAll();
- // failure: no interactions with connectivity manager or native manager
+ // failure: no interactions with native manager
+ verifyUnfullfillableDispatched(res.mReverseMessenger);
verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock, mMockNwMgt);
}
@@ -459,6 +462,8 @@ public class WifiAwareDataPathStateManagerTest {
mDut.onRespondToDataPathSetupRequestResponse(transactionId.getValue(), true, 0);
mMockLooper.dispatchAll();
+ verifyUnfullfillableDispatched(res.mReverseMessenger);
+
// failure if there's further activity
verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock, mMockNwMgt);
}
@@ -611,7 +616,7 @@ public class WifiAwareDataPathStateManagerTest {
InOrder inOrderM = inOrder(mAwareMetricsMock);
// (1) initialize all clients
- Messenger messenger = initOobDataPathEndPoint(true, 2, clientId, inOrder, inOrderM);
+ Messenger messenger = initOobDataPathEndPoint(true, 2, clientId, inOrder, inOrderM).first;
for (int i = 1; i < numRequestsPre + numRequestsPost; ++i) {
initOobDataPathEndPoint(false, 1, clientId + i, inOrder, inOrderM);
}
@@ -751,7 +756,8 @@ public class WifiAwareDataPathStateManagerTest {
InOrder inOrderM = inOrder(mAwareMetricsMock);
// (1) initialize all clients
- Messenger messenger = initOobDataPathEndPoint(true, numNdis, clientId, inOrder, inOrderM);
+ Pair<Messenger, Messenger> res = initOobDataPathEndPoint(true, numNdis, clientId, inOrder,
+ inOrderM);
for (int i = 1; i < numNdis + 3; ++i) {
initOobDataPathEndPoint(false, numNdis, clientId + i, inOrder, inOrderM);
}
@@ -770,7 +776,7 @@ public class WifiAwareDataPathStateManagerTest {
reqNetworkMsg.what = NetworkFactory.CMD_REQUEST_NETWORK;
reqNetworkMsg.obj = nr;
reqNetworkMsg.arg1 = 0;
- messenger.send(reqNetworkMsg);
+ res.first.send(reqNetworkMsg);
mMockLooper.dispatchAll();
if (i < numNdis) {
@@ -797,6 +803,8 @@ public class WifiAwareDataPathStateManagerTest {
netInfo.getPeerIpv6Addr().getAddress());
assertEquals(0, netInfo.getPort()); // uninitialized -> 0
assertEquals(-1, netInfo.getTransportProtocol()); // uninitialized -> -1
+ } else {
+ verifyUnfullfillableDispatched(res.second);
}
}
@@ -1165,6 +1173,7 @@ public class WifiAwareDataPathStateManagerTest {
// consequences of failure:
// Responder (publisher): responds with a rejection to any data-path requests
// Initiator (subscribe): doesn't initiate (i.e. no HAL requests)
+ verifyUnfullfillableDispatched(res.mReverseMessenger);
if (doPublish) {
// (2) get request & respond
mDut.onDataPathRequestNotification(pubSubId, peerDiscoveryMac, ndpId, null);
@@ -1224,6 +1233,7 @@ public class WifiAwareDataPathStateManagerTest {
// consequences of failure:
// Responder (publisher): responds with a rejection to any data-path requests
// Initiator (subscribe): doesn't initiate (i.e. no HAL requests)
+ verifyUnfullfillableDispatched(res.mReverseMessenger);
if (doPublish) {
// (2) get request & respond
mDut.onDataPathRequestNotification(pubSubId, peerDiscoveryMac, ndpId, null);
@@ -1312,6 +1322,7 @@ public class WifiAwareDataPathStateManagerTest {
// short-circuit the rest of this test
inOrderM.verify(mAwareMetricsMock).recordNdpStatus(eq(NanStatusType.INTERNAL_FAILURE),
eq(useDirect), anyLong());
+ verifyUnfullfillableDispatched(res.mReverseMessenger);
verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock);
return;
}
@@ -1339,6 +1350,7 @@ public class WifiAwareDataPathStateManagerTest {
assertTrue(mAlarmManager.dispatch(
WifiAwareStateManager.HAL_DATA_PATH_CONFIRM_TIMEOUT_TAG));
mMockLooper.dispatchAll();
+ verifyUnfullfillableDispatched(res.mReverseMessenger);
inOrder.verify(mMockNative).endDataPath(transactionId.capture(), eq(ndpId));
mDut.onEndDataPathResponse(transactionId.getValue(), true, 0);
mMockLooper.dispatchAll();
@@ -1453,6 +1465,7 @@ public class WifiAwareDataPathStateManagerTest {
assertTrue(mAlarmManager.dispatch(
WifiAwareStateManager.HAL_DATA_PATH_CONFIRM_TIMEOUT_TAG));
mMockLooper.dispatchAll();
+ verifyUnfullfillableDispatched(res.mReverseMessenger);
inOrder.verify(mMockNative).endDataPath(transactionId.capture(), eq(ndpId));
mDut.onEndDataPathResponse(transactionId.getValue(), true, 0);
mMockLooper.dispatchAll();
@@ -1480,6 +1493,7 @@ public class WifiAwareDataPathStateManagerTest {
inOrderM.verify(mAwareMetricsMock).recordNdpSessionDuration(anyLong());
}
} else {
+ verifyUnfullfillableDispatched(res.mReverseMessenger);
inOrder.verify(mMockNative).respondToDataPathRequest(transactionId.capture(), eq(false),
eq(ndpId), eq(""), eq(null), eq(null), eq(null), eq(false), any());
mDut.onRespondToDataPathSetupRequestResponse(transactionId.getValue(), true, 0);
@@ -1577,7 +1591,7 @@ public class WifiAwareDataPathStateManagerTest {
nc.setLinkDownstreamBandwidthKbps(1);
nc.setSignalStrength(1);
- return new NetworkRequest(nc, 0, requestId, NetworkRequest.Type.NONE);
+ return new NetworkRequest(nc, 0, requestId, NetworkRequest.Type.REQUEST);
}
private NetworkRequest getDirectNetworkRequest(int clientId, int role, byte[] peer,
@@ -1642,8 +1656,8 @@ public class WifiAwareDataPathStateManagerTest {
ArgumentCaptor<Integer> sessionId = ArgumentCaptor.forClass(Integer.class);
ArgumentCaptor<Integer> peerIdCaptor = ArgumentCaptor.forClass(Integer.class);
- Messenger messenger = initOobDataPathEndPoint(isFirstIteration, 1, clientId, inOrder,
- inOrderM);
+ Pair<Messenger, Messenger> res = initOobDataPathEndPoint(isFirstIteration, 1, clientId,
+ inOrder, inOrderM);
if (doPublish) {
mDut.publish(clientId, publishConfig, mMockSessionCallback);
@@ -1672,11 +1686,12 @@ public class WifiAwareDataPathStateManagerTest {
eq(someMsg.getBytes()));
return new DataPathEndPointInfo(sessionId.getValue(), peerIdCaptor.getValue(),
- isFirstIteration ? messenger : null);
+ isFirstIteration ? res.first : null, isFirstIteration ? res.second : null);
}
- private Messenger initOobDataPathEndPoint(boolean startUpSequence, int maxNdiInterfaces,
- int clientId, InOrder inOrder, InOrder inOrderM) throws Exception {
+ private Pair<Messenger, Messenger> initOobDataPathEndPoint(boolean startUpSequence,
+ int maxNdiInterfaces, int clientId, InOrder inOrder, InOrder inOrderM)
+ throws Exception {
final int pid = 2000;
final String callingPackage = "com.android.somePackage";
final ConfigRequest configRequest = new ConfigRequest.Builder().build();
@@ -1734,7 +1749,20 @@ public class WifiAwareDataPathStateManagerTest {
mDut.onCreateDataPathInterfaceResponse(transactionId.getValue(), true, 0);
mMockLooper.dispatchAll();
}
- return messengerCaptor.getValue();
+ Messenger messenger = messengerCaptor.getValue();
+
+ Messenger reverseMessenger = null;
+ if (messenger != null) {
+ reverseMessenger = mock(Messenger.class);
+
+ Message fullConnectionMessage = Message.obtain();
+ fullConnectionMessage.what = AsyncChannel.CMD_CHANNEL_FULL_CONNECTION;
+ fullConnectionMessage.replyTo = reverseMessenger;
+ messenger.send(fullConnectionMessage);
+ mMockLooper.dispatchAll();
+ }
+
+ return Pair.create(messenger, reverseMessenger);
}
return null;
@@ -1786,14 +1814,27 @@ public class WifiAwareDataPathStateManagerTest {
int mSessionId;
PeerHandle mPeerHandle;
Messenger mMessenger;
+ Messenger mReverseMessenger;
- DataPathEndPointInfo(int sessionId, int peerId, Messenger messenger) {
+ DataPathEndPointInfo(int sessionId, int peerId, Messenger messenger,
+ Messenger reverseMessenger) {
mSessionId = sessionId;
mPeerHandle = new PeerHandle(peerId);
mMessenger = messenger;
+ mReverseMessenger = reverseMessenger;
}
}
+ /**
+ * Verify that an EVENT_UNFULFILLABLE_REQUEST was dispatched on the (mock) messenger.
+ */
+ private void verifyUnfullfillableDispatched(Messenger messenger) throws Exception {
+ ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
+
+ verify(messenger, atLeastOnce()).send(messageCaptor.capture());
+ assertEquals(NetworkFactory.EVENT_UNFULFILLABLE_REQUEST, messageCaptor.getValue().what);
+ }
+
// copy of the method in WifiAwareDataPathStateManager - but without error checking (so we can
// construct invalid TLVs for testing).
private static byte[] buildTlv(int port, int transportProtocol, boolean includeGarbageTlv) {