Merge "CTS: verify ConnectivityManager.requestNetwork throws for restricted networks" into lmp-dev
diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
index eeae257..cfe756d 100644
--- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
+++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
@@ -34,6 +34,7 @@
import android.net.wifi.WifiManager;
import android.test.AndroidTestCase;
import android.util.Log;
+import android.os.SystemProperties;
import com.android.internal.telephony.PhoneConstants;
@@ -75,10 +76,14 @@
// Get com.android.internal.R.array.networkAttributes
int resId = getContext().getResources().getIdentifier("networkAttributes", "array", "android");
String[] naStrings = getContext().getResources().getStringArray(resId);
-
+ //TODO: What is the "correct" way to determine if this is a wifi only device?
+ boolean wifiOnly = SystemProperties.getBoolean("ro.radio.noril", false);
for (String naString : naStrings) {
try {
NetworkConfig n = new NetworkConfig(naString);
+ if (wifiOnly && ConnectivityManager.isNetworkTypeMobile(n.type)) {
+ continue;
+ }
mNetworks.put(n.type, n);
} catch (Exception e) {}
}
diff --git a/tests/cts/net/src/android/net/cts/DnsTest.java b/tests/cts/net/src/android/net/cts/DnsTest.java
index 879a962..0377d04 100644
--- a/tests/cts/net/src/android/net/cts/DnsTest.java
+++ b/tests/cts/net/src/android/net/cts/DnsTest.java
@@ -16,6 +16,10 @@
package android.net.cts;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.SystemClock;
import android.test.AndroidTestCase;
import android.util.Log;
@@ -34,6 +38,7 @@
private static final boolean DBG = false;
private static final String TAG = "DnsTest";
+ private static final String PROXY_NETWORK_TYPE = "PROXY";
/**
* @return true on success
@@ -71,6 +76,14 @@
// We should have at least one of the addresses to connect!
assertTrue(foundV4 || foundV6);
+ // Skip the rest of the test if the active network for watch is PROXY.
+ // TODO: Check NetworkInfo type in addition to type name once ag/601257 is merged.
+ if (getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)
+ && activeNetworkInfoIsProxy()) {
+ Log.i(TAG, "Skipping test because the active network type name is PROXY.");
+ return;
+ }
+
try {
addrs = InetAddress.getAllByName("ipv6.google.com");
} catch (UnknownHostException e) {}
@@ -241,4 +254,15 @@
Log.e(TAG, "bad URL in testDnsPerf: " + e.toString());
}
}
+
+ private boolean activeNetworkInfoIsProxy() {
+ ConnectivityManager cm = (ConnectivityManager)
+ getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo info = cm.getActiveNetworkInfo();
+ if (PROXY_NETWORK_TYPE.equals(info.getTypeName())) {
+ return true;
+ }
+
+ return false;
+ }
}
diff --git a/tests/cts/net/src/android/net/cts/LocalSocketTest.java b/tests/cts/net/src/android/net/cts/LocalSocketTest.java
index 0a4bc0d..70d69c8 100644
--- a/tests/cts/net/src/android/net/cts/LocalSocketTest.java
+++ b/tests/cts/net/src/android/net/cts/LocalSocketTest.java
@@ -112,6 +112,7 @@
}
public void testAccessors() throws IOException{
+ final int INITIAL_SEND_BUFFER_SIZE = 1998;
LocalSocket socket = new LocalSocket();
LocalSocketAddress addr = new LocalSocketAddress("secondary");
@@ -126,8 +127,14 @@
socket.setReceiveBufferSize(1999);
assertEquals(1999 << 1, socket.getReceiveBufferSize());
- socket.setSendBufferSize(1998);
- assertEquals(1998 << 1, socket.getSendBufferSize());
+ socket.setSendBufferSize(INITIAL_SEND_BUFFER_SIZE);
+ int sendBufferSize = socket.getSendBufferSize();
+ if ((INITIAL_SEND_BUFFER_SIZE << 1) < sendBufferSize) {
+ socket.setSendBufferSize(sendBufferSize / 2);
+ assertEquals(sendBufferSize, socket.getSendBufferSize());
+ } else {
+ assertEquals(INITIAL_SEND_BUFFER_SIZE << 1, sendBufferSize);
+ }
// Timeout is not support at present, so set is ignored
socket.setSoTimeout(1996);
diff --git a/tests/cts/net/src/android/net/ipv6/cts/PingTest.java b/tests/cts/net/src/android/net/ipv6/cts/PingTest.java
index 49fc59c..582b81a 100644
--- a/tests/cts/net/src/android/net/ipv6/cts/PingTest.java
+++ b/tests/cts/net/src/android/net/ipv6/cts/PingTest.java
@@ -53,6 +53,9 @@
/** Maximum size of the packets we're using to test. */
private static final int MAX_SIZE = 4096;
+ /** Size of the ICMPv6 header. */
+ private static final int ICMP_HEADER_SIZE = 8;
+
/** Number of packets to test. */
private static final int NUM_PACKETS = 10;
@@ -65,7 +68,7 @@
* Returns a byte array containing an ICMPv6 echo request with the specified payload length.
*/
private byte[] pingPacket(int payloadLength) {
- byte[] packet = new byte[payloadLength + 8];
+ byte[] packet = new byte[payloadLength + ICMP_HEADER_SIZE];
new Random().nextBytes(packet);
System.arraycopy(PING_HEADER, 0, packet, 0, PING_HEADER.length);
return packet;
@@ -154,7 +157,7 @@
assertEquals("localhost/::1", ipv6Loopback.toString());
for (int i = 0; i < NUM_PACKETS; i++) {
- byte[] packet = pingPacket((int) (Math.random() * MAX_SIZE));
+ byte[] packet = pingPacket((int) (Math.random() * (MAX_SIZE - ICMP_HEADER_SIZE)));
FileDescriptor s = createPingSocket();
// Use both recvfrom and read().
sendPing(s, ipv6Loopback, packet);
diff --git a/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java
index d434728..e132cce 100644
--- a/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java
+++ b/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java
@@ -372,8 +372,6 @@
assertTrue(lastEvent != null);
assertTrue(lastEvent.mInfo.getServiceName().equals(registeredName));
- assertTrue(eventCacheSize() == 2);
-
// Register service again to see if we discover it
checkForAdditionalEvents();
clearEventCache();
@@ -405,7 +403,6 @@
lastEvent.mInfo.getServiceName());
assertTrue(lastEvent.mInfo.getServiceName().equals(registeredName));
- assertTrue(checkCacheSize(2));
checkForAdditionalEvents();
clearEventCache();