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

Commit e1d47a7b authored by Wale Ogunwale's avatar Wale Ogunwale Committed by The Android Automerger
Browse files

Respect DONT_KILL_APP flag when bringing down a disabled service.

Commit 540e123b introduce logic to clean up states when a component is
disabled. For services this included marking the process running the
service as removed so it can be killed later. However, this wasn't
respecting the Intent.EXTRA_DONT_KILL_APP flag where the caller
doesn't want the process of the disabled component to be killed.
This change now takes the flag into account.

Bug: 23491822
Bug: 15804187
Change-Id: I54a6e03cd66164dc8c4606a3c462114fe661ea8e
parent 9820aee6
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -2085,7 +2085,8 @@ public final class ActiveServices {
    }

    private boolean collectPackageServicesLocked(String packageName, Set<String> filterByClasses,
            boolean evenPersistent, boolean doit, ArrayMap<ComponentName, ServiceRecord> services) {
            boolean evenPersistent, boolean doit, boolean killProcess,
            ArrayMap<ComponentName, ServiceRecord> services) {
        boolean didSomething = false;
        for (int i = services.size() - 1; i >= 0; i--) {
            ServiceRecord service = services.valueAt(i);
@@ -2101,7 +2102,7 @@ public final class ActiveServices {
                didSomething = true;
                Slog.i(TAG, "  Force stopping service " + service);
                if (service.app != null) {
                    service.app.removed = true;
                    service.app.removed = killProcess;
                    if (!service.app.persistent) {
                        service.app.services.remove(service);
                    }
@@ -2118,7 +2119,7 @@ public final class ActiveServices {
    }

    boolean bringDownDisabledPackageServicesLocked(String packageName, Set<String> filterByClasses,
            int userId, boolean evenPersistent, boolean doit) {
            int userId, boolean evenPersistent, boolean killProcess, boolean doit) {
        boolean didSomething = false;

        if (mTmpCollectionResults != null) {
@@ -2128,7 +2129,7 @@ public final class ActiveServices {
        if (userId == UserHandle.USER_ALL) {
            for (int i = mServiceMap.size() - 1; i >= 0; i--) {
                didSomething |= collectPackageServicesLocked(packageName, filterByClasses,
                        evenPersistent, doit, mServiceMap.valueAt(i).mServicesByName);
                        evenPersistent, doit, killProcess, mServiceMap.valueAt(i).mServicesByName);
                if (!doit && didSomething) {
                    return true;
                }
@@ -2138,7 +2139,7 @@ public final class ActiveServices {
            if (smap != null) {
                ArrayMap<ComponentName, ServiceRecord> items = smap.mServicesByName;
                didSomething = collectPackageServicesLocked(packageName, filterByClasses,
                        evenPersistent, doit, items);
                        evenPersistent, doit, killProcess, items);
            }
        }

+7 −5
Original line number Diff line number Diff line
@@ -5562,7 +5562,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    }
    private void cleanupDisabledPackageComponentsLocked(
            String packageName, int userId, String[] changedClasses) {
            String packageName, int userId, boolean killProcess, String[] changedClasses) {
        Set<String> disabledClasses = null;
        boolean packageDisabled = false;
@@ -5632,7 +5632,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        // Clean-up disabled services.
        mServices.bringDownDisabledPackageServicesLocked(
                packageName, disabledClasses, userId, false, true);
                packageName, disabledClasses, userId, false, killProcess, true);
        // Clean-up disabled providers.
        ArrayList<ContentProviderRecord> providers = new ArrayList<>();
@@ -5717,7 +5717,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
        if (mServices.bringDownDisabledPackageServicesLocked(
                packageName, null, userId, evenPersistent, doit)) {
                packageName, null, userId, evenPersistent, true, doit)) {
            if (!doit) {
                return true;
            }
@@ -16590,7 +16590,9 @@ public final class ActivityManagerService extends ActivityManagerNative
                                boolean removed = Intent.ACTION_PACKAGE_REMOVED.equals(action);
                                boolean fullUninstall = removed &&
                                        !intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
                                if (!intent.getBooleanExtra(Intent.EXTRA_DONT_KILL_APP, false)) {
                                final boolean killProcess =
                                        !intent.getBooleanExtra(Intent.EXTRA_DONT_KILL_APP, false);
                                if (killProcess) {
                                    forceStopPackageLocked(ssp, UserHandle.getAppId(
                                            intent.getIntExtra(Intent.EXTRA_UID, -1)),
                                            false, true, true, false, fullUninstall, userId,
@@ -16610,7 +16612,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                                        mBatteryStatsService.notePackageUninstalled(ssp);
                                    }
                                } else {
                                    cleanupDisabledPackageComponentsLocked(ssp, userId,
                                    cleanupDisabledPackageComponentsLocked(ssp, userId, killProcess,
                                            intent.getStringArrayExtra(
                                                    Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST));
                                }