blob: 4ac58766ca9428b9d00a6222e29a4e6b006c1694 [file] [log] [blame]
Jae Seo39570912014-02-20 18:23:25 -08001/*
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
Jae Seod5cc4a22014-05-30 16:57:43 -070017package android.media.tv;
Jae Seo39570912014-02-20 18:23:25 -080018
19import android.content.Context;
Youngsang Cho9a22f0f2014-04-09 22:51:54 +090020import android.graphics.Rect;
Jae Seo3d04b762015-05-12 20:05:00 -070021import android.media.PlaybackParams;
Jae Seo39570912014-02-20 18:23:25 -080022import android.net.Uri;
Jae Seoa759b112014-07-18 22:16:08 -070023import android.os.Bundle;
Youngsang Cho9a22f0f2014-04-09 22:51:54 +090024import android.os.IBinder;
Jae Seo6a6059a2014-04-17 21:35:29 -070025import android.os.Looper;
Jae Seo39570912014-02-20 18:23:25 -080026import android.os.Message;
27import android.util.Log;
Jae Seo6a6059a2014-04-17 21:35:29 -070028import android.view.InputChannel;
29import android.view.InputEvent;
30import android.view.InputEventReceiver;
Jae Seo39570912014-02-20 18:23:25 -080031import android.view.Surface;
32
33import com.android.internal.os.HandlerCaller;
Youngsang Cho9a22f0f2014-04-09 22:51:54 +090034import com.android.internal.os.SomeArgs;
Jae Seo39570912014-02-20 18:23:25 -080035
36/**
37 * Implements the internal ITvInputSession interface to convert incoming calls on to it back to
38 * calls on the public TvInputSession interface, scheduling them on the main thread of the process.
39 *
40 * @hide
41 */
42public class ITvInputSessionWrapper extends ITvInputSession.Stub implements HandlerCaller.Callback {
43 private static final String TAG = "TvInputSessionWrapper";
44
Dongwon Kang21add3e2015-04-27 17:43:52 +090045 private static final int EXECUTE_MESSAGE_TIMEOUT_SHORT_MILLIS = 50;
46 private static final int EXECUTE_MESSAGE_TUNE_TIMEOUT_MILLIS = 2000;
47 private static final int EXECUTE_MESSAGE_TIMEOUT_LONG_MILLIS = 5 * 1000;
Youngsang Cho9df2c1b2014-09-03 22:27:56 +090048
Jae Seo39570912014-02-20 18:23:25 -080049 private static final int DO_RELEASE = 1;
Ji-Hwan Lee15c56aa2014-08-18 22:01:55 +090050 private static final int DO_SET_MAIN = 2;
Ji-Hwan Lee4c526972014-07-22 04:46:30 +090051 private static final int DO_SET_SURFACE = 3;
52 private static final int DO_DISPATCH_SURFACE_CHANGED = 4;
53 private static final int DO_SET_STREAM_VOLUME = 5;
54 private static final int DO_TUNE = 6;
55 private static final int DO_SET_CAPTION_ENABLED = 7;
56 private static final int DO_SELECT_TRACK = 8;
Jae Seo10d285a2014-07-31 22:46:47 +090057 private static final int DO_APP_PRIVATE_COMMAND = 9;
58 private static final int DO_CREATE_OVERLAY_VIEW = 10;
59 private static final int DO_RELAYOUT_OVERLAY_VIEW = 11;
60 private static final int DO_REMOVE_OVERLAY_VIEW = 12;
Jae Seoa9033832015-03-11 19:29:46 -070061 private static final int DO_UNBLOCK_CONTENT = 13;
Jae Seoa826d012016-01-18 13:03:35 -080062 private static final int DO_TIME_SHIFT_PLAY = 14;
63 private static final int DO_TIME_SHIFT_PAUSE = 15;
64 private static final int DO_TIME_SHIFT_RESUME = 16;
65 private static final int DO_TIME_SHIFT_SEEK_TO = 17;
66 private static final int DO_TIME_SHIFT_SET_PLAYBACK_PARAMS = 18;
67 private static final int DO_TIME_SHIFT_ENABLE_POSITION_TRACKING = 19;
68 private static final int DO_CONNECT = 20;
69 private static final int DO_DISCONNECT = 21;
70 private static final int DO_START_RECORDING = 22;
71 private static final int DO_STOP_RECORDING = 23;
Jae Seo39570912014-02-20 18:23:25 -080072
Jae Seoa826d012016-01-18 13:03:35 -080073 private final boolean mIsRecordingSession;
Jae Seo39570912014-02-20 18:23:25 -080074 private final HandlerCaller mCaller;
75
Jae Seo782f7342014-06-03 12:51:21 -070076 private TvInputService.Session mTvInputSessionImpl;
Jae Seoa826d012016-01-18 13:03:35 -080077 private TvInputService.RecordingSession mTvInputRecordingSessionImpl;
78
Jae Seo6a6059a2014-04-17 21:35:29 -070079 private InputChannel mChannel;
80 private TvInputEventReceiver mReceiver;
81
Jae Seo782f7342014-06-03 12:51:21 -070082 public ITvInputSessionWrapper(Context context, TvInputService.Session sessionImpl,
Jae Seo6a6059a2014-04-17 21:35:29 -070083 InputChannel channel) {
Jae Seoa826d012016-01-18 13:03:35 -080084 mIsRecordingSession = false;
Jae Seo39570912014-02-20 18:23:25 -080085 mCaller = new HandlerCaller(context, null, this, true /* asyncHandler */);
Jae Seo6a6059a2014-04-17 21:35:29 -070086 mTvInputSessionImpl = sessionImpl;
87 mChannel = channel;
88 if (channel != null) {
89 mReceiver = new TvInputEventReceiver(channel, context.getMainLooper());
90 }
Jae Seo39570912014-02-20 18:23:25 -080091 }
92
Jae Seoa826d012016-01-18 13:03:35 -080093 public ITvInputSessionWrapper(Context context,
94 TvInputService.RecordingSession recordingSessionImpl) {
95 mIsRecordingSession = true;
96 mCaller = new HandlerCaller(context, null, this, true /* asyncHandler */);
97 mTvInputRecordingSessionImpl = recordingSessionImpl;
98 }
99
Jae Seo39570912014-02-20 18:23:25 -0800100 @Override
101 public void executeMessage(Message msg) {
Jae Seoa826d012016-01-18 13:03:35 -0800102 if (!mIsRecordingSession && mTvInputSessionImpl == null) {
103 return;
104 }
105 if (mIsRecordingSession && mTvInputRecordingSessionImpl == null) {
Jae Seo39570912014-02-20 18:23:25 -0800106 return;
107 }
108
Jae Seoc94c0512015-11-20 17:00:26 -0800109 long startTime = System.nanoTime();
Jae Seo39570912014-02-20 18:23:25 -0800110 switch (msg.what) {
111 case DO_RELEASE: {
Jae Seo6a6059a2014-04-17 21:35:29 -0700112 mTvInputSessionImpl.release();
113 mTvInputSessionImpl = null;
114 if (mReceiver != null) {
115 mReceiver.dispose();
116 mReceiver = null;
117 }
118 if (mChannel != null) {
119 mChannel.dispose();
120 mChannel = null;
121 }
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900122 break;
Jae Seo39570912014-02-20 18:23:25 -0800123 }
Ji-Hwan Lee15c56aa2014-08-18 22:01:55 +0900124 case DO_SET_MAIN: {
125 mTvInputSessionImpl.setMain((Boolean) msg.obj);
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900126 break;
Ji-Hwan Lee4c526972014-07-22 04:46:30 +0900127 }
Jae Seo39570912014-02-20 18:23:25 -0800128 case DO_SET_SURFACE: {
Jae Seo6a6059a2014-04-17 21:35:29 -0700129 mTvInputSessionImpl.setSurface((Surface) msg.obj);
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900130 break;
Jae Seo39570912014-02-20 18:23:25 -0800131 }
Youngsang Choe821d712014-07-16 14:22:19 -0700132 case DO_DISPATCH_SURFACE_CHANGED: {
133 SomeArgs args = (SomeArgs) msg.obj;
134 mTvInputSessionImpl.dispatchSurfaceChanged(args.argi1, args.argi2, args.argi3);
135 args.recycle();
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900136 break;
Youngsang Choe821d712014-07-16 14:22:19 -0700137 }
Dongwon Kang4b662d12014-07-17 19:24:56 +0900138 case DO_SET_STREAM_VOLUME: {
139 mTvInputSessionImpl.setStreamVolume((Float) msg.obj);
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900140 break;
Jae Seo39570912014-02-20 18:23:25 -0800141 }
142 case DO_TUNE: {
Sungsoo Lim1a6b25e2014-07-09 10:40:43 +0900143 SomeArgs args = (SomeArgs) msg.obj;
144 mTvInputSessionImpl.tune((Uri) args.arg1, (Bundle) args.arg2);
145 args.recycle();
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900146 break;
Jae Seo39570912014-02-20 18:23:25 -0800147 }
Jae Seo2c1c31c2014-07-10 14:57:01 -0700148 case DO_SET_CAPTION_ENABLED: {
149 mTvInputSessionImpl.setCaptionEnabled((Boolean) msg.obj);
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900150 break;
Jae Seo2c1c31c2014-07-10 14:57:01 -0700151 }
Dongwon Kang1f213912014-07-02 18:35:08 +0900152 case DO_SELECT_TRACK: {
Jae Seo10d285a2014-07-31 22:46:47 +0900153 SomeArgs args = (SomeArgs) msg.obj;
154 mTvInputSessionImpl.selectTrack((Integer) args.arg1, (String) args.arg2);
155 args.recycle();
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900156 break;
Dongwon Kang1f213912014-07-02 18:35:08 +0900157 }
Jae Seoa759b112014-07-18 22:16:08 -0700158 case DO_APP_PRIVATE_COMMAND: {
159 SomeArgs args = (SomeArgs) msg.obj;
Jae Seoa826d012016-01-18 13:03:35 -0800160 if (mIsRecordingSession) {
161 mTvInputRecordingSessionImpl.appPrivateCommand(
162 (String) args.arg1, (Bundle) args.arg2);
163 } else {
164 mTvInputSessionImpl.appPrivateCommand((String) args.arg1, (Bundle) args.arg2);
165 }
Jae Seoa759b112014-07-18 22:16:08 -0700166 args.recycle();
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900167 break;
Jae Seoa759b112014-07-18 22:16:08 -0700168 }
Youngsang Cho9a22f0f2014-04-09 22:51:54 +0900169 case DO_CREATE_OVERLAY_VIEW: {
170 SomeArgs args = (SomeArgs) msg.obj;
Jae Seo6a6059a2014-04-17 21:35:29 -0700171 mTvInputSessionImpl.createOverlayView((IBinder) args.arg1, (Rect) args.arg2);
Youngsang Cho9a22f0f2014-04-09 22:51:54 +0900172 args.recycle();
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900173 break;
Youngsang Cho9a22f0f2014-04-09 22:51:54 +0900174 }
175 case DO_RELAYOUT_OVERLAY_VIEW: {
Jae Seo6a6059a2014-04-17 21:35:29 -0700176 mTvInputSessionImpl.relayoutOverlayView((Rect) msg.obj);
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900177 break;
Youngsang Cho9a22f0f2014-04-09 22:51:54 +0900178 }
179 case DO_REMOVE_OVERLAY_VIEW: {
Jae Seo6a6059a2014-04-17 21:35:29 -0700180 mTvInputSessionImpl.removeOverlayView(true);
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900181 break;
Youngsang Cho9a22f0f2014-04-09 22:51:54 +0900182 }
Jae Seoa9033832015-03-11 19:29:46 -0700183 case DO_UNBLOCK_CONTENT: {
Jae Seo91a801d2014-07-24 13:49:03 -0700184 mTvInputSessionImpl.unblockContent((String) msg.obj);
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900185 break;
Jaewan Kim903d6b72014-07-16 11:28:56 +0900186 }
Jae Seoa826d012016-01-18 13:03:35 -0800187 case DO_TIME_SHIFT_PLAY: {
188 mTvInputSessionImpl.timeShiftPlay((Uri) msg.obj);
189 break;
190 }
Dongwon Kang6f0240c2015-03-31 17:56:36 -0700191 case DO_TIME_SHIFT_PAUSE: {
192 mTvInputSessionImpl.timeShiftPause();
193 break;
194 }
195 case DO_TIME_SHIFT_RESUME: {
196 mTvInputSessionImpl.timeShiftResume();
197 break;
198 }
199 case DO_TIME_SHIFT_SEEK_TO: {
200 mTvInputSessionImpl.timeShiftSeekTo((Long) msg.obj);
201 break;
202 }
Jae Seo4b34cc72015-05-15 17:29:39 -0700203 case DO_TIME_SHIFT_SET_PLAYBACK_PARAMS: {
Dongwon Kangcf4f3d52015-05-20 13:57:34 +0900204 mTvInputSessionImpl.timeShiftSetPlaybackParams((PlaybackParams) msg.obj);
Dongwon Kang6f0240c2015-03-31 17:56:36 -0700205 break;
206 }
Jae Seo465f0d62015-04-06 18:40:46 -0700207 case DO_TIME_SHIFT_ENABLE_POSITION_TRACKING: {
208 mTvInputSessionImpl.timeShiftEnablePositionTracking((Boolean) msg.obj);
Dongwon Kang6f0240c2015-03-31 17:56:36 -0700209 break;
210 }
Jae Seoa826d012016-01-18 13:03:35 -0800211 case DO_CONNECT: {
212 SomeArgs args = (SomeArgs) msg.obj;
213 mTvInputRecordingSessionImpl.connect((Uri) args.arg1, (Bundle) args.arg2);
214 args.recycle();
215 break;
216 }
217 case DO_DISCONNECT: {
218 mTvInputRecordingSessionImpl.disconnect();
219 mTvInputRecordingSessionImpl = null;
220 break;
221 }
222 case DO_START_RECORDING: {
223 mTvInputRecordingSessionImpl.startRecording();
224 break;
225 }
226 case DO_STOP_RECORDING: {
227 mTvInputRecordingSessionImpl.stopRecording();
228 break;
229 }
Jae Seo39570912014-02-20 18:23:25 -0800230 default: {
231 Log.w(TAG, "Unhandled message code: " + msg.what);
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900232 break;
Jae Seo39570912014-02-20 18:23:25 -0800233 }
234 }
Jae Seoc94c0512015-11-20 17:00:26 -0800235 long durationMs = (System.nanoTime() - startTime) / (1000 * 1000);
236 if (durationMs > EXECUTE_MESSAGE_TIMEOUT_SHORT_MILLIS) {
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900237 Log.w(TAG, "Handling message (" + msg.what + ") took too long time (duration="
Jae Seoc94c0512015-11-20 17:00:26 -0800238 + durationMs + "ms)");
239 if (msg.what == DO_TUNE && durationMs > EXECUTE_MESSAGE_TUNE_TIMEOUT_MILLIS) {
240 throw new RuntimeException("Too much time to handle tune request. (" + durationMs
Dongwon Kang21add3e2015-04-27 17:43:52 +0900241 + "ms > " + EXECUTE_MESSAGE_TUNE_TIMEOUT_MILLIS + "ms) "
Dongwon Kangc9181722014-11-18 14:29:50 +0900242 + "Consider handling the tune request in a separate thread.");
243 }
Jae Seoc94c0512015-11-20 17:00:26 -0800244 if (durationMs > EXECUTE_MESSAGE_TIMEOUT_LONG_MILLIS) {
Dongwon Kang21add3e2015-04-27 17:43:52 +0900245 throw new RuntimeException("Too much time to handle a request. (type=" + msg.what +
Jae Seoc94c0512015-11-20 17:00:26 -0800246 ", " + durationMs + "ms > " + EXECUTE_MESSAGE_TIMEOUT_LONG_MILLIS + "ms).");
Dongwon Kang21add3e2015-04-27 17:43:52 +0900247 }
Youngsang Cho9df2c1b2014-09-03 22:27:56 +0900248 }
Jae Seo39570912014-02-20 18:23:25 -0800249 }
250
251 @Override
252 public void release() {
Dongwon Kangce34c6d2014-10-27 17:55:27 +0900253 mTvInputSessionImpl.scheduleOverlayViewCleanup();
Jae Seo39570912014-02-20 18:23:25 -0800254 mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_RELEASE));
255 }
256
257 @Override
Ji-Hwan Lee15c56aa2014-08-18 22:01:55 +0900258 public void setMain(boolean isMain) {
259 mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_MAIN, isMain));
Ji-Hwan Lee4c526972014-07-22 04:46:30 +0900260 }
261
262 @Override
Jae Seo39570912014-02-20 18:23:25 -0800263 public void setSurface(Surface surface) {
264 mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_SURFACE, surface));
265 }
266
267 @Override
Youngsang Choe821d712014-07-16 14:22:19 -0700268 public void dispatchSurfaceChanged(int format, int width, int height) {
269 mCaller.executeOrSendMessage(mCaller.obtainMessageIIII(DO_DISPATCH_SURFACE_CHANGED,
270 format, width, height, 0));
271 }
272
273 @Override
Jae Seo39570912014-02-20 18:23:25 -0800274 public final void setVolume(float volume) {
Dongwon Kang4b662d12014-07-17 19:24:56 +0900275 mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_STREAM_VOLUME, volume));
Jae Seo39570912014-02-20 18:23:25 -0800276 }
277
278 @Override
Sungsoo Lim1a6b25e2014-07-09 10:40:43 +0900279 public void tune(Uri channelUri, Bundle params) {
Dongwon Kangc9181722014-11-18 14:29:50 +0900280 // Clear the pending tune requests.
281 mCaller.removeMessages(DO_TUNE);
Sungsoo Lim1a6b25e2014-07-09 10:40:43 +0900282 mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_TUNE, channelUri, params));
Jae Seo39570912014-02-20 18:23:25 -0800283 }
Youngsang Cho9a22f0f2014-04-09 22:51:54 +0900284
285 @Override
Jae Seo2c1c31c2014-07-10 14:57:01 -0700286 public void setCaptionEnabled(boolean enabled) {
287 mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_CAPTION_ENABLED, enabled));
288 }
289
290 @Override
Jae Seo10d285a2014-07-31 22:46:47 +0900291 public void selectTrack(int type, String trackId) {
292 mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_SELECT_TRACK, type, trackId));
Dongwon Kang1f213912014-07-02 18:35:08 +0900293 }
294
295 @Override
Jae Seoa759b112014-07-18 22:16:08 -0700296 public void appPrivateCommand(String action, Bundle data) {
297 mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_APP_PRIVATE_COMMAND, action,
298 data));
299 }
300
301 @Override
Youngsang Cho9a22f0f2014-04-09 22:51:54 +0900302 public void createOverlayView(IBinder windowToken, Rect frame) {
303 mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_CREATE_OVERLAY_VIEW, windowToken,
304 frame));
305 }
306
307 @Override
308 public void relayoutOverlayView(Rect frame) {
309 mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_RELAYOUT_OVERLAY_VIEW, frame));
310 }
311
312 @Override
313 public void removeOverlayView() {
314 mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_REMOVE_OVERLAY_VIEW));
315 }
Jae Seo6a6059a2014-04-17 21:35:29 -0700316
Jaewan Kim903d6b72014-07-16 11:28:56 +0900317 @Override
Jae Seoa9033832015-03-11 19:29:46 -0700318 public void unblockContent(String unblockedRating) {
Sungsoo Lim9bf671f2014-07-19 12:59:51 +0900319 mCaller.executeOrSendMessage(mCaller.obtainMessageO(
Jae Seoa9033832015-03-11 19:29:46 -0700320 DO_UNBLOCK_CONTENT, unblockedRating));
Jaewan Kim903d6b72014-07-16 11:28:56 +0900321 }
322
Dongwon Kang6f0240c2015-03-31 17:56:36 -0700323 @Override
Jae Seoa826d012016-01-18 13:03:35 -0800324 public void timeShiftPlay(Uri recordedProgramUri) {
325 mCaller.executeOrSendMessage(mCaller.obtainMessageO(
326 DO_TIME_SHIFT_PLAY, recordedProgramUri));
327 }
328
329 @Override
Dongwon Kang6f0240c2015-03-31 17:56:36 -0700330 public void timeShiftPause() {
331 mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_TIME_SHIFT_PAUSE));
332 }
333
334 @Override
335 public void timeShiftResume() {
336 mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_TIME_SHIFT_RESUME));
337 }
338
339 @Override
340 public void timeShiftSeekTo(long timeMs) {
Jae Seo093d9942015-06-05 16:13:03 -0700341 mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_TIME_SHIFT_SEEK_TO, timeMs));
Dongwon Kang6f0240c2015-03-31 17:56:36 -0700342 }
343
344 @Override
Jae Seo4b34cc72015-05-15 17:29:39 -0700345 public void timeShiftSetPlaybackParams(PlaybackParams params) {
346 mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_TIME_SHIFT_SET_PLAYBACK_PARAMS,
347 params));
Dongwon Kang6f0240c2015-03-31 17:56:36 -0700348 }
349
350 @Override
Jae Seo465f0d62015-04-06 18:40:46 -0700351 public void timeShiftEnablePositionTracking(boolean enable) {
352 mCaller.executeOrSendMessage(mCaller.obtainMessageO(
Jae Seo093d9942015-06-05 16:13:03 -0700353 DO_TIME_SHIFT_ENABLE_POSITION_TRACKING, enable));
Dongwon Kang6f0240c2015-03-31 17:56:36 -0700354 }
355
Jae Seoa826d012016-01-18 13:03:35 -0800356 @Override
357 public void connect(Uri channelUri, Bundle params) {
358 // Clear the pending connect requests.
359 mCaller.removeMessages(DO_CONNECT);
360 mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_CONNECT, channelUri, params));
361 }
362
363 @Override
364 public void disconnect() {
365 mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_DISCONNECT));
366 }
367
368 @Override
369 public void startRecording() {
370 mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_START_RECORDING));
371 }
372
373 @Override
374 public void stopRecording() {
375 mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_STOP_RECORDING));
376 }
377
Jae Seo6a6059a2014-04-17 21:35:29 -0700378 private final class TvInputEventReceiver extends InputEventReceiver {
379 public TvInputEventReceiver(InputChannel inputChannel, Looper looper) {
380 super(inputChannel, looper);
381 }
382
383 @Override
384 public void onInputEvent(InputEvent event) {
385 if (mTvInputSessionImpl == null) {
386 // The session has been finished.
387 finishInputEvent(event, false);
388 return;
389 }
390
391 int handled = mTvInputSessionImpl.dispatchInputEvent(event, this);
Jae Seo782f7342014-06-03 12:51:21 -0700392 if (handled != TvInputManager.Session.DISPATCH_IN_PROGRESS) {
393 finishInputEvent(event, handled == TvInputManager.Session.DISPATCH_HANDLED);
Jae Seo6a6059a2014-04-17 21:35:29 -0700394 }
395 }
396 }
Jae Seo39570912014-02-20 18:23:25 -0800397}