]> hydra-www.ietfng.org Git - android-vcpass-oisafe/commitdiff
OI Safe: large patch, added Search activty, completely redid autolock,
authorrmceoin <rmceoin@72b678ce-9140-0410-bee8-679b907dd61a>
Sat, 22 Aug 2009 21:54:04 +0000 (21:54 +0000)
committerrmceoin <rmceoin@72b678ce-9140-0410-bee8-679b907dd61a>
Sat, 22 Aug 2009 21:54:04 +0000 (21:54 +0000)
added preference 'Lock on screen lock' with default of true.
autlock is no longer dependent upon CategoryList, which if not
active would cause app to go unlocked.  Instead each and every
activity listens for the broadcast from the service to know to
autolock.  None of the activities finish() upon lock but instead
launch FrontDoor to present user with AskPassword.  Upon unlock
the user is dropped right back where they left off.

Started using Android 1.5 features like onUserInteraction() which allows
the user to do anything with the app and cause a reset of the timer.
OI Safe now requires 1.5 as a result.

git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@2293 72b678ce-9140-0410-bee8-679b907dd61a

20 files changed:
AndroidManifest.xml
res/layout/pass_edit.xml
res/layout/search.xml [new file with mode: 0644]
res/values/strings.xml
res/values/strings_not_for_translation.xml
src/org/openintents/intents/CryptoIntents.java
src/org/openintents/safe/CategoryEdit.java
src/org/openintents/safe/CategoryList.java
src/org/openintents/safe/ChangePass.java
src/org/openintents/safe/FrontDoor.java
src/org/openintents/safe/Help.java
src/org/openintents/safe/IntentHandler.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/Preferences.java
src/org/openintents/safe/Restore.java
src/org/openintents/safe/Search.java [new file with mode: 0644]
src/org/openintents/safe/service/ServiceDispatchImpl.java

index 17d7b90183219000491ae3724fca0689db33d88f..ac4b2de65c929992670607d4a267246830286472 100644 (file)
@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="org.openintents.safe" \r
-    android:versionName="1.1.1" android:versionCode="8">\r
+    android:versionCode="9" android:versionName="1.2.0">\r
     <!-- History:
+    1.2.0 [9]: 2009-08-22
     1.1.1 [8]: 2009-05-30\r
     1.1.0 [6]: 2009-03-17\r
     1.0.0 [4]: 2009-02-02\r
                        android:value="@string/about_email" />\r
                    
         <activity class=".FrontDoor" android:name="FrontDoor" android:label="@string/app_name"\r
-                       android:theme="@android:style/Theme.Translucent.NoTitleBar">
+                       android:theme="@android:style/Theme.Translucent.NoTitleBar" android:launchMode="singleTop">
                <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />\r
             </intent-filter>           
+               <intent-filter>
+                <action android:name="org.openintents.action.A" />
+                       <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>           
         </activity>
         
         <activity class=".IntentHandler" android:name="IntentHandler" android:label="@string/app_name"
-                  android:permission="org.openintents.safe.ACCESS_INTENTS">
+                  android:permission="org.openintents.safe.ACCESS_INTENTS" android:launchMode="singleTop">
             <intent-filter android:label="@string/intent_encrypt">
                 <action android:name="org.openintents.action.ENCRYPT" />
                 <category android:name="android.intent.category.DEFAULT" />
@@ -79,7 +84,8 @@
         <activity class=".PassList" android:name="PassList" android:label="@string/app_name" />
         <activity class=".PassEdit" android:name="PassEdit" android:label="@string/app_name" />
         <activity class=".CategoryList" android:name="CategoryList" android:label="@string/app_name" />
-        <activity class=".AskPassword" android:name="AskPassword" android:label="@string/app_name"/>\r
+        <activity class=".Search" android:name="Search" android:label="@string/app_name" />
+        <activity class=".AskPassword" android:name="AskPassword" android:label="@string/app_name" android:launchMode="singleTop"/>\r
         <activity class=".Help" android:name="Help" android:label="@string/app_name" />
         <activity class=".ChangePass" android:name="ChangePass" android:label="@string/app_name" />
         <activity class=".Restore" android:name="Restore" android:label="@string/app_name" />
index 4dfe43fab5ac4ec06796919794dd7903ed195989..c2aea67801516a8a3c1a3ffe0aee19bb82247967 100644 (file)
                                <EditText android:id="@+id/website"\r
                                    android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"\r
-                                       android:singleLine="true" 
+                                       android:singleLine="true" \r
+                                       android:inputType="textUri"
                                        android:layout_weight="1"/>\r
                                <Button android:id="@+id/go" \r
-                                               android:text="@string/go"\r
-                                               android:layout_width="wrap_content"\r
-                                               android:layout_height="wrap_content"\r
+                                       android:text="@string/go"\r
+                                       android:layout_width="wrap_content"\r
+                                       android:layout_height="wrap_content"\r
                                />
                        </TableRow>\r
                        <TableRow>\r
@@ -74,6 +75,7 @@
                                        android:text="@string/password" />
                                <EditText android:id="@+id/password"\r
                                        android:singleLine="true"\r
+                                       android:inputType="textVisiblePassword"\r
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content" 
                                        android:layout_weight="1"/>
@@ -86,7 +88,8 @@
        <EditText android:id="@+id/note" android:layout_width="fill_parent"
                android:gravity="top" \r
                android:layout_height="wrap_content"
-               android:layout_weight="1"
+               android:layout_weight="1"\r
+               android:inputType="textShortMessage"
                android:scrollbars="vertical" />
        
 </LinearLayout>\r
