| java.lang.Object | |
| ↳ | org.chromium.net.CronetEngine |
An engine to process UrlRequests, which uses the best HTTP stack available on the current
platform. An instance of this class can be created using CronetEngine.Builder.
| Nested Classes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| CronetEngine.Builder | A builder for CronetEngines, which allows runtime configuration of CronetEngine. |
||||||||||
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int | ACTIVE_REQUEST_COUNT_UNKNOWN | The value of the active request count is unknown | |||||||||
| int | CONNECTION_METRIC_UNKNOWN | The value of a connection metric is unknown. | |||||||||
| int | EFFECTIVE_CONNECTION_TYPE_2G | The estimate of the effective connection type is 2G. | |||||||||
| int | EFFECTIVE_CONNECTION_TYPE_3G | The estimate of the effective connection type is 3G. | |||||||||
| int | EFFECTIVE_CONNECTION_TYPE_4G | The estimate of the effective connection type is 4G. | |||||||||
| int | EFFECTIVE_CONNECTION_TYPE_OFFLINE | The device is offline. | |||||||||
| int | EFFECTIVE_CONNECTION_TYPE_SLOW_2G | The estimate of the effective connection type is slow 2G. | |||||||||
| int | EFFECTIVE_CONNECTION_TYPE_UNKNOWN | The estimate of the effective connection type is unknown. | |||||||||
| long | UNBIND_NETWORK_HANDLE | The value to be used to undo any previous network binding. | |||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Registers a listener that gets called after the end of each request with the request info.
| |||||||||||
Registers a listener that gets called whenever the network quality estimator witnesses a
sample round trip time.
| |||||||||||
Registers a listener that gets called whenever the network quality estimator witnesses a
sample throughput measurement.
| |||||||||||
Binds the engine to the specified network handle.
| |||||||||||
Configures the network quality estimator for testing.
| |||||||||||
Creates a
URLStreamHandlerFactory to handle HTTP and HTTPS traffic. | |||||||||||
Returns the number of active requests.
| |||||||||||
Returns the downstream throughput estimate (in kilobits per second) computed by the network
quality estimator.
| |||||||||||
Returns an estimate of the effective connection type computed by the network quality
estimator.
| |||||||||||
Returns differences in metrics collected by Cronet since the last call to this method.
| |||||||||||
Returns the HTTP RTT estimate (in milliseconds) computed by the network quality estimator.
| |||||||||||
Returns the transport RTT estimate (in milliseconds) computed by the network quality
estimator.
| |||||||||||
Creates a builder for
UrlRequest. | |||||||||||
Establishes a new connection to the resource specified by the
URL url. | |||||||||||
Removes a finished request listener.
| |||||||||||
Removes a listener of round trip times if previously registered with
addRttListener(NetworkQualityRttListener). | |||||||||||
Removes a listener of throughput.
| |||||||||||
Shuts down the
CronetEngine if there are no active requests, otherwise throws an
exception. | |||||||||||
Starts NetLog logging to a specified directory with a bounded size.
| |||||||||||
Starts NetLog logging to a file.
| |||||||||||
Stops NetLog logging and flushes file to disk.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||||
The value of the active request count is unknown
The value of a connection metric is unknown.
The estimate of the effective connection type is 2G.
See also:
The estimate of the effective connection type is 3G.
See also:
The estimate of the effective connection type is 4G.
See also:
The estimate of the effective connection type is slow 2G.
See also:
The estimate of the effective connection type is unknown.
See also:
The value to be used to undo any previous network binding.
Registers a listener that gets called after the end of each request with the request info.
The listener is called on an Executor provided by the
listener.
| Parameters | |
|---|---|
listener |
RequestFinishedInfo.Listener: the listener for finished requests.
|
Registers a listener that gets called whenever the network quality estimator witnesses a
sample round trip time. This must be called after 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
Executor that is passed to enableNetworkQualityEstimator(boolean).
| Parameters | |
|---|---|
listener |
NetworkQualityRttListener: the listener of round trip times.
|
Registers a listener that gets called whenever the network quality estimator witnesses a
sample throughput measurement. This must be called after 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 Executor that is passed
to enableNetworkQualityEstimator(boolean).
| Parameters | |
|---|---|
listener |
NetworkQualityThroughputListener: the listener of throughput.
|
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 | |
|---|---|
networkHandle |
long: the network handle to bind the engine to. Specify UNBIND_NETWORK_HANDLE to unbind.
|
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 | |
|---|---|
useLocalHostRequests |
boolean: include requests to localhost in estimates. |
useSmallerResponses |
boolean: include small responses in throughput estimates. |
disableOfflineCheck |
boolean: when set to true, disables the device offline checks when
computing
the effective connection type or when writing the prefs.
|
Creates a URLStreamHandlerFactory to handle HTTP and HTTPS traffic. An instance of
this class can be installed via setURLStreamHandlerFactory(URLStreamHandlerFactory) thus using this
CronetEngine by default for all requests created via openConnection().
Cronet does not use certain HTTP features provided via the system:
HttpResponseCache.install()
setDefault(Authenticator)
setDefault(CookieHandler)
While Cronet supports and encourages requests using the HTTPS protocol, Cronet does not
provide support for the HttpsURLConnection API. This lack of support also includes
not using certain HTTPS features provided via the system:
HttpsURLConnection.setDefaultHostnameVerifier()
HttpsURLConnection.setDefaultSSLSocketFactory()
| Returns | |
|---|---|
URLStreamHandlerFactory |
an URLStreamHandlerFactory instance implemented by this CronetEngine.
|
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 for more information.
| Returns | |
|---|---|
int |
|
Returns the downstream throughput estimate (in kilobits per second) computed by the network
quality estimator. Set to CONNECTION_METRIC_UNKNOWN if the value is unavailable.
This must be called after enableNetworkQualityEstimator(boolean), and will throw an
exception otherwise.
| Returns | |
|---|---|
int |
Estimate of the downstream throughput in kilobits per second. |
Returns an estimate of the effective connection type computed by the network quality
estimator. Call enableNetworkQualityEstimator(boolean) to begin computing this value.
| Returns | |
|---|---|
int |
the estimated connection type. The returned value is one of EFFECTIVE_CONNECTION_TYPE_* .
|
Returns differences in metrics collected by Cronet since the last call to this method.
Cronet collects these metrics globally. This means deltas returned by getGlobalMetricsDeltas() will include measurements of requests processed by other CronetEngine instances. Since this function returns differences in metrics collected since
the last call, and these metrics are collected globally, a call to any CronetEngine
instance's getGlobalMetricsDeltas() method will affect the deltas returned by any
other
CronetEngine instance's getGlobalMetricsDeltas().
Cronet starts collecting these metrics after the first call to getGlobalMetricsDeltras(), so the first call returns no useful data as no metrics have yet
been collected.
| Returns | |
|---|---|
byte[] |
differences in metrics collected by Cronet, since the last call to getGlobalMetricsDeltas(), serialized as a protobuf
.
|
Returns the HTTP RTT estimate (in milliseconds) computed by the network quality estimator.
Set to CONNECTION_METRIC_UNKNOWN if the value is unavailable. This must be called
after
enableNetworkQualityEstimator(boolean), and will throw an exception otherwise.
| Returns | |
|---|---|
int |
Estimate of the HTTP RTT in milliseconds. |
Returns the transport RTT estimate (in milliseconds) computed by the network quality
estimator. Set to CONNECTION_METRIC_UNKNOWN if the value is unavailable. This must
be called after enableNetworkQualityEstimator(boolean), and will throw an exception
otherwise.
| Returns | |
|---|---|
int |
Estimate of the transport RTT in milliseconds. |
| Returns | |
|---|---|
String |
a human-readable version string of the engine. |
Creates a builder for UrlRequest. All callbacks for generated UrlRequest
objects will be invoked on executor's threads. executor must not run tasks on
the thread calling execute(Runnable) to prevent blocking networking operations and
causing exceptions during shutdown.
| Parameters | |
|---|---|
url |
String: URL for the generated requests. |
callback |
UrlRequest.Callback: callback object that gets invoked on different events. |
executor |
Executor: Executor on which all callbacks will be invoked.
|
| Returns | |
|---|---|
UrlRequest.Builder |
|
Establishes a new connection to the resource specified by the URL url.
Note: Cronet's HttpURLConnection implementation is subject to
certain limitations, see createURLStreamHandlerFactory() for details.
| Parameters | |
|---|---|
url |
URL: URL of resource to connect to. |
| Returns | |
|---|---|
URLConnection |
an HttpURLConnection instance implemented by this CronetEngine. |
| Throws | |
|---|---|
IOException |
if an error occurs while opening the connection. |
Removes a finished request listener.
| Parameters | |
|---|---|
listener |
RequestFinishedInfo.Listener: the listener to remove.
|
Removes a listener of round trip times if previously registered with addRttListener(NetworkQualityRttListener).
This should be called after a NetworkQualityRttListener is added in order to stop
receiving observations.
| Parameters | |
|---|---|
listener |
NetworkQualityRttListener: the listener of round trip times.
|
Removes a listener of throughput. This should be called after a NetworkQualityThroughputListener is added with addThroughputListener(NetworkQualityThroughputListener) in order to
stop receiving observations.
| Parameters | |
|---|---|
listener |
NetworkQualityThroughputListener: the listener of throughput.
|
Shuts down the 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.
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 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 | |
|---|---|
dirPath |
String: 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. |
logAll |
boolean: 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. |
maxSize |
int: the maximum total disk space in bytes that should be used by NetLog. Actual
disk
space usage may exceed this limit slightly.
|
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 | |
|---|---|
fileName |
String: 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. |
logAll |
boolean: 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.
|
Stops NetLog logging and flushes file to disk. If a logging session is not in progress, this call is ignored.