Self-grant notification access

This commit is contained in:
Peter Cai 2023-04-26 14:31:30 -04:00
parent 9210b09b7a
commit 4650e3d679
2 changed files with 13 additions and 0 deletions

View file

@ -25,6 +25,7 @@
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.MANAGE_NOTIFICATION_LISTENERS" />
<uses-sdk
android:minSdkVersion="31"

View file

@ -18,6 +18,8 @@
package net.typeblog.lunatic.Utils;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.PowerExemptionManager;
@ -118,6 +120,16 @@ public final class ServiceUtils {
PowerExemptionManager pem = context.getSystemService(PowerExemptionManager.class);
pem.addToPermanentAllowList("net.typeblog.lunatic");
// Self-grant notification access because why not :)
NotificationManager nm = context.getSystemService(NotificationManager.class);
try {
Method setNotificationListenerAccessGranted = NotificationManager.class.getMethod("setNotificationListenerAccessGranted",
ComponentName.class, boolean.class, boolean.class);
setNotificationListenerAccessGranted.invoke(nm, new ComponentName(context, NotificationService.class), true, true);
} catch (Exception e) {
throw new RuntimeException(e);
}
AnimationManager animationManager = new AnimationManager(context);
if (SettingsManager.isSpotlightEnabled(context)) {