Merge "Add shouldBeSeamless param to Surface.setFrameRate"
diff --git a/config/hiddenapi-max-target-o.txt b/config/hiddenapi-max-target-o.txt
index 023bf38..592b4ae 100644
--- a/config/hiddenapi-max-target-o.txt
+++ b/config/hiddenapi-max-target-o.txt
@@ -91659,8 +91659,6 @@
 Lcom/android/internal/R$dimen;->notification_header_app_name_margin_start:I
 Lcom/android/internal/R$dimen;->notification_header_background_height:I
 Lcom/android/internal/R$dimen;->notification_header_expand_icon_size:I
-Lcom/android/internal/R$dimen;->notification_header_height:I
-Lcom/android/internal/R$dimen;->notification_header_icon_margin_end:I
 Lcom/android/internal/R$dimen;->notification_header_icon_size:I
 Lcom/android/internal/R$dimen;->notification_header_separating_margin:I
 Lcom/android/internal/R$dimen;->notification_header_shrink_min_width:I
@@ -92444,7 +92442,6 @@
 Lcom/android/internal/R$id;->replaceText:I
 Lcom/android/internal/R$id;->replace_app_icon:I
 Lcom/android/internal/R$id;->replace_message:I
-Lcom/android/internal/R$id;->reply_icon_action:I
 Lcom/android/internal/R$id;->resolver_list:I
 Lcom/android/internal/R$id;->rew:I
 Lcom/android/internal/R$id;->rightSpacer:I
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index e5d17d0..70b7d22 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -384,6 +384,7 @@
     private static final ArraySet<Integer> STANDARD_LAYOUTS = new ArraySet<>();
     static {
         STANDARD_LAYOUTS.add(R.layout.notification_template_material_base);
+        STANDARD_LAYOUTS.add(R.layout.notification_template_material_heads_up_base);
         STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_base);
         STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_picture);
         STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text);
@@ -4886,13 +4887,16 @@
             mN.mUsesStandardHeader = false;
         }
 
-        private RemoteViews applyStandardTemplate(int resId, TemplateBindResult result) {
-            return applyStandardTemplate(resId, mParams.reset().fillTextsFrom(this),
-                    result);
+        private RemoteViews applyStandardTemplate(int resId, int viewType,
+                TemplateBindResult result) {
+            return applyStandardTemplate(resId,
+                    mParams.reset().viewType(viewType).fillTextsFrom(this), result);
         }
 
         private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p,
                 TemplateBindResult result) {
+            p.headerless(resId == getBaseLayoutResource()
+                    || resId == getHeadsUpBaseLayoutResource());
             RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId);
 
             resetStandardTemplate(contentView);
@@ -4900,9 +4904,9 @@
             final Bundle ex = mN.extras;
             updateBackgroundColor(contentView, p);
             bindNotificationHeader(contentView, p);
-            bindLargeIconAndReply(contentView, p, result);
+            bindLargeIconAndApplyMargin(contentView, p, result);
             boolean showProgress = handleProgressBar(contentView, ex, p);
-            if (p.title != null) {
+            if (p.title != null && p.title.length() > 0) {
                 contentView.setViewVisibility(R.id.title, View.VISIBLE);
                 contentView.setTextViewText(R.id.title, processTextSpans(p.title));
                 setTextViewColorPrimary(contentView, R.id.title, p);
@@ -5117,53 +5121,39 @@
             }
         }
 
-        private void bindLargeIconAndReply(RemoteViews contentView, StandardTemplateParams p,
-                TemplateBindResult result) {
+        private void bindLargeIconAndApplyMargin(RemoteViews contentView,
+                @NonNull StandardTemplateParams p,
+                @Nullable TemplateBindResult result) {
+            if (result == null) {
+                result = new TemplateBindResult();
+            }
             boolean largeIconShown = bindLargeIcon(contentView, p);
-            boolean replyIconShown = bindReplyIcon(contentView, p);
-            boolean iconContainerVisible = largeIconShown || replyIconShown;
-            contentView.setViewVisibility(R.id.right_icon_container,
-                    iconContainerVisible ? View.VISIBLE : View.GONE);
-            int marginEnd = calculateMarginEnd(largeIconShown, replyIconShown);
-            contentView.setViewLayoutMarginEnd(R.id.line1, marginEnd);
-            contentView.setViewLayoutMarginEnd(R.id.text, marginEnd);
-            contentView.setViewLayoutMarginEnd(R.id.progress, marginEnd);
-            if (result != null) {
-                result.setIconMarginEnd(marginEnd);
-                result.setRightIconContainerVisible(iconContainerVisible);
+            calculateLargeIconMarginEnd(largeIconShown, result);
+            if (p.mHeaderless) {
+                // views in the headerless (collapsed) state
+                contentView.setViewLayoutMarginEnd(R.id.notification_standard_view_column,
+                        result.getHeadingExtraMarginEnd());
+            } else {
+                // views in states with a header (big states)
+                contentView.setInt(R.id.notification_header, "setTopLineExtraMarginEnd",
+                        result.getHeadingExtraMarginEnd());
+                contentView.setViewLayoutMarginEnd(R.id.line1, result.getTitleMarginEnd());
             }
         }
 
-        private int calculateMarginEnd(boolean largeIconShown, boolean replyIconShown) {
-            int marginEnd = 0;
+        private void calculateLargeIconMarginEnd(boolean largeIconShown,
+                @NonNull TemplateBindResult result) {
             int contentMargin = mContext.getResources().getDimensionPixelSize(
                     R.dimen.notification_content_margin_end);
-            int iconSize = mContext.getResources().getDimensionPixelSize(
-                    R.dimen.notification_right_icon_size);
-            if (replyIconShown) {
-                // The size of the reply icon
-                marginEnd += iconSize;
-
-                int replyInset = mContext.getResources().getDimensionPixelSize(
-                        R.dimen.notification_reply_inset);
-                // We're subtracting the inset of the reply icon to make sure it's
-                // aligned nicely on the right, and remove it from the following padding
-                marginEnd -= replyInset * 2;
-            }
+            int expanderSize = mContext.getResources().getDimensionPixelSize(
+                    R.dimen.notification_header_expand_icon_size) - contentMargin;
+            int extraMarginEnd = 0;
             if (largeIconShown) {
-                // adding size of the right icon
-                marginEnd += iconSize;
-
-                if (replyIconShown) {
-                    // We also add some padding to the reply icon if it's around
-                    marginEnd += contentMargin;
-                }
+                int iconSize = mContext.getResources().getDimensionPixelSize(
+                        R.dimen.notification_right_icon_size);
+                extraMarginEnd = iconSize + contentMargin;
             }
-            if (replyIconShown || largeIconShown) {
-                // The padding to the content
-                marginEnd += contentMargin;
-            }
-            return marginEnd;
+            result.setRightIconState(largeIconShown, extraMarginEnd, expanderSize);
         }
 
         /**
@@ -5183,54 +5173,12 @@
             return showLargeIcon;
         }
 
-        /**
-         * Bind the reply icon.
-         * @return if the reply icon is visible
-         */
-        private boolean bindReplyIcon(RemoteViews contentView, StandardTemplateParams p) {
-            boolean actionVisible = !p.hideReplyIcon;
-            Action action = null;
-            if (actionVisible) {
-                action = findReplyAction();
-                actionVisible = action != null;
-            }
-            if (actionVisible) {
-                contentView.setViewVisibility(R.id.reply_icon_action, View.VISIBLE);
-                contentView.setDrawableTint(R.id.reply_icon_action,
-                        false /* targetBackground */,
-                        getNeutralColor(p),
-                        PorterDuff.Mode.SRC_ATOP);
-                contentView.setOnClickPendingIntent(R.id.reply_icon_action, action.actionIntent);
-                contentView.setRemoteInputs(R.id.reply_icon_action, action.mRemoteInputs);
-            } else {
-                contentView.setRemoteInputs(R.id.reply_icon_action, null);
-            }
-            contentView.setViewVisibility(R.id.reply_icon_action,
-                    actionVisible ? View.VISIBLE : View.GONE);
-            return actionVisible;
-        }
-
-        private Action findReplyAction() {
-            ArrayList<Action> actions = mActions;
-            if (mOriginalActions != null) {
-                actions = mOriginalActions;
-            }
-            int numActions = actions.size();
-            for (int i = 0; i < numActions; i++) {
-                Action action = actions.get(i);
-                if (hasValidRemoteInput(action)) {
-                    return action;
-                }
-            }
-            return null;
-        }
-
         private void bindNotificationHeader(RemoteViews contentView, StandardTemplateParams p) {
             bindSmallIcon(contentView, p);
-            bindHeaderAppName(contentView, p);
-            bindHeaderText(contentView, p);
-            bindHeaderTextSecondary(contentView, p);
-            bindHeaderChronometerAndTime(contentView, p);
+            boolean hasTextToLeft = bindHeaderAppName(contentView, p);
+            hasTextToLeft |= bindHeaderTextSecondary(contentView, p, hasTextToLeft);
+            hasTextToLeft |= bindHeaderText(contentView, p, hasTextToLeft);
+            bindHeaderChronometerAndTime(contentView, p, hasTextToLeft);
             bindProfileBadge(contentView, p);
             bindAlertedIcon(contentView, p);
             bindFeedbackIcon(contentView, p);
@@ -5252,10 +5200,12 @@
         }
 
         private void bindHeaderChronometerAndTime(RemoteViews contentView,
-                StandardTemplateParams p) {
+                StandardTemplateParams p, boolean hasTextToLeft) {
             if (showsTimeOrChronometer()) {
-                contentView.setViewVisibility(R.id.time_divider, View.VISIBLE);
-                setTextViewColorSecondary(contentView, R.id.time_divider, p);
+                if (hasTextToLeft) {
+                    contentView.setViewVisibility(R.id.time_divider, View.VISIBLE);
+                    setTextViewColorSecondary(contentView, R.id.time_divider, p);
+                }
                 if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) {
                     contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
                     contentView.setLong(R.id.chronometer, "setBase",
@@ -5276,7 +5226,11 @@
             }
         }
 
-        private void bindHeaderText(RemoteViews contentView, StandardTemplateParams p) {
+        /**
+         * @return true if the header text will be visible
+         */
+        private boolean bindHeaderText(RemoteViews contentView, StandardTemplateParams p,
+                boolean hasTextToLeft) {
             CharSequence summaryText = p.summaryText;
             if (summaryText == null && mStyle != null && mStyle.mSummaryTextSet
                     && mStyle.hasSummaryInHeader()) {
@@ -5293,20 +5247,32 @@
                         processLegacyText(summaryText)));
                 setTextViewColorSecondary(contentView, R.id.header_text, p);
                 contentView.setViewVisibility(R.id.header_text, View.VISIBLE);
-                contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE);
-                setTextViewColorSecondary(contentView, R.id.header_text_divider, p);
+                if (hasTextToLeft) {
+                    contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE);
+                    setTextViewColorSecondary(contentView, R.id.header_text_divider, p);
+                }
+                return true;
             }
+            return false;
         }
 
-        private void bindHeaderTextSecondary(RemoteViews contentView, StandardTemplateParams p) {
+        /**
+         * @return true if the secondary header text will be visible
+         */
+        private boolean bindHeaderTextSecondary(RemoteViews contentView, StandardTemplateParams p,
+                boolean hasTextToLeft) {
             if (!TextUtils.isEmpty(p.headerTextSecondary)) {
                 contentView.setTextViewText(R.id.header_text_secondary, processTextSpans(
                         processLegacyText(p.headerTextSecondary)));
                 setTextViewColorSecondary(contentView, R.id.header_text_secondary, p);
                 contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE);
-                contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE);
-                setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider, p);
+                if (hasTextToLeft) {
+                    contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE);
+                    setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider, p);
+                }
+                return true;
             }
+            return false;
         }
 
         /**
@@ -5343,13 +5309,23 @@
 
             return String.valueOf(name);
         }
-        private void bindHeaderAppName(RemoteViews contentView, StandardTemplateParams p) {
+
+        /**
+         * @return true if the app name will be visible
+         */
+        private boolean bindHeaderAppName(RemoteViews contentView, StandardTemplateParams p) {
+            if (p.mViewType == StandardTemplateParams.VIEW_TYPE_MINIMIZED) {
+                contentView.setViewVisibility(R.id.app_name_text, View.GONE);
+                return false;
+            }
+            contentView.setViewVisibility(R.id.app_name_text, View.VISIBLE);
             contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName());
             if (isColorized(p)) {
                 setTextViewColorPrimary(contentView, R.id.app_name_text, p);
             } else {
                 contentView.setTextColor(R.id.app_name_text, getSecondaryTextColor(p));
             }
+            return true;
         }
 
         private boolean isColorized(StandardTemplateParams p) {
@@ -5393,10 +5369,10 @@
                     R.dimen.notification_content_margin);
         }
 
-        private RemoteViews applyStandardTemplateWithActions(int layoutId,
+        private RemoteViews applyStandardTemplateWithActions(int layoutId, int viewType,
                 TemplateBindResult result) {
-            return applyStandardTemplateWithActions(layoutId, mParams.reset().fillTextsFrom(this),
-                    result);
+            return applyStandardTemplateWithActions(layoutId,
+                    mParams.reset().viewType(viewType).fillTextsFrom(this), result);
         }
 
         private static List<Notification.Action> filterOutContextualActions(
@@ -5536,7 +5512,8 @@
                     return styleView;
                 }
             }
-            return applyStandardTemplate(getBaseLayoutResource(), null /* result */);
+            return applyStandardTemplate(getBaseLayoutResource(),
+                    StandardTemplateParams.VIEW_TYPE_NORMAL, null /* result */);
         }
 
         private boolean useExistingRemoteView() {
@@ -5551,12 +5528,14 @@
             RemoteViews result = null;
             if (mN.bigContentView != null && useExistingRemoteView()) {
                 return mN.bigContentView;
-            } else if (mStyle != null) {
+            }
+            if (mStyle != null) {
                 result = mStyle.makeBigContentView();
                 hideLine1Text(result);
-            } else if (mActions.size() != 0) {
+            }
+            if (result == null) {
                 result = applyStandardTemplateWithActions(getBigBaseLayoutResource(),
-                        null /* result */);
+                        StandardTemplateParams.VIEW_TYPE_BIG, null /* result */);
             }
             makeHeaderExpanded(result);
             return result;
@@ -5569,7 +5548,9 @@
          * @hide
          */
         public RemoteViews makeNotificationHeader() {
-            return makeNotificationHeader(mParams.reset().fillTextsFrom(this));
+            return makeNotificationHeader(mParams.reset()
+                    .viewType(StandardTemplateParams.VIEW_TYPE_GROUP_HEADER)
+                    .fillTextsFrom(this));
         }
 
         /**
@@ -5642,9 +5623,11 @@
 
             // We only want at most a single remote input history to be shown here, otherwise
             // the content would become squished.
-            StandardTemplateParams p = mParams.reset().fillTextsFrom(this)
+            StandardTemplateParams p = mParams.reset()
+                    .viewType(StandardTemplateParams.VIEW_TYPE_HEADS_UP)
+                    .fillTextsFrom(this)
                     .setMaxRemoteInputHistory(1);
-            return applyStandardTemplateWithActions(getBigBaseLayoutResource(),
+            return applyStandardTemplateWithActions(getHeadsUpBaseLayoutResource(),
                     p,
                     null /* result */);
         }
@@ -5690,7 +5673,9 @@
             }
             mN.extras = publicExtras;
             RemoteViews view;
-            StandardTemplateParams params = mParams.reset().fillTextsFrom(this);
+            StandardTemplateParams params = mParams.reset()
+                    .viewType(StandardTemplateParams.VIEW_TYPE_PUBLIC)
+                    .fillTextsFrom(this);
             if (isLowPriority) {
                 params.forceDefaultColor();
             }
@@ -5714,6 +5699,7 @@
          */
         public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) {
             StandardTemplateParams p = mParams.reset()
+                    .viewType(StandardTemplateParams.VIEW_TYPE_MINIMIZED)
                     .forceDefaultColor()
                     .fillTextsFrom(this);
             if (!useRegularSubtext || TextUtils.isEmpty(mParams.summaryText)) {
@@ -6199,6 +6185,10 @@
             return R.layout.notification_template_material_base;
         }
 
+        private int getHeadsUpBaseLayoutResource() {
+            return R.layout.notification_template_material_heads_up_base;
+        }
+
         private int getBigBaseLayoutResource() {
             return R.layout.notification_template_material_big_base;
         }
@@ -6610,7 +6600,10 @@
         }
 
         protected RemoteViews getStandardView(int layoutId) {
-            StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder);
+            // TODO(jeffdq): set the view type based on the layout resource?
+            StandardTemplateParams p = mBuilder.mParams.reset()
+                    .viewType(StandardTemplateParams.VIEW_TYPE_UNSPECIFIED)
+                    .fillTextsFrom(mBuilder);
             return getStandardView(layoutId, p, null);
         }
 
@@ -6939,7 +6932,8 @@
                 mBuilder.mN.largeIcon = null;
             }
 
-            StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder);
+            StandardTemplateParams p = mBuilder.mParams.reset()
+                    .viewType(StandardTemplateParams.VIEW_TYPE_BIG).fillTextsFrom(mBuilder);
             RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource(),
                     p, null /* result */);
             if (mSummaryTextSet) {
@@ -7144,6 +7138,7 @@
         @Override
         public RemoteViews makeHeadsUpContentView(boolean increasedHeight) {
             if (increasedHeight && mBuilder.mActions.size() > 0) {
+                // TODO(b/163626038): pass VIEW_TYPE_HEADS_UP?
                 return makeBigContentView();
             }
             return super.makeHeadsUpContentView(increasedHeight);
@@ -7153,11 +7148,10 @@
          * @hide
          */
         public RemoteViews makeBigContentView() {
-            StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder).text(null);
-            TemplateBindResult result = new TemplateBindResult();
-            RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource(), p,
-                    result);
-            contentView.setInt(R.id.big_text, "setImageEndMargin", result.getIconMarginEnd());
+            StandardTemplateParams p = mBuilder.mParams.reset()
+                    .viewType(StandardTemplateParams.VIEW_TYPE_BIG)
+                    .fillTextsFrom(mBuilder).text(null);
+            RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource(), p, null);
 
             CharSequence bigTextText = mBuilder.processLegacyText(mBigText);
             if (TextUtils.isEmpty(bigTextText)) {
@@ -7170,8 +7164,6 @@
             mBuilder.setTextViewColorSecondary(contentView, R.id.big_text, p);
             contentView.setViewVisibility(R.id.big_text,
                     TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE);
-            contentView.setBoolean(R.id.big_text, "setHasImage",
-                    result.isRightIconContainerVisible());
 
             return contentView;
         }
@@ -7755,11 +7747,12 @@
             Icon largeIcon = mBuilder.mN.mLargeIcon;
             TemplateBindResult bindResult = new TemplateBindResult();
             StandardTemplateParams p = mBuilder.mParams.reset()
+                    .viewType(isCollapsed ? StandardTemplateParams.VIEW_TYPE_NORMAL
+                            : StandardTemplateParams.VIEW_TYPE_BIG)
                     .hasProgress(false)
                     .title(conversationTitle)
                     .text(null)
                     .hideLargeIcon(hideRightIcons || isOneToOne)
