Skip to content

Fix LayoutInflater.From for remapped inflater types#11538

Open
simonrozsival wants to merge 1 commit into
mainfrom
dev/simonrozsival/layoutinflater-from-remap
Open

Fix LayoutInflater.From for remapped inflater types#11538
simonrozsival wants to merge 1 commit into
mainfrom
dev/simonrozsival/layoutinflater-from-remap

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

Summary

LayoutInflater.From(Context) can return null when Android remapping redirects android.view.LayoutInflater to a Java subclass/proxy type, even though the Java object is a valid layout inflater. This breaks callers such as MAUI that use LayoutInflater.From(activity) during startup.

This replaces the generated LayoutInflater.from(Context) binding with a handwritten implementation that delegates to FromContext(Context). FromContext now obtains the layout_inflater system service and, if the managed object is not directly typed as LayoutInflater, wraps the live Java handle as LayoutInflater.

Changes

  • Suppress the generated android.view.LayoutInflater.from(Context) binding via metadata.
  • Add a handwritten registered LayoutInflater.From(Context) method.
  • Make FromContext(Context) handle remapped/proxy inflater instances by wrapping the service handle.
  • Extend the existing remap test to cover both From(...) and FromContext(...).

Validation

  • Rebuilt src/Mono.Android/Mono.Android.csproj locally.
  • Decompiled the rebuilt Mono.Android.dll and confirmed LayoutInflater.From(Context) delegates to FromContext(Context).
  • Built and launched a focused Android remap test app using the local workload on emulator-5554; the app showed PASS with android/view/LayoutInflater remapped to a Java subclass.

Note: the full Mono.Android.NET-Tests APK packaging path is currently blocked in this checkout by an unrelated duplicate Java class from the Java.Interop test artifact (net.dot.jni.test.AndroidInterface).

Replace the generated LayoutInflater.from(Context) binding with a handwritten implementation that delegates to FromContext. FromContext now wraps the live layout_inflater service handle when remapping prevents a direct managed cast, preserving Intune-style LayoutInflater remaps without returning null.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 29, 2026 12:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Android.Views.LayoutInflater.From(Context) returning null when Android remapping causes the runtime to surface a subclass/proxy instance that isn’t directly typed as LayoutInflater on the managed side, which can break early-startup callers (e.g., MAUI).

Changes:

  • Suppresses the generated binding for android.view.LayoutInflater.from(Context) via metadata so it can be replaced safely.
  • Adds a handwritten [Register]ed LayoutInflater.From(Context) that delegates to FromContext(Context).
  • Updates FromContext(Context) to wrap remapped/proxy inflater instances by re-wrapping the Java handle as LayoutInflater, and extends the existing remap test to cover both From(...) and FromContext(...).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/Mono.Android-Tests/Mono.Android-Tests/Android.Views/LayoutInflaterTest.cs Extends remap test to assert both LayoutInflater.From(...) and FromContext(...) return non-null.
src/Mono.Android/metadata Removes the generated LayoutInflater.from(Context) method from the binding surface so a handwritten implementation can replace it.
src/Mono.Android/Android.Views/LayoutInflater.cs Adds handwritten From(Context) and updates FromContext(Context) to handle remapped/proxy service instances by wrapping the live Java handle.

Comment thread src/Mono.Android/Android.Views/LayoutInflater.cs
@simonrozsival
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants