1 /* 2 * Copyright (C) 2016 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 17 package com.android.tv.data.epg; 18 19 import android.support.annotation.AnyThread; 20 import android.support.annotation.NonNull; 21 import android.support.annotation.WorkerThread; 22 import com.android.tv.data.Lineup; 23 import com.android.tv.data.Program; 24 import com.android.tv.data.api.Channel; 25 import com.android.tv.dvr.data.SeriesInfo; 26 import java.util.Collection; 27 import java.util.List; 28 import java.util.Map; 29 import java.util.Set; 30 31 /** An interface used to retrieve the EPG data. This class should be used in worker thread. */ 32 @WorkerThread 33 public interface EpgReader { 34 35 /** Value class that holds a EpgChannelId and its corresponding {@link Channel} */ 36 // TODO(b/72052568): Get autovalue to work in aosp master 37 abstract class EpgChannel { 38 public static EpgChannel createEpgChannel(Channel channel, String epgChannelId) { 39 return new AutoValue_EpgReader_EpgChannel(channel, epgChannelId); 40 } 41 42 public abstract Channel getChannel(); 43 44 public abstract String getEpgChannelId(); 45 } 46 47 /** Checks if the reader is available. */ 48 boolean isAvailable(); 49 50 /** 51 * Returns the timestamp of the current EPG. The format should be YYYYMMDDHHmmSS as a long 52 * value. ex) 20160308141500 53 */ 54 long getEpgTimestamp(); 55 56 /** Sets the region code. */ 57 void setRegionCode(String regionCode); 58 59 /** Returns the lineups list. */ 60 List<Lineup> getLineups(@NonNull String postalCode); 61 62 /** 63 * Returns the list of channel numbers (unsorted) for the given lineup. The result is used to 64 * choose the most appropriate lineup among others by comparing the channel numbers of the 65 * existing channels on the device. 66 */ 67 List<String> getChannelNumbers(@NonNull String lineupId); 68 69 /** 70 * Returns the list of channels for the given lineup. The returned channels should map into the 71 * existing channels on the device. This method is usually called after selecting the lineup. 72 */ 73 Set<EpgChannel> getChannels(Set<Channel> inputChannels, @NonNull String lineupId); 74 75 /** Pre-loads and caches channels for a given lineup. */ 76 void preloadChannels(@NonNull String lineupId); 77 78 /** Clears cached channels for a given lineup. */ 79 @AnyThread 80 void clearCachedChannels(@NonNull String lineupId); 81 82 /** 83 * Returns the programs for the given channel. Must call {@link #getChannels(Set, String)} 84 * beforehand. Note that the {@code Program} doesn't have valid program ID because it's not 85 * retrieved from TvProvider. 86 */ 87 List<Program> getPrograms(EpgChannel epgChannel); 88 89 /** 90 * Returns the programs for the given channels. Note that the {@code Program} doesn't have valid 91 * program ID because it's not retrieved from TvProvider. This method is only used to get 92 * programs for a short duration typically. 93 */ 94 Map<EpgChannel, Collection<Program>> getPrograms( 95 @NonNull Set<EpgChannel> epgChannels, long duration); 96 97 /** Returns the series information for the given series ID. */ 98 SeriesInfo getSeriesInfo(@NonNull String seriesId); 99 } 100