mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Refactor lock
This commit is contained in:
@@ -134,11 +134,13 @@
|
||||
android:configChanges="orientation|keyboardHidden" />
|
||||
<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
|
||||
android:name="com.kunzisoft.keepass.notifications.NotificationCopyingService"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
<!-- Receiver for Autofill -->
|
||||
<service
|
||||
android:name="com.kunzisoft.keepass.autofill.KeeAutofillService"
|
||||
android:label="@string/autofill_service_name"
|
||||
@@ -146,11 +148,11 @@
|
||||
<meta-data
|
||||
android:name="android.autofill"
|
||||
android:resource="@xml/dataset_service" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.service.autofill.AutofillService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -47,6 +47,8 @@ import com.kunzisoft.keepass.database.PwDatabase;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass.database.security.ProtectedString;
|
||||
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.NotificationField;
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||
|
||||
@@ -57,6 +57,8 @@ import com.kunzisoft.keepass.database.security.ProtectedString;
|
||||
import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment;
|
||||
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
|
||||
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.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.kunzisoft.keepass.database.PwNode;
|
||||
import com.kunzisoft.keepass.database.SortNodeEnum;
|
||||
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
|
||||
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
|
||||
import com.kunzisoft.keepass.lock.LockingActivity;
|
||||
import com.kunzisoft.keepass.password.AssignPasswordHelper;
|
||||
import com.kunzisoft.keepass.utils.MenuUtil;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* 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.Service;
|
||||
@@ -31,38 +31,42 @@ import android.util.Log;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
|
||||
mIntentReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if ( action != null && action.equals(Timeout.TIMEOUT) ) {
|
||||
timeout();
|
||||
if ( action != null &&
|
||||
action.equals(LOCK_ACTION)
|
||||
) {
|
||||
lock();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Timeout.TIMEOUT);
|
||||
filter.addAction(LOCK_ACTION);
|
||||
registerReceiver(mIntentReceiver, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId) {
|
||||
super.onStart(intent, startId);
|
||||
Log.d(TAG, "Timeout service started");
|
||||
Log.d(TAG, "Lock service started");
|
||||
}
|
||||
|
||||
private void timeout() {
|
||||
Log.d(TAG, "Timeout");
|
||||
private void lock() {
|
||||
Log.d(TAG, "Lock");
|
||||
App.setShutdown();
|
||||
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
if (nm != null)
|
||||
@@ -73,17 +77,17 @@ public class TimeoutService extends Service {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.d(TAG, "Timeout service stopped");
|
||||
Log.d(TAG, "Lock service stopped");
|
||||
unregisterReceiver(mIntentReceiver);
|
||||
}
|
||||
|
||||
public class TimeoutBinder extends Binder {
|
||||
public TimeoutService getService() {
|
||||
return TimeoutService.this;
|
||||
public class LockBinder extends Binder {
|
||||
public LockService getService() {
|
||||
return LockService.this;
|
||||
}
|
||||
}
|
||||
|
||||
private final IBinder mBinder = new TimeoutBinder();
|
||||
private final IBinder mBinder = new LockBinder();
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
@@ -17,7 +17,7 @@
|
||||
* 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.content.BroadcastReceiver;
|
||||
@@ -17,7 +17,7 @@
|
||||
* 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.Intent;
|
||||
@@ -56,7 +56,7 @@ import com.getkeepsafe.taptargetview.TapTarget;
|
||||
import com.getkeepsafe.taptargetview.TapTargetView;
|
||||
import com.kunzisoft.keepass.R;
|
||||
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.autofill.AutofillHelper;
|
||||
import com.kunzisoft.keepass.compat.ClipDataCompat;
|
||||
|
||||
@@ -28,7 +28,7 @@ import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
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 {
|
||||
|
||||
@@ -28,17 +28,16 @@ import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.lock.LockService;
|
||||
|
||||
public class Timeout {
|
||||
|
||||
public static final String TIMEOUT = "com.kunzisoft.keepass.timeout";
|
||||
|
||||
private static final int REQUEST_ID = 0;
|
||||
private static final long DEFAULT_TIMEOUT = 5 * 60 * 1000; // 5 minutes
|
||||
private static String TAG = "KeePass Timeout";
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -58,7 +57,7 @@ public class Timeout {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.startService(new Intent(ctx, TimeoutService.class));
|
||||
ctx.startService(new Intent(ctx, LockService.class));
|
||||
|
||||
long triggerTime = System.currentTimeMillis() + timeout;
|
||||
AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
|
||||
@@ -77,7 +76,7 @@ public class Timeout {
|
||||
am.cancel(buildIntent(ctx));
|
||||
}
|
||||
|
||||
ctx.stopService(new Intent(ctx, TimeoutService.class));
|
||||
ctx.stopService(new Intent(ctx, LockService.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.activities.LockingActivity;
|
||||
import com.kunzisoft.keepass.lock.LockingActivity;
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
|
||||
public class TimeoutHelper {
|
||||
|
||||
Reference in New Issue
Block a user