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     boolean mReceiverRegistered = false;
21     int mState = STATE_IDLE;
22 
23     @Override
onCreate(Bundle savedInstanceState)24     protected void onCreate(Bundle savedInstanceState) {
25         super.onCreate(savedInstanceState);
26         setContentView(R.layout.pass_fail_text);
27         setPassFailButtonClickListeners();
28         getPassButton().setEnabled(false);
29         mState = STATE_SERVICE2_SETTING_UP;
30         setupServices(this, PaymentService2.COMPONENT);
31     }
32 
33     @Override
onResume()34     protected void onResume() {
35         super.onResume();
36     }
37 
38     @Override
onServicesSetup(boolean result)39     void onServicesSetup(boolean result) {
40         if (mState == STATE_SERVICE2_SETTING_UP) {
41             mState = STATE_SERVICE1_SETTING_UP;
42             setupServices(this, PaymentService1.COMPONENT, PaymentService2.COMPONENT);
43             return;
44         }
45         // Verify HCE service 2 is the default
46         if (makePaymentDefault(PaymentService2.COMPONENT, R.string.nfc_hce_change_preinstalled_wallet)) {
47             mState = STATE_MAKING_SERVICE2_DEFAULT;
48         } else {
49             // Already default
50             NfcDialogs.createHceTapReaderDialog(this,null).show();
51         }
52     }
53 
54     @Override
onPaymentDefaultResult(ComponentName component, boolean success)55     void onPaymentDefaultResult(ComponentName component, boolean success) {
56         if (success) {
57             NfcDialogs.createHceTapReaderDialog(this, null).show();
58         }
59     }
60 
61     @Override
onPause()62     protected void onPause() {
63         super.onPause();
64         if (mReceiverRegistered) {
65             unregisterReceiver(mReceiver);
66         }
67     }
buildReaderIntent(Context context)68     public static Intent buildReaderIntent(Context context) {
69         Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
70         readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS,
71                 PaymentService2.APDU_COMMAND_SEQUENCE);
72         readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES,
73                 PaymentService2.APDU_RESPOND_SEQUENCE);
74         readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL,
75                 context.getString(R.string.nfc_hce_dual_payment_reader));
76         return readerIntent;
77     }
78 
79     @Override
onApduSequenceComplete(ComponentName component, long duration)80     void onApduSequenceComplete(ComponentName component, long duration) {
81         if (component.equals(PaymentService2.COMPONENT)) {
82             getPassButton().setEnabled(true);
83         }
84     }
85 }
86