Skip to content

refactor(android): Make Skia-Android multi-window-ready - #24042

Merged
MartinZikmund merged 55 commits into
masterfrom
dev/mazi/androidunsingleton
Oct 8, 2026
Merged

MartinZikmund merged 55 commits into
masterfrom
dev/mazi/androidunsingleton

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

GitHub Issue: #8341, closes #24943

PR Type:

Review status: a second eight-lens review panel ran after the rebase onto the
Uno.UI.Runtime.Android host-namespace move. Its high findings (window creation while the activity
is paused, re-creation test coverage) and the worthwhile medium ones are fixed in the trailing
commits; the rest are listed as follow-ups at the bottom.

What changed? 🚀

Skia-on-Android baked "one window" into three process-wide static anchors. This PR
de-singletons them so Android converges onto the same per-window ownership pattern the
Skia desktop runtimes (Win32/X11/macOS) and the Apple UIKit runtime already use — making
the architecture multi-window-ready.

SupportsMultipleWindows deliberately stays false. The definition of done here is
per-window instances everywhere, and zero single-window regressions — not a live second window.

The three anchors that went away

  1. NativeWindowWrapper.Instance — was a process-wide Lazy<> singleton returned by
    AndroidSkiaWindowFactory.CreateWindow for every window. It is now an instance bound to
    its window, tracking the activity currently driving it (CurrentActivity), since the managed
    Window outlives individual activities across re-creation.
  2. ApplicationActivity.Instance + the static render stack (render view, native-layer host,
    root layout) — now per-activity instance state. A new activity rebuilds its surface and
    re-attaches on re-creation.
  3. ContextHelper.Current — split into an explicit app-global ApplicationContext and an
    activity-scoped Current that tracks the foreground activity via the existing BaseActivity
    registry, instead of today's sticky "last-ever-set" behaviour.

Supporting changes

  • AndroidSkiaXamlRootHost is per-window: it resolves its own RootElement and driving
    activity, and registers in XamlRootMap so consumers (native element hosting, TextBox
    notifications, IME) resolve the owning activity from a XamlRoot rather than a global.
  • Per-window input sources: pointer and keyboard sources are owned by the window's wrapper and
    registered via ApiExtensibility.Register<IXamlRootHost>(…), matching the Win32 runtime. Each
    window's InputManager resolves its own sources through its host.
  • Lifecycle correctness: the managed window's Closing is raised only when the activity is
    actually finishing, so a configuration-change re-creation no longer spuriously closes the
    surviving window.
  • Render-frame null guards: UnoSKCanvasView now skips a frame when the window's
    root/composition target isn't ready (e.g. mid-teardown during activity re-creation), matching
    the Vulkan backend, instead of dereferencing with !.

API surface

Not additive — this PR contains five deliberate public-surface breaks, all recorded in
doc/articles/migrating-to-uno-7.md and build/PackageDiffIgnore.xml:

  • Uno.UI.ContextHelper.Current is re-typed Android.Content.Context?. It could always be
    null before any activity exists, but was annotated non-null and returned _current!, so the
    compiler never surfaced it. Typing it honestly changed no runtime behaviour and immediately
    exposed 13 unguarded dereferences in Uno.WinRT. Its semantics also change: it now tracks the
    most recently active activity that is still alive, rather than the last one ever assigned.
  • ContextHelper.Current's setter is narrowed to internal. The value is owned by the
    activity lifecycle, which overwrote anything app code assigned; with several activities an
    outside write would point lookups at the wrong one.
  • ApplicationViewHelper.GetBaseActivityEvents() and IBaseActivityEvents are removed. No
    Skia activity implements the interface, so it always returned null (the documented usage threw).
    doc/articles/android-activities.md now points to Application.RegisterActivityLifecycleCallbacks.
  • The Uno.UI.ViewManagement.Activity*Handler delegates are removed. They only typed
    IBaseActivityEvents' events and have no other consumer.
  • Uno.UI.OnSystemUiVisibilityChangeListener is narrowed to internal. It is constructed by
    the host with the activity owning the window; app code had no way to supply one.

ContextHelper.ApplicationContext is new and additive. Everything else in this PR is internal.

