From 314b35644b59a4d2f1dfa44afc9e7a2cd85da6fd Mon Sep 17 00:00:00 2001 From: Kate Montgomery Date: Wed, 14 Jul 2021 12:19:12 +0000 Subject: Do not specify a workSource when setting a delayed alarm so that the alarm can still wake the device up when the device is idle as the AlarmManager.FLAG_ALLOW_WHILE_IDLE_UNRESTRICTED flag indicates. Bug: 188302603,193260066 Test: presubmits Change-Id: I2cc8f7bb49d626644f9b4257b04f4f8ea5fc3d2f --- .../android/server/location/injector/AlarmHelper.java | 1 - .../location/provider/LocationProviderManager.java | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/location/injector/AlarmHelper.java b/services/core/java/com/android/server/location/injector/AlarmHelper.java index f3fb9c84273b..91a1042d9625 100644 --- a/services/core/java/com/android/server/location/injector/AlarmHelper.java +++ b/services/core/java/com/android/server/location/injector/AlarmHelper.java @@ -33,7 +33,6 @@ public abstract class AlarmHelper { WorkSource workSource) { // helps ensure that we're not wasting system resources by setting alarms in the past/now Preconditions.checkArgument(delayMs > 0); - Preconditions.checkArgument(workSource != null); setDelayedAlarmInternal(delayMs, listener, workSource); } diff --git a/services/core/java/com/android/server/location/provider/LocationProviderManager.java b/services/core/java/com/android/server/location/provider/LocationProviderManager.java index 6d7f79250715..290f8edbd373 100644 --- a/services/core/java/com/android/server/location/provider/LocationProviderManager.java +++ b/services/core/java/com/android/server/location/provider/LocationProviderManager.java @@ -705,8 +705,12 @@ public class LocationProviderManager extends if (mExpirationRealtimeMs <= registerTimeMs) { onAlarm(); } else if (mExpirationRealtimeMs < Long.MAX_VALUE) { + // Set WorkSource to null in order to ensure the alarm wakes up the device even when + // it is idle. Do this when the cost of waking up the device is less than the power + // cost of not performing the actions set off by the alarm, such as unregistering a + // location request. mAlarmHelper.setDelayedAlarm(mExpirationRealtimeMs - registerTimeMs, this, - getRequest().getWorkSource()); + null); } // start listening for provider enabled/disabled events @@ -1092,8 +1096,12 @@ public class LocationProviderManager extends if (mExpirationRealtimeMs <= registerTimeMs) { onAlarm(); } else if (mExpirationRealtimeMs < Long.MAX_VALUE) { + // Set WorkSource to null in order to ensure the alarm wakes up the device even when + // it is idle. Do this when the cost of waking up the device is less than the power + // cost of not performing the actions set off by the alarm, such as unregistering a + // location request. mAlarmHelper.setDelayedAlarm(mExpirationRealtimeMs - registerTimeMs, this, - getRequest().getWorkSource()); + null); } } @@ -1955,7 +1963,11 @@ public class LocationProviderManager extends } } }; - mAlarmHelper.setDelayedAlarm(delayMs, mDelayedRegister, newRequest.getWorkSource()); + // Set WorkSource to null in order to ensure the alarm wakes up the device even when it + // is idle. Do this when the cost of waking up the device is less than the power cost of + // not performing the actions set off by the alarm, such as unregistering a location + // request. + mAlarmHelper.setDelayedAlarm(delayMs, mDelayedRegister, null); } return true; -- cgit v1.2.3-59-g8ed1b