diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoUtil.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoUtil.java index dc283ddfe6..a4193184bc 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoUtil.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoUtil.java @@ -16,9 +16,7 @@ package com.google.android.exoplayer2.demo; import android.content.Context; -import android.os.Build; import com.google.android.exoplayer2.DefaultRenderersFactory; -import com.google.android.exoplayer2.ExoPlayerLibraryInfo; import com.google.android.exoplayer2.RenderersFactory; import com.google.android.exoplayer2.database.DatabaseProvider; import com.google.android.exoplayer2.database.ExoDatabaseProvider; @@ -61,13 +59,6 @@ public final class DemoUtil { */ private static final boolean USE_CRONET_FOR_NETWORKING = true; - private static final String USER_AGENT = - "ExoPlayerDemo/" - + ExoPlayerLibraryInfo.VERSION - + " (Linux; Android " - + Build.VERSION.RELEASE - + ") " - + ExoPlayerLibraryInfo.VERSION_SLASHY; private static final String TAG = "DemoUtil"; private static final String DOWNLOAD_ACTION_FILE = "actions"; private static final String DOWNLOAD_TRACKER_ACTION_FILE = "tracked_actions"; @@ -104,9 +95,7 @@ public final class DemoUtil { if (httpDataSourceFactory == null) { if (USE_CRONET_FOR_NETWORKING) { context = context.getApplicationContext(); - @Nullable - CronetEngine cronetEngine = - CronetUtil.buildCronetEngine(context, USER_AGENT, /* preferGMSCoreCronet= */ false); + @Nullable CronetEngine cronetEngine = CronetUtil.buildCronetEngine(context); if (cronetEngine != null) { httpDataSourceFactory = new CronetDataSource.Factory(cronetEngine, Executors.newSingleThreadExecutor()); @@ -117,7 +106,7 @@ public final class DemoUtil { CookieManager cookieManager = new CookieManager(); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER); CookieHandler.setDefault(cookieManager); - httpDataSourceFactory = new DefaultHttpDataSource.Factory().setUserAgent(USER_AGENT); + httpDataSourceFactory = new DefaultHttpDataSource.Factory(); } } return httpDataSourceFactory; diff --git a/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetUtil.java b/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetUtil.java index b448c67e2d..3be1f6671f 100644 --- a/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetUtil.java +++ b/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetUtil.java @@ -35,9 +35,30 @@ public final class CronetUtil { private static final String TAG = "CronetUtil"; /** - * Builds a {@link CronetEngine} suitable for use with ExoPlayer. When choosing a {@link - * CronetProvider Cronet provider} to build the {@link CronetEngine}, disabled providers are not - * considered. Neither are fallback providers, since it's more efficient to use {@link + * Builds a {@link CronetEngine} suitable for use with {@link CronetDataSource}. When choosing a + * {@link CronetProvider Cronet provider} to build the {@link CronetEngine}, disabled providers + * are not considered. Neither are fallback providers, since it's more efficient to use {@link + * DefaultHttpDataSource} than it is to use {@link CronetDataSource} with a fallback {@link + * CronetEngine}. + * + *
Note that it's recommended for applications to create only one instance of {@link + * CronetEngine}, so if your application already has an instance for performing other networking, + * then that instance should be used and calling this method is unnecessary. See the Android developer + * guide to learn more about using Cronet for network operations. + * + * @param context A context. + * @return The {@link CronetEngine}, or {@code null} if no suitable engine could be built. + */ + @Nullable + public static CronetEngine buildCronetEngine(Context context) { + return buildCronetEngine(context, /* userAgent= */ null, /* preferGooglePlayServices= */ false); + } + + /** + * Builds a {@link CronetEngine} suitable for use with {@link CronetDataSource}. When choosing a + * {@link CronetProvider Cronet provider} to build the {@link CronetEngine}, disabled providers + * are not considered. Neither are fallback providers, since it's more efficient to use {@link * DefaultHttpDataSource} than it is to use {@link CronetDataSource} with a fallback {@link * CronetEngine}. *