From 876abe315bd449045dc7d6fd32812016d2c2fcd8 Mon Sep 17 00:00:00 2001 From: ibaker Date: Tue, 3 Dec 2024 08:54:51 -0800 Subject: [PATCH] Increase library target SDK to 31 This only affects the default SDK level that Robolectric tests run at. Also upgrade the Robolectric version to 4.14.1 to pick up https://github.com/robolectric/robolectric/commit/4f32042afe54beb3c8a02a330ba479e16febf49d which is needed for async `ShadowMediaCodec` support (the default in ExoPlayer from API 31+). Some tests fail on Robolectric at API 31. This change configures them to continue running on API 30, so the failures can be investigated and fixed in follow-up changes. PiperOrigin-RevId: 702357124 --- constants.gradle | 4 ++-- .../media3/exoplayer/DefaultLoadControlTest.java | 12 +++++++----- .../exoplayer/audio/MediaCodecAudioRendererTest.java | 1 + .../exoplayer/e2etest/PlaylistPlaybackTest.java | 2 ++ .../media3/exoplayer/e2etest/WebvttPlaybackTest.java | 2 ++ .../ads/ServerSideAdInsertionMediaSourceTest.java | 2 ++ .../exoplayer/video/MediaCodecVideoRendererTest.java | 2 ++ .../exoplayer/hls/e2etest/HlsPlaybackTest.java | 2 ++ 8 files changed, 20 insertions(+), 7 deletions(-) diff --git a/constants.gradle b/constants.gradle index e361bd418b..3e580ad528 100644 --- a/constants.gradle +++ b/constants.gradle @@ -20,7 +20,7 @@ project.ext { appTargetSdkVersion = 34 // Upgrading this requires [Internal ref: b/193254928] to be fixed, or some // additional robolectric config. - targetSdkVersion = 30 + targetSdkVersion = 31 compileSdkVersion = 35 dexmakerVersion = '2.28.3' // Use the same JUnit version as the Android repo: @@ -33,7 +33,7 @@ project.ext { kotlinxCoroutinesVersion = '1.8.1' leakCanaryVersion = '2.10' mockitoVersion = '3.12.4' - robolectricVersion = '4.11' + robolectricVersion = '4.14.1' // Keep this in sync with Google's internal Checker Framework version. checkerframeworkVersion = '3.13.0' errorProneVersion = '2.18.0' diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/DefaultLoadControlTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/DefaultLoadControlTest.java index 88646fba2d..3733a90d08 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/DefaultLoadControlTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/DefaultLoadControlTest.java @@ -17,6 +17,7 @@ package androidx.media3.exoplayer; import static com.google.common.truth.Truth.assertThat; +import android.media.metrics.LogSessionId; import androidx.media3.common.C; import androidx.media3.common.Format; import androidx.media3.common.MediaItem; @@ -61,7 +62,8 @@ public class DefaultLoadControlTest { playerId = Util.SDK_INT < 31 ? new PlayerId(/* playerName= */ "") - : new PlayerId(/* logSessionId= */ null, /* playerName= */ ""); + : new PlayerId( + /* logSessionId= */ LogSessionId.LOG_SESSION_ID_NONE, /* playerName= */ ""); timeline = new SinglePeriodTimeline( /* durationUs= */ 10_000_000L, @@ -128,7 +130,7 @@ public class DefaultLoadControlTest { /* bufferForPlaybackAfterRebufferMs= */ 0); build(); // A second player uses the load control. - PlayerId playerId2 = new PlayerId(/* playerName= */ ""); + PlayerId playerId2 = new PlayerId(LogSessionId.LOG_SESSION_ID_NONE, /* playerName= */ ""); Timeline timeline2 = new FakeTimeline(); MediaSource.MediaPeriodId mediaPeriodId2 = new MediaSource.MediaPeriodId( @@ -729,7 +731,7 @@ public class DefaultLoadControlTest { @Test public void onPrepared_updatesTargetBufferBytes_correctDefaultTargetBufferSize() { - PlayerId playerId2 = new PlayerId(/* playerName= */ ""); + PlayerId playerId2 = new PlayerId(LogSessionId.LOG_SESSION_ID_NONE, /* playerName= */ ""); loadControl = builder.setAllocator(allocator).build(); loadControl.onPrepared(playerId); @@ -741,7 +743,7 @@ public class DefaultLoadControlTest { @Test public void onTrackSelected_updatesTargetBufferBytes_correctTargetBufferSizeFromTrackType() { - PlayerId playerId2 = new PlayerId(/* playerName= */ ""); + PlayerId playerId2 = new PlayerId(LogSessionId.LOG_SESSION_ID_NONE, /* playerName= */ ""); loadControl = builder.setAllocator(allocator).build(); loadControl.onPrepared(playerId); loadControl.onPrepared(playerId2); @@ -789,7 +791,7 @@ public class DefaultLoadControlTest { @Test public void onRelease_removesLoadingStateOfPlayer() { - PlayerId playerId2 = new PlayerId(/* playerName= */ ""); + PlayerId playerId2 = new PlayerId(LogSessionId.LOG_SESSION_ID_NONE, /* playerName= */ ""); loadControl = builder.setAllocator(allocator).build(); loadControl.onPrepared(playerId); loadControl.onPrepared(playerId2); diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/audio/MediaCodecAudioRendererTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/audio/MediaCodecAudioRendererTest.java index af78171476..280df747dd 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/audio/MediaCodecAudioRendererTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/audio/MediaCodecAudioRendererTest.java @@ -72,6 +72,7 @@ import org.mockito.junit.MockitoRule; import org.robolectric.annotation.Config; /** Unit tests for {@link MediaCodecAudioRenderer} */ +@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+. @RunWith(AndroidJUnit4.class) public class MediaCodecAudioRendererTest { @Rule public final MockitoRule mockito = MockitoJUnit.rule(); diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/PlaylistPlaybackTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/PlaylistPlaybackTest.java index 7fd5f4cd5a..68c8cd7e59 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/PlaylistPlaybackTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/PlaylistPlaybackTest.java @@ -41,9 +41,11 @@ import com.google.common.collect.ImmutableList; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.annotation.Config; import org.robolectric.annotation.GraphicsMode; /** End-to-end tests for playlists. */ +@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+. @RunWith(AndroidJUnit4.class) @GraphicsMode(value = NATIVE) public final class PlaylistPlaybackTest { diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/WebvttPlaybackTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/WebvttPlaybackTest.java index 403c6cd04a..7be876cc2a 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/WebvttPlaybackTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/WebvttPlaybackTest.java @@ -53,8 +53,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.ParameterizedRobolectricTestRunner; +import org.robolectric.annotation.Config; /** End-to-end tests using side-loaded WebVTT subtitles. */ +@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+. @RunWith(ParameterizedRobolectricTestRunner.class) public class WebvttPlaybackTest { @ParameterizedRobolectricTestRunner.Parameters(name = "{0}") diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSourceTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSourceTest.java index 6d0d449ab9..fcb65beaea 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSourceTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionMediaSourceTest.java @@ -93,8 +93,10 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.annotation.Config; /** Unit test for {@link ServerSideAdInsertionMediaSource}. */ +@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+. @RunWith(AndroidJUnit4.class) public final class ServerSideAdInsertionMediaSourceTest { diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/video/MediaCodecVideoRendererTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/video/MediaCodecVideoRendererTest.java index 7f92d7efad..f188f10014 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/video/MediaCodecVideoRendererTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/video/MediaCodecVideoRendererTest.java @@ -100,11 +100,13 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.robolectric.Shadows; +import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowDisplay; import org.robolectric.shadows.ShadowLooper; import org.robolectric.shadows.ShadowSystemClock; /** Unit test for {@link MediaCodecVideoRenderer}. */ +@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests pass on API 31+. @RunWith(AndroidJUnit4.class) public class MediaCodecVideoRendererTest { @Rule public final MockitoRule mockito = MockitoJUnit.rule(); diff --git a/libraries/exoplayer_hls/src/test/java/androidx/media3/exoplayer/hls/e2etest/HlsPlaybackTest.java b/libraries/exoplayer_hls/src/test/java/androidx/media3/exoplayer/hls/e2etest/HlsPlaybackTest.java index 6e802c6ebc..4698d3d2b5 100644 --- a/libraries/exoplayer_hls/src/test/java/androidx/media3/exoplayer/hls/e2etest/HlsPlaybackTest.java +++ b/libraries/exoplayer_hls/src/test/java/androidx/media3/exoplayer/hls/e2etest/HlsPlaybackTest.java @@ -59,8 +59,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; +import org.robolectric.annotation.Config; /** End-to-end tests using HLS samples. */ +@Config(sdk = 30) // TODO: b/382017156 - Remove this when the tests are non-flaky on API 31+. @RunWith(AndroidJUnit4.class) public final class HlsPlaybackTest {