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