1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.statusbar; 18 19 import static org.junit.Assert.assertFalse; 20 21 import android.os.Handler; 22 import android.testing.AndroidTestingRunner; 23 import android.testing.TestableLooper; 24 25 import androidx.test.filters.SmallTest; 26 27 import com.android.keyguard.KeyguardUpdateMonitor; 28 import com.android.systemui.Dependency; 29 import com.android.systemui.SysuiTestCase; 30 import com.android.systemui.statusbar.notification.NotificationEntryListener; 31 import com.android.systemui.statusbar.notification.NotificationEntryManager; 32 import com.android.systemui.statusbar.notification.logging.NotificationLogger; 33 import com.android.systemui.statusbar.notification.row.NotificationGutsManager; 34 import com.android.systemui.statusbar.notification.row.NotificationGutsManager.OnSettingsClickListener; 35 import com.android.systemui.statusbar.notification.row.NotificationInfo.CheckSaveListener; 36 import com.android.systemui.statusbar.notification.stack.NotificationListContainer; 37 import com.android.systemui.statusbar.phone.ShadeController; 38 import com.android.systemui.statusbar.policy.HeadsUpManager; 39 40 import org.junit.Before; 41 import org.junit.Ignore; 42 import org.junit.Test; 43 import org.junit.runner.RunWith; 44 import org.mockito.Mock; 45 import org.mockito.MockitoAnnotations; 46 47 /** 48 * Verifies that particular sets of dependencies don't have dependencies on others. For example, 49 * code managing notifications shouldn't directly depend on StatusBar, since there are platforms 50 * which want to manage notifications, but don't use StatusBar. 51 */ 52 @SmallTest 53 @RunWith(AndroidTestingRunner.class) 54 @TestableLooper.RunWithLooper(setAsMainLooper = true) 55 public class NonPhoneDependencyTest extends SysuiTestCase { 56 @Mock private NotificationPresenter mPresenter; 57 @Mock private NotificationListContainer mListContainer; 58 @Mock 59 private NotificationEntryListener mEntryListener; 60 @Mock private HeadsUpManager mHeadsUpManager; 61 @Mock private RemoteInputController.Delegate mDelegate; 62 @Mock private NotificationRemoteInputManager.Callback mRemoteInputManagerCallback; 63 @Mock private CheckSaveListener mCheckSaveListener; 64 @Mock private OnSettingsClickListener mOnSettingsClickListener; 65 66 @Before setUp()67 public void setUp() { 68 MockitoAnnotations.initMocks(this); 69 mDependency.injectMockDependency(KeyguardUpdateMonitor.class); 70 mDependency.injectTestDependency(Dependency.MAIN_HANDLER, 71 new Handler(TestableLooper.get(this).getLooper())); 72 } 73 74 @Ignore("Causes binder calls which fail") 75 @Test testNotificationManagementCodeHasNoDependencyOnStatusBarWindowManager()76 public void testNotificationManagementCodeHasNoDependencyOnStatusBarWindowManager() { 77 mDependency.injectMockDependency(ShadeController.class); 78 NotificationEntryManager entryManager = Dependency.get(NotificationEntryManager.class); 79 NotificationGutsManager gutsManager = Dependency.get(NotificationGutsManager.class); 80 NotificationListener notificationListener = Dependency.get(NotificationListener.class); 81 NotificationLogger notificationLogger = Dependency.get(NotificationLogger.class); 82 NotificationMediaManager mediaManager = Dependency.get(NotificationMediaManager.class); 83 NotificationRemoteInputManager remoteInputManager = 84 Dependency.get(NotificationRemoteInputManager.class); 85 NotificationLockscreenUserManager lockscreenUserManager = 86 Dependency.get(NotificationLockscreenUserManager.class); 87 NotificationViewHierarchyManager viewHierarchyManager = 88 Dependency.get(NotificationViewHierarchyManager.class); 89 entryManager.setUpWithPresenter(mPresenter); 90 entryManager.addNotificationEntryListener(mEntryListener); 91 gutsManager.setUpWithPresenter(mPresenter, mListContainer, 92 mCheckSaveListener, mOnSettingsClickListener); 93 notificationLogger.setUpWithContainer(mListContainer); 94 mediaManager.setUpWithPresenter(mPresenter); 95 remoteInputManager.setUpWithCallback(mRemoteInputManagerCallback, 96 mDelegate); 97 lockscreenUserManager.setUpWithPresenter(mPresenter); 98 viewHierarchyManager.setUpWithPresenter(mPresenter, mListContainer); 99 100 TestableLooper.get(this).processAllMessages(); 101 assertFalse(mDependency.hasInstantiatedDependency(NotificationShadeWindowController.class)); 102 } 103 } 104