• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.offhost;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.nfc.NfcAdapter;
22 import android.os.Build;
23 import android.os.Bundle;
24 import android.widget.TextView;
25 
26 import com.android.cts.verifier.PassFailButtons;
27 import com.android.cts.verifier.R;
28 import com.android.cts.verifier.nfc.hce.HceUtils;
29 
30 public class UiccTransactionEvent2EmulatorActivity extends PassFailButtons.Activity {
31     static final String TAG = "UiccTransactionEvent2EmulatorActivity";
32 
33     TextView mTextView;
34 
35     @Override
onCreate(Bundle savedInstanceState)36     protected void onCreate(Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38 
39         setContentView(R.layout.pass_fail_text);
40         setPassFailButtonClickListeners();
41         if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
42             getPassButton().setEnabled(false);
43         } else {
44             getPassButton().setEnabled(true);
45         }
46 
47         mTextView = (TextView) findViewById(R.id.text);
48         mTextView.setTextSize(12.0f);
49         mTextView.setText(R.string.nfc_offhost_uicc_transaction_event_emulator_help);
50 
51         initProcess();
52     }
53 
54     @Override
onNewIntent(Intent intent)55     protected void onNewIntent(Intent intent) {
56         super.onNewIntent(intent);
57 
58         setContentView(R.layout.pass_fail_text);
59         setPassFailButtonClickListeners();
60         getPassButton().setEnabled(false);
61 
62         mTextView = (TextView) findViewById(R.id.text);
63         mTextView.setTextSize(12.0f);
64 
65         setIntent(intent);
66         initProcess();
67     }
68 
69     @Override
onPause()70     protected void onPause() {
71         super.onPause();
72     }
73 
74     @Override
onResume()75     protected void onResume() {
76         super.onResume();
77     }
78 
buildReaderIntent(Context context)79     public static Intent buildReaderIntent(Context context) {
80         Intent readerIntent = new Intent(context, SimpleOffhostReaderActivity.class);
81         readerIntent.putExtra(SimpleOffhostReaderActivity.EXTRA_APDUS,
82                 UiccTransactionEvent2Service.APDU_COMMAND_SEQUENCE);
83         readerIntent.putExtra(SimpleOffhostReaderActivity.EXTRA_RESPONSES,
84                 UiccTransactionEvent2Service.APDU_RESPOND_SEQUENCE);
85         readerIntent.putExtra(SimpleOffhostReaderActivity.EXTRA_LABEL,
86                 context.getString(R.string.nfc_offhost_uicc_transaction_event2_reader));
87         readerIntent.putExtra(SimpleOffhostReaderActivity.EXTRA_DESELECT, true);
88         return readerIntent;
89     }
90 
initProcess()91     private void initProcess() {
92         Bundle bundle = getIntent().getExtras();
93         if (bundle != null && getIntent().getAction() != null) {
94             byte[] transactionData = bundle.getByteArray(NfcAdapter.EXTRA_DATA);
95             if (transactionData != null) {
96                 runOnUiThread(new Runnable() {
97                     @Override
98                     public void run() {
99                         mTextView.setText("Pass - NFC Action:" + getIntent().getAction() + " uri:" + getIntent().getDataString()
100                             + " data:" + HceUtils.getHexBytes(null, transactionData));
101                         getPassButton().setEnabled(true);
102                     }
103                 });
104             } else {
105                 runOnUiThread(new Runnable() {
106                     @Override
107                     public void run() {
108                         mTextView.setText("Fail - Action:" + getIntent().getAction() + " uri:" + getIntent().getDataString()
109                             + " data: null");
110                         getPassButton().setEnabled(false);
111                     }
112                 });
113             }
114         }
115     }
116 }
117