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

Commit cff5b6bf authored by Neil Fuller's avatar Neil Fuller Committed by Automerger Merge Worker
Browse files

Merge "Implement flag for auto tz detection default" into udc-dev am: 0f2e4e24

parents bbdf36b9 0f2e4e24
Loading
Loading
Loading
Loading
+31 −2
Original line number Original line Diff line number Diff line
@@ -11849,7 +11849,13 @@ public final class Settings {
        /**
        /**
         * Value to specify if the device's UTC system clock should be set automatically, e.g. using
         * Value to specify if the device's UTC system clock should be set automatically, e.g. using
         * telephony signals like NITZ, or other sources like GNSS or NTP. 1=yes, 0=no (manual)
         * telephony signals like NITZ, or other sources like GNSS or NTP.
         *
         * <p>Prefer {@link android.app.time.TimeManager} API calls to determine the state of
         * automatic time detection instead of directly observing this setting as it may be ignored
         * by the time_detector service under various conditions.
         *
         * <p>1=yes, 0=no (manual)
         */
         */
        @Readable
        @Readable
        public static final String AUTO_TIME = "auto_time";
        public static final String AUTO_TIME = "auto_time";
@@ -11857,11 +11863,34 @@ public final class Settings {
        /**
        /**
         * Value to specify if the device's time zone system property should be set automatically,
         * Value to specify if the device's time zone system property should be set automatically,
         * e.g. using telephony signals like MCC and NITZ, or other mechanisms like the location.
         * e.g. using telephony signals like MCC and NITZ, or other mechanisms like the location.
         * 1=yes, 0=no (manual).
         *
         * <p>Prefer {@link android.app.time.TimeManager} API calls to determine the state of
         * automatic time zone detection instead of directly observing this setting as it may be
         * ignored by the time_zone_detector service under various conditions.
         *
         * <p>1=yes, 0=no (manual).
         */
         */
        @Readable
        @Readable
        public static final String AUTO_TIME_ZONE = "auto_time_zone";
        public static final String AUTO_TIME_ZONE = "auto_time_zone";
        /**
         * Records whether an explicit preference for {@link #AUTO_TIME_ZONE} has been expressed
         * instead of the current value being the default. This value is used to tell if the {@link
         * #AUTO_TIME_ZONE} value can be influenced by experiment flags that alter the setting's
         * value for internal testers: once the user indicates a preference they leave the
         * experiment, only users that are still using the default will be affected by the flag.
         *
         * <p>Since {@link #AUTO_TIME_ZONE} can be altered by components besides the system server,
         * and not just via the time_zone_detector logic that sets this value, this isn't guaranteed
         * to be set when the device diverges from the default in all cases. Important AOSP system
         * components like SettingsUI do use the time_zone_detector APIs.
         *
         * <p>1="has been set explicitly"
         *
         * @hide
         */
        public static final String AUTO_TIME_ZONE_EXPLICIT = "auto_time_zone_explicit";
        /**
        /**
         * URI for the car dock "in" event sound.
         * URI for the car dock "in" event sound.
         * @hide
         * @hide
+1 −0
Original line number Original line Diff line number Diff line
@@ -137,6 +137,7 @@ public class SettingsBackupTest {
                    Settings.Global.AUTOFILL_LOGGING_LEVEL,
                    Settings.Global.AUTOFILL_LOGGING_LEVEL,
                    Settings.Global.AUTOFILL_MAX_PARTITIONS_SIZE,
                    Settings.Global.AUTOFILL_MAX_PARTITIONS_SIZE,
                    Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS,
                    Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS,
                    Settings.Global.AUTO_TIME_ZONE_EXPLICIT,
                    Settings.Global.AVERAGE_TIME_TO_DISCHARGE,
                    Settings.Global.AVERAGE_TIME_TO_DISCHARGE,
                    Settings.Global.BATTERY_CHARGING_STATE_UPDATE_DELAY,
                    Settings.Global.BATTERY_CHARGING_STATE_UPDATE_DELAY,
                    Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME,
                    Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME,
+9 −0
Original line number Original line Diff line number Diff line
@@ -69,6 +69,7 @@ public final class ServerFlags {
            KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT,
            KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT,
            KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE,
            KEY_TIME_DETECTOR_LOWER_BOUND_MILLIS_OVERRIDE,
            KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE,
            KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE,
            KEY_TIME_ZONE_DETECTOR_AUTO_DETECTION_ENABLED_DEFAULT,
            KEY_TIME_ZONE_DETECTOR_TELEPHONY_FALLBACK_SUPPORTED,
            KEY_TIME_ZONE_DETECTOR_TELEPHONY_FALLBACK_SUPPORTED,
            KEY_ENHANCED_METRICS_COLLECTION_ENABLED,
            KEY_ENHANCED_METRICS_COLLECTION_ENABLED,
    })
    })
@@ -153,6 +154,14 @@ public final class ServerFlags {
            KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT =
            KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT =
            "location_time_zone_detection_setting_enabled_default";
            "location_time_zone_detection_setting_enabled_default";


    /**
     * The key to alter a device's "automatic time zone detection enabled" setting default value.
     * This flag is only intended for internal testing.
     */
    public static final @DeviceConfigKey String
            KEY_TIME_ZONE_DETECTOR_AUTO_DETECTION_ENABLED_DEFAULT =
            "time_zone_detector_auto_detection_enabled_default";

    /**
    /**
     * The key to control support for time zone detection falling back to telephony detection under
     * The key to control support for time zone detection falling back to telephony detection under
     * certain circumstances.
     * certain circumstances.
+45 −11
Original line number Original line Diff line number Diff line
@@ -64,6 +64,7 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
            ServerFlags.KEY_ENHANCED_METRICS_COLLECTION_ENABLED,
            ServerFlags.KEY_ENHANCED_METRICS_COLLECTION_ENABLED,
            ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT,
            ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT,
            ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE,
            ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE,
            ServerFlags.KEY_TIME_ZONE_DETECTOR_AUTO_DETECTION_ENABLED_DEFAULT,
            ServerFlags.KEY_TIME_ZONE_DETECTOR_TELEPHONY_FALLBACK_SUPPORTED
            ServerFlags.KEY_TIME_ZONE_DETECTOR_TELEPHONY_FALLBACK_SUPPORTED
    );
    );


@@ -174,7 +175,7 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
            }
            }
        }, filter, null, null /* main thread */);
        }, filter, null, null /* main thread */);


        // Add async callbacks for global settings being changed.
        // Add async callbacks for changes to global settings that influence behavior.
        ContentResolver contentResolver = mContext.getContentResolver();
        ContentResolver contentResolver = mContext.getContentResolver();
        ContentObserver contentObserver = new ContentObserver(mContext.getMainThreadHandler()) {
        ContentObserver contentObserver = new ContentObserver(mContext.getMainThreadHandler()) {
            @Override
            @Override
@@ -184,6 +185,9 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
        };
        };
        contentResolver.registerContentObserver(
        contentResolver.registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.AUTO_TIME_ZONE), true, contentObserver);
                Settings.Global.getUriFor(Settings.Global.AUTO_TIME_ZONE), true, contentObserver);
        contentResolver.registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.AUTO_TIME_ZONE_EXPLICIT), true,
                contentObserver);


        // Add async callbacks for user scoped location settings being changed.
        // Add async callbacks for user scoped location settings being changed.
        contentResolver.registerContentObserver(
        contentResolver.registerContentObserver(
@@ -239,8 +243,9 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {


    @Override
    @Override
    public synchronized boolean updateConfiguration(@UserIdInt int userId,
    public synchronized boolean updateConfiguration(@UserIdInt int userId,
            @NonNull TimeZoneConfiguration requestedConfiguration, boolean bypassUserPolicyChecks) {
            @NonNull TimeZoneConfiguration requestedConfigurationUpdates,
        Objects.requireNonNull(requestedConfiguration);
            boolean bypassUserPolicyChecks) {
        Objects.requireNonNull(requestedConfigurationUpdates);


        ConfigurationInternal configurationInternal = getConfigurationInternal(userId);
        ConfigurationInternal configurationInternal = getConfigurationInternal(userId);
        TimeZoneCapabilities capabilities =
        TimeZoneCapabilities capabilities =
@@ -248,7 +253,7 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
        TimeZoneConfiguration oldConfiguration = configurationInternal.asConfiguration();
        TimeZoneConfiguration oldConfiguration = configurationInternal.asConfiguration();


        final TimeZoneConfiguration newConfiguration =
        final TimeZoneConfiguration newConfiguration =
                capabilities.tryApplyConfigChanges(oldConfiguration, requestedConfiguration);
                capabilities.tryApplyConfigChanges(oldConfiguration, requestedConfigurationUpdates);
        if (newConfiguration == null) {
        if (newConfiguration == null) {
            // The changes could not be made because the user's capabilities do not allow it.
            // The changes could not be made because the user's capabilities do not allow it.
            return false;
            return false;
@@ -256,7 +261,7 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {


        // Store the configuration / notify as needed. This will cause the mEnvironment to invoke
        // Store the configuration / notify as needed. This will cause the mEnvironment to invoke
        // handleConfigChanged() asynchronously.
        // handleConfigChanged() asynchronously.
        storeConfiguration(userId, newConfiguration);
        storeConfiguration(userId, requestedConfigurationUpdates, newConfiguration);


        return true;
        return true;
    }
    }
@@ -268,15 +273,20 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
     */
     */
    @GuardedBy("this")
    @GuardedBy("this")
    private void storeConfiguration(@UserIdInt int userId,
    private void storeConfiguration(@UserIdInt int userId,
            @NonNull TimeZoneConfiguration configuration) {
            @NonNull TimeZoneConfiguration requestedConfigurationUpdates,
        Objects.requireNonNull(configuration);
            @NonNull TimeZoneConfiguration newConfiguration) {
        Objects.requireNonNull(newConfiguration);


        // Avoid writing the auto detection enabled setting for devices that do not support auto
        // Avoid writing the auto detection enabled setting for devices that do not support auto
        // time zone detection: if we wrote it down then we'd set the value explicitly, which would
        // time zone detection: if we wrote it down then we'd set the value explicitly, which would
        // prevent detecting "default" later. That might influence what happens on later releases
        // prevent detecting "default" later. That might influence what happens on later releases
        // that support new types of auto detection on the same hardware.
        // that support new types of auto detection on the same hardware.
        if (isAutoDetectionFeatureSupported()) {
        if (isAutoDetectionFeatureSupported()) {
            final boolean autoDetectionEnabled = configuration.isAutoDetectionEnabled();
            if (requestedConfigurationUpdates.hasIsAutoDetectionEnabled()) {
                // Record that the auto detection enabled setting has now been set explicitly.
                Settings.Global.putInt(mCr, Settings.Global.AUTO_TIME_ZONE_EXPLICIT, 1);
            }
            final boolean autoDetectionEnabled = newConfiguration.isAutoDetectionEnabled();
            setAutoDetectionEnabledIfRequired(autoDetectionEnabled);
            setAutoDetectionEnabledIfRequired(autoDetectionEnabled);


            // Only write the geo detection enabled setting when its values is used, e.g.:
            // Only write the geo detection enabled setting when its values is used, e.g.:
@@ -288,10 +298,10 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
            // Not being able to detect if the user has actually expressed a preference could
            // Not being able to detect if the user has actually expressed a preference could
            // influence what happens on later releases that start to support geo detection on the
            // influence what happens on later releases that start to support geo detection on the
            // user's same hardware.
            // user's same hardware.
            if (!getGeoDetectionSettingEnabledOverride().isPresent()
            if (getGeoDetectionSettingEnabledOverride().isEmpty()
                    && isGeoTimeZoneDetectionFeatureSupported()
                    && isGeoTimeZoneDetectionFeatureSupported()
                    && isTelephonyTimeZoneDetectionFeatureSupported()) {
                    && isTelephonyTimeZoneDetectionFeatureSupported()) {
                final boolean geoDetectionEnabledSetting = configuration.isGeoDetectionEnabled();
                final boolean geoDetectionEnabledSetting = newConfiguration.isGeoDetectionEnabled();
                setGeoDetectionEnabledSettingIfRequired(userId, geoDetectionEnabledSetting);
                setGeoDetectionEnabledSettingIfRequired(userId, geoDetectionEnabledSetting);
            }
            }
        }
        }
@@ -335,7 +345,31 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
    }
    }


    private boolean getAutoDetectionEnabledSetting() {
    private boolean getAutoDetectionEnabledSetting() {
        return Settings.Global.getInt(mCr, Settings.Global.AUTO_TIME_ZONE, 1 /* default */) > 0;
        boolean autoDetectionEnabledSetting =
                Settings.Global.getInt(mCr, Settings.Global.AUTO_TIME_ZONE, 1 /* default */) > 0;

        Optional<Boolean> optionalFlagValue = mServerFlags.getOptionalBoolean(
                ServerFlags.KEY_TIME_ZONE_DETECTOR_AUTO_DETECTION_ENABLED_DEFAULT);
        if (optionalFlagValue.isPresent()) {
            // This branch is rare: it is expected to happen only for internal testers.

            if (Settings.Global.getInt(mCr, Settings.Global.AUTO_TIME_ZONE_EXPLICIT, 0) == 0) {
                // The device hasn't explicitly had the auto detection enabled setting updated via a
                // call to storeConfiguration(). This means the device is allowed to use a server
                // flag to determine the default.
                boolean flagValue = optionalFlagValue.get();

                // Best effort to keep the setting in sync with the flag in case something is
                // observing the (public API) Settings.Global.AUTO_TIME_ZONE directly. This change
                // will cause listeners to fire asynchronously but any cascade should stop after one
                // round.
                if (flagValue != autoDetectionEnabledSetting) {
                    Settings.Global.putInt(mCr, Settings.Global.AUTO_TIME_ZONE, flagValue ? 1 : 0);
                }
                autoDetectionEnabledSetting = flagValue;
            }
        }
        return autoDetectionEnabledSetting;
    }
    }


    private boolean getGeoDetectionEnabledSetting(@UserIdInt int userId) {
    private boolean getGeoDetectionEnabledSetting(@UserIdInt int userId) {
+5 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import static com.android.server.timedetector.ServerFlags.KEY_LOCATION_TIME_ZONE
import static com.android.server.timedetector.ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_RUN_IN_BACKGROUND_ENABLED;
import static com.android.server.timedetector.ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_RUN_IN_BACKGROUND_ENABLED;
import static com.android.server.timedetector.ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT;
import static com.android.server.timedetector.ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT;
import static com.android.server.timedetector.ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE;
import static com.android.server.timedetector.ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE;
import static com.android.server.timedetector.ServerFlags.KEY_TIME_ZONE_DETECTOR_AUTO_DETECTION_ENABLED_DEFAULT;
import static com.android.server.timedetector.ServerFlags.KEY_TIME_ZONE_DETECTOR_TELEPHONY_FALLBACK_SUPPORTED;
import static com.android.server.timedetector.ServerFlags.KEY_TIME_ZONE_DETECTOR_TELEPHONY_FALLBACK_SUPPORTED;


import android.app.time.LocationTimeZoneManager;
import android.app.time.LocationTimeZoneManager;
@@ -308,6 +309,10 @@ class TimeZoneDetectorShellCommand extends ShellCommand {
        pw.printf("  %s\n", KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE);
        pw.printf("  %s\n", KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE);
        pw.printf("    Used to override the device's 'geolocation time zone detection enabled'"
        pw.printf("    Used to override the device's 'geolocation time zone detection enabled'"
                + " setting [*].\n");
                + " setting [*].\n");
        pw.printf("  %s\n", KEY_TIME_ZONE_DETECTOR_AUTO_DETECTION_ENABLED_DEFAULT);
        pw.printf("    Used to set the automatic time zone detection enabled default, i.e. when the"
                + " device's automatic time zone detection enabled setting hasn't been set"
                + " explicitly. Intended for internal testers.");
        pw.printf("  %s\n", KEY_TIME_ZONE_DETECTOR_TELEPHONY_FALLBACK_SUPPORTED);
        pw.printf("  %s\n", KEY_TIME_ZONE_DETECTOR_TELEPHONY_FALLBACK_SUPPORTED);
        pw.printf("    Used to enable / disable support for telephony detection fallback. Also see"
        pw.printf("    Used to enable / disable support for telephony detection fallback. Also see"
                + " the %s command.\n", SHELL_COMMAND_ENABLE_TELEPHONY_FALLBACK);
                + " the %s command.\n", SHELL_COMMAND_ENABLE_TELEPHONY_FALLBACK);