Loading core/java/android/app/timezonedetector/ITimeZoneConfigurationListener.aidl +1 −1 Original line number Original line Diff line number Diff line Loading @@ -20,5 +20,5 @@ import android.app.timezonedetector.TimeZoneConfiguration; /** {@hide} */ /** {@hide} */ oneway interface ITimeZoneConfigurationListener { oneway interface ITimeZoneConfigurationListener { void onChange(in TimeZoneConfiguration configuration); void onChange(); } } No newline at end of file core/java/android/app/timezonedetector/ITimeZoneDetectorService.aidl +2 −4 Original line number Original line Diff line number Diff line Loading @@ -32,17 +32,15 @@ import android.app.timezonedetector.TimeZoneConfiguration; * this Binder interface directly. See {@link android.app.timezonedetector.TimeZoneDetectorService} * this Binder interface directly. See {@link android.app.timezonedetector.TimeZoneDetectorService} * for more complete documentation. * for more complete documentation. * * * * {@hide} * {@hide} */ */ interface ITimeZoneDetectorService { interface ITimeZoneDetectorService { TimeZoneCapabilities getCapabilities(); TimeZoneCapabilities getCapabilities(); TimeZoneConfiguration getConfiguration(); boolean updateConfiguration(in TimeZoneConfiguration configuration); void addConfigurationListener(ITimeZoneConfigurationListener listener); void addConfigurationListener(ITimeZoneConfigurationListener listener); void removeConfigurationListener(ITimeZoneConfigurationListener listener); void removeConfigurationListener(ITimeZoneConfigurationListener listener); boolean updateConfiguration(in TimeZoneConfiguration configuration); boolean suggestManualTimeZone(in ManualTimeZoneSuggestion timeZoneSuggestion); boolean suggestManualTimeZone(in ManualTimeZoneSuggestion timeZoneSuggestion); void suggestTelephonyTimeZone(in TelephonyTimeZoneSuggestion timeZoneSuggestion); void suggestTelephonyTimeZone(in TelephonyTimeZoneSuggestion timeZoneSuggestion); } } core/java/android/app/timezonedetector/TimeZoneCapabilities.java +77 −32 Original line number Original line Diff line number Diff line Loading @@ -16,9 +16,12 @@ package android.app.timezonedetector; package android.app.timezonedetector; import static android.app.timezonedetector.TimeZoneConfiguration.SETTING_AUTO_DETECTION_ENABLED; import static android.app.timezonedetector.TimeZoneConfiguration.SETTING_GEO_DETECTION_ENABLED; import android.annotation.IntDef; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.UserIdInt; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; Loading @@ -38,9 +41,9 @@ import java.util.Objects; * * * <p>Actions have associated methods, see the documentation for each action for details. * <p>Actions have associated methods, see the documentation for each action for details. * * * <p>For configuration capabilities, the associated current configuration value can be retrieved * <p>For configuration settings capabilities, the associated settings value can be found via * using {@link TimeZoneDetector#getConfiguration()} and may be changed using * {@link #getConfiguration()} and may be changed using {@link * {@link TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)}. * TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} (if the user's capabilities allow). * * * <p>Note: Capabilities are independent of app permissions required to call the associated APIs. * <p>Note: Capabilities are independent of app permissions required to call the associated APIs. * * Loading @@ -60,7 +63,8 @@ public final class TimeZoneCapabilities implements Parcelable { public static final int CAPABILITY_NOT_SUPPORTED = 10; public static final int CAPABILITY_NOT_SUPPORTED = 10; /** /** * Indicates that a capability is supported on this device, but not allowed for the user. * Indicates that a capability is supported on this device, but not allowed for the user, e.g. * if the capability relates to the ability to modify settings the user is not able to. * This could be because of the user's type (e.g. maybe it applies to the primary user only) or * This could be because of the user's type (e.g. maybe it applies to the primary user only) or * device policy. Depending on the capability, this could mean the associated UI * device policy. Depending on the capability, this could mean the associated UI * should be hidden, or displayed but disabled. * should be hidden, or displayed but disabled. Loading @@ -68,9 +72,11 @@ public final class TimeZoneCapabilities implements Parcelable { public static final int CAPABILITY_NOT_ALLOWED = 20; public static final int CAPABILITY_NOT_ALLOWED = 20; /** /** * Indicates that a capability is possessed but not applicable, e.g. if it is configuration, * Indicates that a capability is possessed but not currently applicable, e.g. if the * the current configuration or device state renders it irrelevant. The associated UI may be * capability relates to the ability to modify settings, the user has the ability to modify * hidden, disabled, or left visible (but ineffective) depending on requirements. * it, but it is currently rendered irrelevant by other settings or other device state (flags, * resource config, etc.). The associated UI may be hidden, disabled, or left visible (but * ineffective) depending on requirements. */ */ public static final int CAPABILITY_NOT_APPLICABLE = 30; public static final int CAPABILITY_NOT_APPLICABLE = 30; Loading @@ -89,13 +95,13 @@ public final class TimeZoneCapabilities implements Parcelable { }; }; private final @UserIdInt int mUserId; @NonNull private final TimeZoneConfiguration mConfiguration; private final @CapabilityState int mConfigureAutoDetectionEnabled; private final @CapabilityState int mConfigureAutoDetectionEnabled; private final @CapabilityState int mConfigureGeoDetectionEnabled; private final @CapabilityState int mConfigureGeoDetectionEnabled; private final @CapabilityState int mSuggestManualTimeZone; private final @CapabilityState int mSuggestManualTimeZone; private TimeZoneCapabilities(@NonNull Builder builder) { private TimeZoneCapabilities(@NonNull Builder builder) { this.mUserId = builder.mUserId; this.mConfiguration = Objects.requireNonNull(builder.mConfiguration); this.mConfigureAutoDetectionEnabled = builder.mConfigureAutoDetectionEnabled; this.mConfigureAutoDetectionEnabled = builder.mConfigureAutoDetectionEnabled; this.mConfigureGeoDetectionEnabled = builder.mConfigureGeoDetectionEnabled; this.mConfigureGeoDetectionEnabled = builder.mConfigureGeoDetectionEnabled; this.mSuggestManualTimeZone = builder.mSuggestManualTimeZone; this.mSuggestManualTimeZone = builder.mSuggestManualTimeZone; Loading @@ -103,7 +109,8 @@ public final class TimeZoneCapabilities implements Parcelable { @NonNull @NonNull private static TimeZoneCapabilities createFromParcel(Parcel in) { private static TimeZoneCapabilities createFromParcel(Parcel in) { return new TimeZoneCapabilities.Builder(in.readInt()) return new TimeZoneCapabilities.Builder() .setConfiguration(in.readParcelable(null)) .setConfigureAutoDetectionEnabled(in.readInt()) .setConfigureAutoDetectionEnabled(in.readInt()) .setConfigureGeoDetectionEnabled(in.readInt()) .setConfigureGeoDetectionEnabled(in.readInt()) .setSuggestManualTimeZone(in.readInt()) .setSuggestManualTimeZone(in.readInt()) Loading @@ -112,21 +119,24 @@ public final class TimeZoneCapabilities implements Parcelable { @Override @Override public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(mUserId); dest.writeParcelable(mConfiguration, flags); dest.writeInt(mConfigureAutoDetectionEnabled); dest.writeInt(mConfigureAutoDetectionEnabled); dest.writeInt(mConfigureGeoDetectionEnabled); dest.writeInt(mConfigureGeoDetectionEnabled); dest.writeInt(mSuggestManualTimeZone); dest.writeInt(mSuggestManualTimeZone); } } /** Returns the user ID the capabilities are for. */ /** public @UserIdInt int getUserId() { * Returns the user's time zone behavior configuration. return mUserId; */ public @NonNull TimeZoneConfiguration getConfiguration() { return mConfiguration; } } /** /** * Returns the user's capability state for controlling whether automatic time zone detection is * Returns the capability state associated with the user's ability to modify the automatic time * enabled via {@link TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and {@link * zone detection setting. The setting can be updated via {@link * TimeZoneConfiguration#isAutoDetectionEnabled()}. * TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and accessed via {@link * #getConfiguration()}. */ */ @CapabilityState @CapabilityState public int getConfigureAutoDetectionEnabled() { public int getConfigureAutoDetectionEnabled() { Loading @@ -134,9 +144,10 @@ public final class TimeZoneCapabilities implements Parcelable { } } /** /** * Returns the user's capability state for controlling whether geolocation can be used to detect * Returns the capability state associated with the user's ability to modify the geolocation * time zone via {@link TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and {@link * detection setting. The setting can be updated via {@link * TimeZoneConfiguration#isGeoDetectionEnabled()}. * TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and accessed via {@link * #getConfiguration()}. */ */ @CapabilityState @CapabilityState public int getConfigureGeoDetectionEnabled() { public int getConfigureGeoDetectionEnabled() { Loading @@ -144,8 +155,8 @@ public final class TimeZoneCapabilities implements Parcelable { } } /** /** * Returns the user's capability state for manually setting the time zone on a device via * Returns the capability state associated with the user's ability to manually set the time zone * {@link TimeZoneDetector#suggestManualTimeZone(ManualTimeZoneSuggestion)}. * on a device via {@link TimeZoneDetector#suggestManualTimeZone(ManualTimeZoneSuggestion)}. * * * <p>The suggestion will be ignored in all cases unless the value is {@link * <p>The suggestion will be ignored in all cases unless the value is {@link * #CAPABILITY_POSSESSED}. See also {@link TimeZoneConfiguration#isAutoDetectionEnabled()}. * #CAPABILITY_POSSESSED}. See also {@link TimeZoneConfiguration#isAutoDetectionEnabled()}. Loading @@ -155,6 +166,38 @@ public final class TimeZoneCapabilities implements Parcelable { return mSuggestManualTimeZone; return mSuggestManualTimeZone; } } /** * Constructs a new {@link TimeZoneConfiguration} from an {@code oldConfiguration} and a set of * {@code requestedChanges}, if the current capabilities allow. The new configuration is * returned and the capabilities are left unchanged. If the capabilities do not permit one or * more of the changes then {@code null} is returned. */ @Nullable public TimeZoneConfiguration applyUpdate(TimeZoneConfiguration requestedChanges) { if (requestedChanges.getUserId() != mConfiguration.getUserId()) { throw new IllegalArgumentException("User does not match:" + " this=" + mConfiguration + ", other=" + requestedChanges); } TimeZoneConfiguration.Builder newConfigBuilder = new TimeZoneConfiguration.Builder(mConfiguration); if (requestedChanges.hasSetting(SETTING_AUTO_DETECTION_ENABLED)) { if (getConfigureAutoDetectionEnabled() < CAPABILITY_NOT_APPLICABLE) { return null; } newConfigBuilder.setAutoDetectionEnabled(requestedChanges.isAutoDetectionEnabled()); } if (requestedChanges.hasSetting(SETTING_GEO_DETECTION_ENABLED)) { if (getConfigureGeoDetectionEnabled() < CAPABILITY_NOT_APPLICABLE) { return null; } newConfigBuilder.setGeoDetectionEnabled(requestedChanges.isGeoDetectionEnabled()); } return newConfigBuilder.build(); } @Override @Override public int describeContents() { public int describeContents() { return 0; return 0; Loading @@ -169,7 +212,7 @@ public final class TimeZoneCapabilities implements Parcelable { return false; return false; } } TimeZoneCapabilities that = (TimeZoneCapabilities) o; TimeZoneCapabilities that = (TimeZoneCapabilities) o; return mUserId == that.mUserId return Objects.equals(mConfiguration, that.mConfiguration) && mConfigureAutoDetectionEnabled == that.mConfigureAutoDetectionEnabled && mConfigureAutoDetectionEnabled == that.mConfigureAutoDetectionEnabled && mConfigureGeoDetectionEnabled == that.mConfigureGeoDetectionEnabled && mConfigureGeoDetectionEnabled == that.mConfigureGeoDetectionEnabled && mSuggestManualTimeZone == that.mSuggestManualTimeZone; && mSuggestManualTimeZone == that.mSuggestManualTimeZone; Loading @@ -177,7 +220,7 @@ public final class TimeZoneCapabilities implements Parcelable { @Override @Override public int hashCode() { public int hashCode() { return Objects.hash(mUserId, return Objects.hash(mConfiguration, mConfigureAutoDetectionEnabled, mConfigureAutoDetectionEnabled, mConfigureGeoDetectionEnabled, mConfigureGeoDetectionEnabled, mSuggestManualTimeZone); mSuggestManualTimeZone); Loading @@ -186,7 +229,7 @@ public final class TimeZoneCapabilities implements Parcelable { @Override @Override public String toString() { public String toString() { return "TimeZoneDetectorCapabilities{" return "TimeZoneDetectorCapabilities{" + "mUserId=" + mUserId + "mConfiguration=" + mConfiguration + ", mConfigureAutomaticDetectionEnabled=" + mConfigureAutoDetectionEnabled + ", mConfigureAutomaticDetectionEnabled=" + mConfigureAutoDetectionEnabled + ", mConfigureGeoDetectionEnabled=" + mConfigureGeoDetectionEnabled + ", mConfigureGeoDetectionEnabled=" + mConfigureGeoDetectionEnabled + ", mSuggestManualTimeZone=" + mSuggestManualTimeZone + ", mSuggestManualTimeZone=" + mSuggestManualTimeZone Loading @@ -196,16 +239,18 @@ public final class TimeZoneCapabilities implements Parcelable { /** @hide */ /** @hide */ public static class Builder { public static class Builder { private final @UserIdInt int mUserId; private TimeZoneConfiguration mConfiguration; private @CapabilityState int mConfigureAutoDetectionEnabled; private @CapabilityState int mConfigureAutoDetectionEnabled; private @CapabilityState int mConfigureGeoDetectionEnabled; private @CapabilityState int mConfigureGeoDetectionEnabled; private @CapabilityState int mSuggestManualTimeZone; private @CapabilityState int mSuggestManualTimeZone; /** /** Sets the user-visible configuration settings. */ * Creates a new Builder with no properties set. public Builder setConfiguration(@NonNull TimeZoneConfiguration configuration) { */ if (!configuration.isComplete()) { public Builder(@UserIdInt int userId) { throw new IllegalArgumentException(configuration + " is not complete"); mUserId = userId; } this.mConfiguration = configuration; return this; } } /** Sets the state for the automatic time zone detection enabled config. */ /** Sets the state for the automatic time zone detection enabled config. */ Loading core/java/android/app/timezonedetector/TimeZoneConfiguration.java +86 −62 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.app.timezonedetector; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.StringDef; import android.annotation.StringDef; import android.annotation.UserIdInt; import android.os.Bundle; import android.os.Bundle; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; Loading @@ -27,21 +28,20 @@ import java.lang.annotation.RetentionPolicy; import java.util.Objects; import java.util.Objects; /** /** * Configuration that controls the behavior of the time zone detector associated with a specific * User visible settings that control the behavior of the time zone detector / manual time zone * user. * entry. * * * <p>Configuration consists of a set of known properties. When reading configuration via * <p>When reading the configuration, values for all settings will be provided. In some cases, such * {@link TimeZoneDetector#getConfiguration()} values for all known properties will be provided. In * as when the device behavior relies on optional hardware / OEM configuration, or the value of * some cases, such as when the configuration relies on optional hardware, the values may be * several settings, the device behavior may not be directly affected by the setting value. * meaningless / defaulted to safe values. * * * <p>Configuration properties can be left absent when updating configuration via {@link * <p>Settings can be left absent when updating configuration via {@link * TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and those values will not be * TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and those settings will not be * changed. Not all configuration properties can be modified by all users. See {@link * changed. Not all configuration settings can be modified by all users: see {@link * TimeZoneDetector#getCapabilities()} and {@link TimeZoneCapabilities}. * TimeZoneDetector#getCapabilities()} and {@link TimeZoneCapabilities} for details. * * * <p>See {@link #isComplete()} to tell if all known properties are present, and {@link * <p>See {@link #hasSetting(String)} with {@code PROPERTY_} constants for testing for the presence * #hasProperty(String)} with {@code PROPERTY_} constants for testing individual properties. * of individual settings. * * * @hide * @hide */ */ Loading @@ -59,80 +59,82 @@ public final class TimeZoneConfiguration implements Parcelable { }; }; /** All configuration properties */ /** All configuration properties */ @StringDef(PROPERTY_AUTO_DETECTION_ENABLED) @StringDef({ SETTING_AUTO_DETECTION_ENABLED, SETTING_GEO_DETECTION_ENABLED }) @Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE) @interface Property {} @interface Setting {} /** See {@link TimeZoneConfiguration#isAutoDetectionEnabled()} for details. */ /** See {@link TimeZoneConfiguration#isAutoDetectionEnabled()} for details. */ @Property @Setting public static final String PROPERTY_AUTO_DETECTION_ENABLED = "autoDetectionEnabled"; public static final String SETTING_AUTO_DETECTION_ENABLED = "autoDetectionEnabled"; /** See {@link TimeZoneConfiguration#isGeoDetectionEnabled()} for details. */ /** See {@link TimeZoneConfiguration#isGeoDetectionEnabled()} for details. */ @Property @Setting public static final String PROPERTY_GEO_DETECTION_ENABLED = "geoDetectionEnabled"; public static final String SETTING_GEO_DETECTION_ENABLED = "geoDetectionEnabled"; private final Bundle mBundle; private final @UserIdInt int mUserId; @NonNull private final Bundle mBundle; private TimeZoneConfiguration(Builder builder) { private TimeZoneConfiguration(Builder builder) { this.mBundle = builder.mBundle; this.mUserId = builder.mUserId; this.mBundle = Objects.requireNonNull(builder.mBundle); } } private static TimeZoneConfiguration createFromParcel(Parcel in) { private static TimeZoneConfiguration createFromParcel(Parcel in) { return new TimeZoneConfiguration.Builder() return new TimeZoneConfiguration.Builder(in.readInt()) .setPropertyBundleInternal(in.readBundle()) .setPropertyBundleInternal(in.readBundle()) .build(); .build(); } } @Override @Override public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(mUserId); dest.writeBundle(mBundle); dest.writeBundle(mBundle); } } /** Returns {@code true} if all known properties are set. */ /** Returns the ID of the user this configuration is associated with. */ public @UserIdInt int getUserId() { return mUserId; } /** Returns {@code true} if all known settings are present. */ public boolean isComplete() { public boolean isComplete() { return hasProperty(PROPERTY_AUTO_DETECTION_ENABLED) return hasSetting(SETTING_AUTO_DETECTION_ENABLED) && hasProperty(PROPERTY_GEO_DETECTION_ENABLED); && hasSetting(SETTING_GEO_DETECTION_ENABLED); } } /** Returns true if the specified property is set. */ /** Returns true if the specified setting is set. */ public boolean hasProperty(@Property String property) { public boolean hasSetting(@Setting String setting) { return mBundle.containsKey(property); return mBundle.containsKey(setting); } } /** /** * Returns the value of the {@link #PROPERTY_AUTO_DETECTION_ENABLED} property. This * Returns the value of the {@link #SETTING_AUTO_DETECTION_ENABLED} setting. This * controls whether a device will attempt to determine the time zone automatically using * controls whether a device will attempt to determine the time zone automatically using * contextual information. * contextual information if the device supports auto detection. * * <p>This setting is global and can be updated by some users. * * * @throws IllegalStateException if the field has not been set * @throws IllegalStateException if the setting has not been set */ */ public boolean isAutoDetectionEnabled() { public boolean isAutoDetectionEnabled() { if (!mBundle.containsKey(PROPERTY_AUTO_DETECTION_ENABLED)) { enforceSettingPresent(SETTING_AUTO_DETECTION_ENABLED); throw new IllegalStateException(PROPERTY_AUTO_DETECTION_ENABLED + " is not set"); return mBundle.getBoolean(SETTING_AUTO_DETECTION_ENABLED); } return mBundle.getBoolean(PROPERTY_AUTO_DETECTION_ENABLED); } } /** /** * Returns the value of the {@link #PROPERTY_GEO_DETECTION_ENABLED} property. This * Returns the value of the {@link #SETTING_GEO_DETECTION_ENABLED} setting. This * controls whether a device can use location to determine time zone. Only used when * controls whether a device can use geolocation to determine time zone. Only used when * {@link #isAutoDetectionEnabled()} is true. * {@link #isAutoDetectionEnabled()} is {@code true} and when the user has allowed their * location to be used. * * <p>This setting is user-scoped and can be updated by some users. * See {@link TimeZoneCapabilities#getConfigureGeoDetectionEnabled()}. * * * @throws IllegalStateException if the field has not been set * @throws IllegalStateException if the setting has not been set */ */ public boolean isGeoDetectionEnabled() { public boolean isGeoDetectionEnabled() { if (!mBundle.containsKey(PROPERTY_GEO_DETECTION_ENABLED)) { enforceSettingPresent(SETTING_GEO_DETECTION_ENABLED); throw new IllegalStateException(PROPERTY_GEO_DETECTION_ENABLED + " is not set"); return mBundle.getBoolean(SETTING_GEO_DETECTION_ENABLED); } return mBundle.getBoolean(PROPERTY_GEO_DETECTION_ENABLED); } /** * Convenience method to merge this with another. The argument configuration properties have * precedence. */ public TimeZoneConfiguration with(TimeZoneConfiguration other) { return new Builder(this).mergeProperties(other).build(); } } @Override @Override Loading @@ -149,43 +151,61 @@ public final class TimeZoneConfiguration implements Parcelable { return false; return false; } } TimeZoneConfiguration that = (TimeZoneConfiguration) o; TimeZoneConfiguration that = (TimeZoneConfiguration) o; return mBundle.kindofEquals(that.mBundle); return mUserId == that.mUserId && mBundle.kindofEquals(that.mBundle); } } @Override @Override public int hashCode() { public int hashCode() { return Objects.hash(mBundle); return Objects.hash(mUserId, mBundle); } } @Override @Override public String toString() { public String toString() { return "TimeZoneDetectorConfiguration{" return "TimeZoneDetectorConfiguration{" + "mUserId=" + mUserId + "mBundle=" + mBundle + "mBundle=" + mBundle + '}'; + '}'; } } private void enforceSettingPresent(@Setting String setting) { if (!mBundle.containsKey(setting)) { throw new IllegalStateException(setting + " is not set"); } } /** @hide */ /** @hide */ public static class Builder { public static class Builder { private Bundle mBundle = new Bundle(); private final @UserIdInt int mUserId; private final Bundle mBundle = new Bundle(); /** /** * Creates a new Builder with no properties set. * Creates a new Builder for a userId with no settings held. */ */ public Builder() {} public Builder(@UserIdInt int userId) { mUserId = userId; } /** /** * Creates a new Builder by copying properties from an existing instance. * Creates a new Builder by copying the user ID and settings from an existing instance. */ */ public Builder(TimeZoneConfiguration toCopy) { public Builder(TimeZoneConfiguration toCopy) { this.mUserId = toCopy.mUserId; mergeProperties(toCopy); mergeProperties(toCopy); } } /** /** * Merges {@code other} properties into this instances, replacing existing values in this * Merges {@code other} settings into this instances, replacing existing values in this * where the properties appear in both. * where the settings appear in both. */ */ public Builder mergeProperties(TimeZoneConfiguration other) { public Builder mergeProperties(TimeZoneConfiguration other) { if (mUserId != other.mUserId) { throw new IllegalArgumentException( "Cannot merge configurations for different user IDs." + " this.mUserId=" + this.mUserId + ", other.mUserId=" + other.mUserId); } this.mBundle.putAll(other.mBundle); this.mBundle.putAll(other.mBundle); return this; return this; } } Loading @@ -195,15 +215,19 @@ public final class TimeZoneConfiguration implements Parcelable { return this; return this; } } /** Sets the desired state of the automatic time zone detection property. */ /** * Sets the state of the {@link #SETTING_AUTO_DETECTION_ENABLED} setting. */ public Builder setAutoDetectionEnabled(boolean enabled) { public Builder setAutoDetectionEnabled(boolean enabled) { this.mBundle.putBoolean(PROPERTY_AUTO_DETECTION_ENABLED, enabled); this.mBundle.putBoolean(SETTING_AUTO_DETECTION_ENABLED, enabled); return this; return this; } } /** Sets the desired state of the geolocation time zone detection enabled property. */ /** * Sets the state of the {@link #SETTING_GEO_DETECTION_ENABLED} setting. */ public Builder setGeoDetectionEnabled(boolean enabled) { public Builder setGeoDetectionEnabled(boolean enabled) { this.mBundle.putBoolean(PROPERTY_GEO_DETECTION_ENABLED, enabled); this.mBundle.putBoolean(SETTING_GEO_DETECTION_ENABLED, enabled); return this; return this; } } Loading core/java/android/app/timezonedetector/TimeZoneDetector.java +20 −22 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/app/timezonedetector/ITimeZoneConfigurationListener.aidl +1 −1 Original line number Original line Diff line number Diff line Loading @@ -20,5 +20,5 @@ import android.app.timezonedetector.TimeZoneConfiguration; /** {@hide} */ /** {@hide} */ oneway interface ITimeZoneConfigurationListener { oneway interface ITimeZoneConfigurationListener { void onChange(in TimeZoneConfiguration configuration); void onChange(); } } No newline at end of file
core/java/android/app/timezonedetector/ITimeZoneDetectorService.aidl +2 −4 Original line number Original line Diff line number Diff line Loading @@ -32,17 +32,15 @@ import android.app.timezonedetector.TimeZoneConfiguration; * this Binder interface directly. See {@link android.app.timezonedetector.TimeZoneDetectorService} * this Binder interface directly. See {@link android.app.timezonedetector.TimeZoneDetectorService} * for more complete documentation. * for more complete documentation. * * * * {@hide} * {@hide} */ */ interface ITimeZoneDetectorService { interface ITimeZoneDetectorService { TimeZoneCapabilities getCapabilities(); TimeZoneCapabilities getCapabilities(); TimeZoneConfiguration getConfiguration(); boolean updateConfiguration(in TimeZoneConfiguration configuration); void addConfigurationListener(ITimeZoneConfigurationListener listener); void addConfigurationListener(ITimeZoneConfigurationListener listener); void removeConfigurationListener(ITimeZoneConfigurationListener listener); void removeConfigurationListener(ITimeZoneConfigurationListener listener); boolean updateConfiguration(in TimeZoneConfiguration configuration); boolean suggestManualTimeZone(in ManualTimeZoneSuggestion timeZoneSuggestion); boolean suggestManualTimeZone(in ManualTimeZoneSuggestion timeZoneSuggestion); void suggestTelephonyTimeZone(in TelephonyTimeZoneSuggestion timeZoneSuggestion); void suggestTelephonyTimeZone(in TelephonyTimeZoneSuggestion timeZoneSuggestion); } }
core/java/android/app/timezonedetector/TimeZoneCapabilities.java +77 −32 Original line number Original line Diff line number Diff line Loading @@ -16,9 +16,12 @@ package android.app.timezonedetector; package android.app.timezonedetector; import static android.app.timezonedetector.TimeZoneConfiguration.SETTING_AUTO_DETECTION_ENABLED; import static android.app.timezonedetector.TimeZoneConfiguration.SETTING_GEO_DETECTION_ENABLED; import android.annotation.IntDef; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.UserIdInt; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; Loading @@ -38,9 +41,9 @@ import java.util.Objects; * * * <p>Actions have associated methods, see the documentation for each action for details. * <p>Actions have associated methods, see the documentation for each action for details. * * * <p>For configuration capabilities, the associated current configuration value can be retrieved * <p>For configuration settings capabilities, the associated settings value can be found via * using {@link TimeZoneDetector#getConfiguration()} and may be changed using * {@link #getConfiguration()} and may be changed using {@link * {@link TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)}. * TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} (if the user's capabilities allow). * * * <p>Note: Capabilities are independent of app permissions required to call the associated APIs. * <p>Note: Capabilities are independent of app permissions required to call the associated APIs. * * Loading @@ -60,7 +63,8 @@ public final class TimeZoneCapabilities implements Parcelable { public static final int CAPABILITY_NOT_SUPPORTED = 10; public static final int CAPABILITY_NOT_SUPPORTED = 10; /** /** * Indicates that a capability is supported on this device, but not allowed for the user. * Indicates that a capability is supported on this device, but not allowed for the user, e.g. * if the capability relates to the ability to modify settings the user is not able to. * This could be because of the user's type (e.g. maybe it applies to the primary user only) or * This could be because of the user's type (e.g. maybe it applies to the primary user only) or * device policy. Depending on the capability, this could mean the associated UI * device policy. Depending on the capability, this could mean the associated UI * should be hidden, or displayed but disabled. * should be hidden, or displayed but disabled. Loading @@ -68,9 +72,11 @@ public final class TimeZoneCapabilities implements Parcelable { public static final int CAPABILITY_NOT_ALLOWED = 20; public static final int CAPABILITY_NOT_ALLOWED = 20; /** /** * Indicates that a capability is possessed but not applicable, e.g. if it is configuration, * Indicates that a capability is possessed but not currently applicable, e.g. if the * the current configuration or device state renders it irrelevant. The associated UI may be * capability relates to the ability to modify settings, the user has the ability to modify * hidden, disabled, or left visible (but ineffective) depending on requirements. * it, but it is currently rendered irrelevant by other settings or other device state (flags, * resource config, etc.). The associated UI may be hidden, disabled, or left visible (but * ineffective) depending on requirements. */ */ public static final int CAPABILITY_NOT_APPLICABLE = 30; public static final int CAPABILITY_NOT_APPLICABLE = 30; Loading @@ -89,13 +95,13 @@ public final class TimeZoneCapabilities implements Parcelable { }; }; private final @UserIdInt int mUserId; @NonNull private final TimeZoneConfiguration mConfiguration; private final @CapabilityState int mConfigureAutoDetectionEnabled; private final @CapabilityState int mConfigureAutoDetectionEnabled; private final @CapabilityState int mConfigureGeoDetectionEnabled; private final @CapabilityState int mConfigureGeoDetectionEnabled; private final @CapabilityState int mSuggestManualTimeZone; private final @CapabilityState int mSuggestManualTimeZone; private TimeZoneCapabilities(@NonNull Builder builder) { private TimeZoneCapabilities(@NonNull Builder builder) { this.mUserId = builder.mUserId; this.mConfiguration = Objects.requireNonNull(builder.mConfiguration); this.mConfigureAutoDetectionEnabled = builder.mConfigureAutoDetectionEnabled; this.mConfigureAutoDetectionEnabled = builder.mConfigureAutoDetectionEnabled; this.mConfigureGeoDetectionEnabled = builder.mConfigureGeoDetectionEnabled; this.mConfigureGeoDetectionEnabled = builder.mConfigureGeoDetectionEnabled; this.mSuggestManualTimeZone = builder.mSuggestManualTimeZone; this.mSuggestManualTimeZone = builder.mSuggestManualTimeZone; Loading @@ -103,7 +109,8 @@ public final class TimeZoneCapabilities implements Parcelable { @NonNull @NonNull private static TimeZoneCapabilities createFromParcel(Parcel in) { private static TimeZoneCapabilities createFromParcel(Parcel in) { return new TimeZoneCapabilities.Builder(in.readInt()) return new TimeZoneCapabilities.Builder() .setConfiguration(in.readParcelable(null)) .setConfigureAutoDetectionEnabled(in.readInt()) .setConfigureAutoDetectionEnabled(in.readInt()) .setConfigureGeoDetectionEnabled(in.readInt()) .setConfigureGeoDetectionEnabled(in.readInt()) .setSuggestManualTimeZone(in.readInt()) .setSuggestManualTimeZone(in.readInt()) Loading @@ -112,21 +119,24 @@ public final class TimeZoneCapabilities implements Parcelable { @Override @Override public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(mUserId); dest.writeParcelable(mConfiguration, flags); dest.writeInt(mConfigureAutoDetectionEnabled); dest.writeInt(mConfigureAutoDetectionEnabled); dest.writeInt(mConfigureGeoDetectionEnabled); dest.writeInt(mConfigureGeoDetectionEnabled); dest.writeInt(mSuggestManualTimeZone); dest.writeInt(mSuggestManualTimeZone); } } /** Returns the user ID the capabilities are for. */ /** public @UserIdInt int getUserId() { * Returns the user's time zone behavior configuration. return mUserId; */ public @NonNull TimeZoneConfiguration getConfiguration() { return mConfiguration; } } /** /** * Returns the user's capability state for controlling whether automatic time zone detection is * Returns the capability state associated with the user's ability to modify the automatic time * enabled via {@link TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and {@link * zone detection setting. The setting can be updated via {@link * TimeZoneConfiguration#isAutoDetectionEnabled()}. * TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and accessed via {@link * #getConfiguration()}. */ */ @CapabilityState @CapabilityState public int getConfigureAutoDetectionEnabled() { public int getConfigureAutoDetectionEnabled() { Loading @@ -134,9 +144,10 @@ public final class TimeZoneCapabilities implements Parcelable { } } /** /** * Returns the user's capability state for controlling whether geolocation can be used to detect * Returns the capability state associated with the user's ability to modify the geolocation * time zone via {@link TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and {@link * detection setting. The setting can be updated via {@link * TimeZoneConfiguration#isGeoDetectionEnabled()}. * TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and accessed via {@link * #getConfiguration()}. */ */ @CapabilityState @CapabilityState public int getConfigureGeoDetectionEnabled() { public int getConfigureGeoDetectionEnabled() { Loading @@ -144,8 +155,8 @@ public final class TimeZoneCapabilities implements Parcelable { } } /** /** * Returns the user's capability state for manually setting the time zone on a device via * Returns the capability state associated with the user's ability to manually set the time zone * {@link TimeZoneDetector#suggestManualTimeZone(ManualTimeZoneSuggestion)}. * on a device via {@link TimeZoneDetector#suggestManualTimeZone(ManualTimeZoneSuggestion)}. * * * <p>The suggestion will be ignored in all cases unless the value is {@link * <p>The suggestion will be ignored in all cases unless the value is {@link * #CAPABILITY_POSSESSED}. See also {@link TimeZoneConfiguration#isAutoDetectionEnabled()}. * #CAPABILITY_POSSESSED}. See also {@link TimeZoneConfiguration#isAutoDetectionEnabled()}. Loading @@ -155,6 +166,38 @@ public final class TimeZoneCapabilities implements Parcelable { return mSuggestManualTimeZone; return mSuggestManualTimeZone; } } /** * Constructs a new {@link TimeZoneConfiguration} from an {@code oldConfiguration} and a set of * {@code requestedChanges}, if the current capabilities allow. The new configuration is * returned and the capabilities are left unchanged. If the capabilities do not permit one or * more of the changes then {@code null} is returned. */ @Nullable public TimeZoneConfiguration applyUpdate(TimeZoneConfiguration requestedChanges) { if (requestedChanges.getUserId() != mConfiguration.getUserId()) { throw new IllegalArgumentException("User does not match:" + " this=" + mConfiguration + ", other=" + requestedChanges); } TimeZoneConfiguration.Builder newConfigBuilder = new TimeZoneConfiguration.Builder(mConfiguration); if (requestedChanges.hasSetting(SETTING_AUTO_DETECTION_ENABLED)) { if (getConfigureAutoDetectionEnabled() < CAPABILITY_NOT_APPLICABLE) { return null; } newConfigBuilder.setAutoDetectionEnabled(requestedChanges.isAutoDetectionEnabled()); } if (requestedChanges.hasSetting(SETTING_GEO_DETECTION_ENABLED)) { if (getConfigureGeoDetectionEnabled() < CAPABILITY_NOT_APPLICABLE) { return null; } newConfigBuilder.setGeoDetectionEnabled(requestedChanges.isGeoDetectionEnabled()); } return newConfigBuilder.build(); } @Override @Override public int describeContents() { public int describeContents() { return 0; return 0; Loading @@ -169,7 +212,7 @@ public final class TimeZoneCapabilities implements Parcelable { return false; return false; } } TimeZoneCapabilities that = (TimeZoneCapabilities) o; TimeZoneCapabilities that = (TimeZoneCapabilities) o; return mUserId == that.mUserId return Objects.equals(mConfiguration, that.mConfiguration) && mConfigureAutoDetectionEnabled == that.mConfigureAutoDetectionEnabled && mConfigureAutoDetectionEnabled == that.mConfigureAutoDetectionEnabled && mConfigureGeoDetectionEnabled == that.mConfigureGeoDetectionEnabled && mConfigureGeoDetectionEnabled == that.mConfigureGeoDetectionEnabled && mSuggestManualTimeZone == that.mSuggestManualTimeZone; && mSuggestManualTimeZone == that.mSuggestManualTimeZone; Loading @@ -177,7 +220,7 @@ public final class TimeZoneCapabilities implements Parcelable { @Override @Override public int hashCode() { public int hashCode() { return Objects.hash(mUserId, return Objects.hash(mConfiguration, mConfigureAutoDetectionEnabled, mConfigureAutoDetectionEnabled, mConfigureGeoDetectionEnabled, mConfigureGeoDetectionEnabled, mSuggestManualTimeZone); mSuggestManualTimeZone); Loading @@ -186,7 +229,7 @@ public final class TimeZoneCapabilities implements Parcelable { @Override @Override public String toString() { public String toString() { return "TimeZoneDetectorCapabilities{" return "TimeZoneDetectorCapabilities{" + "mUserId=" + mUserId + "mConfiguration=" + mConfiguration + ", mConfigureAutomaticDetectionEnabled=" + mConfigureAutoDetectionEnabled + ", mConfigureAutomaticDetectionEnabled=" + mConfigureAutoDetectionEnabled + ", mConfigureGeoDetectionEnabled=" + mConfigureGeoDetectionEnabled + ", mConfigureGeoDetectionEnabled=" + mConfigureGeoDetectionEnabled + ", mSuggestManualTimeZone=" + mSuggestManualTimeZone + ", mSuggestManualTimeZone=" + mSuggestManualTimeZone Loading @@ -196,16 +239,18 @@ public final class TimeZoneCapabilities implements Parcelable { /** @hide */ /** @hide */ public static class Builder { public static class Builder { private final @UserIdInt int mUserId; private TimeZoneConfiguration mConfiguration; private @CapabilityState int mConfigureAutoDetectionEnabled; private @CapabilityState int mConfigureAutoDetectionEnabled; private @CapabilityState int mConfigureGeoDetectionEnabled; private @CapabilityState int mConfigureGeoDetectionEnabled; private @CapabilityState int mSuggestManualTimeZone; private @CapabilityState int mSuggestManualTimeZone; /** /** Sets the user-visible configuration settings. */ * Creates a new Builder with no properties set. public Builder setConfiguration(@NonNull TimeZoneConfiguration configuration) { */ if (!configuration.isComplete()) { public Builder(@UserIdInt int userId) { throw new IllegalArgumentException(configuration + " is not complete"); mUserId = userId; } this.mConfiguration = configuration; return this; } } /** Sets the state for the automatic time zone detection enabled config. */ /** Sets the state for the automatic time zone detection enabled config. */ Loading
core/java/android/app/timezonedetector/TimeZoneConfiguration.java +86 −62 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.app.timezonedetector; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.StringDef; import android.annotation.StringDef; import android.annotation.UserIdInt; import android.os.Bundle; import android.os.Bundle; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; Loading @@ -27,21 +28,20 @@ import java.lang.annotation.RetentionPolicy; import java.util.Objects; import java.util.Objects; /** /** * Configuration that controls the behavior of the time zone detector associated with a specific * User visible settings that control the behavior of the time zone detector / manual time zone * user. * entry. * * * <p>Configuration consists of a set of known properties. When reading configuration via * <p>When reading the configuration, values for all settings will be provided. In some cases, such * {@link TimeZoneDetector#getConfiguration()} values for all known properties will be provided. In * as when the device behavior relies on optional hardware / OEM configuration, or the value of * some cases, such as when the configuration relies on optional hardware, the values may be * several settings, the device behavior may not be directly affected by the setting value. * meaningless / defaulted to safe values. * * * <p>Configuration properties can be left absent when updating configuration via {@link * <p>Settings can be left absent when updating configuration via {@link * TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and those values will not be * TimeZoneDetector#updateConfiguration(TimeZoneConfiguration)} and those settings will not be * changed. Not all configuration properties can be modified by all users. See {@link * changed. Not all configuration settings can be modified by all users: see {@link * TimeZoneDetector#getCapabilities()} and {@link TimeZoneCapabilities}. * TimeZoneDetector#getCapabilities()} and {@link TimeZoneCapabilities} for details. * * * <p>See {@link #isComplete()} to tell if all known properties are present, and {@link * <p>See {@link #hasSetting(String)} with {@code PROPERTY_} constants for testing for the presence * #hasProperty(String)} with {@code PROPERTY_} constants for testing individual properties. * of individual settings. * * * @hide * @hide */ */ Loading @@ -59,80 +59,82 @@ public final class TimeZoneConfiguration implements Parcelable { }; }; /** All configuration properties */ /** All configuration properties */ @StringDef(PROPERTY_AUTO_DETECTION_ENABLED) @StringDef({ SETTING_AUTO_DETECTION_ENABLED, SETTING_GEO_DETECTION_ENABLED }) @Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE) @interface Property {} @interface Setting {} /** See {@link TimeZoneConfiguration#isAutoDetectionEnabled()} for details. */ /** See {@link TimeZoneConfiguration#isAutoDetectionEnabled()} for details. */ @Property @Setting public static final String PROPERTY_AUTO_DETECTION_ENABLED = "autoDetectionEnabled"; public static final String SETTING_AUTO_DETECTION_ENABLED = "autoDetectionEnabled"; /** See {@link TimeZoneConfiguration#isGeoDetectionEnabled()} for details. */ /** See {@link TimeZoneConfiguration#isGeoDetectionEnabled()} for details. */ @Property @Setting public static final String PROPERTY_GEO_DETECTION_ENABLED = "geoDetectionEnabled"; public static final String SETTING_GEO_DETECTION_ENABLED = "geoDetectionEnabled"; private final Bundle mBundle; private final @UserIdInt int mUserId; @NonNull private final Bundle mBundle; private TimeZoneConfiguration(Builder builder) { private TimeZoneConfiguration(Builder builder) { this.mBundle = builder.mBundle; this.mUserId = builder.mUserId; this.mBundle = Objects.requireNonNull(builder.mBundle); } } private static TimeZoneConfiguration createFromParcel(Parcel in) { private static TimeZoneConfiguration createFromParcel(Parcel in) { return new TimeZoneConfiguration.Builder() return new TimeZoneConfiguration.Builder(in.readInt()) .setPropertyBundleInternal(in.readBundle()) .setPropertyBundleInternal(in.readBundle()) .build(); .build(); } } @Override @Override public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(mUserId); dest.writeBundle(mBundle); dest.writeBundle(mBundle); } } /** Returns {@code true} if all known properties are set. */ /** Returns the ID of the user this configuration is associated with. */ public @UserIdInt int getUserId() { return mUserId; } /** Returns {@code true} if all known settings are present. */ public boolean isComplete() { public boolean isComplete() { return hasProperty(PROPERTY_AUTO_DETECTION_ENABLED) return hasSetting(SETTING_AUTO_DETECTION_ENABLED) && hasProperty(PROPERTY_GEO_DETECTION_ENABLED); && hasSetting(SETTING_GEO_DETECTION_ENABLED); } } /** Returns true if the specified property is set. */ /** Returns true if the specified setting is set. */ public boolean hasProperty(@Property String property) { public boolean hasSetting(@Setting String setting) { return mBundle.containsKey(property); return mBundle.containsKey(setting); } } /** /** * Returns the value of the {@link #PROPERTY_AUTO_DETECTION_ENABLED} property. This * Returns the value of the {@link #SETTING_AUTO_DETECTION_ENABLED} setting. This * controls whether a device will attempt to determine the time zone automatically using * controls whether a device will attempt to determine the time zone automatically using * contextual information. * contextual information if the device supports auto detection. * * <p>This setting is global and can be updated by some users. * * * @throws IllegalStateException if the field has not been set * @throws IllegalStateException if the setting has not been set */ */ public boolean isAutoDetectionEnabled() { public boolean isAutoDetectionEnabled() { if (!mBundle.containsKey(PROPERTY_AUTO_DETECTION_ENABLED)) { enforceSettingPresent(SETTING_AUTO_DETECTION_ENABLED); throw new IllegalStateException(PROPERTY_AUTO_DETECTION_ENABLED + " is not set"); return mBundle.getBoolean(SETTING_AUTO_DETECTION_ENABLED); } return mBundle.getBoolean(PROPERTY_AUTO_DETECTION_ENABLED); } } /** /** * Returns the value of the {@link #PROPERTY_GEO_DETECTION_ENABLED} property. This * Returns the value of the {@link #SETTING_GEO_DETECTION_ENABLED} setting. This * controls whether a device can use location to determine time zone. Only used when * controls whether a device can use geolocation to determine time zone. Only used when * {@link #isAutoDetectionEnabled()} is true. * {@link #isAutoDetectionEnabled()} is {@code true} and when the user has allowed their * location to be used. * * <p>This setting is user-scoped and can be updated by some users. * See {@link TimeZoneCapabilities#getConfigureGeoDetectionEnabled()}. * * * @throws IllegalStateException if the field has not been set * @throws IllegalStateException if the setting has not been set */ */ public boolean isGeoDetectionEnabled() { public boolean isGeoDetectionEnabled() { if (!mBundle.containsKey(PROPERTY_GEO_DETECTION_ENABLED)) { enforceSettingPresent(SETTING_GEO_DETECTION_ENABLED); throw new IllegalStateException(PROPERTY_GEO_DETECTION_ENABLED + " is not set"); return mBundle.getBoolean(SETTING_GEO_DETECTION_ENABLED); } return mBundle.getBoolean(PROPERTY_GEO_DETECTION_ENABLED); } /** * Convenience method to merge this with another. The argument configuration properties have * precedence. */ public TimeZoneConfiguration with(TimeZoneConfiguration other) { return new Builder(this).mergeProperties(other).build(); } } @Override @Override Loading @@ -149,43 +151,61 @@ public final class TimeZoneConfiguration implements Parcelable { return false; return false; } } TimeZoneConfiguration that = (TimeZoneConfiguration) o; TimeZoneConfiguration that = (TimeZoneConfiguration) o; return mBundle.kindofEquals(that.mBundle); return mUserId == that.mUserId && mBundle.kindofEquals(that.mBundle); } } @Override @Override public int hashCode() { public int hashCode() { return Objects.hash(mBundle); return Objects.hash(mUserId, mBundle); } } @Override @Override public String toString() { public String toString() { return "TimeZoneDetectorConfiguration{" return "TimeZoneDetectorConfiguration{" + "mUserId=" + mUserId + "mBundle=" + mBundle + "mBundle=" + mBundle + '}'; + '}'; } } private void enforceSettingPresent(@Setting String setting) { if (!mBundle.containsKey(setting)) { throw new IllegalStateException(setting + " is not set"); } } /** @hide */ /** @hide */ public static class Builder { public static class Builder { private Bundle mBundle = new Bundle(); private final @UserIdInt int mUserId; private final Bundle mBundle = new Bundle(); /** /** * Creates a new Builder with no properties set. * Creates a new Builder for a userId with no settings held. */ */ public Builder() {} public Builder(@UserIdInt int userId) { mUserId = userId; } /** /** * Creates a new Builder by copying properties from an existing instance. * Creates a new Builder by copying the user ID and settings from an existing instance. */ */ public Builder(TimeZoneConfiguration toCopy) { public Builder(TimeZoneConfiguration toCopy) { this.mUserId = toCopy.mUserId; mergeProperties(toCopy); mergeProperties(toCopy); } } /** /** * Merges {@code other} properties into this instances, replacing existing values in this * Merges {@code other} settings into this instances, replacing existing values in this * where the properties appear in both. * where the settings appear in both. */ */ public Builder mergeProperties(TimeZoneConfiguration other) { public Builder mergeProperties(TimeZoneConfiguration other) { if (mUserId != other.mUserId) { throw new IllegalArgumentException( "Cannot merge configurations for different user IDs." + " this.mUserId=" + this.mUserId + ", other.mUserId=" + other.mUserId); } this.mBundle.putAll(other.mBundle); this.mBundle.putAll(other.mBundle); return this; return this; } } Loading @@ -195,15 +215,19 @@ public final class TimeZoneConfiguration implements Parcelable { return this; return this; } } /** Sets the desired state of the automatic time zone detection property. */ /** * Sets the state of the {@link #SETTING_AUTO_DETECTION_ENABLED} setting. */ public Builder setAutoDetectionEnabled(boolean enabled) { public Builder setAutoDetectionEnabled(boolean enabled) { this.mBundle.putBoolean(PROPERTY_AUTO_DETECTION_ENABLED, enabled); this.mBundle.putBoolean(SETTING_AUTO_DETECTION_ENABLED, enabled); return this; return this; } } /** Sets the desired state of the geolocation time zone detection enabled property. */ /** * Sets the state of the {@link #SETTING_GEO_DETECTION_ENABLED} setting. */ public Builder setGeoDetectionEnabled(boolean enabled) { public Builder setGeoDetectionEnabled(boolean enabled) { this.mBundle.putBoolean(PROPERTY_GEO_DETECTION_ENABLED, enabled); this.mBundle.putBoolean(SETTING_GEO_DETECTION_ENABLED, enabled); return this; return this; } } Loading
core/java/android/app/timezonedetector/TimeZoneDetector.java +20 −22 File changed.Preview size limit exceeded, changes collapsed. Show changes