[DO NOT MERGE] 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
This commit is contained in:
Matt Pietal
2021-11-16 12:44:14 -05:00
parent 7d75b59495
commit 9688ad33e7
6 changed files with 90 additions and 20 deletions

View File

@@ -9603,6 +9603,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.
*

View File

@@ -191,5 +191,6 @@ public class SecureSettings {
Settings.Secure.LOCATION_TIME_ZONE_DETECTION_ENABLED,
Settings.Secure.LOCKSCREEN_SHOW_CONTROLS,
Settings.Secure.LOCKSCREEN_SHOW_WALLET,
Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK,
};
}

View File

@@ -150,6 +150,7 @@ public class SecureSettingsValidators {
VALIDATORS.put(Secure.POWER_MENU_LOCKED_SHOW_CONTENT, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.LOCKSCREEN_SHOW_CONTROLS, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.LOCKSCREEN_SHOW_WALLET, 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);

View File

@@ -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);
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));