]> hydra-www.ietfng.org Git - android-vcpass-oisafe/commitdiff
A good bit of refactoring
authorNathaniel Wesley Filardo <nwf@pf.priv.oc.ietfng.org>
Thu, 3 Jun 2010 03:17:06 +0000 (23:17 -0400)
committerNathaniel Wesley Filardo <nwf@pf.priv.oc.ietfng.org>
Thu, 3 Jun 2010 03:17:06 +0000 (23:17 -0400)
Eliminate redundant secret store in PassList
Move secret store out of CategoryList to RuntimeSecrets
All Activities are now FrontDooringActivities
    This removes lots of duplicate code from all over
    It was done concurrently with the above changes since
            .isSignedIn() moved.

22 files changed:
src/org/openintents/safe/AskPassword.java
src/org/openintents/safe/CategoryEdit.java
src/org/openintents/safe/CategoryList.java
src/org/openintents/safe/ChangePass.java
src/org/openintents/safe/Constants.java [new file with mode: 0644]
src/org/openintents/safe/CryptoContentProvider.java
src/org/openintents/safe/DBHelper.java
src/org/openintents/safe/Help.java
src/org/openintents/safe/IntentHandler.java
src/org/openintents/safe/LogOffActivity.java
src/org/openintents/safe/PassEdit.java
src/org/openintents/safe/PassGen.java
src/org/openintents/safe/PassList.java
src/org/openintents/safe/PassView.java
src/org/openintents/safe/Passwords.java
src/org/openintents/safe/Preferences.java
src/org/openintents/safe/Restore.java
src/org/openintents/safe/RuntimeSecrets.java [new file with mode: 0644]
src/org/openintents/safe/Search.java
src/org/openintents/safe/service/ServiceDispatchImpl.java
src/org/openintents/util/FrontDooringActivity.java [new file with mode: 0644]
src/org/openintents/util/FrontDooringListActivity.java [new file with mode: 0644]