Why now: 7.0 ships Android multi-window ready; live multi-window (#24397) targets 7.1+ and
must not need a binary break. A contract audit of the Android public surface found the two items
above as the only ones that would otherwise need a break later. Everything else multi-window needs
is additive: InitializeWithWindow for pickers/share/web auth, a per-window context accessor (keyed
on WindowId), per-window overloads for PermissionsHelper, MSAL and the add-ins. New
IAndroidSkiaHostBuilder members must use default interface implementations to stay non-breaking.

Design notes

specs/053-android-multiwindow-ready/plan.md documents the architecture, the phase breakdown,
and the deliberate follow-ups — chiefly flipping SupportsMultipleWindows to true (needs
Activity↔Window lifecycle orchestration and on-device validation, mirroring how iOS staged its
own multi-window behind scene adoption) and threading an explicit owning-window Context through
the remaining ambient ContextHelper.Current consumers.

Validation

  • Compile: Uno.UI.Runtime.Android (with Uno.WinRT for net10.0-android) and
    Uno.UI.RuntimeTests.Skia build clean on the rebased head.
  • Runtime tests: Given_AndroidSkiaXamlRootHost and Given_ApplicationActivity run on the
    Android Skia CI lane. They cover host registration, wrapper-owned input sources, host resolution
    while the activity is paused, and the re-creation handover: the successor takes the window,
    reopens the first-frame gate and becomes ContextHelper.Current.
  • Runtime (device): validated on a Pixel Tablet emulator (API 35) before the rebase. That pass
    caught and fixed a black-window regression in the pre-draw gate. It has not been re-run since the
    rebase; to smoke-test: dotnet run --project src/SamplesApp/SamplesApp -f net10.0-android.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable) — Given_AndroidSkiaXamlRootHost runs on the Android Skia CI lane and asserts host registration, activity resolution and per-window input-source identity. The foreground-repoint logic itself lives on BaseActivity : AppCompatActivity, which the net-based Uno.UI.UnitTests cannot instantiate.
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — the public-surface breaks are recorded in migrating-to-uno-7.md; the in-repo spec covers the architecture.
  • 🖼️ Validated PR Screenshots Compare Test Run results — pending CI.
  • ❗ Contains NO breaking changes — it does; see the API surface section above. All are deliberate and recorded.
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

Known follow-ups

Carried from the review panels, deliberately not in this PR:

  • The wrapper is per-activity, not strictly per-Window. The activity still adopts it through
    the ambient current window, and the factory resolves its activity the same way. An explicit
    activity⇄window binding needs the lifecycle orchestration that lands with the live second activity.
    Marked TODO #8341.
  • ContextHelper.WindowContextResolver is an internal static Func; before 7.1 it should become a
    typed ApiExtensibility registration with a public per-window accessor (additive).
  • AndroidSkiaNativeElementHostingExtension._attachedViews is process-wide; move it onto each
    window's host.
  • ContextHelper.Current consumers that need an activity (dialogs, StartActivity, haptics,
    status bar) still use the ambient value. App-scoped ones now use ApplicationContext.
  • Diagnosability: a window whose composition target never binds re-arms its frame every 100 ms
    with no log. A pending web authentication only ends through the caller's token if its
    activity dies.
  • NativeWindowWrapper's process-wide TitleBar/DpiChanged subscriptions are never removed;
    harmless with one wrapper, a leak with several.
  • Pre-existing: TextInputPlugin.NotifyValueChanged logs full text at Debug, and
    PasswordBox : TextBox, so passwords can reach logcat.
  • The history has fix-on-fix commits from review rounds: squash-merge.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DtsKbXbA642EduoduiNtt4

@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 kind/documentation labels Aug 11, 2026
@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 9m 24s —— View job


Review complete

  • Gather context and understand the PR
  • Read changed files (18 files, 530 lines of context)
  • Analyze for correctness, lifecycle, async discipline, and cross-platform concerns
  • Post inline comments for specific findings
  • Post summary

Overall verdict: fix-first (3 inline issues, 1 optional cleanup)

The architecture is sound. The three-anchor de-singletonization (NativeWindowWrapper.Instance, ApplicationActivity.Instance + static render stack, ContextHelper.Current) correctly mirrors the Win32/iOS pattern, the per-window AndroidSkiaXamlRootHost and XamlRootMap integration follow existing precedent, and the IsFinishing-gated OnNativeClosed is a correct lifecycle fix.

