Loading core/java/android/app/time/LocationTimeZoneManager.java +0 −25 Original line number Diff line number Diff line Loading @@ -49,31 +49,6 @@ public final class LocationTimeZoneManager { */ public static final String SHELL_COMMAND_STOP = "stop"; /** * A shell command that can put providers into different modes. Takes effect next time the * service is started. */ public static final String SHELL_COMMAND_SET_PROVIDER_MODE_OVERRIDE = "set_provider_mode_override"; /** * The default provider mode. * For use with {@link #SHELL_COMMAND_SET_PROVIDER_MODE_OVERRIDE}. */ public static final String PROVIDER_MODE_OVERRIDE_NONE = "none"; /** * The "simulated" provider mode. * For use with {@link #SHELL_COMMAND_SET_PROVIDER_MODE_OVERRIDE}. */ public static final String PROVIDER_MODE_OVERRIDE_SIMULATED = "simulated"; /** * The "disabled" provider mode (equivalent to there being no provider configured). * For use with {@link #SHELL_COMMAND_SET_PROVIDER_MODE_OVERRIDE}. */ public static final String PROVIDER_MODE_OVERRIDE_DISABLED = "disabled"; /** * A shell command that tells the service to record state information during tests. The next * argument value is "true" or "false". Loading core/res/res/values/config.xml +8 −18 Original line number Diff line number Diff line Loading @@ -1637,32 +1637,22 @@ config_timeZoneRulesUpdateTrackingEnabled are true.] --> <integer name="config_timeZoneRulesCheckRetryCount">5</integer> <!-- Whether the geolocation time zone detection feature is enabled. --> <!-- Whether the geolocation time zone detection feature is enabled. Setting this to false means the feature cannot be used. Setting this to true means it may be used if other configuration allows (see provider configuration below, also compile time overlays). --> <bool name="config_enableGeolocationTimeZoneDetection" translatable="false">true</bool> <!-- Whether the primary LocationTimeZoneProvider is enabled device. <!-- Whether the primary LocationTimeZoneProvider is enabled. Ignored if config_enableGeolocationTimeZoneDetection is false --> <bool name="config_enablePrimaryLocationTimeZoneProvider" translatable="false">false</bool> <!-- Used when enablePrimaryLocationTimeZoneProvider is true. Controls whether to enable primary location time zone provider overlay which allows the primary location time zone provider to be replaced by an app at run-time. When disabled, only the config_primaryLocationTimeZoneProviderPackageName package will be searched for the primary location time zone provider, otherwise any system package is eligible. Anyone who wants to disable the runtime overlay mechanism can set it to false. --> <bool name="config_enablePrimaryLocationTimeZoneOverlay" translatable="false">false</bool> <!-- Package name providing the primary location time zone provider. Used only when config_enablePrimaryLocationTimeZoneOverlay is false. --> <!-- The package name providing the primary location time zone provider. Only used when config_enableGeolocationTimeZoneDetection and enablePrimaryLocationTimeZoneProvider are true. --> <string name="config_primaryLocationTimeZoneProviderPackageName" translatable="false">@null</string> <!-- Whether the secondary LocationTimeZoneProvider is enabled device. <!-- Whether the secondary LocationTimeZoneProvider is enabled. Ignored if config_enableGeolocationTimeZoneDetection is false --> <bool name="config_enableSecondaryLocationTimeZoneProvider" translatable="false">true</bool> <!-- Used when enableSecondaryLocationTimeZoneProvider is true. Controls whether to enable secondary location time zone provider overlay which allows the primary location time zone provider to config_secondaryLocationTimeZoneProviderPackageName package will be searched for the secondary location time zone provider, otherwise any system package is eligible. Anyone who wants to disable the runtime overlay mechanism can set it to false. --> <bool name="config_enableSecondaryLocationTimeZoneOverlay" translatable="false">false</bool> <!-- Package name providing the secondary location time zone provider. Used only when config_enableSecondaryLocationTimeZoneOverlay is false. Loading core/res/res/values/symbols.xml +0 −2 Original line number Diff line number Diff line Loading @@ -2180,10 +2180,8 @@ <java-symbol type="bool" name="config_enableGnssTimeUpdateService" /> <java-symbol type="bool" name="config_enableGeolocationTimeZoneDetection" /> <java-symbol type="bool" name="config_enablePrimaryLocationTimeZoneProvider" /> <java-symbol type="bool" name="config_enablePrimaryLocationTimeZoneOverlay" /> <java-symbol type="string" name="config_primaryLocationTimeZoneProviderPackageName" /> <java-symbol type="bool" name="config_enableSecondaryLocationTimeZoneProvider" /> <java-symbol type="bool" name="config_enableSecondaryLocationTimeZoneOverlay" /> <java-symbol type="string" name="config_secondaryLocationTimeZoneProviderPackageName" /> <java-symbol type="layout" name="resolver_list" /> Loading services/core/java/com/android/server/timedetector/ServerFlags.java +21 −8 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ import com.android.internal.annotations.GuardedBy; import com.android.server.timezonedetector.ConfigurationChangeListener; import com.android.server.timezonedetector.ServiceConfigAccessor; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.time.Duration; import java.util.Map; import java.util.Objects; Loading @@ -53,14 +55,15 @@ public final class ServerFlags { */ @StringDef(prefix = "KEY_", value = { KEY_LOCATION_TIME_ZONE_DETECTION_FEATURE_SUPPORTED, KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE, KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE, KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE, KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE, KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_FUZZ_MILLIS, KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_MILLIS, KEY_LOCATION_TIME_ZONE_DETECTION_UNCERTAINTY_DELAY_MILLIS, KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE, KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT, }) @Retention(RetentionPolicy.SOURCE) @interface DeviceConfigKey {} /** Loading @@ -75,19 +78,19 @@ public final class ServerFlags { /** * The key for the server flag that can override the device config for whether the primary * location time zone provider is enabled or disabled. * location time zone provider is enabled, disabled, or (for testing) in simulation mode. */ @DeviceConfigKey public static final String KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE = "primary_location_time_zone_provider_enabled_override"; public static final 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. * 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_ENABLED_OVERRIDE = "secondary_location_time_zone_provider_enabled_override"; public static final 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 Loading Loading @@ -195,6 +198,16 @@ public final class ServerFlags { } } /** * Returns an optional string value from {@link DeviceConfig} from the system_time * namespace, returns {@link Optional#empty()} if there is no explicit value set. */ @NonNull public Optional<String> getOptionalString(@DeviceConfigKey String key) { String value = DeviceConfig.getProperty(NAMESPACE_SYSTEM_TIME, key); return Optional.ofNullable(value); } /** * Returns an optional boolean value from {@link DeviceConfig} from the system_time * namespace, returns {@link Optional#empty()} if there is no explicit value set. Loading services/core/java/com/android/server/timezonedetector/ServiceConfigAccessor.java +79 −28 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.timezonedetector; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.StringDef; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; Loading @@ -27,6 +28,10 @@ import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.server.timedetector.ServerFlags; 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.Collections; import java.util.Objects; Loading @@ -40,13 +45,38 @@ import java.util.Set; */ 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) @interface ProviderMode {} /** * The "simulated" provider mode. * For use with {@link #getPrimaryLocationTimeZoneProviderMode()} and {@link * #getSecondaryLocationTimeZoneProviderMode()}. */ public static final @ProviderMode String PROVIDER_MODE_SIMULATED = "simulated"; /** * The "disabled" provider mode. For use with {@link #getPrimaryLocationTimeZoneProviderMode()} * and {@link #getSecondaryLocationTimeZoneProviderMode()}. */ public static final @ProviderMode String PROVIDER_MODE_DISABLED = "disabled"; /** * The "enabled" provider mode. For use with {@link #getPrimaryLocationTimeZoneProviderMode()} * and {@link #getSecondaryLocationTimeZoneProviderMode()}. */ public static final @ProviderMode String PROVIDER_MODE_ENABLED = "enabled"; private static final Set<String> SERVER_FLAGS_KEYS_TO_WATCH = Collections.unmodifiableSet( new ArraySet<>(new String[] { ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_FEATURE_SUPPORTED, ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT, ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE, ServerFlags.KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE, ServerFlags.KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE, ServerFlags.KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE, ServerFlags.KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE, ServerFlags.KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_MILLIS, ServerFlags.KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_FUZZ_MILLIS, ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_UNCERTAINTY_DELAY_MILLIS Loading Loading @@ -139,14 +169,28 @@ public final class ServiceConfigAccessor { /** * Returns {@code true} if the location-based time zone detection feature is supported on the * device. This can be used during feature testing on builds that are capable of location time * zone detection to enable / disable the feature for some users. * device. */ public boolean isGeoTimeZoneDetectionFeatureSupported() { // For the feature to be enabled it must: // 1) Be turned on in config. // 2) Not be turned off via a server flag. // 3) There must be at least one location time zone provider enabled / configured. return mGeoDetectionFeatureSupportedInConfig && isGeoTimeZoneDetectionFeatureSupportedInternal(); && isGeoTimeZoneDetectionFeatureSupportedInternal() && atLeastOneProviderIsEnabled(); } private boolean atLeastOneProviderIsEnabled() { return !(Objects.equals(getPrimaryLocationTimeZoneProviderMode(), PROVIDER_MODE_DISABLED) && Objects.equals(getSecondaryLocationTimeZoneProviderMode(), PROVIDER_MODE_DISABLED)); } /** * Returns {@code true} if the location-based time zone detection feature is not explicitly * disabled by a server flag. */ private boolean isGeoTimeZoneDetectionFeatureSupportedInternal() { final boolean defaultEnabled = true; return mServerFlags.getBoolean( Loading @@ -154,42 +198,49 @@ public final class ServiceConfigAccessor { defaultEnabled); } @NonNull public String getPrimaryLocationTimeZoneProviderPackageName() { return mContext.getResources().getString( R.string.config_primaryLocationTimeZoneProviderPackageName); } @NonNull public String getSecondaryLocationTimeZoneProviderPackageName() { return mContext.getResources().getString( R.string.config_secondaryLocationTimeZoneProviderPackageName); } /** * Returns {@code true} if the primary location time zone provider can be used. */ public boolean isPrimaryLocationTimeZoneProviderEnabled() { return getPrimaryLocationTimeZoneProviderEnabledOverride() .orElse(isPrimaryLocationTimeZoneProviderEnabledInConfig()); } private boolean isPrimaryLocationTimeZoneProviderEnabledInConfig() { int providerEnabledConfigId = R.bool.config_enablePrimaryLocationTimeZoneProvider; return getConfigBoolean(providerEnabledConfigId); @NonNull public @ProviderMode String getPrimaryLocationTimeZoneProviderMode() { return mServerFlags.getOptionalString( ServerFlags.KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE) .orElse(getPrimaryLocationTimeZoneProviderModeFromConfig()); } @NonNull private Optional<Boolean> getPrimaryLocationTimeZoneProviderEnabledOverride() { return mServerFlags.getOptionalBoolean( ServerFlags.KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE); private @ProviderMode String getPrimaryLocationTimeZoneProviderModeFromConfig() { int providerEnabledConfigId = R.bool.config_enablePrimaryLocationTimeZoneProvider; return getConfigBoolean(providerEnabledConfigId) ? PROVIDER_MODE_ENABLED : PROVIDER_MODE_DISABLED; } /** * Returns {@code true} if the secondary location time zone provider can be used. * Returns the mode for the secondary location time zone provider can be used. */ public boolean isSecondaryLocationTimeZoneProviderEnabled() { return getSecondaryLocationTimeZoneProviderEnabledOverride() .orElse(isSecondaryLocationTimeZoneProviderEnabledInConfig()); } private boolean isSecondaryLocationTimeZoneProviderEnabledInConfig() { int providerEnabledConfigId = R.bool.config_enableSecondaryLocationTimeZoneProvider; return getConfigBoolean(providerEnabledConfigId); public @ProviderMode String getSecondaryLocationTimeZoneProviderMode() { return mServerFlags.getOptionalString( ServerFlags.KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE) .orElse(getSecondaryLocationTimeZoneProviderModeFromConfig()); } @NonNull private Optional<Boolean> getSecondaryLocationTimeZoneProviderEnabledOverride() { return mServerFlags.getOptionalBoolean( ServerFlags.KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE); private @ProviderMode String getSecondaryLocationTimeZoneProviderModeFromConfig() { int providerEnabledConfigId = R.bool.config_enableSecondaryLocationTimeZoneProvider; return getConfigBoolean(providerEnabledConfigId) ? PROVIDER_MODE_ENABLED : PROVIDER_MODE_DISABLED; } /** Loading Loading
core/java/android/app/time/LocationTimeZoneManager.java +0 −25 Original line number Diff line number Diff line Loading @@ -49,31 +49,6 @@ public final class LocationTimeZoneManager { */ public static final String SHELL_COMMAND_STOP = "stop"; /** * A shell command that can put providers into different modes. Takes effect next time the * service is started. */ public static final String SHELL_COMMAND_SET_PROVIDER_MODE_OVERRIDE = "set_provider_mode_override"; /** * The default provider mode. * For use with {@link #SHELL_COMMAND_SET_PROVIDER_MODE_OVERRIDE}. */ public static final String PROVIDER_MODE_OVERRIDE_NONE = "none"; /** * The "simulated" provider mode. * For use with {@link #SHELL_COMMAND_SET_PROVIDER_MODE_OVERRIDE}. */ public static final String PROVIDER_MODE_OVERRIDE_SIMULATED = "simulated"; /** * The "disabled" provider mode (equivalent to there being no provider configured). * For use with {@link #SHELL_COMMAND_SET_PROVIDER_MODE_OVERRIDE}. */ public static final String PROVIDER_MODE_OVERRIDE_DISABLED = "disabled"; /** * A shell command that tells the service to record state information during tests. The next * argument value is "true" or "false". Loading
core/res/res/values/config.xml +8 −18 Original line number Diff line number Diff line Loading @@ -1637,32 +1637,22 @@ config_timeZoneRulesUpdateTrackingEnabled are true.] --> <integer name="config_timeZoneRulesCheckRetryCount">5</integer> <!-- Whether the geolocation time zone detection feature is enabled. --> <!-- Whether the geolocation time zone detection feature is enabled. Setting this to false means the feature cannot be used. Setting this to true means it may be used if other configuration allows (see provider configuration below, also compile time overlays). --> <bool name="config_enableGeolocationTimeZoneDetection" translatable="false">true</bool> <!-- Whether the primary LocationTimeZoneProvider is enabled device. <!-- Whether the primary LocationTimeZoneProvider is enabled. Ignored if config_enableGeolocationTimeZoneDetection is false --> <bool name="config_enablePrimaryLocationTimeZoneProvider" translatable="false">false</bool> <!-- Used when enablePrimaryLocationTimeZoneProvider is true. Controls whether to enable primary location time zone provider overlay which allows the primary location time zone provider to be replaced by an app at run-time. When disabled, only the config_primaryLocationTimeZoneProviderPackageName package will be searched for the primary location time zone provider, otherwise any system package is eligible. Anyone who wants to disable the runtime overlay mechanism can set it to false. --> <bool name="config_enablePrimaryLocationTimeZoneOverlay" translatable="false">false</bool> <!-- Package name providing the primary location time zone provider. Used only when config_enablePrimaryLocationTimeZoneOverlay is false. --> <!-- The package name providing the primary location time zone provider. Only used when config_enableGeolocationTimeZoneDetection and enablePrimaryLocationTimeZoneProvider are true. --> <string name="config_primaryLocationTimeZoneProviderPackageName" translatable="false">@null</string> <!-- Whether the secondary LocationTimeZoneProvider is enabled device. <!-- Whether the secondary LocationTimeZoneProvider is enabled. Ignored if config_enableGeolocationTimeZoneDetection is false --> <bool name="config_enableSecondaryLocationTimeZoneProvider" translatable="false">true</bool> <!-- Used when enableSecondaryLocationTimeZoneProvider is true. Controls whether to enable secondary location time zone provider overlay which allows the primary location time zone provider to config_secondaryLocationTimeZoneProviderPackageName package will be searched for the secondary location time zone provider, otherwise any system package is eligible. Anyone who wants to disable the runtime overlay mechanism can set it to false. --> <bool name="config_enableSecondaryLocationTimeZoneOverlay" translatable="false">false</bool> <!-- Package name providing the secondary location time zone provider. Used only when config_enableSecondaryLocationTimeZoneOverlay is false. Loading
core/res/res/values/symbols.xml +0 −2 Original line number Diff line number Diff line Loading @@ -2180,10 +2180,8 @@ <java-symbol type="bool" name="config_enableGnssTimeUpdateService" /> <java-symbol type="bool" name="config_enableGeolocationTimeZoneDetection" /> <java-symbol type="bool" name="config_enablePrimaryLocationTimeZoneProvider" /> <java-symbol type="bool" name="config_enablePrimaryLocationTimeZoneOverlay" /> <java-symbol type="string" name="config_primaryLocationTimeZoneProviderPackageName" /> <java-symbol type="bool" name="config_enableSecondaryLocationTimeZoneProvider" /> <java-symbol type="bool" name="config_enableSecondaryLocationTimeZoneOverlay" /> <java-symbol type="string" name="config_secondaryLocationTimeZoneProviderPackageName" /> <java-symbol type="layout" name="resolver_list" /> Loading
services/core/java/com/android/server/timedetector/ServerFlags.java +21 −8 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ import com.android.internal.annotations.GuardedBy; import com.android.server.timezonedetector.ConfigurationChangeListener; import com.android.server.timezonedetector.ServiceConfigAccessor; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.time.Duration; import java.util.Map; import java.util.Objects; Loading @@ -53,14 +55,15 @@ public final class ServerFlags { */ @StringDef(prefix = "KEY_", value = { KEY_LOCATION_TIME_ZONE_DETECTION_FEATURE_SUPPORTED, KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE, KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE, KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE, KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE, KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_FUZZ_MILLIS, KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_MILLIS, KEY_LOCATION_TIME_ZONE_DETECTION_UNCERTAINTY_DELAY_MILLIS, KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE, KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT, }) @Retention(RetentionPolicy.SOURCE) @interface DeviceConfigKey {} /** Loading @@ -75,19 +78,19 @@ public final class ServerFlags { /** * The key for the server flag that can override the device config for whether the primary * location time zone provider is enabled or disabled. * location time zone provider is enabled, disabled, or (for testing) in simulation mode. */ @DeviceConfigKey public static final String KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE = "primary_location_time_zone_provider_enabled_override"; public static final 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. * 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_ENABLED_OVERRIDE = "secondary_location_time_zone_provider_enabled_override"; public static final 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 Loading Loading @@ -195,6 +198,16 @@ public final class ServerFlags { } } /** * Returns an optional string value from {@link DeviceConfig} from the system_time * namespace, returns {@link Optional#empty()} if there is no explicit value set. */ @NonNull public Optional<String> getOptionalString(@DeviceConfigKey String key) { String value = DeviceConfig.getProperty(NAMESPACE_SYSTEM_TIME, key); return Optional.ofNullable(value); } /** * Returns an optional boolean value from {@link DeviceConfig} from the system_time * namespace, returns {@link Optional#empty()} if there is no explicit value set. Loading
services/core/java/com/android/server/timezonedetector/ServiceConfigAccessor.java +79 −28 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.timezonedetector; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.StringDef; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; Loading @@ -27,6 +28,10 @@ import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.server.timedetector.ServerFlags; 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.Collections; import java.util.Objects; Loading @@ -40,13 +45,38 @@ import java.util.Set; */ 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) @interface ProviderMode {} /** * The "simulated" provider mode. * For use with {@link #getPrimaryLocationTimeZoneProviderMode()} and {@link * #getSecondaryLocationTimeZoneProviderMode()}. */ public static final @ProviderMode String PROVIDER_MODE_SIMULATED = "simulated"; /** * The "disabled" provider mode. For use with {@link #getPrimaryLocationTimeZoneProviderMode()} * and {@link #getSecondaryLocationTimeZoneProviderMode()}. */ public static final @ProviderMode String PROVIDER_MODE_DISABLED = "disabled"; /** * The "enabled" provider mode. For use with {@link #getPrimaryLocationTimeZoneProviderMode()} * and {@link #getSecondaryLocationTimeZoneProviderMode()}. */ public static final @ProviderMode String PROVIDER_MODE_ENABLED = "enabled"; private static final Set<String> SERVER_FLAGS_KEYS_TO_WATCH = Collections.unmodifiableSet( new ArraySet<>(new String[] { ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_FEATURE_SUPPORTED, ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT, ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE, ServerFlags.KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE, ServerFlags.KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE, ServerFlags.KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE, ServerFlags.KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE, ServerFlags.KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_MILLIS, ServerFlags.KEY_LOCATION_TIME_ZONE_PROVIDER_INITIALIZATION_TIMEOUT_FUZZ_MILLIS, ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_UNCERTAINTY_DELAY_MILLIS Loading Loading @@ -139,14 +169,28 @@ public final class ServiceConfigAccessor { /** * Returns {@code true} if the location-based time zone detection feature is supported on the * device. This can be used during feature testing on builds that are capable of location time * zone detection to enable / disable the feature for some users. * device. */ public boolean isGeoTimeZoneDetectionFeatureSupported() { // For the feature to be enabled it must: // 1) Be turned on in config. // 2) Not be turned off via a server flag. // 3) There must be at least one location time zone provider enabled / configured. return mGeoDetectionFeatureSupportedInConfig && isGeoTimeZoneDetectionFeatureSupportedInternal(); && isGeoTimeZoneDetectionFeatureSupportedInternal() && atLeastOneProviderIsEnabled(); } private boolean atLeastOneProviderIsEnabled() { return !(Objects.equals(getPrimaryLocationTimeZoneProviderMode(), PROVIDER_MODE_DISABLED) && Objects.equals(getSecondaryLocationTimeZoneProviderMode(), PROVIDER_MODE_DISABLED)); } /** * Returns {@code true} if the location-based time zone detection feature is not explicitly * disabled by a server flag. */ private boolean isGeoTimeZoneDetectionFeatureSupportedInternal() { final boolean defaultEnabled = true; return mServerFlags.getBoolean( Loading @@ -154,42 +198,49 @@ public final class ServiceConfigAccessor { defaultEnabled); } @NonNull public String getPrimaryLocationTimeZoneProviderPackageName() { return mContext.getResources().getString( R.string.config_primaryLocationTimeZoneProviderPackageName); } @NonNull public String getSecondaryLocationTimeZoneProviderPackageName() { return mContext.getResources().getString( R.string.config_secondaryLocationTimeZoneProviderPackageName); } /** * Returns {@code true} if the primary location time zone provider can be used. */ public boolean isPrimaryLocationTimeZoneProviderEnabled() { return getPrimaryLocationTimeZoneProviderEnabledOverride() .orElse(isPrimaryLocationTimeZoneProviderEnabledInConfig()); } private boolean isPrimaryLocationTimeZoneProviderEnabledInConfig() { int providerEnabledConfigId = R.bool.config_enablePrimaryLocationTimeZoneProvider; return getConfigBoolean(providerEnabledConfigId); @NonNull public @ProviderMode String getPrimaryLocationTimeZoneProviderMode() { return mServerFlags.getOptionalString( ServerFlags.KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE) .orElse(getPrimaryLocationTimeZoneProviderModeFromConfig()); } @NonNull private Optional<Boolean> getPrimaryLocationTimeZoneProviderEnabledOverride() { return mServerFlags.getOptionalBoolean( ServerFlags.KEY_PRIMARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE); private @ProviderMode String getPrimaryLocationTimeZoneProviderModeFromConfig() { int providerEnabledConfigId = R.bool.config_enablePrimaryLocationTimeZoneProvider; return getConfigBoolean(providerEnabledConfigId) ? PROVIDER_MODE_ENABLED : PROVIDER_MODE_DISABLED; } /** * Returns {@code true} if the secondary location time zone provider can be used. * Returns the mode for the secondary location time zone provider can be used. */ public boolean isSecondaryLocationTimeZoneProviderEnabled() { return getSecondaryLocationTimeZoneProviderEnabledOverride() .orElse(isSecondaryLocationTimeZoneProviderEnabledInConfig()); } private boolean isSecondaryLocationTimeZoneProviderEnabledInConfig() { int providerEnabledConfigId = R.bool.config_enableSecondaryLocationTimeZoneProvider; return getConfigBoolean(providerEnabledConfigId); public @ProviderMode String getSecondaryLocationTimeZoneProviderMode() { return mServerFlags.getOptionalString( ServerFlags.KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_MODE_OVERRIDE) .orElse(getSecondaryLocationTimeZoneProviderModeFromConfig()); } @NonNull private Optional<Boolean> getSecondaryLocationTimeZoneProviderEnabledOverride() { return mServerFlags.getOptionalBoolean( ServerFlags.KEY_SECONDARY_LOCATION_TIME_ZONE_PROVIDER_ENABLED_OVERRIDE); private @ProviderMode String getSecondaryLocationTimeZoneProviderModeFromConfig() { int providerEnabledConfigId = R.bool.config_enableSecondaryLocationTimeZoneProvider; return getConfigBoolean(providerEnabledConfigId) ? PROVIDER_MODE_ENABLED : PROVIDER_MODE_DISABLED; } /** Loading