Support config change

This commit is contained in:
vvb2060 2022-12-03 13:47:01 +08:00 committed by LoveSy
parent b0bf38a8aa
commit d1ea380898
3 changed files with 25 additions and 2 deletions

View File

@ -86,6 +86,15 @@ public class LSPNotificationManager {
return Icon.createWithBitmap(getBitmap(R.drawable.ic_notification)); return Icon.createWithBitmap(getBitmap(R.drawable.ic_notification));
} }
private static boolean hasNotificationChannelForSystem(
INotificationManager nm, String channelId) throws RemoteException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return nm.getNotificationChannelForPackage("android", 1000, channelId, null, false) != null;
} else {
return nm.getNotificationChannelForPackage("android", 1000, channelId, false) != null;
}
}
private static void createNotificationChannel(INotificationManager nm) throws RemoteException { private static void createNotificationChannel(INotificationManager nm) throws RemoteException {
var context = new FakeContext(); var context = new FakeContext();
var list = new ArrayList<NotificationChannel>(); var list = new ArrayList<NotificationChannel>();
@ -94,13 +103,21 @@ public class LSPNotificationManager {
context.getString(R.string.module_updated_channel_name), context.getString(R.string.module_updated_channel_name),
NotificationManager.IMPORTANCE_HIGH); NotificationManager.IMPORTANCE_HIGH);
updated.setShowBadge(false); updated.setShowBadge(false);
list.add(updated); if (hasNotificationChannelForSystem(nm, UPDATED_CHANNEL_ID)) {
nm.updateNotificationChannelForPackage("android", 1000, updated);
} else {
list.add(updated);
}
var status = new NotificationChannel(STATUS_CHANNEL_ID, var status = new NotificationChannel(STATUS_CHANNEL_ID,
context.getString(R.string.status_channel_name), context.getString(R.string.status_channel_name),
NotificationManager.IMPORTANCE_MIN); NotificationManager.IMPORTANCE_MIN);
status.setShowBadge(false); status.setShowBadge(false);
list.add(status); if (hasNotificationChannelForSystem(nm, STATUS_CHANNEL_ID)) {
nm.updateNotificationChannelForPackage("android", 1000, status);
} else {
list.add(status);
}
nm.createNotificationChannelsForPackage("android", 1000, new ParceledListSlice<>(list)); nm.createNotificationChannelsForPackage("android", 1000, new ParceledListSlice<>(list));
} }

View File

@ -209,6 +209,10 @@ public class LSPosedService extends ILSPosedService.Stub {
private void dispatchConfigurationChanged(Intent intent) { private void dispatchConfigurationChanged(Intent intent) {
ConfigFileManager.reloadConfiguration(); ConfigFileManager.reloadConfiguration();
var configManager = ConfigManager.getInstance();
if (configManager.enableStatusNotification()) {
LSPNotificationManager.notifyStatusNotification();
}
} }
private void dispatchSecretCodeReceive(Intent i) { private void dispatchSecretCodeReceive(Intent i) {

View File

@ -19,6 +19,8 @@ public interface INotificationManager extends IInterface {
void createNotificationChannelsForPackage(String pkg, int uid, ParceledListSlice<NotificationChannel> channelsList) throws RemoteException; void createNotificationChannelsForPackage(String pkg, int uid, ParceledListSlice<NotificationChannel> channelsList) throws RemoteException;
void updateNotificationChannelForPackage(String pkg, int uid, NotificationChannel channel);
@RequiresApi(30) @RequiresApi(30)
NotificationChannel getNotificationChannelForPackage(String pkg, int uid, String channelId, String conversationId, boolean includeDeleted) throws RemoteException; NotificationChannel getNotificationChannelForPackage(String pkg, int uid, String channelId, String conversationId, boolean includeDeleted) throws RemoteException;