summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2021-04-19 15:56:26 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-04-19 15:56:26 +0000
commitc277d49287100611c39b3a00a2feb9e900bd2e6f (patch)
treec62a9ce635f259a742f223ba9e0b90cd1a0863b7
parent0e47206b0a157159ec51b4b0739c4e4127507df1 (diff)
parent3c3c68eff8ee55b190dd6d172a033b30f2e4bb6b (diff)
Merge "Add server flag for the lower bound" into sc-dev
-rw-r--r--services/core/java/com/android/server/timedetector/ServerFlags.java31
-rw-r--r--services/core/java/com/android/server/timedetector/ServiceConfigAccessor.java6
-rw-r--r--services/core/java/com/android/server/timedetector/TimeDetectorShellCommand.java4
-rw-r--r--services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java4
4 files changed, 42 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/timedetector/ServerFlags.java b/services/core/java/com/android/server/timedetector/ServerFlags.java
index fda0e3cd947c..7145f5ea4a64 100644
--- a/services/core/java/com/android/server/timedetector/ServerFlags.java
+++ b/services/core/java/com/android/server/timedetector/ServerFlags.java
@@ -30,7 +30,9 @@ import com.android.server.timezonedetector.ServiceConfigAccessor;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.time.DateTimeException;
import java.time.Duration;
+import java.time.Instant;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@@ -62,6 +64,8 @@ public final class ServerFlags {
KEY_LOCATION_TIME_ZONE_DETECTION_UNCERTAINTY_DELAY_MILLIS,
KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE,
KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT,
+ KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE,
+ KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE,
})
@Retention(RetentionPolicy.SOURCE)
@interface DeviceConfigKey {}
@@ -144,6 +148,14 @@ public final class ServerFlags {
public static final String KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE =
"time_detector_origin_priorities_override";
+ /**
+ * The key to override the time detector lower bound configuration. The values is the number of
+ * milliseconds since the beginning of the Unix epoch.
+ */
+ @DeviceConfigKey
+ public static final String KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE =
+ "time_detector_lower_bound_millis_override";
+
@GuardedBy("mListeners")
private final ArrayMap<ConfigurationChangeListener, Set<String>> mListeners = new ArrayMap<>();
@@ -231,6 +243,25 @@ public final class ServerFlags {
}
/**
+ * Returns an {@link Instant} from {@link DeviceConfig} from the system_time
+ * namespace, returns the {@code defaultValue} if the value is missing or invalid.
+ */
+ @NonNull
+ public Optional<Instant> getOptionalInstant(@DeviceConfigKey String key) {
+ String value = DeviceConfig.getProperty(NAMESPACE_SYSTEM_TIME, key);
+ if (value == null) {
+ return Optional.empty();
+ }
+
+ try {
+ long millis = Long.parseLong(value);
+ return Optional.of(Instant.ofEpochMilli(millis));
+ } catch (DateTimeException | NumberFormatException e) {
+ return Optional.empty();
+ }
+ }
+
+ /**
* Returns an optional boolean value from {@link DeviceConfig} from the system_time
* namespace, returns {@link Optional#empty()} if there is no explicit value set.
*/
diff --git a/services/core/java/com/android/server/timedetector/ServiceConfigAccessor.java b/services/core/java/com/android/server/timedetector/ServiceConfigAccessor.java
index 381b77e5d1d2..dac8a0a78ede 100644
--- a/services/core/java/com/android/server/timedetector/ServiceConfigAccessor.java
+++ b/services/core/java/com/android/server/timedetector/ServiceConfigAccessor.java
@@ -15,6 +15,7 @@
*/
package com.android.server.timedetector;
+import static com.android.server.timedetector.ServerFlags.KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE;
import static com.android.server.timedetector.ServerFlags.KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE;
import static com.android.server.timedetector.TimeDetectorStrategy.ORIGIN_NETWORK;
import static com.android.server.timedetector.TimeDetectorStrategy.ORIGIN_TELEPHONY;
@@ -65,6 +66,7 @@ final class ServiceConfigAccessor {
private static final Set<String> SERVER_FLAGS_KEYS_TO_WATCH = Collections.unmodifiableSet(
new ArraySet<>(new String[] {
+ KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE,
KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE,
}));
@@ -137,8 +139,10 @@ final class ServiceConfigAccessor {
return mSystemClockUpdateThresholdMillis;
}
+ @NonNull
Instant autoTimeLowerBound() {
- return TIME_LOWER_BOUND_DEFAULT;
+ return mServerFlags.getOptionalInstant(KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE)
+ .orElse(TIME_LOWER_BOUND_DEFAULT);
}
/**
diff --git a/services/core/java/com/android/server/timedetector/TimeDetectorShellCommand.java b/services/core/java/com/android/server/timedetector/TimeDetectorShellCommand.java
index 3cb21aaf85ce..233cc57fd71b 100644
--- a/services/core/java/com/android/server/timedetector/TimeDetectorShellCommand.java
+++ b/services/core/java/com/android/server/timedetector/TimeDetectorShellCommand.java
@@ -18,6 +18,7 @@ package com.android.server.timedetector;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED;
import static android.provider.DeviceConfig.NAMESPACE_SYSTEM_TIME;
+import static com.android.server.timedetector.ServerFlags.KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE;
import static com.android.server.timedetector.ServerFlags.KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE;
import android.os.ShellCommand;
@@ -68,6 +69,9 @@ class TimeDetectorShellCommand extends ShellCommand {
pw.println();
pw.printf("This service is also affected by the following device_config flags in the"
+ " %s namespace:\n", NAMESPACE_SYSTEM_TIME);
+ pw.printf(" %s - the lower bound used to validate time suggestions when they are"
+ + " received.\n", KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE);
+ pw.println(" Specified in milliseconds since the start of the Unix epoch.");
pw.printf(" %s - [default=null], a comma separated list of origins. See"
+ " TimeDetectorStrategy for details\n",
KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE);
diff --git a/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java b/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java
index db8a59e0ab26..357c23222658 100644
--- a/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java
+++ b/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java
@@ -325,9 +325,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
ipw.println("mEnvironment.systemClockMillis()=" + mEnvironment.systemClockMillis());
ipw.println("mEnvironment.systemClockUpdateThresholdMillis()="
+ mEnvironment.systemClockUpdateThresholdMillis());
+ Instant autoTimeLowerBound = mEnvironment.autoTimeLowerBound();
ipw.printf("mEnvironment.autoTimeLowerBound()=%s(%s)\n",
- mEnvironment.autoTimeLowerBound(),
- mEnvironment.autoTimeLowerBound().toEpochMilli());
+ autoTimeLowerBound, autoTimeLowerBound.toEpochMilli());
String priorities =
Arrays.stream(mEnvironment.autoOriginPriorities())
.mapToObj(TimeDetectorStrategy::originToString)