Stop setting custom user agent in demo app

PiperOrigin-RevId: 401741202
This commit is contained in:
olly 2021-10-08 12:40:30 +01:00 committed by bachinger
parent e66f9fafe1
commit b03ebbeb89
2 changed files with 26 additions and 16 deletions

View File

@ -16,9 +16,7 @@
package com.google.android.exoplayer2.demo; package com.google.android.exoplayer2.demo;
import android.content.Context; import android.content.Context;
import android.os.Build;
import com.google.android.exoplayer2.DefaultRenderersFactory; import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.RenderersFactory; import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.database.DatabaseProvider; import com.google.android.exoplayer2.database.DatabaseProvider;
import com.google.android.exoplayer2.database.ExoDatabaseProvider; 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 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 TAG = "DemoUtil";
private static final String DOWNLOAD_ACTION_FILE = "actions"; private static final String DOWNLOAD_ACTION_FILE = "actions";
private static final String DOWNLOAD_TRACKER_ACTION_FILE = "tracked_actions"; private static final String DOWNLOAD_TRACKER_ACTION_FILE = "tracked_actions";
@ -104,9 +95,7 @@ public final class DemoUtil {
if (httpDataSourceFactory == null) { if (httpDataSourceFactory == null) {
if (USE_CRONET_FOR_NETWORKING) { if (USE_CRONET_FOR_NETWORKING) {
context = context.getApplicationContext(); context = context.getApplicationContext();
@Nullable @Nullable CronetEngine cronetEngine = CronetUtil.buildCronetEngine(context);
CronetEngine cronetEngine =
CronetUtil.buildCronetEngine(context, USER_AGENT, /* preferGMSCoreCronet= */ false);
if (cronetEngine != null) { if (cronetEngine != null) {
httpDataSourceFactory = httpDataSourceFactory =
new CronetDataSource.Factory(cronetEngine, Executors.newSingleThreadExecutor()); new CronetDataSource.Factory(cronetEngine, Executors.newSingleThreadExecutor());
@ -117,7 +106,7 @@ public final class DemoUtil {
CookieManager cookieManager = new CookieManager(); CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
CookieHandler.setDefault(cookieManager); CookieHandler.setDefault(cookieManager);
httpDataSourceFactory = new DefaultHttpDataSource.Factory().setUserAgent(USER_AGENT); httpDataSourceFactory = new DefaultHttpDataSource.Factory();
} }
} }
return httpDataSourceFactory; return httpDataSourceFactory;

View File

@ -35,9 +35,30 @@ public final class CronetUtil {
private static final String TAG = "CronetUtil"; private static final String TAG = "CronetUtil";
/** /**
* Builds a {@link CronetEngine} suitable for use with ExoPlayer. When choosing a {@link * Builds a {@link CronetEngine} suitable for use with {@link CronetDataSource}. When choosing a
* CronetProvider Cronet provider} to build the {@link CronetEngine}, disabled providers are not * {@link CronetProvider Cronet provider} to build the {@link CronetEngine}, disabled providers
* considered. Neither are fallback providers, since it's more efficient to use {@link * 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}.
*
* <p>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 <a
* href="https://developer.android.com/guide/topics/connectivity/cronet/start">Android developer
* guide</a> 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 * DefaultHttpDataSource} than it is to use {@link CronetDataSource} with a fallback {@link
* CronetEngine}. * CronetEngine}.
* *