From 54283746be4a780f8922efc391c55736308bae22 Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 19 Feb 2020 14:21:21 +0000 Subject: [PATCH] Fix lint errors PiperOrigin-RevId: 295953956 --- constants.gradle | 2 +- .../gldemo/VideoProcessingGLSurfaceView.java | 1 + .../google/android/exoplayer2/util/Util.java | 3 --- .../android/exoplayer2/util/UtilTest.java | 15 ++++++++++----- .../exoplayer2/audio/AudioTimestampPoller.java | 4 ++++ .../exoplayer2/audio/DefaultAudioSink.java | 14 +++++++++++++- .../DedicatedThreadAsyncMediaCodecAdapter.java | 5 +++++ .../exoplayer2/mediacodec/MediaCodecInfo.java | 7 ++++--- .../mediacodec/MediaCodecRenderer.java | 2 ++ .../MultiLockAsyncMediaCodecAdapter.java | 5 +++++ .../google/android/exoplayer2/util/GlUtil.java | 3 --- .../video/MediaCodecVideoRenderer.java | 4 +++- .../video/VideoFrameReleaseTimeHelper.java | 17 ++++++++--------- .../android/exoplayer2/ui/DefaultTimeBar.java | 2 -- .../testutil/FakeExtractorOutput.java | 2 +- 15 files changed, 57 insertions(+), 29 deletions(-) diff --git a/constants.gradle b/constants.gradle index b9c36f2523..ede41a54d5 100644 --- a/constants.gradle +++ b/constants.gradle @@ -17,7 +17,7 @@ project.ext { releaseVersionCode = 2011003 minSdkVersion = 16 appTargetSdkVersion = 29 - targetSdkVersion = 28 // TODO: Bump once b/143232359 is resolved + targetSdkVersion = 28 // TODO: Bump once b/143232359 is resolved. Also fix TODOs in UtilTest. compileSdkVersion = 29 dexmakerVersion = '2.21.0' junitVersion = '4.13-rc-2' diff --git a/demos/gl/src/main/java/com/google/android/exoplayer2/gldemo/VideoProcessingGLSurfaceView.java b/demos/gl/src/main/java/com/google/android/exoplayer2/gldemo/VideoProcessingGLSurfaceView.java index 1a41d9ec82..f21e8c6037 100644 --- a/demos/gl/src/main/java/com/google/android/exoplayer2/gldemo/VideoProcessingGLSurfaceView.java +++ b/demos/gl/src/main/java/com/google/android/exoplayer2/gldemo/VideoProcessingGLSurfaceView.java @@ -83,6 +83,7 @@ public final class VideoProcessingGLSurfaceView extends GLSurfaceView { * created, if supported by the device. * @param videoProcessor Processor that draws to the view. */ + @SuppressWarnings("InlinedApi") public VideoProcessingGLSurfaceView( Context context, boolean requireSecureContext, VideoProcessor videoProcessor) { super(context); diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java b/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java index db36db9b73..0402bdb9ef 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java @@ -19,7 +19,6 @@ import static android.content.Context.UI_MODE_SERVICE; import android.Manifest.permission; import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.app.Activity; import android.app.UiModeManager; import android.content.ComponentName; @@ -179,7 +178,6 @@ public final class Util { * @param uris {@link Uri}s that may require {@link permission#READ_EXTERNAL_STORAGE} to read. * @return Whether a permission request was made. */ - @TargetApi(23) public static boolean maybeRequestReadExternalStoragePermission(Activity activity, Uri... uris) { if (Util.SDK_INT < 23) { return false; @@ -204,7 +202,6 @@ public final class Util { * @param uris A list of URIs that will be loaded. * @return Whether it may be possible to load the given URIs. */ - @TargetApi(24) public static boolean checkCleartextTrafficPermitted(Uri... uris) { if (Util.SDK_INT < 24) { // We assume cleartext traffic is permitted. diff --git a/library/common/src/test/java/com/google/android/exoplayer2/util/UtilTest.java b/library/common/src/test/java/com/google/android/exoplayer2/util/UtilTest.java index 88835a40a6..4933d73793 100644 --- a/library/common/src/test/java/com/google/android/exoplayer2/util/UtilTest.java +++ b/library/common/src/test/java/com/google/android/exoplayer2/util/UtilTest.java @@ -784,8 +784,9 @@ public class UtilTest { assertThat(Arrays.copyOf(output.data, output.limit())).isEqualTo(testData); } + // TODO: Revert to @Config(sdk = Config.ALL_SDKS) once b/143232359 is resolved @Test - @Config(sdk = Config.ALL_SDKS) + @Config(minSdk = Config.OLDEST_SDK, maxSdk = Config.TARGET_SDK) public void normalizeLanguageCode_keepsUndefinedTagsUnchanged() { assertThat(Util.normalizeLanguageCode(null)).isNull(); assertThat(Util.normalizeLanguageCode("")).isEmpty(); @@ -793,8 +794,9 @@ public class UtilTest { assertThat(Util.normalizeLanguageCode("DoesNotExist")).isEqualTo("doesnotexist"); } + // TODO: Revert to @Config(sdk = Config.ALL_SDKS) once b/143232359 is resolved @Test - @Config(sdk = Config.ALL_SDKS) + @Config(minSdk = Config.OLDEST_SDK, maxSdk = Config.TARGET_SDK) public void normalizeLanguageCode_normalizesCodeToTwoLetterISOAndLowerCase_keepingAllSubtags() { assertThat(Util.normalizeLanguageCode("es")).isEqualTo("es"); assertThat(Util.normalizeLanguageCode("spa")).isEqualTo("es"); @@ -812,8 +814,9 @@ public class UtilTest { assertThat(Util.normalizeLanguageCode("sv-illegalSubtag")).isEqualTo("sv-illegalsubtag"); } + // TODO: Revert to @Config(sdk = Config.ALL_SDKS) once b/143232359 is resolved @Test - @Config(sdk = Config.ALL_SDKS) + @Config(minSdk = Config.OLDEST_SDK, maxSdk = Config.TARGET_SDK) public void normalizeLanguageCode_iso6392BibliographicalAndTextualCodes_areNormalizedToSameTag() { // See https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes. assertThat(Util.normalizeLanguageCode("alb")).isEqualTo(Util.normalizeLanguageCode("sqi")); @@ -839,8 +842,9 @@ public class UtilTest { assertThat(Util.normalizeLanguageCode("wel")).isEqualTo(Util.normalizeLanguageCode("cym")); } + // TODO: Revert to @Config(sdk = Config.ALL_SDKS) once b/143232359 is resolved @Test - @Config(sdk = Config.ALL_SDKS) + @Config(minSdk = Config.OLDEST_SDK, maxSdk = Config.TARGET_SDK) public void normalizeLanguageCode_deprecatedLanguageTagsAndModernReplacement_areNormalizedToSameTag() { // See https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes, "ISO 639:1988" @@ -877,8 +881,9 @@ public class UtilTest { .isEqualTo(Util.normalizeLanguageCode("zh-hsn")); } + // TODO: Revert to @Config(sdk = Config.ALL_SDKS) once b/143232359 is resolved @Test - @Config(sdk = Config.ALL_SDKS) + @Config(minSdk = Config.OLDEST_SDK, maxSdk = Config.TARGET_SDK) public void normalizeLanguageCode_macrolanguageTags_areFullyMaintained() { // See https://en.wikipedia.org/wiki/ISO_639_macrolanguage assertThat(Util.normalizeLanguageCode("zh-cmn")).isEqualTo("zh-cmn"); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTimestampPoller.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTimestampPoller.java index e101d254d3..9e870735f2 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTimestampPoller.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioTimestampPoller.java @@ -15,6 +15,7 @@ */ package com.google.android.exoplayer2.audio; +import android.annotation.TargetApi; import android.media.AudioTimestamp; import android.media.AudioTrack; import androidx.annotation.IntDef; @@ -115,6 +116,7 @@ import java.lang.annotation.RetentionPolicy; * @param systemTimeUs The current system time, in microseconds. * @return Whether the timestamp was updated. */ + @TargetApi(19) // audioTimestamp will be null if Util.SDK_INT < 19. public boolean maybePollTimestamp(long systemTimeUs) { if (audioTimestamp == null || (systemTimeUs - lastTimestampSampleTimeUs) < sampleIntervalUs) { return false; @@ -220,6 +222,7 @@ import java.lang.annotation.RetentionPolicy; * If {@link #maybePollTimestamp(long)} or {@link #hasTimestamp()} returned {@code true}, returns * the system time at which the latest timestamp was sampled, in microseconds. */ + @TargetApi(19) // audioTimestamp will be null if Util.SDK_INT < 19. public long getTimestampSystemTimeUs() { return audioTimestamp != null ? audioTimestamp.getTimestampSystemTimeUs() : C.TIME_UNSET; } @@ -228,6 +231,7 @@ import java.lang.annotation.RetentionPolicy; * If {@link #maybePollTimestamp(long)} or {@link #hasTimestamp()} returned {@code true}, returns * the latest timestamp's position in frames. */ + @TargetApi(19) // audioTimestamp will be null if Util.SDK_INT < 19. public long getTimestampPositionFrames() { return audioTimestamp != null ? audioTimestamp.getTimestampPositionFrames() : C.POSITION_UNSET; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java index 3441764447..e9ae7d3033 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java @@ -1122,6 +1122,9 @@ public final class DefaultAudioSink implements AudioSink { private static int getMaximumEncodedRateBytesPerSecond(@C.Encoding int encoding) { switch (encoding) { + case C.ENCODING_MP3: + // Maximum bitrate for MPEG-1 layer III: 320 kbit/s. + return 320 * 1000 / 8; case C.ENCODING_AC3: return 640 * 1000 / 8; case C.ENCODING_E_AC3: @@ -1136,12 +1139,13 @@ public final class DefaultAudioSink implements AudioSink { return 18000 * 1000 / 8; case C.ENCODING_DOLBY_TRUEHD: return 24500 * 1000 / 8; - case C.ENCODING_INVALID: case C.ENCODING_PCM_16BIT: + case C.ENCODING_PCM_16BIT_BIG_ENDIAN: case C.ENCODING_PCM_24BIT: case C.ENCODING_PCM_32BIT: case C.ENCODING_PCM_8BIT: case C.ENCODING_PCM_FLOAT: + case C.ENCODING_INVALID: case Format.NO_VALUE: default: throw new IllegalArgumentException(); @@ -1167,6 +1171,14 @@ public final class DefaultAudioSink implements AudioSink { ? 0 : (Ac3Util.parseTrueHdSyncframeAudioSampleCount(buffer, syncframeOffset) * Ac3Util.TRUEHD_RECHUNK_SAMPLE_COUNT); + case C.ENCODING_PCM_16BIT: + case C.ENCODING_PCM_16BIT_BIG_ENDIAN: + case C.ENCODING_PCM_24BIT: + case C.ENCODING_PCM_32BIT: + case C.ENCODING_PCM_8BIT: + case C.ENCODING_PCM_FLOAT: + case C.ENCODING_INVALID: + case Format.NO_VALUE: default: throw new IllegalStateException("Unexpected audio encoding: " + encoding); } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/DedicatedThreadAsyncMediaCodecAdapter.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/DedicatedThreadAsyncMediaCodecAdapter.java index c2da8ec28d..548ed01473 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/DedicatedThreadAsyncMediaCodecAdapter.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/DedicatedThreadAsyncMediaCodecAdapter.java @@ -28,6 +28,9 @@ import androidx.annotation.VisibleForTesting; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.decoder.CryptoInfo; import com.google.android.exoplayer2.util.Util; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; /** @@ -41,6 +44,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; /* package */ final class DedicatedThreadAsyncMediaCodecAdapter extends MediaCodec.Callback implements MediaCodecAdapter { + @Documented + @Retention(RetentionPolicy.SOURCE) @IntDef({STATE_CREATED, STATE_STARTED, STATE_SHUT_DOWN}) private @interface State {} diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java index 1de36af65f..3bd051214c 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java @@ -229,9 +229,10 @@ public final class MediaCodecInfo { * @see CodecCapabilities#getMaxSupportedInstances() */ public int getMaxSupportedInstances() { - return (Util.SDK_INT < 23 || capabilities == null) - ? MAX_SUPPORTED_INSTANCES_UNKNOWN - : getMaxSupportedInstancesV23(capabilities); + if (Util.SDK_INT < 23 || capabilities == null) { + return MAX_SUPPORTED_INSTANCES_UNKNOWN; + } + return getMaxSupportedInstancesV23(capabilities); } /** diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java index 54891722f4..dc8118267b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java @@ -15,6 +15,7 @@ */ package com.google.android.exoplayer2.mediacodec; +import android.annotation.TargetApi; import android.media.MediaCodec; import android.media.MediaCodec.CodecException; import android.media.MediaCodec.CryptoException; @@ -1842,6 +1843,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { * * @throws ExoPlaybackException If an error occurs processing the signal. */ + @TargetApi(23) // codecDrainAction == DRAIN_ACTION_UPDATE_DRM_SESSION implies SDK_INT >= 23. private void processEndOfStream() throws ExoPlaybackException { switch (codecDrainAction) { case DRAIN_ACTION_REINITIALIZE: diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MultiLockAsyncMediaCodecAdapter.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MultiLockAsyncMediaCodecAdapter.java index 8cb7b796c8..a2cdf24bc4 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MultiLockAsyncMediaCodecAdapter.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MultiLockAsyncMediaCodecAdapter.java @@ -30,6 +30,9 @@ import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.decoder.CryptoInfo; import com.google.android.exoplayer2.util.IntArrayQueue; import com.google.android.exoplayer2.util.Util; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayDeque; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @@ -52,6 +55,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; /* package */ final class MultiLockAsyncMediaCodecAdapter extends MediaCodec.Callback implements MediaCodecAdapter { + @Documented + @Retention(RetentionPolicy.SOURCE) @IntDef({STATE_CREATED, STATE_STARTED, STATE_SHUT_DOWN}) private @interface State {} diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/GlUtil.java b/library/core/src/main/java/com/google/android/exoplayer2/util/GlUtil.java index cc4866118d..e90d133334 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/GlUtil.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/GlUtil.java @@ -17,7 +17,6 @@ package com.google.android.exoplayer2.util; import static android.opengl.GLU.gluErrorString; -import android.annotation.TargetApi; import android.content.Context; import android.content.pm.PackageManager; import android.opengl.EGL14; @@ -208,7 +207,6 @@ public final class GlUtil { * Returns whether creating a GL context with {@value EXTENSION_PROTECTED_CONTENT} is possible. If * {@code true}, the device supports a protected output path for DRM content when using GL. */ - @TargetApi(24) public static boolean isProtectedContentExtensionSupported(Context context) { if (Util.SDK_INT < 24) { return false; @@ -236,7 +234,6 @@ public final class GlUtil { /** * Returns whether creating a GL context with {@value EXTENSION_SURFACELESS_CONTEXT} is possible. */ - @TargetApi(17) public static boolean isSurfacelessContextExtensionSupported() { if (Util.SDK_INT < 17) { return false; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java index e9edc810b8..00d64e18d0 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java @@ -16,6 +16,7 @@ package com.google.android.exoplayer2.video; import android.annotation.SuppressLint; +import android.annotation.TargetApi; import android.content.Context; import android.graphics.Point; import android.media.MediaCodec; @@ -658,6 +659,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { } @Override + @TargetApi(29) // codecHandlesHdr10PlusOutOfBandMetadata is false if Util.SDK_INT < 29 protected void handleInputBufferSupplementalData(DecoderInputBuffer buffer) throws ExoPlaybackException { if (!codecHandlesHdr10PlusOutOfBandMetadata) { @@ -682,7 +684,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { byte[] hdr10PlusInfo = new byte[data.remaining()]; data.get(hdr10PlusInfo); data.position(0); - // If codecHandlesHdr10PlusOutOfBandMetadata is true, this is an API 29 or later build. setHdr10PlusInfoV29(getCodec(), hdr10PlusInfo); } } @@ -1179,6 +1180,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { * @return The framework {@link MediaFormat} that should be used to configure the decoder. */ @SuppressLint("InlinedApi") + @TargetApi(21) // tunnelingAudioSessionId is unset if Util.SDK_INT < 21 protected MediaFormat getMediaFormat( Format format, String codecMimeType, diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/VideoFrameReleaseTimeHelper.java b/library/core/src/main/java/com/google/android/exoplayer2/video/VideoFrameReleaseTimeHelper.java index 5044b4f466..76ff19406b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/VideoFrameReleaseTimeHelper.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/VideoFrameReleaseTimeHelper.java @@ -15,6 +15,7 @@ */ package com.google.android.exoplayer2.video; +import android.annotation.TargetApi; import android.content.Context; import android.hardware.display.DisplayManager; import android.os.Handler; @@ -40,9 +41,9 @@ public final class VideoFrameReleaseTimeHelper { private static final long VSYNC_OFFSET_PERCENTAGE = 80; private static final int MIN_FRAMES_FOR_ADJUSTMENT = 6; - private final WindowManager windowManager; - private final VSyncSampler vsyncSampler; - private final DefaultDisplayListener displayListener; + @Nullable private final WindowManager windowManager; + @Nullable private final VSyncSampler vsyncSampler; + @Nullable private final DefaultDisplayListener displayListener; private long vsyncDurationNs; private long vsyncOffsetNs; @@ -88,9 +89,8 @@ public final class VideoFrameReleaseTimeHelper { vsyncOffsetNs = C.TIME_UNSET; } - /** - * Enables the helper. Must be called from the playback thread. - */ + /** Enables the helper. Must be called from the playback thread. */ + @TargetApi(17) // displayListener is null if Util.SDK_INT < 17. public void enable() { haveSync = false; if (windowManager != null) { @@ -102,9 +102,8 @@ public final class VideoFrameReleaseTimeHelper { } } - /** - * Disables the helper. Must be called from the playback thread. - */ + /** Disables the helper. Must be called from the playback thread. */ + @TargetApi(17) // displayListener is null if Util.SDK_INT < 17. public void disable() { if (windowManager != null) { if (displayListener != null) { diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/DefaultTimeBar.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/DefaultTimeBar.java index 15799db2c6..790a8f770a 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/DefaultTimeBar.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/DefaultTimeBar.java @@ -15,7 +15,6 @@ */ package com.google.android.exoplayer2.ui; -import android.annotation.TargetApi; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; @@ -638,7 +637,6 @@ public class DefaultTimeBar extends View implements TimeBar { event.setClassName(ACCESSIBILITY_CLASS_NAME); } - @TargetApi(21) @Override public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { super.onInitializeAccessibilityNodeInfo(info); diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeExtractorOutput.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeExtractorOutput.java index 69fc379b34..ad9d8dcdd2 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeExtractorOutput.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeExtractorOutput.java @@ -59,7 +59,7 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab */ private static final int WRITE_TO_LOCAL = 1; /** Write output to folder {@code /storage/emulated/0/Android/data} of device. */ - private static final int WRITE_TO_DEVICE = 2; + private static final int WRITE_TO_DEVICE = 1 << 1; @DumpFilesAction private static final int DUMP_FILE_ACTION = COMPARE_WITH_EXISTING;