Skip to content

Android: Report FlutterView as a text editor while a text input client is attached - #193074

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
edde746:android-flutterview-text-editor
Nov 17, 2026
Merged

auto-submit[bot] merged 3 commits into
flutter:masterfrom
edde746:android-flutterview-text-editor

Conversation

@edde746

@edde746 edde746 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

FlutterView never overrides View.onCheckIsTextEditor(), so it always reports false. Android's InputMethodManager turns that into the IS_TEXT_EDITOR start-input flag (InputMethodManager.java#L2945), and devices that ship config_preventImeStartupUnlessTextEditor=true (default false in config.xml#L3198; set by the low-RAM Android TV overlay on Chromecast with Google TV, Philips/TCL Google TVs) answer every startInput without that flag with NO_EDITOR and unbind the IME, unless a show is already pending for the window (InputMethodManagerService.startInputUncheckedLocked, shouldPreventImeStartupLocked).

On those devices the sequence for a Flutter TextField is:

  1. Every Flutter-originated startInput returns NO_EDITOR and kills the IME service: window focus gain, the restartInput in TextInputPlugin.setTextInputEditingState, and the restartInput in the IME hide listener. The client records no bind sequence (mBindSequence=-1).
  2. showTextInput → showSoftInput marks a show as requested, so IMMS binds the IME again (logcat shows GoogleInputMethodService.onCreate() ~30 ms after the show) and creates a session.
  3. IMMS sends the client onBindMethod with the new sequence, which the client discards because its own sequence is -1:
    W InputMethodManager: Ignoring onBind: cur seq=-1, given seq=626
    
    The keyboard is drawn (IME mInputViewStarted=true) but the app holds no session (mCurMethod=null, IME mInputBinding=null).
  4. With no session, ViewRootImpl's ImeInputStage returns DISPATCH_NOT_HANDLED for every key, so D-pad events fall through to the view hierarchy, Flutter moves focus, the field detaches, and the keyboard hides. That is the "keyboard disappears on any button" from the issue.

This also explains both workarounds reported on the issue: a platform-view EditText works because EditText.onCheckIsTextEditor() is true, and a hot restart heals it (until Back closes the keyboard) because a startInput issued while a show is pending bypasses shouldPreventImeStartupLocked and records a real sequence.

dumpsys input_method on a Chromecast 4K (Android 14, Gboard TV 17.3.09) while the keyboard was visible but dead:

# IMMS
mCurClient=ClientState{... mPid=13034} mCurSeq=627
mCurId=.../LatinIME mHaveConnection=true mBoundToMethod=true
mInputShown=true
# app client (pid 13034)
mBindSequence=-1 mCurImeId=null
mCurMethod= null
mServedView=io.flutter.embedding.android.FlutterView{...}
mCurrentEditorInfo: inputType=0x80091 imeOptions=0x2000002
# IME service
mInputBinding=null  mInputConnection=null
mInputStarted=true  mInputViewStarted=true

Every StartInput history entry has reason SESSION_CREATED_BY_IME with a fresh imeToken. On a Google TV Streamer (4 GB, flag off, same Gboard build) the same flow shows mBindSequence == mCurSeq, mCurMethod populated, and reasons WINDOW_FOCUS_GAIN / APP_CALLED_RESTART_INPUT_API with a stable token.

Change

FlutterView.onCheckIsTextEditor() now returns isAttachedToFlutterEngine() && textInputPlugin.isTextEditor(), mirroring the guard in onCreateInputConnection. The new TextInputPlugin.isTextEditor() is true when a framework client with an input type other than TextInputType.none is attached (the same condition showTextInput already uses to decide whether to show the keyboard), or when a virtual-display platform view is the input target (its InputConnection is proxied through FlutterView). Hybrid-composition platform views own their InputConnection, so they stay false.

Ordering is already right on the framework side: EditableText._openInputConnection calls TextInput.attach (setClient) before setEditingState and show, so the input target is FRAMEWORK_CLIENT by the time the flag is read. clearTextInputClient resets the target, so the flag drops when the field detaches, which matches EditText being a text editor for as long as it exists.

This is the union of the two earlier attempts at this override: #189662 (FRAMEWORK_CLIENT || VIRTUAL_DISPLAY_PLATFORM_VIEW) and #187778 (FRAMEWORK_CLIENT with a non-none input type), which @Renzo-Olivares suggested combining in #187778 (comment). Both were closed without landing; this PR only carries the onCheckIsTextEditor part, not the focus-restore logic from #187778.

Behavior to call out

