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

Commit 6deec52f authored by Louis Chang's avatar Louis Chang
Browse files

Fixes re-setting activity type when embed activity in split-screen

An exception was thrown by setting the activity's type to
TYPE_UNDEFINED while the activity was already set as TYPE_STANDARD.
It happens while embedding an activity (which reparents the activity
into a TaskFragment) in split-screen.

Activity is no longer be the direct child of a leaf Task while the
activity being embedded. So, we should use WC#getActivity() vs.
checking if the task has any child while updating the activity type.

Bug: 208803173
Test: Drag settings from taskbar into split
Change-Id: Ia2e3dc251ed1908d0b088794853760c4f511138e
parent 3f7eca56
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1451,11 +1451,11 @@ class Task extends TaskFragment {
    }

    /** Called when an {@link ActivityRecord} is added as a descendant */
    void onDescendantActivityAdded(boolean hadChild, int activityType, ActivityRecord r) {
    void onDescendantActivityAdded(boolean hadActivity, int activityType, ActivityRecord r) {
        warnForNonLeafTask("onDescendantActivityAdded");

        // Only set this based on the first activity
        if (!hadChild) {
        if (!hadActivity) {
            if (r.getActivityType() == ACTIVITY_TYPE_UNDEFINED) {
                // Normally non-standard activity type for the activity record will be set when the
                // object is created, however we delay setting the standard application type until
+4 −3
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;

@@ -1659,8 +1660,8 @@ class TaskFragment extends WindowContainer<WindowContainer> {
        boolean isAddingActivity = child.asActivityRecord() != null;
        final Task task = isAddingActivity ? getTask() : null;

        // If this task had any child before we added this one.
        boolean taskHadChild = task != null && task.hasChild();
        // If this task had any activity before we added this one.
        boolean taskHadActivity = task != null && task.getActivity(Objects::nonNull) != null;
        // getActivityType() looks at the top child, so we need to read the type before adding
        // a new child in case the new child is on top and UNDEFINED.
        final int activityType = task != null ? task.getActivityType() : ACTIVITY_TYPE_UNDEFINED;
@@ -1669,7 +1670,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {

        if (isAddingActivity && task != null) {
            child.asActivityRecord().inHistory = true;
            task.onDescendantActivityAdded(taskHadChild, activityType, child.asActivityRecord());
            task.onDescendantActivityAdded(taskHadActivity, activityType, child.asActivityRecord());
        }
    }