HdmiRecordListener.java revision f406cc3442b100e516298318a09af4a42f6bb33a
1/*
2 * Copyright (C) 2014 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
17package android.hardware.hdmi;
18
19import android.annotation.SystemApi;
20import android.hardware.hdmi.HdmiRecordSources.RecordSource;
21
22/**
23 * Listener for hdmi record feature including one touch record and timer recording.
24 * @hide
25 */
26@SystemApi
27public abstract class HdmiRecordListener {
28    protected HdmiRecordListener() {}
29
30    /**
31     * Called when TV received one touch record request from record device. The client of this
32     * should use {@link HdmiRecordSources} to return it.
33     *
34     * @param recorderAddress
35     * @return record source to be used for recording. Null if no device is available.
36     */
37    public abstract RecordSource getOneTouchRecordSource(int recorderAddress);
38
39    /**
40     * Called when one touch record is started or failed during initialization.
41     *
42     * @param result result code. For more details, please look at all constants starting with
43     *            "ONE_TOUCH_RECORD_". Only
44     *            {@link HdmiControlManager#ONE_TOUCH_RECORD_RECORDING_CURRENTLY_SELECTED_SOURCE},
45     *            {@link HdmiControlManager#ONE_TOUCH_RECORD_RECORDING_DIGITAL_SERVICE},
46     *            {@link HdmiControlManager#ONE_TOUCH_RECORD_RECORDING_ANALOGUE_SERVICE}, and
47     *            {@link HdmiControlManager#ONE_TOUCH_RECORD_RECORDING_EXTERNAL_INPUT} mean normal
48     *            start of recording; otherwise, describes failure.
49     */
50    public void onOneTouchRecordResult(int result) {
51    }
52
53    /**
54     * Called when timer recording is started or failed during initialization.
55     *
56     * @param data timer status data. For more details, look at {@link TimerStatusData}.
57     */
58    public void onTimerRecordingResult(TimerStatusData data) {
59    }
60
61    /**
62     * [Timer overlap warning] [Media Info] [Timer Programmed Info]
63     * @hide
64     */
65    @SystemApi
66    public static class TimerStatusData {
67        private boolean mOverlapped;
68        private int mMediaInfo;
69        private boolean mProgrammed;
70
71        private int mProgrammedInfo;
72        private int mNotProgrammedError;
73        private int mDurationHour;
74        private int mDurationMinute;
75
76        private int mExtraError;
77
78        static TimerStatusData parseFrom(int result) {
79            TimerStatusData data = new TimerStatusData();
80            // Timer Overlap Warning - 1 bit
81            data.mOverlapped = ((result >> 31) & 0x1) != 0;
82            // Media Info - 2 bits;
83            data.mMediaInfo = (result >> 29) & 0x7;
84            // Programmed Indicator - 1 bit;
85            data.mProgrammed = ((result >> 28) & 0x1) != 0;
86            if (data.mProgrammed) {
87                data.mProgrammedInfo = (result >> 24) & 0xF;
88                data.mDurationHour = bcdByteToInt((byte) ((result >> 16) & 0xFF));
89                data.mDurationMinute = bcdByteToInt((byte) ((result >> 8) & 0xFF));
90            } else {
91                data.mNotProgrammedError = (result >> 24) & 0xF;
92                data.mDurationHour = bcdByteToInt((byte) ((result >> 16) & 0xFF));
93                data.mDurationMinute = bcdByteToInt((byte) ((result >> 8) & 0xFF));
94            }
95
96            // Programmed Info - 4 bits
97            data.mExtraError = result & 0xFF;
98            return data;
99        }
100
101        // Most significant 4 bits is used for 10 digits and
102        // Least significant 4 bits is used for 1 digits.
103        private static int bcdByteToInt(byte value) {
104            return ((value >> 4) & 0xF) * 10 + value & 0xF;
105        }
106
107        private TimerStatusData() {}
108
109        /**
110         * Indicates if there is another timer block already set which overlaps with this new
111         * recording request.
112         */
113        public boolean isOverlapped() {
114            return mOverlapped;
115        }
116
117        /**
118         * Indicates if removable media is present and its write protect state.
119         * It should be one of the following values.
120         * <ul>
121         *   <li>{@link HdmiControlManager#TIMER_STATUS_MEDIA_INFO_PRESENT_NOT_PROTECTED}
122         *   <li>{@link HdmiControlManager#TIMER_STATUS_MEDIA_INFO_PRESENT_PROTECTED}
123         *   <li>{@link HdmiControlManager#TIMER_STATUS_MEDIA_INFO_NOT_PRESENT}
124         * </ul>
125         */
126        public int getMediaInfo() {
127            return mMediaInfo;
128        }
129
130        /**
131         * Selector for [Timer Programmed Info].
132         * If it is {@code true}, {@link #getProgrammedInfo()} would have meaningful value and
133         * ignore result of {@link #getNotProgammedError()}.
134         */
135        public boolean isProgrammed() {
136            return mProgrammed;
137        }
138
139        /**
140         * Information indicating any non-fatal issues with the programming request.
141         * It's set only if {@link #isProgrammed()} returns true.
142         * It should be one of the following values.
143         * <ul>
144         *   <li>{@link HdmiControlManager#TIMER_STATUS_PROGRAMMED_INFO_ENOUGH_SPACE}
145         *   <li>{@link HdmiControlManager#TIMER_STATUS_PROGRAMMED_INFO_NOT_ENOUGH_SPACE}
146         *   <li>{@link HdmiControlManager#TIMER_STATUS_PROGRAMMED_INFO_MIGHT_NOT_ENOUGH_SPACE}
147         *   <li>{@link HdmiControlManager#TIMER_STATUS_PROGRAMMED_INFO_NO_MEDIA_INFO}
148         * </ul>
149         *
150         * @throws IllegalStateException if it's called when {@link #isProgrammed()}
151         *                               returns false
152         */
153        public int getProgrammedInfo() {
154            if (!isProgrammed()) {
155                throw new IllegalStateException(
156                        "No programmed info. Call getNotProgammedError() instead.");
157            }
158            return mProgrammedInfo;
159        }
160
161        /**
162         * Information indicating any fatal issues with the programming request.
163         * It's set only if {@link #isProgrammed()} returns false.
164         * it should be one of the following values.
165         * <ul>
166         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_NO_FREE_TIME}
167         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_DATE_OUT_OF_RANGE}
168         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_INVALID_SEQUENCE}
169         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_INVALID_EXTERNAL_PHYSICAL_NUMBER}
170         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_CA_NOT_SUPPORTED}
171         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_NO_CA_ENTITLEMENTS}
172         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_UNSUPPORTED_RESOLUTION}
173         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_PARENTAL_LOCK_ON}
174         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_CLOCK_FAILURE}
175         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_DUPLICATED}
176         * </ul>
177         *
178         * @throws IllegalStateException if it's called when {@link #isProgrammed()}
179         *                               returns true
180         */
181        public int getNotProgammedError() {
182            if (isProgrammed()) {
183                throw new IllegalStateException(
184                        "Has no not-programmed error. Call getProgrammedInfo() instead.");
185            }
186            return mNotProgrammedError;
187        }
188
189        /**
190         * Duration hours.
191         * Optional parameter: Contains an estimate of the space left on the media, expressed as a
192         * time. This parameter may be returned when:
193         *  - [Programmed Info] is “Not enough space available”; or
194         *  - [Not Programmed Info] is “Duplicate: already programmed”
195         */
196        public int getDurationHour() {
197            return mDurationHour;
198        }
199
200        /**
201         * Duration minutes.
202         * Optional parameter: Contains an estimate of the space left on the media, expressed as a
203         * time. This parameter may be returned when:
204         *  - [Programmed Info] is “Not enough space available”; or
205         *  - [Not Programmed Info] is “Duplicate: already programmed”
206         */
207        public int getDurationMinute() {
208            return mDurationMinute;
209        }
210
211        /**
212         * Extra error code.
213         * <ul>
214         * <li>{@link HdmiControlManager#TIMER_RECORDING_RESULT_EXTRA_NO_ERROR}
215         *     No extra errors. Other values of this class might be available.
216         * <li>{@link HdmiControlManager#TIMER_RECORDING_RESULT_EXTRA_CHECK_RECORDER_CONNECTION}
217         *     Check record connection. Other values of this class should be ignored.
218         * <li>{@link HdmiControlManager#TIMER_RECORDING_RESULT_EXTRA_FAIL_TO_RECORD_SELECTED_SOURCE}
219         *     Fail to record selected source. Other values of this class should be ignored.
220         * <li>{@link HdmiControlManager#TIMER_RECORDING_RESULT_EXTRA_CEC_DISABLED}
221         *     Cec disabled. Other values of this class should be ignored.
222         * </ul>
223         */
224        public int getExtraError() {
225            return mExtraError;
226        }
227    }
228
229    /**
230     * Called when receiving result for clear timer recording request.
231     *
232     * @param result result of clear timer. It should be one of
233     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_RECORDING}
234     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_MATCHING},
235     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_INFO_AVAILABLE},
236     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_TIMER_CLEARED},
237     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_CHECK_RECORDER_CONNECTION},
238     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_FAIL_TO_CLEAR_SELECTED_SOURCE},
239     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_CEC_DISABLE}.
240     */
241    public void onClearTimerRecordingResult(int result) {
242    }
243}
244