Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c6eef21 authored by Geoffrey Pitsch's avatar Geoffrey Pitsch
Browse files

Developer setting to show toast for notifications without a channel

Bug: 37945054
Test: runtest systemui-notification
Change-Id: I264913c3d7ef6fcd83129b0692e96d3218bc7217
parent 78e03b44
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -10388,6 +10388,15 @@ public final class Settings {
         */
        public static final String MAX_NOTIFICATION_ENQUEUE_RATE = "max_notification_enqueue_rate";

        /**
         * Displays toasts when an app posts a notification that does not specify a valid channel.
         *
         * The value 1 - enable, 0 - disable
         * @hide
         */
        public static final String SHOW_NOTIFICATION_CHANNEL_WARNINGS =
                "show_notification_channel_warnings";

        /**
         * Whether cell is enabled/disabled
         * @hide
+5 −5
Original line number Diff line number Diff line
@@ -3199,10 +3199,8 @@ public class NotificationManagerService extends SystemService {
                    + ", incomingUserId=" + incomingUserId
                    + ", notificationUid=" + notificationUid
                    + ", notification=" + notification;
            // STOPSHIP TODO: should throw instead of logging or toasting.
            // throw new IllegalArgumentException(noChannelStr);
            Log.e(TAG, noChannelStr);
            doDebugOnlyToast("Developer warning for package \"" + pkg + "\"\n" +
            doChannelWarningToast("Developer warning for package \"" + pkg + "\"\n" +
                    "Failed to post notification on channel \"" + channelId + "\"\n" +
                    "See log for more details");
            return;
@@ -3238,8 +3236,10 @@ public class NotificationManagerService extends SystemService {
        mHandler.post(new EnqueueNotificationRunnable(userId, r));
    }

    private void doDebugOnlyToast(CharSequence toastText) {
        if (Build.IS_DEBUGGABLE) {
    private void doChannelWarningToast(CharSequence toastText) {
        final boolean warningEnabled = Settings.System.getInt(getContext().getContentResolver(),
                Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, 0) != 0;
        if (warningEnabled || Build.IS_DEBUGGABLE) {
            try {
                Toast toast = Toast.makeText(getContext(), toastText, Toast.LENGTH_LONG);
                toast.show();