Merge "Remove call to getComponent(StatusBar) from ScreenDecorations."
diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
index ad20986..8a99e45 100644
--- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
+++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
@@ -81,10 +81,16 @@
import java.util.ArrayList;
import java.util.List;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import dagger.Lazy;
+
/**
* An overlay that draws screen decorations in software (e.g for rounded corners or display cutout)
* for antialiasing and emulation purposes.
*/
+@Singleton
public class ScreenDecorations extends SystemUI implements Tunable {
private static final boolean DEBUG = false;
private static final String TAG = "ScreenDecorations";
@@ -94,6 +100,7 @@
private static final boolean DEBUG_SCREENSHOT_ROUNDED_CORNERS =
SystemProperties.getBoolean("debug.screenshot_rounded_corners", false);
private static final boolean VERBOSE = false;
+ private final Lazy<StatusBar> mStatusBarLazy;
private DisplayManager mDisplayManager;
private DisplayManager.DisplayListener mDisplayListener;
@@ -132,8 +139,10 @@
return result;
}
- public ScreenDecorations(Context context) {
+ @Inject
+ public ScreenDecorations(Context context, Lazy<StatusBar> statusBarLazy) {
super(context);
+ mStatusBarLazy = statusBarLazy;
}
@Override
@@ -434,13 +443,13 @@
private void setupStatusBarPadding(int padding) {
// Add some padding to all the content near the edge of the screen.
- StatusBar sb = getComponent(StatusBar.class);
- View statusBar = (sb != null ? sb.getStatusBarWindow() : null);
- if (statusBar != null) {
- TunablePadding.addTunablePadding(statusBar.findViewById(R.id.keyguard_header), PADDING,
- padding, FLAG_END);
+ StatusBar statusBar = mStatusBarLazy.get();
+ View statusBarWindow = statusBar.getStatusBarWindow();
+ if (statusBarWindow != null) {
+ TunablePadding.addTunablePadding(statusBarWindow.findViewById(R.id.keyguard_header),
+ PADDING, padding, FLAG_END);
- FragmentHostManager fragmentHostManager = FragmentHostManager.get(statusBar);
+ FragmentHostManager fragmentHostManager = FragmentHostManager.get(statusBarWindow);
fragmentHostManager.addTagListener(CollapsedStatusBarFragment.TAG,
new TunablePaddingTagListener(padding, R.id.status_bar));
fragmentHostManager.addTagListener(QS.TAG,
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java
index 71c2e38..738f539 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java
@@ -17,6 +17,7 @@
package com.android.systemui.dagger;
import com.android.systemui.LatencyTester;
+import com.android.systemui.ScreenDecorations;
import com.android.systemui.SystemUI;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.pip.PipUI;
@@ -73,6 +74,11 @@
@ClassKey(Recents.class)
public abstract SystemUI bindRecents(Recents sysui);
+ /** Inject into ScreenDecorations. */
+ @Binds
+ @IntoMap
+ @ClassKey(ScreenDecorations.class)
+ public abstract SystemUI bindScreenDecorations(ScreenDecorations sysui);
/** Inject into VolumeUI. */
@Binds
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
index c338d70..7359fdce 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
@@ -61,9 +61,13 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import java.util.Collections;
+import dagger.Lazy;
+
@RunWithLooper
@RunWith(AndroidTestingRunner.class)
@SmallTest
@@ -71,16 +75,19 @@
private TestableLooper mTestableLooper;
private ScreenDecorations mScreenDecorations;
- private StatusBar mStatusBar;
+ @Mock private StatusBar mStatusBar;
private WindowManager mWindowManager;
private FragmentService mFragmentService;
private FragmentHostManager mFragmentHostManager;
private TunerService mTunerService;
private StatusBarWindowView mView;
private TunablePaddingService mTunablePaddingService;
+ @Mock private Lazy<StatusBar> mStatusBarLazy;
@Before
public void setup() {
+ MockitoAnnotations.initMocks(this);
+
mTestableLooper = TestableLooper.get(this);
mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
new Handler(mTestableLooper.getLooper()));
@@ -88,11 +95,10 @@
mTunerService = mDependency.injectMockDependency(TunerService.class);
mFragmentService = mDependency.injectMockDependency(FragmentService.class);
- mStatusBar = mock(StatusBar.class);
mWindowManager = mock(WindowManager.class);
mView = spy(new StatusBarWindowView(mContext, null));
+ when(mStatusBarLazy.get()).thenReturn(mStatusBar);
when(mStatusBar.getStatusBarWindow()).thenReturn(mView);
- mContext.putComponent(StatusBar.class, mStatusBar);
Display display = mContext.getSystemService(WindowManager.class).getDefaultDisplay();
when(mWindowManager.getDefaultDisplay()).thenReturn(display);
@@ -102,7 +108,7 @@
when(mFragmentService.getFragmentHostManager(any())).thenReturn(mFragmentHostManager);
- mScreenDecorations = new ScreenDecorations(mContext) {
+ mScreenDecorations = new ScreenDecorations(mContext, mStatusBarLazy) {
@Override
public void start() {
super.start();