summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-07-26 22:09:00 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-07-26 22:09:00 +0000
commit9ef6adef90d2907c9fe20f34405f3e9eb6810e27 (patch)
tree0c0e44700efa05abf113a64f81973e8f978c05dc
parente15765c974de614090f13e5dc39a5899c8e9cb96 (diff)
parent86ce666f62db6b464536d68944780b46996af04b (diff)
Merge "[AWARE] Support multiple NDPs on an NDI" into oc-mr1-dev
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java79
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java5
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareStateManager.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java291
4 files changed, 255 insertions, 122 deletions
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
index f3ffb08fe..ead0c5f5e 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
@@ -85,7 +85,7 @@ public class WifiAwareDataPathStateManager {
private static final int NETWORK_FACTORY_SIGNAL_STRENGTH_AVAIL = 1;
private final WifiAwareStateManager mMgr;
- private final NetworkInterfaceWrapper mNiWrapper = new NetworkInterfaceWrapper();
+ public NetworkInterfaceWrapper mNiWrapper = new NetworkInterfaceWrapper();
private final NetworkCapabilities mNetworkCapabilitiesFilter = new NetworkCapabilities();
private final Set<String> mInterfaces = new HashSet<>();
private final Map<WifiAwareNetworkSpecifier, AwareNetworkRequestInformation>
@@ -95,7 +95,7 @@ public class WifiAwareDataPathStateManager {
private WifiPermissionsWrapper mPermissionsWrapper;
private Looper mLooper;
private WifiAwareNetworkFactory mNetworkFactory;
- private INetworkManagementService mNwService;
+ public INetworkManagementService mNwService;
public WifiAwareDataPathStateManager(WifiAwareStateManager mgr) {
mMgr = mgr;
@@ -471,14 +471,23 @@ public class WifiAwareDataPathStateManager {
mNetworkCapabilitiesFilter);
LinkProperties linkProperties = new LinkProperties();
- try {
- mNwService.setInterfaceUp(nnri.interfaceName);
- mNwService.enableIpv6(nnri.interfaceName);
- } catch (Exception e) { // NwService throws runtime exceptions for errors
- Log.e(TAG, "onDataPathConfirm: ACCEPT nnri=" + nnri + ": can't configure network - "
- + e);
- mMgr.endDataPath(ndpId);
- return networkSpecifier;
+ boolean interfaceUsedByAnotherNdp = isInterfaceUpAndUsedByAnotherNdp(nnri);
+ if (!interfaceUsedByAnotherNdp) {
+ try {
+ mNwService.setInterfaceUp(nnri.interfaceName);
+ mNwService.enableIpv6(nnri.interfaceName);
+ } catch (Exception e) { // NwService throws runtime exceptions for errors
+ Log.e(TAG, "onDataPathConfirm: ACCEPT nnri=" + nnri
+ + ": can't configure network - "
+ + e);
+ mMgr.endDataPath(ndpId);
+ return networkSpecifier;
+ }
+ } else {
+ if (VDBG) {
+ Log.v(TAG, "onDataPathConfirm: interface already configured: "
+ + nnri.interfaceName);
+ }
}
if (!mNiWrapper.configureAgentProperties(nnri, networkSpecifier, ndpId, networkInfo,
@@ -528,7 +537,7 @@ public class WifiAwareDataPathStateManager {
return;
}
- tearDownInterface(nnriE.getValue());
+ tearDownInterfaceIfPossible(nnriE.getValue());
if (nnriE.getValue().state == AwareNetworkRequestInformation.STATE_CONFIRMED) {
mAwareMetrics.recordNdpSessionDuration(nnriE.getValue().startTimestamp);
}
@@ -542,7 +551,7 @@ public class WifiAwareDataPathStateManager {
if (VDBG) Log.v(TAG, "onAwareDownCleanupDataPaths");
for (AwareNetworkRequestInformation nnri : mNetworkRequestsCache.values()) {
- tearDownInterface(nnri);
+ tearDownInterfaceIfPossible(nnri);
}
mNetworkRequestsCache.clear();
}
@@ -629,13 +638,6 @@ public class WifiAwareDataPathStateManager {
return false;
}
- // TODO (b/63635780) support more then a single concurrent NDP
- if (mNetworkRequestsCache.size() > 0) {
- Log.e(TAG, "WifiAwareNetworkFactory.acceptRequest: request=" + request
- + " - >1 concurrent NDPs aren't supported (yet).");
- return false;
- }
-
mNetworkRequestsCache.put(networkSpecifier, nnri);
return true;
@@ -778,15 +780,23 @@ public class WifiAwareDataPathStateManager {
}
}
- private void tearDownInterface(AwareNetworkRequestInformation nnri) {
- if (VDBG) Log.v(TAG, "tearDownInterface: nnri=" + nnri);
+ private void tearDownInterfaceIfPossible(AwareNetworkRequestInformation nnri) {
+ if (VDBG) Log.v(TAG, "tearDownInterfaceIfPossible: nnri=" + nnri);
- if (nnri.interfaceName != null && !nnri.interfaceName.isEmpty()) {
- try {
- mNwService.setInterfaceDown(nnri.interfaceName);
- } catch (Exception e) { // NwService throws runtime exceptions for errors
- Log.e(TAG,
- "tearDownInterface: nnri=" + nnri + ": can't bring interface down - " + e);
+ if (!TextUtils.isEmpty(nnri.interfaceName)) {
+ boolean interfaceUsedByAnotherNdp = isInterfaceUpAndUsedByAnotherNdp(nnri);
+ if (interfaceUsedByAnotherNdp) {
+ if (VDBG) {
+ Log.v(TAG, "tearDownInterfaceIfPossible: interfaceName=" + nnri.interfaceName
+ + ", still in use - not turning down");
+ }
+ } else {
+ try {
+ mNwService.setInterfaceDown(nnri.interfaceName);
+ } catch (Exception e) { // NwService throws runtime exceptions for errors
+ Log.e(TAG, "tearDownInterfaceIfPossible: nnri=" + nnri
+ + ": can't bring interface down - " + e);
+ }
}
}
@@ -795,6 +805,21 @@ public class WifiAwareDataPathStateManager {
}
}
+ private boolean isInterfaceUpAndUsedByAnotherNdp(AwareNetworkRequestInformation nri) {
+ for (AwareNetworkRequestInformation lnri : mNetworkRequestsCache.values()) {
+ if (lnri == nri) {
+ continue;
+ }
+
+ if (nri.interfaceName.equals(lnri.interfaceName)
+ && lnri.state == AwareNetworkRequestInformation.STATE_CONFIRMED) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
/**
* Select one of the existing interfaces for the new network request.
*
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java b/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java
index 05721afee..2f424db4c 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java
@@ -167,10 +167,9 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub imp
capabilities.maxSubscribeInterfaceAddresses;
frameworkCapabilities.supportedCipherSuites = capabilities.supportedCipherSuites;
- // TODO (b/63635780, b/63635857): enable framework support of >1 NDI and >1 NDP per NDI
- // Until then: force corresponding capabilities to 1.
+ // TODO (b/63635857): enable framework support of >1 NDI
+ // Until then: force corresponding capability to 1.
frameworkCapabilities.maxNdiInterfaces = 1;
- frameworkCapabilities.maxNdpSessions = 1;
mWifiAwareStateManager.onCapabilitiesUpdateResponse(id, frameworkCapabilities);
} else {
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java
index 30aa42a26..6ced9486c 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java
@@ -204,7 +204,7 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
private volatile Characteristics mCharacteristics = null;
private WifiAwareStateMachine mSm;
private WifiAwareRttStateManager mRtt;
- private WifiAwareDataPathStateManager mDataPathMgr;
+ public WifiAwareDataPathStateManager mDataPathMgr;
private PowerManager mPowerManager;
private final SparseArray<WifiAwareClientState> mClients = new SparseArray<>();
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 806300423..37af1ba6f 100644
--- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java
@@ -83,7 +83,6 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import java.lang.reflect.Field;
import java.util.Arrays;
/**
@@ -99,7 +98,6 @@ public class WifiAwareDataPathStateManagerTest {
@Mock private WifiAwareNativeManager mMockNativeManager;
@Mock private WifiAwareNativeApi mMockNative;
@Mock private Context mMockContext;
- @Mock private IWifiAwareManager mMockAwareService;
@Mock private ConnectivityManager mMockCm;
@Mock private INetworkManagementService mMockNwMgt;
@Mock private WifiAwareDataPathStateManager.NetworkInterfaceWrapper mMockNetworkInterface;
@@ -172,7 +170,8 @@ public class WifiAwareDataPathStateManagerTest {
when(mPermissionsWrapperMock.getUidPermission(eq(Manifest.permission.CONNECTIVITY_INTERNAL),
anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED);
- installDataPathStateManagerMocks();
+ mDut.mDataPathMgr.mNwService = mMockNwMgt;
+ mDut.mDataPathMgr.mNiWrapper = mMockNetworkInterface;
}
/**
@@ -252,7 +251,7 @@ public class WifiAwareDataPathStateManagerTest {
mMockLooper.dispatchAll();
}
- verifyNoMoreInteractions(mMockNative);
+ verifyNoMoreInteractions(mMockNative, mMockNwMgt);
}
/**
@@ -273,12 +272,12 @@ public class WifiAwareDataPathStateManagerTest {
anyInt())).thenReturn(PackageManager.PERMISSION_DENIED);
// (0) initialize
- DataPathEndPointInfo res = initDataPathEndPoint(clientId, pubSubId, requestorId,
+ DataPathEndPointInfo res = initDataPathEndPoint(true, clientId, pubSubId, requestorId,
peerDiscoveryMac, inOrder, inOrderM, false);
// (1) request network
NetworkRequest nr = getSessionNetworkRequest(clientId, res.mSessionId, res.mPeerHandle, pmk,
- null, false);
+ null, false, 0);
Message reqNetworkMsg = Message.obtain();
reqNetworkMsg.what = NetworkFactory.CMD_REQUEST_NETWORK;
@@ -288,7 +287,7 @@ public class WifiAwareDataPathStateManagerTest {
mMockLooper.dispatchAll();
// failure: no interactions with connectivity manager or native manager
- verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock);
+ verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock, mMockNwMgt);
}
/**
@@ -309,12 +308,12 @@ public class WifiAwareDataPathStateManagerTest {
ArgumentCaptor<Short> transactionId = ArgumentCaptor.forClass(Short.class);
// (0) initialize
- DataPathEndPointInfo res = initDataPathEndPoint(clientId, pubSubId, requestorId,
+ DataPathEndPointInfo res = initDataPathEndPoint(true, clientId, pubSubId, requestorId,
peerDiscoveryMac, inOrder, inOrderM, true);
// (1) request network
NetworkRequest nr = getSessionNetworkRequest(clientId, res.mSessionId, res.mPeerHandle,
- null, null, true);
+ null, null, true, 0);
Message reqNetworkMsg = Message.obtain();
reqNetworkMsg.what = NetworkFactory.CMD_REQUEST_NETWORK;
@@ -342,7 +341,115 @@ public class WifiAwareDataPathStateManagerTest {
mMockLooper.dispatchAll();
// failure if there's further activity
- verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock);
+ verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock, mMockNwMgt);
+ }
+
+ /**
+ * Validate multiple NDPs created on a single NDI. Most importantly that the interface is
+ * set up on first NDP and torn down on last NDP - and not when one or the other is created or
+ * deleted.
+ *
+ * Procedure:
+ * - create NDP 1, 2, and 3 (interface up only on first)
+ * - delete NDP 2, 1, and 3 (interface down only on last)
+ */
+ @Test
+ public void testMultipleNdpsOnSingleNdi() throws Exception {
+ final int clientId = 123;
+ final byte pubSubId = 58;
+ final int requestorId = 1341234;
+ final int ndpId = 2;
+ final byte[] peerDiscoveryMac = HexEncoding.decode("000102030405".toCharArray(), false);
+ final byte[] peerDataPathMac = HexEncoding.decode("0A0B0C0D0E0F".toCharArray(), false);
+ final int[] startOrder = {0, 1, 2};
+ final int[] endOrder = {1, 0, 2};
+ int networkRequestId = 0;
+
+ ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class);
+ ArgumentCaptor<Short> transactionId = ArgumentCaptor.forClass(Short.class);
+ InOrder inOrder = inOrder(mMockNative, mMockCm, mMockCallback, mMockSessionCallback,
+ mMockNwMgt);
+ InOrder inOrderM = inOrder(mAwareMetricsMock);
+
+ NetworkRequest[] nrs = new NetworkRequest[3];
+ DataPathEndPointInfo[] ress = new DataPathEndPointInfo[3];
+ Messenger[] agentMessengers = new Messenger[3];
+ Messenger messenger = null;
+ boolean first = true;
+ for (int i : startOrder) {
+ networkRequestId += 1;
+ peerDiscoveryMac[5] = (byte) (peerDiscoveryMac[5] + 1);
+ peerDataPathMac[5] = (byte) (peerDataPathMac[5] + 1);
+
+ // (0) initialize
+ ress[i] = initDataPathEndPoint(first, clientId, (byte) (pubSubId + i),
+ requestorId + i, peerDiscoveryMac, inOrder, inOrderM, false);
+ if (first) {
+ messenger = ress[i].mMessenger;
+ }
+
+ // (1) request network
+ nrs[i] = getSessionNetworkRequest(clientId, ress[i].mSessionId, ress[i].mPeerHandle,
+ null, null, false, networkRequestId);
+
+ Message reqNetworkMsg = Message.obtain();
+ reqNetworkMsg.what = NetworkFactory.CMD_REQUEST_NETWORK;
+ reqNetworkMsg.obj = nrs[i];
+ reqNetworkMsg.arg1 = 0;
+ messenger.send(reqNetworkMsg);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).initiateDataPath(transactionId.capture(),
+ eq(requestorId + i),
+ eq(CHANNEL_NOT_REQUESTED), anyInt(), eq(peerDiscoveryMac),
+ eq(sAwareInterfacePrefix + "0"), eq(null),
+ eq(null), eq(false), any());
+
+ mDut.onInitiateDataPathResponseSuccess(transactionId.getValue(), ndpId + i);
+ mMockLooper.dispatchAll();
+
+ // (2) get confirmation
+ mDut.onDataPathConfirmNotification(ndpId + i, peerDataPathMac, true, 0, null);
+ mMockLooper.dispatchAll();
+ if (first) {
+ inOrder.verify(mMockNwMgt).setInterfaceUp(anyString());
+ inOrder.verify(mMockNwMgt).enableIpv6(anyString());
+
+ first = false;
+ }
+ inOrder.verify(mMockCm).registerNetworkAgent(messengerCaptor.capture(), any(), any(),
+ any(), anyInt(), any());
+ agentMessengers[i] = messengerCaptor.getValue();
+ inOrderM.verify(mAwareMetricsMock).recordNdpStatus(eq(NanStatusType.SUCCESS),
+ eq(false), anyLong());
+ inOrderM.verify(mAwareMetricsMock).recordNdpCreation(anyInt(), any());
+ }
+
+ // (3) end data-path (unless didn't get confirmation)
+ int index = 0;
+ for (int i: endOrder) {
+ Message endNetworkReqMsg = Message.obtain();
+ endNetworkReqMsg.what = NetworkFactory.CMD_CANCEL_REQUEST;
+ endNetworkReqMsg.obj = nrs[i];
+ messenger.send(endNetworkReqMsg);
+
+ Message endNetworkUsageMsg = Message.obtain();
+ endNetworkUsageMsg.what = AsyncChannel.CMD_CHANNEL_DISCONNECTED;
+ agentMessengers[i].send(endNetworkUsageMsg);
+ mMockLooper.dispatchAll();
+
+ inOrder.verify(mMockNative).endDataPath(transactionId.capture(), eq(ndpId + i));
+
+ mDut.onEndDataPathResponse(transactionId.getValue(), true, 0);
+ mDut.onDataPathEndNotification(ndpId + i);
+ mMockLooper.dispatchAll();
+
+ if (index++ == endOrder.length - 1) {
+ inOrder.verify(mMockNwMgt).setInterfaceDown(anyString());
+ }
+ inOrderM.verify(mAwareMetricsMock).recordNdpSessionDuration(anyLong());
+ }
+
+ verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock, mMockNwMgt);
}
/*
@@ -563,12 +670,12 @@ public class WifiAwareDataPathStateManagerTest {
InOrder inOrderM = inOrder(mAwareMetricsMock);
// (0) initialize
- DataPathEndPointInfo res = initDataPathEndPoint(clientId, pubSubId, requestorId,
+ DataPathEndPointInfo res = initDataPathEndPoint(true, clientId, pubSubId, requestorId,
peerDiscoveryMac, inOrder, inOrderM, doPublish);
// (1) request network
NetworkRequest nr = getSessionNetworkRequest(clientId, res.mSessionId, res.mPeerHandle, pmk,
- null, doPublish);
+ null, doPublish, 0);
// corrupt the network specifier: reverse the role (so it's mis-matched)
WifiAwareNetworkSpecifier ns =
@@ -603,7 +710,7 @@ public class WifiAwareDataPathStateManagerTest {
eq(ndpId), eq(""), eq(null), eq(null), anyBoolean(), any());
}
- verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock);
+ verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock, mMockNwMgt);
}
private void testDataPathInitiatorResponderInvalidUidUtility(boolean doPublish,
@@ -619,12 +726,12 @@ public class WifiAwareDataPathStateManagerTest {
InOrder inOrderM = inOrder(mAwareMetricsMock);
// (0) initialize
- DataPathEndPointInfo res = initDataPathEndPoint(clientId, pubSubId, requestorId,
+ DataPathEndPointInfo res = initDataPathEndPoint(true, clientId, pubSubId, requestorId,
peerDiscoveryMac, inOrder, inOrderM, doPublish);
// (1) create network request
NetworkRequest nr = getSessionNetworkRequest(clientId, res.mSessionId, res.mPeerHandle, pmk,
- null, doPublish);
+ null, doPublish, 0);
// (2) corrupt request's UID
WifiAwareNetworkSpecifier ns =
@@ -660,7 +767,7 @@ public class WifiAwareDataPathStateManagerTest {
eq(ndpId), eq(""), eq(null), eq(null), anyBoolean(), any());
}
- verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock);
+ verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock, mMockNwMgt);
}
private void testDataPathInitiatorUtility(boolean useDirect, boolean provideMac,
@@ -678,7 +785,8 @@ public class WifiAwareDataPathStateManagerTest {
ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class);
ArgumentCaptor<Short> transactionId = ArgumentCaptor.forClass(Short.class);
- InOrder inOrder = inOrder(mMockNative, mMockCm, mMockCallback, mMockSessionCallback);
+ InOrder inOrder = inOrder(mMockNative, mMockCm, mMockCallback, mMockSessionCallback,
+ mMockNwMgt);
InOrder inOrderM = inOrder(mAwareMetricsMock);
if (!providePmk) {
@@ -694,7 +802,7 @@ public class WifiAwareDataPathStateManagerTest {
}
// (0) initialize
- DataPathEndPointInfo res = initDataPathEndPoint(clientId, pubSubId, requestorId,
+ DataPathEndPointInfo res = initDataPathEndPoint(true, clientId, pubSubId, requestorId,
peerDiscoveryMac, inOrder, inOrderM, false);
// (1) request network
@@ -707,7 +815,7 @@ public class WifiAwareDataPathStateManagerTest {
} else {
nr = getSessionNetworkRequest(clientId, res.mSessionId,
provideMac ? res.mPeerHandle : null, providePmk ? pmk : null,
- providePassphrase ? passphrase : null, false);
+ providePassphrase ? passphrase : null, false, 0);
}
Message reqNetworkMsg = Message.obtain();
@@ -737,6 +845,8 @@ public class WifiAwareDataPathStateManagerTest {
mDut.onDataPathConfirmNotification(ndpId, peerDataPathMac, true, 0,
peerToken.getBytes());
mMockLooper.dispatchAll();
+ inOrder.verify(mMockNwMgt).setInterfaceUp(anyString());
+ inOrder.verify(mMockNwMgt).enableIpv6(anyString());
inOrder.verify(mMockCm).registerNetworkAgent(messengerCaptor.capture(), any(), any(),
any(), anyInt(), any());
inOrderM.verify(mAwareMetricsMock).recordNdpStatus(eq(NanStatusType.SUCCESS),
@@ -763,16 +873,16 @@ public class WifiAwareDataPathStateManagerTest {
Message endNetworkUsageMsg = Message.obtain();
endNetworkUsageMsg.what = AsyncChannel.CMD_CHANNEL_DISCONNECTED;
messengerCaptor.getValue().send(endNetworkUsageMsg);
-
- mMockLooper.dispatchAll();
- inOrder.verify(mMockNative).endDataPath(transactionId.capture(), eq(ndpId));
mDut.onEndDataPathResponse(transactionId.getValue(), true, 0);
mDut.onDataPathEndNotification(ndpId);
mMockLooper.dispatchAll();
+
+ inOrder.verify(mMockNwMgt).setInterfaceDown(anyString());
+ inOrder.verify(mMockNative).endDataPath(transactionId.capture(), eq(ndpId));
inOrderM.verify(mAwareMetricsMock).recordNdpSessionDuration(anyLong());
}
- verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock);
+ verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock, mMockNwMgt);
}
private void testDataPathResponderUtility(boolean useDirect, boolean provideMac,
@@ -790,7 +900,8 @@ public class WifiAwareDataPathStateManagerTest {
ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class);
ArgumentCaptor<Short> transactionId = ArgumentCaptor.forClass(Short.class);
- InOrder inOrder = inOrder(mMockNative, mMockCm, mMockCallback, mMockSessionCallback);
+ InOrder inOrder = inOrder(mMockNative, mMockCm, mMockCallback, mMockSessionCallback,
+ mMockNwMgt);
InOrder inOrderM = inOrder(mAwareMetricsMock);
if (providePmk) {
@@ -800,7 +911,7 @@ public class WifiAwareDataPathStateManagerTest {
}
// (0) initialize
- DataPathEndPointInfo res = initDataPathEndPoint(clientId, pubSubId, requestorId,
+ DataPathEndPointInfo res = initDataPathEndPoint(true, clientId, pubSubId, requestorId,
peerDiscoveryMac, inOrder, inOrderM, true);
// (1) request network
@@ -813,7 +924,7 @@ public class WifiAwareDataPathStateManagerTest {
} else {
nr = getSessionNetworkRequest(clientId, res.mSessionId,
provideMac ? res.mPeerHandle : null, providePmk ? pmk : null,
- providePassphrase ? passphrase : null, true);
+ providePassphrase ? passphrase : null, true, 0);
}
Message reqNetworkMsg = Message.obtain();
@@ -837,6 +948,8 @@ public class WifiAwareDataPathStateManagerTest {
mDut.onDataPathConfirmNotification(ndpId, peerDataPathMac, true, 0,
peerToken.getBytes());
mMockLooper.dispatchAll();
+ inOrder.verify(mMockNwMgt).setInterfaceUp(anyString());
+ inOrder.verify(mMockNwMgt).enableIpv6(anyString());
inOrder.verify(mMockCm).registerNetworkAgent(messengerCaptor.capture(), any(), any(),
any(), anyInt(), any());
inOrderM.verify(mAwareMetricsMock).recordNdpStatus(eq(NanStatusType.SUCCESS),
@@ -864,35 +977,23 @@ public class WifiAwareDataPathStateManagerTest {
endNetworkUsageMsg.what = AsyncChannel.CMD_CHANNEL_DISCONNECTED;
messengerCaptor.getValue().send(endNetworkUsageMsg);
- mMockLooper.dispatchAll();
- inOrder.verify(mMockNative).endDataPath(transactionId.capture(), eq(ndpId));
mDut.onEndDataPathResponse(transactionId.getValue(), true, 0);
mDut.onDataPathEndNotification(ndpId);
mMockLooper.dispatchAll();
+
+ inOrder.verify(mMockNwMgt).setInterfaceDown(anyString());
+ inOrder.verify(mMockNative).endDataPath(transactionId.capture(), eq(ndpId));
inOrderM.verify(mAwareMetricsMock).recordNdpSessionDuration(anyLong());
}
- verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock);
- }
-
- private void installDataPathStateManagerMocks() throws Exception {
- Field field = WifiAwareStateManager.class.getDeclaredField("mDataPathMgr");
- field.setAccessible(true);
- Object mDataPathMgr = field.get(mDut);
-
- field = WifiAwareDataPathStateManager.class.getDeclaredField("mNwService");
- field.setAccessible(true);
- field.set(mDataPathMgr, mMockNwMgt);
-
- field = WifiAwareDataPathStateManager.class.getDeclaredField("mNiWrapper");
- field.setAccessible(true);
- field.set(mDataPathMgr, mMockNetworkInterface);
+ verifyNoMoreInteractions(mMockNative, mMockCm, mAwareMetricsMock, mMockNwMgt);
}
private NetworkRequest getSessionNetworkRequest(int clientId, int sessionId,
- PeerHandle peerHandle, byte[] pmk, String passphrase, boolean doPublish)
+ PeerHandle peerHandle, byte[] pmk, String passphrase, boolean doPublish, int requestId)
throws Exception {
- final WifiAwareManager mgr = new WifiAwareManager(mMockContext, mMockAwareService);
+ final IWifiAwareManager mockAwareService = mock(IWifiAwareManager.class);
+ final WifiAwareManager mgr = new WifiAwareManager(mMockContext, mockAwareService);
final ConfigRequest configRequest = new ConfigRequest.Builder().build();
final PublishConfig publishConfig = new PublishConfig.Builder().build();
final SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().build();
@@ -910,30 +1011,33 @@ public class WifiAwareDataPathStateManagerTest {
DiscoverySessionCallback mockSessionCallback = mock(
DiscoverySessionCallback.class);
+ InOrder inOrderS = inOrder(mockAwareService, mockCallback, mockSessionCallback);
+
mgr.attach(mMockLooperHandler, configRequest, mockCallback, null);
- verify(mMockAwareService).connect(any(), any(),
+ inOrderS.verify(mockAwareService).connect(any(), any(),
clientProxyCallback.capture(), eq(configRequest), eq(false));
- clientProxyCallback.getValue().onConnectSuccess(clientId);
+ IWifiAwareEventCallback iwaec = clientProxyCallback.getValue();
+ iwaec.onConnectSuccess(clientId);
mMockLooper.dispatchAll();
- verify(mockCallback).onAttached(sessionCaptor.capture());
+ inOrderS.verify(mockCallback).onAttached(sessionCaptor.capture());
if (doPublish) {
sessionCaptor.getValue().publish(publishConfig, mockSessionCallback,
mMockLooperHandler);
- verify(mMockAwareService).publish(eq(clientId), eq(publishConfig),
+ inOrderS.verify(mockAwareService).publish(eq(clientId), eq(publishConfig),
sessionProxyCallback.capture());
} else {
sessionCaptor.getValue().subscribe(subscribeConfig, mockSessionCallback,
mMockLooperHandler);
- verify(mMockAwareService).subscribe(eq(clientId), eq(subscribeConfig),
+ inOrderS.verify(mockAwareService).subscribe(eq(clientId), eq(subscribeConfig),
sessionProxyCallback.capture());
}
sessionProxyCallback.getValue().onSessionStarted(sessionId);
mMockLooper.dispatchAll();
if (doPublish) {
- verify(mockSessionCallback).onPublishStarted(
+ inOrderS.verify(mockSessionCallback).onPublishStarted(
(PublishDiscoverySession) discoverySession.capture());
} else {
- verify(mockSessionCallback).onSubscribeStarted(
+ inOrderS.verify(mockSessionCallback).onSubscribeStarted(
(SubscribeDiscoverySession) discoverySession.capture());
}
@@ -957,13 +1061,14 @@ public class WifiAwareDataPathStateManagerTest {
nc.setLinkDownstreamBandwidthKbps(1);
nc.setSignalStrength(1);
- return new NetworkRequest(nc, 0, 0, NetworkRequest.Type.NONE);
+ return new NetworkRequest(nc, 0, requestId, NetworkRequest.Type.NONE);
}
private NetworkRequest getDirectNetworkRequest(int clientId, int role, byte[] peer,
byte[] pmk, String passphrase) throws Exception {
+ final IWifiAwareManager mockAwareService = mock(IWifiAwareManager.class);
final ConfigRequest configRequest = new ConfigRequest.Builder().build();
- final WifiAwareManager mgr = new WifiAwareManager(mMockContext, mMockAwareService);
+ final WifiAwareManager mgr = new WifiAwareManager(mMockContext, mockAwareService);
ArgumentCaptor<WifiAwareSession> sessionCaptor = ArgumentCaptor.forClass(
WifiAwareSession.class);
@@ -973,7 +1078,7 @@ public class WifiAwareDataPathStateManagerTest {
AttachCallback mockCallback = mock(AttachCallback.class);
mgr.attach(mMockLooperHandler, configRequest, mockCallback, null);
- verify(mMockAwareService).connect(any(), any(),
+ verify(mockAwareService).connect(any(), any(),
clientProxyCallback.capture(), eq(configRequest), eq(false));
clientProxyCallback.getValue().onConnectSuccess(clientId);
mMockLooper.dispatchAll();
@@ -1000,9 +1105,9 @@ public class WifiAwareDataPathStateManagerTest {
return new NetworkRequest(nc, 0, 0, NetworkRequest.Type.REQUEST);
}
- private DataPathEndPointInfo initDataPathEndPoint(int clientId, byte pubSubId,
- int requestorId, byte[] peerDiscoveryMac, InOrder inOrder, InOrder inOrderM,
- boolean doPublish)
+ private DataPathEndPointInfo initDataPathEndPoint(boolean isFirstIteration, int clientId,
+ byte pubSubId, int requestorId, byte[] peerDiscoveryMac, InOrder inOrder,
+ InOrder inOrderM, boolean doPublish)
throws Exception {
final int pid = 2000;
final String callingPackage = "com.android.somePackage";
@@ -1020,41 +1125,45 @@ public class WifiAwareDataPathStateManagerTest {
ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class);
ArgumentCaptor<String> strCaptor = ArgumentCaptor.forClass(String.class);
- // (0) start/registrations
- inOrder.verify(mMockCm).registerNetworkFactory(messengerCaptor.capture(),
- strCaptor.capture());
- collector.checkThat("factory name", "WIFI_AWARE_FACTORY", equalTo(strCaptor.getValue()));
+ if (isFirstIteration) {
+ // (0) start/registrations
+ inOrder.verify(mMockCm).registerNetworkFactory(messengerCaptor.capture(),
+ strCaptor.capture());
+ collector.checkThat("factory name", "WIFI_AWARE_FACTORY",
+ equalTo(strCaptor.getValue()));
- // (1) get capabilities
- mDut.queryCapabilities();
- mMockLooper.dispatchAll();
- inOrder.verify(mMockNative).getCapabilities(transactionId.capture());
- mDut.onCapabilitiesUpdateResponse(transactionId.getValue(), capabilities);
- mMockLooper.dispatchAll();
+ // (1) get capabilities
+ mDut.queryCapabilities();
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).getCapabilities(transactionId.capture());
+ mDut.onCapabilitiesUpdateResponse(transactionId.getValue(), capabilities);
+ mMockLooper.dispatchAll();
- // (2) enable usage
- mDut.enableUsage();
- mMockLooper.dispatchAll();
- inOrderM.verify(mAwareMetricsMock).recordEnableUsage();
+ // (2) enable usage
+ mDut.enableUsage();
+ mMockLooper.dispatchAll();
+ inOrderM.verify(mAwareMetricsMock).recordEnableUsage();
- // (3) create client & session & rx message
- mDut.connect(clientId, Process.myUid(), pid, callingPackage, mMockCallback, configRequest,
- false);
- mMockLooper.dispatchAll();
- inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- eq(configRequest), eq(false), eq(true), eq(true), eq(false));
- mDut.onConfigSuccessResponse(transactionId.getValue());
- mMockLooper.dispatchAll();
- inOrder.verify(mMockCallback).onConnectSuccess(clientId);
- inOrderM.verify(mAwareMetricsMock).recordAttachSession(eq(Process.myUid()), eq(false),
- any());
-
- inOrder.verify(mMockNative).createAwareNetworkInterface(transactionId.capture(),
- strCaptor.capture());
- collector.checkThat("interface created -- 0", sAwareInterfacePrefix + 0,
- equalTo(strCaptor.getValue()));
- mDut.onCreateDataPathInterfaceResponse(transactionId.getValue(), true, 0);
- mMockLooper.dispatchAll();
+ // (3) create client & session & rx message
+ mDut.connect(clientId, Process.myUid(), pid, callingPackage, mMockCallback,
+ configRequest,
+ false);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
+ mDut.onConfigSuccessResponse(transactionId.getValue());
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockCallback).onConnectSuccess(clientId);
+ inOrderM.verify(mAwareMetricsMock).recordAttachSession(eq(Process.myUid()), eq(false),
+ any());
+
+ inOrder.verify(mMockNative).createAwareNetworkInterface(transactionId.capture(),
+ strCaptor.capture());
+ collector.checkThat("interface created -- 0", sAwareInterfacePrefix + 0,
+ equalTo(strCaptor.getValue()));
+ mDut.onCreateDataPathInterfaceResponse(transactionId.getValue(), true, 0);
+ mMockLooper.dispatchAll();
+ }
if (doPublish) {
mDut.publish(clientId, publishConfig, mMockSessionCallback);
@@ -1084,7 +1193,7 @@ public class WifiAwareDataPathStateManagerTest {
eq(someMsg.getBytes()));
return new DataPathEndPointInfo(sessionId.getValue(), peerIdCaptor.getValue(),
- messengerCaptor.getValue());
+ isFirstIteration ? messengerCaptor.getValue() : null);
}
private static class DataPathEndPointInfo {