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

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

Merge ""Run in background" less aggressively"

parents dfd697ec c22a335f
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -104,10 +104,10 @@ public final class ConfigurationInternal {
    }

    /**
     * Returns {@code true} if location time zone detection should run all the time on supported
     * devices, even when the user has not enabled it explicitly in settings. Enabled for internal
     * testing only. See {@link #isGeoDetectionExecutionEnabled()} and {@link #getDetectionMode()}
     * for details.
     * Returns {@code true} if location time zone detection should run when auto time zone detection
     * is enabled on supported devices, even when the user has not enabled the algorithm explicitly
     * in settings. Enabled for internal testing only. See {@link #isGeoDetectionExecutionEnabled()}
     * and {@link #getDetectionMode()} for details.
     */
    boolean getGeoDetectionRunInBackgroundEnabledSetting() {
        return mGeoDetectionRunInBackgroundEnabled;
@@ -219,6 +219,7 @@ public final class ConfigurationInternal {
    private boolean getGeoDetectionRunInBackgroundEnabledBehavior() {
        return isGeoDetectionSupported()
                && getLocationEnabledSetting()
                && getAutoDetectionEnabledSetting()
                && getGeoDetectionRunInBackgroundEnabledSetting();
    }

@@ -433,9 +434,9 @@ public final class ConfigurationInternal {
        }

        /**
         * Sets whether location time zone detection should run all the time on supported devices,
         * even when the user has not enabled it explicitly in settings. Enabled for internal
         * testing only.
         * Sets whether location time zone detection should run when auto time zone detection is
         * enabled on supported devices, even when the user has not enabled the algorithm explicitly
         * in settings. Enabled for internal testing only.
         */
        public Builder setGeoDetectionRunInBackgroundEnabled(boolean enabled) {
            mGeoDetectionRunInBackgroundEnabled = enabled;
+1 −1
Original line number Diff line number Diff line
@@ -570,7 +570,7 @@ public class ConfigurationInternalTest {
                    .setAutoDetectionEnabledSetting(false)
                    .build();
            assertFalse(config.getAutoDetectionEnabledBehavior());
            assertTrue(config.isGeoDetectionExecutionEnabled());
            assertFalse(config.isGeoDetectionExecutionEnabled());
            assertEquals(DETECTION_MODE_MANUAL, config.getDetectionMode());
        }
    }
+34 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.service.timezone.TimeZoneProviderStatus.OPERATION_STATUS_O
import static android.service.timezone.TimeZoneProviderStatus.OPERATION_STATUS_UNKNOWN;

import static com.android.server.timezonedetector.ConfigurationInternal.DETECTION_MODE_MANUAL;
import static com.android.server.timezonedetector.ConfigurationInternal.DETECTION_MODE_TELEPHONY;
import static com.android.server.timezonedetector.location.LocationTimeZoneProvider.ProviderState.PROVIDER_STATE_DESTROYED;
import static com.android.server.timezonedetector.location.LocationTimeZoneProvider.ProviderState.PROVIDER_STATE_PERM_FAILED;
import static com.android.server.timezonedetector.location.LocationTimeZoneProvider.ProviderState.PROVIDER_STATE_STARTED_CERTAIN;
@@ -1384,6 +1385,37 @@ public class LocationTimeZoneProviderControllerTest {
        assertFalse(controller.isUncertaintyTimeoutSet());
    }

    /**
     * A controller-state-only test to prove that "run in background" doesn't enable the
     * location-based time zone detection algorithm to run when auto detection is disabled.
     */
    @Test
    public void geoDetectionRunInBackground_obeysAutoDetectionDisabled() {
        LocationTimeZoneProviderController controller = new LocationTimeZoneProviderController(
                mTestThreadingDomain, mTestMetricsLogger, mTestPrimaryLocationTimeZoneProvider,
                mTestSecondaryLocationTimeZoneProvider, false /* recordStateChanges */);

        // A configuration where the user has auto detection disabled.
        ConfigurationInternal autoTimeZoneDisabledConfig =
                new ConfigurationInternal.Builder(USER1_CONFIG_GEO_DETECTION_DISABLED)
                        .setLocationEnabledSetting(true)
                        .setAutoDetectionEnabledSetting(false)
                        .setGeoDetectionEnabledSetting(true)
                        .setGeoDetectionRunInBackgroundEnabled(true)
                        .build();
        assertEquals(DETECTION_MODE_MANUAL, autoTimeZoneDisabledConfig.getDetectionMode());
        assertFalse(autoTimeZoneDisabledConfig.isGeoDetectionExecutionEnabled());

        TestEnvironment testEnvironment = new TestEnvironment(
                mTestThreadingDomain, controller, autoTimeZoneDisabledConfig);

        // Initialize and check initial state.
        controller.initialize(testEnvironment, mTestCallback);

        assertControllerState(controller, STATE_STOPPED);
        mTestMetricsLogger.assertStateChangesAndCommit(STATE_PROVIDERS_INITIALIZING, STATE_STOPPED);
    }

    /**
     * A controller-state-only test to prove that "run in background" configuration behaves as
     * intended. Provider states are well covered by other "enabled" tests.
@@ -1398,7 +1430,7 @@ public class LocationTimeZoneProviderControllerTest {
        ConfigurationInternal runInBackgroundDisabledConfig =
                new ConfigurationInternal.Builder(USER1_CONFIG_GEO_DETECTION_DISABLED)
                        .setLocationEnabledSetting(true)
                        .setAutoDetectionEnabledSetting(false)
                        .setAutoDetectionEnabledSetting(true)
                        .setGeoDetectionEnabledSetting(false)
                        .setGeoDetectionRunInBackgroundEnabled(false)
                        .build();
@@ -1408,7 +1440,7 @@ public class LocationTimeZoneProviderControllerTest {
                new ConfigurationInternal.Builder(runInBackgroundDisabledConfig)
                        .setGeoDetectionRunInBackgroundEnabled(true)
                        .build();
        assertEquals(DETECTION_MODE_MANUAL, runInBackgroundEnabledConfig.getDetectionMode());
        assertEquals(DETECTION_MODE_TELEPHONY, runInBackgroundEnabledConfig.getDetectionMode());
        assertTrue(runInBackgroundEnabledConfig.isGeoDetectionExecutionEnabled());

        TestEnvironment testEnvironment = new TestEnvironment(