bug(keyboard): insets animation callbacks can run after handleOnDestroy cleared the listener on Android
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- mobile-dev
Hướng nghiên cứu
Bắt đầu với các callback Keyboard.java của plugin bàn phím Android, onStart và onEnd, nơi báo cáo cho biết các lệnh gọi listener có thể xảy ra sau teardown. Kiểm tra cách KeyboardPlugin.handleOnDestroy() xóa listener, sau đó bảo vệ cả hai callback khi listener là null, đồng thời giữ nguyên hành vi trả về hiện tại. Hoàn tất khi các callback đến sau teardown bị bỏ qua; issue không nêu tên tệp kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 688
- Fork
- 690
- Merge trung bình
- 16 giờ 15 phút
- Pull request đã merge (30 ngày)
- 7
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ionic-team/capacitor-plugins
-
platform: android
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ionic-team/capacitor-plugins#2646 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
ionic-team/capacitor-plugins#2639 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
platform: android
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
ionic-team/capacitor-plugins#2635 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
ionic-team/capacitor-plugins#2627 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ionic-team/capacitor-plugins#2616 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ionic-team/capacitor-plugins
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
federicoiosue/Omni-Notes#1044 ·
-
Industrial Center Text TypoĐang mởBug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Terraform releases proxy leaves a temp folder behind on every cache refreshCó thể đã có người làm @dhananjay6561 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
terrakube-io/terrakube#4069 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày