X-Git-Url: http://www.average.org/gitweb/?p=YkNeoCR.git;a=blobdiff_plain;f=src%2Forg%2Faverage%2Fnfcauthcr%2FEnroll.java;h=12533e7bf8c469fb9bd719696d5215fa898b3826;hp=4ca03a88bc4f9437cd2f837ceb12a820719f462c;hb=9194bb54ed7bfd3ccb2ee93151fb3b1467cdae35;hpb=7382b20863e60aad30b9320f133773b71205f2d7 diff --git a/src/org/average/nfcauthcr/Enroll.java b/src/org/average/nfcauthcr/Enroll.java index 4ca03a8..12533e7 100644 --- a/src/org/average/nfcauthcr/Enroll.java +++ b/src/org/average/nfcauthcr/Enroll.java @@ -5,49 +5,26 @@ import java.util.Random; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; -import android.content.Context; -import android.content.ComponentName; +import android.preference.PreferenceManager; import android.content.Intent; -import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.DialogInterface; -import android.preference.PreferenceManager; import android.util.Log; import android.view.View; import android.widget.TextView; import android.widget.RadioButton; -import org.average.nfcauthcr.Check; -import org.average.nfcauthcr.CheckConnector; +import org.average.nfcauthcr.TagEvent; public class Enroll extends Activity { private final String TAG = getClass().getName(); - private Enroll thisActivity = this; private static boolean waitingForResult = false; private static SharedPreferences prefs; private static int slot; private AlertDialog swipeDialog; - private CheckConnector checkConnector; - private boolean mBound = false; - private byte[] challenge = new byte[63]; - - private ServiceConnection mConnection = new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName className, - IBinder service) { - checkConnector = (CheckConnector) service; - checkConnector.setCaller(activity); - mBound = true; - } - - @Override - public void onServiceDisconnected(ComponentName arg0) { - mBound = false; - } - }; @Override protected void onCreate(Bundle savedInstanceState) @@ -55,8 +32,6 @@ public class Enroll extends Activity { super.onCreate(savedInstanceState); Log.v(TAG, "Starting"); prefs = PreferenceManager.getDefaultSharedPreferences(this); - Intent intent = new Intent(this, Check.class); - bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Override @@ -79,19 +54,13 @@ public class Enroll extends Activity { protected void onPause() { super.onPause(); Log.v(TAG, "Going inactive, try to stop"); - if (!waitingForResult) { - finish(); - } + if (!waitingForResult) { finish(); } } @Override protected void onStop() { super.onStop(); Log.v(TAG, "Stop requested"); - if (mBound) { - unbindService(mConnection); - mBound = false; - } } public void onSlotSelectionClicked(View view) { @@ -110,24 +79,28 @@ public class Enroll extends Activity { public void onEnrollClicked(View view) { Log.v(TAG, "Enroll clicked"); if (slot > 0) { - runEnrollment(); + runEnrollment(slot); } else { showEnrollResult(R.string.need_slot); } } - public void runCallback(int rc, byte[] response) { - Log.v(TAG, "Got response"); + public void onActivityResult(int requestCode, int resultCode, + Intent intent) { + Log.v(TAG, "Got activity result"); waitingForResult = false; if(swipeDialog != null) { swipeDialog.dismiss(); swipeDialog = null; } - if (rc != 0) { - Log.v(TAG, "Error result code " + rc); + + if (resultCode != RESULT_OK) { + Log.v(TAG, "Error result code " + resultCode); return; } + byte[] challenge = intent.getByteArrayExtra("challenge"); Log.v(TAG, "Challenge is \"" + hex(challenge) + "\""); + byte[] response = intent.getByteArrayExtra("response"); Log.v(TAG, "Response is \"" + hex(response) + "\""); Editor editor = prefs.edit(); editor.putString("challenge", hex(challenge)); @@ -152,12 +125,16 @@ public class Enroll extends Activity { dialog.show(); } - private void runEnrollment() { + private void runEnrollment(int slot) { Random rng = new Random(); + byte[] challenge = new byte[63]; rng.nextBytes(challenge); Log.v(TAG, "Random challenge: " + hex(challenge)); + Intent crIntent = new Intent(this, TagEvent.class); + crIntent.putExtra("slot", slot); + crIntent.putExtra("challenge", challenge); + this.startActivityForResult(crIntent, 0); waitingForResult = true; - checkConnector.runEnroll(slot, challenge); if (swipeDialog != null) swipeDialog.dismiss(); swipeDialog = makeDialog(); swipeDialog.show();