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

Commit 08589876 authored by Neil Fuller's avatar Neil Fuller Committed by Android (Google) Code Review
Browse files

Merge "Fix non-deterministic async test"

parents 3c2ca66a 18a02895
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@ public final class TimeZoneDetectorCallbackImpl implements TimeZoneDetectorStrat
        // that support new types of auto detection on the same hardware.
        if (isAutoDetectionSupported()) {
            final boolean autoDetectionEnabled = configuration.isAutoDetectionEnabled();
            setAutoDetectionEnabled(autoDetectionEnabled);
            setAutoDetectionEnabledIfRequired(autoDetectionEnabled);

            // Avoid writing the geo detection enabled setting for devices that do not support geo
            // time zone detection: if we wrote it down then we'd set the value explicitly, which
@@ -176,7 +176,7 @@ public final class TimeZoneDetectorCallbackImpl implements TimeZoneDetectorStrat
            // releases that support geo detection on the same hardware.
            if (isGeoDetectionSupported()) {
                final boolean geoTzDetectionEnabled = configuration.isGeoDetectionEnabled();
                setGeoDetectionEnabled(userId, geoTzDetectionEnabled);
                setGeoDetectionEnabledIfRequired(userId, geoTzDetectionEnabled);
            }
        }
    }
@@ -198,9 +198,15 @@ public final class TimeZoneDetectorCallbackImpl implements TimeZoneDetectorStrat
        return Settings.Global.getInt(mCr, Settings.Global.AUTO_TIME_ZONE, 1 /* default */) > 0;
    }

    private void setAutoDetectionEnabled(boolean enabled) {
    private void setAutoDetectionEnabledIfRequired(boolean enabled) {
        // This check is racey, but the whole settings update process is racey. This check prevents
        // a ConfigurationChangeListener callback triggering due to ContentObserver's still
        // triggering *sometimes* for no-op updates. Because callbacks are async this is necessary
        // for stable behavior during tests.
        if (isAutoDetectionEnabled() != enabled) {
            Settings.Global.putInt(mCr, Settings.Global.AUTO_TIME_ZONE, enabled ? 1 : 0);
        }
    }

    private boolean isLocationEnabled(@UserIdInt int userId) {
        return mLocationManager.isLocationEnabledForUser(UserHandle.of(userId));
@@ -213,10 +219,13 @@ public final class TimeZoneDetectorCallbackImpl implements TimeZoneDetectorStrat
                (geoDetectionEnabledByDefault ? 1 : 0) /* defaultValue */, userId) != 0;
    }

    private void setGeoDetectionEnabled(@UserIdInt int userId, boolean enabled) {
    private void setGeoDetectionEnabledIfRequired(@UserIdInt int userId, boolean enabled) {
        // See comment in setAutoDetectionEnabledIfRequired. http://b/171953500
        if (isGeoDetectionEnabled(userId) != enabled) {
            Settings.Secure.putIntForUser(mCr, Settings.Secure.LOCATION_TIME_ZONE_DETECTION_ENABLED,
                    enabled ? 1 : 0, userId);
        }
    }

    private boolean deviceHasTelephonyNetwork() {
        // TODO b/150583524 Avoid the use of a deprecated API.