From 93bd046b16061dd8221bb3d7fd29a2bcb76784da Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Tue, 29 Nov 2022 11:00:16 -0800 Subject: [PATCH] [Bouncer] destroy and recreate view when... Reloading color. In consequence, I removed as many reloadColor methods from within the bouncer hierarchy as I could that were safe to remove. By destroying the view, the newly inflated view should have the updated colors. Fixes: 260095692 Test: View pattern view after setting dark theme on and off. Change-Id: Ic7037b06fc9b870fb9cb31af1bd7fdca0a12dbc0 --- .../com/android/keyguard/EmergencyButton.java | 12 ------- .../KeyguardAbsKeyInputViewController.java | 8 ----- .../keyguard/KeyguardInputViewController.java | 11 ------- .../KeyguardMessageAreaController.java | 7 ----- .../KeyguardPasswordViewController.java | 14 --------- .../KeyguardPatternViewController.java | 11 ------- .../keyguard/KeyguardPinViewController.java | 6 ---- .../KeyguardSecurityContainerController.java | 10 ++++-- ...KeyguardSecurityViewFlipperController.java | 11 +------ .../KeyguardSimPinViewController.java | 6 ---- .../KeyguardSimPukViewController.java | 6 ---- ...yguardSecurityContainerControllerTest.java | 31 ++++++++++++++++++- ...uardSecurityViewFlipperControllerTest.java | 2 +- 13 files changed, 39 insertions(+), 96 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java index 458d22efd2064..a25b281f807c6 100644 --- a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java +++ b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java @@ -25,7 +25,6 @@ import android.widget.Button; import com.android.internal.util.EmergencyAffordanceManager; import com.android.internal.widget.LockPatternUtils; -import com.android.settingslib.Utils; /** * This class implements a smart emergency button that updates itself based @@ -91,17 +90,6 @@ public class EmergencyButton extends Button { return super.onTouchEvent(event); } - /** - * Reload colors from resources. - **/ - public void reloadColors() { - int color = Utils.getColorAttrDefaultColor(getContext(), - com.android.internal.R.attr.textColorOnAccent); - setTextColor(color); - setBackground(getContext() - .getDrawable(com.android.systemui.R.drawable.kg_emergency_button_background)); - } - @Override public boolean performLongClick() { return super.performLongClick(); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java index 3e32cf5521ff4..860c8e3a9f77d 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java @@ -20,7 +20,6 @@ import static com.android.internal.util.LatencyTracker.ACTION_CHECK_CREDENTIAL; import static com.android.internal.util.LatencyTracker.ACTION_CHECK_CREDENTIAL_UNLOCKED; import static com.android.keyguard.KeyguardAbsKeyInputView.MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT; -import android.annotation.CallSuper; import android.content.res.ColorStateList; import android.os.AsyncTask; import android.os.CountDownTimer; @@ -117,13 +116,6 @@ public abstract class KeyguardAbsKeyInputViewController public void showMessage(CharSequence message, ColorStateList colorState) { } - /** - * Reload colors from resources. - **/ - @CallSuper - public void reloadColors() { - if (mEmergencyButton != null) { - mEmergencyButton.reloadColors(); - } - } - public void startAppearAnimation() { if (TextUtils.isEmpty(mMessageAreaController.getMessage())) { mMessageAreaController.setMessage(getInitialMessageResId()); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardMessageAreaController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardMessageAreaController.java index c29f632b88d36..6a9216218d075 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardMessageAreaController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardMessageAreaController.java @@ -116,13 +116,6 @@ public class KeyguardMessageAreaController return mView.getText(); } - /** - * Reload colors from resources. - **/ - public void reloadColors() { - mView.reloadColor(); - } - /** Factory for creating {@link com.android.keyguard.KeyguardMessageAreaController}. */ public static class Factory { private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java index 0025986c0e5c3..195e8f92754d4 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordViewController.java @@ -16,7 +16,6 @@ package com.android.keyguard; -import android.content.res.ColorStateList; import android.content.res.Resources; import android.os.UserHandle; import android.text.Editable; @@ -39,7 +38,6 @@ import android.widget.TextView.OnEditorActionListener; import com.android.internal.util.LatencyTracker; import com.android.internal.widget.LockPatternUtils; import com.android.keyguard.KeyguardSecurityModel.SecurityMode; -import com.android.settingslib.Utils; import com.android.systemui.R; import com.android.systemui.classifier.FalsingCollector; import com.android.systemui.dagger.qualifiers.Main; @@ -95,18 +93,6 @@ public class KeyguardPasswordViewController } }; - @Override - public void reloadColors() { - super.reloadColors(); - int textColor = Utils.getColorAttr(mView.getContext(), - android.R.attr.textColorPrimary).getDefaultColor(); - mPasswordEntry.setTextColor(textColor); - mPasswordEntry.setHighlightColor(textColor); - mPasswordEntry.setBackgroundTintList(ColorStateList.valueOf(textColor)); - mPasswordEntry.setForegroundTintList(ColorStateList.valueOf(textColor)); - mSwitchImeButton.setImageTintList(ColorStateList.valueOf(textColor)); - } - protected KeyguardPasswordViewController(KeyguardPasswordView view, KeyguardUpdateMonitor keyguardUpdateMonitor, SecurityMode securityMode, diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java index cdbfb2492e276..571d2740773df 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java @@ -35,7 +35,6 @@ import com.android.internal.widget.LockPatternView.Cell; import com.android.internal.widget.LockscreenCredential; import com.android.keyguard.EmergencyButtonController.EmergencyButtonCallback; import com.android.keyguard.KeyguardSecurityModel.SecurityMode; -import com.android.settingslib.Utils; import com.android.systemui.R; import com.android.systemui.classifier.FalsingClassifier; import com.android.systemui.classifier.FalsingCollector; @@ -271,16 +270,6 @@ public class KeyguardPatternViewController } } - @Override - public void reloadColors() { - super.reloadColors(); - mMessageAreaController.reloadColors(); - int textColor = Utils.getColorAttr(mLockPatternView.getContext(), - android.R.attr.textColorSecondary).getDefaultColor(); - int errorColor = Utils.getColorError(mLockPatternView.getContext()).getDefaultColor(); - mLockPatternView.setColors(textColor, textColor, errorColor); - } - @Override public void onPause() { super.onPause(); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java index 7876f071fdf51..f51ac325c9c17 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPinViewController.java @@ -69,12 +69,6 @@ public class KeyguardPinViewController mPostureController.removeCallback(mPostureCallback); } - @Override - public void reloadColors() { - super.reloadColors(); - mView.reloadColors(); - } - @Override public boolean startDisappearAnimation(Runnable finishRunnable) { return mView.startDisappearAnimation( diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java index 01be33e1e1565..0e6258eccfb90 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java @@ -728,16 +728,20 @@ public class KeyguardSecurityContainerController extends ViewController child : mChildren) { - child.reloadColors(); - } - } - /** Handles density or font scale changes. */ - public void onDensityOrFontScaleChanged() { + public void clearViews() { mView.removeAllViews(); mChildren.clear(); } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java index 76f7d785071d2..db4447399e134 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java @@ -132,12 +132,6 @@ public class KeyguardSimPinViewController } } - @Override - public void reloadColors() { - super.reloadColors(); - mView.reloadColors(); - } - @Override protected void verifyPasswordAndUnlock() { String entry = mPasswordEntry.getText(); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java index 5995e859c786d..e9405eb799015 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java @@ -120,12 +120,6 @@ public class KeyguardSimPukViewController mStateMachine.reset(); } - @Override - public void reloadColors() { - super.reloadColors(); - mView.reloadColors(); - } - @Override protected void verifyPasswordAndUnlock() { mStateMachine.next(); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java index 4d58b09f10767..9423a0a1627d3 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java @@ -558,11 +558,40 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase { configurationListenerArgumentCaptor.getValue().onDensityOrFontScaleChanged(); verify(mView).onDensityOrFontScaleChanged(); - verify(mKeyguardSecurityViewFlipperController).onDensityOrFontScaleChanged(); + verify(mKeyguardSecurityViewFlipperController).clearViews(); verify(mKeyguardSecurityViewFlipperController).getSecurityView(any(SecurityMode.class), any(KeyguardSecurityCallback.class)); } + @Test + public void onThemeChanged() { + ArgumentCaptor + configurationListenerArgumentCaptor = ArgumentCaptor.forClass( + ConfigurationController.ConfigurationListener.class); + mKeyguardSecurityContainerController.onViewAttached(); + verify(mConfigurationController).addCallback(configurationListenerArgumentCaptor.capture()); + configurationListenerArgumentCaptor.getValue().onThemeChanged(); + + verify(mView).reloadColors(); + verify(mKeyguardSecurityViewFlipperController).clearViews(); + verify(mKeyguardSecurityViewFlipperController).getSecurityView(any(SecurityMode.class), + any(KeyguardSecurityCallback.class)); + } + + @Test + public void onUiModeChanged() { + ArgumentCaptor + configurationListenerArgumentCaptor = ArgumentCaptor.forClass( + ConfigurationController.ConfigurationListener.class); + mKeyguardSecurityContainerController.onViewAttached(); + verify(mConfigurationController).addCallback(configurationListenerArgumentCaptor.capture()); + configurationListenerArgumentCaptor.getValue().onUiModeChanged(); + + verify(mView).reloadColors(); + verify(mKeyguardSecurityViewFlipperController).clearViews(); + verify(mKeyguardSecurityViewFlipperController).getSecurityView(any(SecurityMode.class), + any(KeyguardSecurityCallback.class)); + } private KeyguardSecurityContainer.SwipeListener getRegisteredSwipeListener() { mKeyguardSecurityContainerController.onViewAttached(); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java index fd02ac97cec27..1614b577a6cc3 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityViewFlipperControllerTest.java @@ -109,7 +109,7 @@ public class KeyguardSecurityViewFlipperControllerTest extends SysuiTestCase { @Test public void onDensityOrFontScaleChanged() { - mKeyguardSecurityViewFlipperController.onDensityOrFontScaleChanged(); + mKeyguardSecurityViewFlipperController.clearViews(); verify(mView).removeAllViews(); } }