diff options
| author | 2021-11-16 12:44:14 -0500 | |
|---|---|---|
| committer | 2021-11-17 19:26:26 +0000 | |
| commit | 6f341cd95c716d20f3a304259ee68338a3e28249 (patch) | |
| tree | eb1f1552fc55836722d53a700e68b6147dedf1f2 | |
| parent | 85b0025008ca48a5585f9ebdd001e8c5626b43bc (diff) | |
Allow a settings override for double-line clock
This setting allows users to always show a single-line format clock,
regardless of notification status.
Fixes: 194905512
Test: atest KeyguardClockSwitchControllerTest
Change-Id: I77269988447fc5732ff6b8774654ce4bf9c026de
6 files changed, 90 insertions, 20 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 3d7c026810a7..943a3687582f 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -9658,6 +9658,14 @@ public final class Settings { public static final String LOCKSCREEN_SHOW_WALLET = "lockscreen_show_wallet"; /** + * Whether to use the lockscreen double-line clock + * + * @hide + */ + public static final String LOCKSCREEN_USE_DOUBLE_LINE_CLOCK = + "lockscreen_use_double_line_clock"; + + /** * Specifies whether the web action API is enabled. * * @hide diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java index 1c7c19ff56b7..4e2111c7d864 100644 --- a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java +++ b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java @@ -193,5 +193,6 @@ public class SecureSettings { Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, Settings.Secure.LOCKSCREEN_SHOW_WALLET, Settings.Secure.LOCK_SCREEN_SHOW_QR_CODE_SCANNER, + Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK, }; } diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java index 3a5ead3ca429..dd1cb6b32d4f 100644 --- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java +++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java @@ -154,6 +154,7 @@ public class SecureSettingsValidators { VALIDATORS.put(Secure.LOCKSCREEN_SHOW_CONTROLS, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.LOCKSCREEN_SHOW_WALLET, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.LOCK_SCREEN_SHOW_QR_CODE_SCANNER, BOOLEAN_VALIDATOR); + VALIDATORS.put(Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.DOZE_ENABLED, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.DOZE_ALWAYS_ON, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.DOZE_PICK_UP_GESTURE, BOOLEAN_VALIDATOR); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java index 3d4e896178f6..9238b8226bbc 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java @@ -11,7 +11,6 @@ import android.util.AttributeSet; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; -import android.view.ViewTreeObserver.OnPreDrawListener; import android.widget.FrameLayout; import android.widget.RelativeLayout; @@ -89,7 +88,6 @@ public class KeyguardClockSwitch extends RelativeLayout { private int mClockSwitchYAmount; @VisibleForTesting boolean mChildrenAreLaidOut = false; - private OnPreDrawListener mPreDrawListener; public KeyguardClockSwitch(Context context, AttributeSet attrs) { super(context, attrs); @@ -284,30 +282,21 @@ public class KeyguardClockSwitch extends RelativeLayout { // translate them properly if (mChildrenAreLaidOut) { animateClockChange(clockSize == LARGE); - mDisplayedClockSize = clockSize; - } else if (mPreDrawListener == null) { - mPreDrawListener = () -> { - switchToClock(clockSize); - getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener); - mPreDrawListener = null; - return true; - }; - getViewTreeObserver().addOnPreDrawListener(mPreDrawListener); } + + mDisplayedClockSize = clockSize; return true; } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); - mChildrenAreLaidOut = true; - } - void onViewDetached() { - if (mPreDrawListener != null) { - getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener); - mPreDrawListener = null; + if (mDisplayedClockSize != null && !mChildrenAreLaidOut) { + animateClockChange(mDisplayedClockSize == LARGE); } + + mChildrenAreLaidOut = true; } public Paint getPaint() { @@ -368,5 +357,6 @@ public class KeyguardClockSwitch extends RelativeLayout { pw.println(" mDarkAmount: " + mDarkAmount); pw.println(" mSupportsDarkText: " + mSupportsDarkText); pw.println(" mColorPalette: " + Arrays.toString(mColorPalette)); + pw.println(" mDisplayedClockSize: " + mDisplayedClockSize); } } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java index 905495d369a0..c628d4401bb1 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java @@ -23,6 +23,8 @@ import static com.android.keyguard.KeyguardClockSwitch.LARGE; import android.app.WallpaperManager; import android.content.res.Resources; +import android.database.ContentObserver; +import android.provider.Settings; import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; @@ -49,11 +51,13 @@ import com.android.systemui.statusbar.phone.NotificationIconAreaController; import com.android.systemui.statusbar.phone.NotificationIconContainer; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.util.ViewController; +import com.android.systemui.util.settings.SecureSettings; import java.util.HashSet; import java.util.Locale; import java.util.Set; import java.util.TimeZone; +import java.util.concurrent.Executor; import javax.inject.Inject; @@ -72,6 +76,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS private final BatteryController mBatteryController; private final LockscreenSmartspaceController mSmartspaceController; private final Resources mResources; + private final SecureSettings mSecureSettings; /** * Clock for both small and large sizes @@ -109,6 +114,14 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS private SmartspaceTransitionController mSmartspaceTransitionController; private boolean mOnlyClock = false; + private Executor mUiExecutor; + private boolean mCanShowDoubleLineClock = true; + private ContentObserver mDoubleLineClockObserver = new ContentObserver(null) { + @Override + public void onChange(boolean change) { + updateDoubleLineClock(); + } + }; @Inject public KeyguardClockSwitchController( @@ -125,6 +138,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS LockscreenSmartspaceController smartspaceController, KeyguardUnlockAnimationController keyguardUnlockAnimationController, SmartspaceTransitionController smartspaceTransitionController, + SecureSettings secureSettings, + @Main Executor uiExecutor, @Main Resources resources) { super(keyguardClockSwitch); mStatusBarStateController = statusBarStateController; @@ -138,7 +153,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mBypassController = bypassController; mSmartspaceController = smartspaceController; mResources = resources; - + mSecureSettings = secureSettings; + mUiExecutor = uiExecutor; mKeyguardUnlockAnimationController = keyguardUnlockAnimationController; mSmartspaceTransitionController = smartspaceTransitionController; } @@ -223,6 +239,14 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS updateClockLayout(); mSmartspaceTransitionController.setLockscreenSmartspace(mSmartspaceView); } + + mSecureSettings.registerContentObserver( + Settings.Secure.getUriFor(Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK), + false, /* notifyForDescendants */ + mDoubleLineClockObserver + ); + + updateDoubleLineClock(); } int getNotificationIconAreaHeight() { @@ -236,7 +260,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS } mColorExtractor.removeOnColorsChangedListener(mColorsListener); mView.setClockPlugin(null, mStatusBarStateController.getState()); - mView.onViewDetached(); + + mSecureSettings.unregisterContentObserver(mDoubleLineClockObserver); } /** @@ -268,6 +293,10 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS * hidden. */ public void displayClock(@KeyguardClockSwitch.ClockSize int clockSize) { + if (!mCanShowDoubleLineClock && clockSize == KeyguardClockSwitch.LARGE) { + return; + } + boolean appeared = mView.switchToClock(clockSize); if (appeared && clockSize == LARGE) { mLargeClockViewController.animateAppear(); @@ -410,4 +439,13 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS private int getCurrentLayoutDirection() { return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()); } + + private void updateDoubleLineClock() { + mCanShowDoubleLineClock = mSecureSettings.getInt( + Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK, 1) != 0; + + if (!mCanShowDoubleLineClock) { + mUiExecutor.execute(() -> displayClock(KeyguardClockSwitch.SMALL)); + } + } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java index 5e0f427800fc..e967033b69a2 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java @@ -18,14 +18,19 @@ package com.android.keyguard; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.res.Resources; +import android.database.ContentObserver; +import android.net.Uri; +import android.provider.Settings; import android.testing.AndroidTestingRunner; import android.view.View; import android.widget.FrameLayout; @@ -50,6 +55,9 @@ import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.phone.NotificationIconAreaController; import com.android.systemui.statusbar.phone.NotificationIconContainer; import com.android.systemui.statusbar.policy.BatteryController; +import com.android.systemui.util.concurrency.FakeExecutor; +import com.android.systemui.util.settings.SecureSettings; +import com.android.systemui.util.time.FakeSystemClock; import org.junit.Before; import org.junit.Test; @@ -104,11 +112,14 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { private AnimatableClockView mLargeClockView; @Mock private FrameLayout mLargeClockFrame; + @Mock + private SecureSettings mSecureSettings; private final View mFakeSmartspaceView = new View(mContext); private KeyguardClockSwitchController mController; private View mSliceView; + private FakeExecutor mExecutor; @Before public void setup() { @@ -129,6 +140,7 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { when(mView.isAttachedToWindow()).thenReturn(true); when(mSmartspaceController.buildAndConnectView(any())).thenReturn(mFakeSmartspaceView); + mExecutor = new FakeExecutor(new FakeSystemClock()); mController = new KeyguardClockSwitchController( mView, mStatusBarStateController, @@ -143,6 +155,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { mSmartspaceController, mKeyguardUnlockAnimationController, mSmartSpaceTransitionController, + mSecureSettings, + mExecutor, mResources ); @@ -194,7 +208,6 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { verifyAttachment(times(1)); listenerArgumentCaptor.getValue().onViewDetachedFromWindow(mView); - verify(mView).onViewDetached(); verify(mColorExtractor).removeOnColorsChangedListener( any(ColorExtractor.OnColorsChangedListener.class)); } @@ -235,6 +248,25 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { verify(mSmartspaceController).requestSmartspaceUpdate(); } + @Test + public void testChangeToDoubleLineClockSetsSmallClock() { + when(mSecureSettings.getInt(Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK, 1)) + .thenReturn(0); + ArgumentCaptor<ContentObserver> observerCaptor = + ArgumentCaptor.forClass(ContentObserver.class); + mController.init(); + verify(mSecureSettings).registerContentObserver(any(Uri.class), + anyBoolean(), observerCaptor.capture()); + ContentObserver observer = observerCaptor.getValue(); + mExecutor.runAllReady(); + + // When a settings change has occurred to the small clock, make sure the view is adjusted + reset(mView); + observer.onChange(true); + mExecutor.runAllReady(); + verify(mView).switchToClock(KeyguardClockSwitch.SMALL); + } + private void verifyAttachment(VerificationMode times) { verify(mClockManager, times).addOnClockChangedListener( any(ClockManager.ClockChangedListener.class)); |