blob: 43f293a92e065d24a47d2de18ec9d2d6fd35ea88 [file] [log] [blame]
Sungsoo Limb773b242015-09-06 15:51:25 +09001/*
2 * Copyright (C) 2015 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
17package com.android.cts.verifier.tv;
18
19import android.content.Intent;
20import android.database.Cursor;
21import android.graphics.drawable.Drawable;
22import android.media.tv.TvContract;
23import android.text.TextUtils;
24import android.view.View;
25import android.widget.TextView;
26import android.widget.Toast;
27
28import com.android.cts.verifier.R;
29
30/**
31 * Tests for verifying TV app behavior for TV app-link.
32 */
33public class AppLinkTestActivity extends TvAppVerifierActivity implements View.OnClickListener {
34 private static final long TIMEOUT_MS = 5l * 60l * 1000l; // 5 mins.
35
36 private boolean mSelectAppLinkItemPassed;
37 private View mSelectAppLinkItem;
38 private View mVerifyAppLinkIntentItem;
39 private View mVerifyAppLinkCardItem;
40
41 Runnable mSelectAppLinkFailCallback;
42
43 @Override
44 public void onClick(View v) {
45 final View postTarget = getPostTarget();
46
47 if (containsButton(mSelectAppLinkItem, v)) {
48 Intent tvAppIntent = null;
49 String[] projection = { TvContract.Channels._ID };
50 try (Cursor cursor = getContentResolver().query(
51 TvContract.buildChannelsUriForInput(MockTvInputService.getInputId(this)),
52 projection, null, null, null)) {
53 if (cursor != null && cursor.moveToNext()) {
54 tvAppIntent = new Intent(Intent.ACTION_VIEW,
55 TvContract.buildChannelUri(cursor.getLong(0)));
56 }
57 }
58 if (tvAppIntent == null) {
59 Toast.makeText(this, R.string.tv_channel_not_found, Toast.LENGTH_SHORT).show();
60 return;
61 }
62
63 mSelectAppLinkFailCallback = new Runnable() {
64 @Override
65 public void run() {
66 mSelectAppLinkItemPassed = false;
67 setPassState(mSelectAppLinkItem, false);
68 setPassState(mVerifyAppLinkIntentItem, false);
69 }
70 };
71 postTarget.postDelayed(mSelectAppLinkFailCallback, TIMEOUT_MS);
72 mSelectAppLinkItemPassed = true;
73 setPassState(mSelectAppLinkItem, true);
74
75 startActivity(tvAppIntent);
76 } else if (containsButton(mVerifyAppLinkCardItem, v)) {
77 setPassState(mVerifyAppLinkCardItem, true);
78 getPassButton().setEnabled(true);
79 }
80 }
81
82 @Override
83 protected void onNewIntent(Intent intent) {
84 if (mSelectAppLinkItemPassed
85 && TextUtils.equals(MockTvInputSetupActivity.APP_LINK_TEST_VALUE,
86 intent.getStringExtra(MockTvInputSetupActivity.APP_LINK_TEST_KEY))) {
87 getPostTarget().removeCallbacks(mSelectAppLinkFailCallback);
88 setPassState(mVerifyAppLinkIntentItem, true);
89 setButtonEnabled(mVerifyAppLinkCardItem, true);
90 }
91 }
92
93 @Override
94 protected void createTestItems() {
95 mSelectAppLinkItem = createUserItem(R.string.tv_app_link_test_select_app_link,
96 R.string.tv_launch_tv_app, this);
97 setButtonEnabled(mSelectAppLinkItem, true);
98 mVerifyAppLinkIntentItem = createAutoItem(
99 R.string.tv_app_link_test_verify_link_clicked);
100 mVerifyAppLinkCardItem = createUserItem(R.string.tv_input_link_test_verify_link_interface,
101 android.R.string.yes, this);
102 TextView instructions = (TextView) mVerifyAppLinkCardItem.findViewById(R.id.instructions);
103 Drawable image = getDrawable(R.drawable.app_link_img);
104 image.setBounds(0, 0, 317, 241);
105 instructions.setCompoundDrawablePadding(10);
106 instructions.setCompoundDrawables(image, null, null, null);
107 }
108
109 @Override
110 protected void setInfoResources() {
111 setInfoResources(R.string.tv_app_link_test, R.string.tv_app_link_test_info, -1);
112 }
113}