X-Git-Url: http://www.average.org/gitweb/?p=YkNeoCR.git;a=blobdiff_plain;f=src%2Forg%2Faverage%2Fnfcauthcr%2FQueryCrToken.java;fp=src%2Forg%2Faverage%2Fnfcauthcr%2FQueryCrToken.java;h=903aefb4a39937d69a098f529f6ede80e0d28d87;hp=0000000000000000000000000000000000000000;hb=0c96e6ff75abc6adfa713c00963fd14f5de2f34c;hpb=08b05b67a65e78e80fb0fffec8855a69a72ebff9 diff --git a/src/org/average/nfcauthcr/QueryCrToken.java b/src/org/average/nfcauthcr/QueryCrToken.java new file mode 100644 index 0000000..903aefb --- /dev/null +++ b/src/org/average/nfcauthcr/QueryCrToken.java @@ -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 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 response = dispatch.onNewIntent(newintent); + if (response != null) { + Intent masterintent = getIntent(); + masterintent.putExtra("response", response); + setResult(RESULT_OK, masterintent); + finish(); + } + } +}