summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEtan Cohen <etancohen@google.com>2018-07-20 16:53:00 -0700
committerEtan Cohen <etancohen@google.com>2018-09-26 17:49:39 +0000
commit1cb8cdaf63f970533ef80b48ff713ed7c5b120f0 (patch)
tree7af64c3ff23239d9bf861899f37f150fc163afd9 /tests
parentc442cac03988b303a1151a774cc291a89ed1dad1 (diff)
[RTT] Add NPE checks for invalid MAC addresses from Aware
RTT requests for Aware peers may use PeerHandles. The RTT service queries the Aware service for their corresponding MAC addresses. In some corner cases, e.g. the Aware peer just disappeared, a null MAC address may be returned. This was not handled, resulting in an NPE. Bug: 111646773 Test: new unit test added, passes Change-Id: I7d7c37322848fe7e7dd4f9f412f1e1339321e9a8
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java15
1 files changed, 10 insertions, 5 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java
index d1c1b028b..e1f35239f 100644
--- a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java
@@ -305,13 +305,16 @@ public class RttServiceImplTest {
RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0xA);
PeerHandle peerHandle1 = new PeerHandle(1022);
PeerHandle peerHandle2 = new PeerHandle(1023);
+ PeerHandle peerHandle3 = new PeerHandle(1024);
request.mRttPeers.add(ResponderConfig.fromWifiAwarePeerHandleWithDefaults(peerHandle1));
request.mRttPeers.add(ResponderConfig.fromWifiAwarePeerHandleWithDefaults(peerHandle2));
+ request.mRttPeers.add(ResponderConfig.fromWifiAwarePeerHandleWithDefaults(peerHandle3));
Map<Integer, MacAddress> peerHandleToMacMap = new HashMap<>();
MacAddress macAwarePeer1 = MacAddress.fromString("AA:BB:CC:DD:EE:FF");
MacAddress macAwarePeer2 = MacAddress.fromString("BB:BB:BB:EE:EE:EE");
peerHandleToMacMap.put(peerHandle1.peerId, macAwarePeer1);
peerHandleToMacMap.put(peerHandle2.peerId, macAwarePeer2);
+ peerHandleToMacMap.put(peerHandle3.peerId, null); // bad answer from Aware (expired?)
AwareTranslatePeerHandlesToMac answer = new AwareTranslatePeerHandlesToMac(mDefaultUid,
peerHandleToMacMap);
@@ -327,7 +330,8 @@ public class RttServiceImplTest {
RangingRequest finalRequest = mRequestCaptor.getValue();
assertNotEquals("Request to native is not null", null, finalRequest);
- assertEquals("Size of request", request.mRttPeers.size(), finalRequest.mRttPeers.size());
+ assertEquals("Size of request", request.mRttPeers.size() - 1,
+ finalRequest.mRttPeers.size());
assertEquals("Aware peer 1 MAC", macAwarePeer1,
finalRequest.mRttPeers.get(finalRequest.mRttPeers.size() - 2).macAddress);
assertEquals("Aware peer 2 MAC", macAwarePeer2,
@@ -1452,12 +1456,13 @@ public class RttServiceImplTest {
Map<Integer, byte[]> result = new HashMap<>();
for (Integer peerId: peerIds) {
- byte[] mac = mPeerIdToMacMap.get(peerId).toByteArray();
- if (mac == null) {
- continue;
+ byte[] macBytes = null;
+ MacAddress macAddr = mPeerIdToMacMap.get(peerId);
+ if (macAddr != null) {
+ macBytes = macAddr.toByteArray();
}
- result.put(peerId, mac);
+ result.put(peerId, macBytes);
}
try {