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

Commit 48d0a489 authored by Christopher Tate's avatar Christopher Tate
Browse files

Full teardown when the user stops background apps

Not just moving its services out of the FGS mode.

The shell command for invoking this operation has changed; it is now

    adb shell cmd activity stop-app [--user NUM] PACKAGE

Bug: 192504071
Test: manual (Maps nav, YouTube, etc)
Test: atest CtsAppTestCases:android.app.cts.ServiceTest
Test: atest RunningFgsControllerTest
Change-Id: Ic14c1ba557460e25dd1ba2fd79462918e9a47377
parent db314870
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -528,9 +528,11 @@ public abstract class ActivityManagerInternal {
            Notification notification, int id, String pkg, @UserIdInt int userId);

    /**
     * Un-foreground all foreground services in the given app.
     * Fully stop the given app's processes without restoring service starts or
     * bindings, but without the other durable effects of the full-scale
     * "force stop" intervention.
     */
    public abstract void makeServicesNonForeground(String pkg, @UserIdInt int userId);
    public abstract void stopAppForUser(String pkg, @UserIdInt int userId);

    /**
     * If the given app has any FGSs whose notifications are in the given channel,
+1 −1
Original line number Diff line number Diff line
@@ -279,7 +279,7 @@ interface IActivityManager {
    List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState();
    boolean clearApplicationUserData(in String packageName, boolean keepState,
            in IPackageDataObserver observer, int userId);
    void makeServicesNonForeground(in String packageName, int userId);
    void stopAppForUser(in String packageName, int userId);
    /** Returns {@code false} if the callback could not be registered, {@true} otherwise. */
    boolean registerForegroundServiceObserver(in IForegroundServiceObserver callback);
    @UnsupportedAppUsage
+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ class RunningFgsControllerImpl @Inject constructor(
    override fun stopFgs(userId: Int, packageName: String) {
        init()
        try {
            activityManager.makeServicesNonForeground(packageName, userId)
            activityManager.stopAppForUser(packageName, userId)
        } catch (e: RemoteException) {
            e.rethrowFromSystemServer()
        }
+1 −1
Original line number Diff line number Diff line
@@ -246,7 +246,7 @@ public class RunningFgsControllerTest extends SysuiTestCase {
    public void testStopFgs() throws RemoteException {
        String pkgName = "package.name";
        mController.stopFgs(0, pkgName);
        verify(mActivityManager).makeServicesNonForeground(pkgName, 0);
        verify(mActivityManager).stopAppForUser(pkgName, 0);
    }

    /**
+0 −23
Original line number Diff line number Diff line
@@ -5138,29 +5138,6 @@ public final class ActiveServices {
        return didSomething;
    }

    void makeServicesNonForegroundLocked(final String pkg, final @UserIdInt int userId) {
        final ServiceMap smap = mServiceMap.get(userId);
        if (smap != null) {
            ArrayList<ServiceRecord> fgsList = new ArrayList<>();
            for (int i = 0; i < smap.mServicesByInstanceName.size(); i++) {
                final ServiceRecord sr = smap.mServicesByInstanceName.valueAt(i);
                if (sr.appInfo.packageName.equals(pkg) && sr.isForeground) {
                    fgsList.add(sr);
                }
            }

            final int numServices = fgsList.size();
            if (DEBUG_FOREGROUND_SERVICE) {
                Slog.i(TAG_SERVICE, "Forcing " + numServices + " services out of foreground in u"
                        + userId + "/" + pkg);
            }
            for (int i = 0; i < numServices; i++) {
                final ServiceRecord sr = fgsList.get(i);
                setServiceForegroundInnerLocked(sr, 0, null, Service.STOP_FOREGROUND_REMOVE, 0);
            }
        }
    }

    @GuardedBy("mAm")
    private void signalForegroundServiceObserversLocked(ServiceRecord r) {
        final int num = mFgsObservers.beginBroadcast();
Loading