Mark @C.SelectionReason as TYPE_USE (only) and use it in more places

This is not backwards compatible if the @SelectionReason annotation is
used in Kotlin code, but before this change there aren't many library
surfaces that return a value annotated with @SelectionReason, so it
seems relatively unlikely that it is in use in any/many apps.

A follow-up change will fix the positions of existing usages to match
this new config.

#minor-release

PiperOrigin-RevId: 426409877
This commit is contained in:
ibaker 2022-02-04 16:29:02 +00:00 committed by Ian Baker
parent a506d245d1
commit 975910a494
10 changed files with 21 additions and 11 deletions

View File

@ -169,6 +169,10 @@
a fallback value.
* Remove `(Simple)ExoPlayer.setThrowsWhenUsingWrongThread`. Opting out of
the thread enforcement is no longer possible.
* Change the following `IntDefs` to `@Target(TYPE_USE)` only. This may break
the compilation of usages in Kotlin, which can be fixed by moving the
annotation to annotate the type (`Int`).
* `@C.SelectionReason`
### 2.16.1 (2021-11-18)

View File

@ -729,6 +729,7 @@ public final class C {
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(TYPE_USE)
@IntDef(
open = true,
value = {

View File

@ -41,7 +41,7 @@ public final class MediaLoadData {
* One of the {@link SelectionReason selection reasons} if the data belongs to a track. {@link
* C#SELECTION_REASON_UNKNOWN} otherwise.
*/
public final int trackSelectionReason;
public final @C.SelectionReason int trackSelectionReason;
/**
* Optional data associated with the selection of the track to which the data belongs. Null if the
* data does not belong to a track.

View File

@ -546,7 +546,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
}
@Override
public int getSelectionReason() {
public @C.SelectionReason int getSelectionReason() {
return trackSelection.getSelectionReason();
}

View File

@ -313,7 +313,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
private float playbackSpeed;
private int selectedIndex;
private int reason;
private @C.SelectionReason int reason;
private long lastBufferEvaluationMs;
@Nullable private MediaChunk lastBufferEvaluationMediaChunk;
@ -446,7 +446,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
}
int previousSelectedIndex = selectedIndex;
int previousReason = reason;
@C.SelectionReason int previousReason = reason;
int formatIndexOfPreviousChunk =
queue.isEmpty() ? C.INDEX_UNSET : indexOf(Iterables.getLast(queue).trackFormat);
if (formatIndexOfPreviousChunk != C.INDEX_UNSET) {
@ -484,7 +484,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
}
@Override
public int getSelectionReason() {
public @C.SelectionReason int getSelectionReason() {
return reason;
}

View File

@ -122,6 +122,7 @@ public interface ExoTrackSelection extends TrackSelection {
int getSelectedIndex();
/** Returns the reason for the current track selection. */
@C.SelectionReason
int getSelectionReason();
/** Returns optional data associated with the current track selection. */

View File

@ -25,7 +25,7 @@ import java.util.List;
/** A {@link TrackSelection} consisting of a single track. */
public final class FixedTrackSelection extends BaseTrackSelection {
private final int reason;
private final @C.SelectionReason int reason;
@Nullable private final Object data;
/**
@ -53,7 +53,11 @@ public final class FixedTrackSelection extends BaseTrackSelection {
* @param data Optional data associated with the track selection.
*/
public FixedTrackSelection(
TrackGroup group, int track, @Type int type, int reason, @Nullable Object data) {
TrackGroup group,
int track,
@Type int type,
@C.SelectionReason int reason,
@Nullable Object data) {
super(group, /* tracks= */ new int[] {track}, type);
this.reason = reason;
this.data = data;
@ -75,7 +79,7 @@ public final class FixedTrackSelection extends BaseTrackSelection {
}
@Override
public int getSelectionReason() {
public @C.SelectionReason int getSelectionReason() {
return reason;
}

View File

@ -915,7 +915,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
}
@Override
public int getSelectionReason() {
public @C.SelectionReason int getSelectionReason() {
return C.SELECTION_REASON_UNKNOWN;
}

View File

@ -114,7 +114,7 @@ public final class FakeTrackSelection implements ExoTrackSelection {
}
@Override
public int getSelectionReason() {
public @C.SelectionReason int getSelectionReason() {
return C.SELECTION_REASON_UNKNOWN;
}

View File

@ -238,7 +238,7 @@ public final class MediaPeriodAsserts {
}
@Override
public int getSelectionReason() {
public @C.SelectionReason int getSelectionReason() {
return C.SELECTION_REASON_UNKNOWN;
}