From d77061e8e5f6a0f8672571e5fc85ef1c974bfdcc Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Fri, 8 Feb 2019 09:21:44 -0800 Subject: [AWARE] Change parsing return type to a struct No functional change: just a semantic change of return type from a Pair (limited to 2) to a class/struct (unlimited). Preparation for addition of additional parsed variable. Bug: 117605977 Test: atest com.android.server.wifi Change-Id: I7675e20122e66e068ca2948df6fc2a7ec09114ce --- .../wifi/aware/WifiAwareDataPathStateManager.java | 28 +++++++++++++++------- .../aware/WifiAwareDataPathStateManagerTest.java | 7 +++--- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java index fe17f4b15..44328930e 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java @@ -382,10 +382,11 @@ public class WifiAwareDataPathStateManager { // potential transmission mechanism for port/transport-protocol information from // Responder (alternative to confirm message) - Pair peerServerInfo = NetworkInformationData.parseTlv(message); + NetworkInformationData.ParsedResults peerServerInfo = NetworkInformationData.parseTlv( + message); if (peerServerInfo != null) { - nnriE.getValue().peerPort = peerServerInfo.first; - nnriE.getValue().peerTransportProtocol = peerServerInfo.second; + nnriE.getValue().peerPort = peerServerInfo.port; + nnriE.getValue().peerTransportProtocol = peerServerInfo.transportProtocol; } return null; // ignore this for NDP set up flow: it is used to obtain app_info from Resp @@ -572,10 +573,11 @@ public class WifiAwareDataPathStateManager { // only relevant for the initiator if (nnri.networkSpecifier.role == WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR) { - Pair peerServerInfo = NetworkInformationData.parseTlv(message); + NetworkInformationData.ParsedResults peerServerInfo = + NetworkInformationData.parseTlv(message); if (peerServerInfo != null) { - nnri.peerPort = peerServerInfo.first; - nnri.peerTransportProtocol = peerServerInfo.second; + nnri.peerPort = peerServerInfo.port; + nnri.peerTransportProtocol = peerServerInfo.transportProtocol; } } @@ -1479,10 +1481,20 @@ public class WifiAwareDataPathStateManager { return tlvc.getArray(); } + static class ParsedResults { + ParsedResults(int port, int transportProtocol) { + this.port = port; + this.transportProtocol = transportProtocol; + } + + public int port = 0; + public int transportProtocol = -1; + } + /** * Parse the TLV and return . */ - public static Pair parseTlv(byte[] tlvs) { + public static ParsedResults parseTlv(byte[] tlvs) { int port = 0; int transportProtocol = -1; @@ -1517,7 +1529,7 @@ public class WifiAwareDataPathStateManager { if (port == 0 && transportProtocol == -1) { return null; } - return Pair.create(port, transportProtocol); + return new ParsedResults(port, transportProtocol); } private static Pair parseServiceInfoTlv(byte[] tlv) { 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 c92363389..6b51db5b7 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java @@ -74,7 +74,6 @@ 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; @@ -1082,10 +1081,10 @@ public class WifiAwareDataPathStateManagerTest { new byte[]{0x01, 0x0d, 0x00, 0x50, 0x6f, (byte) 0x9a, 0x02, 0x00, 0x02, 0x00, 0x58, 0x1b, 0x01, 0x01, 0x00, 0x06}; - Pair parsed = + WifiAwareDataPathStateManager.NetworkInformationData.ParsedResults parsed = WifiAwareDataPathStateManager.NetworkInformationData.parseTlv(testVector); - assertEquals(port, (int) parsed.first); - assertEquals(transportProtocol, (int) parsed.second); + assertEquals(port, (int) parsed.port); + assertEquals(transportProtocol, (int) parsed.transportProtocol); } /* -- cgit v1.2.3