]> www.average.org Git - YkNeoCR.git/commitdiff
Revert "Merge branch 'master' of ssh://git.average.org/~/NFCAuthCR"
authorEugene Crosser <crosser@average.org>
Sat, 4 May 2013 06:26:35 +0000 (10:26 +0400)
committerEugene Crosser <crosser@average.org>
Sat, 4 May 2013 06:26:35 +0000 (10:26 +0400)
This reverts commit 7382b20863e60aad30b9320f133773b71205f2d7, reversing
changes made to c58b63e0fc452c2884c49a309b45025efd7fb5a7.

src/org/average/nfcauthcr/Check.java
src/org/average/nfcauthcr/CheckConnector.java [deleted file]
src/org/average/nfcauthcr/Enroll.java

index 27a3d7161acfc7fe444c10564acb6d16ebf9d736..36f3b1d8fe17cdb342a25ae85eb90ea56be7f30a 100644 (file)
@@ -1,68 +1,60 @@
 package org.average.nfcauthcr;
 
 package org.average.nfcauthcr;
 
-import android.app.Service;
+import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.PendingIntent;
 import android.app.PendingIntent;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
 import android.nfc.NfcAdapter;
 import android.nfc.Tag;
 import android.nfc.TagLostException;
 import android.nfc.tech.IsoDep;
 import android.nfc.NfcAdapter;
 import android.nfc.Tag;
 import android.nfc.TagLostException;
 import android.nfc.tech.IsoDep;
-import android.os.Binder;
-import android.os.IBinder;
-import android.preference.PreferenceManager;
 import android.util.Log;
 import android.widget.Toast;
 
 import android.util.Log;
 import android.widget.Toast;
 
-import org.average.nfcauthcr.CheckConnector;
 import org.average.nfcauthcr.YkNeo;
 import org.average.nfcauthcr.CRException;
 
 import org.average.nfcauthcr.YkNeo;
 import org.average.nfcauthcr.CRException;
 
