summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDan Egnor <egnor@google.com>2010-02-08 21:56:38 -0800
committerDan Egnor <egnor@google.com>2010-02-10 14:43:21 -0800
commit60586f2ec65d16d185767fce4311d3ed0e9112ac (patch)
tree0006970ad06fc8b155d282651043d87b3972e23e /common
parentd2e6af66ce9fdf7bfa72efe18b74260901a944a6 (diff)
downloadframeworks_base-60586f2ec65d16d185767fce4311d3ed0e9112ac.zip
frameworks_base-60586f2ec65d16d185767fce4311d3ed0e9112ac.tar.gz
frameworks_base-60586f2ec65d16d185767fce4311d3ed0e9112ac.tar.bz2
API CHANGE: Add SSLSessionCache public API to allow unbundled SSL session caching.
Generally clean up the associated SSLCertificateSocketFactory API as well, change AndroidHttpClient to use this new thing, and make the android-common library build SDK-clean (woo hoo). Bug: 2362543 Bug: 2357311
Diffstat (limited to 'common')
-rw-r--r--common/Android.mk1
-rw-r--r--common/java/com/android/common/AndroidHttpClient.java68
-rw-r--r--common/java/com/android/common/ArrayListCursor.java5
3 files changed, 16 insertions, 58 deletions
diff --git a/common/Android.mk b/common/Android.mk
index 76091eb..5c5b01b 100644
--- a/common/Android.mk
+++ b/common/Android.mk
@@ -19,6 +19,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := android-common
+LOCAL_SDK_VERSION := current
LOCAL_SRC_FILES := $(call all-java-files-under, java)
include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/common/java/com/android/common/AndroidHttpClient.java b/common/java/com/android/common/AndroidHttpClient.java
index 99faf6e..4c65eb0 100644
--- a/common/java/com/android/common/AndroidHttpClient.java
+++ b/common/java/com/android/common/AndroidHttpClient.java
@@ -47,8 +47,6 @@ import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.BasicHttpContext;
-import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache;
-import org.apache.harmony.xnet.provider.jsse.SSLContextImpl;
import java.io.IOException;
import java.io.InputStream;
@@ -59,11 +57,11 @@ import java.util.zip.GZIPOutputStream;
import java.net.URI;
import java.security.KeyManagementException;
+import android.content.Context;
import android.content.ContentResolver;
+import android.net.SSLCertificateSocketFactory;
+import android.net.SSLSessionCache;
import android.os.Looper;
-import android.os.SystemProperties;
-import android.provider.Settings;
-import android.text.TextUtils;
import android.util.Log;
/**
@@ -76,11 +74,9 @@ import android.util.Log;
* To retain cookies, simply add a cookie store to the HttpContext:</p>
*
* <pre>context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);</pre>
- *
- * {@hide}
*/
public final class AndroidHttpClient implements HttpClient {
-
+
// Gzip of data shorter than this probably won't be worthwhile
public static long DEFAULT_SYNC_MIN_GZIP_BYTES = 256;
@@ -101,12 +97,11 @@ public final class AndroidHttpClient implements HttpClient {
/**
* Create a new HttpClient with reasonable defaults (which you can update).
*
- * @param userAgent to report in your HTTP requests.
- * @param sessionCache persistent session cache
+ * @param userAgent to report in your HTTP requests
+ * @param context to use for caching SSL sessions (may be null for no caching)
* @return AndroidHttpClient for you to use for all your requests.
*/
- public static AndroidHttpClient newInstance(String userAgent,
- SSLClientSessionCache sessionCache) {
+ public static AndroidHttpClient newInstance(String userAgent, Context context) {
HttpParams params = new BasicHttpParams();
// Turn off stale checking. Our connections break all the time anyway,
@@ -122,13 +117,16 @@ public final class AndroidHttpClient implements HttpClient {
// often wants to re-POST after a redirect, which we must do ourselves.
HttpClientParams.setRedirecting(params, false);
+ // Use a session cache for SSL sockets
+ SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);
+
// Set the specified user agent and register standard protocols.
HttpProtocolParams.setUserAgent(params, userAgent);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http",
PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https",
- socketFactoryWithCache(sessionCache), 443));
+ SSLCertificateSocketFactory.getHttpSocketFactory(30 * 1000, sessionCache), 443));
ClientConnectionManager manager =
new ThreadSafeClientConnManager(params, schemeRegistry);
@@ -139,32 +137,6 @@ public final class AndroidHttpClient implements HttpClient {
}
/**
- * Returns a socket factory backed by the given persistent session cache.
- *
- * @param sessionCache to retrieve sessions from, null for no cache
- */
- private static SSLSocketFactory socketFactoryWithCache(
- SSLClientSessionCache sessionCache) {
- if (sessionCache == null) {
- // Use the default factory which doesn't support persistent
- // caching.
- return SSLSocketFactory.getSocketFactory();
- }
-
- // Create a new SSL context backed by the cache.
- // TODO: Keep a weak *identity* hash map of caches to engines. In the
- // mean time, if we have two engines for the same cache, they'll still
- // share sessions but will have to do so through the persistent cache.
- SSLContextImpl sslContext = new SSLContextImpl();
- try {
- sslContext.engineInit(null, null, null, sessionCache, null);
- } catch (KeyManagementException e) {
- throw new AssertionError(e);
- }
- return new SSLSocketFactory(sslContext.engineGetSocketFactory());
- }
-
- /**
* Create a new HttpClient with reasonable defaults (which you can update).
* @param userAgent to report in your HTTP requests.
* @return AndroidHttpClient for you to use for all your requests.
@@ -339,9 +311,7 @@ public final class AndroidHttpClient implements HttpClient {
* Shorter data will not be compressed.
*/
public static long getMinGzipSize(ContentResolver resolver) {
- return Settings.Secure.getLong(resolver,
- Settings.Secure.SYNC_MIN_GZIP_BYTES,
- DEFAULT_SYNC_MIN_GZIP_BYTES);
+ return DEFAULT_SYNC_MIN_GZIP_BYTES; // For now, this is just a constant.
}
/* cURL logging support. */
@@ -367,15 +337,6 @@ public final class AndroidHttpClient implements HttpClient {
}
/**
- * Returns true if auth logging is turned on for this configuration. Can only be set on
- * insecure devices.
- */
- private boolean isAuthLoggable() {
- String secure = SystemProperties.get("ro.secure");
- return "0".equals(secure) && Log.isLoggable(tag + "-auth", level);
- }
-
- /**
* Prints a message using this configuration.
*/
private void println(String message) {
@@ -421,8 +382,9 @@ public final class AndroidHttpClient implements HttpClient {
if (configuration != null
&& configuration.isLoggable()
&& request instanceof HttpUriRequest) {
- configuration.println(toCurl((HttpUriRequest) request,
- configuration.isAuthLoggable()));
+ // Never print auth token -- we used to check ro.secure=0 to
+ // enable that, but can't do that in unbundled code.
+ configuration.println(toCurl((HttpUriRequest) request, false));
}
}
}
diff --git a/common/java/com/android/common/ArrayListCursor.java b/common/java/com/android/common/ArrayListCursor.java
index cc1fe27..9ad5c36 100644
--- a/common/java/com/android/common/ArrayListCursor.java
+++ b/common/java/com/android/common/ArrayListCursor.java
@@ -115,11 +115,6 @@ public class ArrayListCursor extends AbstractCursor {
}
@Override
- public boolean deleteRow() {
- return false;
- }
-
- @Override
public String[] getColumnNames() {
return mColumnNames;
}