• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.tv.testing.testinput;
17 
18 import android.media.tv.TvTrackInfo;
19 import com.android.tv.testing.constants.Constants;
20 import java.util.Collections;
21 import java.util.List;
22 
23 /** Versioned state information for a channel. */
24 public class ChannelState {
25 
26     /** The video track a channel has by default. */
27     public static final TvTrackInfo DEFAULT_VIDEO_TRACK = Constants.FHD1080P50_VIDEO_TRACK;
28     /** The video track a channel has by default. */
29     public static final TvTrackInfo DEFAULT_AUDIO_TRACK = Constants.EN_STEREO_AUDIO_TRACK;
30     /**
31      * The channel is "tuned" and video available.
32      *
33      * @see #getTuneStatus()
34      */
35     public static final int TUNE_STATUS_VIDEO_AVAILABLE = -2;
36 
37     private static final int CHANNEL_VERSION_DEFAULT = 1;
38     /**
39      * Default ChannelState with version @{value #CHANNEL_VERSION_DEFAULT} and default {@link
40      * ChannelStateData}.
41      */
42     public static final ChannelState DEFAULT =
43             new ChannelState(CHANNEL_VERSION_DEFAULT, new ChannelStateData());
44 
45     private final int mVersion;
46     private final ChannelStateData mData;
47 
ChannelState(int version, ChannelStateData channelStateData)48     private ChannelState(int version, ChannelStateData channelStateData) {
49         mVersion = version;
50         mData = channelStateData;
51     }
52 
53     /** Returns the id of the selected audio track, or null if none is selected. */
getSelectedAudioTrackId()54     public String getSelectedAudioTrackId() {
55         return mData.mSelectedAudioTrackId;
56     }
57 
58     /** Returns the id of the selected audio track, or null if none is selected. */
getSelectedVideoTrackId()59     public String getSelectedVideoTrackId() {
60         return mData.mSelectedVideoTrackId;
61     }
62 
63     /**
64      * The current version. Larger version numbers are newer.
65      *
66      * <p>The version is increased by {@link #next(ChannelStateData)}.
67      */
getVersion()68     public int getVersion() {
69         return mVersion;
70     }
71 
72     /**
73      * Tune status is either {@link #TUNE_STATUS_VIDEO_AVAILABLE} or a {@link
74      * android.media.tv.TvInputService.Session#notifyVideoUnavailable(int) video unavailable reason}
75      */
getTuneStatus()76     public int getTuneStatus() {
77         return mData.mTuneStatus;
78     }
79 
80     /**
81      * An unmodifiable list of TvTrackInfo for a channel, suitable for {@link
82      * android.media.tv.TvInputService.Session#notifyTracksChanged(List)}
83      */
getTrackInfoList()84     public List<TvTrackInfo> getTrackInfoList() {
85         return Collections.unmodifiableList(mData.mTvTrackInfos);
86     }
87 
88     @Override
toString()89     public String toString() {
90         return "v" + mVersion + ":" + mData;
91     }
92 
93     /**
94      * Creates a new ChannelState, with an incremented version and {@code data} provided.
95      *
96      * @param data the data for the new ChannelState
97      */
next(ChannelStateData data)98     public ChannelState next(ChannelStateData data) {
99         return new ChannelState(mVersion + 1, data);
100     }
101 }
102