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 17 package android.media.tv.cts; 18 19 import android.app.Activity; 20 import android.app.Instrumentation; 21 import android.content.Context; 22 import android.cts.util.PollingCheck; 23 import android.media.PlaybackParams; 24 import android.media.tv.TvContentRating; 25 import android.media.tv.TvContract; 26 import android.media.tv.TvInputInfo; 27 import android.media.tv.TvInputManager; 28 import android.media.tv.TvTrackInfo; 29 import android.media.tv.TvView; 30 import android.media.tv.cts.TvInputServiceTest.CountingTvInputService.CountingSession; 31 import android.net.Uri; 32 import android.os.SystemClock; 33 import android.test.ActivityInstrumentationTestCase2; 34 import android.view.InputDevice; 35 import android.view.KeyEvent; 36 import android.view.MotionEvent; 37 import android.view.Surface; 38 import android.view.SurfaceView; 39 import android.view.View; 40 import android.widget.LinearLayout; 41 42 import com.android.cts.tv.R; 43 44 import java.util.ArrayList; 45 import java.util.List; 46 47 48 /** 49 * Test {@link android.media.tv.TvInputService}. 50 */ 51 public class TvInputServiceTest extends ActivityInstrumentationTestCase2<TvViewStubActivity> { 52 /** The maximum time to wait for an operation. */ 53 private static final long TIME_OUT = 15000L; 54 private static final String mDummyTrackId = "dummyTrackId"; 55 private static final TvTrackInfo mDummyTrack = 56 new TvTrackInfo.Builder(TvTrackInfo.TYPE_VIDEO, mDummyTrackId) 57 .setVideoWidth(1920).setVideoHeight(1080).setLanguage("und").build(); 58 59 private TvView mTvView; 60 private Activity mActivity; 61 private Instrumentation mInstrumentation; 62 private TvInputManager mManager; 63 private TvInputInfo mStubInfo; 64 private final StubCallback mCallback = new StubCallback(); 65 private final StubTimeShiftPositionCallback mTimeShiftPositionCallback = 66 new StubTimeShiftPositionCallback(); 67 68 private static class StubCallback extends TvView.TvInputCallback { 69 private int mChannelRetunedCount; 70 private int mVideoAvailableCount; 71 private int mVideoUnavailableCount; 72 private int mTrackSelectedCount; 73 private int mTrackChangedCount; 74 private int mVideoSizeChanged; 75 private int mContentAllowedCount; 76 private int mContentBlockedCount; 77 private int mTimeShiftStatusChangedCount; 78 79 @Override onChannelRetuned(String inputId, Uri channelUri)80 public void onChannelRetuned(String inputId, Uri channelUri) { 81 mChannelRetunedCount++; 82 } 83 84 @Override onVideoAvailable(String inputId)85 public void onVideoAvailable(String inputId) { 86 mVideoAvailableCount++; 87 } 88 89 @Override onVideoUnavailable(String inputId, int reason)90 public void onVideoUnavailable(String inputId, int reason) { 91 mVideoUnavailableCount++; 92 } 93 94 @Override onTrackSelected(String inputId, int type, String trackId)95 public void onTrackSelected(String inputId, int type, String trackId) { 96 mTrackSelectedCount++; 97 } 98 99 @Override onTracksChanged(String inputId, List<TvTrackInfo> trackList)100 public void onTracksChanged(String inputId, List<TvTrackInfo> trackList) { 101 mTrackChangedCount++; 102 } 103 104 @Override onVideoSizeChanged(String inputId, int width, int height)105 public void onVideoSizeChanged(String inputId, int width, int height) { 106 mVideoSizeChanged++; 107 } 108 109 @Override onContentAllowed(String inputId)110 public void onContentAllowed(String inputId) { 111 mContentAllowedCount++; 112 } 113 114 @Override onContentBlocked(String inputId, TvContentRating rating)115 public void onContentBlocked(String inputId, TvContentRating rating) { 116 mContentBlockedCount++; 117 } 118 119 @Override onTimeShiftStatusChanged(String inputId, int status)120 public void onTimeShiftStatusChanged(String inputId, int status) { 121 mTimeShiftStatusChangedCount++; 122 } 123 resetCounts()124 public void resetCounts() { 125 mChannelRetunedCount = 0; 126 mVideoAvailableCount = 0; 127 mVideoUnavailableCount = 0; 128 mTrackSelectedCount = 0; 129 mTrackChangedCount = 0; 130 mContentAllowedCount = 0; 131 mContentBlockedCount = 0; 132 mTimeShiftStatusChangedCount = 0; 133 } 134 } 135 136 private static class StubTimeShiftPositionCallback extends TvView.TimeShiftPositionCallback { 137 private int mTimeShiftStartPositionChanged; 138 private int mTimeShiftCurrentPositionChanged; 139 140 @Override onTimeShiftStartPositionChanged(String inputId, long timeMs)141 public void onTimeShiftStartPositionChanged(String inputId, long timeMs) { 142 mTimeShiftStartPositionChanged++; 143 } 144 145 @Override onTimeShiftCurrentPositionChanged(String inputId, long timeMs)146 public void onTimeShiftCurrentPositionChanged(String inputId, long timeMs) { 147 mTimeShiftCurrentPositionChanged++; 148 } 149 resetCounts()150 public void resetCounts() { 151 mTimeShiftStartPositionChanged = 0; 152 mTimeShiftCurrentPositionChanged = 0; 153 } 154 } 155 TvInputServiceTest()156 public TvInputServiceTest() { 157 super(TvViewStubActivity.class); 158 } 159 160 @Override setUp()161 protected void setUp() throws Exception { 162 super.setUp(); 163 if (!Utils.hasTvInputFramework(getActivity())) { 164 return; 165 } 166 mActivity = getActivity(); 167 mInstrumentation = getInstrumentation(); 168 mTvView = (TvView) mActivity.findViewById(R.id.tvview); 169 mManager = (TvInputManager) mActivity.getSystemService(Context.TV_INPUT_SERVICE); 170 for (TvInputInfo info : mManager.getTvInputList()) { 171 if (info.getServiceInfo().name.equals(CountingTvInputService.class.getName())) { 172 mStubInfo = info; 173 break; 174 } 175 } 176 assertNotNull(mStubInfo); 177 mTvView.setCallback(mCallback); 178 179 CountingTvInputService.sSession = null; 180 } 181 testTvInputService()182 public void testTvInputService() throws Throwable { 183 if (!Utils.hasTvInputFramework(getActivity())) { 184 return; 185 } 186 verifyCommandTune(); 187 verifyCommandSetStreamVolume(); 188 verifyCommandSetCaptionEnabled(); 189 verifyCommandSelectTrack(); 190 verifyCommandDispatchKeyDown(); 191 verifyCommandDispatchKeyMultiple(); 192 verifyCommandDispatchKeyUp(); 193 verifyCommandDispatchTouchEvent(); 194 verifyCommandDispatchTrackballEvent(); 195 verifyCommandDispatchGenericMotionEvent(); 196 verifyCommandTimeShiftPause(); 197 verifyCommandTimeShiftResume(); 198 verifyCommandTimeShiftSeekTo(); 199 verifyCommandTimeShiftSetPlaybackParams(); 200 verifyCommandSetTimeShiftPositionCallback(); 201 verifyCommandOverlayViewSizeChanged(); 202 verifyCallbackChannelRetuned(); 203 verifyCallbackVideoAvailable(); 204 verifyCallbackVideoUnavailable(); 205 verifyCallbackTracksChanged(); 206 verifyCallbackTrackSelected(); 207 verifyCallbackContentAllowed(); 208 verifyCallbackContentBlocked(); 209 verifyCallbackTimeShiftStatusChanged(); 210 verifyCallbackLayoutSurface(); 211 212 runTestOnUiThread(new Runnable() { 213 @Override 214 public void run() { 215 mTvView.reset(); 216 } 217 }); 218 mInstrumentation.waitForIdleSync(); 219 } 220 verifyCommandTune()221 public void verifyCommandTune() { 222 Uri fakeChannelUri = TvContract.buildChannelUri(0); 223 mTvView.tune(mStubInfo.getId(), fakeChannelUri); 224 mInstrumentation.waitForIdleSync(); 225 new PollingCheck(TIME_OUT) { 226 @Override 227 protected boolean check() { 228 CountingSession session = CountingTvInputService.sSession; 229 return session != null && session.mTuneCount > 0 && session.mCreateOverlayView > 0; 230 } 231 }.run(); 232 } 233 verifyCommandSetStreamVolume()234 public void verifyCommandSetStreamVolume() { 235 resetCounts(); 236 mTvView.setStreamVolume(1.0f); 237 mInstrumentation.waitForIdleSync(); 238 new PollingCheck(TIME_OUT) { 239 @Override 240 protected boolean check() { 241 CountingSession session = CountingTvInputService.sSession; 242 return session != null && session.mSetStreamVolumeCount > 0; 243 } 244 }.run(); 245 } 246 verifyCommandSetCaptionEnabled()247 public void verifyCommandSetCaptionEnabled() { 248 resetCounts(); 249 mTvView.setCaptionEnabled(true); 250 mInstrumentation.waitForIdleSync(); 251 new PollingCheck(TIME_OUT) { 252 @Override 253 protected boolean check() { 254 CountingSession session = CountingTvInputService.sSession; 255 return session != null && session.mSetCaptionEnabledCount > 0; 256 } 257 }.run(); 258 } 259 verifyCommandSelectTrack()260 public void verifyCommandSelectTrack() { 261 resetCounts(); 262 verifyCallbackTracksChanged(); 263 mTvView.selectTrack(mDummyTrack.getType(), mDummyTrack.getId()); 264 mInstrumentation.waitForIdleSync(); 265 new PollingCheck(TIME_OUT) { 266 @Override 267 protected boolean check() { 268 CountingSession session = CountingTvInputService.sSession; 269 return session != null && session.mSelectTrackCount > 0; 270 } 271 }.run(); 272 } 273 verifyCommandDispatchKeyDown()274 public void verifyCommandDispatchKeyDown() { 275 resetCounts(); 276 mTvView.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_K)); 277 mInstrumentation.waitForIdleSync(); 278 new PollingCheck(TIME_OUT) { 279 @Override 280 protected boolean check() { 281 CountingSession session = CountingTvInputService.sSession; 282 return session != null && session.mKeyDownCount > 0; 283 } 284 }.run(); 285 } 286 verifyCommandDispatchKeyMultiple()287 public void verifyCommandDispatchKeyMultiple() { 288 resetCounts(); 289 mTvView.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_MULTIPLE, KeyEvent.KEYCODE_K)); 290 mInstrumentation.waitForIdleSync(); 291 new PollingCheck(TIME_OUT) { 292 @Override 293 protected boolean check() { 294 CountingSession session = CountingTvInputService.sSession; 295 return session != null && session.mKeyMultipleCount > 0; 296 } 297 }.run(); 298 } 299 verifyCommandDispatchKeyUp()300 public void verifyCommandDispatchKeyUp() { 301 resetCounts(); 302 mTvView.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_K)); 303 mInstrumentation.waitForIdleSync(); 304 new PollingCheck(TIME_OUT) { 305 @Override 306 protected boolean check() { 307 CountingSession session = CountingTvInputService.sSession; 308 return session != null && session.mKeyUpCount > 0; 309 } 310 }.run(); 311 } 312 verifyCommandDispatchTouchEvent()313 public void verifyCommandDispatchTouchEvent() { 314 resetCounts(); 315 long now = SystemClock.uptimeMillis(); 316 MotionEvent event = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, 1.0f, 1.0f, 317 1.0f, 1.0f, 0, 1.0f, 1.0f, 0, 0); 318 event.setSource(InputDevice.SOURCE_TOUCHSCREEN); 319 mTvView.dispatchTouchEvent(event); 320 mInstrumentation.waitForIdleSync(); 321 new PollingCheck(TIME_OUT) { 322 @Override 323 protected boolean check() { 324 CountingSession session = CountingTvInputService.sSession; 325 return session != null && session.mTouchEventCount > 0; 326 } 327 }.run(); 328 } 329 verifyCommandDispatchTrackballEvent()330 public void verifyCommandDispatchTrackballEvent() { 331 resetCounts(); 332 long now = SystemClock.uptimeMillis(); 333 MotionEvent event = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, 1.0f, 1.0f, 334 1.0f, 1.0f, 0, 1.0f, 1.0f, 0, 0); 335 event.setSource(InputDevice.SOURCE_TRACKBALL); 336 mTvView.dispatchTouchEvent(event); 337 mInstrumentation.waitForIdleSync(); 338 new PollingCheck(TIME_OUT) { 339 @Override 340 protected boolean check() { 341 CountingSession session = CountingTvInputService.sSession; 342 return session != null && session.mTrackballEventCount > 0; 343 } 344 }.run(); 345 } 346 verifyCommandDispatchGenericMotionEvent()347 public void verifyCommandDispatchGenericMotionEvent() { 348 resetCounts(); 349 long now = SystemClock.uptimeMillis(); 350 MotionEvent event = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, 1.0f, 1.0f, 351 1.0f, 1.0f, 0, 1.0f, 1.0f, 0, 0); 352 mTvView.dispatchGenericMotionEvent(event); 353 mInstrumentation.waitForIdleSync(); 354 new PollingCheck(TIME_OUT) { 355 @Override 356 protected boolean check() { 357 CountingSession session = CountingTvInputService.sSession; 358 return session != null && session.mGenricMotionEventCount > 0; 359 } 360 }.run(); 361 } 362 verifyCommandTimeShiftPause()363 public void verifyCommandTimeShiftPause() { 364 resetCounts(); 365 mTvView.timeShiftPause(); 366 mInstrumentation.waitForIdleSync(); 367 new PollingCheck(TIME_OUT) { 368 @Override 369 protected boolean check() { 370 CountingSession session = CountingTvInputService.sSession; 371 return session != null && session.mTimeShiftPauseCount > 0; 372 } 373 }.run(); 374 } 375 verifyCommandTimeShiftResume()376 public void verifyCommandTimeShiftResume() { 377 resetCounts(); 378 mTvView.timeShiftResume(); 379 mInstrumentation.waitForIdleSync(); 380 new PollingCheck(TIME_OUT) { 381 @Override 382 protected boolean check() { 383 CountingSession session = CountingTvInputService.sSession; 384 return session != null && session.mTimeShiftResumeCount > 0; 385 } 386 }.run(); 387 } 388 verifyCommandTimeShiftSeekTo()389 public void verifyCommandTimeShiftSeekTo() { 390 resetCounts(); 391 mTvView.timeShiftSeekTo(0); 392 mInstrumentation.waitForIdleSync(); 393 new PollingCheck(TIME_OUT) { 394 @Override 395 protected boolean check() { 396 CountingSession session = CountingTvInputService.sSession; 397 return session != null && session.mTimeShiftSeekToCount > 0; 398 } 399 }.run(); 400 } 401 verifyCommandTimeShiftSetPlaybackParams()402 public void verifyCommandTimeShiftSetPlaybackParams() { 403 resetCounts(); 404 mTvView.timeShiftSetPlaybackParams(new PlaybackParams().setSpeed(2.0f) 405 .setAudioFallbackMode(PlaybackParams.AUDIO_FALLBACK_MODE_DEFAULT)); 406 mInstrumentation.waitForIdleSync(); 407 new PollingCheck(TIME_OUT) { 408 @Override 409 protected boolean check() { 410 CountingSession session = CountingTvInputService.sSession; 411 return session != null && session.mTimeShiftSetPlaybackParamsCount > 0; 412 } 413 }.run(); 414 } 415 verifyCommandSetTimeShiftPositionCallback()416 public void verifyCommandSetTimeShiftPositionCallback() { 417 resetCounts(); 418 mTvView.setTimeShiftPositionCallback(mTimeShiftPositionCallback); 419 mInstrumentation.waitForIdleSync(); 420 new PollingCheck(TIME_OUT) { 421 @Override 422 protected boolean check() { 423 return mTimeShiftPositionCallback.mTimeShiftCurrentPositionChanged > 0 424 && mTimeShiftPositionCallback.mTimeShiftStartPositionChanged > 0; 425 } 426 }.run(); 427 } 428 verifyCommandOverlayViewSizeChanged()429 public void verifyCommandOverlayViewSizeChanged() { 430 resetCounts(); 431 mActivity.runOnUiThread(new Runnable() { 432 public void run() { 433 mTvView.setLayoutParams(new LinearLayout.LayoutParams(10, 20)); 434 } 435 }); 436 mInstrumentation.waitForIdleSync(); 437 new PollingCheck(TIME_OUT) { 438 @Override 439 protected boolean check() { 440 CountingSession session = CountingTvInputService.sSession; 441 return session != null && session.mOverlayViewSizeChangedCount > 0; 442 } 443 }.run(); 444 } 445 verifyCallbackChannelRetuned()446 public void verifyCallbackChannelRetuned() { 447 resetCounts(); 448 CountingSession session = CountingTvInputService.sSession; 449 assertNotNull(session); 450 Uri fakeChannelUri = TvContract.buildChannelUri(0); 451 session.notifyChannelRetuned(fakeChannelUri); 452 new PollingCheck(TIME_OUT) { 453 @Override 454 protected boolean check() { 455 return mCallback.mChannelRetunedCount > 0; 456 } 457 }.run(); 458 } 459 verifyCallbackVideoAvailable()460 public void verifyCallbackVideoAvailable() { 461 resetCounts(); 462 CountingSession session = CountingTvInputService.sSession; 463 assertNotNull(session); 464 session.notifyVideoAvailable(); 465 new PollingCheck(TIME_OUT) { 466 @Override 467 protected boolean check() { 468 return mCallback.mVideoAvailableCount > 0; 469 } 470 }.run(); 471 } 472 verifyCallbackVideoUnavailable()473 public void verifyCallbackVideoUnavailable() { 474 resetCounts(); 475 CountingSession session = CountingTvInputService.sSession; 476 assertNotNull(session); 477 session.notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING); 478 new PollingCheck(TIME_OUT) { 479 @Override 480 protected boolean check() { 481 return mCallback.mVideoUnavailableCount > 0; 482 } 483 }.run(); 484 } 485 verifyCallbackTracksChanged()486 public void verifyCallbackTracksChanged() { 487 resetCounts(); 488 CountingSession session = CountingTvInputService.sSession; 489 assertNotNull(session); 490 ArrayList<TvTrackInfo> tracks = new ArrayList<>(); 491 tracks.add(mDummyTrack); 492 session.notifyTracksChanged(tracks); 493 new PollingCheck(TIME_OUT) { 494 @Override 495 protected boolean check() { 496 return mCallback.mTrackChangedCount > 0; 497 } 498 }.run(); 499 } 500 verifyCallbackVideoSizeChanged()501 public void verifyCallbackVideoSizeChanged() { 502 resetCounts(); 503 CountingSession session = CountingTvInputService.sSession; 504 assertNotNull(session); 505 ArrayList<TvTrackInfo> tracks = new ArrayList<>(); 506 tracks.add(mDummyTrack); 507 session.notifyTracksChanged(tracks); 508 new PollingCheck(TIME_OUT) { 509 @Override 510 protected boolean check() { 511 return mCallback.mVideoSizeChanged > 0; 512 } 513 }.run(); 514 } 515 verifyCallbackTrackSelected()516 public void verifyCallbackTrackSelected() { 517 resetCounts(); 518 CountingSession session = CountingTvInputService.sSession; 519 assertNotNull(session); 520 session.notifyTrackSelected(mDummyTrack.getType(), mDummyTrack.getId()); 521 new PollingCheck(TIME_OUT) { 522 @Override 523 protected boolean check() { 524 return mCallback.mTrackSelectedCount > 0; 525 } 526 }.run(); 527 } 528 verifyCallbackContentAllowed()529 public void verifyCallbackContentAllowed() { 530 resetCounts(); 531 CountingSession session = CountingTvInputService.sSession; 532 assertNotNull(session); 533 session.notifyContentAllowed(); 534 new PollingCheck(TIME_OUT) { 535 @Override 536 protected boolean check() { 537 return mCallback.mContentAllowedCount > 0; 538 } 539 }.run(); 540 } 541 verifyCallbackContentBlocked()542 public void verifyCallbackContentBlocked() { 543 resetCounts(); 544 CountingSession session = CountingTvInputService.sSession; 545 assertNotNull(session); 546 TvContentRating rating = TvContentRating.createRating("android.media.tv", "US_TVPG", 547 "US_TVPG_TV_MA", "US_TVPG_S", "US_TVPG_V"); 548 session.notifyContentBlocked(rating); 549 new PollingCheck(TIME_OUT) { 550 @Override 551 protected boolean check() { 552 return mCallback.mContentBlockedCount > 0; 553 } 554 }.run(); 555 } 556 verifyCallbackTimeShiftStatusChanged()557 public void verifyCallbackTimeShiftStatusChanged() { 558 resetCounts(); 559 CountingSession session = CountingTvInputService.sSession; 560 assertNotNull(session); 561 session.notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE); 562 new PollingCheck(TIME_OUT) { 563 @Override 564 protected boolean check() { 565 return mCallback.mTimeShiftStatusChangedCount > 0; 566 } 567 }.run(); 568 } 569 verifyCallbackLayoutSurface()570 public void verifyCallbackLayoutSurface() { 571 resetCounts(); 572 final int left = 10; 573 final int top = 20; 574 final int right = 30; 575 final int bottom = 40; 576 CountingSession session = CountingTvInputService.sSession; 577 assertNotNull(session); 578 session.layoutSurface(left, top, right, bottom); 579 new PollingCheck(TIME_OUT) { 580 @Override 581 protected boolean check() { 582 int childCount = mTvView.getChildCount(); 583 for (int i = 0; i < childCount; ++i) { 584 View v = mTvView.getChildAt(i); 585 if (v instanceof SurfaceView) { 586 return v.getLeft() == left && v.getTop() == top && v.getRight() == right 587 && v.getBottom() == bottom; 588 } 589 } 590 return false; 591 } 592 }.run(); 593 } 594 resetCounts()595 private void resetCounts() { 596 if (CountingTvInputService.sSession != null) { 597 CountingTvInputService.sSession.resetCounts(); 598 } 599 mCallback.resetCounts(); 600 mTimeShiftPositionCallback.resetCounts(); 601 } 602 603 public static class CountingTvInputService extends StubTvInputService { 604 static CountingSession sSession; 605 606 @Override onCreateSession(String inputId)607 public Session onCreateSession(String inputId) { 608 sSession = new CountingSession(this); 609 sSession.setOverlayViewEnabled(true); 610 return sSession; 611 } 612 613 public static class CountingSession extends Session { 614 public volatile int mTuneCount; 615 public volatile int mSetStreamVolumeCount; 616 public volatile int mSetCaptionEnabledCount; 617 public volatile int mSelectTrackCount; 618 public volatile int mCreateOverlayView; 619 public volatile int mKeyDownCount; 620 public volatile int mKeyLongPressCount; 621 public volatile int mKeyMultipleCount; 622 public volatile int mKeyUpCount; 623 public volatile int mTouchEventCount; 624 public volatile int mTrackballEventCount; 625 public volatile int mGenricMotionEventCount; 626 public volatile int mOverlayViewSizeChangedCount; 627 public volatile int mTimeShiftPauseCount; 628 public volatile int mTimeShiftResumeCount; 629 public volatile int mTimeShiftSeekToCount; 630 public volatile int mTimeShiftSetPlaybackParamsCount; 631 public volatile long mTimeShiftGetCurrentPositionCount; 632 public volatile long mTimeShiftGetStartPositionCount; 633 CountingSession(Context context)634 CountingSession(Context context) { 635 super(context); 636 } 637 resetCounts()638 public void resetCounts() { 639 mTuneCount = 0; 640 mSetStreamVolumeCount = 0; 641 mSetCaptionEnabledCount = 0; 642 mSelectTrackCount = 0; 643 mCreateOverlayView = 0; 644 mKeyDownCount = 0; 645 mKeyLongPressCount = 0; 646 mKeyMultipleCount = 0; 647 mKeyUpCount = 0; 648 mTouchEventCount = 0; 649 mTrackballEventCount = 0; 650 mGenricMotionEventCount = 0; 651 mOverlayViewSizeChangedCount = 0; 652 mTimeShiftPauseCount = 0; 653 mTimeShiftResumeCount = 0; 654 mTimeShiftSeekToCount = 0; 655 mTimeShiftSetPlaybackParamsCount = 0; 656 mTimeShiftGetCurrentPositionCount = 0; 657 mTimeShiftGetStartPositionCount = 0; 658 } 659 660 @Override onRelease()661 public void onRelease() { 662 } 663 664 @Override onSetSurface(Surface surface)665 public boolean onSetSurface(Surface surface) { 666 return false; 667 } 668 669 @Override onTune(Uri channelUri)670 public boolean onTune(Uri channelUri) { 671 mTuneCount++; 672 return false; 673 } 674 675 @Override onSetStreamVolume(float volume)676 public void onSetStreamVolume(float volume) { 677 mSetStreamVolumeCount++; 678 } 679 680 @Override onSetCaptionEnabled(boolean enabled)681 public void onSetCaptionEnabled(boolean enabled) { 682 mSetCaptionEnabledCount++; 683 } 684 685 @Override onSelectTrack(int type, String id)686 public boolean onSelectTrack(int type, String id) { 687 mSelectTrackCount++; 688 return false; 689 } 690 691 @Override onCreateOverlayView()692 public View onCreateOverlayView() { 693 mCreateOverlayView++; 694 return null; 695 } 696 697 @Override onKeyDown(int keyCode, KeyEvent event)698 public boolean onKeyDown(int keyCode, KeyEvent event) { 699 mKeyDownCount++; 700 return false; 701 } 702 703 @Override onKeyLongPress(int keyCode, KeyEvent event)704 public boolean onKeyLongPress(int keyCode, KeyEvent event) { 705 mKeyLongPressCount++; 706 return false; 707 } 708 709 @Override onKeyMultiple(int keyCode, int count, KeyEvent event)710 public boolean onKeyMultiple(int keyCode, int count, KeyEvent event) { 711 mKeyMultipleCount++; 712 return false; 713 } 714 715 @Override onKeyUp(int keyCode, KeyEvent event)716 public boolean onKeyUp(int keyCode, KeyEvent event) { 717 mKeyUpCount++; 718 return false; 719 } 720 721 @Override onTouchEvent(MotionEvent event)722 public boolean onTouchEvent(MotionEvent event) { 723 mTouchEventCount++; 724 return false; 725 } 726 727 @Override onTrackballEvent(MotionEvent event)728 public boolean onTrackballEvent(MotionEvent event) { 729 mTrackballEventCount++; 730 return false; 731 } 732 733 @Override onGenericMotionEvent(MotionEvent event)734 public boolean onGenericMotionEvent(MotionEvent event) { 735 mGenricMotionEventCount++; 736 return false; 737 } 738 739 @Override onTimeShiftPause()740 public void onTimeShiftPause() { 741 mTimeShiftPauseCount++; 742 } 743 744 @Override onTimeShiftResume()745 public void onTimeShiftResume() { 746 mTimeShiftResumeCount++; 747 } 748 749 @Override onTimeShiftSeekTo(long timeMs)750 public void onTimeShiftSeekTo(long timeMs) { 751 mTimeShiftSeekToCount++; 752 } 753 754 @Override onTimeShiftSetPlaybackParams(PlaybackParams param)755 public void onTimeShiftSetPlaybackParams(PlaybackParams param) { 756 mTimeShiftSetPlaybackParamsCount++; 757 } 758 759 @Override onTimeShiftGetCurrentPosition()760 public long onTimeShiftGetCurrentPosition() { 761 return ++mTimeShiftGetCurrentPositionCount; 762 } 763 764 @Override onTimeShiftGetStartPosition()765 public long onTimeShiftGetStartPosition() { 766 return ++mTimeShiftGetStartPositionCount; 767 } 768 769 @Override onOverlayViewSizeChanged(int width, int height)770 public void onOverlayViewSizeChanged(int width, int height) { 771 mOverlayViewSizeChangedCount++; 772 } 773 } 774 } 775 } 776