1 package com.android.cts.verifier.nfc.hce; 2 3 import android.annotation.TargetApi; 4 import android.content.ComponentName; 5 import android.content.Context; 6 import android.content.Intent; 7 import android.nfc.cardemulation.CardEmulation; 8 import android.os.Bundle; 9 10 import com.android.cts.verifier.R; 11 import com.android.cts.verifier.nfc.NfcDialogs; 12 13 @TargetApi(19) 14 public class DualPaymentEmulatorActivity extends BaseEmulatorActivity { 15 final static int STATE_IDLE = 0; 16 final static int STATE_SERVICE1_SETTING_UP = 1; 17 final static int STATE_SERVICE2_SETTING_UP = 2; 18 final static int STATE_MAKING_SERVICE2_DEFAULT = 3; 19 20 int mState = STATE_IDLE; 21 22 @Override onCreate(Bundle savedInstanceState)23 protected void onCreate(Bundle savedInstanceState) { 24 super.onCreate(savedInstanceState); 25 setContentView(R.layout.pass_fail_text); 26 setPassFailButtonClickListeners(); 27 getPassButton().setEnabled(false); 28 mState = STATE_SERVICE2_SETTING_UP; 29 setupServices(this, PaymentService2.COMPONENT); 30 } 31 32 @Override onResume()33 protected void onResume() { 34 super.onResume(); 35 } 36 37 @Override onServicesSetup(boolean result)38 void onServicesSetup(boolean result) { 39 if (mState == STATE_SERVICE2_SETTING_UP) { 40 mState = STATE_SERVICE1_SETTING_UP; 41 setupServices(this, PaymentService1.COMPONENT, PaymentService2.COMPONENT); 42 return; 43 } 44 // Verify HCE service 2 is the default 45 if (makePaymentDefault(PaymentService2.COMPONENT, R.string.nfc_hce_change_preinstalled_wallet)) { 46 mState = STATE_MAKING_SERVICE2_DEFAULT; 47 } else { 48 // Already default 49 NfcDialogs.createHceTapReaderDialog(this,null).show(); 50 } 51 } 52 53 @Override onPaymentDefaultResult(ComponentName component, boolean success)54 void onPaymentDefaultResult(ComponentName component, boolean success) { 55 if (success) { 56 NfcDialogs.createHceTapReaderDialog(this, null).show(); 57 } 58 } 59 60 @Override onPause()61 protected void onPause() { 62 super.onPause(); 63 } buildReaderIntent(Context context)64 public static Intent buildReaderIntent(Context context) { 65 Intent readerIntent = new Intent(context, SimpleReaderActivity.class); 66 readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS, 67 PaymentService2.APDU_COMMAND_SEQUENCE); 68 readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES, 69 PaymentService2.APDU_RESPOND_SEQUENCE); 70 readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL, 71 context.getString(R.string.nfc_hce_dual_payment_reader)); 72 return readerIntent; 73 } 74 75 @Override onApduSequenceComplete(ComponentName component, long duration)76 void onApduSequenceComplete(ComponentName component, long duration) { 77 if (component.equals(PaymentService2.COMPONENT)) { 78 getPassButton().setEnabled(true); 79 } 80 } 81 } 82