From: Nathaniel Wesley Filardo Date: Thu, 3 Jun 2010 03:17:06 +0000 (-0400) Subject: A good bit of refactoring X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=745551650e2933626155f8ec2fd11e147fbffb6e;p=android-vcpass-oisafe A good bit of refactoring 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. --- diff --git a/src/org/openintents/safe/AskPassword.java b/src/org/openintents/safe/AskPassword.java index 0ffb61c..dce5937 100644 --- a/src/org/openintents/safe/AskPassword.java +++ b/src/org/openintents/safe/AskPassword.java @@ -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(); } diff --git a/src/org/openintents/safe/CategoryEdit.java b/src/org/openintents/safe/CategoryEdit.java index f0c6c67..c4ebd52 100644 --- a/src/org/openintents/safe/CategoryEdit.java +++ b/src/org/openintents/safe/CategoryEdit.java @@ -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); - } - } } diff --git a/src/org/openintents/safe/CategoryList.java b/src/org/openintents/safe/CategoryList.java index ce2e665..6cd2000 100644 --- a/src/org/openintents/safe/CategoryList.java +++ b/src/org/openintents/safe/CategoryList.java @@ -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 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 +} diff --git a/src/org/openintents/safe/ChangePass.java b/src/org/openintents/safe/ChangePass.java index 9e0175f..87cb536 100644 --- a/src/org/openintents/safe/ChangePass.java +++ b/src/org/openintents/safe/ChangePass.java @@ -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 index 0000000..4bc6877 --- /dev/null +++ b/src/org/openintents/safe/Constants.java @@ -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"; +} diff --git a/src/org/openintents/safe/CryptoContentProvider.java b/src/org/openintents/safe/CryptoContentProvider.java index 15844a6..993f5ed 100644 --- a/src/org/openintents/safe/CryptoContentProvider.java +++ b/src/org/openintents/safe/CryptoContentProvider.java @@ -149,7 +149,7 @@ public class CryptoContentProvider extends ContentProvider { } if (debug) Log.d(TAG, "Original file path: " + originalFile); - if (CategoryList.isSignedIn()==false) { + if (RuntimeSecrets.isSignedIn()==false) { Intent frontdoor = new Intent(getContext(), Safe.class); frontdoor.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getContext().startActivity(frontdoor); diff --git a/src/org/openintents/safe/DBHelper.java b/src/org/openintents/safe/DBHelper.java index b36b5e8..e98c8cc 100644 --- a/src/org/openintents/safe/DBHelper.java +++ b/src/org/openintents/safe/DBHelper.java @@ -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, diff --git a/src/org/openintents/safe/Help.java b/src/org/openintents/safe/Help.java index 39fe825..ad0e40d 100644 --- a/src/org/openintents/safe/Help.java +++ b/src/org/openintents/safe/Help.java @@ -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 +} diff --git a/src/org/openintents/safe/IntentHandler.java b/src/org/openintents/safe/IntentHandler.java index be3ad92..6082fc4 100644 --- a/src/org/openintents/safe/IntentHandler.java +++ b/src/org/openintents/safe/IntentHandler.java @@ -184,10 +184,8 @@ public class IntentHandler extends Activity { final String action = thisIntent.getAction(); Intent callbackIntent = getIntent(); int callbackResult = RESULT_CANCELED; - PassList.setSalt(salt); - CategoryList.setSalt(salt); - PassList.setMasterKey(masterKey); - CategoryList.setMasterKey(masterKey); + RuntimeSecrets.setSalt(salt); + RuntimeSecrets.setMasterKey(masterKey); if (debug) Log.d(TAG,"actionDispatch()"); if ((salt==null) || (salt=="")) { diff --git a/src/org/openintents/safe/LogOffActivity.java b/src/org/openintents/safe/LogOffActivity.java index 4949f5e..39b3b9e 100644 --- a/src/org/openintents/safe/LogOffActivity.java +++ b/src/org/openintents/safe/LogOffActivity.java @@ -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); diff --git a/src/org/openintents/safe/PassEdit.java b/src/org/openintents/safe/PassEdit.java index 4dfacff..0f81026 100644 --- a/src/org/openintents/safe/PassEdit.java +++ b/src/org/openintents/safe/PassEdit.java @@ -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); - } - } } diff --git a/src/org/openintents/safe/PassGen.java b/src/org/openintents/safe/PassGen.java index 907c34f..7a64b86 100644 --- a/src/org/openintents/safe/PassGen.java +++ b/src/org/openintents/safe/PassGen.java @@ -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); - } - } } diff --git a/src/org/openintents/safe/PassList.java b/src/org/openintents/safe/PassList.java index f28cd5d..0fb3939 100644 --- a/src/org/openintents/safe/PassList.java +++ b/src/org/openintents/safe/PassList.java @@ -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 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); diff --git a/src/org/openintents/safe/PassView.java b/src/org/openintents/safe/PassView.java index 487d8c7..b183de5 100644 --- a/src/org/openintents/safe/PassView.java +++ b/src/org/openintents/safe/PassView.java @@ -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); - } - } } diff --git a/src/org/openintents/safe/Passwords.java b/src/org/openintents/safe/Passwords.java index 0f5292d..f537347 100644 --- a/src/org/openintents/safe/Passwords.java +++ b/src/org/openintents/safe/Passwords.java @@ -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(); diff --git a/src/org/openintents/safe/Preferences.java b/src/org/openintents/safe/Preferences.java index 3035cca..e5b901e 100644 --- a/src/org/openintents/safe/Preferences.java +++ b/src/org/openintents/safe/Preferences.java @@ -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); diff --git a/src/org/openintents/safe/Restore.java b/src/org/openintents/safe/Restore.java index 6e48974..f85d92a 100644 --- a/src/org/openintents/safe/Restore.java +++ b/src/org/openintents/safe/Restore.java @@ -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 index 0000000..f27fed4 --- /dev/null +++ b/src/org/openintents/safe/RuntimeSecrets.java @@ -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; + } +} diff --git a/src/org/openintents/safe/Search.java b/src/org/openintents/safe/Search.java index f0a8543..a6e994e 100644 --- a/src/org/openintents/safe/Search.java +++ b/src/org/openintents/safe/Search.java @@ -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 results=null; private ArrayAdapter 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(); @@ -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(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); - } - } } diff --git a/src/org/openintents/safe/service/ServiceDispatchImpl.java b/src/org/openintents/safe/service/ServiceDispatchImpl.java index 7c6f990..17a27c9 100644 --- a/src/org/openintents/safe/service/ServiceDispatchImpl.java +++ b/src/org/openintents/safe/service/ServiceDispatchImpl.java @@ -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 index 0000000..6375cb8 --- /dev/null +++ b/src/org/openintents/util/FrontDooringActivity.java @@ -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 index 0000000..d544eda --- /dev/null +++ b/src/org/openintents/util/FrontDooringListActivity.java @@ -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); + } +}