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

Commit 5bf3904a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ifcf66d9e,I9709e3f6

* changes:
  Move DynamicPrivacyController from NSSL
  Move NotifEntryMan and NotifPipeline from NSSL
parents 7753f5eb e1e8f218
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -516,6 +516,7 @@ public class NotificationRemoteInputManager implements Dumpable {
        return mLifetimeExtenders;
    }

    @Nullable
    public RemoteInputController getController() {
        return mRemoteInputController;
    }
+5 −7
Original line number Diff line number Diff line
@@ -65,15 +65,13 @@ class ShadeViewManager constructor(
        return root
    }

    private fun buildNotifNode(entry: ListEntry, parent: NodeSpec): NodeSpec {
        return when (entry) {
    private fun buildNotifNode(entry: ListEntry, parent: NodeSpec): NodeSpec = when (entry) {
        is NotificationEntry -> NodeSpecImpl(parent, viewBarn.requireView(entry))
        is GroupEntry -> NodeSpecImpl(parent, viewBarn.requireView(checkNotNull(entry.summary)))
                .apply { entry.children.forEach { children.add(buildNotifNode(it, this)) } }
        else -> throw RuntimeException("Unexpected entry: $entry")
    }
}
}

class ShadeViewManagerFactory @Inject constructor(
    private val context: Context,
+36 −151
Original line number Diff line number Diff line
@@ -16,14 +16,10 @@

package com.android.systemui.statusbar.notification.stack;

import static android.service.notification.NotificationStats.DISMISSAL_SHADE;
import static android.service.notification.NotificationStats.DISMISS_SENTIMENT_NEUTRAL;

import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator.ExpandAnimationParameters;
import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManagerKt.BUCKET_SILENT;
import static com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.ANCHOR_SCROLLING;
import static com.android.systemui.statusbar.notification.stack.StackStateAnimator.ANIMATION_DURATION_SWIPE;
import static com.android.systemui.statusbar.phone.NotificationIconAreaController.HIGH_PRIORITY;
import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT;

import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -49,10 +45,8 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.NotificationListenerService;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -83,8 +77,6 @@ import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.keyguard.KeyguardSliceView;
import com.android.settingslib.Utils;
import com.android.systemui.Dependency;
@@ -96,27 +88,20 @@ import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.DragDownHelper.DragDownCallback;
import com.android.systemui.statusbar.EmptyShadeView;
import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.NotificationShelf;
import com.android.systemui.statusbar.NotificationShelfController;
import com.android.systemui.statusbar.RemoteInputController;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.SysuiStatusBarStateController;
import com.android.systemui.statusbar.notification.DynamicPrivacyController;
import com.android.systemui.statusbar.notification.FakeShadowView;
import com.android.systemui.statusbar.notification.ForegroundServiceDismissalFeatureController;
import com.android.systemui.statusbar.notification.NotificationActivityStarter;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.notification.ShadeViewRefactor;
import com.android.systemui.statusbar.notification.ShadeViewRefactor.RefactorComponent;
import com.android.systemui.statusbar.notification.collection.NotifCollection;
import com.android.systemui.statusbar.notification.collection.NotifPipeline;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.legacy.VisualStabilityManager;
import com.android.systemui.statusbar.notification.collection.notifcollection.DismissedByUserStats;
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener;
import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManager;
import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
@@ -136,7 +121,6 @@ import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.policy.HeadsUpUtil;
import com.android.systemui.statusbar.policy.ScrollAdapter;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.util.Assert;

import java.io.FileDescriptor;
@@ -173,7 +157,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
     */
    private static final int DISTANCE_BETWEEN_ADJACENT_SECTIONS_PX = 1;
    private KeyguardBypassEnabledProvider mKeyguardBypassEnabledProvider;
    private final DynamicPrivacyController mDynamicPrivacyController;
    private final SysuiStatusBarStateController mStatusbarStateController;

    private ExpandHelper mExpandHelper;
@@ -225,7 +208,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    private int mBottomMargin;
    private int mBottomInset = 0;
    private float mQsExpansionFraction;
    private int mCurrentUserId;

    /**
     * The algorithm which calculates the properties for our children
@@ -468,12 +450,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    private int mHeadsUpInset;
    private HeadsUpAppearanceController mHeadsUpAppearanceController;
    private final Rect mTmpRect = new Rect();
    private final FeatureFlags mFeatureFlags;
    private final NotifPipeline mNotifPipeline;
    private final NotifCollection mNotifCollection;
    private final NotificationEntryManager mEntryManager;
    private final IStatusBarService mBarService = IStatusBarService.Stub.asInterface(
            ServiceManager.getService(Context.STATUS_BAR_SERVICE));
    private DismissAllAnimationListener mDismissAllAnimationListener;
    @VisibleForTesting
    protected final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
    protected final UiEventLogger mUiEventLogger;
@@ -553,18 +530,13 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
            @Named(VIEW_CONTEXT) Context context,
            AttributeSet attrs,
            NotificationRoundnessManager notificationRoundnessManager,
            DynamicPrivacyController dynamicPrivacyController,
            SysuiStatusBarStateController statusbarStateController,
            NotificationSectionsManager notificationSectionsManager,
            ForegroundServiceSectionController fgsSectionController,
            ForegroundServiceDismissalFeatureController fgsFeatureController,
            FeatureFlags featureFlags,
            NotifPipeline notifPipeline,
            NotificationEntryManager entryManager,
            NotifCollection notifCollection,
            UiEventLogger uiEventLogger,
            GroupMembershipManager groupMembershipManager,
            GroupExpansionManager groupExpansionManager
            GroupExpansionManager groupExpansionManager,
            UiEventLogger uiEventLogger
    ) {
        super(context, attrs, 0, 0);
        Resources res = getResources();
@@ -576,7 +548,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        mSectionsManager.initialize(this, LayoutInflater.from(context));
        mSectionsManager.setOnClearSilentNotifsClickListener(v -> {
            // Leave the shade open if there will be other notifs left over to clear
            final boolean closeShade = !hasActiveClearableNotifications(ROWS_HIGH_PRIORITY);
            final boolean closeShade =
                    !mController.hasActiveClearableNotifications(ROWS_HIGH_PRIORITY);
            clearNotifications(ROWS_GENTLE, closeShade);
        });
        mSections = mSectionsManager.createSectionsForBuckets();
@@ -613,37 +586,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
            mDebugPaint.setTextSize(25f);
        }
        mClearAllEnabled = res.getBoolean(R.bool.config_enableNotificationsClearAll);

        TunerService tunerService = Dependency.get(TunerService.class);
        tunerService.addTunable((key, newValue) -> {
            if (key.equals(HIGH_PRIORITY)) {
                mHighPriorityBeforeSpeedBump = "1".equals(newValue);
            }
        }, HIGH_PRIORITY);

        mFeatureFlags = featureFlags;
        mNotifPipeline = notifPipeline;
        mEntryManager = entryManager;
        mNotifCollection = notifCollection;
        if (mFeatureFlags.isNewNotifPipelineRenderingEnabled()) {
            mNotifPipeline.addCollectionListener(new NotifCollectionListener() {
                @Override
                public void onEntryUpdated(NotificationEntry entry) {
                    NotificationStackScrollLayout.this.onEntryUpdated(entry);
                }
            });
        } else {
            mEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
                @Override
                public void onPreEntryUpdated(NotificationEntry entry) {
                    NotificationStackScrollLayout.this.onEntryUpdated(entry);
                }
            });
        }
        mGroupMembershipManager = groupMembershipManager;
        mGroupExpansionManager = groupExpansionManager;

        mDynamicPrivacyController = dynamicPrivacyController;
        mStatusbarStateController = statusbarStateController;
        initializeForegroundServiceSection(fgsFeatureController);
        mUiEventLogger = uiEventLogger;
@@ -707,10 +651,13 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        if (mFooterView == null) {
            return;
        }
        boolean showDismissView = mClearAllEnabled && hasActiveClearableNotifications(ROWS_ALL);
        boolean showFooterView = (showDismissView || hasActiveNotifications())
        // TODO: move this logic to controller, which will invoke updateFooterView directly
        boolean showDismissView = mClearAllEnabled &&
                mController.hasActiveClearableNotifications(ROWS_ALL);
        RemoteInputController remoteInputController = mRemoteInputManager.getController();
        boolean showFooterView = (showDismissView || mController.hasActiveNotifications())
                && mStatusBarState != StatusBarState.KEYGUARD
                && !mRemoteInputManager.getController().isRemoteInputActive();
                && (remoteInputController == null || !remoteInputController.isRemoteInputActive());
        boolean showHistory = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, UserHandle.USER_CURRENT) == 1;

@@ -721,22 +668,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
     * Return whether there are any clearable notifications
     */
    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
    public boolean hasActiveClearableNotifications(@SelectedRows int selection) {
        if (mDynamicPrivacyController.isInLockedDownShade()) {
            return false;
        }
        int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = getChildAt(i);
            if (!(child instanceof ExpandableNotificationRow)) {
                continue;
            }
            final ExpandableNotificationRow row = (ExpandableNotificationRow) child;
            if (row.canViewBeDismissed() && matchesSelection(row, selection)) {
                return true;
            }
        }
        return false;
    boolean hasActiveClearableNotifications(@SelectedRows int selection) {
        return mController.hasActiveClearableNotifications(selection);
    }

    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
@@ -5292,8 +5225,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        updateFooter();
        requestChildrenUpdate();
        onUpdateRowStates();

        mEntryManager.updateNotifications("StatusBar state changed");
        updateVisibility();
    }

