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 com.android.cts.verifier.tv; 18 19 import com.android.cts.verifier.R; 20 import android.annotation.SuppressLint; 21 import android.content.Intent; 22 import android.database.Cursor; 23 import android.media.tv.TvContentRating; 24 import android.media.tv.TvContract; 25 import android.media.tv.TvInputManager; 26 import android.media.tv.TvTrackInfo; 27 import android.os.Bundle; 28 import android.view.LayoutInflater; 29 import android.view.View; 30 import android.view.ViewGroup; 31 import android.widget.Button; 32 import android.widget.ImageView; 33 import android.widget.TextView; 34 import android.widget.Toast; 35 36 /** 37 * Tests for verifying TV app behavior on multiple tracks and subtitle. 38 */ 39 @SuppressLint("NewApi") 40 public class MultipleTracksTestActivity extends TvAppVerifierActivity 41 implements View.OnClickListener { 42 private static final String TAG = "MultipleTracksTestActivity"; 43 44 private static final long TIMEOUT_MS = 5l * 60l * 1000l; // 5 mins. 45 46 private View mSelectSubtitleItem; 47 private View mVerifySetCaptionEnabledItem; 48 private View mVerifySelectSubtitleItem; 49 private View mSelectAudioItem; 50 private View mVerifySelectAudioItem; 51 52 private Intent mTvAppIntent = null; 53 54 @Override onClick(View v)55 public void onClick(View v) { 56 final View postTarget = getPostTarget(); 57 58 if (containsButton(mSelectSubtitleItem, v)) { 59 final Runnable failCallback = new Runnable() { 60 @Override 61 public void run() { 62 setPassState(mVerifySetCaptionEnabledItem, false); 63 setPassState(mVerifySelectSubtitleItem, false); 64 } 65 }; 66 postTarget.postDelayed(failCallback, TIMEOUT_MS); 67 MockTvInputService.expectSetCaptionEnabled(true, postTarget, new Runnable() { 68 @Override 69 public void run() { 70 postTarget.removeCallbacks(failCallback); 71 setPassState(mSelectSubtitleItem, true); 72 setPassState(mVerifySetCaptionEnabledItem, true); 73 Integer tag = (Integer) mSelectAudioItem.getTag(); 74 if (tag == 0) { 75 mSelectAudioItem.setTag(Integer.valueOf(1)); 76 } else if (tag == 1) { 77 setButtonEnabled(mSelectAudioItem, true); 78 } 79 } 80 }); 81 MockTvInputService.expectSelectTrack(TvTrackInfo.TYPE_SUBTITLE, 82 MockTvInputService.sEngSubtitleTrack.getId(), postTarget, new Runnable() { 83 @Override 84 public void run() { 85 postTarget.removeCallbacks(failCallback); 86 setPassState(mSelectSubtitleItem, true); 87 setPassState(mVerifySelectSubtitleItem, true); 88 Integer tag = (Integer) mSelectAudioItem.getTag(); 89 if (tag == 0) { 90 mSelectAudioItem.setTag(Integer.valueOf(1)); 91 } else if (tag == 1) { 92 setButtonEnabled(mSelectAudioItem, true); 93 } 94 } 95 }); 96 } else if (containsButton(mSelectAudioItem, v)) { 97 final Runnable failCallback = new Runnable() { 98 @Override 99 public void run() { 100 setPassState(mVerifySelectAudioItem, false); 101 } 102 }; 103 postTarget.postDelayed(failCallback, TIMEOUT_MS); 104 MockTvInputService.expectSelectTrack(TvTrackInfo.TYPE_AUDIO, 105 MockTvInputService.sSpaAudioTrack.getId(), postTarget, new Runnable() { 106 @Override 107 public void run() { 108 postTarget.removeCallbacks(failCallback); 109 setPassState(mSelectAudioItem, true); 110 setPassState(mVerifySelectAudioItem, true); 111 getPassButton().setEnabled(true); 112 } 113 }); 114 } 115 if (mTvAppIntent == null) { 116 String[] projection = { TvContract.Channels._ID }; 117 try (Cursor cursor = getContentResolver().query( 118 TvContract.buildChannelsUriForInput(MockTvInputService.getInputId(this)), 119 projection, null, null, null)) { 120 if (cursor != null && cursor.moveToNext()) { 121 mTvAppIntent = new Intent(Intent.ACTION_VIEW, 122 TvContract.buildChannelUri(cursor.getLong(0))); 123 } 124 } 125 if (mTvAppIntent == null) { 126 Toast.makeText(this, R.string.tv_channel_not_found, Toast.LENGTH_SHORT).show(); 127 return; 128 } 129 } 130 startActivity(mTvAppIntent); 131 } 132 133 @Override createTestItems()134 protected void createTestItems() { 135 mSelectSubtitleItem = createUserItem( 136 R.string.tv_multiple_tracks_test_select_subtitle, 137 R.string.tv_launch_tv_app, this); 138 setButtonEnabled(mSelectSubtitleItem, true); 139 mVerifySetCaptionEnabledItem = createAutoItem( 140 R.string.tv_multiple_tracks_test_verify_set_caption_enabled); 141 mVerifySelectSubtitleItem = createAutoItem( 142 R.string.tv_multiple_tracks_test_verify_select_subtitle); 143 mSelectAudioItem = createUserItem( 144 R.string.tv_multiple_tracks_test_select_audio, 145 R.string.tv_launch_tv_app, this); 146 mSelectAudioItem.setTag(Integer.valueOf(0)); 147 mVerifySelectAudioItem = createAutoItem( 148 R.string.tv_multiple_tracks_test_verify_select_audio); 149 } 150 151 @Override setInfoResources()152 protected void setInfoResources() { 153 setInfoResources(R.string.tv_multiple_tracks_test, 154 R.string.tv_multiple_tracks_test_info, -1); 155 } 156 } 157