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

Commit 76c0d3c6 authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Reland "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

Original CL ag/25262282 lacked null check in
SuspendedAppActivity.createSuspendedAppInterceptIntent() and caused
b/316388832.

Bug: 263464464
Test: atest PackageManagerSettingsTests
Test: atest PackageUserStateTest
Test: atest com.android.server.pm.SuspendPackageHelperTest
Test: atest CtsSuspendAppsTestCases
Test: atest WmTests:ActivityStartInterceptorTest
Test: make PlatformScenarioTests \
  && adb install -r -g \
  out/target/product/bluejay/testcases/PlatformScenarioTests/arm64/PlatformScenarioTests.apk \
  && adb shell am instrument \
  -w -e class android.platform.test.scenario.clock.HotAppLaunchFromHomeScreen \
  -e listener android.device.collectors.AppStartupListener \
  android.platform.test.scenario/androidx.test.runner.AndroidJUnitRunner
Change-Id: I65507733276dea848d0860a8350260bdf4820c61
parent 479c237f
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
@@ -10000,6 +10000,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.
+8 −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,19 @@ 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 != null ? suspendingPackage.packageName : null)
                .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