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

Commit 71cb7582 authored by Charles Chen's avatar Charles Chen
Browse files

Fix IME switch dialog crash on Dual rootDA display

The crash is because when the IME switch dialog created window token
is removed, it should switch back to listen to ImeContainer.
However, previous CL use the wrong API findAreaForToken, which only
finds the DisplayArea.Token under mAreaForLayer list.
In this scenario, we cannot find one because ImeContainer is moved to
its sub-RootDisplayArea.

This CL updates the naming and add more javaDoc to prevent from
confusion.

Test: atest WindowContextListenerControllerTests
Test: manual - repro steps in b/186366728#comment1
fixes: 186366728

Change-Id: I50d3247b0a158e83d09be893d31802d673a60697
parent 9ccd991d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams.WindowType;

import com.android.internal.util.Preconditions;
import java.util.Objects;

/**
 * Base class for presentations.
 * <p>
@@ -153,7 +154,7 @@ public class Presentation extends Dialog {

    private final Display mDisplay;
    private final DisplayManager mDisplayManager;
    private final Handler mHandler = new Handler(Preconditions.checkNotNull(Looper.myLooper(),
    private final Handler mHandler = new Handler(Objects.requireNonNull(Looper.myLooper(),
            "Presentation must be constructed on a looper thread."));

    /**
+1 −1
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ public class Preconditions {
     *     be converted to a string using {@link String#valueOf(Object)}
     * @return the non-null reference that was validated
     * @throws NullPointerException if {@code reference} is null
     * @deprecated - use {@link java.util.Objects.requireNonNull} instead.
     * @deprecated - use {@link java.util.Objects#requireNonNull} instead.
     */
    @Deprecated
    @UnsupportedAppUsage
+2 −2
Original line number Diff line number Diff line
@@ -74,8 +74,8 @@ public abstract class DisplayAreaPolicy {
     */
    public abstract void addWindow(WindowToken token);

    /** Gets the {@link DisplayArea} which a {@link WindowToken} is about to be attached to. */
    public abstract DisplayArea.Tokens getDisplayAreaForWindowToken(int type, Bundle options,
    /** Gets the {@link DisplayArea} with given window type and launched options */
    public abstract DisplayArea.Tokens findAreaForWindowType(int type, Bundle options,
            boolean ownerCanManageAppTokens, boolean roundedCornerOverlay);

    /**
+8 −8
Original line number Diff line number Diff line
@@ -756,7 +756,14 @@ class DisplayAreaPolicyBuilder {
        @VisibleForTesting
        DisplayArea.Tokens findAreaForToken(WindowToken token) {
            return mSelectRootForWindowFunc.apply(token.windowType, token.mOptions)
                    .findAreaForToken(token);
                    .findAreaForTokenInLayer(token);
        }

        @Override
        public DisplayArea.Tokens findAreaForWindowType(int type, Bundle options,
                boolean ownerCanManageAppTokens, boolean roundedCornerOverlay) {
            return mSelectRootForWindowFunc.apply(type, options).findAreaForWindowTypeInLayer(type,
                    ownerCanManageAppTokens, roundedCornerOverlay);
        }

        @VisibleForTesting
@@ -794,13 +801,6 @@ class DisplayAreaPolicyBuilder {
        public TaskDisplayArea getDefaultTaskDisplayArea() {
            return mDefaultTaskDisplayArea;
        }

        @Override
        public DisplayArea.Tokens getDisplayAreaForWindowToken(int type, Bundle options,
                boolean ownerCanManageAppTokens, boolean roundedCornerOverlay) {
            return mSelectRootForWindowFunc.apply(type, options).findAreaForToken(type,
                    ownerCanManageAppTokens, roundedCornerOverlay);
        }
    }

    static class PendingArea {
+22 −11
Original line number Diff line number Diff line
@@ -1123,15 +1123,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            token.mDisplayContent = this;
            // Add non-app token to container hierarchy on the display. App tokens are added through
            // the parent container managing them (e.g. Tasks).
            switch (token.windowType) {
                case TYPE_INPUT_METHOD:
                case TYPE_INPUT_METHOD_DIALOG:
                    mImeWindowsContainer.addChild(token);
                    break;
                default:
                    mDisplayAreaPolicy.addWindow(token);
                    break;
            }
            final DisplayArea.Tokens da = findAreaForToken(token).asTokens();
            da.addChild(token);
        }
    }

@@ -5979,7 +5972,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        return mMagnificationSpec;
    }

    DisplayArea getAreaForWindowToken(int windowType, Bundle options,
    DisplayArea findAreaForWindowType(int windowType, Bundle options,
            boolean ownerCanManageAppToken, boolean roundedCornerOverlay) {
        // TODO(b/159767464): figure out how to find an appropriate TDA.
        if (windowType >= FIRST_APPLICATION_WINDOW && windowType <= LAST_APPLICATION_WINDOW) {
@@ -5991,10 +5984,28 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        if (windowType == TYPE_INPUT_METHOD || windowType == TYPE_INPUT_METHOD_DIALOG) {
            return getImeContainer();
        }
        return mDisplayAreaPolicy.getDisplayAreaForWindowToken(windowType, options,
        return mDisplayAreaPolicy.findAreaForWindowType(windowType, options,
                ownerCanManageAppToken, roundedCornerOverlay);
    }

    /**
     * Finds the {@link DisplayArea} for the {@link WindowToken} to attach to.
     * <p>
     * Note that the differences between this API and
     * {@link RootDisplayArea#findAreaForTokenInLayer(WindowToken)} is that this API finds a
     * {@link DisplayArea} in {@link DisplayContent} level, which may find a {@link DisplayArea}
     * from multiple {@link RootDisplayArea RootDisplayAreas} under this {@link DisplayContent}'s
     * hierarchy, while {@link RootDisplayArea#findAreaForTokenInLayer(WindowToken)} finds a
     * {@link DisplayArea.Tokens} from a {@link DisplayArea.Tokens} list mapped to window layers.
     * </p>
     *
     * @see DisplayContent#findAreaForTokenInLayer(WindowToken)
     */
    DisplayArea findAreaForToken(WindowToken windowToken) {
        return findAreaForWindowType(windowToken.getWindowType(), windowToken.mOptions,
                windowToken.mOwnerCanManageAppTokens, windowToken.mRoundedCornerOverlay);
    }

    @Override
    DisplayContent asDisplayContent() {
        return this;
Loading