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

Commit c478f902 authored by Selim Cinek's avatar Selim Cinek
Browse files

Creating the right views for low-priority group children

Previously we always created the low-priority views even if it
was in a group, but now we use the collapsed or the singleline
one based on the group state.

Test: runtest systemui
Bug: 35125708
Change-Id: I49d418912f65c3bc8b672d383eb6a0526fcb8993
parent 1a48babb
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar;

import static com.android.systemui.statusbar.notification.NotificationInflater.InflationExceptionHandler;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
@@ -306,14 +308,19 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        mEntry = entry;
        mStatusBarNotification = entry.notification;
        mNotificationInflater.inflateNotificationViews();
        onNotificationUpdated();
    }

    private void onNotificationUpdated() {
        for (NotificationContentView l : mLayouts) {
            l.onNotificationUpdated(entry);
            l.onNotificationUpdated(mEntry);
        }
        mIsColorized = mStatusBarNotification.getNotification().isColorized();
        mShowingPublicInitialized = false;
        updateNotificationColor();
        if (mIsSummaryWithChildren) {
            mChildrenContainer.recreateNotificationHeader(mExpandClickListener, mEntry.notification);
            mChildrenContainer.recreateNotificationHeader(mExpandClickListener,
                    mEntry.notification);
            mChildrenContainer.onNotificationUpdated();
        }
        if (mIconAnimationRunning) {
@@ -463,6 +470,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        boolean childInGroup = StatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
        mNotificationParent = childInGroup ? parent : null;
        mPrivateLayout.setIsChildInGroup(childInGroup);
        if (mNotificationInflater.setIsChildInGroup(childInGroup)) {
            onNotificationUpdated();
        }
        resetBackgroundAlpha();
        updateBackgroundForGroupState();
        updateClickAndFocus();
@@ -1035,6 +1045,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        mNotificationInflater.setRemoteViewClickHandler(remoteViewClickHandler);
    }

    public void setInflateExceptionHandler(InflationExceptionHandler inflateExceptionHandler) {
        mNotificationInflater.setInflateExceptionHandler(inflateExceptionHandler);
    }

    public interface ExpansionLogger {
        public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
    }
+135 −74
Original line number Diff line number Diff line
@@ -35,11 +35,20 @@ import java.util.Objects;
 */
public class NotificationInflater {

    private static final int FLAG_REINFLATE_ALL = ~0;
    private static final int FLAG_REINFLATE_CONTENT_VIEW = 1<<0;
    private static final int FLAG_REINFLATE_EXPANDED_VIEW = 1<<1;
    private static final int FLAG_REINFLATE_HEADS_UP_VIEW = 1<<2;
    private static final int FLAG_REINFLATE_PUBLIC_VIEW = 1<<3;
    private static final int FLAG_REINFLATE_AMBIENT_VIEW = 1<<4;

    private final ExpandableNotificationRow mRow;
    private boolean mIsLowPriority;
    private boolean mUsesIncreasedHeight;
    private boolean mUsesIncreasedHeadsUpHeight;
    private RemoteViews.OnClickHandler mRemoteViewClickHandler;
    private boolean mIsChildInGroup;
    private InflationExceptionHandler mInflateExceptionHandler;

    public NotificationInflater(ExpandableNotificationRow row) {
        mRow = row;
@@ -49,6 +58,28 @@ public class NotificationInflater {
        mIsLowPriority = isLowPriority;
    }

    /**
     * Set whether the notification is a child in a group
     *
     * @return whether the view was re-inflated
     */
    public boolean setIsChildInGroup(boolean childInGroup) {
        if (childInGroup != mIsChildInGroup) {
            mIsChildInGroup = childInGroup;
            if (mIsLowPriority) {
                try {
                    int flags = FLAG_REINFLATE_CONTENT_VIEW | FLAG_REINFLATE_EXPANDED_VIEW;
                    inflateNotificationViews(flags);
                } catch (InflationException e) {
                    mInflateExceptionHandler.handleInflationException(
                            mRow.getStatusBarNotification(), e);
                }
            }
            return true;
        }
        return false;
    }

    public void setUsesIncreasedHeight(boolean usesIncreasedHeight) {
        mUsesIncreasedHeight = usesIncreasedHeight;
    }
@@ -62,6 +93,17 @@ public class NotificationInflater {
    }

    public void inflateNotificationViews() throws InflationException {
        inflateNotificationViews(FLAG_REINFLATE_ALL);
    }

    /**
     * reinflate all views for the specified flags
     * @param reInflateFlags flags which views should be reinflated. Use {@link #FLAG_REINFLATE_ALL}
     *                       to reinflate all of views.
     * @throws InflationException
     */
    private void inflateNotificationViews(int reInflateFlags)
            throws InflationException {
        NotificationData.Entry entry = mRow.getEntry();
        StatusBarNotification sbn = entry.notification;
        Context context = mRow.getContext();
@@ -69,10 +111,12 @@ public class NotificationInflater {
        try {
            final Notification.Builder recoveredBuilder
                    = Notification.Builder.recoverBuilder(context, sbn.getNotification());

            boolean isLowPriority = mIsLowPriority && !mIsChildInGroup;
            if ((reInflateFlags & FLAG_REINFLATE_CONTENT_VIEW) != 0) {
                final RemoteViews newContentView = createContentView(recoveredBuilder,
                    mIsLowPriority, mUsesIncreasedHeadsUpHeight);
            if (!compareRemoteViews(newContentView, entry.cachedContentView)) {
                        isLowPriority, mUsesIncreasedHeadsUpHeight);
                if (!compareRemoteViews(newContentView,
                        entry.cachedContentView)) {
                    View contentViewLocal = newContentView.apply(
                            sbn.getPackageContext(context),
                            privateLayout,
@@ -85,9 +129,11 @@ public class NotificationInflater {
                            mRemoteViewClickHandler);
                }
                entry.cachedContentView = newContentView;
            }

            if ((reInflateFlags & FLAG_REINFLATE_EXPANDED_VIEW) != 0) {
                final RemoteViews newBigContentView = createBigContentView(
                    recoveredBuilder, mIsLowPriority);
                        recoveredBuilder, isLowPriority);
                if (newBigContentView != null) {
                    if (!compareRemoteViews(newBigContentView, entry.cachedBigContentView)) {
                        View bigContentViewLocal = newBigContentView.apply(
@@ -105,11 +151,15 @@ public class NotificationInflater {
                    privateLayout.setExpandedChild(null);
                }
                entry.cachedBigContentView = newBigContentView;
                mRow.setExpandable(newBigContentView != null);
            }

            if ((reInflateFlags & FLAG_REINFLATE_HEADS_UP_VIEW) != 0) {
                final RemoteViews newHeadsUpContentView =
                        recoveredBuilder.createHeadsUpContentView(mUsesIncreasedHeight);
                if (newHeadsUpContentView != null) {
                if (!compareRemoteViews(newHeadsUpContentView, entry.cachedHeadsUpContentView)) {
                    if (!compareRemoteViews(newHeadsUpContentView,
                            entry.cachedHeadsUpContentView)) {
                        View headsUpContentViewLocal = newHeadsUpContentView.apply(
                                sbn.getPackageContext(context),
                                privateLayout,
@@ -125,7 +175,9 @@ public class NotificationInflater {
                    privateLayout.setHeadsUpChild(null);
                }
                entry.cachedHeadsUpContentView = newHeadsUpContentView;
            }

            if ((reInflateFlags & FLAG_REINFLATE_PUBLIC_VIEW) != 0) {
                NotificationContentView publicLayout = mRow.getPublicLayout();
                final RemoteViews newPublicNotification
                        = recoveredBuilder.makePublicContentView();
@@ -142,7 +194,9 @@ public class NotificationInflater {
                            mRemoteViewClickHandler);
                }
                entry.cachedPublicContentView = newPublicNotification;
            }

            if ((reInflateFlags & FLAG_REINFLATE_AMBIENT_VIEW) != 0) {
                final RemoteViews newAmbientNotification
                        = recoveredBuilder.makeAmbientNotification();
                if (!compareRemoteViews(newAmbientNotification, entry.cachedAmbientContentView)) {
@@ -158,8 +212,7 @@ public class NotificationInflater {
                            mRemoteViewClickHandler);
                }
                entry.cachedAmbientContentView = newAmbientNotification;

            mRow.setExpandable(newBigContentView != null);
            }

        } catch (RuntimeException e) {
            final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId());
@@ -199,6 +252,14 @@ public class NotificationInflater {
                        && a.getPackage().equals(b.getPackage())
                        && a.getLayoutId() == b.getLayoutId());
    }

    public void setInflateExceptionHandler(InflationExceptionHandler inflateExceptionHandler) {
        mInflateExceptionHandler = inflateExceptionHandler;
    }

    public interface InflationExceptionHandler {
        void handleInflationException(StatusBarNotification notification, InflationException e);
    }
    public void onDensityOrFontScaleChanged() {
        NotificationData.Entry entry = mRow.getEntry();
        entry.cachedAmbientContentView = null;
+4 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.app.StatusBarManager.WINDOW_STATE_HIDDEN;
import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
import static android.app.StatusBarManager.windowStateToString;

import static com.android.systemui.statusbar.notification.NotificationInflater.InflationExceptionHandler;
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT;
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT_TRANSPARENT;
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_OPAQUE;
@@ -171,6 +172,7 @@ 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.NotificationInflater;
import com.android.systemui.statusbar.notification.VisualStabilityManager;
import com.android.systemui.statusbar.phone.StatusBarIconController.IconManager;
import com.android.systemui.statusbar.phone.UnlockMethodCache.OnUnlockMethodChangedListener;
@@ -716,6 +718,7 @@ public class StatusBar extends SystemUI implements DemoMode,
    private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
    private NotificationIconAreaController mNotificationIconAreaController;
    private ConfigurationListener mDensityChangeListener;
    private InflationExceptionHandler mInflationExceptionHandler = this::handleInflationException;

    private void recycleAllVisibilityObjects(ArraySet<NotificationVisibility> array) {
        final int N = array.size();
@@ -6091,6 +6094,7 @@ public class StatusBar extends SystemUI implements DemoMode,
            row.setRemoteInputController(mRemoteInputController);
            row.setOnExpandClickListener(this);
            row.setRemoteViewClickHandler(mOnClickHandler);
            row.setInflateExceptionHandler(mInflationExceptionHandler);

            // Get the app name.
            // Note that Notification.Builder#bindHeaderAppName has similar logic