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