Merge "Review of suspend/unsuspend APIs" into pi-dev
am: 2188383b8a
Change-Id: Ied0b92474f80760f084fd749587fce0953c8469b
This commit is contained in:
@@ -10956,7 +10956,7 @@ package android.content.pm {
|
||||
method public abstract void onPackageRemoved(java.lang.String, android.os.UserHandle);
|
||||
method public abstract void onPackagesAvailable(java.lang.String[], android.os.UserHandle, boolean);
|
||||
method public void onPackagesSuspended(java.lang.String[], android.os.UserHandle);
|
||||
method public void onPackagesSuspended(java.lang.String[], android.os.Bundle, android.os.UserHandle);
|
||||
method public void onPackagesSuspended(java.lang.String[], android.os.UserHandle, android.os.Bundle);
|
||||
method public abstract void onPackagesUnavailable(java.lang.String[], android.os.UserHandle, boolean);
|
||||
method public void onPackagesUnsuspended(java.lang.String[], android.os.UserHandle);
|
||||
method public void onShortcutsChanged(java.lang.String, java.util.List<android.content.pm.ShortcutInfo>, android.os.UserHandle);
|
||||
|
||||
@@ -1030,7 +1030,7 @@ package android.content.pm {
|
||||
method public abstract void grantRuntimePermission(java.lang.String, java.lang.String, android.os.UserHandle);
|
||||
method public abstract int installExistingPackage(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
|
||||
method public abstract int installExistingPackage(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
|
||||
method public boolean isPackageSuspended(java.lang.String);
|
||||
method public boolean isPackageSuspended(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
|
||||
method public java.util.List<android.content.pm.ResolveInfo> queryBroadcastReceiversAsUser(android.content.Intent, int, android.os.UserHandle);
|
||||
method public abstract void registerDexModule(java.lang.String, android.content.pm.PackageManager.DexModuleRegisterCallback);
|
||||
method public abstract void removeOnPermissionsChangeListener(android.content.pm.PackageManager.OnPermissionsChangedListener);
|
||||
|
||||
@@ -2187,8 +2187,12 @@ public class ApplicationPackageManager extends PackageManager {
|
||||
|
||||
/** @hide */
|
||||
@Override
|
||||
public boolean isPackageSuspended(String packageName) {
|
||||
return isPackageSuspendedForUser(packageName, mContext.getUserId());
|
||||
public boolean isPackageSuspended(String packageName) throws NameNotFoundException {
|
||||
try {
|
||||
return isPackageSuspendedForUser(packageName, mContext.getUserId());
|
||||
} catch (IllegalArgumentException ie) {
|
||||
throw new NameNotFoundException(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,6 +40,7 @@ import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.Process;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.ShellCommand;
|
||||
@@ -1814,8 +1815,12 @@ public class Intent implements Parcelable, Cloneable {
|
||||
public static final String EXTRA_PACKAGE_NAME = "android.intent.extra.PACKAGE_NAME";
|
||||
|
||||
/**
|
||||
* Intent extra: A {@link Bundle} of extras for a package being suspended. Will be sent with
|
||||
* {@link #ACTION_MY_PACKAGE_SUSPENDED}.
|
||||
* Intent extra: A {@link Bundle} of extras for a package being suspended. Will be sent as an
|
||||
* extra with {@link #ACTION_MY_PACKAGE_SUSPENDED}.
|
||||
*
|
||||
* <p>The contents of this {@link Bundle} are a contract between the suspended app and the
|
||||
* suspending app, i.e. any app with the permission {@code android.permission.SUSPEND_APPS}.
|
||||
* This is meant to enable the suspended app to better handle the state of being suspended.
|
||||
*
|
||||
* @see #ACTION_MY_PACKAGE_SUSPENDED
|
||||
* @see #ACTION_MY_PACKAGE_UNSUSPENDED
|
||||
@@ -2284,6 +2289,10 @@ public class Intent implements Parcelable, Cloneable {
|
||||
/**
|
||||
* Activity Action: Started to show more details about why an application was suspended.
|
||||
*
|
||||
* <p>Whenever the system detects an activity launch for a suspended app, it shows a dialog to
|
||||
* the user to inform them of the state and present them an affordance to start this activity
|
||||
* action to show more details about the reason for suspension.
|
||||
*
|
||||
* <p>Apps holding {@link android.Manifest.permission#SUSPEND_APPS} must declare an activity
|
||||
* handling this intent and protect it with
|
||||
* {@link android.Manifest.permission#SEND_SHOW_SUSPENDED_APP_DETAILS}.
|
||||
@@ -2293,6 +2302,8 @@ public class Intent implements Parcelable, Cloneable {
|
||||
* <p class="note">This is a protected intent that can only be sent
|
||||
* by the system.
|
||||
*
|
||||
* @see PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
|
||||
* PersistableBundle, String)
|
||||
* @see PackageManager#isPackageSuspended()
|
||||
* @see #ACTION_PACKAGES_SUSPENDED
|
||||
*
|
||||
|
||||
@@ -212,7 +212,7 @@ public class LauncherApps {
|
||||
* an applicaton.
|
||||
*
|
||||
* <p>Note: On devices running {@link android.os.Build.VERSION_CODES#P Android P} or higher,
|
||||
* any apps that override {@link #onPackagesSuspended(String[], Bundle, UserHandle)} will
|
||||
* any apps that override {@link #onPackagesSuspended(String[], UserHandle, Bundle)} will
|
||||
* not receive this callback.
|
||||
*
|
||||
* @param packageNames The names of the packages that have just been
|
||||
@@ -226,15 +226,20 @@ public class LauncherApps {
|
||||
* Indicates that one or more packages have been suspended. A device administrator or an app
|
||||
* with {@code android.permission.SUSPEND_APPS} can do this.
|
||||
*
|
||||
* @param packageNames The names of the packages that have just been suspended.
|
||||
* @param launcherExtras A {@link Bundle} of extras for the launcher.
|
||||
* @param user the user for which the given packages were suspended.
|
||||
* <p>A suspending app with the permission {@code android.permission.SUSPEND_APPS} can
|
||||
* optionally provide a {@link Bundle} of extra information that it deems helpful for the
|
||||
* launcher to handle the suspended state of these packages. The contents of this
|
||||
* {@link Bundle} supposed to be a contract between the suspending app and the launcher.
|
||||
*
|
||||
* @param packageNames The names of the packages that have just been suspended.
|
||||
* @param user the user for which the given packages were suspended.
|
||||
* @param launcherExtras A {@link Bundle} of extras for the launcher, if provided to the
|
||||
* system, {@code null} otherwise.
|
||||
* @see PackageManager#isPackageSuspended()
|
||||
* @see #getSuspendedPackageLauncherExtras(String, UserHandle)
|
||||
*/
|
||||
public void onPackagesSuspended(String[] packageNames, @Nullable Bundle launcherExtras,
|
||||
UserHandle user) {
|
||||
public void onPackagesSuspended(String[] packageNames, UserHandle user,
|
||||
@Nullable Bundle launcherExtras) {
|
||||
onPackagesSuspended(packageNames, user);
|
||||
}
|
||||
|
||||
@@ -662,6 +667,9 @@ public class LauncherApps {
|
||||
* {@code PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
|
||||
* PersistableBundle, String)}.
|
||||
*
|
||||
* <p>The contents of this {@link Bundle} are supposed to be a contract between the suspending
|
||||
* app and the launcher.
|
||||
*
|
||||
* <p>Note: This just returns whatever extras were provided to the system, <em>which might
|
||||
* even be {@code null}.</em>
|
||||
*
|
||||
@@ -670,7 +678,7 @@ public class LauncherApps {
|
||||
* @return A {@link Bundle} of launcher extras. Or {@code null} if the package is not currently
|
||||
* suspended.
|
||||
*
|
||||
* @see Callback#onPackagesSuspended(String[], Bundle, UserHandle)
|
||||
* @see Callback#onPackagesSuspended(String[], UserHandle, Bundle)
|
||||
* @see PackageManager#isPackageSuspended()
|
||||
*/
|
||||
public @Nullable Bundle getSuspendedPackageLauncherExtras(String packageName, UserHandle user) {
|
||||
@@ -1298,8 +1306,8 @@ public class LauncherApps {
|
||||
mCallback.onPackagesUnavailable(info.packageNames, info.user, info.replacing);
|
||||
break;
|
||||
case MSG_SUSPENDED:
|
||||
mCallback.onPackagesSuspended(info.packageNames, info.launcherExtras,
|
||||
info.user);
|
||||
mCallback.onPackagesSuspended(info.packageNames, info.user, info.launcherExtras
|
||||
);
|
||||
break;
|
||||
case MSG_UNSUSPENDED:
|
||||
mCallback.onPackagesUnsuspended(info.packageNames, info.user);
|
||||
|
||||
@@ -5571,7 +5571,8 @@ public abstract class PackageManager {
|
||||
* @param packageName The name of the package to get the suspended status of.
|
||||
* @param userId The user id.
|
||||
* @return {@code true} if the package is suspended or {@code false} if the package is not
|
||||
* suspended or could not be found.
|
||||
* suspended.
|
||||
* @throws IllegalArgumentException if the package was not found.
|
||||
* @hide
|
||||
*/
|
||||
public abstract boolean isPackageSuspendedForUser(String packageName, int userId);
|
||||
@@ -5580,12 +5581,13 @@ public abstract class PackageManager {
|
||||
* Query if an app is currently suspended.
|
||||
*
|
||||
* @return {@code true} if the given package is suspended, {@code false} otherwise
|
||||
* @throws NameNotFoundException if the package could not be found.
|
||||
*
|
||||
* @see #setPackagesSuspended(String[], boolean, PersistableBundle, PersistableBundle, String)
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public boolean isPackageSuspended(String packageName) {
|
||||
public boolean isPackageSuspended(String packageName) throws NameNotFoundException {
|
||||
throw new UnsupportedOperationException("isPackageSuspended not implemented");
|
||||
}
|
||||
|
||||
@@ -5616,11 +5618,16 @@ public abstract class PackageManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns any extra information supplied as {@code appExtras} to the system when the calling
|
||||
* app was suspended.
|
||||
* Returns a {@link Bundle} of extras that was meant to be sent to the calling app when it was
|
||||
* suspended. An app with the permission {@code android.permission.SUSPEND_APPS} can supply this
|
||||
* to the system at the time of suspending an app.
|
||||
*
|
||||
* <p>Note: If no extras were supplied to the system, this method will return {@code null}, even
|
||||
* when the calling app has been suspended.</p>
|
||||
* <p>This is the same {@link Bundle} that is sent along with the broadcast
|
||||
* {@link Intent#ACTION_MY_PACKAGE_SUSPENDED}, whenever the app is suspended. The contents of
|
||||
* this {@link Bundle} are a contract between the suspended app and the suspending app.
|
||||
*
|
||||
* <p>Note: These extras are optional, so if no extras were supplied to the system, this method
|
||||
* will return {@code null}, even when the calling app has been suspended.
|
||||
*
|
||||
* @return A {@link Bundle} containing the extras for the app, or {@code null} if the
|
||||
* package is not currently suspended.
|
||||
@@ -5628,6 +5635,7 @@ public abstract class PackageManager {
|
||||
* @see #isPackageSuspended()
|
||||
* @see Intent#ACTION_MY_PACKAGE_UNSUSPENDED
|
||||
* @see Intent#ACTION_MY_PACKAGE_SUSPENDED
|
||||
* @see Intent#EXTRA_SUSPENDED_PACKAGE_EXTRAS
|
||||
*/
|
||||
public @Nullable Bundle getSuspendedPackageAppExtras() {
|
||||
throw new UnsupportedOperationException("getSuspendedPackageAppExtras not implemented");
|
||||
|
||||
@@ -14146,9 +14146,6 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
mPermissionManager.enforceCrossUserPermission(callingUid, userId,
|
||||
true /* requireFullPermission */, false /* checkShell */,
|
||||
"isPackageSuspendedForUser for user " + userId);
|
||||
if (getPackageUid(packageName, 0, userId) != callingUid) {
|
||||
mContext.enforceCallingOrSelfPermission(Manifest.permission.SUSPEND_APPS, null);
|
||||
}
|
||||
synchronized (mPackages) {
|
||||
final PackageSetting ps = mSettings.mPackages.get(packageName);
|
||||
if (ps == null || filterAppAccessLPr(ps, callingUid, userId)) {
|
||||
|
||||
@@ -242,7 +242,7 @@ public class SuspendPackagesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsPackageSuspended() {
|
||||
public void testIsPackageSuspended() throws Exception {
|
||||
suspendTestPackage(null, null, null);
|
||||
assertTrue("isPackageSuspended is false",
|
||||
mPackageManager.isPackageSuspended(TEST_APP_PACKAGE_NAME));
|
||||
@@ -370,8 +370,8 @@ public class SuspendPackagesTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackagesSuspended(String[] packageNames, Bundle launcherExtras,
|
||||
UserHandle user) {
|
||||
public void onPackagesSuspended(String[] packageNames, UserHandle user,
|
||||
Bundle launcherExtras) {
|
||||
final StringBuilder errorString = new StringBuilder();
|
||||
if (!Arrays.equals(packageNames, PACKAGES_TO_SUSPEND)) {
|
||||
errorString.append("Received unexpected packageNames in onPackagesSuspended:");
|
||||
|
||||
Reference in New Issue
Block a user