Loading packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java +0 −1 Original line number Original line Diff line number Diff line Loading @@ -47,7 +47,6 @@ public class RemoteInputController { private final Delegate mDelegate; private final Delegate mDelegate; public RemoteInputController(Delegate delegate) { public RemoteInputController(Delegate delegate) { addCallback(Dependency.get(StatusBarWindowManager.class)); mDelegate = delegate; mDelegate = delegate; } } Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -2760,6 +2760,7 @@ public class StatusBar extends SystemUI implements DemoMode, mStackScroller.requestDisallowDismiss(); mStackScroller.requestDisallowDismiss(); } } }); }); mRemoteInputManager.getController().addCallback(mStatusBarWindowManager); mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight()); mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight()); } } Loading packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java +7 −0 Original line number Original line Diff line number Diff line Loading @@ -18,9 +18,11 @@ import static org.mockito.Mockito.mock; import android.content.Context; import android.content.Context; import android.util.ArrayMap; import android.util.ArrayMap; import android.util.ArraySet; public class TestableDependency extends Dependency { public class TestableDependency extends Dependency { private final ArrayMap<Object, Object> mObjs = new ArrayMap<>(); private final ArrayMap<Object, Object> mObjs = new ArrayMap<>(); private final ArraySet<Object> mInstantiatedObjects = new ArraySet<>(); public TestableDependency(Context context) { public TestableDependency(Context context) { mContext = context; mContext = context; Loading @@ -47,6 +49,11 @@ public class TestableDependency extends Dependency { @Override @Override protected <T> T createDependency(Object key) { protected <T> T createDependency(Object key) { if (mObjs.containsKey(key)) return (T) mObjs.get(key); if (mObjs.containsKey(key)) return (T) mObjs.get(key); mInstantiatedObjects.add(key); return super.createDependency(key); return super.createDependency(key); } } public <T> boolean hasInstantiatedDependency(Class<T> key) { return mObjs.containsKey(key) || mInstantiatedObjects.contains(key); } } } packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java 0 → 100644 +99 −0 Original line number Original line Diff line number Diff line /* * 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)); } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java +0 −1 Original line number Original line Diff line number Diff line Loading @@ -47,7 +47,6 @@ public class RemoteInputController { private final Delegate mDelegate; private final Delegate mDelegate; public RemoteInputController(Delegate delegate) { public RemoteInputController(Delegate delegate) { addCallback(Dependency.get(StatusBarWindowManager.class)); mDelegate = delegate; mDelegate = delegate; } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -2760,6 +2760,7 @@ public class StatusBar extends SystemUI implements DemoMode, mStackScroller.requestDisallowDismiss(); mStackScroller.requestDisallowDismiss(); } } }); }); mRemoteInputManager.getController().addCallback(mStatusBarWindowManager); mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight()); mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight()); } } Loading
packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java +7 −0 Original line number Original line Diff line number Diff line Loading @@ -18,9 +18,11 @@ import static org.mockito.Mockito.mock; import android.content.Context; import android.content.Context; import android.util.ArrayMap; import android.util.ArrayMap; import android.util.ArraySet; public class TestableDependency extends Dependency { public class TestableDependency extends Dependency { private final ArrayMap<Object, Object> mObjs = new ArrayMap<>(); private final ArrayMap<Object, Object> mObjs = new ArrayMap<>(); private final ArraySet<Object> mInstantiatedObjects = new ArraySet<>(); public TestableDependency(Context context) { public TestableDependency(Context context) { mContext = context; mContext = context; Loading @@ -47,6 +49,11 @@ public class TestableDependency extends Dependency { @Override @Override protected <T> T createDependency(Object key) { protected <T> T createDependency(Object key) { if (mObjs.containsKey(key)) return (T) mObjs.get(key); if (mObjs.containsKey(key)) return (T) mObjs.get(key); mInstantiatedObjects.add(key); return super.createDependency(key); return super.createDependency(key); } } public <T> boolean hasInstantiatedDependency(Class<T> key) { return mObjs.containsKey(key) || mInstantiatedObjects.contains(key); } } }
packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java 0 → 100644 +99 −0 Original line number Original line Diff line number Diff line /* * 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)); } }