The draft status is appropriate — no on-device runtime validation has been done. The issues below are findable at code-review time and should be resolved before promote-to-ready.


Issues (3 inline, 1 severity each)

HIGH — Vulkan render thread null-dereference (UnoSKVulkanView.cs:220)
_activity.NativeLayerHost!.Path = nativeClipPath retains the old null-forgiving ! that was just fixed in UnoSKCanvasView (which now uses if (_activity.NativeLayerHost is { } nativeLayerHost)). The Vulkan render thread is a background thread; apply the same null guard.

MEDIUM — BaseActivity constructors set ContextHelper.Current before the activity lifecycle (BaseActivity.cs:330)
The PR changes ContextHelper.Current semantics from "sticky last-ever-set" to "foreground-activity scoped", but the constructors (lines 132/138) still call ContextHelper.Current = this before OnCreate. On a configuration-change recreation, Android constructs the new activity before calling OnPause on the old one, so the still-visible old activity loses ContextHelper.Current the moment the new one is constructed. The assignment is redundant since SetAsCurrent() (called from InnerCreate, InnerStart, InnerResume) is the right lifecycle-driven writer.

MEDIUM — ContextHelper.Current getter returns a non-nullable type but the value can be null (ContextHelper.cs:39)
The PR makes _current explicitly Android.Content.Context? and documents that Current may be null, but the getter returns via _current! with a non-nullable return type — a silent NullReferenceException trap for any caller who trusts the C# type system. Consider Android.Content.Context? as the return type (breaking, but honest) or throwing InvalidOperationException explicitly instead of using !.

LOW — Incomplete null chain in GetWindowSize (NativeWindowWrapper.Android.cs:233)
activity.WindowManager?.CurrentWindowMetrics can return null, but windowMetrics.Bounds is called unconditionally on the next line. The PR touched line 232 and is a good opportunity to add a if (windowMetrics is null) return default; guard.


Cross-cutting notes

  • The (this as ApplicationActivity)?.Wrapper pattern in BaseActivity's lifecycle partials is an existing architectural constraint (base class referencing a derived type). The null-conditional ?. is correct hardening for non-ApplicationActivity subclasses.
  • InnerDestroy's ContextHelper.SetForeground repoint logic is correct: ResignCurrent() only affects BaseActivity._current; the separate ContextHelper._current is checked after. The lock on _instances is correctly scoped.
  • No event Action/event Action<T> violations introduced. No new async void without guards. No XAML changes requiring XamlStyler.
  • Conventional Commits titles on all 6 commits are correct.

Comment thread src/Uno.UWP/ContextHelper.cs Resolved
@github-actions github-actions Bot added the area/build Categorizes an issue or PR as relevant to build infrastructure label Aug 11, 2026
@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 8m 3s —— View job


Re-review: 4 new commits since first pass

  • Check what changed since the last review
  • Read current state of files flagged in prior review
  • Check if prior HIGH/MEDIUM issues were addressed
  • Look for new issues in new commits
  • Post inline comments for remaining unfixed findings
  • Update summary

What the 4 new commits addressed

Commit Topic Status
ba048c68 ContextHelper: stay activity-scoped (no app-context fallback), fix InnerDestroy repoint ✅ Addressed
a2e944b2 Null-guard canvas render frame (UnoSKCanvasView) ✅ Fixed
e4e7ffcd Re-arm skipped frames, TeardownRenderer, unsubscribe singletons, correct IsChangingConfigurations gate ✅ Addressed (major)
7a71a164 Type ContextHelper.Current as Android.Content.Context?; update 13 call sites with explicit ! ✅ Fixed (MEDIUM from prior review)

The e4e7ffcd changes to ApplicationActivity.OnDestroy are sound: unsubscribing _inputPane and orientationSensor from process-wide singletons was a real activity-leak on re-creation, and the !IsChangingConfigurations && ReferenceEquals(wrapper.CurrentActivity, this) gate is the correct criterion for raising OnNativeClosed.

