Fix shortcut pinned receiver for Android 14 (#2694)

This commit is contained in:
Howard Wu 2023-08-18 10:32:38 +08:00 committed by GitHub
parent 0b27b23952
commit 5af39a01b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 18 deletions

View File

@ -134,23 +134,16 @@ public class SettingsFragment extends BaseFragment {
parentFragment = null; parentFragment = null;
} }
@Override private boolean setNotificationPreferenceEnabled(MaterialSwitchPreference notificationPreference, boolean preferenceEnabled) {
public void onResume() { var notificationEnabled = ConfigManager.enableStatusNotification();
super.onResume();
MaterialSwitchPreference notificationPreference = findPreference("enable_status_notification");
if (App.isParasitic && notificationPreference != null && notificationPreference.isVisible()) {
setNotificationPreferenceEnabled(notificationPreference, ShortcutUtil.isLaunchShortcutPinned());
}
}
private void setNotificationPreferenceEnabled(MaterialSwitchPreference notificationPreference, boolean enabled) {
if (notificationPreference != null) { if (notificationPreference != null) {
notificationPreference.setEnabled(!ConfigManager.enableStatusNotification() || enabled); notificationPreference.setEnabled(!notificationEnabled || preferenceEnabled);
notificationPreference.setSummaryOn(enabled ? notificationPreference.setSummaryOn(preferenceEnabled ?
notificationPreference.getContext().getString(R.string.settings_enable_status_notification_summary) : notificationPreference.getContext().getString(R.string.settings_enable_status_notification_summary) :
notificationPreference.getContext().getString(R.string.settings_enable_status_notification_summary) + "\n" + notificationPreference.getContext().getString(R.string.settings_enable_status_notification_summary) + "\n" +
notificationPreference.getContext().getString(R.string.disable_status_notification_error)); notificationPreference.getContext().getString(R.string.disable_status_notification_error));
} }
return notificationEnabled;
} }
@Override @Override
@ -179,16 +172,16 @@ public class SettingsFragment extends BaseFragment {
MaterialSwitchPreference notificationPreference = findPreference("enable_status_notification"); MaterialSwitchPreference notificationPreference = findPreference("enable_status_notification");
if (notificationPreference != null) { if (notificationPreference != null) {
if (App.isParasitic && !ShortcutUtil.isLaunchShortcutPinned()) {
setNotificationPreferenceEnabled(notificationPreference, false);
}
notificationPreference.setVisible(installed); notificationPreference.setVisible(installed);
notificationPreference.setChecked(installed && ConfigManager.enableStatusNotification()); if (installed && App.isParasitic) {
notificationPreference.setChecked(setNotificationPreferenceEnabled(notificationPreference, ShortcutUtil.isLaunchShortcutPinned()));
}
notificationPreference.setOnPreferenceChangeListener((p, v) -> { notificationPreference.setOnPreferenceChangeListener((p, v) -> {
var succeeded = ConfigManager.setEnableStatusNotification((boolean) v);
if ((boolean) v && App.isParasitic && !ShortcutUtil.isLaunchShortcutPinned()) { if ((boolean) v && App.isParasitic && !ShortcutUtil.isLaunchShortcutPinned()) {
setNotificationPreferenceEnabled(notificationPreference, false); setNotificationPreferenceEnabled(notificationPreference, false);
} }
return ConfigManager.setEnableStatusNotification((boolean) v); return succeeded;
}); });
} }

View File

@ -115,7 +115,7 @@ public class ShortcutUtil {
} }
}; };
context.registerReceiver(receiver, filter, permission, context.registerReceiver(receiver, filter, permission,
null/* main thread */, Context.RECEIVER_NOT_EXPORTED); null/* main thread */, Context.RECEIVER_EXPORTED);
var intent = new Intent(uuid); var intent = new Intent(uuid);
int flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE; int flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;