changes to locking of the database: implement an alternative to alarm-based timeout (using a timeout variables checked when resuming), closes https://github.com/PhilippC/keepass2android/issues/1346
This commit is contained in:
		@@ -38,7 +38,7 @@ namespace keepass2android
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Locks all currently open databases, quicklocking if available (unless false is passed for allowQuickUnlock)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        void Lock(bool allowQuickUnlock);
 | 
			
		||||
        void Lock(bool allowQuickUnlock, bool lockWasTriggeredByTimeout);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
 
 | 
			
		||||
@@ -234,7 +234,7 @@ namespace keepass2android
 | 
			
		||||
				else
 | 
			
		||||
				{
 | 
			
		||||
					// Let's not bother recovering from a failure to save.  It is too much work.
 | 
			
		||||
					App.Lock(false);
 | 
			
		||||
					App.Lock(false, false);
 | 
			
		||||
				}
 | 
			
		||||
			}, OnFinishToRun);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -82,7 +82,7 @@ namespace keepass2android
 | 
			
		||||
					_editGroup.App.DirtyGroups.Add(_editGroup.Group.ParentGroup);
 | 
			
		||||
				} else
 | 
			
		||||
				{
 | 
			
		||||
					_editGroup._app.Lock(false);
 | 
			
		||||
					_editGroup._app.Lock(false, false);
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				base.Run();
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										7
									
								
								src/keepass2android/ILockCloseActivity.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/keepass2android/ILockCloseActivity.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
namespace keepass2android
 | 
			
		||||
{
 | 
			
		||||
    public interface ILockCloseActivity
 | 
			
		||||
    {
 | 
			
		||||
        void OnLockDatabase(bool lockedByTimeout);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -83,6 +83,7 @@ namespace keepass2android
 | 
			
		||||
		public const Result ExitFileStorageSelectionOk = Result.FirstUser + 8;
 | 
			
		||||
		public const Result ResultOkPasswordGenerator = Result.FirstUser + 9;
 | 
			
		||||
	    public const Result ExitLoadAnotherDb = Result.FirstUser + 10;
 | 
			
		||||
        public const Result ExitLockByTimeout = Result.FirstUser + 11;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		public const string TagsKey = "@tags";
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,8 @@ namespace keepass2android
 | 
			
		||||
	/// Base class for activities displaying sensitive information. 
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// Checks in OnResume whether the timeout occured and the database must be locked/closed.
 | 
			
		||||
	public class LockCloseActivity : LockingActivity {
 | 
			
		||||
	public class LockCloseActivity : LockingActivity, ILockCloseActivity
 | 
			
		||||
    {
 | 
			
		||||
		
 | 
			
		||||
		//the check if the database was locked/closed can be disabled by the caller for activities
 | 
			
		||||
		//which may be used "outside" the database (e.g. GeneratePassword for creating a master password)
 | 
			
		||||
@@ -115,35 +116,13 @@ namespace keepass2android
 | 
			
		||||
			App.Kp2a.CheckForOpenFileChanged(this);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private void OnLockDatabase()
 | 
			
		||||
		{
 | 
			
		||||
			Kp2aLog.Log("Finishing " + ComponentName.ClassName + " due to database lock");
 | 
			
		||||
 | 
			
		||||
			SetResult(KeePass.ExitLock);
 | 
			
		||||
			Finish();
 | 
			
		||||
        public void OnLockDatabase(bool lockedByTimeout)
 | 
			
		||||
        {
 | 
			
		||||
            TimeoutHelper.Lock(this, lockedByTimeout);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		private class LockCloseActivityBroadcastReceiver : BroadcastReceiver
 | 
			
		||||
		{			
 | 
			
		||||
			readonly LockCloseActivity _activity;
 | 
			
		||||
			public LockCloseActivityBroadcastReceiver(LockCloseActivity activity)
 | 
			
		||||
			{
 | 
			
		||||
				_activity = activity;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			public override void OnReceive(Context context, Intent intent)
 | 
			
		||||
			{
 | 
			
		||||
				switch (intent.Action)
 | 
			
		||||
				{
 | 
			
		||||
					case Intents.DatabaseLocked:
 | 
			
		||||
						_activity.OnLockDatabase();
 | 
			
		||||
						break;
 | 
			
		||||
					case Intent.ActionScreenOff:
 | 
			
		||||
						App.Kp2a.OnScreenOff();
 | 
			
		||||
						break;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								src/keepass2android/LockCloseActivityBroadcastReceiver.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/keepass2android/LockCloseActivityBroadcastReceiver.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
using Android.Content;
 | 
			
		||||
 | 
			
		||||
namespace keepass2android
 | 
			
		||||
{
 | 
			
		||||
    public class LockCloseActivityBroadcastReceiver : BroadcastReceiver
 | 
			
		||||
    {
 | 
			
		||||
        readonly ILockCloseActivity _activity;
 | 
			
		||||
        public LockCloseActivityBroadcastReceiver(ILockCloseActivity activity)
 | 
			
		||||
        {
 | 
			
		||||
            _activity = activity;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void OnReceive(Context context, Intent intent)
 | 
			
		||||
        {
 | 
			
		||||
            switch (intent.Action)
 | 
			
		||||
            {
 | 
			
		||||
                case Intents.DatabaseLocked:
 | 
			
		||||
                    _activity.OnLockDatabase(intent.GetBooleanExtra("ByTimeout", false));
 | 
			
		||||
                    break;
 | 
			
		||||
                case Intent.ActionScreenOff:
 | 
			
		||||
                    App.Kp2a.OnScreenOff();
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -29,7 +29,8 @@ namespace keepass2android
 | 
			
		||||
	/// Base class for list activities displaying sensitive information. 
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	/// Checks in OnResume whether the timeout occured and the database must be locked/closed.
 | 
			
		||||
	public class LockCloseListActivity : LockingListActivity {
 | 
			
		||||
	public class LockCloseListActivity : LockingListActivity, ILockCloseActivity
 | 
			
		||||
    {
 | 
			
		||||
		public LockCloseListActivity()
 | 
			
		||||
		{
 | 
			
		||||
			_design = new ActivityDesign(this);
 | 
			
		||||
@@ -49,7 +50,7 @@ namespace keepass2android
 | 
			
		||||
 | 
			
		||||
			_ioc = App.Kp2a.CurrentDb.Ioc;
 | 
			
		||||
 | 
			
		||||
			_intentReceiver = new LockCloseListActivityBroadcastReceiver(this);
 | 
			
		||||
			_intentReceiver = new LockCloseActivityBroadcastReceiver(this);
 | 
			
		||||
			IntentFilter filter = new IntentFilter();
 | 
			
		||||
 | 
			
		||||
			filter.AddAction(Intents.DatabaseLocked);
 | 
			
		||||
@@ -93,34 +94,10 @@ namespace keepass2android
 | 
			
		||||
			base.OnDestroy();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private void OnLockDatabase()
 | 
			
		||||
		{
 | 
			
		||||
			Kp2aLog.Log("Finishing " + ComponentName.ClassName + " due to database lock");
 | 
			
		||||
 | 
			
		||||
			SetResult(KeePass.ExitLock);
 | 
			
		||||
			Finish();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private class LockCloseListActivityBroadcastReceiver : BroadcastReceiver
 | 
			
		||||
        public void OnLockDatabase(bool lockedByTimeout)
 | 
			
		||||
        {
 | 
			
		||||
			readonly LockCloseListActivity _activity;
 | 
			
		||||
			public LockCloseListActivityBroadcastReceiver(LockCloseListActivity activity)
 | 
			
		||||
			{
 | 
			
		||||
				_activity = activity;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			public override void OnReceive(Context context, Intent intent)
 | 
			
		||||
			{
 | 
			
		||||
				switch (intent.Action)
 | 
			
		||||
				{
 | 
			
		||||
					case Intents.DatabaseLocked:
 | 
			
		||||
						_activity.OnLockDatabase();
 | 
			
		||||
						break;
 | 
			
		||||
					case Intent.ActionScreenOff:
 | 
			
		||||
						App.Kp2a.OnScreenOff();
 | 
			
		||||
						break;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
            TimeoutHelper.Lock(this, lockedByTimeout);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,8 @@ using KeePassLib.Serialization;
 | 
			
		||||
namespace keepass2android
 | 
			
		||||
{
 | 
			
		||||
	
 | 
			
		||||
	public class LockingClosePreferenceActivity : LockingPreferenceActivity {
 | 
			
		||||
	public class LockingClosePreferenceActivity : LockingPreferenceActivity, ILockCloseActivity
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
		IOConnectionInfo _ioc;
 | 
			
		||||
@@ -35,7 +36,7 @@ namespace keepass2android
 | 
			
		||||
			_ioc = App.Kp2a.CurrentDb.Ioc;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
			_intentReceiver = new LockingClosePreferenceActivityBroadcastReceiver(this);
 | 
			
		||||
			_intentReceiver = new LockCloseActivityBroadcastReceiver(this);
 | 
			
		||||
			IntentFilter filter = new IntentFilter();
 | 
			
		||||
			filter.AddAction(Intents.DatabaseLocked);
 | 
			
		||||
			RegisterReceiver(_intentReceiver, filter);
 | 
			
		||||
@@ -66,31 +67,11 @@ namespace keepass2android
 | 
			
		||||
			base.OnDestroy();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private void OnLockDatabase()
 | 
			
		||||
		{
 | 
			
		||||
			Kp2aLog.Log("Finishing " + ComponentName.ClassName + " due to database lock");
 | 
			
		||||
 | 
			
		||||
			SetResult(KeePass.ExitLock);
 | 
			
		||||
			Finish();
 | 
			
		||||
		}
 | 
			
		||||
        public void OnLockDatabase(bool lockedByTimeout)
 | 
			
		||||
        {
 | 
			
		||||
            TimeoutHelper.Lock(this, lockedByTimeout);
 | 
			
		||||
 | 
			
		||||
		private class LockingClosePreferenceActivityBroadcastReceiver : BroadcastReceiver
 | 
			
		||||
		{
 | 
			
		||||
			readonly LockingClosePreferenceActivity _service;
 | 
			
		||||
			public LockingClosePreferenceActivityBroadcastReceiver(LockingClosePreferenceActivity service)
 | 
			
		||||
			{
 | 
			
		||||
				_service = service;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			public override void OnReceive(Context context, Intent intent)
 | 
			
		||||
			{
 | 
			
		||||
				switch (intent.Action)
 | 
			
		||||
				{
 | 
			
		||||
					case Intents.DatabaseLocked:
 | 
			
		||||
						_service.OnLockDatabase();
 | 
			
		||||
						break;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -510,6 +510,9 @@ namespace keepass2android
 | 
			
		||||
                    if (!IsFinishing)
 | 
			
		||||
                        Finish();
 | 
			
		||||
                    break;
 | 
			
		||||
                case KeePass.ExitLockByTimeout:
 | 
			
		||||
                    //don't finish, bring up QuickUnlock
 | 
			
		||||
                    break;
 | 
			
		||||
                case KeePass.ExitCloseAfterTaskComplete:
 | 
			
		||||
                    // Do not lock the database
 | 
			
		||||
                    SetResult(KeePass.ExitCloseAfterTaskComplete);
 | 
			
		||||
 
 | 
			
		||||
@@ -109,7 +109,7 @@ namespace keepass2android
 | 
			
		||||
	/// </summary>
 | 
			
		||||
	public class Kp2aApp: IKp2aApp, ICacheSupervisor
 | 
			
		||||
	{
 | 
			
		||||
	    public void Lock(bool allowQuickUnlock = true)
 | 
			
		||||
	    public void Lock(bool allowQuickUnlock = true, bool lockWasTriggeredByTimeout = false)
 | 
			
		||||
	    {
 | 
			
		||||
			if (OpenDatabases.Any())
 | 
			
		||||
			{
 | 
			
		||||
@@ -150,7 +150,10 @@ namespace keepass2android
 | 
			
		||||
	        _currentlyWaitingXcKey = null;
 | 
			
		||||
 | 
			
		||||
			UpdateOngoingNotification();
 | 
			
		||||
			Application.Context.SendBroadcast(new Intent(Intents.DatabaseLocked));
 | 
			
		||||
            var intent = new Intent(Intents.DatabaseLocked);
 | 
			
		||||
            if (lockWasTriggeredByTimeout)
 | 
			
		||||
                intent.PutExtra("ByTimeout", true);
 | 
			
		||||
            Application.Context.SendBroadcast(intent);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -256,6 +259,8 @@ namespace keepass2android
 | 
			
		||||
		            .Commit();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
			TimeoutHelper.ResumingApp();
 | 
			
		||||
 | 
			
		||||
            UpdateOngoingNotification();
 | 
			
		||||
 | 
			
		||||
	        return newDb;
 | 
			
		||||
@@ -289,6 +294,8 @@ namespace keepass2android
 | 
			
		||||
		{
 | 
			
		||||
			QuickLocked = false;
 | 
			
		||||
 | 
			
		||||
			TimeoutHelper.ResumingApp();
 | 
			
		||||
 | 
			
		||||
			UpdateOngoingNotification();
 | 
			
		||||
 | 
			
		||||
			BroadcastDatabaseAction(Application.Context, Strings.ActionUnlockDatabase);
 | 
			
		||||
@@ -1021,6 +1028,11 @@ namespace keepass2android
 | 
			
		||||
			get; set;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// When opening an activity after this time, we should close the database as it timed out.
 | 
			
		||||
		/// </summary>
 | 
			
		||||
        public DateTime TimeoutTime { get; set; }
 | 
			
		||||
 | 
			
		||||
        public void OnScreenOff()
 | 
			
		||||
		{
 | 
			
		||||
			if (PreferenceManager.GetDefaultSharedPreferences(Application.Context)
 | 
			
		||||
@@ -1195,6 +1207,7 @@ namespace keepass2android
 | 
			
		||||
 | 
			
		||||
		    IntentFilter intentFilter = new IntentFilter();
 | 
			
		||||
		    intentFilter.AddAction(Intents.LockDatabase);
 | 
			
		||||
            intentFilter.AddAction(Intents.LockDatabaseByTimeout);
 | 
			
		||||
			intentFilter.AddAction(Intents.CloseDatabase);
 | 
			
		||||
            Context.RegisterReceiver(broadcastReceiver, intentFilter);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,9 @@ namespace keepass2android
 | 
			
		||||
 | 
			
		||||
			switch (intent.Action)
 | 
			
		||||
			{
 | 
			
		||||
                case Intents.LockDatabaseByTimeout:
 | 
			
		||||
                    App.Kp2a.Lock(true, true);
 | 
			
		||||
                    break;
 | 
			
		||||
				case Intents.LockDatabase:
 | 
			
		||||
					App.Kp2a.Lock();
 | 
			
		||||
					break;
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,9 @@ namespace keepass2android
 | 
			
		||||
 | 
			
		||||
		/// <summary>Broadcast this intent to lock the database (with quick unlock if enabled)</summary>
 | 
			
		||||
		public const String LockDatabase = "keepass2android."+AppNames.PackagePart+".lock_database";
 | 
			
		||||
        /// <summary>Broadcast this intent to lock the database (with quick unlock if enabled) after some timeout occurred. As the locking is not triggered explicitly by the user, we expect to show the QuickUnlock dialog instead of leaving the app</summary>
 | 
			
		||||
		public const String LockDatabaseByTimeout = "keepass2android." + AppNames.PackagePart + ".lock_database_by_timeout";
 | 
			
		||||
 | 
			
		||||
        /// <summary>Broadcast this intent to close the database (no quick unlock, full close)</summary>
 | 
			
		||||
		public const String CloseDatabase = "keepass2android." + AppNames.PackagePart + ".close_database";
 | 
			
		||||
		
 | 
			
		||||
 
 | 
			
		||||
@@ -135,6 +135,7 @@
 | 
			
		||||
    <Compile Include="EntryActivityClasses\ViewImagePopupItem.cs" />
 | 
			
		||||
    <Compile Include="FileSaveProcessManager.cs" />
 | 
			
		||||
    <Compile Include="fileselect\FilteredCursor.cs" />
 | 
			
		||||
    <Compile Include="ILockCloseActivity.cs" />
 | 
			
		||||
    <Compile Include="ImageViewActivity.cs" />
 | 
			
		||||
    <Compile Include="addons\OtpKeyProv\EncodingUtil.cs" />
 | 
			
		||||
    <Compile Include="addons\OtpKeyProv\OathHotpKeyProv.cs" />
 | 
			
		||||
@@ -177,6 +178,7 @@
 | 
			
		||||
    <Compile Include="KeeChallenge.cs" />
 | 
			
		||||
    <Compile Include="FixedDrawerLayout.cs" />
 | 
			
		||||
    <Compile Include="KpEntryTemplatedEdit.cs" />
 | 
			
		||||
    <Compile Include="LockCloseActivityBroadcastReceiver.cs" />
 | 
			
		||||
    <Compile Include="MeasuringRelativeLayout.cs" />
 | 
			
		||||
    <Compile Include="NfcOtpActivity.cs" />
 | 
			
		||||
    <Compile Include="NoSecureDisplayActivity.cs" />
 | 
			
		||||
 
 | 
			
		||||
@@ -33,12 +33,17 @@ namespace keepass2android
 | 
			
		||||
		{
 | 
			
		||||
			private const long DefaultTimeout = 5 * 60 * 1000;  // 5 minutes
 | 
			
		||||
			
 | 
			
		||||
			private static PendingIntent BuildIntent(Context ctx)
 | 
			
		||||
			private static PendingIntent BuildPendingBroadcastIntent(Context ctx)
 | 
			
		||||
			{
 | 
			
		||||
				return PendingIntent.GetBroadcast(ctx, 0, new Intent(ctx, typeof(ApplicationBroadcastReceiver)).SetAction(Intents.LockDatabase), PendingIntentFlags.UpdateCurrent);
 | 
			
		||||
				return PendingIntent.GetBroadcast(ctx, 0, BuildBroadcastIntent(ctx), PendingIntentFlags.UpdateCurrent);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			public static void Start(Context ctx)
 | 
			
		||||
            private static Intent BuildBroadcastIntent(Context ctx)
 | 
			
		||||
            {
 | 
			
		||||
                return new Intent(ctx, typeof(ApplicationBroadcastReceiver)).SetAction(Intents.LockDatabaseByTimeout);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public static void LeavingApp(Context ctx)
 | 
			
		||||
			{
 | 
			
		||||
				ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ctx);
 | 
			
		||||
				String sTimeout = prefs.GetString(ctx.GetString(Resource.String.app_timeout_key), ctx.GetString(Resource.String.clipboard_timeout_default));
 | 
			
		||||
@@ -55,28 +60,42 @@ namespace keepass2android
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				//in addition to starting an alarm, check the time in the next resume. This might be required as alarms seems to be unrealiable in more recent android versions
 | 
			
		||||
                App.Kp2a.TimeoutTime = DateTime.Now + TimeSpan.FromMilliseconds(timeout);
 | 
			
		||||
 | 
			
		||||
				long triggerTime = Java.Lang.JavaSystem.CurrentTimeMillis() + timeout;
 | 
			
		||||
				AlarmManager am = (AlarmManager)ctx.GetSystemService(Context.AlarmService);
 | 
			
		||||
 | 
			
		||||
				Kp2aLog.Log("Timeout start");
 | 
			
		||||
				am.Set(AlarmType.Rtc, triggerTime, BuildIntent(ctx));
 | 
			
		||||
				am.Set(AlarmType.Rtc, triggerTime, BuildPendingBroadcastIntent(App.Context));
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			public static void Cancel(Context ctx)
 | 
			
		||||
			public static void ResumingApp(Context ctx)
 | 
			
		||||
			{
 | 
			
		||||
				AlarmManager am = (AlarmManager)ctx.GetSystemService(Context.AlarmService);
 | 
			
		||||
                
 | 
			
		||||
                
 | 
			
		||||
				AlarmManager am = (AlarmManager)ctx.GetSystemService(Context.AlarmService);
 | 
			
		||||
				//cancel alarm
 | 
			
		||||
				Kp2aLog.Log("Timeout cancel");
 | 
			
		||||
				am.Cancel(BuildIntent(ctx));
 | 
			
		||||
				am.Cancel(BuildPendingBroadcastIntent(App.Context));
 | 
			
		||||
                App.Kp2a.TimeoutTime = DateTime.MaxValue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            public static void CheckIfTimedOutWithoutAlarm(Context ctx)
 | 
			
		||||
            {
 | 
			
		||||
                if (DateTime.Now > App.Kp2a.TimeoutTime)
 | 
			
		||||
                {
 | 
			
		||||
                    ctx.SendBroadcast(BuildBroadcastIntent(ctx));
 | 
			
		||||
                }
 | 
			
		||||
			}
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		public static void Pause(Activity act) 
 | 
			
		||||
		{
 | 
			
		||||
			if ( App.Kp2a.DatabaseIsUnlocked )
 | 
			
		||||
			{
 | 
			
		||||
				Timeout.Start(act);
 | 
			
		||||
				Timeout.LeavingApp(act);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
		}
 | 
			
		||||
@@ -85,10 +104,17 @@ namespace keepass2android
 | 
			
		||||
        {
 | 
			
		||||
            if ( App.Kp2a.CurrentDb!= null)
 | 
			
		||||
            {
 | 
			
		||||
				Timeout.Cancel(act);
 | 
			
		||||
                Timeout.CheckIfTimedOutWithoutAlarm(act);
 | 
			
		||||
				Timeout.ResumingApp(act);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        public static void ResumingApp()
 | 
			
		||||
        {
 | 
			
		||||
            Timeout.ResumingApp(App.Context);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		static bool IocChanged(IOConnectionInfo ioc, IOConnectionInfo other)
 | 
			
		||||
		{
 | 
			
		||||
			if ((ioc == null) || (other == null)) return false;
 | 
			
		||||
@@ -103,6 +129,14 @@ namespace keepass2android
 | 
			
		||||
			}
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        public static void Lock(Activity activity, in bool lockedByTimeout)
 | 
			
		||||
        {
 | 
			
		||||
            Kp2aLog.Log("Finishing " + activity.ComponentName.ClassName + " due to database lock");
 | 
			
		||||
 | 
			
		||||
            activity.SetResult(lockedByTimeout ? KeePass.ExitLockByTimeout : KeePass.ExitLock);
 | 
			
		||||
            activity.Finish();
 | 
			
		||||
		}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user