Fixed bug with AppSetting Timeout set to "never"

added more debugging output in TimeoutHelper.cs
This commit is contained in:
Philipp Crocoll 2013-07-24 05:58:33 +02:00
parent 9f3c2dfc06
commit 0a26fdefbb

View File

@ -29,11 +29,10 @@ namespace keepass2android
/// </summary> /// </summary>
public class TimeoutHelper { public class TimeoutHelper {
class Timeout private static class Timeout
{ {
private const int RequestId = 0; private const int RequestId = 0;
private const long DefaultTimeout = 5 * 60 * 1000; // 5 minutes private const long DefaultTimeout = 5 * 60 * 1000; // 5 minutes
private const String Tag = "Keepass2Android Timeout";
private static PendingIntent BuildIntent(Context ctx) private static PendingIntent BuildIntent(Context ctx)
{ {
@ -67,7 +66,7 @@ namespace keepass2android
long triggerTime = Java.Lang.JavaSystem.CurrentTimeMillis() + timeout; long triggerTime = Java.Lang.JavaSystem.CurrentTimeMillis() + timeout;
AlarmManager am = (AlarmManager)ctx.GetSystemService(Context.AlarmService); AlarmManager am = (AlarmManager)ctx.GetSystemService(Context.AlarmService);
Log.Debug(Tag, "Timeout start"); Kp2aLog.Log("Timeout start");
am.Set(AlarmType.Rtc, triggerTime, BuildIntent(ctx)); am.Set(AlarmType.Rtc, triggerTime, BuildIntent(ctx));
} }
@ -75,7 +74,7 @@ namespace keepass2android
{ {
AlarmManager am = (AlarmManager)ctx.GetSystemService(Context.AlarmService); AlarmManager am = (AlarmManager)ctx.GetSystemService(Context.AlarmService);
Log.Debug(Tag, "Timeout cancel"); Kp2aLog.Log("Timeout cancel");
am.Cancel(BuildIntent(ctx)); am.Cancel(BuildIntent(ctx));
ctx.StopService(new Intent(ctx, typeof(TimeoutService))); ctx.StopService(new Intent(ctx, typeof(TimeoutService)));
@ -92,6 +91,8 @@ namespace keepass2android
ISharedPreferencesEditor edit = prefs.Edit(); ISharedPreferencesEditor edit = prefs.Edit();
edit.PutLong(act.GetString(Resource.String.timeout_key), time); edit.PutLong(act.GetString(Resource.String.timeout_key), time);
Kp2aLog.Log("Pause: start at " + time);
EditorCompat.Apply(edit); EditorCompat.Apply(edit);
if ( App.Kp2a.GetDb().Open ) { if ( App.Kp2a.GetDb().Open ) {
@ -111,6 +112,7 @@ namespace keepass2android
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(act); ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(act);
long timeoutStart = prefs.GetLong(act.GetString(Resource.String.timeout_key), -1); long timeoutStart = prefs.GetLong(act.GetString(Resource.String.timeout_key), -1);
Kp2aLog.Log("timeoutStart=" + timeoutStart);
// The timeout never started // The timeout never started
if (timeoutStart == -1) { if (timeoutStart == -1) {
return; return;
@ -119,17 +121,24 @@ namespace keepass2android
String sTimeout = prefs.GetString(act.GetString(Resource.String.app_timeout_key), act.GetString(Resource.String.clipboard_timeout_default)); String sTimeout = prefs.GetString(act.GetString(Resource.String.app_timeout_key), act.GetString(Resource.String.clipboard_timeout_default));
long timeout; long timeout;
if (!long.TryParse(sTimeout, out timeout)) if (!long.TryParse(sTimeout, out timeout) || (timeout == -1))
{ {
Kp2aLog.Log("exit with timeout=" + timeout + "/"+sTimeout);
// We are set to never timeout // We are set to never timeout
return; return;
} }
long diff = curTime - timeoutStart; long diff = curTime - timeoutStart;
if (diff >= timeout) { if (diff >= timeout)
{
// We have timed out // We have timed out
Kp2aLog.Log("Shutdown due to " + diff + ">=" + timeout);
App.Kp2a.SetShutdown(); App.Kp2a.SetShutdown();
} }
else
{
Kp2aLog.Log("No shutdown due to " + diff + "<" + timeout);
}
} }
static bool IocChanged(IOConnectionInfo ioc, IOConnectionInfo other) static bool IocChanged(IOConnectionInfo ioc, IOConnectionInfo other)