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