X-Git-Url: http://www.average.org/gitweb/?p=YkNeoCR.git;a=blobdiff_plain;f=src%2Forg%2Faverage%2Fnfcauthcr%2FNFCAuthCRCheck.java;fp=src%2Forg%2Faverage%2Fnfcauthcr%2FNFCAuthCRCheck.java;h=0000000000000000000000000000000000000000;hp=ea37128d65ed936f8dda42c0079809ed7318392f;hb=a0d60dab1717e69b6d853eb91d0065fe378e3c28;hpb=bdfe828f712fa2a187a424923c6594f12e965a5d diff --git a/src/org/average/nfcauthcr/NFCAuthCRCheck.java b/src/org/average/nfcauthcr/NFCAuthCRCheck.java deleted file mode 100644 index ea37128..0000000 --- a/src/org/average/nfcauthcr/NFCAuthCRCheck.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.average.nfcauthcr; - -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.nfc.NfcAdapter; -import android.nfc.Tag; -import android.nfc.TagLostException; -import android.nfc.tech.IsoDep; -import android.util.Log; -import android.widget.Toast; - -import org.average.nfcauthcr.NFCAuthCRYubiNeo; - -public class NFCAuthCRCheck extends Activity { - - private final String TAG = getClass().getName(); - - private AlertDialog swipeDialog; - private PendingIntent tagIntent; - - @Override - protected void onResume() { - super.onResume(); - Log.v(TAG, "Starting the work"); - - Intent intent = getIntent(); - setResult(RESULT_CANCELED); - if (swipeDialog != null) { - swipeDialog.dismiss(); - swipeDialog = null; - } - int slot = intent.getIntExtra("slot", -1); - if (slot > 0) { - swipeDialog = makeDialog(); - swipeDialog.show(); - enableDispatch(slot); - } - } - - @Override - protected void onPause() { - super.onPause(); - Log.v(TAG, "Finished the work"); - - if(swipeDialog != null) { - swipeDialog.dismiss(); - swipeDialog = null; - } - disableDispatch(); - } - - public void onNewIntent(Intent intent) { - Log.v(TAG, "NFC Intent arrived"); - int slot = intent.getIntExtra("slot", -1); - byte[] challenge = intent.getByteArrayExtra("challenge"); - if (slot <= 0) return; - Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); - if (tag == null) return; - IsoDep isoTag = IsoDep.get(tag); - byte[] response = NFCAuthCRYubiNeo.doChallengeYubiKey( - isoTag, slot, challenge); - if (response != null) { - Intent data = getIntent(); - data.putExtra("response", response); - setResult(RESULT_OK, data); - } - finish(); - } - - private AlertDialog makeDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.challenging); - builder.setMessage(R.string.swipe); - builder.setOnCancelListener( - new DialogInterface.OnCancelListener() { - public void onCancel(DialogInterface dialog) { - finish(); - } - }); - return builder.create(); - } - - private void enableDispatch(int slot) { - Intent intent = getIntent(); - intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); - intent.putExtra("slot", slot); - tagIntent = PendingIntent.getActivity(this, 0, intent, 0); - IntentFilter iso = - new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); - NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); - if (adapter == null) { - Toast.makeText(this, R.string.no_nfc, - Toast.LENGTH_LONG).show(); - finish(); - return; - } - if (! adapter.isEnabled()) { - Toast.makeText(this, R.string.nfc_disabled, - Toast.LENGTH_LONG).show(); - finish(); - return; - } - adapter.enableForegroundDispatch( - this, tagIntent, new IntentFilter[] {iso}, - new String[][] {new String[] {IsoDep.class.getName()}}); - } - - private void disableDispatch() { - if (tagIntent != null) { - tagIntent.cancel(); - tagIntent = null; - } - NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); - if (adapter != null) { - adapter.disableForegroundDispatch(this); - } - } -}