19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* 29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2007 The Android Open Source Project 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License. 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License. 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.app; 189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roosimport android.annotation.SdkConstant; 20c20b795cf05b48fe5e024c19dab9c7e4b18cd10fDavid Christieimport android.annotation.SystemApi; 21e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tateimport android.content.Context; 229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.Intent; 23e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tateimport android.os.Build; 24235510e67210f90de30c2d5582a2077ccc589619Jose Limaimport android.os.Parcel; 25235510e67210f90de30c2d5582a2077ccc589619Jose Limaimport android.os.Parcelable; 269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.RemoteException; 27c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roosimport android.os.UserHandle; 28ebe51fc0d860077245c44bfb00130be62da001e1David Christieimport android.os.WorkSource; 29235510e67210f90de30c2d5582a2077ccc589619Jose Limaimport android.os.Parcelable.Creator; 309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This class provides access to the system alarm services. These allow you 339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to schedule your application to be run at some point in the future. When 349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * an alarm goes off, the {@link Intent} that had been registered for it 359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * is broadcast by the system, automatically starting the target application 369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * if it is not already running. Registered alarms are retained while the 379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * device is asleep (and can optionally wake the device up if they go off 389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * during that time), but will be cleared if it is turned off and rebooted. 39a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * 40a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * <p>The Alarm Manager holds a CPU wake lock as long as the alarm receiver's 41a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * onReceive() method is executing. This guarantees that the phone will not sleep 42a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * until you have finished handling the broadcast. Once onReceive() returns, the 43a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * Alarm Manager releases this wake lock. This means that the phone will in some 44a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * cases sleep as soon as your onReceive() method completes. If your alarm receiver 45a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * called {@link android.content.Context#startService Context.startService()}, it 46a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * is possible that the phone will sleep before the requested service is launched. 47a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * To prevent this, your BroadcastReceiver and Service will need to implement a 48a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * separate wake lock policy to ensure that the phone continues running until the 49a34df8a2ba450b2c2ad83ccbbac30b80e2706bb2Chris Tate * service becomes available. 509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p><b>Note: The Alarm Manager is intended for cases where you want to have 529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * your application code run at a specific time, even if your application is 539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * not currently running. For normal timing operations (ticks, timeouts, 549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * etc) it is easier and much more efficient to use 559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link android.os.Handler}.</b> 569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 57109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * <p class="caution"><strong>Note:</strong> Beginning with API 19 58109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * ({@link android.os.Build.VERSION_CODES#KITKAT}) alarm delivery is inexact: 59109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * the OS will shift alarms in order to minimize wakeups and battery use. There are 60109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * new APIs to support applications which need strict delivery guarantees; see 61109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * {@link #setWindow(int, long, long, PendingIntent)} and 62109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * {@link #setExact(int, long, PendingIntent)}. Applications whose {@code targetSdkVersion} 63109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * is earlier than API 19 will continue to see the previous behavior in which all 64109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * alarms are delivered exactly when requested. 65109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * 669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>You do not 679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * instantiate this class directly; instead, retrieve it through 689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link android.content.Context#getSystemService 699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Context.getSystemService(Context.ALARM_SERVICE)}. 709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class AlarmManager 729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 73e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate private static final String TAG = "AlarmManager"; 74e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate 759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Alarm time in {@link System#currentTimeMillis System.currentTimeMillis()} 779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * (wall clock time in UTC), which will wake up the device when 789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * it goes off. 799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int RTC_WAKEUP = 0; 819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Alarm time in {@link System#currentTimeMillis System.currentTimeMillis()} 839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * (wall clock time in UTC). This alarm does not wake the 849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * device up; if it goes off while the device is asleep, it will not be 859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * delivered until the next time the device wakes up. 869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int RTC = 1; 889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Alarm time in {@link android.os.SystemClock#elapsedRealtime 909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * SystemClock.elapsedRealtime()} (time since boot, including sleep), 919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * which will wake up the device when it goes off. 929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int ELAPSED_REALTIME_WAKEUP = 2; 949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Alarm time in {@link android.os.SystemClock#elapsedRealtime 969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * SystemClock.elapsedRealtime()} (time since boot, including sleep). 979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This alarm does not wake the device up; if it goes off while the device 989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * is asleep, it will not be delivered until the next time the device 999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * wakes up. 1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int ELAPSED_REALTIME = 3; 1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 103c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos /** 104c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * Broadcast Action: Sent after the value returned by 105c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * {@link #getNextAlarmClock()} has changed. 106c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * 107c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * <p class="note">This is a protected intent that can only be sent by the system. 108c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * It is only sent to registered receivers.</p> 109c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos */ 110c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) 111c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos public static final String ACTION_NEXT_ALARM_CLOCK_CHANGED = 112c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos "android.app.action.NEXT_ALARM_CLOCK_CHANGED"; 113c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos 11457ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate /** @hide */ 11557ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate public static final long WINDOW_EXACT = 0; 11657ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate /** @hide */ 11757ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate public static final long WINDOW_HEURISTIC = -1; 11857ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate 1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private final IAlarmManager mService; 120e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate private final boolean mAlwaysExact; 1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12257ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate 1239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * package private on purpose 1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 126e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate AlarmManager(IAlarmManager service, Context ctx) { 1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mService = service; 128e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate 129e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate final int sdkVersion = ctx.getApplicationInfo().targetSdkVersion; 130e8222dddaf2e3da14380101e818d4254899e0c0dChet Haase mAlwaysExact = (sdkVersion < Build.VERSION_CODES.KITKAT); 1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 13257ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate 13357ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate private long legacyExactLength() { 13457ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate return (mAlwaysExact ? WINDOW_EXACT : WINDOW_HEURISTIC); 13557ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate } 13657ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate 1379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 13857ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * <p>Schedule an alarm. <b>Note: for timing operations (ticks, timeouts, 139062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * etc) it is easier and much more efficient to use {@link android.os.Handler}.</b> 140062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * If there is already an alarm scheduled for the same IntentSender, that previous 141062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * alarm will first be canceled. 1429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 143062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <p>If the stated trigger time is in the past, the alarm will be triggered 1449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * immediately. If there is already an alarm for this Intent 1459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * scheduled (with the equality of two intents being defined by 1469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link Intent#filterEquals}), then it will be removed and replaced by 1479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this one. 1489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p> 150062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * The alarm is an Intent broadcast that goes to a broadcast receiver that 1519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you registered with {@link android.content.Context#registerReceiver} 1529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * or through the <receiver> tag in an AndroidManifest.xml file. 1539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p> 1559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Alarm intents are delivered with a data extra of type int called 1569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link Intent#EXTRA_ALARM_COUNT Intent.EXTRA_ALARM_COUNT} that indicates 1579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * how many past alarm events have been accumulated into this intent 1589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * broadcast. Recurring alarms that have gone undelivered because the 1599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * phone was asleep may have a count greater than one when delivered. 160062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * 161109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * <div class="note"> 162062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <p> 163062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <b>Note:</b> Beginning in API 19, the trigger time passed to this method 164062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * is treated as inexact: the alarm will not be delivered before this time, but 165062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * may be deferred and delivered some time later. The OS will use 166062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * this policy in order to "batch" alarms together across the entire system, 167062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * minimizing the number of times the device needs to "wake up" and minimizing 168062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * battery use. In general, alarms scheduled in the near future will not 169062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * be deferred as long as alarms scheduled far in the future. 170062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * 171062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <p> 172062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * With the new batching policy, delivery ordering guarantees are not as 173062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * strong as they were previously. If the application sets multiple alarms, 174109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * it is possible that these alarms' <em>actual</em> delivery ordering may not match 175109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * the order of their <em>requested</em> delivery times. If your application has 176062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * strong ordering requirements there are other APIs that you can use to get 177062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * the necessary behavior; see {@link #setWindow(int, long, long, PendingIntent)} 178062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * and {@link #setExact(int, long, PendingIntent)}. 179062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * 180062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <p> 181109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * Applications whose {@code targetSdkVersion} is before API 19 will 182062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * continue to get the previous alarm behavior: all of their scheduled alarms 183062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * will be treated as exact. 184109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * </div> 185062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * 186062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, 187062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * {@link #RTC}, or {@link #RTC_WAKEUP}. 18879074cd935854b497cb894046da13bb08a113982Jesse Wilson * @param triggerAtMillis time in milliseconds that the alarm should go 18979074cd935854b497cb894046da13bb08a113982Jesse Wilson * off, using the appropriate clock (depending on the alarm type). 1909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param operation Action to perform when the alarm goes off; 1919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * typically comes from {@link PendingIntent#getBroadcast 1929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * IntentSender.getBroadcast()}. 1939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.os.Handler 19557ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #setExact 1969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #setRepeating 19757ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #setWindow 1989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #cancel 1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.content.Context#sendBroadcast 2009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.content.Context#registerReceiver 2019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.content.Intent#filterEquals 2029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #ELAPSED_REALTIME 2039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #ELAPSED_REALTIME_WAKEUP 2049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #RTC 2059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #RTC_WAKEUP 2069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 20779074cd935854b497cb894046da13bb08a113982Jesse Wilson public void set(int type, long triggerAtMillis, PendingIntent operation) { 208c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos setImpl(type, triggerAtMillis, legacyExactLength(), 0, operation, null, null); 2099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Schedule a repeating alarm. <b>Note: for timing operations (ticks, 2139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * timeouts, etc) it is easier and much more efficient to use 2149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link android.os.Handler}.</b> If there is already an alarm scheduled 2159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * for the same IntentSender, it will first be canceled. 2169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 217062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <p>Like {@link #set}, except you can also supply a period at which 218062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * the alarm will automatically repeat. This alarm continues 219062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * repeating until explicitly removed with {@link #cancel}. If the stated 220062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * trigger time is in the past, the alarm will be triggered immediately, with an 2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * alarm count depending on how far in the past the trigger time is relative 2229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to the repeat interval. 2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>If an alarm is delayed (by system sleep, for example, for non 2259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * _WAKEUP alarm types), a skipped repeat will be delivered as soon as 2269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * possible. After that, future alarms will be delivered according to the 2279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * original schedule; they do not drift over time. For example, if you have 2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * set a recurring alarm for the top of every hour but the phone was asleep 2299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * from 7:45 until 8:45, an alarm will be sent as soon as the phone awakens, 2309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * then the next alarm will be sent at 9:00. 2319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>If your application wants to allow the delivery times to drift in 2339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * order to guarantee that at least a certain time interval always elapses 2349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * between alarms, then the approach to take is to use one-time alarms, 2359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * scheduling the next one yourself when handling each alarm delivery. 2369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 237109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * <p class="note"> 238062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <b>Note:</b> as of API 19, all repeating alarms are inexact. If your 239062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * application needs precise delivery times then it must use one-time 240062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * exact alarms, rescheduling each time as described above. Legacy applications 241109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * whose {@code targetSdkVersion} is earlier than API 19 will continue to have all 242062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * of their alarms, including repeating alarms, treated as exact. 243062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * 244062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, 245062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * {@link #RTC}, or {@link #RTC_WAKEUP}. 24679074cd935854b497cb894046da13bb08a113982Jesse Wilson * @param triggerAtMillis time in milliseconds that the alarm should first 24779074cd935854b497cb894046da13bb08a113982Jesse Wilson * go off, using the appropriate clock (depending on the alarm type). 24879074cd935854b497cb894046da13bb08a113982Jesse Wilson * @param intervalMillis interval in milliseconds between subsequent repeats 24979074cd935854b497cb894046da13bb08a113982Jesse Wilson * of the alarm. 2509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param operation Action to perform when the alarm goes off; 2519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * typically comes from {@link PendingIntent#getBroadcast 2529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * IntentSender.getBroadcast()}. 2539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.os.Handler 2559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #set 25657ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #setExact 25757ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #setWindow 2589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #cancel 2599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.content.Context#sendBroadcast 2609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.content.Context#registerReceiver 2619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.content.Intent#filterEquals 2629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #ELAPSED_REALTIME 2639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #ELAPSED_REALTIME_WAKEUP 2649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #RTC 2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #RTC_WAKEUP 2669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 26779074cd935854b497cb894046da13bb08a113982Jesse Wilson public void setRepeating(int type, long triggerAtMillis, 26879074cd935854b497cb894046da13bb08a113982Jesse Wilson long intervalMillis, PendingIntent operation) { 269c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos setImpl(type, triggerAtMillis, legacyExactLength(), intervalMillis, operation, null, null); 27057ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate } 27157ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate 27257ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate /** 273062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * Schedule an alarm to be delivered within a given window of time. This method 274062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * is similar to {@link #set(int, long, PendingIntent)}, but allows the 275062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * application to precisely control the degree to which its delivery might be 276062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * adjusted by the OS. This method allows an application to take advantage of the 277062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * battery optimizations that arise from delivery batching even when it has 278062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * modest timeliness requirements for its alarms. 27957ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * 280062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <p> 281109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * This method can also be used to achieve strict ordering guarantees among 282109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * multiple alarms by ensuring that the windows requested for each alarm do 283109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * not intersect. 28457ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * 285062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <p> 286062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * When precise delivery is not required, applications should use the standard 287062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * {@link #set(int, long, PendingIntent)} method. This will give the OS the most 288109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * flexibility to minimize wakeups and battery use. For alarms that must be delivered 289062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * at precisely-specified times with no acceptable variation, applications can use 290062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * {@link #setExact(int, long, PendingIntent)}. 291062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * 292062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, 293109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * {@link #RTC}, or {@link #RTC_WAKEUP}. 29457ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @param windowStartMillis The earliest time, in milliseconds, that the alarm should 29557ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * be delivered, expressed in the appropriate clock's units (depending on the alarm 29657ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * type). 29757ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @param windowLengthMillis The length of the requested delivery window, 29857ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * in milliseconds. The alarm will be delivered no later than this many 299062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * milliseconds after {@code windowStartMillis}. Note that this parameter 30057ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * is a <i>duration,</i> not the timestamp of the end of the window. 30157ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @param operation Action to perform when the alarm goes off; 30257ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * typically comes from {@link PendingIntent#getBroadcast 30357ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * IntentSender.getBroadcast()}. 30457ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * 30557ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #set 30657ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #setExact 30757ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #setRepeating 30857ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #cancel 30957ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see android.content.Context#sendBroadcast 31057ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see android.content.Context#registerReceiver 31157ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see android.content.Intent#filterEquals 31257ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #ELAPSED_REALTIME 31357ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #ELAPSED_REALTIME_WAKEUP 31457ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #RTC 31557ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate * @see #RTC_WAKEUP 31657ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate */ 31757ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate public void setWindow(int type, long windowStartMillis, long windowLengthMillis, 31857ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate PendingIntent operation) { 319c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos setImpl(type, windowStartMillis, windowLengthMillis, 0, operation, null, null); 320e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate } 321e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate 322e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate /** 323062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * Schedule an alarm to be delivered precisely at the stated time. 324062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * 325062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <p> 326062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * This method is like {@link #set(int, long, PendingIntent)}, but does not permit 327062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * the OS to adjust the delivery time. The alarm will be delivered as nearly as 328062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * possible to the requested trigger time. 329062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * 330062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <p> 331062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * <b>Note:</b> only alarms for which there is a strong demand for exact-time 332062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * delivery (such as an alarm clock ringing at the requested time) should be 333062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * scheduled as exact. Applications are strongly discouraged from using exact 334062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * alarms unnecessarily as they reduce the OS's ability to minimize battery use. 335062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * 336062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, 337062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * {@link #RTC}, or {@link #RTC_WAKEUP}. 338062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @param triggerAtMillis time in milliseconds that the alarm should go 339062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * off, using the appropriate clock (depending on the alarm type). 340062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @param operation Action to perform when the alarm goes off; 341062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * typically comes from {@link PendingIntent#getBroadcast 342062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * IntentSender.getBroadcast()}. 343062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * 344062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see #set 345062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see #setRepeating 346062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see #setWindow 347062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see #cancel 348062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see android.content.Context#sendBroadcast 349062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see android.content.Context#registerReceiver 350062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see android.content.Intent#filterEquals 351062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see #ELAPSED_REALTIME 352062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see #ELAPSED_REALTIME_WAKEUP 353062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see #RTC 354062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @see #RTC_WAKEUP 355e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate */ 356e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate public void setExact(int type, long triggerAtMillis, PendingIntent operation) { 357c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, operation, null, null); 358c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos } 359c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos 360c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos /** 361c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * Schedule an alarm that represents an alarm clock. 362c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * 363c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * The system may choose to display information about this alarm to the user. 364c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * 365c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * <p> 366c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * This method is like {@link #setExact(int, long, PendingIntent)}, but implies 367c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * {@link #RTC_WAKEUP}. 368c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * 369c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @param info 370c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @param operation Action to perform when the alarm goes off; 371c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * typically comes from {@link PendingIntent#getBroadcast 372c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * IntentSender.getBroadcast()}. 373c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * 374c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see #set 375c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see #setRepeating 376c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see #setWindow 377c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see #setExact 378c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see #cancel 379c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see #getNextAlarmClock() 380c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see android.content.Context#sendBroadcast 381c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see android.content.Context#registerReceiver 382c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see android.content.Intent#filterEquals 383c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos */ 384c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos public void setAlarmClock(AlarmClockInfo info, PendingIntent operation) { 385c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos setImpl(RTC_WAKEUP, info.getTriggerTime(), WINDOW_EXACT, 0, operation, null, info); 386ebe51fc0d860077245c44bfb00130be62da001e1David Christie } 387ebe51fc0d860077245c44bfb00130be62da001e1David Christie 388ebe51fc0d860077245c44bfb00130be62da001e1David Christie /** @hide */ 389c20b795cf05b48fe5e024c19dab9c7e4b18cd10fDavid Christie @SystemApi 390ebe51fc0d860077245c44bfb00130be62da001e1David Christie public void set(int type, long triggerAtMillis, long windowMillis, long intervalMillis, 391ebe51fc0d860077245c44bfb00130be62da001e1David Christie PendingIntent operation, WorkSource workSource) { 392c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos setImpl(type, triggerAtMillis, windowMillis, intervalMillis, operation, workSource, null); 393e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate } 394e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate 39557ceaaa0aa1fece02ff82cd903a26bdf65131c56Christopher Tate private void setImpl(int type, long triggerAtMillis, long windowMillis, long intervalMillis, 396c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos PendingIntent operation, WorkSource workSource, AlarmClockInfo alarmClock) { 3975f221e8f93fff70f8a2e192976aac587b8c9c026Christopher Tate if (triggerAtMillis < 0) { 39856cfa244128402ca288be5726cc0eb9b2d668295Christopher Tate /* NOTYET 3995f221e8f93fff70f8a2e192976aac587b8c9c026Christopher Tate if (mAlwaysExact) { 4005f221e8f93fff70f8a2e192976aac587b8c9c026Christopher Tate // Fatal error for KLP+ apps to use negative trigger times 4015f221e8f93fff70f8a2e192976aac587b8c9c026Christopher Tate throw new IllegalArgumentException("Invalid alarm trigger time " 4025f221e8f93fff70f8a2e192976aac587b8c9c026Christopher Tate + triggerAtMillis); 4035f221e8f93fff70f8a2e192976aac587b8c9c026Christopher Tate } 40456cfa244128402ca288be5726cc0eb9b2d668295Christopher Tate */ 4055f221e8f93fff70f8a2e192976aac587b8c9c026Christopher Tate triggerAtMillis = 0; 4065f221e8f93fff70f8a2e192976aac587b8c9c026Christopher Tate } 407ebe51fc0d860077245c44bfb00130be62da001e1David Christie 4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 409ebe51fc0d860077245c44bfb00130be62da001e1David Christie mService.set(type, triggerAtMillis, windowMillis, intervalMillis, operation, 410c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos workSource, alarmClock); 4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException ex) { 4129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 416109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * Available inexact recurrence interval recognized by 417109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * {@link #setInexactRepeating(int, long, long, PendingIntent)} 418109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * when running on Android prior to API 19. 4199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final long INTERVAL_FIFTEEN_MINUTES = 15 * 60 * 1000; 421e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate 422e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate /** 423109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * Available inexact recurrence interval recognized by 424109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * {@link #setInexactRepeating(int, long, long, PendingIntent)} 425109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * when running on Android prior to API 19. 426e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate */ 4279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final long INTERVAL_HALF_HOUR = 2*INTERVAL_FIFTEEN_MINUTES; 428e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate 429e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate /** 430109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * Available inexact recurrence interval recognized by 431109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * {@link #setInexactRepeating(int, long, long, PendingIntent)} 432109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * when running on Android prior to API 19. 433e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate */ 4349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final long INTERVAL_HOUR = 2*INTERVAL_HALF_HOUR; 435e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate 436e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate /** 437109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * Available inexact recurrence interval recognized by 438109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * {@link #setInexactRepeating(int, long, long, PendingIntent)} 439109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * when running on Android prior to API 19. 440e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate */ 4419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final long INTERVAL_HALF_DAY = 12*INTERVAL_HOUR; 442e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate 443e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate /** 444109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * Available inexact recurrence interval recognized by 445109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * {@link #setInexactRepeating(int, long, long, PendingIntent)} 446109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * when running on Android prior to API 19. 447e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate */ 4489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final long INTERVAL_DAY = 2*INTERVAL_HALF_DAY; 449e0a22b324d0e3157e570ea5f71cc682fa9696e01Christopher Tate 4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Schedule a repeating alarm that has inexact trigger time requirements; 4529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * for example, an alarm that repeats every hour, but not necessarily at 4539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the top of every hour. These alarms are more power-efficient than 454109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * the strict recurrences traditionally supplied by {@link #setRepeating}, since the 455109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * system can adjust alarms' delivery times to cause them to fire simultaneously, 4569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * avoiding waking the device from sleep more than necessary. 457109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * 4589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>Your alarm's first trigger will not be before the requested time, 4599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * but it might not occur for almost a full interval after that time. In 4609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * addition, while the overall period of the repeating alarm will be as 4619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * requested, the time between any two successive firings of the alarm 4629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * may vary. If your application demands very low jitter, use 463109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * one-shot alarms with an appropriate window instead; see {@link 464109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * #setWindow(int, long, long, PendingIntent)} and 465109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * {@link #setExact(int, long, PendingIntent)}. 466109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * 467109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * <p class="note"> 468109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * As of API 19, all repeating alarms are inexact. Because this method has 469109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * been available since API 3, your application can safely call it and be 470109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * assured that it will get similar behavior on both current and older versions 471109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * of Android. 47279074cd935854b497cb894046da13bb08a113982Jesse Wilson * 473062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, 474062bce7d87e34f85dc0972c03c59f37d6df15c39Christopher Tate * {@link #RTC}, or {@link #RTC_WAKEUP}. 47579074cd935854b497cb894046da13bb08a113982Jesse Wilson * @param triggerAtMillis time in milliseconds that the alarm should first 47679074cd935854b497cb894046da13bb08a113982Jesse Wilson * go off, using the appropriate clock (depending on the alarm type). This 47779074cd935854b497cb894046da13bb08a113982Jesse Wilson * is inexact: the alarm will not fire before this time, but there may be a 47879074cd935854b497cb894046da13bb08a113982Jesse Wilson * delay of almost an entire alarm interval before the first invocation of 47979074cd935854b497cb894046da13bb08a113982Jesse Wilson * the alarm. 48079074cd935854b497cb894046da13bb08a113982Jesse Wilson * @param intervalMillis interval in milliseconds between subsequent repeats 481109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * of the alarm. Prior to API 19, if this is one of INTERVAL_FIFTEEN_MINUTES, 48279074cd935854b497cb894046da13bb08a113982Jesse Wilson * INTERVAL_HALF_HOUR, INTERVAL_HOUR, INTERVAL_HALF_DAY, or INTERVAL_DAY 48379074cd935854b497cb894046da13bb08a113982Jesse Wilson * then the alarm will be phase-aligned with other alarms to reduce the 48479074cd935854b497cb894046da13bb08a113982Jesse Wilson * number of wakeups. Otherwise, the alarm will be set as though the 485109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * application had called {@link #setRepeating}. As of API 19, all repeating 486109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * alarms will be inexact and subject to batching with other alarms regardless 487109e4db47187adc484dbbf23ceaaa4295c6df105Christopher Tate * of their stated repeat interval. 4889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param operation Action to perform when the alarm goes off; 4899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * typically comes from {@link PendingIntent#getBroadcast 4909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * IntentSender.getBroadcast()}. 4919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 4929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.os.Handler 4939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #set 4949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #cancel 4959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.content.Context#sendBroadcast 4969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.content.Context#registerReceiver 4979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.content.Intent#filterEquals 4989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #ELAPSED_REALTIME 4999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #ELAPSED_REALTIME_WAKEUP 5009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #RTC 5019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #RTC_WAKEUP 5029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #INTERVAL_FIFTEEN_MINUTES 5039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #INTERVAL_HALF_HOUR 5049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #INTERVAL_HOUR 5059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #INTERVAL_HALF_DAY 5069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #INTERVAL_DAY 5079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 50879074cd935854b497cb894046da13bb08a113982Jesse Wilson public void setInexactRepeating(int type, long triggerAtMillis, 50979074cd935854b497cb894046da13bb08a113982Jesse Wilson long intervalMillis, PendingIntent operation) { 510c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, intervalMillis, operation, null, null); 5119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Remove any alarms with a matching {@link Intent}. 5159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Any alarm, of any type, whose Intent matches this one (as defined by 5169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link Intent#filterEquals}), will be canceled. 5179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param operation IntentSender which matches a previously added 5199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * IntentSender. 5209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see #set 5229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void cancel(PendingIntent operation) { 5249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 5259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mService.remove(operation); 5269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException ex) { 5279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 52997e44947282b3918ee0bed2d16b33b983f882580Dan Egnor 53097e44947282b3918ee0bed2d16b33b983f882580Dan Egnor /** 53197e44947282b3918ee0bed2d16b33b983f882580Dan Egnor * Set the system wall clock time. 53297e44947282b3918ee0bed2d16b33b983f882580Dan Egnor * Requires the permission android.permission.SET_TIME. 53397e44947282b3918ee0bed2d16b33b983f882580Dan Egnor * 53497e44947282b3918ee0bed2d16b33b983f882580Dan Egnor * @param millis time in milliseconds since the Epoch 53597e44947282b3918ee0bed2d16b33b983f882580Dan Egnor */ 53697e44947282b3918ee0bed2d16b33b983f882580Dan Egnor public void setTime(long millis) { 53797e44947282b3918ee0bed2d16b33b983f882580Dan Egnor try { 53897e44947282b3918ee0bed2d16b33b983f882580Dan Egnor mService.setTime(millis); 53997e44947282b3918ee0bed2d16b33b983f882580Dan Egnor } catch (RemoteException ex) { 54097e44947282b3918ee0bed2d16b33b983f882580Dan Egnor } 54197e44947282b3918ee0bed2d16b33b983f882580Dan Egnor } 54297e44947282b3918ee0bed2d16b33b983f882580Dan Egnor 54397e44947282b3918ee0bed2d16b33b983f882580Dan Egnor /** 54497e44947282b3918ee0bed2d16b33b983f882580Dan Egnor * Set the system default time zone. 54597e44947282b3918ee0bed2d16b33b983f882580Dan Egnor * Requires the permission android.permission.SET_TIME_ZONE. 54697e44947282b3918ee0bed2d16b33b983f882580Dan Egnor * 54797e44947282b3918ee0bed2d16b33b983f882580Dan Egnor * @param timeZone in the format understood by {@link java.util.TimeZone} 54897e44947282b3918ee0bed2d16b33b983f882580Dan Egnor */ 5499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setTimeZone(String timeZone) { 5509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 5519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mService.setTimeZone(timeZone); 5529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (RemoteException ex) { 5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 555c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos 556c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos /** 557c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * Gets information about the next alarm clock currently scheduled. 558c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * 559c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * The alarm clocks considered are those scheduled by {@link #setAlarmClock} 560c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * from any package of the calling user. 561c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * 562c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see #setAlarmClock 563c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see AlarmClockInfo 564c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos */ 565c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos public AlarmClockInfo getNextAlarmClock() { 566c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos return getNextAlarmClock(UserHandle.myUserId()); 567c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos } 568c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos 569c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos /** 570c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * Gets information about the next alarm clock currently scheduled. 571c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * 572c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * The alarm clocks considered are those scheduled by {@link #setAlarmClock} 573c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * from any package of the given {@parm userId}. 574c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * 575c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see #setAlarmClock 576c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @see AlarmClockInfo 577c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * 578c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos * @hide 579c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos */ 580c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos public AlarmClockInfo getNextAlarmClock(int userId) { 581c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos try { 582c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos return mService.getNextAlarmClock(userId); 583c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos } catch (RemoteException ex) { 584c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos return null; 585c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos } 586c42a1e1071937ae48b7aa5d6291a32c29078b74bAdrian Roos } 587235510e67210f90de30c2d5582a2077ccc589619Jose Lima 588235510e67210f90de30c2d5582a2077ccc589619Jose Lima /** 589235510e67210f90de30c2d5582a2077ccc589619Jose Lima * An immutable description of an alarm clock. 590235510e67210f90de30c2d5582a2077ccc589619Jose Lima * 591235510e67210f90de30c2d5582a2077ccc589619Jose Lima * @see AlarmManager#setAlarmClock 592235510e67210f90de30c2d5582a2077ccc589619Jose Lima * @see AlarmManager#getNextAlarmClock 593235510e67210f90de30c2d5582a2077ccc589619Jose Lima */ 594235510e67210f90de30c2d5582a2077ccc589619Jose Lima public static final class AlarmClockInfo implements Parcelable { 595235510e67210f90de30c2d5582a2077ccc589619Jose Lima 596235510e67210f90de30c2d5582a2077ccc589619Jose Lima private final long mTriggerTime; 597235510e67210f90de30c2d5582a2077ccc589619Jose Lima private final PendingIntent mShowIntent; 598235510e67210f90de30c2d5582a2077ccc589619Jose Lima 599235510e67210f90de30c2d5582a2077ccc589619Jose Lima /** 600235510e67210f90de30c2d5582a2077ccc589619Jose Lima * Creates a new alarm clock description. 601235510e67210f90de30c2d5582a2077ccc589619Jose Lima * 602235510e67210f90de30c2d5582a2077ccc589619Jose Lima * @param triggerTime time at which the underlying alarm is triggered in wall time 603235510e67210f90de30c2d5582a2077ccc589619Jose Lima * milliseconds since the epoch 604235510e67210f90de30c2d5582a2077ccc589619Jose Lima * @param showIntent an intent that can be used to show or edit details of 605235510e67210f90de30c2d5582a2077ccc589619Jose Lima * the alarm clock. 606235510e67210f90de30c2d5582a2077ccc589619Jose Lima */ 607235510e67210f90de30c2d5582a2077ccc589619Jose Lima public AlarmClockInfo(long triggerTime, PendingIntent showIntent) { 608235510e67210f90de30c2d5582a2077ccc589619Jose Lima mTriggerTime = triggerTime; 609235510e67210f90de30c2d5582a2077ccc589619Jose Lima mShowIntent = showIntent; 610235510e67210f90de30c2d5582a2077ccc589619Jose Lima } 611235510e67210f90de30c2d5582a2077ccc589619Jose Lima 612235510e67210f90de30c2d5582a2077ccc589619Jose Lima /** 613235510e67210f90de30c2d5582a2077ccc589619Jose Lima * Use the {@link #CREATOR} 614235510e67210f90de30c2d5582a2077ccc589619Jose Lima * @hide 615235510e67210f90de30c2d5582a2077ccc589619Jose Lima */ 616235510e67210f90de30c2d5582a2077ccc589619Jose Lima AlarmClockInfo(Parcel in) { 617235510e67210f90de30c2d5582a2077ccc589619Jose Lima mTriggerTime = in.readLong(); 618235510e67210f90de30c2d5582a2077ccc589619Jose Lima mShowIntent = in.readParcelable(PendingIntent.class.getClassLoader()); 619235510e67210f90de30c2d5582a2077ccc589619Jose Lima } 620235510e67210f90de30c2d5582a2077ccc589619Jose Lima 621235510e67210f90de30c2d5582a2077ccc589619Jose Lima /** 622235510e67210f90de30c2d5582a2077ccc589619Jose Lima * Returns the time at which the alarm is going to trigger. 623235510e67210f90de30c2d5582a2077ccc589619Jose Lima * 624235510e67210f90de30c2d5582a2077ccc589619Jose Lima * This value is UTC wall clock time in milliseconds, as returned by 625235510e67210f90de30c2d5582a2077ccc589619Jose Lima * {@link System#currentTimeMillis()} for example. 626235510e67210f90de30c2d5582a2077ccc589619Jose Lima */ 627235510e67210f90de30c2d5582a2077ccc589619Jose Lima public long getTriggerTime() { 628235510e67210f90de30c2d5582a2077ccc589619Jose Lima return mTriggerTime; 629235510e67210f90de30c2d5582a2077ccc589619Jose Lima } 630235510e67210f90de30c2d5582a2077ccc589619Jose Lima 631235510e67210f90de30c2d5582a2077ccc589619Jose Lima /** 632235510e67210f90de30c2d5582a2077ccc589619Jose Lima * Returns an intent intent that can be used to show or edit details of the alarm clock in 633235510e67210f90de30c2d5582a2077ccc589619Jose Lima * the application that scheduled it. 634235510e67210f90de30c2d5582a2077ccc589619Jose Lima * 635235510e67210f90de30c2d5582a2077ccc589619Jose Lima * <p class="note">Beware that any application can retrieve and send this intent, 636235510e67210f90de30c2d5582a2077ccc589619Jose Lima * potentially with additional fields filled in. See 637235510e67210f90de30c2d5582a2077ccc589619Jose Lima * {@link PendingIntent#send(android.content.Context, int, android.content.Intent) 638235510e67210f90de30c2d5582a2077ccc589619Jose Lima * PendingIntent.send()} and {@link android.content.Intent#fillIn Intent.fillIn()} 639235510e67210f90de30c2d5582a2077ccc589619Jose Lima * for details. 640235510e67210f90de30c2d5582a2077ccc589619Jose Lima */ 641235510e67210f90de30c2d5582a2077ccc589619Jose Lima public PendingIntent getShowIntent() { 642235510e67210f90de30c2d5582a2077ccc589619Jose Lima return mShowIntent; 643235510e67210f90de30c2d5582a2077ccc589619Jose Lima } 644235510e67210f90de30c2d5582a2077ccc589619Jose Lima 645235510e67210f90de30c2d5582a2077ccc589619Jose Lima @Override 646235510e67210f90de30c2d5582a2077ccc589619Jose Lima public int describeContents() { 647235510e67210f90de30c2d5582a2077ccc589619Jose Lima return 0; 648235510e67210f90de30c2d5582a2077ccc589619Jose Lima } 649235510e67210f90de30c2d5582a2077ccc589619Jose Lima 650235510e67210f90de30c2d5582a2077ccc589619Jose Lima @Override 651235510e67210f90de30c2d5582a2077ccc589619Jose Lima public void writeToParcel(Parcel dest, int flags) { 652235510e67210f90de30c2d5582a2077ccc589619Jose Lima dest.writeLong(mTriggerTime); 653235510e67210f90de30c2d5582a2077ccc589619Jose Lima dest.writeParcelable(mShowIntent, flags); 654235510e67210f90de30c2d5582a2077ccc589619Jose Lima } 655235510e67210f90de30c2d5582a2077ccc589619Jose Lima 656235510e67210f90de30c2d5582a2077ccc589619Jose Lima public static final Creator<AlarmClockInfo> CREATOR = new Creator<AlarmClockInfo>() { 657235510e67210f90de30c2d5582a2077ccc589619Jose Lima @Override 658235510e67210f90de30c2d5582a2077ccc589619Jose Lima public AlarmClockInfo createFromParcel(Parcel in) { 659235510e67210f90de30c2d5582a2077ccc589619Jose Lima return new AlarmClockInfo(in); 660235510e67210f90de30c2d5582a2077ccc589619Jose Lima } 661235510e67210f90de30c2d5582a2077ccc589619Jose Lima 662235510e67210f90de30c2d5582a2077ccc589619Jose Lima @Override 663235510e67210f90de30c2d5582a2077ccc589619Jose Lima public AlarmClockInfo[] newArray(int size) { 664235510e67210f90de30c2d5582a2077ccc589619Jose Lima return new AlarmClockInfo[size]; 665235510e67210f90de30c2d5582a2077ccc589619Jose Lima } 666235510e67210f90de30c2d5582a2077ccc589619Jose Lima }; 667235510e67210f90de30c2d5582a2077ccc589619Jose Lima } 6689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 669