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.nfc.NfcDialogs;
10 import com.android.cts.verifier.R;
11 
12 @TargetApi(19)
13 public class OnAndOffHostEmulatorActivity extends BaseEmulatorActivity {
14     @Override
onCreate(Bundle savedInstanceState)15     protected void onCreate(Bundle savedInstanceState) {
16         super.onCreate(savedInstanceState);
17         setContentView(R.layout.pass_fail_text);
18         setPassFailButtonClickListeners();
19         getPassButton().setEnabled(false);
20         setupServices(this, OffHostService.COMPONENT, AccessService.COMPONENT);
21     }
22 
23     @Override
onResume()24     protected void onResume() {
25         super.onResume();
26     }
27 
28     @Override
onServicesSetup(boolean result)29     void onServicesSetup(boolean result) {
30         NfcDialogs.createHceTapReaderDialog(this, getString(R.string.nfc_hce_on_and_offhost_emulator_help)).show();
31     }
32 
buildReaderIntent(Context context)33     public static Intent buildReaderIntent(Context context) {
34         // Combine command/response APDU arrays
35         CommandApdu[] commandSequences = new CommandApdu[OffHostService.APDU_COMMAND_SEQUENCE.length +
36                                                AccessService.APDU_COMMAND_SEQUENCE.length];
37         System.arraycopy(OffHostService.APDU_COMMAND_SEQUENCE, 0, commandSequences, 0,
38                 OffHostService.APDU_COMMAND_SEQUENCE.length);
39         System.arraycopy(AccessService.APDU_COMMAND_SEQUENCE, 0, commandSequences,
40                 OffHostService.APDU_COMMAND_SEQUENCE.length,
41                 AccessService.APDU_COMMAND_SEQUENCE.length);
42 
43         String[] responseSequences = new String[OffHostService.APDU_RESPOND_SEQUENCE.length +
44                                                AccessService.APDU_RESPOND_SEQUENCE.length];
45         System.arraycopy(OffHostService.APDU_RESPOND_SEQUENCE, 0, responseSequences, 0,
46                 OffHostService.APDU_RESPOND_SEQUENCE.length);
47         System.arraycopy(AccessService.APDU_RESPOND_SEQUENCE, 0, responseSequences,
48                 OffHostService.APDU_RESPOND_SEQUENCE.length,
49                 AccessService.APDU_RESPOND_SEQUENCE.length);
50 
51         Intent readerIntent = new Intent(context, SimpleReaderActivity.class);
52         readerIntent.putExtra(SimpleReaderActivity.EXTRA_APDUS,
53                 commandSequences);
54         readerIntent.putExtra(SimpleReaderActivity.EXTRA_RESPONSES,
55                 responseSequences);
56         readerIntent.putExtra(SimpleReaderActivity.EXTRA_LABEL,
57                 context.getString(R.string.nfc_hce_on_and_offhost_service_reader));
58         return readerIntent;
59     }
60 
61     @Override
onApduSequenceComplete(ComponentName component, long duration)62     void onApduSequenceComplete(ComponentName component, long duration) {
63         if (component.equals(AccessService.COMPONENT)) {
64             getPassButton().setEnabled(true);
65         }
66     }
67 }
68