mirror of
https://github.com/beemdevelopment/Aegis
synced 2024-09-06 16:03:30 +00:00
Use VaultLockReceiver in a Context-registered manner
Turns out we can't listen from ACTION_SCREEN_OFF from a manifest-registered broadcast receiver
This commit is contained in:
parent
8292173297
commit
3d124d225e
|
@ -97,7 +97,6 @@
|
|||
<receiver android:name=".receivers.VaultLockReceiver" android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="${applicationId}.LOCK_VAULT" />
|
||||
<action android:name="android.intent.action.SCREEN_OFF" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Application;
|
|||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.graphics.drawable.Icon;
|
||||
|
@ -11,11 +12,13 @@ import android.os.Build;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleEventObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.ProcessLifecycleOwner;
|
||||
|
||||
import com.beemdevelopment.aegis.receivers.VaultLockReceiver;
|
||||
import com.beemdevelopment.aegis.ui.MainActivity;
|
||||
import com.beemdevelopment.aegis.util.IOUtils;
|
||||
import com.beemdevelopment.aegis.vault.VaultManager;
|
||||
|
@ -48,6 +51,10 @@ public abstract class AegisApplicationBase extends Application {
|
|||
Iconics.init(this);
|
||||
Iconics.registerFont(new MaterialDesignIconic());
|
||||
|
||||
VaultLockReceiver lockReceiver = new VaultLockReceiver();
|
||||
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
|
||||
ContextCompat.registerReceiver(this, lockReceiver, intentFilter, ContextCompat.RECEIVER_NOT_EXPORTED);
|
||||
|
||||
// lock the app if the user moves the application to the background
|
||||
ProcessLifecycleOwner.get().getLifecycle().addObserver(new AppLifecycleObserver());
|
||||
|
||||
|
|
|
@ -22,8 +22,9 @@ public class VaultLockReceiver extends BroadcastReceiver {
|
|||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (!intent.getAction().equals(ACTION_LOCK_VAULT)
|
||||
&& !intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||
if (intent.getAction() == null
|
||||
|| (!intent.getAction().equals(ACTION_LOCK_VAULT)
|
||||
&& !intent.getAction().equals(Intent.ACTION_SCREEN_OFF))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,14 +29,14 @@ public class NotificationService extends Service {
|
|||
|
||||
@SuppressLint("LaunchActivityFromNotification")
|
||||
public void serviceMethod() {
|
||||
Intent intent = new Intent(this, VaultLockReceiver.class);
|
||||
intent.setAction(VaultLockReceiver.ACTION_LOCK_VAULT);
|
||||
intent.setPackage(BuildConfig.APPLICATION_ID);
|
||||
|
||||
int flags = PendingIntent.FLAG_ONE_SHOT;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
flags |= PendingIntent.FLAG_IMMUTABLE;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, VaultLockReceiver.class);
|
||||
intent.setAction(VaultLockReceiver.ACTION_LOCK_VAULT);
|
||||
intent.setPackage(BuildConfig.APPLICATION_ID);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intent, flags);
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
|
||||
|
|
Loading…
Reference in a new issue