diff --git a/core/java/android/annotation/BroadcastBehavior.java b/core/java/android/annotation/BroadcastBehavior.java index 9b2ca3120290f..70d82cb5151b4 100644 --- a/core/java/android/annotation/BroadcastBehavior.java +++ b/core/java/android/annotation/BroadcastBehavior.java @@ -53,4 +53,9 @@ public @interface BroadcastBehavior { * @see Intent#FLAG_RECEIVER_INCLUDE_BACKGROUND */ boolean includeBackground() default false; + + /** + * This broadcast is protected and can only be sent by the OS. + */ + boolean protectedBroadcast() default false; } diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 1b972f79e48ca..e4d2d132fcedb 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 62f2144312e24..1ab45b56e5caa 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. * - *
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 not 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 c561a1908b213..3221c5d895431 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. * * - * @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 { *
Regardless of the app's target SDK version, this call always allows batching of the * alarm.
* - * @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. * - * @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 602cccb1070dc..2b4fb1956c424 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 9059daa62dc77..2dd33013ab8e4 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 3538256761aab..007ea88d676cc 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 notifyForDescendants 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 23f9eea65abe9..1768828eb76c7 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 or existing @@ -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); /** diff --git a/core/java/android/content/ComponentName.java b/core/java/android/content/ComponentName.java index 8aeb22dddd1e2..ea6b7690b4319 100644 --- a/core/java/android/content/ComponentName.java +++ b/core/java/android/content/ComponentName.java @@ -16,6 +16,8 @@ package android.content; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; @@ -52,7 +54,7 @@ public final class ComponentName implements Parcelable, Cloneable, ComparableYou must hold the {@link android.Manifest.permission#BROADCAST_STICKY} - * permission in order to use this API. If you do not hold that - * permission, {@link SecurityException} will be thrown. - * * @deprecated Sticky broadcasts should not be used. They provide no security (anyone * can access them), no protection (anyone can modify them), and many other problems. * The recommended pattern is to use a non-sticky broadcast to report that something @@ -2210,6 +2224,7 @@ public abstract class Context { * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) */ @Deprecated + @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY) public abstract void sendStickyBroadcast(@RequiresPermission Intent intent); /** @@ -2259,6 +2274,7 @@ public abstract class Context { * @see android.app.Activity#RESULT_OK */ @Deprecated + @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY) public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @@ -2268,10 +2284,6 @@ public abstract class Context { *
Remove the data previously sent with {@link #sendStickyBroadcast}, * so that it is as if the sticky broadcast had never happened. * - *
You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
- * permission in order to use this API. If you do not hold that
- * permission, {@link SecurityException} will be thrown.
- *
* @deprecated Sticky broadcasts should not be used. They provide no security (anyone
* can access them), no protection (anyone can modify them), and many other problems.
* The recommended pattern is to use a non-sticky broadcast to report that something
@@ -2283,6 +2295,7 @@ public abstract class Context {
* @see #sendStickyBroadcast
*/
@Deprecated
+ @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
/**
@@ -3048,7 +3061,7 @@ public abstract class Context {
* @see android.os.HardwarePropertiesManager
* @see #HARDWARE_PROPERTIES_SERVICE
*/
- public abstract Object getSystemService(@ServiceName @NonNull String name);
+ public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
/**
* Return the handle to a system-level service by class.
@@ -3078,7 +3091,7 @@ public abstract class Context {
* @return The service or null if the class is not a supported system service.
*/
@SuppressWarnings("unchecked")
- public final You can convert the returned string back to an Intent with
* {@link #getIntent}.
*
- * @param flags Additional operating flags. Either 0,
- * {@link #URI_INTENT_SCHEME}, or {@link #URI_ANDROID_APP_SCHEME}.
+ * @param flags Additional operating flags.
*
* @return Returns a URI encoding URI string describing the entire contents
* of the Intent.
*/
- public String toUri(int flags) {
+ public String toUri(@UriFlags int flags) {
StringBuilder uri = new StringBuilder(128);
if ((flags&URI_ANDROID_APP_SCHEME) != 0) {
if (mPackage == null) {
@@ -9530,7 +9557,8 @@ public class Intent implements Parcelable, Cloneable {
* @throws XmlPullParserException If there was an XML parsing error.
* @throws IOException If there was an I/O error.
*/
- public static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
+ public static @NonNull Intent parseIntent(@NonNull Resources resources,
+ @NonNull XmlPullParser parser, AttributeSet attrs)
throws XmlPullParserException, IOException {
Intent intent = new Intent();
@@ -9677,7 +9705,7 @@ public class Intent implements Parcelable, Cloneable {
* @see #setType
* @see #setTypeAndNormalize
*/
- public static String normalizeMimeType(String type) {
+ public static @Nullable String normalizeMimeType(@Nullable String type) {
if (type == null) {
return null;
}
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 47d79cfba40ca..ecaf7ebe07d28 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -522,6 +522,18 @@ public abstract class PackageManager {
*/
public static final int PERMISSION_DENIED = -1;
+ /** @hide */
+ @IntDef(prefix = { "SIGNATURE_" }, value = {
+ SIGNATURE_MATCH,
+ SIGNATURE_NEITHER_SIGNED,
+ SIGNATURE_FIRST_NOT_SIGNED,
+ SIGNATURE_SECOND_NOT_SIGNED,
+ SIGNATURE_NO_MATCH,
+ SIGNATURE_UNKNOWN_PACKAGE,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface SignatureResult {}
+
/**
* Signature check result: this is returned by {@link #checkSignatures}
* if all signatures on the two packages match.
@@ -558,11 +570,25 @@ public abstract class PackageManager {
*/
public static final int SIGNATURE_UNKNOWN_PACKAGE = -4;
+ /** @hide */
+ @IntDef(prefix = { "COMPONENT_ENABLED_STATE_" }, value = {
+ COMPONENT_ENABLED_STATE_DEFAULT,
+ COMPONENT_ENABLED_STATE_ENABLED,
+ COMPONENT_ENABLED_STATE_DISABLED,
+ COMPONENT_ENABLED_STATE_DISABLED_USER,
+ COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface EnabledState {}
+
/**
- * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
- * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
- * component or application is in its default enabled state (as specified
- * in its manifest).
+ * Flag for {@link #setApplicationEnabledSetting(String, int, int)} and
+ * {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
+ * component or application is in its default enabled state (as specified in
+ * its manifest).
+ *
+ * Explicitly setting the component state to this value restores it's
+ * enabled state to whatever is set in the manifest.
*/
public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0;
@@ -764,6 +790,13 @@ public abstract class PackageManager {
*/
public static final int INSTALL_ALLOCATE_AGGRESSIVE = 0x00008000;
+ /** @hide */
+ @IntDef(flag = true, prefix = { "DONT_KILL_APP" }, value = {
+ DONT_KILL_APP
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface EnabledFlags {}
+
/**
* Flag parameter for
* {@link #setComponentEnabledSetting(android.content.ComponentName, int, int)} to indicate
@@ -2871,7 +2904,7 @@ public abstract class PackageManager {
* does not contain such an activity, or if packageName is not
* recognized.
*/
- public abstract Intent getLaunchIntentForPackage(String packageName);
+ public abstract @Nullable Intent getLaunchIntentForPackage(@NonNull String packageName);
/**
* Return a "good" intent to launch a front-door Leanback activity in a
@@ -2885,7 +2918,7 @@ public abstract class PackageManager {
* the main Leanback activity in the package, or null if the package
* does not contain such an activity.
*/
- public abstract Intent getLeanbackLaunchIntentForPackage(String packageName);
+ public abstract @Nullable Intent getLeanbackLaunchIntentForPackage(@NonNull String packageName);
/**
* Return an array of all of the POSIX secondary group IDs that have been
@@ -2901,7 +2934,7 @@ public abstract class PackageManager {
* @throws NameNotFoundException if a package with the given name cannot be
* found on the system.
*/
- public abstract int[] getPackageGids(String packageName)
+ public abstract int[] getPackageGids(@NonNull String packageName)
throws NameNotFoundException;
/**
@@ -3189,7 +3222,7 @@ public abstract class PackageManager {
* @see #PERMISSION_DENIED
*/
@CheckResult
- public abstract int checkPermission(String permName, String pkgName);
+ public abstract @PermissionResult int checkPermission(String permName, String pkgName);
/**
* Checks whether a particular permissions has been revoked for a
@@ -3419,12 +3452,9 @@ public abstract class PackageManager {
* #SIGNATURE_NO_MATCH} or {@link #SIGNATURE_UNKNOWN_PACKAGE}).
*
* @see #checkSignatures(int, int)
- * @see #SIGNATURE_MATCH
- * @see #SIGNATURE_NO_MATCH
- * @see #SIGNATURE_UNKNOWN_PACKAGE
*/
@CheckResult
- public abstract int checkSignatures(String pkg1, String pkg2);
+ public abstract @SignatureResult int checkSignatures(String pkg1, String pkg2);
/**
* Like {@link #checkSignatures(String, String)}, but takes UIDs of
@@ -3442,12 +3472,9 @@ public abstract class PackageManager {
* #SIGNATURE_NO_MATCH} or {@link #SIGNATURE_UNKNOWN_PACKAGE}).
*
* @see #checkSignatures(String, String)
- * @see #SIGNATURE_MATCH
- * @see #SIGNATURE_NO_MATCH
- * @see #SIGNATURE_UNKNOWN_PACKAGE
*/
@CheckResult
- public abstract int checkSignatures(int uid1, int uid2);
+ public abstract @SignatureResult int checkSignatures(int uid1, int uid2);
/**
* Retrieve the names of all packages that are associated with a particular
@@ -3881,8 +3908,8 @@ public abstract class PackageManager {
* included by one of the specifics intents. If there are
* no matching activities, an empty list is returned.
*/
- public abstract List This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return an integer representing the preferred network type
*
@@ -753,6 +752,7 @@ public class ConnectivityManager {
* the networks to describe their precedence.
*/
@Deprecated
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public int getNetworkPreference() {
return TYPE_NONE;
}
@@ -763,12 +763,11 @@ public class ConnectivityManager {
* You should always check {@link NetworkInfo#isConnected()} before initiating
* network traffic. This may return {@code null} when there is no default
* network.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return a {@link NetworkInfo} object for the current default network
* or {@code null} if no default network is currently active
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public NetworkInfo getActiveNetworkInfo() {
try {
return mService.getActiveNetworkInfo();
@@ -783,12 +782,11 @@ public class ConnectivityManager {
* network disconnects, the returned {@code Network} object will no longer
* be usable. This will return {@code null} when there is no default
* network.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return a {@link Network} object for the current default network or
* {@code null} if no default network is currently active
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public Network getActiveNetwork() {
try {
return mService.getActiveNetwork();
@@ -803,14 +801,13 @@ public class ConnectivityManager {
* network disconnects, the returned {@code Network} object will no longer
* be usable. This will return {@code null} when there is no default
* network for the UID.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
*
* @return a {@link Network} object for the current default network for the
* given UID or {@code null} if no default network is currently active
*
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL)
public Network getActiveNetworkForUid(int uid) {
return getActiveNetworkForUid(uid, false);
}
@@ -871,8 +868,6 @@ public class ConnectivityManager {
* Returns details about the currently active default data network
* for a given uid. This is for internal use only to avoid spying
* other apps.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}
*
* @return a {@link NetworkInfo} object for the current default network
* for the given uid or {@code null} if no default network is
@@ -880,6 +875,7 @@ public class ConnectivityManager {
*
* {@hide}
*/
+ @RequiresPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL)
public NetworkInfo getActiveNetworkInfoForUid(int uid) {
return getActiveNetworkInfoForUid(uid, false);
}
@@ -896,8 +892,6 @@ public class ConnectivityManager {
/**
* Returns connection status information about a particular
* network type.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param networkType integer specifying which networkType in
* which you're interested.
@@ -910,6 +904,7 @@ public class ConnectivityManager {
* {@link #getNetworkInfo(android.net.Network)} instead.
*/
@Deprecated
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public NetworkInfo getNetworkInfo(int networkType) {
try {
return mService.getNetworkInfo(networkType);
@@ -921,8 +916,6 @@ public class ConnectivityManager {
/**
* Returns connection status information about a particular
* Network.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param network {@link Network} specifying which network
* in which you're interested.
@@ -930,6 +923,7 @@ public class ConnectivityManager {
* network or {@code null} if the {@code Network}
* is not valid.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public NetworkInfo getNetworkInfo(Network network) {
return getNetworkInfoForUid(network, Process.myUid(), false);
}
@@ -946,8 +940,6 @@ public class ConnectivityManager {
/**
* Returns connection status information about all network
* types supported by the device.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return an array of {@link NetworkInfo} objects. Check each
* {@link NetworkInfo#getType} for which type each applies.
@@ -957,6 +949,7 @@ public class ConnectivityManager {
* {@link #getNetworkInfo(android.net.Network)} instead.
*/
@Deprecated
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public NetworkInfo[] getAllNetworkInfo() {
try {
return mService.getAllNetworkInfo();
@@ -969,15 +962,13 @@ public class ConnectivityManager {
* Returns the {@link Network} object currently serving a given type, or
* null if the given type is not connected.
*
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
- *
* @hide
* @deprecated This method does not support multiple connected networks
* of the same type. Use {@link #getAllNetworks} and
* {@link #getNetworkInfo(android.net.Network)} instead.
*/
@Deprecated
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public Network getNetworkForType(int networkType) {
try {
return mService.getNetworkForType(networkType);
@@ -989,11 +980,10 @@ public class ConnectivityManager {
/**
* Returns an array of all {@link Network} currently tracked by the
* framework.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return an array of {@link Network} objects.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public Network[] getAllNetworks() {
try {
return mService.getAllNetworks();
@@ -1017,8 +1007,6 @@ public class ConnectivityManager {
/**
* Returns the IP information for the current default network.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return a {@link LinkProperties} object describing the IP info
* for the current default network, or {@code null} if there
@@ -1026,6 +1014,7 @@ public class ConnectivityManager {
*
* {@hide}
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public LinkProperties getActiveLinkProperties() {
try {
return mService.getActiveLinkProperties();
@@ -1036,8 +1025,6 @@ public class ConnectivityManager {
/**
* Returns the IP information for a given network type.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param networkType the network type of interest.
* @return a {@link LinkProperties} object describing the IP info
@@ -1051,6 +1038,7 @@ public class ConnectivityManager {
* {@link #getLinkProperties(android.net.Network)} instead.
*/
@Deprecated
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public LinkProperties getLinkProperties(int networkType) {
try {
return mService.getLinkPropertiesForType(networkType);
@@ -1062,12 +1050,11 @@ public class ConnectivityManager {
/**
* Get the {@link LinkProperties} for the given {@link Network}. This
* will return {@code null} if the network is unknown.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param network The {@link Network} object identifying the network in question.
* @return The {@link LinkProperties} for the network, or {@code null}.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public LinkProperties getLinkProperties(Network network) {
try {
return mService.getLinkProperties(network);
@@ -1079,12 +1066,11 @@ public class ConnectivityManager {
/**
* Get the {@link android.net.NetworkCapabilities} for the given {@link Network}. This
* will return {@code null} if the network is unknown.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param network The {@link Network} object identifying the network in question.
* @return The {@link android.net.NetworkCapabilities} for the network, or {@code null}.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public NetworkCapabilities getNetworkCapabilities(Network network) {
try {
return mService.getNetworkCapabilities(network);
@@ -1727,11 +1713,9 @@ public class ConnectivityManager {
* network is active. Quota status can change rapidly, so these values
* shouldn't be cached.
*
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
- *
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
try {
return mService.getActiveNetworkQuotaInfo();
@@ -1929,13 +1913,12 @@ public class ConnectivityManager {
/**
* Get the set of tetherable, available interfaces. This list is limited by
* device configuration and current interface existence.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return an array of 0 or more Strings of tetherable interface names.
*
* {@hide}
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public String[] getTetherableIfaces() {
try {
return mService.getTetherableIfaces();
@@ -1946,13 +1929,12 @@ public class ConnectivityManager {
/**
* Get the set of tethered interfaces.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return an array of 0 or more String of currently tethered interface names.
*
* {@hide}
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public String[] getTetheredIfaces() {
try {
return mService.getTetheredIfaces();
@@ -1968,14 +1950,13 @@ public class ConnectivityManager {
* may cause them to reset to the available state.
* {@link ConnectivityManager#getLastTetherError} can be used to get more
* information on the cause of the errors.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return an array of 0 or more String indicating the interface names
* which failed to tether.
*
* {@hide}
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public String[] getTetheringErroredIfaces() {
try {
return mService.getTetheringErroredIfaces();
@@ -2060,14 +2041,13 @@ public class ConnectivityManager {
* Check if the device allows for tethering. It may be disabled via
* {@code ro.tether.denied} system property, Settings.TETHER_SUPPORTED or
* due to device configuration.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return a boolean - {@code true} indicating Tethering is supported.
*
* {@hide}
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public boolean isTetheringSupported() {
try {
return mService.isTetheringSupported();
@@ -2171,14 +2151,13 @@ public class ConnectivityManager {
* Get the list of regular expressions that define any tetherable
* USB network interfaces. If USB tethering is not supported by the
* device, this list should be empty.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable usb interfaces.
*
* {@hide}
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public String[] getTetherableUsbRegexs() {
try {
return mService.getTetherableUsbRegexs();
@@ -2191,14 +2170,13 @@ public class ConnectivityManager {
* Get the list of regular expressions that define any tetherable
* Wifi network interfaces. If Wifi tethering is not supported by the
* device, this list should be empty.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable wifi interfaces.
*
* {@hide}
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public String[] getTetherableWifiRegexs() {
try {
return mService.getTetherableWifiRegexs();
@@ -2211,14 +2189,13 @@ public class ConnectivityManager {
* Get the list of regular expressions that define any tetherable
* Bluetooth network interfaces. If Bluetooth tethering is not supported by the
* device, this list should be empty.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable bluetooth interfaces.
*
* {@hide}
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public String[] getTetherableBluetoothRegexs() {
try {
return mService.getTetherableBluetoothRegexs();
@@ -2280,8 +2257,6 @@ public class ConnectivityManager {
/**
* Get a more detailed error code after a Tethering or Untethering
* request asynchronously failed.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param iface The name of the interface of interest
* @return error The error code of the last error tethering or untethering the named
@@ -2289,6 +2264,7 @@ public class ConnectivityManager {
*
* {@hide}
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public int getLastTetherError(String iface) {
try {
return mService.getLastTetherError(iface);
@@ -2362,13 +2338,12 @@ public class ConnectivityManager {
* for typical HTTP proxies - they are general network dependent. However if you're
* doing something unusual like general internal filtering this may be useful. On
* a private network where the proxy is not accessible, you may break HTTP using this.
- * This method requires the caller to hold the permission
- * android.Manifest.permission#CONNECTIVITY_INTERNAL.
*
* @param p A {@link ProxyInfo} object defining the new global
* HTTP proxy. A {@code null} value will clear the global HTTP proxy.
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL)
public void setGlobalProxy(ProxyInfo p) {
try {
mService.setGlobalProxy(p);
@@ -2434,14 +2409,13 @@ public class ConnectivityManager {
* hardware supports it. For example a GSM phone without a SIM
* should still return {@code true} for mobile data, but a wifi only
* tablet would return {@code false}.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param networkType The network type we'd like to check
* @return {@code true} if supported, else {@code false}
*
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public boolean isNetworkSupported(int networkType) {
try {
return mService.isNetworkSupported(networkType);
@@ -2457,12 +2431,11 @@ public class ConnectivityManager {
* battery/performance issues. You should check this before doing large
* data transfers, and warn the user or delay the operation until another
* network is available.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @return {@code true} if large transfers should be avoided, otherwise
* {@code false}.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public boolean isActiveNetworkMetered() {
try {
return mService.isActiveNetworkMetered();
@@ -2541,13 +2514,12 @@ public class ConnectivityManager {
/**
* Set the value for enabling/disabling airplane mode
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
*
* @param enable whether to enable airplane mode or not
*
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL)
public void setAirplaneMode(boolean enable) {
try {
mService.setAirplaneMode(enable);
@@ -3225,14 +3197,13 @@ public class ConnectivityManager {
* Registers to receive notifications about all networks which satisfy the given
* {@link NetworkRequest}. The callbacks will continue to be called until
* either the application exits or link #unregisterNetworkCallback(NetworkCallback)} is called.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param request {@link NetworkRequest} describing this request.
* @param networkCallback The {@link NetworkCallback} that the system will call as suitable
* networks change state.
* The callback is invoked on the default internal Handler.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public void registerNetworkCallback(NetworkRequest request, NetworkCallback networkCallback) {
registerNetworkCallback(request, networkCallback, getDefaultHandler());
}
@@ -3241,14 +3212,13 @@ public class ConnectivityManager {
* Registers to receive notifications about all networks which satisfy the given
* {@link NetworkRequest}. The callbacks will continue to be called until
* either the application exits or link #unregisterNetworkCallback(NetworkCallback)} is called.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param request {@link NetworkRequest} describing this request.
* @param networkCallback The {@link NetworkCallback} that the system will call as suitable
* networks change state.
* @param handler {@link Handler} to specify the thread upon which the callback will be invoked.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public void registerNetworkCallback(
NetworkRequest request, NetworkCallback networkCallback, Handler handler) {
CallbackHandler cbHandler = new CallbackHandler(handler);
@@ -3280,13 +3250,12 @@ public class ConnectivityManager {
*
* The request may be released normally by calling
* {@link #unregisterNetworkCallback(android.app.PendingIntent)}.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
* @param request {@link NetworkRequest} describing this request.
* @param operation Action to perform when the network is available (corresponds
* to the {@link NetworkCallback#onAvailable} call. Typically
* comes from {@link PendingIntent#getBroadcast}. Cannot be null.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public void registerNetworkCallback(NetworkRequest request, PendingIntent operation) {
checkPendingIntent(operation);
try {
@@ -3300,13 +3269,12 @@ public class ConnectivityManager {
* Registers to receive notifications about changes in the system default network. The callbacks
* will continue to be called until either the application exits or
* {@link #unregisterNetworkCallback(NetworkCallback)} is called.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param networkCallback The {@link NetworkCallback} that the system will call as the
* system default network changes.
* The callback is invoked on the default internal Handler.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public void registerDefaultNetworkCallback(NetworkCallback networkCallback) {
registerDefaultNetworkCallback(networkCallback, getDefaultHandler());
}
@@ -3315,13 +3283,12 @@ public class ConnectivityManager {
* Registers to receive notifications about changes in the system default network. The callbacks
* will continue to be called until either the application exits or
* {@link #unregisterNetworkCallback(NetworkCallback)} is called.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param networkCallback The {@link NetworkCallback} that the system will call as the
* system default network changes.
* @param handler {@link Handler} to specify the thread upon which the callback will be invoked.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public void registerDefaultNetworkCallback(NetworkCallback networkCallback, Handler handler) {
// This works because if the NetworkCapabilities are null,
// ConnectivityService takes them from the default request.
@@ -3398,15 +3365,13 @@ public class ConnectivityManager {
* {@code always} is true, then the choice is remembered, so that the next time the user
* connects to this network, the system will switch to it.
*
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}
- *
* @param network The network to accept.
* @param accept Whether to accept the network even if unvalidated.
* @param always Whether to remember this choice in the future.
*
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL)
public void setAcceptUnvalidated(Network network, boolean accept, boolean always) {
try {
mService.setAcceptUnvalidated(network, accept, always);
@@ -3421,13 +3386,11 @@ public class ConnectivityManager {
* {@code config_networkAvoidBadWifi} configuration variable is set to 0 and the {@code
* NETWORK_AVOID_BAD_WIFI setting is unset}.
*
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}
- *
* @param network The network to accept.
*
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL)
public void setAvoidUnvalidated(Network network) {
try {
mService.setAvoidUnvalidated(network);
@@ -3488,15 +3451,13 @@ public class ConnectivityManager {
* for multipath data transfer on this network when it is not the system default network.
* Applications desiring to use multipath network protocols should call this method before
* each such operation.
- *
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param network The network on which the application desires to use multipath data.
* If {@code null}, this method will return the a preference that will generally
* apply to metered networks.
* @return a bitwise OR of zero or more of the {@code MULTIPATH_PREFERENCE_*} constants.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
public @MultipathPreference int getMultipathPreference(Network network) {
try {
return mService.getMultipathPreference(network);
diff --git a/core/java/android/os/Parcelable.java b/core/java/android/os/Parcelable.java
index c10abec7a80a8..6632ca51e74c5 100644
--- a/core/java/android/os/Parcelable.java
+++ b/core/java/android/os/Parcelable.java
@@ -16,6 +16,11 @@
package android.os;
+import android.annotation.IntDef;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
* Interface for classes whose instances can be written to
* and restored from a {@link Parcel}. Classes implementing the Parcelable
@@ -53,6 +58,14 @@ package android.os;
* }
*/
public interface Parcelable {
+ /** @hide */
+ @IntDef(flag = true, prefix = { "PARCELABLE_" }, value = {
+ PARCELABLE_WRITE_RETURN_VALUE,
+ PARCELABLE_ELIDE_DUPLICATES,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface WriteFlags {}
+
/**
* Flag for use with {@link #writeToParcel}: the object being written
* is a return value, that is the result of a function such as
@@ -79,6 +92,13 @@ public interface Parcelable {
* marshalled.
*/
+ /** @hide */
+ @IntDef(flag = true, prefix = { "CONTENTS_" }, value = {
+ CONTENTS_FILE_DESCRIPTOR,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface ContentsFlags {}
+
/**
* Descriptor bit used with {@link #describeContents()}: indicates that
* the Parcelable object's flattened representation includes a file descriptor.
@@ -96,10 +116,8 @@ public interface Parcelable {
*
* @return a bitmask indicating the set of special object types marshaled
* by this Parcelable object instance.
- *
- * @see #CONTENTS_FILE_DESCRIPTOR
*/
- public int describeContents();
+ public @ContentsFlags int describeContents();
/**
* Flatten this object in to a Parcel.
@@ -108,7 +126,7 @@ public interface Parcelable {
* @param flags Additional flags about how the object should be written.
* May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
*/
- public void writeToParcel(Parcel dest, int flags);
+ public void writeToParcel(Parcel dest, @WriteFlags int flags);
/**
* Interface that must be implemented and provided as a public CREATOR
diff --git a/core/java/android/os/Vibrator.java b/core/java/android/os/Vibrator.java
index c6bbf484e7024..1e55c78845d1a 100644
--- a/core/java/android/os/Vibrator.java
+++ b/core/java/android/os/Vibrator.java
@@ -16,6 +16,7 @@
package android.os;
+import android.annotation.RequiresPermission;
import android.app.ActivityThread;
import android.content.Context;
import android.media.AudioAttributes;
@@ -65,22 +66,19 @@ public abstract class Vibrator {
/**
* Vibrate constantly for the specified period of time.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#VIBRATE}.
*
* @param milliseconds The number of milliseconds to vibrate.
*
* @deprecated Use {@link #vibrate(VibrationEffect)} instead.
*/
@Deprecated
+ @RequiresPermission(android.Manifest.permission.VIBRATE)
public void vibrate(long milliseconds) {
vibrate(milliseconds, null);
}
/**
* Vibrate constantly for the specified period of time.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#VIBRATE}.
*
* @param milliseconds The number of milliseconds to vibrate.
* @param attributes {@link AudioAttributes} corresponding to the vibration. For example,
@@ -91,6 +89,7 @@ public abstract class Vibrator {
* @deprecated Use {@link #vibrate(VibrationEffect, AudioAttributes)} instead.
*/
@Deprecated
+ @RequiresPermission(android.Manifest.permission.VIBRATE)
public void vibrate(long milliseconds, AudioAttributes attributes) {
try {
// This ignores all exceptions to stay compatible with pre-O implementations.
@@ -115,8 +114,6 @@ public abstract class Vibrator {
* To cause the pattern to repeat, pass the index into the pattern array at which
* to start the repeat, or -1 to disable repeating.
* This method requires the caller to hold the permission
- * {@link android.Manifest.permission#VIBRATE}.
*
* @param pattern an array of longs of times for which to turn the vibrator on or off.
* @param repeat the index into pattern at which to repeat, or -1 if
@@ -125,6 +122,7 @@ public abstract class Vibrator {
* @deprecated Use {@link #vibrate(VibrationEffect)} instead.
*/
@Deprecated
+ @RequiresPermission(android.Manifest.permission.VIBRATE)
public void vibrate(long[] pattern, int repeat) {
vibrate(pattern, repeat, null);
}
@@ -142,8 +140,6 @@ public abstract class Vibrator {
* To cause the pattern to repeat, pass the index into the pattern array at which
* to start the repeat, or -1 to disable repeating.
* This method requires the caller to hold the permission
- * {@link android.Manifest.permission#VIBRATE}.
*
* @param pattern an array of longs of times for which to turn the vibrator on or off.
* @param repeat the index into pattern at which to repeat, or -1 if
@@ -156,6 +152,7 @@ public abstract class Vibrator {
* @deprecated Use {@link #vibrate(VibrationEffect, AudioAttributes)} instead.
*/
@Deprecated
+ @RequiresPermission(android.Manifest.permission.VIBRATE)
public void vibrate(long[] pattern, int repeat, AudioAttributes attributes) {
// This call needs to continue throwing ArrayIndexOutOfBoundsException but ignore all other
// exceptions for compatibility purposes
@@ -170,10 +167,12 @@ public abstract class Vibrator {
}
}
+ @RequiresPermission(android.Manifest.permission.VIBRATE)
public void vibrate(VibrationEffect vibe) {
vibrate(vibe, null);
}
+ @RequiresPermission(android.Manifest.permission.VIBRATE)
public void vibrate(VibrationEffect vibe, AudioAttributes attributes) {
vibrate(Process.myUid(), mPackageName, vibe, attributes);
}
@@ -183,13 +182,13 @@ public abstract class Vibrator {
* that the vibration is owned by someone else.
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.VIBRATE)
public abstract void vibrate(int uid, String opPkg,
VibrationEffect vibe, AudioAttributes attributes);
/**
* Turn the vibrator off.
- * This method requires the caller to hold the permission
- * {@link android.Manifest.permission#VIBRATE}.
*/
+ @RequiresPermission(android.Manifest.permission.VIBRATE)
public abstract void cancel();
}