closeSoftKeyboard() times out ("Wait on operation result timed out") on API 36+ when the focused window isn't the IME's served window (targetSdk ≥ 36)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 52/100
調査の方向性
Start by reading Espresso's CloseKeyboardAction and its tests, then reproduce the issue with the API 36 emulator and targetSdk 36 using the AlertDialog steps in the report. Compare the hideSoftInputFromWindow result handling with the IME visibility and insets behavior described here. Done means closeSoftKeyboard returns promptly when the IME is hidden and hides it when visible, including when a dialog has window focus.
索引モデルが issue の本文から書いたものです。
説明
Versions:
- androidx.test.espresso:espresso-core:3.7.0
- Emulator system-images;android-36;google_apis;x86_64, with Gboard
- App targetSdkVersion 36 or higher (reproduced with 37)
Summary
ViewActions.closeSoftKeyboard() / Espresso.closeSoftKeyboard() intermittently fails with:
PerformException: Error performing 'close keyboard' on view 'view.getRootView() to equal view'
Caused by: java.util.concurrent.TimeoutException: Wait on operation result timed out
It fails whenever the focused root is a window the IME isn't serving. A common case is an AlertDialog with no text field: it has FLAG_ALT_FOCUSABLE_IM, so it takes window focus but not IME focus. Each failure takes about 6.7 s (3 attempts × 2 s), and it happens whether or not the keyboard is showing. When the keyboard is showing behind the dialog, it also stays up.
Root cause
- CloseKeyboardAction calls InputMethodManager.hideSoftInputFromWindow(windowToken, 0, resultReceiver). It treats a return value of true as "a result will arrive", then waits up to 2 s for the ResultReceiver, three times.
- With compat change ALWAYS_RETURN_TRUE_HIDE_SOFT_INPUT_FROM_WINDOW (id 395521150, enableSinceTargetSdk = 36), hideSoftInputFromWindow returns true even when the served view is null or its window token doesn't match the caller's. In that case it logs ImeTracker onFailed at PHASE_CLIENT_VIEW_SERVED and never invokes the receiver.
- Espresso's assumption that true means a callback is coming no longer holds, so it waits for a result that never arrives.
Steps to reproduce
- Build an app with targetSdkVersion 36.
- Write an instrumentation test that shows an AlertDialog with only buttons, no EditText, then calls Espresso.closeSoftKeyboard() (or onView(isRoot()).perform(closeSoftKeyboard())).
- Run it on an API 36 emulator.
Optional: focus an EditText in the activity so the keyboard is showing, then show the dialog and call closeSoftKeyboard().
Expected: returns immediately when no keyboard is showing. Hides the keyboard when one is showing, even if a dialog has window focus.
Actual:
- With the keyboard hidden: 4/4 runs fail with a TimeoutException after about 6.7 s.
- With the keyboard showing behind the dialog: 2/2 runs fail, and the keyboard is still showing.
- Without a dialog, it passes, but takes about 850–1100 ms.
Suggested fix
Before calling hideSoftInputFromWindow, check whether the keyboard is showing:
- API 30+: read WindowInsetsCompat.isVisible(Type.ime()) for the root, and return at once if it's hidden.
- If it's showing: hide it with WindowInsetsControllerCompat.hide(Type.ime()) and wait for the IME insets to change, rather than for the ResultReceiver.
- Alternatively: don't wait on the receiver when the IME isn't serving the root's window.
Workaround we use: a helper that reads IME visibility from window insets (the root and the resumed activity's window). It returns immediately when the keyboard is hidden, and otherwise hides it through the insets controller and waits on the insets. Results:
- With a focused dialog: 3–4 ms when the keyboard is hidden, about 230 ms when it's showing.
- With no dialog: about 15 ms when the keyboard is hidden, about 220 ms when it's showing.
- 主要言語
- Java
- スター
- 1.2k
- フォーク
- 343
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 16
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
android/android-test のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
android/android-test#681 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
android/android-test#2541 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
ξεκσνδξδオープン
難易度 5/5 1週間以上 初心者へのやさしさ 1/100
android/android-test#2499 ·
メンテナーはふだん 1 日以内に返信
-
ησξξσオープン
難易度 5/5 1週間以上 初心者へのやさしさ 1/100
android/android-test#2498 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
android/android-test#2473 ·
メンテナーはふだん 1 日以内に返信
android/android-test の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
bloxbean/yaci-store#1445 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
-
Spare Permissionオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
Etar-Group/Etar-Calendar#2234 ·
メンテナーはふだん 1 日以内に返信