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

Commit e23bf10e authored by Christophe Pinelli's avatar Christophe Pinelli Committed by Android Build Coastguard Worker
Browse files

Restrict activity launch when caller is running in the background

Test: test on device + atest-src BackgroundActivityLaunchTest#testBackgroundActivityBlockedInStartNextMatchingActivity
Bug: 230492947
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3e9da3ec4705b072dbe8a10e8ffc841f4928381c)
Merged-In: Ie774b142a7fab12d596ccd64872b781e3825e9ba
Change-Id: Ie774b142a7fab12d596ccd64872b781e3825e9ba
parent a176edb7
Loading
Loading
Loading
Loading
+31 −22
Original line number Diff line number Diff line
@@ -1364,6 +1364,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())
@@ -1380,13 +1391,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;
        }
    }