Refactor lock

This commit is contained in:
J-Jamet
2018-06-06 19:11:20 +02:00
parent ef8db46ae7
commit 37ca15b77c
11 changed files with 40 additions and 30 deletions

View File

@@ -134,11 +134,13 @@
android:configChanges="orientation|keyboardHidden" /> android:configChanges="orientation|keyboardHidden" />
<activity android:name="com.kunzisoft.keepass.settings.SettingsAutofillActivity" /> <activity android:name="com.kunzisoft.keepass.settings.SettingsAutofillActivity" />
<service android:name="com.kunzisoft.keepass.timeout.TimeoutService" /> <!-- Receiver for lock-->
<service android:name="com.kunzisoft.keepass.lock.LockService" />
<service <service
android:name="com.kunzisoft.keepass.notifications.NotificationCopyingService" android:name="com.kunzisoft.keepass.notifications.NotificationCopyingService"
android:enabled="true" android:enabled="true"
android:exported="false" /> android:exported="false" />
<!-- Receiver for Autofill -->
<service <service
android:name="com.kunzisoft.keepass.autofill.KeeAutofillService" android:name="com.kunzisoft.keepass.autofill.KeeAutofillService"
android:label="@string/autofill_service_name" android:label="@string/autofill_service_name"
@@ -146,11 +148,11 @@
<meta-data <meta-data
android:name="android.autofill" android:name="android.autofill"
android:resource="@xml/dataset_service" /> android:resource="@xml/dataset_service" />
<intent-filter> <intent-filter>
<action android:name="android.service.autofill.AutofillService" /> <action android:name="android.service.autofill.AutofillService" />
</intent-filter> </intent-filter>
</service> </service>
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" /> <meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
</application> </application>
</manifest> </manifest>

View File

@@ -47,6 +47,8 @@ import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.security.ProtectedString; import com.kunzisoft.keepass.database.security.ProtectedString;
import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.lock.LockingActivity;
import com.kunzisoft.keepass.lock.LockingHideActivity;
import com.kunzisoft.keepass.notifications.NotificationCopyingService; import com.kunzisoft.keepass.notifications.NotificationCopyingService;
import com.kunzisoft.keepass.notifications.NotificationField; import com.kunzisoft.keepass.notifications.NotificationField;
import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.settings.PreferencesUtil;

View File

@@ -57,6 +57,8 @@ import com.kunzisoft.keepass.database.security.ProtectedString;
import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment; import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment;
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment; import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.lock.LockingActivity;
import com.kunzisoft.keepass.lock.LockingHideActivity;
import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus; import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;

View File

