1 /*
2  * Copyright (C) 2011 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.nfc;
18 
19 import com.android.cts.verifier.ArrayTestListAdapter;
20 import com.android.cts.verifier.PassFailButtons;
21 import com.android.cts.verifier.R;
22 import com.android.cts.verifier.TestListAdapter.TestListItem;
23 import com.android.cts.verifier.nfc.hce.HceEmulatorTestActivity;
24 import com.android.cts.verifier.nfc.hce.HceReaderTestActivity;
25 
26 import android.content.Intent;
27 import android.content.pm.PackageManager;
28 import android.nfc.tech.MifareUltralight;
29 import android.nfc.tech.Ndef;
30 import android.nfc.tech.TagTechnology;
31 import android.os.Build;
32 import android.os.Bundle;
33 
34 /** Activity that lists all the NFC tests. */
35 public class NfcTestActivity extends PassFailButtons.TestListActivity {
36 
37     private static final String NDEF_ID =
38             TagVerifierActivity.getTagTestId(Ndef.class);
39 
40     private static final String MIFARE_ULTRALIGHT_ID =
41             TagVerifierActivity.getTagTestId(MifareUltralight.class);
42 
43     private static final String FEATURE_NFC_MIFARE = "com.nxp.mifare";
44 
45     @Override
onCreate(Bundle savedInstanceState)46     protected void onCreate(Bundle savedInstanceState) {
47         super.onCreate(savedInstanceState);
48         setContentView(R.layout.pass_fail_list);
49         setInfoResources(R.string.nfc_test, R.string.nfc_test_info, 0);
50         setPassFailButtonClickListeners();
51 
52         ArrayTestListAdapter adapter = new ArrayTestListAdapter(this);
53 
54         adapter.add(TestListItem.newCategory(this, R.string.nfc_pee_2_pee));
55         adapter.add(TestListItem.newTest(this, R.string.nfc_ndef_push_sender,
56                 NdefPushSenderActivity.class.getName(),
57                 new Intent(this, NdefPushSenderActivity.class), null));
58         adapter.add(TestListItem.newTest(this, R.string.nfc_ndef_push_receiver,
59                 NdefPushReceiverActivity.class.getName(),
60                 new Intent(this, NdefPushReceiverActivity.class), null));
61 
62         if ("MNC".equals(Build.VERSION.CODENAME) || Build.VERSION.SDK_INT >= 23) {
63             adapter.add(TestListItem.newTest(this, R.string.nfc_llcp_version_check,
64                     LlcpVersionActivity.class.getName(),
65                     new Intent(this, LlcpVersionActivity.class), null));
66         }
67         adapter.add(TestListItem.newCategory(this, R.string.nfc_tag_verification));
68         adapter.add(TestListItem.newTest(this, R.string.nfc_ndef,
69                 NDEF_ID, getTagIntent(Ndef.class), null));
70         if (getPackageManager().hasSystemFeature(FEATURE_NFC_MIFARE)) {
71             adapter.add(TestListItem.newTest(this, R.string.nfc_mifare_ultralight,
72                     MIFARE_ULTRALIGHT_ID, getTagIntent(MifareUltralight.class), null));
73         }
74 
75         if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
76             adapter.add(TestListItem.newCategory(this, R.string.nfc_hce));
77             adapter.add(TestListItem.newTest(this, R.string.nfc_hce_reader_tests,
78                     HceReaderTestActivity.class.getName(),
79                     new Intent(this, HceReaderTestActivity.class), null));
80             adapter.add(TestListItem.newTest(this, R.string.nfc_hce_emulator_tests,
81                     HceEmulatorTestActivity.class.getName(),
82                     new Intent(this, HceEmulatorTestActivity.class), null));
83         }
84 
85         setTestListAdapter(adapter);
86     }
87 
getTagIntent(Class<? extends TagTechnology> primaryTech)88     private Intent getTagIntent(Class<? extends TagTechnology> primaryTech) {
89         return new Intent(this, TagVerifierActivity.class)
90                 .putExtra(TagVerifierActivity.EXTRA_TECH, primaryTech.getName());
91     }
92 }
93