mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add database lock for screen off
This commit is contained in:
@@ -22,26 +22,8 @@ package com.keepassdroid;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.kunzisoft.keepass.KeePass;
|
||||
import com.keepassdroid.app.App;
|
||||
|
||||
public abstract class LockCloseActivity extends LockingActivity {
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
checkShutdown();
|
||||
}
|
||||
|
||||
private void checkShutdown() {
|
||||
if ( App.isShutdown() && App.getDB().Loaded() ) {
|
||||
setResult(KeePass.EXIT_LOCK);
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc) Workaround for HTC Linkify issues
|
||||
* @see android.app.Activity#startActivity(android.content.Intent)
|
||||
*/
|
||||
|
||||
@@ -20,23 +20,76 @@
|
||||
package com.keepassdroid;
|
||||
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.settings.PrefsUtil;
|
||||
import com.keepassdroid.stylish.StylishActivity;
|
||||
import com.keepassdroid.timeout.TimeoutHelper;
|
||||
import com.kunzisoft.keepass.KeePass;
|
||||
|
||||
|
||||
public abstract class LockingActivity extends StylishActivity {
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
private ScreenReceiver screenReceiver;
|
||||
|
||||
TimeoutHelper.pause(this);
|
||||
}
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (PrefsUtil.isLockDatabaseWhenScreenShutOffEnable(this)) {
|
||||
screenReceiver = new ScreenReceiver();
|
||||
registerReceiver(screenReceiver, new IntentFilter((Intent.ACTION_SCREEN_OFF)));
|
||||
} else
|
||||
screenReceiver = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
checkShutdown();
|
||||
TimeoutHelper.resume(this);
|
||||
}
|
||||
|
||||
private void checkShutdown() {
|
||||
if ( App.isShutdown() && App.getDB().Loaded() ) {
|
||||
setResult(KeePass.EXIT_LOCK);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
TimeoutHelper.pause(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if(screenReceiver != null)
|
||||
unregisterReceiver(screenReceiver);
|
||||
}
|
||||
|
||||
public class ScreenReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
if(intent.getAction() != null) {
|
||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||
if (PrefsUtil.isLockDatabaseWhenScreenShutOffEnable(LockingActivity.this)) {
|
||||
App.setShutdown();
|
||||
checkShutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,4 +55,10 @@ public class PrefsUtil {
|
||||
return prefs.getBoolean(ctx.getString(R.string.clipboard_notifications_key),
|
||||
ctx.getResources().getBoolean(R.bool.clipboard_notifications_default));
|
||||
}
|
||||
|
||||
public static boolean isLockDatabaseWhenScreenShutOffEnable(Context ctx) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
return prefs.getBoolean(ctx.getString(R.string.lock_database_screen_off_key),
|
||||
ctx.getResources().getBoolean(R.bool.lock_database_screen_off_default));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,6 +208,8 @@
|
||||
<string name="list_password_generator_options_summary">Définir les caractères par défaut du générateur de mot de passe</string>
|
||||
<string name="clipboard_notifications_title">Notifications du presse-papiers</string>
|
||||
<string name="clipboard_notifications_summary">Activer les notifications du presse-papiers pour copier le nom d\'utilisateur et le mot de passe</string>
|
||||
<string name="lock_database_screen_off_title">Verrouillage d\'écran</string>
|
||||
<string name="lock_database_screen_off_summary">Verrouiller la base de données quand l\'écran est éteint</string>
|
||||
|
||||
<string-array name="clipboard_timeout_options">
|
||||
<item>30 secondes</item>
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
<string name="saf_key" translatable="false">storage_access_framework_key</string>
|
||||
<string name="setting_style_key" translatable="false">setting_style_key</string>
|
||||
<string name="clipboard_notifications_key" translatable="false">clipboard_notifications_key</string>
|
||||
<string name="lock_database_screen_off_key" translatable="false">lock_database_screen_off_key</string>
|
||||
|
||||
<bool name="maskpass_default" translatable="false">true</bool>
|
||||
<bool name="keyfile_default" translatable="false">true</bool>
|
||||
@@ -61,6 +62,7 @@
|
||||
<bool name="recentfile_default" translatable="false">true</bool>
|
||||
<bool name="saf_default" translatable="false">false</bool>
|
||||
<bool name="clipboard_notifications_default" translatable="false">true</bool>
|
||||
<bool name="lock_database_screen_off_default" translatable="false">true</bool>
|
||||
|
||||
<string name="clipboard_timeout_default" translatable="false">300000</string>
|
||||
<string-array name="clipboard_timeout_values">
|
||||
|
||||
@@ -208,6 +208,9 @@
|
||||
<string name="list_password_generator_options_summary">Set the default password generator characters</string>
|
||||
<string name="clipboard_notifications_title">Clipboard Notifications</string>
|
||||
<string name="clipboard_notifications_summary">Enable clipboard notifications to copy username and password</string>
|
||||
<string name="lock">Lock</string>
|
||||
<string name="lock_database_screen_off_title">Screen lock</string>
|
||||
<string name="lock_database_screen_off_summary">Lock the database when the screen is off</string>
|
||||
|
||||
<string-array name="clipboard_timeout_options">
|
||||
<item>30 seconds</item>
|
||||
|
||||
@@ -23,6 +23,26 @@
|
||||
<PreferenceCategory
|
||||
android:title="@string/general">
|
||||
|
||||
<SwitchPreference
|
||||
android:summary="@string/omitbackup_summary"
|
||||
android:defaultValue="@bool/omitbackup_default"
|
||||
android:title="@string/omitbackup_title"
|
||||
android:key="@string/omitbackup_key"/>
|
||||
<SwitchPreference
|
||||
android:summary="@string/use_saf_summary"
|
||||
android:defaultValue="@bool/saf_default"
|
||||
android:title="@string/use_saf_title"
|
||||
android:key="@string/saf_key"/>
|
||||
<SwitchPreference
|
||||
android:key="@string/clipboard_notifications_key"
|
||||
android:title="@string/clipboard_notifications_title"
|
||||
android:defaultValue="@bool/clipboard_notifications_default"
|
||||
android:summary="@string/clipboard_notifications_summary" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/lock">
|
||||
<ListPreference
|
||||
android:key="@string/clipboard_timeout_key"
|
||||
android:title="@string/clipboard_timeout"
|
||||
@@ -40,21 +60,10 @@
|
||||
android:dialogTitle="@string/app_timeout"
|
||||
android:defaultValue="@string/clipboard_timeout_default"/>
|
||||
<SwitchPreference
|
||||
android:summary="@string/omitbackup_summary"
|
||||
android:defaultValue="@bool/omitbackup_default"
|
||||
android:title="@string/omitbackup_title"
|
||||
android:key="@string/omitbackup_key"/>
|
||||
<SwitchPreference
|
||||
android:summary="@string/use_saf_summary"
|
||||
android:defaultValue="@bool/saf_default"
|
||||
android:title="@string/use_saf_title"
|
||||
android:key="@string/saf_key"/>
|
||||
<SwitchPreference
|
||||
android:key="@string/clipboard_notifications_key"
|
||||
android:title="@string/clipboard_notifications_title"
|
||||
android:defaultValue="@bool/clipboard_notifications_default"
|
||||
android:summary="@string/clipboard_notifications_summary" />
|
||||
|
||||
android:key="@string/lock_database_screen_off_key"
|
||||
android:title="@string/lock_database_screen_off_title"
|
||||
android:summary="@string/lock_database_screen_off_summary"
|
||||
android:defaultValue="@bool/lock_database_screen_off_default"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
||||
Reference in New Issue
Block a user