diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2017-04-12 22:43:09 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-04-12 22:43:09 +0000 |
commit | adc933f52565630a0dbab11528898e19ae311efb (patch) | |
tree | 0aea3998dc79073ce41b9493a85a8710d2b906a7 | |
parent | 87bbb7718a8d6a2d5cd419064825528ad2e861f6 (diff) | |
parent | 8c8188a1e8b4b784d47500272135305735d1c54c (diff) |
Merge "Make the NetworkSpecifier a class instead of a string."
am: 8c8188a1e8
Change-Id: I8103200228d7e5c3b191bc87226e6619e6a91053
-rw-r--r-- | service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java | 36 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java | 11 |
2 files changed, 35 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 5842a3bf8..b0a3f027a 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java @@ -22,12 +22,15 @@ import android.net.ConnectivityManager; import android.net.IpPrefix; import android.net.LinkAddress; import android.net.LinkProperties; +import android.net.MatchAllNetworkSpecifier; import android.net.NetworkAgent; import android.net.NetworkCapabilities; import android.net.NetworkFactory; import android.net.NetworkInfo; import android.net.NetworkRequest; +import android.net.NetworkSpecifier; import android.net.RouteInfo; +import android.net.StringNetworkSpecifier; import android.net.wifi.aware.WifiAwareManager; import android.os.IBinder; import android.os.INetworkManagementService; @@ -113,8 +116,7 @@ public class WifiAwareDataPathStateManager { .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) .addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED); - mNetworkCapabilitiesFilter - .setNetworkSpecifier(NetworkCapabilities.MATCH_ALL_REQUESTS_NETWORK_SPECIFIER); + mNetworkCapabilitiesFilter.setNetworkSpecifier(new MatchAllNetworkSpecifier()); mNetworkCapabilitiesFilter.setLinkUpstreamBandwidthKbps(NETWORK_FACTORY_BANDWIDTH_AVAIL); mNetworkCapabilitiesFilter.setLinkDownstreamBandwidthKbps(NETWORK_FACTORY_BANDWIDTH_AVAIL); mNetworkCapabilitiesFilter.setSignalStrength(NETWORK_FACTORY_SIGNAL_STRENGTH_AVAIL); @@ -568,12 +570,17 @@ public class WifiAwareDataPathStateManager { return false; } - String networkSpecifier = request.networkCapabilities.getNetworkSpecifier(); - if (TextUtils.isEmpty(networkSpecifier)) { + NetworkSpecifier networkSpecifierObj = + request.networkCapabilities.getNetworkSpecifier(); + if (networkSpecifierObj == null + || !(networkSpecifierObj instanceof StringNetworkSpecifier) + || TextUtils.isEmpty( + ((StringNetworkSpecifier) networkSpecifierObj).specifier)) { Log.w(TAG, "WifiAwareNetworkFactory.acceptRequest: request=" + request - + " - empty (or null) NetworkSpecifier"); + + " - null, empty, or not a StringNetworkSpecifier"); return false; } + String networkSpecifier = ((StringNetworkSpecifier) networkSpecifierObj).specifier; // look up specifier - are we being called again? AwareNetworkRequestInformation nnri = mNetworkRequestsCache.get(networkSpecifier); @@ -609,7 +616,13 @@ public class WifiAwareDataPathStateManager { + networkRequest + ", score=" + score); } - String networkSpecifier = networkRequest.networkCapabilities.getNetworkSpecifier(); + NetworkSpecifier networkSpecifierObj = + networkRequest.networkCapabilities.getNetworkSpecifier(); + String networkSpecifier = ""; + if (networkSpecifierObj != null + && networkSpecifierObj instanceof StringNetworkSpecifier) { + networkSpecifier = ((StringNetworkSpecifier) networkSpecifierObj).specifier; + } AwareNetworkRequestInformation nnri = mNetworkRequestsCache.get(networkSpecifier); if (nnri == null) { Log.e(TAG, "WifiAwareNetworkFactory.needNetworkFor: networkRequest=" @@ -656,7 +669,14 @@ public class WifiAwareDataPathStateManager { + networkRequest); } - String networkSpecifier = networkRequest.networkCapabilities.getNetworkSpecifier(); + NetworkSpecifier networkSpecifierObj = + networkRequest.networkCapabilities.getNetworkSpecifier(); + String networkSpecifier = ""; + if (networkSpecifierObj != null + && networkSpecifierObj instanceof StringNetworkSpecifier) { + networkSpecifier = ((StringNetworkSpecifier) networkSpecifierObj).specifier; + } + AwareNetworkRequestInformation nnri = mNetworkRequestsCache.get(networkSpecifier); if (nnri == null) { Log.e(TAG, "WifiAwareNetworkFactory.releaseNetworkFor: networkRequest=" @@ -1034,7 +1054,7 @@ public class WifiAwareDataPathStateManager { networkInfo.setIsAvailable(true); networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null, null); - networkCapabilities.setNetworkSpecifier(networkSpecifier); + networkCapabilities.setNetworkSpecifier(new StringNetworkSpecifier(networkSpecifier)); linkProperties.setInterfaceName(nnri.interfaceName); linkProperties.addLinkAddress(new LinkAddress(linkLocal, 64)); 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 29d0d12a6..912dce2f3 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java @@ -37,6 +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.wifi.aware.AttachCallback; import android.net.wifi.aware.ConfigRequest; import android.net.wifi.aware.DiscoverySession; @@ -417,10 +418,12 @@ public class WifiAwareDataPathStateManagerTest { doPublish); // corrupt the network specifier: reverse the role (so it's mis-matched) - JSONObject jsonObject = new JSONObject(nr.networkCapabilities.getNetworkSpecifier()); + 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(jsonObject.toString()); + nr.networkCapabilities.setNetworkSpecifier( + new StringNetworkSpecifier(jsonObject.toString())); Message reqNetworkMsg = Message.obtain(); reqNetworkMsg.what = NetworkFactory.CMD_REQUEST_NETWORK; @@ -691,7 +694,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(ns); + nc.setNetworkSpecifier(new StringNetworkSpecifier(ns)); nc.setLinkUpstreamBandwidthKbps(1); nc.setLinkDownstreamBandwidthKbps(1); nc.setSignalStrength(1); @@ -729,7 +732,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(ns); + nc.setNetworkSpecifier(new StringNetworkSpecifier(ns)); nc.setLinkUpstreamBandwidthKbps(1); nc.setLinkDownstreamBandwidthKbps(1); nc.setSignalStrength(1); |