@@ -5697,10 +5628,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        return mController;
    }

    void setCurrentUserid(int userId) {
        mCurrentUserId = userId;
    }

    void addSwipedOutView(View v) {
        mSwipedOutViews.add(v);
    }
@@ -5774,6 +5701,14 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        return mCheckForLeavebehind;
    }

    void setDismissAllAnimationListener(DismissAllAnimationListener dismissAllAnimationListener) {
        mDismissAllAnimationListener = dismissAllAnimationListener;
    }

    public void setHighPriorityBeforeSpeedBump(boolean highPriorityBeforeSpeedBump) {
        mHighPriorityBeforeSpeedBump = highPriorityBeforeSpeedBump;
    }

    /**
     * A listener that is notified when the empty space below the notifications is clicked on
     */
@@ -5852,7 +5787,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        mSwipeHelper.resetExposedMenuView(animate, force);
    }

    private static boolean matchesSelection(
    static boolean matchesSelection(
            ExpandableNotificationRow row,
            @SelectedRows int selection) {
        switch (selection) {
@@ -6127,7 +6062,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable

    // --------------------- NotificationEntryManager/NotifPipeline methods ------------------------

    private void onEntryUpdated(NotificationEntry entry) {
    void onEntryUpdated(NotificationEntry entry) {
        // If the row already exists, the user may have performed a dismiss action on the
        // notification. Since it's not clearable we should snap it back.
        if (entry.rowExists() && !entry.getSbn().isClearable()) {
@@ -6135,72 +6070,16 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        }
    }

    private boolean hasActiveNotifications() {
        if (mFeatureFlags.isNewNotifPipelineRenderingEnabled()) {
            return !mNotifPipeline.getShadeList().isEmpty();
        } else {
            return mEntryManager.hasActiveNotifications();
        }
    }

    /**
     * Called after the animations for a "clear all notifications" action has ended.
     */
    private void onDismissAllAnimationsEnd(
            List<ExpandableNotificationRow> viewsToRemove,
            @SelectedRows int selectedRows) {
        if (mFeatureFlags.isNewNotifPipelineRenderingEnabled()) {
            if (selectedRows == ROWS_ALL) {
                mNotifCollection.dismissAllNotifications(mCurrentUserId);
            } else {
                final List<Pair<NotificationEntry, DismissedByUserStats>>
                        entriesWithRowsDismissedFromShade = new ArrayList<>();
                final int numVisibleEntries = mNotifPipeline.getShadeListCount();
                for (int i = 0; i < viewsToRemove.size(); i++) {
                    final NotificationEntry entry = viewsToRemove.get(i).getEntry();
                    entriesWithRowsDismissedFromShade.add(
                            new Pair<NotificationEntry, DismissedByUserStats>(
                                    entry,
                                    getDismissedByUserStats(entry, numVisibleEntries)));
                }
                mNotifCollection.dismissNotifications(entriesWithRowsDismissedFromShade);
            }
        } else {
            for (ExpandableNotificationRow rowToRemove : viewsToRemove) {
                if (canChildBeDismissed(rowToRemove)) {
                    mEntryManager.performRemoveNotification(
                            rowToRemove.getEntry().getSbn(),
                            getDismissedByUserStats(
                                    rowToRemove.getEntry(),
                                    mEntryManager.getActiveNotificationsCount()),
                            NotificationListenerService.REASON_CANCEL_ALL);
                } else {
                    rowToRemove.resetTranslation();
                }
            }
            if (selectedRows == ROWS_ALL) {
                try {
                    mBarService.onClearAllNotifications(mCurrentUserId);
                } catch (Exception ex) {
                }
        if (mDismissAllAnimationListener != null) {
            mDismissAllAnimationListener.onAnimationEnd(viewsToRemove, selectedRows);
        }
    }
    }

    private DismissedByUserStats getDismissedByUserStats(
            NotificationEntry entry,
            int numVisibleEntries
    ) {
        return new DismissedByUserStats(
            DISMISSAL_SHADE,
            DISMISS_SENTIMENT_NEUTRAL,
            NotificationVisibility.obtain(
                    entry.getKey(),
                    entry.getRanking().getRank(),
                    numVisibleEntries,
                    true,
                    NotificationLogger.getNotificationLocation(entry)));
    }

    public void setKeyguardMediaControllorVisible(boolean keyguardMediaControllorVisible) {
        mKeyguardMediaControllorVisible = keyguardMediaControllorVisible;
@@ -6218,7 +6097,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        /* Only ever called as a consequence of a lockscreen expansion gesture. */
        @Override
        public boolean onDraggedDown(View startingChild, int dragLengthY) {
            boolean canDragDown = hasActiveNotifications() || mKeyguardMediaControllorVisible;
            boolean canDragDown =
                    mController.hasActiveNotifications() || mKeyguardMediaControllorVisible;
            if (mStatusBarState == StatusBarState.KEYGUARD && canDragDown) {
                mLockscreenGestureLogger.write(
                        MetricsEvent.ACTION_LS_SHADE,
@@ -6236,7 +6116,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
                }

                return true;
            } else if (mDynamicPrivacyController.isInLockedDownShade()) {
            } else if (mController.isInLockedDownShade()) {
                mStatusbarStateController.setLeaveOpenOnKeyguardHide(true);
                mStatusBar.dismissKeyguardThenExecute(() -> false /* dismissAction */,
                        null /* cancelRunnable */, false /* afterKeyguardGone */);
@@ -6280,7 +6160,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
            if (isDragDownAnywhereEnabled()) {
                return true;
            }
            if (mDynamicPrivacyController.isInLockedDownShade()) {
            if (mController.isInLockedDownShade()) {
                if (view == null) {
                    // Dragging down is allowed in general
                    return true;
@@ -6424,7 +6304,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    /** Enum for selecting some or all notification rows (does not included non-notif views). */
    @Retention(SOURCE)
    @IntDef({ROWS_ALL, ROWS_HIGH_PRIORITY, ROWS_GENTLE})
    public @interface SelectedRows {}
    @interface SelectedRows {}
    /** All rows representing notifs. */
    public static final int ROWS_ALL = 0;
    /** Only rows where entry.isHighPriority() is true. */
@@ -6466,4 +6346,9 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    interface KeyguardBypassEnabledProvider {
        boolean getBypassEnabled();
    }

    interface DismissAllAnimationListener {
        void onAnimationEnd(
                List<ExpandableNotificationRow> viewsToRemove, @SelectedRows int selectedRows);
    }
}
+158 −13

File changed.

Preview size limit exceeded, changes collapsed.

+21 −82

File changed.

Preview size limit exceeded, changes collapsed.

Loading