begin converting to multiple ops per request
[YkNeoCR.git] / src / org / average / nfcauthcr / QueryCrToken.java
1 package org.average.nfcauthcr;
2
3 import java.util.ArrayList;
4
5 import android.os.Bundle;
6 import android.app.Activity;
7 import android.app.AlertDialog;
8 import android.app.PendingIntent;
9 import android.content.DialogInterface;
10 import android.content.Intent;
11 import android.content.IntentFilter;
12 import android.content.SharedPreferences;
13 import android.nfc.NfcAdapter;
14 import android.nfc.Tag;
15 import android.nfc.TagLostException;
16 import android.nfc.tech.IsoDep;
17 import android.preference.PreferenceManager;
18 import android.util.Log;
19 import android.widget.Toast;
20
21 import org.average.nfcauthcr.NfcCRdispatch;
22
23 public class QueryCrToken extends Activity {
24
25         private final String TAG = getClass().getName();
26
27         private NfcCRdispatch dispatch = new NfcCRdispatch((Activity)this);
28         private SharedPreferences prefs;
29
30         @Override
31         protected void onCreate(Bundle savedInstanceState) {
32                 super.onCreate(savedInstanceState);
33                 Log.v(TAG, "onCreate get prefs");
34                 prefs = PreferenceManager.getDefaultSharedPreferences(this);
35         }
36
37         @Override
38         protected void onResume() {
39                 super.onResume();
40                 Log.v(TAG, "Starting the work");
41
42                 new AlertDialog.Builder(this)
43                         .setTitle(R.string.challenging)
44                         .setMessage(R.string.swipe)
45                         .setOnCancelListener(
46                                 new DialogInterface.OnCancelListener() {
47                                 public void onCancel(DialogInterface dialog) {
48                                         Log.v(TAG, "Cancel");
49                                         finish();
50                                 }
51                         })
52                         .create().show();
53
54                 Intent intent = getIntent();
55                 ArrayList<String> challenge =
56                                 intent.getStringArrayListExtra("challenge");
57                 int slot = prefs.getInt("slot_number", -1);
58                 intent.putExtra("yubikey_neo_slot", slot);
59                 setResult(RESULT_CANCELED);
60                 if (challenge != null) {
61                         dispatch.onResume(challenge);
62                 } else {
63                         Log.e(TAG, "Challenge missing in the Intent");
64                         finish();
65                 }
66         }
67
68         @Override
69         protected void onPause() {
70                 super.onPause();
71                 Log.v(TAG, "Finished the work");
72
73                 dispatch.onPause();
74         }
75
76         public void onNewIntent(Intent newintent) {
77                 Log.v(TAG, "NFC Intent arrived");
78
79                 ArrayList<String> response = dispatch.onNewIntent(newintent);
80                 if (response != null) {
81                         Intent masterintent = getIntent();
82                         masterintent.putExtra("response", response);
83                         setResult(RESULT_OK, masterintent);
84                         finish();
85                 }
86         }
87 }