From 1a48babb5ed30e8a3eb9645355d6455b21041406 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Fri, 17 Feb 2017 19:38:40 -0800 Subject: [PATCH] Move the inflation away from the statusbar Since the notifications need to inflate more dynamically based on their own state, the inflation is moved away from the statusbar. This also improves the apply inplace logic, that was reinflating all views even if only a single notification layout was changed. Test: runtest systemui Bug: 35125708 Change-Id: I42a33065ab60b7c45ca979ae2d7baa1518bf92b7 --- .../ActivatableNotificationView.java | 6 - .../statusbar/ExpandableNotificationRow.java | 41 +-- .../statusbar/NotificationContentView.java | 98 +++--- .../systemui/statusbar/NotificationData.java | 121 +------ .../notification/InflationException.java | 26 ++ .../NotificationCustomViewWrapper.java | 18 +- .../notification/NotificationInflater.java | 217 ++++++++++++ .../notification/NotificationViewWrapper.java | 2 +- .../systemui/statusbar/phone/StatusBar.java | 332 ++++-------------- 9 files changed, 393 insertions(+), 468 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/notification/InflationException.java create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java index 98787f7c6ec00..d4997ead8292c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java @@ -923,12 +923,6 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView mOnActivatedListener = onActivatedListener; } - public void reset() { - setTintColor(0); - resetBackgroundAlpha(); - setBelowSpeedBump(false); - } - public boolean hasSameBgColor(ActivatableNotificationView otherView) { return calculateBgColor() == otherView.calculateBgColor(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index bfe4bb266684c..58b0bcac292a3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -42,6 +42,7 @@ import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.Chronometer; import android.widget.ImageView; +import android.widget.RemoteViews; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; @@ -52,6 +53,8 @@ import com.android.systemui.R; import com.android.systemui.classifier.FalsingManager; import com.android.systemui.plugins.statusbar.NotificationMenuRowProvider.MenuItem; import com.android.systemui.statusbar.notification.HybridNotificationView; +import com.android.systemui.statusbar.notification.InflationException; +import com.android.systemui.statusbar.notification.NotificationInflater; import com.android.systemui.statusbar.notification.NotificationUtils; import com.android.systemui.statusbar.notification.VisualStabilityManager; import com.android.systemui.statusbar.phone.NotificationGroupManager; @@ -70,6 +73,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { private static final int DEFAULT_DIVIDER_ALPHA = 0x29; private static final int COLORED_DIVIDER_ALPHA = 0x7B; + private final NotificationInflater mNotificationInflater; private int mIconTransformContentShift; private int mIconTransformContentShiftNoIcon; private int mNotificationMinHeightLegacy; @@ -298,9 +302,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { } } - public void onNotificationUpdated(NotificationData.Entry entry) { + public void updateNotification(NotificationData.Entry entry) throws InflationException { mEntry = entry; mStatusBarNotification = entry.notification; + mNotificationInflater.inflateNotificationViews(); for (NotificationContentView l : mLayouts) { l.onNotificationUpdated(entry); } @@ -711,7 +716,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { } } - public void reInflateViews() { + public void onDensityOrFontScaleChanged() { initDimens(); if (mIsSummaryWithChildren) { if (mChildrenContainer != null) { @@ -742,6 +747,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { for (NotificationContentView l : mLayouts) { l.reInflateViews(); } + mNotificationInflater.onDensityOrFontScaleChanged(); + onNotificationUpdated(); } public void setContentBackground(int customBackgroundColor, boolean animate, @@ -1008,6 +1015,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { public void setIsLowPriority(boolean isLowPriority) { mIsLowPriority = isLowPriority; mPrivateLayout.setIsLowPriority(isLowPriority); + mNotificationInflater.setIsLowPriority(mIsLowPriority); if (mChildrenContainer != null) { mChildrenContainer.setIsLowPriority(isLowPriority); } @@ -1015,10 +1023,16 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { public void setUseIncreasedCollapsedHeight(boolean use) { mUseIncreasedCollapsedHeight = use; + mNotificationInflater.setUsesIncreasedHeight(use); } public void setUseIncreasedHeadsUpHeight(boolean use) { mUseIncreasedHeadsUpHeight = use; + mNotificationInflater.setUsesIncreasedHeadsUpHeight(use); + } + + public void setRemoteViewClickHandler(RemoteViews.OnClickHandler remoteViewClickHandler) { + mNotificationInflater.setRemoteViewClickHandler(remoteViewClickHandler); } public interface ExpansionLogger { @@ -1028,6 +1042,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { public ExpandableNotificationRow(Context context, AttributeSet attrs) { super(context, attrs); mFalsingManager = FalsingManager.getInstance(context); + mNotificationInflater = new NotificationInflater(this); initDimens(); } @@ -1063,26 +1078,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { /** * Resets this view so it can be re-used for an updated notification. */ - @Override public void reset() { - super.reset(); - final boolean wasExpanded = isExpanded(); - mExpandable = false; - mHasUserChangedExpansion = false; - mUserLocked = false; - mShowingPublic = false; - mSensitive = false; mShowingPublicInitialized = false; - mIsSystemExpanded = false; - mOnKeyguard = false; - mPublicLayout.reset(); - mPrivateLayout.reset(); - resetHeight(); - resetTranslation(); - logExpansionEvent(false, wasExpanded); - } - - public void resetHeight() { onHeightReset(); requestLayout(); } @@ -1828,9 +1825,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { return mShowingPublic ? mPublicLayout : mPrivateLayout; } - public void setShowingLegacyBackground(boolean showing) { + public void setLegacy(boolean legacy) { for (NotificationContentView l : mLayouts) { - l.setShowingLegacyBackground(showing); + l.setLegacy(legacy); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java index 57d2e1c841156..8c39a763f93e0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java @@ -80,7 +80,7 @@ public class NotificationContentView extends FrameLayout { private boolean mDark; private boolean mAnimate; private boolean mIsHeadsUp; - private boolean mShowingLegacyBackground; + private boolean mLegacy; private boolean mIsChildInGroup; private int mSmallHeight; private int mHeadsUpHeight; @@ -140,7 +140,6 @@ public class NotificationContentView extends FrameLayout { R.dimen.min_notification_layout_height); mNotificationContentMarginEnd = getResources().getDimensionPixelSize( com.android.internal.R.dimen.notification_content_margin_end); - reset(); } public void setHeights(int smallHeight, int headsUpMaxHeight, int maxHeight, @@ -329,41 +328,6 @@ public class NotificationContentView extends FrameLayout { updateVisibility(); } - public void reset() { - mPreviousExpandedRemoteInputIntent = null; - if (mExpandedRemoteInput != null) { - mExpandedRemoteInput.onNotificationUpdateOrReset(); - if (mExpandedRemoteInput.isActive()) { - mPreviousExpandedRemoteInputIntent = mExpandedRemoteInput.getPendingIntent(); - mCachedExpandedRemoteInput = mExpandedRemoteInput; - mExpandedRemoteInput.dispatchStartTemporaryDetach(); - ((ViewGroup)mExpandedRemoteInput.getParent()).removeView(mExpandedRemoteInput); - } - } - if (mExpandedChild != null) { - mExpandedChild.animate().cancel(); - removeView(mExpandedChild); - mExpandedRemoteInput = null; - } - mPreviousHeadsUpRemoteInputIntent = null; - if (mHeadsUpRemoteInput != null) { - mHeadsUpRemoteInput.onNotificationUpdateOrReset(); - if (mHeadsUpRemoteInput.isActive()) { - mPreviousHeadsUpRemoteInputIntent = mHeadsUpRemoteInput.getPendingIntent(); - mCachedHeadsUpRemoteInput = mHeadsUpRemoteInput; - mHeadsUpRemoteInput.dispatchStartTemporaryDetach(); - ((ViewGroup)mHeadsUpRemoteInput.getParent()).removeView(mHeadsUpRemoteInput); - } - } - if (mHeadsUpChild != null) { - mHeadsUpChild.animate().cancel(); - removeView(mHeadsUpChild); - mHeadsUpRemoteInput = null; - } - mExpandedChild = null; - mHeadsUpChild = null; - } - public View getContractedChild() { return mContractedChild; } @@ -394,8 +358,30 @@ public class NotificationContentView extends FrameLayout { public void setExpandedChild(View child) { if (mExpandedChild != null) { + mPreviousExpandedRemoteInputIntent = null; + if (mExpandedRemoteInput != null) { + mExpandedRemoteInput.onNotificationUpdateOrReset(); + if (mExpandedRemoteInput.isActive()) { + mPreviousExpandedRemoteInputIntent = mExpandedRemoteInput.getPendingIntent(); + mCachedExpandedRemoteInput = mExpandedRemoteInput; + mExpandedRemoteInput.dispatchStartTemporaryDetach(); + ((ViewGroup)mExpandedRemoteInput.getParent()).removeView(mExpandedRemoteInput); + } + } mExpandedChild.animate().cancel(); removeView(mExpandedChild); + mExpandedRemoteInput = null; + } + if (child == null) { + mExpandedChild = null; + mExpandedWrapper = null; + if (mVisibleType == VISIBLE_TYPE_EXPANDED) { + mVisibleType = VISIBLE_TYPE_CONTRACTED; + } + if (mTransformationStartVisibleType == VISIBLE_TYPE_EXPANDED) { + mTransformationStartVisibleType = UNDEFINED; + } + return; } addView(child); mExpandedChild = child; @@ -405,8 +391,30 @@ public class NotificationContentView extends FrameLayout { public void setHeadsUpChild(View child) { if (mHeadsUpChild != null) { + mPreviousHeadsUpRemoteInputIntent = null; + if (mHeadsUpRemoteInput != null) { + mHeadsUpRemoteInput.onNotificationUpdateOrReset(); + if (mHeadsUpRemoteInput.isActive()) { + mPreviousHeadsUpRemoteInputIntent = mHeadsUpRemoteInput.getPendingIntent(); + mCachedHeadsUpRemoteInput = mHeadsUpRemoteInput; + mHeadsUpRemoteInput.dispatchStartTemporaryDetach(); + ((ViewGroup)mHeadsUpRemoteInput.getParent()).removeView(mHeadsUpRemoteInput); + } + } mHeadsUpChild.animate().cancel(); removeView(mHeadsUpChild); + mHeadsUpRemoteInput = null; + } + if (child == null) { + mHeadsUpChild = null; + mHeadsUpWrapper = null; + if (mVisibleType == VISIBLE_TYPE_HEADSUP) { + mVisibleType = VISIBLE_TYPE_CONTRACTED; + } + if (mTransformationStartVisibleType == VISIBLE_TYPE_HEADSUP) { + mTransformationStartVisibleType = UNDEFINED; + } + return; } addView(child); mHeadsUpChild = child; @@ -978,20 +986,20 @@ public class NotificationContentView extends FrameLayout { return false; } - public void setShowingLegacyBackground(boolean showing) { - mShowingLegacyBackground = showing; - updateShowingLegacyBackground(); + public void setLegacy(boolean legacy) { + mLegacy = legacy; + updateLegacy(); } - private void updateShowingLegacyBackground() { + private void updateLegacy() { if (mContractedChild != null) { - mContractedWrapper.setShowingLegacyBackground(mShowingLegacyBackground); + mContractedWrapper.setLegacy(mLegacy); } if (mExpandedChild != null) { - mExpandedWrapper.setShowingLegacyBackground(mShowingLegacyBackground); + mExpandedWrapper.setLegacy(mLegacy); } if (mHeadsUpChild != null) { - mHeadsUpWrapper.setShowingLegacyBackground(mShowingLegacyBackground); + mHeadsUpWrapper.setLegacy(mLegacy); } } @@ -1017,7 +1025,7 @@ public class NotificationContentView extends FrameLayout { mAmbientWrapper.notifyContentUpdated(entry.notification, mIsLowPriority); } applyRemoteInput(entry); - updateShowingLegacyBackground(); + updateLegacy(); mForceSelectNextLayout = true; setDark(mDark, false /* animate */, 0 /* delay */); mPreviousExpandedRemoteInputIntent = null; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java index 81db42927682f..8f8d966ffff57 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java @@ -34,6 +34,7 @@ import android.widget.RemoteViews; import com.android.internal.statusbar.StatusBarIcon; import com.android.internal.util.NotificationColorUtil; +import com.android.systemui.statusbar.notification.InflationException; import com.android.systemui.statusbar.phone.NotificationGroupManager; import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.policy.HeadsUpManager; @@ -65,7 +66,6 @@ public class NotificationData { public ExpandableNotificationRow row; // the outer expanded view private boolean interruption; public boolean autoRedacted; // whether the redacted notification was generated by us - public boolean legacy; // whether the notification has a legacy, dark background public int targetSdk; private long lastFullScreenIntentLaunchTime = NOT_LAUNCHED_YET; public RemoteViews cachedContentView; @@ -95,118 +95,20 @@ public class NotificationData { * Resets the notification entry to be re-used. */ public void reset() { - // NOTE: Icon needs to be preserved for now. - // We should fix this at some point. - autoRedacted = false; - legacy = false; lastFullScreenIntentLaunchTime = NOT_LAUNCHED_YET; if (row != null) { row.reset(); } } - public View getContentView() { - return row.getPrivateLayout().getContractedChild(); - } - public View getExpandedContentView() { return row.getPrivateLayout().getExpandedChild(); } - public View getHeadsUpContentView() { - return row.getPrivateLayout().getHeadsUpChild(); - } - public View getPublicContentView() { return row.getPublicLayout().getContractedChild(); } - public View getAmbientContentView() { - return row.getPrivateLayout().getAmbientChild(); - } - - public boolean cacheContentViews(Context ctx, Notification updatedNotification, - boolean isLowPriority, boolean useIncreasedCollapsedView, - boolean useIncreasedHeadsUp) { - boolean applyInPlace = false; - if (updatedNotification != null) { - final Notification.Builder updatedNotificationBuilder - = Notification.Builder.recoverBuilder(ctx, updatedNotification); - final RemoteViews newContentView = createContentView(updatedNotificationBuilder, - isLowPriority, useIncreasedCollapsedView); - final RemoteViews newBigContentView = createBigContentView( - updatedNotificationBuilder, isLowPriority); - final RemoteViews newHeadsUpContentView = - updatedNotificationBuilder.createHeadsUpContentView(useIncreasedHeadsUp); - final RemoteViews newPublicNotification - = updatedNotificationBuilder.makePublicContentView(); - final RemoteViews newAmbientNotification - = updatedNotificationBuilder.makeAmbientNotification(); - - boolean sameCustomView = Objects.equals( - notification.getNotification().extras.getBoolean( - Notification.EXTRA_CONTAINS_CUSTOM_VIEW), - updatedNotification.extras.getBoolean( - Notification.EXTRA_CONTAINS_CUSTOM_VIEW)); - applyInPlace = compareRemoteViews(cachedContentView, newContentView) - && compareRemoteViews(cachedBigContentView, newBigContentView) - && compareRemoteViews(cachedHeadsUpContentView, newHeadsUpContentView) - && compareRemoteViews(cachedPublicContentView, newPublicNotification) - && compareRemoteViews(cachedAmbientContentView, newAmbientNotification) - && sameCustomView; - cachedPublicContentView = newPublicNotification; - cachedHeadsUpContentView = newHeadsUpContentView; - cachedBigContentView = newBigContentView; - cachedContentView = newContentView; - cachedAmbientContentView = newAmbientNotification; - } else { - final Notification.Builder builder - = Notification.Builder.recoverBuilder(ctx, notification.getNotification()); - - cachedContentView = createContentView(builder, isLowPriority, - useIncreasedCollapsedView); - cachedBigContentView = createBigContentView(builder, isLowPriority); - cachedHeadsUpContentView = builder.createHeadsUpContentView(useIncreasedHeadsUp); - cachedPublicContentView = builder.makePublicContentView(); - cachedAmbientContentView = builder.makeAmbientNotification(); - - applyInPlace = false; - } - return applyInPlace; - } - - private RemoteViews createBigContentView(Notification.Builder builder, - boolean isLowPriority) { - RemoteViews bigContentView = builder.createBigContentView(); - if (bigContentView != null) { - return bigContentView; - } - if (isLowPriority) { - RemoteViews contentView = builder.createContentView(); - Notification.Builder.makeHeaderExpanded(contentView); - return contentView; - } - return null; - } - - private RemoteViews createContentView(Notification.Builder builder, - boolean isLowPriority, boolean useLarge) { - if (isLowPriority) { - return builder.makeLowPriorityContentView(false /* useRegularSubtext */); - } - return builder.createContentView(useLarge); - } - - // Returns true if the RemoteViews are the same. - private boolean compareRemoteViews(final RemoteViews a, final RemoteViews b) { - return (a == null && b == null) || - (a != null && b != null - && b.getPackage() != null - && a.getPackage() != null - && a.getPackage().equals(b.getPackage()) - && a.getLayoutId() == b.getLayoutId()); - } - public void notifyFullScreenIntentLaunched() { lastFullScreenIntentLaunchTime = SystemClock.elapsedRealtime(); } @@ -219,13 +121,14 @@ public class NotificationData { * Create the icons for a notification * @param context the context to create the icons with * @param sbn the notification - * @throws IconException + * @throws InflationException */ - public void createIcons(Context context, StatusBarNotification sbn) throws IconException { + public void createIcons(Context context, StatusBarNotification sbn) + throws InflationException { Notification n = sbn.getNotification(); final Icon smallIcon = n.getSmallIcon(); if (smallIcon == null) { - throw new IconException("No small icon in notification from " + throw new InflationException("No small icon in notification from " + sbn.getPackageName()); } @@ -248,7 +151,7 @@ public class NotificationData { if (!icon.set(ic) || !expandedIcon.set(ic)) { icon = null; expandedIcon = null; - throw new IconException("Couldn't create icon: " + ic); + throw new InflationException("Couldn't create icon: " + ic); } expandedIcon.setVisibility(View.INVISIBLE); expandedIcon.setOnVisibilityChangedListener( @@ -270,9 +173,9 @@ public class NotificationData { * Update the notification icons. * @param context the context to create the icons with. * @param n the notification to read the icon from. - * @throws IconException + * @throws InflationException */ - public void updateIcons(Context context, Notification n) throws IconException { + public void updateIcons(Context context, Notification n) throws InflationException { if (icon != null) { // Update the icon final StatusBarIcon ic = new StatusBarIcon( @@ -285,7 +188,7 @@ public class NotificationData { icon.setNotification(n); expandedIcon.setNotification(n); if (!icon.set(ic) || !expandedIcon.set(ic)) { - throw new IconException("Couldn't update icon: " + ic); + throw new InflationException("Couldn't update icon: " + ic); } } } @@ -612,10 +515,4 @@ public class NotificationData { public String getCurrentMediaNotificationKey(); public NotificationGroupManager getGroupManager(); } - - public static class IconException extends Exception { - IconException(String error) { - super(error); - } - } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/InflationException.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/InflationException.java new file mode 100644 index 0000000000000..b484138d7a662 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/InflationException.java @@ -0,0 +1,26 @@ +/* + * 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 + */ + +package com.android.systemui.statusbar.notification; + +/** + * An exception that something went wrong during the inflation + */ +public class InflationException extends Exception { + public InflationException(String error) { + super(error); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationCustomViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationCustomViewWrapper.java index e5f32df8af7b9..3efa29f874506 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationCustomViewWrapper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationCustomViewWrapper.java @@ -19,13 +19,8 @@ package com.android.systemui.statusbar.notification; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; -import android.graphics.Color; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; -import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; -import android.service.notification.StatusBarNotification; -import android.support.v4.graphics.ColorUtils; import android.view.View; import com.android.systemui.R; @@ -40,7 +35,7 @@ public class NotificationCustomViewWrapper extends NotificationViewWrapper { private final ViewInvertHelper mInvertHelper; private final Paint mGreyPaint = new Paint(); - private boolean mShowingLegacyBackground; + private boolean mIsLegacy; private int mLegacyColor; protected NotificationCustomViewWrapper(View view, ExpandableNotificationRow row) { @@ -55,7 +50,7 @@ public class NotificationCustomViewWrapper extends NotificationViewWrapper { return; } super.setDark(dark, fade, delay); - if (!mShowingLegacyBackground && mShouldInvertDark) { + if (!mIsLegacy && mShouldInvertDark) { if (fade) { mInvertHelper.fade(dark, delay); } else { @@ -112,15 +107,14 @@ public class NotificationCustomViewWrapper extends NotificationViewWrapper { @Override public int getCustomBackgroundColor() { int customBackgroundColor = super.getCustomBackgroundColor(); - if (customBackgroundColor == 0 && mShowingLegacyBackground) { + if (customBackgroundColor == 0 && mIsLegacy) { return mLegacyColor; } return customBackgroundColor; } - @Override - public void setShowingLegacyBackground(boolean showing) { - super.setShowingLegacyBackground(showing); - mShowingLegacyBackground = showing; + public void setLegacy(boolean legacy) { + super.setLegacy(legacy); + mIsLegacy = legacy; } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java new file mode 100644 index 0000000000000..3fa02c3d0f680 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java @@ -0,0 +1,217 @@ +/* + * 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 + */ + +package com.android.systemui.statusbar.notification; + +import android.app.Notification; +import android.content.Context; +import android.service.notification.StatusBarNotification; +import android.util.Log; +import android.view.View; +import android.widget.RemoteViews; + +import com.android.systemui.statusbar.ExpandableNotificationRow; +import com.android.systemui.statusbar.NotificationContentView; +import com.android.systemui.statusbar.NotificationData; +import com.android.systemui.statusbar.phone.StatusBar; + +import java.util.Objects; + +/** + * A utility that inflates the right kind of contentView based on the state + */ +public class NotificationInflater { + + private final ExpandableNotificationRow mRow; + private boolean mIsLowPriority; + private boolean mUsesIncreasedHeight; + private boolean mUsesIncreasedHeadsUpHeight; + private RemoteViews.OnClickHandler mRemoteViewClickHandler; + + public NotificationInflater(ExpandableNotificationRow row) { + mRow = row; + } + + public void setIsLowPriority(boolean isLowPriority) { + mIsLowPriority = isLowPriority; + } + + public void setUsesIncreasedHeight(boolean usesIncreasedHeight) { + mUsesIncreasedHeight = usesIncreasedHeight; + } + + public void setUsesIncreasedHeadsUpHeight(boolean usesIncreasedHeight) { + mUsesIncreasedHeadsUpHeight = usesIncreasedHeight; + } + + public void setRemoteViewClickHandler(RemoteViews.OnClickHandler remoteViewClickHandler) { + mRemoteViewClickHandler = remoteViewClickHandler; + } + + public void inflateNotificationViews() throws InflationException { + NotificationData.Entry entry = mRow.getEntry(); + StatusBarNotification sbn = entry.notification; + Context context = mRow.getContext(); + NotificationContentView privateLayout = mRow.getPrivateLayout(); + try { + final Notification.Builder recoveredBuilder + = Notification.Builder.recoverBuilder(context, sbn.getNotification()); + + final RemoteViews newContentView = createContentView(recoveredBuilder, + mIsLowPriority, mUsesIncreasedHeadsUpHeight); + if (!compareRemoteViews(newContentView, entry.cachedContentView)) { + View contentViewLocal = newContentView.apply( + sbn.getPackageContext(context), + privateLayout, + mRemoteViewClickHandler); + contentViewLocal.setIsRootNamespace(true); + privateLayout.setContractedChild(contentViewLocal); + } else { + newContentView.reapply(sbn.getPackageContext(context), + privateLayout.getContractedChild(), + mRemoteViewClickHandler); + } + entry.cachedContentView = newContentView; + + final RemoteViews newBigContentView = createBigContentView( + recoveredBuilder, mIsLowPriority); + if (newBigContentView != null) { + if (!compareRemoteViews(newBigContentView, entry.cachedBigContentView)) { + View bigContentViewLocal = newBigContentView.apply( + sbn.getPackageContext(context), + privateLayout, + mRemoteViewClickHandler); + bigContentViewLocal.setIsRootNamespace(true); + privateLayout.setExpandedChild(bigContentViewLocal); + } else { + newBigContentView.reapply(sbn.getPackageContext(context), + privateLayout.getExpandedChild(), + mRemoteViewClickHandler); + } + } else if (entry.cachedBigContentView != null) { + privateLayout.setExpandedChild(null); + } + entry.cachedBigContentView = newBigContentView; + + final RemoteViews newHeadsUpContentView = + recoveredBuilder.createHeadsUpContentView(mUsesIncreasedHeight); + if (newHeadsUpContentView != null) { + if (!compareRemoteViews(newHeadsUpContentView, entry.cachedHeadsUpContentView)) { + View headsUpContentViewLocal = newHeadsUpContentView.apply( + sbn.getPackageContext(context), + privateLayout, + mRemoteViewClickHandler); + headsUpContentViewLocal.setIsRootNamespace(true); + privateLayout.setHeadsUpChild(headsUpContentViewLocal); + } else { + newHeadsUpContentView.reapply(sbn.getPackageContext(context), + privateLayout.getHeadsUpChild(), + mRemoteViewClickHandler); + } + } else if (entry.cachedHeadsUpContentView != null) { + privateLayout.setHeadsUpChild(null); + } + entry.cachedHeadsUpContentView = newHeadsUpContentView; + + NotificationContentView publicLayout = mRow.getPublicLayout(); + final RemoteViews newPublicNotification + = recoveredBuilder.makePublicContentView(); + if (!compareRemoteViews(newPublicNotification, entry.cachedPublicContentView)) { + View publicContentView = newPublicNotification.apply( + sbn.getPackageContext(context), + publicLayout, + mRemoteViewClickHandler); + publicContentView.setIsRootNamespace(true); + publicLayout.setContractedChild(publicContentView); + } else { + newPublicNotification.reapply(sbn.getPackageContext(context), + publicLayout.getContractedChild(), + mRemoteViewClickHandler); + } + entry.cachedPublicContentView = newPublicNotification; + + final RemoteViews newAmbientNotification + = recoveredBuilder.makeAmbientNotification(); + if (!compareRemoteViews(newAmbientNotification, entry.cachedAmbientContentView)) { + View ambientContentView = newAmbientNotification.apply( + sbn.getPackageContext(context), + privateLayout, + mRemoteViewClickHandler); + ambientContentView.setIsRootNamespace(true); + privateLayout.setAmbientChild(ambientContentView); + } else { + newAmbientNotification.reapply(sbn.getPackageContext(context), + privateLayout.getAmbientChild(), + mRemoteViewClickHandler); + } + entry.cachedAmbientContentView = newAmbientNotification; + + mRow.setExpandable(newBigContentView != null); + + } catch (RuntimeException e) { + final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId()); + Log.e(StatusBar.TAG, "couldn't inflate view for notification " + ident, e); + throw new InflationException("Couldn't inflate contentViews"); + } + } + + private RemoteViews createBigContentView(Notification.Builder builder, + boolean isLowPriority) { + RemoteViews bigContentView = builder.createBigContentView(); + if (bigContentView != null) { + return bigContentView; + } + if (isLowPriority) { + RemoteViews contentView = builder.createContentView(); + Notification.Builder.makeHeaderExpanded(contentView); + return contentView; + } + return null; + } + + private RemoteViews createContentView(Notification.Builder builder, + boolean isLowPriority, boolean useLarge) { + if (isLowPriority) { + return builder.makeLowPriorityContentView(false /* useRegularSubtext */); + } + return builder.createContentView(useLarge); + } + + // Returns true if the RemoteViews are the same. + private boolean compareRemoteViews(final RemoteViews a, final RemoteViews b) { + return (a == null && b == null) || + (a != null && b != null + && b.getPackage() != null + && a.getPackage() != null + && a.getPackage().equals(b.getPackage()) + && a.getLayoutId() == b.getLayoutId()); + } + public void onDensityOrFontScaleChanged() { + NotificationData.Entry entry = mRow.getEntry(); + entry.cachedAmbientContentView = null; + entry.cachedBigContentView = null; + entry.cachedContentView = null; + entry.cachedHeadsUpContentView = null; + entry.cachedPublicContentView = null; + try { + inflateNotificationViews(); + } catch (InflationException e) { + mInflateExceptionHandler.handleInflationException( + mRow.getStatusBarNotification(), e); + } + } + +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationViewWrapper.java index 5f5e1e46e9d24..8f0dcb0255a91 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationViewWrapper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationViewWrapper.java @@ -185,7 +185,7 @@ public abstract class NotificationViewWrapper implements TransformableView { return mRow.isSummaryWithChildren() ? 0 : mBackgroundColor; } - public void setShowingLegacyBackground(boolean showing) { + public void setLegacy(boolean legacy) { } public void setContentHeight(int contentHeight, int minHeightHint) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 213b0aa0fa07c..51d0c5e460f32 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -124,7 +124,6 @@ import com.android.keyguard.ViewMediatorCallback; import com.android.systemui.ActivityStarterDelegate; import com.android.systemui.DemoMode; import com.android.systemui.Dependency; -import com.android.systemui.EventLogConstants; import com.android.systemui.EventLogTags; import com.android.systemui.Interpolators; import com.android.systemui.Prefs; @@ -161,7 +160,6 @@ import com.android.systemui.statusbar.ExpandableNotificationRow; import com.android.systemui.statusbar.GestureRecorder; import com.android.systemui.statusbar.KeyboardShortcuts; import com.android.systemui.statusbar.KeyguardIndicationController; -import com.android.systemui.statusbar.NotificationContentView; import com.android.systemui.statusbar.NotificationData; import com.android.systemui.statusbar.NotificationData.Entry; import com.android.systemui.statusbar.NotificationGuts; @@ -172,6 +170,7 @@ import com.android.systemui.statusbar.RemoteInputController; import com.android.systemui.statusbar.ScrimView; import com.android.systemui.statusbar.SignalClusterView; import com.android.systemui.statusbar.StatusBarState; +import com.android.systemui.statusbar.notification.InflationException; import com.android.systemui.statusbar.notification.VisualStabilityManager; import com.android.systemui.statusbar.phone.StatusBarIconController.IconManager; import com.android.systemui.statusbar.phone.UnlockMethodCache.OnUnlockMethodChangedListener; @@ -299,7 +298,7 @@ public class StatusBar extends SystemUI implements DemoMode, "com.android.systemui.statusbar.banner_action_setup"; private static final String NOTIFICATION_UNLOCKED_BY_WORK_CHALLENGE_ACTION = "com.android.systemui.statusbar.work_challenge_unlocked_notification_action"; - static final String TAG = "StatusBar"; + public static final String TAG = "StatusBar"; public static final boolean DEBUG = false; public static final boolean SPEW = false; public static final boolean DUMPTRUCK = true; // extra dumpsys info @@ -1276,12 +1275,11 @@ public class StatusBar extends SystemUI implements DemoMode, Entry entry = activeNotifications.get(i); boolean exposedGuts = mNotificationGutsExposed != null && entry.row.getGuts() == mNotificationGutsExposed; - entry.row.reInflateViews(); + entry.row.onDensityOrFontScaleChanged(); if (exposedGuts) { mNotificationGutsExposed = entry.row.getGuts(); bindGuts(entry.row, mGutsMenuItem); } - inflateViews(entry, mStackScroller); } // end old BaseStatusBar.onDensityOrFontScaleChanged(). mScrimController.onDensityOrFontScaleChanged(); @@ -1550,14 +1548,11 @@ public class StatusBar extends SystemUI implements DemoMode, } public void addNotification(StatusBarNotification notification, RankingMap ranking, - Entry oldEntry) { + Entry oldEntry) throws InflationException { if (DEBUG) Log.d(TAG, "addNotification key=" + notification.getKey()); mNotificationData.updateRanking(ranking); Entry shadeEntry = createNotificationViews(notification); - if (shadeEntry == null) { - return; - } boolean isHeadsUped = shouldPeek(shadeEntry); if (isHeadsUped) { mHeadsUpManager.showNotification(shadeEntry); @@ -1599,6 +1594,10 @@ public class StatusBar extends SystemUI implements DemoMode, setAreThereNotifications(); } + public void handleInflationException(StatusBarNotification notification, InflationException e) { + handleNotificationError(notification, e.getMessage()); + } + private boolean shouldSuppressFullScreenIntent(String key) { if (isDeviceInVrMode()) { return true; @@ -1663,10 +1662,17 @@ public class StatusBar extends SystemUI implements DemoMode, sbn.getOpPkg(), sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(), newNotification, sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime()); - - updateNotification(newSbn, null); - mKeysKeptForRemoteInput.add(entry.key); - return; + boolean updated = false; + try { + updateNotification(newSbn, null); + updated = true; + } catch (InflationException e) { + deferRemoval = false; + } + if (updated) { + mKeysKeptForRemoteInput.add(entry.key); + return; + } } if (deferRemoval) { mLatestRankingMap = ranking; @@ -1808,15 +1814,6 @@ public class StatusBar extends SystemUI implements DemoMode, updatePublicContentView(ent, ent.notification); } ent.row.setSensitive(sensitive, deviceSensitive); - if (ent.autoRedacted && ent.legacy) { - // TODO: Also fade this? Or, maybe easier (and better), provide a dark redacted form - // for legacy auto redacted notifications. - if (showingPublic) { - ent.row.setShowingLegacyBackground(false); - } else { - ent.row.setShowingLegacyBackground(true); - } - } if (mGroupManager.isChildInGroupWithSummary(ent.row.getStatusBarNotification())) { ExpandableNotificationRow summary = mGroupManager.getGroupSummary( ent.row.getStatusBarNotification()); @@ -5513,7 +5510,11 @@ public class StatusBar extends SystemUI implements DemoMode, @Override public void run() { for (StatusBarNotification sbn : notifications) { - addNotification(sbn, currentRanking, null /* oldEntry */); + try { + addNotification(sbn, currentRanking, null /* oldEntry */); + } catch (InflationException e) { + handleInflationException(sbn, e); + } } } }); @@ -5549,10 +5550,14 @@ public class StatusBar extends SystemUI implements DemoMode, } return; } - if (isUpdate) { - updateNotification(sbn, rankingMap); - } else { - addNotification(sbn, rankingMap, null /* oldEntry */); + try { + if (isUpdate) { + updateNotification(sbn, rankingMap); + } else { + addNotification(sbn, rankingMap, null /* oldEntry */); + } + } catch (InflationException e) { + handleInflationException(sbn, e); } } }); @@ -5682,26 +5687,6 @@ public class StatusBar extends SystemUI implements DemoMode, return mGroupManager; } - protected void bindDismissRunnable(final ExpandableNotificationRow row) { - row.setOnDismissRunnable(() -> performRemoveNotification(row.getStatusBarNotification())); - } - - protected void applyColorsAndBackgrounds(StatusBarNotification sbn, - NotificationData.Entry entry) { - - if (entry.getContentView().getId() - != com.android.internal.R.id.status_bar_latest_event_content) { - // Using custom RemoteViews - if (entry.targetSdk >= Build.VERSION_CODES.GINGERBREAD - && entry.targetSdk < Build.VERSION_CODES.LOLLIPOP) { - entry.row.setShowingLegacyBackground(true); - entry.legacy = true; - } - } - - entry.setIconTag(R.id.icon_is_pre_L, entry.targetSdk < Build.VERSION_CODES.LOLLIPOP); - } - public boolean isMediaNotification(NotificationData.Entry entry) { // TODO: confirm that there's a valid media key return entry.getExpandedContentView() != null && @@ -6084,55 +6069,16 @@ public class StatusBar extends SystemUI implements DemoMode, } } - protected boolean inflateViews(Entry entry, ViewGroup parent) { + protected void inflateViews(Entry entry, ViewGroup parent) throws + InflationException { PackageManager pmUser = getPackageManagerForUser(mContext, entry.notification.getUser().getIdentifier()); final StatusBarNotification sbn = entry.notification; - boolean isLowPriority = mNotificationData.isAmbient(sbn.getKey()); - boolean useIncreasedCollapsedHeight = mMessagingUtil.isImportantMessaging(sbn, - mNotificationData.getImportance(sbn.getKey())); - boolean useIncreasedHeadsUp = useIncreasedCollapsedHeight && mPanelExpanded; - try { - entry.cacheContentViews(mContext, null, isLowPriority, useIncreasedCollapsedHeight, - useIncreasedHeadsUp); - } catch (RuntimeException e) { - Log.e(TAG, "Unable to get notification remote views", e); - return false; - } - - final RemoteViews contentView = entry.cachedContentView; - final RemoteViews bigContentView = entry.cachedBigContentView; - final RemoteViews headsUpContentView = entry.cachedHeadsUpContentView; - final RemoteViews publicContentView = entry.cachedPublicContentView; - final RemoteViews ambientContentView = entry.cachedAmbientContentView; - - if (contentView == null) { - Log.v(TAG, "no contentView for: " + sbn.getNotification()); - return false; - } - - if (DEBUG) { - Log.v(TAG, "publicContentView: " + publicContentView); - } - ExpandableNotificationRow row; - - // Stash away previous user expansion state so we can restore it at - // the end. - boolean hasUserChangedExpansion = false; - boolean userExpanded = false; - boolean userLocked = false; - if (entry.row != null) { row = entry.row; - hasUserChangedExpansion = row.hasUserChangedExpansion(); - userExpanded = row.isUserExpanded(); - userLocked = row.isUserLocked(); entry.reset(); - if (hasUserChangedExpansion) { - row.setUserExpanded(userExpanded); - } } else { // create the row view LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( @@ -6144,6 +6090,7 @@ public class StatusBar extends SystemUI implements DemoMode, row.setHeadsUpManager(mHeadsUpManager); row.setRemoteInputController(mRemoteInputController); row.setOnExpandClickListener(this); + row.setRemoteViewClickHandler(mOnClickHandler); // Get the app name. // Note that Notification.Builder#bindHeaderAppName has similar logic @@ -6163,86 +6110,19 @@ public class StatusBar extends SystemUI implements DemoMode, // Do nothing } row.setAppName(appname); + row.setOnDismissRunnable(() -> + performRemoveNotification(row.getStatusBarNotification())); + row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); + if (ENABLE_REMOTE_INPUT) { + row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); + } } - bindDismissRunnable(row); + boolean isLowPriority = mNotificationData.isAmbient(sbn.getKey()); row.setIsLowPriority(isLowPriority); - - // NB: the large icon is now handled entirely by the template - // bind the click event to the content area - NotificationContentView contentContainer = row.getPrivateLayout(); - NotificationContentView contentContainerPublic = row.getPublicLayout(); - - row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); - if (ENABLE_REMOTE_INPUT) { - row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); - } - mNotificationClicker.register(row, sbn); - // set up the adaptive layout - View contentViewLocal = null; - View bigContentViewLocal = null; - View headsUpContentViewLocal = null; - View publicViewLocal = null; - View ambientViewLocal = null; - try { - contentViewLocal = contentView.apply( - sbn.getPackageContext(mContext), - contentContainer, - mOnClickHandler); - if (bigContentView != null) { - bigContentViewLocal = bigContentView.apply( - sbn.getPackageContext(mContext), - contentContainer, - mOnClickHandler); - } - if (headsUpContentView != null) { - headsUpContentViewLocal = headsUpContentView.apply( - sbn.getPackageContext(mContext), - contentContainer, - mOnClickHandler); - } - if (publicContentView != null) { - publicViewLocal = publicContentView.apply( - sbn.getPackageContext(mContext), - contentContainerPublic, mOnClickHandler); - } - if (ambientContentView != null) { - ambientViewLocal = ambientContentView.apply( - sbn.getPackageContext(mContext), - contentContainer, mOnClickHandler); - } - - if (contentViewLocal != null) { - contentViewLocal.setIsRootNamespace(true); - contentContainer.setContractedChild(contentViewLocal); - } - if (bigContentViewLocal != null) { - bigContentViewLocal.setIsRootNamespace(true); - contentContainer.setExpandedChild(bigContentViewLocal); - } - if (headsUpContentViewLocal != null) { - headsUpContentViewLocal.setIsRootNamespace(true); - contentContainer.setHeadsUpChild(headsUpContentViewLocal); - } - if (publicViewLocal != null) { - publicViewLocal.setIsRootNamespace(true); - contentContainerPublic.setContractedChild(publicViewLocal); - } - - if (ambientViewLocal != null) { - ambientViewLocal.setIsRootNamespace(true); - contentContainer.setAmbientChild(ambientViewLocal); - } - } - catch (RuntimeException e) { - final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId()); - Log.e(TAG, "couldn't inflate view for notification " + ident, e); - return false; - } - // Extract target SDK version. try { ApplicationInfo info = pmUser.getApplicationInfo(sbn.getPackageName(), 0); @@ -6250,25 +6130,20 @@ public class StatusBar extends SystemUI implements DemoMode, } catch (NameNotFoundException ex) { Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.getPackageName(), ex); } + row.setLegacy(entry.targetSdk >= Build.VERSION_CODES.GINGERBREAD + && entry.targetSdk < Build.VERSION_CODES.LOLLIPOP); + entry.setIconTag(R.id.icon_is_pre_L, entry.targetSdk < Build.VERSION_CODES.LOLLIPOP); entry.autoRedacted = entry.notification.getNotification().publicVersion == null; entry.row = row; entry.row.setOnActivatedListener(this); - entry.row.setExpandable(bigContentViewLocal != null); - applyColorsAndBackgrounds(sbn, entry); - - // Restore previous flags. - if (hasUserChangedExpansion) { - // Note: setUserExpanded() conveniently ignores calls with - // userExpanded=true if !isExpandable(). - row.setUserExpanded(userExpanded); - } - row.setUserLocked(userLocked); + boolean useIncreasedCollapsedHeight = mMessagingUtil.isImportantMessaging(sbn, + mNotificationData.getImportance(sbn.getKey())); + boolean useIncreasedHeadsUp = useIncreasedCollapsedHeight && mPanelExpanded; row.setUseIncreasedCollapsedHeight(useIncreasedCollapsedHeight); row.setUseIncreasedHeadsUpHeight(useIncreasedHeadsUp); - row.onNotificationUpdated(entry); - return true; + row.updateNotification(entry); } /** @@ -6606,23 +6481,17 @@ public class StatusBar extends SystemUI implements DemoMode, return entry.notification; } - protected NotificationData.Entry createNotificationViews(StatusBarNotification sbn) { + protected NotificationData.Entry createNotificationViews(StatusBarNotification sbn) + throws InflationException { if (DEBUG) { Log.d(TAG, "createNotificationViews(notification=" + sbn); } NotificationData.Entry entry = new NotificationData.Entry(sbn); Dependency.get(LeakDetector.class).trackInstance(entry); - try { - entry.createIcons(mContext, sbn); - } catch (NotificationData.IconException exception) { - handleNotificationError(sbn, exception.getMessage()); - } + entry.createIcons(mContext, sbn); // Construct the expanded view. - if (!inflateViews(entry, mStackScroller)) { - handleNotificationError(sbn, "Couldn't expand RemoteViews for: " + sbn); - return null; - } + inflateViews(entry, mStackScroller); return entry; } @@ -6743,7 +6612,8 @@ public class StatusBar extends SystemUI implements DemoMode, } } - public void updateNotification(StatusBarNotification notification, RankingMap ranking) { + public void updateNotification(StatusBarNotification notification, RankingMap ranking) + throws InflationException { if (DEBUG) Log.d(TAG, "updateNotification(" + notification + ")"); final String key = notification.getKey(); @@ -6758,56 +6628,16 @@ public class StatusBar extends SystemUI implements DemoMode, Notification n = notification.getNotification(); mNotificationData.updateRanking(ranking); - boolean useIncreasedCollapsedHeight = mMessagingUtil.isImportantMessaging(notification, - mNotificationData.getImportance(notification.getKey())); - entry.row.setUseIncreasedCollapsedHeight(useIncreasedCollapsedHeight); - boolean useIncreasedHeadsUp = useIncreasedCollapsedHeight && mPanelExpanded; - entry.row.setUseIncreasedHeadsUpHeight(useIncreasedHeadsUp); - boolean applyInPlace; - try { - applyInPlace = entry.cacheContentViews(mContext, notification.getNotification(), - mNotificationData.isAmbient(key), useIncreasedCollapsedHeight, - useIncreasedHeadsUp); - } catch (RuntimeException e) { - Log.e(TAG, "Unable to get notification remote views", e); - applyInPlace = false; - } - boolean shouldPeek = shouldPeek(entry, notification); - boolean alertAgain = alertAgain(entry, n); - if (DEBUG) { - Log.d(TAG, "applyInPlace=" + applyInPlace - + " shouldPeek=" + shouldPeek - + " alertAgain=" + alertAgain); - } - final StatusBarNotification oldNotification = entry.notification; entry.notification = notification; mGroupManager.onEntryUpdated(entry, oldNotification); - boolean updateSuccessful = false; - try { - if (applyInPlace) { - if (DEBUG) Log.d(TAG, "reusing notification for key: " + key); - try { - entry.updateIcons(mContext, n); - updateNotificationViews(entry, notification); - updateSuccessful = true; - } catch (RuntimeException e) { - // It failed to apply cleanly. - Log.w(TAG, "Couldn't reapply views for package " + - notification.getPackageName(), e); - } - } - if (!updateSuccessful) { - entry.updateIcons(mContext, n); - if (!inflateViews(entry, mStackScroller)) { - handleNotificationError(notification, "Couldn't update remote views for: " - + notification); - } - } - } catch (NotificationData.IconException e) { - handleNotificationError(notification, e.getMessage()); - } + entry.updateIcons(mContext, n); + inflateViews(entry, mStackScroller); + + boolean shouldPeek = shouldPeek(entry, notification); + boolean alertAgain = alertAgain(entry, n); + updateHeadsUp(key, entry, shouldPeek, alertAgain); updateNotifications(); @@ -6822,44 +6652,9 @@ public class StatusBar extends SystemUI implements DemoMode, boolean isForCurrentUser = isNotificationForCurrentProfiles(notification); Log.d(TAG, "notification is " + (isForCurrentUser ? "" : "not ") + "for you"); } - setAreThereNotifications(); } - private void updateNotificationViews(Entry entry, StatusBarNotification sbn) { - final RemoteViews contentView = entry.cachedContentView; - final RemoteViews bigContentView = entry.cachedBigContentView; - final RemoteViews headsUpContentView = entry.cachedHeadsUpContentView; - final RemoteViews publicContentView = entry.cachedPublicContentView; - final RemoteViews ambientContentView = entry.cachedAmbientContentView; - - // Reapply the RemoteViews - contentView.reapply(mContext, entry.getContentView(), mOnClickHandler); - if (bigContentView != null && entry.getExpandedContentView() != null) { - bigContentView.reapply(sbn.getPackageContext(mContext), - entry.getExpandedContentView(), - mOnClickHandler); - } - View headsUpChild = entry.getHeadsUpContentView(); - if (headsUpContentView != null && headsUpChild != null) { - headsUpContentView.reapply(sbn.getPackageContext(mContext), - headsUpChild, mOnClickHandler); - } - if (publicContentView != null && entry.getPublicContentView() != null) { - publicContentView.reapply(sbn.getPackageContext(mContext), - entry.getPublicContentView(), mOnClickHandler); - } - if (ambientContentView != null && entry.getAmbientContentView() != null) { - ambientContentView.reapply(sbn.getPackageContext(mContext), - entry.getAmbientContentView(), mOnClickHandler); - } - // update the contentIntent - mNotificationClicker.register(entry.row, sbn); - - entry.row.onNotificationUpdated(entry); - entry.row.resetHeight(); - } - protected void updatePublicContentView(Entry entry, StatusBarNotification sbn) { final RemoteViews publicContentView = entry.cachedPublicContentView; @@ -6873,10 +6668,7 @@ public class StatusBar extends SystemUI implements DemoMode, TextView titleView = (TextView) inflatedView.findViewById(android.R.id.title); if (titleView != null && !titleView.getText().toString().equals(notificationHiddenText)) { - publicContentView.setTextViewText(android.R.id.title, notificationHiddenText); - publicContentView.reapply(sbn.getPackageContext(mContext), - inflatedView, mOnClickHandler); - entry.row.onNotificationUpdated(entry); + titleView.setText(notificationHiddenText); } } }