Repository navigation
[Android] Prevent Shell crashes when loading flyout or back button icons - #40691
Conversation
…rride: a stream icon load that throws crashes the app from async void UpdateLeftBarButtonItem
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Selected Tests
🧪 Test selection — click to expand
🧪 UI tests —
|
| Platform | Categories |
|---|---|
| Android | Shell1, Shell2 |
📊 Results — succeeded: 5 passed, 0 failed of 5 jobs
🔗 All test results · Build logs
| Job | Result |
|---|---|
| Android UITests CoreClr Controls (API 30) Shell1 | ✅ succeeded |
| Android UITests CoreClr Controls (API 30) Shell2 | ✅ succeeded |
| Android UITests Shell Renderer Controls Shell Renderer (API 30) Shell1 | ✅ succeeded |
| Android UITests Shell Renderer Controls Shell Renderer (API 30) Shell2 | ✅ succeeded |
| Build UITests CoreCLR Sample App Build Sample App | ✅ succeeded |
🧪 Device tests — Controls.Shell on Android
✅ maui-pr-devicetests #1702761 passed.
GPT-6.2 Sol: Run Android Controls.Shell device tests for icon fallback and cancellation regressions.
MAI Code 2: Run Android Controls.Shell device tests for failed and superseded flyout/back-button icon loads.
🧪 Ran — 1 category on Android
| Platform | Categories |
|---|---|
| Android | Controls.Shell |
📊 Results — succeeded: 2 passed, 0 failed of 2 jobs
🔗 All test results · Build logs
| Job | Result |
|---|---|
| net11.0 CoreCLR Android Helix Tests Run DeviceTests Android (CoreCLR) | ✅ succeeded |
| net11.0 CoreCLR ios/catalyst/android Helix Tests Build Device Tests (CoreCLR) | ✅ succeeded |
⏭️ Skipped — what neither suite runs
UI tests — 75 categories, 3 platforms
Platforms not run: iOS, MacCatalyst, Windows
Categories not run: Accessibility, ActionSheet, ActivityIndicator, Animation, AppLinks, Border, BoxView, Brush, Button, CarouselView, CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7, Cells, CheckBox, ContextActions, CustomRenderers, DatePicker, Dispatcher, DisplayAlert, DisplayPrompt, DragAndDrop, Entry, Editor, Effects, Essentials, FlyoutPage, Focus, Fonts, Frame, Gestures, GraphicsView, Image, ImageButton, IndicatorView, InputTransparent, IsEnabled, IsVisible, Label, Layout, Lifecycle, ManualReview, Maps, Navigation, Page, Performance, Picker, ProgressBar, RadioButton, RefreshView, SafeAreaEdges, Shadow, ScrollView, SearchBar, Shape, Slider, SoftInput, Stepper, Switch, SwipeView, TabbedPage, TableView, TimePicker, TitleView, ToolbarItem, Triggers, ViewBaseTests, VisualStateManager, Window, WebView, Material3
Each skipped platform and category is listed as a maui-pr-uitests (skipped) … status on this commit. Use /azp run maui-pr-uitests for the full suite.
Device tests — 104 categories, 3 platforms
Platforms not run: iOS, MacCatalyst, Windows
Categories not run: Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay, Graphics, Essentials, BlazorWebView
Each skipped platform and project is listed as a maui-pr-devicetests (skipped) … status on this commit. Use /azp run maui-pr-devicetests for the full suite.
🤖 Why these tests — AI rationale (GPT-6.2 Sol + MAI Code 2)
UI tests
Each model chose independently; every test that runs was selected by at least one of them.
| Platform | GPT-6.2 Sol | MAI Code 2 |
|---|---|---|
| Android | Shell1, Shell2 |
Shell1, Shell2 |
| iOS | — | — |
| MacCatalyst | — | — |
| Windows | — | — |
GPT-6.2 Sol — Run both Android Shell UI shards for the flyout and back-button icon fallback change.
- Android ShellToolbarTracker changes how the flyout and back icons fall back on load failure or cancellation; run both Shell UI shards.
- Other platforms and categories are excluded because shared navigation and image loading are unchanged.
MAI Code 2 — Android-only Shell navigation icon failure handling; runs Shell UI and device coverage on Android.
- ShellToolbarTracker change is under the Android Shell compatibility handler, so select only Android.
- Flyout and back-button icon loading/fallback directly affects the Shell UI category; use the Shell umbrella for its CI shards.
- No other platform code or broadly shared base infrastructure changed, so iOS, MacCatalyst, Windows, full UI runs, and unrelated categories are excluded.
Device tests
Each model chose independently; every test that runs was selected by at least one of them.
| Platform | GPT-6.2 Sol | MAI Code 2 |
|---|---|---|
| Android | Controls.Shell |
Controls.Shell |
| iOS | — | — |
| MacCatalyst | — | — |
| Windows | — | — |
GPT-6.2 Sol — Run Android Controls.Shell device tests for icon fallback and cancellation regressions.
- ShellTests.Android.cs adds regressions for failed icon streams and for current and superseded cancellations.
- The fix is confined to Android Shell; no Core handler or shared device infrastructure changed.
MAI Code 2 — Run Android Controls.Shell device tests for failed and superseded flyout/back-button icon loads.
- The production change is in the Android Controls Shell toolbar tracker, and the added Shell.Android device tests target this behavior.
- Controls.Shell covers flyout and back-button icon loading, cancellation, and fallback; no Core handler or wider project category is changed.
- The change and tests are Android-only, so other platforms and a full device run are excluded.
Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification.
| }); | ||
|
|
||
| await AssertEventually(() => streamRequested.Task.IsCompleted, | ||
| message: "Shell did not request the canceled icon stream."); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - This case starts with the default hamburger already installed and asserts the same drawable type and progress after cancellation. streamRequested is signaled before the exception reaches the tracker, and AssertEventually returns immediately when its predicate matches. An unconditional OperationCanceledException return that skips fallback for a still-current request therefore also satisfies this test, even though it would leave an old custom icon installed in an app. Install and assert a custom icon first, as the IOException theory does, then assign the canceled source so the final assertion requires a transition back to the default.
f1cba67
into
dotnet:candidate/11.0.1xx-sr3
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). This is test infrastructure for the .NET 12 (`main`) line, so it targets `main`. ### Description of Change Migrate all repository test execution from **Helix + XHarness** to plain **`dotnet test`** on **Microsoft.Testing.Platform (MTP)**. This PR carries the migration from #39918 (by @mattleibow, commits preserved) brought up to date with current `main` (.NET 12 SDK, `/review run-device-tests`, recent product and test fixes), plus the follow-up fixes needed to make it build and pass on .NET 12. #### Why we need this - **One way to run tests, everywhere.** Today unit tests run through Arcade's Helix SDK (`eng/helix.proj`), device tests through Helix + XHarness (`eng/helix_xharness.proj`), Appium tests through Cake, and locally through yet other scripts. After this change the same command — `dotnet test --project <test project>` (plus `--device` for mobile) — runs every suite on a developer machine, in CI, and in the Copilot review gate. A CI failure can be reproduced locally with the exact command CI used. - **Remove a fragile, opaque layer.** Helix/XHarness add payload zipping, remote queues, a job monitor, custom work-item scripts and a separate result path. Many recurring device-test infra failures (XHarness exit 78/80/83 `APP_LAUNCH_FAILURE`/`APP_CRASH`, Helix jobs never scheduled, stale or missing `testResults.xml`, queue/image drift such as XHarness requiring an iPhone 11 Pro device type that iOS 27.1+ no longer ships) come from that layer, not from MAUI. Direct execution on the agent gives real logs, real exit codes and the actual device in the job. - **Genuine, trustworthy results.** Every suite now produces the test framework's own TRX via MTP (`--report-trx`), and empty selections or missing reports fail the job instead of silently passing. On Android/iOS the native app's own TRX is collected and reconciled with the host proxy, so a crash cannot be reported as a pass. - **Modern test stack.** xUnit v2 + VSTest + XHarness test runners are replaced by **xUnit v3 + MTP**, which is what the .NET SDK `dotnet test` and device (`--device`) support is built on. This unblocks newer xUnit features (`TestContext`, cancellation, `Assert.Skip*`) and keeps us on the path the SDK supports directly. - **Fewer moving parts to maintain.** Removes `eng/helix.proj`, `eng/helix_xharness.proj`, the Helix pipeline stages, the XHarness CLI tool, and the XHarness/Helix package dependencies. #### What changes - **Unit tests**: all repository xUnit suites move to xUnit v3 (`4.0.2`) on MTP (`2.5.1`); `global.json` selects `Microsoft.Testing.Platform` as the `dotnet test` runner. CI (`stage-unit-tests.yml`) runs each project with `dotnet test --project … --report-trx` on Windows and macOS (Debug and Release) and validates the TRX (`eng/scripts/Assert-TestResults.ps1`). Helix unit-test stages are removed. - **Device tests** (Controls, Core, Graphics, Essentials, BlazorWebView): the XHarness/visual runners are replaced by native MTP hosts — Android instrumentation, the normal Apple MAUI app/scene lifecycle, and an owned Windows MSIX/unpackaged launcher. `maui-pr-devicetests` runs them directly on device-capable agents (`stage-device-tests.yml`, `device-tests-steps.yml`) with job-owned emulators/simulators. - **UI tests (Appium)** stay on NUnit, now hosted on MTP with matching fixture-failure, retry and attachment handling. - **Integration tests** run with `dotnet test`; legacy `--filter` selectors are translated to MTP filters. iOS template apps are launched with `simctl` on a dedicated simulator instead of XHarness. - **Local tooling** (`Run-DeviceTests.ps1`, Cake, review-gate scripts, skills/instructions) updated to the same direct commands. #### Changes made while bringing #39918 onto current `main` - Merged `main` (.NET 12 move #40060, `/review run-device-tests` #40545, review-gate removal #40595, and other fixes) and resolved 23 conflicts. - **`/review run-device-tests` selection ported** to the direct template: `ci-device-tests.yml` passes `selectedRun`/`selectedPlatforms`/`selectedProjects`/`selectedFilters`, and `stage-device-tests.yml` runs only the selected platforms and projects with the selected category skip-lists. Verified with the AzDO YAML preview API (full run: 28 jobs; a sample selection of Android+iOS / Controls+Essentials with `SkipCategories=Shell,Label`: exactly 4 jobs with that filter). `eng/helix_xharness.proj` is no longer a trusted dispatch path. - **Device tests default to `net12.0` and CoreCLR only** — the .NET 12 mobile workloads no longer provide Mono (same as #40060). - Took main's Switch hover-resource fix (#40209) over the PR's earlier variant; kept the HybridWebView asset-ownership change together with main's `DynamicDependency`. - Ported main's UI-test retry recovery rules (#40407) into the shared `UITestRetry.cs` used by Cake and MTP. - Dropped the XHarness-only simulator runtime selection (`SelectLatestIOSVersion`) and its tests; runtime/device-type selection is covered by `SimulatorTests`. #### Fixes found by running CI / locally after the merge - **xUnit v3 adaptation of tests added on `main`**: `TestContext.Current.CancellationToken` (xUnit1051), source-info constructor for `WindowsFact` (xUnit3003); `UITest.NUnit.Tests` and the Windows launcher build for the repo TFM instead of `net11.0`. - **Async-void / inline continuation differences in xUnit v3** (v2's `AsyncTestSyncContext` hid them): - `ListProxyTests.SynchronizedCollectionAdd` leaked thread-static dispatcher options onto a thread-pool thread, so later tests got a dispatcher that always required dispatch (68 Storyboard failures in macOS Release). Restored after use; fixtures reset the options. - Shell tests resumed inline from `Navigated`, so the *next* tests ran inside Shell's navigation callback and had their implicit routes reset (`DeferPopNavigation(Pop)`). Verified locally by detecting `FireNavigatedEvents` on the next test's stack before/after the change. - **Native runner thread affinity** (test bodies run on the thread pool, not the UI thread as under XHarness): `WillTerminateDestroysMainPageWindowOnce` resolved the `Application` off the UI thread; the CarouselView leak test posted a UIKit notification off the UI thread. - **iOS simulator selection**: only use device types that the runtime lists (device-specific iOS 27.1 builds only accept one, causing `SimError 403 Incompatible device`), and prefer the iPhone 11 Pro profile XHarness used (Shell flyout header geometry tests from #39877 fail on Dynamic Island phones; passes on iPhone 11 Pro, fails on iPhone 16 — reproduced locally). - **Mac Catalyst**: `dotnet test` starts the app executable directly, so unlike `open`/XHarness it isn't activated; activate it before running (animated CarouselView scrolls intermittently never finished). - **Integration tests**: shut down build servers after installing the test workloads — reused MSBuild nodes kept a stale workload resolver and nested `UseWorkload=true` sample builds failed with NU1015 (reproduced locally; Samples macOS now passes in CI). The Android `maui-blazor` + `TrimMode=full` row is skipped explicitly: the previous runner silently dropped `TrimMode`, and Blazor does not support full trimming (dotnet/aspnetcore#63951). - **Windows `HybridWebView` disconnect** NRE when `CoreWebView2` is not (or no longer) initialized — exposed by the new fixture teardown that disconnects every handler. - Docs spellcheck word, and a template boolean comparison so the device stage doesn't expand to zero jobs. - **UI-test retry reconciliation**: when a fixture's `OneTimeSetUp` fails, NUnit reports its `[Ignore]`d tests as failed and the retry reports them skipped. MTP's TRX names classes of fixtures with arguments (every UI-test fixture, e.g. `EditorFeatureTests(Windows)`) by namespace only, so the ignored tests were never matched as recovered and the job failed although the retry passed. Replaying the real CI TRX/NUnit reports reproduces the failure before the fix and merges cleanly after it; `FixtureRecoveryReconcilesIgnoredTestsInParameterizedFixtures` covers it. - **iOS CarouselView test timing** (`Animated ScrollTo Does Not Report Positions It Passes Over`, failed on every native CI run, passed under Helix): with logging, every failing run showed a still-queued initial-position pass scrolling back to page 0 without animation, cancelling the test's animated `ScrollTo`. Under the native runner the test can resume between those queued passes. The test now lets them drain; full-class cold runs went from 2/9 failing to 5/5 passing, and it passes in CI. - **`main` build breaks from re-enabled CA1416** (#40663): carried the fixes from #40708 (merged) and #40720 (`UISettings.AnimationsEnabledChanged` in `PlatformTicker` and `MotionPolicy` requires Windows 10.0.19041). The Windows errors only surfaced one project at a time because `Core` references `Essentials`. ### Validation Local (macOS arm64, .NET SDK `12.0.100-alpha.1.26523.103`, Debug, `dotnet test --project <csproj> --report-trx`): | Project | Result | | --- | --- | | Controls.Xaml.UnitTests | 2,327 passed, 8 skipped | | Controls.Core.UnitTests | 7,453 passed, 30 skipped | | Controls.BindingSourceGen.UnitTests | 135 passed | | SourceGen.UnitTests | 997 passed | | Core.UnitTests | 1,147 passed | | Resizetizer.UnitTests | 795 passed, 3 skipped | | Essentials.UnitTests | 520 passed | | Essentials.ExternalBackend.UnitTests | 6 passed | | Graphics.Tests | 406 passed | | VisualTestUtils.MagickNet.Tests | 13 passed | | MauiBlazorWebView.UnitTests | 70 passed | | MauiBlazorWebView.ExternalHandler.UnitTests | 52 passed | | UITest.NUnit.Tests | 50 passed, 5 skipped | | TestUtils.UnitTests | 61 passed, 1 skipped | Pester (pipeline/runner scripts): `Direct-TestDevice`, `Cake-Mtp`, `RunTests`, `NUnitMtp`, `XunitMtp`, `Run-DeviceTests`, `WindowsTestPackage`, `Assert-TestResults`, `CopilotPipeline`, `Review-PR`, `Verify-TestsFail`, `BuildAndRunHostApp`, `Review-Tests`, `Recover-MissedReviewCommands`: 600+ passed. The only remaining failure (`handles qualified selections in every stage guard`, expects 10 vs 11) also fails on `main` and is unrelated. Note: `StoryboardTests.StoppingFromPropertyChangingDuringATakeoverRaisesOnePairOfNotifications` (added on `main`) is culture-sensitive and fails under a comma-decimal locale on `main` as well; it passes under `en-US` as in CI. #### CI Every pipeline was run with `/azp run` on this PR and on validation-only drafts: - #40703: this PR's changes on `net11`. - #40705: the #40703 changes plus sample PRs #40696, #40660, #40654 and #40691, to check that tests added by other PRs run under the native runners. - #40706: this PR plus sample PR #40669. Failures were compared against `main`/`net11` Helix baselines by test name. | Pipeline | This PR (`main`) | `net11` validation (#40703 / #40705) | | --- | --- | --- | | `maui-pr` (build, pack, unit tests, integration) | ✅ 35/35 jobs (with the CA1416 fixes) | ✅ 33/33 jobs | | `maui-pr-devicetests` | ✅ Android, iOS, Mac Catalyst except `PageTransitions` tests that fail identically in `main`'s Helix runs | ✅ Android, iOS, Mac Catalyst; only intermittent single-test failures that don't repeat across runs | | `maui-pr-uitests` (Appium on MTP) | ✅ 133/134 jobs; the only failure, WinUI `SharedElementLandsAndSourceIsRestoredAfterPop`, also fails on `main`'s Helix runs | ✅ 130/133; see below | Remaining UI-test failures on `net11`, none of them regressions: - `DragAndDropWithAnElementThatIsRemoved` (Mac Catalyst) fails in 2 of the last 10 `net11` Helix runs too. - The RefreshView tests failed only on #40705, which includes RefreshView sample PR #40660. - The `vlatest` shard failed because the agent couldn't download the iOS 18.5 simulator runtime. - Material3 (API 36) screenshots in the last two runs came out 87 px taller. #40603, merged on `net11` yesterday, now crops by the status-bar height that Appium reports. The same tree and emulator setup passed 430/433 in the two previous runs. **Known remaining device-test blockers (from #39918, not regressions of this merge):** packaged Windows MSIX installation is rejected with `0x800B0109` (the temporary signer is not a trusted root on the agent image — needs owner-provided signing/provisioning), and the Windows Controls unpackaged suite can terminate with `0xDEAD` after ~350 tests (native composition resource exhaustion investigated in #39918). ### Issues Fixed No product issue. Supersedes/continues #39918. --------- Co-authored-by: Matthew Leibowitz <mattleibow@live.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Target Branch
mainnet11, for reviewFor .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into
net11; agents must not retarget or merge.Issue details
On Android, an app can crash when Shell loads a custom hamburger or back-button icon from a stream. This affects both the Shell handler and renderer. The stream may throw an exception, for example, when downloading an icon while offline, or MAUI may cancel an in-progress load when a toolbar refresh requests the same icon again.
Root cause
Both Android Shell implementations use UpdateLeftBarButtonItem. This async void method awaited the icon load without handling exceptions. As a result, a load failure or cancellation could propagate to the Android UI thread and crash the app.
Description of change
The ShellToolbarTracker now handles exceptions during icon loading. If the current request fails or is canceled, Shell logs a warning and falls back to the existing default hamburger icon or back arrow. If an obsolete request is canceled, Shell ignores it without logging an unnecessary warning or affecting the toolbar.
Issues Fixed
Fixes #40685
Screenshot
40685BeforeFix.mov
40685AfterFix.mov