diff --git a/src/com/android/keepass/KeePass.java b/src/com/android/keepass/KeePass.java index aa21fb0c5..c04b62b01 100644 --- a/src/com/android/keepass/KeePass.java +++ b/src/com/android/keepass/KeePass.java @@ -24,7 +24,6 @@ import android.content.Intent; import android.os.Bundle; import com.keepassdroid.fileselect.FileSelectActivity; -import com.keepassdroid.services.TimeoutService; public class KeePass extends Activity { @@ -37,7 +36,6 @@ public class KeePass extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - startService(new Intent(this, TimeoutService.class)); } @@ -56,8 +54,6 @@ public class KeePass extends Activity { @Override protected void onDestroy() { super.onDestroy(); - - stopService(new Intent(this, TimeoutService.class)); } @Override diff --git a/src/com/keepassdroid/services/TimeoutService.java b/src/com/keepassdroid/services/TimeoutService.java index 77e477442..57aa628dd 100644 --- a/src/com/keepassdroid/services/TimeoutService.java +++ b/src/com/keepassdroid/services/TimeoutService.java @@ -57,18 +57,29 @@ public class TimeoutService extends Service { } + @Override + public void onStart(Intent intent, int startId) { + super.onStart(intent, startId); + + Log.d(TAG, "Timeout service started"); + } + private void timeout(Context context) { Log.d(TAG, "Timeout"); App.setShutdown(); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.cancelAll(); + + stopSelf(); } @Override public void onDestroy() { super.onDestroy(); - + + Log.d(TAG, "Timeout service stopped"); + unregisterReceiver(mIntentReceiver); } diff --git a/src/com/keepassdroid/timers/Timeout.java b/src/com/keepassdroid/timers/Timeout.java index 6507cec55..32aa1671c 100644 --- a/src/com/keepassdroid/timers/Timeout.java +++ b/src/com/keepassdroid/timers/Timeout.java @@ -7,10 +7,11 @@ import android.content.Intent; import android.util.Log; import com.keepassdroid.intents.Intents; +import com.keepassdroid.services.TimeoutService; public class Timeout { private static final int REQUEST_ID = 0; - private static final long DEFAULT_TIMEOUT = 5 * 60 * 1000; // 5 minutes + private static final long DEFAULT_TIMEOUT = 20 * 1000; // 5 minutes private static String TAG = "KeePass Timeout"; private static PendingIntent buildIntent(Context ctx) { @@ -21,8 +22,10 @@ public class Timeout { } public static void start(Context ctx) { + + ctx.startService(new Intent(ctx, TimeoutService.class)); + long triggerTime = System.currentTimeMillis() + DEFAULT_TIMEOUT; - AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); Log.d(TAG, "Timeout start"); @@ -34,6 +37,9 @@ public class Timeout { Log.d(TAG, "Timeout cancel"); am.cancel(buildIntent(ctx)); + + ctx.stopService(new Intent(ctx, TimeoutService.class)); + } }