From f0d748bee9d998b7572483c0227a5e2778bebed7 Mon Sep 17 00:00:00 2001 From: lpeter Date: Tue, 20 Jun 2023 08:06:36 +0000 Subject: [PATCH] Add "conditional=true" annotation for setPackagesSuspended API. We have the @RequiresPermission(Manifest.permission.SUSPEND_APPS) annotation for PackageManager.setPackagesSuspended API, but we allow the device owner and profile owner to use this API directly without the permission "Manifest.permission.SUSPEND_APPS" in the service implementation. So we need to add "conditional=true" to @RequiresPermission annotation for this API. Bug: 284455031 Test: build pass and boot success Change-Id: I9f31f074736afd216935f4112584fef9ea98e2bf --- core/api/system-current.txt | 2 +- core/java/android/content/pm/PackageManager.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 928e41da9c3b7..4cf45f6ba18f9 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -3907,7 +3907,7 @@ package android.content.pm { method @NonNull @RequiresPermission(android.Manifest.permission.SUSPEND_APPS) public String[] setDistractingPackageRestrictions(@NonNull String[], int); method @RequiresPermission(android.Manifest.permission.SET_HARMFUL_APP_WARNINGS) public void setHarmfulAppWarning(@NonNull String, @Nullable CharSequence); method @Deprecated @Nullable @RequiresPermission(android.Manifest.permission.SUSPEND_APPS) public String[] setPackagesSuspended(@Nullable String[], boolean, @Nullable android.os.PersistableBundle, @Nullable android.os.PersistableBundle, @Nullable String); - method @Nullable @RequiresPermission(android.Manifest.permission.SUSPEND_APPS) public String[] setPackagesSuspended(@Nullable String[], boolean, @Nullable android.os.PersistableBundle, @Nullable android.os.PersistableBundle, @Nullable android.content.pm.SuspendDialogInfo); + method @Nullable @RequiresPermission(value=android.Manifest.permission.SUSPEND_APPS, conditional=true) public String[] setPackagesSuspended(@Nullable String[], boolean, @Nullable android.os.PersistableBundle, @Nullable android.os.PersistableBundle, @Nullable android.content.pm.SuspendDialogInfo); method @RequiresPermission(value=android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE, conditional=true) public void setSyntheticAppDetailsActivityEnabled(@NonNull String, boolean); method public void setSystemAppState(@NonNull String, int); method @RequiresPermission(android.Manifest.permission.INSTALL_PACKAGES) public abstract void setUpdateAvailable(@NonNull String, boolean); diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index dca4544f9a143..20137b95fbb3e 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -9487,7 +9487,8 @@ public abstract class PackageManager { * {@link PersistableBundle} objects to be shared with the apps being suspended and the * launcher to support customization that they might need to handle the suspended state. * - *

The caller must hold {@link Manifest.permission#SUSPEND_APPS} to use this API. + *

The caller must hold {@link Manifest.permission#SUSPEND_APPS} to use this API except for + * device owner and profile owner. * * @param packageNames The names of the packages to set the suspended status. * @param suspended If set to {@code true}, the packages will be suspended, if set to @@ -9513,7 +9514,7 @@ public abstract class PackageManager { * @hide */ @SystemApi - @RequiresPermission(Manifest.permission.SUSPEND_APPS) + @RequiresPermission(value=Manifest.permission.SUSPEND_APPS, conditional=true) @Nullable public String[] setPackagesSuspended(@Nullable String[] packageNames, boolean suspended, @Nullable PersistableBundle appExtras, @Nullable PersistableBundle launcherExtras,