# JavaCronetEngine


```
public final class JavaCronetEngine extends CronetEngineBase
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||||
| ↳ | [org.chromium.net.CronetEngine](https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine) |||
|   | ↳ | [org.chromium.net.impl.CronetEngineBase](https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/CronetEngineBase) ||
|   |   | ↳ | [org.chromium.net.impl.JavaCronetEngine](https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine) |

*** ** * ** ***

`https://developer.android.com/reference/java/net/HttpURLConnection.html` backed CronetEngine.

Does not support netlogs, transferred data measurement, bidistream, cache, or priority.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#JavaCronetEngine(org.chromium.net.impl.CronetEngineBuilderImpl)(https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/CronetEngineBuilderImpl builder)` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#addRequestFinishedListener(org.chromium.net.RequestFinishedInfo.Listener)(https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/RequestFinishedInfo.Listener listener)` Registers a listener that gets called after the end of each request with the request info. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#addRttListener(org.chromium.net.NetworkQualityRttListener)(https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkQualityRttListener listener)` Registers a listener that gets called whenever the network quality estimator witnesses a sample round trip time. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#addThroughputListener(org.chromium.net.NetworkQualityThroughputListener)(https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkQualityThroughputListener listener)` Registers a listener that gets called whenever the network quality estimator witnesses a sample throughput measurement. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#bindToNetwork(long)(long networkHandle)` Binds the engine to the specified network handle. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#configureNetworkQualityEstimatorForTesting(boolean,boolean,boolean)( boolean useLocalHostRequests, boolean useSmallerResponses, boolean disableOfflineCheck )` Configures the network quality estimator for testing. |
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/ExperimentalUrlRequest` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#createRequest(java.lang.String,org.chromium.net.UrlRequest.Callback,java.util.concurrent.Executor,int,java.util.Collection<java.lang.Object>,boolean,boolean,boolean,boolean,int,boolean,int,org.chromium.net.RequestFinishedInfo.Listener,int,long,java.lang.String,java.util.ArrayList<java.util.Map.Entry<java.lang.String,java.lang.String>>,org.chromium.net.UploadDataProvider,java.util.concurrent.Executor,byte[],java.nio.ByteBuffer,java.lang.String)( https://developer.android.com/reference/java/lang/String.html url, https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest.Callback callback, https://developer.android.com/reference/java/util/concurrent/Executor.html executor, int priority, https://developer.android.com/reference/java/util/Collection.html<https://developer.android.com/reference/java/lang/Object.html> connectionAnnotations, boolean disableCache, boolean disableConnectionMigration, boolean allowDirectExecutor, boolean trafficStatsTagSet, int trafficStatsTag, boolean trafficStatsUidSet, int trafficStatsUid, https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/RequestFinishedInfo.Listener requestFinishedListener, int idempotency, long networkHandle, https://developer.android.com/reference/java/lang/String.html method, https://developer.android.com/reference/java/util/ArrayList.html<https://developer.android.com/reference/java/util/Map.Entry.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html>> requestHeaders, https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/UploadDataProvider uploadDataProvider, https://developer.android.com/reference/java/util/concurrent/Executor.html uploadDataProviderExecutor, byte[] sharedDictionaryHash, https://developer.android.com/reference/java/nio/ByteBuffer.html sharedDictionary, @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html sharedDictionaryId )` |
| `https://developer.android.com/reference/java/net/URLStreamHandlerFactory.html` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#createURLStreamHandlerFactory()()` Creates a `https://developer.android.com/reference/java/net/URLStreamHandlerFactory.html` to handle HTTP and HTTPS traffic. |
| `int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#getActiveRequestCount()()` Returns the number of active requests. |
| `int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#getDownstreamThroughputKbps()()` Returns the downstream throughput estimate (in kilobits per second) computed by the network quality estimator. |
| `int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#getEffectiveConnectionType()()` Returns an estimate of the effective connection type computed by the network quality estimator. |
| `byte[]` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#getGlobalMetricsDeltas()()` **This method is deprecated.** In modern versions of Cronet, this will always return an empty array. <br /> |
| `int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#getHttpRttMs()()` Returns the HTTP RTT estimate (in milliseconds) computed by the network quality estimator. |
| `int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#getTransportRttMs()()` Returns the transport RTT estimate (in milliseconds) computed by the network quality estimator. |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#getVersionString()()` |
| `https://developer.android.com/reference/java/net/URLConnection.html` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#openConnection(java.net.URL)(https://developer.android.com/reference/java/net/URL.html url)` Establishes a new connection to the resource specified by the `https://developer.android.com/reference/java/net/URL.html``url`. |
| `https://developer.android.com/reference/java/net/URLConnection.html` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#openConnection(java.net.URL,java.net.Proxy)(https://developer.android.com/reference/java/net/URL.html url, https://developer.android.com/reference/java/net/Proxy.html proxy)` Establishes a new connection to the resource specified by the `https://developer.android.com/reference/java/net/URL.html``url` using the given proxy. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#removeRequestFinishedListener(org.chromium.net.RequestFinishedInfo.Listener)(https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/RequestFinishedInfo.Listener listener)` Removes a finished request listener. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#removeRttListener(org.chromium.net.NetworkQualityRttListener)(https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkQualityRttListener listener)` Removes a listener of round trip times if previously registered with `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#addRttListener(org.chromium.net.NetworkQualityRttListener)`. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#removeThroughputListener(org.chromium.net.NetworkQualityThroughputListener)(https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkQualityThroughputListener listener)` Removes a listener of throughput. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#shutdown()()` Shuts down the `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine` if there are no active requests, otherwise throws an exception. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#startNetLogToDisk(java.lang.String,boolean,int)(https://developer.android.com/reference/java/lang/String.html dirPath, boolean logAll, int maxSize)` Starts NetLog logging to a specified directory with a bounded size. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#startNetLogToFile(java.lang.String,boolean)(https://developer.android.com/reference/java/lang/String.html fileName, boolean logAll)` Starts NetLog logging to a file. |
| `void` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#stopNetLog()()` Stops NetLog logging and flushes file to disk. |

