AlarmClock.java revision c545799b80344a8747865627427bea746b6f28cb
1/*
2 * Copyright (C) 2010 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
17package android.provider;
18
19import android.annotation.SdkConstant;
20import android.annotation.SdkConstant.SdkConstantType;
21
22/**
23 * The AlarmClock provider contains an Intent action and extras that can be used
24 * to start an Activity to set a new alarm or timer in an alarm clock application.
25 *
26 * Applications that wish to receive the ACTION_SET_ALARM  and ACTION_SET_TIMER Intents
27 * should create an activity to handle the Intent that requires the permission
28 * com.android.alarm.permission.SET_ALARM.  Applications that wish to create a
29 * new alarm or timer should use
30 * {@link android.content.Context#startActivity Context.startActivity()} so that
31 * the user has the option of choosing which alarm clock application to use.
32 *
33 * Android TV devices may not support the alarm intents.
34 */
35public final class AlarmClock {
36    /**
37     * Activity Action: Set an alarm.
38     * <p>
39     * Activates an existing alarm or creates a new one.
40     * </p><p>
41     * This action requests an alarm to be set for a given time of day. If no time of day is
42     * specified, an implementation should start an activity that is capable of setting an alarm
43     * ({@link #EXTRA_SKIP_UI} is ignored in this case). If a time of day is specified, and
44     * {@link #EXTRA_SKIP_UI} is {@code true}, and the alarm is not repeating, the implementation
45     * should remove this alarm after it has been dismissed. If an identical alarm exists matching
46     * all parameters, the implementation may re-use it instead of creating a new one (in this case,
47     * the alarm should not be removed after dismissal).
48     * </p><p>
49     * This action always enables the alarm.
50     * </p><p>
51     * This activity could also be started in Voice Interaction mode. The activity should check
52     * {@link android.app.Activity#isVoiceInteraction}, and if true, the implementation should
53     * report a deeplink of the created/enabled alarm using
54     * {@link android.app.VoiceInteractor.CompleteVoiceRequest}. This allows follow-on voice actions
55     * such as {@link #ACTION_DISMISS_ALARM} to dismiss the alarm that was just enabled.
56     * </p>
57     * <h3>Request parameters</h3>
58     * <ul>
59     * <li>{@link #EXTRA_HOUR} <em>(optional)</em>: The hour of the alarm being set.
60     * <li>{@link #EXTRA_MINUTES} <em>(optional)</em>: The minutes of the alarm being set.
61     * <li>{@link #EXTRA_DAYS} <em>(optional)</em>: Weekdays for repeating alarm.
62     * <li>{@link #EXTRA_MESSAGE} <em>(optional)</em>: A custom message for the alarm.
63     * <li>{@link #EXTRA_RINGTONE} <em>(optional)</em>: A ringtone to play with this alarm.
64     * <li>{@link #EXTRA_VIBRATE} <em>(optional)</em>: Whether or not to activate the device
65     * vibrator for this alarm.
66     * <li>{@link #EXTRA_SKIP_UI} <em>(optional)</em>: Whether or not to display an activity for
67     * setting this alarm.
68     * </ul>
69     */
70    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
71    public static final String ACTION_SET_ALARM = "android.intent.action.SET_ALARM";
72
73    /**
74     * Activity Action: Dismiss an alarm.
75     * <p>
76     * The alarm to dismiss can be specified or searched for in one of the following ways:
77     * <ol>
78     * <li>The Intent's data URI, which represents a deeplink to the alarm.
79     * <li>The extra {@link #EXTRA_ALARM_SEARCH_MODE} to determine how to search for the alarm.
80     * </ol>
81     * </p><p>
82     * If neither of the above are given then:
83     * <ul>
84     * <li>If exactly one active alarm exists, it is dismissed.
85     * <li>If more than one active alarm exists, the user is prompted to choose the alarm to
86     * dismiss.
87     * </ul>
88     * </p><p>
89     * If the extra {@link #EXTRA_ALARM_SEARCH_MODE} is used, and the search results contain two or
90     * more matching alarms, then the implementation should show an UI with the results and allow
91     * the user to select the alarm to dismiss. If the implementation supports
92     * {@link android.content.Intent#CATEGORY_VOICE} and the activity is started in Voice
93     * Interaction mode (i.e. check {@link android.app.Activity#isVoiceInteraction}), then the
94     * implementation should additionally use {@link android.app.VoiceInteractor.PickOptionRequest}
95     * to start a voice interaction follow-on flow to help the user disambiguate the alarm by voice.
96     * </p><p>
97     * If the specified alarm is a single occurrence alarm, then dismissing it effectively disables
98     * the alarm; it will never ring again unless explicitly re-enabled.
99     * </p><p>
100     * If the specified alarm is a repeating alarm, then dismissing it only prevents the upcoming
101     * instance from ringing. The alarm remains enabled so that it will still ring on the date and
102     * time of the next instance (i.e. the instance after the upcoming one).
103     * </p>
104     *
105     * @see #EXTRA_ALARM_SEARCH_MODE
106     */
107    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
108    public static final String ACTION_DISMISS_ALARM = "android.intent.action.DISMISS_ALARM";
109
110    /**
111     * Activity Action: Snooze a currently ringing alarm.
112     * <p>
113     * Snoozes the currently ringing alarm. The extra {@link #EXTRA_ALARM_SNOOZE_DURATION} can be
114     * optionally set to specify the snooze duration; if unset, the implementation should use a
115     * reasonable default, for example 10 minutes. The alarm should ring again after the snooze
116     * duration.
117     * </p><p>
118     * Note: setting the extra {@link #EXTRA_ALARM_SNOOZE_DURATION} does not change the default
119     * snooze duration; it's only applied to the currently ringing alarm.
120     * </p><p>
121     * If there is no currently ringing alarm, then this is a no-op.
122     * </p>
123     *
124     * @see #EXTRA_ALARM_SNOOZE_DURATION
125     */
126    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
127    public static final String ACTION_SNOOZE_ALARM = "android.intent.action.SNOOZE_ALARM";
128
129    /**
130     * Activity Action: Set a timer.
131     * <p>
132     * Activates an existing timer or creates a new one.
133     * </p><p>
134     * This action requests a timer to be started for a specific {@link #EXTRA_LENGTH length} of
135     * time. If no {@link #EXTRA_LENGTH length} is specified, the implementation should start an
136     * activity that is capable of setting a timer ({@link #EXTRA_SKIP_UI} is ignored in this case).
137     * If a {@link #EXTRA_LENGTH length} is specified, and {@link #EXTRA_SKIP_UI} is {@code true},
138     * the implementation should remove this timer after it has been dismissed. If an identical,
139     * unused timer exists matching both parameters, an implementation may re-use it instead of
140     * creating a new one (in this case, the timer should not be removed after dismissal).
141     *
142     * This action always starts the timer.
143     * </p>
144     *
145     * <h3>Request parameters</h3>
146     * <ul>
147     * <li>{@link #EXTRA_LENGTH} <em>(optional)</em>: The length of the timer being set.
148     * <li>{@link #EXTRA_MESSAGE} <em>(optional)</em>: A custom message for the timer.
149     * <li>{@link #EXTRA_SKIP_UI} <em>(optional)</em>: Whether or not to display an activity for
150     * setting this timer.
151     * </ul>
152     */
153    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
154    public static final String ACTION_SET_TIMER = "android.intent.action.SET_TIMER";
155
156    /**
157     * Activity Action: Dismiss timers.
158     * <p>
159     * Dismiss all currently expired timers. If there are no expired timers, then this is a no-op.
160     * </p>
161     */
162    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
163    public static final String ACTION_DISMISS_TIMER = "android.intent.action.DISMISS_TIMER";
164
165    /**
166     * Activity Action: Show the timers.
167     * <p>
168     * This action opens the timers page.
169     * </p>
170     */
171    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
172    public static final String ACTION_SHOW_TIMERS = "android.intent.action.SHOW_TIMERS";
173
174    /**
175     * Activity Action: Show the alarms.
176     * <p>
177     * This action opens the alarms page.
178     * </p>
179     */
180     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
181     public static final String ACTION_SHOW_ALARMS = "android.intent.action.SHOW_ALARMS";
182
183    /**
184     * Bundle extra: Specify the type of search mode to look up an alarm.
185     * <p>
186     * For example, used by {@link #ACTION_DISMISS_ALARM} to identify the alarm to dismiss.
187     * </p><p>
188     * This extra is only used when the alarm is not already identified by a deeplink as
189     * specified in the Intent's data URI.
190     * </p><p>
191     * The value of this extra is a {@link String}, restricted to the following set of supported
192     * search modes:
193     * <ul>
194     * <li><i>Time</i> - {@link #ALARM_SEARCH_MODE_TIME}: Selects the alarm that is most
195     * closely matched by the search parameters {@link #EXTRA_HOUR}, {@link #EXTRA_MINUTES},
196     * {@link #EXTRA_IS_PM}.
197     * <li><i>Next alarm</i> - {@link #ALARM_SEARCH_MODE_NEXT}: Selects the alarm that will
198     * ring next, or the alarm that is currently ringing, if any.
199     * <li><i>All alarms</i> - {@link #ALARM_SEARCH_MODE_ALL}: Selects all alarms.
200     * <li><i>Label</i> - {@link #ALARM_SEARCH_MODE_LABEL}: Search by alarm label. Should return
201     * alarms that contain the word or phrase in given label.
202     * </ul>
203     * </p>
204     *
205     * @see #ALARM_SEARCH_MODE_TIME
206     * @see #ALARM_SEARCH_MODE_NEXT
207     * @see #ALARM_SEARCH_MODE_ALL
208     * @see #ALARM_SEARCH_MODE_LABEL
209     * @see #ACTION_DISMISS_ALARM
210     */
211    public static final String EXTRA_ALARM_SEARCH_MODE = "android.intent.extra.alarm.SEARCH_MODE";
212
213    /**
214     * Search for the alarm that is most closely matched by the search parameters
215     * {@link #EXTRA_HOUR}, {@link #EXTRA_MINUTES}, {@link #EXTRA_IS_PM}.
216     * In this search mode, at least one of these additional extras are required.
217     * <ul>
218     * <li>{@link #EXTRA_HOUR} - The hour to search for the alarm.
219     * <li>{@link #EXTRA_MINUTES} - The minute to search for the alarm.
220     * <li>{@link #EXTRA_IS_PM} - Whether the hour is AM or PM.
221     * </ul>
222     *
223     * @see #EXTRA_ALARM_SEARCH_MODE
224     */
225    public static final String ALARM_SEARCH_MODE_TIME = "android.time";
226
227    /**
228     * Selects the alarm that will ring next, or the alarm that is currently ringing, if any.
229     *
230     * @see #EXTRA_ALARM_SEARCH_MODE
231     */
232    public static final String ALARM_SEARCH_MODE_NEXT = "android.next";
233
234    /**
235     * Selects all alarms.
236     *
237     * @see #EXTRA_ALARM_SEARCH_MODE
238     */
239    public static final String ALARM_SEARCH_MODE_ALL = "android.all";
240
241    /**
242     * Search by alarm label. Should return alarms that contain the word or phrase in given label.
243     *
244     * @see #EXTRA_ALARM_SEARCH_MODE
245     */
246    public static final String ALARM_SEARCH_MODE_LABEL = "android.label";
247
248    /**
249     * Bundle extra: The AM/PM of the alarm.
250     * <p>
251     * Used by {@link #ACTION_DISMISS_ALARM}.
252     * </p><p>
253     * This extra is optional and only used when {@link #EXTRA_ALARM_SEARCH_MODE} is set to
254     * {@link #ALARM_SEARCH_MODE_TIME}. In this search mode, the {@link #EXTRA_IS_PM} is
255     * used together with {@link #EXTRA_HOUR} and {@link #EXTRA_MINUTES}. The implementation should
256     * look up the alarm that is most closely matched by these search parameters.
257     * If {@link #EXTRA_IS_PM} is missing, then the AM/PM of the specified {@link #EXTRA_HOUR} is
258     * ambiguous and the implementation should ask for clarification from the user.
259     * </p><p>
260     * The value is a {@link Boolean}, where false=AM and true=PM.
261     * </p>
262     *
263     * @see #ACTION_DISMISS_ALARM
264     * @see #EXTRA_HOUR
265     * @see #EXTRA_MINUTES
266     */
267    public static final String EXTRA_IS_PM = "android.intent.extra.alarm.IS_PM";
268
269
270    /**
271     * Bundle extra: The snooze duration of the alarm in minutes.
272     * <p>
273     * Used by {@link #ACTION_SNOOZE_ALARM}. This extra is optional and the value is an
274     * {@link Integer} that specifies the duration in minutes for which to snooze the alarm.
275     * </p>
276     *
277     * @see #ACTION_SNOOZE_ALARM
278     */
279    public static final String EXTRA_ALARM_SNOOZE_DURATION =
280        "android.intent.extra.alarm.SNOOZE_DURATION";
281
282    /**
283     * Bundle extra: Weekdays for repeating alarm.
284     * <p>
285     * Used by {@link #ACTION_SET_ALARM}.
286     * </p><p>
287     * The value is an {@code ArrayList<Integer>}. Each item can be:
288     * </p>
289     * <ul>
290     * <li> {@link java.util.Calendar#SUNDAY},
291     * <li> {@link java.util.Calendar#MONDAY},
292     * <li> {@link java.util.Calendar#TUESDAY},
293     * <li> {@link java.util.Calendar#WEDNESDAY},
294     * <li> {@link java.util.Calendar#THURSDAY},
295     * <li> {@link java.util.Calendar#FRIDAY},
296     * <li> {@link java.util.Calendar#SATURDAY}
297     * </ul>
298     */
299    public static final String EXTRA_DAYS = "android.intent.extra.alarm.DAYS";
300
301    /**
302     * Bundle extra: The hour of the alarm.
303     * <p>
304     * Used by {@link #ACTION_SET_ALARM}.
305     * </p><p>
306     * This extra is optional. If not provided, an implementation should open an activity
307     * that allows a user to set an alarm with user provided time.
308     * </p><p>
309     * The value is an {@link Integer} and ranges from 0 to 23.
310     * </p>
311     *
312     * @see #ACTION_SET_ALARM
313     * @see #EXTRA_MINUTES
314     * @see #EXTRA_DAYS
315     */
316    public static final String EXTRA_HOUR = "android.intent.extra.alarm.HOUR";
317
318    /**
319     * Bundle extra: The length of the timer in seconds.
320     * <p>
321     * Used by {@link #ACTION_SET_TIMER}.
322     * </p><p>
323     * This extra is optional. If not provided, an implementation should open an activity
324     * that allows a user to set a timer with user provided length.
325     * </p><p>
326     * The value is an {@link Integer} and ranges from 1 to 86400 (24 hours).
327     * </p>
328     *
329     * @see #ACTION_SET_TIMER
330     */
331    public static final String EXTRA_LENGTH = "android.intent.extra.alarm.LENGTH";
332
333    /**
334     * Bundle extra: A custom message for the alarm or timer.
335     * <p>
336     * Used by {@link #ACTION_SET_ALARM} and {@link #ACTION_SET_TIMER}.
337     * </p><p>
338     * The value is a {@link String}.
339     * </p>
340     *
341     * @see #ACTION_SET_ALARM
342     * @see #ACTION_SET_TIMER
343     */
344    public static final String EXTRA_MESSAGE = "android.intent.extra.alarm.MESSAGE";
345
346    /**
347     * Bundle extra: The minutes of the alarm.
348     * <p>
349     * Used by {@link #ACTION_SET_ALARM}.
350     * </p><p>
351     * The value is an {@link Integer} and ranges from 0 to 59. If not provided, it defaults to 0.
352     * </p>
353     *
354     * @see #ACTION_SET_ALARM
355     * @see #EXTRA_HOUR
356     * @see #EXTRA_DAYS
357     */
358    public static final String EXTRA_MINUTES = "android.intent.extra.alarm.MINUTES";
359
360    /**
361     * Bundle extra: A ringtone to be played with this alarm.
362     * <p>
363     * Used by {@link #ACTION_SET_ALARM}.
364     * </p><p>
365     * This value is a {@link String} and can either be set to {@link #VALUE_RINGTONE_SILENT} or
366     * to a content URI of the media to be played. If not specified or the URI doesn't exist,
367     * {@code "content://settings/system/alarm_alert} will be used.
368     * </p>
369     *
370     * @see #ACTION_SET_ALARM
371     * @see #VALUE_RINGTONE_SILENT
372     * @see #EXTRA_VIBRATE
373     */
374    public static final String EXTRA_RINGTONE = "android.intent.extra.alarm.RINGTONE";
375
376    /**
377     * Bundle extra: Whether or not to display an activity after performing the action.
378     * <p>
379     * Used by {@link #ACTION_SET_ALARM} and {@link #ACTION_SET_TIMER}.
380     * </p><p>
381     * If true, the application is asked to bypass any intermediate UI. If false, the application
382     * may display intermediate UI like a confirmation dialog or settings.
383     * </p><p>
384     * The value is a {@link Boolean}. The default is {@code false}.
385     * </p>
386     *
387     * @see #ACTION_SET_ALARM
388     * @see #ACTION_SET_TIMER
389     */
390    public static final String EXTRA_SKIP_UI = "android.intent.extra.alarm.SKIP_UI";
391
392    /**
393     * Bundle extra: Whether or not to activate the device vibrator.
394     * <p>
395     * Used by {@link #ACTION_SET_ALARM}.
396     * </p><p>
397     * The value is a {@link Boolean}. The default is {@code true}.
398     * </p>
399     *
400     * @see #ACTION_SET_ALARM
401     * @see #EXTRA_RINGTONE
402     * @see #VALUE_RINGTONE_SILENT
403     */
404    public static final String EXTRA_VIBRATE = "android.intent.extra.alarm.VIBRATE";
405
406    /**
407     * Bundle extra value: Indicates no ringtone should be played.
408     * <p>
409     * Used by {@link #ACTION_SET_ALARM}, passed in through {@link #EXTRA_RINGTONE}.
410     * </p>
411     *
412     * @see #ACTION_SET_ALARM
413     * @see #EXTRA_RINGTONE
414     * @see #EXTRA_VIBRATE
415     */
416    public static final String VALUE_RINGTONE_SILENT = "silent";
417}
418