Source:
<code>public void testLocationAllDisabled() throws Exception { assertTrue("Screen is off", getPowerManager().isInteractive()); assertFalse(getPowerManager().isPowerSaveMode()); assertEquals(PowerManager.LOCATION_MODE_NO_CHANGE, getPowerManager().getLocationPowerSaveMode()); assertEquals(0, getLocationGlobalKillSwitch()); putSecureSetting(LOCATION_PROVIDERS_ALLOWED, "+gps"); assertNotEquals(LOCATION_MODE_OFF, getLocationMode()); assertTrue(getLocationManager().isLocationEnabled()); runDumpsysBatteryUnplug(); enableBatterySaver(true); final int mode = getPowerManager().getLocationPowerSaveMode(); if (mode != PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF) { Log.i(TAG, "Unexpected location power save mode (" + mode + "), skipping."); Log.i(TAG, "Deactivate battery saver."); <START> enableBatterySaver(false); <END> return; } assertTrue(getPowerManager().isInteractive()); assertEquals(0, getLocationGlobalKillSwitch()); assertNotEquals(LOCATION_MODE_OFF, getLocationMode()); assertTrue(getLocationManager().isLocationEnabled()); runWithExpectingLocationCallback(() -> { turnOnScreen(false); waitUntil("Kill switch still off", () -> getLocationGlobalKillSwitch() == 1); assertEquals(LOCATION_MODE_OFF, getLocationMode()); assertFalse(getLocationManager().isLocationEnabled()); }); runWithExpectingLocationCallback(() -> { turnOnScreen(true); waitUntil("Kill switch still off", () -> getLocationGlobalKillSwitch() == 0); assertNotEquals(LOCATION_MODE_OFF, getLocationMode()); assertTrue(getLocationManager().isLocationEnabled()); }); runWithExpectingLocationCallback(() -> { turnOnScreen(false); waitUntil("Kill switch still off", () -> getLocationGlobalKillSwitch() == 1); assertEquals(LOCATION_MODE_OFF, getLocationMode()); assertFalse(getLocationManager().isLocationEnabled()); }); runWithExpectingLocationCallback(() -> { enableBatterySaver(false); waitUntil("Kill switch still on", () -> getLocationGlobalKillSwitch() == 0); assertNotEquals(LOCATION_MODE_OFF, getLocationMode()); assertTrue(getLocationManager().isLocationEnabled()); }); }</code><technical_language>do in BatterySavingTestBase.mInitializeAndCleanupRule.onAfter(), runDumpsysBatteryReset() instead</technical_language>

Target:
public void testLocationAllDisabled() throws Exception { assertTrue("Screen is off", getPowerManager().isInteractive()); assertFalse(getPowerManager().isPowerSaveMode()); assertEquals(PowerManager.LOCATION_MODE_NO_CHANGE, getPowerManager().getLocationPowerSaveMode()); assertEquals(0, getLocationGlobalKillSwitch()); putSecureSetting(LOCATION_PROVIDERS_ALLOWED, "+gps"); assertNotEquals(LOCATION_MODE_OFF, getLocationMode()); assertTrue(getLocationManager().isLocationEnabled()); runDumpsysBatteryUnplug(); enableBatterySaver(true); final int mode = getPowerManager().getLocationPowerSaveMode(); if (mode != PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF) { Log.i(TAG, "Unexpected location power save mode (" + mode + "), skipping."); return; } assertTrue(getPowerManager().isInteractive()); assertEquals(0, getLocationGlobalKillSwitch()); assertNotEquals(LOCATION_MODE_OFF, getLocationMode()); assertTrue(getLocationManager().isLocationEnabled()); runWithExpectingLocationCallback(() -> { turnOnScreen(false); waitUntil("Kill switch still off", () -> getLocationGlobalKillSwitch() == 1); assertEquals(LOCATION_MODE_OFF, getLocationMode()); assertFalse(getLocationManager().isLocationEnabled()); }); runWithExpectingLocationCallback(() -> { turnOnScreen(true); waitUntil("Kill switch still off", () -> getLocationGlobalKillSwitch() == 0); assertNotEquals(LOCATION_MODE_OFF, getLocationMode()); assertTrue(getLocationManager().isLocationEnabled()); }); runWithExpectingLocationCallback(() -> { turnOnScreen(false); waitUntil("Kill switch still off", () -> getLocationGlobalKillSwitch() == 1); assertEquals(LOCATION_MODE_OFF, getLocationMode()); assertFalse(getLocationManager().isLocationEnabled()); }); runWithExpectingLocationCallback(() -> { enableBatterySaver(false); waitUntil("Kill switch still on", () -> getLocationGlobalKillSwitch() == 0); assertNotEquals(LOCATION_MODE_OFF, getLocationMode()); assertTrue(getLocationManager().isLocationEnabled()); }); }