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

Commit 29967216 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge changes Id07d7df4,Ieb47095b into main

* changes:
  Support adding task listeners for incoming tasks
  Log remove reason string for easier debugging
parents 2ef017c6 09e17a63
Loading
Loading
Loading
Loading
+53 −8
Original line number Diff line number Diff line
@@ -171,6 +171,9 @@ public class ShellTaskOrganizer extends TaskOrganizer {
    /** @see #setPendingLaunchCookieListener */
    private final ArrayMap<IBinder, TaskListener> mLaunchCookieToListener = new ArrayMap<>();

    /** @see #setPendingTaskListener(int, TaskListener)  */
    private final ArrayMap<Integer, TaskListener> mPendingTaskToListener = new ArrayMap<>();

    // Keeps track of taskId's with visible locusIds. Used to notify any {@link LocusIdListener}s
    // that might be set.
    private final SparseArray<LocusId> mVisibleTasksWithLocusId = new SparseArray<>();
@@ -365,7 +368,7 @@ public class ShellTaskOrganizer extends TaskOrganizer {
    }

    /**
     * Adds a listener for a specific task id.
     * Adds a listener for a specific task id.  This only applies if
     */
    public void addListenerForTaskId(TaskListener listener, int taskId) {
        synchronized (mLock) {
@@ -383,7 +386,12 @@ public class ShellTaskOrganizer extends TaskOrganizer {

            final TaskAppearedInfo info = mTasks.get(taskId);
            if (info == null) {
                throw new IllegalArgumentException("addListenerForTaskId unknown taskId=" + taskId);
                ProtoLog.v(WM_SHELL_TASK_ORG, "Queueing pending listener");
                // The caller may have received a transition with the task before the organizer
                // was notified of the task appearing, so set a pending task listener for the
                // task to be retrieved when the task actually appears
                mPendingTaskToListener.put(taskId, listener);
                return;
            }

            final TaskListener oldListener = getTaskListener(info.getTaskInfo());
@@ -423,6 +431,14 @@ public class ShellTaskOrganizer extends TaskOrganizer {
    public void removeListener(TaskListener listener) {
        synchronized (mLock) {
            ProtoLog.v(WM_SHELL_TASK_ORG, "Remove listener=%s", listener);

            // Remove all occurrences of the pending listener
            for (int i = mPendingTaskToListener.size() - 1; i >= 0; --i) {
                if (mPendingTaskToListener.valueAt(i) == listener) {
                    mPendingTaskToListener.removeAt(i);
                }
            }

            final int index = mTaskListeners.indexOfValue(listener);
            if (index == -1) {
                Log.w(TAG, "No registered listener found");
@@ -438,7 +454,7 @@ public class ShellTaskOrganizer extends TaskOrganizer {
                tasks.add(data);
            }

            // Remove listener, there can be the multiple occurrences, so search the whole list.
            // Remove occurrences of the listener
            for (int i = mTaskListeners.size() - 1; i >= 0; --i) {
                if (mTaskListeners.valueAt(i) == listener) {
                    mTaskListeners.removeAt(i);
@@ -456,9 +472,11 @@ public class ShellTaskOrganizer extends TaskOrganizer {

    /**
     * Associated a listener to a pending launch cookie so we can route the task later once it
     * appears.
     * appears.  If both this and a pending task-id listener is set, then this will take priority.
     */
    public void setPendingLaunchCookieListener(IBinder cookie, TaskListener listener) {
        ProtoLog.v(WM_SHELL_TASK_ORG, "setPendingLaunchCookieListener(): cookie=%s listener=%s",
                cookie, listener);
        synchronized (mLock) {
            mLaunchCookieToListener.put(cookie, listener);
        }
@@ -904,7 +922,7 @@ public class ShellTaskOrganizer extends TaskOrganizer {
    }

    private TaskListener getTaskListener(RunningTaskInfo runningTaskInfo,
            boolean removeLaunchCookieIfNeeded) {
            boolean removePendingIfNeeded) {

        final int taskId = runningTaskInfo.taskId;
        TaskListener listener;
@@ -916,15 +934,34 @@ public class ShellTaskOrganizer extends TaskOrganizer {
            listener = mLaunchCookieToListener.get(cookie);
            if (listener == null) continue;

            if (removeLaunchCookieIfNeeded) {
            if (removePendingIfNeeded) {
                ProtoLog.v(WM_SHELL_TASK_ORG, "Migrating cookie listener to task: taskId=%d",
                        runningTaskInfo.taskId);
                        taskId);
                // Remove the cookie and add the listener.
                mLaunchCookieToListener.remove(cookie);
                if (mPendingTaskToListener.containsKey(taskId)
                        && mPendingTaskToListener.get(taskId) != listener) {
                    Log.w(TAG, "Conflicting pending task listeners reported for taskId=" + taskId);
                }
                mPendingTaskToListener.remove(taskId);
                mTaskListeners.put(taskId, listener);
            }
            return listener;
        }

        // Next priority goes to the pending task id listener
        if (mPendingTaskToListener.containsKey(taskId)) {
            listener = mPendingTaskToListener.get(taskId);
            if (listener != null) {
                if (removePendingIfNeeded) {
                    ProtoLog.v(WM_SHELL_TASK_ORG, "Migrating pending listener to task: taskId=%d",
                            taskId);
                    mPendingTaskToListener.remove(taskId);
                    mTaskListeners.put(taskId, listener);
                }
                return listener;
            }
        }

        // Next priority goes to taskId specific listeners.
        listener = mTaskListeners.get(taskId);
@@ -1025,13 +1062,21 @@ public class ShellTaskOrganizer extends TaskOrganizer {
            }

            pw.println();
            pw.println(innerPrefix + mLaunchCookieToListener.size() + " Launch Cookies");
            pw.println(innerPrefix + mLaunchCookieToListener.size()
                    + " Pending launch cookies listeners");
            for (int i = mLaunchCookieToListener.size() - 1; i >= 0; --i) {
                final IBinder key = mLaunchCookieToListener.keyAt(i);
                final TaskListener listener = mLaunchCookieToListener.valueAt(i);
                pw.println(innerPrefix + "#" + i + " cookie=" + key + " listener=" + listener);
            }

            pw.println();
            pw.println(innerPrefix + mPendingTaskToListener.size() + " Pending task listeners");
            for (int i = mPendingTaskToListener.size() - 1; i >= 0; --i) {
                final int taskId = mPendingTaskToListener.keyAt(i);
                final TaskListener listener = mPendingTaskToListener.valueAt(i);
                pw.println(innerPrefix + "#" + i + " taskId=" + taskId + " listener=" + listener);
            }
        }
    }
}
+10 −7
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.bubbles;
import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIVATE;
import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_BUBBLES;
import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.wm.shell.bubbles.Bubbles.dismissReasonToString;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BUBBLES;

import android.annotation.NonNull;
@@ -819,8 +820,8 @@ public class BubbleData {
            if (hasOverflowBubbleWithKey(key)
                    && shouldRemoveHiddenBubble) {
                Bubble b = getOverflowBubbleWithKey(key);
                ProtoLog.d(WM_SHELL_BUBBLES, "doRemove - cancel overflow bubble=%s reason=%d",
                        key, reason);
                ProtoLog.d(WM_SHELL_BUBBLES, "doRemove - cancel overflow bubble=%s reason=%s",
                        key, dismissReasonToString(reason));
                if (b != null) {
                    b.stopInflation();
                }
@@ -834,8 +835,8 @@ public class BubbleData {
            }
            if (hasSuppressedBubbleWithKey(key) && shouldRemoveHiddenBubble) {
                Bubble b = getSuppressedBubbleWithKey(key);
                ProtoLog.d(WM_SHELL_BUBBLES, "doRemove - cancel suppressed bubble=%s reason=%d",
                        key, reason);
                ProtoLog.d(WM_SHELL_BUBBLES, "doRemove - cancel suppressed bubble=%s reason=%s",
                        key, dismissReasonToString(reason));
                if (b != null) {
                    mSuppressedBubbles.remove(b.getLocusId());
                    b.stopInflation();
@@ -845,7 +846,8 @@ public class BubbleData {
            return;
        }
        Bubble bubbleToRemove = mBubbles.get(indexToRemove);
        ProtoLog.d(WM_SHELL_BUBBLES, "doRemove=%s reason=%d", bubbleToRemove.getKey(), reason);
        ProtoLog.d(WM_SHELL_BUBBLES, "doRemove=%s reason=%s", bubbleToRemove.getKey(),
                dismissReasonToString(reason));
        bubbleToRemove.stopInflation();
        overflowBubble(reason, bubbleToRemove);

@@ -951,7 +953,8 @@ public class BubbleData {
                || reason == Bubbles.DISMISS_RELOAD_FROM_DISK)) {
            return;
        }
        ProtoLog.d(WM_SHELL_BUBBLES, "overflowBubble=%s reason=%d", bubble.getKey(), reason);
        ProtoLog.d(WM_SHELL_BUBBLES, "overflowBubble=%s reason=%s", bubble.getKey(),
                dismissReasonToString(reason));
        mLogger.logOverflowAdd(bubble, mPositioner.isShowingInBubbleBar(), reason);
        if (mOverflowBubbles.isEmpty()) {
            mStateChange.showOverflowChanged = true;
@@ -975,7 +978,7 @@ public class BubbleData {
    }

    public void dismissAll(@DismissReason int reason) {
        ProtoLog.d(WM_SHELL_BUBBLES, "dismissAll reason=%d", reason);
        ProtoLog.d(WM_SHELL_BUBBLES, "dismissAll reason=%s", dismissReasonToString(reason));
        if (mBubbles.isEmpty() && mSuppressedBubbles.isEmpty()) {
            return;
        }
+3 −2
Original line number Diff line number Diff line
@@ -123,8 +123,9 @@ public class BubbleTaskViewListener implements TaskView.Listener {
        // Post to keep the lifecycle normal
        // TODO - currently based on type, really it's what the "launch item" is.
        mParentView.post(() -> {
            ProtoLog.d(WM_SHELL_BUBBLES, "onInitialized: calling startActivity, bubble=%s",
                    getBubbleKey());
            ProtoLog.d(WM_SHELL_BUBBLES,
                    "onInitialized: calling startActivity, bubble=%s hasPreparingTransition=%b",
                    getBubbleKey(), mBubble.getPreparingTransition() != null);
            try {
                options.setTaskAlwaysOnTop(true /* alwaysOnTop */);
                options.setPendingIntentBackgroundActivityStartMode(
+3 −1
Original line number Diff line number Diff line
@@ -694,7 +694,9 @@ public class BubbleTransitions {
            mTaskViewTransitions.prepareOpenAnimation(tv, true /* new */, startT, mFinishT,
                    (ActivityManager.RunningTaskInfo) mTaskInfo, mTaskLeash, mFinishWct);
            // Add the task view task listener manually since we aren't going through
            // TaskViewTransitions (which normally sets up the listener via a pending launch cookie
            // TaskViewTransitions (which normally sets up the listener via a pending launch cookie)
            // Note: In this path, because a new task is being started, the transition may receive
            // the transition for the task before the organizer does
            mTaskOrganizer.addListenerForTaskId(tv, mTaskInfo.taskId);

            if (mFinishWct.isEmpty()) {
+27 −0
Original line number Diff line number Diff line
@@ -312,6 +312,33 @@ public interface Bubbles {
     */
    boolean canShowBubbleNotification();

    /**
     * Returns the string representation of the given dismiss reason.
     */
    public static String dismissReasonToString(@DismissReason int dismissReason) {
        switch (dismissReason) {
            case DISMISS_USER_GESTURE: return "USER_GESTURE";
            case DISMISS_AGED: return "AGED";
            case DISMISS_TASK_FINISHED: return "TASK_FINISHED";
            case DISMISS_BLOCKED: return "BLOCKED";
            case DISMISS_NOTIF_CANCEL: return "NOTIF_CANCEL";
            case DISMISS_ACCESSIBILITY_ACTION: return "ACCESSIBILITY_ACTION";
            case DISMISS_NO_LONGER_BUBBLE: return "NO_LONGER_BUBBLE";
            case DISMISS_USER_CHANGED: return "USER_CHANGED";
            case DISMISS_GROUP_CANCELLED: return "GROUP_CANCELLED";
            case DISMISS_INVALID_INTENT: return "INVALID_INTENT";
            case DISMISS_OVERFLOW_MAX_REACHED: return "OVERFLOW_MAX_REACHED";
            case DISMISS_SHORTCUT_REMOVED: return "SHORTCUT_REMOVED";
            case DISMISS_PACKAGE_REMOVED: return "PACKAGE_REMOVED";
            case DISMISS_NO_BUBBLE_UP: return "NO_BUBBLE_UP";
            case DISMISS_RELOAD_FROM_DISK: return "RELOAD_FROM_DISK";
            case DISMISS_USER_ACCOUNT_REMOVED: return "USER_ACCOUNT_REMOVED";
            case DISMISS_SWITCH_TO_STACK: return "SWITCH_TO_STACK";
            case DISMISS_USER_GESTURE_FROM_LAUNCHER: return "USER_GESTURE_FROM_LAUNCHER";
            default: return "UNKNOWN";
        }
    }

    /**
     * A listener to be notified of bubble state changes, used by launcher to render bubbles in
     * its process.
Loading