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

Commit c806d90e authored by Chong Zhang's avatar Chong Zhang
Browse files

Show toast for non-resizeble docked task under the task itself

Move the show toast code to WM, so that we can schedule to show the
toast when the app becomes visible. Otherwise the toast always shows
up a long time before the app itself.

bug: 25433902
bug: 25873338

Change-Id: I879f8e0570829934fac806c2861bda9f65e08969
parent 98fe08fe
Loading
Loading
Loading
Loading
+9 −11
Original line number Diff line number Diff line
@@ -184,7 +184,6 @@ public final class ActivityStackSupervisor implements DisplayListener {
    static final int CONTAINER_CALLBACK_TASK_LIST_EMPTY = FIRST_SUPERVISOR_STACK_MSG + 11;
    static final int LAUNCH_TASK_BEHIND_COMPLETE = FIRST_SUPERVISOR_STACK_MSG + 12;
    static final int SHOW_LOCK_TASK_ESCAPE_MESSAGE_MSG = FIRST_SUPERVISOR_STACK_MSG + 13;
    static final int SHOW_NON_RESIZEABLE_DOCK_TOAST = FIRST_SUPERVISOR_STACK_MSG + 14;

    private static final String VIRTUAL_DISPLAY_BASE_NAME = "ActivityViewVirtualDisplay";

@@ -2592,6 +2591,11 @@ public final class ActivityStackSupervisor implements DisplayListener {
            mService.setFocusedActivityLocked(r, "startedActivity");
        }
        updateUserStackLocked(r.userId, targetStack);

        if (!r.task.mResizeable && isStackDockedInEffect(targetStack.mStackId)) {
            showNonResizeableDockToast(r.task.taskId);
        }

        return ActivityManager.START_SUCCESS;
    }

@@ -3393,7 +3397,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
        resumeTopActivitiesLocked();

        if (!task.mResizeable && isStackDockedInEffect(stackId)) {
            showNonResizeableDockToast();
            showNonResizeableDockToast(taskId);
        }
    }

@@ -4327,8 +4331,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
        }
    }

    void showNonResizeableDockToast() {
        mHandler.sendEmptyMessage(SHOW_NON_RESIZEABLE_DOCK_TOAST);
    private void showNonResizeableDockToast(int taskId) {
        mWindowManager.scheduleShowNonResizeableDockToast(taskId);
    }

    void showLockTaskToast() {
@@ -4643,13 +4647,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
                        }
                    }
                } break;
                case SHOW_NON_RESIZEABLE_DOCK_TOAST: {
                    final Toast toast = Toast.makeText(
                            mService.mContext,
                            mService.mContext.getString(R.string.dock_non_resizeble_text),
                            Toast.LENGTH_LONG);
                    toast.show();
                } break;

            }
        }
    }
+45 −0
Original line number Diff line number Diff line
@@ -26,6 +26,11 @@ import static com.android.server.wm.WindowManagerService.TAG;
import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
import static com.android.server.wm.WindowManagerService.DEBUG_STACK;
import static com.android.server.wm.WindowManagerService.H.RESIZE_TASK;
import static com.android.server.wm.WindowManagerService.H.SHOW_NON_RESIZEABLE_DOCK_TOAST;
import static android.view.WindowManager.DOCKED_INVALID;
import static android.view.WindowManager.DOCKED_LEFT;
import static android.view.WindowManager.DOCKED_RIGHT;
import static android.view.WindowManager.DOCKED_TOP;

