diff options
Diffstat (limited to 'core/java/android/app/AlarmManager.java')
| -rw-r--r-- | core/java/android/app/AlarmManager.java | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/core/java/android/app/AlarmManager.java b/core/java/android/app/AlarmManager.java index c561a1908b21..3221c5d89543 100644 --- a/core/java/android/app/AlarmManager.java +++ b/core/java/android/app/AlarmManager.java @@ -16,6 +16,7 @@ package android.app; +import android.annotation.IntDef; import android.annotation.SdkConstant; import android.annotation.SystemApi; import android.content.Context; @@ -34,6 +35,8 @@ import android.util.Log; import libcore.util.ZoneInfoDB; import java.io.IOException; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; /** * This class provides access to the system alarm services. These allow you @@ -78,6 +81,16 @@ import java.io.IOException; public class AlarmManager { private static final String TAG = "AlarmManager"; + /** @hide */ + @IntDef(prefix = { "RTC", "ELAPSED" }, value = { + RTC_WAKEUP, + RTC, + ELAPSED_REALTIME_WAKEUP, + ELAPSED_REALTIME, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface AlarmType {} + /** * Alarm time in {@link System#currentTimeMillis System.currentTimeMillis()} * (wall clock time in UTC), which will wake up the device when @@ -311,8 +324,7 @@ public class AlarmManager { * will be treated as exact. * </div> * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should go * off, using the appropriate clock (depending on the alarm type). * @param operation Action to perform when the alarm goes off; @@ -332,7 +344,7 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void set(int type, long triggerAtMillis, PendingIntent operation) { + public void set(@AlarmType int type, long triggerAtMillis, PendingIntent operation) { setImpl(type, triggerAtMillis, legacyExactLength(), 0, 0, operation, null, null, null, null, null); } @@ -346,8 +358,7 @@ public class AlarmManager { * invoked via the specified target Handler, or on the application's main looper * if {@code null} is passed as the {@code targetHandler} parameter. * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should go * off, using the appropriate clock (depending on the alarm type). * @param tag string describing the alarm, used for logging and battery-use @@ -360,7 +371,7 @@ public class AlarmManager { * @param targetHandler {@link Handler} on which to execute the listener's onAlarm() * callback, or {@code null} to run that callback on the main looper. */ - public void set(int type, long triggerAtMillis, String tag, OnAlarmListener listener, + public void set(@AlarmType int type, long triggerAtMillis, String tag, OnAlarmListener listener, Handler targetHandler) { setImpl(type, triggerAtMillis, legacyExactLength(), 0, 0, null, listener, tag, targetHandler, null, null); @@ -399,8 +410,7 @@ public class AlarmManager { * whose {@code targetSdkVersion} is earlier than API 19 will continue to have all * of their alarms, including repeating alarms, treated as exact. * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should first * go off, using the appropriate clock (depending on the alarm type). * @param intervalMillis interval in milliseconds between subsequent repeats @@ -422,7 +432,7 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void setRepeating(int type, long triggerAtMillis, + public void setRepeating(@AlarmType int type, long triggerAtMillis, long intervalMillis, PendingIntent operation) { setImpl(type, triggerAtMillis, legacyExactLength(), intervalMillis, 0, operation, null, null, null, null, null); @@ -448,8 +458,7 @@ public class AlarmManager { * at precisely-specified times with no acceptable variation, applications can use * {@link #setExact(int, long, PendingIntent)}. * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param windowStartMillis The earliest time, in milliseconds, that the alarm should * be delivered, expressed in the appropriate clock's units (depending on the alarm * type). @@ -473,7 +482,7 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void setWindow(int type, long windowStartMillis, long windowLengthMillis, + public void setWindow(@AlarmType int type, long windowStartMillis, long windowLengthMillis, PendingIntent operation) { setImpl(type, windowStartMillis, windowLengthMillis, 0, 0, operation, null, null, null, null, null); @@ -488,7 +497,7 @@ public class AlarmManager { * invoked via the specified target Handler, or on the application's main looper * if {@code null} is passed as the {@code targetHandler} parameter. */ - public void setWindow(int type, long windowStartMillis, long windowLengthMillis, + public void setWindow(@AlarmType int type, long windowStartMillis, long windowLengthMillis, String tag, OnAlarmListener listener, Handler targetHandler) { setImpl(type, windowStartMillis, windowLengthMillis, 0, 0, null, listener, tag, targetHandler, null, null); @@ -508,8 +517,7 @@ public class AlarmManager { * scheduled as exact. Applications are strongly discouraged from using exact * alarms unnecessarily as they reduce the OS's ability to minimize battery use. * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should go * off, using the appropriate clock (depending on the alarm type). * @param operation Action to perform when the alarm goes off; @@ -528,7 +536,7 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void setExact(int type, long triggerAtMillis, PendingIntent operation) { + public void setExact(@AlarmType int type, long triggerAtMillis, PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, 0, operation, null, null, null, null, null); } @@ -542,8 +550,8 @@ public class AlarmManager { * invoked via the specified target Handler, or on the application's main looper * if {@code null} is passed as the {@code targetHandler} parameter. */ - public void setExact(int type, long triggerAtMillis, String tag, OnAlarmListener listener, - Handler targetHandler) { + public void setExact(@AlarmType int type, long triggerAtMillis, String tag, + OnAlarmListener listener, Handler targetHandler) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, 0, null, listener, tag, targetHandler, null, null); } @@ -553,8 +561,8 @@ public class AlarmManager { * the given time. * @hide */ - public void setIdleUntil(int type, long triggerAtMillis, String tag, OnAlarmListener listener, - Handler targetHandler) { + public void setIdleUntil(@AlarmType int type, long triggerAtMillis, String tag, + OnAlarmListener listener, Handler targetHandler) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, FLAG_IDLE_UNTIL, null, listener, tag, targetHandler, null, null); } @@ -590,8 +598,8 @@ public class AlarmManager { /** @hide */ @SystemApi - public void set(int type, long triggerAtMillis, long windowMillis, long intervalMillis, - PendingIntent operation, WorkSource workSource) { + public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, + long intervalMillis, PendingIntent operation, WorkSource workSource) { setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, operation, null, null, null, workSource, null); } @@ -606,8 +614,9 @@ public class AlarmManager { * * @hide */ - public void set(int type, long triggerAtMillis, long windowMillis, long intervalMillis, - String tag, OnAlarmListener listener, Handler targetHandler, WorkSource workSource) { + public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, + long intervalMillis, String tag, OnAlarmListener listener, Handler targetHandler, + WorkSource workSource) { setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, tag, targetHandler, workSource, null); } @@ -623,15 +632,17 @@ public class AlarmManager { * @hide */ @SystemApi - public void set(int type, long triggerAtMillis, long windowMillis, long intervalMillis, - OnAlarmListener listener, Handler targetHandler, WorkSource workSource) { + public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, + long intervalMillis, OnAlarmListener listener, Handler targetHandler, + WorkSource workSource) { setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, null, targetHandler, workSource, null); } - private void setImpl(int type, long triggerAtMillis, long windowMillis, long intervalMillis, - int flags, PendingIntent operation, final OnAlarmListener listener, String listenerTag, - Handler targetHandler, WorkSource workSource, AlarmClockInfo alarmClock) { + private void setImpl(@AlarmType int type, long triggerAtMillis, long windowMillis, + long intervalMillis, int flags, PendingIntent operation, final OnAlarmListener listener, + String listenerTag, Handler targetHandler, WorkSource workSource, + AlarmClockInfo alarmClock) { if (triggerAtMillis < 0) { /* NOTYET if (mAlwaysExact) { @@ -728,8 +739,7 @@ public class AlarmManager { * assured that it will get similar behavior on both current and older versions * of Android. * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should first * go off, using the appropriate clock (depending on the alarm type). This * is inexact: the alarm will not fire before this time, but there may be a @@ -763,7 +773,7 @@ public class AlarmManager { * @see #INTERVAL_HALF_DAY * @see #INTERVAL_DAY */ - public void setInexactRepeating(int type, long triggerAtMillis, + public void setInexactRepeating(@AlarmType int type, long triggerAtMillis, long intervalMillis, PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, intervalMillis, 0, operation, null, null, null, null, null); @@ -795,8 +805,7 @@ public class AlarmManager { * <p>Regardless of the app's target SDK version, this call always allows batching of the * alarm.</p> * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should go * off, using the appropriate clock (depending on the alarm type). * @param operation Action to perform when the alarm goes off; @@ -814,7 +823,8 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void setAndAllowWhileIdle(int type, long triggerAtMillis, PendingIntent operation) { + public void setAndAllowWhileIdle(@AlarmType int type, long triggerAtMillis, + PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, 0, FLAG_ALLOW_WHILE_IDLE, operation, null, null, null, null, null); } @@ -848,8 +858,7 @@ public class AlarmManager { * device is idle it may take even more liberties with scheduling in order to optimize * for battery life.</p> * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should go * off, using the appropriate clock (depending on the alarm type). * @param operation Action to perform when the alarm goes off; @@ -868,7 +877,8 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void setExactAndAllowWhileIdle(int type, long triggerAtMillis, PendingIntent operation) { + public void setExactAndAllowWhileIdle(@AlarmType int type, long triggerAtMillis, + PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, FLAG_ALLOW_WHILE_IDLE, operation, null, null, null, null, null); } |
