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

Commit 2d5a1e95 authored by Gus Prevas's avatar Gus Prevas
Browse files

Removes circular dependency between NotificationMediaManager and NotificationEntryManager.

This change makes NotificationMediaManager register itself as a
NotificationEntryListener instead of having NotificationEntryManager
separately and explicitly notify it of a notification being removed.
This allows us to remove the dependency of NotificationEntryManager on
NotificationMediaManager.  (The reverse dependency already existed.)

Test: atest SystemUITests, manual
Change-Id: I0577bf864668ccbecd70a3c3b13b610f981f7fc4
parent dca2be5f
Loading
Loading
Loading
Loading
+0 −30
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.car;

import android.content.Context;

import com.android.systemui.statusbar.NotificationMediaManager;

public class CarNotificationMediaManager extends NotificationMediaManager {
    public CarNotificationMediaManager(Context context) {
        super(context);
    }

    @Override
    public void updateMediaMetaData(boolean metaDataChanged, boolean allowEnterAnimation) {
        // Do nothing, we don't want to display media art in the lock screen for a car.
    }
}
+40 −45
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.media.session.PlaybackState;
import android.os.Handler;
import android.os.Trace;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
@@ -45,8 +46,8 @@ import com.android.systemui.Dependency;
import com.android.systemui.Dumpable;
import com.android.systemui.Interpolators;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.statusbar.notification.NotificationData;
import com.android.systemui.statusbar.notification.NotificationData.Entry;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.phone.BiometricUnlockController;
import com.android.systemui.statusbar.phone.LockscreenWallpaper;
@@ -64,6 +65,8 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;

import dagger.Lazy;

/**
 * Handles tasks and state related to media notifications. For example, there is a 'current' media
 * notification, which this class keeps track of.
@@ -83,9 +86,9 @@ public class NotificationMediaManager implements Dumpable {

    // Late binding, also @Nullable due to being in com.android.systemui.statusbar.phone package
    @Nullable
    private ShadeController mShadeController;
    private Lazy<ShadeController> mShadeController;
    @Nullable
    private StatusBarWindowController mStatusBarWindowController;
    private Lazy<StatusBarWindowController> mStatusBarWindowController;

    @Nullable
    private BiometricUnlockController mBiometricUnlockController;
@@ -135,37 +138,30 @@ public class NotificationMediaManager implements Dumpable {
        }
    };

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

    @Nullable
    private StatusBarWindowController getWindowController() {
        if (mStatusBarWindowController == null) {
            mStatusBarWindowController = Dependency.get(StatusBarWindowController.class);
        }
        return mStatusBarWindowController;
    }

    private NotificationEntryManager getEntryManager() {
        if (mEntryManager == null) {
            mEntryManager = Dependency.get(NotificationEntryManager.class);
        }
        return mEntryManager;
    }

    @Inject
    public NotificationMediaManager(Context context) {
    public NotificationMediaManager(
            Context context,
            Lazy<ShadeController> shadeController,
            Lazy<StatusBarWindowController> statusBarWindowController,
            NotificationEntryManager notificationEntryManager) {
        mContext = context;
        mMediaListeners = new ArrayList<>();
        mMediaSessionManager
                = (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE);
        // TODO: use MediaSessionManager.SessionListener to hook us up to future updates
        // in session state
        mShadeController = shadeController;
        mStatusBarWindowController = statusBarWindowController;
        mEntryManager = notificationEntryManager;
        notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
            @Override
            public void onEntryRemoved(String key, StatusBarNotification old,
                    boolean lifetimeExtended, boolean removedByUser) {
                if (!lifetimeExtended) {
                    onNotificationRemoved(key);
                }
            }
        });
    }

    public void setUpWithPresenter(NotificationPresenter presenter) {
@@ -191,9 +187,8 @@ public class NotificationMediaManager implements Dumpable {
        if (mMediaNotificationKey == null) {
            return null;
        }
        NotificationEntryManager manager = getEntryManager();
        synchronized (manager.getNotificationData()) {
            Entry entry = manager.getNotificationData().get(mMediaNotificationKey);
        synchronized (mEntryManager.getNotificationData()) {
            Entry entry = mEntryManager.getNotificationData().get(mMediaNotificationKey);
            if (entry == null || entry.expandedIcon == null) {
                return null;
            }
@@ -214,10 +209,9 @@ public class NotificationMediaManager implements Dumpable {
    public void findAndUpdateMediaNotifications() {
        boolean metaDataChanged = false;

        NotificationEntryManager manager = getEntryManager();
        synchronized (manager.getNotificationData()) {
            ArrayList<Entry> activeNotifications = manager
                    .getNotificationData().getActiveNotifications();
        synchronized (mEntryManager.getNotificationData()) {
            ArrayList<Entry> activeNotifications =
                    mEntryManager.getNotificationData().getActiveNotifications();
            final int N = activeNotifications.size();

            // Promote the media notification with a controller in 'playing' state, if any.
@@ -305,7 +299,7 @@ public class NotificationMediaManager implements Dumpable {
        }

        if (metaDataChanged) {
            getEntryManager().updateNotifications();
            mEntryManager.updateNotifications();
        }

        dispatchUpdateMediaMetaData(metaDataChanged, true /* allowEnterAnimation */);
@@ -440,8 +434,9 @@ public class NotificationMediaManager implements Dumpable {
            }
        }

        boolean hideBecauseOccluded = getShadeController() != null
                && getShadeController().isOccluded();
        ShadeController shadeController = mShadeController.get();
        StatusBarWindowController windowController = mStatusBarWindowController.get();
        boolean hideBecauseOccluded = shadeController != null && shadeController.isOccluded();

        final boolean hasArtwork = artworkDrawable != null;
        mColorExtractor.setHasBackdrop(hasArtwork);
