Commit b1b93069 by Oliver Woodman

Merge pull request #7324 from tpiDev:cronet/migrate-to-play-services-17-0-0

PiperOrigin-RevId: 310115628
parents 62e1000d 2cae3b39
......@@ -180,6 +180,10 @@
* IMA extension: Upgrade to IMA SDK version 3.18.1, and migrate to new
preloading APIs ([#6429](https://github.com/google/ExoPlayer/issues/6429)).
* OkHttp extension: Upgrade OkHttp dependency to 3.12.11.
* Cronet extension: Default to using the Cronet implementation in Google Play
Services rather than Cronet Embedded. This allows Cronet to be used with a
negligible increase in application size, compared to approximately 8MB when
embedding the library.
### 2.11.4 (2020-04-08)
......
......@@ -20,6 +20,10 @@ Alternatively, you can clone the ExoPlayer repository and depend on the module
locally. Instructions for doing this can be found in ExoPlayer's
[top level README][].
Note that by default, the extension will use the Cronet implementation in
Google Play Services. If you prefer, it's also possible to embed the Cronet
implementation directly into your application. See below for more details.
[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md
## Using the extension ##
......@@ -47,6 +51,46 @@ new DefaultDataSourceFactory(
```
respectively.
## Choosing between Google Play Services Cronet and Cronet Embedded ##
The underlying Cronet implementation is available both via a [Google Play
Services](https://developers.google.com/android/guides/overview) API, and as a
library that can be embedded directly into your application. When you depend on
`com.google.android.exoplayer:extension-cronet:2.X.X`, the library will _not_ be
embedded into your application by default. The extension will attempt to use the
Cronet implementation in Google Play Services. The benefits of this approach
are:
* A negligible increase in the size of your application.
* The Cronet implementation is updated automatically by Google Play Services.
If Google Play Services is not available on a device, `CronetDataSourceFactory`
will fall back to creating `DefaultHttpDataSource` instances, or
`HttpDataSource` instances created by a `fallbackFactory` that you can specify.
It's also possible to embed the Cronet implementation directly into your
application. To do this, add an additional gradle dependency to the Cronet
Embedded library:
```gradle
implementation 'com.google.android.exoplayer:extension-cronet:2.X.X'
implementation 'org.chromium.net:cronet-embedded:XX.XXXX.XXX'
```
where `XX.XXXX.XXX` is the version of the library that you wish to use. The
extension will automatically detect and use the library. Embedding will add
approximately 8MB to your application, however it may be suitable if:
* Your application is likely to be used in markets where Google Play Services is
not widely available.
* You want to control the exact version of the Cronet implementation being used.
If you do embed the library, you can specify which implementation should
be preferred if the Google Play Services implementation is also available. This
is controlled by a `preferGMSCoreCronet` parameter, which can be passed to the
`CronetEngineWrapper` constructor (GMS Core is another name for Google Play
Services).
## Links ##
* [Javadoc][]: Classes matching `com.google.android.exoplayer2.ext.cronet.*`
......
......@@ -31,7 +31,7 @@ android {
}
dependencies {
api 'org.chromium.net:cronet-embedded:76.3809.111'
api "com.google.android.gms:play-services-cronet:17.0.0"
implementation project(modulePrefix + 'library-core')
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
......
......@@ -48,6 +48,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
......@@ -57,7 +58,6 @@ import org.chromium.net.CronetEngine;
import org.chromium.net.NetworkException;
import org.chromium.net.UrlRequest;
import org.chromium.net.UrlResponseInfo;
import org.chromium.net.impl.UrlResponseInfoImpl;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -147,15 +147,62 @@ public final class CronetDataSourceTest {
private UrlResponseInfo createUrlResponseInfoWithUrl(String url, int statusCode) {
ArrayList<Map.Entry<String, String>> responseHeaderList = new ArrayList<>();
responseHeaderList.addAll(testResponseHeader.entrySet());
return new UrlResponseInfoImpl(
Collections.singletonList(url),
statusCode,
null, // httpStatusText
responseHeaderList,
false, // wasCached
null, // negotiatedProtocol
null); // proxyServer
Map<String, List<String>> responseHeaderMap = new HashMap<>();
for (Map.Entry<String, String> entry : testResponseHeader.entrySet()) {
responseHeaderList.add(entry);
responseHeaderMap.put(entry.getKey(), Collections.singletonList(entry.getValue()));
}
return new UrlResponseInfo() {
@Override
public String getUrl() {
return url;
}
@Override
public List<String> getUrlChain() {
return Collections.singletonList(url);
}
@Override
public int getHttpStatusCode() {
return statusCode;
}
@Override
public String getHttpStatusText() {
return null;
}
@Override
public List<Map.Entry<String, String>> getAllHeadersAsList() {
return responseHeaderList;
}
@Override
public Map<String, List<String>> getAllHeaders() {
return responseHeaderMap;
}
@Override
public boolean wasCached() {
return false;
}
@Override
public String getNegotiatedProtocol() {
return null;
}
@Override
public String getProxyServer() {
return null;
}
@Override
public long getReceivedByteCount() {
return 0;
}
};
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment