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.annotation.TargetApi; 20 import android.app.Activity; 21 import android.app.AlertDialog; 22 import android.app.ProgressDialog; 23 import android.content.BroadcastReceiver; 24 import android.content.ComponentName; 25 import android.content.Context; 26 import android.content.DialogInterface; 27 import android.content.Intent; 28 import android.content.IntentFilter; 29 import android.nfc.NfcAdapter; 30 import android.nfc.cardemulation.CardEmulation; 31 import android.os.AsyncTask; 32 import android.os.Build; 33 import android.os.Bundle; 34 import android.util.Log; 35 import android.widget.TextView; 36 37 import java.util.ArrayList; 38 import java.util.Arrays; 39 import java.util.List; 40 41 import com.android.cts.verifier.PassFailButtons; 42 import com.android.cts.verifier.R; 43 44 import com.android.cts.verifier.nfc.hce.HceUtils; 45 46 public class UiccTransactionEvent3EmulatorActivity extends PassFailButtons.Activity { 47 static final String TAG = "UiccTransactionEvent3EmulatorActivity"; 48 49 TextView mTextView; 50 51 @Override onCreate(Bundle savedInstanceState)52 protected void onCreate(Bundle savedInstanceState) { 53 super.onCreate(savedInstanceState); 54 55 setContentView(R.layout.pass_fail_text); 56 setPassFailButtonClickListeners(); 57 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) { 58 getPassButton().setEnabled(false); 59 } else { 60 getPassButton().setEnabled(true); 61 } 62 63 mTextView = (TextView) findViewById(R.id.text); 64 mTextView.setTextSize(12.0f); 65 mTextView.setText(R.string.nfc_offhost_uicc_transaction_event_emulator_help); 66 67 initProcess(); 68 } 69 70 @Override onNewIntent(Intent intent)71 protected void onNewIntent(Intent intent) { 72 super.onNewIntent(intent); 73 74 setContentView(R.layout.pass_fail_text); 75 setPassFailButtonClickListeners(); 76 getPassButton().setEnabled(false); 77 78 mTextView = (TextView) findViewById(R.id.text); 79 mTextView.setTextSize(12.0f); 80 81 setIntent(intent); 82 initProcess(); 83 } 84 85 @Override onPause()86 protected void onPause() { 87 super.onPause(); 88 } 89 90 @Override onResume()91 protected void onResume() { 92 super.onResume(); 93 } 94 buildReaderIntent(Context context)95 public static Intent buildReaderIntent(Context context) { 96 Intent readerIntent = new Intent(context, SimpleOffhostReaderActivity.class); 97 readerIntent.putExtra(SimpleOffhostReaderActivity.EXTRA_APDUS, 98 UiccTransactionEvent3Service.APDU_COMMAND_SEQUENCE); 99 readerIntent.putExtra(SimpleOffhostReaderActivity.EXTRA_RESPONSES, 100 UiccTransactionEvent3Service.APDU_RESPOND_SEQUENCE); 101 readerIntent.putExtra(SimpleOffhostReaderActivity.EXTRA_LABEL, 102 context.getString(R.string.nfc_offhost_uicc_transaction_event3_reader)); 103 return readerIntent; 104 } 105 initProcess()106 private void initProcess() { 107 Bundle bundle = getIntent().getExtras(); 108 if(bundle != null){ 109 byte[] transactionData = bundle.getByteArray(NfcAdapter.EXTRA_DATA); 110 if(transactionData != null){ 111 runOnUiThread(new Runnable() { 112 @Override 113 public void run() { 114 mTextView.setText("Pass - NFC Action:" + getIntent().getAction() + " uri:" + getIntent().getDataString() 115 + " data:" + HceUtils.getHexBytes(null, transactionData)); 116 getPassButton().setEnabled(true); 117 } 118 }); 119 } else { 120 runOnUiThread(new Runnable() { 121 @Override 122 public void run() { 123 mTextView.setText("Fail - Action:" + getIntent().getAction() + " uri:" + getIntent().getDataString() 124 + " data: null"); 125 getPassButton().setEnabled(false); 126 } 127 }); 128 } 129 } 130 } 131 } 132