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.os.Bundle; 8 9 import com.android.cts.verifier.R; 10 import com.android.cts.verifier.nfc.NfcDialogs; 11 12 @TargetApi(19) 13 public class PrefixPaymentEmulator2Activity extends BaseEmulatorActivity { 14 final static int STATE_IDLE = 0; 15 final static int STATE_SERVICE1_SETTING_UP = 1; 16 final static int STATE_SERVICE2_SETTING_UP = 2; 17 final static int STATE_MAKING_SERVICE2_DEFAULT = 3; 18 19 boolean mReceiverRegistered = false; 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, PrefixPaymentService2.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, PrefixPaymentService1.COMPONENT, PrefixPaymentService2.COMPONENT); 42 return; 43 } 44 // Verify HCE service 2 is the default 45 if (makePaymentDefault(PrefixPaymentService2.COMPONENT, R.string.nfc_hce_change_preinstalled_wallet)) { 46 mState = STATE_MAKING_SERVICE2_DEFAULT; 47 } else { 48 // Already default 49 NfcDialogs.createHceTapReaderDialog(this,getString(R.string.nfc_hce_payment_prefix_aids_help)).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, getString(R.string.nfc_hce_payment_prefix_aids_help)).show(); 57 } 58 } 59 60 @Override onPause()61 protected void onPause() { 62 super.onPause(); 63 if (mReceiverRegistered) { 64 unregisterReceiver(mReceiver); 65 } 66 } buildReaderIntent(Context context)67 public static Intent buildReaderIntent(Context context) { 68 Intent readerIntent = new Intent(context, SimpleReaderActivity.class); 69 readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS, 70 PrefixPaymentService2.APDU_COMMAND_SEQUENCE); 71 readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES, 72 PrefixPaymentService2.APDU_RESPOND_SEQUENCE); 73 readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL, 74 context.getString(R.string.nfc_hce_payment_prefix_aids_reader_2)); 75 return readerIntent; 76 } 77 78 @Override onApduSequenceComplete(ComponentName component, long duration)79 void onApduSequenceComplete(ComponentName component, long duration) { 80 if (component.equals(PrefixPaymentService2.COMPONENT)) { 81 getPassButton().setEnabled(true); 82 } 83 } 84 } 85