mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-12-23 15:38:47 -05:00
Fixed bug with AppSetting Timeout set to "never"
added more debugging output in TimeoutHelper.cs
This commit is contained in:
parent
9f3c2dfc06
commit
0a26fdefbb
@ -29,12 +29,11 @@ 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)
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(Intents.Timeout);
|
Intent intent = new Intent(Intents.Timeout);
|
||||||
@ -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)));
|
||||||
@ -91,6 +90,8 @@ namespace keepass2android
|
|||||||
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(act);
|
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(act);
|
||||||
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);
|
||||||
|
|
||||||
@ -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,16 +121,23 @@ 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
|
||||||
App.Kp2a.SetShutdown();
|
Kp2aLog.Log("Shutdown due to " + diff + ">=" + timeout);
|
||||||
|
App.Kp2a.SetShutdown();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Kp2aLog.Log("No shutdown due to " + diff + "<" + timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user