From 8829c45d3265cbd298e167a0457720f54af2a985 Mon Sep 17 00:00:00 2001 From: ibaker Date: Mon, 1 Nov 2021 11:13:15 +0000 Subject: [PATCH] Add TYPE_USE to IntDefs used in the media3 stable API This allows the use of the intdef in parameterized types, e.g. List<@MyIntDef Integer> For IntDefs that are already released in ExoPlayer 2.15.1 we add TYPE_USE in addition to all other reasonable targets, to maintain backwards compatibility with Kotlin code (where an incorrectly positioned annotation is a compilation failure). 'reasonable targets' includes FIELD, METHOD, PARAMETER and LOCAL_VARIABLE but not TYPE, CONSTRUCTOR, ANNOTATION_TYPE, PACKAGE or MODULE. TYPE_PARAMETER is implied by TYPE_USE. For not-yet-released IntDefs we just add TYPE_USE. #minor-release PiperOrigin-RevId: 406793413 --- .../java/com/google/android/exoplayer2/C.java | 17 +++++++++++++++-- .../android/exoplayer2/MediaMetadata.java | 9 +++++++++ .../android/exoplayer2/PlaybackException.java | 8 ++++++++ .../com/google/android/exoplayer2/Player.java | 16 ++++++++++++++++ .../com/google/android/exoplayer2/text/Cue.java | 11 +++++++++++ 5 files changed, 59 insertions(+), 2 deletions(-) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/C.java b/library/common/src/main/java/com/google/android/exoplayer2/C.java index a779729bd9..7c26b57600 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/C.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/C.java @@ -15,6 +15,12 @@ */ package com.google.android.exoplayer2; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.LOCAL_VARIABLE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; + import android.content.Context; import android.media.AudioAttributes; import android.media.AudioFormat; @@ -29,7 +35,6 @@ import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.Util; import com.google.errorprone.annotations.InlineMe; import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -126,6 +131,7 @@ public final class C { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target(TYPE_USE) @IntDef( open = true, value = { @@ -306,6 +312,7 @@ public final class C { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ CONTENT_TYPE_MOVIE, CONTENT_TYPE_MUSIC, @@ -334,6 +341,7 @@ public final class C { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef( flag = true, value = {FLAG_AUDIBILITY_ENFORCED}) @@ -354,6 +362,7 @@ public final class C { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ USAGE_ALARM, USAGE_ASSISTANCE_ACCESSIBILITY, @@ -422,6 +431,7 @@ public final class C { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ALLOW_CAPTURE_BY_ALL, ALLOW_CAPTURE_BY_NONE, ALLOW_CAPTURE_BY_SYSTEM}) public @interface AudioAllowedCapturePolicy {} /** See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_ALL}. */ @@ -565,6 +575,7 @@ public final class C { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef( flag = true, value = {SELECTION_FLAG_DEFAULT, SELECTION_FLAG_FORCED, SELECTION_FLAG_AUTOSELECT}) @@ -680,7 +691,7 @@ public final class C { */ @Documented @Retention(RetentionPolicy.SOURCE) - @Target({ElementType.TYPE_USE}) + @Target(TYPE_USE) @IntDef( open = true, value = { @@ -976,6 +987,7 @@ public final class C { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({WAKE_MODE_NONE, WAKE_MODE_LOCAL, WAKE_MODE_NETWORK}) public @interface WakeMode {} /** @@ -1012,6 +1024,7 @@ public final class C { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef( flag = true, value = { diff --git a/library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java b/library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java index 4dad2da4c3..3df88a5aa9 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java @@ -15,6 +15,12 @@ */ package com.google.android.exoplayer2; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.LOCAL_VARIABLE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; + import android.net.Uri; import android.os.Bundle; import androidx.annotation.IntDef; @@ -26,6 +32,7 @@ import com.google.common.base.Objects; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.Arrays; import java.util.List; @@ -500,6 +507,7 @@ public final class MediaMetadata implements Bundleable { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ FOLDER_TYPE_NONE, FOLDER_TYPE_MIXED, @@ -537,6 +545,7 @@ public final class MediaMetadata implements Bundleable { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ PICTURE_TYPE_OTHER, PICTURE_TYPE_FILE_ICON, diff --git a/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java b/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java index b643530678..0adea0535a 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java @@ -15,6 +15,12 @@ */ package com.google.android.exoplayer2; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.LOCAL_VARIABLE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; + import android.net.ConnectivityManager; import android.os.Bundle; import android.os.RemoteException; @@ -28,6 +34,7 @@ import com.google.android.exoplayer2.util.Util; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; /** Thrown when a non locally recoverable playback failure occurs. */ public class PlaybackException extends Exception implements Bundleable { @@ -40,6 +47,7 @@ public class PlaybackException extends Exception implements Bundleable { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef( open = true, value = { diff --git a/library/common/src/main/java/com/google/android/exoplayer2/Player.java b/library/common/src/main/java/com/google/android/exoplayer2/Player.java index 5c60097eb0..08bfbe9016 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/Player.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/Player.java @@ -15,6 +15,12 @@ */ package com.google.android.exoplayer2; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.LOCAL_VARIABLE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; + import android.os.Bundle; import android.os.Looper; import android.view.Surface; @@ -40,6 +46,7 @@ import com.google.common.base.Objects; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.ArrayList; import java.util.List; @@ -1079,6 +1086,7 @@ public interface Player { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({STATE_IDLE, STATE_BUFFERING, STATE_READY, STATE_ENDED}) @interface State {} /** The player is idle, and must be {@link #prepare() prepared} before it will play the media. */ @@ -1107,6 +1115,7 @@ public interface Player { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST, PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS, @@ -1133,6 +1142,7 @@ public interface Player { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ PLAYBACK_SUPPRESSION_REASON_NONE, PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS @@ -1149,6 +1159,7 @@ public interface Player { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({REPEAT_MODE_OFF, REPEAT_MODE_ONE, REPEAT_MODE_ALL}) @interface RepeatMode {} /** @@ -1180,6 +1191,7 @@ public interface Player { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ DISCONTINUITY_REASON_AUTO_TRANSITION, DISCONTINUITY_REASON_SEEK, @@ -1218,6 +1230,7 @@ public interface Player { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, TIMELINE_CHANGE_REASON_SOURCE_UPDATE}) @interface TimelineChangeReason {} /** Timeline changed as a result of a change of the playlist items or the order of the items. */ @@ -1238,6 +1251,7 @@ public interface Player { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ MEDIA_ITEM_TRANSITION_REASON_REPEAT, MEDIA_ITEM_TRANSITION_REASON_AUTO, @@ -1270,6 +1284,7 @@ public interface Player { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ EVENT_TIMELINE_CHANGED, EVENT_MEDIA_ITEM_TRANSITION, @@ -1355,6 +1370,7 @@ public interface Player { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ COMMAND_INVALID, COMMAND_PLAY_PAUSE, diff --git a/library/common/src/main/java/com/google/android/exoplayer2/text/Cue.java b/library/common/src/main/java/com/google/android/exoplayer2/text/Cue.java index 66ab2f3682..0ef89f9b0b 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/text/Cue.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/text/Cue.java @@ -15,6 +15,12 @@ */ package com.google.android.exoplayer2.text; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.LOCAL_VARIABLE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; + import android.graphics.Bitmap; import android.graphics.Color; import android.os.Bundle; @@ -32,6 +38,7 @@ import com.google.common.base.Objects; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import org.checkerframework.dataflow.qual.Pure; /** Contains information about a specific cue, including textual content and formatting data. */ @@ -53,6 +60,7 @@ public final class Cue implements Bundleable { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({TYPE_UNSET, ANCHOR_TYPE_START, ANCHOR_TYPE_MIDDLE, ANCHOR_TYPE_END}) public @interface AnchorType {} @@ -80,6 +88,7 @@ public final class Cue implements Bundleable { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({TYPE_UNSET, LINE_TYPE_FRACTION, LINE_TYPE_NUMBER}) public @interface LineType {} @@ -96,6 +105,7 @@ public final class Cue implements Bundleable { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ TYPE_UNSET, TEXT_SIZE_TYPE_FRACTIONAL, @@ -119,6 +129,7 @@ public final class Cue implements Bundleable { */ @Documented @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE}) @IntDef({ TYPE_UNSET, VERTICAL_TYPE_RL,