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

Commit d8368be4 authored by Christophe Pinelli's avatar Christophe Pinelli
Browse files

Restrict activity launch when caller is running in the background

Test: test on device + atest-src BackgroundActivityLaunchTest#testBackgroundActivityBlockedInStartNextMatchingActivity
Bug: 230492947
Merged-In: I1a0c13e74622d301866efaca1b5351a6b241ebe5
Change-Id: I7ae88eb62e435b9a77d2a724c5a953fe1f35b838
parent 71e7d412
Loading
Loading
Loading
Loading
+31 −22
Original line number Diff line number Diff line
@@ -1223,6 +1223,17 @@ 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())
@@ -1239,13 +1250,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;
        }
    }