-                    .hideReplyIcon(hideRightIcons)
                     .headerTextSecondary(conversationTitle);
             RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(
                     isConversationLayout
@@ -7772,7 +7765,7 @@
             if (!isConversationLayout) {
                 // also update the end margin if there is an image
                 contentView.setViewLayoutMarginEnd(R.id.notification_messaging,
-                        bindResult.getIconMarginEnd());
+                        bindResult.getHeadingExtraMarginEnd());
             }
             contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor",
                     mBuilder.isColorized(p)
@@ -8260,7 +8253,9 @@
          * @hide
          */
         public RemoteViews makeBigContentView() {
-            StandardTemplateParams p = mBuilder.mParams.reset().fillTextsFrom(mBuilder).text(null);
+            StandardTemplateParams p = mBuilder.mParams.reset()
+                    .viewType(StandardTemplateParams.VIEW_TYPE_BIG)
+                    .fillTextsFrom(mBuilder).text(null);
             TemplateBindResult result = new TemplateBindResult();
             RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource(), p, result);
 
@@ -8312,8 +8307,6 @@
                             mBuilder.processTextSpans(mBuilder.processLegacyText(str)));
                     mBuilder.setTextViewColorSecondary(contentView, rowIds[i], p);
                     contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0);
-                    handleInboxImageMargin(contentView, rowIds[i], first,
-                            result.getIconMarginEnd());
                     if (first) {
                         onlyViewId = rowIds[i];
                     } else {
@@ -8359,20 +8352,6 @@
             }
             return false;
         }
-
-        private void handleInboxImageMargin(RemoteViews contentView, int id, boolean first,
-                int marginEndValue) {
-            int endMargin = 0;
-            if (first) {
-                final int max = mBuilder.mN.extras.getInt(EXTRA_PROGRESS_MAX, 0);
-                final boolean ind = mBuilder.mN.extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE);
-                boolean hasProgress = max != 0 || ind;
-                if (!hasProgress) {
-                    endMargin = marginEndValue;
-                }
-            }
-            contentView.setViewLayoutMarginEnd(id, endMargin);
-        }
     }
 
     /**
@@ -8580,8 +8559,9 @@
         }
 
         private RemoteViews makeMediaContentView() {
-            StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).fillTextsFrom(
-                    mBuilder);
+            StandardTemplateParams p = mBuilder.mParams.reset()
+                    .viewType(StandardTemplateParams.VIEW_TYPE_NORMAL)
+                    .hasProgress(false).fillTextsFrom(mBuilder);
             RemoteViews view = mBuilder.applyStandardTemplate(
                     R.layout.notification_template_material_media, p,
                     null /* result */);
@@ -8627,8 +8607,9 @@
             if (!mBuilder.mN.hasLargeIcon() && actionCount <= actionsInCompact) {
                 return null;
             }
-            StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).fillTextsFrom(
-                    mBuilder);
+            StandardTemplateParams p = mBuilder.mParams.reset()
+                    .viewType(StandardTemplateParams.VIEW_TYPE_BIG)
+                    .hasProgress(false).fillTextsFrom(mBuilder);
             RemoteViews big = mBuilder.applyStandardTemplate(
                     R.layout.notification_template_material_big_media, p , null /* result */);
 
@@ -8727,16 +8708,18 @@
             }
             TemplateBindResult result = new TemplateBindResult();
             RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions(
-                        mBuilder.getBigBaseLayoutResource(), result);
-            buildIntoRemoteViewContent(remoteViews, headsUpContentView, result);
+                    mBuilder.getHeadsUpBaseLayoutResource(),
+                    StandardTemplateParams.VIEW_TYPE_HEADS_UP, result);
+            buildIntoRemoteViewContent(remoteViews, headsUpContentView, result, false);
             return remoteViews;
         }
 
         private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) {
             TemplateBindResult result = new TemplateBindResult();
             RemoteViews remoteViews = mBuilder.applyStandardTemplate(
-                    mBuilder.getBaseLayoutResource(), result);
-            buildIntoRemoteViewContent(remoteViews, customContent, result);
+                    mBuilder.getBaseLayoutResource(),
+                    StandardTemplateParams.VIEW_TYPE_NORMAL, result);
+            buildIntoRemoteViewContent(remoteViews, customContent, result, true);
             return remoteViews;
         }
 
@@ -8744,18 +8727,16 @@
             RemoteViews bigContentView = mBuilder.mN.bigContentView == null
                     ? mBuilder.mN.contentView
                     : mBuilder.mN.bigContentView;