IS_TEXT_EDITOR (hasEditorFocused() in ImeVisibilityStateComputer.computeState) feeds three IMMS decisions, and this change flips all of them for a FlutterView with an attached client:

  1. The startup-prevention gate above, which is the bug.
  2. SOFT_INPUT_STATE_UNSPECIFIED + window focus gain: today IMMS hides the IME (HIDE_UNSPECIFIED_WINDOW) because the focused view is not an editor. With this change, regaining window focus while a TextField is attached no longer hides the keyboard, same as a native EditText. This likely fixes a class of "keyboard closes when a system dialog/popup is dismissed" reports; #187778 measured this override alone as the difference for keyboard restore after Home → Recents on a Pixel 7.
  3. SOFT_INPUT_STATE_UNSPECIFIED + adjustResize (or a large layout) + SOFT_INPUT_IS_FORWARD_NAVIGATION + text editor: IMMS auto-shows the IME on window focus gain (SHOW_AUTO_EDITOR_FORWARD_NAV). EditText apps get this today; Flutter apps with an attached client start getting it too. Flutter's app template sets windowSoftInputMode="adjustResize", so this applies to most apps. The flag is computed by the framework from onCheckIsTextEditor() regardless of start reason, so it cannot be suppressed for WINDOW_GAINED_FOCUS only; flagging it here for reviewers to weigh.

Not affected: key routing (FlutterView.dispatchKeyEvent is unchanged), InputConnectionAdaptor, IME insets sync, and autofill (notifyViewEntered already uses mView).

Verification

The affected Robolectric classes were run locally against this branch with the shell/platform/android/test_runner Gradle configuration (compileSdk 36, Robolectric 4.16, Mockito 5.17.0, embedding dependencies from tools/androidx/files.json) without a full engine build:

class tests result
io.flutter.embedding.android.FlutterViewTest 89 all pass
io.flutter.plugin.editing.TextInputPluginTest 117 all pass

FlutterViewTest.onCheckIsTextEditor_reflectsAttachedTextInputClient fails at the assertion after setClient with the FlutterView override removed and passes with it. The Java files are formatted with google-java-format 1.7, the version pinned in DEPS.

The same mechanism is what Plezy ships today as an app-side workaround on Android TV: a 1×1 focusable child of FlutterView that reports onCheckIsTextEditor() from a Dart-side flag, delegates onCreateInputConnection to FlutterView, and returns true from checkInputConnectionProxy(flutterView); D-pad input in TextFields works on the affected Chromecast with that in place. This engine change makes the proxy view unnecessary.

Fixes #177360

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@edde746
edde746 requested a review from a team as a code owner September 20, 2026 19:56
@edde746
edde746 requested review from gmackall and removed request for a team September 20, 2026 19:56
@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems platform-android Android applications specifically engine flutter/engine related. See also e: labels. team-android Owned by Android platform team labels Sep 20, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements onCheckIsTextEditor in FlutterView and isTextEditor in TextInputPlugin to report whether the view is currently acting as a text editor, with corresponding unit tests added. Feedback suggests adding a null check for textInputPlugin in onCheckIsTextEditor to prevent a potential NullPointerException during lifecycle transitions.

