1 package org.average.ykneocr;
3 import java.util.ArrayList;
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;
21 import org.average.ykneocr.NfcCRdispatch;
23 public class QueryCrToken extends Activity {
25 private final String TAG = getClass().getName();
27 private NfcCRdispatch dispatch = new NfcCRdispatch((Activity)this);
28 private SharedPreferences prefs;
31 protected void onCreate(Bundle savedInstanceState) {
32 super.onCreate(savedInstanceState);
33 Log.v(TAG, "onCreate get prefs");
34 prefs = PreferenceManager.getDefaultSharedPreferences(this);
38 protected void onResume() {
40 Log.v(TAG, "Starting the work");
42 setResult(RESULT_CANCELED);
43 int slot = prefs.getInt("slot_number", -1);
44 if (slot != 1 && slot != 2) {
45 Log.e(TAG, "Slot " + slot + " cannot be used");
46 Toast.makeText(this, R.string.need_slot,
47 Toast.LENGTH_LONG).show();
50 new AlertDialog.Builder(this)
51 .setTitle(R.string.challenging)
52 .setMessage(R.string.swipe)
54 new DialogInterface.OnCancelListener() {
55 public void onCancel(DialogInterface dialog) {
62 Intent intent = getIntent();
63 ArrayList<String> challenge =
64 intent.getStringArrayListExtra("challenge");
65 intent.putExtra("yubikey_neo_slot", slot);
66 if (challenge != null) {
67 if (!dispatch.onResume(challenge)) {
68 Log.e(TAG, "Failed to enable fg dispatch");
72 Log.e(TAG, "Challenge missing in the Intent");
78 protected void onPause() {
80 Log.v(TAG, "Finished the work");
85 public void onNewIntent(Intent newintent) {
86 Log.v(TAG, "NFC Intent arrived");
88 ArrayList<String> response = dispatch.onNewIntent(newintent);
89 if (response != null) {
90 Intent masterintent = getIntent();
91 masterintent.putExtra("response", response);
92 setResult(RESULT_OK, masterintent);