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 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 
     35     boolean isInitialized();
     36 
     37     /** Returns {@code true} if the schedules were loaded, otherwise {@code false}. */
     38     boolean isDvrScheduleLoadFinished();
     39 
     40     /** Returns {@code true} if the recorded programs were loaded, otherwise {@code false}. */
     41     boolean isRecordedProgramLoadFinished();
     42 
     43     /** Returns past recordings. */
     44     List<RecordedProgram> getRecordedPrograms();
     45 
     46     /** Returns past recorded programs in the given series. */
     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      */
     54     List<ScheduledRecording> getAllScheduledRecordings();
     55 
     56     /**
     57      * Returns all available {@link ScheduledRecording}, it contains started and non started
     58      * recordings.
     59      */
     60     List<ScheduledRecording> getAvailableScheduledRecordings();
     61 
     62     /** Returns started recordings that expired. */
     63     List<ScheduledRecording> getStartedRecordings();
     64 
     65     /** Returns scheduled but not started recordings that have not expired. */
     66     List<ScheduledRecording> getNonStartedScheduledRecordings();
     67 
     68     /** Returns failed recordings. */
     69     List<ScheduledRecording> getFailedScheduledRecordings();
     70 
     71     /** Returns series recordings. */
     72     List<SeriesRecording> getSeriesRecordings();
     73 
     74     /** Returns series recordings from the given input. */
     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      */
     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      */
     95     List<ScheduledRecording> getScheduledRecordings(Range<Long> period, @RecordingState int state);
     96 
     97     /** Returns a list of the schedules in the given series. */
     98     List<ScheduledRecording> getScheduledRecordings(long seriesRecordingId);
     99 
    100     /** Returns a list of the schedules from the given input. */
    101     List<ScheduledRecording> getScheduledRecordings(String inputId);
    102 
    103     /** Add a {@link OnDvrScheduleLoadFinishedListener}. */
    104     void addDvrScheduleLoadFinishedListener(OnDvrScheduleLoadFinishedListener listener);
    105 
    106     /** Remove a {@link OnDvrScheduleLoadFinishedListener}. */
    107     void removeDvrScheduleLoadFinishedListener(OnDvrScheduleLoadFinishedListener listener);
    108 
    109     /** Add a {@link OnRecordedProgramLoadFinishedListener}. */
    110     void addRecordedProgramLoadFinishedListener(OnRecordedProgramLoadFinishedListener listener);
    111 
    112     /** Remove a {@link OnRecordedProgramLoadFinishedListener}. */
    113     void removeRecordedProgramLoadFinishedListener(OnRecordedProgramLoadFinishedListener listener);
    114 
    115     /** Add a {@link ScheduledRecordingListener}. */
    116     void addScheduledRecordingListener(ScheduledRecordingListener scheduledRecordingListener);
    117 
    118     /** Remove a {@link ScheduledRecordingListener}. */
    119     void removeScheduledRecordingListener(ScheduledRecordingListener scheduledRecordingListener);
    120 
    121     /** Add a {@link RecordedProgramListener}. */
    122     void addRecordedProgramListener(RecordedProgramListener listener);
    123 
    124     /** Remove a {@link RecordedProgramListener}. */
    125     void removeRecordedProgramListener(RecordedProgramListener listener);
    126 
    127     /** Add a {@link ScheduledRecordingListener}. */
    128     void addSeriesRecordingListener(SeriesRecordingListener seriesRecordingListener);
    129 
    130     /** Remove a {@link ScheduledRecordingListener}. */
    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
    137     ScheduledRecording getScheduledRecording(long recordingId);
    138 
    139     /** Returns the scheduled recording program with the given programId or null if is not found. */
    140     @Nullable
    141     ScheduledRecording getScheduledRecordingForProgramId(long programId);
    142 
    143     /** Returns the recorded program with the given recordingId or null if is not found. */
    144     @Nullable
    145     RecordedProgram getRecordedProgram(long recordingId);
    146 
    147     /** Returns the series recording with the given seriesId or null if is not found. */
    148     @Nullable
    149     SeriesRecording getSeriesRecording(long seriesRecordingId);
    150 
    151     /** Returns the series recording with the given series ID or {@code null} if not found. */
    152     @Nullable
    153     SeriesRecording getSeriesRecording(String seriesId);
    154 
    155     /** Returns the schedules which are marked deleted. */
    156     Collection<ScheduledRecording> getDeletedSchedules();
    157 
    158     /** Returns the program IDs which is not allowed to make a schedule automatically. */
    159     @NonNull
    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      */
    167     void checkAndRemoveEmptySeriesRecording(long... seriesRecordingIds);
    168 
    169     /** Listens for the DVR schedules loading finished. */
    170     interface OnDvrScheduleLoadFinishedListener {
    171         void onDvrScheduleLoadFinished();
    172     }
    173 
    174     /** Listens for the recorded program loading finished. */
    175     interface OnRecordedProgramLoadFinishedListener {
    176         void onRecordedProgramLoadFinished();
    177     }
    178 
    179     /** Listens for changes to {@link ScheduledRecording}s. */
    180     interface ScheduledRecordingListener {
    181         void onScheduledRecordingAdded(ScheduledRecording... scheduledRecordings);
    182 
    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          */
    190         void onScheduledRecordingStatusChanged(ScheduledRecording... scheduledRecordings);
    191     }
    192 
    193     /** Listens for changes to {@link SeriesRecording}s. */
    194     interface SeriesRecordingListener {
    195         void onSeriesRecordingAdded(SeriesRecording... seriesRecordings);
    196 
    197         void onSeriesRecordingRemoved(SeriesRecording... seriesRecordings);
    198 
    199         void onSeriesRecordingChanged(SeriesRecording... seriesRecordings);
    200     }
    201 
    202     /** Listens for changes to {@link RecordedProgram}s. */
    203     interface RecordedProgramListener {
    204         void onRecordedProgramsAdded(RecordedProgram... recordedPrograms);
    205 
    206         void onRecordedProgramsChanged(RecordedProgram... recordedPrograms);
    207 
    208         void onRecordedProgramsRemoved(RecordedProgram... recordedPrograms);
    209     }
    210 }
    211