The new Given_AndroidSkiaXamlRootHost runtime-test class is well-structured: [PlatformCondition(… SkiaAndroid)], reflection-based access (no compile-time dep on the Android assembly), and the three scenarios (host registration, activity identity, input-source stability) cover the core de-singletoning invariants.


Remaining issues (2 inline comments posted)

HIGH — Vulkan NativeLayerHost! null-forgiving (still unfixed) — UnoSKVulkanView.cs:226
a2e944b2 applied the null-guard to the canvas view but not to the Vulkan view. Line 226 still reads _activity.NativeLayerHost!.Path = nativeClipPath. Lifecycle analysis confirms the ordering is safe today (surface destroyed → render thread joined → then _nativeLayerHost = null), but the ! is inconsistent with the canvas peer and silently crashes if that ordering shifts. One-line fix: same if (_activity.NativeLayerHost is { } nativeLayerHost) pattern.

LOW — GetWindowSize null chain (still unfixed) — NativeWindowWrapper.Android.cs:233
windowMetrics.Bounds is called unconditionally when windowMetrics can be null. Suggestion in the inline comment.


Note on BaseActivity constructors

The constructor-level ContextHelper.Current = this (lines 132/138) is still present and was called out in the first pass. After tracing the ba048c68 intent — keep the last-activity behavior for single-window callers that hard-cast Current — the constructor assignment serves as a belt-and-suspenders to advance ContextHelper._current from the destroyed old activity to the new one as early as possible. The gap before InnerCreate → SetAsCurrent is tiny, and nothing in Initialize() reads ContextHelper.Current, so this is low-risk. It is still cosmetically redundant, but fix-first priority is lower than the two inline findings above.


Verdict: fix-first (2 inline findings remain open)

The new commits are a meaningful improvement. Address the Vulkan NativeLayerHost! guard and the GetWindowSize null chain before promoting to ready.

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/androidunsingleton branch from 9dc62c3 to d12374d Compare August 14, 2026 18:21
@github-actions

github-actions Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 3m 8s —— View job


Re-review pass 3 (commits 2542a0c9, 080f5262, d12374d1)

  • Check new commits since last review
  • Read files for remaining open findings
  • Check for any new issues in new commits
  • Post inline comments
  • Update summary

What the 3 new commits addressed

Commit Topic Status
2542a0c9 Re-arm skipped frames, TeardownRenderer, unsubscribe singletons, IsChangingConfigurations gate ✅ Sound — no new issues
080f5262 Type ContextHelper.Current as Android.Content.Context?; 13 call sites updated with explicit ! ✅ Fixed (MEDIUM from prior passes)
d12374d1 Docs: migration guide additions, PackageDiffIgnore.xml, Given_AndroidSkiaXamlRootHost runtime test, spec corrections ✅ Sound

The new Given_AndroidSkiaXamlRootHost runtime test is well-formed: [PlatformCondition(ConditionMode.Include, RuntimeTestPlatforms.SkiaAndroid)] correctly gates it to the Android Skia CI lane; the three synchronous void methods don't await anything so the void return type is correct; reflection-based access avoids a compile-time dependency on the Android assembly.


Verdict: fix-first — 2 inline findings still open

The same two issues from the first two review passes remain unaddressed:

HIGH — UnoSKVulkanView.cs:225 — _activity.NativeLayerHost!.Path = nativeClipPath still uses the null-forgiving !. The canvas view received this fix in commit a2e944b2; the Vulkan view did not. See inline comment.

LOW — NativeWindowWrapper.Android.cs:233 — windowMetrics.Bounds is called unconditionally when windowMetrics can be null. See inline comment.

Neither the re-arm commit (2542a0c9) nor either of the two subsequent commits (080f5262, d12374d1) touched these lines. Both carry a one-line suggestion in their inline comments.

@github-actions

github-actions Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 1m 34s —— View job


Re-review pass 4 — final

  • Gather context from prior review passes
  • Check new commits since pass 3 (d12374d1): two new commits — e903e2dc and 15925978
  • Read current state of UnoSKVulkanView.cs and NativeWindowWrapper.Android.cs
  • Check for any new issues in new commits
  • Update summary

What the 2 new commits addressed

Commit Topic Status
e903e2dc Guard null context in StoreContextExtension review flow ✅ Sound
15925978 Null-guard Vulkan clip (NativeLayerHost) and window metrics ✅ Both prior findings fixed