| ### Protected methods |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/ExperimentalBidirectionalStream` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/JavaCronetEngine#createBidirectionalStream(java.lang.String,org.chromium.net.BidirectionalStream.Callback,java.util.concurrent.Executor,java.lang.String,java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>>,int,boolean,java.util.Collection<java.lang.Object>,boolean,int,boolean,int,long)( https://developer.android.com/reference/java/lang/String.html url, https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/BidirectionalStream.Callback callback, https://developer.android.com/reference/java/util/concurrent/Executor.html executor, https://developer.android.com/reference/java/lang/String.html httpMethod, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/util/Map.Entry.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html>> requestHeaders, @https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/CronetEngineBase.StreamPriority int priority, boolean delayRequestHeadersUntilFirstFlush, https://developer.android.com/reference/java/util/Collection.html<https://developer.android.com/reference/java/lang/Object.html> connectionAnnotations, boolean trafficStatsTagSet, int trafficStatsTag, boolean trafficStatsUidSet, int trafficStatsUid, long networkHandle )` |

| ### Inherited Constants |
|---|
| From [org.chromium.net.CronetEngine](https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine) |---|---| | `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#ACTIVE_REQUEST_COUNT_UNKNOWN() = -1` The value of the active request count is unknown | |
| From [org.chromium.net.impl.CronetEngineBase](https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/CronetEngineBase) |---|---| | `static final long` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/CronetEngineBase#DEFAULT_NETWORK_HANDLE() = -1` | |

| ### Inherited methods |
|---|
| From [org.chromium.net.impl.CronetEngineBase](https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/CronetEngineBase) |---|---| | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/ExperimentalUrlRequest.Builder` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/impl/CronetEngineBase#newUrlRequestBuilder(java.lang.String,org.chromium.net.UrlRequest.Callback,java.util.concurrent.Executor)( https://developer.android.com/reference/java/lang/String.html url, https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest.Callback callback, https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Creates a builder for `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest`. | |

## Public constructors

### JavaCronetEngine

```
public JavaCronetEngine(CronetEngineBuilderImpl builder)
```

## Public methods

### addRequestFinishedListener

```
public void addRequestFinishedListener(RequestFinishedInfo.Listener listener)
```

Registers a listener that gets called after the end of each request with the request info.

The listener is called on an `https://developer.android.com/reference/java/util/concurrent/Executor.html` provided by the listener.

