diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2017-04-24 11:18:03 -0600 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2017-04-24 13:20:46 -0600 |
| commit | 30e06bb668f2e4b024c4ebc2a131de91c96de5eb (patch) | |
| tree | 23912af279b2c4c54de4b213712eb8528dfd34c3 /core/java/android/app | |
| parent | 4d23f258d4c15df9329d9c66ee902afa78cebca7 (diff) | |
Even more auto-doc work.
Update docs based on what new lint detector found. Add new @IntDef
to parameters or methods returning constants or flags, and add
@RequiresPermission to methods mentioning permissions.
Test: make -j32 offline-sdk-docs
Bug: 37526420
Change-Id: I7f640f7883fcb66b911a52ae93b83f77306571ec
Diffstat (limited to 'core/java/android/app')
| -rw-r--r-- | core/java/android/app/Activity.java | 2 | ||||
| -rw-r--r-- | core/java/android/app/ActivityManager.java | 33 | ||||
| -rw-r--r-- | core/java/android/app/AlarmManager.java | 86 | ||||
| -rw-r--r-- | core/java/android/app/Notification.java | 16 | ||||
| -rw-r--r-- | core/java/android/app/NotificationChannel.java | 5 | ||||
| -rw-r--r-- | core/java/android/app/job/JobInfo.java | 70 | ||||
| -rw-r--r-- | core/java/android/app/job/JobScheduler.java | 22 |
7 files changed, 141 insertions, 93 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 1b972f79e48c..e4d2d132fced 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -5844,7 +5844,7 @@ public class Activity extends ContextThemeWrapper * @return Returns the single SharedPreferences instance that can be used * to retrieve and modify the preference values. */ - public SharedPreferences getPreferences(int mode) { + public SharedPreferences getPreferences(@Context.PreferencesMode int mode) { return getSharedPreferences(getLocalClassName(), mode); } diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 62f2144312e2..1ab45b56e5ca 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -2350,6 +2350,14 @@ public class ActivityManager { } } + /** @hide */ + @IntDef(flag = true, prefix = { "MOVE_TASK_" }, value = { + MOVE_TASK_WITH_HOME, + MOVE_TASK_NO_USER_ACTION, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface MoveTaskFlags {} + /** * Flag for {@link #moveTaskToFront(int, int)}: also move the "home" * activity along with the task, so it is positioned immediately behind @@ -2370,28 +2378,26 @@ public class ActivityManager { * * @param taskId The identifier of the task to be moved, as found in * {@link RunningTaskInfo} or {@link RecentTaskInfo}. - * @param flags Additional operational flags, 0 or more of - * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}. + * @param flags Additional operational flags. */ - public void moveTaskToFront(int taskId, int flags) { + @RequiresPermission(android.Manifest.permission.REORDER_TASKS) + public void moveTaskToFront(int taskId, @MoveTaskFlags int flags) { moveTaskToFront(taskId, flags, null); } /** * Ask that the task associated with a given task ID be moved to the - * front of the stack, so it is now visible to the user. Requires that - * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS} - * or a SecurityException will be thrown. + * front of the stack, so it is now visible to the user. * * @param taskId The identifier of the task to be moved, as found in * {@link RunningTaskInfo} or {@link RecentTaskInfo}. - * @param flags Additional operational flags, 0 or more of - * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}. + * @param flags Additional operational flags. * @param options Additional options for the operation, either null or * as per {@link Context#startActivity(Intent, android.os.Bundle) * Context.startActivity(Intent, Bundle)}. */ - public void moveTaskToFront(int taskId, int flags, Bundle options) { + @RequiresPermission(android.Manifest.permission.REORDER_TASKS) + public void moveTaskToFront(int taskId, @MoveTaskFlags int flags, Bundle options) { try { getService().moveTaskToFront(taskId, flags, options); } catch (RemoteException e) { @@ -3637,13 +3643,10 @@ public class ActivityManager { * processes to reclaim memory; the system will take care of restarting * these processes in the future as needed. * - * <p>You must hold the permission - * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to - * call this method. - * * @param packageName The name of the package whose processes are to * be killed. */ + @RequiresPermission(Manifest.permission.KILL_BACKGROUND_PROCESSES) public void killBackgroundProcesses(String packageName) { try { getService().killBackgroundProcesses(packageName, @@ -4015,13 +4018,13 @@ public class ActivityManager { * Perform a system dump of various state associated with the given application * package name. This call blocks while the dump is being performed, so should * not be done on a UI thread. The data will be written to the given file - * descriptor as text. An application must hold the - * {@link android.Manifest.permission#DUMP} permission to make this call. + * descriptor as text. * @param fd The file descriptor that the dump should be written to. The file * descriptor is <em>not</em> closed by this function; the caller continues to * own it. * @param packageName The name of the package that is to be dumped. */ + @RequiresPermission(Manifest.permission.DUMP) public void dumpPackageState(FileDescriptor fd, String packageName) { dumpPackageStateStatic(fd, packageName); } diff --git a/core/java/android/app/AlarmManager.java b/core/java/android/app/AlarmManager.java index c561a1908b21..3221c5d89543 100644 --- a/core/java/android/app/AlarmManager.java +++ b/core/java/android/app/AlarmManager.java @@ -16,6 +16,7 @@ package android.app; +import android.annotation.IntDef; import android.annotation.SdkConstant; import android.annotation.SystemApi; import android.content.Context; @@ -34,6 +35,8 @@ import android.util.Log; import libcore.util.ZoneInfoDB; import java.io.IOException; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; /** * This class provides access to the system alarm services. These allow you @@ -78,6 +81,16 @@ import java.io.IOException; public class AlarmManager { private static final String TAG = "AlarmManager"; + /** @hide */ + @IntDef(prefix = { "RTC", "ELAPSED" }, value = { + RTC_WAKEUP, + RTC, + ELAPSED_REALTIME_WAKEUP, + ELAPSED_REALTIME, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface AlarmType {} + /** * Alarm time in {@link System#currentTimeMillis System.currentTimeMillis()} * (wall clock time in UTC), which will wake up the device when @@ -311,8 +324,7 @@ public class AlarmManager { * will be treated as exact. * </div> * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should go * off, using the appropriate clock (depending on the alarm type). * @param operation Action to perform when the alarm goes off; @@ -332,7 +344,7 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void set(int type, long triggerAtMillis, PendingIntent operation) { + public void set(@AlarmType int type, long triggerAtMillis, PendingIntent operation) { setImpl(type, triggerAtMillis, legacyExactLength(), 0, 0, operation, null, null, null, null, null); } @@ -346,8 +358,7 @@ public class AlarmManager { * invoked via the specified target Handler, or on the application's main looper * if {@code null} is passed as the {@code targetHandler} parameter. * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should go * off, using the appropriate clock (depending on the alarm type). * @param tag string describing the alarm, used for logging and battery-use @@ -360,7 +371,7 @@ public class AlarmManager { * @param targetHandler {@link Handler} on which to execute the listener's onAlarm() * callback, or {@code null} to run that callback on the main looper. */ - public void set(int type, long triggerAtMillis, String tag, OnAlarmListener listener, + public void set(@AlarmType int type, long triggerAtMillis, String tag, OnAlarmListener listener, Handler targetHandler) { setImpl(type, triggerAtMillis, legacyExactLength(), 0, 0, null, listener, tag, targetHandler, null, null); @@ -399,8 +410,7 @@ public class AlarmManager { * whose {@code targetSdkVersion} is earlier than API 19 will continue to have all * of their alarms, including repeating alarms, treated as exact. * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should first * go off, using the appropriate clock (depending on the alarm type). * @param intervalMillis interval in milliseconds between subsequent repeats @@ -422,7 +432,7 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void setRepeating(int type, long triggerAtMillis, + public void setRepeating(@AlarmType int type, long triggerAtMillis, long intervalMillis, PendingIntent operation) { setImpl(type, triggerAtMillis, legacyExactLength(), intervalMillis, 0, operation, null, null, null, null, null); @@ -448,8 +458,7 @@ public class AlarmManager { * at precisely-specified times with no acceptable variation, applications can use * {@link #setExact(int, long, PendingIntent)}. * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param windowStartMillis The earliest time, in milliseconds, that the alarm should * be delivered, expressed in the appropriate clock's units (depending on the alarm * type). @@ -473,7 +482,7 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void setWindow(int type, long windowStartMillis, long windowLengthMillis, + public void setWindow(@AlarmType int type, long windowStartMillis, long windowLengthMillis, PendingIntent operation) { setImpl(type, windowStartMillis, windowLengthMillis, 0, 0, operation, null, null, null, null, null); @@ -488,7 +497,7 @@ public class AlarmManager { * invoked via the specified target Handler, or on the application's main looper * if {@code null} is passed as the {@code targetHandler} parameter. */ - public void setWindow(int type, long windowStartMillis, long windowLengthMillis, + public void setWindow(@AlarmType int type, long windowStartMillis, long windowLengthMillis, String tag, OnAlarmListener listener, Handler targetHandler) { setImpl(type, windowStartMillis, windowLengthMillis, 0, 0, null, listener, tag, targetHandler, null, null); @@ -508,8 +517,7 @@ public class AlarmManager { * scheduled as exact. Applications are strongly discouraged from using exact * alarms unnecessarily as they reduce the OS's ability to minimize battery use. * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should go * off, using the appropriate clock (depending on the alarm type). * @param operation Action to perform when the alarm goes off; @@ -528,7 +536,7 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void setExact(int type, long triggerAtMillis, PendingIntent operation) { + public void setExact(@AlarmType int type, long triggerAtMillis, PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, 0, operation, null, null, null, null, null); } @@ -542,8 +550,8 @@ public class AlarmManager { * invoked via the specified target Handler, or on the application's main looper * if {@code null} is passed as the {@code targetHandler} parameter. */ - public void setExact(int type, long triggerAtMillis, String tag, OnAlarmListener listener, - Handler targetHandler) { + public void setExact(@AlarmType int type, long triggerAtMillis, String tag, + OnAlarmListener listener, Handler targetHandler) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, 0, null, listener, tag, targetHandler, null, null); } @@ -553,8 +561,8 @@ public class AlarmManager { * the given time. * @hide */ - public void setIdleUntil(int type, long triggerAtMillis, String tag, OnAlarmListener listener, - Handler targetHandler) { + public void setIdleUntil(@AlarmType int type, long triggerAtMillis, String tag, + OnAlarmListener listener, Handler targetHandler) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, FLAG_IDLE_UNTIL, null, listener, tag, targetHandler, null, null); } @@ -590,8 +598,8 @@ public class AlarmManager { /** @hide */ @SystemApi - public void set(int type, long triggerAtMillis, long windowMillis, long intervalMillis, - PendingIntent operation, WorkSource workSource) { + public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, + long intervalMillis, PendingIntent operation, WorkSource workSource) { setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, operation, null, null, null, workSource, null); } @@ -606,8 +614,9 @@ public class AlarmManager { * * @hide */ - public void set(int type, long triggerAtMillis, long windowMillis, long intervalMillis, - String tag, OnAlarmListener listener, Handler targetHandler, WorkSource workSource) { + public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, + long intervalMillis, String tag, OnAlarmListener listener, Handler targetHandler, + WorkSource workSource) { setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, tag, targetHandler, workSource, null); } @@ -623,15 +632,17 @@ public class AlarmManager { * @hide */ @SystemApi - public void set(int type, long triggerAtMillis, long windowMillis, long intervalMillis, - OnAlarmListener listener, Handler targetHandler, WorkSource workSource) { + public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, + long intervalMillis, OnAlarmListener listener, Handler targetHandler, + WorkSource workSource) { setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, null, targetHandler, workSource, null); } - private void setImpl(int type, long triggerAtMillis, long windowMillis, long intervalMillis, - int flags, PendingIntent operation, final OnAlarmListener listener, String listenerTag, - Handler targetHandler, WorkSource workSource, AlarmClockInfo alarmClock) { + private void setImpl(@AlarmType int type, long triggerAtMillis, long windowMillis, + long intervalMillis, int flags, PendingIntent operation, final OnAlarmListener listener, + String listenerTag, Handler targetHandler, WorkSource workSource, + AlarmClockInfo alarmClock) { if (triggerAtMillis < 0) { /* NOTYET if (mAlwaysExact) { @@ -728,8 +739,7 @@ public class AlarmManager { * assured that it will get similar behavior on both current and older versions * of Android. * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should first * go off, using the appropriate clock (depending on the alarm type). This * is inexact: the alarm will not fire before this time, but there may be a @@ -763,7 +773,7 @@ public class AlarmManager { * @see #INTERVAL_HALF_DAY * @see #INTERVAL_DAY */ - public void setInexactRepeating(int type, long triggerAtMillis, + public void setInexactRepeating(@AlarmType int type, long triggerAtMillis, long intervalMillis, PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, intervalMillis, 0, operation, null, null, null, null, null); @@ -795,8 +805,7 @@ public class AlarmManager { * <p>Regardless of the app's target SDK version, this call always allows batching of the * alarm.</p> * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should go * off, using the appropriate clock (depending on the alarm type). * @param operation Action to perform when the alarm goes off; @@ -814,7 +823,8 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void setAndAllowWhileIdle(int type, long triggerAtMillis, PendingIntent operation) { + public void setAndAllowWhileIdle(@AlarmType int type, long triggerAtMillis, + PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, 0, FLAG_ALLOW_WHILE_IDLE, operation, null, null, null, null, null); } @@ -848,8 +858,7 @@ public class AlarmManager { * device is idle it may take even more liberties with scheduling in order to optimize * for battery life.</p> * - * @param type One of {@link #ELAPSED_REALTIME}, {@link #ELAPSED_REALTIME_WAKEUP}, - * {@link #RTC}, or {@link #RTC_WAKEUP}. + * @param type type of alarm. * @param triggerAtMillis time in milliseconds that the alarm should go * off, using the appropriate clock (depending on the alarm type). * @param operation Action to perform when the alarm goes off; @@ -868,7 +877,8 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void setExactAndAllowWhileIdle(int type, long triggerAtMillis, PendingIntent operation) { + public void setExactAndAllowWhileIdle(@AlarmType int type, long triggerAtMillis, + PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, FLAG_ALLOW_WHILE_IDLE, operation, null, null, null, null, null); } diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 602cccb1070d..2b4fb1956c42 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -676,7 +676,16 @@ public class Notification implements Parcelable * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon * and ticker until the user has bypassed the lockscreen. */ - public int visibility; + public @Visibility int visibility; + + /** @hide */ + @IntDef(prefix = { "VISIBILITY_" }, value = { + VISIBILITY_PUBLIC, + VISIBILITY_PRIVATE, + VISIBILITY_SECRET, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Visibility {} /** * Notification visibility: Show this notification in its entirety on all lockscreens. @@ -3545,12 +3554,9 @@ public class Notification implements Parcelable /** * Specify the value of {@link #visibility}. * - * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default), - * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}. - * * @return The same Builder. */ - public Builder setVisibility(int visibility) { + public Builder setVisibility(@Visibility int visibility) { mN.visibility = visibility; return this; } diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java index 9059daa62dc7..2dd33013ab8e 100644 --- a/core/java/android/app/NotificationChannel.java +++ b/core/java/android/app/NotificationChannel.java @@ -162,10 +162,9 @@ public final class NotificationChannel implements Parcelable { * broadcast. The recommended maximum length is 40 characters; the value may be * truncated if it is too long. * @param importance The importance of the channel. This controls how interruptive notifications - * posted to this channel are. See e.g. - * {@link NotificationManager#IMPORTANCE_DEFAULT}. + * posted to this channel are. */ - public NotificationChannel(String id, CharSequence name, int importance) { + public NotificationChannel(String id, CharSequence name, @Importance int importance) { this.mId = getTrimmedString(id); this.mName = name != null ? getTrimmedString(name.toString()) : null; this.mImportance = importance; diff --git a/core/java/android/app/job/JobInfo.java b/core/java/android/app/job/JobInfo.java index 3538256761aa..007ea88d676c 100644 --- a/core/java/android/app/job/JobInfo.java +++ b/core/java/android/app/job/JobInfo.java @@ -18,8 +18,10 @@ package android.app.job; import static android.util.TimeUtils.formatDuration; +import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.content.ClipData; import android.content.ComponentName; import android.net.Uri; @@ -30,6 +32,8 @@ import android.os.Parcelable; import android.os.PersistableBundle; import android.util.Log; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Objects; @@ -43,6 +47,18 @@ import java.util.Objects; */ public class JobInfo implements Parcelable { private static String TAG = "JobInfo"; + + /** @hide */ + @IntDef(prefix = { "NETWORK_TYPE_" }, value = { + NETWORK_TYPE_NONE, + NETWORK_TYPE_ANY, + NETWORK_TYPE_UNMETERED, + NETWORK_TYPE_NOT_ROAMING, + NETWORK_TYPE_METERED, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface NetworkType {} + /** Default. */ public static final int NETWORK_TYPE_NONE = 0; /** This job requires network connectivity. */ @@ -64,6 +80,14 @@ public class JobInfo implements Parcelable { */ public static final long MAX_BACKOFF_DELAY_MILLIS = 5 * 60 * 60 * 1000; // 5 hours. + /** @hide */ + @IntDef(prefix = { "BACKOFF_POLICY_" }, value = { + BACKOFF_POLICY_LINEAR, + BACKOFF_POLICY_EXPONENTIAL, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface BackoffPolicy {} + /** * Linearly back-off a failed job. See * {@link android.app.job.JobInfo.Builder#setBackoffCriteria(long, int)} @@ -349,14 +373,8 @@ public class JobInfo implements Parcelable { /** * The kind of connectivity requirements that the job has. - * - * @return One of {@link android.app.job.JobInfo#NETWORK_TYPE_ANY}, - * {@link android.app.job.JobInfo#NETWORK_TYPE_NONE}, - * {@link android.app.job.JobInfo#NETWORK_TYPE_UNMETERED}, - * {@link android.app.job.JobInfo#NETWORK_TYPE_METERED}, or - * {@link android.app.job.JobInfo#NETWORK_TYPE_NOT_ROAMING}, */ - public int getNetworkType() { + public @NetworkType int getNetworkType() { return networkType; } @@ -421,11 +439,9 @@ public class JobInfo implements Parcelable { } /** - * One of either {@link android.app.job.JobInfo#BACKOFF_POLICY_EXPONENTIAL}, or - * {@link android.app.job.JobInfo#BACKOFF_POLICY_LINEAR}, depending on which criteria you set - * when creating this job. + * Return the backoff policy of this job. */ - public int getBackoffPolicy() { + public @BackoffPolicy int getBackoffPolicy() { return backoffPolicy; } @@ -692,6 +708,13 @@ public class JobInfo implements Parcelable { private final Uri mUri; private final int mFlags; + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(flag = true, prefix = { "FLAG_" }, value = { + FLAG_NOTIFY_FOR_DESCENDANTS, + }) + public @interface Flags { } + /** * Flag for trigger: also trigger if any descendants of the given URI change. * Corresponds to the <var>notifyForDescendants</var> of @@ -702,10 +725,9 @@ public class JobInfo implements Parcelable { /** * Create a new trigger description. * @param uri The URI to observe. Must be non-null. - * @param flags Optional flags for the observer, either 0 or - * {@link #FLAG_NOTIFY_FOR_DESCENDANTS}. + * @param flags Flags for the observer. */ - public TriggerContentUri(@NonNull Uri uri, int flags) { + public TriggerContentUri(@NonNull Uri uri, @Flags int flags) { mUri = uri; mFlags = flags; } @@ -720,7 +742,7 @@ public class JobInfo implements Parcelable { /** * Return the flags supplied for the trigger. */ - public int getFlags() { + public @Flags int getFlags() { return mFlags; } @@ -886,7 +908,7 @@ public class JobInfo implements Parcelable { * job. If the network requested is not available your job will never run. See * {@link #setOverrideDeadline(long)} to change this behaviour. */ - public Builder setRequiredNetworkType(int networkType) { + public Builder setRequiredNetworkType(@NetworkType int networkType) { mNetworkType = networkType; return this; } @@ -1067,10 +1089,9 @@ public class JobInfo implements Parcelable { * mode. * @param initialBackoffMillis Millisecond time interval to wait initially when job has * failed. - * @param backoffPolicy is one of {@link #BACKOFF_POLICY_LINEAR} or - * {@link #BACKOFF_POLICY_EXPONENTIAL} */ - public Builder setBackoffCriteria(long initialBackoffMillis, int backoffPolicy) { + public Builder setBackoffCriteria(long initialBackoffMillis, + @BackoffPolicy int backoffPolicy) { mBackoffPolicySet = true; mInitialBackoffMillis = initialBackoffMillis; mBackoffPolicy = backoffPolicy; @@ -1078,13 +1099,12 @@ public class JobInfo implements Parcelable { } /** - * Set whether or not to persist this job across device reboots. This will only have an - * effect if your application holds the permission - * {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED}. Otherwise an exception will - * be thrown. - * @param isPersisted True to indicate that the job will be written to disk and loaded at - * boot. + * Set whether or not to persist this job across device reboots. + * + * @param isPersisted True to indicate that the job will be written to + * disk and loaded at boot. */ + @RequiresPermission(android.Manifest.permission.RECEIVE_BOOT_COMPLETED) public Builder setPersisted(boolean isPersisted) { mIsPersisted = isPersisted; return this; diff --git a/core/java/android/app/job/JobScheduler.java b/core/java/android/app/job/JobScheduler.java index 23f9eea65abe..1768828eb76c 100644 --- a/core/java/android/app/job/JobScheduler.java +++ b/core/java/android/app/job/JobScheduler.java @@ -16,6 +16,7 @@ package android.app.job; +import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; @@ -24,6 +25,8 @@ import android.content.Intent; import android.os.Bundle; import android.os.PersistableBundle; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.List; /** @@ -51,6 +54,14 @@ import java.util.List; * Context.getSystemService(Context.JOB_SCHEDULER_SERVICE)}. */ public abstract class JobScheduler { + /** @hide */ + @IntDef(prefix = { "RESULT_" }, value = { + RESULT_FAILURE, + RESULT_SUCCESS, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Result {} + /** * Returned from {@link #schedule(JobInfo)} when an invalid parameter was supplied. This can occur * if the run-time for your job is too short, or perhaps the system can't resolve the @@ -70,9 +81,9 @@ public abstract class JobScheduler { * @param job The job you wish scheduled. See * {@link android.app.job.JobInfo.Builder JobInfo.Builder} for more detail on the sorts of jobs * you can schedule. - * @return An int representing ({@link #RESULT_SUCCESS} or {@link #RESULT_FAILURE}). + * @return the result of the schedule request. */ - public abstract int schedule(@NonNull JobInfo job); + public abstract @Result int schedule(@NonNull JobInfo job); /** * Similar to {@link #schedule}, but allows you to enqueue work for a new <em>or existing</em> @@ -107,9 +118,9 @@ public abstract class JobScheduler { * {@link android.app.job.JobInfo.Builder JobInfo.Builder} for more detail on the sorts of jobs * you can schedule. * @param work New work to enqueue. This will be available later when the job starts running. - * @return An int representing ({@link #RESULT_SUCCESS} or {@link #RESULT_FAILURE}). + * @return the result of the enqueue request. */ - public abstract int enqueue(@NonNull JobInfo job, @NonNull JobWorkItem work); + public abstract @Result int enqueue(@NonNull JobInfo job, @NonNull JobWorkItem work); /** * @@ -118,11 +129,10 @@ public abstract class JobScheduler { * used to track battery usage and appIdleState. * @param userId User on behalf of whom this job is to be scheduled. * @param tag Debugging tag for dumps associated with this job (instead of the service class) - * @return {@link #RESULT_SUCCESS} or {@link #RESULT_FAILURE} * @hide */ @SystemApi - public abstract int scheduleAsPackage(@NonNull JobInfo job, @NonNull String packageName, + public abstract @Result int scheduleAsPackage(@NonNull JobInfo job, @NonNull String packageName, int userId, String tag); /** |