e903e2dc — StoreContextExtension.OnComplete previously cast ContextHelper.Current to Activity unconditionally at the top of the method, including on the early-return path that never used it. Now the is not Activity activity check sits after the early return and returns StoreRateAndReviewStatus.Error (instead of throwing InvalidCastException) when no foreground activity is available. The fix is correct and the logging guard follows the file's own conventions.

15925978 — Addresses the two remaining blockers:

  • UnoSKVulkanView.cs:225 (HIGH, flagged 3 times): _activity.NativeLayerHost!.Path = nativeClipPath is now if (_activity.NativeLayerHost is { } nativeLayerHost) { nativeLayerHost.Path = nativeClipPath; } — matches the canvas view pattern exactly. ✅
  • NativeWindowWrapper.Android.cs:232–236 (LOW, flagged 3 times): windowMetrics is null guard inserted before windowMetrics.Bounds — eliminates the latent NullReferenceException on a null WindowManager. ✅

Verdict: ship

All inline findings from the three prior review passes are now resolved. No new issues introduced by the two new commits. The architecture is sound, the lifecycle fixes are correct, and the StoreContextExtension null-guard is a proper fix (not a guard-over-a-broken-invariant). The only outstanding items are the deliberate follow-ups documented in the PR body and the known-follow-ups section, none of which are merge blockers.

The draft status pending the on-device smoke-test remains the last gate before promote-to-ready.

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/androidunsingleton branch from 1592597 to 0c0e514 Compare August 20, 2026 12:42
@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 3m 15s —— View job


Re-review pass 5 — post-rebase check

  • Update comment with task list
  • Check new commits since pass 4
  • Read changed files for new findings
  • No inline comments needed — no new issues found
  • Update summary

What triggered this pass

The branch was rebased after the pass 4 ship verdict, changing all 11 commit SHAs without altering the diff content. The PR synchronize event fired because of the force-push. No new code was added.

Verification of pass-4 fixes

Both pass-4 blockers are confirmed present in the rebased commits:

Finding File Status
HIGH — Vulkan NativeLayerHost! null-forgiving UnoSKVulkanView.cs:225 ✅ if (_activity.NativeLayerHost is { } nativeLayerHost)
LOW — GetWindowSize null chain on windowMetrics NativeWindowWrapper.Android.cs:232–236 ✅ if (windowMetrics is null) return default;

The GetWindowInsets method at line 189 (activity.WindowManager?.CurrentWindowMetrics.WindowInsets) has a similar CurrentWindowMetrics→.WindowInsets null chain, but that code was not touched by this PR and was pre-existing before the branch diverged from feature/breakingchanges — not a new finding to block this PR.

Verdict: ship

No new issues. All prior findings resolved. The only remaining gate is the on-device smoke-test (launch/render, touch, text input, rotation, background→foreground, config-change re-creation) noted in the PR description as the reason it remains a draft.

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/androidunsingleton branch from 0c0e514 to 10cb8c2 Compare August 21, 2026 15:50
@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 3m 16s —— View job


Re-review pass 6 — post-rebase check

  • Update comment with task list
  • Check new commits since pass 5
  • Read changed files for new findings
  • No inline comments needed — no new issues found
  • Update summary

What triggered this pass

The branch was rebased again (second rebase since the pass 4 ship verdict), changing all 11 commit SHAs without altering the diff content. No new code was introduced.

Verification of pass-4/pass-5 fixes

All prior blockers confirmed present in the rebased commits:

Finding File Status
HIGH — Vulkan NativeLayerHost! null-forgiving UnoSKVulkanView.cs:225 ✅ if (_activity.NativeLayerHost is { } nativeLayerHost)
MEDIUM — ContextHelper.Current non-nullable return type ContextHelper.cs ✅ Return type is Android.Content.Context? with #nullable enable
LOW — GetWindowSize null chain on windowMetrics NativeWindowWrapper.Android.cs:232–235 ✅ if (windowMetrics is null) return default;
MEDIUM — Guard in StoreContextExtension review flow StoreContextExtension.cs:74 ✅ if (ContextHelper.Current is not Activity activity) after early-return

