am 4c01e968: Merge "LocalSocketTest.testAccessors: fix the *SendBufferSize* test"
* commit '4c01e96840853caca9abfb375a828b27f89022fb':
LocalSocketTest.testAccessors: fix the *SendBufferSize* test
diff --git a/tests/cts/net/Android.mk b/tests/cts/net/Android.mk
index 82abd62..da19a4d 100644
--- a/tests/cts/net/Android.mk
+++ b/tests/cts/net/Android.mk
@@ -21,7 +21,7 @@
# and when built explicitly put it in the data partition
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_JAVA_LIBRARIES := android.test.runner voip-common
+LOCAL_JAVA_LIBRARIES := voip-common conscrypt
LOCAL_JNI_SHARED_LIBRARIES := libnativedns_jni
@@ -33,7 +33,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := ctstestserver ctsdeviceutil ctstestrunner \
core-tests-support
-# uncomment when dalvik.annotation.Test* are removed or part of SDK
+# uncomment when b/13249961 is fixed
#LOCAL_SDK_VERSION := current
include $(BUILD_CTS_PACKAGE)
diff --git a/tests/cts/net/AndroidManifest.xml b/tests/cts/net/AndroidManifest.xml
index ade6728..652262d 100644
--- a/tests/cts/net/AndroidManifest.xml
+++ b/tests/cts/net/AndroidManifest.xml
@@ -32,9 +32,12 @@
<uses-library android:name="android.test.runner" />
</application>
- <instrumentation android:name="android.test.InstrumentationCtsTestRunner"
+ <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
android:targetPackage="com.android.cts.net"
- android:label="CTS tests of android.net"/>
+ android:label="CTS tests of android.net">
+ <meta-data android:name="listener"
+ android:value="com.android.cts.runner.CtsTestRunListener" />
+ </instrumentation>
</manifest>
diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
index adb2b3a..5656119 100644
--- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
+++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
@@ -272,9 +272,13 @@
return;
}
- boolean isWifiConnected = mWifiManager.isWifiEnabled()
- && mWifiManager.getConnectionInfo().getSSID() != null;
+ boolean isWifiEnabled = mWifiManager.isWifiEnabled();
+ boolean isWifiConnected = false;
+ NetworkInfo nwInfo = mCm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ if (nwInfo != null) {
+ isWifiConnected = nwInfo.isConnected();
+ }
try {
// Make sure WiFi is connected to an access point.
if (!isWifiConnected) {
@@ -308,7 +312,7 @@
// TODO wait for HIPRI to go
// TODO check dns selection
// TODO check routes
- if (!isWifiConnected) {
+ if (!isWifiEnabled) {
mWifiManager.setWifiEnabled(false);
}
}
diff --git a/tests/cts/net/src/android/net/cts/MultinetworkTest.java b/tests/cts/net/src/android/net/cts/MultinetworkTest.java
new file mode 100644
index 0000000..256c030
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/MultinetworkTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.cts;
+
+import android.system.ErrnoException;
+import android.system.Os;
+import android.system.OsConstants;
+import android.system.StructStat;
+import android.test.AndroidTestCase;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.IOException;
+
+/**
+ * Tests for multinetwork functionality.
+ */
+public class MultinetworkTest extends AndroidTestCase {
+
+ // Global sysctls. Must be present and set to 1.
+ private static final String[] GLOBAL_SYSCTLS = {
+ "/proc/sys/net/ipv4/fwmark_reflect",
+ "/proc/sys/net/ipv6/fwmark_reflect",
+ "/proc/sys/net/ipv4/tcp_fwmark_accept",
+ };
+
+ // Per-interface IPv6 autoconf sysctls.
+ private static final String IPV6_SYSCTL_DIR = "/proc/sys/net/ipv6/conf";
+ private static final String AUTOCONF_SYSCTL = "accept_ra_rt_table";
+
+ // Expected mode, UID, and GID of sysctl files.
+ private static final int SYSCTL_MODE = 0100644;
+ private static final int SYSCTL_UID = 0;
+ private static final int SYSCTL_GID = 0;
+
+ private void checkSysctlPermissions(String fileName) throws ErrnoException {
+ StructStat stat = Os.stat(fileName);
+ assertEquals("mode of " + fileName + ":", SYSCTL_MODE, stat.st_mode);
+ assertEquals("UID of " + fileName + ":", SYSCTL_UID, stat.st_uid);
+ assertEquals("GID of " + fileName + ":", SYSCTL_GID, stat.st_gid);
+ }
+
+ private void assertLess(String what, int a, int b) {
+ assertTrue(what + " expected < " + b + " but was: " + a, a < b);
+ }
+
+ private String readFile(String fileName) throws ErrnoException, IOException {
+ byte[] buf = new byte[1024];
+ FileDescriptor fd = Os.open(fileName, 0, OsConstants.O_RDONLY);
+ int bytesRead = Os.read(fd, buf, 0, buf.length);
+ assertLess("length of " + fileName + ":", bytesRead, buf.length);
+ return new String(buf);
+ }
+
+ /**
+ * Checks that the sysctls for multinetwork kernel features are present and
+ * enabled. The necessary kernel commits are:
+ *
+ * Mainline Linux:
+ * e110861 net: add a sysctl to reflect the fwmark on replies
+ * 1b3c61d net: Use fwmark reflection in PMTU discovery.
+ * 84f39b0 net: support marking accepting TCP sockets
+ *
+ * Common Android tree (e.g., 3.10):
+ * a03f539 net: ipv6: autoconf routes into per-device tables
+ */
+ public void testProcFiles() throws ErrnoException, IOException, NumberFormatException {
+ for (String sysctl : GLOBAL_SYSCTLS) {
+ checkSysctlPermissions(sysctl);
+ int value = Integer.parseInt(readFile(sysctl).trim());
+ assertEquals("value of " + sysctl + ":", 1, value);
+ }
+
+ File[] interfaceDirs = new File(IPV6_SYSCTL_DIR).listFiles();
+ for (File interfaceDir : interfaceDirs) {
+ if (interfaceDir.getName().equals("all") || interfaceDir.getName().equals("lo")) {
+ continue;
+ }
+ String sysctl = new File(interfaceDir, AUTOCONF_SYSCTL).getAbsolutePath();
+ checkSysctlPermissions(sysctl);
+ int value = Integer.parseInt(readFile(sysctl).trim());
+ assertLess("value of " + sysctl + ":", value, 0);
+ }
+ }
+}
diff --git a/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java b/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
index cb8aeaf..6175923 100644
--- a/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
+++ b/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
@@ -26,8 +26,6 @@
import android.net.SSLCertificateSocketFactory;
import android.test.AndroidTestCase;
-import dalvik.annotation.BrokenTest;
-
import libcore.javax.net.ssl.SSLDefaultConfigurationAsserts;
public class SSLCertificateSocketFactoryTest extends AndroidTestCase {
diff --git a/tests/cts/net/src/android/net/cts/VpnServiceTest.java b/tests/cts/net/src/android/net/cts/VpnServiceTest.java
index 9e35375..8bdd7b0 100644
--- a/tests/cts/net/src/android/net/cts/VpnServiceTest.java
+++ b/tests/cts/net/src/android/net/cts/VpnServiceTest.java
@@ -42,7 +42,7 @@
// Should be always resolved by only one activity.
int count = mContext.getPackageManager().queryIntentActivities(intent, 0).size();
- assertEquals(count, 1);
+ assertEquals(1, count);
}
public void testEstablish() throws Exception {
diff --git a/tests/cts/net/src/android/net/http/cts/X509TrustManagerExtensionsTest.java b/tests/cts/net/src/android/net/http/cts/X509TrustManagerExtensionsTest.java
new file mode 100644
index 0000000..9c0d774
--- /dev/null
+++ b/tests/cts/net/src/android/net/http/cts/X509TrustManagerExtensionsTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.http.cts;
+
+import android.net.http.X509TrustManagerExtensions;
+import android.util.Base64;
+
+import java.io.File;
+import java.io.ByteArrayInputStream;
+
+import java.security.KeyStore;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+
+import junit.framework.TestCase;
+
+import com.android.org.conscrypt.TrustedCertificateStore;
+import com.android.org.conscrypt.TrustManagerImpl;
+
+public class X509TrustManagerExtensionsTest extends TestCase {
+
+ public void testIsUserAddedCert() throws Exception {
+ final String testCert =
+ "MIICfjCCAeegAwIBAgIJAMefIzKHY5H4MA0GCSqGSIb3DQEBBQUAMFgxCzAJBgNV" +
+ "BAYTAlVTMQswCQYDVQQIDAJDQTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzEPMA0G" +
+ "A1UECgwGR2V3Z3VsMRMwEQYDVQQDDApnZXdndWwuY29tMB4XDTEzMTEwNTAwNDE0" +
+ "MFoXDTEzMTIwNTAwNDE0MFowWDELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRYw" +
+ "FAYDVQQHDA1Nb3VudGFpbiBWaWV3MQ8wDQYDVQQKDAZHZXdndWwxEzARBgNVBAMM" +
+ "Cmdld2d1bC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKpc/I0Ss4sm" +
+ "yV2iX5xRMM7+XXAhiWrceGair4MpvDrGIa1kFj2phtx4IqTfDnNU7AhRJYkDYmJQ" +
+ "fUJ8i6F+I08uNiGVO4DtPJbZcBXg9ME9EMaJCslm995ueeNWSw1Ky8zM0tt4p+94" +
+ "BcXJ7PC3N2WgkvtE8xwNbaeUfhGPzJKXAgMBAAGjUDBOMB0GA1UdDgQWBBQQ/iW7" +
+ "JCkSI2sbn4nTBiZ9PSiO8zAfBgNVHSMEGDAWgBQQ/iW7JCkSI2sbn4nTBiZ9PSiO" +
+ "8zAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBABQBrUOWTCSIl3vkRR3w" +
+ "3bPzh3BpqDmxH9xe4rZr+MVKKjpGjY1z2m2EEtyNz3tbgVQym5+si00DUHFL0IP1" +
+ "SuRULmPyEpTBVbV+PA5Kc967ZcDgYt4JtdMcCeKbIFaU6r8oEYEL2PTlNZmgbunM" +
+ "pXktkhVvNxZeSa8yM9bPhXkN";
+
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ X509Certificate cert = (X509Certificate)cf.generateCertificate(
+ new ByteArrayInputStream(Base64.decode(testCert, Base64.DEFAULT)));
+
+ // Test without adding cert to keystore.
+ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ X509TrustManagerExtensions tmeNegative =
+ new X509TrustManagerExtensions(new TrustManagerImpl(keyStore));
+ assertEquals(false, tmeNegative.isUserAddedCertificate(cert));
+
+ // Test with cert added to keystore.
+ final File DIR_TEMP = new File(System.getProperty("java.io.tmpdir"));
+ final File DIR_TEST = new File(DIR_TEMP, "test");
+ final File system = new File(DIR_TEST, "system-test");
+ final File added = new File(DIR_TEST, "added-test");
+ final File deleted = new File(DIR_TEST, "deleted-test");
+
+ TrustedCertificateStore tcs = new TrustedCertificateStore(system, added, deleted);
+ added.mkdirs();
+ tcs.installCertificate(cert);
+ X509TrustManagerExtensions tmePositive =
+ new X509TrustManagerExtensions(new TrustManagerImpl(keyStore, null, tcs));
+ assertEquals(true, tmePositive.isUserAddedCertificate(cert));
+ }
+}
diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java
index 58298d5..6e395aa 100644
--- a/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java
+++ b/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java
@@ -17,6 +17,7 @@
package android.net.wifi.cts;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiEnterpriseConfig.Eap;
@@ -34,6 +35,11 @@
private static final String ANON_IDENTITY = "anonidentity";
private static final int ENABLE_DELAY = 10000;
+ private boolean hasWifi() {
+ return getContext().getPackageManager().hasSystemFeature(
+ PackageManager.FEATURE_WIFI);
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -42,10 +48,16 @@
assertNotNull(mWifiManager);
mWifiManager.setWifiEnabled(true);
Thread.sleep(ENABLE_DELAY);
- assertTrue(mWifiManager.isWifiEnabled());
+ if (hasWifi()) {
+ assertTrue(mWifiManager.isWifiEnabled());
+ }
}
public void testSettersAndGetters() {
+ if (!hasWifi()) {
+ return;
+ }
+
WifiEnterpriseConfig config = new WifiEnterpriseConfig();
assertTrue(config.getEapMethod() == Eap.NONE);
config.setEapMethod(Eap.PEAP);
@@ -78,6 +90,10 @@
}
public void testAddEapNetwork() {
+ if (!hasWifi()) {
+ return;
+ }
+
WifiConfiguration config = new WifiConfiguration();
WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
enterpriseConfig.setEapMethod(Eap.PWD);