Skip to content

fix(android): Restore autofill for Skia text inputs - #26609

Open
Xiaoy312 wants to merge 9 commits into
masterfrom
dev/xygu/20261119/android-skia-autofill-structure
Open

Xiaoy312 wants to merge 9 commits into
masterfrom
dev/xygu/20261119/android-skia-autofill-structure

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: related to #26610 (Android part)

PR Type:

🐞 Bugfix

What changed? 🚀

On Skia Android, autofill services (1Password, Google) saw no username/password fields: the render view's autofill structure had no children.

Autofill structure

  • TextInputPlugin.OnProvideAutofillVirtualStructure was disabled (#if false). It now exposes each TextBox/PasswordBox as a virtual child: id, bounds relative to the render view, current value, input type, enabled state. Every child is marked sensitive, like a native EditText, so typed text is stripped from fill requests and only sent for saving. The id is the one already used by NotifyViewEntered, NotifyValueChanged and View.Autofill.
  • Only the TextBoxes of the render view's window are listed, in screen order (top to bottom, then left to right). Collapsed ones, and those of a page being navigated away from, are reported as Gone.
  • Autofill hints come from the password mode and input scope (password, email, phone, full name), like iOS does with TextContentType. A visible plain text field directly above a visible password field gets the username hint (Google autofill does not recognize it otherwise). Other fields get no hint.

Live TextBox list and visibility

  • Nothing called ITextBoxNotificationsProviderSingleton.OnEnteredVisualTree / OnLeaveVisualTree anymore, so the Android live TextBox list was always empty. TextBoxCore now calls them on load/unload.
  • Visibility changes are reported to the autofill framework (NotifyViewVisibilityChanged, API 27+) on load/unload and after layout, so the save prompt can show once the form is gone, whether it is navigated away from or collapsed.

Hardening

  • OnProvideAutofillVirtualStructure and Autofill are guarded: an exception is logged instead of crossing back into Java. The three render views' duplicated Autofill now share one implementation that only fills text values into enabled, editable TextBoxes of its window.
  • The NotifyValueChanged debug trace no longer prints the input text (it included PasswordBox values).

Scope: Android only. #26610 also covers the other Skia targets (iOS, WebAssembly, Desktop); they are not addressed here. Follow-ups not in this PR: a way for a TextBox to opt out of autofill, a public API to set hints explicitly, and highlighting autofilled fields.

Validation

  • Runtime test Given_TextBox.When_Loaded_And_Unloaded_Then_Platform_Notified_Of_Visual_Tree_Changes (TextBox and PasswordBox): checks the enter/leave notifications across load, unload, reload and re-parenting. Passes on Skia Desktop, fails without the TextBoxCore calls.
  • Manually on a Pixel 8 (API 36), with the PasswordBox_AutoFill samples and a standalone login repro:
    • 1Password: filling from the username field and from the password field fills both; after changing the credentials, logging in shows the save prompt (Android does not offer a save when the values are unchanged from the filled dataset). Re-checked after the latest changes.
    • Google autofill: same three checks pass.
    • Both services re-checked on the final code with the app in the bottom half of split-screen, where the render view starts mid-screen, to cover the screen offset handling of the field bounds.
  • Not run on API ≤ 34.

Samples: PasswordBoxTests/PasswordBox_AutoFill (plain TextBox above a PasswordBox) exercises the username hint; TextBox/PasswordBox_AutoFill uses InputScope="EmailSmtpAddress", so it exercises the email hint, and now shows live value readouts to see what autofill wrote.

PR Checklist ✅

🤖 Generated with Claude Code

@github-actions github-actions Bot added platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia labels Nov 19, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 247788 found UI Test snapshots differences: skia-linux-screenshots: 275, skia-windows-screenshots: 276

Details
  • skia-linux-screenshots: 275 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AutomationProperties_AutomationId.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • AppWindowTitleBar Properties.png-dark
    • Accessibility_Showcase.png-dark
    • AnimatedVisualsTestbedPage.png
    • AutomationProperties_StructureAndProps.png
    • Basics.png-dark
    • Basics.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • ClipboardTests.png-dark
    • Accessibility_Showcase.png
    • ClipboardTests.png
  • skia-windows-screenshots: 276 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • BenchmarkDotNet.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • Accessibility_Showcase.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • BasicAcrylicBrushTest2.png
    • BenchmarkDotNet.png-dark
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • AnimatedVisualsTestbedPage.png
    • AutomationProperties_StructureAndProps.png
    • Border_CornerRadius_BorderThickness.png-dark

Xiaoy312 and others added 9 commits November 20, 2026 16:01
Re-enable TextInputPlugin.OnProvideAutofillVirtualStructure so autofill
services see each live TextBox as a virtual child (id, bounds, value, input
type), and derive autofill hints from password mode and input scope.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…unload

Nothing called ITextBoxNotificationsProviderSingleton.OnEnteredVisualTree /
OnLeaveVisualTree anymore, so the Android live TextBox list was always empty
and the autofill virtual structure had no children. Call them from
TextBoxCore load/unload, and make the Android registration idempotent.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…tials can be saved

The TextBoxes are virtual children of the render view, so the autofill
framework never learned they went away (e.g. on navigation after login) and
never offered to save the credentials. Report visibility on TextBox
load/unload.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Google autofill did not recognize a plain text field as the username, so it
only filled the password and never offered to save. Mark a text field that
directly precedes a password field with AutofillHintUsername.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Assert one OnEnteredVisualTree per Loaded and one OnLeaveVisualTree per
Unloaded for TextBox and PasswordBox, including reload and re-parenting,
so the Android autofill live list can't silently go empty again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The autofill structure listed every live TextBox of the process as Visible,
in load order. List only the TextBoxes of the render view's window, report
collapsed ones (and those of a page being navigated away from) as Gone, and
order them on screen so the username hint goes to the field above the
password field. Visibility changes are now also reported after layout, so
collapsing a login form lets the autofill framework offer to save.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An exception in OnProvideAutofillVirtualStructure or Autofill crossed back
into Java and crashed the app, and Autofill read TextValue without checking
the value type. Move the duplicated Autofill of the three render views into
TextInputPlugin, catch and log failures, and only fill text values into
enabled, editable TextBoxes of the view's window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The NotifyValueChanged debug trace printed the text of every input,
PasswordBox included. Log the virtual id instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261119/android-skia-autofill-structure branch from 1769961 to 89b9446 Compare November 20, 2026 21:21
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Nov 20, 2026
Comment on lines +254 to +260
catch (Exception e)
{
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().Error($"{nameof(OnProvideAutofillVirtualStructure)} failed", e);
}
}
Comment on lines +279 to +285
catch (Exception e)
{
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().Error($"{nameof(Autofill)} failed", e);
}
}
@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248099 found UI Test snapshots differences: skia-linux-screenshots: 264, skia-windows-screenshots: 264