The pre-existing GetWindowInsets null chain (activity.WindowManager?.CurrentWindowMetrics.WindowInsets at line 189) remains — it was not touched by this PR and is not a merge blocker.

Verdict: ship

No new issues. All prior findings resolved. The only remaining gate is the on-device smoke-test (launch/render, touch, text input, rotation, background→foreground, config-change re-creation) noted in the PR description as the reason it remains a draft.

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/androidunsingleton branch from 10cb8c2 to b366505 Compare August 22, 2026 09:51
@github-actions

github-actions Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 3m 46s —— View job


Re-review pass 7 — post-synchronize check

  • Update comment with task list
  • Check new commits since pass 6
  • Read changed files for new findings
  • No inline comments needed — no new issues found
  • Update summary

What triggered this pass

The branch was rebased again (third rebase since the pass 4 ship verdict), changing all 11 commit SHAs without altering the diff content (642 additions, 185 deletions, 32 files — identical to prior passes). No new code was introduced.

Verification of prior fixes

All prior blockers confirmed present in the rebased commits:

Finding File Status
HIGH — Vulkan NativeLayerHost! null-forgiving UnoSKVulkanView.cs:225 ✅ if (_activity.NativeLayerHost is { } nativeLayerHost)
MEDIUM — ContextHelper.Current non-nullable return type ContextHelper.cs ✅ Return type is Android.Content.Context? with #nullable enable
LOW — GetWindowSize null chain on windowMetrics NativeWindowWrapper.Android.cs:232–235 ✅ if (windowMetrics is null) return default;
MEDIUM — Guard in StoreContextExtension review flow StoreContextExtension.cs:74 ✅ if (ContextHelper.Current is not Activity activity) after early-return

Full diff sweep findings

A fresh pass over all 32 changed files turned up no new issues:

  • UnoSKCanvasView.TeardownRenderer (ResetContext + Dispose) is safe to call from OnDestroy: surfaceDestroyed runs before OnDestroy and blocks until the GL thread finishes, so the thread is idle when teardown runs.
  • ExtensionsRegistrar per-window input-source registrations (IXamlRootHost → PointerSource/KeyboardSource) follow the same factory pattern as the Win32 runtime; the ArgumentException on a non-AndroidSkiaXamlRootHost is the correct hard failure for a misconfigured target.
  • Given_AndroidSkiaXamlRootHost runtime test is well-formed: [PlatformCondition(ConditionMode.Include, SkiaAndroid)], reflection-based access, and three scenarios that cover host registration, activity identity, and per-window input-source stability.
  • No event Action / event Action<T> violations. No new async void without guards. No new NoWarn/#pragma warning disable growth.
  • The pre-existing GetWindowInsets null chain at NativeWindowWrapper.Android.cs:189 (activity.WindowManager?.CurrentWindowMetrics.WindowInsets) remains — it was not touched by this PR and is not a merge blocker.

Verdict: ship

No new issues. All prior findings resolved. The only remaining gate is the on-device smoke-test (launch/render, touch, text input, rotation, background→foreground, config-change re-creation) noted in the PR description as the reason it remains a draft.

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/androidunsingleton branch from b366505 to 4d0334d Compare August 29, 2026 15:05
@MartinZikmund
MartinZikmund changed the base branch from feature/breakingchanges to master September 2, 2026 20:02
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/androidunsingleton branch from 4d0334d to e8677bb Compare September 2, 2026 20:30
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 1m 2s —— View job


Re-review pass 8 — post-rebase check

  • Check new commits since pass 7
  • Diff current HEAD against origin/master and compare to the previously-reviewed diff
  • Re-verify the two long-standing findings are still fixed in the current commit set
  • Sweep for any new issues
  • Update summary

What triggered this pass

The branch was rebased again since the pass 7 ship verdict — all 11 commit SHAs changed (HEAD is now e8677bbf), but the diff content against origin/master is byte-for-byte identical: 649 insertions / 192 deletions across the same 32 files, matching every prior pass. No new code was introduced.

Verification of prior fixes

Both blockers from the earliest review passes remain fixed in the current commits:

