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

Commit c22a335f authored by Neil Fuller's avatar Neil Fuller
Browse files

"Run in background" less aggressively

"Run location time zone detection algorithm in background" less
aggressively.

In a recent bug affecting a teamfooder, they were expecting that
toggling auto tz would force the time zone detector to forget previous
suggestions. Because "run in background" was enabled, this didn't have
the result they expected as the location-based time zone detection
algorithm just kept running. We get to define/change what this internal
testing flag does and it's not widely used and behavior is arbitrary so
this commit changes that behavior.

Testing:
$ adb shell cmd device_config put system_time location_time_zone_detection_run_in_background_enabled true
$ adb shell dumpsys time_zone_detector
<Toggle auto tz>
$ adb shell dumpsys time_zone_detector

...before and after.

Bug: 267788915
Test: Manual testing described above + treehugger
Test: atest services/tests/servicestests/src/com/android/server/timezonedetector/ConfigurationInternalTest.java
Test: atest services/tests/servicestests/src/com/android/server/timezonedetector/location/LocationTimeZoneProviderControllerTest.java
Change-Id: I2b2700b61f7977beb93a6060708cc34763e2b0a5
parent bac13cfa
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();
    }

@@ -431,9 +432,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(