bug(keyboard): insets animation callbacks can run after handleOnDestroy cleared the listener on Android
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- mobile-dev
Direzione di ricerca
Inizia dai callback Keyboard.java del plugin della tastiera Android, onStart e onEnd, dove la segnalazione indica che le chiamate al listener possono verificarsi dopo il teardown. Controlla come KeyboardPlugin.handleOnDestroy() azzera il listener, quindi proteggi entrambi i callback nel caso in cui il listener sia null, mantenendo il comportamento di ritorno esistente. Il lavoro è concluso quando i callback che arrivano dopo il teardown vengono ignorati; l’issue non indica un file di test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Report
Plugin(s)
@capacitor/keyboard 8.0.6 (same code in 9.0.0-next.3)
Capacitor Version
@capacitor/core: 8.6.0
@capacitor/android: 8.6.0
@capacitor/keyboard: 8.0.6
Platform(s)
Android
Current Behavior
When the activity is destroyed while an IME insets animation is running (for example a configuration change that relaunches the activity), InsetsController.cancelExistingAnimations dispatches onEnd to the plugin's WindowInsetsAnimationCompat.Callback during ViewRootImpl.dispatchDetachedFromWindow. By then KeyboardPlugin.handleOnDestroy() may already have called implementation.setKeyboardEventListener(null), and Keyboard's onStart/onEnd call keyboardEventListener.onKeyboardEvent(...) without a null check, so the callback can throw a NullPointerException during teardown.
On 8.0.3 the same teardown crashed one step earlier because ViewCompat.getRootWindowInsets(rootView) returned null:
java.lang.NullPointerException
at androidx.core.view.WindowInsetsCompat.isVisible (WindowInsetsCompat.java:711)
at com.capacitorjs.plugins.keyboard.Keyboard$1.onEnd (Keyboard.java:112)
at androidx.core.view.WindowInsetsAnimationCompat$Impl30$ProxyCallback.onEnd (WindowInsetsAnimationCompat.java:1099)
at android.view.InsetsController.cancelExistingAnimations (InsetsController.java:1915)
at android.view.ViewRootImpl.dispatchDetachedFromWindow (ViewRootImpl.java:6231)
at android.app.ActivityThread.handleDestroyActivity (ActivityThread.java:6047)
at android.app.ActivityThread.handleRelaunchActivityInner (ActivityThread.java:6322)
8.0.6 added if (insets == null) return;, which covers that case, but the listener can still be null at that point.
Expected Behavior
Insets animation callbacks that arrive after handleOnDestroy are ignored.
Code Reproduction
Teardown race: open the keyboard in any Capacitor app and trigger an activity relaunch (for example change the system font size or dark mode with a configuration the app does not handle) while the IME animation runs. We saw the 8.0.3 variant in production once in 28 days.
Other Technical Details
The fix we ship as a patch, in both callbacks:
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(rootView);
-if (insets == null) return;
+if (insets == null || keyboardEventListener == null) return;
(onStart returns super.onStart(animation, bounds) in the same condition.)
Additional Context
Happy to open a pull request against main with this change if you agree with the approach.
This report was prepared with AI assistance (Claude) on behalf of the app team.
- Lingua principale
- Java
- Stelle
- 688
- Fork
- 690
- Merge medio
- 16h 15m
- PR unite (30g)
- 7
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ionic-team/capacitor-plugins
-
platform: android
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ionic-team/capacitor-plugins#2646 ·
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
ionic-team/capacitor-plugins#2639 ·
I maintainer di solito rispondono entro 1 giorno
-
platform: android
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
ionic-team/capacitor-plugins#2635 ·
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
ionic-team/capacitor-plugins#2627 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ionic-team/capacitor-plugins#2616 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ionic-team/capacitor-plugins
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
federicoiosue/Omni-Notes#1044 ·
-
Industrial Center Text TypoApertaBug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Terraform releases proxy leaves a temp folder behind on every cache refreshForse già presa @dhananjay6561 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
terrakube-io/terrakube#4069 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno