diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java b/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java index 97e3d22c6a468..cfc69a8f67a99 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java @@ -47,7 +47,6 @@ public class RemoteInputController { private final Delegate mDelegate; public RemoteInputController(Delegate delegate) { - addCallback(Dependency.get(StatusBarWindowManager.class)); mDelegate = delegate; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 2da1e4d108b4f..440f9f6c29b47 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -2742,6 +2742,7 @@ public class StatusBar extends SystemUI implements DemoMode, mStackScroller.requestDisallowDismiss(); } }); + mRemoteInputManager.getController().addCallback(mStatusBarWindowManager); mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight()); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java b/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java index 53a799497fd8c..5c83d99b646ae 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java +++ b/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java @@ -18,9 +18,11 @@ import static org.mockito.Mockito.mock; import android.content.Context; import android.util.ArrayMap; +import android.util.ArraySet; public class TestableDependency extends Dependency { private final ArrayMap mObjs = new ArrayMap<>(); + private final ArraySet mInstantiatedObjects = new ArraySet<>(); public TestableDependency(Context context) { mContext = context; @@ -47,6 +49,11 @@ public class TestableDependency extends Dependency { @Override protected T createDependency(Object key) { if (mObjs.containsKey(key)) return (T) mObjs.get(key); + mInstantiatedObjects.add(key); return super.createDependency(key); } + + public boolean hasInstantiatedDependency(Class key) { + return mObjs.containsKey(key) || mInstantiatedObjects.contains(key); + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java new file mode 100644 index 0000000000000..5f763a45f3eb7 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2017 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.statusbar; + +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.when; + +import android.os.Handler; +import android.os.Looper; +import android.support.test.filters.SmallTest; +import android.testing.AndroidTestingRunner; +import android.testing.TestableLooper; + +import com.android.systemui.Dependency; +import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.phone.NotificationGroupManager; +import com.android.systemui.statusbar.phone.StatusBarWindowManager; +import com.android.systemui.statusbar.policy.HeadsUpManager; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Verifies that particular sets of dependencies don't have dependencies on others. For example, + * code managing notifications shouldn't directly depend on StatusBar, since there are platforms + * which want to manage notifications, but don't use StatusBar. + */ +@SmallTest +@RunWith(AndroidTestingRunner.class) +@TestableLooper.RunWithLooper +public class NonPhoneDependencyTest extends SysuiTestCase { + @Mock private NotificationPresenter mPresenter; + @Mock private NotificationListContainer mListContainer; + @Mock private NotificationEntryManager.Callback mEntryManagerCallback; + @Mock private HeadsUpManager mHeadsUpManager; + @Mock private RemoteInputController.Delegate mDelegate; + @Mock private NotificationInfo.CheckSaveListener mCheckSaveListener; + @Mock private NotificationGutsManager.OnSettingsClickListener mOnClickListener; + @Mock private NotificationRemoteInputManager.Callback mRemoteInputManagerCallback; + + private Handler mHandler; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mHandler = new Handler(Looper.getMainLooper()); + when(mPresenter.getHandler()).thenReturn(mHandler); + } + + @Test + public void testNotificationManagementCodeHasNoDependencyOnStatusBarWindowManager() { + NotificationEntryManager entryManager = Dependency.get(NotificationEntryManager.class); + NotificationGutsManager gutsManager = Dependency.get(NotificationGutsManager.class); + NotificationListener notificationListener = Dependency.get(NotificationListener.class); + NotificationLogger notificationLogger = Dependency.get(NotificationLogger.class); + NotificationMediaManager mediaManager = Dependency.get(NotificationMediaManager.class); + NotificationRemoteInputManager remoteInputManager = + Dependency.get(NotificationRemoteInputManager.class); + NotificationLockscreenUserManager lockscreenUserManager = + Dependency.get(NotificationLockscreenUserManager.class); + NotificationViewHierarchyManager viewHierarchyManager = + Dependency.get(NotificationViewHierarchyManager.class); + + when(mPresenter.getNotificationLockscreenUserManager()).thenReturn(lockscreenUserManager); + when(mPresenter.getGroupManager()).thenReturn( + Dependency.get(NotificationGroupManager.class)); + + entryManager.setUpWithPresenter(mPresenter, mListContainer, mEntryManagerCallback, + mHeadsUpManager); + gutsManager.setUpWithPresenter(mPresenter, entryManager, mListContainer, + mCheckSaveListener, mOnClickListener); + notificationListener.setUpWithPresenter(mPresenter, entryManager); + notificationLogger.setUpWithEntryManager(entryManager, mListContainer); + mediaManager.setUpWithPresenter(mPresenter, entryManager); + remoteInputManager.setUpWithPresenter(mPresenter, entryManager, mRemoteInputManagerCallback, + mDelegate); + lockscreenUserManager.setUpWithPresenter(mPresenter, entryManager); + viewHierarchyManager.setUpWithPresenter(mPresenter, entryManager, mListContainer); + + assertFalse(mDependency.hasInstantiatedDependency(StatusBarWindowManager.class)); + } +}