mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-22 01:02:16 -05:00
Added option to lock database when screen off
This commit is contained in:
parent
08093531e9
commit
0ad00eefe2
@ -45,6 +45,7 @@ namespace keepass2android
|
||||
_intentReceiver = new LockCloseActivityBroadcastReceiver(this);
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.AddAction(Intents.DatabaseLocked);
|
||||
filter.AddAction(Intent.ActionScreenOff);
|
||||
RegisterReceiver(_intentReceiver, filter);
|
||||
}
|
||||
|
||||
@ -102,6 +103,9 @@ namespace keepass2android
|
||||
case Intents.DatabaseLocked:
|
||||
_service.OnLockDatabase();
|
||||
break;
|
||||
case Intent.ActionScreenOff:
|
||||
App.Kp2a.OnScreenOff();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
using System;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Preferences;
|
||||
using Android.Runtime;
|
||||
using KeePassLib.Serialization;
|
||||
|
||||
@ -43,7 +44,9 @@ namespace keepass2android
|
||||
|
||||
_intentReceiver = new LockCloseListActivityBroadcastReceiver(this);
|
||||
IntentFilter filter = new IntentFilter();
|
||||
|
||||
filter.AddAction(Intents.DatabaseLocked);
|
||||
filter.AddAction(Intent.ActionScreenOff);
|
||||
RegisterReceiver(_intentReceiver, filter);
|
||||
|
||||
}
|
||||
@ -95,6 +98,9 @@ namespace keepass2android
|
||||
case Intents.DatabaseLocked:
|
||||
_service.OnLockDatabase();
|
||||
break;
|
||||
case Intent.ActionScreenOff:
|
||||
App.Kp2a.OnScreenOff();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,7 @@
|
||||
<string name="LastInfoVersionCode_key">LastInfoVersion</string>
|
||||
|
||||
<string name="UseFileTransactions_key">UseFileTransactions</string>
|
||||
<string name="LockWhenScreenOff_key">LockWhenScreenOff</string>
|
||||
<string name="UseOfflineCache_key">UseOfflineCache</string>
|
||||
<string name="CheckForFileChangesOnSave_key">CheckForFileChangesOnSave</string>
|
||||
|
||||
|
@ -235,6 +235,8 @@
|
||||
<string name="credentials_dialog_title">Enter server credentials</string>
|
||||
<string name="UseFileTransactions_title">File transactions</string>
|
||||
<string name="UseFileTransactions_summary">Use file transactions for writing databases</string>
|
||||
<string name="LockWhenScreenOff_title">Lock when screen off</string>
|
||||
<string name="LockWhenScreenOff_summary">Lock the database when screen is switched off.</string>
|
||||
<string name="UseOfflineCache_title">Database caching</string>
|
||||
<string name="UseOfflineCache_summary">Keep a copy of remote database files in the application cache directory. This allows to use remote databases even when offline.</string>
|
||||
<string name="ClearOfflineCache_title">Clear cache?</string>
|
||||
|
@ -72,6 +72,14 @@
|
||||
android:entryValues="@array/clipboard_timeout_values"
|
||||
android:dialogTitle="@string/app_timeout"
|
||||
android:defaultValue="@string/clipboard_timeout_default"/>
|
||||
<CheckBoxPreference
|
||||
android:enabled="true"
|
||||
android:persistent="true"
|
||||
android:summary="@string/LockWhenScreenOff_summary"
|
||||
android:defaultValue="false"
|
||||
android:title="@string/LockWhenScreenOff_title"
|
||||
android:key="@string/LockWhenScreenOff_key" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="@string/RememberRecentFiles_key"
|
||||
android:title="@string/RememberRecentFiles_title"
|
||||
|
@ -534,6 +534,17 @@ namespace keepass2android
|
||||
return cacheEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnScreenOff()
|
||||
{
|
||||
if (PreferenceManager.GetDefaultSharedPreferences(Application.Context)
|
||||
.GetBoolean(
|
||||
Application.Context.GetString(Resource.String.LockWhenScreenOff_key),
|
||||
false))
|
||||
{
|
||||
App.Kp2a.LockDatabase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@ using System;
|
||||
using System.Linq;
|
||||
using Android.Content;
|
||||
using Android.App;
|
||||
using Android.Preferences;
|
||||
|
||||
|
||||
namespace keepass2android
|
||||
|
@ -35,11 +35,23 @@ namespace keepass2android
|
||||
[Service]
|
||||
public class OngoingNotificationsService : Service
|
||||
{
|
||||
private ScreenOffReceiver _screenOffReceiver;
|
||||
|
||||
#region Service
|
||||
private const int QuickUnlockId = 100;
|
||||
private const int UnlockedWarningId = 200;
|
||||
|
||||
public override void OnCreate()
|
||||
{
|
||||
base.OnCreate();
|
||||
|
||||
_screenOffReceiver = new ScreenOffReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.AddAction(Intent.ActionScreenOff);
|
||||
RegisterReceiver(_screenOffReceiver, filter);
|
||||
}
|
||||
|
||||
|
||||
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
|
||||
{
|
||||
Kp2aLog.Log("Starting/Updating OngoingNotificationsService. Database " + (App.Kp2a.DatabaseIsUnlocked ? "Unlocked" : (App.Kp2a.QuickLocked ? "QuickLocked" : "Locked")));
|
||||
@ -111,6 +123,8 @@ namespace keepass2android
|
||||
{
|
||||
App.Kp2a.LockDatabase();
|
||||
}
|
||||
|
||||
UnregisterReceiver(_screenOffReceiver);
|
||||
}
|
||||
|
||||
public override IBinder OnBind(Intent intent)
|
||||
@ -191,6 +205,14 @@ namespace keepass2android
|
||||
return name;
|
||||
}
|
||||
#endregion
|
||||
|
||||
class ScreenOffReceiver: BroadcastReceiver
|
||||
{
|
||||
public override void OnReceive(Context context, Intent intent)
|
||||
{
|
||||
App.Kp2a.OnScreenOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user