From fa256af3e168f62dfd5ccb6059e173b495ad656c Mon Sep 17 00:00:00 2001 From: "isaac.jones" Date: Sun, 18 Jan 2009 01:12:55 +0000 Subject: [PATCH] Created intent for restarting the timer, and called this intent from a few places within the code, notibly on PassList and CategoryList when items were selected or edited. This stops the timer from timing out surprisingly while the user is editing stuff. git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@1760 72b678ce-9140-0410-bee8-679b907dd61a --- AndroidManifest.xml | 5 ++++- res/values/strings.xml | 1 + src/org/openintents/intents/CryptoIntents.java | 10 ++++++++++ src/org/openintents/safe/CategoryList.java | 14 ++++++++++---- src/org/openintents/safe/FrontDoor.java | 12 +++++++++++- src/org/openintents/safe/PassList.java | 6 +++++- .../openintents/safe/service/ServiceDispatch.aidl | 1 + .../safe/service/ServiceDispatchImpl.java | 15 ++++++++------- 8 files changed, 50 insertions(+), 14 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 28e173a..8c7e872 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -49,7 +49,10 @@ - + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 77631be..bae4898 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -132,6 +132,7 @@ Encrypt (OI Safe) Get password (OI Safe) Set password (OI Safe) + Restart timer (OI Safe) Open OI Safe Lock Continue diff --git a/src/org/openintents/intents/CryptoIntents.java b/src/org/openintents/intents/CryptoIntents.java index 6f5ba4b..a5b0e6e 100644 --- a/src/org/openintents/intents/CryptoIntents.java +++ b/src/org/openintents/intents/CryptoIntents.java @@ -62,6 +62,16 @@ public class CryptoIntents { *

Constant Value: "org.openintents.action.SET_PASSWORD"

*/ public static final String ACTION_SET_PASSWORD = "org.openintents.action.SET_PASSWORD"; + + /** + * Activity Action: Restarts the timer for the Crypto intent service. + * The timer gets reset when using GET or set password anyway, but this is + * a way to reset the timer for other kinds of actions. Use sparingly since + * we do actually want the timer to time out eventually! + * + *

Constant Value: "org.openintents.action.RESTART_TIMER"

+ */ + public static final String ACTION_RESTART_TIMER = "org.openintents.action.RESTART_TIMER"; /** * Broadcast Action: Sent when the user got logged out of the diff --git a/src/org/openintents/safe/CategoryList.java b/src/org/openintents/safe/CategoryList.java index b3fe460..5543724 100644 --- a/src/org/openintents/safe/CategoryList.java +++ b/src/org/openintents/safe/CategoryList.java @@ -119,6 +119,7 @@ public class CategoryList extends ListActivity { private static String masterKey; private List rows; + private Intent restartTimerIntent; BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { @@ -187,6 +188,8 @@ public class CategoryList extends ListActivity { if (debug) Log.d(TAG,"onCreate()"); + restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER); + if (!isSignedIn()) { Intent frontdoor = new Intent(this, FrontDoor.class); startActivity(frontdoor); @@ -239,7 +242,7 @@ public class CategoryList extends ListActivity { @Override protected void onPause() { super.onPause(); - + if (debug) Log.d(TAG,"onPause()"); if ((importThread != null) && (importThread.isAlive())) { @@ -466,7 +469,8 @@ public class CategoryList extends ListActivity { } public boolean onOptionsItemSelected(MenuItem item) { - + startActivity (restartTimerIntent); + AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int position=-1; if (info==null) { @@ -597,7 +601,8 @@ public class CategoryList extends ListActivity { protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); - + + startActivity (restartTimerIntent); launchPassList(rows.get(position).id); } @@ -623,7 +628,8 @@ public class CategoryList extends ListActivity { if (debug) Log.d(TAG,"addCategory("+name+")"); if ((name==null) || (name=="")) return -1; CategoryEntry entry = new CategoryEntry(); - + + startActivity (restartTimerIntent); String namePlain = name; try { diff --git a/src/org/openintents/safe/FrontDoor.java b/src/org/openintents/safe/FrontDoor.java index a15ff76..aa747ff 100644 --- a/src/org/openintents/safe/FrontDoor.java +++ b/src/org/openintents/safe/FrontDoor.java @@ -148,7 +148,17 @@ public class FrontDoor extends Activity { } else if (externalAccess){ // which action? - if (action.equals (CryptoIntents.ACTION_ENCRYPT)) { + if (action.equals (CryptoIntents.ACTION_RESTART_TIMER)) { + if (service != null) { + try { + service.restartTimer(); + callbackResult = RESULT_OK; + } catch (RemoteException e) { + // TODO Auto-generated catch block + Log.e (TAG, "remoteException in Restart Timer"); + } + } + } else if (action.equals (CryptoIntents.ACTION_ENCRYPT)) { callbackResult = encryptIntent(thisIntent, callbackIntent); } else if (action.equals (CryptoIntents.ACTION_DECRYPT)) { callbackResult = decryptIntent(thisIntent, callbackIntent); diff --git a/src/org/openintents/safe/PassList.java b/src/org/openintents/safe/PassList.java index d142576..f97f435 100644 --- a/src/org/openintents/safe/PassList.java +++ b/src/org/openintents/safe/PassList.java @@ -24,6 +24,8 @@ import java.util.HashMap; import java.util.List; import java.util.Set; +import org.openintents.intents.CryptoIntents; + import android.app.AlertDialog; import android.app.Dialog; import android.app.ListActivity; @@ -72,6 +74,7 @@ public class PassList extends ListActivity { private CryptoHelper ch; private DBHelper dbHelper=null; private static Long CategoryId=null; + private Intent restartTimerIntent; private static String masterKey; @@ -85,6 +88,7 @@ public class PassList extends ListActivity { super.onCreate(icicle); if (debug) Log.d(TAG,"onCreate()"); + restartTimerIntent = new Intent (CryptoIntents.ACTION_RESTART_TIMER); setContentView(R.layout.pass_list); if (dbHelper==null) { @@ -343,7 +347,7 @@ public class PassList extends ListActivity { } public boolean onOptionsItemSelected(MenuItem item) { - + startActivity (restartTimerIntent); AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int position=-1; if (info==null) { diff --git a/src/org/openintents/safe/service/ServiceDispatch.aidl b/src/org/openintents/safe/service/ServiceDispatch.aidl index ba06008..631be0d 100644 --- a/src/org/openintents/safe/service/ServiceDispatch.aidl +++ b/src/org/openintents/safe/service/ServiceDispatch.aidl @@ -22,4 +22,5 @@ interface ServiceDispatch { String encrypt (String clearText); String decrypt (String cryptoText); void setTimeoutMinutes(int timeoutMinutesIn); + void restartTimer(); } diff --git a/src/org/openintents/safe/service/ServiceDispatchImpl.java b/src/org/openintents/safe/service/ServiceDispatchImpl.java index 39c5835..8b9033d 100644 --- a/src/org/openintents/safe/service/ServiceDispatchImpl.java +++ b/src/org/openintents/safe/service/ServiceDispatchImpl.java @@ -84,13 +84,6 @@ public class ServiceDispatchImpl extends Service { Log.d(TAG, "Timer started with: " + timeoutUntilStop ); } - private void restartTimer () { - // must be started with startTimer first. - if (t != null) { - t.cancel(); - t.start(); - } - } /** * The ServiceDispatch is defined through IDL @@ -139,6 +132,14 @@ public class ServiceDispatchImpl extends Service { timeoutUntilStop = timeoutMinutes * 60000; Log.d(TAG,"set timeout to "+timeoutMinutes); } + + public void restartTimer () { + // must be started with startTimer first. + if (t != null) { + t.cancel(); + t.start(); + } + } }; } -- 2.50.1