Skip to content

Commit

Permalink
Lock on minimize in case ALWAYS_FINISH_ACTIVITIES is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbakker committed Dec 31, 2024
1 parent 920df1d commit 4b29b94
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.provider.Settings;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
Expand All @@ -17,23 +18,14 @@
import androidx.lifecycle.LifecycleEventObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ProcessLifecycleOwner;
import androidx.room.Room;

import com.beemdevelopment.aegis.database.AppDatabase;
import com.beemdevelopment.aegis.database.AuditLogEntry;
import com.beemdevelopment.aegis.database.AuditLogRepository;
import com.beemdevelopment.aegis.receivers.VaultLockReceiver;
import com.beemdevelopment.aegis.ui.MainActivity;
import com.beemdevelopment.aegis.util.IOUtils;
import com.beemdevelopment.aegis.vault.VaultManager;
import com.topjohnwu.superuser.Shell;

import org.checkerframework.checker.units.qual.A;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import dagger.hilt.InstallIn;
import dagger.hilt.android.EarlyEntryPoint;
Expand Down Expand Up @@ -114,9 +106,16 @@ private void initNotificationChannels() {
private class AppLifecycleObserver implements LifecycleEventObserver {
@Override
public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
if (event == Lifecycle.Event.ON_STOP
&& _vaultManager.isAutoLockEnabled(Preferences.AUTO_LOCK_ON_MINIMIZE)
&& !_vaultManager.isAutoLockBlocked()) {
if (event != Lifecycle.Event.ON_STOP ) {
return;
}

// Immediately lock if "Don't keep activities" is enabled to work around an issue where
// MainActivity is destroyed before the ACTION_SCREEN_OFF intent is received
boolean lockOnMinimize = _vaultManager.isAutoLockEnabled(Preferences.AUTO_LOCK_ON_MINIMIZE)
|| Settings.Global.getInt(getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0;

if (lockOnMinimize && !_vaultManager.isAutoLockBlocked()) {
_vaultManager.lock(false);
}
}
Expand Down

0 comments on commit 4b29b94

Please sign in to comment.