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 */
16package com.android.tv.testing.testinput;
17
18import android.media.tv.TvTrackInfo;
19
20import com.android.tv.testing.Constants;
21
22import java.util.Collections;
23import java.util.List;
24
25/**
26 * Versioned state information for a channel.
27 */
28public class ChannelState {
29
30    /**
31     * The video track a channel has by default.
32     */
33    public static final TvTrackInfo DEFAULT_VIDEO_TRACK = Constants.FHD1080P50_VIDEO_TRACK;
34    /**
35     * The video track a channel has by default.
36     */
37    public static final TvTrackInfo DEFAULT_AUDIO_TRACK = Constants.EN_STEREO_AUDIO_TRACK;
38    /**
39     * The channel is "tuned" and video available.
40     *
41     * @see #getTuneStatus()
42     */
43    public static final int TUNE_STATUS_VIDEO_AVAILABLE = -2;
44
45    private static final int CHANNEL_VERSION_DEFAULT = 1;
46    /**
47     * Default ChannelState with version @{value #CHANNEL_VERSION_DEFAULT} and default {@link
48     * ChannelStateData}.
49     */
50    public static final ChannelState DEFAULT = new ChannelState(CHANNEL_VERSION_DEFAULT,
51            new ChannelStateData());
52    private final int mVersion;
53    private final ChannelStateData mData;
54
55
56    private ChannelState(int version, ChannelStateData channelStateData) {
57        mVersion = version;
58        mData = channelStateData;
59    }
60
61    /**
62     * Returns the id of the selected audio track, or null if none is selected.
63     */
64    public String getSelectedAudioTrackId() {
65        return mData.mSelectedAudioTrackId;
66    }
67
68    /**
69     * Returns the id of the selected audio track, or null if none is selected.
70     */
71    public String getSelectedVideoTrackId() {
72        return mData.mSelectedVideoTrackId;
73    }
74
75    /**
76     * The current version. Larger version numbers are newer.
77     *
78     * <p>The version is increased by {@link #next(ChannelStateData)}.
79     */
80    public int getVersion() {
81        return mVersion;
82    }
83
84    /**
85     * Tune status is either {@link #TUNE_STATUS_VIDEO_AVAILABLE} or a  {@link
86     * android.media.tv.TvInputService.Session#notifyVideoUnavailable(int) video unavailable
87     * reason}
88     */
89    public int getTuneStatus() {
90        return mData.mTuneStatus;
91    }
92
93    /**
94     * An unmodifiable list of TvTrackInfo for a channel, suitable for {@link
95     * android.media.tv.TvInputService.Session#notifyTracksChanged(List)}
96     */
97    public List<TvTrackInfo> getTrackInfoList() {
98        return Collections.unmodifiableList(mData.mTvTrackInfos);
99    }
100
101    @Override
102    public String toString() {
103        return "v" + mVersion + ":" + mData;
104    }
105
106    /**
107     * Creates a new ChannelState, with an incremented version and {@code data} provided.
108     *
109     * @param data the data for the new ChannelState
110     */
111    public ChannelState next(ChannelStateData data) {
112        return new ChannelState(mVersion + 1, data);
113    }
114}
115