diff --git a/services/core/java/com/android/server/timedetector/ServerFlags.java b/services/core/java/com/android/server/timedetector/ServerFlags.java index fe977f8b39217..ac2d76e89d762 100644 --- a/services/core/java/com/android/server/timedetector/ServerFlags.java +++ b/services/core/java/com/android/server/timedetector/ServerFlags.java @@ -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") diff --git a/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java b/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java index ff5060e6618e8..acabb6e393a80 100644 --- a/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java +++ b/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java @@ -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); diff --git a/services/core/java/com/android/server/timezonedetector/MetricsTimeZoneDetectorState.java b/services/core/java/com/android/server/timezonedetector/MetricsTimeZoneDetectorState.java index 27b50d8921441..9eb6a458e8e32 100644 --- a/services/core/java/com/android/server/timezonedetector/MetricsTimeZoneDetectorState.java +++ b/services/core/java/com/android/server/timezonedetector/MetricsTimeZoneDetectorState.java @@ -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()) { diff --git a/services/core/java/com/android/server/timezonedetector/OrdinalGenerator.java b/services/core/java/com/android/server/timezonedetector/OrdinalGenerator.java index 50875308db7de..dfefb8fc83354 100644 --- a/services/core/java/com/android/server/timezonedetector/OrdinalGenerator.java +++ b/services/core/java/com/android/server/timezonedetector/OrdinalGenerator.java @@ -33,7 +33,7 @@ import java.util.function.Function; class OrdinalGenerator { private final ArraySet mKnownIds = new ArraySet<>(); - private final @NonNull Function mCanonicalizationFunction; + @NonNull private final Function mCanonicalizationFunction; OrdinalGenerator(@NonNull Function canonicalizationFunction) { mCanonicalizationFunction = Objects.requireNonNull(canonicalizationFunction); diff --git a/services/core/java/com/android/server/timezonedetector/ServiceConfigAccessor.java b/services/core/java/com/android/server/timezonedetector/ServiceConfigAccessor.java index 23f6bbe481723..2be8e355b0161 100644 --- a/services/core/java/com/android/server/timezonedetector/ServiceConfigAccessor.java +++ b/services/core/java/com/android/server/timezonedetector/ServiceConfigAccessor.java @@ -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 {} /** diff --git a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProvider.java b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProvider.java index c2add2d85d260..c0fd6b1d79fad 100644 --- a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProvider.java +++ b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProvider.java @@ -48,6 +48,10 @@ import com.android.server.timezonedetector.ReferenceWithHistory; import com.android.server.timezonedetector.location.LocationTimeZoneProvider.ProviderState.ProviderStateEnum; import com.android.server.timezonedetector.location.ThreadingDomain.SingleRunnableQueue; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -101,34 +105,36 @@ abstract class LocationTimeZoneProvider implements Dumpable { value = { PROVIDER_STATE_UNKNOWN, PROVIDER_STATE_STARTED_INITIALIZING, PROVIDER_STATE_STARTED_CERTAIN, PROVIDER_STATE_STARTED_UNCERTAIN, PROVIDER_STATE_STOPPED, PROVIDER_STATE_PERM_FAILED, PROVIDER_STATE_DESTROYED }) + @Retention(RetentionPolicy.SOURCE) + @Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER }) @interface ProviderStateEnum {} /** * Uninitialized value. Must not be used afte {@link LocationTimeZoneProvider#initialize}. */ - static final int PROVIDER_STATE_UNKNOWN = 0; + static final @ProviderStateEnum int PROVIDER_STATE_UNKNOWN = 0; /** * The provider is started and has not reported its first event. */ - static final int PROVIDER_STATE_STARTED_INITIALIZING = 1; + static final @ProviderStateEnum int PROVIDER_STATE_STARTED_INITIALIZING = 1; /** * The provider is started and most recently reported a "suggestion" event. */ - static final int PROVIDER_STATE_STARTED_CERTAIN = 2; + static final @ProviderStateEnum int PROVIDER_STATE_STARTED_CERTAIN = 2; /** * The provider is started and most recently reported an "uncertain" event. */ - static final int PROVIDER_STATE_STARTED_UNCERTAIN = 3; + static final @ProviderStateEnum int PROVIDER_STATE_STARTED_UNCERTAIN = 3; /** * The provider is stopped. * * This is the state after {@link #initialize} is called. */ - static final int PROVIDER_STATE_STOPPED = 4; + static final @ProviderStateEnum int PROVIDER_STATE_STOPPED = 4; /** * The provider has failed and cannot be restarted. This is a terminated state triggered by @@ -136,16 +142,16 @@ abstract class LocationTimeZoneProvider implements Dumpable { * * Providers may enter this state any time after a provider is started. */ - static final int PROVIDER_STATE_PERM_FAILED = 5; + static final @ProviderStateEnum int PROVIDER_STATE_PERM_FAILED = 5; /** * The provider has been destroyed by the controller and cannot be restarted. Similar to * {@link #PROVIDER_STATE_PERM_FAILED} except that a provider is set into this state. */ - static final int PROVIDER_STATE_DESTROYED = 6; + static final @ProviderStateEnum int PROVIDER_STATE_DESTROYED = 6; /** The {@link LocationTimeZoneProvider} the state is for. */ - public final @NonNull LocationTimeZoneProvider provider; + @NonNull public final LocationTimeZoneProvider provider; /** The state enum value of the current state. */ public final @ProviderStateEnum int stateEnum; diff --git a/services/core/java/com/android/server/timezonedetector/location/TimeZoneProviderEvent.java b/services/core/java/com/android/server/timezonedetector/location/TimeZoneProviderEvent.java index 3e224e03fda01..7648795763caf 100644 --- a/services/core/java/com/android/server/timezonedetector/location/TimeZoneProviderEvent.java +++ b/services/core/java/com/android/server/timezonedetector/location/TimeZoneProviderEvent.java @@ -22,6 +22,10 @@ import android.annotation.Nullable; import android.service.timezone.TimeZoneProviderService; import android.service.timezone.TimeZoneProviderSuggestion; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.Objects; /** @@ -31,31 +35,32 @@ final class TimeZoneProviderEvent { @IntDef(prefix = "EVENT_TYPE_", value = { EVENT_TYPE_PERMANENT_FAILURE, EVENT_TYPE_SUGGESTION, EVENT_TYPE_UNCERTAIN }) + @Retention(RetentionPolicy.SOURCE) + @Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER }) public @interface EventType {} /** * The provider failed permanently. See {@link * TimeZoneProviderService#reportPermanentFailure(Throwable)} */ - public static final int EVENT_TYPE_PERMANENT_FAILURE = 1; + public static final @EventType int EVENT_TYPE_PERMANENT_FAILURE = 1; /** * The provider made a suggestion. See {@link * TimeZoneProviderService#reportSuggestion(TimeZoneProviderSuggestion)} */ - public static final int EVENT_TYPE_SUGGESTION = 2; + public static final @EventType int EVENT_TYPE_SUGGESTION = 2; /** * The provider was uncertain about the time zone. See {@link * TimeZoneProviderService#reportUncertain()} */ - public static final int EVENT_TYPE_UNCERTAIN = 3; + public static final @EventType int EVENT_TYPE_UNCERTAIN = 3; private static final TimeZoneProviderEvent UNCERTAIN_EVENT = new TimeZoneProviderEvent(EVENT_TYPE_UNCERTAIN, null, null); - @EventType - private final int mType; + private final @EventType int mType; @Nullable private final TimeZoneProviderSuggestion mSuggestion;