From 75fb864e80c34a9e06e669ed31b68e3ef68ce4d6 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Thu, 1 Oct 2015 10:24:31 -0700 Subject: [PATCH] DO NOT MERGE Introduce direct listener API for alarm delivery The Alarm Manager now supports a set() variant that takes a listener callback to invoke at alarm trigger time rather than a PendingIntent. This is much lower overhead and has guaranteed low delivery latency from the trigger time. The tradeoff is that the app must be running *continuously* from the time the alarm is set to the time it is delivered. If the app exits for any reason before the alarm fires, the listener becomes invalid and the alarm will be dropped. This is more or less equivalent to setting an alarm with a broadcast PendingIntent that matches only a runtime-registered receiver. The app's alarm listener can be any object that implements the new AlarmManager.OnAlarmListener interface and implements its onAlarm() method. There is no data delivered at alarm trigger time: whatever state needs to be associated with the specific alarm instance should simply be packaged inside the OnAlarmListener instance. An alarm using OnAlarmListener can request that the onAlarm() method be called on an arbitrary handler. If the program passes 'null' for this parameter when setting the alarm, the callback occurs on the application's main Looper thread. Cherry-picked from b481a892d219fdfc7562b2441b8f720759d6f902 Bug 20157436 Change-Id: I2eb030a24efdd466a2eee1666c5231201b43684b --- .../src/com/android/server/NetworkStatsServiceTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java index 90b4f43c8e..c12f978d02 100644 --- a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java @@ -876,11 +876,12 @@ public class NetworkStatsServiceTest extends AndroidTestCase { } private void expectSystemReady() throws Exception { - mAlarmManager.remove(isA(PendingIntent.class)); + mAlarmManager.remove(isA(PendingIntent.class), null); expectLastCall().anyTimes(); - mAlarmManager.set(eq(AlarmManager.ELAPSED_REALTIME), anyLong(), anyLong(), anyLong(), - anyInt(), isA(PendingIntent.class), isA(WorkSource.class), + mAlarmManager.set(getContext().getPackageName(), + eq(AlarmManager.ELAPSED_REALTIME), anyLong(), anyLong(), anyLong(), + anyInt(), isA(PendingIntent.class), null, null, isA(WorkSource.class), isA(AlarmManager.AlarmClockInfo.class)); expectLastCall().atLeastOnce();