return early if cannot init adapter
[YkNeoCR.git] / src / org / average / nfcauthcr / QueryCrToken.java
index 8e5c4632a1f2594db141cfc8910657ec875c04a5..f8565c975ee86ab9e96c5fd48e7d388085e9b3cf 100644 (file)
@@ -39,6 +39,14 @@ public class QueryCrToken extends Activity {
                super.onResume();
                Log.v(TAG, "Starting the work");
 
+               setResult(RESULT_CANCELED);
+               int slot = prefs.getInt("slot_number", -1);
+               if (slot != 1 && slot != 2) {
+                       Log.e(TAG, "Slot " + slot + " cannot be used");
+                       Toast.makeText(this, R.string.need_slot,
+                                               Toast.LENGTH_LONG).show();
+                       finish();
+               }
                new AlertDialog.Builder(this)
                        .setTitle(R.string.challenging)
                        .setMessage(R.string.swipe)
@@ -54,11 +62,12 @@ public class QueryCrToken extends Activity {
                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);
+                       if (!dispatch.onResume(challenge)) {
+                               Log.e(TAG, "Failed to enable fg dispatch");
+                               finish();
+                       }
                } else {
                        Log.e(TAG, "Challenge missing in the Intent");
                        finish();