Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32a4e9d2 authored by Neil Fuller's avatar Neil Fuller
Browse files

Tidy up annotations in timedetector, etc.

Platform annotations like @Nullable / @NonNull are not TYPE_USE
annotations. Move usages on fields to before access modifiers for
consistency.

@IntDef / @StringDef can apparently be TYPE_USE and TYPE_PARAMETER, so
switch to using them as such. Also fix retention policy at the same
time.

Bug: 165832200
Test: compiler only (treehugger)
Change-Id: I621ea50d09262807963a8a74c3838ff1b516bc26
parent 47c1c1ff
Loading
Loading
Loading
Loading
+20 −20
Original line number Diff line number Diff line
@@ -28,8 +28,10 @@ import com.android.internal.annotations.GuardedBy;
import com.android.server.timezonedetector.ConfigurationChangeListener;
import com.android.server.timezonedetector.ServiceConfigAccessor;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.time.DateTimeException;
import java.time.Duration;
import java.time.Instant;
@@ -63,6 +65,7 @@ public final class ServerFlags {
            KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE,
            KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE,
    })
    @Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER })
    @Retention(RetentionPolicy.SOURCE)
    @interface DeviceConfigKey {}

@@ -72,40 +75,39 @@ public final class ServerFlags {
     * {@link ServiceConfigAccessor#isGeoTimeZoneDetectionFeatureSupportedInConfig()} and {@link
     * ServiceConfigAccessor#isGeoTimeZoneDetectionFeatureSupported()}.
     */
    @DeviceConfigKey
    public static final String KEY_LOCATION_TIME_ZONE_DETECTION_FEATURE_SUPPORTED =
    public static final @DeviceConfigKey String KEY_LOCATION_TIME_ZONE_DETECTION_FEATURE_SUPPORTED =
            "location_time_zone_detection_feature_supported";

    /**
     * The key for the server flag that can override the device config for whether the primary
     * location time zone provider is enabled, disabled, or (for testing) in simulation mode.
     */
    @DeviceConfigKey
    public static final String KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE =
    public static final @DeviceConfigKey String
            KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE =
            "primary_location_time_zone_provider_mode_override";

    /**
     * The key for the server flag that can override the device config for whether the secondary
     * location time zone provider is enabled or disabled, or (for testing) in simulation mode.
     */
    @DeviceConfigKey
    public static final String KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE =
    public static final @DeviceConfigKey String
            KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE =
            "secondary_location_time_zone_provider_mode_override";

    /**
     * The key for the minimum delay after location time zone detection has been enabled before the
     * location time zone manager can report it is uncertain about the time zone.
     */
    @DeviceConfigKey
    public static final String KEY_LOCATION_TIME_ZONE_DETECTION_UNCERTAINTY_DELAY_MILLIS =
    public static final @DeviceConfigKey String
            KEY_LOCATION_TIME_ZONE_DETECTION_UNCERTAINTY_DELAY_MILLIS =
            "location_time_zone_detection_uncertainty_delay_millis";

    /**
     * The key for the timeout passed to a location time zone provider that tells it how long it has
     * to provide an explicit first suggestion without being declared uncertain.
     */
    @DeviceConfigKey
    public static final String KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_MILLIS =
    public static final @DeviceConfigKey String
            KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_MILLIS =
            "ltpz_init_timeout_millis";

    /**
@@ -113,8 +115,8 @@ public final class ServerFlags {
     * #KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_MILLIS} by the location time zone
     * manager before the location time zone provider will actually be declared uncertain.
     */
    @DeviceConfigKey
    public static final String KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_FUZZ_MILLIS =
    public static final @DeviceConfigKey String
            KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_FUZZ_MILLIS =
            "ltpz_init_timeout_fuzz_millis";

    /**
@@ -123,16 +125,16 @@ public final class ServerFlags {
     * disable the feature by turning off the master location switch, or by disabling automatic time
     * zone detection.
     */
    @DeviceConfigKey
    public static final String KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE =
    public static final @DeviceConfigKey String
            KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE =
            "location_time_zone_detection_setting_enabled_override";

    /**
     * The key for the default value used to determine whether location time zone detection is
     * enabled when the user hasn't explicitly set it yet.
     */
    @DeviceConfigKey
    public static final String KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT =
    public static final @DeviceConfigKey String
            KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT =
            "location_time_zone_detection_setting_enabled_default";

    /**
@@ -140,16 +142,14 @@ public final class ServerFlags {
     * of strings that will be passed to {@link TimeDetectorStrategy#stringToOrigin(String)}.
     * All values must be recognized or the override value will be ignored.
     */
    @DeviceConfigKey
    public static final String KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE =
    public static final @DeviceConfigKey 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 =
    public static final @DeviceConfigKey String KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE =
            "time_detector_lower_bound_millis_override";

    @GuardedBy("mListeners")
+5 −10
Original line number Diff line number Diff line
@@ -53,24 +53,19 @@ public interface TimeDetectorStrategy extends Dumpable {
    @interface Origin {}

    /** Used when a time value originated from a telephony signal. */
    @Origin
    int ORIGIN_TELEPHONY = 1;
    @Origin int ORIGIN_TELEPHONY = 1;

    /** Used when a time value originated from a user / manual settings. */
    @Origin
    int ORIGIN_MANUAL = 2;
    @Origin int ORIGIN_MANUAL = 2;

    /** Used when a time value originated from a network signal. */
    @Origin
    int ORIGIN_NETWORK = 3;
    @Origin int ORIGIN_NETWORK = 3;

    /** Used when a time value originated from a gnss signal. */
    @Origin
    int ORIGIN_GNSS = 4;
    @Origin int ORIGIN_GNSS = 4;

    /** Used when a time value originated from an externally specified signal. */
    @Origin
    int ORIGIN_EXTERNAL = 5;
    @Origin int ORIGIN_EXTERNAL = 5;

    /** Processes the suggested time from telephony sources. */
    void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion);
+10 −8
Original line number Diff line number Diff line
@@ -26,6 +26,10 @@ import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
import android.util.proto.ProtoOutputStream;

import java.io.ByteArrayOutputStream;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@@ -44,14 +48,13 @@ public final class MetricsTimeZoneDetectorState {

    @IntDef(prefix = "DETECTION_MODE_",
            value = { DETECTION_MODE_MANUAL, DETECTION_MODE_GEO, DETECTION_MODE_TELEPHONY})
    @Retention(RetentionPolicy.SOURCE)
    @Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER })
    @interface DetectionMode {};

    @DetectionMode
    public static final int DETECTION_MODE_MANUAL = 0;
    @DetectionMode
    public static final int DETECTION_MODE_GEO = 1;
    @DetectionMode
    public static final int DETECTION_MODE_TELEPHONY = 2;
    public static final @DetectionMode int DETECTION_MODE_MANUAL = 0;
    public static final @DetectionMode int DETECTION_MODE_GEO = 1;
    public static final @DetectionMode int DETECTION_MODE_TELEPHONY = 2;

    @NonNull
    private final ConfigurationInternal mConfigurationInternal;
@@ -132,8 +135,7 @@ public final class MetricsTimeZoneDetectorState {
     * Returns the detection mode the device is currently using, which can be influenced by various
     * things besides the user's setting.
     */
    @DetectionMode
    public int getDetectionMode() {
    public @DetectionMode int getDetectionMode() {
        if (!mConfigurationInternal.getAutoDetectionEnabledBehavior()) {
            return DETECTION_MODE_MANUAL;
        } else if (mConfigurationInternal.getGeoDetectionEnabledBehavior()) {
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import java.util.function.Function;
class OrdinalGenerator<T> {
    private final ArraySet<T> mKnownIds = new ArraySet<>();

    private final @NonNull Function<T, T> mCanonicalizationFunction;
    @NonNull private final Function<T, T> mCanonicalizationFunction;

    OrdinalGenerator(@NonNull Function<T, T> canonicalizationFunction) {
        mCanonicalizationFunction = Objects.requireNonNull(canonicalizationFunction);
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ public final class ServiceConfigAccessor {
    @StringDef(prefix = "PROVIDER_MODE_",
            value = { PROVIDER_MODE_SIMULATED, PROVIDER_MODE_DISABLED, PROVIDER_MODE_ENABLED})
    @Retention(RetentionPolicy.SOURCE)
    @Target(ElementType.TYPE_USE)
    @Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER })
    @interface ProviderMode {}

    /**
Loading