Remove SysUiServiceProvider and mComponents.
Bug: 142537875 Test: atest SystemUITests Change-Id: I6c48b182c1e6a1ff8b5ce352a40b5afdb5f07442
This commit is contained in:
@@ -24,12 +24,6 @@ the main path for onConfigurationChanged, now also happens through
|
||||
ConfigurationController). They also receive a callback for onBootCompleted
|
||||
since these objects may be started before the device has finished booting.
|
||||
|
||||
SystemUI and SystemUIApplication also have methods for putComponent and
|
||||
getComponent which were existing systems to get a hold of other parts of
|
||||
sysui before Dependency existed. Generally new things should not be added
|
||||
to putComponent, instead Dependency and other refactoring is preferred to
|
||||
make sysui structure cleaner.
|
||||
|
||||
Each SystemUI service is expected to be a major part of system ui and the
|
||||
goal is to minimize communication between them. So in general they should be
|
||||
relatively silo'd.
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* The interface for getting core components of SysUI. Exists for Testability
|
||||
* since tests don't have SystemUIApplication as their ApplicationContext.
|
||||
*/
|
||||
public interface SysUiServiceProvider {
|
||||
<T> T getComponent(Class<T> interfaceType);
|
||||
|
||||
public static <T> T getComponent(Context context, Class<T> interfaceType) {
|
||||
return ((SysUiServiceProvider) context.getApplicationContext()).getComponent(interfaceType);
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,9 @@ import android.os.Bundle;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class SystemUI implements SysUiServiceProvider {
|
||||
public abstract class SystemUI {
|
||||
protected final Context mContext;
|
||||
public Map<Class<?>, Object> mComponents;
|
||||
|
||||
public SystemUI(Context context) {
|
||||
mContext = context;
|
||||
@@ -44,17 +42,6 @@ public abstract class SystemUI implements SysUiServiceProvider {
|
||||
protected void onBootCompleted() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getComponent(Class<T> interfaceType) {
|
||||
return (T) (mComponents != null ? mComponents.get(interfaceType) : null);
|
||||
}
|
||||
|
||||
public <T, C extends T> void putComponent(Class<T> interfaceType, C component) {
|
||||
if (mComponents != null) {
|
||||
mComponents.put(interfaceType, component);
|
||||
}
|
||||
}
|
||||
|
||||
public static void overrideNotificationAppName(Context context, Notification.Builder n,
|
||||
boolean system) {
|
||||
final Bundle extras = new Bundle();
|
||||
|
||||
@@ -36,13 +36,11 @@ import com.android.systemui.util.NotificationChannels;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Application class for SystemUI.
|
||||
*/
|
||||
public class SystemUIApplication extends Application implements SysUiServiceProvider,
|
||||
public class SystemUIApplication extends Application implements
|
||||
SystemUIAppComponentFactory.ContextInitializer {
|
||||
|
||||
public static final String TAG = "SystemUIService";
|
||||
@@ -56,7 +54,6 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
|
||||
private SystemUI[] mServices;
|
||||
private boolean mServicesStarted;
|
||||
private boolean mBootCompleted;
|
||||
private final Map<Class<?>, Object> mComponents = new HashMap<>();
|
||||
private SystemUIAppComponentFactory.ContextAvailableCallback mContextAvailableCallback;
|
||||
|
||||
public SystemUIApplication() {
|
||||
@@ -199,7 +196,6 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
mServices[i].mComponents = mComponents;
|
||||
if (DEBUG) Log.d(TAG, "running: " + mServices[i]);
|
||||
mServices[i].start();
|
||||
log.traceEnd();
|
||||
@@ -232,11 +228,6 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getComponent(Class<T> interfaceType) {
|
||||
return (T) mComponents.get(interfaceType);
|
||||
}
|
||||
|
||||
public SystemUI[] getServices() {
|
||||
return mServices;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import android.widget.Toast;
|
||||
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysUiServiceProvider;
|
||||
import com.android.systemui.shared.recents.IOverviewProxy;
|
||||
import com.android.systemui.shared.system.ActivityManagerWrapper;
|
||||
import com.android.systemui.stackdivider.Divider;
|
||||
@@ -73,7 +72,7 @@ public class OverviewProxyRecentsImpl implements RecentsImplementation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Context context, SysUiServiceProvider sysUiServiceProvider) {
|
||||
public void onStart(Context context) {
|
||||
mContext = context;
|
||||
mHandler = new Handler();
|
||||
mTrustManager = (TrustManager) context.getSystemService(Context.TRUST_SERVICE);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Recents extends SystemUI implements CommandQueue.Callbacks {
|
||||
@Override
|
||||
public void start() {
|
||||
mCommandQueue.addCallback(this);
|
||||
mImpl.onStart(mContext, this);
|
||||
mImpl.onStart(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,15 +19,13 @@ import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Rect;
|
||||
|
||||
import com.android.systemui.SysUiServiceProvider;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* API for creating a Recents view.
|
||||
*/
|
||||
public interface RecentsImplementation {
|
||||
default void onStart(Context context, SysUiServiceProvider sysUiServiceProvider) {}
|
||||
default void onStart(Context context) {}
|
||||
default void onBootCompleted() {}
|
||||
default void onAppTransitionFinished() {}
|
||||
default void onConfigurationChanged(Configuration newConfig) {}
|
||||
|
||||
@@ -148,7 +148,6 @@ import com.android.systemui.bubbles.BubbleController;
|
||||
import com.android.systemui.charging.WirelessChargingAnimation;
|
||||
import com.android.systemui.classifier.FalsingLog;
|
||||
import com.android.systemui.colorextraction.SysuiColorExtractor;
|
||||
import com.android.systemui.doze.DozeHost;
|
||||
import com.android.systemui.fragments.ExtensionFragmentListener;
|
||||
import com.android.systemui.fragments.FragmentHostManager;
|
||||
import com.android.systemui.keyguard.DismissCallbackRegistry;
|
||||
@@ -794,7 +793,6 @@ public class StatusBar extends SystemUI implements DemoMode,
|
||||
R.bool.config_vibrateOnIconAnimation);
|
||||
|
||||
DateTimeView.setReceiverHandler(Dependency.get(Dependency.TIME_TICK_HANDLER));
|
||||
putComponent(StatusBar.class, this);
|
||||
|
||||
// start old BaseStatusBar.start().
|
||||
mWindowManagerService = WindowManagerGlobal.getWindowManagerService();
|
||||
@@ -896,7 +894,6 @@ public class StatusBar extends SystemUI implements DemoMode,
|
||||
mDozeServiceHost.initialize(this, mNotificationIconAreaController,
|
||||
mStatusBarWindowViewController, mStatusBarWindow, mStatusBarKeyguardViewManager,
|
||||
mNotificationPanel, mAmbientIndicationContainer);
|
||||
putComponent(DozeHost.class, mDozeServiceHost);
|
||||
|
||||
Dependency.get(ActivityStarterDelegate.class).setActivityStarterImpl(this);
|
||||
|
||||
|
||||
@@ -50,8 +50,6 @@ public class TvStatusBar extends SystemUI implements CommandQueue.Callbacks {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
putComponent(TvStatusBar.class, this);
|
||||
|
||||
final IStatusBarService barService = IStatusBarService.Stub.asInterface(
|
||||
ServiceManager.getService(Context.STATUS_BAR_SERVICE));
|
||||
mCommandQueue.addCallback(this);
|
||||
|
||||
@@ -136,7 +136,6 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
||||
mTestableLooper.processAllMessages();
|
||||
}
|
||||
};
|
||||
mScreenDecorations.mComponents = mContext.getComponents();
|
||||
reset(mTunerService);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,13 +17,9 @@ package com.android.systemui;
|
||||
import android.content.Context;
|
||||
import android.testing.LeakCheck;
|
||||
import android.testing.TestableContext;
|
||||
import android.util.ArrayMap;
|
||||
import android.view.Display;
|
||||
|
||||
public class SysuiTestableContext extends TestableContext implements SysUiServiceProvider {
|
||||
|
||||
private ArrayMap<Class<?>, Object> mComponents;
|
||||
|
||||
public class SysuiTestableContext extends TestableContext {
|
||||
public SysuiTestableContext(Context base) {
|
||||
super(base);
|
||||
setTheme(R.style.Theme_SystemUI);
|
||||
@@ -34,21 +30,6 @@ public class SysuiTestableContext extends TestableContext implements SysUiServic
|
||||
setTheme(R.style.Theme_SystemUI);
|
||||
}
|
||||
|
||||
public ArrayMap<Class<?>, Object> getComponents() {
|
||||
if (mComponents == null) mComponents = new ArrayMap<>();
|
||||
return mComponents;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getComponent(Class<T> interfaceType) {
|
||||
return (T) (mComponents != null ? mComponents.get(interfaceType) : null);
|
||||
}
|
||||
|
||||
public <T, C extends T> void putComponent(Class<T> interfaceType, C component) {
|
||||
if (mComponents == null) mComponents = new ArrayMap<>();
|
||||
mComponents.put(interfaceType, component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createDisplayContext(Display display) {
|
||||
if (display == null) {
|
||||
|
||||
@@ -53,7 +53,6 @@ import android.testing.TestableLooper.RunWithLooper;
|
||||
import com.android.internal.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.CommandQueue;
|
||||
import com.android.systemui.statusbar.phone.StatusBar;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -88,8 +87,6 @@ public class AuthControllerTest extends SysuiTestCase {
|
||||
|
||||
TestableContext context = spy(mContext);
|
||||
|
||||
mContext.putComponent(StatusBar.class, mock(StatusBar.class));
|
||||
|
||||
when(context.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE))
|
||||
.thenReturn(true);
|
||||
@@ -104,7 +101,6 @@ public class AuthControllerTest extends SysuiTestCase {
|
||||
|
||||
mAuthController = new TestableAuthController(
|
||||
context, mock(CommandQueue.class), new MockInjector());
|
||||
mAuthController.mComponents = mContext.getComponents();
|
||||
|
||||
mAuthController.start();
|
||||
}
|
||||
|
||||
@@ -687,7 +687,6 @@ public class PowerUITest extends SysuiTestCase {
|
||||
|
||||
private void createPowerUi() {
|
||||
mPowerUI = new PowerUI(mContext, mBroadcastDispatcher, mStatusBarLazy);
|
||||
mPowerUI.mComponents = mContext.getComponents();
|
||||
mPowerUI.mThermalService = mThermalServiceMock;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ import androidx.test.filters.SmallTest;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiBaseFragmentTest;
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||
import com.android.systemui.statusbar.CommandQueue;
|
||||
import com.android.systemui.tuner.TunerService;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -58,10 +56,8 @@ public class CollapsedStatusBarFragmentTest extends SysuiBaseFragmentTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mSysuiContext.putComponent(CommandQueue.class, mock(CommandQueue.class));
|
||||
StatusBar statusBar = mock(StatusBar.class);
|
||||
mDependency.injectTestDependency(StatusBar.class, statusBar);
|
||||
mSysuiContext.putComponent(TunerService.class, mock(TunerService.class));
|
||||
mStatusBarStateController = mDependency
|
||||
.injectMockDependency(StatusBarStateController.class);
|
||||
injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES);
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.phone;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.graphics.PixelFormat;
|
||||
import android.hardware.display.DisplayManager;
|
||||
@@ -37,7 +36,6 @@ import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.SysuiTestableContext;
|
||||
import com.android.systemui.assist.AssistManager;
|
||||
import com.android.systemui.recents.OverviewProxyService;
|
||||
import com.android.systemui.statusbar.CommandQueue;
|
||||
import com.android.systemui.statusbar.policy.KeyguardStateController;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -60,11 +58,9 @@ public class NavigationBarButtonTest extends SysuiTestCase {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mContext.putComponent(CommandQueue.class, mock(CommandQueue.class));
|
||||
final Display display = createVirtualDisplay();
|
||||
final SysuiTestableContext context =
|
||||
(SysuiTestableContext) mContext.createDisplayContext(display);
|
||||
context.putComponent(CommandQueue.class, mock(CommandQueue.class));
|
||||
|
||||
mDependency.injectMockDependency(AssistManager.class);
|
||||
mDependency.injectMockDependency(OverviewProxyService.class);
|
||||
|
||||
@@ -33,7 +33,6 @@ import androidx.test.filters.SmallTest;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.assist.AssistManager;
|
||||
import com.android.systemui.recents.OverviewProxyService;
|
||||
import com.android.systemui.statusbar.CommandQueue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -52,7 +51,6 @@ public class NavigationBarInflaterViewTest extends SysuiTestCase {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext.putComponent(CommandQueue.class, mock(CommandQueue.class));
|
||||
mDependency.injectMockDependency(AssistManager.class);
|
||||
mDependency.injectMockDependency(OverviewProxyService.class);
|
||||
mDependency.injectMockDependency(NavigationModeController.class);
|
||||
|
||||
@@ -389,7 +389,6 @@ public class StatusBarTest extends SysuiTestCase {
|
||||
|
||||
// TODO: we should be able to call mStatusBar.start() and have all the below values
|
||||
// initialized automatically.
|
||||
mStatusBar.mComponents = mContext.getComponents();
|
||||
mStatusBar.mStatusBarWindow = mStatusBarWindowView;
|
||||
mStatusBar.mNotificationPanel = mNotificationPanelView;
|
||||
mStatusBar.mDozeScrimController = mDozeScrimController;
|
||||
|
||||
@@ -82,7 +82,6 @@ public class StatusBarWindowViewTest extends SysuiTestCase {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mView = new StatusBarWindowView(getContext(), null);
|
||||
mContext.putComponent(StatusBar.class, mStatusBar);
|
||||
when(mStatusBar.isDozing()).thenReturn(false);
|
||||
mDependency.injectTestDependency(ShadeController.class, mShadeController);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user