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

Commit 6015866a authored by Eric Lin's avatar Eric Lin Committed by Android (Google) Code Review
Browse files

Merge "Refactor BubblesTransitionObserver#onTransitionReady." into main

parents 88098a86 8c556702
Loading
Loading
Loading
Loading
+30 −13
Original line number Diff line number Diff line
@@ -13,9 +13,11 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.bubbles;

import static android.app.ActivityTaskManager.INVALID_TASK_ID;

import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BUBBLES_NOISY;

import android.app.ActivityManager;
@@ -51,38 +53,53 @@ public class BubblesTransitionObserver implements Transitions.TransitionObserver
    public void onTransitionReady(@NonNull IBinder transition, @NonNull TransitionInfo info,
            @NonNull SurfaceControl.Transaction startTransaction,
            @NonNull SurfaceControl.Transaction finishTransaction) {
        for (TransitionInfo.Change change : info.getChanges()) {
            final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
            // We only care about opens / move to fronts when bubbles are expanded & not animating.
            if (taskInfo == null
                    || taskInfo.taskId == INVALID_TASK_ID
                    || !TransitionUtil.isOpeningType(change.getMode())
                    || mBubbleController.isStackAnimating()

        // --- Pre-conditions (Loop-invariant checks) ---
        // If bubbles aren't expanded, are animating, or no bubble is selected,
        // we don't need to process any transitions for collapsing.
        if (mBubbleController.isStackAnimating()
                || !mBubbleData.isExpanded()
                || mBubbleData.getSelectedBubble() == null) {
            return;
        }

        final int expandedTaskId = mBubbleData.getSelectedBubble().getTaskId();
        // If expanded task id is invalid, we don't need to process any transitions for collapsing.
        if (expandedTaskId == INVALID_TASK_ID) {
            return;
        }

        final int bubbleViewDisplayId = mBubbleController.getCurrentViewDisplayId();
        for (TransitionInfo.Change change : info.getChanges()) {
            // We only care about opens / move to fronts.
            if (!TransitionUtil.isOpeningType(change.getMode())) {
                continue;
            }
            final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
            // We only handle task transitions.
            if (taskInfo == null || taskInfo.taskId == INVALID_TASK_ID) {
                continue;
            }
            final int expandedId = mBubbleData.getSelectedBubble().getTaskId();
            // If the opening task id is the same as the expanded bubble, skip collapsing
            // because it is our bubble that is opening.
            if (expandedId == INVALID_TASK_ID || expandedId == taskInfo.taskId) {
            if (taskInfo.taskId == expandedTaskId) {
                continue;
            }
            // If the opening task is on a different display, skip collapsing because the task
            // opening does not visually overlap with the bubbles.
            final int bubbleViewDisplayId = mBubbleController.getCurrentViewDisplayId();
            if (taskInfo.displayId != bubbleViewDisplayId) {
                continue;
            }
            // If the opening task was launched by another bubble, skip collapsing the existing one
            // since BubbleTransitions will start a new bubble for it
            if (BubbleAnythingFlagHelper.enableCreateAnyBubble() && taskInfo.isAppBubble) {
                ProtoLog.d(WM_SHELL_BUBBLES_NOISY,
                        "TransitionObserver.onTransitionReady(): skipping app bubble for taskId=%d",
                        taskInfo.taskId);
                ProtoLog.d(WM_SHELL_BUBBLES_NOISY, "TransitionObserver.onTransitionReady(): "
                        + "skipping app bubble for taskId=%d", taskInfo.taskId);
                continue;
            }

            mBubbleData.setExpanded(false);
            return;
        }
    }