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

Commit 8386a055 authored by Ned Burns's avatar Ned Burns
Browse files

Break circular dependencies in notif code

Bug: 186481467
Test: atest
Change-Id: Ie5b07bda46c2d217f5eb3be341595a6cb70fdd57
parent be6088d1
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -49,6 +49,12 @@ public interface NotificationLockscreenUserManager {
    /** Adds a listener to be notified when the current user changes. */
    void addUserChangedListener(UserChangedListener listener);

    /**
     * Registers a [KeyguardNotificationSuppressor] that will be consulted during
     * {@link #shouldShowOnKeyguard(NotificationEntry)}
     */
    void addKeyguardNotificationSuppressor(KeyguardNotificationSuppressor suppressor);

    /**
     * Removes a listener previously registered with
     * {@link #addUserChangedListener(UserChangedListener)}
@@ -88,4 +94,9 @@ public interface NotificationLockscreenUserManager {
        default void onUserChanged(int userId) {}
        default void onCurrentProfilesChanged(SparseArray<UserInfo> currentProfiles) {}
    }

    /** Used to hide notifications on the lockscreen */
    interface KeyguardNotificationSuppressor {
        boolean shouldSuppressOnKeyguard(NotificationEntry entry);
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ public class NotificationLockscreenUserManagerImpl implements
    private LockPatternUtils mLockPatternUtils;
    protected KeyguardManager mKeyguardManager;
    private int mState = StatusBarState.SHADE;
    private List<KeyguardNotificationSuppressor> mKeyguardSuppressors = new ArrayList<>();

    protected final BroadcastReceiver mAllUsersReceiver = new BroadcastReceiver() {
        @Override
@@ -343,6 +344,11 @@ public class NotificationLockscreenUserManagerImpl implements
            Log.wtf(TAG, "mEntryManager was null!", new Throwable());
            return false;
        }
        for (int i = 0; i < mKeyguardSuppressors.size(); i++) {
            if (mKeyguardSuppressors.get(i).shouldSuppressOnKeyguard(entry)) {
                return false;
            }
        }
        boolean exceedsPriorityThreshold;
        if (hideSilentNotificationsOnLockscreen()) {
            exceedsPriorityThreshold =
@@ -620,6 +626,11 @@ public class NotificationLockscreenUserManagerImpl implements
        mListeners.add(listener);
    }

    @Override
    public void addKeyguardNotificationSuppressor(KeyguardNotificationSuppressor suppressor) {
        mKeyguardSuppressors.add(suppressor);
    }

    @Override
    public void removeUserChangedListener(UserChangedListener listener) {
        mListeners.remove(listener);
+11 −19
Original line number Diff line number Diff line
@@ -46,8 +46,9 @@ import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.NotificationRemoveInterceptor;
import com.android.systemui.statusbar.NotificationUiAdjustment;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationRankingManager;
import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinder;
import com.android.systemui.statusbar.notification.collection.legacy.LegacyNotificationRanker;
import com.android.systemui.statusbar.notification.collection.legacy.LegacyNotificationRankerStub;
import com.android.systemui.statusbar.notification.collection.legacy.NotificationGroupManagerLegacy;
import com.android.systemui.statusbar.notification.collection.legacy.VisualStabilityManager;
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection;
@@ -138,12 +139,11 @@ public class NotificationEntryManager implements
    private final LeakDetector mLeakDetector;
    private final List<NotifCollectionListener> mNotifCollectionListeners = new ArrayList<>();

    private final KeyguardEnvironment mKeyguardEnvironment;
    private final NotificationGroupManagerLegacy mGroupManager;
    private final Lazy<NotificationRankingManager> mRankingManager;
    private final FeatureFlags mFeatureFlags;
    private final ForegroundServiceDismissalFeatureController mFgsFeatureController;

    private LegacyNotificationRanker mRanker = new LegacyNotificationRankerStub();
    private NotificationPresenter mPresenter;
    private RankingMap mLatestRankingMap;

@@ -200,8 +200,6 @@ public class NotificationEntryManager implements
    public NotificationEntryManager(
            NotificationEntryManagerLogger logger,
            NotificationGroupManagerLegacy groupManager,
            Lazy<NotificationRankingManager> rankingManager,
            KeyguardEnvironment keyguardEnvironment,
            FeatureFlags featureFlags,
            Lazy<NotificationRowBinder> notificationRowBinderLazy,
            Lazy<NotificationRemoteInputManager> notificationRemoteInputManagerLazy,
@@ -211,8 +209,6 @@ public class NotificationEntryManager implements
    ) {
        mLogger = logger;
        mGroupManager = groupManager;
        mRankingManager = rankingManager;
        mKeyguardEnvironment = keyguardEnvironment;
        mFeatureFlags = featureFlags;
        mNotificationRowBinderLazy = notificationRowBinderLazy;
        mRemoteInputManagerLazy = notificationRemoteInputManagerLazy;
@@ -226,6 +222,10 @@ public class NotificationEntryManager implements
        notificationListener.addNotificationHandler(mNotifListener);
    }

    public void setRanker(LegacyNotificationRanker ranker) {
        mRanker = ranker;
    }

    /** Adds a {@link NotificationEntryListener}. */
    public void addNotificationEntryListener(NotificationEntryListener listener) {
        mNotificationEntryListeners.add(listener);
@@ -419,7 +419,7 @@ public class NotificationEntryManager implements

        mActiveNotifications.put(entry.getKey(), entry);
        mGroupManager.onEntryAdded(entry);
        updateRankingAndSort(mRankingManager.get().getRankingMap(), "addEntryInternalInternal");
        updateRankingAndSort(mRanker.getRankingMap(), "addEntryInternalInternal");
    }

    /**
@@ -698,13 +698,6 @@ public class NotificationEntryManager implements

        updateNotifications("updateNotificationInternal");

        if (DEBUG) {
            // Is this for you?
            boolean isForCurrentUser = mKeyguardEnvironment
                    .isNotificationForCurrentProfiles(notification);
            Log.d(TAG, "notification is " + (isForCurrentUser ? "" : "not ") + "for you");
        }

        for (NotificationEntryListener listener : mNotificationEntryListeners) {
            listener.onPostEntryUpdated(entry);
        }
@@ -862,8 +855,7 @@ public class NotificationEntryManager implements
        final int len = mActiveNotifications.size();
        for (int i = 0; i < len; i++) {
            NotificationEntry entry = mActiveNotifications.valueAt(i);
            final StatusBarNotification sbn = entry.getSbn();
            if (!mKeyguardEnvironment.isNotificationForCurrentProfiles(sbn)) {
            if (!mRanker.isNotificationForCurrentProfiles(entry)) {
                continue;
            }
            filtered.add(entry);
@@ -886,13 +878,13 @@ public class NotificationEntryManager implements

    /** Resorts / filters the current notification set with the current RankingMap */
    public void reapplyFilterAndSort(String reason) {
        updateRankingAndSort(mRankingManager.get().getRankingMap(), reason);
        updateRankingAndSort(mRanker.getRankingMap(), reason);
    }

    /** Calls to NotificationRankingManager and updates mSortedAndFiltered */
    private void updateRankingAndSort(@NonNull RankingMap rankingMap, String reason) {
        mSortedAndFiltered.clear();
        mSortedAndFiltered.addAll(mRankingManager.get().updateRanking(
        mSortedAndFiltered.addAll(mRanker.updateRanking(
                rankingMap, mActiveNotifications.values(), reason));
    }

+17 −43
Original line number Diff line number Diff line
@@ -27,14 +27,13 @@ import android.os.RemoteException;
import android.service.notification.StatusBarNotification;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dependency;
import com.android.systemui.ForegroundServiceController;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.media.MediaFeatureFlag;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.notification.NotificationEntryManager.KeyguardEnvironment;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.phone.ShadeController;

import javax.inject.Inject;

@@ -46,68 +45,43 @@ import javax.inject.Inject;
public class NotificationFilter {

    private final StatusBarStateController mStatusBarStateController;
    private final KeyguardEnvironment mKeyguardEnvironment;
    private final ForegroundServiceController mForegroundServiceController;
    private final NotificationLockscreenUserManager mUserManager;
    private final Boolean mIsMediaFlagEnabled;

    private NotificationEntryManager.KeyguardEnvironment mEnvironment;
    private ShadeController mShadeController;
    private ForegroundServiceController mFsc;
    private NotificationLockscreenUserManager mUserManager;

    @Inject
    public NotificationFilter(
            StatusBarStateController statusBarStateController,
            KeyguardEnvironment keyguardEnvironment,
            ForegroundServiceController foregroundServiceController,
            NotificationLockscreenUserManager userManager,
            MediaFeatureFlag mediaFeatureFlag) {
        mStatusBarStateController = statusBarStateController;
        mKeyguardEnvironment = keyguardEnvironment;
        mForegroundServiceController = foregroundServiceController;
        mUserManager = userManager;
        mIsMediaFlagEnabled = mediaFeatureFlag.getEnabled();
    }

    private NotificationEntryManager.KeyguardEnvironment getEnvironment() {
        if (mEnvironment == null) {
            mEnvironment = Dependency.get(NotificationEntryManager.KeyguardEnvironment.class);
        }
        return mEnvironment;
    }

    private ShadeController getShadeController() {
        if (mShadeController == null) {
            mShadeController = Dependency.get(ShadeController.class);
        }
        return mShadeController;
    }

    private ForegroundServiceController getFsc() {
        if (mFsc == null) {
            mFsc = Dependency.get(ForegroundServiceController.class);
        }
        return mFsc;
    }

    private NotificationLockscreenUserManager getUserManager() {
        if (mUserManager == null) {
            mUserManager = Dependency.get(NotificationLockscreenUserManager.class);
        }
        return mUserManager;
    }


    /**
     * @return true if the provided notification should NOT be shown right now.
     */
    public boolean shouldFilterOut(NotificationEntry entry) {
        final StatusBarNotification sbn = entry.getSbn();
        if (!(getEnvironment().isDeviceProvisioned()
        if (!(mKeyguardEnvironment.isDeviceProvisioned()
                || showNotificationEvenIfUnprovisioned(sbn))) {
            return true;
        }

        if (!getEnvironment().isNotificationForCurrentProfiles(sbn)) {
        if (!mKeyguardEnvironment.isNotificationForCurrentProfiles(sbn)) {
            return true;
        }

        if (getUserManager().isLockscreenPublicMode(sbn.getUserId())
        if (mUserManager.isLockscreenPublicMode(sbn.getUserId())
                && (sbn.getNotification().visibility == Notification.VISIBILITY_SECRET
                        || getUserManager().shouldHideNotifications(sbn.getUserId())
                        || getUserManager().shouldHideNotifications(sbn.getKey()))) {
                        || mUserManager.shouldHideNotifications(sbn.getUserId())
                        || mUserManager.shouldHideNotifications(sbn.getKey()))) {
            return true;
        }

@@ -123,8 +97,8 @@ public class NotificationFilter {
            return true;
        }

        if (getFsc().isDisclosureNotification(sbn)
                && !getFsc().isDisclosureNeededForUser(sbn.getUserId())) {
        if (mForegroundServiceController.isDisclosureNotification(sbn)
                && !mForegroundServiceController.isDisclosureNeededForUser(sbn.getUserId())) {
            // this is a foreground-service disclosure for a user that does not need to show one
            return true;
        }
+13 −5
Original line number Diff line number Diff line
@@ -23,9 +23,11 @@ import android.service.notification.NotificationListenerService.Ranking
import android.service.notification.NotificationListenerService.RankingMap
import android.service.notification.StatusBarNotification
import com.android.systemui.statusbar.NotificationMediaManager
import com.android.systemui.statusbar.notification.NotificationEntryManager.KeyguardEnvironment
import com.android.systemui.statusbar.notification.NotificationEntryManagerLogger
import com.android.systemui.statusbar.notification.NotificationFilter
import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager
import com.android.systemui.statusbar.notification.collection.legacy.LegacyNotificationRanker
import com.android.systemui.statusbar.notification.collection.legacy.NotificationGroupManagerLegacy
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier
@@ -39,7 +41,6 @@ import com.android.systemui.statusbar.policy.HeadsUpManager
import dagger.Lazy
import java.util.Objects
import javax.inject.Inject
import kotlin.Comparator

private const val TAG = "NotifRankingManager"

@@ -60,10 +61,11 @@ open class NotificationRankingManager @Inject constructor(
    private val logger: NotificationEntryManagerLogger,
    private val sectionsFeatureManager: NotificationSectionsFeatureManager,
    private val peopleNotificationIdentifier: PeopleNotificationIdentifier,
    private val highPriorityProvider: HighPriorityProvider
) {
    private val highPriorityProvider: HighPriorityProvider,
    private val keyguardEnvironment: KeyguardEnvironment
) : LegacyNotificationRanker {

    var rankingMap: RankingMap? = null
    override var rankingMap: RankingMap? = null
        protected set
    private val mediaManager by lazy {
        mediaManagerLazy.get()
@@ -115,7 +117,7 @@ open class NotificationRankingManager @Inject constructor(
        }
    }

    fun updateRanking(
    override fun updateRanking(
        newRankingMap: RankingMap?,
        entries: Collection<NotificationEntry>,
        reason: String
@@ -131,6 +133,12 @@ open class NotificationRankingManager @Inject constructor(
        }
    }

    override fun isNotificationForCurrentProfiles(
        entry: NotificationEntry
    ): Boolean {
        return keyguardEnvironment.isNotificationForCurrentProfiles(entry.sbn)
    }

    /** Uses the [rankingComparator] to sort notifications which aren't filtered */
    private fun filterAndSortLocked(
        entries: Collection<NotificationEntry>,
Loading