Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 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 | |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 17 | package android.media.tv; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 20 | import android.graphics.Rect; |
Jae Seo | 3d04b76 | 2015-05-12 20:05:00 -0700 | [diff] [blame] | 21 | import android.media.PlaybackParams; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 22 | import android.net.Uri; |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 23 | import android.os.Bundle; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 24 | import android.os.IBinder; |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 25 | import android.os.Looper; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 26 | import android.os.Message; |
| 27 | import android.util.Log; |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 28 | import android.view.InputChannel; |
| 29 | import android.view.InputEvent; |
| 30 | import android.view.InputEventReceiver; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 31 | import android.view.Surface; |
| 32 | |
| 33 | import com.android.internal.os.HandlerCaller; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 34 | import com.android.internal.os.SomeArgs; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 35 | |
| 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 | */ |
| 42 | public class ITvInputSessionWrapper extends ITvInputSession.Stub implements HandlerCaller.Callback { |
| 43 | private static final String TAG = "TvInputSessionWrapper"; |
| 44 | |
Dongwon Kang | 21add3e | 2015-04-27 17:43:52 +0900 | [diff] [blame] | 45 | 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 Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 48 | |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 49 | private static final int DO_RELEASE = 1; |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 50 | private static final int DO_SET_MAIN = 2; |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 51 | 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 Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 57 | 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 Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 61 | private static final int DO_UNBLOCK_CONTENT = 13; |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 62 | 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 Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 72 | |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 73 | private final boolean mIsRecordingSession; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 74 | private final HandlerCaller mCaller; |
| 75 | |
Jae Seo | 782f734 | 2014-06-03 12:51:21 -0700 | [diff] [blame] | 76 | private TvInputService.Session mTvInputSessionImpl; |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 77 | private TvInputService.RecordingSession mTvInputRecordingSessionImpl; |
| 78 | |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 79 | private InputChannel mChannel; |
| 80 | private TvInputEventReceiver mReceiver; |
| 81 | |
Jae Seo | 782f734 | 2014-06-03 12:51:21 -0700 | [diff] [blame] | 82 | public ITvInputSessionWrapper(Context context, TvInputService.Session sessionImpl, |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 83 | InputChannel channel) { |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 84 | mIsRecordingSession = false; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 85 | mCaller = new HandlerCaller(context, null, this, true /* asyncHandler */); |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 86 | mTvInputSessionImpl = sessionImpl; |
| 87 | mChannel = channel; |
| 88 | if (channel != null) { |
| 89 | mReceiver = new TvInputEventReceiver(channel, context.getMainLooper()); |
| 90 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 93 | 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 Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 100 | @Override |
| 101 | public void executeMessage(Message msg) { |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 102 | if (!mIsRecordingSession && mTvInputSessionImpl == null) { |
| 103 | return; |
| 104 | } |
| 105 | if (mIsRecordingSession && mTvInputRecordingSessionImpl == null) { |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 106 | return; |
| 107 | } |
| 108 | |
Jae Seo | c94c051 | 2015-11-20 17:00:26 -0800 | [diff] [blame] | 109 | long startTime = System.nanoTime(); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 110 | switch (msg.what) { |
| 111 | case DO_RELEASE: { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 112 | 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 Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 122 | break; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 123 | } |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 124 | case DO_SET_MAIN: { |
| 125 | mTvInputSessionImpl.setMain((Boolean) msg.obj); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 126 | break; |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 127 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 128 | case DO_SET_SURFACE: { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 129 | mTvInputSessionImpl.setSurface((Surface) msg.obj); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 130 | break; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 131 | } |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 132 | case DO_DISPATCH_SURFACE_CHANGED: { |
| 133 | SomeArgs args = (SomeArgs) msg.obj; |
| 134 | mTvInputSessionImpl.dispatchSurfaceChanged(args.argi1, args.argi2, args.argi3); |
| 135 | args.recycle(); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 136 | break; |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 137 | } |
Dongwon Kang | 4b662d1 | 2014-07-17 19:24:56 +0900 | [diff] [blame] | 138 | case DO_SET_STREAM_VOLUME: { |
| 139 | mTvInputSessionImpl.setStreamVolume((Float) msg.obj); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 140 | break; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 141 | } |
| 142 | case DO_TUNE: { |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 143 | SomeArgs args = (SomeArgs) msg.obj; |
| 144 | mTvInputSessionImpl.tune((Uri) args.arg1, (Bundle) args.arg2); |
| 145 | args.recycle(); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 146 | break; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 147 | } |
Jae Seo | 2c1c31c | 2014-07-10 14:57:01 -0700 | [diff] [blame] | 148 | case DO_SET_CAPTION_ENABLED: { |
| 149 | mTvInputSessionImpl.setCaptionEnabled((Boolean) msg.obj); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 150 | break; |
Jae Seo | 2c1c31c | 2014-07-10 14:57:01 -0700 | [diff] [blame] | 151 | } |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 152 | case DO_SELECT_TRACK: { |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 153 | SomeArgs args = (SomeArgs) msg.obj; |
| 154 | mTvInputSessionImpl.selectTrack((Integer) args.arg1, (String) args.arg2); |
| 155 | args.recycle(); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 156 | break; |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 157 | } |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 158 | case DO_APP_PRIVATE_COMMAND: { |
| 159 | SomeArgs args = (SomeArgs) msg.obj; |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 160 | 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 Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 166 | args.recycle(); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 167 | break; |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 168 | } |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 169 | case DO_CREATE_OVERLAY_VIEW: { |
| 170 | SomeArgs args = (SomeArgs) msg.obj; |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 171 | mTvInputSessionImpl.createOverlayView((IBinder) args.arg1, (Rect) args.arg2); |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 172 | args.recycle(); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 173 | break; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 174 | } |
| 175 | case DO_RELAYOUT_OVERLAY_VIEW: { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 176 | mTvInputSessionImpl.relayoutOverlayView((Rect) msg.obj); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 177 | break; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 178 | } |
| 179 | case DO_REMOVE_OVERLAY_VIEW: { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 180 | mTvInputSessionImpl.removeOverlayView(true); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 181 | break; |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 182 | } |
Jae Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 183 | case DO_UNBLOCK_CONTENT: { |
Jae Seo | 91a801d | 2014-07-24 13:49:03 -0700 | [diff] [blame] | 184 | mTvInputSessionImpl.unblockContent((String) msg.obj); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 185 | break; |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 186 | } |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 187 | case DO_TIME_SHIFT_PLAY: { |
| 188 | mTvInputSessionImpl.timeShiftPlay((Uri) msg.obj); |
| 189 | break; |
| 190 | } |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 191 | 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 Seo | 4b34cc7 | 2015-05-15 17:29:39 -0700 | [diff] [blame] | 203 | case DO_TIME_SHIFT_SET_PLAYBACK_PARAMS: { |
Dongwon Kang | cf4f3d5 | 2015-05-20 13:57:34 +0900 | [diff] [blame] | 204 | mTvInputSessionImpl.timeShiftSetPlaybackParams((PlaybackParams) msg.obj); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 205 | break; |
| 206 | } |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 207 | case DO_TIME_SHIFT_ENABLE_POSITION_TRACKING: { |
| 208 | mTvInputSessionImpl.timeShiftEnablePositionTracking((Boolean) msg.obj); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 209 | break; |
| 210 | } |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 211 | 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 Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 230 | default: { |
| 231 | Log.w(TAG, "Unhandled message code: " + msg.what); |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 232 | break; |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
Jae Seo | c94c051 | 2015-11-20 17:00:26 -0800 | [diff] [blame] | 235 | long durationMs = (System.nanoTime() - startTime) / (1000 * 1000); |
| 236 | if (durationMs > EXECUTE_MESSAGE_TIMEOUT_SHORT_MILLIS) { |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 237 | Log.w(TAG, "Handling message (" + msg.what + ") took too long time (duration=" |
Jae Seo | c94c051 | 2015-11-20 17:00:26 -0800 | [diff] [blame] | 238 | + 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 Kang | 21add3e | 2015-04-27 17:43:52 +0900 | [diff] [blame] | 241 | + "ms > " + EXECUTE_MESSAGE_TUNE_TIMEOUT_MILLIS + "ms) " |
Dongwon Kang | c918172 | 2014-11-18 14:29:50 +0900 | [diff] [blame] | 242 | + "Consider handling the tune request in a separate thread."); |
| 243 | } |
Jae Seo | c94c051 | 2015-11-20 17:00:26 -0800 | [diff] [blame] | 244 | if (durationMs > EXECUTE_MESSAGE_TIMEOUT_LONG_MILLIS) { |
Dongwon Kang | 21add3e | 2015-04-27 17:43:52 +0900 | [diff] [blame] | 245 | throw new RuntimeException("Too much time to handle a request. (type=" + msg.what + |
Jae Seo | c94c051 | 2015-11-20 17:00:26 -0800 | [diff] [blame] | 246 | ", " + durationMs + "ms > " + EXECUTE_MESSAGE_TIMEOUT_LONG_MILLIS + "ms)."); |
Dongwon Kang | 21add3e | 2015-04-27 17:43:52 +0900 | [diff] [blame] | 247 | } |
Youngsang Cho | 9df2c1b | 2014-09-03 22:27:56 +0900 | [diff] [blame] | 248 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public void release() { |
Dongwon Kang | ce34c6d | 2014-10-27 17:55:27 +0900 | [diff] [blame] | 253 | mTvInputSessionImpl.scheduleOverlayViewCleanup(); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 254 | mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_RELEASE)); |
| 255 | } |
| 256 | |
| 257 | @Override |
Ji-Hwan Lee | 15c56aa | 2014-08-18 22:01:55 +0900 | [diff] [blame] | 258 | public void setMain(boolean isMain) { |
| 259 | mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_MAIN, isMain)); |
Ji-Hwan Lee | 4c52697 | 2014-07-22 04:46:30 +0900 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | @Override |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 263 | public void setSurface(Surface surface) { |
| 264 | mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_SURFACE, surface)); |
| 265 | } |
| 266 | |
| 267 | @Override |
Youngsang Cho | e821d71 | 2014-07-16 14:22:19 -0700 | [diff] [blame] | 268 | 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 Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 274 | public final void setVolume(float volume) { |
Dongwon Kang | 4b662d1 | 2014-07-17 19:24:56 +0900 | [diff] [blame] | 275 | mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_STREAM_VOLUME, volume)); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | @Override |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 279 | public void tune(Uri channelUri, Bundle params) { |
Dongwon Kang | c918172 | 2014-11-18 14:29:50 +0900 | [diff] [blame] | 280 | // Clear the pending tune requests. |
| 281 | mCaller.removeMessages(DO_TUNE); |
Sungsoo Lim | 1a6b25e | 2014-07-09 10:40:43 +0900 | [diff] [blame] | 282 | mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_TUNE, channelUri, params)); |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 283 | } |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 284 | |
| 285 | @Override |
Jae Seo | 2c1c31c | 2014-07-10 14:57:01 -0700 | [diff] [blame] | 286 | public void setCaptionEnabled(boolean enabled) { |
| 287 | mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_CAPTION_ENABLED, enabled)); |
| 288 | } |
| 289 | |
| 290 | @Override |
Jae Seo | 10d285a | 2014-07-31 22:46:47 +0900 | [diff] [blame] | 291 | public void selectTrack(int type, String trackId) { |
| 292 | mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_SELECT_TRACK, type, trackId)); |
Dongwon Kang | 1f21391 | 2014-07-02 18:35:08 +0900 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | @Override |
Jae Seo | a759b11 | 2014-07-18 22:16:08 -0700 | [diff] [blame] | 296 | public void appPrivateCommand(String action, Bundle data) { |
| 297 | mCaller.executeOrSendMessage(mCaller.obtainMessageOO(DO_APP_PRIVATE_COMMAND, action, |
| 298 | data)); |
| 299 | } |
| 300 | |
| 301 | @Override |
Youngsang Cho | 9a22f0f | 2014-04-09 22:51:54 +0900 | [diff] [blame] | 302 | 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 Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 316 | |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 317 | @Override |
Jae Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 318 | public void unblockContent(String unblockedRating) { |
Sungsoo Lim | 9bf671f | 2014-07-19 12:59:51 +0900 | [diff] [blame] | 319 | mCaller.executeOrSendMessage(mCaller.obtainMessageO( |
Jae Seo | a903383 | 2015-03-11 19:29:46 -0700 | [diff] [blame] | 320 | DO_UNBLOCK_CONTENT, unblockedRating)); |
Jaewan Kim | 903d6b7 | 2014-07-16 11:28:56 +0900 | [diff] [blame] | 321 | } |
| 322 | |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 323 | @Override |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 324 | public void timeShiftPlay(Uri recordedProgramUri) { |
| 325 | mCaller.executeOrSendMessage(mCaller.obtainMessageO( |
| 326 | DO_TIME_SHIFT_PLAY, recordedProgramUri)); |
| 327 | } |
| 328 | |
| 329 | @Override |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 330 | 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 Seo | 093d994 | 2015-06-05 16:13:03 -0700 | [diff] [blame] | 341 | mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_TIME_SHIFT_SEEK_TO, timeMs)); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | @Override |
Jae Seo | 4b34cc7 | 2015-05-15 17:29:39 -0700 | [diff] [blame] | 345 | public void timeShiftSetPlaybackParams(PlaybackParams params) { |
| 346 | mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_TIME_SHIFT_SET_PLAYBACK_PARAMS, |
| 347 | params)); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | @Override |
Jae Seo | 465f0d6 | 2015-04-06 18:40:46 -0700 | [diff] [blame] | 351 | public void timeShiftEnablePositionTracking(boolean enable) { |
| 352 | mCaller.executeOrSendMessage(mCaller.obtainMessageO( |
Jae Seo | 093d994 | 2015-06-05 16:13:03 -0700 | [diff] [blame] | 353 | DO_TIME_SHIFT_ENABLE_POSITION_TRACKING, enable)); |
Dongwon Kang | 6f0240c | 2015-03-31 17:56:36 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Jae Seo | a826d01 | 2016-01-18 13:03:35 -0800 | [diff] [blame] | 356 | @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 Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 378 | 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 Seo | 782f734 | 2014-06-03 12:51:21 -0700 | [diff] [blame] | 392 | if (handled != TvInputManager.Session.DISPATCH_IN_PROGRESS) { |
| 393 | finishInputEvent(event, handled == TvInputManager.Session.DISPATCH_HANDLED); |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | } |
Jae Seo | 3957091 | 2014-02-20 18:23:25 -0800 | [diff] [blame] | 397 | } |