Initialise Notification*Manager dependencies directly.

Currently, adding a new dependency to any of these classes means
updating the constructors of any subclasses, and the construction in the
corresponding SystemUIFactory classes and subclasses. In particular,
updating these in separate vendor/ projects is annoying. So, initialise
the dependencies using field initialisers. The downside is that it's
harder to notice circular Dependencys.

Bug: 63874929
Bug: 62602530
Test: runtest systemui
Test: Compile and run
Change-Id: I21d58d0cc0edeb6d53fb7b387c9baeec7bd80589
This commit is contained in:
Eliot Courtney
2017-12-14 19:57:51 +09:00
parent 4a96b36fd9
commit 6c313d3224
15 changed files with 85 additions and 188 deletions

View File

@@ -127,35 +127,13 @@ public class SystemUIFactory {
providers.put(VisualStabilityManager.class, VisualStabilityManager::new);
providers.put(NotificationGroupManager.class, NotificationGroupManager::new);
providers.put(NotificationMediaManager.class, () -> new NotificationMediaManager(context));
providers.put(NotificationGutsManager.class, () -> new NotificationGutsManager(
Dependency.get(NotificationLockscreenUserManager.class), context));
providers.put(NotificationGutsManager.class, () -> new NotificationGutsManager(context));
providers.put(NotificationRemoteInputManager.class,
() -> new NotificationRemoteInputManager(
Dependency.get(NotificationLockscreenUserManager.class), context));
providers.put(NotificationListener.class, () -> new NotificationListener(
Dependency.get(NotificationRemoteInputManager.class), context));
providers.put(NotificationLogger.class, () -> new NotificationLogger(
Dependency.get(NotificationListener.class),
Dependency.get(UiOffloadThread.class)));
providers.put(NotificationViewHierarchyManager.class, () ->
new NotificationViewHierarchyManager(
Dependency.get(NotificationLockscreenUserManager.class),
Dependency.get(NotificationGroupManager.class),
Dependency.get(VisualStabilityManager.class),
context));
providers.put(NotificationEntryManager.class, () ->
new NotificationEntryManager(
Dependency.get(NotificationLockscreenUserManager.class),
Dependency.get(NotificationGroupManager.class),
Dependency.get(NotificationGutsManager.class),
Dependency.get(NotificationRemoteInputManager.class),
Dependency.get(NotificationMediaManager.class),
Dependency.get(ForegroundServiceController.class),
Dependency.get(NotificationListener.class),
Dependency.get(MetricsLogger.class),
Dependency.get(DeviceProvisionedController.class),
Dependency.get(VisualStabilityManager.class),
Dependency.get(UiOffloadThread.class),
context));
() -> new NotificationRemoteInputManager(context));
providers.put(NotificationListener.class, () -> new NotificationListener(context));
providers.put(NotificationLogger.class, NotificationLogger::new);
providers.put(NotificationViewHierarchyManager.class,
() -> new NotificationViewHierarchyManager(context));
providers.put(NotificationEntryManager.class, () -> new NotificationEntryManager(context));
}
}

View File

