diff options
author | Etan Cohen <etancohen@google.com> | 2017-03-30 08:58:19 -0700 |
---|---|---|
committer | Etan Cohen <etancohen@google.com> | 2017-04-06 08:06:35 -0700 |
commit | fed87ea776ae79754b001a0a8cf5cd7d6a312139 (patch) | |
tree | deb50063d59090c47fca48bbfec26aee45ac378a /tests | |
parent | b81eb91076f713e800415d26d57a8109d4f35037 (diff) |
[AWARE] Implement custom network specifier
Implement support for Wi-Fi Aware custom network specifier.
Simplifies code (no string parsing) and provides infrastructure
for additional controls on network matching (to be added later).
Bug: 36275276
Bug: 36053921
Test: unit tests and integration (sl4a) tests.
Change-Id: If526f80f3d0a76002b0b5f8a013f8d188b14e456
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java | 31 |
1 files changed, 19 insertions, 12 deletions
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 912dce2f3..e7a383c5e 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java @@ -37,7 +37,7 @@ import android.net.ConnectivityManager; import android.net.NetworkCapabilities; import android.net.NetworkFactory; import android.net.NetworkRequest; -import android.net.StringNetworkSpecifier; +import android.net.NetworkSpecifier; import android.net.wifi.aware.AttachCallback; import android.net.wifi.aware.ConfigRequest; import android.net.wifi.aware.DiscoverySession; @@ -51,6 +51,7 @@ import android.net.wifi.aware.PublishDiscoverySession; import android.net.wifi.aware.SubscribeConfig; import android.net.wifi.aware.SubscribeDiscoverySession; import android.net.wifi.aware.WifiAwareManager; +import android.net.wifi.aware.WifiAwareNetworkSpecifier; import android.net.wifi.aware.WifiAwareSession; import android.os.Handler; import android.os.INetworkManagementService; @@ -64,7 +65,6 @@ import com.android.internal.util.AsyncChannel; import libcore.util.HexEncoding; -import org.json.JSONObject; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -418,12 +418,19 @@ public class WifiAwareDataPathStateManagerTest { doPublish); // corrupt the network specifier: reverse the role (so it's mis-matched) - JSONObject jsonObject = new JSONObject( - ((StringNetworkSpecifier) nr.networkCapabilities.getNetworkSpecifier()).specifier); - jsonObject.put(WifiAwareManager.NETWORK_SPECIFIER_KEY_ROLE, - 1 - jsonObject.getInt(WifiAwareManager.NETWORK_SPECIFIER_KEY_ROLE)); - nr.networkCapabilities.setNetworkSpecifier( - new StringNetworkSpecifier(jsonObject.toString())); + WifiAwareNetworkSpecifier ns = + (WifiAwareNetworkSpecifier) nr.networkCapabilities.getNetworkSpecifier(); + ns = new WifiAwareNetworkSpecifier( + ns.type, + 1 - ns.role, // corruption hack + ns.clientId, + ns.sessionId, + ns.peerId, + ns.peerMac, + ns.pmk, + ns.passphrase + ); + nr.networkCapabilities.setNetworkSpecifier(ns); Message reqNetworkMsg = Message.obtain(); reqNetworkMsg.what = NetworkFactory.CMD_REQUEST_NETWORK; @@ -682,7 +689,7 @@ public class WifiAwareDataPathStateManagerTest { (SubscribeDiscoverySession) discoverySession.capture()); } - String ns; + NetworkSpecifier ns; if (pmk == null) { ns = discoverySession.getValue().createNetworkSpecifierOpen(peerHandle); } else { @@ -694,7 +701,7 @@ public class WifiAwareDataPathStateManagerTest { nc.addTransportType(NetworkCapabilities.TRANSPORT_WIFI_AWARE); nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN).addCapability( NetworkCapabilities.NET_CAPABILITY_NOT_METERED); - nc.setNetworkSpecifier(new StringNetworkSpecifier(ns)); + nc.setNetworkSpecifier(ns); nc.setLinkUpstreamBandwidthKbps(1); nc.setLinkDownstreamBandwidthKbps(1); nc.setSignalStrength(1); @@ -721,7 +728,7 @@ public class WifiAwareDataPathStateManagerTest { mMockLooper.dispatchAll(); verify(mockCallback).onAttached(sessionCaptor.capture()); - String ns; + NetworkSpecifier ns; if (pmk == null) { ns = sessionCaptor.getValue().createNetworkSpecifierOpen(role, peer); } else { @@ -732,7 +739,7 @@ public class WifiAwareDataPathStateManagerTest { nc.addTransportType(NetworkCapabilities.TRANSPORT_WIFI_AWARE); nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN).addCapability( NetworkCapabilities.NET_CAPABILITY_NOT_METERED); - nc.setNetworkSpecifier(new StringNetworkSpecifier(ns)); + nc.setNetworkSpecifier(ns); nc.setLinkUpstreamBandwidthKbps(1); nc.setLinkDownstreamBandwidthKbps(1); nc.setSignalStrength(1); |