aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/data/epg/EpgReader.java
blob: 7147905a866c2f0fce1141b9112bc2f9523d503d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.tv.data.epg;

import android.support.annotation.AnyThread;
import android.support.annotation.NonNull;
import android.support.annotation.WorkerThread;
import com.android.tv.data.Lineup;
import com.android.tv.data.Program;
import com.android.tv.data.api.Channel;
import com.android.tv.dvr.data.SeriesInfo;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/** An interface used to retrieve the EPG data. This class should be used in worker thread. */
@WorkerThread
public interface EpgReader {

    /** Value class that holds a EpgChannelId and its corresponding {@link Channel} */
    // TODO(b/72052568): Get autovalue to work in aosp master
    abstract class EpgChannel {
        public static EpgChannel createEpgChannel(Channel channel, String epgChannelId) {
            return new AutoValue_EpgReader_EpgChannel(channel, epgChannelId);
        }

        public abstract Channel getChannel();

        public abstract String getEpgChannelId();
    }

    /** Checks if the reader is available. */
    boolean isAvailable();

    /**
     * Returns the timestamp of the current EPG. The format should be YYYYMMDDHHmmSS as a long
     * value. ex) 20160308141500
     */
    long getEpgTimestamp();

    /** Sets the region code. */
    void setRegionCode(String regionCode);

    /** Returns the lineups list. */
    List<Lineup> getLineups(@NonNull String postalCode);

    /**
     * Returns the list of channel numbers (unsorted) for the given lineup. The result is used to
     * choose the most appropriate lineup among others by comparing the channel numbers of the
     * existing channels on the device.
     */
    List<String> getChannelNumbers(@NonNull String lineupId);

    /**
     * Returns the list of channels for the given lineup. The returned channels should map into the
     * existing channels on the device. This method is usually called after selecting the lineup.
     */
    Set<EpgChannel> getChannels(Set<Channel> inputChannels, @NonNull String lineupId);

    /** Pre-loads and caches channels for a given lineup. */
    void preloadChannels(@NonNull String lineupId);

    /** Clears cached channels for a given lineup. */
    @AnyThread
    void clearCachedChannels(@NonNull String lineupId);

    /**
     * Returns the programs for the given channel. Must call {@link #getChannels(Set, String)}
     * beforehand. Note that the {@code Program} doesn't have valid program ID because it's not
     * retrieved from TvProvider.
     */
    List<Program> getPrograms(EpgChannel epgChannel);

    /**
     * Returns the programs for the given channels. Note that the {@code Program} doesn't have valid
     * program ID because it's not retrieved from TvProvider. This method is only used to get
     * programs for a short duration typically.
     */
    Map<EpgChannel, Collection<Program>> getPrograms(
            @NonNull Set<EpgChannel> epgChannels, long duration);

    /** Returns the series information for the given series ID. */
    SeriesInfo getSeriesInfo(@NonNull String seriesId);
}