| Parameters |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/RequestFinishedInfo.Listener listener` | the listener for finished requests. |

### addRttListener

```
public void addRttListener(NetworkQualityRttListener listener)
```

Registers a listener that gets called whenever the network quality estimator witnesses a sample round trip time. This must be called after `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.Builder#enableNetworkQualityEstimator(boolean)`, and with throw an exception otherwise. Round trip times may be recorded at various layers of the network stack, including TCP, QUIC, and at the URL request layer. The listener is called on the `https://developer.android.com/reference/java/util/concurrent/Executor.html` that is passed to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.Builder#enableNetworkQualityEstimator(boolean)`.

| Parameters |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkQualityRttListener listener` | the listener of round trip times. |

### addThroughputListener

```
public void addThroughputListener(NetworkQualityThroughputListener listener)
```

Registers a listener that gets called whenever the network quality estimator witnesses a sample throughput measurement. This must be called after `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.Builder#enableNetworkQualityEstimator(boolean)`. Throughput observations are computed by measuring bytes read over the active network interface at times when at least one URL response is being received. The listener is called on the `https://developer.android.com/reference/java/util/concurrent/Executor.html` that is passed to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.Builder#enableNetworkQualityEstimator(boolean)`.

| Parameters |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkQualityThroughputListener listener` | the listener of throughput. |

### bindToNetwork

```
public void bindToNetwork(long networkHandle)
```

Binds the engine to the specified network handle. All requests created through this engine will use the network associated to this handle. If this network disconnects all requests will fail, the exact error will depend on the stage of request processing when the network disconnects. Network handles can be obtained through `Network#getNetworkHandle`. Only available starting from Android Marshmallow.

| Parameters |
|---|---|
| `long networkHandle` | the network handle to bind the engine to. Specify `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#UNBIND_NETWORK_HANDLE()` to unbind. |

### configureNetworkQualityEstimatorForTesting

```
public void configureNetworkQualityEstimatorForTesting(
    boolean useLocalHostRequests,
    boolean useSmallerResponses,
    boolean disableOfflineCheck
)
```

Configures the network quality estimator for testing. This must be called before round trip time and throughput listeners are added, and after the network quality estimator has been enabled.

| Parameters |
|---|---|
| `boolean useLocalHostRequests` | include requests to localhost in estimates. |
| `boolean useSmallerResponses` | include small responses in throughput estimates. |
| `boolean disableOfflineCheck` | when set to true, disables the device offline checks when computing the effective connection type or when writing the prefs. |

### createRequest

```
public ExperimentalUrlRequest createRequest(
    String url,
    UrlRequest.Callback callback,
    Executor executor,
    int priority,
    Collection<Object> connectionAnnotations,
    boolean disableCache,
    boolean disableConnectionMigration,
    boolean allowDirectExecutor,
    boolean trafficStatsTagSet,
    int trafficStatsTag,
    boolean trafficStatsUidSet,
    int trafficStatsUid,
    RequestFinishedInfo.Listener requestFinishedListener,
    int idempotency,
    long networkHandle,
    String method,
    ArrayList<Map.Entry<String, String>> requestHeaders,
    UploadDataProvider uploadDataProvider,
    Executor uploadDataProviderExecutor,
    byte[] sharedDictionaryHash,
    ByteBuffer sharedDictionary,
    @NonNull String sharedDictionaryId
)
```

### createURLStreamHandlerFactory

```
public URLStreamHandlerFactory createURLStreamHandlerFactory()
```

Creates a `https://developer.android.com/reference/java/net/URLStreamHandlerFactory.html` to handle HTTP and HTTPS traffic. An instance of this class can be installed via `https://developer.android.com/reference/java/net/URL.html#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory)` thus using this CronetEngine by default for all requests created via openConnection.

Cronet does not use certain HTTP features provided via the system:

- the HTTP cache installed via `https://developer.android.com/reference/android/net/http/HttpResponseCache.html#install(java.io.File, long)`
- the HTTP authentication method installed via `https://developer.android.com/reference/java/net/Authenticator.html#setDefault(java.net.Authenticator)`
- the HTTP cookie storage installed via `https://developer.android.com/reference/java/net/CookieHandler.html#setDefault(java.net.CookieHandler)`