Comment on lines +904 to +906
public boolean onCheckIsTextEditor() {
return isAttachedToFlutterEngine() && textInputPlugin.isTextEditor();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

During attachToFlutterEngine and detachFromFlutterEngine, there are windows of time where isAttachedToFlutterEngine() returns true (because flutterEngine is non-null) but textInputPlugin is null (since they are not set/cleared atomically). If the Android framework triggers a focus or layout pass during these lifecycle transitions, onCheckIsTextEditor() can be called and will throw a NullPointerException.

To prevent this, we should explicitly check that textInputPlugin is non-null before calling isTextEditor().

Suggested change
public boolean onCheckIsTextEditor() {
return isAttachedToFlutterEngine() && textInputPlugin.isTextEditor();
}
public boolean onCheckIsTextEditor() {
return isAttachedToFlutterEngine() && textInputPlugin != null && textInputPlugin.isTextEditor();
}
References
  1. Enforce defensive programming by ensuring appropriate null checks exist before object property accesses in languages that support nullable references.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add this null check!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null window doesn't exist on detach: textInputPlugin is destroyed but never nulled, and isAttachedToFlutterEngine() goes false at renderSurface.detachFromRenderer(). On first attach there's a window between renderSurface.attachToRenderer() and the plugin assignment. But onCheckIsTextEditor() is only called from IMM's getStartInputFlags, from startInputInner/window-focus handling. Those run on the UI thread, and view focus changes are posted via dispatchCheckFocus, so they can't interleave with attachToFlutterEngine. Even if something re-entered there, startInputInner calls onCreateInputConnection right after, and that method has the same isAttachedToFlutterEngine() guard with an unguarded textInputPlugin dereference. I mirrored that guard deliberately. Happy to add the check anyway if you'd prefer it as defense.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation! For what it's worth, I think you're right, but can we add it just as an extra line of defense? Thanks!

camsim99
camsim99 previously approved these changes Sep 28, 2026

@camsim99 camsim99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than resolving the Gemini comment, LGTM!

Comment on lines +904 to +906
public boolean onCheckIsTextEditor() {
return isAttachedToFlutterEngine() && textInputPlugin.isTextEditor();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add this null check!

@camsim99 camsim99 added the CICD Run CI/CD label Sep 28, 2026
@Renzo-Olivares
Renzo-Olivares self-requested a review October 1, 2026 20:41
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 5, 2026

@camsim99 camsim99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the quick fix :) we'll need a second review.

@Renzo-Olivares Renzo-Olivares left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! The other PR also targeted #159670, this uses the same approach so we should check if this also solves that issue so we can close it.

@Renzo-Olivares
Renzo-Olivares force-pushed the android-flutterview-text-editor branch from f281ea3 to e5d8796 Compare October 14, 2026 06:53
@Renzo-Olivares Renzo-Olivares added the CICD Run CI/CD label Oct 14, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 14, 2026
@camsim99 camsim99 added the CICD Run CI/CD label Oct 14, 2026
@Renzo-Olivares
Renzo-Olivares force-pushed the android-flutterview-text-editor branch from aad138f to 7772765 Compare October 29, 2026 20:37
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 29, 2026
@Renzo-Olivares Renzo-Olivares added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Oct 29, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 29, 2026
@auto-submit

auto-submit Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/193074, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 12, 2026
@Renzo-Olivares Renzo-Olivares added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Nov 12, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 12, 2026
@auto-submit

auto-submit Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/193074, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label.

@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 12, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit

auto-submit Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193074, Failed to enqueue flutter/flutter/193074 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 14, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 14, 2026
@auto-submit

auto-submit Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193074, Failed to enqueue flutter/flutter/193074 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 14, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 14, 2026
@auto-submit

auto-submit Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193074, Failed to enqueue flutter/flutter/193074 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 2026
@auto-submit

auto-submit Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193074, Failed to enqueue flutter/flutter/193074 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 17, 2026
@camsim99 camsim99 added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Nov 17, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 17, 2026
Merged via the queue into flutter:master with commit 792e63d Nov 17, 2026
27 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 2026
LouiseHsu pushed a commit to flutter/packages that referenced this pull request Nov 18, 2026
flutter/flutter@2f09f96...06f32f8

2026-11-18 [email protected] Move macOS
desktop builds to ThinLTO (flutter/flutter#196804)
2026-11-18 [email protected] Roll Dart SDK from
5ed55b4b2ebc to 753488ede427 (2 revisions) (flutter/flutter#196893)
2026-11-18 [email protected] Roll Packages from
9af69be to dca2e58 (7 revisions) (flutter/flutter#196892)
2026-11-18 [email protected] Roll Skia from 503a380ebecc
to 81ee7327e81c (29 revisions) (flutter/flutter#196889)
2026-11-18 [email protected] Roll Dart SDK from
26e38955d9d4 to 5ed55b4b2ebc (4 revisions) (flutter/flutter#196843)
2026-11-18 [email protected] Fix permissions for action updates
(flutter/flutter#196791)
2026-11-18 [email protected] iOS: Apply platform view mutators from
FlutterPlatformViewLayer (flutter/flutter#196753)
2026-11-18 [email protected] [flutter_tools] Remove ambient Doctor,
FeatureFlags, and device getters (flutter/flutter#196572)
2026-11-18 [email protected] Fix
RelativeRect.lerp crash when b is null (flutter/flutter#196655)
2026-11-18 [email protected] [web] Harden
WebP and GIF header readers against truncated and malformed buffers
(flutter/flutter#196075)
2026-11-17 [email protected] Enable apps to
control focus behavior during app lifecycle changes via
`FocusLifecyclePolicy` (flutter/flutter#190570)
2026-11-17 [email protected] Don't re-run the code freeze check
on label changes (flutter/flutter#196745)
2026-11-17 [email protected] Android: Report
FlutterView as a text editor while a text input client is attached
(flutter/flutter#193074)
2026-11-17 [email protected] Roll Packages from
4c6a7d3 to 9af69be (5 revisions) (flutter/flutter#196812)
2026-11-17 [email protected] [flutter_tools] Handle target VM filesystem
errors in DevFS.create (flutter/flutter#196234)
2026-11-17 [email protected] [flutter_tools] Clarify analytics reporting
status when on a feature branch (flutter/flutter#194496)
2026-11-17 [email protected] [web] Recover
CanvasKit surfaces from WebGL failures without per-frame null crashes
(flutter/flutter#196257)
2026-11-17 [email protected] [devicelab] Trigger navigation tap via
Flutter Driver in service_extensions_test (flutter/flutter#194456)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to
ensure that a human
is aware of the problem.

To file a bug in Packages:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] [Google Chromecast] Unable to use software keyboard with TextField

3 participants