Annotate @SystemApi with required permissions.
Most @SystemApi methods should be protected with system (or higher)
permissions, so annotate common methods with @RequiresPermission to
make automatic verification easier.
Verification is really only relevant when calling into system
services (where permissions checking can happen on the other side of
a Binder call), so annotate managers with the new @SystemService
annotation, which is now automatically documented.
This is purely a docs change; no logic changes are being made.
Test: make -j32 update-api && make -j32 offline-sdk-docs
Bug: 62263906
Change-Id: I2554227202d84465676aa4ab0dd336b5c45fc651
diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java
index 8fd8043..8e4b915 100644
--- a/core/java/android/accounts/AccountManager.java
+++ b/core/java/android/accounts/AccountManager.java
@@ -24,6 +24,7 @@
import android.annotation.SdkConstant;
import android.annotation.Size;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.BroadcastBehavior;
import android.app.Activity;
@@ -161,6 +162,7 @@
* the application's main event thread. These operations throw
* {@link IllegalStateException} if they are used on the main thread.
*/
+@SystemService(Context.ACCOUNT_SERVICE)
public class AccountManager {
private static final String TAG = "AccountManager";
@@ -3237,6 +3239,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
public AccountManagerFuture<Bundle> finishSessionAsUser(
final Bundle sessionBundle,
final Activity activity,
diff --git a/core/java/android/annotation/SystemService.java b/core/java/android/annotation/SystemService.java
new file mode 100644
index 0000000..ba5002a
--- /dev/null
+++ b/core/java/android/annotation/SystemService.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.annotation;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import android.content.Context;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Description of a system service available through
+ * {@link Context#getSystemService(Class)}.
+ *
+ * @hide
+ */
+@Retention(SOURCE)
+@Target(TYPE)
+public @interface SystemService {
+ String value();
+}
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index 369968f..f398c8d 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -22,6 +22,7 @@
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.annotation.TestApi;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
@@ -117,6 +118,7 @@
* be used for testing and debugging purposes only.
* </p>
*/
+@SystemService(Context.ACTIVITY_SERVICE)
public class ActivityManager {
private static String TAG = "ActivityManager";
@@ -3610,6 +3612,7 @@
* @hide
*/
@SystemApi @TestApi
+ @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
public void addOnUidImportanceListener(OnUidImportanceListener listener,
@RunningAppProcessInfo.Importance int importanceCutpoint) {
synchronized (this) {
@@ -3638,6 +3641,7 @@
* @hide
*/
@SystemApi @TestApi
+ @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
public void removeOnUidImportanceListener(OnUidImportanceListener listener) {
synchronized (this) {
UidObserver observer = mImportanceListeners.remove(listener);
@@ -4005,6 +4009,10 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(anyOf = {
+ "android.permission.INTERACT_ACROSS_USERS",
+ "android.permission.INTERACT_ACROSS_USERS_FULL"
+ })
public static int getCurrentUser() {
UserInfo ui;
try {
diff --git a/core/java/android/app/AlarmManager.java b/core/java/android/app/AlarmManager.java
index 620e5cf..d497db0 100644
--- a/core/java/android/app/AlarmManager.java
+++ b/core/java/android/app/AlarmManager.java
@@ -19,6 +19,7 @@
import android.annotation.IntDef;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
@@ -72,12 +73,8 @@
* {@link #setExact(int, long, PendingIntent)}. Applications whose {@code targetSdkVersion}
* is earlier than API 19 will continue to see the previous behavior in which all
* alarms are delivered exactly when requested.
- *
- * <p>You do not
- * instantiate this class directly; instead, retrieve it through
- * {@link android.content.Context#getSystemService
- * Context.getSystemService(Context.ALARM_SERVICE)}.
*/
+@SystemService(Context.ALARM_SERVICE)
public class AlarmManager {
private static final String TAG = "AlarmManager";
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index 8292152..e672ada 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -17,7 +17,9 @@
package android.app;
import android.Manifest;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.app.usage.UsageStatsManager;
import android.content.Context;
import android.media.AudioAttributes.AttributeUsage;
@@ -42,10 +44,9 @@
* API for interacting with "application operation" tracking.
*
* <p>This API is not generally intended for third party application developers; most
- * features are only available to system applications. Obtain an instance of it through
- * {@link Context#getSystemService(String) Context.getSystemService} with
- * {@link Context#APP_OPS_SERVICE Context.APP_OPS_SERVICE}.</p>
+ * features are only available to system applications.
*/
+@SystemService(Context.APP_OPS_SERVICE)
public class AppOpsManager {
/**
* <p>App ops allows callers to:</p>
@@ -1409,6 +1410,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.UPDATE_APP_OPS_STATS)
public void setUidMode(String appOp, int uid, int mode) {
try {
mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode);
diff --git a/core/java/android/app/BroadcastOptions.java b/core/java/android/app/BroadcastOptions.java
index 175b979..b6cff38 100644
--- a/core/java/android/app/BroadcastOptions.java
+++ b/core/java/android/app/BroadcastOptions.java
@@ -16,6 +16,7 @@
package android.app;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.os.Build;
import android.os.Bundle;
@@ -72,6 +73,7 @@
* power whitelist when this broadcast is being delivered to it.
* @param duration The duration in milliseconds; 0 means to not place on whitelist.
*/
+ @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST)
public void setTemporaryAppWhitelistDuration(long duration) {
mTemporaryAppWhitelistDuration = duration;
}
diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java
index b89c165..5baaeb3 100644
--- a/core/java/android/app/DownloadManager.java
+++ b/core/java/android/app/DownloadManager.java
@@ -19,6 +19,7 @@
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.ContentResolver;
import android.content.ContentUris;
@@ -51,18 +52,15 @@
* request that a URI be downloaded to a particular destination file. The download manager will
* conduct the download in the background, taking care of HTTP interactions and retrying downloads
* after failures or across connectivity changes and system reboots.
- *
- * Instances of this class should be obtained through
- * {@link android.content.Context#getSystemService(String)} by passing
- * {@link android.content.Context#DOWNLOAD_SERVICE}.
- *
+ * <p>
* Apps that request downloads through this API should register a broadcast receiver for
* {@link #ACTION_NOTIFICATION_CLICKED} to appropriately handle when the user clicks on a running
* download in a notification or from the downloads UI.
- *
+ * <p>
* Note that the application must have the {@link android.Manifest.permission#INTERNET}
* permission to use this class.
*/
+@SystemService(Context.DOWNLOAD_SERVICE)
public class DownloadManager {
/**
diff --git a/core/java/android/app/KeyguardManager.java b/core/java/android/app/KeyguardManager.java
index fcf0aab..2a29616 100644
--- a/core/java/android/app/KeyguardManager.java
+++ b/core/java/android/app/KeyguardManager.java
@@ -20,6 +20,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
+import android.annotation.SystemService;
import android.app.trust.ITrustManager;
import android.content.Context;
import android.content.Intent;
@@ -44,12 +45,11 @@
import java.util.List;
/**
- * Class that can be used to lock and unlock the keyboard. Get an instance of this
- * class by calling {@link android.content.Context#getSystemService(java.lang.String)}
- * with argument {@link android.content.Context#KEYGUARD_SERVICE}. The
+ * Class that can be used to lock and unlock the keyboard. The
* actual class to control the keyboard locking is
* {@link android.app.KeyguardManager.KeyguardLock}.
*/
+@SystemService(Context.KEYGUARD_SERVICE)
public class KeyguardManager {
private static final String TAG = "KeyguardManager";
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 31f52db..ad6b454 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -22,6 +22,7 @@
import android.annotation.DrawableRes;
import android.annotation.IntDef;
import android.annotation.NonNull;
+import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
@@ -1009,6 +1010,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP)
public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup";
/**
@@ -1110,6 +1112,7 @@
/** @hide */
@SystemApi
+ @RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME)
public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName";
/**
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 6c55548..235b8d4 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -20,6 +20,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
+import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.Notification.Builder;
import android.content.ComponentName;
@@ -81,10 +82,6 @@
* to the {@link #cancel(int)} or {@link #cancel(String, int)} method to clear
* this notification.
*
- * <p>
- * You do not instantiate this class directly; instead, retrieve it through
- * {@link android.content.Context#getSystemService}.
- *
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For a guide to creating notifications, read the
@@ -93,10 +90,9 @@
* </div>
*
* @see android.app.Notification
- * @see android.content.Context#getSystemService
*/
-public class NotificationManager
-{
+@SystemService(Context.NOTIFICATION_SERVICE)
+public class NotificationManager {
private static String TAG = "NotificationManager";
private static boolean localLOGV = false;
diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java
index c529e4b..ea990ad 100644
--- a/core/java/android/app/SearchManager.java
+++ b/core/java/android/app/SearchManager.java
@@ -16,6 +16,7 @@
package android.app;
+import android.annotation.SystemService;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -46,10 +47,6 @@
* services are provided through methods in {@link android.app.Activity Activity}
* and the {@link android.content.Intent#ACTION_SEARCH ACTION_SEARCH}
* {@link android.content.Intent Intent}.
- * If you do require direct access to the SearchManager, do not instantiate
- * this class directly. Instead, retrieve it through
- * {@link android.content.Context#getSystemService
- * context.getSystemService(Context.SEARCH_SERVICE)}.
*
* <div class="special reference">
* <h3>Developer Guides</h3>
@@ -58,9 +55,9 @@
* <a href="{@docRoot}guide/topics/search/index.html">Search</a> developer guide.</p>
* </div>
*/
+@SystemService(Context.SEARCH_SERVICE)
public class SearchManager
- implements DialogInterface.OnDismissListener, DialogInterface.OnCancelListener
-{
+ implements DialogInterface.OnDismissListener, DialogInterface.OnCancelListener {
private static final boolean DBG = false;
private static final String TAG = "SearchManager";
diff --git a/core/java/android/app/StatusBarManager.java b/core/java/android/app/StatusBarManager.java
index e57a9b5..fb8bd39 100644
--- a/core/java/android/app/StatusBarManager.java
+++ b/core/java/android/app/StatusBarManager.java
@@ -18,6 +18,7 @@
package android.app;
import android.annotation.IntDef;
+import android.annotation.SystemService;
import android.content.Context;
import android.os.Binder;
import android.os.RemoteException;
@@ -36,6 +37,7 @@
*
* @hide
*/
+@SystemService(Context.STATUS_BAR_SERVICE)
public class StatusBarManager {
public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;
diff --git a/core/java/android/app/UiModeManager.java b/core/java/android/app/UiModeManager.java
index 07e2570..bc61668 100644
--- a/core/java/android/app/UiModeManager.java
+++ b/core/java/android/app/UiModeManager.java
@@ -17,6 +17,7 @@
package android.app;
import android.annotation.IntDef;
+import android.annotation.SystemService;
import android.annotation.TestApi;
import android.content.Context;
import android.content.res.Configuration;
@@ -49,11 +50,8 @@
* displayed allowing the user to exit dock mode. Thus the dock mode
* represented here may be different than the current state of the underlying
* dock event broadcast.
- *
- * <p>You do not instantiate this class directly; instead, retrieve it through
- * {@link android.content.Context#getSystemService
- * Context.getSystemService(Context.UI_MODE_SERVICE)}.
*/
+@SystemService(Context.UI_MODE_SERVICE)
public class UiModeManager {
private static final String TAG = "UiModeManager";
diff --git a/core/java/android/app/VrManager.java b/core/java/android/app/VrManager.java
index 8014eca..b40c96c 100644
--- a/core/java/android/app/VrManager.java
+++ b/core/java/android/app/VrManager.java
@@ -1,19 +1,20 @@
package android.app;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.content.ComponentName;
+import android.content.Context;
import android.os.RemoteException;
import android.service.vr.IVrManager;
/**
* Used to control aspects of a devices Virtual Reality (VR) capabilities.
- * <p>
- * You do not instantiate this class directly; instead, retrieve it through
- * {@link android.content.Context#getSystemService}.
* @hide
*/
@SystemApi
+@SystemService(Context.VR_SERVICE)
public class VrManager {
private final IVrManager mService;
@@ -29,11 +30,10 @@
* remain in VR mode even if the foreground does not specify Vr mode being enabled. Mainly used
* by VR viewers to indicate that a device is placed in a VR viewer.
*
- * <p>Requires {@link android.Manifest.permission#ACCESS_VR_MANAGER} permission.</p>
- *
* @see Activity#setVrModeEnabled(boolean, ComponentName)
* @param enabled true if the device should be placed in persistent VR mode.
*/
+ @RequiresPermission(android.Manifest.permission.RESTRICTED_VR_ACCESS)
public void setPersistentVrModeEnabled(boolean enabled) {
try {
mService.setPersistentVrModeEnabled(enabled);
@@ -46,13 +46,12 @@
* Sets the resolution and DPI of the vr2d virtual display used to display 2D
* applications in VR mode.
*
- * <p>Requires {@link android.Manifest.permission#ACCESS_VR_MANAGER} permission.</p>
- *
* @param vr2dDisplayProp properties to be set to the virtual display for
* 2D applications in VR mode.
*
* {@hide}
*/
+ @RequiresPermission(android.Manifest.permission.RESTRICTED_VR_ACCESS)
public void setVr2dDisplayProperties(
Vr2dDisplayProperties vr2dDisplayProp) {
try {
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index db2f937..a850423 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -18,8 +18,10 @@
import android.annotation.IntDef;
import android.annotation.RawRes;
+import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -76,13 +78,13 @@
/**
* Provides access to the system wallpaper. With WallpaperManager, you can
* get the current wallpaper, get the desired dimensions for the wallpaper, set
- * the wallpaper, and more. Get an instance of WallpaperManager with
- * {@link #getInstance(android.content.Context) getInstance()}.
+ * the wallpaper, and more.
*
* <p> An app can check whether wallpapers are supported for the current user, by calling
* {@link #isWallpaperSupported()}, and whether setting of wallpapers is allowed, by calling
* {@link #isSetWallpaperAllowed()}.
*/
+@SystemService(Context.WALLPAPER_SERVICE)
public class WallpaperManager {
private static String TAG = "WallpaperManager";
private static boolean DEBUG = false;
@@ -1355,6 +1357,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_HINTS)
public void setDisplayPadding(Rect padding) {
try {
if (sGlobals.mService == null) {
@@ -1395,6 +1398,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.SET_WALLPAPER)
public void clearWallpaper() {
clearWallpaper(FLAG_LOCK, mContext.getUserId());
clearWallpaper(FLAG_SYSTEM, mContext.getUserId());
@@ -1407,6 +1411,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.SET_WALLPAPER)
public void clearWallpaper(@SetWallpaperFlags int which, int userId) {
if (sGlobals.mService == null) {
Log.w(TAG, "WallpaperService not running");
@@ -1422,12 +1427,10 @@
/**
* Set the live wallpaper.
*
- * This can only be called by packages with android.permission.SET_WALLPAPER_COMPONENT
- * permission.
- *
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT)
public boolean setWallpaperComponent(ComponentName name) {
return setWallpaperComponent(name, UserHandle.myUserId());
}
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 9ae5d1c..b6c6f5b 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -20,9 +20,12 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
+import android.annotation.SuppressLint;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UserIdInt;
import android.annotation.WorkerThread;
@@ -98,6 +101,7 @@
* "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
* guide. </div>
*/
+@SystemService(Context.DEVICE_POLICY_SERVICE)
public class DevicePolicyManager {
private static String TAG = "DevicePolicyManager";
@@ -4653,6 +4657,7 @@
*/
@Deprecated
@SystemApi
+ @SuppressLint("Doclava125")
public @Nullable String getDeviceInitializerApp() {
return null;
}
@@ -4664,6 +4669,7 @@
*/
@Deprecated
@SystemApi
+ @SuppressLint("Doclava125")
public @Nullable ComponentName getDeviceInitializerComponent() {
return null;
}
@@ -4686,6 +4692,7 @@
*/
@Deprecated
@SystemApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS)
public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
throws IllegalArgumentException {
throwIfParentInstance("setActiveProfileOwner");
@@ -6773,8 +6780,7 @@
* Called by the system update service to notify device and profile owners of pending system
* updates.
*
- * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
- * permission. This method should only be used when it is unknown whether the pending system
+ * This method should only be used when it is unknown whether the pending system
* update is a security patch. Otherwise, use
* {@link #notifyPendingSystemUpdate(long, boolean)}.
*
@@ -6785,6 +6791,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
public void notifyPendingSystemUpdate(long updateReceivedTime) {
throwIfParentInstance("notifyPendingSystemUpdate");
if (mService != null) {
@@ -6800,8 +6807,7 @@
* Called by the system update service to notify device and profile owners of pending system
* updates.
*
- * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
- * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
+ * This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
* when it is known whether the pending system update is a security patch.
*
* @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
@@ -6813,6 +6819,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE)
public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
throwIfParentInstance("notifyPendingSystemUpdate");
if (mService != null) {
@@ -7711,6 +7718,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
public void setDeviceProvisioningConfigApplied() {
try {
mService.setDeviceProvisioningConfigApplied();
diff --git a/core/java/android/app/backup/BackupManager.java b/core/java/android/app/backup/BackupManager.java
index 9d02f53..9f9b217 100644
--- a/core/java/android/app/backup/BackupManager.java
+++ b/core/java/android/app/backup/BackupManager.java
@@ -16,6 +16,7 @@
package android.app.backup;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.content.ComponentName;
import android.content.Context;
@@ -324,6 +325,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public RestoreSession beginRestoreSession() {
RestoreSession session = null;
checkServiceBinder();
@@ -348,11 +350,10 @@
* mechanism was disabled will still be backed up properly if it is enabled
* at some point in the future.
*
- * <p>Callers must hold the android.permission.BACKUP permission to use this method.
- *
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public void setBackupEnabled(boolean isEnabled) {
checkServiceBinder();
if (sService != null) {
@@ -367,11 +368,10 @@
/**
* Report whether the backup mechanism is currently enabled.
*
- * <p>Callers must hold the android.permission.BACKUP permission to use this method.
- *
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public boolean isBackupEnabled() {
checkServiceBinder();
if (sService != null) {
@@ -390,11 +390,10 @@
* the archival restore dataset (if any). When disabled, no such attempt will
* be made.
*
- * <p>Callers must hold the android.permission.BACKUP permission to use this method.
- *
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public void setAutoRestore(boolean isEnabled) {
checkServiceBinder();
if (sService != null) {
@@ -407,14 +406,14 @@
}
/**
- * Identify the currently selected transport. Callers must hold the
- * android.permission.BACKUP permission to use this method.
+ * Identify the currently selected transport.
* @return The name of the currently active backup transport. In case of
* failure or if no transport is currently active, this method returns {@code null}.
*
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public String getCurrentTransport() {
checkServiceBinder();
if (sService != null) {
@@ -428,12 +427,12 @@
}
/**
- * Request a list of all available backup transports' names. Callers must
- * hold the android.permission.BACKUP permission to use this method.
+ * Request a list of all available backup transports' names.
*
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public String[] listAllTransports() {
checkServiceBinder();
if (sService != null) {
@@ -449,8 +448,6 @@
/**
* Specify the current backup transport.
*
- * <p> Callers must hold the android.permission.BACKUP permission to use this method.
- *
* @param transport The name of the transport to select. This should be one
* of the names returned by {@link #listAllTransports()}. This is the String returned by
* {@link BackupTransport#name()} for the particular transport.
@@ -462,6 +459,7 @@
*/
@Deprecated
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public String selectBackupTransport(String transport) {
checkServiceBinder();
if (sService != null) {
@@ -479,8 +477,6 @@
* This method is async because BackupManager might need to bind to the specified transport
* which is in a separate process.
*
- * <p>Callers must hold the android.permission.BACKUP permission to use this method.
- *
* @param transport ComponentName of the service hosting the transport. This is different from
* the transport's name that is returned by {@link BackupTransport#name()}.
* @param listener A listener object to get a callback on the transport being selected.
@@ -488,6 +484,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public void selectBackupTransport(ComponentName transport,
SelectBackupTransportCallback listener) {
checkServiceBinder();
@@ -510,11 +507,10 @@
* transport will still be asked to confirm via the usual requestBackupTime()
* method.
*
- * <p>Callers must hold the android.permission.BACKUP permission to use this method.
- *
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public void backupNow() {
checkServiceBinder();
if (sService != null) {
@@ -530,8 +526,6 @@
* Ask the framework which dataset, if any, the given package's data would be
* restored from if we were to install it right now.
*
- * <p>Callers must hold the android.permission.BACKUP permission to use this method.
- *
* @param packageName The name of the package whose most-suitable dataset we
* wish to look up
* @return The dataset token from which a restore should be attempted, or zero if
@@ -540,6 +534,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public long getAvailableRestoreToken(String packageName) {
checkServiceBinder();
if (sService != null) {
@@ -555,14 +550,13 @@
/**
* Ask the framework whether this app is eligible for backup.
*
- * <p>Callers must hold the android.permission.BACKUP permission to use this method.
- *
* @param packageName The name of the package.
* @return Whether this app is eligible for backup.
*
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public boolean isAppEligibleForBackup(String packageName) {
checkServiceBinder();
if (sService != null) {
@@ -592,6 +586,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public int requestBackup(String[] packages, BackupObserver observer) {
return requestBackup(packages, observer, null, 0);
}
@@ -615,6 +610,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public int requestBackup(String[] packages, BackupObserver observer,
BackupManagerMonitor monitor, int flags) {
checkServiceBinder();
@@ -638,11 +634,10 @@
* Cancel all running backups. After this call returns, no currently running backups will
* interact with the selected transport.
*
- * <p>Callers must hold the android.permission.BACKUP permission to use this method.
- *
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.BACKUP)
public void cancelBackups() {
checkServiceBinder();
if (sService != null) {
diff --git a/core/java/android/app/job/JobScheduler.java b/core/java/android/app/job/JobScheduler.java
index 1768828..3868439 100644
--- a/core/java/android/app/job/JobScheduler.java
+++ b/core/java/android/app/job/JobScheduler.java
@@ -19,8 +19,11 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.content.ClipData;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
@@ -53,6 +56,7 @@
* {@link android.content.Context#getSystemService
* Context.getSystemService(Context.JOB_SCHEDULER_SERVICE)}.
*/
+@SystemService(Context.JOB_SCHEDULER_SERVICE)
public abstract class JobScheduler {
/** @hide */
@IntDef(prefix = { "RESULT_" }, value = {
@@ -132,6 +136,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS)
public abstract @Result int scheduleAsPackage(@NonNull JobInfo job, @NonNull String packageName,
int userId, String tag);
diff --git a/core/java/android/app/trust/TrustManager.java b/core/java/android/app/trust/TrustManager.java
index 06b0aacd..54a7e5c 100644
--- a/core/java/android/app/trust/TrustManager.java
+++ b/core/java/android/app/trust/TrustManager.java
@@ -18,6 +18,8 @@
import android.Manifest;
import android.annotation.RequiresPermission;
+import android.annotation.SystemService;
+import android.content.Context;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -31,6 +33,7 @@
* See {@link com.android.server.trust.TrustManagerService}
* @hide
*/
+@SystemService(Context.TRUST_SERVICE)
public class TrustManager {
private static final int MSG_TRUST_CHANGED = 1;
diff --git a/core/java/android/app/usage/NetworkStatsManager.java b/core/java/android/app/usage/NetworkStatsManager.java
index 6cd4e92..ef262e0 100644
--- a/core/java/android/app/usage/NetworkStatsManager.java
+++ b/core/java/android/app/usage/NetworkStatsManager.java
@@ -19,6 +19,7 @@
import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.Nullable;
+import android.annotation.SystemService;
import android.app.usage.NetworkStats.Bucket;
import android.content.Context;
import android.net.ConnectivityManager;
@@ -82,6 +83,7 @@
* the above permission, even to access an app's own data usage, and carrier-privileged apps were
* not included.
*/
+@SystemService(Context.NETWORK_STATS_SERVICE)
public class NetworkStatsManager {
private static final String TAG = "NetworkStatsManager";
private static final boolean DBG = false;
diff --git a/core/java/android/app/usage/StorageStatsManager.java b/core/java/android/app/usage/StorageStatsManager.java
index 0b2b190..7c68079 100644
--- a/core/java/android/app/usage/StorageStatsManager.java
+++ b/core/java/android/app/usage/StorageStatsManager.java
@@ -20,6 +20,7 @@
import android.annotation.BytesLong;
import android.annotation.NonNull;
+import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.WorkerThread;
import android.content.Context;
@@ -50,6 +51,7 @@
* application.
* </p>
*/
+@SystemService(Context.STORAGE_STATS_SERVICE)
public class StorageStatsManager {
private final Context mContext;
private final IStorageStatsManager mService;
diff --git a/core/java/android/app/usage/UsageStatsManager.java b/core/java/android/app/usage/UsageStatsManager.java
index 75a4a53..1f939f9 100644
--- a/core/java/android/app/usage/UsageStatsManager.java
+++ b/core/java/android/app/usage/UsageStatsManager.java
@@ -16,7 +16,9 @@
package android.app.usage;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.os.RemoteException;
@@ -51,6 +53,7 @@
* the permission implies intention to use the API and the user of the device can grant permission
* through the Settings application.
*/
+@SystemService(Context.USAGE_STATS_SERVICE)
public final class UsageStatsManager {
/**
@@ -252,7 +255,6 @@
* Temporarily whitelist the specified app for a short duration. This is to allow an app
* receiving a high priority message to be able to access the network and acquire wakelocks
* even if the device is in power-save mode or the app is currently considered inactive.
- * The caller must hold the CHANGE_DEVICE_IDLE_TEMP_WHITELIST permission.
* @param packageName The package name of the app to whitelist.
* @param duration Duration to whitelist the app for, in milliseconds. It is recommended that
* this be limited to 10s of seconds. Requested duration will be clamped to a few minutes.
@@ -261,6 +263,7 @@
* @see #isAppInactive(String)
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST)
public void whitelistAppTemporarily(String packageName, long duration, UserHandle user) {
try {
mService.whitelistAppTemporarily(packageName, duration, user.getIdentifier());
diff --git a/core/java/android/appwidget/AppWidgetManager.java b/core/java/android/appwidget/AppWidgetManager.java
index 6327f34..969b19e 100644
--- a/core/java/android/appwidget/AppWidgetManager.java
+++ b/core/java/android/appwidget/AppWidgetManager.java
@@ -20,6 +20,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
+import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.PendingIntent;
import android.content.ComponentName;
@@ -51,6 +52,7 @@
* <a href="{@docRoot}guide/topics/appwidgets/index.html">App Widgets</a> developer guide.</p>
* </div>
*/
+@SystemService(Context.APPWIDGET_SERVICE)
public class AppWidgetManager {
/**
diff --git a/core/java/android/bluetooth/BluetoothManager.java b/core/java/android/bluetooth/BluetoothManager.java
index c7191ba..e2fa38a 100644
--- a/core/java/android/bluetooth/BluetoothManager.java
+++ b/core/java/android/bluetooth/BluetoothManager.java
@@ -18,6 +18,7 @@
import android.Manifest;
import android.annotation.RequiresPermission;
+import android.annotation.SystemService;
import android.content.Context;
import android.os.RemoteException;
import android.util.Log;
@@ -48,6 +49,7 @@
* @see Context#getSystemService
* @see BluetoothAdapter#getDefaultAdapter()
*/
+@SystemService(Context.BLUETOOTH_SERVICE)
public final class BluetoothManager {
private static final String TAG = "BluetoothManager";
private static final boolean DBG = true;
diff --git a/core/java/android/companion/CompanionDeviceManager.java b/core/java/android/companion/CompanionDeviceManager.java
index 4e70e3f..dabe608 100644
--- a/core/java/android/companion/CompanionDeviceManager.java
+++ b/core/java/android/companion/CompanionDeviceManager.java
@@ -21,6 +21,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemService;
import android.app.Activity;
import android.app.Application;
import android.app.PendingIntent;
@@ -47,6 +48,7 @@
*
* @see AssociationRequest
*/
+@SystemService(Context.COMPANION_DEVICE_SERVICE)
public final class CompanionDeviceManager {
private static final boolean DEBUG = false;
diff --git a/core/java/android/content/ClipboardManager.java b/core/java/android/content/ClipboardManager.java
index f1c2f34..718e465 100644
--- a/core/java/android/content/ClipboardManager.java
+++ b/core/java/android/content/ClipboardManager.java
@@ -16,6 +16,7 @@
package android.content;
+import android.annotation.SystemService;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
@@ -29,10 +30,6 @@
* the global clipboard.
*
* <p>
- * You do not instantiate this class directly; instead, retrieve it through
- * {@link android.content.Context#getSystemService}.
- *
- * <p>
* The ClipboardManager API itself is very simple: it consists of methods
* to atomically get and set the current primary clipboard data. That data
* is expressed as a {@link ClipData} object, which defines the protocol
@@ -44,9 +41,8 @@
* <a href="{@docRoot}guide/topics/clipboard/copy-paste.html">Copy and Paste</a>
* developer guide.</p>
* </div>
- *
- * @see android.content.Context#getSystemService
*/
+@SystemService(Context.CLIPBOARD_SERVICE)
public class ClipboardManager extends android.text.ClipboardManager {
private final Context mContext;
private final IClipboard mService;
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 10594af..db80c72 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -1630,13 +1630,13 @@
/**
* Version of {@link #startActivity(Intent)} that allows you to specify the
* user the activity will be started for. This is not available to applications
- * that are not pre-installed on the system image. Using it requires holding
- * the INTERACT_ACROSS_USERS_FULL permission.
+ * that are not pre-installed on the system image.
* @param intent The description of the activity to start.
* @param user The UserHandle of the user to start this activity for.
* @throws ActivityNotFoundException
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
throw new RuntimeException("Not implemented. Must override in a subclass.");
}
@@ -1672,8 +1672,7 @@
/**
* Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
* user the activity will be started for. This is not available to applications
- * that are not pre-installed on the system image. Using it requires holding
- * the INTERACT_ACROSS_USERS_FULL permission.
+ * that are not pre-installed on the system image.
* @param intent The description of the activity to start.
* @param options Additional options for how the Activity should be started.
* May be null if there are no options. See {@link android.app.ActivityOptions}
@@ -1683,6 +1682,7 @@
* @throws ActivityNotFoundException
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
UserHandle userId) {
throw new RuntimeException("Not implemented. Must override in a subclass.");
@@ -1781,6 +1781,7 @@
* @see #startActivities(Intent[])
* @see PackageManager#resolveActivity
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
throw new RuntimeException("Not implemented. Must override in a subclass.");
}
@@ -2081,20 +2082,19 @@
/**
* Version of {@link #sendBroadcast(Intent)} that allows you to specify the
* user the broadcast will be sent to. This is not available to applications
- * that are not pre-installed on the system image. Using it requires holding
- * the INTERACT_ACROSS_USERS permission.
+ * that are not pre-installed on the system image.
* @param intent The intent to broadcast
* @param user UserHandle to send the intent to.
* @see #sendBroadcast(Intent)
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
UserHandle user);
/**
* Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
* user the broadcast will be sent to. This is not available to applications
- * that are not pre-installed on the system image. Using it requires holding
- * the INTERACT_ACROSS_USERS permission.
+ * that are not pre-installed on the system image.
*
* @param intent The Intent to broadcast; all receivers matching this
* Intent will receive the broadcast.
@@ -2105,14 +2105,14 @@
*
* @see #sendBroadcast(Intent, String)
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
UserHandle user, @Nullable String receiverPermission);
/**
* Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
* user the broadcast will be sent to. This is not available to applications
- * that are not pre-installed on the system image. Using it requires holding
- * the INTERACT_ACROSS_USERS permission.
+ * that are not pre-installed on the system image.
*
* @param intent The Intent to broadcast; all receivers matching this
* Intent will receive the broadcast.
@@ -2127,14 +2127,14 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
/**
* Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
* user the broadcast will be sent to. This is not available to applications
- * that are not pre-installed on the system image. Using it requires holding
- * the INTERACT_ACROSS_USERS permission.
+ * that are not pre-installed on the system image.
*
* @param intent The Intent to broadcast; all receivers matching this
* Intent will receive the broadcast.
@@ -2148,6 +2148,7 @@
*
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
UserHandle user, @Nullable String receiverPermission, int appOp);
@@ -2156,8 +2157,7 @@
* {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
* that allows you to specify the
* user the broadcast will be sent to. This is not available to applications
- * that are not pre-installed on the system image. Using it requires holding
- * the INTERACT_ACROSS_USERS permission.
+ * that are not pre-installed on the system image.
*
* <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
*
@@ -2181,6 +2181,7 @@
*
* @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
@Nullable Handler scheduler, int initialCode, @Nullable String initialData,
@@ -2192,6 +2193,7 @@
* BroadcastReceiver, Handler, int, String, Bundle)
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
@Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
@Nullable Handler scheduler, int initialCode, @Nullable String initialData,
@@ -2203,6 +2205,7 @@
* BroadcastReceiver, Handler, int, String, Bundle)
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
@Nullable String receiverPermission, int appOp, @Nullable Bundle options,
BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
@@ -2307,8 +2310,7 @@
/**
* <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
* user the broadcast will be sent to. This is not available to applications
- * that are not pre-installed on the system image. Using it requires holding
- * the INTERACT_ACROSS_USERS permission.
+ * that are not pre-installed on the system image.
*
* @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.
@@ -2324,6 +2326,10 @@
* @see #sendBroadcast(Intent)
*/
@Deprecated
+ @RequiresPermission(allOf = {
+ android.Manifest.permission.INTERACT_ACROSS_USERS,
+ android.Manifest.permission.BROADCAST_STICKY
+ })
public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
UserHandle user);
@@ -2332,6 +2338,10 @@
* This is just here for sending CONNECTIVITY_ACTION.
*/
@Deprecated
+ @RequiresPermission(allOf = {
+ android.Manifest.permission.INTERACT_ACROSS_USERS,
+ android.Manifest.permission.BROADCAST_STICKY
+ })
public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
UserHandle user, Bundle options);
@@ -2340,8 +2350,7 @@
* {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
* that allows you to specify the
* user the broadcast will be sent to. This is not available to applications
- * that are not pre-installed on the system image. Using it requires holding
- * the INTERACT_ACROSS_USERS permission.
+ * that are not pre-installed on the system image.
*
* <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
*
@@ -2369,6 +2378,10 @@
* @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
*/
@Deprecated
+ @RequiresPermission(allOf = {
+ android.Manifest.permission.INTERACT_ACROSS_USERS,
+ android.Manifest.permission.BROADCAST_STICKY
+ })
public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
UserHandle user, BroadcastReceiver resultReceiver,
@Nullable Handler scheduler, int initialCode, @Nullable String initialData,
@@ -2377,8 +2390,7 @@
/**
* <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
* user the broadcast will be sent to. This is not available to applications
- * that are not pre-installed on the system image. Using it requires holding
- * the INTERACT_ACROSS_USERS permission.
+ * that are not pre-installed on the system image.
*
* <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
* permission in order to use this API. If you do not hold that
@@ -2396,6 +2408,10 @@
* @see #sendStickyBroadcastAsUser
*/
@Deprecated
+ @RequiresPermission(allOf = {
+ android.Manifest.permission.INTERACT_ACROSS_USERS,
+ android.Manifest.permission.BROADCAST_STICKY
+ })
public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
UserHandle user);
@@ -2562,9 +2578,7 @@
* @hide
* Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
* but for a specific user. This receiver will receiver broadcasts that
- * are sent to the requested user. It
- * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
- * permission.
+ * are sent to the requested user.
*
* @param receiver The BroadcastReceiver to handle the broadcast.
* @param user UserHandle to send the intent to.
@@ -2583,6 +2597,7 @@
* @see #unregisterReceiver
*/
@Nullable
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
@Nullable Handler scheduler);
@@ -2691,6 +2706,7 @@
* @hide like {@link #startForegroundService(Intent)} but for a specific user.
*/
@Nullable
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
/**
@@ -2728,11 +2744,13 @@
* @hide like {@link #startService(Intent)} but for a specific user.
*/
@Nullable
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
/**
* @hide like {@link #stopService(Intent)} but for a specific user.
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
/**
@@ -2792,6 +2810,7 @@
*/
@SystemApi
@SuppressWarnings("unused")
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
int flags, UserHandle user) {
throw new RuntimeException("Not implemented. Must override in a subclass.");
@@ -2803,6 +2822,7 @@
*
* @hide
*/
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
Handler handler, UserHandle user) {
throw new RuntimeException("Not implemented. Must override in a subclass.");
diff --git a/core/java/android/content/RestrictionsManager.java b/core/java/android/content/RestrictionsManager.java
index 88aae66..b463ec6 100644
--- a/core/java/android/content/RestrictionsManager.java
+++ b/core/java/android/content/RestrictionsManager.java
@@ -16,6 +16,7 @@
package android.content;
+import android.annotation.SystemService;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.pm.ApplicationInfo;
@@ -120,6 +121,7 @@
* @see DevicePolicyManager#setRestrictionsProvider(ComponentName, ComponentName)
* @see DevicePolicyManager#setApplicationRestrictions(ComponentName, String, Bundle)
*/
+@SystemService(Context.RESTRICTIONS_SERVICE)
public class RestrictionsManager {
private static final String TAG = "RestrictionsManager";
diff --git a/core/java/android/content/pm/LauncherApps.java b/core/java/android/content/pm/LauncherApps.java
index 8ead0ec..ed41e79 100644
--- a/core/java/android/content/pm/LauncherApps.java
+++ b/core/java/android/content/pm/LauncherApps.java
@@ -20,6 +20,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
+import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.TestApi;
import android.app.PendingIntent;
@@ -79,6 +80,7 @@
* Note as of Android O, apps on a managed profile are no longer allowed to access apps on the
* main profile. Apps can only access profiles returned by {@link #getProfiles()}.
*/
+@SystemService(Context.LAUNCHER_APPS_SERVICE)
public class LauncherApps {
static final String TAG = "LauncherApps";
diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java
index 4e11233..7f3f35f 100644
--- a/core/java/android/content/pm/PackageInstaller.java
+++ b/core/java/android/content/pm/PackageInstaller.java
@@ -473,6 +473,7 @@
/** {@hide} */
@SystemApi
+ @RequiresPermission(android.Manifest.permission.INSTALL_PACKAGES)
public void setPermissionsResult(int sessionId, boolean accepted) {
try {
mInstaller.setPermissionsResult(sessionId, accepted);
@@ -1156,6 +1157,7 @@
/** {@hide} */
@SystemApi
+ @RequiresPermission(android.Manifest.permission.ALLOCATE_AGGRESSIVE)
public void setAllocateAggressive(boolean allocateAggressive) {
if (allocateAggressive) {
installFlags |= PackageManager.INSTALL_ALLOCATE_AGGRESSIVE;
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index a68c097..be2cd10 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -3208,8 +3208,7 @@
/**
* Return a List of all packages that are installed on the device, for a
- * specific user. Requesting a list of installed packages for another user
- * will require the permission INTERACT_ACROSS_USERS_FULL.
+ * specific user.
*
* @param flags Additional option flags to modify the data returned.
* @param userId The user for whom the installed packages are to be listed
@@ -3224,6 +3223,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
public abstract List<PackageInfo> getInstalledPackagesAsUser(@PackageInfoFlags int flags,
@UserIdInt int userId);
@@ -3365,6 +3365,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS)
public abstract void grantRuntimePermission(@NonNull String packageName,
@NonNull String permissionName, @NonNull UserHandle user);
@@ -3390,6 +3391,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS)
public abstract void revokeRuntimePermission(@NonNull String packageName,
@NonNull String permissionName, @NonNull UserHandle user);
@@ -3404,6 +3406,10 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(anyOf = {
+ android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS,
+ android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS
+ })
public abstract @PermissionFlags int getPermissionFlags(String permissionName,
String packageName, @NonNull UserHandle user);
@@ -3420,6 +3426,10 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(anyOf = {
+ android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS,
+ android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS
+ })
public abstract void updatePermissionFlags(String permissionName,
String packageName, @PermissionFlags int flagMask, @PermissionFlags int flagValues,
@NonNull UserHandle user);
@@ -4719,6 +4729,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.INTENT_FILTER_VERIFICATION_AGENT)
public abstract void verifyIntentFilter(int verificationId, int verificationCode,
List<String> failedDomains);
@@ -4766,6 +4777,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
public abstract boolean updateIntentVerificationStatusAsUser(String packageName, int status,
@UserIdInt int userId);
@@ -4826,6 +4838,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
public abstract boolean setDefaultBrowserPackageNameAsUser(String packageName,
@UserIdInt int userId);
@@ -5289,6 +5302,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(Manifest.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS)
public abstract void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener);
/**
diff --git a/core/java/android/content/pm/ShortcutManager.java b/core/java/android/content/pm/ShortcutManager.java
index f779aeb..6cf6627 100644
--- a/core/java/android/content/pm/ShortcutManager.java
+++ b/core/java/android/content/pm/ShortcutManager.java
@@ -17,6 +17,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UserIdInt;
import android.app.Activity;
@@ -569,6 +570,7 @@
* All shortcut information is stored in credential encrypted storage, so no shortcuts can be
* accessed when the user is locked.
*/
+@SystemService(Context.SHORTCUT_SERVICE)
public class ShortcutManager {
private static final String TAG = "ShortcutManager";
diff --git a/core/java/android/hardware/ConsumerIrManager.java b/core/java/android/hardware/ConsumerIrManager.java
index b221e16..c7a33ff 100644
--- a/core/java/android/hardware/ConsumerIrManager.java
+++ b/core/java/android/hardware/ConsumerIrManager.java
@@ -16,6 +16,7 @@
package android.hardware;
+import android.annotation.SystemService;
import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -24,14 +25,8 @@
/**
* Class that operates consumer infrared on the device.
- *
- * <p>
- * To obtain an instance of the system infrared transmitter, call
- * {@link android.content.Context#getSystemService(java.lang.String)
- * Context.getSystemService()} with
- * {@link android.content.Context#CONSUMER_IR_SERVICE} as the argument.
- * </p>
*/
+@SystemService(Context.CONSUMER_IR_SERVICE)
public final class ConsumerIrManager {
private static final String TAG = "ConsumerIr";
diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java
index ed56391..4bc62b1 100644
--- a/core/java/android/hardware/SensorManager.java
+++ b/core/java/android/hardware/SensorManager.java
@@ -17,6 +17,8 @@
package android.hardware;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
+import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.MemoryFile;
@@ -30,10 +32,7 @@
/**
* <p>
* SensorManager lets you access the device's {@link android.hardware.Sensor
- * sensors}. Get an instance of this class by calling
- * {@link android.content.Context#getSystemService(java.lang.String)
- * Context.getSystemService()} with the argument
- * {@link android.content.Context#SENSOR_SERVICE}.
+ * sensors}.
* </p>
* <p>
* Always make sure to disable sensors you don't need, especially when your
@@ -79,6 +78,7 @@
* @see Sensor
*
*/
+@SystemService(Context.SENSOR_SERVICE)
public abstract class SensorManager {
/** @hide */
protected static final String TAG = "SensorManager";
diff --git a/core/java/android/hardware/SerialManager.java b/core/java/android/hardware/SerialManager.java
index 83f7649..610f6a5 100644
--- a/core/java/android/hardware/SerialManager.java
+++ b/core/java/android/hardware/SerialManager.java
@@ -16,6 +16,7 @@
package android.hardware;
+import android.annotation.SystemService;
import android.content.Context;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
@@ -25,6 +26,7 @@
/**
* @hide
*/
+@SystemService(Context.SERIAL_SERVICE)
public class SerialManager {
private static final String TAG = "SerialManager";
diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java
index f61032e..1b150bf 100644
--- a/core/java/android/hardware/camera2/CameraManager.java
+++ b/core/java/android/hardware/camera2/CameraManager.java
@@ -17,6 +17,7 @@
package android.hardware.camera2;
import android.annotation.RequiresPermission;
+import android.annotation.SystemService;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
@@ -44,15 +45,11 @@
* <p>A system service manager for detecting, characterizing, and connecting to
* {@link CameraDevice CameraDevices}.</p>
*
- * <p>You can get an instance of this class by calling
- * {@link android.content.Context#getSystemService(String) Context.getSystemService()}.</p>
- *
- * <pre>CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);</pre>
- *
* <p>For more details about communicating with camera devices, read the Camera
* developer guide or the {@link android.hardware.camera2 camera2}
* package documentation.</p>
*/
+@SystemService(Context.CAMERA_SERVICE)
public final class CameraManager {
private static final String TAG = "CameraManager";
diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java
index 266be9a..6a02b6b 100644
--- a/core/java/android/hardware/display/DisplayManager.java
+++ b/core/java/android/hardware/display/DisplayManager.java
@@ -18,6 +18,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemService;
import android.content.Context;
import android.media.projection.MediaProjection;
import android.os.Handler;
@@ -29,13 +30,8 @@
/**
* Manages the properties of attached displays.
- * <p>
- * Get an instance of this class by calling
- * {@link android.content.Context#getSystemService(java.lang.String)
- * Context.getSystemService()} with the argument
- * {@link android.content.Context#DISPLAY_SERVICE}.
- * </p>
*/
+@SystemService(Context.DISPLAY_SERVICE)
public final class DisplayManager {
private static final String TAG = "DisplayManager";
private static final boolean DEBUG = false;
diff --git a/core/java/android/hardware/fingerprint/FingerprintManager.java b/core/java/android/hardware/fingerprint/FingerprintManager.java
index 324a08c..b51a791 100644
--- a/core/java/android/hardware/fingerprint/FingerprintManager.java
+++ b/core/java/android/hardware/fingerprint/FingerprintManager.java
@@ -19,6 +19,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
+import android.annotation.SystemService;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Binder;
@@ -47,12 +48,8 @@
/**
* A class that coordinates access to the fingerprint hardware.
- * <p>
- * Use {@link android.content.Context#getSystemService(java.lang.String)}
- * with argument {@link android.content.Context#FINGERPRINT_SERVICE} to get
- * an instance of this class.
*/
-
+@SystemService(Context.FINGERPRINT_SERVICE)
public class FingerprintManager {
private static final String TAG = "FingerprintManager";
private static final boolean DEBUG = true;
diff --git a/core/java/android/hardware/hdmi/HdmiControlManager.java b/core/java/android/hardware/hdmi/HdmiControlManager.java
index 27e2a50..1371351 100644
--- a/core/java/android/hardware/hdmi/HdmiControlManager.java
+++ b/core/java/android/hardware/hdmi/HdmiControlManager.java
@@ -19,7 +19,9 @@
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
+import android.content.Context;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.os.RemoteException;
import android.util.ArrayMap;
import android.util.Log;
@@ -37,6 +39,7 @@
* @hide
*/
@SystemApi
+@SystemService(Context.HDMI_CONTROL_SERVICE)
public final class HdmiControlManager {
private static final String TAG = "HdmiControlManager";
diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java
index 631b77d..5149e93 100644
--- a/core/java/android/hardware/input/InputManager.java
+++ b/core/java/android/hardware/input/InputManager.java
@@ -21,6 +21,7 @@
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
+import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
import android.media.AudioAttributes;
@@ -53,13 +54,8 @@
/**
* Provides information about input devices and available key layouts.
- * <p>
- * Get an instance of this class by calling
- * {@link android.content.Context#getSystemService(java.lang.String)
- * Context.getSystemService()} with the argument
- * {@link android.content.Context#INPUT_SERVICE}.
- * </p>
*/
+@SystemService(Context.INPUT_SERVICE)
public final class InputManager {
private static final String TAG = "InputManager";
private static final boolean DEBUG = false;
diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java
index 7c4df47..6050046 100644
--- a/core/java/android/hardware/location/ContextHubManager.java
+++ b/core/java/android/hardware/location/ContextHubManager.java
@@ -15,7 +15,10 @@
*/
package android.hardware.location;
+import android.annotation.RequiresPermission;
+import android.annotation.SuppressLint;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
@@ -33,6 +36,7 @@
* @hide
*/
@SystemApi
+@SystemService(Context.CONTEXTHUB_SERVICE)
public final class ContextHubManager {
private static final String TAG = "ContextHubManager";
@@ -91,6 +95,7 @@
* Get a handle to all the context hubs in the system
* @return array of context hub handles
*/
+ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public int[] getContextHubHandles() {
try {
return mService.getContextHubHandles();
@@ -107,6 +112,7 @@
*
* @see ContextHubInfo
*/
+ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public ContextHubInfo getContextHubInfo(int hubHandle) {
try {
return mService.getContextHubInfo(hubHandle);
@@ -134,6 +140,7 @@
*
* @see NanoApp
*/
+ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public int loadNanoApp(int hubHandle, NanoApp app) {
try {
return mService.loadNanoApp(hubHandle, app);
@@ -157,6 +164,7 @@
* @return 0 if the command for unloading was sent to the context hub;
* -1 otherwise
*/
+ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public int unloadNanoApp(int nanoAppHandle) {
try {
return mService.unloadNanoApp(nanoAppHandle);
@@ -191,6 +199,7 @@
*
* @see NanoAppInstanceInfo
*/
+ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public NanoAppInstanceInfo getNanoAppInstanceInfo(int nanoAppHandle) {
try {
return mService.getNanoAppInstanceInfo(nanoAppHandle);
@@ -209,6 +218,7 @@
*
* @return int[] Array of handles to any found nano apps
*/
+ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public int[] findNanoAppOnHub(int hubHandle, NanoAppFilter filter) {
try {
return mService.findNanoAppOnHub(hubHandle, filter);
@@ -236,6 +246,7 @@
*
* @return int 0 on success, -1 otherwise
*/
+ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public int sendMessage(int hubHandle, int nanoAppHandle, ContextHubMessage message) {
try {
return mService.sendMessage(hubHandle, nanoAppHandle, message);
@@ -253,6 +264,7 @@
*
* @return int 0 on success, -1 otherwise
*/
+ @SuppressLint("Doclava125")
public int registerCallback(Callback callback) {
return registerCallback(callback, null);
}
@@ -281,6 +293,7 @@
*
* @return int 0 on success, -1 otherwise
*/
+ @SuppressLint("Doclava125")
public int registerCallback(Callback callback, Handler handler) {
synchronized(this) {
if (mCallback != null) {
@@ -302,6 +315,7 @@
*
* @return int 0 on success, -1 otherwise
*/
+ @SuppressLint("Doclava125")
public int unregisterCallback(Callback callback) {
synchronized(this) {
if (callback != mCallback) {
diff --git a/core/java/android/hardware/radio/RadioManager.java b/core/java/android/hardware/radio/RadioManager.java
index 14bb923..403b13c 100644
--- a/core/java/android/hardware/radio/RadioManager.java
+++ b/core/java/android/hardware/radio/RadioManager.java
@@ -17,6 +17,7 @@
package android.hardware.radio;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.content.Context;
import android.os.Handler;
import android.os.Parcel;
@@ -32,6 +33,7 @@
* @hide
*/
@SystemApi
+@SystemService(Context.RADIO_SERVICE)
public class RadioManager {
/** Method return status: successful operation */
diff --git a/core/java/android/hardware/usb/UsbManager.java b/core/java/android/hardware/usb/UsbManager.java
index b2a2aaf..33a92fd 100644
--- a/core/java/android/hardware/usb/UsbManager.java
+++ b/core/java/android/hardware/usb/UsbManager.java
@@ -19,6 +19,7 @@
import android.annotation.Nullable;
import android.annotation.SdkConstant;
+import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.PendingIntent;
import android.content.ComponentName;
@@ -38,18 +39,13 @@
* This class allows you to access the state of USB and communicate with USB devices.
* Currently only host mode is supported in the public API.
*
- * <p>You can obtain an instance of this class by calling
- * {@link android.content.Context#getSystemService(java.lang.String) Context.getSystemService()}.
- *
- * {@samplecode
- * UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);}
- *
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For more information about communicating with USB hardware, read the
* <a href="{@docRoot}guide/topics/connectivity/usb/index.html">USB developer guide</a>.</p>
* </div>
*/
+@SystemService(Context.USB_SERVICE)
public class UsbManager {
private static final String TAG = "UsbManager";
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index b0cc38c..e64cbcd 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -23,6 +23,7 @@
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -64,9 +65,7 @@
/**
* Class that answers queries about the state of network connectivity. It also
- * notifies applications when network connectivity changes. Get an instance
- * of this class by calling
- * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.CONNECTIVITY_SERVICE)}.
+ * notifies applications when network connectivity changes.
* <p>
* The primary responsibilities of this class are to:
* <ol>
@@ -80,6 +79,7 @@
* traffic</li>
* </ol>
*/
+@SystemService(Context.CONNECTIVITY_SERVICE)
public class ConnectivityManager {
private static final String TAG = "ConnectivityManager";
@@ -2105,6 +2105,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void startTethering(int type, boolean showProvisioningUi,
final OnStartTetheringCallback callback, Handler handler) {
checkNotNull(callback, "OnStartTetheringCallback cannot be null.");
@@ -2139,6 +2140,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void stopTethering(int type) {
try {
mService.stopTethering(type);
diff --git a/core/java/android/net/EthernetManager.java b/core/java/android/net/EthernetManager.java
index 664b7b4..31a3096 100644
--- a/core/java/android/net/EthernetManager.java
+++ b/core/java/android/net/EthernetManager.java
@@ -16,6 +16,7 @@
package android.net;
+import android.annotation.SystemService;
import android.content.Context;
import android.net.IEthernetManager;
import android.net.IEthernetServiceListener;
@@ -31,6 +32,7 @@
*
* @hide
*/
+@SystemService(Context.ETHERNET_SERVICE)
public class EthernetManager {
private static final String TAG = "EthernetManager";
private static final int MSG_AVAILABILITY_CHANGED = 1000;
diff --git a/core/java/android/net/IpSecManager.java b/core/java/android/net/IpSecManager.java
index 114e46e..e3cda5e 100644
--- a/core/java/android/net/IpSecManager.java
+++ b/core/java/android/net/IpSecManager.java
@@ -18,6 +18,8 @@
import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.NonNull;
+import android.annotation.SystemService;
+import android.content.Context;
import android.os.Binder;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
@@ -34,12 +36,9 @@
* This class contains methods for managing IPsec sessions, which will perform kernel-space
* encryption and decryption of socket or Network traffic.
*
- * <p>An IpSecManager may be obtained by calling {@link
- * android.content.Context#getSystemService(String) Context#getSystemService(String)} with {@link
- * android.content.Context#IPSEC_SERVICE Context#IPSEC_SERVICE}
- *
* @hide
*/
+@SystemService(Context.IPSEC_SERVICE)
public final class IpSecManager {
private static final String TAG = "IpSecManager";
diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java
index 43fab03..4d94a55 100644
--- a/core/java/android/net/NetworkPolicyManager.java
+++ b/core/java/android/net/NetworkPolicyManager.java
@@ -19,6 +19,7 @@
import static android.content.pm.PackageManager.GET_SIGNATURES;
import static android.net.NetworkPolicy.CYCLE_NONE;
+import android.annotation.SystemService;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
@@ -40,6 +41,7 @@
*
* {@hide}
*/
+@SystemService(Context.NETWORK_POLICY_SERVICE)
public class NetworkPolicyManager {
/* POLICY_* are masks and can be ORed, although currently they are not.*/
diff --git a/core/java/android/net/NetworkScoreManager.java b/core/java/android/net/NetworkScoreManager.java
index 9f6e45c..7e0c9ce 100644
--- a/core/java/android/net/NetworkScoreManager.java
+++ b/core/java/android/net/NetworkScoreManager.java
@@ -19,9 +19,11 @@
import android.Manifest.permission;
import android.annotation.IntDef;
import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -34,12 +36,6 @@
/**
* Class that manages communication between network subsystems and a network scorer.
*
- * <p>You can get an instance of this class by calling
- * {@link android.content.Context#getSystemService(String)}:
- *
- * <pre>NetworkScoreManager manager =
- * (NetworkScoreManager) getSystemService(Context.NETWORK_SCORE_SERVICE)</pre>
- *
* <p>A network scorer is any application which:
* <ul>
* <li>Declares the {@link permission#SCORE_NETWORKS} permission.
@@ -51,6 +47,7 @@
* @hide
*/
@SystemApi
+@SystemService(Context.NETWORK_SCORE_SERVICE)
public class NetworkScoreManager {
/**
* Activity action: ask the user to change the active network scorer. This will show a dialog
@@ -243,6 +240,7 @@
* @hide
*/
@Nullable
+ @RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES)
public NetworkScorerAppData getActiveScorer() {
try {
return mService.getActiveScorer();
@@ -276,6 +274,7 @@
* @return whether the update was successful.
* @throws SecurityException if the caller is not the active scorer.
*/
+ @RequiresPermission(android.Manifest.permission.SCORE_NETWORKS)
public boolean updateScores(ScoredNetwork[] networks) throws SecurityException {
try {
return mService.updateScores(networks);
@@ -296,6 +295,7 @@
* @return whether the clear was successful.
* @throws SecurityException if the caller is not the active scorer or privileged.
*/
+ @RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES)
public boolean clearScores() throws SecurityException {
try {
return mService.clearScores();
@@ -316,6 +316,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.SCORE_NETWORKS)
public boolean setActiveScorer(String packageName) throws SecurityException {
try {
return mService.setActiveScorer(packageName);
@@ -331,6 +332,7 @@
*
* @throws SecurityException if the caller is neither the active scorer nor the system.
*/
+ @RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES)
public void disableScoring() throws SecurityException {
try {
mService.disableScoring();
diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java
index fc66395..f934616 100644
--- a/core/java/android/net/TrafficStats.java
+++ b/core/java/android/net/TrafficStats.java
@@ -16,6 +16,7 @@
package android.net;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.app.DownloadManager;
import android.app.backup.BackupManager;
@@ -243,6 +244,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS)
public static void setThreadStatsUid(int uid) {
NetworkManagementSocketTagger.setThreadSocketStatsUid(uid);
}
@@ -255,6 +257,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS)
public static void clearThreadStatsUid() {
NetworkManagementSocketTagger.setThreadSocketStatsUid(-1);
}
diff --git a/core/java/android/net/VpnService.java b/core/java/android/net/VpnService.java
index c6daa15..2d9860c 100644
--- a/core/java/android/net/VpnService.java
+++ b/core/java/android/net/VpnService.java
@@ -19,6 +19,7 @@
import static android.system.OsConstants.AF_INET;
import static android.system.OsConstants.AF_INET6;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.app.Activity;
import android.app.PendingIntent;
@@ -177,6 +178,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.CONTROL_VPN)
public static void prepareAndAuthorize(Context context) {
IConnectivityManager cm = getService();
String packageName = context.getPackageName();
diff --git a/core/java/android/net/nsd/NsdManager.java b/core/java/android/net/nsd/NsdManager.java
index 1dde3ca..2d480a1 100644
--- a/core/java/android/net/nsd/NsdManager.java
+++ b/core/java/android/net/nsd/NsdManager.java
@@ -17,6 +17,7 @@
package android.net.nsd;
import android.annotation.SdkConstant;
+import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
import android.os.Handler;
@@ -113,11 +114,9 @@
* http://www.iana.org/form/ports-service. Existing services can be found at
* http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml
*
- * Get an instance of this class by calling {@link android.content.Context#getSystemService(String)
- * Context.getSystemService(Context.NSD_SERVICE)}.
- *
* {@see NsdServiceInfo}
*/
+@SystemService(Context.NSD_SERVICE)
public final class NsdManager {
private static final String TAG = NsdManager.class.getSimpleName();
private static final boolean DBG = false;
diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java
index 783c25a..48869c7 100644
--- a/core/java/android/nfc/NfcAdapter.java
+++ b/core/java/android/nfc/NfcAdapter.java
@@ -18,6 +18,7 @@
import java.util.HashMap;
+import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
@@ -725,6 +726,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
public boolean enable() {
try {
return sService.enable();
@@ -753,6 +755,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
public boolean disable() {
try {
return sService.disable(true);
@@ -767,6 +770,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
public boolean disable(boolean persist) {
try {
return sService.disable(persist);
@@ -1552,6 +1556,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
public boolean enableNdefPush() {
if (!sHasNfcFeature) {
throw new UnsupportedOperationException();
@@ -1570,6 +1575,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
public boolean disableNdefPush() {
synchronized (NfcAdapter.class) {
if (!sHasNfcFeature) {
@@ -1736,6 +1742,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
public boolean addNfcUnlockHandler(final NfcUnlockHandler unlockHandler,
String[] tagTechnologies) {
synchronized (NfcAdapter.class) {
@@ -1785,6 +1792,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
public boolean removeNfcUnlockHandler(NfcUnlockHandler unlockHandler) {
synchronized (NfcAdapter.class) {
if (!sHasNfcFeature) {
diff --git a/core/java/android/nfc/NfcManager.java b/core/java/android/nfc/NfcManager.java
index ea08014..50d6745 100644
--- a/core/java/android/nfc/NfcManager.java
+++ b/core/java/android/nfc/NfcManager.java
@@ -16,6 +16,7 @@
package android.nfc;
+import android.annotation.SystemService;
import android.content.Context;
/**
@@ -34,9 +35,9 @@
* <a href="{@docRoot}guide/topics/nfc/index.html">Near Field Communication</a> developer guide.</p>
* </div>
*
- * @see Context#getSystemService
* @see NfcAdapter#getDefaultAdapter(android.content.Context)
*/
+@SystemService(Context.NFC_SERVICE)
public final class NfcManager {
private final NfcAdapter mAdapter;
diff --git a/core/java/android/os/BatteryManager.java b/core/java/android/os/BatteryManager.java
index 734d89e..f715f50 100644
--- a/core/java/android/os/BatteryManager.java
+++ b/core/java/android/os/BatteryManager.java
@@ -16,6 +16,8 @@
package android.os;
+import android.annotation.SystemService;
+import android.content.Context;
import android.hardware.health.V1_0.Constants;
import com.android.internal.app.IBatteryStats;
@@ -24,6 +26,7 @@
* in the {@link android.content.Intent#ACTION_BATTERY_CHANGED} Intent, and
* provides a method for querying battery and charging properties.
*/
+@SystemService(Context.BATTERY_SERVICE)
public class BatteryManager {
/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
diff --git a/core/java/android/os/DropBoxManager.java b/core/java/android/os/DropBoxManager.java
index db84b6f..97f0e0c 100644
--- a/core/java/android/os/DropBoxManager.java
+++ b/core/java/android/os/DropBoxManager.java
@@ -17,6 +17,7 @@
package android.os;
import android.annotation.SdkConstant;
+import android.annotation.SystemService;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
import android.util.Log;
@@ -36,13 +37,10 @@
* enqueued data exceeds the maximum size. You can think of this as a
* persistent, system-wide, blob-oriented "logcat".
*
- * <p>You can obtain an instance of this class by calling
- * {@link android.content.Context#getSystemService}
- * with {@link android.content.Context#DROPBOX_SERVICE}.
- *
* <p>DropBoxManager entries are not sent anywhere directly, but other system
* services and debugging tools may scan and upload entries for processing.
*/
+@SystemService(Context.DROPBOX_SERVICE)
public class DropBoxManager {
private static final String TAG = "DropBoxManager";
diff --git a/core/java/android/os/HardwarePropertiesManager.java b/core/java/android/os/HardwarePropertiesManager.java
index 67edefc..aad202e 100644
--- a/core/java/android/os/HardwarePropertiesManager.java
+++ b/core/java/android/os/HardwarePropertiesManager.java
@@ -17,6 +17,7 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
+import android.annotation.SystemService;
import android.content.Context;
import android.hardware.thermal.V1_0.Constants;
import android.util.Log;
@@ -28,6 +29,7 @@
* The HardwarePropertiesManager class provides a mechanism of accessing hardware state of a
* device: CPU, GPU and battery temperatures, CPU usage per core, fan speed, etc.
*/
+@SystemService(Context.HARDWARE_PROPERTIES_SERVICE)
public class HardwarePropertiesManager {
private static final String TAG = HardwarePropertiesManager.class.getSimpleName();
diff --git a/core/java/android/os/IncidentManager.java b/core/java/android/os/IncidentManager.java
index 976d594..bc8e2e4 100644
--- a/core/java/android/os/IncidentManager.java
+++ b/core/java/android/os/IncidentManager.java
@@ -16,7 +16,9 @@
package android.os;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.annotation.TestApi;
import android.content.Context;
import android.os.IIncidentManager;
@@ -31,6 +33,7 @@
*/
@SystemApi
@TestApi
+@SystemService(Context.INCIDENT_SERVICE)
public class IncidentManager {
private static final String TAG = "incident";
@@ -46,6 +49,10 @@
/**
* Take an incident report and put it in dropbox.
*/
+ @RequiresPermission(allOf = {
+ android.Manifest.permission.DUMP,
+ android.Manifest.permission.PACKAGE_USAGE_STATS
+ })
public void reportIncident(IncidentReportArgs args) {
final IIncidentManager service = IIncidentManager.Stub.asInterface(
ServiceManager.getService("incident"));
@@ -76,6 +83,10 @@
* {@link android.util.proto.ProtoOutputStream#bytes bytes()} method to retrieve
* the encoded data for the header.
*/
+ @RequiresPermission(allOf = {
+ android.Manifest.permission.DUMP,
+ android.Manifest.permission.PACKAGE_USAGE_STATS
+ })
public void reportIncident(String settingName, byte[] headerProto) {
// Sections
String setting = Settings.System.getString(mContext.getContentResolver(), settingName);
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index 7d1369f..a85ed9c 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -17,8 +17,10 @@
package android.os;
import android.annotation.IntDef;
+import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.content.Context;
import android.util.Log;
import java.lang.annotation.Retention;
@@ -32,9 +34,6 @@
* Do not acquire {@link WakeLock}s unless you really need them, use the minimum levels
* possible, and be sure to release them as soon as possible.
* </p><p>
- * You can obtain an instance of this class by calling
- * {@link android.content.Context#getSystemService(java.lang.String) Context.getSystemService()}.
- * </p><p>
* The primary API you'll use is {@link #newWakeLock(int, String) newWakeLock()}.
* This will create a {@link PowerManager.WakeLock} object. You can then use methods
* on the wake lock object to control the power state of the device.
@@ -102,6 +101,7 @@
* permission in an {@code <uses-permission>} element of the application's manifest.
* </p>
*/
+@SystemService(Context.POWER_SERVICE)
public final class PowerManager {
private static final String TAG = "PowerManager";
@@ -689,6 +689,10 @@
* @hide Requires signature or system permission.
*/
@SystemApi
+ @RequiresPermission(anyOf = {
+ android.Manifest.permission.DEVICE_POWER,
+ android.Manifest.permission.USER_ACTIVITY
+ })
public void userActivity(long when, int event, int flags) {
try {
mService.userActivity(when, event, flags);
diff --git a/core/java/android/os/RecoverySystem.java b/core/java/android/os/RecoverySystem.java
index d2598c7..ba339a3 100644
--- a/core/java/android/os/RecoverySystem.java
+++ b/core/java/android/os/RecoverySystem.java
@@ -18,7 +18,10 @@
import static java.nio.charset.StandardCharsets.UTF_8;
+import android.annotation.RequiresPermission;
+import android.annotation.SuppressLint;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -67,6 +70,7 @@
* recovery system (the separate partition that can be used to install
* system updates, wipe user data, etc.)
*/
+@SystemService(Context.RECOVERY_SERVICE)
public class RecoverySystem {
private static final String TAG = "RecoverySystem";
@@ -387,6 +391,7 @@
* {@hide}
*/
@SystemApi
+ @SuppressLint("Doclava125")
public static boolean verifyPackageCompatibility(File compatibilityFile) throws IOException {
try (InputStream inputStream = new FileInputStream(compatibilityFile)) {
return verifyPackageCompatibility(inputStream);
@@ -409,6 +414,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.RECOVERY)
public static void processPackage(Context context,
File packageFile,
final ProgressListener listener,
@@ -469,6 +475,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.RECOVERY)
public static void processPackage(Context context,
File packageFile,
final ProgressListener listener)
@@ -490,6 +497,7 @@
* @throws IOException if writing the recovery command file
* fails, or if the reboot itself fails.
*/
+ @RequiresPermission(android.Manifest.permission.RECOVERY)
public static void installPackage(Context context, File packageFile)
throws IOException {
installPackage(context, packageFile, false);
@@ -511,6 +519,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.RECOVERY)
public static void installPackage(Context context, File packageFile, boolean processed)
throws IOException {
synchronized (sRequestLock) {
@@ -602,6 +611,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.RECOVERY)
public static void scheduleUpdateOnBoot(Context context, File packageFile)
throws IOException {
String filename = packageFile.getCanonicalPath();
@@ -639,6 +649,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.RECOVERY)
public static void cancelScheduledUpdate(Context context)
throws IOException {
RecoverySystem rs = (RecoverySystem) context.getSystemService(Context.RECOVERY_SERVICE);
@@ -777,6 +788,10 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(allOf = {
+ android.Manifest.permission.RECOVERY,
+ android.Manifest.permission.REBOOT
+ })
public static void rebootWipeAb(Context context, File packageFile, String reason)
throws IOException {
String reasonArg = null;
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 7bd3bf6..a7fc2e7 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -23,6 +23,7 @@
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UserIdInt;
import android.annotation.WorkerThread;
@@ -63,6 +64,7 @@
* <p>
* See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles.
*/
+@SystemService(Context.USER_SERVICE)
public class UserManager {
private static final String TAG = "UserManager";
@@ -1038,12 +1040,12 @@
/**
* Checks if the calling app is running in a managed profile.
- * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
*
* @return whether the caller is in a managed profile.
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
public boolean isManagedProfile() {
// No need for synchronization. Once it becomes non-null, it'll be non-null forever.
// Worst case we might end up calling the AIDL method multiple times but that's fine.
@@ -1067,6 +1069,7 @@
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
public boolean isManagedProfile(@UserIdInt int userId) {
if (userId == UserHandle.myUserId()) {
return isManagedProfile();
@@ -1252,7 +1255,6 @@
* @hide
*
* Returns who set a user restriction on a user.
- * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @param restrictionKey the string key representing the restriction
* @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
* @return The source of user restriction. Any combination of {@link #RESTRICTION_NOT_SET},
@@ -1263,6 +1265,7 @@
@Deprecated
@SystemApi
@UserRestrictionSource
+ @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
public int getUserRestrictionSource(String restrictionKey, UserHandle userHandle) {
try {
return mService.getUserRestrictionSource(restrictionKey, userHandle.getIdentifier());
@@ -1275,12 +1278,12 @@
* @hide
*
* Returns a list of users who set a user restriction on a given user.
- * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
* @param restrictionKey the string key representing the restriction
* @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
* @return a list of user ids enforcing this restriction.
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
public List<EnforcingUser> getUserRestrictionSources(
String restrictionKey, UserHandle userHandle) {
try {
@@ -1622,9 +1625,10 @@
/**
* @hide
*
- * Returns the preferred account name for user creation. Requires MANAGE_USERS permission.
+ * Returns the preferred account name for user creation.
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
public String getSeedAccountName() {
try {
return mService.getSeedAccountName();
@@ -1636,9 +1640,10 @@
/**
* @hide
*
- * Returns the preferred account type for user creation. Requires MANAGE_USERS permission.
+ * Returns the preferred account type for user creation.
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
public String getSeedAccountType() {
try {
return mService.getSeedAccountType();
@@ -1650,11 +1655,11 @@
/**
* @hide
*
- * Returns the preferred account's options bundle for user creation. Requires MANAGE_USERS
- * permission.
+ * Returns the preferred account's options bundle for user creation.
* @return Any options set by the requestor that created the user.
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
public PersistableBundle getSeedAccountOptions() {
try {
return mService.getSeedAccountOptions();
@@ -1686,9 +1691,10 @@
/**
* @hide
- * Clears the seed information used to create this user. Requires MANAGE_USERS permission.
+ * Clears the seed information used to create this user.
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
public void clearSeedAccountData() {
try {
mService.clearSeedAccountData();
@@ -1771,13 +1777,13 @@
/**
* Returns serial numbers of all users on this device.
- * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
*
* @param excludeDying specify if the list should exclude users being removed.
* @return the list of serial numbers of users that exist on the device.
* @hide
*/
@SystemApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
public long[] getSerialNumbersOfUsers(boolean excludeDying) {
try {
List<UserInfo> users = mService.getUsers(excludeDying);
diff --git a/core/java/android/os/Vibrator.java b/core/java/android/os/Vibrator.java
index 2f0eeca..8078fb8 100644
--- a/core/java/android/os/Vibrator.java
+++ b/core/java/android/os/Vibrator.java
@@ -17,6 +17,7 @@
package android.os;
import android.annotation.RequiresPermission;
+import android.annotation.SystemService;
import android.app.ActivityThread;
import android.content.Context;
import android.media.AudioAttributes;
@@ -27,10 +28,8 @@
* <p>
* If your process exits, any vibration you started will stop.
* </p>
- *
- * To obtain an instance of the system vibrator, call
- * {@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as the argument.
*/
+@SystemService(Context.VIBRATOR_SERVICE)
public abstract class Vibrator {
private static final String TAG = "Vibrator";
diff --git a/core/java/android/os/health/SystemHealthManager.java b/core/java/android/os/health/SystemHealthManager.java
index 7c0af25..bba4cd1 100644
--- a/core/java/android/os/health/SystemHealthManager.java
+++ b/core/java/android/os/health/SystemHealthManager.java
@@ -16,6 +16,7 @@
package android.os.health;
+import android.annotation.SystemService;
import android.content.Context;
import android.os.BatteryStats;
import android.os.Process;
@@ -40,6 +41,7 @@
* JobScheduler}), and while that can affect charging rates, it is still preferable
* to actually draining the battery.
*/
+@SystemService(Context.SYSTEM_HEALTH_SERVICE)
public class SystemHealthManager {
private final IBatteryStats mBatteryStats;
diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java
index d81ee4e..d13ccf7 100644
--- a/core/java/android/os/storage/StorageManager.java
+++ b/core/java/android/os/storage/StorageManager.java
@@ -26,6 +26,7 @@
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.annotation.WorkerThread;
import android.app.ActivityThread;
import android.content.ContentResolver;
@@ -98,11 +99,8 @@
* guarantee the security of the OBB file itself: if any program modifies the
* OBB, there is no guarantee that a read from that OBB will produce the
* expected output.
- * <p>
- * Get an instance of this class by calling
- * {@link android.content.Context#getSystemService(java.lang.String)} with an
- * argument of {@link android.content.Context#STORAGE_SERVICE}.
*/
+@SystemService(Context.STORAGE_SERVICE)
public class StorageManager {
private static final String TAG = "StorageManager";
@@ -1701,8 +1699,8 @@
/** @hide */
@SystemApi
- public long getAllocatableBytes(@NonNull UUID storageUuid, @AllocateFlags int flags)
- throws IOException {
+ public long getAllocatableBytes(@NonNull UUID storageUuid,
+ @RequiresPermission @AllocateFlags int flags) throws IOException {
try {
return mStorageManager.getAllocatableBytes(convert(storageUuid), flags);
} catch (ParcelableException e) {
@@ -1715,8 +1713,8 @@
/** @removed */
@Deprecated
- public long getAllocatableBytes(@NonNull File path, @AllocateFlags int flags)
- throws IOException {
+ public long getAllocatableBytes(@NonNull File path,
+ @RequiresPermission @AllocateFlags int flags) throws IOException {
return getAllocatableBytes(getUuidForPath(path), flags);
}
@@ -1750,7 +1748,7 @@
/** @hide */
@SystemApi
public void allocateBytes(@NonNull UUID storageUuid, @BytesLong long bytes,
- @AllocateFlags int flags) throws IOException {
+ @RequiresPermission @AllocateFlags int flags) throws IOException {
try {
mStorageManager.allocateBytes(convert(storageUuid), bytes, flags);
} catch (ParcelableException e) {
@@ -1762,8 +1760,8 @@
/** @removed */
@Deprecated
- public void allocateBytes(@NonNull File path, @BytesLong long bytes, @AllocateFlags int flags)
- throws IOException {
+ public void allocateBytes(@NonNull File path, @BytesLong long bytes,
+ @RequiresPermission @AllocateFlags int flags) throws IOException {
allocateBytes(getUuidForPath(path), bytes, flags);
}
@@ -1798,8 +1796,8 @@
/** @hide */
@SystemApi
- public void allocateBytes(FileDescriptor fd, @BytesLong long bytes, @AllocateFlags int flags)
- throws IOException {
+ public void allocateBytes(FileDescriptor fd, @BytesLong long bytes,
+ @RequiresPermission @AllocateFlags int flags) throws IOException {
final File file = ParcelFileDescriptor.getFile(fd);
for (int i = 0; i < 3; i++) {
try {
diff --git a/core/java/android/print/PrintManager.java b/core/java/android/print/PrintManager.java
index 8ee0517..e8ff2e2 100644
--- a/core/java/android/print/PrintManager.java
+++ b/core/java/android/print/PrintManager.java
@@ -19,6 +19,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.app.Activity;
import android.app.Application.ActivityLifecycleCallbacks;
import android.content.ComponentName;
@@ -57,14 +58,6 @@
/**
* System level service for accessing the printing capabilities of the platform.
- * <p>
- * To obtain a handle to the print manager do the following:
- * </p>
- *
- * <pre>
- * PrintManager printManager =
- * (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
- * </pre>
*
* <h3>Print mechanics</h3>
* <p>
@@ -109,6 +102,7 @@
* @see PrintJob
* @see PrintJobInfo
*/
+@SystemService(Context.PRINT_SERVICE)
public final class PrintManager {
private static final String LOG_TAG = "PrintManager";
diff --git a/core/java/android/service/oemlock/OemLockManager.java b/core/java/android/service/oemlock/OemLockManager.java
index c4fbe5e..e2ade87 100644
--- a/core/java/android/service/oemlock/OemLockManager.java
+++ b/core/java/android/service/oemlock/OemLockManager.java
@@ -17,7 +17,10 @@
package android.service.oemlock;
import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
+import android.content.Context;
import android.os.RemoteException;
/**
@@ -31,6 +34,7 @@
* @hide
*/
@SystemApi
+@SystemService(Context.OEM_LOCK_SERVICE)
public class OemLockManager {
private IOemLockService mService;
@@ -55,6 +59,7 @@
*
* @see #isOemUnlockAllowedByCarrier()
*/
+ @RequiresPermission(android.Manifest.permission.MANAGE_CARRIER_OEM_UNLOCK_STATE)
public void setOemUnlockAllowedByCarrier(boolean allowed, @Nullable byte[] signature) {
try {
mService.setOemUnlockAllowedByCarrier(allowed, signature);
@@ -69,6 +74,7 @@
*
* @see #setOemUnlockAllowedByCarrier(boolean, byte[])
*/
+ @RequiresPermission(android.Manifest.permission.MANAGE_CARRIER_OEM_UNLOCK_STATE)
public boolean isOemUnlockAllowedByCarrier() {
try {
return mService.isOemUnlockAllowedByCarrier();
@@ -86,6 +92,7 @@
*
* @see #isOemUnlockAllowedByUser()
*/
+ @RequiresPermission(android.Manifest.permission.MANAGE_USER_OEM_UNLOCK_STATE)
public void setOemUnlockAllowedByUser(boolean allowed) {
try {
mService.setOemUnlockAllowedByUser(allowed);
@@ -100,6 +107,7 @@
*
* @see #setOemUnlockAllowedByUser(boolean)
*/
+ @RequiresPermission(android.Manifest.permission.MANAGE_USER_OEM_UNLOCK_STATE)
public boolean isOemUnlockAllowedByUser() {
try {
return mService.isOemUnlockAllowedByUser();
diff --git a/core/java/android/service/persistentdata/PersistentDataBlockManager.java b/core/java/android/service/persistentdata/PersistentDataBlockManager.java
index 326796a..fa75ad3 100644
--- a/core/java/android/service/persistentdata/PersistentDataBlockManager.java
+++ b/core/java/android/service/persistentdata/PersistentDataBlockManager.java
@@ -16,10 +16,14 @@
package android.service.persistentdata;
-import android.annotation.SystemApi;
import android.annotation.IntDef;
+import android.annotation.RequiresPermission;
+import android.annotation.SuppressLint;
+import android.annotation.SystemApi;
+import android.annotation.SystemService;
+import android.content.Context;
import android.os.RemoteException;
-import android.util.Slog;
+import android.service.oemlock.OemLockManager;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -43,6 +47,7 @@
* @hide
*/
@SystemApi
+@SystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE)
public class PersistentDataBlockManager {
private static final String TAG = PersistentDataBlockManager.class.getSimpleName();
private IPersistentDataBlockService sService;
@@ -85,6 +90,7 @@
*
* @param data the data to write
*/
+ @SuppressLint("Doclava125")
public int write(byte[] data) {
try {
return sService.write(data);
@@ -96,6 +102,7 @@
/**
* Returns the data block stored on the persistent partition.
*/
+ @SuppressLint("Doclava125")
public byte[] read() {
try {
return sService.read();
@@ -109,6 +116,7 @@
*
* Return -1 on error.
*/
+ @RequiresPermission(android.Manifest.permission.ACCESS_PDB_STATE)
public int getDataBlockSize() {
try {
return sService.getDataBlockSize();
@@ -136,6 +144,7 @@
* It will also prevent any further {@link #write} operation until reboot,
* in order to prevent a potential race condition. See b/30352311.
*/
+ @RequiresPermission(android.Manifest.permission.OEM_UNLOCK_STATE)
public void wipe() {
try {
sService.wipe();
@@ -149,6 +158,7 @@
*
* @deprecated use {@link OemLockManager#setOemUnlockAllowedByUser(boolean)} instead.
*/
+ @RequiresPermission(android.Manifest.permission.OEM_UNLOCK_STATE)
public void setOemUnlockEnabled(boolean enabled) {
try {
sService.setOemUnlockEnabled(enabled);
@@ -162,6 +172,10 @@
*
* @deprecated use {@link OemLockManager#isOemUnlockAllowedByUser()} instead.
*/
+ @RequiresPermission(anyOf = {
+ android.Manifest.permission.READ_OEM_UNLOCK_STATE,
+ android.Manifest.permission.OEM_UNLOCK_STATE
+ })
public boolean getOemUnlockEnabled() {
try {
return sService.getOemUnlockEnabled();
@@ -177,6 +191,10 @@
* {@link #FLASH_LOCK_UNLOCKED} if device bootloader is unlocked, or {@link #FLASH_LOCK_UNKNOWN}
* if this information cannot be ascertained on this device.
*/
+ @RequiresPermission(anyOf = {
+ android.Manifest.permission.READ_OEM_UNLOCK_STATE,
+ android.Manifest.permission.OEM_UNLOCK_STATE
+ })
@FlashLockState
public int getFlashLockState() {
try {
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java
index ad46d07..47b8d92 100644
--- a/core/java/android/view/LayoutInflater.java
+++ b/core/java/android/view/LayoutInflater.java
@@ -18,6 +18,7 @@
import android.annotation.LayoutRes;
import android.annotation.Nullable;
+import android.annotation.SystemService;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -47,10 +48,7 @@
* {@link android.app.Activity#getLayoutInflater()} or
* {@link Context#getSystemService} to retrieve a standard LayoutInflater instance
* that is already hooked up to the current context and correctly configured
- * for the device you are running on. For example:
- *
- * <pre>LayoutInflater inflater = (LayoutInflater)context.getSystemService
- * (Context.LAYOUT_INFLATER_SERVICE);</pre>
+ * for the device you are running on.
*
* <p>
* To create a new LayoutInflater with an additional {@link Factory} for your
@@ -64,9 +62,8 @@
* to use LayoutInflater with an XmlPullParser over a plain XML file at runtime;
* it only works with an XmlPullParser returned from a compiled resource
* (R.<em>something</em> file.)
- *
- * @see Context#getSystemService
*/
+@SystemService(Context.LAYOUT_INFLATER_SERVICE)
public abstract class LayoutInflater {
private static final String TAG = LayoutInflater.class.getSimpleName();
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 3dd8d2a..4060b9a 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -19,6 +19,7 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.KeyguardManager;
import android.app.Presentation;
@@ -39,8 +40,6 @@
/**
* The interface that apps use to talk to the window manager.
- * <p>
- * Use <code>Context.getSystemService(Context.WINDOW_SERVICE)</code> to get one of these.
* </p><p>
* Each window manager instance is bound to a particular {@link Display}.
* To obtain a {@link WindowManager} for a different display, use
@@ -52,10 +51,8 @@
* {@link Presentation}. The presentation will automatically obtain a
* {@link WindowManager} and {@link Context} for that display.
* </p>
- *
- * @see android.content.Context#getSystemService
- * @see android.content.Context#WINDOW_SERVICE
*/
+@SystemService(Context.WINDOW_SERVICE)
public interface WindowManager extends ViewManager {
/** @hide */
diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java
index 7eb7bd9..41a8b8a 100644
--- a/core/java/android/view/accessibility/AccessibilityManager.java
+++ b/core/java/android/view/accessibility/AccessibilityManager.java
@@ -24,6 +24,7 @@
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
+import android.annotation.SystemService;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -59,15 +60,6 @@
* {@link android.view.View} changes etc. Parties interested in handling accessibility
* events implement and register an accessibility service which extends
* {@link android.accessibilityservice.AccessibilityService}.
- * <p>
- * To obtain a handle to the accessibility manager do the following:
- * </p>
- * <p>
- * <code>
- * <pre>AccessibilityManager accessibilityManager =
- * (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);</pre>
- * </code>
- * </p>
*
* @see AccessibilityEvent
* @see AccessibilityNodeInfo
@@ -75,6 +67,7 @@
* @see Context#getSystemService
* @see Context#ACCESSIBILITY_SERVICE
*/
+@SystemService(Context.ACCESSIBILITY_SERVICE)
public final class AccessibilityManager {
private static final boolean DEBUG = false;
diff --git a/core/java/android/view/accessibility/CaptioningManager.java b/core/java/android/view/accessibility/CaptioningManager.java
index 14f0b0a..d6455e7 100644
--- a/core/java/android/view/accessibility/CaptioningManager.java
+++ b/core/java/android/view/accessibility/CaptioningManager.java
@@ -18,6 +18,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemService;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -34,14 +35,8 @@
/**
* Contains methods for accessing and monitoring preferred video captioning state and visual
* properties.
- * <p>
- * To obtain a handle to the captioning manager, do the following:
- * <p>
- * <code>
- * <pre>CaptioningManager captioningManager =
- * (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE);</pre>
- * </code>
*/
+@SystemService(Context.CAPTIONING_SERVICE)
public class CaptioningManager {
/** Default captioning enabled value. */
private static final int DEFAULT_ENABLED = 0;
diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java
index 02ecc50..310ec1c 100644
--- a/core/java/android/view/autofill/AutofillManager.java
+++ b/core/java/android/view/autofill/AutofillManager.java
@@ -23,6 +23,7 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemService;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
@@ -55,6 +56,7 @@
*
* <p>It is safe to call into this from any thread.
*/
+@SystemService(Context.AUTOFILL_MANAGER_SERVICE)
public final class AutofillManager {
private static final String TAG = "AutofillManager";
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index da9316c..e2f7979 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -21,6 +21,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
+import android.annotation.SystemService;
import android.content.Context;
import android.graphics.Rect;
import android.net.Uri;
@@ -73,8 +74,6 @@
/**
* Central system API to the overall input method framework (IMF) architecture,
* which arbitrates interaction between applications and the current input method.
- * You can retrieve an instance of this interface with
- * {@link Context#getSystemService(String) Context.getSystemService()}.
*
* <p>Topics covered here:
* <ol>
@@ -211,6 +210,7 @@
* and want to make it available for use.</p>
* </ul>
*/
+@SystemService(Context.INPUT_METHOD_SERVICE)
public final class InputMethodManager {
static final boolean DEBUG = false;
static final String TAG = "InputMethodManager";
diff --git a/core/java/android/view/textclassifier/TextClassificationManager.java b/core/java/android/view/textclassifier/TextClassificationManager.java
index 6b641db..efc88e2 100644
--- a/core/java/android/view/textclassifier/TextClassificationManager.java
+++ b/core/java/android/view/textclassifier/TextClassificationManager.java
@@ -18,6 +18,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemService;
import android.content.Context;
import android.os.ParcelFileDescriptor;
import android.util.Log;
@@ -33,10 +34,8 @@
/**
* Interface to the text classification service.
- *
- * <p>You do not instantiate this class directly; instead, retrieve it through
- * {@link android.content.Context#getSystemService}.
*/
+@SystemService(Context.TEXT_CLASSIFICATION_SERVICE)
public final class TextClassificationManager {
private static final String LOG_TAG = "TextClassificationManager";
diff --git a/core/java/android/view/textservice/TextServicesManager.java b/core/java/android/view/textservice/TextServicesManager.java
index b4e6c56..d9bfade 100644
--- a/core/java/android/view/textservice/TextServicesManager.java
+++ b/core/java/android/view/textservice/TextServicesManager.java
@@ -16,6 +16,7 @@
package android.view.textservice;
+import android.annotation.SystemService;
import android.content.Context;
import android.os.Bundle;
import android.os.RemoteException;
@@ -30,8 +31,7 @@
/**
* System API to the overall text services, which arbitrates interaction between applications
- * and text services. You can retrieve an instance of this interface with
- * {@link Context#getSystemService(String) Context.getSystemService()}.
+ * and text services.
*
* The user can change the current text services in Settings. And also applications can specify
* the target text services.
@@ -61,6 +61,7 @@
* </ul>
*
*/
+@SystemService(Context.TEXT_SERVICES_MANAGER_SERVICE)
public final class TextServicesManager {
private static final String TAG = TextServicesManager.class.getSimpleName();
private static final boolean DBG = false;