bug(keyboard): insets animation callbacks can run after handleOnDestroy cleared the listener on Android
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 领域
- mobile-dev
调研方向
从 Android 键盘插件的回调 Keyboard.java、onStart 和 onEnd 入手,报告指出 listener 调用可能在 teardown 后发生。检查 KeyboardPlugin.handleOnDestroy() 如何清除 listener,然后为两个回调添加 listener 为 null 时的保护,同时保留现有的返回行为。完成标准是忽略 teardown 后到达的回调;issue 未指定测试文件。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Java
- 星标
- 688
- 派生
- 690
- 平均合并
- 16 小时 15 分钟
- 30 天内合并 PR
- 7
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ionic-team/capacitor-plugins 的其他 Issue
-
platform: android
难度 2/5 1-3 小时 新手友好度 78/100
ionic-team/capacitor-plugins#2646 ·
维护者通常 1 天内回复
-
triage
难度 2/5 1-3 小时 新手友好度 70/100
ionic-team/capacitor-plugins#2639 ·
维护者通常 1 天内回复
-
platform: android
难度 2/5 1-3 小时 新手友好度 88/100
ionic-team/capacitor-plugins#2635 ·
维护者通常 1 天内回复
-
triage
难度 2/5 1-3 小时 新手友好度 80/100
ionic-team/capacitor-plugins#2627 · 1 条评论 ·
维护者通常 1 天内回复
-
triage
难度 2/5 1-3 小时 新手友好度 72/100
ionic-team/capacitor-plugins#2616 ·
维护者通常 1 天内回复
查看 ionic-team/capacitor-plugins 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 82/100
federicoiosue/Omni-Notes#1044 ·
-
Bug
难度 1/5 1 小时以内 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
Terraform releases proxy leaves a temp folder behind on every cache refresh可能已有人在做 @dhananjay6561 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
terrakube-io/terrakube#4069 · 1 条评论 ·
维护者通常 1 天内回复