@@ -464,8 +459,8 @@ public class NotificationMediaManager implements Dumpable {
                    mBackdrop.animate().cancel();
                    mBackdrop.setAlpha(1f);
                }
                if (getWindowController() != null) {
                    getWindowController().setBackdropShowing(true);
                if (windowController != null) {
                    windowController.setBackdropShowing(true);
                }
                metaDataChanged = true;
                if (DEBUG_MEDIA) {
@@ -512,8 +507,8 @@ public class NotificationMediaManager implements Dumpable {
                if (DEBUG_MEDIA) {
                    Log.v(TAG, "DEBUG_MEDIA: Fading out album artwork");
                }
                boolean cannotAnimateDoze = getShadeController() != null
                        && getShadeController().isDozing()
                boolean cannotAnimateDoze = shadeController != null
                        && shadeController.isDozing()
                        && !ScrimState.AOD.getAnimateChange();
                if (mBiometricUnlockController != null && mBiometricUnlockController.getMode()
                        == BiometricUnlockController.MODE_WAKE_AND_UNLOCK_PULSING
@@ -522,12 +517,12 @@ public class NotificationMediaManager implements Dumpable {
                    // We are unlocking directly - no animation!
                    mBackdrop.setVisibility(View.GONE);
                    mBackdropBack.setImageDrawable(null);
                    if (getWindowController() != null) {
                        getWindowController().setBackdropShowing(false);
                    if (windowController != null) {
                        windowController.setBackdropShowing(false);
                    }
                } else {
                    if (getWindowController() != null) {
                        getWindowController().setBackdropShowing(false);
                    if (windowController != null) {
                        windowController.setBackdropShowing(false);
                    }
                    mBackdrop.animate()
                            .alpha(0)
+0 −10
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import com.android.systemui.ForegroundServiceController;
import com.android.systemui.bubbles.BubbleController;
import com.android.systemui.statusbar.AmbientPulseManager;
import com.android.systemui.statusbar.NotificationLifetimeExtender;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.NotificationPresenter;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.NotificationUiAdjustment;
@@ -99,7 +98,6 @@ public class NotificationEntryManager implements

    // Lazily retrieved dependencies
    private NotificationRemoteInputManager mRemoteInputManager;
    private NotificationMediaManager mMediaManager;
    private NotificationRowBinder mNotificationRowBinder;

    private final Handler mDeferredNotificationViewUpdateHandler;
@@ -168,13 +166,6 @@ public class NotificationEntryManager implements
        return mRemoteInputManager;
    }

    private NotificationMediaManager getMediaManager() {
        if (mMediaManager == null) {
            mMediaManager = Dependency.get(NotificationMediaManager.class);
        }
        return mMediaManager;
    }

    private NotificationRowBinder getRowBinder() {
        if (mNotificationRowBinder == null) {
            mNotificationRowBinder = Dependency.get(NotificationRowBinder.class);
@@ -390,7 +381,6 @@ public class NotificationEntryManager implements
                    extender.setShouldManageLifetime(entry, false /* shouldManage */);
                }

                getMediaManager().onNotificationRemoved(key);
                mForegroundServiceController.removeNotification(entry.notification);

                if (entry.rowExists()) {
+0 −3
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.util.Log;

import com.android.systemui.Dependency;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.notification.NotificationData.KeyguardEnvironment;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;

@@ -34,8 +33,6 @@ public class KeyguardEnvironmentImpl implements KeyguardEnvironment {
            Dependency.get(NotificationLockscreenUserManager.class);
    private final DeviceProvisionedController mDeviceProvisionedController =
            Dependency.get(DeviceProvisionedController.class);
    private final NotificationMediaManager mMediaManager =
            Dependency.get(NotificationMediaManager.class);

    public KeyguardEnvironmentImpl() {
    }
+0 −4
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.NotificationLifetimeExtender;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.NotificationPresenter;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.RemoteInputController;
@@ -118,7 +117,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
    @Mock private NotificationGroupManager mGroupManager;
    @Mock private NotificationGutsManager mGutsManager;
    @Mock private NotificationRemoteInputManager mRemoteInputManager;
    @Mock private NotificationMediaManager mMediaManager;
    @Mock private NotificationListener mNotificationListener;
    @Mock private DeviceProvisionedController mDeviceProvisionedController;
    @Mock private VisualStabilityManager mVisualStabilityManager;
@@ -204,7 +202,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
        mDependency.injectTestDependency(NotificationGroupManager.class, mGroupManager);
        mDependency.injectTestDependency(NotificationGutsManager.class, mGutsManager);
        mDependency.injectTestDependency(NotificationRemoteInputManager.class, mRemoteInputManager);
        mDependency.injectTestDependency(NotificationMediaManager.class, mMediaManager);
        mDependency.injectTestDependency(NotificationListener.class, mNotificationListener);
        mDependency.injectTestDependency(DeviceProvisionedController.class,
                mDeviceProvisionedController);
@@ -319,7 +316,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
        verify(mBarService, never()).onNotificationError(any(), any(), anyInt(), anyInt(), anyInt(),
                any(), anyInt());

        verify(mMediaManager).onNotificationRemoved(mSbn.getKey());
        verify(mForegroundServiceController).removeNotification(mSbn);
        verify(mListContainer).cleanUpViewStateForEntry(mEntry);
        verify(mPresenter).updateNotificationViews();