1 // Copyright 2016 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 package android.net.http; 5 6 import java.time.Instant; 7 import java.util.Collections; 8 import java.util.Set; 9 10 /** 11 * Defines methods that the actual implementation of {@link HttpEngine.Builder} has to implement. 12 * {@link HttpEngine.Builder} uses this interface to delegate the calls. 13 * For the documentation of individual methods, please see the identically named methods in 14 * {@link HttpEngine.Builder} and 15 * {@link ExperimentalHttpEngine.Builder}. 16 * 17 * <p>{@hide internal class} 18 */ 19 public abstract class IHttpEngineBuilder { 20 // The fields below list values which are known to getSupportedConfigOptions(). 21 // 22 // Given the fields are final the constant value associated with them is compiled into 23 // class using them. This makes it safe for all implementation to use the field in their code 24 // and not worry about version skew (new implementation aware of values the old API is not), 25 // as long as the values don't change meaning. This isn't true of enums and other dynamic 26 // structures, hence we resort to plain old good ints. 27 public static final int CONNECTION_MIGRATION_OPTIONS = 1; 28 public static final int DNS_OPTIONS = 2; 29 public static final int QUIC_OPTIONS = 3; 30 31 // Public API methods. addPublicKeyPins(String hostName, Set<byte[]> pinsSha256, boolean includeSubdomains, Instant expirationInstant)32 public abstract IHttpEngineBuilder addPublicKeyPins(String hostName, Set<byte[]> pinsSha256, 33 boolean includeSubdomains, Instant expirationInstant); 34 addQuicHint(String host, int port, int alternatePort)35 public abstract IHttpEngineBuilder addQuicHint(String host, int port, int alternatePort); 36 enableHttp2(boolean value)37 public abstract IHttpEngineBuilder enableHttp2(boolean value); 38 enableHttpCache(int cacheMode, long maxSize)39 public abstract IHttpEngineBuilder enableHttpCache(int cacheMode, long maxSize); 40 enablePublicKeyPinningBypassForLocalTrustAnchors( boolean value)41 public abstract IHttpEngineBuilder enablePublicKeyPinningBypassForLocalTrustAnchors( 42 boolean value); 43 enableQuic(boolean value)44 public abstract IHttpEngineBuilder enableQuic(boolean value); 45 enableSdch(boolean value)46 public abstract IHttpEngineBuilder enableSdch(boolean value); 47 enableBrotli(boolean value)48 public IHttpEngineBuilder enableBrotli(boolean value) { 49 // Do nothing for older implementations. 50 return this; 51 } 52 setQuicOptions(QuicOptions quicOptions)53 public IHttpEngineBuilder setQuicOptions(QuicOptions quicOptions) { 54 return this; 55 } 56 setDnsOptions(DnsOptions dnsOptions)57 public IHttpEngineBuilder setDnsOptions(DnsOptions dnsOptions) { 58 return this; 59 } 60 setConnectionMigrationOptions( ConnectionMigrationOptions connectionMigrationOptions)61 public IHttpEngineBuilder setConnectionMigrationOptions( 62 ConnectionMigrationOptions connectionMigrationOptions) { 63 return this; 64 } 65 setExperimentalOptions(String options)66 public abstract IHttpEngineBuilder setExperimentalOptions(String options); setStoragePath(String value)67 public abstract IHttpEngineBuilder setStoragePath(String value); 68 setUserAgent(String userAgent)69 public abstract IHttpEngineBuilder setUserAgent(String userAgent); 70 getDefaultUserAgent()71 public abstract String getDefaultUserAgent(); 72 build()73 public abstract ExperimentalHttpEngine build(); 74 75 /** 76 * Returns the set of configuration options the builder is able to support natively. This is 77 * used internally to emulate newly added functionality using older APIs where possible. 78 * 79 * <p>The default implementation returns an empty set. Subclasses should override this method to 80 * reflect the supported options that are applicable to them. 81 */ getSupportedConfigOptions()82 protected Set<Integer> getSupportedConfigOptions() { 83 return Collections.emptySet(); 84 } 85 86 // Experimental API methods. 87 // 88 // Note: all experimental API methods should have default implementation. This will allow 89 // removing the experimental methods from the implementation layer without breaking 90 // the client. 91 enableNetworkQualityEstimator(boolean value)92 public IHttpEngineBuilder enableNetworkQualityEstimator(boolean value) { 93 return this; 94 } 95 setThreadPriority(int priority)96 public IHttpEngineBuilder setThreadPriority(int priority) { 97 return this; 98 } 99 }