import android.app.ActivityManager.StackId;
import android.content.res.Configuration;
@@ -76,6 +81,11 @@ class Task implements DimLayer.DimLayerUser {
    // Whether the task is resizeable
    private boolean mResizeable;

    // Whether we need to show toast about the app being non-resizeable when it becomes visible.
    // This flag is set when a non-resizeable task is docked (or side-by-side). It's cleared
    // after we show the toast.
    private boolean mShowNonResizeableDockToast;

    // Whether the task is currently being drag-resized
    private boolean mDragResizing;

@@ -92,6 +102,41 @@ class Task implements DimLayer.DimLayerUser {
        return mStack.getDisplayContent();
    }

    void setShowNonResizeableDockToast() {
        mShowNonResizeableDockToast = true;
    }

    void scheduleShowNonResizeableDockToastIfNeeded() {
        if (!mShowNonResizeableDockToast) {
            return;
        }
        final DisplayContent displayContent = mStack.getDisplayContent();
        // If docked stack is not yet visible, we don't want to show the toast yet,
        // since we need the visible rect of the docked task to position the toast.
        if (displayContent == null || displayContent.getDockedStackLocked() == null) {
            return;
        }

        mShowNonResizeableDockToast = false;

        final int dockSide = mStack.getDockSide();
        int xOffset = 0;
        int yOffset = 0;
        if (dockSide != DOCKED_INVALID) {
            mStack.getBounds(mTmpRect);
            displayContent.getLogicalDisplayRect(mTmpRect2);

            if (dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT) {
                xOffset = mTmpRect.centerX() - mTmpRect2.centerX();
            } else if (dockSide == DOCKED_TOP) {
                // We don't adjust for DOCKED_BOTTOM case since it's already at the bottom.
                yOffset = mTmpRect2.bottom - mTmpRect.bottom;
            }
            mService.mH.obtainMessage(
                    SHOW_NON_RESIZEABLE_DOCK_TOAST, xOffset, yOffset).sendToTarget();
        }
    }

    void addAppToken(int addPos, AppWindowToken wtoken) {
        final int lastPos = mAppTokens.size();
        if (addPos >= lastPos) {
+3 −2
Original line number Diff line number Diff line
@@ -658,10 +658,11 @@ public class TaskStack implements DimLayer.DimLayerUser {
    }

    /**
     * For docked workspace provides information which side of the screen was the dock anchored.
     * For docked workspace (or workspace that's side-by-side to the docked), provides
     * information which side of the screen was the dock anchored.
     */
    int getDockSide() {
        if (mStackId != DOCKED_STACK_ID) {
        if (mStackId != DOCKED_STACK_ID && !StackId.isResizeableByDockedStack(mStackId)) {
            return DOCKED_INVALID;
        }
        if (mDisplayContent == null) {
+25 −0
Original line number Diff line number Diff line
@@ -149,8 +149,10 @@ import android.view.WindowManagerInternal;
import android.view.WindowManagerPolicy;
import android.view.WindowManagerPolicy.PointerEventListener;
import android.view.animation.Animation;
import android.widget.Toast;

import com.android.internal.app.IAssistScreenshotReceiver;
import com.android.internal.R;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.view.IInputContext;
import com.android.internal.view.IInputMethodClient;
@@ -4787,6 +4789,17 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    public void scheduleShowNonResizeableDockToast(int taskId) {
        synchronized (mWindowMap) {
            Task task = mTaskIdToTask.get(taskId);
            if (task == null) {
                if (DEBUG_STACK) Slog.i(TAG, "scheduleShowToast: could not find taskId=" + taskId);
                return;
            }
            task.setShowNonResizeableDockToast();
        }
    }

    public void getStackBounds(int stackId, Rect bounds) {
        synchronized (mWindowMap) {
            final TaskStack stack = mStackIdToStack.get(stackId);
@@ -7452,6 +7465,7 @@ public class WindowManagerService extends IWindowManager.Stub
        public static final int RESIZE_TASK = 44;

        public static final int TWO_FINGER_SCROLL_START = 45;
        public static final int SHOW_NON_RESIZEABLE_DOCK_TOAST = 46;

        /**
         * Used to denote that an integer field in a message will not be used.
@@ -8024,6 +8038,17 @@ public class WindowManagerService extends IWindowManager.Stub
                    }
                }
                break;
                case SHOW_NON_RESIZEABLE_DOCK_TOAST: {
                    final Toast toast = Toast.makeText(mContext,
                            mContext.getString(R.string.dock_non_resizeble_text),
                            Toast.LENGTH_LONG);
                    final int gravity = toast.getGravity();
                    final int xOffset = toast.getXOffset() + msg.arg1;
                    final int yOffset = toast.getYOffset() + msg.arg2;
                    toast.setGravity(gravity, xOffset, yOffset);
                    toast.show();
                }
                break;
            }
            if (DEBUG_WINDOW_TRACE) {
                Slog.v(TAG, "handleMessage: exit");
+5 −0
Original line number Diff line number Diff line
@@ -1474,6 +1474,11 @@ class WindowStateAnimator {
                }
                mWin.mAppToken.updateReportedVisibilityLocked();
            }

            final Task task = mWin.getTask();
            if (task != null) {
                task.scheduleShowNonResizeableDockToastIfNeeded();
            }
            return true;
        }
        return false;