[DO NOT MERGE] Allow a settings override for double-line clock am: 9688ad33e7

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16276227

Change-Id: I82d3eb807b7f2ad955a3876bad4b0e94849aa968
This commit is contained in:
Matt Pietal
2021-11-17 17:41:25 +00:00
committed by Automerger Merge Worker
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"; 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. * 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.LOCATION_TIME_ZONE_DETECTION_ENABLED,
Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, Settings.Secure.LOCKSCREEN_SHOW_CONTROLS,
Settings.Secure.LOCKSCREEN_SHOW_WALLET, 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.POWER_MENU_LOCKED_SHOW_CONTENT, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.LOCKSCREEN_SHOW_CONTROLS, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.LOCKSCREEN_SHOW_CONTROLS, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.LOCKSCREEN_SHOW_WALLET, 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_ENABLED, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.DOZE_ALWAYS_ON, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.DOZE_ALWAYS_ON, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.DOZE_PICK_UP_GESTURE, 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.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
@@ -89,7 +88,6 @@ public class KeyguardClockSwitch extends RelativeLayout {
private int mClockSwitchYAmount; private int mClockSwitchYAmount;
@VisibleForTesting boolean mChildrenAreLaidOut = false; @VisibleForTesting boolean mChildrenAreLaidOut = false;
private OnPreDrawListener mPreDrawListener;
public KeyguardClockSwitch(Context context, AttributeSet attrs) { public KeyguardClockSwitch(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
@@ -284,30 +282,21 @@ public class KeyguardClockSwitch extends RelativeLayout {
// translate them properly // translate them properly
if (mChildrenAreLaidOut) { if (mChildrenAreLaidOut) {
animateClockChange(clockSize == LARGE); 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; return true;
} }
@Override @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) { protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b); super.onLayout(changed, l, t, r, b);
mChildrenAreLaidOut = true;
if (mDisplayedClockSize != null && !mChildrenAreLaidOut) {
animateClockChange(mDisplayedClockSize == LARGE);
} }
void onViewDetached() { mChildrenAreLaidOut = true;
if (mPreDrawListener != null) {
getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener);
mPreDrawListener = null;
}
} }
public Paint getPaint() { public Paint getPaint() {
@@ -368,5 +357,6 @@ public class KeyguardClockSwitch extends RelativeLayout {
pw.println(" mDarkAmount: " + mDarkAmount); pw.println(" mDarkAmount: " + mDarkAmount);
pw.println(" mSupportsDarkText: " + mSupportsDarkText); pw.println(" mSupportsDarkText: " + mSupportsDarkText);
pw.println(" mColorPalette: " + Arrays.toString(mColorPalette)); 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.app.WallpaperManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.ContentObserver;
import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.phone.NotificationIconContainer;
import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.util.ViewController; import com.android.systemui.util.ViewController;
import com.android.systemui.util.settings.SecureSettings;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.concurrent.Executor;
import javax.inject.Inject; import javax.inject.Inject;
@@ -72,6 +76,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
private final BatteryController mBatteryController; private final BatteryController mBatteryController;
private final LockscreenSmartspaceController mSmartspaceController; private final LockscreenSmartspaceController mSmartspaceController;
private final Resources mResources; private final Resources mResources;
private final SecureSettings mSecureSettings;
/** /**
* Clock for both small and large sizes * Clock for both small and large sizes
@@ -109,6 +114,14 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
private SmartspaceTransitionController mSmartspaceTransitionController; private SmartspaceTransitionController mSmartspaceTransitionController;
private boolean mOnlyClock = false; 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 @Inject
public KeyguardClockSwitchController( public KeyguardClockSwitchController(
@@ -125,6 +138,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
LockscreenSmartspaceController smartspaceController, LockscreenSmartspaceController smartspaceController,
KeyguardUnlockAnimationController keyguardUnlockAnimationController, KeyguardUnlockAnimationController keyguardUnlockAnimationController,
SmartspaceTransitionController smartspaceTransitionController, SmartspaceTransitionController smartspaceTransitionController,
SecureSettings secureSettings,
@Main Executor uiExecutor,
@Main Resources resources) { @Main Resources resources) {
super(keyguardClockSwitch); super(keyguardClockSwitch);
mStatusBarStateController = statusBarStateController; mStatusBarStateController = statusBarStateController;
@@ -138,7 +153,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
mBypassController = bypassController; mBypassController = bypassController;
mSmartspaceController = smartspaceController; mSmartspaceController = smartspaceController;
mResources = resources; mResources = resources;
mSecureSettings = secureSettings;
mUiExecutor = uiExecutor;
mKeyguardUnlockAnimationController = keyguardUnlockAnimationController; mKeyguardUnlockAnimationController = keyguardUnlockAnimationController;
mSmartspaceTransitionController = smartspaceTransitionController; mSmartspaceTransitionController = smartspaceTransitionController;
} }
@@ -223,6 +239,14 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
updateClockLayout(); updateClockLayout();
mSmartspaceTransitionController.setLockscreenSmartspace(mSmartspaceView); mSmartspaceTransitionController.setLockscreenSmartspace(mSmartspaceView);
} }
mSecureSettings.registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK),
false, /* notifyForDescendants */
mDoubleLineClockObserver
);
updateDoubleLineClock();
} }
int getNotificationIconAreaHeight() { int getNotificationIconAreaHeight() {
@@ -236,7 +260,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
} }
mColorExtractor.removeOnColorsChangedListener(mColorsListener); mColorExtractor.removeOnColorsChangedListener(mColorsListener);
mView.setClockPlugin(null, mStatusBarStateController.getState()); mView.setClockPlugin(null, mStatusBarStateController.getState());
mView.onViewDetached();
mSecureSettings.unregisterContentObserver(mDoubleLineClockObserver);
} }
/** /**
@@ -268,6 +293,10 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
* hidden. * hidden.
*/ */
public void displayClock(@KeyguardClockSwitch.ClockSize int clockSize) { public void displayClock(@KeyguardClockSwitch.ClockSize int clockSize) {
if (!mCanShowDoubleLineClock && clockSize == KeyguardClockSwitch.LARGE) {
return;
}
boolean appeared = mView.switchToClock(clockSize); boolean appeared = mView.switchToClock(clockSize);
if (appeared && clockSize == LARGE) { if (appeared && clockSize == LARGE) {
mLargeClockViewController.animateAppear(); mLargeClockViewController.animateAppear();
@@ -410,4 +439,13 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
private int getCurrentLayoutDirection() { private int getCurrentLayoutDirection() {
return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()); 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.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.ContentObserver;
import android.net.Uri;
import android.provider.Settings;
import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; 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.NotificationIconAreaController;
import com.android.systemui.statusbar.phone.NotificationIconContainer; import com.android.systemui.statusbar.phone.NotificationIconContainer;
import com.android.systemui.statusbar.policy.BatteryController; 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.Before;
import org.junit.Test; import org.junit.Test;
@@ -104,11 +112,14 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
private AnimatableClockView mLargeClockView; private AnimatableClockView mLargeClockView;
@Mock @Mock
private FrameLayout mLargeClockFrame; private FrameLayout mLargeClockFrame;
@Mock
private SecureSettings mSecureSettings;
private final View mFakeSmartspaceView = new View(mContext); private final View mFakeSmartspaceView = new View(mContext);
private KeyguardClockSwitchController mController; private KeyguardClockSwitchController mController;
private View mSliceView; private View mSliceView;
private FakeExecutor mExecutor;
@Before @Before
public void setup() { public void setup() {
@@ -129,6 +140,7 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
when(mView.isAttachedToWindow()).thenReturn(true); when(mView.isAttachedToWindow()).thenReturn(true);
when(mSmartspaceController.buildAndConnectView(any())).thenReturn(mFakeSmartspaceView); when(mSmartspaceController.buildAndConnectView(any())).thenReturn(mFakeSmartspaceView);
mExecutor = new FakeExecutor(new FakeSystemClock());
mController = new KeyguardClockSwitchController( mController = new KeyguardClockSwitchController(
mView, mView,
mStatusBarStateController, mStatusBarStateController,
@@ -143,6 +155,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
mSmartspaceController, mSmartspaceController,
mKeyguardUnlockAnimationController, mKeyguardUnlockAnimationController,
mSmartSpaceTransitionController, mSmartSpaceTransitionController,
mSecureSettings,
mExecutor,
mResources mResources
); );
@@ -194,7 +208,6 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
verifyAttachment(times(1)); verifyAttachment(times(1));
listenerArgumentCaptor.getValue().onViewDetachedFromWindow(mView); listenerArgumentCaptor.getValue().onViewDetachedFromWindow(mView);
verify(mView).onViewDetached();
verify(mColorExtractor).removeOnColorsChangedListener( verify(mColorExtractor).removeOnColorsChangedListener(
any(ColorExtractor.OnColorsChangedListener.class)); any(ColorExtractor.OnColorsChangedListener.class));
} }
@@ -235,6 +248,25 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
verify(mSmartspaceController).requestSmartspaceUpdate(); 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) { private void verifyAttachment(VerificationMode times) {
verify(mClockManager, times).addOnClockChangedListener( verify(mClockManager, times).addOnClockChangedListener(
any(ClockManager.ClockChangedListener.class)); any(ClockManager.ClockChangedListener.class));