Remove Dependency.get(MAIN_HANDLER) from NotificationLockscreenUserManagerImpl
Also, clean up a bunch of other injectable objects.
Bug: 144503618
Test: atest SystemUITests
Change-Id: I5ec005ee21689d800238fa30c86ef6e08b832bbf
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java b/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java
index e31e44e..606605a 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java
@@ -27,7 +27,6 @@
import android.os.Looper;
import android.os.Process;
import android.os.ServiceManager;
-import android.os.UserManager;
import android.util.DisplayMetrics;
import android.view.IWindowManager;
import android.view.LayoutInflater;
@@ -236,13 +235,6 @@
}
/** */
- @Singleton
- @Provides
- public UserManager providesUserManager(Context context) {
- return context.getSystemService(UserManager.class);
- }
-
- /** */
@Provides
public ViewMediatorCallback providesViewMediatorCallback(KeyguardViewMediator viewMediator) {
return viewMediator.getViewMediatorCallback();
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemServicesModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemServicesModule.java
index 0d4cc01..0205089 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SystemServicesModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemServicesModule.java
@@ -24,6 +24,7 @@
import android.app.IWallpaperManager;
import android.app.KeyguardManager;
import android.app.WallpaperManager;
+import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.res.Resources;
import android.hardware.SensorPrivacyManager;
@@ -31,6 +32,7 @@
import android.os.PowerManager;
import android.os.ServiceManager;
import android.os.UserHandle;
+import android.os.UserManager;
import android.service.dreams.DreamService;
import android.service.dreams.IDreamManager;
import android.view.IWindowManager;
@@ -61,6 +63,12 @@
return context.getSystemService(AlarmManager.class);
}
+ @Provides
+ @Singleton
+ static DevicePolicyManager provideDevicePolicyManager(Context context) {
+ return context.getSystemService(DevicePolicyManager.class);
+ }
+
@Singleton
@Provides
static IActivityManager provideIActivityManager() {
@@ -141,6 +149,12 @@
}
@Provides
+ @Singleton
+ static UserManager provideUserManager(Context context) {
+ return context.getSystemService(UserManager.class);
+ }
+
+ @Provides
static WallpaperManager provideWallpaperManager(Context context) {
return (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
index 89aad8f..f5710a8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
@@ -32,8 +32,8 @@
import android.content.IntentSender;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
+import android.os.Handler;
import android.os.RemoteException;
-import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -48,6 +48,7 @@
import com.android.systemui.Dependency;
import com.android.systemui.Dumpable;
import com.android.systemui.broadcast.BroadcastDispatcher;
+import com.android.systemui.dagger.qualifiers.MainHandler;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.recents.OverviewProxyService;
@@ -76,10 +77,8 @@
private static final String TAG = "LockscreenUserManager";
private static final boolean ENABLE_LOCK_SCREEN_ALLOW_REMOTE_INPUT = false;
- private final DeviceProvisionedController mDeviceProvisionedController =
- Dependency.get(DeviceProvisionedController.class);
- private final KeyguardStateController mKeyguardStateController = Dependency.get(
- KeyguardStateController.class);
+ private final DeviceProvisionedController mDeviceProvisionedController;
+ private final KeyguardStateController mKeyguardStateController;
// Lazy
private NotificationEntryManager mEntryManager;
@@ -168,6 +167,7 @@
};
protected final Context mContext;
+ private final Handler mMainHandler;
protected final SparseArray<UserInfo> mCurrentProfiles = new SparseArray<>();
protected int mCurrentUserId = 0;
@@ -184,24 +184,33 @@
@Inject
public NotificationLockscreenUserManagerImpl(Context context,
- BroadcastDispatcher broadcastDispatcher) {
+ BroadcastDispatcher broadcastDispatcher,
+ DevicePolicyManager devicePolicyManager,
+ UserManager userManager,
+ IStatusBarService iStatusBarService,
+ KeyguardManager keyguardManager,
+ StatusBarStateController statusBarStateController,
+ @MainHandler Handler mainHandler,
+ DeviceProvisionedController deviceProvisionedController,
+ KeyguardStateController keyguardStateController) {
mContext = context;
- mDevicePolicyManager = (DevicePolicyManager) mContext.getSystemService(
- Context.DEVICE_POLICY_SERVICE);
- mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ mMainHandler = mainHandler;
+ mDevicePolicyManager = devicePolicyManager;
+ mUserManager = userManager;
mCurrentUserId = ActivityManager.getCurrentUser();
- mBarService = IStatusBarService.Stub.asInterface(
- ServiceManager.getService(Context.STATUS_BAR_SERVICE));
- Dependency.get(StatusBarStateController.class).addCallback(this);
+ mBarService = iStatusBarService;
+ statusBarStateController.addCallback(this);
mLockPatternUtils = new LockPatternUtils(context);
- mKeyguardManager = context.getSystemService(KeyguardManager.class);
+ mKeyguardManager = keyguardManager;
mBroadcastDispatcher = broadcastDispatcher;
+ mDeviceProvisionedController = deviceProvisionedController;
+ mKeyguardStateController = keyguardStateController;
}
public void setUpWithPresenter(NotificationPresenter presenter) {
mPresenter = presenter;
- mLockscreenSettingsObserver = new ContentObserver(Dependency.get(Dependency.MAIN_HANDLER)) {
+ mLockscreenSettingsObserver = new ContentObserver(mMainHandler) {
@Override
public void onChange(boolean selfChange) {
// We don't know which user changed LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS or
@@ -215,7 +224,7 @@
}
};
- mSettingsObserver = new ContentObserver(Dependency.get(Dependency.MAIN_HANDLER)) {
+ mSettingsObserver = new ContentObserver(mMainHandler) {
@Override
public void onChange(boolean selfChange) {
updateLockscreenNotificationSetting();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
index d54e24ba..ba7b2e2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
@@ -31,6 +31,8 @@
import static org.mockito.Mockito.when;
import android.app.ActivityManager;
+import android.app.KeyguardManager;
+import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -45,12 +47,13 @@
import androidx.test.filters.SmallTest;
+import com.android.internal.statusbar.IStatusBarService;
import com.android.systemui.Dependency;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
+import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
-import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
@@ -66,14 +69,28 @@
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
- @Mock private NotificationPresenter mPresenter;
- @Mock private UserManager mUserManager;
+ @Mock
+ private NotificationPresenter mPresenter;
+ @Mock
+ private UserManager mUserManager;
// Dependency mocks:
- @Mock private NotificationEntryManager mEntryManager;
- @Mock private DeviceProvisionedController mDeviceProvisionedController;
- @Mock private StatusBarKeyguardViewManager mKeyguardViewManager;
- @Mock private BroadcastDispatcher mBroadcastDispatcher;
+ @Mock
+ private NotificationEntryManager mEntryManager;
+ @Mock
+ private DevicePolicyManager mDevicePolicyManager;
+ @Mock
+ private IStatusBarService mIStatusBarService;
+ @Mock
+ private KeyguardManager mKeyguardManager;
+ @Mock
+ private DeviceProvisionedController mDeviceProvisionedController;
+ @Mock
+ private StatusBarStateController mStatusBarStateController;
+ @Mock
+ private BroadcastDispatcher mBroadcastDispatcher;
+ @Mock
+ private KeyguardStateController mKeyguardStateController;
private int mCurrentUserId;
private TestNotificationLockscreenUserManager mLockscreenUserManager;
@@ -82,11 +99,7 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
- mDependency.injectTestDependency(DeviceProvisionedController.class,
- mDeviceProvisionedController);
- mDependency.injectMockDependency(KeyguardStateController.class);
- mContext.addMockSystemService(UserManager.class, mUserManager);
mCurrentUserId = ActivityManager.getCurrentUser();
when(mUserManager.getProfiles(mCurrentUserId)).thenReturn(Lists.newArrayList(
@@ -196,7 +209,10 @@
private class TestNotificationLockscreenUserManager
extends NotificationLockscreenUserManagerImpl {
public TestNotificationLockscreenUserManager(Context context) {
- super(context, mBroadcastDispatcher);
+ super(context, mBroadcastDispatcher, mDevicePolicyManager, mUserManager,
+ mIStatusBarService, NotificationLockscreenUserManagerTest.this.mKeyguardManager,
+ mStatusBarStateController, Handler.createAsync(Looper.myLooper()),
+ mDeviceProvisionedController, mKeyguardStateController);
}
public BroadcastReceiver getBaseBroadcastReceiverForTest() {