-package org.average.nfcauthcr;
+package org.average.ykneocr;
+
+import java.io.IOException;
+import java.util.ArrayList;
import android.app.Activity;
import android.app.PendingIntent;
import android.util.Log;
import android.widget.Toast;
-import org.average.nfcauthcr.YkNeo;
-import org.average.nfcauthcr.CRException;
+import org.average.ykneocr.YkNeo;
+import org.average.ykneocr.CRException;
public class NfcCRdispatch {
private Activity activity = null;
private PendingIntent tagIntent = null;
- private byte[] challenge;
+ private ArrayList<String> challenge;
NfcCRdispatch(Activity activity) {
Log.v(TAG, "new NfcCRdispatch, activity=" + activity);
this.activity = activity;
}
- public byte[] onNewIntent(Intent intent) {
+ public ArrayList<String> onNewIntent(Intent intent) {
Log.v(TAG, "NFC Intent arrived");
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
if (tag == null) return null;
IsoDep isoTag = IsoDep.get(tag);
try {
int slot = intent.getIntExtra("yubikey_neo_slot", -1);
+ isoTag.connect();
return YkNeo.doChalResp(isoTag, slot, challenge);
+ } catch (TagLostException e) {
+ Log.v(TAG, e.getMessage());
+ Toast.makeText(activity, e.getMessage(),
+ Toast.LENGTH_LONG).show();
+ } catch (IOException e) {
+ Log.v(TAG, e.getMessage());
+ Toast.makeText(activity, e.getMessage(),
+ Toast.LENGTH_LONG).show();
} catch (CRException e) {
Log.v(TAG, e.getMessage());
Toast.makeText(activity, e.getMessage(),
Toast.LENGTH_LONG).show();
- return null;
}
+ return null;
}
- public void onResume(byte[] challenge) {
+ public boolean onResume(ArrayList<String> challenge) {
this.challenge = challenge;
Intent intent = activity.getIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
if (adapter == null) {
Toast.makeText(activity, R.string.no_nfc,
Toast.LENGTH_LONG).show();
- return;
+ return false;
}
if (!adapter.isEnabled()) {
Toast.makeText(activity, R.string.nfc_disabled,
Toast.LENGTH_LONG).show();
- return;
+ return false;
}
adapter.enableForegroundDispatch(activity, tagIntent,
new IntentFilter[] {iso},
new String[][] {techs});
+ return true;
}
public void onPause() {