Remove dependency from RemoteInputController to StatusBarWindowManager.

Removes the direct dependecy from RemoteInputController to
StatusBarWindowManager and adds a test testing that notification
management code doesn't depend upon StatusBarWindowManager.

Bug: 63874929
Bug: 62602530
Test: runtest systemui
Test: Compile and run
Change-Id: I9cf63a7069cd6c4b7bd05db881c3029fe5bb1fad
This commit is contained in:
Eliot Courtney
2018-01-10 18:22:55 +09:00
parent 482907c1cc
commit 012fae99b3
4 changed files with 107 additions and 1 deletions

View File

@@ -47,7 +47,6 @@ public class RemoteInputController {
private final Delegate mDelegate;
public RemoteInputController(Delegate delegate) {
addCallback(Dependency.get(StatusBarWindowManager.class));
mDelegate = delegate;
}

View File

@@ -2742,6 +2742,7 @@ public class StatusBar extends SystemUI implements DemoMode,
mStackScroller.requestDisallowDismiss();
}
});
mRemoteInputManager.getController().addCallback(mStatusBarWindowManager);
mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight());
}

View File

@@ -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<Object, Object> mObjs = new ArrayMap<>();
private final ArraySet<Object> mInstantiatedObjects = new ArraySet<>();
public TestableDependency(Context context) {
mContext = context;
@@ -47,6 +49,11 @@ public class TestableDependency extends Dependency {
@Override
protected <T> T createDependency(Object key) {
if (mObjs.containsKey(key)) return (T) mObjs.get(key);
mInstantiatedObjects.add(key);
return super.createDependency(key);
}
public <T> boolean hasInstantiatedDependency(Class<T> key) {
return mObjs.containsKey(key) || mInstantiatedObjects.contains(key);
}
}

View File

@@ -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));
}
}