Add sources for API 35

Downloaded from https://dl.google.com/android/repository/source-35_r01.zip
using SdkManager in Studio

Test: None
Change-Id: I83f78aa820b66edfdc9f8594d17bc7b6cacccec1
diff --git a/android-35/com/android/okhttp/internalandroidapi/AndroidResponseCacheAdapter.java b/android-35/com/android/okhttp/internalandroidapi/AndroidResponseCacheAdapter.java
new file mode 100644
index 0000000..1c5c6e6
--- /dev/null
+++ b/android-35/com/android/okhttp/internalandroidapi/AndroidResponseCacheAdapter.java
@@ -0,0 +1,223 @@
+/* GENERATED SOURCE. DO NOT MODIFY. */
+/*
+ * Copyright (C) 2015 Square, Inc.
+ *
+ * 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 com.android.okhttp.internalandroidapi;
+
+import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
+
+import android.annotation.SystemApi;
+
+import com.android.okhttp.internalandroidapi.HasCacheHolder.CacheHolder;
+
+import libcore.util.NonNull;
+import libcore.util.Nullable;
+
+import com.android.okhttp.Cache;
+import com.android.okhttp.Request;
+import com.android.okhttp.Response;
+import com.android.okhttp.internal.huc.JavaApiConverter;
+
+import java.io.IOException;
+import java.net.CacheRequest;
+import java.net.CacheResponse;
+import java.net.URI;
+import java.net.URLConnection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A modified copy of {@link com.android.okhttp.AndroidShimResponseCache} that exposes a
+ * {@link CacheHolder} instead of a {@link Cache}. We want to keep the framework code that interacts
+ * with OkHttp at arms length. By delegating to this class the Android HttpResponseCache class has
+ * no knowledge of OkHttp internal classes at class resolution time and there are no internal
+ * classes appearing on method signatures.
+ * @hide
+ * @hide This class is not part of the Android public SDK API
+ */
+@SystemApi(client = MODULE_LIBRARIES)
[email protected](status = libcore.api.CorePlatformApi.Status.STABLE)
+public final class AndroidResponseCacheAdapter {
+
+    private final CacheHolder cacheHolder;
+    private final Cache okHttpCache;
+
+    /**
+     * Creates an instance from {@link CacheHolder}
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public AndroidResponseCacheAdapter(@NonNull CacheHolder cacheHolder) {
+        this.cacheHolder = cacheHolder;
+        // Avoid one level of dereferencing by storing the reference to the OkHttp cache for later.
+        this.okHttpCache = cacheHolder.getCache();
+    }
+
+    /**
+     * Returns the {@link CacheHolder} associated with this instance and can be used by OkHttp
+     * internal code to obtain the underlying OkHttp Cache object.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public @NonNull CacheHolder getCacheHolder() {
+        return cacheHolder;
+    }
+
+    /**
+     * Used to implement {@link java.net.ResponseCache#get(URI, String, Map)}. See that method for
+     * details.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public @Nullable CacheResponse get(@NonNull URI uri, @NonNull String requestMethod,
+            @Nullable Map<String, List<String>> requestHeaders) throws IOException {
+        Request okRequest = JavaApiConverter.createOkRequest(uri, requestMethod, requestHeaders);
+        Response okResponse = okHttpCache.internalCache.get(okRequest);
+        if (okResponse == null) {
+            return null;
+        }
+        return JavaApiConverter.createJavaCacheResponse(okResponse);
+    }
+
+    /**
+     * Used to implement {@link java.net.ResponseCache#put(URI, URLConnection)}. See that method for
+     * details.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public @Nullable CacheRequest put(@NonNull URI uri, @NonNull URLConnection urlConnection)
+            throws IOException {
+        Response okResponse = JavaApiConverter.createOkResponseForCachePut(uri, urlConnection);
+        if (okResponse == null) {
+            // The URLConnection is not cacheable or could not be converted. Stop.
+            return null;
+        }
+        com.android.okhttp.internal.http.CacheRequest okCacheRequest =
+                okHttpCache.internalCache.put(okResponse);
+        if (okCacheRequest == null) {
+            return null;
+        }
+        return JavaApiConverter.createJavaCacheRequest(okCacheRequest);
+    }
+
+    /**
+     * Returns the number of bytes currently being used to store the values in
+     * this cache. This may be greater than the {@link #getMaxSize()} if a background
+     * deletion is pending. IOException is thrown if the size cannot be determined.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public long getSize() throws IOException {
+        return okHttpCache.getSize();
+    }
+
+    /**
+     * Returns the maximum number of bytes that this cache should use to store
+     * its data.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public long getMaxSize() {
+        return okHttpCache.getMaxSize();
+    }
+
+    /**
+     * Force buffered operations to the filesystem. This ensures that responses
+     * written to the cache will be available the next time the cache is opened,
+     * even if this process is killed. IOException is thrown if the flush fails.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public void flush() throws IOException {
+        okHttpCache.flush();
+    }
+
+    /**
+     * Returns the number of HTTP requests that required the network to either
+     * supply a response or validate a locally cached response.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public int getNetworkCount() {
+        return okHttpCache.getNetworkCount();
+    }
+
+    /**
+     * Returns the number of HTTP requests whose response was provided by the
+     * cache. This may include conditional {@code GET} requests that were
+     * validated over the network.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public int getHitCount() {
+        return okHttpCache.getHitCount();
+    }
+
+    /**
+     * Returns the total number of HTTP requests that were made. This includes
+     * both client requests and requests that were made on the client's behalf
+     * to handle a redirects and retries.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public int getRequestCount() {
+        return okHttpCache.getRequestCount();
+    }
+
+    /**
+     * Closes this cache. Stored values will remain on the filesystem.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public void close() throws IOException {
+        okHttpCache.close();
+    }
+
+    /**
+     * Closes the cache and deletes all of its stored values. This will delete
+     * all files in the cache directory including files that weren't created by
+     * the cache.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    public void delete() throws IOException {
+        okHttpCache.delete();
+    }
+}
diff --git a/android-35/com/android/okhttp/internalandroidapi/Dns.java b/android-35/com/android/okhttp/internalandroidapi/Dns.java
new file mode 100644
index 0000000..4da9d8f
--- /dev/null
+++ b/android-35/com/android/okhttp/internalandroidapi/Dns.java
@@ -0,0 +1,37 @@
+/* GENERATED SOURCE. DO NOT MODIFY. */
+/*
+ * Copyright (C) 2017 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 com.android.okhttp.internalandroidapi;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.List;
+
+/**
+ * A domain name service that resolves IP addresses for host names.
+ * @hide
+ * @hide This class is not part of the Android public SDK API
+ */
+public interface Dns {
+    /**
+     * Returns the IP addresses of {@code hostname}, in the order they should
+     * be attempted.
+     *
+     * @hide
+     */
+    List<InetAddress> lookup(String hostname) throws UnknownHostException;
+}
diff --git a/android-35/com/android/okhttp/internalandroidapi/HasCacheHolder.java b/android-35/com/android/okhttp/internalandroidapi/HasCacheHolder.java
new file mode 100644
index 0000000..67ae1ca
--- /dev/null
+++ b/android-35/com/android/okhttp/internalandroidapi/HasCacheHolder.java
@@ -0,0 +1,108 @@
+/* GENERATED SOURCE. DO NOT MODIFY. */
+/*
+ * Copyright (C) 2018 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 com.android.okhttp.internalandroidapi;
+
+import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
+
+import android.annotation.SystemApi;
+
+import libcore.util.NonNull;
+
+import com.android.okhttp.Cache;
+
+import java.io.File;
+
+/**
+ * An interface used to indicate a class can return a {@link CacheHolder} object.
+ * @hide
+ * @hide This class is not part of the Android public SDK API
+ */
+@SystemApi(client = MODULE_LIBRARIES)
[email protected](status = libcore.api.CorePlatformApi.Status.STABLE)
+public interface HasCacheHolder {
+
+    /**
+     * Returns the {@link CacheHolder} object.
+     *
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    @NonNull CacheHolder getCacheHolder();
+
+    /**
+     * A holder for an OkHttp internal Cache object. This class exists as an opaque layer over
+     * OkHttp internal classes.
+     * @hide
+     */
+    @SystemApi(client = MODULE_LIBRARIES)
+    @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+    final class CacheHolder {
+
+        private final Cache okHttpCache;
+
+        private CacheHolder(Cache okHttpCache) {
+            this.okHttpCache = okHttpCache;
+        }
+
+        // This constructor is required for @libcore.api.CorePlatformApi stubs generation. Without
+        // it the constructor above is included in the stubs code which adds a dependency on
+        // okhttp.Cache that we don't want.
+        @SuppressWarnings("unused")
+        private CacheHolder() {
+            throw new UnsupportedOperationException();
+        }
+
+        /**
+         * Returns the underlying {@link Cache} object.
+         * @hide
+         */
+        public Cache getCache() {
+            return okHttpCache;
+        }
+
+        /**
+         * Returns a new {@link CacheHolder} containing an OKHttp Cache with the specified settings.
+         *
+         * @param directory a writable directory
+         * @param maxSizeBytes the maximum number of bytes this cache should use to store
+         *
+         * @hide
+         */
+        @SystemApi(client = MODULE_LIBRARIES)
+        @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+        public static @NonNull CacheHolder create(@NonNull File directory, long maxSizeBytes) {
+            Cache cache = new Cache(directory, maxSizeBytes);
+            return new CacheHolder(cache);
+        }
+
+        /**
+         * Returns true if the arguments supplied would result in an equivalent cache to this one
+         * being created if they were passed to {@link #create(File, long)}.
+         *
+         * @hide
+         */
+        @SystemApi(client = MODULE_LIBRARIES)
+        @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE)
+        public boolean isEquivalent(@NonNull File directory, long maxSizeBytes) {
+            return (okHttpCache.getDirectory().equals(directory)
+                    && okHttpCache.getMaxSize() == maxSizeBytes
+                    && !okHttpCache.isClosed());
+        }
+    }
+}
diff --git a/android-35/com/android/okhttp/internalandroidapi/HttpURLConnectionFactory.java b/android-35/com/android/okhttp/internalandroidapi/HttpURLConnectionFactory.java
new file mode 100644
index 0000000..f4403b8
--- /dev/null
+++ b/android-35/com/android/okhttp/internalandroidapi/HttpURLConnectionFactory.java
@@ -0,0 +1,194 @@
+/* GENERATED SOURCE. DO NOT MODIFY. */
+/*
+ * Copyright (C) 2017 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 com.android.okhttp.internalandroidapi;
+
+import com.android.okhttp.ConnectionPool;
+import com.android.okhttp.HttpHandler;
+import com.android.okhttp.HttpsHandler;
+import com.android.okhttp.OkHttpClient;
+import com.android.okhttp.OkUrlFactories;
+import com.android.okhttp.OkUrlFactory;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.Proxy;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.UnknownHostException;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import javax.net.SocketFactory;
+
+/**
+ * A way to construct {@link java.net.HttpURLConnection}s that supports some
+ * configuration on a per-factory or per-connection basis rather than only via
+ * global static state such as {@link java.net.CookieHandler#setDefault(java.net.CookieHandler)}.
+ * The per-factory configuration is <b>optional</b>; if not set, global
+ * configuration or default behavior is used.
+ *
+ * This facade prevents tight coupling with the underlying implementation (on
+ * top of a particular version of OkHttp). Android code outside of libcore
+ * should never depend directly on OkHttp.
+ *
+ * This abstraction is not suitable for general use. Talk to the maintainers of
+ * this class before modifying it or adding additional dependencies.
+ *
+ * @hide
+ * @hide This class is not part of the Android public SDK API
+ */
+public final class HttpURLConnectionFactory {
+
+    private ConnectionPool connectionPool;
+    private com.android.okhttp.Dns dns;
+
+    /** @hide */
+    public HttpURLConnectionFactory() {
+    }
+
+    /**
+     * Sets a new ConnectionPool, specific to this URLFactory and not shared with
+     * any other connections, with the given configuration.
+     *
+     * @hide
+     */
+    public void setNewConnectionPool(int maxIdleConnections, long keepAliveDuration,
+            TimeUnit timeUnit) {
+        this.connectionPool = new ConnectionPool(maxIdleConnections, keepAliveDuration, timeUnit);
+    }
+
+    /** @hide */
+    public void setDns(Dns dns) {
+        Objects.requireNonNull(dns);
+        this.dns = new DnsAdapter(dns);
+    }
+
+    /**
+     * Opens a connection that uses the system default proxy settings and SocketFactory.
+     *
+     * @hide
+     */
+    public URLConnection openConnection(URL url) throws IOException {
+        return internalOpenConnection(url, null /* socketFactory */, null /* proxy */);
+    }
+
+    /**
+     * Opens a connection that uses the system default SocketFactory and the specified
+     * proxy settings.
+     *
+     * @hide
+     */
+    public URLConnection openConnection(URL url, Proxy proxy) throws IOException {
+        Objects.requireNonNull(proxy);
+        return internalOpenConnection(url, null /* socketFactory */, proxy);
+    }
+
+    /**
+     * Opens a connection that uses the specified SocketFactory and the system default
+     * proxy settings.
+     *
+     * @hide
+     */
+    public URLConnection openConnection(URL url, SocketFactory socketFactory) throws IOException {
+        Objects.requireNonNull(socketFactory);
+        return internalOpenConnection(url, socketFactory, null /* proxy */);
+    }
+
+    /**
+     * Opens a connection using the specified SocketFactory and the specified proxy
+     * settings, overriding any system wide configuration.
+     *
+     * @hide
+     */
+    public URLConnection openConnection(URL url, SocketFactory socketFactory, Proxy proxy)
+            throws IOException {
+        Objects.requireNonNull(socketFactory);
+        Objects.requireNonNull(proxy);
+        return internalOpenConnection(url, socketFactory, proxy);
+    }
+
+    private URLConnection internalOpenConnection(URL url, SocketFactory socketFactoryOrNull,
+            Proxy proxyOrNull) throws IOException {
+        String protocol = url.getProtocol();
+        OkUrlFactory okUrlFactory;
+        // TODO: HttpHandler creates OkUrlFactory instances that share the default ResponseCache.
+        // Could this cause unexpected behavior?
+        if (protocol.equals("http")) {
+            okUrlFactory = HttpHandler.createHttpOkUrlFactory(proxyOrNull);
+        } else if (protocol.equals("https")) {
+            okUrlFactory = HttpsHandler.createHttpsOkUrlFactory(proxyOrNull);
+        } else {
+            // OkHttp only supports HTTP and HTTPS.
+            throw new MalformedURLException("Invalid URL or unrecognized protocol " + protocol);
+        }
+
+        OkHttpClient client = okUrlFactory.client();
+        if (connectionPool != null) {
+            client.setConnectionPool(connectionPool);
+        }
+        if (dns != null) {
+            client.setDns(dns);
+        }
+        if (socketFactoryOrNull != null) {
+            client.setSocketFactory(socketFactoryOrNull);
+        }
+        if (proxyOrNull == null) {
+            return okUrlFactory.open(url);
+        } else {
+            return OkUrlFactories.open(okUrlFactory, url, proxyOrNull);
+        }
+    }
+
+    /**
+     * Adapts a {@link Dns} as a {@link com.android.okhttp.Dns}.
+     *
+     * @hide
+     */
+    static final class DnsAdapter implements com.android.okhttp.Dns {
+        private final Dns adaptee;
+
+        DnsAdapter(Dns adaptee) {
+            this.adaptee = Objects.requireNonNull(adaptee);
+        }
+
+        @Override
+        public List<InetAddress> lookup(String hostname) throws UnknownHostException {
+            return adaptee.lookup(hostname);
+        }
+
+        @Override
+        public int hashCode() {
+            return 31 * DnsAdapter.class.hashCode() + adaptee.hashCode();
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (!(obj instanceof DnsAdapter)) {
+                return false;
+            }
+            return adaptee.equals(((DnsAdapter) obj).adaptee);
+        }
+
+        @Override
+        public String toString() {
+            return adaptee.toString();
+        }
+    }
+
+}