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

Commit 4bb2de25 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Inflate and strip remote views for pre-N apps." into nyc-dev

parents 5cac50c3 d4ea741d
Loading
Loading
Loading
Loading
+76 −18
Original line number Diff line number Diff line
@@ -263,8 +263,8 @@ public class Notification implements Parcelable
     * The view that will represent this notification in the notification list (which is pulled
     * down from the status bar).
     *
     * As of N, this field is not used. The notification view is determined by the inputs to
     * {@link Notification.Builder}; a custom RemoteViews can optionally be
     * As of N, this field may be null. The notification view is determined by the inputs
     * to {@link Notification.Builder}; a custom RemoteViews can optionally be
     * supplied with {@link Notification.Builder#setCustomContentView(RemoteViews)}.
     */
    @Deprecated
@@ -275,7 +275,7 @@ public class Notification implements Parcelable
     * opportunity to show more detail. The system UI may choose to show this
     * instead of the normal content view at its discretion.
     *
     * As of N, this field is not used. The expanded notification view is determined by the
     * As of N, this field may be null. The expanded notification view is determined by the
     * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be
     * supplied with {@link Notification.Builder#setCustomBigContentView(RemoteViews)}.
     */
@@ -289,7 +289,7 @@ public class Notification implements Parcelable
     * choose to show this as a heads-up notification, which will pop up so the user can see
     * it without leaving their current activity.
     *
     * As of N, this field is not used. The heads-up notification view is determined by the
     * As of N, this field may be null. The heads-up notification view is determined by the
     * inputs to {@link Notification.Builder}; a custom RemoteViews can optionally be
     * supplied with {@link Notification.Builder#setCustomHeadsUpContentView(RemoteViews)}.
     */
@@ -2129,8 +2129,23 @@ public class Notification implements Parcelable
     * </pre>
     */
    public static class Builder {
        /**
         * @hide
         */
        public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT =
                "android.rebuild.contentViewActionCount";
        /**
         * @hide
         */
        public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT
                = "android.rebuild.bigViewActionCount";
        /**
         * @hide
         */
        public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT
                = "android.rebuild.hudViewActionCount";

        private static final int MAX_ACTION_BUTTONS = 3;
        private static final float LARGE_TEXT_SCALE = 1.3f;

        private Context mContext;
        private Notification mN;
@@ -3566,19 +3581,6 @@ public class Notification implements Parcelable
            return null;
        }

        private void setBuilderContentView(Notification n, RemoteViews contentView) {
            n.contentView = contentView;
        }

        private void setBuilderBigContentView(Notification n, RemoteViews bigContentView) {
            n.bigContentView = bigContentView;
        }

        private void setBuilderHeadsUpContentView(Notification n,
                RemoteViews headsUpContentView) {
            n.headsUpContentView = headsUpContentView;
        }

        /**
         * @deprecated Use {@link #build()} instead.
         */
@@ -3606,6 +3608,28 @@ public class Notification implements Parcelable
                mStyle.buildStyled(mN);
            }

            if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) {
                if (mN.contentView == null) {
                    mN.contentView = makeContentView();
                    mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT,
                            mN.contentView.getSequenceNumber());
                }
                if (mN.bigContentView == null) {
                    mN.bigContentView = makeBigContentView();
                    if (mN.bigContentView != null) {
                        mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT,
                                mN.bigContentView.getSequenceNumber());
                    }
                }
                if (mN.headsUpContentView == null) {
                    mN.headsUpContentView = makeHeadsUpContentView();
                    if (mN.headsUpContentView != null) {
                        mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT,
                                mN.headsUpContentView.getSequenceNumber());
                    }
                }
            }

            if ((mN.defaults & DEFAULT_LIGHTS) != 0) {
                mN.flags |= FLAG_SHOW_LIGHTS;
            }
@@ -3623,6 +3647,40 @@ public class Notification implements Parcelable
            return n;
        }

        /**
         * @hide
         */
        public static void stripForDelivery(Notification n) {
            String templateClass = n.extras.getString(EXTRA_TEMPLATE);
            if (TextUtils.isEmpty(templateClass)) {
                return;
            }
            // Only strip views for known Styles because we won't know how to
            // re-create them otherwise.
            if (getNotificationStyleClass(templateClass) == null) {
                return;
            }
            // Get rid of unmodified BuilderRemoteViews.
            if (n.contentView instanceof BuilderRemoteViews &&
                    n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) ==
                            n.contentView.getSequenceNumber()) {
                n.contentView = null;
                n.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT);
            }
            if (n.bigContentView instanceof BuilderRemoteViews &&
                    n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) ==
                            n.bigContentView.getSequenceNumber()) {
                n.bigContentView = null;
                n.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT);
            }
            if (n.headsUpContentView instanceof BuilderRemoteViews &&
                    n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) ==
                            n.headsUpContentView.getSequenceNumber()) {
                n.headsUpContentView = null;
                n.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT);
            }
        }

        private int getBaseLayoutResource() {
            return R.layout.notification_template_material_base;
        }
+1 −0
Original line number Diff line number Diff line
@@ -246,6 +246,7 @@ public class NotificationManager
        }
        if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")");
        final Notification copy = notification.clone();
        Builder.stripForDelivery(copy);
        try {
            service.enqueueNotificationWithTag(pkg, mContext.getOpPackageName(), tag, id,
                    copy, idOut, user.getIdentifier());