From d86b8fea43ebb6e5c31691b44d8ceb0d8d3c9072 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 2 Jun 2017 17:36:26 -0600 Subject: [PATCH] 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 --- core/java/android/accounts/AccountManager.java | 3 + core/java/android/annotation/SystemService.java | 37 ++++++++++++ core/java/android/app/ActivityManager.java | 8 +++ core/java/android/app/AlarmManager.java | 7 +-- core/java/android/app/AppOpsManager.java | 8 ++- core/java/android/app/BroadcastOptions.java | 2 + core/java/android/app/DownloadManager.java | 10 ++-- core/java/android/app/KeyguardManager.java | 6 +- core/java/android/app/Notification.java | 3 + core/java/android/app/NotificationManager.java | 10 +--- core/java/android/app/SearchManager.java | 9 +-- core/java/android/app/StatusBarManager.java | 2 + core/java/android/app/UiModeManager.java | 6 +- core/java/android/app/VrManager.java | 13 ++--- core/java/android/app/WallpaperManager.java | 13 +++-- .../android/app/admin/DevicePolicyManager.java | 16 ++++-- core/java/android/app/backup/BackupManager.java | 39 ++++++------- core/java/android/app/job/JobScheduler.java | 5 ++ core/java/android/app/trust/TrustManager.java | 3 + .../android/app/usage/NetworkStatsManager.java | 2 + .../android/app/usage/StorageStatsManager.java | 2 + core/java/android/app/usage/UsageStatsManager.java | 5 +- core/java/android/appwidget/AppWidgetManager.java | 2 + core/java/android/bluetooth/BluetoothManager.java | 2 + .../android/companion/CompanionDeviceManager.java | 2 + core/java/android/content/ClipboardManager.java | 8 +-- core/java/android/content/Context.java | 66 ++++++++++++++-------- core/java/android/content/RestrictionsManager.java | 2 + core/java/android/content/pm/LauncherApps.java | 2 + core/java/android/content/pm/PackageInstaller.java | 2 + core/java/android/content/pm/PackageManager.java | 18 +++++- core/java/android/content/pm/ShortcutManager.java | 2 + core/java/android/hardware/ConsumerIrManager.java | 9 +-- core/java/android/hardware/SensorManager.java | 8 +-- core/java/android/hardware/SerialManager.java | 2 + .../android/hardware/camera2/CameraManager.java | 7 +-- .../android/hardware/display/DisplayManager.java | 8 +-- .../hardware/fingerprint/FingerprintManager.java | 7 +-- .../android/hardware/hdmi/HdmiControlManager.java | 3 + core/java/android/hardware/input/InputManager.java | 8 +-- .../hardware/location/ContextHubManager.java | 14 +++++ core/java/android/hardware/radio/RadioManager.java | 2 + core/java/android/hardware/usb/UsbManager.java | 8 +-- core/java/android/net/ConnectivityManager.java | 8 ++- core/java/android/net/EthernetManager.java | 2 + core/java/android/net/IpSecManager.java | 7 +-- core/java/android/net/NetworkPolicyManager.java | 2 + core/java/android/net/NetworkScoreManager.java | 14 +++-- core/java/android/net/TrafficStats.java | 3 + core/java/android/net/VpnService.java | 2 + core/java/android/net/nsd/NsdManager.java | 5 +- core/java/android/nfc/NfcAdapter.java | 8 +++ core/java/android/nfc/NfcManager.java | 3 +- core/java/android/os/BatteryManager.java | 3 + core/java/android/os/DropBoxManager.java | 6 +- .../java/android/os/HardwarePropertiesManager.java | 2 + core/java/android/os/IncidentManager.java | 11 ++++ core/java/android/os/PowerManager.java | 10 +++- core/java/android/os/RecoverySystem.java | 15 +++++ core/java/android/os/UserManager.java | 24 +++++--- core/java/android/os/Vibrator.java | 5 +- .../android/os/health/SystemHealthManager.java | 2 + core/java/android/os/storage/StorageManager.java | 24 ++++---- core/java/android/print/PrintManager.java | 10 +--- .../android/service/oemlock/OemLockManager.java | 8 +++ .../persistentdata/PersistentDataBlockManager.java | 22 +++++++- core/java/android/view/LayoutInflater.java | 9 +-- core/java/android/view/WindowManager.java | 7 +-- .../view/accessibility/AccessibilityManager.java | 11 +--- .../view/accessibility/CaptioningManager.java | 9 +-- .../android/view/autofill/AutofillManager.java | 2 + .../view/inputmethod/InputMethodManager.java | 4 +- .../textclassifier/TextClassificationManager.java | 5 +- .../view/textservice/TextServicesManager.java | 5 +- .../java/android/location/CountryDetector.java | 7 +-- .../java/android/location/LocationManager.java | 15 ++--- media/java/android/media/AudioManager.java | 8 ++- media/java/android/media/MediaRouter.java | 2 + media/java/android/media/midi/MidiManager.java | 9 +-- .../media/projection/MediaProjectionManager.java | 9 +-- .../android/media/session/MediaSessionManager.java | 8 ++- .../media/soundtrigger/SoundTriggerDetector.java | 3 + .../media/soundtrigger/SoundTriggerManager.java | 7 +++ media/java/android/media/tv/TvInputManager.java | 9 ++- telecomm/java/android/telecom/TelecomManager.java | 3 + .../android/telephony/CarrierConfigManager.java | 13 ++--- telephony/java/android/telephony/SmsManager.java | 3 + .../android/telephony/SubscriptionManager.java | 5 +- .../java/android/telephony/TelephonyManager.java | 37 +++++++++--- wifi/java/android/net/wifi/RttManager.java | 10 +++- wifi/java/android/net/wifi/WifiManager.java | 45 +++++++++------ wifi/java/android/net/wifi/WifiScanner.java | 20 ++++++- .../android/net/wifi/aware/WifiAwareManager.java | 6 +- wifi/java/android/net/wifi/p2p/WifiP2pManager.java | 5 +- 94 files changed, 549 insertions(+), 314 deletions(-) create mode 100644 core/java/android/annotation/SystemService.java diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java index 8fd8043a772a..8e4b9150b755 100644 --- a/core/java/android/accounts/AccountManager.java +++ b/core/java/android/accounts/AccountManager.java @@ -24,6 +24,7 @@ import android.annotation.RequiresPermission; 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 @@ import java.util.concurrent.TimeoutException; * 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 @@ public class AccountManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public AccountManagerFuture 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 000000000000..ba5002a4f1b5 --- /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 369968f3c33b..f398c8dc9d6a 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -22,6 +22,7 @@ import android.annotation.NonNull; 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 @@ import java.util.List; * be used for testing and debugging purposes only. *

