Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f710befd authored by Chulwoo Lee's avatar Chulwoo Lee Committed by Android (Google) Code Review
Browse files

Merge "Fix checking trackId" into lmp-dev

parents b79a70ab 984d99b5
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -1170,16 +1170,19 @@ public final class TvInputManager {
         */
        public void selectTrack(int type, String trackId) {
            if (type == TvTrackInfo.TYPE_AUDIO) {
                if (trackId != null && !mAudioTracks.contains(trackId)) {
                if (trackId != null && !containsTrack(mAudioTracks, trackId)) {
                    Log.w(TAG, "Invalid audio trackId: " + trackId);
                    return;
                }
            } else if (type == TvTrackInfo.TYPE_VIDEO) {
                if (trackId != null && !mVideoTracks.contains(trackId)) {
                if (trackId != null && !containsTrack(mVideoTracks, trackId)) {
                    Log.w(TAG, "Invalid video trackId: " + trackId);
                    return;
                }
            } else if (type == TvTrackInfo.TYPE_SUBTITLE) {
                if (trackId != null && !mSubtitleTracks.contains(trackId)) {
                if (trackId != null && !containsTrack(mSubtitleTracks, trackId)) {
                    Log.w(TAG, "Invalid subtitle trackId: " + trackId);
                    return;
                }
            } else {
                throw new IllegalArgumentException("invalid type: " + type);
@@ -1195,6 +1198,15 @@ public final class TvInputManager {
            }
        }

        private boolean containsTrack(List<TvTrackInfo> tracks, String trackId) {
            for (TvTrackInfo track : tracks) {
                if (track.getId().equals(trackId)) {
                    return true;
                }
            }
            return false;
        }

        /**
         * Returns the list of tracks for a given type. Returns {@code null} if the information is
         * not available.