Migrate KeyguardClockSwitch to dagger.
Bug: 122448325
Test: atest KeyguardClockSwitchTest
Change-Id: I1e68e3ba0cc92cd4fda9597d2c9c296b80298dc7
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
index ce65b5a..ea8f429 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
@@ -1,5 +1,7 @@
package com.android.keyguard;
+import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT;
+
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
@@ -24,8 +26,8 @@
import androidx.annotation.VisibleForTesting;
import com.android.internal.colorextraction.ColorExtractor;
+import com.android.internal.colorextraction.ColorExtractor.OnColorsChangedListener;
import com.android.keyguard.clock.ClockManager;
-import com.android.systemui.Dependency;
import com.android.systemui.Interpolators;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.plugins.ClockPlugin;
@@ -37,37 +39,65 @@
import java.util.Arrays;
import java.util.TimeZone;
+import javax.inject.Inject;
+import javax.inject.Named;
+
/**
* Switch to show plugin clock when plugin is connected, otherwise it will show default clock.
*/
public class KeyguardClockSwitch extends RelativeLayout {
+ /**
+ * Controller used to track StatusBar state to know when to show the big_clock_container.
+ */
+ private final StatusBarStateController mStatusBarStateController;
+
+ /**
+ * Color extractor used to apply colors from wallpaper to custom clock faces.
+ */
+ private final SysuiColorExtractor mSysuiColorExtractor;
+
+ /**
+ * Manager used to know when to show a custom clock face.
+ */
+ private final ClockManager mClockManager;
+
+ /**
+ * Layout transition that scales the default clock face.
+ */
private final Transition mTransition;
+
/**
* Optional/alternative clock injected via plugin.
*/
private ClockPlugin mClockPlugin;
+
/**
* Default clock.
*/
private TextClock mClockView;
+
/**
* Frame for default and custom clock.
*/
private FrameLayout mSmallClockFrame;
+
/**
* Container for big custom clock.
*/
private ViewGroup mBigClockContainer;
+
/**
* Status area (date and other stuff) shown below the clock. Plugin can decide whether or not to
* show it below the alternate clock.
*/
private View mKeyguardStatusArea;
+
/**
* Maintain state so that a newly connected plugin can be initialized.
*/
private float mDarkAmount;
+
/**
* If the Keyguard Slice has a header (big center-aligned text.)
*/
@@ -96,22 +126,20 @@
*
* The color palette changes when the wallpaper is changed.
*/
- private SysuiColorExtractor.OnColorsChangedListener mColorsListener = (extractor, which) -> {
+ private final OnColorsChangedListener mColorsListener = (extractor, which) -> {
if ((which & WallpaperManager.FLAG_LOCK) != 0) {
- if (extractor instanceof SysuiColorExtractor) {
- updateColors((SysuiColorExtractor) extractor);
- } else {
- updateColors(Dependency.get(SysuiColorExtractor.class));
- }
+ updateColors();
}
};
- public KeyguardClockSwitch(Context context) {
- this(context, null);
- }
-
- public KeyguardClockSwitch(Context context, AttributeSet attrs) {
+ @Inject
+ public KeyguardClockSwitch(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs,
+ StatusBarStateController statusBarStateController, SysuiColorExtractor colorExtractor,
+ ClockManager clockManager) {
super(context, attrs);
+ mStatusBarStateController = statusBarStateController;
+ mSysuiColorExtractor = colorExtractor;
+ mClockManager = clockManager;
mTransition = new ClockBoundsTransition();
}
@@ -133,22 +161,18 @@
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
- Dependency.get(ClockManager.class).addOnClockChangedListener(mClockChangedListener);
- StatusBarStateController stateController = Dependency.get(StatusBarStateController.class);
- stateController.addCallback(mStateListener);
- mStateListener.onStateChanged(stateController.getState());
- SysuiColorExtractor colorExtractor = Dependency.get(SysuiColorExtractor.class);
- colorExtractor.addOnColorsChangedListener(mColorsListener);
- updateColors(colorExtractor);
+ mClockManager.addOnClockChangedListener(mClockChangedListener);
+ mStatusBarStateController.addCallback(mStateListener);
+ mSysuiColorExtractor.addOnColorsChangedListener(mColorsListener);
+ updateColors();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- Dependency.get(ClockManager.class).removeOnClockChangedListener(mClockChangedListener);
- Dependency.get(StatusBarStateController.class).removeCallback(mStateListener);
- Dependency.get(SysuiColorExtractor.class)
- .removeOnColorsChangedListener(mColorsListener);
+ mClockManager.removeOnClockChangedListener(mClockChangedListener);
+ mStatusBarStateController.removeCallback(mStateListener);
+ mSysuiColorExtractor.removeOnColorsChangedListener(mColorsListener);
setClockPlugin(null);
}
@@ -293,9 +317,9 @@
}
}
- private void updateColors(SysuiColorExtractor colorExtractor) {
- ColorExtractor.GradientColors colors = colorExtractor.getColors(WallpaperManager.FLAG_LOCK,
- true);
+ private void updateColors() {
+ ColorExtractor.GradientColors colors = mSysuiColorExtractor.getColors(
+ WallpaperManager.FLAG_LOCK, true);
mSupportsDarkText = colors.supportsDarkText();
mColorPalette = colors.getColorPalette();
if (mClockPlugin != null) {
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java b/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java
index 9dd9717..ae8bc52 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardDisplayManager.java
@@ -28,9 +28,12 @@
import android.util.SparseArray;
import android.view.Display;
import android.view.DisplayInfo;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
+import com.android.systemui.util.InjectionInflationController;
+
// TODO(multi-display): Support multiple external displays
public class KeyguardDisplayManager {
protected static final String TAG = "KeyguardDisplayManager";
@@ -38,6 +41,7 @@
private final MediaRouter mMediaRouter;
private final DisplayManager mDisplayService;
+ private final InjectionInflationController mInjectableInflater;
private final Context mContext;
private boolean mShowing;
@@ -75,8 +79,10 @@
}
};
- public KeyguardDisplayManager(Context context) {
+ public KeyguardDisplayManager(Context context,
+ InjectionInflationController injectableInflater) {
mContext = context;
+ mInjectableInflater = injectableInflater;
mMediaRouter = mContext.getSystemService(MediaRouter.class);
mDisplayService = mContext.getSystemService(DisplayManager.class);
mDisplayService.registerDisplayListener(mDisplayListener, null /* handler */);
@@ -110,7 +116,7 @@
final int displayId = display.getDisplayId();
Presentation presentation = mPresentations.get(displayId);
if (presentation == null) {
- presentation = new KeyguardPresentation(mContext, display);
+ presentation = new KeyguardPresentation(mContext, display, mInjectableInflater);
presentation.setOnDismissListener(dialog -> {
if (null != mPresentations.get(displayId)) {
mPresentations.remove(displayId);
@@ -201,6 +207,7 @@
private final static class KeyguardPresentation extends Presentation {
private static final int VIDEO_SAFE_REGION = 80; // Percentage of display width & height
private static final int MOVE_CLOCK_TIMEOUT = 10000; // 10s
+ private final InjectionInflationController mInjectableInflater;
private View mClock;
private int mUsableWidth;
private int mUsableHeight;
@@ -217,8 +224,10 @@
}
};
- KeyguardPresentation(Context context, Display display) {
+ KeyguardPresentation(Context context, Display display,
+ InjectionInflationController injectionInflater) {
super(context, display, R.style.keyguard_presentation_theme);
+ mInjectableInflater = injectionInflater;
getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
setCancelable(false);
}
@@ -239,7 +248,9 @@
mMarginLeft = (100 - VIDEO_SAFE_REGION) * p.x / 200;
mMarginTop = (100 - VIDEO_SAFE_REGION) * p.y / 200;
- setContentView(R.layout.keyguard_presentation);
+ LayoutInflater inflater = mInjectableInflater.injectable(
+ LayoutInflater.from(getContext()));
+ setContentView(inflater.inflate(R.layout.keyguard_presentation, null));
mClock = findViewById(R.id.clock);
// Avoid screen burn in
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 676e594..d70d0d8 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -90,6 +90,7 @@
import com.android.systemui.statusbar.phone.NotificationPanelView;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
+import com.android.systemui.util.InjectionInflationController;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -710,7 +711,10 @@
mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
SYSTEMUI_PERMISSION, null /* scheduler */);
- mKeyguardDisplayManager = new KeyguardDisplayManager(mContext);
+ InjectionInflationController injectionInflationController =
+ new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent());
+ mKeyguardDisplayManager = new KeyguardDisplayManager(mContext,
+ injectionInflationController);
mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
index 253bdfb..b902e43 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -92,6 +92,7 @@
import com.android.systemui.statusbar.policy.KeyguardUserSwitcher;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
import com.android.systemui.statusbar.policy.ZenModeController;
+import com.android.systemui.util.InjectionInflationController;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -141,6 +142,7 @@
private static final AnimationProperties CLOCK_ANIMATION_PROPERTIES = new AnimationProperties()
.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
+ private final InjectionInflationController mInjectionInflationController;
private final PowerManager mPowerManager;
private final AccessibilityManager mAccessibilityManager;
private final NotificationWakeUpCoordinator mWakeUpCoordinator;
@@ -336,10 +338,12 @@
@Inject
public NotificationPanelView(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs,
+ InjectionInflationController injectionInflationController,
NotificationWakeUpCoordinator coordinator,
PulseExpansionHandler pulseExpansionHandler) {
super(context, attrs);
setWillNotDraw(!DEBUG);
+ mInjectionInflationController = injectionInflationController;
mFalsingManager = FalsingManager.getInstance(context);
mPowerManager = context.getSystemService(PowerManager.class);
mWakeUpCoordinator = coordinator;
@@ -475,10 +479,11 @@
// Re-inflate the status view group.
int index = indexOfChild(mKeyguardStatusView);
removeView(mKeyguardStatusView);
- mKeyguardStatusView = (KeyguardStatusView) LayoutInflater.from(mContext).inflate(
- R.layout.keyguard_status_view,
- this,
- false);
+ mKeyguardStatusView = (KeyguardStatusView) mInjectionInflationController
+ .injectable(LayoutInflater.from(mContext)).inflate(
+ R.layout.keyguard_status_view,
+ this,
+ false);
addView(mKeyguardStatusView, index);
// Re-associate the clock container with the keyguard clock switch.
@@ -490,10 +495,11 @@
index = indexOfChild(mKeyguardBottomArea);
removeView(mKeyguardBottomArea);
KeyguardBottomAreaView oldBottomArea = mKeyguardBottomArea;
- mKeyguardBottomArea = (KeyguardBottomAreaView) LayoutInflater.from(mContext).inflate(
- R.layout.keyguard_bottom_area,
- this,
- false);
+ mKeyguardBottomArea = (KeyguardBottomAreaView) mInjectionInflationController
+ .injectable(LayoutInflater.from(mContext)).inflate(
+ R.layout.keyguard_bottom_area,
+ this,
+ false);
mKeyguardBottomArea.initFrom(oldBottomArea);
addView(mKeyguardBottomArea, index);
initBottomArea();
diff --git a/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java b/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
index e6b6672..7705e4e 100644
--- a/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
+++ b/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
@@ -23,6 +23,7 @@
import android.view.LayoutInflater;
import android.view.View;
+import com.android.keyguard.KeyguardClockSwitch;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.qs.QSCarrierGroup;
import com.android.systemui.qs.QSFooterImpl;
@@ -130,6 +131,11 @@
* Creates the QSCarrierGroup
*/
QSCarrierGroup createQSCarrierGroup();
+
+ /**
+ * Creates the KeyguardClockSwitch.
+ */
+ KeyguardClockSwitch createKeyguardClockSwitch();
}
/**
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
index 29505a2..632b0c0 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
@@ -39,10 +39,12 @@
import android.widget.TextClock;
import com.android.keyguard.clock.ClockManager;
+import com.android.systemui.SystemUIFactory;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.ClockPlugin;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarState;
+import com.android.systemui.util.InjectionInflationController;
import org.junit.Before;
import org.junit.Test;
@@ -70,7 +72,10 @@
@Before
public void setUp() {
- LayoutInflater layoutInflater = LayoutInflater.from(getContext());
+ InjectionInflationController inflationController = new InjectionInflationController(
+ SystemUIFactory.getInstance().getRootComponent());
+ LayoutInflater layoutInflater = inflationController
+ .injectable(LayoutInflater.from(getContext()));
mKeyguardClockSwitch =
(KeyguardClockSwitch) layoutInflater.inflate(R.layout.keyguard_clock_switch, null);
mClockContainer = mKeyguardClockSwitch.findViewById(R.id.clock_view);
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
index 3582ab0..31ea39c 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
@@ -24,8 +24,10 @@
import android.testing.TestableLooper.RunWithLooper;
import android.view.LayoutInflater;
+import com.android.systemui.SystemUIFactory;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.util.Assert;
+import com.android.systemui.util.InjectionInflationController;
import org.junit.Before;
import org.junit.Test;
@@ -48,7 +50,10 @@
@Before
public void setUp() {
Assert.sMainLooper = TestableLooper.get(this).getLooper();
- LayoutInflater layoutInflater = LayoutInflater.from(getContext());
+ InjectionInflationController inflationController = new InjectionInflationController(
+ SystemUIFactory.getInstance().getRootComponent());
+ LayoutInflater layoutInflater = inflationController
+ .injectable(LayoutInflater.from(getContext()));
mKeyguardStatusView =
(KeyguardStatusView) layoutInflater.inflate(R.layout.keyguard_status_view, null);
org.mockito.MockitoAnnotations.initMocks(this);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardPresentationTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardPresentationTest.java
index eec836f..dfe2913 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardPresentationTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardPresentationTest.java
@@ -23,7 +23,9 @@
import androidx.test.filters.SmallTest;
import com.android.systemui.R;
+import com.android.systemui.SystemUIFactory;
import com.android.systemui.SysuiTestCase;
+import com.android.systemui.util.InjectionInflationController;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,7 +37,10 @@
@Test
public void testInflation_doesntCrash() {
com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
- LayoutInflater inflater = LayoutInflater.from(getContext());
+ InjectionInflationController inflationController = new InjectionInflationController(
+ SystemUIFactory.getInstance().getRootComponent());
+ LayoutInflater inflater = inflationController
+ .injectable(LayoutInflater.from(getContext()));
inflater.inflate(R.layout.keyguard_presentation, null);
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java
index 6889c57..232c6a2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewTest.java
@@ -27,6 +27,7 @@
import androidx.test.filters.SmallTest;
import com.android.keyguard.KeyguardStatusView;
+import com.android.systemui.SystemUIFactory;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.AmbientPulseManager;
@@ -38,6 +39,7 @@
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ZenModeController;
+import com.android.systemui.util.InjectionInflationController;
import org.junit.Before;
import org.junit.Test;
@@ -104,7 +106,10 @@
private class TestableNotificationPanelView extends NotificationPanelView {
TestableNotificationPanelView(NotificationWakeUpCoordinator coordinator,
PulseExpansionHandler expansionHandler) {
- super(NotificationPanelViewTest.this.mContext, null, coordinator, expansionHandler);
+ super(NotificationPanelViewTest.this.mContext, null,
+ new InjectionInflationController(
+ SystemUIFactory.getInstance().getRootComponent()),
+ coordinator, expansionHandler);
mNotificationStackScroller = mNotificationStackScrollLayout;
mKeyguardStatusView = NotificationPanelViewTest.this.mKeyguardStatusView;
mKeyguardStatusBar = NotificationPanelViewTest.this.mKeyguardStatusBar;