]> www.average.org Git - YkNeoCR.git/blobdiff - src/org/average/nfcauthcr/QueryCrToken.java
begin converting to multiple ops per request
[YkNeoCR.git] / src / org / average / nfcauthcr / QueryCrToken.java
diff --git a/src/org/average/nfcauthcr/QueryCrToken.java b/src/org/average/nfcauthcr/QueryCrToken.java
new file mode 100644 (file)
index 0000000..903aefb
--- /dev/null
@@ -0,0 +1,87 @@
+package org.average.nfcauthcr;
+
+import java.util.ArrayList;
+
+import android.os.Bundle;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.PendingIntent;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.nfc.NfcAdapter;
+import android.nfc.Tag;
+import android.nfc.TagLostException;
+import android.nfc.tech.IsoDep;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.widget.Toast;
+
+import org.average.nfcauthcr.NfcCRdispatch;
+
+public class QueryCrToken extends Activity {
+
+       private final String TAG = getClass().getName();
+
+       private NfcCRdispatch dispatch = new NfcCRdispatch((Activity)this);
+       private SharedPreferences prefs;
+
+       @Override
+       protected void onCreate(Bundle savedInstanceState) {
+               super.onCreate(savedInstanceState);
+               Log.v(TAG, "onCreate get prefs");
+               prefs = PreferenceManager.getDefaultSharedPreferences(this);
+       }
+
+       @Override
+       protected void onResume() {
+               super.onResume();
+               Log.v(TAG, "Starting the work");
+
+               new AlertDialog.Builder(this)
+                       .setTitle(R.string.challenging)
+                       .setMessage(R.string.swipe)
+                       .setOnCancelListener(
+                               new DialogInterface.OnCancelListener() {
+                               public void onCancel(DialogInterface dialog) {
+                                       Log.v(TAG, "Cancel");
+                                       finish();
+                               }
+                       })
+                       .create().show();
+
+               Intent intent = getIntent();
+               ArrayList<String> challenge =
+                               intent.getStringArrayListExtra("challenge");
+               int slot = prefs.getInt("slot_number", -1);
+               intent.putExtra("yubikey_neo_slot", slot);
+               setResult(RESULT_CANCELED);
+               if (challenge != null) {
+                       dispatch.onResume(challenge);
+               } else {
+                       Log.e(TAG, "Challenge missing in the Intent");
+                       finish();
+               }
+       }
+
+       @Override
+       protected void onPause() {
+               super.onPause();
+               Log.v(TAG, "Finished the work");
+
+               dispatch.onPause();
+       }
+
+       public void onNewIntent(Intent newintent) {
+               Log.v(TAG, "NFC Intent arrived");
+
+               ArrayList<String> response = dispatch.onNewIntent(newintent);
+               if (response != null) {
+                       Intent masterintent = getIntent();
+                       masterintent.putExtra("response", response);
+                       setResult(RESULT_OK, masterintent);
+                       finish();
+               }
+       }
+}