• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.content.Intent;
20 import android.content.pm.PackageManager;
21 import android.nfc.tech.MifareUltralight;
22 import android.nfc.tech.Ndef;
23 import android.nfc.tech.TagTechnology;
24 import android.os.Bundle;
25 
26 import com.android.cts.verifier.ArrayTestListAdapter;
27 import com.android.cts.verifier.PassFailButtons;
28 import com.android.cts.verifier.R;
29 import com.android.cts.verifier.TestListAdapter.TestListItem;
30 import com.android.cts.verifier.nfc.hce.HceEmulatorTestActivity;
31 import com.android.cts.verifier.nfc.hce.HceReaderTestActivity;
32 import com.android.cts.verifier.nfc.hcef.HceFEmulatorTestActivity;
33 import com.android.cts.verifier.nfc.hcef.HceFReaderTestActivity;
34 import com.android.cts.verifier.nfc.offhost.OffhostUiccEmulatorTestActivity;
35 import com.android.cts.verifier.nfc.offhost.OffhostUiccReaderTestActivity;
36 
37 /** Activity that lists all the NFC tests. */
38 public class NfcTestActivity extends PassFailButtons.TestListActivity {
39 
40     private static final String NDEF_ID =
41             TagVerifierActivity.getTagTestId(Ndef.class);
42 
43     private static final String MIFARE_ULTRALIGHT_ID =
44             TagVerifierActivity.getTagTestId(MifareUltralight.class);
45 
46     private static final String FEATURE_NFC_MIFARE = "com.nxp.mifare";
47 
48     @Override
onCreate(Bundle savedInstanceState)49     protected void onCreate(Bundle savedInstanceState) {
50         super.onCreate(savedInstanceState);
51         setContentView(R.layout.pass_fail_list);
52         setInfoResources(R.string.nfc_test, R.string.nfc_test_info, 0);
53         setPassFailButtonClickListeners();
54 
55         ArrayTestListAdapter adapter = new ArrayTestListAdapter(this);
56 
57         if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
58             adapter.add(TestListItem.newCategory(this, R.string.nfc_tag_verification));
59             adapter.add(TestListItem.newTest(this, R.string.nfc_ndef,
60                     NDEF_ID, getTagIntent(Ndef.class), null));
61             if (getPackageManager().hasSystemFeature(FEATURE_NFC_MIFARE)) {
62                 adapter.add(TestListItem.newTest(this, R.string.nfc_mifare_ultralight,
63                         MIFARE_ULTRALIGHT_ID, getTagIntent(MifareUltralight.class), null));
64             }
65         }
66 
67         if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
68             adapter.add(TestListItem.newCategory(this, R.string.nfc_hce));
69             if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
70                 adapter.add(TestListItem.newTest(this, R.string.nfc_hce_reader_tests,
71                         HceReaderTestActivity.class.getName(),
72                         new Intent(this, HceReaderTestActivity.class), null));
73             }
74             adapter.add(TestListItem.newTest(this, R.string.nfc_hce_emulator_tests,
75                     HceEmulatorTestActivity.class.getName(),
76                     new Intent(this, HceEmulatorTestActivity.class), null));
77         }
78 
79         if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION_NFCF)) {
80             adapter.add(TestListItem.newCategory(this, R.string.nfc_hce_f));
81             if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
82                 adapter.add(TestListItem.newTest(this, R.string.nfc_hce_f_reader_tests,
83                         HceFReaderTestActivity.class.getName(),
84                         new Intent(this, HceFReaderTestActivity.class), null));
85             }
86             adapter.add(TestListItem.newTest(this, R.string.nfc_hce_f_emulator_tests,
87                     HceFEmulatorTestActivity.class.getName(),
88                     new Intent(this, HceFEmulatorTestActivity.class), null));
89         }
90 
91         if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC_OFF_HOST_CARD_EMULATION_UICC)) {
92             adapter.add(TestListItem.newCategory(this, R.string.nfc_offhost_uicc));
93             if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
94                 adapter.add(TestListItem.newTest(this, R.string.nfc_offhost_uicc_reader_tests,
95                         OffhostUiccReaderTestActivity.class.getName(),
96                         new Intent(this, OffhostUiccReaderTestActivity.class), null));
97             }
98             adapter.add(TestListItem.newTest(this, R.string.nfc_offhost_uicc_emulator_tests,
99                     OffhostUiccEmulatorTestActivity.class.getName(),
100                     new Intent(this, OffhostUiccEmulatorTestActivity.class), null));
101         }
102 
103         setTestListAdapter(adapter);
104     }
105 
getTagIntent(Class<? extends TagTechnology> primaryTech)106     private Intent getTagIntent(Class<? extends TagTechnology> primaryTech) {
107         return new Intent(this, TagVerifierActivity.class)
108                 .putExtra(TagVerifierActivity.EXTRA_TECH, primaryTech.getName());
109     }
110 }
111