diff --git a/res/layout/search.xml b/res/layout/search.xml
new file mode 100644 (file)
index 0000000..d9a5f9b
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+* $Id$
+* 
+* Copyright (C) 2009 OpenIntents.org
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent">
+
+       <TableLayout android:layout_width="fill_parent" 
+               android:layout_height="wrap_content">
+               <TableRow>
+                       <EditText android:id="@+id/search_criteria"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:inputType="textFilter"
+                               android:maxLength="50"
+                               android:hint="@string/search_hint" 
+                               android:layout_weight="1"/>
+                       <Button android:id="@+id/go_button" 
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:text="@string/search"/>
+               </TableRow>
+               <TableRow>
+                       <ListView
+                               android:id="@id/android:list"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"/>
+               </TableRow>
+       </TableLayout>
+</LinearLayout>
index 930bdb244d816abd7f0da2a5f4dd0d7cb8d6ec36..7ac871b06c33a5d948b539bce07e39db83f296b0 100644 (file)
        <string name="dialog_summary_first_time_warning">A new random master key has been created. Use menu > backup and store this key in a safe place. Without this key you may lose encrypted data.</string>\r
        <string name="switch_mode">Switch mode</string>\r
        <string name="decrypt_progress">Decrypting...</string>\r
+       <string name="search">Search</string>\r
+       <string name="search_progress">Searching...</string>\r
+       <string name="search_hint">Type search criteria</string>\r
        \r
        \r
        <!-- ***************************\r
@@ -255,6 +258,8 @@ Current version: %s
     <string-array name="pref_entries_lock_timeout">\r
         <item>1 minute</item>\r
         <item>5 minutes</item>\r
+        <item>10 minutes</item>\r
+        <item>15 minutes</item>\r
         <item>30 minutes</item>  \r
     </string-array>\r
 \r
index df7e8b92386321077dec81f89dd3393646964a23..a54dcddf9b6dca106146c0c1f763fe8645ad33e6 100644 (file)
@@ -69,6 +69,8 @@
     <string-array name="pref_entryvalues_lock_timeout">\r
         <item>1</item>\r
         <item>5</item>\r
+        <item>10</item>\r
+        <item>15</item>\r
         <item>30</item>  \r
     </string-array>\r
     \r
