am 4ae1e382: Merge "Tracking merge of dalvik-dev to gingerbread" into gingerbread
Merge commit '4ae1e382f4b6c5bb9e757f35f82ad48dc02c32af' into gingerbread-plus-aosp * commit '4ae1e382f4b6c5bb9e757f35f82ad48dc02c32af': Tracking merge of dalvik-dev to gingerbread
This commit is contained in:
29
Android.mk
29
Android.mk
@@ -193,7 +193,7 @@ LOCAL_INTERMEDIATE_SOURCES := \
|
||||
$(framework_res_source_path)/com/android/internal/R.java
|
||||
|
||||
LOCAL_NO_STANDARD_LIBRARIES := true
|
||||
LOCAL_JAVA_LIBRARIES := core ext
|
||||
LOCAL_JAVA_LIBRARIES := bouncycastle core core-junit ext
|
||||
|
||||
LOCAL_MODULE := framework
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
@@ -301,34 +301,14 @@ fwbase_dirs_to_document += core/config/sdk
|
||||
# Intentionally not included from libcore:
|
||||
# icu openssl suncompat support
|
||||
libcore_to_document := \
|
||||
annotation/src/main/java/java \
|
||||
archive/src/main/java/java \
|
||||
auth/src/main/java/javax \
|
||||
awt-kernel/src/main/java/java \
|
||||
concurrent/src/main/java \
|
||||
crypto/src/main/java/javax \
|
||||
dalvik/src/main/java/dalvik \
|
||||
json/src/main/java \
|
||||
junit/src/main/java \
|
||||
logging/src/main/java/java \
|
||||
luni/src/main/java/java \
|
||||
luni-kernel/src/main/java/java \
|
||||
math/src/main/java/java \
|
||||
nio/src/main/java/java \
|
||||
nio_char/src/main/java/java \
|
||||
prefs/src/main/java/java \
|
||||
regex/src/main/java/java \
|
||||
security/src/main/java/java \
|
||||
security/src/main/java/javax \
|
||||
security-kernel/src/main/java/java \
|
||||
sql/src/main/java/java \
|
||||
sql/src/main/java/javax \
|
||||
text/src/main/java/java \
|
||||
x-net/src/main/java/javax \
|
||||
xml/src/main/java/javax \
|
||||
xml/src/main/java/org/xml/sax \
|
||||
luni/src/main/java/javax \
|
||||
luni/src/main/java/org/xml/sax \
|
||||
luni/src/main/java/org/w3c \
|
||||
xml/src/main/java/org/xmlpull/v1 \
|
||||
xml/src/main/java/org/w3c
|
||||
|
||||
non_base_dirs := \
|
||||
../../external/apache-http/src/org/apache/http
|
||||
@@ -361,6 +341,7 @@ framework_docs_LOCAL_INTERMEDIATE_SOURCES := \
|
||||
$(framework_res_source_path)/com/android/internal/R.java
|
||||
|
||||
framework_docs_LOCAL_JAVA_LIBRARIES := \
|
||||
bouncycastle \
|
||||
core \
|
||||
ext \
|
||||
framework \
|
||||
|
||||
15012
api/current.xml
15012
api/current.xml
File diff suppressed because it is too large
Load Diff
@@ -46,9 +46,9 @@ import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl;
|
||||
import org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl;
|
||||
import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache;
|
||||
import org.apache.harmony.xnet.provider.jsse.SSLContextImpl;
|
||||
import org.apache.harmony.xnet.provider.jsse.SSLParameters;
|
||||
|
||||
/**
|
||||
@@ -210,7 +210,7 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory {
|
||||
|
||||
private SSLSocketFactory makeSocketFactory(TrustManager[] trustManagers) {
|
||||
try {
|
||||
SSLContextImpl sslContext = new SSLContextImpl();
|
||||
OpenSSLContextImpl sslContext = new OpenSSLContextImpl();
|
||||
sslContext.engineInit(null, trustManagers, null, mSessionCache, null);
|
||||
return sslContext.engineGetSocketFactory();
|
||||
} catch (KeyManagementException e) {
|
||||
|
||||
@@ -19,8 +19,8 @@ package android.net.http;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import org.apache.harmony.xnet.provider.jsse.FileClientSessionCache;
|
||||
import org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl;
|
||||
import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache;
|
||||
import org.apache.harmony.xnet.provider.jsse.SSLContextImpl;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpHost;
|
||||
@@ -79,7 +79,7 @@ public class HttpsConnection extends Connection {
|
||||
cache = FileClientSessionCache.usingDirectory(sessionDir);
|
||||
}
|
||||
|
||||
SSLContextImpl sslContext = new SSLContextImpl();
|
||||
OpenSSLContextImpl sslContext = new OpenSSLContextImpl();
|
||||
|
||||
// here, trust managers is a single trust-all manager
|
||||
TrustManager[] trustManagers = new TrustManager[] {
|
||||
|
||||
@@ -66,10 +66,6 @@ public class ZygoteInit {
|
||||
/** when preloading, GC after allocating this many bytes */
|
||||
private static final int PRELOAD_GC_THRESHOLD = 50000;
|
||||
|
||||
/** throw on missing preload, only if this looks like a developer */
|
||||
private static final boolean THROW_ON_MISSING_PRELOAD =
|
||||
"1".equals(SystemProperties.get("persist.service.adb.enable"));
|
||||
|
||||
public static final String USAGE_STRING =
|
||||
" <\"true\"|\"false\" for startSystemServer>";
|
||||
|
||||
@@ -287,7 +283,6 @@ public class ZygoteInit {
|
||||
|
||||
int count = 0;
|
||||
String line;
|
||||
String missingClasses = null;
|
||||
while ((line = br.readLine()) != null) {
|
||||
// Skip comments and blank lines.
|
||||
line = line.trim();
|
||||
@@ -311,12 +306,7 @@ public class ZygoteInit {
|
||||
}
|
||||
count++;
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.e(TAG, "Class not found for preloading: " + line);
|
||||
if (missingClasses == null) {
|
||||
missingClasses = line;
|
||||
} else {
|
||||
missingClasses += " " + line;
|
||||
}
|
||||
Log.w(TAG, "Class not found for preloading: " + line);
|
||||
} catch (Throwable t) {
|
||||
Log.e(TAG, "Error preloading " + line + ".", t);
|
||||
if (t instanceof Error) {
|
||||
@@ -329,13 +319,6 @@ public class ZygoteInit {
|
||||
}
|
||||
}
|
||||
|
||||
if (THROW_ON_MISSING_PRELOAD &&
|
||||
missingClasses != null) {
|
||||
throw new IllegalStateException(
|
||||
"Missing class(es) for preloading, update preloaded-classes ["
|
||||
+ missingClasses + "]");
|
||||
}
|
||||
|
||||
Log.i(TAG, "...preloaded " + count + " classes in "
|
||||
+ (SystemClock.uptimeMillis()-startTime) + "ms.");
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -517,6 +517,40 @@ static void readLocale(char* language, char* region)
|
||||
//LOGD("language=%s region=%s\n", language, region);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a property containing space-separated options that should be
|
||||
* passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
|
||||
*
|
||||
* This will cut up "extraOptsBuf" as we chop it into individual options.
|
||||
*
|
||||
* Adds the strings, if any, to mOptions.
|
||||
*/
|
||||
void AndroidRuntime::parseExtraOpts(char* extraOptsBuf)
|
||||
{
|
||||
JavaVMOption opt;
|
||||
char* start;
|
||||
char* end;
|
||||
|
||||
memset(&opt, 0, sizeof(opt));
|
||||
start = extraOptsBuf;
|
||||
while (*start != '\0') {
|
||||
while (*start == ' ') /* skip leading whitespace */
|
||||
start++;
|
||||
if (*start == '\0') /* was trailing ws, bail */
|
||||
break;
|
||||
|
||||
end = start+1;
|
||||
while (*end != ' ' && *end != '\0') /* find end of token */
|
||||
end++;
|
||||
if (*end == ' ')
|
||||
*end++ = '\0'; /* mark end, advance to indicate more */
|
||||
|
||||
opt.optionString = start;
|
||||
mOptions.add(opt);
|
||||
start = end;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Start the Dalvik Virtual Machine.
|
||||
*
|
||||
@@ -536,6 +570,7 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
|
||||
char enableAssertBuf[sizeof("-ea:")-1 + PROPERTY_VALUE_MAX];
|
||||
char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
|
||||
char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
|
||||
char extraOptsBuf[PROPERTY_VALUE_MAX];
|
||||
char* stackTraceFile = NULL;
|
||||
bool checkJni = false;
|
||||
bool checkDexSum = false;
|
||||
@@ -844,7 +879,11 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
|
||||
opt.optionString = stackTraceFile;
|
||||
mOptions.add(opt);
|
||||
}
|
||||
|
||||
|
||||
/* extra options; parse this late so it overrides others */
|
||||
property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
|
||||
parseExtraOpts(extraOptsBuf);
|
||||
|
||||
/* Set the properties for locale */
|
||||
{
|
||||
char langOption[sizeof("-Duser.language=") + 3];
|
||||
|
||||
@@ -13,7 +13,9 @@ LOCAL_SRC_FILES := \
|
||||
|
||||
LOCAL_STATIC_JAVA_LIBRARIES += android-common
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := android.test.runner
|
||||
LOCAL_DX_FLAGS := --core-library
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := core-tests-supportlib
|
||||
LOCAL_JAVA_LIBRARIES := android.test.runner android-common
|
||||
LOCAL_PACKAGE_NAME := FrameworksCoreTests
|
||||
|
||||
LOCAL_CERTIFICATE := platform
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.net.ssl.TestSSLContext;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.params.ConnRoutePNames;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import tests.http.MockResponse;
|
||||
import tests.http.MockWebServer;
|
||||
import tests.http.RecordedRequest;
|
||||
|
||||
public class HttpsThroughHttpProxyTest extends TestCase {
|
||||
|
||||
public void testConnectViaHttps() throws IOException, InterruptedException {
|
||||
TestSSLContext testSSLContext = TestSSLContext.create();
|
||||
|
||||
MockWebServer server = new MockWebServer();
|
||||
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
|
||||
server.enqueue(new MockResponse()
|
||||
.setResponseCode(200)
|
||||
.setBody("this response comes via HTTPS"));
|
||||
server.play();
|
||||
|
||||
HttpClient httpClient = new DefaultHttpClient();
|
||||
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(
|
||||
testSSLContext.clientContext.getSocketFactory());
|
||||
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
|
||||
httpClient.getConnectionManager().getSchemeRegistry()
|
||||
.register(new Scheme("https", sslSocketFactory, server.getPort()));
|
||||
|
||||
HttpResponse response = httpClient.execute(
|
||||
new HttpGet("https://localhost:" + server.getPort() + "/foo"));
|
||||
assertEquals("this response comes via HTTPS", contentToString(response));
|
||||
|
||||
RecordedRequest request = server.takeRequest();
|
||||
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* http://code.google.com/p/android/issues/detail?id=2690
|
||||
*/
|
||||
public void testConnectViaProxy() throws IOException, InterruptedException {
|
||||
MockWebServer proxy = new MockWebServer();
|
||||
MockResponse mockResponse = new MockResponse()
|
||||
.setResponseCode(200)
|
||||
.setBody("this response comes via a proxy");
|
||||
proxy.enqueue(mockResponse);
|
||||
proxy.play();
|
||||
|
||||
HttpClient httpProxyClient = new DefaultHttpClient();
|
||||
httpProxyClient.getParams().setParameter(
|
||||
ConnRoutePNames.DEFAULT_PROXY, new HttpHost("localhost", proxy.getPort()));
|
||||
|
||||
HttpResponse response = httpProxyClient.execute(new HttpGet("http://android.com/foo"));
|
||||
assertEquals("this response comes via a proxy", contentToString(response));
|
||||
|
||||
RecordedRequest request = proxy.takeRequest();
|
||||
assertEquals("GET http://android.com/foo HTTP/1.1", request.getRequestLine());
|
||||
assertContains(request.getHeaders(), "Host: android.com");
|
||||
}
|
||||
|
||||
public void testConnectViaHttpProxyToHttps() throws IOException, InterruptedException {
|
||||
TestSSLContext testSSLContext = TestSSLContext.create();
|
||||
|
||||
MockWebServer proxy = new MockWebServer();
|
||||
proxy.useHttps(testSSLContext.serverContext.getSocketFactory(), true);
|
||||
MockResponse connectResponse = new MockResponse()
|
||||
.setResponseCode(200);
|
||||
connectResponse.getHeaders().clear();
|
||||
proxy.enqueue(connectResponse);
|
||||
proxy.enqueue(new MockResponse()
|
||||
.setResponseCode(200)
|
||||
.setBody("this response comes via a secure proxy"));
|
||||
proxy.play();
|
||||
|
||||
HttpClient httpProxyClient = new DefaultHttpClient();
|
||||
HttpHost proxyHost = new HttpHost("localhost", proxy.getPort());
|
||||
httpProxyClient.getParams().setParameter(
|
||||
ConnRoutePNames.DEFAULT_PROXY, proxyHost);
|
||||
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(
|
||||
testSSLContext.clientContext.getSocketFactory());
|
||||
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
|
||||
httpProxyClient.getConnectionManager().getSchemeRegistry()
|
||||
.register(new Scheme("https", sslSocketFactory, 443));
|
||||
|
||||
HttpResponse response = httpProxyClient.execute(new HttpGet("https://android.com/foo"));
|
||||
assertEquals("this response comes via a secure proxy", contentToString(response));
|
||||
|
||||
RecordedRequest connect = proxy.takeRequest();
|
||||
assertEquals("Connect line failure on proxy " + proxyHost.toHostString(),
|
||||
"CONNECT android.com:443 HTTP/1.1", connect.getRequestLine());
|
||||
assertContains(connect.getHeaders(), "Host: android.com");
|
||||
|
||||
RecordedRequest get = proxy.takeRequest();
|
||||
assertEquals("GET /foo HTTP/1.1", get.getRequestLine());
|
||||
assertContains(get.getHeaders(), "Host: android.com");
|
||||
}
|
||||
|
||||
private void assertContains(List<String> headers, String header) {
|
||||
assertTrue(headers.toString(), headers.contains(header));
|
||||
}
|
||||
|
||||
private String contentToString(HttpResponse response) throws IOException {
|
||||
StringWriter writer = new StringWriter();
|
||||
char[] buffer = new char[1024];
|
||||
Reader reader = new InputStreamReader(response.getEntity().getContent());
|
||||
int length;
|
||||
while ((length = reader.read(buffer)) != -1) {
|
||||
writer.write(buffer, 0, length);
|
||||
}
|
||||
reader.close();
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
@@ -98,6 +98,7 @@ public:
|
||||
|
||||
private:
|
||||
static int startReg(JNIEnv* env);
|
||||
void parseExtraOpts(char* extraOptsBuf);
|
||||
int startVm(JavaVM** pJavaVM, JNIEnv** pEnv);
|
||||
|
||||
Vector<JavaVMOption> mOptions;
|
||||
|
||||
@@ -697,19 +697,13 @@ com.google.android.gles_jni.GLImpl
|
||||
com.ibm.icu4jni.charset.CharsetDecoderICU
|
||||
com.ibm.icu4jni.charset.CharsetEncoderICU
|
||||
com.ibm.icu4jni.charset.CharsetICU
|
||||
com.ibm.icu4jni.charset.CharsetProviderICU
|
||||
com.ibm.icu4jni.charset.NativeConverter
|
||||
com.ibm.icu4jni.common.ErrorCode
|
||||
com.ibm.icu4jni.lang.UCharacter
|
||||
com.ibm.icu4jni.regex.NativeRegEx
|
||||
com.ibm.icu4jni.text.Collator
|
||||
com.ibm.icu4jni.text.NativeBreakIterator
|
||||
com.ibm.icu4jni.text.NativeCollation
|
||||
com.ibm.icu4jni.text.NativeDecimalFormat
|
||||
com.ibm.icu4jni.text.RuleBasedCollator
|
||||
com.ibm.icu4jni.text.RuleBasedNumberFormat
|
||||
com.ibm.icu4jni.util.Resources
|
||||
com.ibm.icu4jni.util.Resources$DefaultTimeZones
|
||||
dalvik.system.DalvikLogHandler
|
||||
dalvik.system.DalvikLogging
|
||||
dalvik.system.NativeStart
|
||||
@@ -758,7 +752,6 @@ java.io.PrintStream
|
||||
java.io.PrintWriter
|
||||
java.io.PushbackReader
|
||||
java.io.RandomAccessFile
|
||||
java.io.RandomAccessFile$RepositionLock
|
||||
java.io.Reader
|
||||
java.io.Serializable
|
||||
java.io.StreamCorruptedException
|
||||
@@ -853,6 +846,7 @@ java.math.BigDecimal
|
||||
java.math.BigInt
|
||||
java.math.BigInteger
|
||||
java.math.Multiplication
|
||||
java.math.NativeBN
|
||||
java.net.AddressCache
|
||||
java.net.AddressCache$1
|
||||
java.net.ConnectException
|
||||
@@ -930,7 +924,6 @@ java.security.Security
|
||||
java.security.cert.X509Certificate
|
||||
java.text.AttributedCharacterIterator$Attribute
|
||||
java.text.Collator
|
||||
java.text.Collator$1
|
||||
java.text.DateFormat
|
||||
java.text.DateFormat$Field
|
||||
java.text.DecimalFormat
|
||||
@@ -1126,7 +1119,6 @@ org.apache.harmony.luni.util.InputStreamHelper
|
||||
org.apache.harmony.luni.util.InputStreamHelper$1
|
||||
org.apache.harmony.luni.util.InputStreamHelper$ExposedByteArrayInputStream
|
||||
org.apache.harmony.luni.util.LocaleCache
|
||||
org.apache.harmony.luni.util.Msg
|
||||
org.apache.harmony.luni.util.NumberConverter
|
||||
org.apache.harmony.luni.util.PriviAction
|
||||
org.apache.harmony.luni.util.ThreadLocalCache
|
||||
@@ -1178,7 +1170,6 @@ org.apache.harmony.security.x509.SubjectPublicKeyInfo
|
||||
org.apache.harmony.security.x509.TBSCertificate
|
||||
org.apache.harmony.security.x509.Time
|
||||
org.apache.harmony.security.x509.Validity
|
||||
org.apache.harmony.text.BidiWrapper
|
||||
org.apache.harmony.xml.ExpatAttributes
|
||||
org.apache.harmony.xml.ExpatParser
|
||||
org.apache.harmony.xml.ExpatPullParser
|
||||
@@ -1260,7 +1251,6 @@ org.ccil.cowan.tagsoup.Parser
|
||||
org.json.JSONObject
|
||||
org.kxml2.io.KXmlParser
|
||||
org.kxml2.io.KXmlSerializer
|
||||
org.openssl.NativeBN
|
||||
org.xml.sax.Attributes
|
||||
org.xml.sax.InputSource
|
||||
org.xml.sax.helpers.AttributesImpl
|
||||
|
||||
@@ -20,7 +20,7 @@ include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := core framework
|
||||
LOCAL_JAVA_LIBRARIES := core core-junit framework
|
||||
|
||||
LOCAL_MODULE:= android.test.runner
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ LOCAL_MODULE_TAGS := tests
|
||||
LOCAL_SRC_FILES := \
|
||||
$(call all-subdir-java-files)
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := android.test.runner
|
||||
LOCAL_JAVA_LIBRARIES := android.test.runner bouncycastle
|
||||
|
||||
LOCAL_PACKAGE_NAME := CoreTests
|
||||
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.core;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.harmony.xnet.provider.jsse.OpenSSLMessageDigest;
|
||||
import org.bouncycastle.crypto.Digest;
|
||||
import org.bouncycastle.crypto.ExtendedDigest;
|
||||
import org.bouncycastle.crypto.digests.MD4Digest;
|
||||
import org.bouncycastle.crypto.digests.MD5Digest;
|
||||
import org.bouncycastle.crypto.digests.SHA1Digest;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
|
||||
/**
|
||||
* Implements unit tests for our JNI wrapper around OpenSSL. We use the
|
||||
* existing Bouncy Castle implementation as our test oracle.
|
||||
*/
|
||||
public class CryptoTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Processes the two given message digests for the same data and checks
|
||||
* the results. Requirement is that the results must be equal, the digest
|
||||
* implementations must have the same properties, and the new implementation
|
||||
* must be faster than the old one.
|
||||
*
|
||||
* @param oldDigest The old digest implementation, provided by Bouncy Castle
|
||||
* @param newDigest The new digest implementation, provided by OpenSSL
|
||||
*/
|
||||
public void doTestMessageDigest(Digest oldDigest, Digest newDigest) {
|
||||
final int ITERATIONS = 10;
|
||||
|
||||
byte[] data = new byte[1024];
|
||||
|
||||
byte[] oldHash = new byte[oldDigest.getDigestSize()];
|
||||
byte[] newHash = new byte[newDigest.getDigestSize()];
|
||||
|
||||
Assert.assertEquals("Hash names must be equal", oldDigest.getAlgorithmName(), newDigest.getAlgorithmName());
|
||||
Assert.assertEquals("Hash sizes must be equal", oldHash.length, newHash.length);
|
||||
Assert.assertEquals("Hash block sizes must be equal", ((ExtendedDigest)oldDigest).getByteLength(), ((ExtendedDigest)newDigest).getByteLength());
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = (byte)i;
|
||||
}
|
||||
|
||||
long oldTime = 0;
|
||||
long newTime = 0;
|
||||
|
||||
for (int j = 0; j < ITERATIONS; j++) {
|
||||
long t0 = System.currentTimeMillis();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
oldDigest.update(data, 0, data.length);
|
||||
}
|
||||
int oldLength = oldDigest.doFinal(oldHash, 0);
|
||||
long t1 = System.currentTimeMillis();
|
||||
|
||||
oldTime = oldTime + (t1 - t0);
|
||||
|
||||
long t2 = System.currentTimeMillis();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
newDigest.update(data, 0, data.length);
|
||||
}
|
||||
int newLength = newDigest.doFinal(newHash, 0);
|
||||
long t3 = System.currentTimeMillis();
|
||||
|
||||
newTime = newTime + (t3 - t2);
|
||||
|
||||
Assert.assertEquals("Hash sizes must be equal", oldLength, newLength);
|
||||
|
||||
for (int i = 0; i < oldLength; i++) {
|
||||
Assert.assertEquals("Hashes[" + i + "] must be equal", oldHash[i], newHash[i]);
|
||||
}
|
||||
}
|
||||
|
||||
android.util.Log.d("CryptoTest", "Time for " + ITERATIONS + " x old hash processing: " + oldTime + " ms");
|
||||
android.util.Log.d("CryptoTest", "Time for " + ITERATIONS + " x new hash processing: " + newTime + " ms");
|
||||
|
||||
// Assert.assertTrue("New hash should be faster", newTime < oldTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the MD4 implementation.
|
||||
*/
|
||||
@MediumTest
|
||||
public void testMD4() {
|
||||
Digest oldDigest = new MD4Digest();
|
||||
Digest newDigest = OpenSSLMessageDigest.getInstance("MD4");
|
||||
doTestMessageDigest(oldDigest, newDigest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the MD5 implementation.
|
||||
*/
|
||||
@MediumTest
|
||||
public void testMD5() {
|
||||
Digest oldDigest = new MD5Digest();
|
||||
Digest newDigest = OpenSSLMessageDigest.getInstance("MD5");
|
||||
doTestMessageDigest(oldDigest, newDigest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the SHA-1 implementation.
|
||||
*/
|
||||
@MediumTest
|
||||
public void testSHA1() {
|
||||
Digest oldDigest = new SHA1Digest();
|
||||
Digest newDigest = OpenSSLMessageDigest.getInstance("SHA-1");
|
||||
doTestMessageDigest(oldDigest, newDigest);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,8 +19,8 @@ package android.core;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.os.Debug;
|
||||
import org.apache.harmony.xnet.provider.jsse.FileClientSessionCache;
|
||||
import org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl;
|
||||
import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache;
|
||||
import org.apache.harmony.xnet.provider.jsse.SSLContextImpl;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
@@ -189,14 +189,14 @@ public class SSLPerformanceTest extends AndroidTestCase {
|
||||
public void testEngineInit() throws IOException, KeyManagementException {
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
|
||||
new SSLContextImpl().engineInit(null, null, null);
|
||||
new OpenSSLContextImpl().engineInit(null, null, null);
|
||||
|
||||
stopwatch.stop();
|
||||
}
|
||||
|
||||
public void testWebRequestWithoutCache() throws IOException,
|
||||
KeyManagementException {
|
||||
SSLContextImpl sslContext = new SSLContextImpl();
|
||||
OpenSSLContextImpl sslContext = new OpenSSLContextImpl();
|
||||
sslContext.engineInit(null, null, null);
|
||||
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
@@ -210,7 +210,7 @@ public class SSLPerformanceTest extends AndroidTestCase {
|
||||
KeyManagementException {
|
||||
deleteDirectory();
|
||||
|
||||
SSLContextImpl sslContext = new SSLContextImpl();
|
||||
OpenSSLContextImpl sslContext = new OpenSSLContextImpl();
|
||||
sslContext.engineInit(null, null, null,
|
||||
FileClientSessionCache.usingDirectory(getCacheDirectory()),
|
||||
null);
|
||||
@@ -234,7 +234,7 @@ public class SSLPerformanceTest extends AndroidTestCase {
|
||||
KeyManagementException {
|
||||
deleteDirectory();
|
||||
|
||||
SSLContextImpl sslContext = new SSLContextImpl();
|
||||
OpenSSLContextImpl sslContext = new OpenSSLContextImpl();
|
||||
sslContext.engineInit(null, null, null);
|
||||
|
||||
// Make sure www.google.com is in the cache.
|
||||
@@ -247,7 +247,7 @@ public class SSLPerformanceTest extends AndroidTestCase {
|
||||
stopwatch.stop();
|
||||
}
|
||||
|
||||
private void getVerisignDotCom(SSLContextImpl sslContext)
|
||||
private void getVerisignDotCom(OpenSSLContextImpl sslContext)
|
||||
throws IOException {
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("https",
|
||||
|
||||
@@ -19,9 +19,9 @@ package android.core;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.harmony.xnet.provider.jsse.SSLContextImpl;
|
||||
import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache;
|
||||
import org.apache.harmony.xnet.provider.jsse.FileClientSessionCache;
|
||||
import org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl;
|
||||
import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
@@ -907,7 +907,7 @@ public class SSLSocketTest extends TestCase {
|
||||
*/
|
||||
public void testClientSessionCaching() throws IOException,
|
||||
KeyManagementException {
|
||||
SSLContextImpl context = new SSLContextImpl();
|
||||
OpenSSLContextImpl context = new OpenSSLContextImpl();
|
||||
|
||||
// Cache size = 2.
|
||||
FakeClientSessionCache fakeCache = new FakeClientSessionCache();
|
||||
@@ -997,7 +997,7 @@ public class SSLSocketTest extends TestCase {
|
||||
|
||||
public void testFileBasedClientSessionCache() throws IOException,
|
||||
KeyManagementException {
|
||||
SSLContextImpl context = new SSLContextImpl();
|
||||
OpenSSLContextImpl context = new OpenSSLContextImpl();
|
||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||
if (tmpDir == null) {
|
||||
fail("Please set 'java.io.tmpdir' system property.");
|
||||
|
||||
Reference in New Issue
Block a user