-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Microsoft.Android.Sdk.ILLink] fix crash when TZ changes (#7956)
Fixes: #7953 Context: 11f0e1b When a timezone changes in a `Release` config app, it can crash with: [monodroid] Unable to find Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()! In commit 11f0e1b, we removed the line: <?xml version="1.0" encoding="utf-8" ?> <linker> <assembly fullname="Mono.Android"> -- <type fullname="Android.Runtime.AndroidEnvironment" /> Unfortunately, `AndroidEnvironment.NotifyTimeZoneChanged()` is called from non-managed code, via: * The `NotifyTimeZoneChanges` broadcast receiver (in `src/java-runtime/java/mono/android/app/NotifyTimeZoneChanges.java`) which calls- * The `Rutime.notifyTimeZoneChanged()` `native` method (in `src/java-runtime/java/mono/android/Runtime.java`), implemented in- * `Java_mono_android_Runtime_notifyTimeZoneChanged()` (in`src/monodroid/jni/timezones.cc`). The managed linker cannot "see" any of these references, so we need to *always* preserve this method, as it is always callable. Update `src/Microsoft.Android.Sdk.ILLink/PreserveLists/Mono.Android.xml` so that `Android.Runtime.AndroidEnvironment.NotifyTimeZoneChanged()` is always preserved. Added a test for this scenario. TODO: we may want to audit all `mono_class_get_method_from_name()` calls and add more tests cases. I also cleaned up the tests a bit with a `getResource()` local function.
- Loading branch information
1 parent
a693bc5
commit 837ca0d
Showing
4 changed files
with
42 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
22 changes: 22 additions & 0 deletions
22
tests/MSBuildDeviceIntegration/Resources/LinkDescTest/PreserveTest.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Reflection; | ||
|
||
public class PreserveTest | ||
{ | ||
// [Test] | ||
public static string MethodsArePreserved () | ||
{ | ||
try { | ||
// See src/monodroid/jni/timezones.cc for usage | ||
var androidEnvironment = Type.GetType ("Android.Runtime.AndroidEnvironment, Mono.Android", throwOnError: true); | ||
var notifyTimeZoneChanged = androidEnvironment.GetMethod ("NotifyTimeZoneChanged", BindingFlags.Static | BindingFlags.NonPublic); | ||
if (notifyTimeZoneChanged == null) { | ||
return $"[FAIL] {nameof (PreserveTest)}.{nameof (MethodsArePreserved)} FAILED: {nameof (notifyTimeZoneChanged)} is null)"; | ||
} | ||
notifyTimeZoneChanged.Invoke (null, null); | ||
return $"[PASS] {nameof (PreserveTest)}.{nameof (MethodsArePreserved)}"; | ||
} catch (Exception ex) { | ||
return $"[FAIL] {nameof (PreserveTest)}.{nameof (MethodsArePreserved)} FAILED: {ex}"; | ||
} | ||
} | ||
} |
This file contains 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