From 30e06bb668f2e4b024c4ebc2a131de91c96de5eb Mon Sep 17 00:00:00 2001
From: Jeff Sharkey 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.
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 @@ -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();
}