Use an exact alarm for location timeout.

Use an exact alarm for the location timeout to avoid keeping the GPS
active for too long.

Bug: 194385761
Test: atest DeviceIdleTest
Test: atest FrameworksMockingServicesTests:DeviceIdleControllerTest
Change-Id: I52b7ec6d993705ee605e3780a29a484c0d48e633
This commit is contained in:
Kweku Adams
2021-08-16 08:49:37 -07:00
parent 2486a5f188
commit a7cb583f3a
2 changed files with 5 additions and 0 deletions

View File

@@ -3941,6 +3941,10 @@ public class DeviceIdleController extends SystemService
if (idleUntil) {
mAlarmManager.setIdleUntil(AlarmManager.ELAPSED_REALTIME_WAKEUP,
mNextAlarmTime, "DeviceIdleController.deep", mDeepAlarmListener, mHandler);
} else if (mState == STATE_LOCATING) {
// Use setExact so we don't keep the GPS active for too long.
mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP,
mNextAlarmTime, "DeviceIdleController.deep", mDeepAlarmListener, mHandler);
} else {
if (mConstants.USE_WINDOW_ALARMS) {
mAlarmManager.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP,

View File

@@ -323,6 +323,7 @@ public class DeviceIdleControllerTest {
when(mPowerManager.newWakeLock(anyInt(), anyString())).thenReturn(mWakeLock);
doNothing().when(mWakeLock).acquire();
doNothing().when(mAlarmManager).set(anyInt(), anyLong(), anyString(), any(), any());
doNothing().when(mAlarmManager).setExact(anyInt(), anyLong(), anyString(), any(), any());
doNothing().when(mAlarmManager)
.setWindow(anyInt(), anyLong(), anyLong(), anyString(), any(), any());
doReturn(mock(Sensor.class)).when(mSensorManager)