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

Commit 83a57e54 authored by Christophe Pinelli's avatar Christophe Pinelli Committed by Brian Egizi
Browse files

Restrict activity launch when caller is running in the background

Cherry picked Ie3bc5bd88bfd3bd4777210c0740ad34ea6d3311e to master due to b/286408867.

Code was merged via `-s ours` and is missing even though the sha exists on the target branch. Cherry pick is required to bring in the code.

Manually remove the "Merged in" directive to allow for downstream propagation.

Test: atest BackgroundActivityLaunchTest#testBackgroundActivityBlockedInStartNextMatchingActivity
Bug: 230492947
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e3c537ddea5ce8b28eeb89300ef602753cfe42a4)
Change-Id: I61477a7bc6e6bffe09dba79c37787b81bdc94a78
parent ee0d5683
Loading
Loading
Loading
Loading
+31 −21
Original line number Diff line number Diff line
@@ -1411,6 +1411,18 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {

            final long origId = Binder.clearCallingIdentity();
            // TODO(b/64750076): Check if calling pid should really be -1.
            try {
                if (options == null) {
                    options = new SafeActivityOptions(ActivityOptions.makeBasic());
                }

                // Fixes b/230492947
                // Prevents background activity launch through #startNextMatchingActivity
                // An activity going into the background could still go back to the foreground
                // if the intent used matches both:
                // - the activity in the background
                // - a second activity.
                options.getOptions(r).setAvoidMoveToFront();
                final int res = getActivityStartController()
                        .obtainStarter(intent, "startNextMatchingActivity")
                        .setCaller(r.app.getThread())
@@ -1427,13 +1439,11 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                        .setRealCallingUid(r.launchedFromUid)
                        .setActivityOptions(options)
                        .execute();
            Binder.restoreCallingIdentity(origId);

                r.finishing = wasFinishing;
            if (res != ActivityManager.START_SUCCESS) {
                return false;
                return res == ActivityManager.START_SUCCESS;
            } finally {
                Binder.restoreCallingIdentity(origId);
            }
            return true;
        }
    }