While Cronet supports and encourages requests using the HTTPS protocol, Cronet does not provide support for the `https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html` API. This lack of support also includes not using certain HTTPS features provided via the system:

- the HTTPS hostname verifier installed via `https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html#setDefaultHostnameVerifier(javax.net.ssl.HostnameVerifier)`
- the HTTPS socket factory installed via `https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html#setDefaultSSLSocketFactory(javax.net.ssl.SSLSocketFactory)`

| Returns |
|---|---|
| `https://developer.android.com/reference/java/net/URLStreamHandlerFactory.html` | an `https://developer.android.com/reference/java/net/URLStreamHandlerFactory.html` instance implemented by this CronetEngine. |

### getActiveRequestCount

```
public int getActiveRequestCount()
```

Returns the number of active requests.

A request becomes "active" in UrlRequest.start(), assuming that method does not throw an exception. It becomes inactive when all callbacks have returned and no additional callbacks can be triggered in the future. In practice, that means the request is inactive once onSucceeded/onCanceled/onFailed has returned and all request finished listeners have returned. [Cronet requests's lifecycle](https://developer.android.com/guide/topics/connectivity/cronet/lifecycle) for more information.

### getDownstreamThroughputKbps

```
public int getDownstreamThroughputKbps()
```

Returns the downstream throughput estimate (in kilobits per second) computed by the network quality estimator. Set to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#CONNECTION_METRIC_UNKNOWN()` if the value is unavailable. This must be called after `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.Builder#enableNetworkQualityEstimator(boolean)`, and will throw an exception otherwise.

| Returns |
|---|---|
| `int` | Estimate of the downstream throughput in kilobits per second. |

### getEffectiveConnectionType

```
public int getEffectiveConnectionType()
```

Returns an estimate of the effective connection type computed by the network quality estimator. Call `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.Builder#enableNetworkQualityEstimator(boolean)` to begin computing this value.

| Returns |
|---|---|
| `int` | the estimated connection type. The returned value is one of `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#EFFECTIVE_CONNECTION_TYPE_UNKNOWN()`. |

### getGlobalMetricsDeltas

```
public byte[] getGlobalMetricsDeltas()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> In modern versions of Cronet, this will always return an empty array. In older versions, this used to return a serialized protobuf containing metrics data.

### getHttpRttMs

```
public int getHttpRttMs()
```

Returns the HTTP RTT estimate (in milliseconds) computed by the network quality estimator. Set to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#CONNECTION_METRIC_UNKNOWN()` if the value is unavailable. This must be called after `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.Builder#enableNetworkQualityEstimator(boolean)`, and will throw an exception otherwise.

| Returns |
|---|---|
| `int` | Estimate of the HTTP RTT in milliseconds. |

### getTransportRttMs

```
public int getTransportRttMs()
```

Returns the transport RTT estimate (in milliseconds) computed by the network quality estimator. Set to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#CONNECTION_METRIC_UNKNOWN()` if the value is unavailable. This must be called after `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine.Builder#enableNetworkQualityEstimator(boolean)`, and will throw an exception otherwise.

| Returns |
|---|---|
| `int` | Estimate of the transport RTT in milliseconds. |

### getVersionString

```
public String getVersionString()
```

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | a human-readable version string of the engine. |

### openConnection

```
public URLConnection openConnection(URL url)
```

Establishes a new connection to the resource specified by the `https://developer.android.com/reference/java/net/URL.html``url`.

**Note:** Cronet's `https://developer.android.com/reference/java/net/HttpURLConnection.html` implementation is subject to certain limitations, see `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#createURLStreamHandlerFactory()` for details.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/net/URL.html url` | URL of resource to connect to. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/net/URLConnection.html` | an `https://developer.android.com/reference/java/net/HttpURLConnection.html` instance implemented by this CronetEngine. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | if an error occurs while opening the connection. |

### openConnection

```
public URLConnection openConnection(URL url, Proxy proxy)
```

Establishes a new connection to the resource specified by the `https://developer.android.com/reference/java/net/URL.html``url` using the given proxy.

**Note:** Cronet's `https://developer.android.com/reference/java/net/HttpURLConnection.html` implementation is subject to certain limitations, see `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#createURLStreamHandlerFactory()` for details.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/net/URL.html url` | URL of resource to connect to. |
| `https://developer.android.com/reference/java/net/Proxy.html proxy` | proxy to use when establishing connection. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/net/URLConnection.html` | an `https://developer.android.com/reference/java/net/HttpURLConnection.html` instance implemented by this CronetEngine. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | if an error occurs while opening the connection. |

### removeRequestFinishedListener

```
public void removeRequestFinishedListener(RequestFinishedInfo.Listener listener)
```

Removes a finished request listener.

| Parameters |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/RequestFinishedInfo.Listener listener` | the listener to remove. |

### removeRttListener

```
public void removeRttListener(NetworkQualityRttListener listener)
```

Removes a listener of round trip times if previously registered with `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#addRttListener(org.chromium.net.NetworkQualityRttListener)`. This should be called after a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkQualityRttListener` is added in order to stop receiving observations.

| Parameters |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkQualityRttListener listener` | the listener of round trip times. |

### removeThroughputListener

```
public void removeThroughputListener(NetworkQualityThroughputListener listener)
```

Removes a listener of throughput. This should be called after a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkQualityThroughputListener` is added with `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#addThroughputListener(org.chromium.net.NetworkQualityThroughputListener)` in order to stop receiving observations.

| Parameters |
|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkQualityThroughputListener listener` | the listener of throughput. |

### shutdown

```
public void shutdown()
```

Shuts down the `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine` if there are no active requests, otherwise throws an exception.

Cannot be called on network thread - the thread Cronet calls into Executor on (which is different from the thread the Executor invokes callbacks on). May block until all the `
CronetEngine`'s resources have been cleaned up.

### startNetLogToDisk

```
public void startNetLogToDisk(String dirPath, boolean logAll, int maxSize)
```

Starts NetLog logging to a specified directory with a bounded size. The NetLog will contain events emitted by all live CronetEngines. The NetLog is useful for debugging. Once logging has stopped `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetEngine#stopNetLog()`, the data will be written to netlog.json in `dirPath`. If logging is interrupted, you can stitch the files found in .inprogress subdirectory manually using: https://chromium.googlesource.com/chromium/src/+/main/net/tools/stitch_net_log_files.py. The log can be viewed using a Chrome browser navigated to chrome://net-internals/#import.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html dirPath` | the directory where the netlog.json file will be created. dirPath must already exist. NetLog files must not exist in the directory. If actively logging, this method is ignored. |
| `boolean logAll` | `true` to include basic events, user cookies, credentials and all transferred bytes in the log. This option presents a privacy risk, since it exposes the user's credentials, and should only be used with the user's consent and in situations where the log won't be public. `false` to just include basic events. |
| `int maxSize` | the maximum total disk space in bytes that should be used by NetLog. Actual disk space usage may exceed this limit slightly. |

### startNetLogToFile

```
public void startNetLogToFile(String fileName, boolean logAll)
```

Starts NetLog logging to a file. The NetLog will contain events emitted by all live CronetEngines. The NetLog is useful for debugging. The file can be viewed using a Chrome browser navigated to chrome://net-internals/#import

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html fileName` | the complete file path. It must not be empty. If the file exists, it is truncated before starting. If actively logging, this method is ignored. |
| `boolean logAll` | `true` to include basic events, user cookies, credentials and all transferred bytes in the log. This option presents a privacy risk, since it exposes the user's credentials, and should only be used with the user's consent and in situations where the log won't be public. `false` to just include basic events. |

### stopNetLog

```
public void stopNetLog()
```

Stops NetLog logging and flushes file to disk. If a logging session is not in progress, this call is ignored.

## Protected methods

### createBidirectionalStream

```
protected ExperimentalBidirectionalStream createBidirectionalStream(
    String url,
    BidirectionalStream.Callback callback,
    Executor executor,
    String httpMethod,
    List<Map.Entry<String, String>> requestHeaders,
    @CronetEngineBase.StreamPriority int priority,
    boolean delayRequestHeadersUntilFirstFlush,
    Collection<Object> connectionAnnotations,
    boolean trafficStatsTagSet,
    int trafficStatsTag,
    boolean trafficStatsUidSet,
    int trafficStatsUid,
    long networkHandle
)
```