Details
  • skia-linux-screenshots: 264 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppWindowTitleBar Properties.png
    • Basics.png-dark
    • Basics.png
    • Accessibility_Showcase.png-dark
    • AnimatedVisualsTestbedPage.png
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
  • skia-windows-screenshots: 264 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • ClipboardTests.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • Accessibility_Showcase.png-dark
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedVisualsTestbedPage.png
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Basics.png-dark
    • Basics.png
    • Border_CornerRadius_BorderThickness.png-dark

@Xiaoy312
Xiaoy312 marked this pull request as ready for review November 23, 2026 17:05
@mergify

mergify Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248466 found UI Test snapshots differences: skia-linux-screenshots: 247, skia-windows-screenshots: 303

Details
  • skia-linux-screenshots: 247 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedVisualsTestbedPage.png
    • AppWindowTitleBar Properties.png
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • AutomationProperties_StructureAndProps.png-dark
    • Basics.png-dark
    • Basics.png
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • CalendarView_Theming.png-dark
    • ClipboardTests.png-dark
    • ComboBox_MaxDropdownHeight.png-dark
    • ClipboardTests.png
    • ComboBox_MaxDropdownHeight.png
    • Accessibility_Showcase.png
  • skia-windows-screenshots: 303 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedVisualsTestbedPage.png-dark
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • AutomationPropertiesExtensions_Role.png-dark
    • AutomationPropertiesExtensions_Role.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • Accessibility_Showcase.png-dark
    • Basics.png-dark
    • Basics.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png

