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

Commit 60c47fae authored by Taran Singh's avatar Taran Singh
Browse files

Handle BadTokenException when adding IME ink window

BadTokenException can be thrown if token used to add IME window is
stale. We already do this for main IME window (SoftInputWindow), we
should do the same for InkWindow.

Fix: 355815690
Test: atest CtsInputMethodTestCases
Flag: EXEMPT_bug_fix_only
Change-Id: I97ad30520d0830621ab519af4306f77ddc4ace69
parent 52f8f787
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -92,8 +92,19 @@ final class InkWindow extends PhoneWindow {
        }
        getDecorView().setVisibility(keepInvisible ? View.INVISIBLE : View.VISIBLE);
        if (!mIsViewAdded) {
            try {
                mWindowManager.addView(getDecorView(), getAttributes());
                mIsViewAdded = true;
            } catch (WindowManager.BadTokenException | WindowManager.InvalidDisplayException e) {
                // Similar to SoftInputWindow#show(), just ignore this exception. Since show() can
                // be requested from other components such as the system and there could be multiple
                // event queues before the request finally arrives here, the system may have already
                // invalidated the window token attached to our window. In such a scenario,
                // receiving BadTokenException here is an expected behavior. We just ignore it.
                Slog.i(InputMethodService.TAG,
                        "Probably the IME/InkWindow token is already invalidated."
                        + " InkWindow#show() does nothing.");
            }
        }
    }