HdmiRecordListener.java revision 2b0da5c4c84305f1d391dc78b85e244c9fd92456
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/*
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Copyright (C) 2014 The Android Open Source Project
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Licensed under the Apache License, Version 2.0 (the "License");
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * you may not use this file except in compliance with the License.
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * You may obtain a copy of the License at
74ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch *
86e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) *      http://www.apache.org/licenses/LICENSE-2.0
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Unless required by applicable law or agreed to in writing, software
116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) * distributed under the License is distributed on an "AS IS" BASIS,
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * See the License for the specific language governing permissions and
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * limitations under the License.
1523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) */
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)package android.hardware.hdmi;
18116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
19116680a4aac90f2aa7413d9095a592090648e557Ben Murdochimport android.annotation.SystemApi;
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciimport android.hardware.hdmi.HdmiRecordSources.RecordSource;
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/**
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Listener for hdmi record feature including one touch record and timer recording.
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * @hide
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)@SystemApi
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public abstract class HdmiRecordListener {
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public HdmiRecordListener() {}
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
304ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch    /**
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Called when TV received one touch record request from record device. The client of this
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * should use {@link HdmiRecordSources} to return it.
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param recorderAddress
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @return record source to be used for recording. Null if no device is available.
364ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch     */
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public abstract RecordSource onOneTouchRecordSourceRequested(int recorderAddress);
386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Called when one touch record is started or failed during initialization.
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param result result code. For more details, please look at all constants starting with
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *            "ONE_TOUCH_RECORD_". Only
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *            {@link HdmiControlManager#ONE_TOUCH_RECORD_RECORDING_CURRENTLY_SELECTED_SOURCE},
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *            {@link HdmiControlManager#ONE_TOUCH_RECORD_RECORDING_DIGITAL_SERVICE},
464ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch     *            {@link HdmiControlManager#ONE_TOUCH_RECORD_RECORDING_ANALOGUE_SERVICE}, and
474ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch     *            {@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) & 0x3;
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                // Programmed Info - 4 bits
92                data.mNotProgrammedError = (result >> 24) & 0xF;
93                data.mDurationHour = bcdByteToInt((byte) ((result >> 16) & 0xFF));
94                data.mDurationMinute = bcdByteToInt((byte) ((result >> 8) & 0xFF));
95            }
96
97            // The last byte is used for extra error.
98            data.mExtraError = result & 0xFF;
99            return data;
100        }
101
102        // Most significant 4 bits is used for 10 digits and
103        // Least significant 4 bits is used for 1 digits.
104        private static int bcdByteToInt(byte value) {
105            return ((value >> 4) & 0xF) * 10 + value & 0xF;
106        }
107
108        private TimerStatusData() {}
109
110        /**
111         * Indicates if there is another timer block already set which overlaps with this new
112         * recording request.
113         */
114        public boolean isOverlapped() {
115            return mOverlapped;
116        }
117
118        /**
119         * Indicates if removable media is present and its write protect state.
120         * It should be one of the following values.
121         * <ul>
122         *   <li>{@link HdmiControlManager#TIMER_STATUS_MEDIA_INFO_PRESENT_NOT_PROTECTED}
123         *   <li>{@link HdmiControlManager#TIMER_STATUS_MEDIA_INFO_PRESENT_PROTECTED}
124         *   <li>{@link HdmiControlManager#TIMER_STATUS_MEDIA_INFO_NOT_PRESENT}
125         * </ul>
126         */
127        public int getMediaInfo() {
128            return mMediaInfo;
129        }
130
131        /**
132         * Selector for [Timer Programmed Info].
133         * If it is {@code true}, {@link #getProgrammedInfo()} would have meaningful value and
134         * ignore result of {@link #getNotProgammedError()}.
135         */
136        public boolean isProgrammed() {
137            return mProgrammed;
138        }
139
140        /**
141         * Information indicating any non-fatal issues with the programming request.
142         * It's set only if {@link #isProgrammed()} returns true.
143         * It should be one of the following values.
144         * <ul>
145         *   <li>{@link HdmiControlManager#TIMER_STATUS_PROGRAMMED_INFO_ENOUGH_SPACE}
146         *   <li>{@link HdmiControlManager#TIMER_STATUS_PROGRAMMED_INFO_NOT_ENOUGH_SPACE}
147         *   <li>{@link HdmiControlManager#TIMER_STATUS_PROGRAMMED_INFO_MIGHT_NOT_ENOUGH_SPACE}
148         *   <li>{@link HdmiControlManager#TIMER_STATUS_PROGRAMMED_INFO_NO_MEDIA_INFO}
149         * </ul>
150         *
151         * @throws IllegalStateException if it's called when {@link #isProgrammed()}
152         *                               returns false
153         */
154        public int getProgrammedInfo() {
155            if (!isProgrammed()) {
156                throw new IllegalStateException(
157                        "No programmed info. Call getNotProgammedError() instead.");
158            }
159            return mProgrammedInfo;
160        }
161
162        /**
163         * Information indicating any fatal issues with the programming request.
164         * It's set only if {@link #isProgrammed()} returns false.
165         * it should be one of the following values.
166         * <ul>
167         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_NO_FREE_TIME}
168         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_DATE_OUT_OF_RANGE}
169         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_INVALID_SEQUENCE}
170         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_INVALID_EXTERNAL_PHYSICAL_NUMBER}
171         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_CA_NOT_SUPPORTED}
172         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_NO_CA_ENTITLEMENTS}
173         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_UNSUPPORTED_RESOLUTION}
174         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_PARENTAL_LOCK_ON}
175         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_CLOCK_FAILURE}
176         *   <li>{@link HdmiControlManager#TIMER_STATUS_NOT_PROGRAMMED_DUPLICATED}
177         * </ul>
178         *
179         * @throws IllegalStateException if it's called when {@link #isProgrammed()}
180         *                               returns true
181         */
182        public int getNotProgammedError() {
183            if (isProgrammed()) {
184                throw new IllegalStateException(
185                        "Has no not-programmed error. Call getProgrammedInfo() instead.");
186            }
187            return mNotProgrammedError;
188        }
189
190        /**
191         * Duration hours.
192         * Optional parameter: Contains an estimate of the space left on the media, expressed as a
193         * time. This parameter may be returned when:
194         *  - [Programmed Info] is “Not enough space available”; or
195         *  - [Not Programmed Info] is “Duplicate: already programmed”
196         */
197        public int getDurationHour() {
198            return mDurationHour;
199        }
200
201        /**
202         * Duration minutes.
203         * Optional parameter: Contains an estimate of the space left on the media, expressed as a
204         * time. This parameter may be returned when:
205         *  - [Programmed Info] is “Not enough space available”; or
206         *  - [Not Programmed Info] is “Duplicate: already programmed”
207         */
208        public int getDurationMinute() {
209            return mDurationMinute;
210        }
211
212        /**
213         * Extra error code.
214         * <ul>
215         * <li>{@link HdmiControlManager#TIMER_RECORDING_RESULT_EXTRA_NO_ERROR}
216         *     No extra errors. Other values of this class might be available.
217         * <li>{@link HdmiControlManager#TIMER_RECORDING_RESULT_EXTRA_CHECK_RECORDER_CONNECTION}
218         *     Check record connection. Other values of this class should be ignored.
219         * <li>{@link HdmiControlManager#TIMER_RECORDING_RESULT_EXTRA_FAIL_TO_RECORD_SELECTED_SOURCE}
220         *     Fail to record selected source. Other values of this class should be ignored.
221         * <li>{@link HdmiControlManager#TIMER_RECORDING_RESULT_EXTRA_CEC_DISABLED}
222         *     Cec disabled. Other values of this class should be ignored.
223         * </ul>
224         */
225        public int getExtraError() {
226            return mExtraError;
227        }
228    }
229
230    /**
231     * Called when receiving result for clear timer recording request.
232     *
233     * @param result result of clear timer. It should be one of
234     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_RECORDING}
235     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_MATCHING},
236     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_INFO_AVAILABLE},
237     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_TIMER_CLEARED},
238     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_CHECK_RECORDER_CONNECTION},
239     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_FAIL_TO_CLEAR_SELECTED_SOURCE},
240     *            {@link HdmiControlManager#CLEAR_TIMER_STATUS_CEC_DISABLE}.
241     */
242    public void onClearTimerRecordingResult(int result) {
243    }
244}
245