Fix LayoutInflater.From for remapped inflater types#11538
Open
simonrozsival wants to merge 1 commit into
Open
Conversation
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>
Contributor
There was a problem hiding this comment.
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]edLayoutInflater.From(Context)that delegates toFromContext(Context). - Updates
FromContext(Context)to wrap remapped/proxy inflater instances by re-wrapping the Java handle asLayoutInflater, and extends the existing remap test to cover bothFrom(...)andFromContext(...).
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. |
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LayoutInflater.From(Context)can returnnullwhen Android remapping redirectsandroid.view.LayoutInflaterto a Java subclass/proxy type, even though the Java object is a valid layout inflater. This breaks callers such as MAUI that useLayoutInflater.From(activity)during startup.This replaces the generated
LayoutInflater.from(Context)binding with a handwritten implementation that delegates toFromContext(Context).FromContextnow obtains thelayout_inflatersystem service and, if the managed object is not directly typed asLayoutInflater, wraps the live Java handle asLayoutInflater.Changes
android.view.LayoutInflater.from(Context)binding via metadata.LayoutInflater.From(Context)method.FromContext(Context)handle remapped/proxy inflater instances by wrapping the service handle.From(...)andFromContext(...).Validation
src/Mono.Android/Mono.Android.csprojlocally.Mono.Android.dlland confirmedLayoutInflater.From(Context)delegates toFromContext(Context).emulator-5554; the app showedPASSwithandroid/view/LayoutInflaterremapped to a Java subclass.Note: the full
Mono.Android.NET-TestsAPK 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).