From 9d3bbc82a06d902d04b8ffaecdd9c1503f8b9a71 Mon Sep 17 00:00:00 2001 From: Kurt Partridge Date: Sun, 14 Apr 2013 12:27:29 -0700 Subject: [PATCH] Fix alarm bug The AlarmManager takes absolute times as an argument, not durations. Change-Id: I419434ba5908c5f4070608070bbecf753088ecc8 --- .../inputmethod/research/UploaderService.java | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/java/src/com/android/inputmethod/research/UploaderService.java b/java/src/com/android/inputmethod/research/UploaderService.java index 6a9717b7c..d2db34927 100644 --- a/java/src/com/android/inputmethod/research/UploaderService.java +++ b/java/src/com/android/inputmethod/research/UploaderService.java @@ -22,6 +22,7 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.os.SystemClock; import com.android.inputmethod.latin.define.ProductionFlag; @@ -79,28 +80,14 @@ public final class UploaderService extends IntentService { */ public static void cancelAndRescheduleUploadingService(final Context context, final boolean needsRescheduling) { - final PendingIntent pendingIntent = getPendingIntentForService(context); + final Intent intent = new Intent(context, UploaderService.class); + final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0); final AlarmManager alarmManager = (AlarmManager) context.getSystemService( Context.ALARM_SERVICE); - cancelAnyScheduledServiceAlarm(alarmManager, pendingIntent); + alarmManager.cancel(pendingIntent); if (needsRescheduling) { - scheduleServiceAlarm(alarmManager, pendingIntent); + alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + + UploaderService.RUN_INTERVAL, pendingIntent); } } - - private static PendingIntent getPendingIntentForService(final Context context) { - final Intent intent = new Intent(context, UploaderService.class); - return PendingIntent.getService(context, 0, intent, 0); - } - - private static void cancelAnyScheduledServiceAlarm(final AlarmManager alarmManager, - final PendingIntent pendingIntent) { - alarmManager.cancel(pendingIntent); - } - - private static void scheduleServiceAlarm(final AlarmManager alarmManager, - final PendingIntent pendingIntent) { - alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, UploaderService.RUN_INTERVAL, - pendingIntent); - } }