Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [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 | |
| 17 | package com.android.cts.verifier.tv; |
| 18 | |
Dongwon Kang | aa1e803 | 2015-06-01 15:13:06 +0900 | [diff] [blame] | 19 | import android.app.SearchableInfo; |
| 20 | import android.content.Context; |
Wonsik Kim | d71946a | 2014-11-20 23:11:16 +0900 | [diff] [blame] | 21 | import android.content.Intent; |
| 22 | import android.media.tv.TvContract; |
Dongwon Kang | aa1e803 | 2015-06-01 15:13:06 +0900 | [diff] [blame] | 23 | import android.os.AsyncTask; |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 24 | import android.view.View; |
| 25 | |
Wonsik Kim | d71946a | 2014-11-20 23:11:16 +0900 | [diff] [blame] | 26 | import com.android.cts.verifier.R; |
| 27 | |
Dongwon Kang | aa1e803 | 2015-06-01 15:13:06 +0900 | [diff] [blame] | 28 | import java.util.List; |
| 29 | |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 30 | /** |
Wonsik Kim | d71946a | 2014-11-20 23:11:16 +0900 | [diff] [blame] | 31 | * Tests for verifying TV app behavior for third-party TV input apps. |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 32 | */ |
| 33 | public class TvInputDiscoveryTestActivity extends TvAppVerifierActivity |
| 34 | implements View.OnClickListener { |
| 35 | private static final String TAG = "TvInputDiscoveryTestActivity"; |
| 36 | |
Wonsik Kim | d71946a | 2014-11-20 23:11:16 +0900 | [diff] [blame] | 37 | private static final Intent TV_APP_INTENT = new Intent(Intent.ACTION_VIEW, |
Dongwon Kang | 9845395 | 2015-05-13 19:00:07 +0900 | [diff] [blame] | 38 | TvContract.Channels.CONTENT_URI); |
Dongwon Kang | 2ad14c9 | 2015-05-13 18:46:13 +0900 | [diff] [blame] | 39 | private static final Intent EPG_INTENT = new Intent(Intent.ACTION_VIEW, |
| 40 | TvContract.Programs.CONTENT_URI); |
Wonsik Kim | d71946a | 2014-11-20 23:11:16 +0900 | [diff] [blame] | 41 | |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 42 | private static final long TIMEOUT_MS = 5l * 60l * 1000l; // 5 mins. |
| 43 | |
| 44 | private View mGoToSetupItem; |
| 45 | private View mVerifySetupItem; |
| 46 | private View mTuneToChannelItem; |
| 47 | private View mVerifyTuneItem; |
Dongwon Kang | 9bbf0ca | 2014-12-01 15:51:03 +0900 | [diff] [blame] | 48 | private View mVerifyOverlayViewItem; |
Dongwon Kang | aa1e803 | 2015-06-01 15:13:06 +0900 | [diff] [blame] | 49 | private View mVerifyGlobalSearchItem; |
Dongwon Kang | 2ad14c9 | 2015-05-13 18:46:13 +0900 | [diff] [blame] | 50 | private View mGoToEpgItem; |
| 51 | private View mVerifyEpgItem; |
Dongwon Kang | 9bbf0ca | 2014-12-01 15:51:03 +0900 | [diff] [blame] | 52 | private boolean mTuneVerified; |
| 53 | private boolean mOverlayViewVerified; |
Dongwon Kang | aa1e803 | 2015-06-01 15:13:06 +0900 | [diff] [blame] | 54 | private boolean mGlobalSearchVerified; |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 55 | |
| 56 | @Override |
| 57 | public void onClick(View v) { |
| 58 | final View postTarget = getPostTarget(); |
| 59 | |
| 60 | if (containsButton(mGoToSetupItem, v)) { |
| 61 | final Runnable failCallback = new Runnable() { |
| 62 | @Override |
| 63 | public void run() { |
| 64 | setPassState(mVerifySetupItem, false); |
| 65 | } |
| 66 | }; |
| 67 | postTarget.postDelayed(failCallback, TIMEOUT_MS); |
| 68 | MockTvInputSetupActivity.expectLaunch(postTarget, new Runnable() { |
| 69 | @Override |
| 70 | public void run() { |
| 71 | postTarget.removeCallbacks(failCallback); |
| 72 | setPassState(mGoToSetupItem, true); |
| 73 | setPassState(mVerifySetupItem, true); |
| 74 | setButtonEnabled(mTuneToChannelItem, true); |
| 75 | } |
| 76 | }); |
Dongwon Kang | 2ad14c9 | 2015-05-13 18:46:13 +0900 | [diff] [blame] | 77 | startActivity(TV_APP_INTENT); |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 78 | } else if (containsButton(mTuneToChannelItem, v)) { |
| 79 | final Runnable failCallback = new Runnable() { |
| 80 | @Override |
| 81 | public void run() { |
| 82 | setPassState(mVerifyTuneItem, false); |
| 83 | } |
| 84 | }; |
| 85 | postTarget.postDelayed(failCallback, TIMEOUT_MS); |
| 86 | MockTvInputService.expectTune(postTarget, new Runnable() { |
| 87 | @Override |
| 88 | public void run() { |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 89 | setPassState(mTuneToChannelItem, true); |
| 90 | setPassState(mVerifyTuneItem, true); |
Dongwon Kang | 9bbf0ca | 2014-12-01 15:51:03 +0900 | [diff] [blame] | 91 | |
| 92 | mTuneVerified = true; |
Dongwon Kang | 2ad14c9 | 2015-05-13 18:46:13 +0900 | [diff] [blame] | 93 | goToNextState(postTarget, failCallback); |
Dongwon Kang | 9bbf0ca | 2014-12-01 15:51:03 +0900 | [diff] [blame] | 94 | } |
| 95 | }); |
| 96 | MockTvInputService.expectOverlayView(postTarget, new Runnable() { |
| 97 | @Override |
| 98 | public void run() { |
| 99 | postTarget.removeCallbacks(failCallback); |
| 100 | setPassState(mVerifyOverlayViewItem, true); |
| 101 | |
| 102 | mOverlayViewVerified = true; |
Dongwon Kang | 2ad14c9 | 2015-05-13 18:46:13 +0900 | [diff] [blame] | 103 | goToNextState(postTarget, failCallback); |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 104 | } |
| 105 | }); |
Dongwon Kang | aa1e803 | 2015-06-01 15:13:06 +0900 | [diff] [blame] | 106 | verifyGlobalSearch(postTarget, failCallback); |
Dongwon Kang | 2ad14c9 | 2015-05-13 18:46:13 +0900 | [diff] [blame] | 107 | startActivity(TV_APP_INTENT); |
| 108 | } else if (containsButton(mGoToEpgItem, v)) { |
| 109 | startActivity(EPG_INTENT); |
| 110 | setPassState(mGoToEpgItem, true); |
| 111 | setButtonEnabled(mVerifyEpgItem, true); |
| 112 | } else if (containsButton(mVerifyEpgItem, v)) { |
| 113 | setPassState(mVerifyEpgItem, true); |
| 114 | getPassButton().setEnabled(true); |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 115 | } |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Override |
| 119 | protected void createTestItems() { |
| 120 | mGoToSetupItem = createUserItem(R.string.tv_input_discover_test_go_to_setup, |
| 121 | R.string.tv_launch_tv_app, this); |
| 122 | setButtonEnabled(mGoToSetupItem, true); |
| 123 | mVerifySetupItem = createAutoItem(R.string.tv_input_discover_test_verify_setup); |
| 124 | mTuneToChannelItem = createUserItem(R.string.tv_input_discover_test_tune_to_channel, |
| 125 | R.string.tv_launch_tv_app, this); |
| 126 | mVerifyTuneItem = createAutoItem(R.string.tv_input_discover_test_verify_tune); |
Dongwon Kang | 9bbf0ca | 2014-12-01 15:51:03 +0900 | [diff] [blame] | 127 | mVerifyOverlayViewItem = createAutoItem( |
| 128 | R.string.tv_input_discover_test_verify_overlay_view); |
Dongwon Kang | aa1e803 | 2015-06-01 15:13:06 +0900 | [diff] [blame] | 129 | mVerifyGlobalSearchItem = createAutoItem( |
| 130 | R.string.tv_input_discover_test_verify_global_search); |
Dongwon Kang | 2ad14c9 | 2015-05-13 18:46:13 +0900 | [diff] [blame] | 131 | mGoToEpgItem = createUserItem(R.string.tv_input_discover_test_go_to_epg, |
| 132 | R.string.tv_launch_epg, this); |
| 133 | mVerifyEpgItem = createUserItem(R.string.tv_input_discover_test_verify_epg, |
| 134 | R.string.tv_input_discover_test_yes, this); |
Dongwon Kang | 9bbf0ca | 2014-12-01 15:51:03 +0900 | [diff] [blame] | 135 | } |
| 136 | |
Dongwon Kang | aa1e803 | 2015-06-01 15:13:06 +0900 | [diff] [blame] | 137 | @Override |
| 138 | protected void setInfoResources() { |
| 139 | setInfoResources(R.string.tv_input_discover_test, |
| 140 | R.string.tv_input_discover_test_info, -1); |
| 141 | } |
| 142 | |
Dongwon Kang | 2ad14c9 | 2015-05-13 18:46:13 +0900 | [diff] [blame] | 143 | private void goToNextState(View postTarget, Runnable failCallback) { |
Dongwon Kang | aa1e803 | 2015-06-01 15:13:06 +0900 | [diff] [blame] | 144 | if (mTuneVerified && mOverlayViewVerified && mGlobalSearchVerified) { |
Dongwon Kang | 9bbf0ca | 2014-12-01 15:51:03 +0900 | [diff] [blame] | 145 | postTarget.removeCallbacks(failCallback); |
Dongwon Kang | 2ad14c9 | 2015-05-13 18:46:13 +0900 | [diff] [blame] | 146 | setButtonEnabled(mGoToEpgItem, true); |
Dongwon Kang | 9bbf0ca | 2014-12-01 15:51:03 +0900 | [diff] [blame] | 147 | } |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 148 | } |
Wonsik Kim | d71946a | 2014-11-20 23:11:16 +0900 | [diff] [blame] | 149 | |
Dongwon Kang | aa1e803 | 2015-06-01 15:13:06 +0900 | [diff] [blame] | 150 | private void verifyGlobalSearch(final View postTarget, final Runnable failCallback) { |
| 151 | new AsyncTask<Void, Void, Boolean>() { |
| 152 | @Override |
| 153 | protected Boolean doInBackground(Void... params) { |
| 154 | Context context = TvInputDiscoveryTestActivity.this; |
| 155 | for (SearchableInfo info : SearchUtil.getSearchableInfos(context)) { |
| 156 | if (SearchUtil.verifySearchResult(context, info, |
| 157 | MockTvInputSetupActivity.CHANNEL_NAME, |
| 158 | MockTvInputSetupActivity.PROGRAM_TITLE) |
| 159 | && SearchUtil.verifySearchResult(context, info, |
| 160 | MockTvInputSetupActivity.PROGRAM_TITLE, |
| 161 | MockTvInputSetupActivity.PROGRAM_TITLE)) { |
| 162 | return true; |
| 163 | } |
| 164 | } |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | protected void onPostExecute(Boolean result) { |
| 170 | super.onPostExecute(result); |
| 171 | setPassState(mVerifyGlobalSearchItem, result); |
| 172 | mGlobalSearchVerified = result; |
| 173 | goToNextState(postTarget, failCallback); |
| 174 | } |
| 175 | }.execute(); |
Wonsik Kim | d71946a | 2014-11-20 23:11:16 +0900 | [diff] [blame] | 176 | } |
Wonsik Kim | 0215fde | 2014-10-30 00:47:57 +0900 | [diff] [blame] | 177 | } |