@@ -41,6 +41,7 @@ import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum; import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment; import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.SortDialogFragment; import com.kunzisoft.keepass.dialogs.SortDialogFragment;
import com.kunzisoft.keepass.lock.LockingActivity;
import com.kunzisoft.keepass.password.AssignPasswordHelper; import com.kunzisoft.keepass.password.AssignPasswordHelper;
import com.kunzisoft.keepass.utils.MenuUtil; import com.kunzisoft.keepass.utils.MenuUtil;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft. * Copyright 2018 Jeremy Jamet / Kunzisoft.
* *
* This file is part of KeePass DX. * This file is part of KeePass DX.
* *
@@ -17,7 +17,7 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.timeout; package com.kunzisoft.keepass.lock;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.Service; import android.app.Service;
@@ -31,38 +31,42 @@ import android.util.Log;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
public class TimeoutService extends Service { public class LockService extends Service {
private static final String TAG = LockService.class.getName();
public static final String LOCK_ACTION = "com.kunzisoft.keepass.LOCK";
private static final String TAG = TimeoutService.class.getName();
private BroadcastReceiver mIntentReceiver; private BroadcastReceiver mIntentReceiver;
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
mIntentReceiver = new BroadcastReceiver() { mIntentReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
if ( action != null && action.equals(Timeout.TIMEOUT) ) { if ( action != null &&
timeout(); action.equals(LOCK_ACTION)
) {
lock();
} }
} }
}; };
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(Timeout.TIMEOUT); filter.addAction(LOCK_ACTION);
registerReceiver(mIntentReceiver, filter); registerReceiver(mIntentReceiver, filter);
} }
@Override @Override
public void onStart(Intent intent, int startId) { public void onStart(Intent intent, int startId) {
super.onStart(intent, startId); super.onStart(intent, startId);
Log.d(TAG, "Timeout service started"); Log.d(TAG, "Lock service started");
} }
private void timeout() { private void lock() {
Log.d(TAG, "Timeout"); Log.d(TAG, "Lock");
App.setShutdown(); App.setShutdown();
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (nm != null) if (nm != null)
@@ -73,17 +77,17 @@ public class TimeoutService extends Service {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
Log.d(TAG, "Timeout service stopped"); Log.d(TAG, "Lock service stopped");
unregisterReceiver(mIntentReceiver); unregisterReceiver(mIntentReceiver);
} }
public class TimeoutBinder extends Binder { public class LockBinder extends Binder {
public TimeoutService getService() { public LockService getService() {
return TimeoutService.this; return LockService.this;
} }
} }
private final IBinder mBinder = new TimeoutBinder(); private final IBinder mBinder = new LockBinder();
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {

View File

@@ -17,7 +17,7 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.activities; package com.kunzisoft.keepass.lock;
import android.app.Activity; import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;

View File

@@ -17,7 +17,7 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.activities; package com.kunzisoft.keepass.lock;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;

View File

@@ -56,7 +56,7 @@ import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView; import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.GroupActivity; import com.kunzisoft.keepass.activities.GroupActivity;
import com.kunzisoft.keepass.activities.LockingActivity; import com.kunzisoft.keepass.lock.LockingActivity;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.autofill.AutofillHelper; import com.kunzisoft.keepass.autofill.AutofillHelper;
import com.kunzisoft.keepass.compat.ClipDataCompat; import com.kunzisoft.keepass.compat.ClipDataCompat;

View File

@@ -28,7 +28,7 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem; import android.view.MenuItem;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.LockingActivity; import com.kunzisoft.keepass.lock.LockingActivity;
public class SettingsActivity extends LockingActivity implements MainPreferenceFragment.Callback { public class SettingsActivity extends LockingActivity implements MainPreferenceFragment.Callback {

View File

@@ -28,17 +28,16 @@ import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.lock.LockService;
public class Timeout { public class Timeout {
public static final String TIMEOUT = "com.kunzisoft.keepass.timeout";
private static final int REQUEST_ID = 0; private static final int REQUEST_ID = 0;
private static final long DEFAULT_TIMEOUT = 5 * 60 * 1000; // 5 minutes private static final long DEFAULT_TIMEOUT = 5 * 60 * 1000; // 5 minutes
private static String TAG = "KeePass Timeout"; private static String TAG = "KeePass Timeout";
private static PendingIntent buildIntent(Context ctx) { private static PendingIntent buildIntent(Context ctx) {
Intent intent = new Intent(TIMEOUT); Intent intent = new Intent(LockService.LOCK_ACTION);
return PendingIntent.getBroadcast(ctx, REQUEST_ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); return PendingIntent.getBroadcast(ctx, REQUEST_ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);
} }
@@ -58,7 +57,7 @@ public class Timeout {
return; return;
} }
ctx.startService(new Intent(ctx, TimeoutService.class)); ctx.startService(new Intent(ctx, LockService.class));
long triggerTime = System.currentTimeMillis() + timeout; long triggerTime = System.currentTimeMillis() + timeout;
AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
@@ -77,7 +76,7 @@ public class Timeout {
am.cancel(buildIntent(ctx)); am.cancel(buildIntent(ctx));
} }
ctx.stopService(new Intent(ctx, TimeoutService.class)); ctx.stopService(new Intent(ctx, LockService.class));
} }
} }

View File

@@ -24,7 +24,7 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.LockingActivity; import com.kunzisoft.keepass.lock.LockingActivity;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
public class TimeoutHelper { public class TimeoutHelper {