Remove DemoUtil.ALLOW_CRONET_FOR_NETWORKING

This boolean only exists to be changed in source, but it is now used
as part of a 3-way fallback logic (since adding `HttpEngine`
integration), so it's not really more convenient or clearer to change
this constant than just hack the code of `getHttpDataSourceFactory`
directly.

PiperOrigin-RevId: 677834348
This commit is contained in:
ibaker 2024-09-23 09:53:26 -07:00 committed by Copybara-Service
parent b4436c523c
commit 869a91bba8

View File

@ -50,16 +50,6 @@ public final class DemoUtil {
public static final String DOWNLOAD_NOTIFICATION_CHANNEL_ID = "download_channel"; public static final String DOWNLOAD_NOTIFICATION_CHANNEL_ID = "download_channel";
/**
* Whether the demo application uses Cronet for networking when {@link HttpEngine} is not
* supported. Note that Cronet does not provide automatic support for cookies
* (https://github.com/google/ExoPlayer/issues/5975).
*
* <p>If set to false, the {@link DefaultHttpDataSource} is used with a {@link CookieManager}
* configured in {@link #getHttpDataSourceFactory} when {@link HttpEngine} is not supported.
*/
private static final boolean ALLOW_CRONET_FOR_NETWORKING = true;
private static final String TAG = "DemoUtil"; private static final String TAG = "DemoUtil";
private static final String DOWNLOAD_CONTENT_DIRECTORY = "downloads"; private static final String DOWNLOAD_CONTENT_DIRECTORY = "downloads";
@ -114,16 +104,13 @@ public final class DemoUtil {
new HttpEngineDataSource.Factory(httpEngine, Executors.newSingleThreadExecutor()); new HttpEngineDataSource.Factory(httpEngine, Executors.newSingleThreadExecutor());
return httpDataSourceFactory; return httpDataSourceFactory;
} }
if (ALLOW_CRONET_FOR_NETWORKING) { @Nullable CronetEngine cronetEngine = CronetUtil.buildCronetEngine(context);
@Nullable CronetEngine cronetEngine = CronetUtil.buildCronetEngine(context); if (cronetEngine != null) {
if (cronetEngine != null) { httpDataSourceFactory =
httpDataSourceFactory = new CronetDataSource.Factory(cronetEngine, Executors.newSingleThreadExecutor());
new CronetDataSource.Factory(cronetEngine, Executors.newSingleThreadExecutor()); return httpDataSourceFactory;
return httpDataSourceFactory;
}
} }
// The device doesn't support HttpEngine or we don't want to allow Cronet, or we failed to // The device doesn't support HttpEngine and we failed to instantiate a CronetEngine.
// instantiate a CronetEngine.
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);