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

Commit 4e8f77b9 authored by Geoffrey Boullanger's avatar Geoffrey Boullanger
Browse files

Added the skeleton to allow for the tracking and notifying of time zone changes

BYPASS_LARGE_CHANGE_WARNING

Design doc: go/android-tznotifications

Test: existing atest still pass and device runs normally
Bug: 283267917
Flag: com.android.server.flags.datetime_notifications

Change-Id: Ib0eac05eca1c802fec0bd053e3a74dc5265972a9
parent 40a39e23
Loading
Loading
Loading
Loading
+52 −9
Original line number Diff line number Diff line
@@ -55,7 +55,8 @@ public final class TimeZoneCapabilities implements Parcelable {
     * The user the capabilities are for. This is used for object equality and debugging but there
     * is no accessor.
     */
    @NonNull private final UserHandle mUserHandle;
    @NonNull
    private final UserHandle mUserHandle;
    private final @CapabilityState int mConfigureAutoDetectionEnabledCapability;

    /**
@@ -69,6 +70,7 @@ public final class TimeZoneCapabilities implements Parcelable {

    private final @CapabilityState int mConfigureGeoDetectionEnabledCapability;
    private final @CapabilityState int mSetManualTimeZoneCapability;
    private final @CapabilityState int mConfigureNotificationsEnabledCapability;

    private TimeZoneCapabilities(@NonNull Builder builder) {
        this.mUserHandle = Objects.requireNonNull(builder.mUserHandle);
@@ -78,6 +80,8 @@ public final class TimeZoneCapabilities implements Parcelable {
        this.mConfigureGeoDetectionEnabledCapability =
                builder.mConfigureGeoDetectionEnabledCapability;
        this.mSetManualTimeZoneCapability = builder.mSetManualTimeZoneCapability;
        this.mConfigureNotificationsEnabledCapability =
                builder.mConfigureNotificationsEnabledCapability;
    }

    @NonNull
@@ -88,6 +92,7 @@ public final class TimeZoneCapabilities implements Parcelable {
                .setUseLocationEnabled(in.readBoolean())
                .setConfigureGeoDetectionEnabledCapability(in.readInt())
                .setSetManualTimeZoneCapability(in.readInt())
                .setConfigureNotificationsEnabledCapability(in.readInt())
                .build();
    }

@@ -98,6 +103,7 @@ public final class TimeZoneCapabilities implements Parcelable {
        dest.writeBoolean(mUseLocationEnabled);
        dest.writeInt(mConfigureGeoDetectionEnabledCapability);
        dest.writeInt(mSetManualTimeZoneCapability);
        dest.writeInt(mConfigureNotificationsEnabledCapability);
    }

    /**
@@ -117,8 +123,8 @@ public final class TimeZoneCapabilities implements Parcelable {
     *
     * Not part of the SDK API because it is intended for use by SettingsUI, which can display
     * text about needing it to be on for location-based time zone detection.
     * @hide
     *
     * @hide
     */
    public boolean isUseLocationEnabled() {
        return mUseLocationEnabled;
@@ -147,6 +153,18 @@ public final class TimeZoneCapabilities implements Parcelable {
        return mSetManualTimeZoneCapability;
    }

    /**
     * Returns the capability state associated with the user's ability to modify the time zone
     * notification setting. The setting can be updated via {@link
     * TimeManager#updateTimeZoneConfiguration(TimeZoneConfiguration)}.
     *
     * @hide
     */
    @CapabilityState
    public int getConfigureNotificationsEnabledCapability() {
        return mConfigureNotificationsEnabledCapability;
    }

    /**
     * Tries to create a new {@link TimeZoneConfiguration} from the {@code config} and the set of
     * {@code requestedChanges}, if {@code this} capabilities allow. The new configuration is
@@ -174,6 +192,12 @@ public final class TimeZoneCapabilities implements Parcelable {
            newConfigBuilder.setGeoDetectionEnabled(requestedChanges.isGeoDetectionEnabled());
        }

        if (requestedChanges.hasIsNotificationsEnabled()) {
            if (this.getConfigureNotificationsEnabledCapability() < CAPABILITY_NOT_APPLICABLE) {
                return null;
            }
            newConfigBuilder.setNotificationsEnabled(requestedChanges.areNotificationsEnabled());
        }
        return newConfigBuilder.build();
    }

@@ -197,13 +221,16 @@ public final class TimeZoneCapabilities implements Parcelable {
                && mUseLocationEnabled == that.mUseLocationEnabled
                && mConfigureGeoDetectionEnabledCapability
                == that.mConfigureGeoDetectionEnabledCapability
                && mSetManualTimeZoneCapability == that.mSetManualTimeZoneCapability;
                && mSetManualTimeZoneCapability == that.mSetManualTimeZoneCapability
                && mConfigureNotificationsEnabledCapability
                == that.mConfigureNotificationsEnabledCapability;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mUserHandle, mConfigureAutoDetectionEnabledCapability,
                mConfigureGeoDetectionEnabledCapability, mSetManualTimeZoneCapability);
                mConfigureGeoDetectionEnabledCapability, mSetManualTimeZoneCapability,
                mConfigureNotificationsEnabledCapability);
    }

    @Override
@@ -216,6 +243,8 @@ public final class TimeZoneCapabilities implements Parcelable {
                + ", mConfigureGeoDetectionEnabledCapability="
                + mConfigureGeoDetectionEnabledCapability
                + ", mSetManualTimeZoneCapability=" + mSetManualTimeZoneCapability
                + ", mConfigureNotificationsEnabledCapability="
                + mConfigureNotificationsEnabledCapability
                + '}';
    }

@@ -226,11 +255,13 @@ public final class TimeZoneCapabilities implements Parcelable {
     */
    public static class Builder {

        @NonNull private UserHandle mUserHandle;
        @NonNull
        private UserHandle mUserHandle;
        private @CapabilityState int mConfigureAutoDetectionEnabledCapability;
        private Boolean mUseLocationEnabled;
        private @CapabilityState int mConfigureGeoDetectionEnabledCapability;
        private @CapabilityState int mSetManualTimeZoneCapability;
        private @CapabilityState int mConfigureNotificationsEnabledCapability;

        public Builder(@NonNull UserHandle userHandle) {
            mUserHandle = Objects.requireNonNull(userHandle);
@@ -246,6 +277,8 @@ public final class TimeZoneCapabilities implements Parcelable {
                    capabilitiesToCopy.mConfigureGeoDetectionEnabledCapability;
            mSetManualTimeZoneCapability =
                    capabilitiesToCopy.mSetManualTimeZoneCapability;
            mConfigureNotificationsEnabledCapability =
                    capabilitiesToCopy.mConfigureNotificationsEnabledCapability;
        }

        /** Sets the value for the "configure automatic time zone detection enabled" capability. */
@@ -274,6 +307,14 @@ public final class TimeZoneCapabilities implements Parcelable {
            return this;
        }

        /**
         * Sets the value for the "configure time notifications enabled" capability.
         */
        public Builder setConfigureNotificationsEnabledCapability(@CapabilityState int value) {
            this.mConfigureNotificationsEnabledCapability = value;
            return this;
        }

        /** Returns the {@link TimeZoneCapabilities}. */
        @NonNull
        public TimeZoneCapabilities build() {
@@ -283,7 +324,9 @@ public final class TimeZoneCapabilities implements Parcelable {
            verifyCapabilitySet(mConfigureGeoDetectionEnabledCapability,
                    "configureGeoDetectionEnabledCapability");
            verifyCapabilitySet(mSetManualTimeZoneCapability,
                    "mSetManualTimeZoneCapability");
                    "setManualTimeZoneCapability");
            verifyCapabilitySet(mConfigureNotificationsEnabledCapability,
                    "configureNotificationsEnabledCapability");
            return new TimeZoneCapabilities(this);
        }

+46 −4
Original line number Diff line number Diff line
@@ -62,7 +62,8 @@ public final class TimeZoneConfiguration implements Parcelable {
     *
     * @hide
     */
    @StringDef({ SETTING_AUTO_DETECTION_ENABLED, SETTING_GEO_DETECTION_ENABLED })
    @StringDef({SETTING_AUTO_DETECTION_ENABLED, SETTING_GEO_DETECTION_ENABLED,
            SETTING_NOTIFICATIONS_ENABLED})
    @Retention(RetentionPolicy.SOURCE)
    @interface Setting {}

@@ -74,6 +75,10 @@ public final class TimeZoneConfiguration implements Parcelable {
    @Setting
    private static final String SETTING_GEO_DETECTION_ENABLED = "geoDetectionEnabled";

    /** See {@link TimeZoneConfiguration#areNotificationsEnabled()} for details. */
    @Setting
    private static final String SETTING_NOTIFICATIONS_ENABLED = "notificationsEnabled";

    @NonNull private final Bundle mBundle;

    private TimeZoneConfiguration(Builder builder) {
@@ -98,7 +103,8 @@ public final class TimeZoneConfiguration implements Parcelable {
     */
    public boolean isComplete() {
        return hasIsAutoDetectionEnabled()
                && hasIsGeoDetectionEnabled();
                && hasIsGeoDetectionEnabled()
                && hasIsNotificationsEnabled();
    }

    /**
@@ -128,8 +134,7 @@ public final class TimeZoneConfiguration implements Parcelable {
    /**
     * Returns the value of the {@link #SETTING_GEO_DETECTION_ENABLED} setting. This
     * controls whether the device can use geolocation to determine time zone. This value may only
     * be used by Android under some circumstances. For example, it is not used when
     * {@link #isGeoDetectionEnabled()} is {@code false}.
     * be used by Android under some circumstances.
     *
     * <p>See {@link TimeZoneCapabilities#getConfigureGeoDetectionEnabledCapability()} for how to
     * tell if the setting is meaningful for the current user at this time.
@@ -150,6 +155,32 @@ public final class TimeZoneConfiguration implements Parcelable {
        return mBundle.containsKey(SETTING_GEO_DETECTION_ENABLED);
    }

    /**
     * Returns the value of the {@link #SETTING_NOTIFICATIONS_ENABLED} setting. This controls
     * whether the device can send time and time zone related notifications. This value may only
     * be used by Android under some circumstances.
     *
     * <p>See {@link TimeZoneCapabilities#getConfigureNotificationsEnabledCapability()} ()} for how
     * to tell if the setting is meaningful for the current user at this time.
     *
     * @throws IllegalStateException if the setting is not present
     *
     * @hide
     */
    public boolean areNotificationsEnabled() {
        enforceSettingPresent(SETTING_NOTIFICATIONS_ENABLED);
        return mBundle.getBoolean(SETTING_NOTIFICATIONS_ENABLED);
    }

    /**
     * Returns {@code true} if the {@link #areNotificationsEnabled()} setting is present.
     *
     * @hide
     */
    public boolean hasIsNotificationsEnabled() {
        return mBundle.containsKey(SETTING_NOTIFICATIONS_ENABLED);
    }

    @Override
    public int describeContents() {
        return 0;
@@ -244,6 +275,17 @@ public final class TimeZoneConfiguration implements Parcelable {
            return this;
        }

        /**
         * Sets the state of the {@link #SETTING_NOTIFICATIONS_ENABLED} setting.         *
         *
         * @hide
         */
        @NonNull
        public Builder setNotificationsEnabled(boolean enabled) {
            this.mBundle.putBoolean(SETTING_NOTIFICATIONS_ENABLED, enabled);
            return this;
        }

        /** Returns the {@link TimeZoneConfiguration}. */
        @NonNull
        public TimeZoneConfiguration build() {
+10 −0
Original line number Diff line number Diff line
@@ -13346,6 +13346,16 @@ public final class Settings {
         */
        public static final String AUTO_TIME_ZONE_EXPLICIT = "auto_time_zone_explicit";
        /**
         * Value to specify if the device should send notifications when {@link #AUTO_TIME_ZONE} is
         * on and the device's time zone changes.
         *
         * <p>1=yes, 0=no.
         *
         * @hide
         */
        public static final String TIME_ZONE_NOTIFICATIONS = "time_zone_notifications";
        /**
         * URI for the car dock "in" event sound.
         * @hide
+7 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ public class SystemNotificationChannels {
    public static final String NETWORK_ALERTS = "NETWORK_ALERTS";
    public static final String NETWORK_AVAILABLE = "NETWORK_AVAILABLE";
    public static final String VPN = "VPN";
    public static final String TIME = "TIME";
    /**
     * @deprecated Legacy device admin channel with low importance which is no longer used,
     *  Use the high importance {@link #DEVICE_ADMIN} channel instead.
@@ -145,6 +146,12 @@ public class SystemNotificationChannels {
                NotificationManager.IMPORTANCE_LOW);
        channelsList.add(vpn);

        final NotificationChannel time = new NotificationChannel(
                TIME,
                context.getString(R.string.notification_channel_system_time),
                NotificationManager.IMPORTANCE_DEFAULT);
        channelsList.add(time);

        final NotificationChannel deviceAdmin = new NotificationChannel(
                DEVICE_ADMIN,
                getDeviceAdminNotificationChannelName(context),
+12 −0
Original line number Diff line number Diff line
@@ -2083,6 +2083,18 @@
         See com.android.server.timezonedetector.TimeZoneDetectorStrategy for more information. -->
    <bool name="config_supportTelephonyTimeZoneFallback" translatable="false">true</bool>

    <!-- Whether the time notifications feature is enabled. Settings this to false means the feature
         cannot be used. Setting this to true means the feature can be enabled on the device. -->
    <bool name="config_enableTimeZoneNotificationsSupported" translatable="false">true</bool>

    <!-- Whether the time zone notifications tracking feature is enabled. Settings this to false
         means the feature cannot be used. -->
    <bool name="config_enableTimeZoneNotificationsTrackingSupported" translatable="false">true</bool>

    <!-- Whether the time zone manual change tracking feature is enabled. Settings this to false
         means the feature cannot be used. -->
    <bool name="config_enableTimeZoneManualChangeTrackingSupported" translatable="false">true</bool>

    <!-- Whether to enable network location overlay which allows network location provider to be
         replaced by an app at run-time. When disabled, only the
         config_networkLocationProviderPackageName package will be searched for network location
Loading