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

Commit 3bcf800c authored by Andrei Stingaceanu's avatar Andrei Stingaceanu
Browse files

Suspend apps - block

* kill app when suspending
* block starting ONLY activities for suspended apps
* do not allow suspending the device admin package

Bug: 22776761
Change-Id: I3ee5fcb2d6828f363ce0f024dbc662ab29275192
parent 03b42004
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import static android.app.ActivityManager.INTENT_SENDER_ACTIVITY;
import static android.app.ActivityManager.START_CLASS_NOT_FOUND;
import static android.app.ActivityManager.START_DELIVERED_TO_TOP;
import static android.app.ActivityManager.START_FLAG_ONLY_IF_NEEDED;
import static android.app.ActivityManager.START_PERMISSION_DENIED;
import static android.app.ActivityManager.START_RETURN_INTENT_TO_CALLER;
import static android.app.ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
import static android.app.ActivityManager.START_SUCCESS;
@@ -42,6 +43,7 @@ import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
import static android.content.pm.ApplicationInfo.FLAG_SUSPENDED;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOCUS;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PERMISSIONS_REVIEW;
@@ -228,6 +230,17 @@ class ActivityStarter {
            }
        }

        if (aInfo != null) {
            if ((aInfo.applicationInfo.flags & FLAG_SUSPENDED) != 0) {
                Slog.w(TAG, "Application \"" + aInfo.applicationInfo.packageName
                        + "\" is suspended. Refusing to start: " + intent.toString());
                // TODO: show a dialog/activity informing the user that the application is suspended 
                // and redirect the launch to it. Do not return START_PERMISSION_DENIED because 
                // it is wrong.
                err = ActivityManager.START_PERMISSION_DENIED;
            }
        }

        final int userId = aInfo != null ? UserHandle.getUserId(aInfo.applicationInfo.uid) : 0;

        if (err == ActivityManager.START_SUCCESS) {
+13 −3
Original line number Diff line number Diff line
@@ -10202,16 +10202,25 @@ public class PackageManagerService extends IPackageManager.Stub {
        enforceCrossUserPermission(Binder.getCallingUid(), userId, true, true,
                "setPackageSuspended for user " + userId);
        // TODO: investigate and add more restrictions for suspending crucial packages.
        if (isPackageDeviceAdmin(packageName, userId)) {
            Slog.w(TAG, "Not suspending/un-suspending package \"" + packageName
                    + "\": has active device admin");
            return false;
        }
        long callingId = Binder.clearCallingIdentity();
        try {
            boolean changed = false;
            boolean success = false;
            int appId = -1;
            synchronized (mPackages) {
                final PackageSetting pkgSetting = mSettings.mPackages.get(packageName);
                if (pkgSetting != null) {
                    if (pkgSetting.getSuspended(userId) != suspended) {
                        pkgSetting.setSuspended(suspended, userId);
                        mSettings.writePackageRestrictionsLPr(userId);
                        appId = pkgSetting.appId;
                        changed = true;
                    }
                    success = true;
@@ -10219,10 +10228,11 @@ public class PackageManagerService extends IPackageManager.Stub {
            }
            if (changed) {
                // TODO:
                // * maybe kill application if suspended
                // * hide suspended app from recents
                sendPackagesSuspendedForUser(new String[]{packageName}, userId, suspended);
                if (suspended) {
                    killApplication(packageName, UserHandle.getUid(userId, appId),
                            "suspending package");
                }
            }
            return success;
        } finally {