From 91633e6ae3ca0a41652154f99477dc757981fd88 Mon Sep 17 00:00:00 2001 From: okunhardt Date: Mon, 8 Jul 2024 06:10:32 -0700 Subject: [PATCH] Update HttpEngineDataSource to require at least S extension 7. This earlier version supports [HttpEngine](https://developer.android.com/reference/android/net/http/HttpEngine) and thus this change allows more devices to use HttpEngine. This fixes Issue: androidx/media#1262, which suggests to do this. PiperOrigin-RevId: 650224711 --- RELEASENOTES.md | 4 ++++ constants.gradle | 3 +-- .../src/main/java/androidx/media3/demo/main/DemoUtil.java | 4 +++- .../media3/datasource/ByteArrayUploadDataProvider.java | 5 +++-- .../androidx/media3/datasource/HttpEngineDataSource.java | 5 +++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 07b8ac69ec6..b61b9e995d3 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -24,6 +24,10 @@ * Extractors: * Allow `Mp4Extractor` to identify H264 samples that are not used as reference by subsequent samples. +* DataSource: + * Update `HttpEngineDataSource` to allow use starting at version S + extension 7 instead of API level 34 + ([#1262](https://github.com/androidx/media/issues/1262)). * Audio: * Video: * Text: diff --git a/constants.gradle b/constants.gradle index 2f94608125f..66cc6ee29bf 100644 --- a/constants.gradle +++ b/constants.gradle @@ -38,8 +38,7 @@ project.ext { errorProneVersion = '2.18.0' jsr305Version = '3.0.2' kotlinAnnotationsVersion = '1.9.0' - // Updating this to 1.4.0+ will import Kotlin stdlib [internal ref: b/277891049]. - androidxAnnotationVersion = '1.3.0' + androidxAnnotationVersion = '1.6.0' androidxAnnotationExperimentalVersion = '1.3.1' androidxAppCompatVersion = '1.6.1' androidxCollectionVersion = '1.2.0' diff --git a/demos/main/src/main/java/androidx/media3/demo/main/DemoUtil.java b/demos/main/src/main/java/androidx/media3/demo/main/DemoUtil.java index 4713817524d..5d73c58cbb5 100644 --- a/demos/main/src/main/java/androidx/media3/demo/main/DemoUtil.java +++ b/demos/main/src/main/java/androidx/media3/demo/main/DemoUtil.java @@ -18,6 +18,7 @@ import android.content.Context; import android.net.http.HttpEngine; import android.os.Build; +import android.os.ext.SdkExtensions; import androidx.annotation.OptIn; import androidx.media3.database.DatabaseProvider; import androidx.media3.database.StandaloneDatabaseProvider; @@ -106,7 +107,8 @@ public static synchronized DataSource.Factory getHttpDataSourceFactory(Context c return httpDataSourceFactory; } context = context.getApplicationContext(); - if (Build.VERSION.SDK_INT >= 34) { + if (Build.VERSION.SDK_INT >= 30 + && SdkExtensions.getExtensionVersion(Build.VERSION_CODES.S) >= 7) { HttpEngine httpEngine = new HttpEngine.Builder(context).build(); httpDataSourceFactory = new HttpEngineDataSource.Factory(httpEngine, Executors.newSingleThreadExecutor()); diff --git a/libraries/datasource/src/main/java/androidx/media3/datasource/ByteArrayUploadDataProvider.java b/libraries/datasource/src/main/java/androidx/media3/datasource/ByteArrayUploadDataProvider.java index f2f321dd51c..9892906849e 100644 --- a/libraries/datasource/src/main/java/androidx/media3/datasource/ByteArrayUploadDataProvider.java +++ b/libraries/datasource/src/main/java/androidx/media3/datasource/ByteArrayUploadDataProvider.java @@ -19,12 +19,13 @@ import android.net.http.UploadDataProvider; import android.net.http.UploadDataSink; -import androidx.annotation.RequiresApi; +import android.os.Build; +import androidx.annotation.RequiresExtension; import java.io.IOException; import java.nio.ByteBuffer; /** A {@link UploadDataProvider} implementation that provides data from a {@code byte[]}. */ -@RequiresApi(34) +@RequiresExtension(extension = Build.VERSION_CODES.S, version = 7) /* package */ final class ByteArrayUploadDataProvider extends UploadDataProvider { private final byte[] data; diff --git a/libraries/datasource/src/main/java/androidx/media3/datasource/HttpEngineDataSource.java b/libraries/datasource/src/main/java/androidx/media3/datasource/HttpEngineDataSource.java index 57879947ebf..9e6c97f032a 100644 --- a/libraries/datasource/src/main/java/androidx/media3/datasource/HttpEngineDataSource.java +++ b/libraries/datasource/src/main/java/androidx/media3/datasource/HttpEngineDataSource.java @@ -26,9 +26,10 @@ import android.net.http.UrlRequest; import android.net.http.UrlRequest.Status; import android.net.http.UrlResponseInfo; +import android.os.Build; import android.text.TextUtils; import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; +import androidx.annotation.RequiresExtension; import androidx.annotation.VisibleForTesting; import androidx.media3.common.C; import androidx.media3.common.PlaybackException; @@ -65,7 +66,7 @@ * priority) the {@code dataSpec}, {@link #setRequestProperty} and the default parameters used to * construct the instance. */ -@RequiresApi(34) +@RequiresExtension(extension = Build.VERSION_CODES.S, version = 7) @UnstableApi public final class HttpEngineDataSource extends BaseDataSource implements HttpDataSource {