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

Commit a93c50cd 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:d8368be4f8fb7019ea24b4798f029301c704092c)
Merged-In: I7ae88eb62e435b9a77d2a724c5a953fe1f35b838
Change-Id: I7ae88eb62e435b9a77d2a724c5a953fe1f35b838
parent 737733c2
Loading
Loading
Loading
Loading
+31 −22
Original line number Original line Diff line number Diff line
@@ -1224,6 +1224,17 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {


            final long origId = Binder.clearCallingIdentity();
            final long origId = Binder.clearCallingIdentity();
            // TODO(b/64750076): Check if calling pid should really be -1.
            // 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()
                final int res = getActivityStartController()
                        .obtainStarter(intent, "startNextMatchingActivity")
                        .obtainStarter(intent, "startNextMatchingActivity")
                        .setCaller(r.app.getThread())
                        .setCaller(r.app.getThread())
@@ -1240,13 +1251,11 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                        .setRealCallingUid(r.launchedFromUid)
                        .setRealCallingUid(r.launchedFromUid)
                        .setActivityOptions(options)
                        .setActivityOptions(options)
                        .execute();
                        .execute();
            Binder.restoreCallingIdentity(origId);

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