*/ +@SystemService(Context.ACTIVITY_SERVICE) public class ActivityManager { private static String TAG = "ActivityManager"; @@ -3610,6 +3612,7 @@ public class ActivityManager { * @hide */ @SystemApi @TestApi + @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS) public void addOnUidImportanceListener(OnUidImportanceListener listener, @RunningAppProcessInfo.Importance int importanceCutpoint) { synchronized (this) { @@ -3638,6 +3641,7 @@ public class ActivityManager { * @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 @@ public class ActivityManager { * @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 620e5cf374ca..d497db0a0023 100644 --- a/core/java/android/app/AlarmManager.java +++ b/core/java/android/app/AlarmManager.java @@ -19,6 +19,7 @@ package android.app; 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 @@ import java.lang.annotation.RetentionPolicy; * {@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. - * - *

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 82921524457f..e672ada3cbb4 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 @@ import java.util.List; * API for interacting with "application operation" tracking. * *

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}.

+ * features are only available to system applications. */ +@SystemService(Context.APP_OPS_SERVICE) public class AppOpsManager { /** *

App ops allows callers to:

@@ -1409,6 +1410,7 @@ public class AppOpsManager { * @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 175b9799c5db..b6cff385d752 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 @@ public class BroadcastOptions { * 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 b89c16539b4c..5baaeb30e233 100644 --- a/core/java/android/app/DownloadManager.java +++ b/core/java/android/app/DownloadManager.java @@ -19,6 +19,7 @@ package android.app; 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 @@ import java.util.List; * 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}. - * + *

* 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. - * + *

* 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 fcf0aab0c821..2a29616aab76 100644 --- a/core/java/android/app/KeyguardManager.java +++ b/core/java/android/app/KeyguardManager.java @@ -20,6 +20,7 @@ import android.Manifest; 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 com.android.internal.policy.IKeyguardDismissCallback; 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 31f52dbea548..ad6b45476c4b 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -22,6 +22,7 @@ import android.annotation.ColorInt; 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 @@ public class Notification implements Parcelable * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; /** @@ -1110,6 +1112,7 @@ public class Notification implements Parcelable /** @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 6c55548c2ea4..235b8d445b1c 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -20,6 +20,7 @@ import android.annotation.IntDef; 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 @@ import java.util.Objects; * to the {@link #cancel(int)} or {@link #cancel(String, int)} method to clear * this notification. * - *

- * You do not instantiate this class directly; instead, retrieve it through - * {@link android.content.Context#getSystemService}. - * *

*

Developer Guides

*

For a guide to creating notifications, read the @@ -93,10 +90,9 @@ import java.util.Objects; *

* * @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 c529e4ba1678..ea990ad2924e 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 @@ import java.util.List; * 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)}. * *
*

Developer Guides

@@ -58,9 +55,9 @@ import java.util.List; * Search developer guide.

*
*/ +@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 e57a9b5231e3..fb8bd3951ed7 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 @@ import java.lang.annotation.RetentionPolicy; * * @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 07e257083fa2..bc616686eced 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 @@ import java.lang.annotation.RetentionPolicy; * 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. - * - *

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 8014ecafa9a2..b40c96c6f0c8 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. - *

- * 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 @@ public class VrManager { * 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. * - *

Requires {@link android.Manifest.permission#ACCESS_VR_MANAGER} permission.

- * * @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 @@ public class VrManager { * Sets the resolution and DPI of the vr2d virtual display used to display 2D * applications in VR mode. * - *

Requires {@link android.Manifest.permission#ACCESS_VR_MANAGER} permission.

- * * @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 db2f937e2ef2..a8504237e82b 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -18,8 +18,10 @@ package android.app; 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 @@ import java.util.concurrent.TimeUnit; /** * 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. * *

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 @@ public class WallpaperManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_HINTS) public void setDisplayPadding(Rect padding) { try { if (sGlobals.mService == null) { @@ -1395,6 +1398,7 @@ public class WallpaperManager { * @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 @@ public class WallpaperManager { * @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 @@ public class WallpaperManager { /** * 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 9ae5d1c86842..b6c6f5b0c035 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -20,9 +20,12 @@ import android.annotation.ColorInt; 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 @@ import java.util.Set; * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration developer * guide. */ +@SystemService(Context.DEVICE_POLICY_SERVICE) public class DevicePolicyManager { private static String TAG = "DevicePolicyManager"; @@ -4653,6 +4657,7 @@ public class DevicePolicyManager { */ @Deprecated @SystemApi + @SuppressLint("Doclava125") public @Nullable String getDeviceInitializerApp() { return null; } @@ -4664,6 +4669,7 @@ public class DevicePolicyManager { */ @Deprecated @SystemApi + @SuppressLint("Doclava125") public @Nullable ComponentName getDeviceInitializerComponent() { return null; } @@ -4686,6 +4692,7 @@ public class DevicePolicyManager { */ @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 @@ public class DevicePolicyManager { * 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 @@ public class DevicePolicyManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.NOTIFY_PENDING_SYSTEM_UPDATE) public void notifyPendingSystemUpdate(long updateReceivedTime) { throwIfParentInstance("notifyPendingSystemUpdate"); if (mService != null) { @@ -6800,8 +6807,7 @@ public class DevicePolicyManager { * 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 @@ public class DevicePolicyManager { * @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 @@ public class DevicePolicyManager { * @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 9d02f53b13bd..9f9b217069d8 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 @@ public class BackupManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.BACKUP) public RestoreSession beginRestoreSession() { RestoreSession session = null; checkServiceBinder(); @@ -348,11 +350,10 @@ public class BackupManager { * mechanism was disabled will still be backed up properly if it is enabled * at some point in the future. * - *

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 @@ public class BackupManager { /** * Report whether the backup mechanism is currently enabled. * - *

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 @@ public class BackupManager { * the archival restore dataset (if any). When disabled, no such attempt will * be made. * - *

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 @@ public class BackupManager { } /** - * 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 @@ public class BackupManager { } /** - * 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 @@ public class BackupManager { /** * Specify the current backup transport. * - *

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 @@ public class BackupManager { */ @Deprecated @SystemApi + @RequiresPermission(android.Manifest.permission.BACKUP) public String selectBackupTransport(String transport) { checkServiceBinder(); if (sService != null) { @@ -479,8 +477,6 @@ public class BackupManager { * This method is async because BackupManager might need to bind to the specified transport * which is in a separate process. * - *

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 @@ public class BackupManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.BACKUP) public void selectBackupTransport(ComponentName transport, SelectBackupTransportCallback listener) { checkServiceBinder(); @@ -510,11 +507,10 @@ public class BackupManager { * transport will still be asked to confirm via the usual requestBackupTime() * method. * - *

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 @@ public class BackupManager { * Ask the framework which dataset, if any, the given package's data would be * restored from if we were to install it right now. * - *

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 @@ public class BackupManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.BACKUP) public long getAvailableRestoreToken(String packageName) { checkServiceBinder(); if (sService != null) { @@ -555,14 +550,13 @@ public class BackupManager { /** * Ask the framework whether this app is eligible for backup. * - *

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 @@ public class BackupManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.BACKUP) public int requestBackup(String[] packages, BackupObserver observer) { return requestBackup(packages, observer, null, 0); } @@ -615,6 +610,7 @@ public class BackupManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.BACKUP) public int requestBackup(String[] packages, BackupObserver observer, BackupManagerMonitor monitor, int flags) { checkServiceBinder(); @@ -638,11 +634,10 @@ public class BackupManager { * Cancel all running backups. After this call returns, no currently running backups will * interact with the selected transport. * - *

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 1768828eb76c..3868439f092f 100644 --- a/core/java/android/app/job/JobScheduler.java +++ b/core/java/android/app/job/JobScheduler.java @@ -19,8 +19,11 @@ package android.app.job; 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 @@ import java.util.List; * {@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 @@ public abstract class JobScheduler { * @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 06b0aacd8654..54a7e5caa270 100644 --- a/core/java/android/app/trust/TrustManager.java +++ b/core/java/android/app/trust/TrustManager.java @@ -18,6 +18,8 @@ package android.app.trust; 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 @@ import com.android.internal.widget.LockPatternUtils; * 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 6cd4e92383b2..ef262e046021 100644 --- a/core/java/android/app/usage/NetworkStatsManager.java +++ b/core/java/android/app/usage/NetworkStatsManager.java @@ -19,6 +19,7 @@ package android.app.usage; 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 @@ import android.util.Log; * 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 0b2b1900c4e0..7c680794d140 100644 --- a/core/java/android/app/usage/StorageStatsManager.java +++ b/core/java/android/app/usage/StorageStatsManager.java @@ -20,6 +20,7 @@ import static android.os.storage.StorageManager.convert; 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 @@ import java.util.UUID; * application. *

*/ +@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 75a4a535186e..1f939f996c68 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 @@ import java.util.Map; * 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 @@ public final class UsageStatsManager { * 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 @@ public final class UsageStatsManager { * @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 6327f34ebd5e..969b19ee48ac 100644 --- a/core/java/android/appwidget/AppWidgetManager.java +++ b/core/java/android/appwidget/AppWidgetManager.java @@ -20,6 +20,7 @@ import android.annotation.BroadcastBehavior; 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 @@ import java.util.List; * App Widgets developer guide.

* */ +@SystemService(Context.APPWIDGET_SERVICE) public class AppWidgetManager { /** diff --git a/core/java/android/bluetooth/BluetoothManager.java b/core/java/android/bluetooth/BluetoothManager.java index c7191ba2638b..e2fa38a9309f 100644 --- a/core/java/android/bluetooth/BluetoothManager.java +++ b/core/java/android/bluetooth/BluetoothManager.java @@ -18,6 +18,7 @@ package android.bluetooth; 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 @@ import java.util.List; * @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 4e70e3fe8ce5..dabe608c038f 100644 --- a/core/java/android/companion/CompanionDeviceManager.java +++ b/core/java/android/companion/CompanionDeviceManager.java @@ -21,6 +21,7 @@ import static com.android.internal.util.Preconditions.checkNotNull; 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 @@ import java.util.List; * * @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 f1c2f342eb3e..718e465bf0de 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 @@ import java.util.ArrayList; * the global clipboard. * *

- * You do not instantiate this class directly; instead, retrieve it through - * {@link android.content.Context#getSystemService}. - * - *

* 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 @@ import java.util.ArrayList; * Copy and Paste * developer guide.

* - * - * @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 10594afc7f9d..db80c7259179 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -1630,13 +1630,13 @@ public abstract class Context { /** * 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 @@ public abstract class Context { /** * 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 @@ public abstract class Context { * @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 @@ public abstract class Context { * @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 @@ public abstract class Context { /** * 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 @@ public abstract class Context { * * @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 @@ public abstract class Context { * @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 @@ public abstract class Context { * * @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 @@ public abstract class Context { * {@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. * *

See {@link BroadcastReceiver} for more information on Intent broadcasts. * @@ -2181,6 +2181,7 @@ public abstract class Context { * * @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 @@ public abstract class Context { * 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 @@ public abstract class Context { * 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 @@ public abstract class Context { /** *

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 @@ public abstract class Context { * @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 @@ public abstract class Context { * 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 @@ public abstract class Context { * {@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. * *

See {@link BroadcastReceiver} for more information on Intent broadcasts. * @@ -2369,6 +2378,10 @@ public abstract class Context { * @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 @@ public abstract class Context { /** *

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. * *

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 @@ public abstract class Context { * @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 @@ public abstract class Context { * @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 @@ public abstract class Context { * @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 @@ public abstract class Context { * @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 @@ public abstract class Context { * @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 @@ public abstract class Context { */ @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 @@ public abstract class Context { * * @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 88aae6655428..b463ec6277e7 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 @@ import java.util.List; * @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 8ead0ec612f8..ed41e79e2c6c 100644 --- a/core/java/android/content/pm/LauncherApps.java +++ b/core/java/android/content/pm/LauncherApps.java @@ -20,6 +20,7 @@ import android.annotation.IntDef; 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 @@ import java.util.List; * 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 4e112331a1ed..7f3f35ffd4f3 100644 --- a/core/java/android/content/pm/PackageInstaller.java +++ b/core/java/android/content/pm/PackageInstaller.java @@ -473,6 +473,7 @@ public class PackageInstaller { /** {@hide} */ @SystemApi + @RequiresPermission(android.Manifest.permission.INSTALL_PACKAGES) public void setPermissionsResult(int sessionId, boolean accepted) { try { mInstaller.setPermissionsResult(sessionId, accepted); @@ -1156,6 +1157,7 @@ public class PackageInstaller { /** {@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 a68c0973b473..be2cd107fcbf 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -3208,8 +3208,7 @@ public abstract class PackageManager { /** * 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 @@ public abstract class PackageManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public abstract List getInstalledPackagesAsUser(@PackageInfoFlags int flags, @UserIdInt int userId); @@ -3365,6 +3365,7 @@ public abstract class PackageManager { * @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 @@ public abstract class PackageManager { * @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 @@ public abstract class PackageManager { * @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 @@ public abstract class PackageManager { * @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 @@ public abstract class PackageManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.INTENT_FILTER_VERIFICATION_AGENT) public abstract void verifyIntentFilter(int verificationId, int verificationCode, List failedDomains); @@ -4766,6 +4777,7 @@ public abstract class PackageManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS) public abstract boolean updateIntentVerificationStatusAsUser(String packageName, int status, @UserIdInt int userId); @@ -4826,6 +4838,7 @@ public abstract class PackageManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS) public abstract boolean setDefaultBrowserPackageNameAsUser(String packageName, @UserIdInt int userId); @@ -5289,6 +5302,7 @@ public abstract class PackageManager { * @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 f779aeb879e2..6cf6627f7941 100644 --- a/core/java/android/content/pm/ShortcutManager.java +++ b/core/java/android/content/pm/ShortcutManager.java @@ -17,6 +17,7 @@ package android.content.pm; 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 @@ import java.util.List; * 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 b221e1604949..c7a33ffa1b0f 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 @@ import android.util.Log; /** * Class that operates consumer infrared on the device. - * - *

- * 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. - *

*/ +@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 ed563914a46e..4bc62b1d04d3 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 @@ import java.util.List; /** *

* 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}. *

*

* Always make sure to disable sensors you don't need, especially when your @@ -79,6 +78,7 @@ import java.util.List; * @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 83f7649ff326..610f6a587e51 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 @@ import java.io.IOException; /** * @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 f61032ef8250..1b150bfca63a 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 @@ import java.util.ArrayList; *

A system service manager for detecting, characterizing, and connecting to * {@link CameraDevice CameraDevices}.

* - *

You can get an instance of this class by calling - * {@link android.content.Context#getSystemService(String) Context.getSystemService()}.

- * - *
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
- * *

For more details about communicating with camera devices, read the Camera * developer guide or the {@link android.hardware.camera2 camera2} * package documentation.

*/ +@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 266be9a1dd0f..6a02b6b2e6e7 100644 --- a/core/java/android/hardware/display/DisplayManager.java +++ b/core/java/android/hardware/display/DisplayManager.java @@ -18,6 +18,7 @@ package android.hardware.display; 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 @@ import java.util.ArrayList; /** * Manages the properties of attached displays. - *

- * 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}. - *

*/ +@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 324a08ca9e1b..b51a7919e3bf 100644 --- a/core/java/android/hardware/fingerprint/FingerprintManager.java +++ b/core/java/android/hardware/fingerprint/FingerprintManager.java @@ -19,6 +19,7 @@ package android.hardware.fingerprint; 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 @@ import static android.Manifest.permission.USE_FINGERPRINT; /** * A class that coordinates access to the fingerprint hardware. - *

- * 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 27e2a5072287..1371351cc8ff 100644 --- a/core/java/android/hardware/hdmi/HdmiControlManager.java +++ b/core/java/android/hardware/hdmi/HdmiControlManager.java @@ -19,7 +19,9 @@ package android.hardware.hdmi; 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 @@ import android.util.Log; * @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 631b77d4132c..5149e930d94a 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -21,6 +21,7 @@ import com.android.internal.os.SomeArgs; 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 @@ import java.util.List; /** * Provides information about input devices and available key layouts. - *

- * 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}. - *

*/ +@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 7c4df473a9da..60500463d82e 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 @@ import android.util.Log; * @hide */ @SystemApi +@SystemService(Context.CONTEXTHUB_SERVICE) public final class ContextHubManager { private static final String TAG = "ContextHubManager"; @@ -91,6 +95,7 @@ public final class ContextHubManager { * 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 @@ public final class ContextHubManager { * * @see ContextHubInfo */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public ContextHubInfo getContextHubInfo(int hubHandle) { try { return mService.getContextHubInfo(hubHandle); @@ -134,6 +140,7 @@ public final class ContextHubManager { * * @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 @@ public final class ContextHubManager { * @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 @@ public final class ContextHubManager { * * @see NanoAppInstanceInfo */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public NanoAppInstanceInfo getNanoAppInstanceInfo(int nanoAppHandle) { try { return mService.getNanoAppInstanceInfo(nanoAppHandle); @@ -209,6 +218,7 @@ public final class ContextHubManager { * * @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 @@ public final class ContextHubManager { * * @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 @@ public final class ContextHubManager { * * @return int 0 on success, -1 otherwise */ + @SuppressLint("Doclava125") public int registerCallback(Callback callback) { return registerCallback(callback, null); } @@ -281,6 +293,7 @@ public final class ContextHubManager { * * @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 @@ public final class ContextHubManager { * * @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 14bb923767ed..403b13c0a3df 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 @@ import java.util.Arrays; * @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 b2a2aafac6da..33a92fd769f3 100644 --- a/core/java/android/hardware/usb/UsbManager.java +++ b/core/java/android/hardware/usb/UsbManager.java @@ -19,6 +19,7 @@ package android.hardware.usb; 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 @@ import java.util.HashMap; * 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. * - *

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);} - * *

*

Developer Guides

*

For more information about communicating with USB hardware, read the * USB developer guide.

*
*/ +@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 b0cc38c2cf3e..e64cbcd5ade8 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -23,6 +23,7 @@ import android.annotation.RequiresPermission; 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 @@ import java.util.concurrent.atomic.AtomicInteger; /** * 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. *

* The primary responsibilities of this class are to: *

    @@ -80,6 +79,7 @@ import java.util.concurrent.atomic.AtomicInteger; * traffic *
*/ +@SystemService(Context.CONNECTIVITY_SERVICE) public class ConnectivityManager { private static final String TAG = "ConnectivityManager"; @@ -2105,6 +2105,7 @@ public class ConnectivityManager { * @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 @@ public class ConnectivityManager { * @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 664b7b408975..31a30968cbcd 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 @@ import java.util.ArrayList; * * @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 114e46e54fe7..e3cda5e7d85d 100644 --- a/core/java/android/net/IpSecManager.java +++ b/core/java/android/net/IpSecManager.java @@ -18,6 +18,8 @@ package android.net; 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 @@ import java.net.Socket; * This class contains methods for managing IPsec sessions, which will perform kernel-space * encryption and decryption of socket or Network traffic. * - *

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 43fab037f254..4d94a55cd0c4 100644 --- a/core/java/android/net/NetworkPolicyManager.java +++ b/core/java/android/net/NetworkPolicyManager.java @@ -19,6 +19,7 @@ package android.net; 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 @@ import java.util.TimeZone; * * {@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 9f6e45ca6fb5..7e0c9ce33b82 100644 --- a/core/java/android/net/NetworkScoreManager.java +++ b/core/java/android/net/NetworkScoreManager.java @@ -19,9 +19,11 @@ package android.net; 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 @@ import java.util.List; /** * Class that manages communication between network subsystems and a network scorer. * - *

You can get an instance of this class by calling - * {@link android.content.Context#getSystemService(String)}: - * - *

NetworkScoreManager manager =
- *     (NetworkScoreManager) getSystemService(Context.NETWORK_SCORE_SERVICE)
- * *

A network scorer is any application which: *

*/ +@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 6b641dbfef8e..efc88e23fa67 100644 --- a/core/java/android/view/textclassifier/TextClassificationManager.java +++ b/core/java/android/view/textclassifier/TextClassificationManager.java @@ -18,6 +18,7 @@ package android.view.textclassifier; 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 @@ import java.util.Locale; /** * Interface to the text classification service. - * - *

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 b4e6c5699007..d9bfade33539 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 @@ import java.util.Locale; /** * 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 @@ import java.util.Locale; * * */ +@SystemService(Context.TEXT_SERVICES_MANAGER_SERVICE) public final class TextServicesManager { private static final String TAG = TextServicesManager.class.getSimpleName(); private static final boolean DBG = false; diff --git a/location/java/android/location/CountryDetector.java b/location/java/android/location/CountryDetector.java index ce3c56f73c01..ec6dfb713b10 100644 --- a/location/java/android/location/CountryDetector.java +++ b/location/java/android/location/CountryDetector.java @@ -18,6 +18,8 @@ package android.location; import java.util.HashMap; +import android.annotation.SystemService; +import android.content.Context; import android.os.Handler; import android.os.Looper; import android.os.RemoteException; @@ -40,13 +42,10 @@ import android.util.Log; * To be notified of the future country change, use the * {@link #addCountryListener} *

- *

- * You do not instantiate this class directly; instead, retrieve it through - * {@link android.content.Context#getSystemService - * Context.getSystemService(Context.COUNTRY_DETECTOR)}. * * @hide */ +@SystemService(Context.COUNTRY_DETECTOR) public class CountryDetector { /** diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index f9385c6d3b7f..4ab8543b7f6a 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -20,7 +20,9 @@ import com.android.internal.location.ProviderProperties; import android.Manifest; import android.annotation.RequiresPermission; +import android.annotation.SuppressLint; import android.annotation.SystemApi; +import android.annotation.SystemService; import android.annotation.TestApi; import android.app.PendingIntent; import android.content.Context; @@ -47,11 +49,6 @@ import static android.Manifest.permission.ACCESS_FINE_LOCATION; * {@link Intent} when the device enters the proximity of a given * geographical location. * - *

You do not - * instantiate this class directly; instead, retrieve it through - * {@link android.content.Context#getSystemService - * Context.getSystemService(Context.LOCATION_SERVICE)}. - * *

Unless noted, all Location API methods require * the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} or * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permissions. @@ -60,8 +57,8 @@ import static android.Manifest.permission.ACCESS_FINE_LOCATION; * return location results, but the update rate will be throttled and the exact * location will be obfuscated to a coarse level of accuracy. */ -public class LocationManager -{ +@SystemService(Context.LOCATION_SERVICE) +public class LocationManager { private static final String TAG = "LocationManager"; private final Context mContext; @@ -1820,6 +1817,7 @@ public class LocationManager */ @Deprecated @SystemApi + @SuppressLint("Doclava125") public boolean addGpsMeasurementListener(GpsMeasurementsEvent.Listener listener) { return false; } @@ -1857,6 +1855,7 @@ public class LocationManager */ @Deprecated @SystemApi + @SuppressLint("Doclava125") public void removeGpsMeasurementListener(GpsMeasurementsEvent.Listener listener) { } @@ -1877,6 +1876,7 @@ public class LocationManager */ @Deprecated @SystemApi + @SuppressLint("Doclava125") public boolean addGpsNavigationMessageListener(GpsNavigationMessageEvent.Listener listener) { return false; } @@ -1891,6 +1891,7 @@ public class LocationManager */ @Deprecated @SystemApi + @SuppressLint("Doclava125") public void removeGpsNavigationMessageListener(GpsNavigationMessageEvent.Listener listener) { } diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 0b5dff227d23..20deeb1634c8 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -19,9 +19,11 @@ package android.media; import android.Manifest; import android.annotation.NonNull; 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.app.NotificationManager; import android.app.PendingIntent; import android.bluetooth.BluetoothDevice; @@ -58,10 +60,8 @@ import java.util.concurrent.ConcurrentHashMap; /** * AudioManager provides access to volume and ringer mode control. - *

- * Use Context.getSystemService(Context.AUDIO_SERVICE) to get - * an instance of this class. */ +@SystemService(Context.AUDIO_SERVICE) public class AudioManager { private Context mOriginalContext; @@ -2827,6 +2827,7 @@ public class AudioManager { * {@link #SUCCESS} otherwise. */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public int registerAudioPolicy(@NonNull AudioPolicy policy) { if (policy == null) { throw new IllegalArgumentException("Illegal null AudioPolicy argument"); @@ -2852,6 +2853,7 @@ public class AudioManager { * @param policy the non-null {@link AudioPolicy} to unregister. */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public void unregisterAudioPolicyAsync(@NonNull AudioPolicy policy) { if (policy == null) { throw new IllegalArgumentException("Illegal null AudioPolicy argument"); diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java index 44494a644178..91dada7f1066 100644 --- a/media/java/android/media/MediaRouter.java +++ b/media/java/android/media/MediaRouter.java @@ -20,6 +20,7 @@ import android.Manifest; import android.annotation.DrawableRes; import android.annotation.IntDef; import android.annotation.NonNull; +import android.annotation.SystemService; import android.app.ActivityThread; import android.content.BroadcastReceiver; import android.content.Context; @@ -61,6 +62,7 @@ import java.util.concurrent.CopyOnWriteArrayList; *

The media router API is not thread-safe; all interactions with it must be * done from the main thread of the process.

*/ +@SystemService(Context.MEDIA_ROUTER_SERVICE) public class MediaRouter { private static final String TAG = "MediaRouter"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); diff --git a/media/java/android/media/midi/MidiManager.java b/media/java/android/media/midi/MidiManager.java index 07c8ae86adcf..a015732ddfdd 100644 --- a/media/java/android/media/midi/MidiManager.java +++ b/media/java/android/media/midi/MidiManager.java @@ -16,7 +16,9 @@ package android.media.midi; +import android.annotation.SystemService; import android.bluetooth.BluetoothDevice; +import android.content.Context; import android.os.Binder; import android.os.IBinder; import android.os.Bundle; @@ -28,13 +30,8 @@ import java.util.concurrent.ConcurrentHashMap; /** * This class is the public application interface to the MIDI service. - * - *

You can obtain an instance of this class by calling - * {@link android.content.Context#getSystemService(java.lang.String) Context.getSystemService()}. - * - * {@samplecode - * MidiManager manager = (MidiManager) getSystemService(Context.MIDI_SERVICE);} */ +@SystemService(Context.MIDI_SERVICE) public final class MidiManager { private static final String TAG = "MidiManager"; diff --git a/media/java/android/media/projection/MediaProjectionManager.java b/media/java/android/media/projection/MediaProjectionManager.java index f4a548bb5329..9f2c08e5c6ae 100644 --- a/media/java/android/media/projection/MediaProjectionManager.java +++ b/media/java/android/media/projection/MediaProjectionManager.java @@ -18,6 +18,7 @@ package android.media.projection; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.SystemService; import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -33,14 +34,8 @@ import java.util.Map; /** * Manages the retrieval of certain types of {@link MediaProjection} tokens. - * - *

- * 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#MEDIA_PROJECTION_SERVICE}. - *

*/ +@SystemService(Context.MEDIA_PROJECTION_SERVICE) public final class MediaProjectionManager { private static final String TAG = "MediaProjectionManager"; /** @hide */ diff --git a/media/java/android/media/session/MediaSessionManager.java b/media/java/android/media/session/MediaSessionManager.java index 83793aeb2466..e02a4dcba9e4 100644 --- a/media/java/android/media/session/MediaSessionManager.java +++ b/media/java/android/media/session/MediaSessionManager.java @@ -18,7 +18,9 @@ package android.media.session; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.annotation.SystemApi; +import android.annotation.SystemService; import android.content.ComponentName; import android.content.Context; import android.media.AudioManager; @@ -42,13 +44,11 @@ import java.util.List; * Provides support for interacting with {@link MediaSession media sessions} * that applications have published to express their ongoing media playback * state. - *

- * Use Context.getSystemService(Context.MEDIA_SESSION_SERVICE) to - * get an instance of this class. * * @see MediaSession * @see MediaController */ +@SystemService(Context.MEDIA_SESSION_SERVICE) public final class MediaSessionManager { private static final String TAG = "SessionManager"; @@ -357,6 +357,7 @@ public final class MediaSessionManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER) public void setOnVolumeKeyLongPressListener( OnVolumeKeyLongPressListener listener, @Nullable Handler handler) { synchronized (mLock) { @@ -392,6 +393,7 @@ public final class MediaSessionManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.SET_MEDIA_KEY_LISTENER) public void setOnMediaKeyListener(OnMediaKeyListener listener, @Nullable Handler handler) { synchronized (mLock) { try { diff --git a/media/java/android/media/soundtrigger/SoundTriggerDetector.java b/media/java/android/media/soundtrigger/SoundTriggerDetector.java index d5296ae42031..a48abff29555 100644 --- a/media/java/android/media/soundtrigger/SoundTriggerDetector.java +++ b/media/java/android/media/soundtrigger/SoundTriggerDetector.java @@ -20,6 +20,7 @@ import static android.hardware.soundtrigger.SoundTrigger.STATUS_OK; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.hardware.soundtrigger.IRecognitionStatusCallback; import android.hardware.soundtrigger.SoundTrigger; @@ -235,6 +236,7 @@ public final class SoundTriggerDetector { * {@link Callback}. * @return Indicates whether the call succeeded or not. */ + @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public boolean startRecognition(@RecognitionFlags int recognitionFlags) { if (DBG) { Slog.d(TAG, "startRecognition()"); @@ -258,6 +260,7 @@ public final class SoundTriggerDetector { /** * Stops recognition for the associated model. */ + @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public boolean stopRecognition() { int status = STATUS_OK; try { diff --git a/media/java/android/media/soundtrigger/SoundTriggerManager.java b/media/java/android/media/soundtrigger/SoundTriggerManager.java index fdd7fc2a8f19..7f8140adaed2 100644 --- a/media/java/android/media/soundtrigger/SoundTriggerManager.java +++ b/media/java/android/media/soundtrigger/SoundTriggerManager.java @@ -18,7 +18,9 @@ package android.media.soundtrigger; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.annotation.SystemApi; +import android.annotation.SystemService; import android.content.Context; import android.hardware.soundtrigger.SoundTrigger; import android.os.Handler; @@ -39,6 +41,7 @@ import java.util.UUID; * @hide */ @SystemApi +@SystemService(Context.SOUND_TRIGGER_SERVICE) public final class SoundTriggerManager { private static final boolean DBG = false; private static final String TAG = "SoundTriggerManager"; @@ -65,6 +68,7 @@ public final class SoundTriggerManager { /** * Updates the given sound trigger model. */ + @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public void updateModel(Model model) { try { mSoundTriggerService.updateSoundModel(model.getGenericSoundModel()); @@ -77,6 +81,7 @@ public final class SoundTriggerManager { * Returns the sound trigger model represented by the given UUID. An instance of {@link Model} * is returned. */ + @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public Model getModel(UUID soundModelId) { try { return new Model(mSoundTriggerService.getSoundModel( @@ -89,6 +94,7 @@ public final class SoundTriggerManager { /** * Deletes the sound model represented by the provided UUID. */ + @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public void deleteModel(UUID soundModelId) { try { mSoundTriggerService.deleteSoundModel(new ParcelUuid(soundModelId)); @@ -110,6 +116,7 @@ public final class SoundTriggerManager { * @return Instance of {@link SoundTriggerDetector} or null on error. */ @Nullable + @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public SoundTriggerDetector createSoundTriggerDetector(UUID soundModelId, @NonNull SoundTriggerDetector.Callback callback, @Nullable Handler handler) { if (soundModelId == null) { diff --git a/media/java/android/media/tv/TvInputManager.java b/media/java/android/media/tv/TvInputManager.java index 68ee02cab7a4..28fd338aabc7 100644 --- a/media/java/android/media/tv/TvInputManager.java +++ b/media/java/android/media/tv/TvInputManager.java @@ -21,6 +21,8 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SystemApi; +import android.annotation.SystemService; +import android.content.Context; import android.content.Intent; import android.graphics.Rect; import android.media.PlaybackParams; @@ -57,9 +59,7 @@ import java.util.Map; /** * Central system API to the overall TV input framework (TIF) architecture, which arbitrates - * interaction between applications and the selected TV inputs. You can retrieve an instance of - * this interface with {@link android.content.Context#getSystemService - * Context.getSystemService(Context.TV_INPUT_SERVICE)}. + * interaction between applications and the selected TV inputs. * *

There are three primary parties involved in the TV input framework (TIF) architecture: * @@ -78,6 +78,7 @@ import java.util.Map; * programs. * */ +@SystemService(Context.TV_INPUT_SERVICE) public final class TvInputManager { private static final String TAG = "TvInputManager"; @@ -1516,6 +1517,7 @@ public final class TvInputManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.CAPTURE_TV_INPUT) public List getAvailableTvStreamConfigList(String inputId) { try { return mService.getAvailableTvStreamConfigList(inputId, mUserId); @@ -1534,6 +1536,7 @@ public final class TvInputManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.CAPTURE_TV_INPUT) public boolean captureFrame(String inputId, Surface surface, TvStreamConfig config) { try { return mService.captureFrame(inputId, surface, config, mUserId); diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java index 0a47a9890c8d..55de7ab7eb1e 100644 --- a/telecomm/java/android/telecom/TelecomManager.java +++ b/telecomm/java/android/telecom/TelecomManager.java @@ -18,6 +18,7 @@ import android.Manifest; import android.annotation.RequiresPermission; import android.annotation.SuppressAutoDoc; import android.annotation.SystemApi; +import android.annotation.SystemService; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -48,6 +49,7 @@ import java.util.List; * descriptions. */ @SuppressAutoDoc +@SystemService(Context.TELECOM_SERVICE) public class TelecomManager { /** @@ -1216,6 +1218,7 @@ public class TelecomManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean endCall() { try { if (isServiceConnected()) { diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java index 7174a70dd01b..c6c1be3b23c3 100644 --- a/telephony/java/android/telephony/CarrierConfigManager.java +++ b/telephony/java/android/telephony/CarrierConfigManager.java @@ -18,7 +18,10 @@ package android.telephony; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresPermission; +import android.annotation.SuppressLint; import android.annotation.SystemApi; +import android.annotation.SystemService; import android.content.Context; import android.os.PersistableBundle; import android.os.RemoteException; @@ -29,14 +32,8 @@ import com.android.internal.telephony.ICarrierConfigLoader; /** * Provides access to telephony configuration values that are carrier-specific. - *

- * Users should obtain an instance of this class by calling - * {@code mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);} - *

- * - * @see Context#getSystemService - * @see Context#CARRIER_CONFIG_SERVICE */ +@SystemService(Context.CARRIER_CONFIG_SERVICE) public class CarrierConfigManager { private final static String TAG = "CarrierConfigManager"; @@ -1742,6 +1739,7 @@ public class CarrierConfigManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void updateConfigForPhoneId(int phoneId, String simState) { try { ICarrierConfigLoader loader = getICarrierConfigLoader(); @@ -1763,6 +1761,7 @@ public class CarrierConfigManager { */ @NonNull @SystemApi + @SuppressLint("Doclava125") public static PersistableBundle getDefaultConfig() { return new PersistableBundle(sDefaults); } diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java index 7d4d90bb75ab..1eac263133e5 100644 --- a/telephony/java/android/telephony/SmsManager.java +++ b/telephony/java/android/telephony/SmsManager.java @@ -16,6 +16,7 @@ package android.telephony; +import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.app.ActivityThread; import android.app.PendingIntent; @@ -346,6 +347,7 @@ public final class SmsManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void sendTextMessageWithoutPersisting( String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent) { @@ -530,6 +532,7 @@ public final class SmsManager { * @hide **/ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void sendMultipartTextMessageWithoutPersisting( String destinationAddress, String scAddress, List parts, List sentIntents, List deliveryIntents) { diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 7f616ad6fb08..709877da24ca 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -18,6 +18,7 @@ package android.telephony; import android.annotation.NonNull; import android.annotation.SdkConstant; +import android.annotation.SystemService; import android.annotation.SdkConstant.SdkConstantType; import android.content.Context; import android.content.Intent; @@ -41,12 +42,10 @@ import java.util.List; /** * SubscriptionManager is the application interface to SubscriptionController * and provides information about the current Telephony Subscriptions. - * *

- * You do not instantiate this class directly; instead, you retrieve - * a reference to an instance through {@link #from}. *

* All SDK public methods require android.Manifest.permission.READ_PHONE_STATE. */ +@SystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) public class SubscriptionManager { private static final String LOG_TAG = "SubscriptionManager"; private static final boolean DBG = false; diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index b8e24f0aa4d1..e3555627a486 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -22,8 +22,10 @@ import android.annotation.IntDef; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; +import android.annotation.SuppressLint; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; +import android.annotation.SystemService; import android.annotation.WorkerThread; import android.app.ActivityThread; import android.app.PendingIntent; @@ -79,11 +81,6 @@ import java.util.regex.Pattern; * types of subscriber information. Applications can also register * a listener to receive notification of telephony state changes. *

- * You do not instantiate this class directly; instead, you retrieve - * a reference to an instance through - * {@link android.content.Context#getSystemService - * Context.getSystemService(Context.TELEPHONY_SERVICE)}. - * * The returned TelephonyManager will use the default subscription for all calls. * To call an API for a specific subscription, use {@link #createForSubscriptionId(int)}. e.g. * @@ -96,6 +93,7 @@ import java.util.regex.Pattern; * its manifest file. Where permissions apply, they are noted in the * the methods through which you access the protected information. */ +@SystemService(Context.TELEPHONY_SERVICE) public class TelephonyManager { private static final String TAG = "TelephonyManager"; @@ -2671,8 +2669,8 @@ public class TelephonyManager { * be implemented instead. */ @SystemApi + @SuppressLint("Doclava125") public void setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled){ - } /** @@ -4855,12 +4853,14 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public String getCdmaMdn() { return getCdmaMdn(getSubId()); } /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public String getCdmaMdn(int subId) { try { ITelephony telephony = getITelephony(); @@ -4876,12 +4876,14 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public String getCdmaMin() { return getCdmaMin(getSubId()); } /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public String getCdmaMin(int subId) { try { ITelephony telephony = getITelephony(); @@ -4975,6 +4977,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.CALL_PHONE) public void call(String callingPackage, String number) { try { ITelephony telephony = getITelephony(); @@ -4987,6 +4990,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.CALL_PHONE) public boolean endCall() { try { ITelephony telephony = getITelephony(); @@ -5000,6 +5004,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void answerRingingCall() { try { ITelephony telephony = getITelephony(); @@ -5074,6 +5079,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean supplyPin(String pin) { try { ITelephony telephony = getITelephony(); @@ -5087,6 +5093,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean supplyPuk(String puk, String pin) { try { ITelephony telephony = getITelephony(); @@ -5100,6 +5107,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPinReportResult(String pin) { try { ITelephony telephony = getITelephony(); @@ -5113,6 +5121,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPukReportResult(String puk, String pin) { try { ITelephony telephony = getITelephony(); @@ -5232,6 +5241,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean handlePinMmi(String dialString) { try { ITelephony telephony = getITelephony(); @@ -5245,6 +5255,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean handlePinMmiForSubscriber(int subId, String dialString) { try { ITelephony telephony = getITelephony(); @@ -5258,6 +5269,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void toggleRadioOnOff() { try { ITelephony telephony = getITelephony(); @@ -5270,6 +5282,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setRadio(boolean turnOn) { try { ITelephony telephony = getITelephony(); @@ -5283,6 +5296,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setRadioPower(boolean turnOn) { try { ITelephony telephony = getITelephony(); @@ -5308,6 +5322,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean enableDataConnectivity() { try { ITelephony telephony = getITelephony(); @@ -5321,6 +5336,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean disableDataConnectivity() { try { ITelephony telephony = getITelephony(); @@ -5371,12 +5387,14 @@ public class TelephonyManager { * * @see #hasCarrierPrivileges */ + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataEnabled(boolean enable) { setDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enable); } /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataEnabled(int subId, boolean enable) { try { Log.d(TAG, "setDataEnabled: enabled=" + enable); @@ -5466,6 +5484,7 @@ public class TelephonyManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void enableVideoCalling(boolean enable) { try { ITelephony telephony = getITelephony(); @@ -6346,6 +6365,7 @@ public class TelephonyManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public List getTelephonyHistograms() { try { ITelephony service = getITelephony(); @@ -6373,6 +6393,7 @@ public class TelephonyManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int setAllowedCarriers(int slotIndex, List carriers) { try { ITelephony service = getITelephony(); @@ -6391,9 +6412,6 @@ public class TelephonyManager { * Get the allowed carrier list for slotIndex. * Require system privileges. In the future we may add this to carrier APIs. * - *

Requires Permission: - * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} - * *

This method returns valid data on devices with {@link * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. * @@ -6402,6 +6420,7 @@ public class TelephonyManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public List getAllowedCarriers(int slotIndex) { try { ITelephony service = getITelephony(); diff --git a/wifi/java/android/net/wifi/RttManager.java b/wifi/java/android/net/wifi/RttManager.java index b133a44d0117..a4b3bf2a3019 100644 --- a/wifi/java/android/net/wifi/RttManager.java +++ b/wifi/java/android/net/wifi/RttManager.java @@ -1,7 +1,10 @@ package android.net.wifi; import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.annotation.SuppressLint; import android.annotation.SystemApi; +import android.annotation.SystemService; import android.content.Context; import android.os.Bundle; import android.os.Handler; @@ -20,6 +23,7 @@ import com.android.internal.util.Protocol; /** @hide */ @SystemApi +@SystemService(Context.WIFI_RTT_SERVICE) public class RttManager { private static final boolean DBG = false; @@ -167,6 +171,7 @@ public class RttManager { /** @deprecated Use the new {@link android.net.wifi.RttManager#getRttCapabilities()} API.*/ @Deprecated + @SuppressLint("Doclava125") public Capabilities getCapabilities() { return new Capabilities(); } @@ -990,7 +995,7 @@ public class RttManager { * @exception throw IllegalArgumentException when params are illegal * throw IllegalStateException when RttCapabilities do not exist */ - + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startRanging(RttParams[] params, RttListener listener) { int index = 0; for(RttParams rttParam : params) { @@ -1006,6 +1011,7 @@ public class RttManager { 0, putListener(listener), parcelableParams); } + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void stopRanging(RttListener listener) { validateChannel(); mAsyncChannel.sendMessage(CMD_OP_STOP_RANGING, 0, removeListener(listener)); @@ -1039,6 +1045,7 @@ public class RttManager { * @param callback Callback for responder enabling/disabling result. * @throws IllegalArgumentException If {@code callback} is null. */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void enableResponder(ResponderCallback callback) { if (callback == null) { throw new IllegalArgumentException("callback cannot be null"); @@ -1058,6 +1065,7 @@ public class RttManager { * @param callback The same callback used for enabling responder. * @throws IllegalArgumentException If {@code callback} is null. */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void disableResponder(ResponderCallback callback) { if (callback == null) { throw new IllegalArgumentException("callback cannot be null"); diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 58df4ee227f2..05312a979614 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -17,9 +17,12 @@ package android.net.wifi; import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.annotation.SdkConstant; +import android.annotation.SuppressLint; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; +import android.annotation.SystemService; import android.content.Context; import android.content.pm.ParceledListSlice; import android.net.ConnectivityManager; @@ -56,27 +59,30 @@ import java.util.concurrent.CountDownLatch; /** * This class provides the primary API for managing all aspects of Wi-Fi - * connectivity. Get an instance of this class by calling - * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.WIFI_SERVICE)}. - * On releases before NYC, it should only be obtained from an application context, and not from - * any other derived context to avoid memory leaks within the calling process. - + * connectivity. + *

+ * On releases before {@link android.os.Build.VERSION_CODES#N}, this object + * should only be obtained from an {@linkplain Context#getApplicationContext() + * application context}, and not from any other derived context to avoid memory + * leaks within the calling process. + *

* It deals with several categories of items: *

    - *
  • The list of configured networks. The list can be viewed and updated, - * and attributes of individual entries can be modified.
  • + *
  • The list of configured networks. The list can be viewed and updated, and + * attributes of individual entries can be modified.
  • *
  • The currently active Wi-Fi network, if any. Connectivity can be - * established or torn down, and dynamic information about the state of - * the network can be queried.
  • - *
  • Results of access point scans, containing enough information to - * make decisions about what access point to connect to.
  • - *
  • It defines the names of various Intent actions that are broadcast - * upon any sort of change in Wi-Fi state. + * established or torn down, and dynamic information about the state of the + * network can be queried.
  • + *
  • Results of access point scans, containing enough information to make + * decisions about what access point to connect to.
  • + *
  • It defines the names of various Intent actions that are broadcast upon + * any sort of change in Wi-Fi state. *
- * This is the API to use when performing Wi-Fi specific operations. To - * perform operations that pertain to network connectivity at an abstract - * level, use {@link android.net.ConnectivityManager}. + * This is the API to use when performing Wi-Fi specific operations. To perform + * operations that pertain to network connectivity at an abstract level, use + * {@link android.net.ConnectivityManager}. */ +@SystemService(Context.WIFI_SERVICE) public class WifiManager { private static final String TAG = "WifiManager"; @@ -966,6 +972,7 @@ public class WifiManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.READ_WIFI_CREDENTIAL) public List getPrivilegedConfiguredNetworks() { try { ParceledListSlice parceledList = @@ -981,6 +988,7 @@ public class WifiManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.READ_WIFI_CREDENTIAL) public WifiConnectionStatistics getConnectionStatistics() { try { return mService.getConnectionStatistics(); @@ -1522,6 +1530,7 @@ public class WifiManager { /** @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public boolean startScan(WorkSource workSource) { try { String packageName = mContext.getOpPackageName(); @@ -1542,6 +1551,7 @@ public class WifiManager { */ @Deprecated @SystemApi + @SuppressLint("Doclava125") public boolean startLocationRestrictedScan(WorkSource workSource) { return false; } @@ -1556,6 +1566,7 @@ public class WifiManager { */ @Deprecated @SystemApi + @SuppressLint("Doclava125") public boolean isBatchedScanSupported() { return false; } @@ -1569,6 +1580,7 @@ public class WifiManager { */ @Deprecated @SystemApi + @SuppressLint("Doclava125") public List getBatchedScanResults() { return null; } @@ -1808,6 +1820,7 @@ public class WifiManager { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) { String packageName = mContext.getOpPackageName(); diff --git a/wifi/java/android/net/wifi/WifiScanner.java b/wifi/java/android/net/wifi/WifiScanner.java index c02ceef95b73..f47d5caf182b 100644 --- a/wifi/java/android/net/wifi/WifiScanner.java +++ b/wifi/java/android/net/wifi/WifiScanner.java @@ -16,7 +16,10 @@ package android.net.wifi; +import android.annotation.RequiresPermission; +import android.annotation.SuppressLint; import android.annotation.SystemApi; +import android.annotation.SystemService; import android.content.Context; import android.os.Bundle; import android.os.Handler; @@ -40,12 +43,10 @@ import java.util.List; /** * This class provides a way to scan the Wifi universe around the device - * Get an instance of this class by calling - * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context - * .WIFI_SCANNING_SERVICE)}. * @hide */ @SystemApi +@SystemService(Context.WIFI_SCANNING_SERVICE) public class WifiScanner { /** no band specified; use channel list instead */ @@ -732,6 +733,7 @@ public class WifiScanner { * key for this scan, and must also be specified to cancel the scan. Multiple * scans should also not share this object. */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startBackgroundScan(ScanSettings settings, ScanListener listener) { startBackgroundScan(settings, listener, null); } @@ -744,6 +746,7 @@ public class WifiScanner { * key for this scan, and must also be specified to cancel the scan. Multiple * scans should also not share this object. */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startBackgroundScan(ScanSettings settings, ScanListener listener, WorkSource workSource) { Preconditions.checkNotNull(listener, "listener cannot be null"); @@ -761,6 +764,7 @@ public class WifiScanner { * @param listener specifies which scan to cancel; must be same object as passed in {@link * #startBackgroundScan} */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void stopBackgroundScan(ScanListener listener) { Preconditions.checkNotNull(listener, "listener cannot be null"); int key = removeListener(listener); @@ -772,6 +776,7 @@ public class WifiScanner { * reports currently available scan results on appropriate listeners * @return true if all scan results were reported correctly */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public boolean getScanResults() { validateChannel(); Message reply = mAsyncChannel.sendMessageSynchronously(CMD_GET_SCAN_RESULTS, 0); @@ -786,6 +791,7 @@ public class WifiScanner { * key for this scan, and must also be specified to cancel the scan. Multiple * scans should also not share this object. */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startScan(ScanSettings settings, ScanListener listener) { startScan(settings, listener, null); } @@ -799,6 +805,7 @@ public class WifiScanner { * key for this scan, and must also be specified to cancel the scan. Multiple * scans should also not share this object. */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startScan(ScanSettings settings, ScanListener listener, WorkSource workSource) { Preconditions.checkNotNull(listener, "listener cannot be null"); int key = addListener(listener); @@ -815,6 +822,7 @@ public class WifiScanner { * hasn't been called on the listener, ignored otherwise * @param listener */ + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void stopScan(ScanListener listener) { Preconditions.checkNotNull(listener, "listener cannot be null"); int key = removeListener(listener); @@ -962,6 +970,7 @@ public class WifiScanner { * @param bssidInfos access points to watch */ @Deprecated + @SuppressLint("Doclava125") public void configureWifiChange( int rssiSampleSize, /* sample size for RSSI averaging */ int lostApSampleSize, /* samples to confirm AP's loss */ @@ -995,6 +1004,7 @@ public class WifiScanner { * provided on {@link #stopTrackingWifiChange} */ @Deprecated + @SuppressLint("Doclava125") public void startTrackingWifiChange(WifiChangeListener listener) { throw new UnsupportedOperationException(); } @@ -1005,6 +1015,7 @@ public class WifiScanner { * #stopTrackingWifiChange} */ @Deprecated + @SuppressLint("Doclava125") public void stopTrackingWifiChange(WifiChangeListener listener) { throw new UnsupportedOperationException(); } @@ -1012,6 +1023,7 @@ public class WifiScanner { /** @hide */ @SystemApi @Deprecated + @SuppressLint("Doclava125") public void configureWifiChange(WifiChangeSettings settings) { throw new UnsupportedOperationException(); } @@ -1067,6 +1079,7 @@ public class WifiScanner { * also be provided on {@link #stopTrackingBssids} */ @Deprecated + @SuppressLint("Doclava125") public void startTrackingBssids(BssidInfo[] bssidInfos, int apLostThreshold, BssidListener listener) { throw new UnsupportedOperationException(); @@ -1077,6 +1090,7 @@ public class WifiScanner { * @param listener same object provided in {@link #startTrackingBssids} */ @Deprecated + @SuppressLint("Doclava125") public void stopTrackingBssids(BssidListener listener) { throw new UnsupportedOperationException(); } diff --git a/wifi/java/android/net/wifi/aware/WifiAwareManager.java b/wifi/java/android/net/wifi/aware/WifiAwareManager.java index d3ed79245426..c22daafe514c 100644 --- a/wifi/java/android/net/wifi/aware/WifiAwareManager.java +++ b/wifi/java/android/net/wifi/aware/WifiAwareManager.java @@ -20,6 +20,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SdkConstant; +import android.annotation.SystemService; import android.annotation.SdkConstant.SdkConstantType; import android.content.Context; import android.net.ConnectivityManager; @@ -48,9 +49,7 @@ import java.util.List; /** * This class provides the primary API for managing Wi-Fi Aware operations: - * discovery and peer-to-peer data connections. Get an instance of this class by calling - * {@link android.content.Context#getSystemService(String) - * Context.getSystemService(Context.WIFI_AWARE_SERVICE)}. + * discovery and peer-to-peer data connections. *

* The class provides access to: *

    @@ -120,6 +119,7 @@ import java.util.List; * {@link DiscoverySession#createNetworkSpecifierPassphrase(PeerHandle, String)}. *
*/ +@SystemService(Context.WIFI_AWARE_SERVICE) public class WifiAwareManager { private static final String TAG = "WifiAwareManager"; private static final boolean DBG = false; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java index c93ac7b5f8f1..95d0a79bb28b 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java @@ -17,6 +17,7 @@ package android.net.wifi.p2p; import android.annotation.SdkConstant; +import android.annotation.SystemService; import android.annotation.SdkConstant.SdkConstantType; import android.content.Context; import android.net.wifi.WpsInfo; @@ -119,9 +120,6 @@ import java.util.Map; * {@link android.Manifest.permission#CHANGE_WIFI_STATE} to perform any further peer-to-peer * operations. * - * Get an instance of this class by calling {@link android.content.Context#getSystemService(String) - * Context.getSystemService(Context.WIFI_P2P_SERVICE)}. - * * {@see WifiP2pConfig} * {@see WifiP2pInfo} * {@see WifiP2pGroup} @@ -129,6 +127,7 @@ import java.util.Map; * {@see WifiP2pDeviceList} * {@see android.net.wifi.WpsInfo} */ +@SystemService(Context.WIFI_P2P_SERVICE) public class WifiP2pManager { private static final String TAG = "WifiP2pManager"; /** -- 2.11.0