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

Commit 6d89f482 authored by Alan Viverette's avatar Alan Viverette
Browse files

Don't end transitions on a detached window, prevent crash in WindowId

A WindowId's token should never be null, but let's avoid getting into
that situation in the first place.

Fixes: 70015590
Test: manual, cannot reliably repro in CTS test
Change-Id: I378ba9ba822ecc445d3b8de265b5ec0d20a12dd3
parent 85a6db68
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -18049,19 +18049,20 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * currently attached to.
     */
    public WindowId getWindowId() {
        if (mAttachInfo == null) {
        AttachInfo ai = mAttachInfo;
        if (ai == null) {
            return null;
        }
        if (mAttachInfo.mWindowId == null) {
        if (ai.mWindowId == null) {
            try {
                mAttachInfo.mIWindowId = mAttachInfo.mSession.getWindowId(
                        mAttachInfo.mWindowToken);
                mAttachInfo.mWindowId = new WindowId(
                        mAttachInfo.mIWindowId);
                ai.mIWindowId = ai.mSession.getWindowId(ai.mWindowToken);
                if (ai.mIWindowId != null) {
                    ai.mWindowId = new WindowId(ai.mIWindowId);
                }
            } catch (RemoteException e) {
            }
        }
        return mAttachInfo.mWindowId;
        return ai.mWindowId;
    }
    /**
+13 −10
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.view;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
@@ -35,6 +37,7 @@ import java.util.HashMap;
 * that doesn't allow the other process to negatively harm your window.
 */
public class WindowId implements Parcelable {
    @NonNull
    private final IWindowId mToken;

    /**
@@ -74,8 +77,7 @@ public class WindowId implements Parcelable {
            }
        };

        final HashMap<IBinder, WindowId> mRegistrations
                = new HashMap<IBinder, WindowId>();
        final HashMap<IBinder, WindowId> mRegistrations = new HashMap<>();

        class H extends Handler {
            @Override
@@ -163,10 +165,9 @@ public class WindowId implements Parcelable {
     * same package.
     */
    @Override
    public boolean equals(Object otherObj) {
    public boolean equals(@Nullable Object otherObj) {
        if (otherObj instanceof WindowId) {
            return mToken.asBinder().equals(((WindowId) otherObj)
                    .mToken.asBinder());
            return mToken.asBinder().equals(((WindowId) otherObj).mToken.asBinder());
        }
        return false;
    }
@@ -182,7 +183,7 @@ public class WindowId implements Parcelable {
        sb.append("IntentSender{");
        sb.append(Integer.toHexString(System.identityHashCode(this)));
        sb.append(": ");
        sb.append(mToken != null ? mToken.asBinder() : null);
        sb.append(mToken.asBinder());
        sb.append('}');
        return sb.toString();
    }
@@ -195,30 +196,32 @@ public class WindowId implements Parcelable {
        out.writeStrongBinder(mToken.asBinder());
    }

    public static final Parcelable.Creator<WindowId> CREATOR
            = new Parcelable.Creator<WindowId>() {
    public static final Parcelable.Creator<WindowId> CREATOR = new Parcelable.Creator<WindowId>() {
        @Override
        public WindowId createFromParcel(Parcel in) {
            IBinder target = in.readStrongBinder();
            return target != null ? new WindowId(target) : null;
        }

        @Override
        public WindowId[] newArray(int size) {
            return new WindowId[size];
        }
    };

    /** @hide */
    @NonNull
    public IWindowId getTarget() {
        return mToken;
    }

    /** @hide */
    public WindowId(IWindowId target) {
    public WindowId(@NonNull IWindowId target) {
        mToken = target;
    }

    /** @hide */
    public WindowId(IBinder target) {
    public WindowId(@NonNull IBinder target) {
        mToken = IWindowId.Stub.asInterface(target);
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -2563,8 +2563,10 @@ public class PopupWindow {
                    public void onViewDetachedFromWindow(View v) {
                        v.removeOnAttachStateChangeListener(this);

                        if (isAttachedToWindow()) {
                            TransitionManager.endTransitions(PopupDecorView.this);
                        }
                    }
                };

        @Override