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

Commit d85e500f authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Added limit of descendant amount when adding activity to task

This avoid bad apps to consume available layers of surfaceflinger.

The tree weight is a simple field (instead of iterating activities)
to indicate the total amount of descendant window containers.

Background launch restriction only disallow launching new task from
background. If the target task is an existing own task, the new
activity will still be added.

When exceeding this limit, the target task will be removed, so if
a problematical loop is still starting activity, it will becomes
a new task that will be blocked by background launch restriction.

Bug: 268590786
Bug: 270477256
Test: Endless loop to start activities in its own task in
      background. There won't have Surface$OutOfResourcesException.
Change-Id: Ief0d23477bd095f7e60a0a9079b66b3bc88f6df9
parent 57e90d8f
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -171,6 +171,12 @@ class ActivityStarter {

    private static final int INVALID_LAUNCH_MODE = -1;

    /**
     * Avoid problematical apps from occupying system resources (e.g. the amount of surface) by
     * launching too many activities in a task.
     */
    private static final long MAX_TASK_WEIGHT_FOR_ADDING_ACTIVITY = 300;

    /**
     * Feature flag to protect PendingIntent being abused to start background activity.
     */
@@ -1647,6 +1653,13 @@ class ActivityStarter {
        }

        if (targetTask != null) {
            if (targetTask.getTreeWeight() > MAX_TASK_WEIGHT_FOR_ADDING_ACTIVITY) {
                Slog.e(TAG, "Remove " + targetTask + " because it has contained too many"
                        + " activities or windows (abort starting " + r
                        + " from uid=" + mCallingUid);
                targetTask.removeImmediately("bulky-task");
                return START_ABORTED;
            }
            mPriorAboveTask = TaskDisplayArea.getRootTaskAbove(targetTask.getRootTask());
        }