@ajpinedam ajpinedam 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.

I reviewed this and checked the main points on a Pixel 6 (API 34, Google autofill) with a Debug SamplesApp built from 89b9446987. Good news first: the basic flow works on API 34 too. Google recognizes both fields, and the save dialog appears once the form is removed.

Three things reproduced on the device (details inline):

  1. The password still reaches logcat, through TextInputConnection.OnTextInputHostChanged on the same NotifyValueChanged path.
  2. The save prompt is lost when a field is collapsed and the app goes to the background and comes back, because the render views don't override IsVisibleToUserForAutofill(int).
  3. The username hint can land on the wrong field: a "First name | Last name" row above the password, or a right-to-left row.

Other points, from reading the code:

  • None of the Android-only logic has an automated test: structure order, hints, Gone, which fields Autofill accepts, the API 27/28 paths. Moving the order and hint selection into a pure helper would make it unit-testable. Otherwise, could the PR say which API levels and render views were run?
  • FinishAutofillContext is still under #if false in TextBoxCore.Input.cs:775. Is that intended? Autofill was turned off in 163100d (uno-private#631) with no recorded reason, and the removed comment called the derived hints "not really correct", so it would help to say why it's fine to bring it back now.
  • The "page being navigated away from" case can't trigger: IsLeavingFrame is only true inside the try/finally of Frame.MoveFocusFromCurrentContent. Those fields become Gone because they unload, which works, but the comment on IsEffectivelyVisible and the PR text describe something else.
  • The input-scope-to-hint table repeats the iOS one (InputScopeHelper.UIKit.cs), and they already differ. Maybe track a shared model on #26610 before WebAssembly and Desktop add more copies.
  • Nits: the new test could take [GitHubWorkItem] and clear the window content in a finally; the sample's instructions only mention iOS; four commit subjects are over 50 characters.

// Resolves the text input plugin of the render view owning the given XamlRoot's window.
// TODO #8341: the foreground-activity fallback is ambiguous once multiple windows exist.
private static TextInputPlugin? GetTextInputPlugin(XamlRoot? xamlRoot = null)
internal static TextInputPlugin? GetTextInputPlugin(XamlRoot? xamlRoot = null)

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.

The autofill paths now use this to decide which view owns a TextBox, so the fallback to BaseActivity.Current matters. Take a TextBox whose window is gone, or whose XamlRoot is null at Unloaded: it's treated as belonging to the foreground activity, listed in that activity's structure, and it accepts fills there.

A strict match without the fallback would be safer for GetAutofillFields and Autofill.

LiveTextBoxes.Add(textBox);
LiveTextBoxesMap.Add(textBox.GetHashCode(), textBox);
// Unloaded runs before the next Loaded (also when re-parenting), but never register an instance twice.
if (LiveTextBoxesMap.TryAdd(textBox.GetHashCode(), textBox))

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.

The id is GetHashCode(), which isn't unique. With TryAdd, a TextBox whose hash collides with another is silently left out; the old Add threw instead. When that TextBox unloads, Remove(hash) on line 90 drops the other TextBox's entry.

It's rare, but cheap to guard: only remove the entry when the map value is the same instance.

internal static bool IsEffectivelyVisible(TextBoxCore textBox)
=> textBox.Owner.Visibility == Visibility.Visible && textBox.Owner.AreAllAncestorsVisible();

