Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59ed73ed authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Update data types to support cross user suspension

This CL is a refactoring for the follow-up implementation and shouldn't
change any behavior. It changes the data types and signatures to allow
expressing cross-profile suspension and refactors the code to make
adding a flagged functionality change easier in a follow-up. Some
changes only make sense in that contex.

String package is replaced with UserPackage, which encapsulates both
suspending user id and suspending package. In this CL suspending user
id is always the same as target user id, so suspension is never cross
user.

Some userId arguments were renamed to make it clearer whether it refers
to the suspending user or the target user.

Brief doc: go/ae-xu-suspend

Also inline setPackagesSuspendedByAdmin into PMII

Bug: 263464464
Test: atest PackageManagerSettingsTests
Test: atest PackageUserStateTest
Test: atest com.android.server.pm.SuspendPackageHelperTest
Test: atest CtsSuspendAppsTestCases
Test: atest WmTests:ActivityStartInterceptorTest
Change-Id: I71a4c524fb22fc3d3e0c64fd0b984ea44423b5d8
parent dc21a79c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2909,7 +2909,7 @@ public class ApplicationPackageManager extends PackageManager {
        try {
            return mPM.setPackagesSuspendedAsUser(packageNames, suspended, appExtras,
                    launcherExtras, dialogInfo, flags, mContext.getOpPackageName(),
                    getUserId());
                    UserHandle.myUserId() /* suspendingUserId */, getUserId() /* targetUserId */);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+2 −1
Original line number Diff line number Diff line
@@ -300,7 +300,8 @@ interface IPackageManager {

    String[] setPackagesSuspendedAsUser(in String[] packageNames, boolean suspended,
            in PersistableBundle appExtras, in PersistableBundle launcherExtras,
            in SuspendDialogInfo dialogInfo, int flags, String callingPackage, int userId);
            in SuspendDialogInfo dialogInfo, int flags, String suspendingPackage,
            int suspendingUserId, int targetUserId);

    String[] getUnsuspendablePackagesForUser(in String[] packageNames, int userId);

+3 −0
Original line number Diff line number Diff line
@@ -9990,6 +9990,9 @@ public abstract class PackageManager {
     * device administrators or apps holding {@link android.Manifest.permission#MANAGE_USERS} or
     * {@link android.Manifest.permission#SUSPEND_APPS}.
     *
     * <p>
     * <strong>Note:</strong>This API doesn't support cross user suspension and should only be used
     * for testing.
     * @param suspendedPackage The package that has been suspended.
     * @return Name of the package that suspended the given package. Returns {@code null} if the
     * given package is not currently suspended and the platform package name - i.e.
+7 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.SuspendDialogInfo;
import android.content.pm.UserPackage;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -308,7 +309,8 @@ public class SuspendedAppActivity extends AlertActivity
                        try {
                            final String[] errored = ipm.setPackagesSuspendedAsUser(
                                    new String[]{mSuspendedPackage}, false, null, null, null, 0,
                                    mSuspendingPackage, mUserId);
                                    mSuspendingPackage, mUserId /* suspendingUserId */,
                                    mUserId /* targetUserId */);
                            if (ArrayUtils.contains(errored, mSuspendedPackage)) {
                                Slog.e(TAG, "Could not unsuspend " + mSuspendedPackage);
                                break;
@@ -350,17 +352,18 @@ public class SuspendedAppActivity extends AlertActivity
    }

    public static Intent createSuspendedAppInterceptIntent(String suspendedPackage,
            String suspendingPackage, SuspendDialogInfo dialogInfo, Bundle options,
            UserPackage suspendingPackage, SuspendDialogInfo dialogInfo, Bundle options,
            IntentSender onUnsuspend, int userId) {
        return new Intent()
        Intent intent = new Intent()
                .setClassName("android", SuspendedAppActivity.class.getName())
                .putExtra(EXTRA_SUSPENDED_PACKAGE, suspendedPackage)
                .putExtra(EXTRA_DIALOG_INFO, dialogInfo)
                .putExtra(EXTRA_SUSPENDING_PACKAGE, suspendingPackage)
                .putExtra(EXTRA_SUSPENDING_PACKAGE, suspendingPackage.packageName)
                .putExtra(EXTRA_UNSUSPEND_INTENT, onUnsuspend)
                .putExtra(EXTRA_ACTIVITY_OPTIONS, options)
                .putExtra(Intent.EXTRA_USER_ID, userId)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        return intent;
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import android.content.pm.ServiceInfo;
import android.content.pm.ShortcutServiceInternal;
import android.content.pm.SuspendDialogInfo;
import android.content.pm.UserInfo;
import android.content.pm.UserPackage;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
@@ -559,10 +560,11 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
                onClickIntent = UnlaunchableAppActivity.createInQuietModeDialogIntent(appUserId);
            } else if (provider.maskedBySuspendedPackage) {
                showBadge = mUserManager.hasBadge(appUserId);
                final String suspendingPackage = mPackageManagerInternal.getSuspendingPackage(
                final UserPackage suspendingPackage = mPackageManagerInternal.getSuspendingPackage(
                        appInfo.packageName, appUserId);
                // TODO(b/281839596): don't rely on platform always meaning suspended by admin.
                if (PLATFORM_PACKAGE_NAME.equals(suspendingPackage)) {
                if (suspendingPackage != null
                        && PLATFORM_PACKAGE_NAME.equals(suspendingPackage.packageName)) {
                    onClickIntent = mDevicePolicyManagerInternal.createShowAdminSupportIntent(
                            appUserId, true);
                } else {
Loading