Finding File Status
HIGH — Vulkan NativeLayerHost! null-forgiving UnoSKVulkanView.cs:227 ✅ if (_activity.NativeLayerHost is { } nativeLayerHost)
LOW — GetWindowSize null chain on windowMetrics NativeWindowWrapper.Android.cs:236–242 ✅ if (windowMetrics is null) return default;

The MEDIUM findings from earlier passes (ContextHelper.Current nullable return type, the StoreContextExtension review-flow guard) are also still present as fixed, per the pass-4/pass-6 verification.

Full sweep for new issues

Since the diff is unchanged from pass 7's fully-reviewed content, no new inline comments were posted. Nothing new surfaced:

  • No event Action / event Action<T> violations.
  • No new async void without a wrapping try/catch, no .Result/.GetAwaiter().GetResult().
  • No Generated/ folder edits, no platform-suffix violations.
  • No new NoWarn/#pragma warning disable growth.
  • The pre-existing, untouched GetWindowInsets null chain (NativeWindowWrapper.Android.cs:189) remains out of scope for this PR.

Verdict: ship

No new issues. All previously-flagged findings remain resolved. The only remaining gate — noted in the PR description — is the on-device smoke test (launch/render, touch, text input, rotation, background→foreground, config-change re-creation), which keeps this PR in draft.

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/androidunsingleton branch from e8677bb to 639118d Compare September 3, 2026 07:33
MartinZikmund and others added 22 commits October 8, 2026 11:58
The recreation tests reflected on ApplicationActivity.Instance, which the
de-singletoning removed, so trimming the Android heads failed (IL2037).
Resolve the activity driving the test window through its XamlRoot host
instead, and compare the first-frame gate with its int value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DtsKbXbA642EduoduiNtt4
- ContextHelper.Current's setter is now internal: the value is owned by the
  activity lifecycle, and an app-assigned value was overwritten anyway. With
  several activities an outside write would point lookups at the wrong one,
  and internalizing it after 7.0 would be a binary break.
- Remove ApplicationViewHelper.GetBaseActivityEvents() and
  IBaseActivityEvents: no Skia activity implements the interface, so it
  always returned null. The docs now point to
  Application.RegisterActivityLifecycleCallbacks.
- Stop pointing ContextHelper.Current users at a XamlRoot lookup that has
  no public API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DtsKbXbA642EduoduiNtt4
The r8 pin works around an NPE that R8 9.1.31 hits in release mode while
desugaring androidx.core without shrinking. Debug never needed it: the SDK
already dexes through R8 with shrinking off. Pinning it there turned
shrinking on with no JNI keep rules (AndroidLinkMode=None generates none),
which stripped AndroidX and crashed the Debug head on launch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GUsTVQvbj18pADVocyZaSj
SurfaceDestroyed disposed the renderer, context and native window even
when the render thread outlived the join, racing its in-flight frame.
Leave them to the process teardown instead, as TeardownRenderer does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ed8fDt9yDQpZwoTfCyNUhU
The wrapper kept observing the destroyed activity and carried its attach
state over, so the pre-draw gate could open before the new activity's
content view attached.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ed8fDt9yDQpZwoTfCyNUhU
Both read internal host members through reflection, which NativeAOT
trims, so they fail there without a product fault.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ed8fDt9yDQpZwoTfCyNUhU
A render thread that outlived the SurfaceDestroyed join kept reading the
view's shared swapchain, renderer and native window fields while the
abandon path nulled them and the next surface's thread overwrote them.
Each render thread now creates, uses and releases its own resources, so
a straggler never sees a successor's objects and frees its own once its
frame ends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014MKMBCoDVcXf5j7uLvSTtL
The registry gains an activity at construction, so a destroyed
activity could hand the ambient context to a replacement that had not
reached OnCreate yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014MKMBCoDVcXf5j7uLvSTtL
ContextHelper.Current is now null once the last activity is destroyed,
while the process (and background handlers such as NetworkStatusChanged)
can stay alive. System services, package info and the content resolver
don't need an activity, so they now come from ApplicationContext.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0169CMCUD6YcRAtuZYm4qJpX
BaseActivity.Current is cleared on OnPause/OnStop, so creating the window
after OnLaunched awaited something that paused the activity (e.g. a
permission prompt) threw. Fall back to the most recently active live
activity, which ContextHelper keeps until it is destroyed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0169CMCUD6YcRAtuZYm4qJpX
The public Activity*Handler delegates only typed IBaseActivityEvents'
events. With the interface gone they have no consumer, and removing them
later would be its own binary break.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0169CMCUD6YcRAtuZYm4qJpX
ContextHelper.Current is now null by design once the last activity is
destroyed, so warning on every read there spammed advice about the
MainActivity base class that doesn't apply.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0169CMCUD6YcRAtuZYm4qJpX
A throwing render teardown skipped base.OnDestroy() (SuperNotCalled) and
the static unsubscriptions, leaking the activity; on the GL thread it
crossed JNI and killed the process with no managed log.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0169CMCUD6YcRAtuZYm4qJpX
OnCreate runs before OnStart builds the per-activity render view, so the
"recreated activity reuses the render view" branch can no longer run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0169CMCUD6YcRAtuZYm4qJpX
The paused case resolves the host activity with BaseActivity.Current
cleared, as OnPause leaves it. The input-source test now checks the
host hands out its window wrapper's sources; the old same-instance
check passed against a process-wide singleton too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0169CMCUD6YcRAtuZYm4qJpX
Asserts the re-created activity takes the window, reopens the first-frame
gate (the black-app regression only happened on this path) and becomes
ContextHelper.Current. Also keeps XamlRootMap.GetHostForRoot for the
reflective lookups under trimming.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0169CMCUD6YcRAtuZYm4qJpX
Repoints the TODO to #8341, aligns Current's contract with the migration
guide and records the emulator validation and the current SamplesApp head.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0169CMCUD6YcRAtuZYm4qJpX

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 17s —— View job


