Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60586f2e authored by Dan Egnor's avatar Dan Egnor
Browse files

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
parent d2e6af66
Loading
Loading
Loading
Loading
+80 −23
Original line number Diff line number Diff line
@@ -86670,15 +86670,11 @@
 type="android.net.SSLCertificateSocketFactory"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="socketReadTimeoutForSslHandshake" type="int">
<parameter name="handshakeTimeoutMillis" type="int">
</parameter>
<exception name="KeyManagementException" type="java.security.KeyManagementException">
</exception>
<exception name="NoSuchAlgorithmException" type="java.security.NoSuchAlgorithmException">
</exception>
</constructor>
<method name="createSocket"
 return="java.net.Socket"
@@ -86690,13 +86686,13 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="socket" type="java.net.Socket">
<parameter name="k" type="java.net.Socket">
</parameter>
<parameter name="s" type="java.lang.String">
<parameter name="host" type="java.lang.String">
</parameter>
<parameter name="i" type="int">
<parameter name="port" type="int">
</parameter>
<parameter name="flag" type="boolean">
<parameter name="close" type="boolean">
</parameter>
<exception name="IOException" type="java.io.IOException">
</exception>
@@ -86711,13 +86707,13 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="inaddr" type="java.net.InetAddress">
<parameter name="addr" type="java.net.InetAddress">
</parameter>
<parameter name="i" type="int">
<parameter name="port" type="int">
</parameter>
<parameter name="inaddr2" type="java.net.InetAddress">
<parameter name="localAddr" type="java.net.InetAddress">
</parameter>
<parameter name="j" type="int">
<parameter name="localPort" type="int">
</parameter>
<exception name="IOException" type="java.io.IOException">
</exception>
@@ -86732,9 +86728,9 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="inaddr" type="java.net.InetAddress">
<parameter name="addr" type="java.net.InetAddress">
</parameter>
<parameter name="i" type="int">
<parameter name="port" type="int">
</parameter>
<exception name="IOException" type="java.io.IOException">
</exception>
@@ -86749,13 +86745,13 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="s" type="java.lang.String">
<parameter name="host" type="java.lang.String">
</parameter>
<parameter name="i" type="int">
<parameter name="port" type="int">
</parameter>
<parameter name="inaddr" type="java.net.InetAddress">
<parameter name="localAddr" type="java.net.InetAddress">
</parameter>
<parameter name="j" type="int">
<parameter name="localPort" type="int">
</parameter>
<exception name="IOException" type="java.io.IOException">
</exception>
@@ -86770,9 +86766,9 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="s" type="java.lang.String">
<parameter name="host" type="java.lang.String">
</parameter>
<parameter name="i" type="int">
<parameter name="port" type="int">
</parameter>
<exception name="IOException" type="java.io.IOException">
</exception>
@@ -86787,7 +86783,22 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="socketReadTimeoutForSslHandshake" type="int">
<parameter name="handshakeTimeoutMillis" type="int">
</parameter>
</method>
<method name="getDefault"
 return="javax.net.SocketFactory"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="handshakeTimeoutMillis" type="int">
</parameter>
<parameter name="cache" type="android.net.SSLSessionCache">
</parameter>
</method>
<method name="getDefaultCipherSuites"
@@ -86801,6 +86812,21 @@
 visibility="public"
>
</method>
<method name="getHttpSocketFactory"
 return="org.apache.http.conn.ssl.SSLSocketFactory"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="handshakeTimeoutMillis" type="int">
</parameter>
<parameter name="cache" type="android.net.SSLSessionCache">
</parameter>
</method>
<method name="getSupportedCipherSuites"
 return="java.lang.String[]"
 abstract="false"
@@ -86813,6 +86839,37 @@
>
</method>
</class>
<class name="SSLSessionCache"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="SSLSessionCache"
 type="android.net.SSLSessionCache"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="dir" type="java.io.File">
</parameter>
<exception name="IOException" type="java.io.IOException">
</exception>
</constructor>
<constructor name="SSLSessionCache"
 type="android.net.SSLSessionCache"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="context" type="android.content.Context">
</parameter>
</constructor>
</class>
<class name="TrafficStats"
 extends="java.lang.Object"
 abstract="false"
+1 −0
Original line number Diff line number Diff line
@@ -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)

+15 −53
Original line number Diff line number Diff line
@@ -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,8 +74,6 @@ 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 {

@@ -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);
@@ -138,32 +136,6 @@ public final class AndroidHttpClient implements HttpClient {
        return new AndroidHttpClient(manager, params);
    }

    /**
     * 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.
@@ -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. */
@@ -366,15 +336,6 @@ public final class AndroidHttpClient implements HttpClient {
            return Log.isLoggable(tag, level);
        }

        /**
         * 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.
         */
@@ -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));
            }
        }
    }
+0 −5
Original line number Diff line number Diff line
@@ -114,11 +114,6 @@ public class ArrayListCursor extends AbstractCursor {
        return mRows.length;
    }

    @Override
    public boolean deleteRow() {
        return false;
    }

    @Override
    public String[] getColumnNames() {
        return mColumnNames;
+113 −163

File changed.

Preview size limit exceeded, changes collapsed.

Loading