Skip to content

[release/11.0.1xx][NativeAOT] Initialize the device startup time zone offset - #13365

Open
simonrozsival wants to merge 2 commits into
release/11.0.1xxfrom
simonrozsival-nativeaot-offset-backport-11-0-1xx
Open

simonrozsival wants to merge 2 commits into
release/11.0.1xxfrom
simonrozsival-nativeaot-offset-backport-11-0-1xx

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Backport of dotnet/android#13359 to release/11.0.1xx.

Context: dotnet/android#13357

NativeAOT does not initialize System.TimeZoneInfo.LocalDateTimeOffset, leaving the first DateTimeOffset.Now call without the runtime startup-offset fast path. The offset must reflect the Android device at process startup.

Pass the offset computed by NativeAotRuntimeProvider through the Java init declaration to the matching managed UCO, then publish its invariant string before managed JNI runtime creation or application registration. Preserve the release branch's XA_Host_NativeAOT_OnInit call and leave the NativeAOT_OnInit C ABI unchanged. Add the NativeAotStartupOffsetMatchesDevice regression test.

Validation ran with process-local TZ=Pacific/Honolulu, workspace-local SDK/toolchain/NuGet/Gradle directories, CCACHE_DISABLE=1 on the successful retry, and emulator emulator-5554 at API 35 / arm64-v8a.

  • make prepare CONFIGURATION=Release — passed; installed SDK 11.0.100-rtm.26524.110.
  • make leeroy CONFIGURATION=Release — passed on retry; ILCompiler and NativeAOT runtime pack resolved to 11.0.0. One workload warning reported that tools/workload-dependencies has no commit metadata. The first attempt failed because the isolated NUGET_PACKAGES path lacked a trailing slash; retry corrected it.
  • ./dotnet-local.sh build -t:Install -c Release tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -p:TestsFlavor=NativeAOT -p:PublishAot=true -p:RuntimeIdentifier=android-arm64 -p:AndroidSupportedAbis=arm64-v8a -p:IncludeCategories=NativeAOTTimeZone — passed and installed the arm64 test package. The build emitted NativeAOT trim/AOT analysis warnings and XA0036 because AndroidSupportedAbis is deprecated; the selected RuntimeIdentifier was android-arm64.
  • (cd tests/Mono.Android-Tests/Mono.Android-Tests && ../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Release --device emulator-5554 --report-trx --results-directory ../../../bin/TestRelease/TestResults -p:TestsFlavor=NativeAOT -p:PublishAot=true -p:RuntimeIdentifier=android-arm64 -p:IncludeCategories=NativeAOTTimeZone) — passed, 1/1 (NativeAotStartupOffsetMatchesDevice). The installed APK base/split code hashes matched the final AAB.

Context: #13359

Context: #13357

NativeAOT did not initialize System.TimeZoneInfo.LocalDateTimeOffset, leaving the first DateTimeOffset.Now call without the runtime startup-offset fast path. The value must reflect the Android device at process startup rather than a build-time host setting.

Pass the device offset from NativeAotRuntimeProvider through the Java init declaration to the managed UCO, and publish its invariant string before managed JNI runtime creation or application registration. Preserve the release branch XA_Host_NativeAOT_OnInit call and add the NativeAOT device-offset regression test. The NativeAOT_OnInit C ABI remains unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 31, 2026 10:57
@simonrozsival simonrozsival changed the title [NativeAOT] Initialize the device startup time zone offset (backport #13359) [release/11.0.1xx][NativeAOT] Initialize the device startup time zone offset (backport #13359) Oct 31, 2026
@simonrozsival simonrozsival changed the title [release/11.0.1xx][NativeAOT] Initialize the device startup time zone offset (backport #13359) [release/11.0.1xx][NativeAOT] Initialize the device startup time zone offset Oct 31, 2026

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.

🟢 Approval recommended

No active review issues are identified for the NativeAOT device UTC-offset startup change.

No open issues 🎉

What changed in this PR

Backports #13359 to release/11.0.1xx, enabling NativeAOT’s DateTimeOffset.Now startup fast path using the Android device’s UTC offset rather than the build host’s time zone.

Changes:

  • Compute the device offset, including daylight saving time, with support for pre-API-26 devices.
  • Pass the offset through Java/JNI and publish it before managed runtime creation, preserving the existing host initialization call and C ABI.
  • Add a NativeAOT regression test checking the startup value and DateTimeOffset.Now.Offset against the device.
File Description
tests/​Mono.Android-Tests/​Mono.Android-Tests/​System/​TimeZoneTest.cs Adds device-offset regression coverage for NativeAOT.
src/​Xamarin.Android.Build.Tasks/​Resources/​NativeAotRuntimeProvider.java Computes and forwards the device’s startup UTC offset.
src/​Xamarin.Android.Build.Tasks/​Resources/​JavaInteropRuntime.java Adds the offset parameter to the native initialization declaration.
src/​Microsoft.Android.Runtime.NativeAOT/​Android.Runtime.NativeAOT/​JavaInteropRuntime.cs Receives the offset and publishes its invariant string through AppContext.

Review effort: Balanced

This branch has not been deployed

No deployments
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