index 4b6678becf088603b86d6113c386687afd8b2353..646e0edebd325a03a0e5917eb3f323224baa03cb 100644 (file)
@@ -100,6 +100,14 @@ public class CryptoIntents {
         */\r
        public static final String ACTION_CRYPTO_LOGGED_OUT = "org.openintents.action.CRYPTO_LOGGED_OUT";\r
        \r
+       /**\r
+        * Activity Action: Initiate automatic locking of the safe.\r
+        * This is used internally from any activity to launch the lock screen.\r
+        * \r
+        * <p>Constant Value: "org.openintents.action.AUTOLOCK"</p>\r
+        */\r
+       public static final String ACTION_AUTOLOCK = "org.openintents.action.AUTOLOCK";\r
+\r
        /**\r
         * The text to encrypt or decrypt, or the location for the return result.\r
         * \r
index 1a4c40a51be14b317032924867c07ec4650f7b8e..bed6de75d54a3bac12ad4f9e19617db43fce0ce2 100644 (file)
  */
 package org.openintents.safe;
 
+import org.openintents.intents.CryptoIntents;
+
 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;
 import android.view.View;
@@ -38,10 +43,29 @@ public class CategoryEdit extends Activity {
     private EditText nameText;
     private Long RowId;
 
+    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");
                
+               frontdoor = new Intent(this, FrontDoor.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
+               if (CategoryList.isSignedIn()==false) {
+                       startActivity(frontdoor);
+       }
+               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
+
                String title = getResources().getString(R.string.app_name) + " - " +
                getResources().getString(R.string.edit_entry);
                setTitle(title);
@@ -91,6 +115,12 @@ public class CategoryEdit extends Activity {
     protected void onPause() {
                super.onPause();
                if (debug) Log.d(TAG, "onPause");
+               
+               try {
+                       unregisterReceiver(mIntentReceiver);
+               } catch (IllegalArgumentException e) {
+                       if (debug) Log.d(TAG,"IllegalArgumentException");
+               }
     }
 
     @Override
@@ -100,10 +130,11 @@ public class CategoryEdit extends Activity {
                if (!CategoryList.isSignedIn()) {
                        Intent frontdoor = new Intent(this, FrontDoor.class);
                        startActivity(frontdoor);               
-                       finish();
                        return;
                }
                populateFields();
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
     }
 
     private void saveState() {
@@ -136,4 +167,17 @@ public class CategoryEdit extends Activity {
                    nameText.setText(catEntry.plainName);
                }
     }
+
+    @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 9296b8845adbfb6a9663204f215b6d502d5a47ca..49d6893b3ee12800b9423df21eff832643ba0bab 100644 (file)
@@ -77,13 +77,14 @@ public class CategoryList extends ListActivity {
     public static final int ADD_CATEGORY_INDEX = Menu.FIRST + 3;
     public static final int DEL_CATEGORY_INDEX = Menu.FIRST + 4;
     public static final int HELP_INDEX = Menu.FIRST + 5;
-    public static final int EXPORT_INDEX = Menu.FIRST + 6;
-    public static final int IMPORT_INDEX = Menu.FIRST + 7;
-    public static final int CHANGE_PASS_INDEX = Menu.FIRST + 8;
-    public static final int BACKUP_INDEX = Menu.FIRST + 9;
-    public static final int RESTORE_INDEX = Menu.FIRST + 10;
-    public static final int PREFERENCES_INDEX = Menu.FIRST + 11;
-    public static final int ABOUT_INDEX = Menu.FIRST + 12;
+    public static final int SEARCH_INDEX = Menu.FIRST + 6;
+    public static final int EXPORT_INDEX = Menu.FIRST + 7;
+    public static final int IMPORT_INDEX = Menu.FIRST + 8;
+    public static final int CHANGE_PASS_INDEX = Menu.FIRST + 9;
+    public static final int BACKUP_INDEX = Menu.FIRST + 10;
+    public static final int RESTORE_INDEX = Menu.FIRST + 11;
+    public static final int PREFERENCES_INDEX = Menu.FIRST + 12;
+    public static final int ABOUT_INDEX = Menu.FIRST + 13;
     
     public static final int REQUEST_ONCREATE = 0;
     public static final int REQUEST_EDIT_CATEGORY = 1;
@@ -119,7 +120,7 @@ public class CategoryList extends ListActivity {
     private static String masterKey;                   
 
     private List<CategoryEntry> rows;
-    private Intent restartTimerIntent;
+    private Intent restartTimerIntent=null;
     private int lastPosition=0;
     
     private boolean lockOnScreenLock=true;
@@ -201,8 +202,8 @@ public class CategoryList extends ListActivity {
                
                if (isSignedIn()==false) {
                        Intent frontdoor = new Intent(this, FrontDoor.class);
+                       frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
                        startActivity(frontdoor);               
-                       finish();
                        return;
        }
                
@@ -246,10 +247,12 @@ public class CategoryList extends ListActivity {
 
                if (isSignedIn()==false) {
                        Intent frontdoor = new Intent(this, FrontDoor.class);
-                       startActivity(frontdoor);               
-                       finish();
+                       frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
+                       startActivity(frontdoor);
                        return;
        }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
 
         showFirstTimeWarningDialog();
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
@@ -292,6 +295,11 @@ 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
@@ -299,18 +307,18 @@ public class CategoryList extends ListActivity {
                super.onStop();
 
                if (debug) Log.d(TAG,"onStop()");
-//             dbHelper.close();
     }
     
     @Override
     public void onDestroy() {
                super.onDestroy();
                
-               if (mIntentReceiver!=null) {
+               if (debug) Log.d(TAG,"onDestroy()");
+               try {
                        unregisterReceiver(mIntentReceiver);
-                       mIntentReceiver=null;
+               } catch (IllegalArgumentException e) {
+                       if (debug) Log.d(TAG,"IllegalArgumentException");
                }
-               if (debug) Log.d(TAG,"onDestroy()");
     }
     @Override
     public void onCreateContextMenu(ContextMenu menu, View view,
@@ -429,6 +437,9 @@ public class CategoryList extends ListActivity {
                        .setIcon(android.R.drawable.ic_menu_add)
                        .setShortcut('2', 'a');
 
+               menu.add(0, SEARCH_INDEX, 0, R.string.search)
+               .setIcon(android.R.drawable.ic_menu_search);
+
                menu.add(0, DEL_CATEGORY_INDEX, 0, R.string.password_delete)  
                        .setIcon(android.R.drawable.ic_menu_delete)
                        .setShortcut('3', 'd')
@@ -538,6 +549,10 @@ public class CategoryList extends ListActivity {
                    Intent help = new Intent(this, Help.class);
                    startActivity(help);
                        break;
+               case SEARCH_INDEX:
+                   Intent search = new Intent(this, Search.class);
+                   startActivity(search);
+                       break;
                case EXPORT_INDEX:
                        Dialog exportDialog = new AlertDialog.Builder(CategoryList.this)
                        .setIcon(R.drawable.passicon)
@@ -602,9 +617,8 @@ public class CategoryList extends ListActivity {
            stopService(serviceIntent);
                masterKey=null;
            Intent frontdoor = new Intent(this, FrontDoor.class);
-           frontdoor.setAction(Intent.ACTION_MAIN);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
            startActivity(frontdoor);
-           finish();
     }
     
        /**
@@ -971,4 +985,19 @@ 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 d00faf25570e9cfe267e93a652fcd2422c54cbcb..5d00b09234b49faa1a388d658fbeaf9c8baa19b2 100644 (file)
@@ -18,9 +18,15 @@ package org.openintents.safe;
 
 import java.util.List;
 
+import org.openintents.intents.CryptoIntents;
+
 import android.app.Activity;
 import android.app.Dialog;
 import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
@@ -65,6 +71,18 @@ 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. 
      */
@@ -74,10 +92,12 @@ public class ChangePass extends Activity {
 
                if (debug) Log.d(TAG,"onCreate()");
 
+               frontdoor = new Intent(this, FrontDoor.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
                if (CategoryList.isSignedIn()==false) {
-                       finish();
-                       return;
-               }
+                       startActivity(frontdoor);
+       }
+               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
                
                setContentView(R.layout.chg_pass);
                String title = getResources().getString(R.string.app_name) + " - " +
@@ -107,6 +127,11 @@ 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
@@ -116,9 +141,11 @@ public class ChangePass extends Activity {
                if (debug) Log.d(TAG,"onResume()");
 
                if (CategoryList.isSignedIn()==false) {
-                       finish();
+                       startActivity(frontdoor);
                        return;
-       }
+               }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
     }
     
     @Override
@@ -393,4 +420,16 @@ 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);
+               }
+       }
 }
index 58f69f0a777bdd3a913651d41bc7f1c1359db01c..cf5822a7dde2c118639e1f5fcd67a61bd35be5ac 100644 (file)
  */\r
 package org.openintents.safe;\r
 \r
+import org.openintents.intents.CryptoIntents;\r
+\r
 import android.app.Activity;\r
 import android.content.Intent;\r
 import android.os.Bundle;\r
+import android.util.Log;\r
 \r
 \r
 /**\r
@@ -31,16 +34,29 @@ import android.os.Bundle;
  */\r
 public class FrontDoor extends Activity {\r
 \r
+    private static final String TAG = "FrontDoor";\r
+       private static final boolean debug = false;\r
+\r
+//     public static final String KEY_AUTOLOCK = "autolock";\r
+       \r
        /** Called when the activity is first created. */\r
     @Override\r
     public void onCreate(Bundle icicle) {\r
        super.onCreate(icicle);\r
+       \r
+       if (debug) Log.d(TAG,"onCreate()");\r
        final Intent thisIntent = getIntent();\r
        final String action = thisIntent.getAction();\r
-       if (action == null || action.equals(Intent.ACTION_MAIN)){\r
+       if (action == null || action.equals(Intent.ACTION_MAIN) || action.equals(CryptoIntents.ACTION_AUTOLOCK)){\r
                //TODO: When launched from debugger, action is null. Other such cases?\r
                Intent i = new Intent(getApplicationContext(),\r
                                IntentHandler.class);\r
+//             boolean autoLock = icicle != null ? icicle.getBoolean(FrontDoor.KEY_AUTOLOCK) : false;\r
+                       if (debug) Log.d(TAG,"action="+action);\r
+//                     if (action.equals(CryptoIntents.ACTION_AUTOLOCK)) {\r
+       //                      i.setAction(CryptoIntents.ACTION_AUTOLOCK);\r
+               //      }\r
+                       i.setAction(action);\r
                startActivity(i);\r
        }  // otherwise, do not start intents, those must be protected by permissions\r
        finish();\r
index e3422d8061516dbf3ee8d014f56d5de07caebb9d..c7262f8d52d33cdbdd533c7dc50942fac9790a08 100644 (file)
@@ -18,7 +18,14 @@ package org.openintents.safe;
 
 import java.io.IOException;
 import java.io.InputStream;
+
+import org.openintents.intents.CryptoIntents;
+
 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;
 import android.view.Menu;
@@ -37,15 +44,29 @@ 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, FrontDoor.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
                if (CategoryList.isSignedIn()==false) {
-                       finish();
-                       return;
-               }
+                       startActivity(frontdoor);
+       }
+               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
 
                //Setup layout
                setContentView(R.layout.help);
@@ -86,6 +107,16 @@ 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();
@@ -93,9 +124,11 @@ public class Help extends Activity {
                if (debug) Log.d(TAG,"onResume()");
 
                if (CategoryList.isSignedIn()==false) {
-                       finish();
+                       startActivity(frontdoor);
                        return;
                }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
        }
 
     @Override
@@ -116,4 +149,17 @@ 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 76186b16ffe832aeda8e03f583680748fdc6a07e..f7eb8f658f0c04fda3564c1682fd7d592407e8b5 100644 (file)
@@ -87,7 +87,7 @@ public class IntentHandler extends Activity {
                switch (requestCode) {\r
                case REQUEST_CODE_ASK_PASSWORD:\r
                        if (resultCode == RESULT_OK) {\r
-\r
+                               if (debug) Log.d(TAG,"RESULT_OK");\r
                                if (service == null) {\r
                                        mServiceIntent = data;\r
                                        // setServiceParametersFromExtrasAndDispatchAction() is called in onServiceConnected.\r
@@ -96,7 +96,9 @@ public class IntentHandler extends Activity {
                                \r
                                setServiceParametersFromExtrasAndDispatchAction(data);\r
                                \r
-                       } else { // resultCode == RESULT_CANCELED\r
+                       } else { // resultCode == RESULT_CANCELED, which means the user hit Back at AskPassword\r
+                               if (debug) Log.d(TAG,"RESULT_CANCELED");\r
+                               moveTaskToBack(true);\r
                                setResult(RESULT_CANCELED);\r
                                finish();\r
                        }\r
@@ -208,6 +210,9 @@ public class IntentHandler extends Activity {
                Intent i = new Intent(getApplicationContext(),\r
                                CategoryList.class);\r
                startActivity(i);\r
+        } else if (action.equals(CryptoIntents.ACTION_AUTOLOCK)) {\r
+               if (debug) Log.d(TAG,"autolock");\r
+               finish();\r
         } else if (externalAccess){\r
 \r
                // which action?\r
@@ -525,6 +530,11 @@ public class IntentHandler extends Activity {
                                                final Intent thisIntent = getIntent();\r
                                                String inputBody = thisIntent.getStringExtra (CryptoIntents.EXTRA_TEXT);\r
        \r
+                                               String action=thisIntent.getAction();\r
+                                               if (action!=null && action.equals(CryptoIntents.ACTION_AUTOLOCK)) {\r
+                                                       if (debug) Log.d(TAG,"autolock");\r
+                                                       askPassIsLocal=true;\r
+                                               }\r
                                                askPass.putExtra (CryptoIntents.EXTRA_TEXT, inputBody);\r
                                                askPass.putExtra (AskPassword.EXTRA_IS_LOCAL, askPassIsLocal);\r
                                                //TODO: Is there a way to make sure all the extras are set?     \r
index b1f7f95039f15dcd6eb21b828f8c242d0b6afec5..7bbdf767589ad56f2d7e8e3a7eb2dac72ff598bd 100644 (file)
@@ -27,6 +27,7 @@ import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.net.Uri;
 import android.os.Bundle;
 import android.text.ClipboardManager;
@@ -58,25 +59,25 @@ public class PassEdit extends Activity {
 
        public static final int RESULT_DELETED = RESULT_FIRST_USER;
 
-    private Intent restartTimerIntent;
-
        private EditText descriptionText;
        private EditText passwordText;
        private EditText usernameText;
        private EditText websiteText;
        private EditText noteText;
        private Long RowId;
+       private Long CategoryId;
        private boolean pass_gen_ret = false;
        private boolean discardEntry = false;
        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");
-                frontdoor.setAction(Intent.ACTION_MAIN);
                 startActivity(frontdoor);
             }
         }
@@ -88,11 +89,9 @@ public class PassEdit extends Activity {
                if (debug) Log.d(TAG,"onCreate()");
                
                frontdoor = new Intent(this, FrontDoor.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
                if (CategoryList.isSignedIn()==false) {
                        startActivity(frontdoor);
-                       // normally we'd do a finish() here, but
-                       // by starting frontdoor from here the user could
-                       // potentially find this activity and continue editing
        }
                restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
 
@@ -116,6 +115,13 @@ public class PassEdit extends Activity {
                        Bundle extras = getIntent().getExtras();
                        RowId = extras != null ? extras.getLong(PassList.KEY_ID) : null;
                }
+               CategoryId = icicle != null ? icicle.getLong(PassList.KEY_CATEGORY_ID) : null;
+               if (CategoryId == null) {
+                       Bundle extras = getIntent().getExtras();
+                       CategoryId = extras != null ? extras.getLong(PassList.KEY_CATEGORY_ID) : null;
+               }
+               if (debug) Log.d(TAG,"RowId="+RowId);
+               if (debug) Log.d(TAG,"CategoryId="+CategoryId);
 
                entryEdited = false;
 
@@ -160,6 +166,7 @@ public class PassEdit extends Activity {
                } else {
                        outState.putLong(PassList.KEY_ID, -1);
                }
+               outState.putLong(PassList.KEY_CATEGORY_ID, CategoryId);
        }
 
        @Override
@@ -168,6 +175,11 @@ public class PassEdit extends Activity {
                if (isFinishing() && discardEntry==false) {
                        savePassword();
                }
+               try {
+                       unregisterReceiver(mIntentReceiver);
+               } catch (IllegalArgumentException e) {
+                       if (debug) Log.d(TAG,"IllegalArgumentException");
+               }
        }
 
        @Override
@@ -178,16 +190,19 @@ public class PassEdit extends Activity {
 
                if (CategoryList.isSignedIn()==false) {
                        saveState();
-                       finish();
+                       startActivity(frontdoor);
                        return;
                }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
+
                populateFields();
        }
 
        private void saveState() {
                PassEntry entry = new PassEntry();
 
-               entry.category = PassList.getCategoryId();
+               entry.category = CategoryId;
                entry.plainDescription = descriptionText.getText().toString();
                entry.plainWebsite = websiteText.getText().toString();
                entry.plainUsername = usernameText.getText().toString();
@@ -338,11 +353,13 @@ public class PassEdit extends Activity {
                }
                if ((RowId != null) && (RowId != -1)) {
                        PassEntry passEntry = Passwords.getPassEntry(RowId, true, false);
-                       descriptionText.setText(passEntry.plainDescription);
-                       websiteText.setText(passEntry.plainWebsite);
-                       usernameText.setText(passEntry.plainUsername);
-                       passwordText.setText(passEntry.plainPassword);
-                       noteText.setText(passEntry.plainNote);
+                       if (passEntry!=null) {
+                               descriptionText.setText(passEntry.plainDescription);
+                               websiteText.setText(passEntry.plainWebsite);
+                               usernameText.setText(passEntry.plainUsername);
+                               passwordText.setText(passEntry.plainPassword);
+                               noteText.setText(passEntry.plainNote);
+                       }
                }
                populated=true;
        }
@@ -368,4 +385,17 @@ 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 071a8e95c6937533d735ea778a170b5a309c1bf3..70b8eb7e03a677e5ec3717d23fc53efdb1c58901 100644 (file)
@@ -19,9 +19,16 @@ package org.openintents.safe;
 import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
 
+import org.openintents.intents.CryptoIntents;
+
 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;
 import android.view.KeyEvent;
 import android.view.Menu;
 import android.view.View;
@@ -40,7 +47,10 @@ import android.view.View.OnFocusChangeListener;
  * @author Steven Osborn - http://steven.bitsetters.com
  */
 public class PassGen extends Activity {
-       
+
+       private static boolean debug = false;
+       private static String TAG = "PassGen";
+
        public static final int CHANGE_ENTRY_RESULT = 2;
        public static final String NEW_PASS_KEY="new_pass";
        
@@ -56,6 +66,18 @@ 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();
@@ -106,10 +128,12 @@ public class PassGen extends Activity {
     public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
                
+               frontdoor = new Intent(this, FrontDoor.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
                if (CategoryList.isSignedIn()==false) {
-                       finish();
-                       return;
-               }
+                       startActivity(frontdoor);
+       }
+               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
 
                setContentView(R.layout.pass_gen);
                
@@ -192,6 +216,12 @@ public class PassGen extends Activity {
     @Override
     protected void onPause() {
                super.onPause();
+
+               try {
+                       unregisterReceiver(mIntentReceiver);
+               } catch (IllegalArgumentException e) {
+                       if (debug) Log.d(TAG,"IllegalArgumentException");
+               }
     }
 
     @Override
@@ -199,9 +229,11 @@ public class PassGen extends Activity {
                super.onResume();
 
                if (CategoryList.isSignedIn()==false) {
-                       finish();
+                       startActivity(frontdoor);
                        return;
                }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
     }
 
     @Override
@@ -210,4 +242,16 @@ public class PassGen 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);
+               }
+       }
 }
index 5f2cb90b31a21d7a4f5c7ca90385d6e385d37f95..73093c3663c71f8ac7489612de4e294532f0f977 100644 (file)
@@ -29,8 +29,11 @@ import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.ListActivity;
 import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
@@ -79,8 +82,10 @@ public class PassList extends ListActivity {
     public static final String KEY_ID = "id";  // Intent keys
     public static final String KEY_CATEGORY_ID = "categoryId";  // Intent keys
 
-    private static Long CategoryId=null;
-    private Intent restartTimerIntent;
+    private Long CategoryId=null;
+
+    Intent frontdoor;
+    private Intent restartTimerIntent=null;
 
     private static String salt;
     private static String masterKey;
@@ -112,6 +117,15 @@ public class PassList 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);
+            }
+        }
+    };
+
     /** 
      * Called when the activity is first created. 
      */
@@ -120,8 +134,10 @@ public class PassList extends ListActivity {
                super.onCreate(icicle);
                
                if (debug) Log.d(TAG,"onCreate()");
+               
+               frontdoor = new Intent(this, FrontDoor.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
                if (CategoryList.isSignedIn()==false) {
-                       finish();
                        return;
        }
                restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
@@ -177,6 +193,11 @@ public class PassList extends ListActivity {
                        try { fillerThread.join(maxWaitToDie); } 
                        catch(InterruptedException e){} //  ignore 
                }
+               try {
+                       unregisterReceiver(mIntentReceiver);
+               } catch (IllegalArgumentException e) {
+                       if (debug) Log.d(TAG,"IllegalArgumentException");
+               }
     }
 
     @Override
@@ -186,9 +207,11 @@ public class PassList extends ListActivity {
                if (debug) Log.d(TAG,"onResume()");
 
                if (CategoryList.isSignedIn()==false) {
-                       finish();
+                       startActivity(frontdoor);
                        return;
                }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
     }
     
     @Override
@@ -320,12 +343,10 @@ public class PassList extends ListActivity {
                return masterKey;
     }
 
-    static long getCategoryId() {
-       return CategoryId;
-    }
-
     private void addPassword() {
                Intent i = new Intent(this, PassEdit.class);
+               i.putExtra(PassList.KEY_ID, (long)-1);
+               i.putExtra(PassList.KEY_CATEGORY_ID, CategoryId);
            startActivityForResult(i,REQUEST_ADD_PASSWORD);
     }
        /**
@@ -462,4 +483,17 @@ public class PassList extends ListActivity {
                fillData();
        }
     }
+
+    @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 77c8a258687f751950c10addc169aa06bb3e9cac..7270ea62bd63bfe219eda6319992284e3557b780 100644 (file)
@@ -18,12 +18,17 @@ package org.openintents.safe;
 
 import java.util.ArrayList;
 
+import org.openintents.intents.CryptoIntents;
+
 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;
+import android.content.IntentFilter;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
@@ -34,6 +39,8 @@ import android.util.Log;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
 import android.widget.Button;
 import android.widget.TextView;
 import android.widget.Toast;
@@ -65,14 +72,29 @@ public class PassView extends Activity {
        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()");
+               
+               frontdoor = new Intent(this, FrontDoor.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
                if (CategoryList.isSignedIn()==false) {
-                       finish();
-                       return;
+                       startActivity(frontdoor);
        }
+               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
 
                String title = getResources().getString(R.string.app_name) + " - "
                                + getResources().getString(R.string.view_entry);
@@ -151,6 +173,20 @@ public class PassView extends Activity {
        @Override
        protected void onPause() {
                super.onPause();
+
+               if (debug) Log.d(TAG,"onResume()");
+
+               try {
+                       unregisterReceiver(mIntentReceiver);
+               } catch (IllegalArgumentException e) {
+                       if (debug) Log.d(TAG,"IllegalArgumentException");
+               }
+               // hide the window from view
+               Window w=getWindow();
+               WindowManager.LayoutParams attrs=w.getAttributes();
+               attrs.alpha=0;
+               w.setAttributes(attrs);
+//             w.setLayout(0, 0);
        }
 
        @Override
@@ -160,9 +196,17 @@ public class PassView extends Activity {
                if (debug) Log.d(TAG,"onResume()");
 
                if (CategoryList.isSignedIn()==false) {
-                       finish();
+                       startActivity(frontdoor);
                        return;
                }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
+        // show the window
+               Window w=getWindow();
+               WindowManager.LayoutParams attrs=w.getAttributes();
+               attrs.alpha=1;
+               w.setAttributes(attrs);
+//             w.setLayout(getWallpaperDesiredMinimumWidth(), getWallpaperDesiredMinimumWidth());
        }
 
        @Override
@@ -270,6 +314,10 @@ public class PassView extends Activity {
                if (debug) Log.d(TAG,"populateFields()");
                if (RowId != null) {
                        PassEntry row = Passwords.getPassEntry(RowId, true, false);
+                       if (row==null) {
+                               if (debug) Log.d(TAG,"populateFields: row=null");
+                               return;
+                       }
                ArrayList<String> packageAccess = Passwords.getPackageAccess(RowId);
                        descriptionText.setText(row.plainDescription);
                        websiteText.setText(row.plainWebsite);
@@ -308,4 +356,17 @@ public class PassView 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 900431209c7afaa3c09fc5c29508314234509ddb..3fddb5f6e61be2fd1c5ab7b73d5ce611568a0b1b 100644 (file)
@@ -1,12 +1,22 @@
 package org.openintents.safe;
 
+import org.openintents.intents.CryptoIntents;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceManager;
+import android.util.Log;
 
 public class Preferences extends PreferenceActivity {
 
+       private static boolean debug = false;
+       private static String TAG = "Preferences";
+
        public static final String PREFERENCE_ALLOW_EXTERNAL_ACCESS = "external_access";
        public static final String PREFERENCE_LOCK_TIMEOUT = "lock_timeout";
        public static final String PREFERENCE_LOCK_TIMEOUT_DEFAULT_VALUE = "5";
@@ -14,15 +24,29 @@ public class Preferences extends PreferenceActivity {
        public static final String PREFERENCE_FIRST_TIME_WARNING = "first_time_warning";
        public static final String PREFERENCE_KEYPAD = "keypad";
        public static final String PREFERENCE_KEYPAD_MUTE = "keypad_mute";
-       
+
+       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
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         
+               frontdoor = new Intent(this, FrontDoor.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
                if (CategoryList.isSignedIn()==false) {
-                       finish();
-                       return;
-               }
+                       startActivity(frontdoor);
+       }
+               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
 
         // Load the preferences from an XML resource
         addPreferencesFromResource(R.xml.preferences);
@@ -33,9 +57,11 @@ public class Preferences extends PreferenceActivity {
                super.onResume();
 
                if (CategoryList.isSignedIn()==false) {
-                       finish();
+                       startActivity(frontdoor);
                        return;
                }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
        }
 
        @Override
@@ -45,6 +71,24 @@ public class Preferences extends PreferenceActivity {
                SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
                boolean lockOnScreenLock = mPreferences.getBoolean(Preferences.PREFERENCE_LOCK_ON_SCREEN_LOCK, true);
                IntentHandler.setLockOnScreenLock(lockOnScreenLock);
+               
+               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 (CategoryList.isSignedIn()==false) {
+                       startActivity(frontdoor);
+               }else{
+                       if (restartTimerIntent!=null) sendBroadcast (restartTimerIntent);
+               }
+       }
 }
index 453ac5f722c61ce7620cd098f55845af00e3ce6b..a3caf9a172a719eab9dad66a18e1f42553d27691 100644 (file)
@@ -24,6 +24,7 @@ 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;
@@ -31,8 +32,11 @@ import org.xml.sax.XMLReader;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Dialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
@@ -58,6 +62,18 @@ 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);
@@ -70,12 +86,13 @@ public class Restore extends Activity {
                    firstTime = extras != null ? extras.getBoolean(Restore.KEY_FIRST_TIME) : false;
                }
 
+               frontdoor = new Intent(this, FrontDoor.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
                if ((!firstTime) && (CategoryList.isSignedIn()==false)) {
-                       Intent frontdoor = new Intent(this, FrontDoor.class);
                        startActivity(frontdoor);               
-                       finish();
                        return;
                }
+               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
 
                setContentView(R.layout.restore);
                String title = getResources().getString(R.string.app_name) + " - " +
@@ -122,6 +139,17 @@ 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();
@@ -129,11 +157,11 @@ public class Restore extends Activity {
                if (debug) Log.d(TAG,"onResume()");
                
                if ((!firstTime) && (CategoryList.isSignedIn()==false)) {
-                       Intent frontdoor = new Intent(this, FrontDoor.class);
                        startActivity(frontdoor);               
-                       finish();
                        return;
                }
+        IntentFilter filter = new IntentFilter(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
+        registerReceiver(mIntentReceiver, filter);
        }
 
     private boolean backupFileExists(String filename) {
@@ -332,4 +360,17 @@ 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/Search.java b/src/org/openintents/safe/Search.java
new file mode 100644 (file)
index 0000000..9011870
--- /dev/null
@@ -0,0 +1,289 @@
+/* $Id$
+ * 
+ * Copyright (C) 2009 OpenIntents.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openintents.safe;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openintents.intents.CryptoIntents;
+
+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;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ListView;
+
+public class Search extends ListActivity {
+       
+       private static final String TAG = "Search";
+       private static boolean debug = false;
+
+       public static final int REQUEST_VIEW_PASSWORD = 1;
+
+       private static final int SEARCH_PROGRESS_KEY = 0;
+
+       private static final int MSG_SEARCH_COMPLETE = 0;
+
+       private Thread searchThread=null;
+
+       private EditText etSearchCriteria;
+       private String searchCriteria="";
+       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) {
+               switch (msg.what) {
+               case MSG_SEARCH_COMPLETE:
+                       setListAdapter(entries);
+                       break;
+               }
+               super.handleMessage(msg);
+       }
+    }; 
+
+    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);
+
+               if (debug) Log.d(TAG,"onCreate()");
+
+               setContentView(R.layout.search);
+               String title = getResources().getString(R.string.app_name) + " - " +
+                       getResources().getString(R.string.search);
+               setTitle(title);
+
+               frontdoor = new Intent(this, FrontDoor.class);
+               frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
+               if (CategoryList.isSignedIn()==false) {
+                       startActivity(frontdoor);
+       }
+               restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER);
+
+               etSearchCriteria = (EditText) findViewById(R.id.search_criteria);
+               results=new ArrayList<PassEntry>();
+
+               Button goButton = (Button) findViewById(R.id.go_button);
+               goButton.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               searchCriteria = etSearchCriteria.getText().toString().trim().toLowerCase();
+                               searchThreadStart();
+                       }
+               });
+               
+               restoreMe();
+    }
+
+       @Override
+       protected void onPause() {
+               super.onPause();
+
+               if (debug) Log.d(TAG,"onPause()");
+               
+               if ((searchThread != null) && (searchThread.isAlive())) {
+                       if (debug) Log.d(TAG,"wait for search thread");
+                       int maxWaitToDie=500000;
+                       try { searchThread.join(maxWaitToDie); } 
+                       catch(InterruptedException e){} //  ignore 
+               }
+               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);
+                
+    }
+
+       protected void onListItemClick(ListView l, View v, int position, long id) {
+               super.onListItemClick(l, v, position, id);
+
+               if (debug) Log.d(TAG,"onListItemClick: position="+position);
+               if ((results==null) || (results.size()==0)) {
+                       return;
+               }
+               Intent passView = new Intent(this, PassView.class);
+               passView.putExtra(PassList.KEY_ID, results.get(position).id);
+               if (debug) Log.d(TAG,"onListItemClick: category="+results.get(position).category);
+               passView.putExtra(PassList.KEY_CATEGORY_ID, results.get(position).category);
+               startActivityForResult(passView,REQUEST_VIEW_PASSWORD);
+       }
+
+       @Override
+       protected void onActivityResult(int requestCode, int resultCode, Intent i) {
+               super.onActivityResult(requestCode, resultCode, i);
+               
+               if (((requestCode==REQUEST_VIEW_PASSWORD)&&(PassView.entryEdited)) ||
+                       (resultCode==RESULT_OK)) {
+                       searchThreadStart();
+               }
+       }
+
+       @Override
+       protected Dialog onCreateDialog(int id) {
+               switch (id) {
+               case SEARCH_PROGRESS_KEY: {
+                       ProgressDialog dialog = new ProgressDialog(this);
+                       dialog.setMessage(getString(R.string.search_progress));
+                       dialog.setIndeterminate(false);
+                       dialog.setCancelable(false);
+                       return dialog;
+               }
+               }
+               return null;
+       }
+
+       /**
+        * Start a separate thread to search the database.   By running
+        * the search in a thread it allows the main UI thread to return
+        * and permit the updating of the progress dialog.
+        */
+       private void searchThreadStart(){
+               showDialog(SEARCH_PROGRESS_KEY);
+               searchThread = new Thread(new Runnable() {
+                       public void run() {
+                               doSearch();
+                               dismissDialog(SEARCH_PROGRESS_KEY);
+                               sendBroadcast (restartTimerIntent);
+
+                               Message m = new Message();
+                               m.what = MSG_SEARCH_COMPLETE;
+                               Search.this.myViewUpdateHandler.sendMessage(m); 
+
+                               if (debug) Log.d(TAG,"thread end");
+                               }
+                       });
+               searchThread.start();
+       }
+
+       private void doSearch() {
+               if (debug) Log.d(TAG,"doSearch: searchCriteria="+searchCriteria);
+               results.clear();
+               if (searchCriteria.length()==0) {
+                       // don't bother searching for nothing
+                       return;
+               }
+
+               
+               List<CategoryEntry> categories=Passwords.getCategoryEntries();
+               for (CategoryEntry catRow : categories) {
+                       if (debug) Log.d(TAG,"doSearch: category="+catRow.plainName);
+                       List<PassEntry> passwords=Passwords.getPassEntries(catRow.id, true, false);
+                       for (PassEntry passRow : passwords) {
+                       if (searchThread.isInterrupted()) {
+                               return;
+                       }
+
+                               String description=passRow.plainDescription.toLowerCase();
+                               String website=passRow.plainWebsite.toLowerCase();
+                               String username=passRow.plainUsername.toLowerCase();
+                               String password=passRow.plainPassword.toLowerCase();
+                               String note=passRow.plainNote.toLowerCase();
+                               if (description.contains(searchCriteria) ||
+                                               website.contains(searchCriteria) ||
+                                               username.contains(searchCriteria) ||
+                                               password.contains(searchCriteria) ||
+                                               note.contains(searchCriteria)) {
+                                       if (debug) Log.d(TAG,"matches: "+passRow.plainDescription);
+                                       results.add(passRow);
+                                       continue;
+                               }
+                       }
+               }
+
+               updateListFromResults();
+       }
+
+       @Override  
+       public Object onRetainNonConfigurationInstance() {  
+               return(results);  
+       }  
+
+       @SuppressWarnings("unchecked")
+       private void restoreMe() {  
+               if (getLastNonConfigurationInstance()!=null) {  
+                       results=(List<PassEntry>)getLastNonConfigurationInstance();
+                       updateListFromResults();
+                       setListAdapter(entries);
+               }  
+       }
+       
+       private void updateListFromResults() {
+               if ((results==null) || (results.size()==0)) {
+                       return;
+               }
+
+               List<String> passDescriptions=new ArrayList<String>();
+
+               for (PassEntry passRow : results) {
+                       passDescriptions.add(passRow.plainDescription);
+               }
+               entries = 
+                       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 56065e7835b558b91c8cb87f8b386d619e61cff6..4bfa123342311290657dabb1a2e90a699f4e3410 100644 (file)
@@ -36,7 +36,7 @@ import android.util.Log;
 import android.os.CountDownTimer;
 
 public class ServiceDispatchImpl extends Service {
-       private static boolean debug = false;
+       private static boolean debug = true;
        private static String TAG = "ServiceDispatchIMPL";
        public static CryptoHelper ch;  // TODO Peli: Could clean this up by moving it into a singleton? Or at least a separate static class?
        private String salt;
@@ -83,21 +83,22 @@ public class ServiceDispatchImpl extends Service {
     @Override
     public void onDestroy() {
          super.onDestroy();
+
+         if (debug) Log.d( TAG,"onDestroy" );
          masterKey = null;
          ch = null;
          unregisterReceiver(mIntentReceiver);
          ServiceNotification.clearNotification(ServiceDispatchImpl.this);
          
+         CategoryList.setSignedOut();
          Intent intent = new Intent(CryptoIntents.ACTION_CRYPTO_LOGGED_OUT);
          sendBroadcast(intent);
-         CategoryList.setSignedOut();
          
-         if (debug) Log.d( TAG,"onDestroy" );
     }
     
     private void startTimer () {
                if (debug) Log.d(TAG,"startTimer with timeoutUntilStop="+timeoutUntilStop);
-       t = new CountDownTimer(timeoutUntilStop, timeoutUntilStop) {
+       t = new CountDownTimer(timeoutUntilStop, 10000) {
                public void onTick(long millisUntilFinished) {
                        //doing nothing.
                          if (debug) Log.d(TAG, "tick: " + millisUntilFinished );