Re-review: post-synchronize check

  • Check new commits since the last pass
  • Read the diffs of the commits I hadn't seen
  • No inline comments needed

Verdict: ship (diff read only; no Android build or on-device run)

The earlier passes covered the branch up to 15991d3c. The tip is now 7cb6eb2f, and the new commits are mostly the ones the PR description already lists as second-panel fixes. I read these:

  • 1206685b: AndroidSkiaWindowFactory.ResolveHostActivity() falls back to ContextHelper.Current when BaseActivity.Current is null while paused. That fixes the paused-window case, and the #8341 TODO is kept.
  • 8bd2d245: ContextHelper warns about a null Current only if no activity ever existed. Current's setter now goes through SetForeground, so there is one mutation point.
  • 7cb6eb2f: spec text only.

I did not read the other new commits in detail: 84956750, b4f2c8d4 and 3cb8618a (all touched in earlier passes), plus 680b2406, a216047c and 3319490e. The PR description and the earlier passes cover them.

Still open (tracked in their own threads):

  • Adopted native views keep the old activity's Context. You deferred this to 7.x.
  • The TEMP Android NativeAOT CI condition in .azure-devops-tests-android-nativeaot-skia.yml must be reverted before merge.
  • The on-device smoke test is still pending, so the PR stays in draft.
    · branch dev/mazi/androidunsingleton

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 238155 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 1141

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DisplayInformation.png-dark
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • Examples.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • DropDownButtonPage.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
  • skia-windows-screenshots: 1141 changed over 2474

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedIconPage.png-dark
    • AppBarButtonWithIconTest.png
    • Basics_Automated.png-dark
    • Basics_Automated.png
    • BindableDrawerLayout_ChangePane.png-dark
    • BindableDrawerLayout_ChangePane.png
    • BorderTopwithmargins.png-dark
    • BorderTopwithmargins.png
    • BorderVersusPanelClipping.png-dark
    • BorderVersusPanelClipping.png
    • Border_CornerRadius_Alignments.png-dark
    • Border_CornerRadius_Alignments.png
    • Border_Simple_No_Background_With_TextBox.png-dark
    • Border_Simple_No_Background_With_TextBox.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • Brushes_ImplicitConvert.png-dark
    • Brushes_ImplicitConvert.png

@unodevops

Copy link
Copy Markdown
Contributor

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/build Categorizes an issue or PR as relevant to build infrastructure area/skia ✏️ Categorizes an issue or PR as relevant to Skia kind/documentation 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.

SamplesApp Android Debug head crashes on launch: R8 shrinks with no JNI keep rules

5 participants