From 72ea9c68847dc52ece1ab3cad5bd20045754fa85 Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Mon, 20 Sep 2021 13:26:13 -0400 Subject: [PATCH] Fix unstyled Notification RemoteViews inflation logic for apps targeting API 23 and lower. Fixes: 199152536 Test: post ForegroundServiceNotification with ApiDemos; ensure expandble. Change-Id: Iac5cb78fb8a8462c8778f92a407387c57792d812 --- core/java/android/app/Notification.java | 31 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 719025f9e2159..61b1abe25ca29 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -6506,25 +6506,34 @@ public class Notification implements Parcelable if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N && !styleDisplaysCustomViewInline()) { - if (mN.contentView == null) { - mN.contentView = createContentView(); + RemoteViews newContentView = mN.contentView; + RemoteViews newBigContentView = mN.bigContentView; + RemoteViews newHeadsUpContentView = mN.headsUpContentView; + if (newContentView == null) { + newContentView = createContentView(); mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, - mN.contentView.getSequenceNumber()); + newContentView.getSequenceNumber()); } - if (mN.bigContentView == null) { - mN.bigContentView = createBigContentView(); - if (mN.bigContentView != null) { + if (newBigContentView == null) { + newBigContentView = createBigContentView(); + if (newBigContentView != null) { mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, - mN.bigContentView.getSequenceNumber()); + newBigContentView.getSequenceNumber()); } } - if (mN.headsUpContentView == null) { - mN.headsUpContentView = createHeadsUpContentView(); - if (mN.headsUpContentView != null) { + if (newHeadsUpContentView == null) { + newHeadsUpContentView = createHeadsUpContentView(); + if (newHeadsUpContentView != null) { mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, - mN.headsUpContentView.getSequenceNumber()); + newHeadsUpContentView.getSequenceNumber()); } } + // Don't set any of the content views until after they have all been generated, + // to avoid the generated .contentView triggering the logic which skips generating + // the .bigContentView. + mN.contentView = newContentView; + mN.bigContentView = newBigContentView; + mN.headsUpContentView = newHeadsUpContentView; } if ((mN.defaults & DEFAULT_LIGHTS) != 0) {