@@ -18,37 +18,13 @@ package com.android.systemui.car;
import android.content.Context;
import android.service.notification.StatusBarNotification;
import com.android.internal.logging.MetricsLogger;
import com.android.systemui.ForegroundServiceController;
import com.android.systemui.UiOffloadThread;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationData;
import com.android.systemui.statusbar.NotificationEntryManager;
import com.android.systemui.statusbar.NotificationGutsManager;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.notification.VisualStabilityManager;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
public class CarNotificationEntryManager extends NotificationEntryManager {
public CarNotificationEntryManager(
NotificationLockscreenUserManager lockscreenUserManager,
NotificationGroupManager groupManager,
NotificationGutsManager gutsManager,
NotificationRemoteInputManager remoteInputManager,
NotificationMediaManager mediaManager,
ForegroundServiceController foregroundServiceController,
NotificationListener notificationListener,
MetricsLogger metricsLogger,
DeviceProvisionedController deviceProvisionedController,
VisualStabilityManager visualStabilityManager,
UiOffloadThread uiOffloadThread, Context context) {
super(lockscreenUserManager, groupManager, gutsManager, remoteInputManager, mediaManager,
foregroundServiceController, notificationListener, metricsLogger,
deviceProvisionedController, visualStabilityManager, uiOffloadThread, context);
public CarNotificationEntryManager(Context context) {
super(context);
}
/**

View File

@@ -45,18 +45,7 @@ public class CarSystemUIFactory extends SystemUIFactory {
Context context) {
super.injectDependencies(providers, context);
providers.put(VolumeDialogController.class, () -> new CarVolumeDialogController(context));
providers.put(NotificationEntryManager.class, () -> new CarNotificationEntryManager(
Dependency.get(NotificationLockscreenUserManager.class),
Dependency.get(NotificationGroupManager.class),
Dependency.get(NotificationGutsManager.class),
Dependency.get(NotificationRemoteInputManager.class),
Dependency.get(NotificationMediaManager.class),
Dependency.get(ForegroundServiceController.class),
Dependency.get(NotificationListener.class),
Dependency.get(MetricsLogger.class),
Dependency.get(DeviceProvisionedController.class),
Dependency.get(VisualStabilityManager.class),
Dependency.get(UiOffloadThread.class),
context));
providers.put(NotificationEntryManager.class,
() -> new CarNotificationEntryManager(context));
}
}

View File

@@ -80,24 +80,36 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
protected static final boolean DEBUG = false;
protected static final boolean ENABLE_HEADS_UP = true;
protected static final String SETTING_HEADS_UP_TICKER = "ticker_gets_heads_up";
protected final NotificationMessagingUtil mMessagingUtil;
protected final Context mContext;
protected final NotificationLockscreenUserManager mLockscreenUserManager;
protected final NotificationGroupManager mGroupManager;
protected final NotificationGutsManager mGutsManager;
protected final NotificationRemoteInputManager mRemoteInputManager;
protected final HashMap<String, NotificationData.Entry> mPendingNotifications = new HashMap<>();
protected final NotificationMediaManager mMediaManager;
protected final MetricsLogger mMetricsLogger;
protected final DeviceProvisionedController mDeviceProvisionedController;
protected final VisualStabilityManager mVisualStabilityManager;
protected final UiOffloadThread mUiOffloadThread;
protected final ForegroundServiceController mForegroundServiceController;
protected final NotificationListener mNotificationListener;
protected final NotificationClicker mNotificationClicker = new NotificationClicker();
protected final ArraySet<NotificationData.Entry> mHeadsUpEntriesToRemoveOnSwitch =
new ArraySet<>();
// Dependencies:
protected final NotificationLockscreenUserManager mLockscreenUserManager =
Dependency.get(NotificationLockscreenUserManager.class);
protected final NotificationGroupManager mGroupManager =
Dependency.get(NotificationGroupManager.class);
protected final NotificationGutsManager mGutsManager =
Dependency.get(NotificationGutsManager.class);
protected final NotificationRemoteInputManager mRemoteInputManager =
Dependency.get(NotificationRemoteInputManager.class);
protected final NotificationMediaManager mMediaManager =
Dependency.get(NotificationMediaManager.class);
protected final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
protected final DeviceProvisionedController mDeviceProvisionedController =
Dependency.get(DeviceProvisionedController.class);
protected final VisualStabilityManager mVisualStabilityManager =
Dependency.get(VisualStabilityManager.class);
protected final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class);
protected final ForegroundServiceController mForegroundServiceController =
Dependency.get(ForegroundServiceController.class);
protected final NotificationListener mNotificationListener =
Dependency.get(NotificationListener.class);
protected IStatusBarService mBarService;
protected NotificationPresenter mPresenter;
protected Callback mCallback;
@@ -205,28 +217,7 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
pw.println(mUseHeadsUp);
}
public NotificationEntryManager(NotificationLockscreenUserManager lockscreenUserManager,
NotificationGroupManager groupManager,
NotificationGutsManager gutsManager,
NotificationRemoteInputManager remoteInputManager,
NotificationMediaManager mediaManager,
ForegroundServiceController foregroundServiceController,
NotificationListener notificationListener,
MetricsLogger metricsLogger,
DeviceProvisionedController deviceProvisionedController,
VisualStabilityManager visualStabilityManager,
UiOffloadThread uiOffloadThread, Context context) {
mLockscreenUserManager = lockscreenUserManager;
mGroupManager = groupManager;
mGutsManager = gutsManager;
mRemoteInputManager = remoteInputManager;
mMediaManager = mediaManager;
mForegroundServiceController = foregroundServiceController;
mNotificationListener = notificationListener;
mMetricsLogger = metricsLogger;
mDeviceProvisionedController = deviceProvisionedController;
mVisualStabilityManager = visualStabilityManager;
mUiOffloadThread = uiOffloadThread;
public NotificationEntryManager(Context context) {
mContext = context;
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mBarService = IStatusBarService.Stub.asInterface(

View File

@@ -66,7 +66,10 @@ public class NotificationGutsManager implements Dumpable {
private final Set<String> mNonBlockablePkgs;
private final Context mContext;
private final AccessibilityManager mAccessibilityManager;
private final NotificationLockscreenUserManager mLockscreenUserManager;
// Dependencies:
private final NotificationLockscreenUserManager mLockscreenUserManager =
Dependency.get(NotificationLockscreenUserManager.class);
// which notification is currently being longpress-examined by the user
private NotificationGuts mNotificationGutsExposed;
@@ -78,10 +81,7 @@ public class NotificationGutsManager implements Dumpable {
private OnSettingsClickListener mOnSettingsClickListener;
private String mKeyToRemoveOnGutsClosed;
public NotificationGutsManager(
NotificationLockscreenUserManager lockscreenUserManager,
Context context) {
mLockscreenUserManager = lockscreenUserManager;
public NotificationGutsManager(Context context) {
mContext = context;
Resources res = context.getResources();

View File

@@ -27,6 +27,7 @@ import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import com.android.systemui.Dependency;
import com.android.systemui.statusbar.phone.NotificationListenerWithPlugins;
/**
@@ -36,15 +37,16 @@ import com.android.systemui.statusbar.phone.NotificationListenerWithPlugins;
public class NotificationListener extends NotificationListenerWithPlugins {
private static final String TAG = "NotificationListener";
private final NotificationRemoteInputManager mRemoteInputManager;
// Dependencies:
private final NotificationRemoteInputManager mRemoteInputManager =
Dependency.get(NotificationRemoteInputManager.class);
private final Context mContext;
protected NotificationPresenter mPresenter;
protected NotificationEntryManager mEntryManager;
public NotificationListener(NotificationRemoteInputManager remoteInputManager,
Context context) {
mRemoteInputManager = remoteInputManager;
public NotificationListener(Context context) {
mContext = context;
}

View File

@@ -27,6 +27,7 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.systemui.Dependency;
import com.android.systemui.UiOffloadThread;
import java.util.ArrayList;
@@ -46,8 +47,11 @@ public class NotificationLogger {
/** Keys of notifications currently visible to the user. */
private final ArraySet<NotificationVisibility> mCurrentlyVisibleNotifications =
new ArraySet<>();
private final NotificationListenerService mNotificationListener;
private final UiOffloadThread mUiOffloadThread;
// Dependencies:
private final NotificationListenerService mNotificationListener =
Dependency.get(NotificationListener.class);
private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class);
protected NotificationEntryManager mEntryManager;
protected Handler mHandler = new Handler();
@@ -132,10 +136,7 @@ public class NotificationLogger {
}
};
public NotificationLogger(NotificationListenerService notificationListener,
UiOffloadThread uiOffloadThread) {
mNotificationListener = notificationListener;
mUiOffloadThread = uiOffloadThread;
public NotificationLogger() {
mBarService = IStatusBarService.Stub.asInterface(
ServiceManager.getService(Context.STATUS_BAR_SERVICE));
}

View File

@@ -39,6 +39,7 @@ import android.widget.TextView;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.statusbar.IStatusBarService;
import com.android.systemui.Dependency;
import com.android.systemui.Dumpable;
import com.android.systemui.statusbar.policy.RemoteInputView;
@@ -70,7 +71,10 @@ public class NotificationRemoteInputManager implements Dumpable {
protected final ArraySet<NotificationData.Entry> mRemoteInputEntriesToRemoveOnCollapse =
new ArraySet<>();
protected final NotificationLockscreenUserManager mLockscreenUserManager;
// Dependencies:
protected final NotificationLockscreenUserManager mLockscreenUserManager =
Dependency.get(NotificationLockscreenUserManager.class);
/**
* Notifications with keys in this set are not actually around anymore. We kept them around
@@ -264,9 +268,7 @@ public class NotificationRemoteInputManager implements Dumpable {
}
};
public NotificationRemoteInputManager(NotificationLockscreenUserManager lockscreenUserManager,
Context context) {
mLockscreenUserManager = lockscreenUserManager;
public NotificationRemoteInputManager(Context context) {
mContext = context;
mBarService = IStatusBarService.Stub.asInterface(
ServiceManager.getService(Context.STATUS_BAR_SERVICE));

View File

@@ -22,6 +22,7 @@ import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.VisualStabilityManager;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
@@ -43,9 +44,14 @@ public class NotificationViewHierarchyManager {
private final HashMap<ExpandableNotificationRow, List<ExpandableNotificationRow>>
mTmpChildOrderMap = new HashMap<>();
protected final NotificationLockscreenUserManager mLockscreenUserManager;
protected final NotificationGroupManager mGroupManager;
protected final VisualStabilityManager mVisualStabilityManager;
// Dependencies:
protected final NotificationLockscreenUserManager mLockscreenUserManager =
Dependency.get(NotificationLockscreenUserManager.class);
protected final NotificationGroupManager mGroupManager =
Dependency.get(NotificationGroupManager.class);
protected final VisualStabilityManager mVisualStabilityManager =
Dependency.get(VisualStabilityManager.class);
/**
* {@code true} if notifications not part of a group should by default be rendered in their
@@ -58,15 +64,7 @@ public class NotificationViewHierarchyManager {
private NotificationEntryManager mEntryManager;
private NotificationListContainer mListContainer;
public NotificationViewHierarchyManager(
NotificationLockscreenUserManager lockscreenUserManager,
NotificationGroupManager groupManager,
VisualStabilityManager visualStabilityManager,
Context context) {
mLockscreenUserManager = lockscreenUserManager;
mGroupManager = groupManager;
mVisualStabilityManager = visualStabilityManager;
public NotificationViewHierarchyManager(Context context) {
Resources res = context.getResources();
mAlwaysExpandNonGroupedNotification =
res.getBoolean(R.bool.config_alwaysExpandNonGroupedNotifications);

View File

@@ -101,22 +101,8 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
private class TestableNotificationEntryManager extends NotificationEntryManager {
private final CountDownLatch mCountDownLatch;
public TestableNotificationEntryManager(
NotificationLockscreenUserManager lockscreenUserManager,
NotificationGroupManager groupManager,
NotificationGutsManager gutsManager,
NotificationRemoteInputManager remoteInputManager,
NotificationMediaManager mediaManager,
ForegroundServiceController foregroundServiceController,
NotificationListener notificationListener,
MetricsLogger metricsLogger,
DeviceProvisionedController deviceProvisionedController,
VisualStabilityManager visualStabilityManager,
UiOffloadThread uiOffloadThread, Context context,
IStatusBarService barService) {
super(lockscreenUserManager, groupManager, gutsManager, remoteInputManager,
mediaManager, foregroundServiceController, notificationListener, metricsLogger,
deviceProvisionedController, visualStabilityManager, uiOffloadThread, context);
public TestableNotificationEntryManager(Context context, IStatusBarService barService) {
super(context);
mBarService = barService;
mCountDownLatch = new CountDownLatch(1);
mUseHeadsUp = true;
@@ -170,12 +156,7 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
mEntry = new NotificationData.Entry(mSbn);
mEntry.expandedIcon = mock(StatusBarIconView.class);
mEntryManager = new TestableNotificationEntryManager(mLockscreenUserManager,
mGroupManager, mGutsManager, mRemoteInputManager, mMediaManager,
mForegroundServiceController, mNotificationListener, mMetricsLogger,
mDeviceProvisionedController, mVisualStabilityManager,
mDependency.get(UiOffloadThread.class), mContext,
mBarService);
mEntryManager = new TestableNotificationEntryManager(mContext, mBarService);
mEntryManager.setUpWithPresenter(mPresenter, mListContainer, mCallback, mHeadsUpManager);
}

View File

@@ -77,7 +77,7 @@ public class NotificationListenerTest extends SysuiTestCase {
when(mEntryManager.getNotificationData()).thenReturn(mNotificationData);
when(mRemoteInputManager.getKeysKeptForRemoteInput()).thenReturn(mKeysKeptForRemoteInput);
mListener = new NotificationListener(mRemoteInputManager, mContext);
mListener = new NotificationListener(mContext);
mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0,
new Notification(), UserHandle.CURRENT, null, 0);

View File

@@ -80,8 +80,7 @@ public class NotificationLoggerTest extends SysuiTestCase {
mEntry = new NotificationData.Entry(mSbn);
mEntry.row = mRow;
mLogger = new TestableNotificationLogger(mListener, mDependency.get(UiOffloadThread.class),
mBarService);
mLogger = new TestableNotificationLogger(mBarService);
mLogger.setUpWithEntryManager(mEntryManager, mListContainer);
}
@@ -127,11 +126,7 @@ public class NotificationLoggerTest extends SysuiTestCase {
private class TestableNotificationLogger extends NotificationLogger {
public TestableNotificationLogger(
NotificationListenerService notificationListener,
UiOffloadThread uiOffloadThread,
IStatusBarService barService) {
super(notificationListener, uiOffloadThread);
public TestableNotificationLogger(IStatusBarService barService) {
mBarService = barService;
// Make this on the main thread so we can wait for it during tests.
mHandler = new Handler(Looper.getMainLooper());

View File

@@ -61,8 +61,7 @@ public class NotificationRemoteInputManagerTest extends SysuiTestCase {
when(mPresenter.getHandler()).thenReturn(mHandler);
when(mEntryManager.getLatestRankingMap()).thenReturn(mRanking);
mRemoteInputManager = new TestableNotificationRemoteInputManager(mLockscreenUserManager,
mContext);
mRemoteInputManager = new TestableNotificationRemoteInputManager(mContext);
mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID,
0, new Notification(), UserHandle.CURRENT, null, 0);
mEntry = new NotificationData.Entry(mSbn);
@@ -108,9 +107,8 @@ public class NotificationRemoteInputManagerTest extends SysuiTestCase {
private class TestableNotificationRemoteInputManager extends NotificationRemoteInputManager {
public TestableNotificationRemoteInputManager(
NotificationLockscreenUserManager lockscreenUserManager, Context context) {
super(lockscreenUserManager, context);
public TestableNotificationRemoteInputManager(Context context) {
super(context);
}
public void setUpWithPresenterForTest(NotificationPresenter presenter,

View File

@@ -73,8 +73,7 @@ public class NotificationViewHierarchyManagerTest extends SysuiTestCase {
when(mEntryManager.getNotificationData()).thenReturn(mNotificationData);
mViewHierarchyManager = new NotificationViewHierarchyManager(mLockscreenUserManager,
mGroupManager, mVisualStabilityManager, mContext);
mViewHierarchyManager = new NotificationViewHierarchyManager(mContext);
mViewHierarchyManager.setUpWithPresenter(mPresenter, mEntryManager, mListContainer);
}

View File

@@ -150,8 +150,7 @@ public class StatusBarTest extends SysuiTestCase {
mMetricsLogger = new FakeMetricsLogger();
mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
mNotificationLogger = new NotificationLogger(mNotificationListener,
mDependency.get(UiOffloadThread.class));
mNotificationLogger = new NotificationLogger();
mDependency.injectTestDependency(NotificationLogger.class, mNotificationLogger);
IPowerManager powerManagerService = mock(IPowerManager.class);
@@ -183,8 +182,8 @@ public class StatusBarTest extends SysuiTestCase {
return null;
}).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any());
mEntryManager = new TestableNotificationEntryManager(mMetricsLogger,
mSystemServicesProxy, mPowerManager, mContext);
mEntryManager = new TestableNotificationEntryManager(mSystemServicesProxy, mPowerManager,
mContext);
mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache,
mKeyguardIndicationController, mStackScroller, mHeadsUpManager,
mPowerManager, mNotificationPanelView, mBarService, mNotificationListener,
@@ -637,21 +636,9 @@ public class StatusBarTest extends SysuiTestCase {
private class TestableNotificationEntryManager extends NotificationEntryManager {
public TestableNotificationEntryManager(MetricsLogger metricsLogger,
SystemServicesProxy systemServicesProxy, PowerManager powerManager,
Context context) {
super(mDependency.get(NotificationLockscreenUserManager.class),
mDependency.get(NotificationGroupManager.class),
mDependency.get(NotificationGutsManager.class),
mDependency.get(NotificationRemoteInputManager.class),
mDependency.get(NotificationMediaManager.class),
mDependency.get(ForegroundServiceController.class),
mDependency.get(NotificationListener.class),
metricsLogger,
mDependency.get(DeviceProvisionedController.class),
mDependency.get(VisualStabilityManager.class),
mDependency.get(UiOffloadThread.class),
context);
public TestableNotificationEntryManager(SystemServicesProxy systemServicesProxy,
PowerManager powerManager, Context context) {
super(context);
mSystemServicesProxy = systemServicesProxy;
mPowerManager = powerManager;
}