From 38eba47271329c6f6ff706124160763d10d6b94d Mon Sep 17 00:00:00 2001 From: Stevie Kideckel Date: Wed, 16 Jun 2021 16:34:39 +0000 Subject: [PATCH] Add a config value for the default of the analog clock flag Also, handle this config value being set to 0 by hiding the seconds hand and ticking once per minute. Bug: 191269485 Test: locally Change-Id: Ib2b705437d570d46328174d618ec0de6193212ca --- core/java/android/widget/AnalogClock.java | 13 ++++++---- core/java/android/widget/WidgetFlags.java | 3 --- core/res/res/values/config.xml | 4 ++++ core/res/res/values/symbols.xml | 1 + .../server/am/CoreSettingsObserver.java | 24 +++++++++++++++---- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/core/java/android/widget/AnalogClock.java b/core/java/android/widget/AnalogClock.java index d5966269a753a..9c1285064afb6 100644 --- a/core/java/android/widget/AnalogClock.java +++ b/core/java/android/widget/AnalogClock.java @@ -111,7 +111,9 @@ public class AnalogClock extends View { mSecondsHandFps = AppGlobals.getIntCoreSetting( WidgetFlags.KEY_ANALOG_CLOCK_SECONDS_HAND_FPS, - WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS_DEFAULT); + context.getResources() + .getInteger(com.android.internal.R.integer + .config_defaultAnalogClockSecondsHandFps)); final TypedArray a = context.obtainStyledAttributes( attrs, com.android.internal.R.styleable.AnalogClock, defStyleAttr, defStyleRes); @@ -720,7 +722,7 @@ public class AnalogClock extends View { canvas.restore(); final Drawable secondHand = mSecondHand; - if (secondHand != null) { + if (secondHand != null && mSecondsHandFps > 0) { canvas.save(); canvas.rotate(mSeconds / 60.0f * 360.0f, x, y); @@ -752,7 +754,10 @@ public class AnalogClock extends View { // n positions between two given numbers, where n is the number of ticks per second. This // ensures the second hand advances by a consistent distance despite our handler callbacks // occurring at inconsistent frequencies. - mSeconds = Math.round(rawSeconds * mSecondsHandFps) / (float) mSecondsHandFps; + mSeconds = + mSecondsHandFps <= 0 + ? rawSeconds + : Math.round(rawSeconds * mSecondsHandFps) / (float) mSecondsHandFps; mMinutes = localTime.getMinute() + mSeconds / 60.0f; mHour = localTime.getHour() + mMinutes / 60.0f; mChanged = true; @@ -789,7 +794,7 @@ public class AnalogClock extends View { LocalTime localTime = zonedDateTime.toLocalTime(); long millisUntilNextTick; - if (mSecondHand == null) { + if (mSecondHand == null || mSecondsHandFps <= 0) { // If there's no second hand, then tick at the start of the next minute. // // This must be done with ZonedDateTime as opposed to LocalDateTime to ensure proper diff --git a/core/java/android/widget/WidgetFlags.java b/core/java/android/widget/WidgetFlags.java index 097126807f711..fb40ee5ec8430 100644 --- a/core/java/android/widget/WidgetFlags.java +++ b/core/java/android/widget/WidgetFlags.java @@ -207,9 +207,6 @@ public final class WidgetFlags { public static final String KEY_ANALOG_CLOCK_SECONDS_HAND_FPS = "widget__analog_clock_seconds_hand_fps"; - /** Default value for the flag {@link #ANALOG_CLOCK_SECONDS_HAND_FPS}. */ - public static final int ANALOG_CLOCK_SECONDS_HAND_FPS_DEFAULT = 1; - private WidgetFlags() { } } diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 3c47366a59dba..cbdffce4567d5 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -5006,4 +5006,8 @@ 0.05 + + + 1 diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 97a2a38bdab82..3bf10f3bb5e54 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -489,6 +489,7 @@ + diff --git a/services/core/java/com/android/server/am/CoreSettingsObserver.java b/services/core/java/com/android/server/am/CoreSettingsObserver.java index b325ea3b21b34..5c9d38515e49f 100644 --- a/services/core/java/com/android/server/am/CoreSettingsObserver.java +++ b/services/core/java/com/android/server/am/CoreSettingsObserver.java @@ -27,6 +27,7 @@ import android.provider.DeviceConfig; import android.provider.Settings; import android.widget.WidgetFlags; +import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import java.util.ArrayList; @@ -159,12 +160,9 @@ final class CoreSettingsObserver extends ContentObserver { DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ASPECT_RATIO, WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class, WidgetFlags.MAGNIFIER_ASPECT_RATIO_DEFAULT)); - sDeviceConfigEntries.add(new DeviceConfigEntry<>( - DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS, - WidgetFlags.KEY_ANALOG_CLOCK_SECONDS_HAND_FPS, int.class, - WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS_DEFAULT)); // add other device configs here... } + private static volatile boolean sDeviceConfigContextEntriesLoaded = false; private final Bundle mCoreSettings = new Bundle(); @@ -172,11 +170,29 @@ final class CoreSettingsObserver extends ContentObserver { public CoreSettingsObserver(ActivityManagerService activityManagerService) { super(activityManagerService.mHandler); + + if (!sDeviceConfigContextEntriesLoaded) { + synchronized (sDeviceConfigEntries) { + if (!sDeviceConfigContextEntriesLoaded) { + loadDeviceConfigContextEntries(activityManagerService.mContext); + sDeviceConfigContextEntriesLoaded = true; + } + } + } + mActivityManagerService = activityManagerService; beginObserveCoreSettings(); sendCoreSettings(); } + private static void loadDeviceConfigContextEntries(Context context) { + sDeviceConfigEntries.add(new DeviceConfigEntry<>( + DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS, + WidgetFlags.KEY_ANALOG_CLOCK_SECONDS_HAND_FPS, int.class, + context.getResources() + .getInteger(R.integer.config_defaultAnalogClockSecondsHandFps))); + } + public Bundle getCoreSettingsLocked() { return (Bundle) mCoreSettings.clone(); }