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