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

Commit a6075e69 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "testing_s_notifications"

* changes:
  Apps targeting S can't be exempt from having an expanded view.
  Add a setting to test the new notification rules on existing apps.
parents 3507a65f a5de0583
Loading
Loading
Loading
Loading
+44 −1
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;
@@ -5146,6 +5147,11 @@ public class Notification implements Parcelable
                contentView.setViewVisibility(R.id.right_icon, View.VISIBLE);
                contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon);
                processLargeLegacyIcon(mN.mLargeIcon, contentView, p);
            } else {
                // The "reset" doesn't clear the drawable, so we do it here.  This clear is
                // important because the presence of a drawable in this view (regardless of the
                // visibility) is used by NotificationGroupingUtil to set the visibility.
                contentView.setImageViewIcon(R.id.right_icon, null);
            }
            return showLargeIcon;
        }
@@ -5525,9 +5531,17 @@ public class Notification implements Parcelable
            return result;
        }

        // This code is executed on behalf of other apps' notifications, sometimes even by 3p apps,
        // a use case that is not supported by the Compat Framework library.  Workarounds to resolve
        // the change's state in NotificationManagerService were very complex. While it's possible
        // apps can detect the change, it's most likely that the changes will simply result in
        // visual regressions.
        @SuppressWarnings("AndroidFrameworkCompatChange")
        private boolean bigContentViewRequired() {
            if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.S) {
                return true;
            }
            // If the big content view has no content, we can exempt the app from having to show it.
            // TODO(b/173550917): add an UNDO style then force this requirement on apps targeting S
            boolean exempt = mN.contentView != null && mN.bigContentView == null
                    && mStyle == null && mActions.size() == 0
                    && mN.extras.getCharSequence(EXTRA_TITLE) == null
@@ -11198,4 +11212,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
@@ -14572,6 +14572,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();