-            if (mBuilder.mActions.size() == 0) {
-                return makeStandardTemplateWithCustomContent(bigContentView);
-            }
             TemplateBindResult result = new TemplateBindResult();
             RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions(
-                    mBuilder.getBigBaseLayoutResource(), result);
-            buildIntoRemoteViewContent(remoteViews, bigContentView, result);
+                    mBuilder.getBigBaseLayoutResource(),
+                    StandardTemplateParams.VIEW_TYPE_BIG, result);
+            buildIntoRemoteViewContent(remoteViews, bigContentView, result, false);
             return remoteViews;
         }
 
         private void buildIntoRemoteViewContent(RemoteViews remoteViews,
-                RemoteViews customContent, TemplateBindResult result) {
+                RemoteViews customContent, TemplateBindResult result, boolean headerless) {
             int childIndex = -1;
             if (customContent != null) {
                 // Need to clone customContent before adding, because otherwise it can no longer be
@@ -8769,11 +8750,14 @@
             remoteViews.setIntTag(R.id.notification_main_column,
                     com.android.internal.R.id.notification_custom_view_index_tag,
                     childIndex);
-            // also update the end margin if there is an image
-            Resources resources = mBuilder.mContext.getResources();
-            int endMargin = resources.getDimensionPixelSize(
-                    R.dimen.notification_content_margin_end) + result.getIconMarginEnd();
-            remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin);
+            if (!headerless) {
+                // also update the end margin to account for the large icon or expander
+                Resources resources = mBuilder.mContext.getResources();
+                int endMargin = resources.getDimensionPixelSize(
+                        R.dimen.notification_content_margin_end) + result.getTitleMarginEnd();
+                remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column,
+                        endMargin);
+            }
         }
 
         /**
@@ -11009,35 +10993,57 @@
      * A result object where information about the template that was created is saved.
      */
     private static class TemplateBindResult {
-        int mIconMarginEnd;
-        boolean mRightIconContainerVisible;
+        boolean mRightIconVisible;
+        int mRightIconMarginEnd;
+        int mExpanderSize;
 
         /**
-         * Get the margin end that needs to be added to any fields that may overlap
-         * with the right actions.
+         * @return the margin end that needs to be added to the heading so that it won't overlap
+         * with the large icon.  This value includes the space required to accommodate the large
+         * icon, but should be added to the space needed to accommodate the expander. This does
+         * not include the 16dp content margin that all notification views must have.
          */
-        public int getIconMarginEnd() {
-            return mIconMarginEnd;
+        public int getHeadingExtraMarginEnd() {
+            return mRightIconMarginEnd;
         }
 
         /**
-         * Is the icon container visible on the right size because of the reply button or the
-         * right icon.
+         * @return the margin end that needs to be added to the heading so that it won't overlap
+         * with the large icon.  This value includes the space required to accommodate the large
+         * icon as well as the expander.  This does not include the 16dp content margin that all
+         * notification views must have.
          */
-        public boolean isRightIconContainerVisible() {
-            return mRightIconContainerVisible;
+        public int getHeadingFullMarginEnd() {
+            return mRightIconMarginEnd + mExpanderSize;
         }
 
-        public void setIconMarginEnd(int iconMarginEnd) {
-            this.mIconMarginEnd = iconMarginEnd;
+        /**
+         * @return the margin end that needs to be added to the title text of the big state
+         * so that it won't overlap with the large icon, but assuming the text can run under
+         * the expander when that icon is not visible.
+         */
+        public int getTitleMarginEnd() {
+            return mRightIconVisible ? getHeadingFullMarginEnd() : 0;
         }
 
-        public void setRightIconContainerVisible(boolean iconContainerVisible) {
-            mRightIconContainerVisible = iconContainerVisible;
+        public void setRightIconState(boolean visible, int marginEnd, int expanderSize) {
+            mRightIconVisible = visible;
+            mRightIconMarginEnd = marginEnd;
+            mExpanderSize = expanderSize;
         }
     }
 
     private static class StandardTemplateParams {
+        public static int VIEW_TYPE_UNSPECIFIED = 0;
+        public static int VIEW_TYPE_NORMAL = 1;
+        public static int VIEW_TYPE_BIG = 2;
+        public static int VIEW_TYPE_HEADS_UP = 3;
+        public static int VIEW_TYPE_MINIMIZED = 4;
+        public static int VIEW_TYPE_PUBLIC = 5;
+        public static int VIEW_TYPE_GROUP_HEADER = 6;
+
+        int mViewType = VIEW_TYPE_UNSPECIFIED;
+        boolean mHeaderless;
         boolean hasProgress = true;
         CharSequence title;
         CharSequence text;
@@ -11045,11 +11051,12 @@
         CharSequence summaryText;
         int maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES;
         boolean hideLargeIcon;
-        boolean hideReplyIcon;
         boolean allowColorization  = true;
         boolean forceDefaultColor = false;
 
         final StandardTemplateParams reset() {
+            mViewType = VIEW_TYPE_UNSPECIFIED;
+            mHeaderless = false;
             hasProgress = true;
             title = null;
             text = null;
@@ -11061,6 +11068,16 @@
             return this;
         }
 
+        final StandardTemplateParams viewType(int viewType) {
+            mViewType = viewType;
+            return this;
+        }
+
+        public StandardTemplateParams headerless(boolean headerless) {
+            mHeaderless = headerless;
+            return this;
+        }
+
         final StandardTemplateParams hasProgress(boolean hasProgress) {
             this.hasProgress = hasProgress;
             return this;
@@ -11091,11 +11108,6 @@
             return this;
         }
 
-        final StandardTemplateParams hideReplyIcon(boolean hideReplyIcon) {
-            this.hideReplyIcon = hideReplyIcon;
-            return this;
-        }
-
         final StandardTemplateParams disallowColorization() {
             this.allowColorization = false;
             return this;
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 44640c4..abc2a69 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -16,7 +16,6 @@
 
 package android.inputmethodservice;
 
-import static android.graphics.Color.TRANSPARENT;
 import static android.inputmethodservice.InputMethodServiceProto.CANDIDATES_VIEW_STARTED;
 import static android.inputmethodservice.InputMethodServiceProto.CANDIDATES_VISIBILITY;
 import static android.inputmethodservice.InputMethodServiceProto.CONFIGURATION;
@@ -50,6 +49,7 @@
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
 import static android.view.WindowInsets.Type.navigationBars;
+import static android.view.WindowInsets.Type.statusBars;
 import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
 
 import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -1244,13 +1244,8 @@
                 Context.LAYOUT_INFLATER_SERVICE);
         mWindow = new SoftInputWindow(this, "InputMethod", mTheme, null, null, mDispatcherState,
                 WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.BOTTOM, false);
-        mWindow.getWindow().getAttributes().setFitInsetsTypes(navigationBars());
+        mWindow.getWindow().getAttributes().setFitInsetsTypes(statusBars() | navigationBars());
         mWindow.getWindow().getAttributes().setFitInsetsSides(Side.all() & ~Side.BOTTOM);
-        mWindow.getWindow().getAttributes().setFitInsetsIgnoringVisibility(true);
-
-        // Our window will extend into the status bar area no matter the bar is visible or not.
-        // We don't want the ColorView to be visible when status bar is shown.
-        mWindow.getWindow().setStatusBarColor(TRANSPARENT);
 
         // Automotive devices may request the navigation bar to be hidden when the IME shows up
         // (controlled via config_automotiveHideNavBarForKeyboard) in order to maximize the visible
diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java
index 2bd3d46..f7fbb1c 100644
--- a/core/java/android/view/NotificationHeaderView.java
+++ b/core/java/android/view/NotificationHeaderView.java
@@ -27,6 +27,7 @@
 import android.graphics.drawable.Drawable;
 import android.os.Build;
 import android.util.AttributeSet;
+import android.widget.FrameLayout;
 import android.widget.RemoteViews;
 
 import com.android.internal.R;
@@ -41,15 +42,14 @@
  * @hide
  */
 @RemoteViews.RemoteView
-public class NotificationHeaderView extends ViewGroup {
-    private final int mChildMinWidth;
+public class NotificationHeaderView extends FrameLayout {
     private final int mContentEndMargin;
+    private final int mHeadingEndMargin;
     private OnClickListener mExpandClickListener;
     private HeaderTouchListener mTouchListener = new HeaderTouchListener();
     private NotificationTopLineView mTopLineView;
     private NotificationExpandButton mExpandButton;
     private CachingIconView mIcon;
-    private int mHeaderTextMarginEnd;
     private Drawable mBackground;
     private boolean mEntireHeaderClickable;
     private boolean mExpandOnlyOnButton;
@@ -82,8 +82,8 @@
             int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
         Resources res = getResources();
-        mChildMinWidth = res.getDimensionPixelSize(R.dimen.notification_header_shrink_min_width);
         mContentEndMargin = res.getDimensionPixelSize(R.dimen.notification_content_margin_end);
+        mHeadingEndMargin = res.getDimensionPixelSize(R.dimen.notification_heading_margin_end);
         mEntireHeaderClickable = res.getBoolean(R.bool.config_notificationHeaderClickableForExpand);
     }
 
@@ -96,108 +96,6 @@
         setClipToPadding(false);
     }
 
-    @Override
-    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        final int givenWidth = MeasureSpec.getSize(widthMeasureSpec);
-        final int givenHeight = MeasureSpec.getSize(heightMeasureSpec);
-        int wrapContentWidthSpec = MeasureSpec.makeMeasureSpec(givenWidth,
-                MeasureSpec.AT_MOST);
-        int wrapContentHeightSpec = MeasureSpec.makeMeasureSpec(givenHeight,
-                MeasureSpec.AT_MOST);
-        int totalWidth = getPaddingStart();
-        int iconWidth = getPaddingEnd();
-        for (int i = 0; i < getChildCount(); i++) {
-            final View child = getChildAt(i);
-            if (child.getVisibility() == GONE) {
-                // We'll give it the rest of the space in the end
-                continue;
-            }
-            final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
-            int childWidthSpec = getChildMeasureSpec(wrapContentWidthSpec,
-                    lp.leftMargin + lp.rightMargin, lp.width);
-            int childHeightSpec = getChildMeasureSpec(wrapContentHeightSpec,
-                    lp.topMargin + lp.bottomMargin, lp.height);
-            child.measure(childWidthSpec, childHeightSpec);
-            // Icons that should go at the end
-            if (child == mExpandButton) {
-                iconWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
-            } else {
-                totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
-            }
-        }
-
-        // Ensure that there is at least enough space for the icons
-        int endMargin = Math.max(mHeaderTextMarginEnd, iconWidth);
-        if (totalWidth > givenWidth - endMargin) {
-            int overFlow = totalWidth - givenWidth + endMargin;
-            // We are overflowing; shrink the top line
-            shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mTopLineView,
-                    mChildMinWidth);
-        }
-        setMeasuredDimension(givenWidth, givenHeight);
-    }
-
-    private int shrinkViewForOverflow(int heightSpec, int overFlow, View targetView,
-            int minimumWidth) {
-        final int oldWidth = targetView.getMeasuredWidth();
-        if (overFlow > 0 && targetView.getVisibility() != GONE && oldWidth > minimumWidth) {
-            // we're still too big
-            int newSize = Math.max(minimumWidth, oldWidth - overFlow);
-            int childWidthSpec = MeasureSpec.makeMeasureSpec(newSize, MeasureSpec.AT_MOST);
-            targetView.measure(childWidthSpec, heightSpec);
-            overFlow -= oldWidth - newSize;
-        }
-        return overFlow;
-    }
-
-    @Override
-    protected void onLayout(boolean changed, int l, int t, int r, int b) {
-        int left = getPaddingStart();
-        int end = getMeasuredWidth();
-        int childCount = getChildCount();
-        int ownHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
-        for (int i = 0; i < childCount; i++) {
-            View child = getChildAt(i);
-            if (child.getVisibility() == GONE) {
-                continue;
-            }
-            int childHeight = child.getMeasuredHeight();
-            MarginLayoutParams params = (MarginLayoutParams) child.getLayoutParams();
-            int layoutLeft;
-            int layoutRight;
-            int top = (int) (getPaddingTop() + (ownHeight - childHeight) / 2.0f);
-            int bottom = top + childHeight;
-            // Icons that should go at the end
-            if (child == mExpandButton) {
-                if (end == getMeasuredWidth()) {
-                    layoutRight = end - mContentEndMargin;
-                } else {
-                    layoutRight = end - params.getMarginEnd();
-                }
-                layoutLeft = layoutRight - child.getMeasuredWidth();
-                end = layoutLeft - params.getMarginStart();
-            } else {
-                left += params.getMarginStart();
-                int right = left + child.getMeasuredWidth();
-                layoutLeft = left;
-                layoutRight = right;
-                left = right + params.getMarginEnd();
-            }
-            if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
-                int ltrLeft = layoutLeft;
-                layoutLeft = getWidth() - layoutRight;
-                layoutRight = getWidth() - ltrLeft;
-            }
-            child.layout(layoutLeft, top, layoutRight, bottom);
-        }
-        updateTouchListener();
-    }
-
-    @Override
-    public LayoutParams generateLayoutParams(AttributeSet attrs) {
-        return new MarginLayoutParams(getContext(), attrs);
-    }
-
     /**
      * Set a {@link Drawable} to be displayed as a background on the header.
      */
@@ -252,23 +150,34 @@
     }
 
     /**
-     * Sets the margin end for the text portion of the header, excluding right-aligned elements
-     * @param headerTextMarginEnd margin size
+     * Sets the extra margin at the end of the top line of left-aligned text + icons.
+     * This value will have the margin required to accommodate the expand button added to it.
+     *
+     * @param extraMarginEnd extra margin
      */
     @RemotableViewMethod
-    public void setHeaderTextMarginEnd(int headerTextMarginEnd) {
-        if (mHeaderTextMarginEnd != headerTextMarginEnd) {
-            mHeaderTextMarginEnd = headerTextMarginEnd;
-            requestLayout();
-        }
+    public void setTopLineExtraMarginEnd(int extraMarginEnd) {
+        mTopLineView.setHeaderTextMarginEnd(extraMarginEnd + mHeadingEndMargin);
     }
 
     /**
-     * Get the current margin end value for the header text
-     * @return margin size
+     * Get the current margin end value for the header text.
+     * Add this to {@link #getTopLineBaseMarginEnd()} to get the total margin of the top line.
+     *
+     * @return extra margin
      */
-    public int getHeaderTextMarginEnd() {
-        return mHeaderTextMarginEnd;
+    public int getTopLineExtraMarginEnd() {
+        return mTopLineView.getHeaderTextMarginEnd() - mHeadingEndMargin;
+    }
+
+    /**
+     * Get the base margin at the end of the top line view.
+     * Add this to {@link #getTopLineExtraMarginEnd()} to get the total margin of the top line.
+     *
+     * @return base margin
+     */
+    public int getTopLineBaseMarginEnd() {
+        return mHeadingEndMargin;
     }
 
     /**
diff --git a/core/java/android/view/NotificationTopLineView.java b/core/java/android/view/NotificationTopLineView.java
index 2474822..a8eabe5 100644
--- a/core/java/android/view/NotificationTopLineView.java
+++ b/core/java/android/view/NotificationTopLineView.java
@@ -26,9 +26,6 @@
 
 import com.android.internal.R;
 
-import java.util.Arrays;
-import java.util.List;
-
 /**
  * The top line of content in a notification view.
  * This includes the text views and badges but excludes the icon and the expander.
@@ -39,16 +36,14 @@
 public class NotificationTopLineView extends ViewGroup {
     private final int mGravityY;
     private final int mChildMinWidth;
-    private final int mContentEndMargin;
-    private View mAppName;
+    @Nullable private View mAppName;
+    @Nullable private View mTitle;
     private View mHeaderText;
     private View mSecondaryHeaderText;
     private OnClickListener mFeedbackListener;
     private HeaderTouchListener mTouchListener = new HeaderTouchListener();
-    private View mProfileBadge;
     private View mFeedbackIcon;
     private int mHeaderTextMarginEnd;
-    private List<View> mIconsAtEnd;
 
     private int mMaxAscent;
     private int mMaxDescent;
@@ -71,7 +66,6 @@
         super(context, attrs, defStyleAttr, defStyleRes);
         Resources res = getResources();
         mChildMinWidth = res.getDimensionPixelSize(R.dimen.notification_header_shrink_min_width);
-        mContentEndMargin = res.getDimensionPixelSize(R.dimen.notification_content_margin_end);
 
         // NOTE: Implementation only supports TOP, BOTTOM, and CENTER_VERTICAL gravities,
         // with CENTER_VERTICAL being the default.
@@ -92,11 +86,10 @@
     protected void onFinishInflate() {
         super.onFinishInflate();
         mAppName = findViewById(R.id.app_name_text);
+        mTitle = findViewById(R.id.title);
         mHeaderText = findViewById(R.id.header_text);
         mSecondaryHeaderText = findViewById(R.id.header_text_secondary);
-        mProfileBadge = findViewById(R.id.profile_badge);
         mFeedbackIcon = findViewById(R.id.feedback);
-        mIconsAtEnd = Arrays.asList(mProfileBadge, mFeedbackIcon);
     }
 
     @Override
@@ -109,7 +102,6 @@
         int wrapContentHeightSpec = MeasureSpec.makeMeasureSpec(givenHeight,
                 MeasureSpec.AT_MOST);
         int totalWidth = getPaddingStart();
-        int iconWidth = getPaddingEnd();
         int maxChildHeight = -1;
         mMaxAscent = -1;
         mMaxDescent = -1;
@@ -125,12 +117,7 @@
             int childHeightSpec = getChildMeasureSpec(wrapContentHeightSpec,
                     lp.topMargin + lp.bottomMargin, lp.height);
             child.measure(childWidthSpec, childHeightSpec);
-            // Icons that should go at the end
-            if (mIconsAtEnd.contains(child)) {
-                iconWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
-            } else {
-                totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
-            }
+            totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
             int childBaseline = child.getBaseline();
             int childHeight = child.getMeasuredHeight();
             if (childBaseline != -1) {
@@ -141,12 +128,20 @@
         }
 
         // Ensure that there is at least enough space for the icons
-        int endMargin = Math.max(mHeaderTextMarginEnd, iconWidth);
+        int endMargin = Math.max(mHeaderTextMarginEnd, getPaddingEnd());
         if (totalWidth > givenWidth - endMargin) {
             int overFlow = totalWidth - givenWidth + endMargin;
-            // We are overflowing, lets shrink the app name first
-            overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mAppName,
-                    mChildMinWidth);
+            if (mAppName != null) {
+                // We are overflowing, lets shrink the app name first
+                overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mAppName,
+                        mChildMinWidth);
+            }
+
+            if (mTitle != null) {
+                // still overflowing, we shrink the title text
+                overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mTitle,
+                        mChildMinWidth);
+            }
 
             // still overflowing, we shrink the header text
             overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mHeaderText, 0);
@@ -174,7 +169,6 @@
     @Override
     protected void onLayout(boolean changed, int l, int t, int r, int b) {
         int left = getPaddingStart();
-        int end = getMeasuredWidth();
         int childCount = getChildCount();
         int ownHeight = b - t;
         int childSpace = ownHeight - mPaddingTop - mPaddingBottom;
@@ -228,22 +222,12 @@
                     childTop = mPaddingTop;
             }
 
-            // Icons that should go at the end
-            if (mIconsAtEnd.contains(child)) {
-                if (end == getMeasuredWidth()) {
-                    layoutRight = end - mContentEndMargin;
-                } else {
-                    layoutRight = end - params.getMarginEnd();
-                }
-                layoutLeft = layoutRight - child.getMeasuredWidth();
-                end = layoutLeft - params.getMarginStart();
-            } else {
-                left += params.getMarginStart();
-                int right = left + child.getMeasuredWidth();
-                layoutLeft = left;
-                layoutRight = right;
-                left = right + params.getMarginEnd();
-            }
+            left += params.getMarginStart();
+            int right = left + child.getMeasuredWidth();
+            layoutLeft = left;
+            layoutRight = right;
+            left = right + params.getMarginEnd();
+
             if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
                 int ltrLeft = layoutLeft;
                 layoutLeft = getWidth() - layoutRight;
@@ -298,6 +282,13 @@
         return mHeaderTextMarginEnd;
     }
 
+    /**
+     * Set padding at the start of the view.
+     */
+    public void setPaddingStart(int paddingStart) {
+        setPaddingRelative(paddingStart, getPaddingTop(), getPaddingEnd(), getPaddingBottom());
+    }
+
     private class HeaderTouchListener implements OnTouchListener {
 
         private Rect mFeedbackRect;
diff --git a/core/java/com/android/internal/util/ScreenshotHelper.java b/core/java/com/android/internal/util/ScreenshotHelper.java
index 0bafb2f..4ad7795 100644
--- a/core/java/com/android/internal/util/ScreenshotHelper.java
+++ b/core/java/com/android/internal/util/ScreenshotHelper.java
@@ -1,12 +1,15 @@
 package com.android.internal.util;
 
+import static android.content.Intent.ACTION_USER_SWITCHED;
 import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_OTHER;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.graphics.Insets;
 import android.graphics.Rect;
@@ -161,8 +164,21 @@
     private ServiceConnection mScreenshotConnection = null;
     private final Context mContext;
 
+    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            synchronized (mScreenshotLock) {
+                if (ACTION_USER_SWITCHED.equals(intent.getAction())) {
+                    resetConnection();
+                }
+            }
+        }
+    };
+
     public ScreenshotHelper(Context context) {
         mContext = context;
+        IntentFilter filter = new IntentFilter(ACTION_USER_SWITCHED);
+        mContext.registerReceiver(mBroadcastReceiver, filter);
     }
 
     /**
@@ -280,9 +296,7 @@
                 synchronized (mScreenshotLock) {
                     if (mScreenshotConnection != null) {
                         Log.e(TAG, "Timed out before getting screenshot capture response");
-                        mContext.unbindService(mScreenshotConnection);
-                        mScreenshotConnection = null;
-                        mScreenshotService = null;
+                        resetConnection();
                         notifyScreenshotError();
                     }
                 }
@@ -305,11 +319,7 @@
                             break;
                         case SCREENSHOT_MSG_PROCESS_COMPLETE:
                             synchronized (mScreenshotLock) {
-                                if (mScreenshotConnection != null) {
-                                    mContext.unbindService(mScreenshotConnection);
-                                    mScreenshotConnection = null;
-                                    mScreenshotService = null;
-                                }
+                                resetConnection();
                             }
                             break;
                     }
@@ -349,9 +359,7 @@
                     public void onServiceDisconnected(ComponentName name) {
                         synchronized (mScreenshotLock) {
                             if (mScreenshotConnection != null) {
-                                mContext.unbindService(mScreenshotConnection);
-                                mScreenshotConnection = null;
-                                mScreenshotService = null;
+                                resetConnection();
                                 // only log an error if we're still within the timeout period
                                 if (handler.hasCallbacks(mScreenshotTimeout)) {
                                     Log.e(TAG, "Screenshot service disconnected");
@@ -385,6 +393,17 @@
     }
 
     /**
+     * Unbinds the current screenshot connection (if any).
+     */
+    private void resetConnection() {
+        if (mScreenshotConnection != null) {
+            mContext.unbindService(mScreenshotConnection);
+            mScreenshotConnection = null;
+            mScreenshotService = null;
+        }
+    }
+
+    /**
      * Notifies the screenshot service to show an error.
      */
     private void notifyScreenshotError() {
diff --git a/core/java/com/android/internal/widget/ConversationLayout.java b/core/java/com/android/internal/widget/ConversationLayout.java
index 289a36f..40e671f 100644
--- a/core/java/com/android/internal/widget/ConversationLayout.java
+++ b/core/java/com/android/internal/widget/ConversationLayout.java
@@ -134,7 +134,6 @@
     private CachingIconView mConversationIconBadgeBg;
     private Icon mLargeIcon;
     private View mExpandButtonContainer;
-    private View mExpandButtonInnerContainer;
     private ViewGroup mExpandButtonAndContentContainer;
     private NotificationExpandButton mExpandButton;
     private MessagingLinearLayout mImageMessageContainer;
@@ -266,7 +265,6 @@
         mConversationHeader = findViewById(R.id.conversation_header);
         mContentContainer = findViewById(R.id.notification_action_list_margin_target);
         mExpandButtonAndContentContainer = findViewById(R.id.expand_button_and_content_container);
-        mExpandButtonInnerContainer = findViewById(R.id.expand_button_inner_container);
         mExpandButton = findViewById(R.id.expand_button);
         mExpandButtonExpandedTopMargin = getResources().getDimensionPixelSize(
                 R.dimen.conversation_expand_button_top_margin_expanded);
@@ -1217,25 +1215,18 @@
     }
 
     private void updateExpandButton() {
-        int drawableId;
-        int contentDescriptionId;
         int gravity;
         int topMargin = 0;
         ViewGroup newContainer;
         if (mIsCollapsed) {
-            drawableId = R.drawable.ic_expand_notification;
-            contentDescriptionId = R.string.expand_button_content_description_collapsed;
             gravity = Gravity.CENTER;
             newContainer = mExpandButtonAndContentContainer;
         } else {
-            drawableId = R.drawable.ic_collapse_notification;
-            contentDescriptionId = R.string.expand_button_content_description_expanded;
             gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
             topMargin = mExpandButtonExpandedTopMargin;
             newContainer = this;
         }
-        mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
-        mExpandButton.setColorFilter(mExpandButton.getOriginalNotificationColor());
+        mExpandButton.setExpanded(!mIsCollapsed);
 
         // We need to make sure that the expand button is in the linearlayout pushing over the
         // content when collapsed, but allows the content to flow under it when expanded.
@@ -1250,8 +1241,6 @@
         layoutParams.gravity = gravity;
         layoutParams.topMargin = topMargin;
         mExpandButton.setLayoutParams(layoutParams);
-
-        mExpandButtonInnerContainer.setContentDescription(mContext.getText(contentDescriptionId));
     }
 
     private void updateContentEndPaddings() {
@@ -1298,7 +1287,7 @@
         mExpandable = expandable;
         if (expandable) {
             mExpandButtonContainer.setVisibility(VISIBLE);
-            mExpandButtonInnerContainer.setOnClickListener(onClickListener);
+            mExpandButton.setOnClickListener(onClickListener);
             mConversationIconContainer.setOnClickListener(onClickListener);
         } else {
             mExpandButtonContainer.setVisibility(GONE);
diff --git a/core/java/com/android/internal/widget/MediaNotificationView.java b/core/java/com/android/internal/widget/MediaNotificationView.java
index 9bb4501..f42d5da 100644
--- a/core/java/com/android/internal/widget/MediaNotificationView.java
+++ b/core/java/com/android/internal/widget/MediaNotificationView.java
@@ -98,12 +98,14 @@
                 mMainColumn.setLayoutParams(params);
                 reMeasure = true;
             }
+            // TODO(b/172652345): validate all this logic (especially positioning of expand button)
             // margin for the entire header line
             int headerMarginEnd = imageEndMargin;
             // margin for the header text (not including the expand button and other icons)
-            int headerTextMarginEnd = size + imageEndMargin;
-            if (headerTextMarginEnd != mHeader.getHeaderTextMarginEnd()) {
-                mHeader.setHeaderTextMarginEnd(headerTextMarginEnd);
+            int headerExtraMarginEnd = Math.max(0,
+                    size + imageEndMargin - mHeader.getTopLineBaseMarginEnd());
+            if (headerExtraMarginEnd != mHeader.getTopLineExtraMarginEnd()) {
+                mHeader.setTopLineExtraMarginEnd(headerExtraMarginEnd);
                 reMeasure = true;
             }
             params = (MarginLayoutParams) mHeader.getLayoutParams();
diff --git a/core/java/com/android/internal/widget/NotificationExpandButton.java b/core/java/com/android/internal/widget/NotificationExpandButton.java
index 986412d..8add34f 100644
--- a/core/java/com/android/internal/widget/NotificationExpandButton.java
+++ b/core/java/com/android/internal/widget/NotificationExpandButton.java
@@ -23,6 +23,7 @@
 import android.graphics.Rect;
 import android.util.AttributeSet;
 import android.view.RemotableViewMethod;
+import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityNodeInfo;
 import android.widget.Button;
 import android.widget.ImageView;
@@ -36,33 +37,58 @@
 @RemoteViews.RemoteView
 public class NotificationExpandButton extends ImageView {
 
+    private final int mMinTouchTargetSize;
     private boolean mExpanded;
     private int mOriginalNotificationColor;
 
     public NotificationExpandButton(Context context) {
-        super(context);
+        this(context, null, 0, 0);
     }
 
     public NotificationExpandButton(Context context, @Nullable AttributeSet attrs) {
-        super(context, attrs);
+        this(context, attrs, 0, 0);
     }
 
     public NotificationExpandButton(Context context, @Nullable AttributeSet attrs,
             int defStyleAttr) {
-        super(context, attrs, defStyleAttr);
+        this(context, attrs, defStyleAttr, 0);
     }
 
     public NotificationExpandButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
             int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
+        mMinTouchTargetSize = (int) (getResources().getDisplayMetrics().density * 48 + 0.5);
     }
 
+    /**
+     * Show the touchable area of the view for a11y.
+     * If the parent is the touch container, then that view's bounds are the touchable area.
+     */
     @Override
     public void getBoundsOnScreen(Rect outRect, boolean clipToParent) {
-        super.getBoundsOnScreen(outRect, clipToParent);
+        ViewGroup parent = (ViewGroup) getParent();
+        if (parent != null && parent.getId() == R.id.expand_button_touch_container) {
+            parent.getBoundsOnScreen(outRect, clipToParent);
+        } else {
+            super.getBoundsOnScreen(outRect, clipToParent);
+        }
         extendRectToMinTouchSize(outRect);
     }
 
+    /**
+     * Determined if the given point should be touchable.
+     * If the parent is the touch container, then any point in that view should be touchable.
+     */
+    @Override
+    public boolean pointInView(float localX, float localY, float slop) {
+        ViewGroup parent = (ViewGroup) getParent();
+        if (parent != null && parent.getId() == R.id.expand_button_touch_container) {
+            // If our parent is checking with us, then the point must be within its bounds.
+            return true;
+        }
+        return super.pointInView(localX, localY, slop);
+    }
+
     @RemotableViewMethod
     public void setOriginalNotificationColor(int color) {
         mOriginalNotificationColor = color;
@@ -81,11 +107,14 @@
     }
 
     private void extendRectToMinTouchSize(Rect rect) {
-        int touchTargetSize = (int) (getResources().getDisplayMetrics().density * 48);
-        rect.left = rect.centerX() - touchTargetSize / 2;
-        rect.right = rect.left + touchTargetSize;
-        rect.top = rect.centerY() - touchTargetSize / 2;
-        rect.bottom = rect.top + touchTargetSize;
+        if (rect.width() < mMinTouchTargetSize) {
+            rect.left = rect.centerX() - mMinTouchTargetSize / 2;
+            rect.right = rect.left + mMinTouchTargetSize;
+        }
+        if (rect.height() < mMinTouchTargetSize) {
+            rect.top = rect.centerY() - mMinTouchTargetSize / 2;
+            rect.bottom = rect.top + mMinTouchTargetSize;
+        }
     }
 
     @Override
diff --git a/core/java/com/android/internal/widget/NotificationMaxHeightFrameLayout.java b/core/java/com/android/internal/widget/NotificationMaxHeightFrameLayout.java
new file mode 100644
index 0000000..6d5fb66
--- /dev/null
+++ b/core/java/com/android/internal/widget/NotificationMaxHeightFrameLayout.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.FrameLayout;
+import android.widget.RemoteViews;
+
+/**
+ * This custom subclass of FrameLayout enforces that its calculated height be no larger than the
+ * standard height of a notification.  This is not required in the normal case, as the
+ * NotificationContentView gets this same value from the ExpandableNotificationRow, and enforces it
+ * as a maximum.  It is required in the case of the HUN version of the headerless notification,
+ * because that style puts the actions below the headerless portion.  If we don't cap this, then in
+ * certain situations (larger fonts, decorated custom views) the contents of the headerless
+ * notification push on the margins and increase the size of that view, which causes the actions to
+ * be cropped on the bottom by the HUN notification max height.
+ */
+@RemoteViews.RemoteView
+public class NotificationMaxHeightFrameLayout extends FrameLayout {
+    private final int mNotificationMaxHeight;
+
+    public NotificationMaxHeightFrameLayout(Context context) {
+        this(context, null, 0, 0);
+    }
+
+    public NotificationMaxHeightFrameLayout(Context context, @Nullable AttributeSet attrs) {
+        this(context, attrs, 0, 0);
+    }
+
+    public NotificationMaxHeightFrameLayout(Context context, @Nullable AttributeSet attrs,
+            int defStyleAttr) {
+        this(context, attrs, defStyleAttr, 0);
+    }
+
+    public NotificationMaxHeightFrameLayout(Context context, AttributeSet attrs, int defStyleAttr,
+            int defStyleRes) {
+        super(context, attrs, defStyleAttr, defStyleRes);
+        // `notification_min_height` refers to "minimized" not "minimum"; it is a max height
+        mNotificationMaxHeight = getFontScaledHeight(mContext,
+                com.android.internal.R.dimen.notification_min_height);
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        if (MeasureSpec.getSize(heightMeasureSpec) > mNotificationMaxHeight) {
+            final int mode = MeasureSpec.getMode(heightMeasureSpec);
+            heightMeasureSpec = MeasureSpec.makeMeasureSpec(mNotificationMaxHeight, mode);
+        }
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+    }
+
+    /**
+     * NOTE: This is copied from com.android.systemui.statusbar.notification.NotificationUtils
+     *
+     * @param dimenId the dimen to look up
+     * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
+     */
+    private static int getFontScaledHeight(Context context, int dimenId) {
+        final int dimensionPixelSize = context.getResources().getDimensionPixelSize(dimenId);
+        final float factor = Math.max(1.0f, context.getResources().getDisplayMetrics().scaledDensity
+                / context.getResources().getDisplayMetrics().density);
+        return (int) (dimensionPixelSize * factor);
+    }
+}
diff --git a/core/res/res/drawable/ic_reply_notification.xml b/core/res/res/drawable/ic_reply_notification.xml
deleted file mode 100644
index a9864b0..0000000
--- a/core/res/res/drawable/ic_reply_notification.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<!--
-  ~ Copyright (C) 2017 The Android Open Source Project
-  ~
-  ~ Licensed under the Apache License, Version 2.0 (the "License");
-  ~ you may not use this file except in compliance with the License.
-  ~ You may obtain a copy of the License at
-  ~
-  ~      http://www.apache.org/licenses/LICENSE-2.0
-  ~
-  ~ Unless required by applicable law or agreed to in writing, software
-  ~ distributed under the License is distributed on an "AS IS" BASIS,
-  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  ~ See the License for the specific language governing permissions and
-  ~ limitations under the License
-  -->
-<inset xmlns:android="http://schemas.android.com/apk/res/android"
-       android:inset="@dimen/notification_reply_inset">
-    <vector android:width="24dp"
-            android:height="24dp"
-            android:viewportWidth="24"
-            android:viewportHeight="24">
-
-        <path
-            android:fillColor="#000000"
-            android:strokeWidth="1"
-            android:pathData="M16,10 L6.83,10 L9,7.83 L10.41,6.42 L9,5 L3,11 L9,17 L10.41,15.59 L9,14.17 L6.83,12 L16,12 C17.65,12 19,13.35 19,15 L19,19 L21,19 L21,15 C21,12.24 18.76,10 16,10 Z" />
-        <path
-            android:fillColor="#000000"
-            android:strokeWidth="1"
-            android:pathData="M16,10 L6.83,10 L9,7.83 L10.41,6.42 L9,5 L3,11 L9,17 L10.41,15.59 L9,14.17 L6.83,12 L16,12 C17.65,12 19,13.35 19,15 L19,19 L21,19 L21,15 C21,12.24 18.76,10 16,10 Z" />
-    </vector>
-</inset>
diff --git a/core/res/res/drawable/notification_big_picture_outline.xml b/core/res/res/drawable/notification_big_picture_outline.xml
new file mode 100644
index 0000000..4c4fa50
--- /dev/null
+++ b/core/res/res/drawable/notification_big_picture_outline.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <corners android:radius="16dp" />
+    <solid android:color="#00000000" />
+</shape>
diff --git a/core/res/res/drawable/notification_icon_circle.xml b/core/res/res/drawable/notification_icon_circle.xml
new file mode 100644
index 0000000..b10a52d
--- /dev/null
+++ b/core/res/res/drawable/notification_icon_circle.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
+    <solid android:color="#333" />
+</shape>
diff --git a/core/res/res/drawable/notification_large_icon_outline.xml b/core/res/res/drawable/notification_large_icon_outline.xml
new file mode 100644
index 0000000..bac03d2
--- /dev/null
+++ b/core/res/res/drawable/notification_large_icon_outline.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <corners android:radius="5dp" />
+    <solid android:color="#00000000" />
+</shape>
diff --git a/core/res/res/layout/notification_material_action_list.xml b/core/res/res/layout/notification_material_action_list.xml
index bf66e69..552a1bd 100644
--- a/core/res/res/layout/notification_material_action_list.xml
+++ b/core/res/res/layout/notification_material_action_list.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2014 The Android Open Source Project
 
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
@@ -14,50 +13,54 @@
      limitations under the License.
 -->
 
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:id="@+id/actions_container"
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/actions_container"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:layout_marginTop="@dimen/notification_action_list_margin_top"
+    android:layout_gravity="bottom"
+    >
+
+    <LinearLayout
+        android:id="@+id/actions_container_layout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginTop="@dimen/notification_action_list_margin_top"
-        android:layout_gravity="bottom">
+        android:gravity="end"
+        android:orientation="horizontal"
+        android:paddingEnd="@dimen/bubble_gone_padding_end"
+        android:background="@color/notification_action_list_background_color"
+        >
 
-        <LinearLayout
-            android:id="@+id/actions_container_layout"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:gravity="end"
+        <com.android.internal.widget.NotificationActionListLayout
+            android:id="@+id/actions"
+            android:layout_width="0dp"
+            android:layout_weight="1"
+            android:layout_height="@dimen/notification_action_list_height"
             android:orientation="horizontal"
-            android:paddingEnd="@dimen/bubble_gone_padding_end"
-            android:background="@color/notification_action_list_background_color"
+            android:gravity="center_vertical"
+            android:paddingStart="@dimen/notification_actions_padding_start"
+            android:visibility="gone"
             >
+            <!-- actions will be added here -->
+        </com.android.internal.widget.NotificationActionListLayout>
 
-            <com.android.internal.widget.NotificationActionListLayout
-                android:id="@+id/actions"
-                android:layout_width="0dp"
-                android:layout_weight="1"
-                android:layout_height="@dimen/notification_action_list_height"
-                android:orientation="horizontal"
-                android:gravity="center_vertical"
-                android:visibility="gone"
-                >
-                <!-- actions will be added here -->
-            </com.android.internal.widget.NotificationActionListLayout>
+        <ImageView
+            android:id="@+id/snooze_button"
+            android:layout_width="@dimen/notification_actions_icon_size"
+            android:layout_height="@dimen/notification_actions_icon_size"
+            android:layout_gravity="center_vertical|end"
+            android:visibility="gone"
+            android:scaleType="centerInside"
+            />
 
-            <ImageView
-                android:id="@+id/snooze_button"
-                android:layout_width="48dp"
-                android:layout_height="48dp"
-                android:layout_gravity="center_vertical|end"
-                android:visibility="gone"
-                android:scaleType="centerInside"
-                />
-            <ImageView
-                android:id="@+id/bubble_button"
-                android:layout_width="48dp"
-                android:layout_height="48dp"
-                android:layout_gravity="center_vertical|end"
-                android:visibility="gone"
-                android:scaleType="centerInside"
-                />
+        <ImageView
+            android:id="@+id/bubble_button"
+            android:layout_width="@dimen/notification_actions_icon_size"
+            android:layout_height="@dimen/notification_actions_icon_size"
+            android:layout_gravity="center_vertical|end"
+            android:visibility="gone"
+            android:scaleType="centerInside"
+            />
     </LinearLayout>
 </FrameLayout>
diff --git a/core/res/res/layout/notification_template_header.xml b/core/res/res/layout/notification_template_header.xml
index d11875e..a26473a 100644
--- a/core/res/res/layout/notification_template_header.xml
+++ b/core/res/res/layout/notification_template_header.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright (C) 2015 The Android Open Source Project
   ~
   ~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,40 +13,66 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License
   -->
-<!-- extends ViewGroup -->
+<!-- extends FrameLayout -->
 <NotificationHeaderView
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:theme="@style/Theme.DeviceDefault.Notification"
     android:id="@+id/notification_header"
-    android:orientation="horizontal"
     android:layout_width="wrap_content"
-    android:layout_height="@dimen/notification_header_height"
+    android:layout_height="@dimen/notification_header_solo_height"
+    android:layout_marginBottom="@dimen/notification_header_margin_bottom"
     android:clipChildren="false"
-    style="?attr/notificationHeaderStyle">
-    <!-- Wrapper used to expand the width of the "space" containing the icon programmatically -->
-    <FrameLayout
-        android:id="@+id/header_icon_container"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content">
+    android:gravity="center_vertical"
+    android:orientation="horizontal"
+    android:theme="@style/Theme.DeviceDefault.Notification"
+    >
 
-        <com.android.internal.widget.CachingIconView
-            android:id="@+id/icon"
-            android:layout_width="?attr/notificationHeaderIconSize"
-            android:layout_height="?attr/notificationHeaderIconSize"
-            android:layout_marginEnd="@dimen/notification_header_icon_margin_end"
-            android:layout_gravity="center"
+    <com.android.internal.widget.CachingIconView
+        android:id="@+id/icon"
+        android:layout_width="@dimen/notification_icon_circle_size"
+        android:layout_height="@dimen/notification_icon_circle_size"
+        android:layout_gravity="center_vertical|start"
+        android:layout_marginStart="@dimen/notification_icon_circle_start"
+        android:background="@drawable/notification_icon_circle"
+        android:padding="@dimen/notification_icon_circle_padding"
         />
-    </FrameLayout>
-    <include layout="@layout/notification_template_top_line" />
+
+    <!-- extends ViewGroup -->
+    <NotificationTopLineView
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/notification_top_line"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_gravity="center_vertical"
+        android:clipChildren="false"
+        android:gravity="center_vertical"
+        android:paddingEnd="@dimen/notification_heading_margin_end"
+        android:paddingStart="@dimen/notification_content_margin_start"
+        android:theme="@style/Theme.DeviceDefault.Notification"
+        >
+
+        <TextView
+            android:id="@+id/app_name_text"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="@dimen/notification_header_separating_margin"
+            android:singleLine="true"
+            android:textAppearance="?attr/notificationHeaderTextAppearance"
+            android:visibility="?attr/notificationHeaderAppNameVisibility"
+            />
+
+        <include layout="@layout/notification_top_line_views" />
+
+    </NotificationTopLineView>
+
     <com.android.internal.widget.NotificationExpandButton
         android:id="@+id/expand_button"
-        android:background="@null"
         android:layout_width="@dimen/notification_header_expand_icon_size"
         android:layout_height="@dimen/notification_header_expand_icon_size"
-        android:layout_marginStart="4dp"
-        android:paddingTop="@dimen/notification_expand_button_padding_top"
-        android:visibility="gone"
+        android:layout_gravity="center_vertical|end"
         android:contentDescription="@string/expand_button_content_description_collapsed"
+        android:paddingTop="@dimen/notification_expand_button_padding_top"
+        android:scaleType="center"
+        android:visibility="gone"
         />
-</NotificationHeaderView>
 
+</NotificationHeaderView>
diff --git a/core/res/res/layout/notification_template_material_base.xml b/core/res/res/layout/notification_template_material_base.xml
index 34c7fa7..46b3a8f 100644
--- a/core/res/res/layout/notification_template_material_base.xml
+++ b/core/res/res/layout/notification_template_material_base.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright (C) 2014 The Android Open Source Project
   ~
   ~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,30 +14,115 @@
   ~ limitations under the License
   -->
 
-<FrameLayout
+<com.android.internal.widget.NotificationMaxHeightFrameLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/status_bar_latest_event_content"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:tag="base" >
-    <include layout="@layout/notification_template_header" />
-    <LinearLayout
-        android:id="@+id/notification_main_column"
+    android:minHeight="@dimen/notification_headerless_min_height"
+    android:tag="base"
+    >
+
+    <com.android.internal.widget.CachingIconView
+        android:id="@+id/icon"
+        android:layout_width="@dimen/notification_icon_circle_size"
+        android:layout_height="@dimen/notification_icon_circle_size"
+        android:layout_gravity="center_vertical|start"
+        android:layout_marginStart="@dimen/notification_icon_circle_start"
+        android:background="@drawable/notification_icon_circle"
+        android:padding="@dimen/notification_icon_circle_padding"
+        />
+
+    <com.android.internal.widget.RemeasuringLinearLayout
+        android:id="@+id/notification_standard_view_column"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_gravity="top"
-        android:layout_marginStart="@dimen/notification_content_margin_start"
-        android:layout_marginEnd="@dimen/notification_content_margin_end"
-        android:layout_marginTop="@dimen/notification_content_margin_top"
-        android:layout_marginBottom="@dimen/notification_content_margin"
-        android:orientation="vertical" >
-        <include layout="@layout/notification_template_part_line1" />
-        <include layout="@layout/notification_template_text" />
-        <include
+        android:layout_gravity="center_vertical"
+        android:layout_marginBottom="@dimen/notification_headerless_margin_vertical"
+        android:layout_marginTop="@dimen/notification_headerless_margin_vertical"
+        android:orientation="vertical"
+        >
+
+        <!-- extends ViewGroup -->
+        <NotificationTopLineView
+            android:id="@+id/notification_top_line"
+            android:layout_width="wrap_content"
+            android:layout_height="@dimen/notification_headerless_line_height"
+            android:layout_marginEnd="@dimen/notification_heading_margin_end"
+            android:layout_marginStart="@dimen/notification_content_margin_start"
+            android:clipChildren="false"
+            android:theme="@style/Theme.DeviceDefault.Notification"
+            >
+
+            <TextView
+                android:id="@+id/title"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:ellipsize="marquee"
+                android:fadingEdge="horizontal"
+                android:singleLine="true"
+                android:textAlignment="viewStart"
+                android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.Title"
+                />
+
+            <include layout="@layout/notification_top_line_views" />
+
+        </NotificationTopLineView>
+
+        <com.android.internal.widget.RemeasuringLinearLayout
+            android:id="@+id/notification_main_column"
             android:layout_width="match_parent"
-            android:layout_height="@dimen/notification_progress_bar_height"
-            android:layout_marginTop="@dimen/notification_progress_margin_top"
-            layout="@layout/notification_template_progress" />
-    </LinearLayout>
-    <include layout="@layout/notification_template_right_icon" />
-</FrameLayout>
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="@dimen/notification_heading_margin_end"
+            android:layout_marginStart="@dimen/notification_content_margin_start"
+            android:orientation="vertical"
+            >
+
+            <include
+                layout="@layout/notification_template_text"
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/notification_headerless_line_height"
+                android:layout_marginTop="0dp"
+                />
+
+            <include
+                layout="@layout/notification_template_progress"
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/notification_headerless_line_height"
+                />
+
+        </com.android.internal.widget.RemeasuringLinearLayout>
+    </com.android.internal.widget.RemeasuringLinearLayout>
+
+    <ImageView
+        android:id="@+id/right_icon"
+        android:layout_width="@dimen/notification_right_icon_size"
+        android:layout_height="@dimen/notification_right_icon_size"
+        android:layout_gravity="center_vertical|end"
+        android:layout_marginTop="@dimen/notification_right_icon_headerless_margin"
+        android:layout_marginBottom="@dimen/notification_right_icon_headerless_margin"
+        android:layout_marginEnd="@dimen/notification_header_expand_icon_size"
+        android:background="@drawable/notification_large_icon_outline"
+        android:importantForAccessibility="no"
+        android:scaleType="centerCrop"
+        />
+
+    <FrameLayout
+        android:id="@+id/expand_button_touch_container"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_gravity="end">
+
+        <com.android.internal.widget.NotificationExpandButton
+            android:id="@+id/expand_button"
+            android:layout_width="@dimen/notification_header_expand_icon_size"
+            android:layout_height="@dimen/notification_header_expand_icon_size"
+            android:layout_gravity="center_vertical|end"
+            android:contentDescription="@string/expand_button_content_description_collapsed"
+            android:paddingTop="@dimen/notification_expand_button_padding_top"
+            android:scaleType="center"
+            />
+
+    </FrameLayout>
+
+</com.android.internal.widget.NotificationMaxHeightFrameLayout>
diff --git a/core/res/res/layout/notification_template_material_big_base.xml b/core/res/res/layout/notification_template_material_big_base.xml
index 2106890..36903fff 100644
--- a/core/res/res/layout/notification_template_material_big_base.xml
+++ b/core/res/res/layout/notification_template_material_big_base.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright (C) 2014 The Android Open Source Project
   ~
   ~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,19 +20,30 @@
     android:layout_height="wrap_content"
     android:orientation="vertical"
     android:clipChildren="false"
-    android:tag="big" >
+    android:tag="big"
+    >
+
     <LinearLayout
-            android:id="@+id/notification_action_list_margin_target"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginBottom="@dimen/notification_action_list_height"
-            android:orientation="vertical" >
+        android:id="@+id/notification_action_list_margin_target"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginBottom="@dimen/notification_action_list_height"
+        android:orientation="vertical"
+        >
+
         <FrameLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_weight="1"
-            android:layout_gravity="top" >
-            <include layout="@layout/notification_template_header" />
+            android:layout_gravity="top"
+            >
+
+            <include
+                layout="@layout/notification_template_header"
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/notification_header_big_height"
+                />
+
             <LinearLayout
                 android:id="@+id/notification_main_column"
                 android:layout_width="match_parent"
@@ -41,28 +51,40 @@
                 android:layout_marginStart="@dimen/notification_content_margin_start"
                 android:layout_marginEnd="@dimen/notification_content_margin_end"
                 android:layout_marginTop="@dimen/notification_content_margin_top"
-                android:orientation="vertical" >
+                android:orientation="vertical"
+                >
+
                 <include layout="@layout/notification_template_part_line1" />
+
                 <include layout="@layout/notification_template_text" />
+
                 <include
                     android:layout_width="match_parent"
                     android:layout_height="@dimen/notification_progress_bar_height"
                     android:layout_marginTop="@dimen/notification_progress_margin_top"
-                    layout="@layout/notification_template_progress" />
+                    layout="@layout/notification_template_progress"
+                    />
             </LinearLayout>
+
             <include layout="@layout/notification_template_right_icon" />
         </FrameLayout>
+
         <ViewStub
             android:layout="@layout/notification_material_reply_text"
             android:id="@+id/notification_material_reply_container"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content" />
-        <include layout="@layout/notification_template_smart_reply_container"
+            android:layout_height="wrap_content"
+            />
+
+        <include
+            layout="@layout/notification_template_smart_reply_container"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginStart="@dimen/notification_content_margin_start"
             android:layout_marginEnd="@dimen/notification_content_margin_end"
-            android:layout_marginTop="@dimen/notification_content_margin" />
+            android:layout_marginTop="@dimen/notification_content_margin"
+            />
+
         <include layout="@layout/notification_material_action_list" />
     </LinearLayout>
 </FrameLayout>
diff --git a/core/res/res/layout/notification_template_material_big_media.xml b/core/res/res/layout/notification_template_material_big_media.xml
index 6c47c2c..bbe49e5 100644
--- a/core/res/res/layout/notification_template_material_big_media.xml
+++ b/core/res/res/layout/notification_template_material_big_media.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright (C) 2014 The Android Open Source Project
   ~
   ~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,22 +24,28 @@
     android:tag="bigMediaNarrow"
     >
     <!-- The size will actually be determined at runtime -->
-    <ImageView android:id="@+id/right_icon"
+    <ImageView
+        android:id="@+id/right_icon"
         android:layout_width="0dp"
         android:layout_height="0dp"
         android:layout_gravity="top|end"
         android:scaleType="centerCrop"
-    />
-    <include layout="@layout/notification_template_header"
+        />
+
+    <include
+        layout="@layout/notification_template_header"
         android:layout_width="match_parent"
         android:layout_height="@dimen/media_notification_header_height"
-        android:layout_gravity="start"/>
+        android:layout_gravity="start"
+        />
+
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:id="@+id/notification_media_content"
         >
+
         <LinearLayout
             android:id="@+id/notification_main_column"
             android:layout_width="match_parent"
@@ -52,38 +57,49 @@
             android:minHeight="@dimen/notification_min_content_height"
             android:orientation="vertical"
             >
+
             <include layout="@layout/notification_template_part_line1" />
+
             <include layout="@layout/notification_template_text" />
         </LinearLayout>
+
         <LinearLayout
             android:id="@+id/media_actions"
             android:orientation="horizontal"
             android:layoutDirection="ltr"
-            style="@style/NotificationMediaActionContainer" >
+            style="@style/NotificationMediaActionContainer"
+            >
+
             <include
                 layout="@layout/notification_material_media_action"
                 android:id="@+id/action0"
-            />
+                />
+
             <include
                 layout="@layout/notification_material_media_action"
                 android:id="@+id/action1"
-            />
+                />
+
             <include
                 layout="@layout/notification_material_media_action"
                 android:id="@+id/action2"
-            />
+                />
+
             <include
                 layout="@layout/notification_material_media_action"
                 android:id="@+id/action3"
-            />
+                />
+
             <include
                 layout="@layout/notification_material_media_action"
                 android:id="@+id/action4"
-            />
+                />
         </LinearLayout>
-        <ViewStub android:id="@+id/notification_media_seekbar_container"
+
+        <ViewStub
+            android:id="@+id/notification_media_seekbar_container"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-        />
+            />
     </LinearLayout>
 </com.android.internal.widget.MediaNotificationView>
diff --git a/core/res/res/layout/notification_template_material_big_picture.xml b/core/res/res/layout/notification_template_material_big_picture.xml
index 7a1cc1e..38853c6 100644
--- a/core/res/res/layout/notification_template_material_big_picture.xml
+++ b/core/res/res/layout/notification_template_material_big_picture.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright (C) 2014 The Android Open Source Project
   ~
   ~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,61 +14,83 @@
   ~ limitations under the License
   -->
 
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/status_bar_latest_event_content"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:tag="bigPicture"
     android:clipChildren="false"
     >
-    <include layout="@layout/notification_template_header" />
+
+    <include
+        layout="@layout/notification_template_header"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/notification_header_big_height"
+        />
+
     <include layout="@layout/notification_template_right_icon" />
+
     <LinearLayout
-            android:id="@+id/notification_action_list_margin_target"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:layout_gravity="top"
-            android:layout_marginTop="@dimen/notification_content_margin_top"
-            android:clipToPadding="false"
-            android:orientation="vertical"
-            >
+        android:id="@+id/notification_action_list_margin_target"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_gravity="top"
+        android:layout_marginTop="@dimen/notification_content_margin_top"
+        android:clipToPadding="false"
+        android:orientation="vertical"
+        >
+
         <LinearLayout
             android:id="@+id/notification_main_column"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginStart="@dimen/notification_content_margin_start"
             android:layout_marginEnd="@dimen/notification_content_margin_end"
-            android:orientation="vertical">
-            <include layout="@layout/notification_template_part_line1"/>
-            <include layout="@layout/notification_template_progress"
-                     android:layout_width="match_parent"
-                     android:layout_height="@dimen/notification_progress_bar_height"
-                     android:layout_marginTop="@dimen/notification_progress_margin_top"/>
-            <include layout="@layout/notification_template_text"/>
-        </LinearLayout>
-        <ImageView
-                android:id="@+id/big_picture"
+            android:orientation="vertical"
+            >
+
+            <include layout="@layout/notification_template_part_line1" />
+
+            <include
+                layout="@layout/notification_template_progress"
                 android:layout_width="match_parent"
-                android:layout_height="0dp"
-                android:adjustViewBounds="true"
-                android:layout_weight="1"
-                android:layout_marginTop="13dp"
-                android:layout_marginStart="@dimen/notification_content_margin_start"
-                android:layout_marginEnd="@dimen/notification_content_margin_end"
-                android:scaleType="centerCrop"
+                android:layout_height="@dimen/notification_progress_bar_height"
+                android:layout_marginTop="@dimen/notification_progress_margin_top"
                 />
 
-        <ViewStub android:layout="@layout/notification_material_reply_text"
-                android:id="@+id/notification_material_reply_container"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                />
-        <include layout="@layout/notification_template_smart_reply_container"
+            <include layout="@layout/notification_template_text" />
+        </LinearLayout>
+
+        <ImageView
+            android:id="@+id/big_picture"
+            android:layout_width="match_parent"
+            android:layout_height="0dp"
+            android:adjustViewBounds="true"
+            android:layout_weight="1"
+            android:layout_marginTop="13dp"
+            android:layout_marginStart="@dimen/notification_content_margin_start"
+            android:layout_marginEnd="@dimen/notification_content_margin_end"
+            android:background="@drawable/notification_big_picture_outline"
+            android:scaleType="centerCrop"
+            />
+
+        <ViewStub
+            android:layout="@layout/notification_material_reply_text"
+            android:id="@+id/notification_material_reply_container"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            />
+
+        <include
+            layout="@layout/notification_template_smart_reply_container"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginStart="@dimen/notification_content_margin_start"
             android:layout_marginEnd="@dimen/notification_content_margin_end"
-            android:layout_marginTop="@dimen/notification_content_margin" />
+            android:layout_marginTop="@dimen/notification_content_margin"
+            />
+
         <include layout="@layout/notification_material_action_list" />
     </LinearLayout>
 </FrameLayout>
diff --git a/core/res/res/layout/notification_template_material_big_text.xml b/core/res/res/layout/notification_template_material_big_text.xml
index d5ea96f..b8e827d 100644
--- a/core/res/res/layout/notification_template_material_big_text.xml
+++ b/core/res/res/layout/notification_template_material_big_text.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright (C) 2014 The Android Open Source Project
   ~
   ~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,24 +14,31 @@
   ~ limitations under the License
   -->
 
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/status_bar_latest_event_content"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:clipChildren="false"
     android:tag="bigText"
     >
-    <include layout="@layout/notification_template_header" />
+
+    <include
+        layout="@layout/notification_template_header"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/notification_header_big_height"
+        />
 
     <com.android.internal.widget.RemeasuringLinearLayout
-            android:id="@+id/notification_action_list_margin_target"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:layout_gravity="top"
-            android:layout_marginTop="@dimen/notification_content_margin_top"
-            android:layout_marginBottom="@dimen/notification_action_list_height"
-            android:clipToPadding="false"
-            android:orientation="vertical">
+        android:id="@+id/notification_action_list_margin_target"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_gravity="top"
+        android:layout_marginTop="@dimen/notification_content_margin_top"
+        android:layout_marginBottom="@dimen/notification_action_list_height"
+        android:clipToPadding="false"
+        android:orientation="vertical"
+        >
 
         <com.android.internal.widget.RemeasuringLinearLayout
             android:id="@+id/notification_main_column"
@@ -46,13 +52,19 @@
             android:orientation="vertical"
             android:layout_weight="1"
             >
+
             <include layout="@layout/notification_template_part_line1" />
-            <include layout="@layout/notification_template_progress"
+
+            <include
+                layout="@layout/notification_template_progress"
                 android:layout_width="match_parent"
                 android:layout_height="@dimen/notification_progress_bar_height"
                 android:layout_marginTop="@dimen/notification_progress_margin_top"
-                android:layout_marginBottom="6dp"/>
-            <com.android.internal.widget.ImageFloatingTextView android:id="@+id/big_text"
+                android:layout_marginBottom="6dp"
+                />
+
+            <com.android.internal.widget.ImageFloatingTextView
+                android:id="@+id/big_text"
                 style="@style/Widget.DeviceDefault.Notification.Text"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -64,17 +76,24 @@
                 />
         </com.android.internal.widget.RemeasuringLinearLayout>
 
-        <ViewStub android:layout="@layout/notification_material_reply_text"
-                android:id="@+id/notification_material_reply_container"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content" />
-        <include layout="@layout/notification_template_smart_reply_container"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_marginStart="@dimen/notification_content_margin_start"
-                android:layout_marginEnd="@dimen/notification_content_margin_end"
-                android:layout_marginTop="@dimen/notification_content_margin" />
+        <ViewStub
+            android:layout="@layout/notification_material_reply_text"
+            android:id="@+id/notification_material_reply_container"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            />
+
+        <include
+            layout="@layout/notification_template_smart_reply_container"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="@dimen/notification_content_margin_start"
+            android:layout_marginEnd="@dimen/notification_content_margin_end"
+            android:layout_marginTop="@dimen/notification_content_margin"
+            />
+
         <include layout="@layout/notification_material_action_list" />
     </com.android.internal.widget.RemeasuringLinearLayout>
+
     <include layout="@layout/notification_template_right_icon" />
 </FrameLayout>
diff --git a/core/res/res/layout/notification_template_material_conversation.xml b/core/res/res/layout/notification_template_material_conversation.xml
index 48cfa07..520ae28 100644
--- a/core/res/res/layout/notification_template_material_conversation.xml
+++ b/core/res/res/layout/notification_template_material_conversation.xml
@@ -33,6 +33,7 @@
         android:clipToPadding="false"
         android:paddingTop="12dp"
         android:paddingBottom="12dp"
+        android:importantForAccessibility="no"
     >
 
         <FrameLayout
@@ -206,17 +207,19 @@
                         android:visibility="gone"
                     />
 
-                    <ImageView
-                        android:id="@+id/alerted_icon"
-                        android:layout_width="@dimen/notification_alerted_size"
-                        android:layout_height="@dimen/notification_alerted_size"
+                    <ImageButton
+                        android:id="@+id/feedback"
+                        android:layout_width="@dimen/notification_feedback_size"
+                        android:layout_height="@dimen/notification_feedback_size"
                         android:layout_gravity="center"
-                        android:layout_marginStart="4dp"
+                        android:layout_marginStart="@dimen/notification_header_separating_margin"
+                        android:background="?android:selectableItemBackgroundBorderless"
+                        android:contentDescription="@string/notification_feedback_indicator"
                         android:paddingTop="2dp"
                         android:scaleType="fitCenter"
+                        android:src="@drawable/ic_feedback_indicator"
                         android:visibility="gone"
-                        android:contentDescription="@string/notification_alerted_content_description"
-                        android:src="@drawable/ic_notifications_alerted"/>
+                        />
 
                     <ImageView
                         android:id="@+id/profile_badge"
@@ -228,7 +231,21 @@
                         android:scaleType="fitCenter"
                         android:visibility="gone"
                         android:contentDescription="@string/notification_work_profile_content_description"
-                    />
+                        />
+
+                    <ImageView
+                        android:id="@+id/alerted_icon"
+                        android:layout_width="@dimen/notification_alerted_size"
+                        android:layout_height="@dimen/notification_alerted_size"
+                        android:layout_gravity="center"
+                        android:layout_marginStart="4dp"
+                        android:contentDescription="@string/notification_alerted_content_description"
+                        android:paddingTop="2dp"
+                        android:scaleType="fitCenter"
+                        android:src="@drawable/ic_notifications_alerted"
+                        android:visibility="gone"
+                        />
+
                     <LinearLayout
                         android:id="@+id/app_ops"
                         android:layout_height="wrap_content"
@@ -268,19 +285,6 @@
                             android:contentDescription="@string/notification_appops_overlay_active"
                             />
                     </LinearLayout>
-                    <ImageButton
-                        android:id="@+id/feedback"
-                        android:layout_width="@dimen/notification_feedback_size"
-                        android:layout_height="@dimen/notification_feedback_size"
-                        android:layout_marginStart="@dimen/notification_header_separating_margin"
-                        android:paddingTop="2dp"
-                        android:layout_gravity="center"
-                        android:scaleType="fitCenter"
-                        android:src="@drawable/ic_feedback_indicator"
-                        android:background="?android:selectableItemBackgroundBorderless"
-                        android:visibility="gone"
-                        android:contentDescription="@string/notification_feedback_indicator"
-                    />
                 </LinearLayout>
 
                 <!-- Messages -->
@@ -320,7 +324,7 @@
             collapsed layout while the parent makes sure that we're never laid out bigger
             than the messaging content.-->
         <LinearLayout
-            android:id="@+id/expand_button_inner_container"
+            android:id="@+id/expand_button_touch_container"
             android:layout_width="wrap_content"
             android:layout_height="@dimen/conversation_expand_button_size"
             android:paddingStart="16dp"
@@ -359,12 +363,11 @@
                 />
             <com.android.internal.widget.NotificationExpandButton
                 android:id="@+id/expand_button"
-                android:layout_width="@dimen/notification_header_expand_icon_size"
-                android:layout_height="@dimen/notification_header_expand_icon_size"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
                 android:layout_gravity="center"
                 android:drawable="@drawable/ic_expand_notification"
-                android:clickable="false"
-                android:importantForAccessibility="no"
+                android:contentDescription="@string/expand_button_content_description_collapsed"
                 />
         </LinearLayout>
     </FrameLayout>
diff --git a/core/res/res/layout/notification_template_material_heads_up_base.xml b/core/res/res/layout/notification_template_material_heads_up_base.xml
new file mode 100644
index 0000000..d554991
--- /dev/null
+++ b/core/res/res/layout/notification_template_material_heads_up_base.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ Copyright (C) 2014 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/status_bar_latest_event_content"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:clipChildren="false"
+    android:tag="headsUp"
+    >
+
+    <com.android.internal.widget.RemeasuringLinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:clipChildren="false"
+        android:orientation="vertical"
+        >
+
+        <include
+            layout="@layout/notification_template_material_base"
+            android:id="@null"
+            />
+
+        <com.android.internal.widget.RemeasuringLinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="-12dp"
+            android:clipChildren="false"
+            android:orientation="vertical"
+            >
+
+            <ViewStub
+                android:layout="@layout/notification_material_reply_text"
+                android:id="@+id/notification_material_reply_container"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                />
+
+            <include
+                layout="@layout/notification_template_smart_reply_container"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="@dimen/notification_content_margin_start"
+                android:layout_marginEnd="@dimen/notification_content_margin_end"
+                android:layout_marginTop="@dimen/notification_content_margin"
+                />
+
+            <include layout="@layout/notification_material_action_list" />
+        </com.android.internal.widget.RemeasuringLinearLayout>
+    </com.android.internal.widget.RemeasuringLinearLayout>
+</FrameLayout>
diff --git a/core/res/res/layout/notification_template_material_messaging.xml b/core/res/res/layout/notification_template_material_messaging.xml
index 10c7509..de9814b 100644
--- a/core/res/res/layout/notification_template_material_messaging.xml
+++ b/core/res/res/layout/notification_template_material_messaging.xml
@@ -57,5 +57,5 @@
                 android:layout_marginEnd="@dimen/notification_content_margin_end" />
         <include layout="@layout/notification_material_action_list" />
     </com.android.internal.widget.RemeasuringLinearLayout>
-    <include layout="@layout/notification_template_right_icon"/>
+    <include layout="@layout/notification_template_right_icon" />
 </com.android.internal.widget.MessagingLayout>
diff --git a/core/res/res/layout/notification_template_part_line1.xml b/core/res/res/layout/notification_template_part_line1.xml
index 622f080..fc5bd9c 100644
--- a/core/res/res/layout/notification_template_part_line1.xml
+++ b/core/res/res/layout/notification_template_part_line1.xml
@@ -22,7 +22,7 @@
     android:orientation="horizontal"
     >
     <TextView android:id="@+id/title"
-        android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.Title"
+        android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.BigTitle"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:singleLine="true"
diff --git a/core/res/res/layout/notification_template_right_icon.xml b/core/res/res/layout/notification_template_right_icon.xml
index ee416ad..d22d4c2 100644
--- a/core/res/res/layout/notification_template_right_icon.xml
+++ b/core/res/res/layout/notification_template_right_icon.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright (C) 2015 The Android Open Source Project
   ~
   ~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,29 +13,15 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License
   -->
-<!-- The view only has 8dp padding at the end instead of notification_content_margin_end,
-     since the reply icon has an inset of 8dp and we want it to visually start at the start of the
-     icon. -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-             android:id="@+id/right_icon_container"
-             android:layout_width="wrap_content"
-             android:layout_height="wrap_content"
-             android:layout_marginTop="@dimen/notification_content_margin_top"
-             android:layout_marginEnd="8dp"
-             android:layout_gravity="top|end">
-    <ImageView android:id="@+id/right_icon"
-               android:layout_width="@dimen/notification_right_icon_size"
-               android:layout_height="@dimen/notification_right_icon_size"
-               android:layout_gravity="top|end"
-               android:layout_marginEnd="8dp"
-               android:scaleType="centerCrop"
-               android:importantForAccessibility="no" />
-    <ImageView android:id="@+id/reply_icon_action"
-                 android:layout_width="@dimen/notification_right_icon_size"
-                 android:layout_height="@dimen/notification_right_icon_size"
-                 android:layout_gravity="top|end"
-                 android:contentDescription="@string/notification_reply_button_accessibility"
-                 android:scaleType="centerCrop"
-                 android:src="@drawable/ic_reply_notification"/>
-</LinearLayout>
-
+<ImageView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/right_icon"
+    android:layout_width="@dimen/notification_right_icon_size"
+    android:layout_height="@dimen/notification_right_icon_size"
+    android:layout_gravity="top|end"
+    android:layout_marginEnd="@dimen/notification_header_expand_icon_size"
+    android:layout_marginTop="@dimen/notification_right_icon_big_margin_top"
+    android:background="@drawable/notification_large_icon_outline"
+    android:importantForAccessibility="no"
+    android:scaleType="centerCrop"
+    />
diff --git a/core/res/res/layout/notification_template_text.xml b/core/res/res/layout/notification_template_text.xml
index 01b14ae..4920c79 100644
--- a/core/res/res/layout/notification_template_text.xml
+++ b/core/res/res/layout/notification_template_text.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright (C) 2016 The Android Open Source Project
   ~
   ~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,11 +13,12 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License
   -->
-<com.android.internal.widget.ImageFloatingTextView xmlns:android="http://schemas.android.com/apk/res/android"
+<com.android.internal.widget.ImageFloatingTextView
+    xmlns:android="http://schemas.android.com/apk/res/android"
     style="@style/Widget.DeviceDefault.Notification.Text"
     android:id="@+id/text"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="@dimen/notification_text_height"
     android:layout_gravity="top"
     android:layout_marginTop="@dimen/notification_text_margin_top"
     android:ellipsize="marquee"
diff --git a/core/res/res/layout/notification_template_top_line.xml b/core/res/res/layout/notification_top_line_views.xml
similarity index 82%
rename from core/res/res/layout/notification_template_top_line.xml
rename to core/res/res/layout/notification_top_line_views.xml
index 0786e13..51974ac 100644
--- a/core/res/res/layout/notification_template_top_line.xml
+++ b/core/res/res/layout/notification_top_line_views.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
   ~ Copyright (C) 2015 The Android Open Source Project
   ~
   ~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,25 +13,13 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License
   -->
-<!-- extends ViewGroup -->
-<NotificationTopLineView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:theme="@style/Theme.DeviceDefault.Notification"
-    android:id="@+id/notification_top_line"
-    android:layout_width="wrap_content"
-    android:layout_height="@dimen/notification_header_height"
-    android:clipChildren="false"
-    >
-    <TextView
-        android:id="@+id/app_name_text"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:textAppearance="?attr/notificationHeaderTextAppearance"
-        android:layout_marginStart="@dimen/notification_header_app_name_margin_start"
-        android:layout_marginEnd="@dimen/notification_header_separating_margin"
-        android:visibility="?attr/notificationHeaderAppNameVisibility"
-        android:singleLine="true"
-        />
+<!--
+ This layout file should be included inside a NotificationTopLineView, usually after either a
+ <TextView android:id="@+id/app_name_text"/> or <TextView android:id="@+id/title"/>
+-->
+<merge
+    xmlns:android="http://schemas.android.com/apk/res/android">
+
     <TextView
         android:id="@+id/header_text_secondary_divider"
         android:layout_width="wrap_content"
@@ -41,7 +28,9 @@
         android:layout_marginStart="@dimen/notification_header_separating_margin"
         android:layout_marginEnd="@dimen/notification_header_separating_margin"
         android:text="@string/notification_header_divider_symbol"
-        android:visibility="gone"/>
+        android:visibility="gone"
+        />
+
     <TextView
         android:id="@+id/header_text_secondary"
         android:layout_width="wrap_content"
@@ -50,7 +39,9 @@
         android:layout_marginStart="@dimen/notification_header_separating_margin"
         android:layout_marginEnd="@dimen/notification_header_separating_margin"
         android:visibility="gone"
-        android:singleLine="true"/>
+        android:singleLine="true"
+        />
+
     <TextView
         android:id="@+id/header_text_divider"
         android:layout_width="wrap_content"
@@ -59,7 +50,9 @@
         android:layout_marginStart="@dimen/notification_header_separating_margin"
         android:layout_marginEnd="@dimen/notification_header_separating_margin"
         android:text="@string/notification_header_divider_symbol"
-        android:visibility="gone"/>
+        android:visibility="gone"
+        />
+
     <TextView
         android:id="@+id/header_text"
         android:layout_width="wrap_content"
@@ -68,7 +61,9 @@
         android:layout_marginStart="@dimen/notification_header_separating_margin"
         android:layout_marginEnd="@dimen/notification_header_separating_margin"
         android:visibility="gone"
-        android:singleLine="true"/>
+        android:singleLine="true"
+        />
+
     <TextView
         android:id="@+id/time_divider"
         android:layout_width="wrap_content"
@@ -78,7 +73,9 @@
         android:layout_marginEnd="@dimen/notification_header_separating_margin"
         android:text="@string/notification_header_divider_symbol"
         android:singleLine="true"
-        android:visibility="gone"/>
+        android:visibility="gone"
+        />
+
     <DateTimeView
         android:id="@+id/time"
         android:textAppearance="@style/TextAppearance.Material.Notification.Time"
@@ -88,7 +85,9 @@
         android:layout_marginEnd="@dimen/notification_header_separating_margin"
         android:showRelative="true"
         android:singleLine="true"
-        android:visibility="gone" />
+        android:visibility="gone"
+        />
+
     <ViewStub
         android:id="@+id/chronometer"
         android:layout_width="wrap_content"
@@ -98,17 +97,7 @@
         android:layout="@layout/notification_template_part_chronometer"
         android:visibility="gone"
         />
-    <ImageView
-        android:id="@+id/alerted_icon"
-        android:layout_width="@dimen/notification_alerted_size"
-        android:layout_height="@dimen/notification_alerted_size"
-        android:layout_marginStart="4dp"
-        android:baseline="10dp"
-        android:scaleType="fitCenter"
-        android:visibility="gone"
-        android:contentDescription="@string/notification_alerted_content_description"
-        android:src="@drawable/ic_notifications_alerted"
-    />
+
     <ImageButton
         android:id="@+id/feedback"
         android:layout_width="@dimen/notification_feedback_size"
@@ -121,7 +110,8 @@
         android:background="?android:selectableItemBackgroundBorderless"
         android:visibility="gone"
         android:contentDescription="@string/notification_feedback_indicator"
-    />
+        />
+
     <ImageView
         android:id="@+id/profile_badge"
         android:layout_width="@dimen/notification_badge_size"
@@ -132,5 +122,17 @@
         android:visibility="gone"
         android:contentDescription="@string/notification_work_profile_content_description"
         />
-</NotificationTopLineView>
+
+    <ImageView
+        android:id="@+id/alerted_icon"
+        android:layout_width="@dimen/notification_alerted_size"
+        android:layout_height="@dimen/notification_alerted_size"
+        android:layout_marginStart="4dp"
+        android:baseline="10dp"
+        android:contentDescription="@string/notification_alerted_content_description"
+        android:scaleType="fitCenter"
+        android:src="@drawable/ic_notifications_alerted"
+        android:visibility="gone"
+        />
+</merge>
 
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index 544be54e..d7722ef 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -207,14 +207,14 @@
     <!-- Default padding for dialogs. -->
     <dimen name="dialog_padding">16dp</dimen>
 
-    <!-- The margin on the start of the content view -->
-    <dimen name="notification_content_margin_start">16dp</dimen>
+    <!-- The margin on the start of the content view (accommodates the icon) -->
+    <dimen name="notification_content_margin_start">52dp</dimen>
 
-    <!-- The margin on the end of the content view. -->
+    <!-- The margin on the end of most content views (ignores the expander) -->
     <dimen name="notification_content_margin_end">16dp</dimen>
 
-    <!-- The inset of the reply icon. -->
-    <dimen name="notification_reply_inset">8dp</dimen>
+    <!-- The margin on the end of the top-line content views (accommodates the expander) -->
+    <dimen name="notification_heading_margin_end">48dp</dimen>
 
     <!-- The margin for text at the end of the image view for media notifications -->
     <dimen name="notification_media_image_margin_end">72dp</dimen>
@@ -228,11 +228,18 @@
     <!-- The height of the notification action list -->
     <dimen name="notification_action_emphasized_height">48dp</dimen>
 
+    <!-- The padding of the actions in non-conversation layout. For conversations, the analogous
+         value is calculated in ConversationLayout#updateActionListPadding() -->
+    <dimen name="notification_actions_padding_start">36dp</dimen>
+
+    <!-- The size of icons for visual actions in the notification_material_action_list -->
+    <dimen name="notification_actions_icon_size">48dp</dimen>
+
     <!-- Size of the stroke with for the emphasized notification button style -->
     <dimen name="emphasized_button_stroke_width">1dp</dimen>
 
     <!-- height of the content margin to accomodate for the header -->
-    <dimen name="notification_content_margin_top">46dp</dimen>
+    <dimen name="notification_content_margin_top">50dp</dimen>
 
     <!-- height of the content margin that is applied at the end of the notification content -->
     <dimen name="notification_content_margin">20dp</dimen>
@@ -243,8 +250,11 @@
     <!-- The top margin before the notification progress bar. -->
     <dimen name="notification_progress_margin_top">8dp</dimen>
 
-    <!-- height of the notification header (for icon and package name) -->
-    <dimen name="notification_header_height">50dp</dimen>
+    <!-- height of the notification header when the notification is alone (minimized / groups) -->
+    <dimen name="notification_header_solo_height">48dp</dimen>
+
+    <!-- height of the notification header when in a "big" layout -->
+    <dimen name="notification_header_big_height">56dp</dimen>
 
     <!-- The height of the background for a notification header on a group -->
     <dimen name="notification_header_background_height">49.5dp</dimen>
@@ -258,12 +268,18 @@
     <!-- The margin at the bottom of the notification header. -->
     <dimen name="notification_header_margin_bottom">0dp</dimen>
 
-    <!-- The end margin after the application icon in the notification header -->
-    <dimen name="notification_header_icon_margin_end">3dp</dimen>
-
     <!-- size (width and height) of the icon in the notification header -->
     <dimen name="notification_header_icon_size">18dp</dimen>
 
+    <!-- size (width and height) of the circle around the icon in the notification header -->
+    <dimen name="notification_icon_circle_size">24dp</dimen>
+
+    <!-- padding between the notification icon and the circle containing it -->
+    <dimen name="notification_icon_circle_padding">4dp</dimen>
+
+    <!-- start margin of the icon circle in the notification view -->
+    <dimen name="notification_icon_circle_start">16dp</dimen>
+
     <!-- size (width and height) of the icon in the notification header -->
     <dimen name="notification_header_icon_size_ambient">18dp</dimen>
 
@@ -276,14 +292,23 @@
     <!-- The margin before and after each of the items in the conversation header. -->
     <dimen name="notification_conversation_header_separating_margin">4dp</dimen>
 
-    <!-- The absolute size of the notification expand icon. -2 for wrap_content. -->
-    <dimen name="notification_header_expand_icon_size">-2px</dimen>
+    <!-- The absolute size of the notification expand icon. -->
+    <dimen name="notification_header_expand_icon_size">48dp</dimen>
 
     <!-- The top padding for the notification expand button. -->
     <dimen name="notification_expand_button_padding_top">1dp</dimen>
 
+    <!-- vertical margin for the headerless notification content -->
+    <dimen name="notification_headerless_margin_vertical">18dp</dimen>
+
+    <!-- The height of each of the 1 or 2 lines in the headerless notification template -->
+    <dimen name="notification_headerless_line_height">20sp</dimen>
+
+    <!-- vertical margin for the headerless notification content -->
+    <dimen name="notification_headerless_min_height">56dp</dimen>
+
     <!-- Height of a small notification in the status bar -->
-    <dimen name="notification_min_height">106dp</dimen>
+    <dimen name="notification_min_height">76dp</dimen>
 
     <!-- The width of the big icons in notifications. -->
     <dimen name="notification_large_icon_width">64dp</dimen>
@@ -310,7 +335,7 @@
     <dimen name="media_notification_expanded_image_margin_bottom">20dp</dimen>
 
     <!-- The absolute height for the header in a media notification. -->
-    <dimen name="media_notification_header_height">@dimen/notification_header_height</dimen>
+    <dimen name="media_notification_header_height">@dimen/notification_header_big_height</dimen>
 
     <!-- The margin of the content to an image-->
     <dimen name="notification_content_image_margin_end">8dp</dimen>
@@ -426,6 +451,8 @@
     <dimen name="notification_text_size">14sp</dimen>
     <!-- Size of notification text titles (see TextAppearance.StatusBar.EventContent.Title) -->
     <dimen name="notification_title_text_size">14sp</dimen>
+    <!-- Size of big notification text titles (see TextAppearance.StatusBar.EventContent.BigTitle) -->
+    <dimen name="notification_big_title_text_size">16sp</dimen>
     <!-- Size of smaller notification text (see TextAppearance.StatusBar.EventContent.Line2, Info, Time) -->
     <dimen name="notification_subtext_size">12sp</dimen>
     <!-- Top padding for notifications in the standard layout. -->
@@ -444,7 +471,10 @@
     <dimen name="notification_large_icon_circle_padding">11dp</dimen>
 
     <!-- The margin on top of the text of the notification -->
-    <dimen name="notification_text_margin_top">0.5dp</dimen>
+    <dimen name="notification_text_margin_top">6dp</dimen>
+
+    <!-- Height of a single line text view in a notification -->
+    <dimen name="notification_text_height">20sp</dimen>
 
     <!-- The padding on top of inbox style elements -->
     <dimen name="notification_inbox_item_top_padding">5dp</dimen>
@@ -679,7 +709,11 @@
     <!-- The maximum width of a image in a media notification. The images will be reduced to that width in case they are bigger.-->
     <dimen name="notification_media_image_max_width">280dp</dimen>
     <!-- The size of the right icon -->
-    <dimen name="notification_right_icon_size">36dp</dimen>
+    <dimen name="notification_right_icon_size">52dp</dimen>
+    <!-- The top and bottom margin of the right icon in the normal notification states -->
+    <dimen name="notification_right_icon_headerless_margin">12dp</dimen>
+    <!-- The top margin of the right icon in the "big" notification states -->
+    <dimen name="notification_right_icon_big_margin_top">16dp</dimen>
     <!-- The alpha of a disabled notification button -->
     <item type="dimen" format="float" name="notification_action_disabled_alpha">0.5</item>
 
@@ -700,8 +734,10 @@
     <!-- The maximum size of the grayscale icon -->
     <dimen name="notification_grayscale_icon_max_size">256dp</dimen>
 
-    <dimen name="messaging_avatar_size">@dimen/notification_right_icon_size</dimen>
+    <dimen name="messaging_avatar_size">36dp</dimen>
     <dimen name="conversation_avatar_size">52dp</dimen>
+    <!-- start margin of the icon circle in the conversation's skin of the header -->
+    <dimen name="conversation_icon_circle_start">28dp</dimen>
     <!-- Start of the content in the conversation template -->
     <dimen name="conversation_content_start">80dp</dimen>
     <!-- Size of the expand button in the conversation layout -->
diff --git a/core/res/res/values/styles_device_defaults.xml b/core/res/res/values/styles_device_defaults.xml
index ef019ba..439ae48 100644
--- a/core/res/res/values/styles_device_defaults.xml
+++ b/core/res/res/values/styles_device_defaults.xml
@@ -290,6 +290,9 @@
     <style name="TextAppearance.DeviceDefault.Notification.Title" parent="TextAppearance.Material.Notification.Title">
         <item name="fontFamily">@string/config_headlineFontFamilyMedium</item>
     </style>
+    <style name="TextAppearance.DeviceDefault.Notification.BigTitle" parent="TextAppearance.Material.Notification.BigTitle">
+        <item name="fontFamily">@string/config_headlineFontFamilyMedium</item>
+    </style>
     <style name="TextAppearance.DeviceDefault.Notification.Reply" parent="TextAppearance.Material.Notification.Reply">
         <item name="fontFamily">@string/config_bodyFontFamily</item>
     </style>
diff --git a/core/res/res/values/styles_material.xml b/core/res/res/values/styles_material.xml
index 67536fd..158289a 100644
--- a/core/res/res/values/styles_material.xml
+++ b/core/res/res/values/styles_material.xml
@@ -477,6 +477,11 @@
         <item name="textSize">@dimen/notification_title_text_size</item>
     </style>
 
+    <style name="TextAppearance.Material.Notification.BigTitle">
+        <item name="fontFamily">sans-serif-medium</item>
+        <item name="textSize">@dimen/notification_big_title_text_size</item>
+    </style>
+
     <style name="TextAppearance.Material.Notification.Line2">
         <item name="textSize">@dimen/notification_subtext_size</item>
     </style>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 966cb37..7567468 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -218,6 +218,7 @@
   <java-symbol type="id" name="inbox_text6" />
   <java-symbol type="id" name="status_bar_latest_event_content" />
   <java-symbol type="id" name="notification_main_column" />
+  <java-symbol type="id" name="notification_standard_view_column" />
   <java-symbol type="id" name="sms_short_code_confirm_message" />
   <java-symbol type="id" name="sms_short_code_detail_layout" />
   <java-symbol type="id" name="sms_short_code_detail_message" />
@@ -2184,6 +2185,7 @@
   <java-symbol type="layout" name="notification_material_action_list" />
   <java-symbol type="layout" name="notification_material_action_tombstone" />
   <java-symbol type="layout" name="notification_template_material_base" />
+  <java-symbol type="layout" name="notification_template_material_heads_up_base" />
   <java-symbol type="layout" name="notification_template_material_big_base" />
   <java-symbol type="layout" name="notification_template_material_big_picture" />
   <java-symbol type="layout" name="notification_template_material_inbox" />
@@ -2873,14 +2875,12 @@
   <java-symbol type="dimen" name="notification_header_shrink_min_width" />
   <java-symbol type="dimen" name="notification_content_margin_start" />
   <java-symbol type="dimen" name="notification_content_margin_end" />
-  <java-symbol type="dimen" name="notification_reply_inset" />
+  <java-symbol type="dimen" name="notification_heading_margin_end" />
   <java-symbol type="dimen" name="notification_content_margin_top" />
   <java-symbol type="dimen" name="notification_content_margin" />
   <java-symbol type="dimen" name="notification_header_background_height" />
-  <java-symbol type="dimen" name="notification_header_height" />
   <java-symbol type="dimen" name="notification_header_expand_icon_size" />
   <java-symbol type="dimen" name="notification_expand_button_padding_top" />
-  <java-symbol type="dimen" name="notification_header_icon_margin_end" />
   <java-symbol type="dimen" name="notification_header_icon_size" />
   <java-symbol type="dimen" name="notification_header_app_name_margin_start" />
   <java-symbol type="dimen" name="notification_header_separating_margin" />
@@ -3401,9 +3401,6 @@
   <java-symbol type="bool" name="config_allowEscrowTokenForTrustAgent"/>
   <java-symbol type="string" name="config_defaultTrustAgent" />
 
-  <!-- Time picker -->
-  <java-symbol type="id" name="right_icon_container"/>
-  <java-symbol type="id" name="reply_icon_action"/>
   <java-symbol type="id" name="toggle_mode"/>
   <java-symbol type="id" name="input_mode"/>
   <java-symbol type="id" name="input_header"/>
@@ -3937,8 +3934,9 @@
   <java-symbol type="dimen" name="importance_ring_anim_max_stroke_width" />
   <java-symbol type="dimen" name="importance_ring_size" />
   <java-symbol type="dimen" name="conversation_icon_size_badged" />
+  <java-symbol type="dimen" name="conversation_icon_circle_start" />
+  <java-symbol type="dimen" name="notification_icon_circle_start" />
 
-  <java-symbol type="id" name="header_icon_container" />
   <java-symbol type="attr" name="notificationHeaderTextAppearance" />
   <java-symbol type="string" name="conversation_single_line_name_display" />
   <java-symbol type="string" name="conversation_single_line_image_placeholder" />
@@ -3949,7 +3947,7 @@
   <java-symbol type="id" name="conversation_icon_badge_ring" />
   <java-symbol type="id" name="conversation_icon_badge_bg" />
   <java-symbol type="id" name="expand_button_container" />
-  <java-symbol type="id" name="expand_button_inner_container" />
+  <java-symbol type="id" name="expand_button_touch_container" />
   <java-symbol type="id" name="messaging_group_content_container" />
   <java-symbol type="id" name="expand_button_and_content_container" />
   <java-symbol type="id" name="conversation_header" />
diff --git a/packages/SystemUI/res/drawable/people_space_tile_view_card.xml b/packages/SystemUI/res/drawable/people_space_tile_view_card.xml
index 6b81703..4772ae7 100644
--- a/packages/SystemUI/res/drawable/people_space_tile_view_card.xml
+++ b/packages/SystemUI/res/drawable/people_space_tile_view_card.xml
@@ -15,14 +15,5 @@
   -->
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
     <solid android:color="@android:color/white" />
-    <padding
-        android:left="1dp"
-        android:top="1dp"
-        android:right="1dp"
-        android:bottom="1dp" />
-    <corners
-        android:bottomRightRadius="7dp"
-        android:bottomLeftRadius="7dp"
-        android:topRightRadius="7dp"
-        android:topLeftRadius="7dp" />
+    <corners android:radius="@dimen/people_space_widget_radius" />
 </shape>
\ No newline at end of file
diff --git a/packages/SystemUI/res/drawable/people_space_widget_background.xml b/packages/SystemUI/res/drawable/people_space_widget_background.xml
new file mode 100644
index 0000000..b929359
--- /dev/null
+++ b/packages/SystemUI/res/drawable/people_space_widget_background.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2020 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle" >
+    <solid
+        android:color="?android:attr/colorControlNormal" />
+    <corners android:radius="@dimen/people_space_widget_radius" />
+    <padding
+        android:left="@dimen/people_space_widget_background_padding"
+        android:top="@dimen/people_space_widget_background_padding"
+        android:right="@dimen/people_space_widget_background_padding"
+        android:bottom="@dimen/people_space_widget_background_padding"/>
+</shape>
diff --git a/packages/SystemUI/res/layout/people_space_widget.xml b/packages/SystemUI/res/layout/people_space_widget.xml
index 6020099..b417fcf 100644
--- a/packages/SystemUI/res/layout/people_space_widget.xml
+++ b/packages/SystemUI/res/layout/people_space_widget.xml
@@ -19,7 +19,7 @@
     android:id="@+id/widget_list_view"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="@android:color/holo_blue_light"
+    android:background="@drawable/people_space_widget_background"
     android:clipChildren="false"
     android:clipToPadding="false"
     android:padding="5dp"
diff --git a/packages/SystemUI/res/values-night/dimens.xml b/packages/SystemUI/res/values-night/dimens.xml
index 23e3231..d2d4198 100644
--- a/packages/SystemUI/res/values-night/dimens.xml
+++ b/packages/SystemUI/res/values-night/dimens.xml
@@ -16,8 +16,6 @@
   -->
 
 <resources>
-    <!-- The height of the divider between the individual notifications. -->
-    <dimen name="notification_divider_height">1dp</dimen>
 
     <!-- Height of the background gradient behind the screenshot UI (taller in dark mode) -->
     <dimen name="screenshot_bg_protection_height">375dp</dimen>
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index d946f7c..57e1d43 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -133,17 +133,23 @@
     <!-- Height of a small notification in the status bar which was used before android P -->
     <dimen name="notification_min_height_before_p">92dp</dimen>
 
+    <!-- Height of a small notification in the status bar which was used before android S -->
+    <dimen name="notification_min_height_before_s">106dp</dimen>
+
     <!-- Height of a large notification in the status bar -->
     <dimen name="notification_max_height">294dp</dimen>
 
     <!-- Height of a heads up notification in the status bar for legacy custom views -->
     <dimen name="notification_max_heads_up_height_legacy">128dp</dimen>
 
-    <!-- Height of a heads up notification in the status bar for custom views before andoid P -->
+    <!-- Height of a heads up notification in the status bar for custom views before android P -->
     <dimen name="notification_max_heads_up_height_before_p">148dp</dimen>
 
+    <!-- Height of a heads up notification in the status bar for custom views before android S -->
+    <dimen name="notification_max_heads_up_height_before_s">162dp</dimen>
+
     <!-- Height of a heads up notification in the status bar -->
-    <dimen name="notification_max_heads_up_height">162dp</dimen>
+    <dimen name="notification_max_heads_up_height">132dp</dimen>
 
     <!-- Height of a heads up notification in the status bar -->
     <dimen name="notification_max_heads_up_height_increased">188dp</dimen>
@@ -1296,4 +1302,7 @@
     <dimen name="media_output_dialog_header_icon_padding">16dp</dimen>
     <dimen name="media_output_dialog_icon_corner_radius">16dp</dimen>
     <dimen name="media_output_dialog_title_anim_y_delta">12.5dp</dimen>
+
+    <dimen name="people_space_widget_radius">10dp</dimen>
+    <dimen name="people_space_widget_background_padding">6dp</dimen>
 </resources>
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java
index 5f35e60..672f82c 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java
@@ -125,9 +125,9 @@
     };
 
     @Inject
-    public TakeScreenshotService(ScreenshotController globalScreenshot, UserManager userManager,
+    public TakeScreenshotService(ScreenshotController screenshotController, UserManager userManager,
             UiEventLogger uiEventLogger) {
-        mScreenshot = globalScreenshot;
+        mScreenshot = screenshotController;
         mUserManager = userManager;
         mUiEventLogger = uiEventLogger;
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java
index 25c8e7f..216b83f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java
@@ -33,6 +33,7 @@
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * A Util to manage {@link android.view.NotificationHeaderView} objects and their redundancies.
@@ -324,13 +325,15 @@
         @Override
         public boolean compare(View parent, View child, Object parentData, Object childData) {
             TextView parentView = (TextView) parent;
+            CharSequence parentText = parentView == null ? "" : parentView.getText();
             TextView childView = (TextView) child;
-            return parentView.getText().equals(childView.getText());
+            CharSequence childText = childView == null ? "" : childView.getText();
+            return Objects.equals(parentText, childText);
         }
 
         @Override
         public boolean isEmpty(View view) {
-            return TextUtils.isEmpty(((TextView) view).getText());
+            return view == null || TextUtils.isEmpty(((TextView) view).getText());
         }
     }
 
@@ -369,7 +372,9 @@
 
         @Override
         public void apply(View parent, View view, boolean apply, boolean reset) {
-            view.setVisibility(apply ? View.GONE : View.VISIBLE);
+            if (view != null) {
+                view.setVisibility(apply ? View.GONE : View.VISIBLE);
+            }
         }
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/TransformableView.java b/packages/SystemUI/src/com/android/systemui/statusbar/TransformableView.java
index 063252f..e932bfe 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/TransformableView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/TransformableView.java
@@ -28,6 +28,7 @@
     int TRANSFORMING_VIEW_IMAGE = 3;
     int TRANSFORMING_VIEW_PROGRESS = 4;
     int TRANSFORMING_VIEW_ACTIONS = 5;
+    int TRANSFORMING_VIEW_EXPANDER = 6;
 
     /**
      * Get the current state of a view in a transform animation
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/TransformState.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/TransformState.java
index 9a8cff0..20d10d3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/TransformState.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/TransformState.java
@@ -456,9 +456,6 @@
         if (view instanceof ImageView) {
             ImageTransformState result = ImageTransformState.obtain();
             result.initFrom(view, transformInfo);
-            if (view.getId() == com.android.internal.R.id.reply_icon_action) {
-                ((TransformState) result).setIsSameAsAnyView(true);
-            }
             return result;
         }
         if (view instanceof ProgressBar) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
index 3e23a93..ea39064 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
@@ -35,7 +35,6 @@
 import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.content.res.Resources;
-import android.graphics.Color;
 import android.graphics.Path;
 import android.graphics.drawable.AnimatedVectorDrawable;
 import android.graphics.drawable.AnimationDrawable;
@@ -71,6 +70,7 @@
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.internal.util.ContrastColorUtil;
 import com.android.internal.widget.CachingIconView;
+import com.android.internal.widget.MessagingLayout;
 import com.android.systemui.Dependency;
 import com.android.systemui.Interpolators;
 import com.android.systemui.R;
@@ -154,14 +154,16 @@
     private int mIconTransformContentShift;
     private int mMaxHeadsUpHeightBeforeN;
     private int mMaxHeadsUpHeightBeforeP;
+    private int mMaxHeadsUpHeightBeforeS;
     private int mMaxHeadsUpHeight;
     private int mMaxHeadsUpHeightIncreased;
-    private int mNotificationMinHeightBeforeN;
-    private int mNotificationMinHeightBeforeP;
-    private int mNotificationMinHeight;
-    private int mNotificationMinHeightLarge;
-    private int mNotificationMinHeightMedia;
-    private int mNotificationMaxHeight;
+    private int mMaxSmallHeightBeforeN;
+    private int mMaxSmallHeightBeforeP;
+    private int mMaxSmallHeightBeforeS;
+    private int mMaxSmallHeight;
+    private int mMaxSmallHeightLarge;
+    private int mMaxSmallHeightMedia;
+    private int mMaxExpandedHeight;
     private int mIncreasedPaddingBetweenElements;
     private int mNotificationLaunchHeight;
     private boolean mMustStayOnScreen;
@@ -647,28 +649,48 @@
                 != com.android.internal.R.id.status_bar_latest_event_content;
         boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
         boolean beforeP = mEntry.targetSdk < Build.VERSION_CODES.P;
-        int minHeight;
+        boolean beforeS = mEntry.targetSdk < Build.VERSION_CODES.S;
+        int smallHeight;
 
         View expandedView = layout.getExpandedChild();
         boolean isMediaLayout = expandedView != null
                 && expandedView.findViewById(com.android.internal.R.id.media_actions) != null;
+        boolean isMessagingLayout = layout.getContractedChild() instanceof MessagingLayout;
         boolean showCompactMediaSeekbar = mMediaManager.getShowCompactMediaSeekbar();
 
-        if (customView && beforeP && !mIsSummaryWithChildren) {
-            minHeight = beforeN ? mNotificationMinHeightBeforeN : mNotificationMinHeightBeforeP;
+        if (customView && beforeS && !mIsSummaryWithChildren) {
+            if (beforeN) {
+                smallHeight = mMaxSmallHeightBeforeN;
+            } else if (beforeP) {
+                smallHeight = mMaxSmallHeightBeforeP;
+            } else {
+                smallHeight = mMaxSmallHeightBeforeS;
+            }
         } else if (isMediaLayout && showCompactMediaSeekbar) {
-            minHeight = mNotificationMinHeightMedia;
+            smallHeight = mMaxSmallHeightMedia;
+        } else if (isMessagingLayout) {
+            // TODO(b/173204301): MessagingStyle notifications currently look broken when we enforce
+            //  the standard notification height, so we have to afford them more vertical space to
+            //  make sure we don't crop them terribly.  We actually need to revisit this and give
+            //  them a headerless design, then remove this hack.
+            smallHeight = mMaxSmallHeightLarge;
         } else if (mUseIncreasedCollapsedHeight && layout == mPrivateLayout) {
-            minHeight = mNotificationMinHeightLarge;
+            smallHeight = mMaxSmallHeightLarge;
         } else {
-            minHeight = mNotificationMinHeight;
+            smallHeight = mMaxSmallHeight;
         }
         boolean headsUpCustom = layout.getHeadsUpChild() != null &&
                 layout.getHeadsUpChild().getId()
                         != com.android.internal.R.id.status_bar_latest_event_content;
         int headsUpHeight;
-        if (headsUpCustom && beforeP) {
-            headsUpHeight = beforeN ? mMaxHeadsUpHeightBeforeN : mMaxHeadsUpHeightBeforeP;
+        if (headsUpCustom && beforeS) {
+            if (beforeN) {
+                headsUpHeight = mMaxHeadsUpHeightBeforeN;
+            } else if (beforeP) {
+                headsUpHeight = mMaxHeadsUpHeightBeforeP;
+            } else {
+                headsUpHeight = mMaxHeadsUpHeightBeforeS;
+            }
         } else if (mUseIncreasedHeadsUpHeight && layout == mPrivateLayout) {
             headsUpHeight = mMaxHeadsUpHeightIncreased;
         } else {
@@ -679,7 +701,7 @@
         if (headsUpWrapper != null) {
             headsUpHeight = Math.max(headsUpHeight, headsUpWrapper.getMinLayoutHeight());
         }
-        layout.setHeights(minHeight, headsUpHeight, mNotificationMaxHeight);
+        layout.setHeights(smallHeight, headsUpHeight, mMaxExpandedHeight);
     }
 
     @NonNull
@@ -1598,22 +1620,26 @@
     }
 
     private void initDimens() {
-        mNotificationMinHeightBeforeN = NotificationUtils.getFontScaledHeight(mContext,
+        mMaxSmallHeightBeforeN = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_min_height_legacy);
-        mNotificationMinHeightBeforeP = NotificationUtils.getFontScaledHeight(mContext,
+        mMaxSmallHeightBeforeP = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_min_height_before_p);
-        mNotificationMinHeight = NotificationUtils.getFontScaledHeight(mContext,
+        mMaxSmallHeightBeforeS = NotificationUtils.getFontScaledHeight(mContext,
+                R.dimen.notification_min_height_before_s);
+        mMaxSmallHeight = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_min_height);
-        mNotificationMinHeightLarge = NotificationUtils.getFontScaledHeight(mContext,
+        mMaxSmallHeightLarge = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_min_height_increased);
-        mNotificationMinHeightMedia = NotificationUtils.getFontScaledHeight(mContext,
+        mMaxSmallHeightMedia = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_min_height_media);
-        mNotificationMaxHeight = NotificationUtils.getFontScaledHeight(mContext,
+        mMaxExpandedHeight = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_max_height);
         mMaxHeadsUpHeightBeforeN = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_max_heads_up_height_legacy);
         mMaxHeadsUpHeightBeforeP = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_max_heads_up_height_before_p);
+        mMaxHeadsUpHeightBeforeS = NotificationUtils.getFontScaledHeight(mContext,
+                R.dimen.notification_max_heads_up_height_before_s);
         mMaxHeadsUpHeight = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_max_heads_up_height);
         mMaxHeadsUpHeightIncreased = NotificationUtils.getFontScaledHeight(mContext,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
index 79c3007..3287745 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
@@ -318,30 +318,13 @@
         // We need to update the expanded and the collapsed header to have exactly the same with to
         // have the expand buttons laid out at the same location.
         NotificationHeaderView contractedHeader = mContractedWrapper.getNotificationHeader();
-        if (contractedHeader != null) {
-            if (mExpandedChild != null
-                    && mExpandedWrapper.getNotificationHeader() != null) {
-                NotificationHeaderView expandedHeader = mExpandedWrapper.getNotificationHeader();
-
-                int headerTextMargin = expandedHeader.getHeaderTextMarginEnd();
-                if (headerTextMargin != contractedHeader.getHeaderTextMarginEnd()) {
-                    contractedHeader.setHeaderTextMarginEnd(headerTextMargin);
-                    return true;
-                }
-            } else {
-                int paddingEnd = mNotificationContentMarginEnd;
-                if (contractedHeader.getPaddingEnd() != paddingEnd) {
-                    contractedHeader.setPadding(
-                            contractedHeader.isLayoutRtl()
-                                    ? paddingEnd
-                                    : contractedHeader.getPaddingLeft(),
-                            contractedHeader.getPaddingTop(),
-                            contractedHeader.isLayoutRtl()
-                                    ? contractedHeader.getPaddingLeft()
-                                    : paddingEnd,
-                            contractedHeader.getPaddingBottom());
-                    return true;
-                }
+        if (contractedHeader != null && mExpandedWrapper != null
+                && mExpandedWrapper.getNotificationHeader() != null) {
+            NotificationHeaderView expandedHeader = mExpandedWrapper.getNotificationHeader();
+            int headerTextMargin = expandedHeader.getTopLineExtraMarginEnd();
+            if (headerTextMargin != contractedHeader.getTopLineExtraMarginEnd()) {
+                contractedHeader.setTopLineExtraMarginEnd(headerTextMargin);
+                return true;
             }
         }
         return false;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationBigPictureTemplateViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationBigPictureTemplateViewWrapper.java
index 7248bce..1d36ad3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationBigPictureTemplateViewWrapper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationBigPictureTemplateViewWrapper.java
@@ -40,6 +40,8 @@
     public void onContentUpdated(ExpandableNotificationRow row) {
         super.onContentUpdated(row);
         updateImageTag(row.getEntry().getSbn());
+        // Round the corners of the big picture content
+        mView.findViewById(com.android.internal.R.id.big_picture).setClipToOutline(true);
     }
 
     private void updateImageTag(StatusBarNotification notification) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationConversationTemplateViewWrapper.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationConversationTemplateViewWrapper.kt
index 17f326b..c49f6cb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationConversationTemplateViewWrapper.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationConversationTemplateViewWrapper.kt
@@ -50,7 +50,6 @@
     private lateinit var conversationBadgeBg: View
     private lateinit var expandButton: View
     private lateinit var expandButtonContainer: View
-    private lateinit var expandButtonInnerContainer: View
     private lateinit var imageMessageContainer: ViewGroup
     private lateinit var messagingLinearLayout: MessagingLinearLayout
     private lateinit var conversationTitleView: View
@@ -70,8 +69,6 @@
             expandButton = requireViewById(com.android.internal.R.id.expand_button)
             expandButtonContainer =
                     requireViewById(com.android.internal.R.id.expand_button_container)
-            expandButtonInnerContainer =
-                    requireViewById(com.android.internal.R.id.expand_button_inner_container)
             importanceRing = requireViewById(com.android.internal.R.id.conversation_icon_badge_ring)
             appName = requireViewById(com.android.internal.R.id.app_name_text)
             conversationTitleView = requireViewById(com.android.internal.R.id.conversation_text)
@@ -137,7 +134,7 @@
         )
     }
 
-    override fun getExpandButton() = expandButtonInnerContainer
+    override fun getExpandButton() = super.getExpandButton()
 
     override fun setShelfIconVisible(visible: Boolean) {
         if (conversationLayout.isImportantConversation) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java
index 5aeacab..d228ce1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java
@@ -28,7 +28,6 @@
 import android.view.ViewGroup.MarginLayoutParams;
 import android.view.animation.Interpolator;
 import android.view.animation.PathInterpolator;
-import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.TextView;
 
@@ -63,8 +62,8 @@
     private TextView mAppNameText;
     private ImageView mWorkProfileImage;
     private View mAudiblyAlertedIcon;
-    private FrameLayout mIconContainer;
     private View mFeedbackIcon;
+    private View mRightIcon;
 
     private boolean mIsLowPriority;
     private boolean mTransformLowPriorityTitle;
@@ -103,11 +102,11 @@
     }
 
     protected void resolveHeaderViews() {
-        mIconContainer = mView.findViewById(com.android.internal.R.id.header_icon_container);
         mIcon = mView.findViewById(com.android.internal.R.id.icon);
         mHeaderText = mView.findViewById(com.android.internal.R.id.header_text);
         mAppNameText = mView.findViewById(com.android.internal.R.id.app_name_text);
         mExpandButton = mView.findViewById(com.android.internal.R.id.expand_button);
+        mRightIcon = mView.findViewById(com.android.internal.R.id.right_icon);
         mWorkProfileImage = mView.findViewById(com.android.internal.R.id.profile_badge);
         mNotificationHeader = mView.findViewById(com.android.internal.R.id.notification_header);
         mNotificationTopLine = mView.findViewById(com.android.internal.R.id.notification_top_line);
@@ -145,6 +144,9 @@
         updateCropToPaddingForImageViews();
         Notification notification = row.getEntry().getSbn().getNotification();
         mIcon.setTag(ImageTransformState.ICON_TAG, notification.getSmallIcon());
+        if (mRightIcon != null) {
+            mRightIcon.setClipToOutline(true);
+        }
 
         // We need to reset all views that are no longer transforming in case a view was previously
         // transformed, but now we decided to transform its container instead.
@@ -165,19 +167,16 @@
             MarginLayoutParams layoutParams = (MarginLayoutParams) mAppNameText.getLayoutParams();
             layoutParams.setMarginStart(0);
         }
-        if (mIconContainer != null) {
-            MarginLayoutParams layoutParams = (MarginLayoutParams) mIconContainer.getLayoutParams();
-            layoutParams.width =
-                    mIconContainer.getContext().getResources().getDimensionPixelSize(
-                            com.android.internal.R.dimen.conversation_content_start);
-            final int marginStart =
-                    mIconContainer.getContext().getResources().getDimensionPixelSize(
-                            com.android.internal.R.dimen.notification_content_margin_start);
-            layoutParams.setMarginStart(marginStart * -1);
+        if (mNotificationTopLine != null) {
+            int paddingStart = mNotificationTopLine.getResources().getDimensionPixelSize(
+                    com.android.internal.R.dimen.conversation_content_start);
+            mNotificationTopLine.setPaddingStart(paddingStart);
         }
         if (mIcon != null) {
             MarginLayoutParams layoutParams = (MarginLayoutParams) mIcon.getLayoutParams();
-            layoutParams.setMarginEnd(0);
+            int marginStart = mIcon.getResources().getDimensionPixelSize(
+                    com.android.internal.R.dimen.conversation_icon_circle_start);
+            layoutParams.setMarginStart(marginStart);
         }
     }
 
@@ -189,20 +188,20 @@
                     com.android.internal.R.style.TextAppearance_DeviceDefault_Notification_Info);
             mAppNameText.setTextAppearance(textAppearance);
             MarginLayoutParams layoutParams = (MarginLayoutParams) mAppNameText.getLayoutParams();
-            final int marginStart = mAppNameText.getContext().getResources().getDimensionPixelSize(
+            final int marginStart = mAppNameText.getResources().getDimensionPixelSize(
                     com.android.internal.R.dimen.notification_header_app_name_margin_start);
             layoutParams.setMarginStart(marginStart);
         }
-        if (mIconContainer != null) {
-            MarginLayoutParams layoutParams = (MarginLayoutParams) mIconContainer.getLayoutParams();
-            layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
-            layoutParams.setMarginStart(0);
+        if (mNotificationTopLine != null) {
+            int paddingStart = mNotificationTopLine.getResources().getDimensionPixelSize(
+                    com.android.internal.R.dimen.notification_content_margin_start);
+            mNotificationTopLine.setPaddingStart(paddingStart);
         }
         if (mIcon != null) {
             MarginLayoutParams layoutParams = (MarginLayoutParams) mIcon.getLayoutParams();
-            final int marginEnd = mIcon.getContext().getResources().getDimensionPixelSize(
-                    com.android.internal.R.dimen.notification_header_icon_margin_end);
-            layoutParams.setMarginEnd(marginEnd);
+            int marginStart = mIcon.getResources().getDimensionPixelSize(
+                    com.android.internal.R.dimen.notification_icon_circle_start);
+            layoutParams.setMarginStart(marginStart);
         }
     }
 
@@ -241,8 +240,9 @@
 
     protected void updateTransformedTypes() {
         mTransformationHelper.reset();
-        mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_ICON,
-                mIcon);
+        mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_ICON, mIcon);
+        mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_EXPANDER,
+                mExpandButton);
         mTransformationHelper.addViewTransformingToSimilar(mWorkProfileImage);
         if (mIsLowPriority && mHeaderText != null) {
             mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_TITLE,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationTemplateViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationTemplateViewWrapper.java
index 76ec59e..e9934c0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationTemplateViewWrapper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationTemplateViewWrapper.java
@@ -16,14 +16,14 @@
 
 package com.android.systemui.statusbar.notification.row.wrapper;
 
+import static android.view.View.VISIBLE;
+
 import static com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.DEFAULT_HEADER_VISIBLE_AMOUNT;
 
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.res.ColorStateList;
 import android.graphics.Color;
-import android.graphics.PorterDuffColorFilter;
-import android.graphics.drawable.Drawable;
 import android.service.notification.StatusBarNotification;
 import android.util.ArraySet;
 import android.view.View;
@@ -56,7 +56,6 @@
     private TextView mTitle;
     private TextView mText;
     protected View mActionsContainer;
-    private ImageView mReplyAction;
 
     private int mContentHeight;
     private int mMinHeightHint;
@@ -64,6 +63,7 @@
     private ArraySet<PendingIntent> mCancelledPendingIntents = new ArraySet<>();
     private UiOffloadThread mUiOffloadThread;
     private View mRemoteInputHistory;
+    private boolean mCanHideHeader;
     private float mHeaderTranslation;
 
     protected NotificationTemplateViewWrapper(Context ctx, View view,
@@ -156,7 +156,6 @@
         }
         mActionsContainer = mView.findViewById(com.android.internal.R.id.actions_container);
         mActions = mView.findViewById(com.android.internal.R.id.actions);
-        mReplyAction = mView.findViewById(com.android.internal.R.id.reply_icon_action);
         mRemoteInputHistory = mView.findViewById(
                 com.android.internal.R.id.notification_material_reply_container);
         updatePendingIntentCancellations();
@@ -190,31 +189,6 @@
                 });
             }
         }
-        if (mReplyAction != null) {
-            // Let's reset the view on update, assuming the new pending intent isn't cancelled
-            // anymore. The color filter automatically resets when it's updated.
-            mReplyAction.setEnabled(true);
-            performOnPendingIntentCancellation(mReplyAction, () -> {
-                if (mReplyAction != null && mReplyAction.isEnabled()) {
-                    mReplyAction.setEnabled(false);
-                    // The visual appearance doesn't look disabled enough yet, let's add the
-                    // alpha as well. Since Alpha doesn't play nicely right now with the
-                    // transformation, we rather blend it manually with the background color.
-                    Drawable drawable = mReplyAction.getDrawable().mutate();
-                    PorterDuffColorFilter colorFilter =
-                            (PorterDuffColorFilter) drawable.getColorFilter();
-                    float disabledAlpha = mView.getResources().getFloat(
-                            com.android.internal.R.dimen.notification_action_disabled_alpha);
-                    if (colorFilter != null) {
-                        int color = colorFilter.getColor();
-                        color = blendColorWithBackground(color, disabledAlpha);
-                        drawable.mutate().setColorFilter(color, colorFilter.getMode());
-                    } else {
-                        mReplyAction.setAlpha(disabledAlpha);
-                    }
-                }
-            });
-        }
     }
 
     private int blendColorWithBackground(int color, float alpha) {
@@ -260,21 +234,15 @@
     }
 
     @Override
-    public boolean disallowSingleClick(float x, float y) {
-        if (mReplyAction != null && mReplyAction.getVisibility() == View.VISIBLE) {
-            if (isOnView(mReplyAction, x, y) || isOnView(mPicture, x, y)) {
-                return true;
-            }
-        }
-        return super.disallowSingleClick(x, y);
-    }
-
-    @Override
     public void onContentUpdated(ExpandableNotificationRow row) {
         // Reinspect the notification. Before the super call, because the super call also updates
         // the transformation types and we need to have our values set by then.
         resolveTemplateViews(row.getEntry().getSbn());
         super.onContentUpdated(row);
+        // With the modern templates, a large icon visually overlaps the header, so we can't
+        // simply hide the header -- just show the
+        mCanHideHeader = mNotificationHeader != null
+                && (mPicture == null || mPicture.getVisibility() != VISIBLE);
         if (row.getHeaderVisibleAmount() != DEFAULT_HEADER_VISIBLE_AMOUNT) {
             setHeaderVisibleAmount(row.getHeaderVisibleAmount());
         }
@@ -333,14 +301,14 @@
 
     @Override
     public int getHeaderTranslation(boolean forceNoHeader) {
-        return forceNoHeader ? mFullHeaderTranslation : (int) mHeaderTranslation;
+        return forceNoHeader && mCanHideHeader ? mFullHeaderTranslation : (int) mHeaderTranslation;
     }
 
     @Override
     public void setHeaderVisibleAmount(float headerVisibleAmount) {
         super.setHeaderVisibleAmount(headerVisibleAmount);
         float headerTranslation = 0f;
-        if (mNotificationHeader != null) {
+        if (mCanHideHeader && mNotificationHeader != null) {
             mNotificationHeader.setAlpha(headerVisibleAmount);
             headerTranslation = (1.0f - headerVisibleAmount) * mFullHeaderTranslation;
         }
diff --git a/packages/SystemUI/tools/lint/baseline.xml b/packages/SystemUI/tools/lint/baseline.xml
index 096a639..3e49403 100644
--- a/packages/SystemUI/tools/lint/baseline.xml
+++ b/packages/SystemUI/tools/lint/baseline.xml
@@ -2909,17 +2909,6 @@
 
     <issue
         id="UnusedResources"
-        message="The resource `R.dimen.notification_header_height` appears to be unused"
-        errorLine1="    &lt;dimen name=&quot;notification_header_height&quot;>53dp&lt;/dimen>"
-        errorLine2="           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
-        <location
-            file="res/values/dimens.xml"
-            line="473"
-            column="12"/>
-    </issue>
-
-    <issue
-        id="UnusedResources"
         message="The resource `R.dimen.speed_bump_height` appears to be unused"
         errorLine1="    &lt;dimen name=&quot;speed_bump_height&quot;>16dp&lt;/dimen>"
         errorLine2="           ~~~~~~~~~~~~~~~~~~~~~~~~">
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index aefe8f8..4d959d0 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -2407,7 +2407,14 @@
                         .addTransportType(NetworkCapabilities.TRANSPORT_TEST)
                         .build();
             } else {
-                req = cm.getDefaultRequest();
+                // Basically, the request here is referring to the default request which is defined
+                // in ConnectivityService. Ideally, ConnectivityManager should provide an new API
+                // which can provide the status of physical network even though there is a virtual
+                // network. b/147280869 is used for tracking the new API.
+                // TODO: Use the new API to register default physical network.
+                req = new NetworkRequest.Builder()
+                        .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
+                        .build();
             }
 
             cm.requestNetwork(req, mNetworkCallback);
diff --git a/services/core/java/com/android/server/net/LockdownVpnTracker.java b/services/core/java/com/android/server/net/LockdownVpnTracker.java
index 0b774df..64c3c28 100644
--- a/services/core/java/com/android/server/net/LockdownVpnTracker.java
+++ b/services/core/java/com/android/server/net/LockdownVpnTracker.java
@@ -16,6 +16,7 @@
 
 package com.android.server.net;
 
+import static android.net.ConnectivityManager.TYPE_NONE;
 import static android.provider.Settings.ACTION_VPN_SETTINGS;
 
 import static com.android.server.connectivity.NetworkNotificationManager.NOTIFICATION_CHANNEL_VPN;
@@ -27,7 +28,6 @@
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
-import android.net.ConnectivityManager;
 import android.net.LinkAddress;
 import android.net.LinkProperties;
 import android.net.NetworkInfo;
@@ -125,12 +125,11 @@
         final boolean egressChanged = egressProp == null
                 || !TextUtils.equals(mAcceptedEgressIface, egressProp.getInterfaceName());
 
-        final String egressTypeName = (egressInfo == null) ?
-                null : ConnectivityManager.getNetworkTypeName(egressInfo.getType());
+        final int egressType = (egressInfo == null) ? TYPE_NONE : egressInfo.getType();
         final String egressIface = (egressProp == null) ?
                 null : egressProp.getInterfaceName();
-        Slog.d(TAG, "handleStateChanged: egress=" + egressTypeName +
-                " " + mAcceptedEgressIface + "->" + egressIface);
+        Slog.d(TAG, "handleStateChanged: egress=" + egressType
+                + " " + mAcceptedEgressIface + "->" + egressIface);
 
         if (egressDisconnected || egressChanged) {
             mAcceptedEgressIface = null;
@@ -141,7 +140,6 @@
             return;
         }
 
-        final int egressType = egressInfo.getType();
         if (vpnInfo.getDetailedState() == DetailedState.FAILED) {
             EventLogTags.writeLockdownVpnError(egressType);
         }
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 2686ef7..98c38f9 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -2761,19 +2761,33 @@
         // than destroy immediately.
         final boolean isNextNotYetVisible = next != null
                 && (!next.nowVisible || !next.mVisibleRequested);
-        if (isCurrentVisible && isNextNotYetVisible) {
-            // Add this activity to the list of stopping activities. It will be processed and
-            // destroyed when the next activity reports idle.
-            addToStopping(false /* scheduleIdle */, false /* idleDelayed */,
-                    "completeFinishing");
-            setState(STOPPING, "completeFinishing");
-        } else if (addToFinishingAndWaitForIdle()) {
-            // We added this activity to the finishing list and something else is becoming resumed.
-            // The activity will complete finishing when the next activity reports idle. No need to
-            // do anything else here.
+
+        // Clear last paused activity to ensure top activity can be resumed during sleeping.
+        if (isNextNotYetVisible && mDisplayContent.isSleeping()
+                && next == next.getRootTask().mLastPausedActivity) {
+            next.getRootTask().mLastPausedActivity = null;
+        }
+
+        if (isCurrentVisible) {
+            if (isNextNotYetVisible) {
+                // Add this activity to the list of stopping activities. It will be processed and
+                // destroyed when the next activity reports idle.
+                addToStopping(false /* scheduleIdle */, false /* idleDelayed */,
+                        "completeFinishing");
+                setState(STOPPING, "completeFinishing");
+            } else if (addToFinishingAndWaitForIdle()) {
+                // We added this activity to the finishing list and something else is becoming
+                // resumed. The activity will complete finishing when the next activity reports
+                // idle. No need to do anything else here.
+            } else {
+                // Not waiting for the next one to become visible, and nothing else will be
+                // resumed in place of this activity - requesting destruction right away.
+                activityRemoved = destroyIfPossible(reason);
+            }
         } else {
-            // Not waiting for the next one to become visible, and nothing else will be resumed in
-            // place of this activity - requesting destruction right away.
+            // Just need to make sure the next activities can be resumed (if needed) and is free
+            // to destroy this activity since it is currently not visible.
+            addToFinishingAndWaitForIdle();
             activityRemoved = destroyIfPossible(reason);
         }
 
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java
index 61cc430..fc3fc47 100644
--- a/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -499,11 +499,10 @@
                         synchronized (mLock) {
                             mDisplayContent.calculateSystemGestureExclusion(
                                     excludedRegion, null /* outUnrestricted */);
-                            final boolean sideAllowed = mNavigationBarAlwaysShowOnSideGesture
-                                    || mNavigationBarPosition == NAV_BAR_RIGHT;
-                            if (mNavigationBar != null && sideAllowed
-                                    && !mSystemGestures.currentGestureStartedInRegion(
-                                            excludedRegion)) {
+                            final boolean excluded =
+                                    mSystemGestures.currentGestureStartedInRegion(excludedRegion);
+                            if (mNavigationBar != null && (mNavigationBarPosition == NAV_BAR_RIGHT
+                                    || !excluded && mNavigationBarAlwaysShowOnSideGesture)) {
                                 requestTransientBars(mNavigationBar);
                             }
                             checkAltBarSwipeForTransientBars(ALT_BAR_RIGHT);
@@ -517,11 +516,10 @@
                         synchronized (mLock) {
                             mDisplayContent.calculateSystemGestureExclusion(
                                     excludedRegion, null /* outUnrestricted */);
-                            final boolean sideAllowed = mNavigationBarAlwaysShowOnSideGesture
-                                    || mNavigationBarPosition == NAV_BAR_LEFT;
-                            if (mNavigationBar != null && sideAllowed
-                                    && !mSystemGestures.currentGestureStartedInRegion(
-                                            excludedRegion)) {
+                            final boolean excluded =
+                                    mSystemGestures.currentGestureStartedInRegion(excludedRegion);
+                            if (mNavigationBar != null && (mNavigationBarPosition == NAV_BAR_LEFT
+                                    || !excluded && mNavigationBarAlwaysShowOnSideGesture)) {
                                 requestTransientBars(mNavigationBar);
                             }
                             checkAltBarSwipeForTransientBars(ALT_BAR_LEFT);
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index 3200bbc..e8400af 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -2379,6 +2379,7 @@
                         }
                         return resumed;
                     }, false /* initValue */);
+            result |= resumedOnDisplay;
             if (!resumedOnDisplay) {
                 // In cases when there are no valid activities (e.g. device just booted or launcher
                 // crashed) it's possible that nothing was resumed on a display. Requesting resume
diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java
index 802c8f9..50b24e2 100644
--- a/services/core/java/com/android/server/wm/TaskDisplayArea.java
+++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java
@@ -1189,6 +1189,12 @@
             return;
         }
 
+        // Clear last paused activity if focused root task changed while sleeping, so that the
+        // top activity of current focused task can be resumed.
+        if (mDisplayContent.isSleeping()) {
+            currentFocusedTask.mLastPausedActivity = null;
+        }
+
         mLastFocusedStack = prevFocusedTask;
         EventLogTags.writeWmFocusedStack(mRootWindowContainer.mCurrentUser,
                 mDisplayContent.mDisplayId,
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
index 7b9ccae..54ec382 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
@@ -1020,6 +1020,32 @@
     }
 
     /**
+     * Verify that complete finish request for top invisible activity must not be delayed while
+     * sleeping, but next invisible activity must be resumed (and paused/stopped)
+     */
+    @Test
+    public void testCompleteFinishing_noWaitForNextVisible_sleeping() {
+        // Create a top activity on a new task
+        final ActivityRecord topActivity = new ActivityBuilder(mAtm).setCreateTask(true).build();
+        mDisplayContent.setIsSleeping(true);
+        doReturn(true).when(mActivity).shouldBeVisible();
+        topActivity.mVisibleRequested = false;
+        topActivity.nowVisible = false;
+        topActivity.finishing = true;
+        topActivity.setState(STOPPED, "true");
+
+        // Mark the activity behind (on a separate task) as not visible
+        mActivity.mVisibleRequested = false;
+        mActivity.nowVisible = false;
+        mActivity.setState(STOPPED, "test");
+
+        clearInvocations(mActivity);
+        topActivity.completeFinishing("test");
+        verify(mActivity).setState(eq(RESUMED), any());
+        verify(topActivity).destroyIfPossible(anyString());
+    }
+
+    /**
      * Verify that complete finish request for invisible activity must not be delayed.
      */
     @Test
@@ -1232,12 +1258,13 @@
      */
     @Test
     public void testCompleteFinishing_lastActivityAboveEmptyHomeStack() {
-        // Empty the home stack.
-        final Task homeStack = mActivity.getDisplayArea().getRootHomeTask();
-        homeStack.forAllLeafTasks((t) -> {
-            homeStack.removeChild(t, "test");
+        // Empty the home root task.
+        final Task homeRootTask = mActivity.getDisplayArea().getRootHomeTask();
+        homeRootTask.forAllLeafTasks((t) -> {
+            homeRootTask.removeChild(t, "test");
         }, true /* traverseTopToBottom */);
         mActivity.finishing = true;
+        mActivity.mVisibleRequested = true;
         spyOn(mStack);
 
         // Try to finish the last activity above the home stack.
diff --git a/tests/net/common/java/android/net/MatchAllNetworkSpecifierTest.kt b/tests/net/common/java/android/net/MatchAllNetworkSpecifierTest.kt
index a50f046..a67156a 100644
--- a/tests/net/common/java/android/net/MatchAllNetworkSpecifierTest.kt
+++ b/tests/net/common/java/android/net/MatchAllNetworkSpecifierTest.kt
@@ -19,13 +19,19 @@
 import android.net.wifi.aware.DiscoverySession
 import android.net.wifi.aware.PeerHandle
 import android.net.wifi.aware.WifiAwareNetworkSpecifier
+import android.os.Build
 import androidx.test.filters.SmallTest
 import androidx.test.runner.AndroidJUnit4
 
 import com.android.testutils.assertParcelSane
+import com.android.testutils.DevSdkIgnoreRule
+import com.android.testutils.DevSdkIgnoreRule.IgnoreAfter
+import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo
 
 import java.lang.IllegalStateException
 
+import org.junit.Assert.assertFalse
+import org.junit.Rule
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.mockito.Mockito
@@ -33,18 +39,32 @@
 @RunWith(AndroidJUnit4::class)
 @SmallTest
 class MatchAllNetworkSpecifierTest {
+    @Rule @JvmField
+    val ignoreRule: DevSdkIgnoreRule = DevSdkIgnoreRule()
+
+    private val specifier = MatchAllNetworkSpecifier()
+    private val discoverySession = Mockito.mock(DiscoverySession::class.java)
+    private val peerHandle = Mockito.mock(PeerHandle::class.java)
+    private val wifiAwareNetworkSpecifier = WifiAwareNetworkSpecifier.Builder(discoverySession,
+            peerHandle).build()
+
     @Test
     fun testParcel() {
         assertParcelSane(MatchAllNetworkSpecifier(), 0)
     }
 
+    @Test @IgnoreAfter(Build.VERSION_CODES.R)
+    fun testCanBeSatisfiedBy_BeforeS() {
+        // MatchAllNetworkSpecifier didn't follow its parent class to change the satisfiedBy() to
+        // canBeSatisfiedBy(), so if a caller calls MatchAllNetworkSpecifier#canBeSatisfiedBy(), the
+        // NetworkSpecifier#canBeSatisfiedBy() will be called actually, and false will be returned.
+        // Although it's not meeting the expectation, the behavior still needs to be verified.
+        assertFalse(specifier.canBeSatisfiedBy(wifiAwareNetworkSpecifier))
+    }
+
     @Test(expected = IllegalStateException::class)
+    @IgnoreUpTo(Build.VERSION_CODES.R)
     fun testCanBeSatisfiedBy() {
-        val specifier = MatchAllNetworkSpecifier()
-        val discoverySession = Mockito.mock(DiscoverySession::class.java)
-        val peerHandle = Mockito.mock(PeerHandle::class.java)
-        val wifiAwareNetworkSpecifier = WifiAwareNetworkSpecifier.Builder(discoverySession,
-                peerHandle).build()
         specifier.canBeSatisfiedBy(wifiAwareNetworkSpecifier)
     }
 }