private void ReportVisibility(TextBoxCore textBox, bool isVisible)

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.

Reproduced on the device. Android re-reads the visibility of every tracked field through View.IsVisibleToUserForAutofill(int), both when the activity resumes (AutofillManager.onVisibleForAutofill) and when it rebuilds its tracked list. The default returns true, and the Android docs say views with virtual children must override it. None of the three render views do.

Combined with the dedupe here, a field reported Gone before a resume becomes visible again for Android, and it is never reported again.

Steps:

  1. Type a username, then collapse it.
  2. Press Home and come back.
  3. Type the password, then remove the form.

There is no save prompt. With verbose autofill logs:

  • on resume, autofillClientGetViewVisibility(): [true, true];
  • when the form is removed, only the password's isVisible=false;
  • finishSessionLocked is never called.

The same steps without Home/back show the save dialog.

Overriding IsVisibleToUserForAutofill in the render views, returning IsEffectivelyVisible for the matching TextBox and false for unknown ids, should fix it.

}
}

private void OnLayoutUpdated(object? sender, object e)

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.

Once a TextBox loads, this walks the ancestors of every live TextBox after every layout pass, in every app. That includes API 26, where the virtual visibility call does nothing, and devices with no autofill service.

It costs nothing at idle, since UpdateLayout returns early. But it runs every frame during layout animations, which goes against the note in TextBoxCore.IME.cs:143.

Could the subscription be limited to API ≥ 27 with AutofillManager.IsEnabled, or ideally to an active autofill session?

{
this.LogDebug()?.Debug($"NotifyValueChanged: {newValue}");
// Never log the value: it can be a password.
this.LogDebug()?.Debug($"NotifyValueChanged: {virtualId}");

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.

The value is still logged two lines down. _inputConnection?.OnTextInputHostChanged() logs OnActiveTextInputHostChanged: {_activeHost.Text} at Debug (TextInputConnection.cs:109), and for a PasswordBox Text is the password.

On the device, typing in a PasswordBox printed OnActiveTextInputHostChanged: Secr3tPwA right next to NotifyValueChanged: -387129234 (SamplesApp turns on Debug for Uno.UI.Runtime.*). CommitText (:586) and SetComposingText (:848) log typed text too.

Could those log the length instead? Otherwise the commit message should say it only fixes this one line.

&& ReferenceEquals(AndroidSkiaTextBoxNotificationsProviderSingleton.GetTextInputPlugin(textBox.Owner.XamlRoot), this)
&& values.ValueAt(i) is AutofillValue { IsText: true } value)
{
textBox.Text = value.TextValue ?? string.Empty;

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.

textBox.Text = … runs app code: TextChanging handlers and two-way bindings. If it throws, the catch below ends the loop, so the remaining fields (often the password) aren't filled. The error also only goes to the Uno log, which release apps usually have off.

Catching per field and calling Application.Current?.RaiseRecoverableUnhandledException(e), as NativeApplication.cs:185 does, would fill the other fields and surface the error.

Also, this accepts fields that the structure reports as Gone. Checking IsEffectivelyVisible here would make it match the structure.

child.SetEnabled(textBox.Owner.IsEnabled && !textBox.IsReadOnly);
child.SetVisibility(isVisible ? ViewStates.Visible : ViewStates.Gone);

var isBeforePassword = isVisible && i + 1 < fields.Count && fields[i + 1] is { IsVisible: true, TextBox.IsPassword: true };

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.

This picks the next field in screen order, not the field above the password. On the device:

  • With a "First name | Last name" row above a password, Google's fill response and save info treat Last name as the username.
  • In a FlowDirection="RightToLeft" user | password row, the user field gets no hint and Google ignores it.

Fields with an unmapped input scope (Number, Url, Search) right before a password also get the username hint.

Could this be limited to a field directly above the password, overlapping it horizontally? Or it could wait until there's an explicit hint API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants