1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.app; 18 19 import android.annotation.IntDef; 20 import android.annotation.RequiresPermission; 21 import android.annotation.SdkConstant; 22 import android.annotation.SystemApi; 23 import android.annotation.SystemService; 24 import android.compat.annotation.UnsupportedAppUsage; 25 import android.content.Context; 26 import android.content.Intent; 27 import android.os.Build; 28 import android.os.Handler; 29 import android.os.Parcel; 30 import android.os.Parcelable; 31 import android.os.RemoteException; 32 import android.os.WorkSource; 33 import android.text.TextUtils; 34 import android.util.Log; 35 import android.util.proto.ProtoOutputStream; 36 37 import libcore.timezone.ZoneInfoDb; 38 39 import java.io.IOException; 40 import java.lang.annotation.Retention; 41 import java.lang.annotation.RetentionPolicy; 42 import java.lang.ref.WeakReference; 43 import java.util.WeakHashMap; 44 45 /** 46 * This class provides access to the system alarm services. These allow you 47 * to schedule your application to be run at some point in the future. When 48 * an alarm goes off, the {@link Intent} that had been registered for it 49 * is broadcast by the system, automatically starting the target application 50 * if it is not already running. Registered alarms are retained while the 51 * device is asleep (and can optionally wake the device up if they go off 52 * during that time), but will be cleared if it is turned off and rebooted. 53 * 54 * <p>The Alarm Manager holds a CPU wake lock as long as the alarm receiver's 55 * onReceive() method is executing. This guarantees that the phone will not sleep 56 * until you have finished handling the broadcast. Once onReceive() returns, the 57 * Alarm Manager releases this wake lock. This means that the phone will in some 58 * cases sleep as soon as your onReceive() method completes. If your alarm receiver 59 * called {@link android.content.Context#startService Context.startService()}, it 60 * is possible that the phone will sleep before the requested service is launched. 61 * To prevent this, your BroadcastReceiver and Service will need to implement a 62 * separate wake lock policy to ensure that the phone continues running until the 63 * service becomes available. 64 * 65 * <p><b>Note: The Alarm Manager is intended for cases where you want to have 66 * your application code run at a specific time, even if your application is 67 * not currently running. For normal timing operations (ticks, timeouts, 68 * etc) it is easier and much more efficient to use 69 * {@link android.os.Handler}.</b> 70 * 71 * <p class="caution"><strong>Note:</strong> Beginning with API 19 72 * ({@link android.os.Build.VERSION_CODES#KITKAT}) alarm delivery is inexact: 73 * the OS will shift alarms in order to minimize wakeups and battery use. There are 74 * new APIs to support applications which need strict delivery guarantees; see 75 * {@link #setWindow(int, long, long, PendingIntent)} and 76 * {@link #setExact(int, long, PendingIntent)}. Applications whose {@code targetSdkVersion} 77 * is earlier than API 19 will continue to see the previous behavior in which all 78 * alarms are delivered exactly when requested. 79 */ 80 @SystemService(Context.ALARM_SERVICE) 81 public class AlarmManager { 82 private static final String TAG = "AlarmManager"; 83 84 /** @hide */ 85 @IntDef(prefix = { "RTC", "ELAPSED" }, value = { 86 RTC_WAKEUP, 87 RTC, 88 ELAPSED_REALTIME_WAKEUP, 89 ELAPSED_REALTIME, 90 }) 91 @Retention(RetentionPolicy.SOURCE) 92 public @interface AlarmType {} 93 94 /** 95 * Alarm time in {@link System#currentTimeMillis System.currentTimeMillis()} 96 * (wall clock time in UTC), which will wake up the device when 97 * it goes off. 98 */ 99 public static final int RTC_WAKEUP = 0; 100 /** 101 * Alarm time in {@link System#currentTimeMillis System.currentTimeMillis()} 102 * (wall clock time in UTC). This alarm does not wake the 103 * device up; if it goes off while the device is asleep, it will not be 104 * delivered until the next time the device wakes up. 105 */ 106 public static final int RTC = 1; 107 /** 108 * Alarm time in {@link android.os.SystemClock#elapsedRealtime 109 * SystemClock.elapsedRealtime()} (time since boot, including sleep), 110 * which will wake up the device when it goes off. 111 */ 112 public static final int ELAPSED_REALTIME_WAKEUP = 2; 113 /** 114 * Alarm time in {@link android.os.SystemClock#elapsedRealtime 115 * SystemClock.elapsedRealtime()} (time since boot, including sleep). 116 * This alarm does not wake the device up; if it goes off while the device 117 * is asleep, it will not be delivered until the next time the device 118 * wakes up. 119 */ 120 public static final int ELAPSED_REALTIME = 3; 121 122 /** 123 * Broadcast Action: Sent after the value returned by 124 * {@link #getNextAlarmClock()} has changed. 125 * 126 * <p class="note">This is a protected intent that can only be sent by the system. 127 * It is only sent to registered receivers.</p> 128 */ 129 @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) 130 public static final String ACTION_NEXT_ALARM_CLOCK_CHANGED = 131 "android.app.action.NEXT_ALARM_CLOCK_CHANGED"; 132 133 /** @hide */ 134 @UnsupportedAppUsage 135 public static final long WINDOW_EXACT = 0; 136 /** @hide */ 137 @UnsupportedAppUsage 138 public static final long WINDOW_HEURISTIC = -1; 139 140 /** 141 * Flag for alarms: this is to be a stand-alone alarm, that should not be batched with 142 * other alarms. 143 * @hide 144 */ 145 @UnsupportedAppUsage 146 public static final int FLAG_STANDALONE = 1<<0; 147 148 /** 149 * Flag for alarms: this alarm would like to wake the device even if it is idle. This 150 * is, for example, an alarm for an alarm clock. 151 * @hide 152 */ 153 @UnsupportedAppUsage 154 public static final int FLAG_WAKE_FROM_IDLE = 1<<1; 155 156 /** 157 * Flag for alarms: this alarm would like to still execute even if the device is 158 * idle. This won't bring the device out of idle, just allow this specific alarm to 159 * run. Note that this means the actual time this alarm goes off can be inconsistent 160 * with the time of non-allow-while-idle alarms (it could go earlier than the time 161 * requested by another alarm). 162 * 163 * @hide 164 */ 165 public static final int FLAG_ALLOW_WHILE_IDLE = 1<<2; 166 167 /** 168 * Flag for alarms: same as {@link #FLAG_ALLOW_WHILE_IDLE}, but doesn't have restrictions 169 * on how frequently it can be scheduled. Only available (and automatically applied) to 170 * system alarms. 171 * 172 * @hide 173 */ 174 @UnsupportedAppUsage 175 public static final int FLAG_ALLOW_WHILE_IDLE_UNRESTRICTED = 1<<3; 176 177 /** 178 * Flag for alarms: this alarm marks the point where we would like to come out of idle 179 * mode. It may be moved by the alarm manager to match the first wake-from-idle alarm. 180 * Scheduling an alarm with this flag puts the alarm manager in to idle mode, where it 181 * avoids scheduling any further alarms until the marker alarm is executed. 182 * @hide 183 */ 184 @UnsupportedAppUsage 185 public static final int FLAG_IDLE_UNTIL = 1<<4; 186 187 @UnsupportedAppUsage 188 private final IAlarmManager mService; 189 private final Context mContext; 190 private final String mPackageName; 191 private final boolean mAlwaysExact; 192 private final int mTargetSdkVersion; 193 private final Handler mMainThreadHandler; 194 195 /** 196 * Direct-notification alarms: the requester must be running continuously from the 197 * time the alarm is set to the time it is delivered, or delivery will fail. Only 198 * one-shot alarms can be set using this mechanism, not repeating alarms. 199 */ 200 public interface OnAlarmListener { 201 /** 202 * Callback method that is invoked by the system when the alarm time is reached. 203 */ onAlarm()204 public void onAlarm(); 205 } 206 207 final class ListenerWrapper extends IAlarmListener.Stub implements Runnable { 208 final OnAlarmListener mListener; 209 Handler mHandler; 210 IAlarmCompleteListener mCompletion; 211 ListenerWrapper(OnAlarmListener listener)212 public ListenerWrapper(OnAlarmListener listener) { 213 mListener = listener; 214 } 215 setHandler(Handler h)216 public void setHandler(Handler h) { 217 mHandler = h; 218 } 219 cancel()220 public void cancel() { 221 try { 222 mService.remove(null, this); 223 } catch (RemoteException ex) { 224 throw ex.rethrowFromSystemServer(); 225 } 226 } 227 228 @Override doAlarm(IAlarmCompleteListener alarmManager)229 public void doAlarm(IAlarmCompleteListener alarmManager) { 230 mCompletion = alarmManager; 231 232 mHandler.post(this); 233 } 234 235 @Override run()236 public void run() { 237 // Now deliver it to the app 238 try { 239 mListener.onAlarm(); 240 } finally { 241 // No catch -- make sure to report completion to the system process, 242 // but continue to allow the exception to crash the app. 243 244 try { 245 mCompletion.alarmComplete(this); 246 } catch (Exception e) { 247 Log.e(TAG, "Unable to report completion to Alarm Manager!", e); 248 } 249 } 250 } 251 } 252 253 /** 254 * Tracking of the OnAlarmListener -> ListenerWrapper mapping, for cancel() support. 255 * An entry is guaranteed to stay in this map as long as its ListenerWrapper is held by the 256 * server. 257 * 258 * <p>Access is synchronized on the AlarmManager class object. 259 */ 260 private static WeakHashMap<OnAlarmListener, WeakReference<ListenerWrapper>> sWrappers; 261 262 /** 263 * package private on purpose 264 */ AlarmManager(IAlarmManager service, Context ctx)265 AlarmManager(IAlarmManager service, Context ctx) { 266 mService = service; 267 268 mContext = ctx; 269 mPackageName = ctx.getPackageName(); 270 mTargetSdkVersion = ctx.getApplicationInfo().targetSdkVersion; 271 mAlwaysExact = (mTargetSdkVersion < Build.VERSION_CODES.KITKAT); 272 mMainThreadHandler = new Handler(ctx.getMainLooper()); 273 } 274 legacyExactLength()275 private long legacyExactLength() { 276 return (mAlwaysExact ? WINDOW_EXACT : WINDOW_HEURISTIC); 277 } 278 279 /** 280 * <p>Schedule an alarm. <b>Note: for timing operations (ticks, timeouts, 281 * etc) it is easier and much more efficient to use {@link android.os.Handler}.</b> 282 * If there is already an alarm scheduled for the same IntentSender, that previous 283 * alarm will first be canceled. 284 * 285 * <p>If the stated trigger time is in the past, the alarm will be triggered 286 * immediately. If there is already an alarm for this Intent 287 * scheduled (with the equality of two intents being defined by 288 * {@link Intent#filterEquals}), then it will be removed and replaced by 289 * this one. 290 * 291 * <p> 292 * The alarm is an Intent broadcast that goes to a broadcast receiver that 293 * you registered with {@link android.content.Context#registerReceiver} 294 * or through the <receiver> tag in an AndroidManifest.xml file. 295 * 296 * <p> 297 * Alarm intents are delivered with a data extra of type int called 298 * {@link Intent#EXTRA_ALARM_COUNT Intent.EXTRA_ALARM_COUNT} that indicates 299 * how many past alarm events have been accumulated into this intent 300 * broadcast. Recurring alarms that have gone undelivered because the 301 * phone was asleep may have a count greater than one when delivered. 302 * 303 * <div class="note"> 304 * <p> 305 * <b>Note:</b> Beginning in API 19, the trigger time passed to this method 306 * is treated as inexact: the alarm will not be delivered before this time, but 307 * may be deferred and delivered some time later. The OS will use 308 * this policy in order to "batch" alarms together across the entire system, 309 * minimizing the number of times the device needs to "wake up" and minimizing 310 * battery use. In general, alarms scheduled in the near future will not 311 * be deferred as long as alarms scheduled far in the future. 312 * 313 * <p> 314 * With the new batching policy, delivery ordering guarantees are not as 315 * strong as they were previously. If the application sets multiple alarms, 316 * it is possible that these alarms' <em>actual</em> delivery ordering may not match 317 * the order of their <em>requested</em> delivery times. If your application has 318 * strong ordering requirements there are other APIs that you can use to get 319 * the necessary behavior; see {@link #setWindow(int, long, long, PendingIntent)} 320 * and {@link #setExact(int, long, PendingIntent)}. 321 * 322 * <p> 323 * Applications whose {@code targetSdkVersion} is before API 19 will 324 * continue to get the previous alarm behavior: all of their scheduled alarms 325 * will be treated as exact. 326 * </div> 327 * 328 * @param type type of alarm. 329 * @param triggerAtMillis time in milliseconds that the alarm should go 330 * off, using the appropriate clock (depending on the alarm type). 331 * @param operation Action to perform when the alarm goes off; 332 * typically comes from {@link PendingIntent#getBroadcast 333 * IntentSender.getBroadcast()}. 334 * 335 * @see android.os.Handler 336 * @see #setExact 337 * @see #setRepeating 338 * @see #setWindow 339 * @see #cancel 340 * @see android.content.Context#sendBroadcast 341 * @see android.content.Context#registerReceiver 342 * @see android.content.Intent#filterEquals 343 * @see #ELAPSED_REALTIME 344 * @see #ELAPSED_REALTIME_WAKEUP 345 * @see #RTC 346 * @see #RTC_WAKEUP 347 */ set(@larmType int type, long triggerAtMillis, PendingIntent operation)348 public void set(@AlarmType int type, long triggerAtMillis, PendingIntent operation) { 349 setImpl(type, triggerAtMillis, legacyExactLength(), 0, 0, operation, null, null, 350 null, null, null); 351 } 352 353 /** 354 * Direct callback version of {@link #set(int, long, PendingIntent)}. Rather than 355 * supplying a PendingIntent to be sent when the alarm time is reached, this variant 356 * supplies an {@link OnAlarmListener} instance that will be invoked at that time. 357 * <p> 358 * The OnAlarmListener's {@link OnAlarmListener#onAlarm() onAlarm()} method will be 359 * invoked via the specified target Handler, or on the application's main looper 360 * if {@code null} is passed as the {@code targetHandler} parameter. 361 * 362 * @param type type of alarm. 363 * @param triggerAtMillis time in milliseconds that the alarm should go 364 * off, using the appropriate clock (depending on the alarm type). 365 * @param tag string describing the alarm, used for logging and battery-use 366 * attribution 367 * @param listener {@link OnAlarmListener} instance whose 368 * {@link OnAlarmListener#onAlarm() onAlarm()} method will be 369 * called when the alarm time is reached. A given OnAlarmListener instance can 370 * only be the target of a single pending alarm, just as a given PendingIntent 371 * can only be used with one alarm at a time. 372 * @param targetHandler {@link Handler} on which to execute the listener's onAlarm() 373 * callback, or {@code null} to run that callback on the main looper. 374 */ set(@larmType int type, long triggerAtMillis, String tag, OnAlarmListener listener, Handler targetHandler)375 public void set(@AlarmType int type, long triggerAtMillis, String tag, OnAlarmListener listener, 376 Handler targetHandler) { 377 setImpl(type, triggerAtMillis, legacyExactLength(), 0, 0, null, listener, tag, 378 targetHandler, null, null); 379 } 380 381 /** 382 * Schedule a repeating alarm. <b>Note: for timing operations (ticks, 383 * timeouts, etc) it is easier and much more efficient to use 384 * {@link android.os.Handler}.</b> If there is already an alarm scheduled 385 * for the same IntentSender, it will first be canceled. 386 * 387 * <p>Like {@link #set}, except you can also supply a period at which 388 * the alarm will automatically repeat. This alarm continues 389 * repeating until explicitly removed with {@link #cancel}. If the stated 390 * trigger time is in the past, the alarm will be triggered immediately, with an 391 * alarm count depending on how far in the past the trigger time is relative 392 * to the repeat interval. 393 * 394 * <p>If an alarm is delayed (by system sleep, for example, for non 395 * _WAKEUP alarm types), a skipped repeat will be delivered as soon as 396 * possible. After that, future alarms will be delivered according to the 397 * original schedule; they do not drift over time. For example, if you have 398 * set a recurring alarm for the top of every hour but the phone was asleep 399 * from 7:45 until 8:45, an alarm will be sent as soon as the phone awakens, 400 * then the next alarm will be sent at 9:00. 401 * 402 * <p>If your application wants to allow the delivery times to drift in 403 * order to guarantee that at least a certain time interval always elapses 404 * between alarms, then the approach to take is to use one-time alarms, 405 * scheduling the next one yourself when handling each alarm delivery. 406 * 407 * <p class="note"> 408 * <b>Note:</b> as of API 19, all repeating alarms are inexact. If your 409 * application needs precise delivery times then it must use one-time 410 * exact alarms, rescheduling each time as described above. Legacy applications 411 * whose {@code targetSdkVersion} is earlier than API 19 will continue to have all 412 * of their alarms, including repeating alarms, treated as exact. 413 * 414 * @param type type of alarm. 415 * @param triggerAtMillis time in milliseconds that the alarm should first 416 * go off, using the appropriate clock (depending on the alarm type). 417 * @param intervalMillis interval in milliseconds between subsequent repeats 418 * of the alarm. 419 * @param operation Action to perform when the alarm goes off; 420 * typically comes from {@link PendingIntent#getBroadcast 421 * IntentSender.getBroadcast()}. 422 * 423 * @see android.os.Handler 424 * @see #set 425 * @see #setExact 426 * @see #setWindow 427 * @see #cancel 428 * @see android.content.Context#sendBroadcast 429 * @see android.content.Context#registerReceiver 430 * @see android.content.Intent#filterEquals 431 * @see #ELAPSED_REALTIME 432 * @see #ELAPSED_REALTIME_WAKEUP 433 * @see #RTC 434 * @see #RTC_WAKEUP 435 */ setRepeating(@larmType int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)436 public void setRepeating(@AlarmType int type, long triggerAtMillis, 437 long intervalMillis, PendingIntent operation) { 438 setImpl(type, triggerAtMillis, legacyExactLength(), intervalMillis, 0, operation, 439 null, null, null, null, null); 440 } 441 442 /** 443 * Schedule an alarm to be delivered within a given window of time. This method 444 * is similar to {@link #set(int, long, PendingIntent)}, but allows the 445 * application to precisely control the degree to which its delivery might be 446 * adjusted by the OS. This method allows an application to take advantage of the 447 * battery optimizations that arise from delivery batching even when it has 448 * modest timeliness requirements for its alarms. 449 * 450 * <p> 451 * This method can also be used to achieve strict ordering guarantees among 452 * multiple alarms by ensuring that the windows requested for each alarm do 453 * not intersect. 454 * 455 * <p> 456 * When precise delivery is not required, applications should use the standard 457 * {@link #set(int, long, PendingIntent)} method. This will give the OS the most 458 * flexibility to minimize wakeups and battery use. For alarms that must be delivered 459 * at precisely-specified times with no acceptable variation, applications can use 460 * {@link #setExact(int, long, PendingIntent)}. 461 * 462 * @param type type of alarm. 463 * @param windowStartMillis The earliest time, in milliseconds, that the alarm should 464 * be delivered, expressed in the appropriate clock's units (depending on the alarm 465 * type). 466 * @param windowLengthMillis The length of the requested delivery window, 467 * in milliseconds. The alarm will be delivered no later than this many 468 * milliseconds after {@code windowStartMillis}. Note that this parameter 469 * is a <i>duration,</i> not the timestamp of the end of the window. 470 * @param operation Action to perform when the alarm goes off; 471 * typically comes from {@link PendingIntent#getBroadcast 472 * IntentSender.getBroadcast()}. 473 * 474 * @see #set 475 * @see #setExact 476 * @see #setRepeating 477 * @see #cancel 478 * @see android.content.Context#sendBroadcast 479 * @see android.content.Context#registerReceiver 480 * @see android.content.Intent#filterEquals 481 * @see #ELAPSED_REALTIME 482 * @see #ELAPSED_REALTIME_WAKEUP 483 * @see #RTC 484 * @see #RTC_WAKEUP 485 */ setWindow(@larmType int type, long windowStartMillis, long windowLengthMillis, PendingIntent operation)486 public void setWindow(@AlarmType int type, long windowStartMillis, long windowLengthMillis, 487 PendingIntent operation) { 488 setImpl(type, windowStartMillis, windowLengthMillis, 0, 0, operation, 489 null, null, null, null, null); 490 } 491 492 /** 493 * Direct callback version of {@link #setWindow(int, long, long, PendingIntent)}. Rather 494 * than supplying a PendingIntent to be sent when the alarm time is reached, this variant 495 * supplies an {@link OnAlarmListener} instance that will be invoked at that time. 496 * <p> 497 * The OnAlarmListener {@link OnAlarmListener#onAlarm() onAlarm()} method will be 498 * invoked via the specified target Handler, or on the application's main looper 499 * if {@code null} is passed as the {@code targetHandler} parameter. 500 */ setWindow(@larmType int type, long windowStartMillis, long windowLengthMillis, String tag, OnAlarmListener listener, Handler targetHandler)501 public void setWindow(@AlarmType int type, long windowStartMillis, long windowLengthMillis, 502 String tag, OnAlarmListener listener, Handler targetHandler) { 503 setImpl(type, windowStartMillis, windowLengthMillis, 0, 0, null, listener, tag, 504 targetHandler, null, null); 505 } 506 507 /** 508 * Schedule an alarm to be delivered precisely at the stated time. 509 * 510 * <p> 511 * This method is like {@link #set(int, long, PendingIntent)}, but does not permit 512 * the OS to adjust the delivery time. The alarm will be delivered as nearly as 513 * possible to the requested trigger time. 514 * 515 * <p> 516 * <b>Note:</b> only alarms for which there is a strong demand for exact-time 517 * delivery (such as an alarm clock ringing at the requested time) should be 518 * scheduled as exact. Applications are strongly discouraged from using exact 519 * alarms unnecessarily as they reduce the OS's ability to minimize battery use. 520 * 521 * @param type type of alarm. 522 * @param triggerAtMillis time in milliseconds that the alarm should go 523 * off, using the appropriate clock (depending on the alarm type). 524 * @param operation Action to perform when the alarm goes off; 525 * typically comes from {@link PendingIntent#getBroadcast 526 * IntentSender.getBroadcast()}. 527 * 528 * @see #set 529 * @see #setRepeating 530 * @see #setWindow 531 * @see #cancel 532 * @see android.content.Context#sendBroadcast 533 * @see android.content.Context#registerReceiver 534 * @see android.content.Intent#filterEquals 535 * @see #ELAPSED_REALTIME 536 * @see #ELAPSED_REALTIME_WAKEUP 537 * @see #RTC 538 * @see #RTC_WAKEUP 539 */ setExact(@larmType int type, long triggerAtMillis, PendingIntent operation)540 public void setExact(@AlarmType int type, long triggerAtMillis, PendingIntent operation) { 541 setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, 0, operation, null, null, null, 542 null, null); 543 } 544 545 /** 546 * Direct callback version of {@link #setExact(int, long, PendingIntent)}. Rather 547 * than supplying a PendingIntent to be sent when the alarm time is reached, this variant 548 * supplies an {@link OnAlarmListener} instance that will be invoked at that time. 549 * <p> 550 * The OnAlarmListener's {@link OnAlarmListener#onAlarm() onAlarm()} method will be 551 * invoked via the specified target Handler, or on the application's main looper 552 * if {@code null} is passed as the {@code targetHandler} parameter. 553 */ setExact(@larmType int type, long triggerAtMillis, String tag, OnAlarmListener listener, Handler targetHandler)554 public void setExact(@AlarmType int type, long triggerAtMillis, String tag, 555 OnAlarmListener listener, Handler targetHandler) { 556 setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, 0, null, listener, tag, 557 targetHandler, null, null); 558 } 559 560 /** 561 * Schedule an idle-until alarm, which will keep the alarm manager idle until 562 * the given time. 563 * @hide 564 */ setIdleUntil(@larmType int type, long triggerAtMillis, String tag, OnAlarmListener listener, Handler targetHandler)565 public void setIdleUntil(@AlarmType int type, long triggerAtMillis, String tag, 566 OnAlarmListener listener, Handler targetHandler) { 567 setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, FLAG_IDLE_UNTIL, null, 568 listener, tag, targetHandler, null, null); 569 } 570 571 /** 572 * Schedule an alarm that represents an alarm clock, which will be used to notify the user 573 * when it goes off. The expectation is that when this alarm triggers, the application will 574 * further wake up the device to tell the user about the alarm -- turning on the screen, 575 * playing a sound, vibrating, etc. As such, the system will typically also use the 576 * information supplied here to tell the user about this upcoming alarm if appropriate. 577 * 578 * <p>Due to the nature of this kind of alarm, similar to {@link #setExactAndAllowWhileIdle}, 579 * these alarms will be allowed to trigger even if the system is in a low-power idle 580 * (a.k.a. doze) mode. The system may also do some prep-work when it sees that such an 581 * alarm coming up, to reduce the amount of background work that could happen if this 582 * causes the device to fully wake up -- this is to avoid situations such as a large number 583 * of devices having an alarm set at the same time in the morning, all waking up at that 584 * time and suddenly swamping the network with pending background work. As such, these 585 * types of alarms can be extremely expensive on battery use and should only be used for 586 * their intended purpose.</p> 587 * 588 * <p> 589 * This method is like {@link #setExact(int, long, PendingIntent)}, but implies 590 * {@link #RTC_WAKEUP}. 591 * 592 * @param info 593 * @param operation Action to perform when the alarm goes off; 594 * typically comes from {@link PendingIntent#getBroadcast 595 * IntentSender.getBroadcast()}. 596 * 597 * @see #set 598 * @see #setRepeating 599 * @see #setWindow 600 * @see #setExact 601 * @see #cancel 602 * @see #getNextAlarmClock() 603 * @see android.content.Context#sendBroadcast 604 * @see android.content.Context#registerReceiver 605 * @see android.content.Intent#filterEquals 606 */ setAlarmClock(AlarmClockInfo info, PendingIntent operation)607 public void setAlarmClock(AlarmClockInfo info, PendingIntent operation) { 608 setImpl(RTC_WAKEUP, info.getTriggerTime(), WINDOW_EXACT, 0, 0, operation, 609 null, null, null, null, info); 610 } 611 612 /** @hide */ 613 @SystemApi 614 @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) set(@larmType int type, long triggerAtMillis, long windowMillis, long intervalMillis, PendingIntent operation, WorkSource workSource)615 public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, 616 long intervalMillis, PendingIntent operation, WorkSource workSource) { 617 setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, operation, null, null, 618 null, workSource, null); 619 } 620 621 /** 622 * Direct callback version of {@link #set(int, long, long, long, PendingIntent, WorkSource)}. 623 * Note that repeating alarms must use the PendingIntent variant, not an OnAlarmListener. 624 * <p> 625 * The OnAlarmListener's {@link OnAlarmListener#onAlarm() onAlarm()} method will be 626 * invoked via the specified target Handler, or on the application's main looper 627 * if {@code null} is passed as the {@code targetHandler} parameter. 628 * 629 * @hide 630 */ 631 @UnsupportedAppUsage set(@larmType int type, long triggerAtMillis, long windowMillis, long intervalMillis, String tag, OnAlarmListener listener, Handler targetHandler, WorkSource workSource)632 public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, 633 long intervalMillis, String tag, OnAlarmListener listener, Handler targetHandler, 634 WorkSource workSource) { 635 setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, tag, 636 targetHandler, workSource, null); 637 } 638 639 /** 640 * Direct callback version of {@link #set(int, long, long, long, PendingIntent, WorkSource)}. 641 * Note that repeating alarms must use the PendingIntent variant, not an OnAlarmListener. 642 * <p> 643 * The OnAlarmListener's {@link OnAlarmListener#onAlarm() onAlarm()} method will be 644 * invoked via the specified target Handler, or on the application's main looper 645 * if {@code null} is passed as the {@code targetHandler} parameter. 646 * 647 * @hide 648 */ 649 @SystemApi 650 @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) set(@larmType int type, long triggerAtMillis, long windowMillis, long intervalMillis, OnAlarmListener listener, Handler targetHandler, WorkSource workSource)651 public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, 652 long intervalMillis, OnAlarmListener listener, Handler targetHandler, 653 WorkSource workSource) { 654 setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, null, 655 targetHandler, workSource, null); 656 } 657 setImpl(@larmType int type, long triggerAtMillis, long windowMillis, long intervalMillis, int flags, PendingIntent operation, final OnAlarmListener listener, String listenerTag, Handler targetHandler, WorkSource workSource, AlarmClockInfo alarmClock)658 private void setImpl(@AlarmType int type, long triggerAtMillis, long windowMillis, 659 long intervalMillis, int flags, PendingIntent operation, final OnAlarmListener listener, 660 String listenerTag, Handler targetHandler, WorkSource workSource, 661 AlarmClockInfo alarmClock) { 662 if (triggerAtMillis < 0) { 663 /* NOTYET 664 if (mAlwaysExact) { 665 // Fatal error for KLP+ apps to use negative trigger times 666 throw new IllegalArgumentException("Invalid alarm trigger time " 667 + triggerAtMillis); 668 } 669 */ 670 triggerAtMillis = 0; 671 } 672 673 ListenerWrapper recipientWrapper = null; 674 if (listener != null) { 675 synchronized (AlarmManager.class) { 676 if (sWrappers == null) { 677 sWrappers = new WeakHashMap<>(); 678 } 679 680 final WeakReference<ListenerWrapper> weakRef = sWrappers.get(listener); 681 if (weakRef != null) { 682 recipientWrapper = weakRef.get(); 683 } 684 // no existing wrapper => build a new one 685 if (recipientWrapper == null) { 686 recipientWrapper = new ListenerWrapper(listener); 687 sWrappers.put(listener, new WeakReference<>(recipientWrapper)); 688 } 689 } 690 691 final Handler handler = (targetHandler != null) ? targetHandler : mMainThreadHandler; 692 recipientWrapper.setHandler(handler); 693 } 694 695 try { 696 mService.set(mPackageName, type, triggerAtMillis, windowMillis, intervalMillis, flags, 697 operation, recipientWrapper, listenerTag, workSource, alarmClock); 698 } catch (RemoteException ex) { 699 throw ex.rethrowFromSystemServer(); 700 } 701 } 702 703 /** 704 * Available inexact recurrence interval recognized by 705 * {@link #setInexactRepeating(int, long, long, PendingIntent)} 706 * when running on Android prior to API 19. 707 */ 708 public static final long INTERVAL_FIFTEEN_MINUTES = 15 * 60 * 1000; 709 710 /** 711 * Available inexact recurrence interval recognized by 712 * {@link #setInexactRepeating(int, long, long, PendingIntent)} 713 * when running on Android prior to API 19. 714 */ 715 public static final long INTERVAL_HALF_HOUR = 2*INTERVAL_FIFTEEN_MINUTES; 716 717 /** 718 * Available inexact recurrence interval recognized by 719 * {@link #setInexactRepeating(int, long, long, PendingIntent)} 720 * when running on Android prior to API 19. 721 */ 722 public static final long INTERVAL_HOUR = 2*INTERVAL_HALF_HOUR; 723 724 /** 725 * Available inexact recurrence interval recognized by 726 * {@link #setInexactRepeating(int, long, long, PendingIntent)} 727 * when running on Android prior to API 19. 728 */ 729 public static final long INTERVAL_HALF_DAY = 12*INTERVAL_HOUR; 730 731 /** 732 * Available inexact recurrence interval recognized by 733 * {@link #setInexactRepeating(int, long, long, PendingIntent)} 734 * when running on Android prior to API 19. 735 */ 736 public static final long INTERVAL_DAY = 2*INTERVAL_HALF_DAY; 737 738 /** 739 * Schedule a repeating alarm that has inexact trigger time requirements; 740 * for example, an alarm that repeats every hour, but not necessarily at 741 * the top of every hour. These alarms are more power-efficient than 742 * the strict recurrences traditionally supplied by {@link #setRepeating}, since the 743 * system can adjust alarms' delivery times to cause them to fire simultaneously, 744 * avoiding waking the device from sleep more than necessary. 745 * 746 * <p>Your alarm's first trigger will not be before the requested time, 747 * but it might not occur for almost a full interval after that time. In 748 * addition, while the overall period of the repeating alarm will be as 749 * requested, the time between any two successive firings of the alarm 750 * may vary. If your application demands very low jitter, use 751 * one-shot alarms with an appropriate window instead; see {@link 752 * #setWindow(int, long, long, PendingIntent)} and 753 * {@link #setExact(int, long, PendingIntent)}. 754 * 755 * <p class="note"> 756 * As of API 19, all repeating alarms are inexact. Because this method has 757 * been available since API 3, your application can safely call it and be 758 * assured that it will get similar behavior on both current and older versions 759 * of Android. 760 * 761 * @param type type of alarm. 762 * @param triggerAtMillis time in milliseconds that the alarm should first 763 * go off, using the appropriate clock (depending on the alarm type). This 764 * is inexact: the alarm will not fire before this time, but there may be a 765 * delay of almost an entire alarm interval before the first invocation of 766 * the alarm. 767 * @param intervalMillis interval in milliseconds between subsequent repeats 768 * of the alarm. Prior to API 19, if this is one of INTERVAL_FIFTEEN_MINUTES, 769 * INTERVAL_HALF_HOUR, INTERVAL_HOUR, INTERVAL_HALF_DAY, or INTERVAL_DAY 770 * then the alarm will be phase-aligned with other alarms to reduce the 771 * number of wakeups. Otherwise, the alarm will be set as though the 772 * application had called {@link #setRepeating}. As of API 19, all repeating 773 * alarms will be inexact and subject to batching with other alarms regardless 774 * of their stated repeat interval. 775 * @param operation Action to perform when the alarm goes off; 776 * typically comes from {@link PendingIntent#getBroadcast 777 * IntentSender.getBroadcast()}. 778 * 779 * @see android.os.Handler 780 * @see #set 781 * @see #cancel 782 * @see android.content.Context#sendBroadcast 783 * @see android.content.Context#registerReceiver 784 * @see android.content.Intent#filterEquals 785 * @see #ELAPSED_REALTIME 786 * @see #ELAPSED_REALTIME_WAKEUP 787 * @see #RTC 788 * @see #RTC_WAKEUP 789 * @see #INTERVAL_FIFTEEN_MINUTES 790 * @see #INTERVAL_HALF_HOUR 791 * @see #INTERVAL_HOUR 792 * @see #INTERVAL_HALF_DAY 793 * @see #INTERVAL_DAY 794 */ setInexactRepeating(@larmType int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)795 public void setInexactRepeating(@AlarmType int type, long triggerAtMillis, 796 long intervalMillis, PendingIntent operation) { 797 setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, intervalMillis, 0, operation, null, 798 null, null, null, null); 799 } 800 801 /** 802 * Like {@link #set(int, long, PendingIntent)}, but this alarm will be allowed to execute 803 * even when the system is in low-power idle (a.k.a. doze) modes. This type of alarm must 804 * <b>only</b> be used for situations where it is actually required that the alarm go off while 805 * in idle -- a reasonable example would be for a calendar notification that should make a 806 * sound so the user is aware of it. When the alarm is dispatched, the app will also be 807 * added to the system's temporary whitelist for approximately 10 seconds to allow that 808 * application to acquire further wake locks in which to complete its work.</p> 809 * 810 * <p>These alarms can significantly impact the power use 811 * of the device when idle (and thus cause significant battery blame to the app scheduling 812 * them), so they should be used with care. To reduce abuse, there are restrictions on how 813 * frequently these alarms will go off for a particular application. 814 * Under normal system operation, it will not dispatch these 815 * alarms more than about every minute (at which point every such pending alarm is 816 * dispatched); when in low-power idle modes this duration may be significantly longer, 817 * such as 15 minutes.</p> 818 * 819 * <p>Unlike other alarms, the system is free to reschedule this type of alarm to happen 820 * out of order with any other alarms, even those from the same app. This will clearly happen 821 * when the device is idle (since this alarm can go off while idle, when any other alarms 822 * from the app will be held until later), but may also happen even when not idle.</p> 823 * 824 * <p>Regardless of the app's target SDK version, this call always allows batching of the 825 * alarm.</p> 826 * 827 * @param type type of alarm. 828 * @param triggerAtMillis time in milliseconds that the alarm should go 829 * off, using the appropriate clock (depending on the alarm type). 830 * @param operation Action to perform when the alarm goes off; 831 * typically comes from {@link PendingIntent#getBroadcast 832 * IntentSender.getBroadcast()}. 833 * 834 * @see #set(int, long, PendingIntent) 835 * @see #setExactAndAllowWhileIdle 836 * @see #cancel 837 * @see android.content.Context#sendBroadcast 838 * @see android.content.Context#registerReceiver 839 * @see android.content.Intent#filterEquals 840 * @see #ELAPSED_REALTIME 841 * @see #ELAPSED_REALTIME_WAKEUP 842 * @see #RTC 843 * @see #RTC_WAKEUP 844 */ setAndAllowWhileIdle(@larmType int type, long triggerAtMillis, PendingIntent operation)845 public void setAndAllowWhileIdle(@AlarmType int type, long triggerAtMillis, 846 PendingIntent operation) { 847 setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, 0, FLAG_ALLOW_WHILE_IDLE, 848 operation, null, null, null, null, null); 849 } 850 851 /** 852 * Like {@link #setExact(int, long, PendingIntent)}, but this alarm will be allowed to execute 853 * even when the system is in low-power idle modes. If you don't need exact scheduling of 854 * the alarm but still need to execute while idle, consider using 855 * {@link #setAndAllowWhileIdle}. This type of alarm must <b>only</b> 856 * be used for situations where it is actually required that the alarm go off while in 857 * idle -- a reasonable example would be for a calendar notification that should make a 858 * sound so the user is aware of it. When the alarm is dispatched, the app will also be 859 * added to the system's temporary whitelist for approximately 10 seconds to allow that 860 * application to acquire further wake locks in which to complete its work.</p> 861 * 862 * <p>These alarms can significantly impact the power use 863 * of the device when idle (and thus cause significant battery blame to the app scheduling 864 * them), so they should be used with care. To reduce abuse, there are restrictions on how 865 * frequently these alarms will go off for a particular application. 866 * Under normal system operation, it will not dispatch these 867 * alarms more than about every minute (at which point every such pending alarm is 868 * dispatched); when in low-power idle modes this duration may be significantly longer, 869 * such as 15 minutes.</p> 870 * 871 * <p>Unlike other alarms, the system is free to reschedule this type of alarm to happen 872 * out of order with any other alarms, even those from the same app. This will clearly happen 873 * when the device is idle (since this alarm can go off while idle, when any other alarms 874 * from the app will be held until later), but may also happen even when not idle. 875 * Note that the OS will allow itself more flexibility for scheduling these alarms than 876 * regular exact alarms, since the application has opted into this behavior. When the 877 * device is idle it may take even more liberties with scheduling in order to optimize 878 * for battery life.</p> 879 * 880 * @param type type of alarm. 881 * @param triggerAtMillis time in milliseconds that the alarm should go 882 * off, using the appropriate clock (depending on the alarm type). 883 * @param operation Action to perform when the alarm goes off; 884 * typically comes from {@link PendingIntent#getBroadcast 885 * IntentSender.getBroadcast()}. 886 * 887 * @see #set 888 * @see #setRepeating 889 * @see #setWindow 890 * @see #cancel 891 * @see android.content.Context#sendBroadcast 892 * @see android.content.Context#registerReceiver 893 * @see android.content.Intent#filterEquals 894 * @see #ELAPSED_REALTIME 895 * @see #ELAPSED_REALTIME_WAKEUP 896 * @see #RTC 897 * @see #RTC_WAKEUP 898 */ setExactAndAllowWhileIdle(@larmType int type, long triggerAtMillis, PendingIntent operation)899 public void setExactAndAllowWhileIdle(@AlarmType int type, long triggerAtMillis, 900 PendingIntent operation) { 901 setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, FLAG_ALLOW_WHILE_IDLE, operation, 902 null, null, null, null, null); 903 } 904 905 /** 906 * Remove any alarms with a matching {@link Intent}. 907 * Any alarm, of any type, whose Intent matches this one (as defined by 908 * {@link Intent#filterEquals}), will be canceled. 909 * 910 * @param operation IntentSender which matches a previously added 911 * IntentSender. This parameter must not be {@code null}. 912 * 913 * @see #set 914 */ cancel(PendingIntent operation)915 public void cancel(PendingIntent operation) { 916 if (operation == null) { 917 final String msg = "cancel() called with a null PendingIntent"; 918 if (mTargetSdkVersion >= Build.VERSION_CODES.N) { 919 throw new NullPointerException(msg); 920 } else { 921 Log.e(TAG, msg); 922 return; 923 } 924 } 925 926 try { 927 mService.remove(operation, null); 928 } catch (RemoteException ex) { 929 throw ex.rethrowFromSystemServer(); 930 } 931 } 932 933 /** 934 * Remove any alarm scheduled to be delivered to the given {@link OnAlarmListener}. 935 * 936 * @param listener OnAlarmListener instance that is the target of a currently-set alarm. 937 */ cancel(OnAlarmListener listener)938 public void cancel(OnAlarmListener listener) { 939 if (listener == null) { 940 throw new NullPointerException("cancel() called with a null OnAlarmListener"); 941 } 942 943 ListenerWrapper wrapper = null; 944 synchronized (AlarmManager.class) { 945 if (sWrappers != null) { 946 final WeakReference<ListenerWrapper> weakRef = sWrappers.get(listener); 947 if (weakRef != null) { 948 wrapper = weakRef.get(); 949 } 950 } 951 } 952 953 if (wrapper == null) { 954 Log.w(TAG, "Unrecognized alarm listener " + listener); 955 return; 956 } 957 958 wrapper.cancel(); 959 } 960 961 /** 962 * Set the system wall clock time. 963 * Requires the permission android.permission.SET_TIME. 964 * 965 * @param millis time in milliseconds since the Epoch 966 */ 967 @RequiresPermission(android.Manifest.permission.SET_TIME) setTime(long millis)968 public void setTime(long millis) { 969 try { 970 mService.setTime(millis); 971 } catch (RemoteException ex) { 972 throw ex.rethrowFromSystemServer(); 973 } 974 } 975 976 /** 977 * Sets the system's persistent default time zone. This is the time zone for all apps, even 978 * after a reboot. Use {@link java.util.TimeZone#setDefault} if you just want to change the 979 * time zone within your app, and even then prefer to pass an explicit 980 * {@link java.util.TimeZone} to APIs that require it rather than changing the time zone for 981 * all threads. 982 * 983 * <p> On android M and above, it is an error to pass in a non-Olson timezone to this 984 * function. Note that this is a bad idea on all Android releases because POSIX and 985 * the {@code TimeZone} class have opposite interpretations of {@code '+'} and {@code '-'} 986 * in the same non-Olson ID. 987 * 988 * @param timeZone one of the Olson ids from the list returned by 989 * {@link java.util.TimeZone#getAvailableIDs} 990 */ 991 @RequiresPermission(android.Manifest.permission.SET_TIME_ZONE) setTimeZone(String timeZone)992 public void setTimeZone(String timeZone) { 993 if (TextUtils.isEmpty(timeZone)) { 994 return; 995 } 996 997 // Reject this timezone if it isn't an Olson zone we recognize. 998 if (mTargetSdkVersion >= Build.VERSION_CODES.M) { 999 boolean hasTimeZone = false; 1000 try { 1001 hasTimeZone = ZoneInfoDb.getInstance().hasTimeZone(timeZone); 1002 } catch (IOException ignored) { 1003 } 1004 1005 if (!hasTimeZone) { 1006 throw new IllegalArgumentException("Timezone: " + timeZone + " is not an Olson ID"); 1007 } 1008 } 1009 1010 try { 1011 mService.setTimeZone(timeZone); 1012 } catch (RemoteException ex) { 1013 throw ex.rethrowFromSystemServer(); 1014 } 1015 } 1016 1017 /** @hide */ getNextWakeFromIdleTime()1018 public long getNextWakeFromIdleTime() { 1019 try { 1020 return mService.getNextWakeFromIdleTime(); 1021 } catch (RemoteException ex) { 1022 throw ex.rethrowFromSystemServer(); 1023 } 1024 } 1025 1026 /** 1027 * Gets information about the next alarm clock currently scheduled. 1028 * 1029 * The alarm clocks considered are those scheduled by any application 1030 * using the {@link #setAlarmClock} method. 1031 * 1032 * @return An {@link AlarmClockInfo} object describing the next upcoming alarm 1033 * clock event that will occur. If there are no alarm clock events currently 1034 * scheduled, this method will return {@code null}. 1035 * 1036 * @see #setAlarmClock 1037 * @see AlarmClockInfo 1038 * @see #ACTION_NEXT_ALARM_CLOCK_CHANGED 1039 */ getNextAlarmClock()1040 public AlarmClockInfo getNextAlarmClock() { 1041 return getNextAlarmClock(mContext.getUserId()); 1042 } 1043 1044 /** 1045 * Gets information about the next alarm clock currently scheduled. 1046 * 1047 * The alarm clocks considered are those scheduled by any application 1048 * using the {@link #setAlarmClock} method within the given user. 1049 * 1050 * @return An {@link AlarmClockInfo} object describing the next upcoming alarm 1051 * clock event that will occur within the given user. If there are no alarm clock 1052 * events currently scheduled in that user, this method will return {@code null}. 1053 * 1054 * @see #setAlarmClock 1055 * @see AlarmClockInfo 1056 * @see #ACTION_NEXT_ALARM_CLOCK_CHANGED 1057 * 1058 * @hide 1059 */ getNextAlarmClock(int userId)1060 public AlarmClockInfo getNextAlarmClock(int userId) { 1061 try { 1062 return mService.getNextAlarmClock(userId); 1063 } catch (RemoteException ex) { 1064 throw ex.rethrowFromSystemServer(); 1065 } 1066 } 1067 1068 /** 1069 * An immutable description of a scheduled "alarm clock" event. 1070 * 1071 * @see AlarmManager#setAlarmClock 1072 * @see AlarmManager#getNextAlarmClock 1073 */ 1074 public static final class AlarmClockInfo implements Parcelable { 1075 1076 private final long mTriggerTime; 1077 private final PendingIntent mShowIntent; 1078 1079 /** 1080 * Creates a new alarm clock description. 1081 * 1082 * @param triggerTime time at which the underlying alarm is triggered in wall time 1083 * milliseconds since the epoch 1084 * @param showIntent an intent that can be used to show or edit details of 1085 * the alarm clock. 1086 */ AlarmClockInfo(long triggerTime, PendingIntent showIntent)1087 public AlarmClockInfo(long triggerTime, PendingIntent showIntent) { 1088 mTriggerTime = triggerTime; 1089 mShowIntent = showIntent; 1090 } 1091 1092 /** 1093 * Use the {@link #CREATOR} 1094 * @hide 1095 */ AlarmClockInfo(Parcel in)1096 AlarmClockInfo(Parcel in) { 1097 mTriggerTime = in.readLong(); 1098 mShowIntent = in.readParcelable(PendingIntent.class.getClassLoader()); 1099 } 1100 1101 /** 1102 * Returns the time at which the alarm is going to trigger. 1103 * 1104 * This value is UTC wall clock time in milliseconds, as returned by 1105 * {@link System#currentTimeMillis()} for example. 1106 */ getTriggerTime()1107 public long getTriggerTime() { 1108 return mTriggerTime; 1109 } 1110 1111 /** 1112 * Returns an intent that can be used to show or edit details of the alarm clock in 1113 * the application that scheduled it. 1114 * 1115 * <p class="note">Beware that any application can retrieve and send this intent, 1116 * potentially with additional fields filled in. See 1117 * {@link PendingIntent#send(android.content.Context, int, android.content.Intent) 1118 * PendingIntent.send()} and {@link android.content.Intent#fillIn Intent.fillIn()} 1119 * for details. 1120 */ getShowIntent()1121 public PendingIntent getShowIntent() { 1122 return mShowIntent; 1123 } 1124 1125 @Override describeContents()1126 public int describeContents() { 1127 return 0; 1128 } 1129 1130 @Override writeToParcel(Parcel dest, int flags)1131 public void writeToParcel(Parcel dest, int flags) { 1132 dest.writeLong(mTriggerTime); 1133 dest.writeParcelable(mShowIntent, flags); 1134 } 1135 1136 public static final @android.annotation.NonNull Creator<AlarmClockInfo> CREATOR = new Creator<AlarmClockInfo>() { 1137 @Override 1138 public AlarmClockInfo createFromParcel(Parcel in) { 1139 return new AlarmClockInfo(in); 1140 } 1141 1142 @Override 1143 public AlarmClockInfo[] newArray(int size) { 1144 return new AlarmClockInfo[size]; 1145 } 1146 }; 1147 1148 /** @hide */ dumpDebug(ProtoOutputStream proto, long fieldId)1149 public void dumpDebug(ProtoOutputStream proto, long fieldId) { 1150 final long token = proto.start(fieldId); 1151 proto.write(AlarmClockInfoProto.TRIGGER_TIME_MS, mTriggerTime); 1152 if (mShowIntent != null) { 1153 mShowIntent.dumpDebug(proto, AlarmClockInfoProto.SHOW_INTENT); 1154 } 1155 proto.end(token); 1156 } 1157 } 1158 } 1159