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

Commit 2ce46560 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Add a setting to test the new notification rules on existing apps.

Test: manual
Change-Id: I560ac597bf8e8320d1d9e404ffcf1e6464cfe82d
parent c7c4e4a7
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.LocusId;
@@ -11198,4 +11199,33 @@ public class Notification implements Parcelable
            return this;
        }
    }

    /**
     * A class to centrally access various developer flags related to notifications.
     * This class is a non-final wrapper around Settings.Global which allows mocking for unit tests.
     * TODO(b/176239013): Try to remove this before shipping S
     * @hide
     */
    public static class DevFlags {
        private static final boolean DEFAULT_BACKPORT_S_NOTIF_RULES = false;

        /**
         * Used by unit tests to force that this class returns its default values, which is required
         * in cases where the ContentResolver instance is a mock.
         * @hide
         */
        public static boolean sForceDefaults;

        /**
         * @return if the S notification rules should be backported to apps not yet targeting S
         * @hide
         */
        public static boolean shouldBackportSNotifRules(@NonNull ContentResolver contentResolver) {
            if (sForceDefaults) {
                return DEFAULT_BACKPORT_S_NOTIF_RULES;
            }
            return Settings.Global.getInt(contentResolver, Settings.Global.BACKPORT_S_NOTIF_RULES,
                        DEFAULT_BACKPORT_S_NOTIF_RULES ? 1 : 0) == 1;
        }
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -14540,6 +14540,20 @@ public final class Settings {
         */
        public static final String SHOW_NEW_NOTIF_DISMISS = "show_new_notif_dismiss";
        /**
         * Whether to enforce the new notification rules (aka rules that are only applied to
         * notifications from apps targeting S) on all notifications.
         * - Collapsed custom view notifications will get the new 76dp height instead of 106dp.
         * - Custom view notifications will be partially decorated.
         * - Large icons will be given an aspect ratio of up to 16:9.
         *
         * Values are:
         * 0: Disabled (Only apps targeting S will receive the new rules)
         * 1: Enabled (All apps will receive the new rules)
         * @hide
         */
        public static final String BACKPORT_S_NOTIF_RULES = "backport_s_notif_rules";
        /**
         * Block untrusted touches mode.
         *
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ public class SettingsBackupTest {
                    Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS,
                    Settings.Global.AUTOMATIC_POWER_SAVE_MODE,
                    Settings.Global.AVERAGE_TIME_TO_DISCHARGE,
                    Settings.Global.BACKPORT_S_NOTIF_RULES,
                    Settings.Global.BATTERY_CHARGING_STATE_UPDATE_DELAY,
                    Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME,
                    Settings.Global.BROADCAST_BG_CONSTANTS,
+5 −0
Original line number Diff line number Diff line
@@ -650,6 +650,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
        boolean beforeP = mEntry.targetSdk < Build.VERSION_CODES.P;
        boolean beforeS = mEntry.targetSdk < Build.VERSION_CODES.S;
        if (Notification.DevFlags.shouldBackportSNotifRules(mContext.getContentResolver())) {
            // When back-porting S rules, if an app targets P/Q/R then enforce the new S rule on
            // that notification.  If it's before P though, we still want to enforce legacy rules.
            beforeS = beforeP;
        }
        int smallHeight;

        View expandedView = layout.getExpandedChild();