Revert "Merge branch 'master' of ssh://git.average.org/~/NFCAuthCR"
[YkNeoCR.git] / src / org / average / nfcauthcr / Check.java
index c3738f7fc4f80dbe2c799925d522beaa0ea62153..36f3b1d8fe17cdb342a25ae85eb90ea56be7f30a 100644 (file)
@@ -14,6 +14,7 @@ import android.util.Log;
 import android.widget.Toast;
 
 import org.average.nfcauthcr.YkNeo;
+import org.average.nfcauthcr.CRException;
 
 public class Check extends Activity {
 
@@ -61,12 +62,16 @@ public class Check extends Activity {
                Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
                if (tag == null) return;
                IsoDep isoTag = IsoDep.get(tag);
-               byte[] response = YkNeo.doChallengeYubiKey(
+               try {
+                       byte[] response = YkNeo.doChallengeYubiKey(
                                                isoTag, slot, challenge);
-               if (response != null) {
                        Intent data = getIntent();
                        data.putExtra("response", response);
                        setResult(RESULT_OK, data);
+               } catch (CRException e) {
+                       Log.v(TAG, e.getMessage());
+                       Toast.makeText(this, e.getMessage(),
+                                       Toast.LENGTH_LONG).show();
                }
                finish();
        }
@@ -84,6 +89,27 @@ public class Check extends Activity {
                return builder.create();
        }
 
+/*
+<receiver android:name=".IsoDepReceiver"
+          android:label="IsoDepReceiver">
+     <intent-filter>
+         <action android:name="android.nfc.action.TECH_DISCOVERED" />
+     </intent-filter>
+
+     <meta-data android:name="android.nfc.action.TECH_DISCOVERED"
+         android:resource="@xml/filter_nfc"
+     />
+ </receiver>
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+     <!-- capture anything using IsoDep -->
+     <tech-list>
+         <tech>android.nfc.tech.IsoDep</tech>
+     </tech-list>
+ </resources>
+
+*/
+
        private void enableDispatch(int slot) {
                Intent intent = getIntent();
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
@@ -96,13 +122,11 @@ public class Check extends Activity {
                        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},