-public class Check extends Service {
+public class Check extends Activity {
 
        private final String TAG = getClass().getName();
 
 
        private final String TAG = getClass().getName();
 
-       private final CheckConnector checkConnector = new CheckConnector();
-       private SharedPreferences prefs;
-       private int startId;
+       private AlertDialog swipeDialog;
        private PendingIntent tagIntent;
 
        @Override
        private PendingIntent tagIntent;
 
        @Override
-       public void onCreate() {
-               Log.v(TAG, "Created");
-               prefs = PreferenceManager.getDefaultSharedPreferences(this);
-       }
+       protected void onResume() {
+               super.onResume();
+               Log.v(TAG, "Starting the work");
 
 
-       @Override
-       public int onStartCommand (Intent intent, int flags, int startId) {
-               Log.v(TAG, "Starting service");
-               this.startId = startId;
-               int slot = prefs.getInt("slot_number", -1);
+               Intent intent = getIntent();
+               setResult(RESULT_CANCELED);
+               if (swipeDialog != null) {
+                       swipeDialog.dismiss();
+                       swipeDialog = null;
+               }
+               int slot = intent.getIntExtra("slot", -1);
                if (slot > 0) {
                if (slot > 0) {
+                       swipeDialog = makeDialog();
+                       swipeDialog.show();
                        enableDispatch(slot);
                        enableDispatch(slot);
-               } else {
-                       stopSelf(startId);
                }
                }
-               return START_NOT_STICKY;
        }
 
        @Override
        }
 
        @Override
-       public IBinder onBind(Intent intent) {
-               Log.v(TAG, "Binding");
-               checkConnector.setService(this);
-               return checkConnector;
-       }
+       protected void onPause() {
+               super.onPause();
+               Log.v(TAG, "Finished the work");
 
 
-       @Override
-       public void onDestroy() {
-               Log.v(TAG, "Finished the run");
+               if(swipeDialog != null) {
+                       swipeDialog.dismiss();
+                       swipeDialog = null;
+               }
                disableDispatch();
        }
 
                disableDispatch();
        }
 
-       @Override
-       protected void onNewIntent(Intent intent) {
+       public void onNewIntent(Intent intent) {
                Log.v(TAG, "NFC Intent arrived");
                int slot = intent.getIntExtra("slot", -1);
                byte[] challenge = intent.getByteArrayExtra("challenge");
                Log.v(TAG, "NFC Intent arrived");
                int slot = intent.getIntExtra("slot", -1);
                byte[] challenge = intent.getByteArrayExtra("challenge");
diff --git a/src/org/average/nfcauthcr/CheckConnector.java b/src/org/average/nfcauthcr/CheckConnector.java
deleted file mode 100644 (file)
index 69f6378..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.average.nfcauthcr;
-
-import android.content.Context;
-import android.os.Binder;
-import android.util.Log;
-
-import org.average.nfcauthcr.Enroll;
-import org.average.nfcauthcr.Check;
-
-public class CheckConnector extends Binder {
-
-       private final String TAG = getClass().getName();
-
-       private Enroll caller;
-       private Check service;
-
-       public void setCaller(Enroll caller) {
-               this.caller = caller;
-       }
-
-       public void setService(Check service) {
-               this.service = service;
-       }
-
-       public void runEnroll(int slot, byte[] challenge) {
-               Log.v(TAG, "runEnroll");
-               service.runEnroll(slot, challenge);
-       }
-
-       public void runCallback(int rc, byte[] response) {
-               Log.v(TAG, "runCallback");
-               caller.runCallback(rc, response);
-       }
-}
index 4ca03a88bc4f9437cd2f837ceb12a820719f462c..190c08ff921c190b65754e5d3b01eb4ae9f5c331 100644 (file)
@@ -5,49 +5,25 @@ import java.util.Random;
 import android.os.Bundle;
 import android.app.Activity;
 import android.app.AlertDialog;
 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.Intent;
-import android.content.ServiceConnection;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
 import android.content.DialogInterface;
 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 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;
 
 public class Enroll extends Activity {
 
        private final String TAG = getClass().getName();
 
 
 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 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)
 
        @Override
        protected void onCreate(Bundle savedInstanceState)
@@ -55,8 +31,6 @@ public class Enroll extends Activity {
                super.onCreate(savedInstanceState);
                Log.v(TAG, "Starting");
                prefs = PreferenceManager.getDefaultSharedPreferences(this);
                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
        }
 
        @Override
@@ -79,19 +53,13 @@ public class Enroll extends Activity {
        protected void onPause() {
                super.onPause();
                Log.v(TAG, "Going inactive, try to stop");
        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");
        }
 
        @Override
        protected void onStop() {
                super.onStop();
                Log.v(TAG, "Stop requested");
-               if (mBound) {
-                       unbindService(mConnection);
-                       mBound = false;
-               }
        }
 
        public void onSlotSelectionClicked(View view) {
        }
 
        public void onSlotSelectionClicked(View view) {
@@ -110,24 +78,24 @@ public class Enroll extends Activity {
        public void onEnrollClicked(View view) {
                Log.v(TAG, "Enroll clicked");
                if (slot > 0) {
        public void onEnrollClicked(View view) {
                Log.v(TAG, "Enroll clicked");
                if (slot > 0) {
-                       runEnrollment();
+                       runEnrollment(slot);
                } else {
                        showEnrollResult(R.string.need_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;
                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;
                }
                        return;
                }
+               byte[] challenge = intent.getByteArrayExtra("challenge");
                Log.v(TAG, "Challenge is \"" + hex(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));
                Log.v(TAG, "Response is  \"" + hex(response) + "\"");
                Editor editor = prefs.edit();
                editor.putString("challenge", hex(challenge));
@@ -152,28 +120,17 @@ public class Enroll extends Activity {
                dialog.show();
        }
 
                dialog.show();
        }
 
-       private void runEnrollment() {
+       private void runEnrollment(int slot) {
                Random rng = new Random();
                Random rng = new Random();
+               byte[] challenge = new byte[63];
                rng.nextBytes(challenge);
                Log.v(TAG, "Random challenge: " + hex(challenge));
                rng.nextBytes(challenge);
                Log.v(TAG, "Random challenge: " + hex(challenge));
+               Log.v(TAG, "Launching challenging activity");
+               Intent crIntent = new Intent(this, Check.class);
+               crIntent.putExtra("slot", slot);
+               crIntent.putExtra("challenge", challenge);
+               this.startActivityForResult(crIntent, 0);
                waitingForResult = true;
                waitingForResult = true;
-               checkConnector.runEnroll(slot, challenge);
-               if (swipeDialog != null) swipeDialog.dismiss();
-               swipeDialog = makeDialog();
-               swipeDialog.show();
-       }
-
-       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) {
-                               Log.v(TAG, "unbind service FIXME");
-                       }
-               });
-               return builder.create();
        }
 
        private String hex(byte[] a) {
        }
 
        private String hex(byte[] a) {