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