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 
17 package com.android.tv.dvr;
18 
19 import android.support.annotation.MainThread;
20 import android.support.annotation.NonNull;
21 import android.support.annotation.Nullable;
22 import android.util.Range;
23 import com.android.tv.dvr.data.RecordedProgram;
24 import com.android.tv.dvr.data.ScheduledRecording;
25 import com.android.tv.dvr.data.ScheduledRecording.RecordingState;
26 import com.android.tv.dvr.data.SeriesRecording;
27 import java.util.Collection;
28 import java.util.List;
29 
30 /** Read only data manager. */
31 @MainThread
32 public interface DvrDataManager {
33     long NEXT_START_TIME_NOT_FOUND = -1;
34 
isInitialized()35     boolean isInitialized();
36 
37     /** Returns {@code true} if the schedules were loaded, otherwise {@code false}. */
isDvrScheduleLoadFinished()38     boolean isDvrScheduleLoadFinished();
39 
40     /** Returns {@code true} if the recorded programs were loaded, otherwise {@code false}. */
isRecordedProgramLoadFinished()41     boolean isRecordedProgramLoadFinished();
42 
43     /** Returns past recordings. */
getRecordedPrograms()44     List<RecordedProgram> getRecordedPrograms();
45 
46     /** Returns past recorded programs in the given series. */
getRecordedPrograms(long seriesRecordingId)47     List<RecordedProgram> getRecordedPrograms(long seriesRecordingId);
48 
49     /**
50      * Returns all {@link ScheduledRecording} regardless of state.
51      *
52      * <p>The result doesn't contain the deleted schedules.
53      */
getAllScheduledRecordings()54     List<ScheduledRecording> getAllScheduledRecordings();
55 
56     /**
57      * Returns all available {@link ScheduledRecording}, it contains started and non started
58      * recordings.
59      */
getAvailableScheduledRecordings()60     List<ScheduledRecording> getAvailableScheduledRecordings();
61 
62     /** Returns started recordings that expired. */
getStartedRecordings()63     List<ScheduledRecording> getStartedRecordings();
64 
65     /** Returns scheduled but not started recordings that have not expired. */
getNonStartedScheduledRecordings()66     List<ScheduledRecording> getNonStartedScheduledRecordings();
67 
68     /** Returns failed recordings. */
getFailedScheduledRecordings()69     List<ScheduledRecording> getFailedScheduledRecordings();
70 
71     /** Returns series recordings. */
getSeriesRecordings()72     List<SeriesRecording> getSeriesRecordings();
73 
74     /** Returns series recordings from the given input. */
getSeriesRecordings(String inputId)75     List<SeriesRecording> getSeriesRecordings(String inputId);
76 
77     /**
78      * Returns the next start time after {@code time} or {@link #NEXT_START_TIME_NOT_FOUND} if none
79      * is found.
80      *
81      * @param time time milliseconds
82      */
getNextScheduledStartTimeAfter(long time)83     long getNextScheduledStartTimeAfter(long time);
84 
85     /**
86      * Returns a list of the schedules with a overlap with the given time period inclusive and with
87      * the given state.
88      *
89      * <p>A recording overlaps with a period when {@code recording.getStartTime() <=
90      * period.getUpper() && recording.getEndTime() >= period.getLower()}.
91      *
92      * @param period a time period in milliseconds.
93      * @param state the state of the schedule.
94      */
getScheduledRecordings(Range<Long> period, @RecordingState int state)95     List<ScheduledRecording> getScheduledRecordings(Range<Long> period, @RecordingState int state);
96 
97     /** Returns a list of the schedules in the given series. */
getScheduledRecordings(long seriesRecordingId)98     List<ScheduledRecording> getScheduledRecordings(long seriesRecordingId);
99 
100     /** Returns a list of the schedules from the given input. */
getScheduledRecordings(String inputId)101     List<ScheduledRecording> getScheduledRecordings(String inputId);
102 
103     /** Add a {@link OnDvrScheduleLoadFinishedListener}. */
addDvrScheduleLoadFinishedListener(OnDvrScheduleLoadFinishedListener listener)104     void addDvrScheduleLoadFinishedListener(OnDvrScheduleLoadFinishedListener listener);
105 
106     /** Remove a {@link OnDvrScheduleLoadFinishedListener}. */
removeDvrScheduleLoadFinishedListener(OnDvrScheduleLoadFinishedListener listener)107     void removeDvrScheduleLoadFinishedListener(OnDvrScheduleLoadFinishedListener listener);
108 
109     /** Add a {@link OnRecordedProgramLoadFinishedListener}. */
addRecordedProgramLoadFinishedListener(OnRecordedProgramLoadFinishedListener listener)110     void addRecordedProgramLoadFinishedListener(OnRecordedProgramLoadFinishedListener listener);
111 
112     /** Remove a {@link OnRecordedProgramLoadFinishedListener}. */
removeRecordedProgramLoadFinishedListener(OnRecordedProgramLoadFinishedListener listener)113     void removeRecordedProgramLoadFinishedListener(OnRecordedProgramLoadFinishedListener listener);
114 
115     /** Add a {@link ScheduledRecordingListener}. */
addScheduledRecordingListener(ScheduledRecordingListener scheduledRecordingListener)116     void addScheduledRecordingListener(ScheduledRecordingListener scheduledRecordingListener);
117 
118     /** Remove a {@link ScheduledRecordingListener}. */
removeScheduledRecordingListener(ScheduledRecordingListener scheduledRecordingListener)119     void removeScheduledRecordingListener(ScheduledRecordingListener scheduledRecordingListener);
120 
121     /** Add a {@link RecordedProgramListener}. */
addRecordedProgramListener(RecordedProgramListener listener)122     void addRecordedProgramListener(RecordedProgramListener listener);
123 
124     /** Remove a {@link RecordedProgramListener}. */
removeRecordedProgramListener(RecordedProgramListener listener)125     void removeRecordedProgramListener(RecordedProgramListener listener);
126 
127     /** Add a {@link ScheduledRecordingListener}. */
addSeriesRecordingListener(SeriesRecordingListener seriesRecordingListener)128     void addSeriesRecordingListener(SeriesRecordingListener seriesRecordingListener);
129 
130     /** Remove a {@link ScheduledRecordingListener}. */
removeSeriesRecordingListener(SeriesRecordingListener seriesRecordingListener)131     void removeSeriesRecordingListener(SeriesRecordingListener seriesRecordingListener);
132 
133     /**
134      * Returns the scheduled recording program with the given recordingId or null if is not found.
135      */
136     @Nullable
getScheduledRecording(long recordingId)137     ScheduledRecording getScheduledRecording(long recordingId);
138 
139     /** Returns the scheduled recording program with the given programId or null if is not found. */
140     @Nullable
getScheduledRecordingForProgramId(long programId)141     ScheduledRecording getScheduledRecordingForProgramId(long programId);
142 
143     /** Returns the recorded program with the given recordingId or null if is not found. */
144     @Nullable
getRecordedProgram(long recordingId)145     RecordedProgram getRecordedProgram(long recordingId);
146 
147     /** Returns the series recording with the given seriesId or null if is not found. */
148     @Nullable
getSeriesRecording(long seriesRecordingId)149     SeriesRecording getSeriesRecording(long seriesRecordingId);
150 
151     /** Returns the series recording with the given series ID or {@code null} if not found. */
152     @Nullable
getSeriesRecording(String seriesId)153     SeriesRecording getSeriesRecording(String seriesId);
154 
155     /** Returns the schedules which are marked deleted. */
getDeletedSchedules()156     Collection<ScheduledRecording> getDeletedSchedules();
157 
158     /** Returns the program IDs which is not allowed to make a schedule automatically. */
159     @NonNull
getDisallowedProgramIds()160     Collection<Long> getDisallowedProgramIds();
161 
162     /**
163      * Checks each of the give series recordings to see if it's empty, i.e., it doesn't contains any
164      * available schedules or recorded programs, and it's status is {@link
165      * SeriesRecording#STATE_SERIES_STOPPED}; and removes those empty series recordings.
166      */
checkAndRemoveEmptySeriesRecording(long... seriesRecordingIds)167     void checkAndRemoveEmptySeriesRecording(long... seriesRecordingIds);
168 
169     /** Listens for the DVR schedules loading finished. */
170     interface OnDvrScheduleLoadFinishedListener {
onDvrScheduleLoadFinished()171         void onDvrScheduleLoadFinished();
172     }
173 
174     /** Listens for the recorded program loading finished. */
175     interface OnRecordedProgramLoadFinishedListener {
onRecordedProgramLoadFinished()176         void onRecordedProgramLoadFinished();
177     }
178 
179     /** Listens for changes to {@link ScheduledRecording}s. */
180     interface ScheduledRecordingListener {
onScheduledRecordingAdded(ScheduledRecording... scheduledRecordings)181         void onScheduledRecordingAdded(ScheduledRecording... scheduledRecordings);
182 
onScheduledRecordingRemoved(ScheduledRecording... scheduledRecordings)183         void onScheduledRecordingRemoved(ScheduledRecording... scheduledRecordings);
184 
185         /**
186          * Called when the schedules are updated.
187          *
188          * <p>Note that the passed arguments are the new objects with the same ID as the old ones.
189          */
onScheduledRecordingStatusChanged(ScheduledRecording... scheduledRecordings)190         void onScheduledRecordingStatusChanged(ScheduledRecording... scheduledRecordings);
191     }
192 
193     /** Listens for changes to {@link SeriesRecording}s. */
194     interface SeriesRecordingListener {
onSeriesRecordingAdded(SeriesRecording... seriesRecordings)195         void onSeriesRecordingAdded(SeriesRecording... seriesRecordings);
196 
onSeriesRecordingRemoved(SeriesRecording... seriesRecordings)197         void onSeriesRecordingRemoved(SeriesRecording... seriesRecordings);
198 
onSeriesRecordingChanged(SeriesRecording... seriesRecordings)199         void onSeriesRecordingChanged(SeriesRecording... seriesRecordings);
200     }
201 
202     /** Listens for changes to {@link RecordedProgram}s. */
203     interface RecordedProgramListener {
onRecordedProgramsAdded(RecordedProgram... recordedPrograms)204         void onRecordedProgramsAdded(RecordedProgram... recordedPrograms);
205 
onRecordedProgramsChanged(RecordedProgram... recordedPrograms)206         void onRecordedProgramsChanged(RecordedProgram... recordedPrograms);
207 
onRecordedProgramsRemoved(RecordedProgram... recordedPrograms)208         void onRecordedProgramsRemoved(RecordedProgram... recordedPrograms);
209     }
210 }
211