index 0ffb61c7db8e79d28c97c9786965f8b514bf24fa..dce59375a0eeb19d774bf7e255f0f8918be575ec 100644 (file)
@@ -249,7 +249,7 @@ public class AskPassword extends Activity {
        }
        
        private void checkForBackup() {
-               String filename=CategoryList.BACKUP_FILENAME;
+               String filename=Constants.BACKUP_FILENAME;
                File restoreFile=new File(filename);
                if (!restoreFile.exists()) {
                        return;
@@ -295,11 +295,11 @@ public class AskPassword extends Activity {
                super.onPause();
 
                if (debug) Log.d(TAG, "onResume()");
-               if (CategoryList.isSignedIn()==true) {
+               if (RuntimeSecrets.isSignedIn()) {
                        if (debug) Log.d(TAG,"already signed in");
                        Intent callbackIntent = new Intent();
-                       callbackIntent.putExtra("salt", CategoryList.getSalt());
-                       callbackIntent.putExtra("masterKey", CategoryList.getMasterKey());
+                       callbackIntent.putExtra("salt", RuntimeSecrets.getSalt());
+                       callbackIntent.putExtra("masterKey", RuntimeSecrets.getMasterKey());
                        setResult(RESULT_OK, callbackIntent);
                        finish();
                        return;
@@ -408,10 +408,10 @@ public class AskPassword extends Activity {
        super.onActivityResult(requestCode, resultCode, i);
 
        if ((requestCode== REQUEST_RESTORE) && (resultCode == RESULT_OK)) {
-               Log.d(TAG,"returning masterkey: "+CategoryList.getMasterKey());
+               Log.d(TAG,"returning masterkey: "+RuntimeSecrets.getMasterKey());
                        Intent callbackIntent = new Intent();
-                       callbackIntent.putExtra("salt", CategoryList.getSalt());
-                       callbackIntent.putExtra("masterKey", CategoryList.getMasterKey());
+                       callbackIntent.putExtra("salt", RuntimeSecrets.getSalt());
+                       callbackIntent.putExtra("masterKey", RuntimeSecrets.getMasterKey());
                        setResult(RESULT_OK, callbackIntent);
                finish();
        }
index f0c6c67e8a550f4cf138d01dbe74e8fdf5733e97..c4ebd5297f7df4ca72dbb60ecacf3f89c1787876 100644 (file)
@@ -17,6 +17,7 @@
 package org.openintents.safe;
 
 import org.openintents.intents.CryptoIntents;
+import org.openintents.util.FrontDooringActivity;
 
 import android.app.Activity;
 import android.content.BroadcastReceiver;
@@ -35,7 +36,7 @@ import android.widget.Toast;
  * 
  * @author Randy McEoin
  */
-public class CategoryEdit extends Activity {
+public class CategoryEdit extends FrontDooringActivity {
 
        private static final boolean debug = false;
     private static String TAG = "CategoryEdit";
@@ -44,26 +45,10 @@ public class CategoryEdit extends Activity {
     private Long RowId;
        boolean populated = false;
 
-    Intent frontdoor;
-    private Intent restartTimerIntent=null;
-    
-    BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
-                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
-                startActivity(frontdoor);
-            }
-        }
-    };
-
     public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
                if (debug) Log.d(TAG,"onCreate("+icicle+")");
                
-               frontdoor = new Intent(this, Safe.class);
-               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
-               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
-
                String title = getResources().getString(R.string.app_name) + " - " +
                getResources().getString(R.string.edit_entry);
                setTitle(title);
@@ -116,28 +101,10 @@ public class CategoryEdit extends Activity {
                populated=true;
        }
 
-    @Override
-    protected void onPause() {
-               super.onPause();
-               if (debug) Log.d(TAG, "onPause");
-               
-               try {
-                       unregisterReceiver(mIntentReceiver);
-               } catch (IllegalArgumentException e) {
-                       //if (debug) Log.d(TAG,"IllegalArgumentException");
-               }
-    }
-
     @Override
     protected void onResume() {
                super.onResume();
                if (debug) Log.d(TAG, "onResume");
-               if (!CategoryList.isSignedIn()) {
-                       startActivity(frontdoor);               
-                       return;
-               }
-        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
-        registerReceiver(mIntentReceiver, filter);
 
         Passwords.Initialize(this);
 
@@ -178,17 +145,4 @@ public class CategoryEdit extends Activity {
                }
                populated=true;
     }
-
-    @Override
-       public void onUserInteraction() {
-               super.onUserInteraction();
-
-               if (debug) Log.d(TAG,"onUserInteraction()");
-
-               if (CategoryList.isSignedIn()==false) {
-//                     startActivity(frontdoor);
-               }else{
-                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
-               }
-       }
 }
index ce2e665580e67535d2f959ded9ea271a34f69cf6..6cd20006a26cda98734489f2a752def7bb7bdc70 100644 (file)
@@ -32,10 +32,10 @@ import org.openintents.safe.dialog.DialogHostingActivity;
 import org.openintents.safe.service.ServiceDispatchImpl;
 import org.openintents.util.IntentUtils;
 import org.openintents.util.SecureDelete;
+import org.openintents.util.FrontDooringListActivity;
 
 import android.app.AlertDialog;
 import android.app.Dialog;
-import android.app.ListActivity;
 import android.app.ProgressDialog;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -65,7 +65,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
  * @author Randy McEoin
  * @author Steven Osborn - http://steven.bitsetters.com
  */
-public class CategoryList extends ListActivity {
+public class CategoryList extends FrontDooringListActivity {
 
        private static boolean debug = false;
     private static final String TAG = "CategoryList";
@@ -101,10 +101,6 @@ public class CategoryList extends ListActivity {
     private static final int ABOUT_KEY = IMPORT_PROGRESS_KEY + 2;
 
     public static final int MAX_CATEGORIES = 256;
-
-    private static final String EXPORT_FILENAME = "/sdcard/oisafe.csv";
-    public static final String BACKUP_FILENAME = "/sdcard/oisafe.xml";
-    private static final String PASSWORDSAFE_IMPORT_FILENAME = "/sdcard/passwordsafe.csv";
     
     public static final String KEY_ID = "id";  // Intent keys
 
@@ -116,9 +112,6 @@ public class CategoryList extends ListActivity {
 
        private Thread backupThread=null;
 
-       private static String salt;
-    private static String masterKey;                   
-
     private List<CategoryEntry> rows=null;
     private CategoryListItemAdapter catAdapter=null;
     private Intent restartTimerIntent=null;
@@ -126,20 +119,6 @@ public class CategoryList extends ListActivity {
     
     private boolean lockOnScreenLock=true;
     
-    BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
-                if (debug) Log.d(TAG,"caught ACTION_SCREEN_OFF");
-                if (lockOnScreenLock) {
-                        masterKey=null;
-                }
-            } else if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
-                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
-                lockAndShutFrontDoor();
-            }
-        }
-    };
-
     public Handler myViewUpdateHandler = new Handler(){
        // @Override
        public void handleMessage(Message msg) {
@@ -225,15 +204,6 @@ public class CategoryList extends ListActivity {
 
                if (debug) Log.d(TAG,"onResume()");
 
-               if (isSignedIn()==false) {
-                       Intent frontdoor = new Intent(this, Safe.class);
-                       frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
-                       startActivity(frontdoor);
-                       return;
-       }
-        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
-        registerReceiver(mIntentReceiver, filter);
-
         showFirstTimeWarningDialog();
                if (Passwords.getPrePopulate()==true)
                {
@@ -291,11 +261,6 @@ public class CategoryList extends ListActivity {
                        try { backupThread.join(maxWaitToDie); } 
                        catch(InterruptedException e){} //  ignore 
                }
-               try {
-                       unregisterReceiver(mIntentReceiver);
-               } catch (IllegalArgumentException e) {
-                       //if (debug) Log.d(TAG,"IllegalArgumentException");
-               }
     }
 
     @Override
@@ -305,17 +270,6 @@ public class CategoryList extends ListActivity {
                if (debug) Log.d(TAG,"onStop()");
     }
     
-    @Override
-    public void onDestroy() {
-               super.onDestroy();
-               
-               if (debug) Log.d(TAG,"onDestroy()");
-               try {
-                       unregisterReceiver(mIntentReceiver);
-               } catch (IllegalArgumentException e) {
-                       //if (debug) Log.d(TAG,"IllegalArgumentException");
-               }
-    }
     @Override
     public void onCreateContextMenu(ContextMenu menu, View view,
                ContextMenuInfo menuInfo) {
@@ -353,7 +307,7 @@ public class CategoryList extends ListActivity {
             case BACKUP_PROGRESS_KEY: {
                 ProgressDialog dialog = new ProgressDialog(this);
                 dialog.setMessage(getString(R.string.backup_progress)+
-                               " "+BACKUP_FILENAME);
+                               " "+Constants.BACKUP_FILENAME);
                 dialog.setIndeterminate(false);
                 dialog.setCancelable(false);
                 return dialog;
@@ -364,28 +318,6 @@ public class CategoryList extends ListActivity {
         return null;
     }
 
-    /**
-     * Returns the current status of signedIn. 
-     * 
-     * @return True if signed in
-     */
-    public static boolean isSignedIn() {
-       if ((salt != null) && (masterKey != null)) {
-               return true;
-       }
-       return false;
-    }
-    
-    
-    /**
-     * Sets signedIn status to false.
-     * 
-     * @see org.openintents.safe.CategoryList#isSignedIn
-     */
-    public static void setSignedOut() {
-       if (debug) Log.d(TAG,"setSignedOut()");
-       masterKey=null;
-    }
     /**
      * Populates the category ListView
      */
@@ -466,22 +398,6 @@ public class CategoryList extends ListActivity {
                return super.onCreateOptionsMenu(menu);
     }
 
-    static void setSalt(String saltIn) {
-               salt = saltIn;
-    }
-
-    static String getSalt() {
-               return salt;
-    }
-
-    static void setMasterKey(String key) {
-               masterKey = key;
-    }
-
-    static String getMasterKey() {
-               return masterKey;
-    }
-
     private void addCategoryActivity() {
        if (debug) Log.d(TAG,"addCategoryActivity()");
                Intent i = new Intent(this, CategoryEdit.class);
@@ -603,7 +519,7 @@ public class CategoryList extends ListActivity {
     private String backupDatabase() {
        Backup backup=new Backup(this);
        
-       backup.write(BACKUP_FILENAME);
+       backup.write(Constants.BACKUP_FILENAME);
        return backup.getResult();
     }
 
@@ -612,7 +528,7 @@ public class CategoryList extends ListActivity {
        Intent serviceIntent = new Intent();
                serviceIntent.setClass(this, ServiceDispatchImpl.class );
            stopService(serviceIntent);
-               masterKey=null;
+               RuntimeSecrets.setSignedOut();
            Intent frontdoor = new Intent(this, Safe.class);
                frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
            startActivity(frontdoor);
@@ -644,9 +560,6 @@ public class CategoryList extends ListActivity {
        }
 
     private void restoreDatabase() {
-//     Restore restore=new Restore(myViewUpdateHandler, this);
-       
-//     restore.read(BACKUP_FILENAME, masterKey);
                Intent i = new Intent(this, Restore.class);
            startActivityForResult(i,REQUEST_RESTORE);
     }
@@ -692,7 +605,7 @@ public class CategoryList extends ListActivity {
     
        public boolean exportDatabase(){
                if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
-               String filename=EXPORT_FILENAME;
+               String filename=Constants.EXPORT_FILENAME;
                try {
                        CSVWriter writer = new CSVWriter(new FileWriter(filename), ',');
 
@@ -762,12 +675,12 @@ public class CategoryList extends ListActivity {
                
        public void importDatabase(){
                final String filename;
-               File oiImport=new File(EXPORT_FILENAME);
-               File pwsImport=new File(PASSWORDSAFE_IMPORT_FILENAME);
+               File oiImport=new File(Constants.EXPORT_FILENAME);
+               File pwsImport=new File(Constants.PASSWORDSAFE_IMPORT_FILENAME);
                if (oiImport.exists() || !pwsImport.exists()) {
-                       filename=EXPORT_FILENAME;
+                       filename=Constants.EXPORT_FILENAME;
                }else{
-                       filename=PASSWORDSAFE_IMPORT_FILENAME;
+                       filename=Constants.PASSWORDSAFE_IMPORT_FILENAME;
                }
                File csvFile=new File(filename);
                if (!csvFile.exists()) {
@@ -990,19 +903,4 @@ public class CategoryList extends ListActivity {
                        importMessage=getString(R.string.import_file_error);
                }
        }
-
-       @Override
-       public void onUserInteraction() {
-               super.onUserInteraction();
-
-               if (debug) Log.d(TAG,"onUserInteraction()");
-
-               if (CategoryList.isSignedIn()==false) {
-//                     Intent frontdoor = new Intent(this, FrontDoor.class);
-//                     frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
-//                     startActivity(frontdoor);
-               }else{
-                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
-               }
-       }
-}
\ No newline at end of file
+}
index 9e0175fd312e2662f034da5cc783ee4a58ecd414..87cb53674f413667ae35f209ef99babf2c35c6ef 100644 (file)
@@ -19,6 +19,7 @@ package org.openintents.safe;
 import java.util.List;
 
 import org.openintents.intents.CryptoIntents;
+import org.openintents.util.FrontDooringActivity;
 
 import android.app.Activity;
 import android.app.Dialog;
@@ -42,7 +43,7 @@ import android.widget.Toast;
  * 
  * @author Randy McEoin
  */
-public class ChangePass extends Activity {
+public class ChangePass extends FrontDooringActivity {
 
        private static boolean debug = false;
        private static final String TAG = "ChangePass";
@@ -71,18 +72,6 @@ public class ChangePass extends Activity {
                }
     }; 
 
-    Intent frontdoor;
-    private Intent restartTimerIntent=null;
-
-    BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
-                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
-                startActivity(frontdoor);
-            }
-        }
-    };
-
     /** 
      * Called when the activity is first created. 
      */
@@ -92,10 +81,6 @@ public class ChangePass extends Activity {
 
                if (debug) Log.d(TAG,"onCreate()");
 
-               frontdoor = new Intent(this, Safe.class);
-               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
-               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
-               
                setContentView(R.layout.chg_pass);
                String title = getResources().getString(R.string.app_name) + " - " +
                        getResources().getString(R.string.change_password);
@@ -124,11 +109,6 @@ public class ChangePass extends Activity {
                        try { changePassThread.join(maxWaitToDie); } 
                        catch(InterruptedException e){} //  ignore 
                }
-               try {
-                       unregisterReceiver(mIntentReceiver);
-               } catch (IllegalArgumentException e) {
-                       //if (debug) Log.d(TAG,"IllegalArgumentException");
-               }
     }
 
     @Override
@@ -136,13 +116,6 @@ public class ChangePass extends Activity {
                super.onResume();
 
                if (debug) Log.d(TAG,"onResume()");
-
-               if (CategoryList.isSignedIn()==false) {
-                       startActivity(frontdoor);
-                       return;
-               }
-        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
-        registerReceiver(mIntentReceiver, filter);
         
         Passwords.Initialize(this);
     }
@@ -382,8 +355,7 @@ public class ChangePass extends Activity {
 
                dbHelper.commit();
                
-               PassList.setMasterKey(newPass);
-               CategoryList.setMasterKey(newPass);
+               RuntimeSecrets.setMasterKey(newPass);
 
                dbHelper.close();
     }
@@ -418,17 +390,4 @@ public class ChangePass extends Activity {
                }
                return false;
        }
-
-    @Override
-       public void onUserInteraction() {
-               super.onUserInteraction();
-
-               if (debug) Log.d(TAG,"onUserInteraction()");
-
-               if (CategoryList.isSignedIn()==false) {
-//                     startActivity(frontdoor);
-               }else{
-                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
-               }
-       }
 }
diff --git a/src/org/openintents/safe/Constants.java b/src/org/openintents/safe/Constants.java
new file mode 100644 (file)
index 0000000..4bc6877
--- /dev/null
@@ -0,0 +1,9 @@
+/* A new central holding place for some constants that got scattered around */
+
+package org.openintents.safe;
+
+public class Constants {
+    public static final String EXPORT_FILENAME = "/sdcard/oisafe.csv";
+    public static final String BACKUP_FILENAME = "/sdcard/oisafe.xml";
+    public static final String PASSWORDSAFE_IMPORT_FILENAME = "/sdcard/passwordsafe.csv";
+}
index 15844a677ff00aa376426ba5151fa1898434979c..993f5edca9bf58091b5c1dbdedfce8f696c6d3a6 100644 (file)
@@ -149,7 +149,7 @@ public class CryptoContentProvider extends ContentProvider {
                                }\r
                                \r
                                if (debug) Log.d(TAG, "Original file path: " + originalFile);\r
-                                       if (CategoryList.isSignedIn()==false) {\r
+                                       if (RuntimeSecrets.isSignedIn()==false) {\r
                                                Intent frontdoor = new Intent(getContext(), Safe.class);\r
                                                frontdoor.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\r
                                                getContext().startActivity(frontdoor);          \r
index b36b5e8ee87629d14345c1b9b889d2b68089da30..e98c8cc85b32b0d1d31827206716f5ec19f1822a 100644 (file)
@@ -49,7 +49,6 @@ public class DBHelper {
     private static final String TABLE_CIPHER_ACCESS = "cipher_access";
     private static final int DATABASE_VERSION = 4;
     private static String TAG = "DBHelper";
-    Context myCtx;
 
     private static final String DBVERSION_CREATE = 
        "create table " + TABLE_DBVERSION + " ("
@@ -106,17 +105,16 @@ public class DBHelper {
 //     "drop table " + TABLE_CIPHER_ACCESS + ";";
 
     private SQLiteDatabase db;
-    private static boolean needsPrePopulation=false;
-    private static boolean needsUpgrade=false;
+    private boolean needsPrePopulation=false;
+    private boolean needsUpgrade=false;
 
     /**
      * 
      * @param ctx
      */
     public DBHelper(Context ctx) {
-       myCtx = ctx;
                try {
-                       db = myCtx.openOrCreateDatabase(DATABASE_NAME, 0,null);
+                       db = ctx.openOrCreateDatabase(DATABASE_NAME, 0,null);
 
                        // Check for the existence of the DBVERSION table
                        // If it doesn't exist than create the overall data,
index 39fe825c1a2af92dfc17fd01246e776e7cc75296..ad0e40d4f73d5b2b5c0ec81e856cdefc23d5e55e 100644 (file)
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.InputStream;
 
 import org.openintents.intents.CryptoIntents;
+import org.openintents.util.FrontDooringActivity;
 
 import android.app.Activity;
 import android.content.BroadcastReceiver;
@@ -37,7 +38,7 @@ import android.webkit.WebView;
  * 
  * @author Randy McEoin
  */
-public class Help extends Activity {
+public class Help extends FrontDooringActivity {
 
        private static boolean debug = false;
        private static String TAG = "Help";
@@ -45,26 +46,10 @@ public class Help extends Activity {
     // Menu Item order
     public static final int CLOSE_HELP_INDEX = Menu.FIRST;
 
-    Intent frontdoor;
-    private Intent restartTimerIntent=null;
-
-    BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
-                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
-                startActivity(frontdoor);
-            }
-        }
-    };
-    
     @Override
     public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
 
-               frontdoor = new Intent(this, Safe.class);
-               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
-               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
-
                //Setup layout
                setContentView(R.layout.help);
                String title = getResources().getString(R.string.app_name) + " - " +
@@ -104,30 +89,6 @@ public class Help extends Activity {
 
     }
 
-    @Override
-       protected void onPause() {
-               super.onPause();
-               try {
-                       unregisterReceiver(mIntentReceiver);
-               } catch (IllegalArgumentException e) {
-                       //if (debug) Log.d(TAG,"IllegalArgumentException");
-               }
-       }
-
-       @Override
-       protected void onResume() {
-               super.onResume();
-
-               if (debug) Log.d(TAG,"onResume()");
-
-               if (CategoryList.isSignedIn()==false) {
-                       startActivity(frontdoor);
-                       return;
-               }
-        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
-        registerReceiver(mIntentReceiver, filter);
-       }
-
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
                super.onCreateOptionsMenu(menu);
@@ -146,17 +107,4 @@ public class Help extends Activity {
                }
                return super.onOptionsItemSelected(item);
     }
-
-    @Override
-       public void onUserInteraction() {
-               super.onUserInteraction();
-
-               if (debug) Log.d(TAG,"onUserInteraction()");
-
-               if (CategoryList.isSignedIn()==false) {
-//                     startActivity(frontdoor);
-               }else{
-                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
-               }
-       }
-}
\ No newline at end of file
+}
index be3ad92532b3894366a2fddbf26715ccd55b092a..6082fc43bc46cb7f34691076d341be6f37926e32 100644 (file)
@@ -184,10 +184,8 @@ public class IntentHandler extends Activity {
         final String action = thisIntent.getAction();\r
        Intent callbackIntent = getIntent(); \r
        int callbackResult = RESULT_CANCELED;\r
-               PassList.setSalt(salt);\r
-        CategoryList.setSalt(salt);\r
-               PassList.setMasterKey(masterKey);\r
-        CategoryList.setMasterKey(masterKey);\r
+        RuntimeSecrets.setSalt(salt);\r
+        RuntimeSecrets.setMasterKey(masterKey);\r
         \r
         if (debug) Log.d(TAG,"actionDispatch()");\r
         if ((salt==null) || (salt=="")) {\r
index 4949f5e8b9c08e3f4131f39cfe8317e57001b250..39b3b9e9c1bacaeecedf2f7dee50a3d0e33657ac 100644 (file)
@@ -33,7 +33,7 @@ public class LogOffActivity extends Activity {
                                        Intent serviceIntent = new Intent();
                                        serviceIntent.setClass(LogOffActivity.this, ServiceDispatchImpl.class );
                                        stopService(serviceIntent);
-                                       CategoryList.setSignedOut();
+                                       RuntimeSecrets.setSignedOut();
                                        
                                        /*
                                        Intent intent = new Intent(LogOffActivity.this, FrontDoor.class);
index 4dfacffb464f21fb01d2bc1889f719017b8fc53c..0f81026fec929bd46bfec93275307f1fe406bd65 100644 (file)
@@ -18,6 +18,7 @@ package org.openintents.safe;
 
 
 import org.openintents.intents.CryptoIntents;
+import org.openintents.util.FrontDooringActivity;
 
 import android.app.Activity;
 import android.app.AlertDialog;
@@ -45,7 +46,7 @@ import android.widget.Toast;
  * @author Steven Osborn - http://steven.bitsetters.com
  * @author Randy McEoin
  */
-public class PassEdit extends Activity {
+public class PassEdit extends FrontDooringActivity {
 
        private static boolean debug = false;
        private static String TAG = "PassEdit";
@@ -71,18 +72,6 @@ public class PassEdit extends Activity {
        public static boolean entryEdited = false;
        boolean populated = false;
 
-       Intent frontdoor;
-    private Intent restartTimerIntent=null;
-
-    BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
-                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
-                startActivity(frontdoor);
-            }
-        }
-    };
-
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
 
@@ -107,10 +96,6 @@ public class PassEdit extends Activity {
                        return;
                }
 
-               frontdoor = new Intent(this, Safe.class);
-               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
-               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
-
                String title = getResources().getString(R.string.app_name) + " - "
                                + getResources().getString(R.string.edit_entry);
                setTitle(title);
@@ -156,8 +141,6 @@ public class PassEdit extends Activity {
                        }
                });
                restoreMe();
-
-               sendBroadcast (restartTimerIntent);
        }
 
        @Override
@@ -191,11 +174,6 @@ public class PassEdit extends Activity {
                if (isFinishing() && discardEntry==false) {
                        savePassword();
                }
-               try {
-                       unregisterReceiver(mIntentReceiver);
-               } catch (IllegalArgumentException e) {
-                       //if (debug) Log.d(TAG,"IllegalArgumentException");
-               }
        }
 
        @Override
@@ -204,16 +182,6 @@ public class PassEdit extends Activity {
 
                if (debug) Log.d(TAG,"onResume()");
 
-               if (CategoryList.isSignedIn()==false) {
-//                     if (Passwords.isCryptoInitialized()) {
-//                             saveState();
-//                     }
-                       startActivity(frontdoor);
-                       return;
-               }
-        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
-        registerReceiver(mIntentReceiver, filter);
-
                Passwords.Initialize(this);
 
                populateFields();
@@ -405,17 +373,4 @@ public class PassEdit extends Activity {
                        }
                }  
        }
-       
-       @Override
-       public void onUserInteraction() {
-               super.onUserInteraction();
-
-               if (debug) Log.d(TAG,"onUserInteraction()");
-
-               if (CategoryList.isSignedIn()==false) {
-//                     startActivity(frontdoor);
-               }else{
-                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
-               }
-       }
 }
index 907c34fe695fe16ef2c1859389451247472a2e17..7a64b865af278fcaa46d73c53f30cbd85ee00d01 100644 (file)
@@ -20,12 +20,9 @@ import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
 
 import org.openintents.intents.CryptoIntents;
+import org.openintents.util.FrontDooringActivity;
 
-import android.app.Activity;
-import android.content.BroadcastReceiver;
 import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
 import android.os.Bundle;
 import android.text.ClipboardManager;
 import android.util.Log;
@@ -46,7 +43,7 @@ import android.view.View.OnFocusChangeListener;
  * 
  * @author Steven Osborn - http://steven.bitsetters.com
  */
-public class PassGen extends Activity {
+public class PassGen extends FrontDooringActivity {
 
        private static boolean debug = false;
        private static String TAG = "PassGen";
@@ -66,18 +63,6 @@ public class PassGen extends Activity {
        Button copy_entry;
        Button cancel;
 
-       Intent frontdoor;
-    private Intent restartTimerIntent=null;
-
-    BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
-                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
-                startActivity(frontdoor);
-            }
-        }
-    };
-
        private final OnClickListener update_click = new OnClickListener() {
                public void onClick(View v) {
                        genPassword();
@@ -128,10 +113,6 @@ public class PassGen extends Activity {
     public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
                
-               frontdoor = new Intent(this, Safe.class);
-               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
-               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
-
                setContentView(R.layout.pass_gen);
                
                String title = getString(R.string.app_name) + " - " +
@@ -211,45 +192,9 @@ public class PassGen extends Activity {
 
     }
 
-    @Override
-    protected void onPause() {
-               super.onPause();
-
-               try {
-                       unregisterReceiver(mIntentReceiver);
-               } catch (IllegalArgumentException e) {
-                       if (debug) Log.d(TAG,"IllegalArgumentException");
-               }
-    }
-
-    @Override
-    protected void onResume() {
-               super.onResume();
-
-               if (CategoryList.isSignedIn()==false) {
-                       startActivity(frontdoor);
-                       return;
-               }
-        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
-        registerReceiver(mIntentReceiver, filter);
-    }
-
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
                super.onCreateOptionsMenu(menu);
                return false;
     }
-
-    @Override
-       public void onUserInteraction() {
-               super.onUserInteraction();
-
-               if (debug) Log.d(TAG,"onUserInteraction()");
-
-               if (CategoryList.isSignedIn()==false) {
-//                     startActivity(frontdoor);
-               }else{
-                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
-               }
-       }
 }
index f28cd5d62a3a40d8b97dd79491a2209646f13c09..0fb3939beee673d273eb080df10a3f07793a3488 100644 (file)
@@ -88,9 +88,6 @@ public class PassList extends ListActivity {
     Intent frontdoor;
     private Intent restartTimerIntent=null;
 
-    private static String salt;
-    private static String masterKey;
-    
        private Thread fillerThread=null;
 
     private List<PassEntry> rows=null;
@@ -205,7 +202,7 @@ public class PassList extends ListActivity {
                
                if (debug) Log.d(TAG,"onResume()");
 
-               if (CategoryList.isSignedIn()==false) {
+               if (RuntimeSecrets.isSignedIn()==false) {
                        startActivity(frontdoor);
                        return;
                }
@@ -354,22 +351,6 @@ public class PassList extends ListActivity {
                return super.onCreateOptionsMenu(menu);
     }
 
-    static void setSalt(String saltIn) {
-               salt = saltIn;
-    }
-
-    static String getSalt() {
-               return salt;
-    }
-
-    static void setMasterKey(String key) {
-               masterKey = key;
-    }
-
-    static String getMasterKey() {
-               return masterKey;
-    }
-
     private void addPassword() {
                Intent i = new Intent(this, PassEdit.class);
                i.putExtra(PassList.KEY_ID, (long)-1);
@@ -517,7 +498,7 @@ public class PassList extends ListActivity {
 
                if (debug) Log.d(TAG,"onUserInteraction()");
 
-               if (CategoryList.isSignedIn()==false) {
+               if (RuntimeSecrets.isSignedIn()==false) {
 //                     startActivity(frontdoor);
                }else{
                        if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
index 487d8c792d39d3aeaaa14662a0565486ddf1c647..b183de581487323ef0a49c1a0b22adf7b2f9e9a4 100644 (file)
@@ -19,12 +19,12 @@ package org.openintents.safe;
 import java.util.ArrayList;
 
 import org.openintents.intents.CryptoIntents;
+import org.openintents.util.FrontDooringActivity;
 
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.content.ActivityNotFoundException;
-import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -48,7 +48,8 @@ import android.widget.Toast;
  * 
  * @author Randy McEoin
  */
-public class PassView extends Activity implements View.OnClickListener {
+public class PassView extends FrontDooringActivity
+                                       implements View.OnClickListener {
 
        private static boolean debug = false;
        private static String TAG = "PassView";
@@ -70,27 +71,11 @@ public class PassView extends Activity implements View.OnClickListener {
        private Long CategoryId;
        public static boolean entryEdited=false;
 
-       Intent frontdoor;
-    private Intent restartTimerIntent=null;
-
-    BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
-                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
-                startActivity(frontdoor);
-            }
-        }
-    };
-
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
 
                if (debug) Log.d(TAG,"onCreate("+icicle+")");
                
-               frontdoor = new Intent(this, Safe.class);
-               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
-               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
-
                String title = getResources().getString(R.string.app_name) + " - "
                                + getResources().getString(R.string.view_entry);
                setTitle(title);
@@ -168,32 +153,12 @@ public class PassView extends Activity implements View.OnClickListener {
                outState.putLong(PassList.KEY_CATEGORY_ID, CategoryId);
        }
 
-       @Override
-       protected void onPause() {
-               super.onPause();
-
-               if (debug) Log.d(TAG,"onResume()");
-
-               try {
-                       unregisterReceiver(mIntentReceiver);
-               } catch (IllegalArgumentException e) {
-                       //if (debug) Log.d(TAG,"IllegalArgumentException");
-               }
-       }
-
        @Override
        protected void onResume() {
                super.onResume();
 
                if (debug) Log.d(TAG,"onResume()");
 
-               if (CategoryList.isSignedIn()==false) {
-                       startActivity(frontdoor);
-                       return;
-               }
-        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
-        registerReceiver(mIntentReceiver, filter);
-
                Passwords.Initialize(this);
 
         populateFields();
@@ -377,17 +342,4 @@ public class PassView extends Activity implements View.OnClickListener {
                ClipboardManager cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                cb.setText(value);
        }
-
-       @Override
-       public void onUserInteraction() {
-               super.onUserInteraction();
-
-               if (debug) Log.d(TAG,"onUserInteraction()");
-
-               if (CategoryList.isSignedIn()==false) {
-//                     startActivity(frontdoor);
-               }else{
-                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
-               }
-       }
 }
index 0f5292dd3d5a5e4e9f4395cc328b1c4c42e775a8..f53734747ddfba41ba09a559f4aed492fca7d4e9 100644 (file)
@@ -62,13 +62,12 @@ public class Passwords {
                if (ch==null) {
                        ch = new CryptoHelper();
                }
-               if ((cryptoInitialized==false) &&
-                               (CategoryList.getSalt()!=null) &&
-                               (CategoryList.getMasterKey()!=null))
+               if ((cryptoInitialized==false) && RuntimeSecrets.isSignedIn())
                {
                        try {
                                Passwords.InitCrypto(CryptoHelper.EncryptionMedium,
-                                               CategoryList.getSalt(), CategoryList.getMasterKey());
+                                               RuntimeSecrets.getSalt(),
+                                               RuntimeSecrets.getMasterKey());
                                cryptoInitialized=true;
                        } catch (Exception e) {
                                e.printStackTrace();
index 3035cca84f0498ba83f7eca23f6cee9837f4e2b0..e5b901e0395341d19430eeac088626936410f484 100644 (file)
@@ -53,7 +53,7 @@ public class Preferences extends PreferenceActivity {
        protected void onResume() {
                super.onResume();
 
-               if (CategoryList.isSignedIn()==false) {
+               if (RuntimeSecrets.isSignedIn()==false) {
                        startActivity(frontdoor);
                        return;
                }
@@ -82,7 +82,7 @@ public class Preferences extends PreferenceActivity {
 
                if (debug) Log.d(TAG,"onUserInteraction()");
 
-               if (CategoryList.isSignedIn()==false) {
+               if (RuntimeSecrets.isSignedIn()==false) {
 //                     startActivity(frontdoor);
                }else{
                        if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
index 6e489747b9e197f3d797201f3613eb9762d0d482..f85d92a5e7493d471a4138eafbaf0a7e7267b9a4 100644 (file)
@@ -20,11 +20,13 @@ import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 
+import org.openintents.intents.CryptoIntents;
+import org.openintents.util.FrontDooringActivity;
+
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
-import org.openintents.intents.CryptoIntents;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
@@ -49,7 +51,7 @@ import android.widget.EditText;
 import android.widget.TextView;
 import android.widget.Toast;
 
-public class Restore extends Activity {
+public class Restore extends FrontDooringActivity {
        
        private static boolean debug = false;
        private static final String TAG = "Restore";
@@ -62,18 +64,6 @@ public class Restore extends Activity {
 
     public static final String KEY_FIRST_TIME = "first_time";  // Intent keys
 
-       Intent frontdoor;
-    private Intent restartTimerIntent=null;
-
-    BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
-                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
-                startActivity(frontdoor);
-            }
-        }
-    };
-
        @Override
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
@@ -86,10 +76,6 @@ public class Restore extends Activity {
                    firstTime = extras != null ? extras.getBoolean(Restore.KEY_FIRST_TIME) : false;
                }
 
-               frontdoor = new Intent(this, Safe.class);
-               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
-               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
-
                Passwords.Initialize(this);
 
                setContentView(R.layout.restore);
@@ -98,7 +84,7 @@ public class Restore extends Activity {
                setTitle(title);
                
                if (filename==null) {
-                       filename=CategoryList.BACKUP_FILENAME;
+                       filename=Constants.BACKUP_FILENAME;
                }
                TextView filenameText;
                filenameText = (TextView) findViewById(R.id.restore_filename);
@@ -137,31 +123,6 @@ public class Restore extends Activity {
                });
     }
 
-       @Override
-       protected void onPause() {
-               super.onPause();
-               
-               try {
-                       unregisterReceiver(mIntentReceiver);
-               } catch (IllegalArgumentException e) {
-                       //if (debug) Log.d(TAG,"IllegalArgumentException");
-               }
-       }
-
-    @Override
-       protected void onResume() {
-               super.onResume();
-               
-               if (debug) Log.d(TAG,"onResume()");
-               
-               if ((!firstTime) && (CategoryList.isSignedIn()==false)) {
-                       startActivity(frontdoor);               
-                       return;
-               }
-        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
-        registerReceiver(mIntentReceiver, filter);
-       }
-
     private boolean backupFileExists(String filename) {
                FileReader fr;
                try {
@@ -320,10 +281,8 @@ public class Restore extends Activity {
 
                dbHelper.storeSalt(restoreDataSet.getSalt());
                dbHelper.storeMasterKey(restoreDataSet.getMasterKeyEncrypted());
-               CategoryList.setSalt(restoreDataSet.getSalt());
-               PassList.setSalt(restoreDataSet.getSalt());
-               CategoryList.setMasterKey(masterKey);
-               PassList.setMasterKey(masterKey);
+               RuntimeSecrets.setSalt(restoreDataSet.getSalt());
+               RuntimeSecrets.setMasterKey(masterKey);
                for (CategoryEntry category : restoreDataSet.getCategories()) {
                        if (debug) Log.d(TAG,"category="+category.name);
                        dbHelper.addCategory(category);
@@ -358,17 +317,4 @@ public class Restore extends Activity {
                setResult(RESULT_OK);
                finish();
        }
-
-       @Override
-       public void onUserInteraction() {
-               super.onUserInteraction();
-
-               if (debug) Log.d(TAG,"onUserInteraction()");
-
-               if (CategoryList.isSignedIn()==false) {
-//                     startActivity(frontdoor);
-               }else{
-                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
-               }
-       }
 }
diff --git a/src/org/openintents/safe/RuntimeSecrets.java b/src/org/openintents/safe/RuntimeSecrets.java
new file mode 100644 (file)
index 0000000..f27fed4
--- /dev/null
@@ -0,0 +1,50 @@
+/* A new central holding place for runtime secrets of the safe */
+
+package org.openintents.safe;
+
+import android.util.Log;
+
+public class RuntimeSecrets {
+
+       private static final boolean debug = false;
+       private static final String TAG = "RuntimeSecrets";
+
+       private static String salt;
+    static void setSalt(String saltIn) {
+               salt = saltIn;
+    }
+    static String getSalt() {
+               return salt;
+    }
+
+    private static String masterKey;                   
+    static void setMasterKey(String key) {
+               masterKey = key;
+    }
+
+    static String getMasterKey() {
+               return masterKey;
+    }
+
+    /**
+     * Returns the current status of signedIn. 
+     * 
+     * @return True if signed in
+     */
+    public static boolean isSignedIn() {
+       if ((salt != null) && (masterKey != null)) {
+               return true;
+       }
+       return false;
+    }
+    
+    /**
+     * Sets signedIn status to false.
+     * 
+     * @see org.openintents.safe.CategoryList#isSignedIn
+     */
+    public static void setSignedOut() {
+       if (debug) Log.d(TAG,"setSignedOut()");
+       masterKey=null;
+    }
+}
index f0a85431431063c2eac578041dfcd2bb45b2bdca..a6e994ee6c2d233d6c6b66607dd37d0f6b0b0166 100644 (file)
@@ -22,11 +22,10 @@ import java.util.Comparator;
 import java.util.List;
 
 import org.openintents.intents.CryptoIntents;
+import org.openintents.util.FrontDooringListActivity;
 
 import android.app.Dialog;
-import android.app.ListActivity;
 import android.app.ProgressDialog;
-import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
@@ -45,7 +44,7 @@ import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.Toast;
 
-public class Search extends ListActivity {
+public class Search extends FrontDooringListActivity {
        
        private static final String TAG = "Search";
        private static boolean debug = false;
@@ -63,9 +62,6 @@ public class Search extends ListActivity {
        private List<PassEntry> results=null;
        private ArrayAdapter<String> entries=null;
        
-       Intent frontdoor;
-    private Intent restartTimerIntent=null;
-       
     public Handler myViewUpdateHandler = new Handler(){
        // @Override
        public void handleMessage(Message msg) {
@@ -82,15 +78,6 @@ public class Search extends ListActivity {
        }
     }; 
 
-    BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
-                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
-                startActivity(frontdoor);
-            }
-        }
-    };
-
        @Override
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
@@ -102,10 +89,6 @@ public class Search extends ListActivity {
                        getResources().getString(R.string.search);
                setTitle(title);
 
-               frontdoor = new Intent(this, Safe.class);
-               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
-               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
-
                etSearchCriteria = (EditText) findViewById(R.id.search_criteria);
                results=new ArrayList<PassEntry>();
 
@@ -160,13 +143,6 @@ public class Search extends ListActivity {
                
                if (debug) Log.d(TAG,"onResume()");
 
-               if (CategoryList.isSignedIn()==false) {
-                       startActivity(frontdoor);
-                       return;
-               }
-        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
-        registerReceiver(mIntentReceiver, filter);
-
         Passwords.Initialize(this);
     }
 
@@ -312,17 +288,4 @@ public class Search extends ListActivity {
                        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                                passDescriptions);
        }
-       
-       @Override
-       public void onUserInteraction() {
-               super.onUserInteraction();
-
-               if (debug) Log.d(TAG,"onUserInteraction()");
-
-               if (CategoryList.isSignedIn()==false) {
-//                     startActivity(frontdoor);
-               }else{
-                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
-               }
-       }
 }
index 7c6f99018de8355a1fb25676c591c8246c7274b4..17a27c964219bf14b37f8f3a521fd17d68f3f493 100644 (file)
@@ -21,9 +21,9 @@ package org.openintents.safe.service;
 // if there are still clients attached.  Should be fixed.
 
 import org.openintents.intents.CryptoIntents;
-import org.openintents.safe.CategoryList;
 import org.openintents.safe.CryptoHelper;
 import org.openintents.safe.CryptoHelperException;
+import org.openintents.safe.RuntimeSecrets;
 
 
 import android.app.Service;
@@ -98,7 +98,7 @@ public class ServiceDispatchImpl extends Service {
          ch = null;
          ServiceNotification.clearNotification(ServiceDispatchImpl.this);
          
-         CategoryList.setSignedOut();
+         RuntimeSecrets.setSignedOut();
          Intent intent = new Intent(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
          sendBroadcast(intent);
     }
diff --git a/src/org/openintents/util/FrontDooringActivity.java b/src/org/openintents/util/FrontDooringActivity.java
new file mode 100644 (file)
index 0000000..6375cb8
--- /dev/null
@@ -0,0 +1,76 @@
+/* Since just about everybody does this dance, we move it out to its own place */
+package org.openintents.util;
+
+import org.openintents.intents.CryptoIntents;
+import org.openintents.safe.RuntimeSecrets;
+import org.openintents.safe.Safe;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.util.Log;
+
+public class FrontDooringActivity extends Activity {
+
+       private static boolean debug = false;           // nonfinal for inheritance
+       private static String TAG = "FrontDooringActivity";             // ditto
+
+       private Intent frontdoor;
+    protected Intent restartTimerIntent=null;
+
+    protected BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
+        public void onReceive(Context context, Intent intent) {
+            if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
+                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
+                startActivity(frontdoor);
+            }
+        }
+    };
+
+    @Override
+    protected void onResume() {
+               super.onResume();
+
+               if (RuntimeSecrets.isSignedIn()==false) {
+                       startActivity(frontdoor);
+                       return;
+               }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
+    }
+
+    @Override
+    protected void onPause() {
+               super.onPause();
+
+               try {
+                       unregisterReceiver(mIntentReceiver);
+               } catch (IllegalArgumentException e) {
+                       if (debug) Log.d(TAG,"IllegalArgumentException");
+               }
+    }
+
+    @Override
+       public void onUserInteraction() {
+               super.onUserInteraction();
+
+               if (debug) Log.d(TAG,"onUserInteraction()");
+
+               if (!RuntimeSecrets.isSignedIn()==false) {
+                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
+               }
+       }
+
+    public void onCreate(Bundle icicle) {
+               super.onCreate(icicle);
+               
+               frontdoor = new Intent(this, Safe.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
+               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
+
+               sendBroadcast (restartTimerIntent);
+       }
+}
diff --git a/src/org/openintents/util/FrontDooringListActivity.java b/src/org/openintents/util/FrontDooringListActivity.java
new file mode 100644 (file)
index 0000000..d544eda
--- /dev/null
@@ -0,0 +1,76 @@
+/* Since just about everybody does this dance, we move it out to its own place */
+package org.openintents.util;
+
+import org.openintents.intents.CryptoIntents;
+import org.openintents.safe.RuntimeSecrets;
+import org.openintents.safe.Safe;
+
+import android.app.ListActivity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.util.Log;
+
+public class FrontDooringListActivity extends ListActivity {
+
+       private static boolean debug = false;           // nonfinal for inheritance
+       private static String TAG = "FrontDooringActivity";             // ditto
+
+       private Intent frontdoor;
+    protected Intent restartTimerIntent=null;
+
+    protected BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
+        public void onReceive(Context context, Intent intent) {
+            if (intent.getAction().equals(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT)) {
+                if (debug) Log.d(TAG,"caught ACTION_CRYPTO_LOGGED_OUT");
+                startActivity(frontdoor);
+            }
+        }
+    };
+
+    @Override
+    protected void onResume() {
+               super.onResume();
+
+               if (RuntimeSecrets.isSignedIn()==false) {
+                       startActivity(frontdoor);
+                       return;
+               }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
+    }
+
+    @Override
+    protected void onPause() {
+               super.onPause();
+
+               try {
+                       unregisterReceiver(mIntentReceiver);
+               } catch (IllegalArgumentException e) {
+                       if (debug) Log.d(TAG,"IllegalArgumentException");
+               }
+    }
+
+    @Override
+       public void onUserInteraction() {
+               super.onUserInteraction();
+
+               if (debug) Log.d(TAG,"onUserInteraction()");
+
+               if (!RuntimeSecrets.isSignedIn()==false) {
+                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
+               }
+       }
+
+    public void onCreate(Bundle icicle) {
+               super.onCreate(icicle);
+               
+               frontdoor = new Intent(this, Safe.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
+               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
+
+               sendBroadcast (restartTimerIntent);
+       }
+}