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

Commit 6e0b27a1 authored by Charles Chen's avatar Charles Chen
Browse files

Fix SplitContainer not updated when folded.

The root cause is that TaskFragmentParentInfo wasn't be dispatched
when there's a display or visibility change because we didn't
implement getTaskFragment() in TaskFragment and it led to
the TskFragment can't return itself if the predicate function
returns true.

This CL fixes WC#getTaskFragment and changes to dispatch
Task#shouldBeVisible instead of Task#isVisibleRequested.
The reason is that the visibleRequested change is not early enough for
the scenario that device is folded from unfolded state, and lead to
Settings flickering.

Test: manual - open Settings and fold the device
Test: atest TaskTests#testGetTaskFragment
Test: atest TaskFragmentOrganizerControllerTest ActivityRecordTests
fixes: 249055633
Change-Id: Ie1c56758697d14b426c9ed713da84e49c9f880d8
parent 36f16a2f
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -33,19 +33,19 @@ public class TaskFragmentParentInfo implements Parcelable {

    private final int mDisplayId;

    private final boolean mVisibleRequested;
    private final boolean mVisible;

    public TaskFragmentParentInfo(@NonNull Configuration configuration, int displayId,
            boolean visibleRequested) {
            boolean visible) {
        mConfiguration.setTo(configuration);
        mDisplayId = displayId;
        mVisibleRequested = visibleRequested;
        mVisible = visible;
    }

    public TaskFragmentParentInfo(@NonNull TaskFragmentParentInfo info) {
        mConfiguration.setTo(info.getConfiguration());
        mDisplayId = info.mDisplayId;
        mVisibleRequested = info.mVisibleRequested;
        mVisible = info.mVisible;
    }

    /** The {@link Configuration} of the parent Task */
@@ -62,9 +62,9 @@ public class TaskFragmentParentInfo implements Parcelable {
        return mDisplayId;
    }

    /** Whether the parent Task is requested to be visible or not */
    public boolean isVisibleRequested() {
        return mVisibleRequested;
    /** Whether the parent Task is visible or not */
    public boolean isVisible() {
        return mVisible;
    }

    /**
@@ -80,7 +80,7 @@ public class TaskFragmentParentInfo implements Parcelable {
            return false;
        }
        return getWindowingMode() == that.getWindowingMode() && mDisplayId == that.mDisplayId
                && mVisibleRequested == that.mVisibleRequested;
                && mVisible == that.mVisible;
    }

    @WindowConfiguration.WindowingMode
@@ -93,7 +93,7 @@ public class TaskFragmentParentInfo implements Parcelable {
        return TaskFragmentParentInfo.class.getSimpleName() + ":{"
                + "config=" + mConfiguration
                + ", displayId=" + mDisplayId
                + ", visibleRequested=" + mVisibleRequested
                + ", visible=" + mVisible
                + "}";
    }

@@ -114,14 +114,14 @@ public class TaskFragmentParentInfo implements Parcelable {
        final TaskFragmentParentInfo that = (TaskFragmentParentInfo) obj;
        return mConfiguration.equals(that.mConfiguration)
                && mDisplayId == that.mDisplayId
                && mVisibleRequested == that.mVisibleRequested;
                && mVisible == that.mVisible;
    }

    @Override
    public int hashCode() {
        int result = mConfiguration.hashCode();
        result = 31 * result + mDisplayId;
        result = 31 * result + (mVisibleRequested ? 1 : 0);
        result = 31 * result + (mVisible ? 1 : 0);
        return result;
    }

@@ -129,13 +129,13 @@ public class TaskFragmentParentInfo implements Parcelable {
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        mConfiguration.writeToParcel(dest, flags);
        dest.writeInt(mDisplayId);
        dest.writeBoolean(mVisibleRequested);
        dest.writeBoolean(mVisible);
    }

    private TaskFragmentParentInfo(Parcel in) {
        mConfiguration.readFromParcel(in);
        mDisplayId = in.readInt();
        mVisibleRequested = in.readBoolean();
        mVisible = in.readBoolean();
    }

    public static final Creator<TaskFragmentParentInfo> CREATOR =
+1 −1
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ class TaskContainer {
    void updateTaskFragmentParentInfo(@NonNull TaskFragmentParentInfo info) {
        mConfiguration.setTo(info.getConfiguration());
        mDisplayId = info.getDisplayId();
        mIsVisible = info.isVisibleRequested();
        mIsVisible = info.isVisible();
    }

    /**
+6 −2
Original line number Diff line number Diff line
@@ -3525,12 +3525,16 @@ class Task extends TaskFragment {
     * {@link android.window.TaskFragmentOrganizer}
     */
    TaskFragmentParentInfo getTaskFragmentParentInfo() {
        return new TaskFragmentParentInfo(getConfiguration(), getDisplayId(), isVisibleRequested());
        return new TaskFragmentParentInfo(getConfiguration(), getDisplayId(),
                shouldBeVisible(null /* starting */));
    }

    @Override
    void onActivityVisibleRequestedChanged() {
        if (mVisibleRequested != isVisibleRequested()) {
        final boolean prevVisibleRequested = mVisibleRequested;
        // mVisibleRequested is updated in super method.
        super.onActivityVisibleRequestedChanged();
        if (prevVisibleRequested != mVisibleRequested) {
            sendTaskFragmentParentInfoChangedIfNeeded();
        }
    }
+15 −1
Original line number Diff line number Diff line
@@ -2690,12 +2690,26 @@ class TaskFragment extends WindowContainer<WindowContainer> {
            return;
        }
        mVisibleRequested = isVisibleRequested;
        final TaskFragment parentTf = getParent().asTaskFragment();
        final WindowContainer<?> parent = getParent();
        if (parent == null) {
            return;
        }
        final TaskFragment parentTf = parent.asTaskFragment();
        if (parentTf != null) {
            parentTf.onActivityVisibleRequestedChanged();
        }
    }

    @Nullable
    @Override
    TaskFragment getTaskFragment(Predicate<TaskFragment> callback) {
        final TaskFragment taskFragment = super.getTaskFragment(callback);
        if (taskFragment != null) {
            return taskFragment;
        }
        return callback.test(this) ? this : null;
    }

    String toFullString() {
        final StringBuilder sb = new StringBuilder(128);
        sb.append(this);
+1 −0
Original line number Diff line number Diff line
@@ -920,6 +920,7 @@ public class TaskFragmentOrganizerController extends ITaskFragmentOrganizerContr
        for (int i = 0, n = pendingEvents.size(); i < n; i++) {
            final PendingTaskFragmentEvent event = pendingEvents.get(i);
            final Task task = event.mTaskFragment != null ? event.mTaskFragment.getTask() : null;
            // TODO(b/251132298): move visibility check to the client side.
            if (task != null && (task.lastActiveTime <= event.mDeferTime
                    || !(isTaskVisible(task, visibleTasks, invisibleTasks)
                    || shouldSendEventWhenTaskInvisible(event)))) {
Loading