diff --git a/external/Java.Interop b/external/Java.Interop index d3636b45ba8..d546a083f31 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit d3636b45ba8823f2ed96572f9f550c458ba79099 +Subproject commit d546a083f3139243243959fbf1d9b7d35f6c2cbf diff --git a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs index d32e1993f1b..918b8377b54 100644 --- a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs +++ b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs @@ -832,7 +832,11 @@ internal void RemovePeer (IJavaPeerable value, IntPtr hash) return null; } - public override void ActivatePeer (IJavaPeerable? self, JniObjectReference reference, ConstructorInfo cinfo, object? []? argumentValues) + public override void ActivatePeer ( + JniObjectReference reference, + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, + ConstructorInfo cinfo, + object?[]? argumentValues) { Java.Interop.TypeManager.Activate (reference.Handle, cinfo, argumentValues); } diff --git a/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs b/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs index 210f6f343a0..e07fda8e225 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs @@ -249,39 +249,12 @@ public override void FinalizePeer (IJavaPeerable value) value.Finalized (); } - public override void ActivatePeer (IJavaPeerable? self, JniObjectReference reference, ConstructorInfo cinfo, object?[]? argumentValues) + public override void ActivatePeer (JniObjectReference reference, [DynamicallyAccessedMembers (Constructors)] Type type, ConstructorInfo cinfo, object?[]? argumentValues) { - try { - ActivateViaReflection (reference, cinfo, argumentValues); - } catch (Exception e) { - var m = string.Format ( - CultureInfo.InvariantCulture, - "Could not activate {{ PeerReference={0} IdentityHashCode=0x{1} Java.Type={2} }} for managed type '{3}'.", - reference, - GetJniIdentityHashCode (reference).ToString ("x", CultureInfo.InvariantCulture), - JniEnvironment.Types.GetJniTypeNameFromInstance (reference), - cinfo.DeclaringType?.FullName); - Debug.WriteLine (m); - - throw new NotSupportedException (m, e); - } - } - - void ActivateViaReflection (JniObjectReference reference, ConstructorInfo cinfo, object?[]? argumentValues) - { - var declType = GetDeclaringType (cinfo); - -#pragma warning disable IL2072 - var self = (IJavaPeerable) System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject (declType); -#pragma warning restore IL2072 - self.SetPeerReference (reference); - - cinfo.Invoke (self, argumentValues); + if (RuntimeFeature.TrimmableTypeMap) + throw new PlatformNotSupportedException ("Activating Java peers is not supported when TrimmableTypeMap is enabled."); - [UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = "🤷‍♂️")] - [return: DynamicallyAccessedMembers (Constructors)] - Type GetDeclaringType (ConstructorInfo cinfo) => - cinfo.DeclaringType ?? throw new NotSupportedException ("Do not know the type to create!"); + base.ActivatePeer (reference, type, cinfo, argumentValues); } public override List GetSurfacedPeers () diff --git a/src/Mono.Android/Microsoft.Android.Runtime/SimpleValueManager.cs b/src/Mono.Android/Microsoft.Android.Runtime/SimpleValueManager.cs index 57d8ef5f84d..bcccf6d6fd1 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/SimpleValueManager.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/SimpleValueManager.cs @@ -207,41 +207,6 @@ public override void FinalizePeer (IJavaPeerable value) value.Finalized (); } - public override void ActivatePeer (IJavaPeerable? self, JniObjectReference reference, ConstructorInfo cinfo, object?[]? argumentValues) - { - try { - ActivateViaReflection (reference, cinfo, argumentValues); - } catch (Exception e) { - var m = string.Format ( - CultureInfo.InvariantCulture, - "Could not activate {{ PeerReference={0} IdentityHashCode=0x{1} Java.Type={2} }} for managed type '{3}'.", - reference, - GetJniIdentityHashCode (reference).ToString ("x", CultureInfo.InvariantCulture), - JniEnvironment.Types.GetJniTypeNameFromInstance (reference), - cinfo.DeclaringType?.FullName); - Debug.WriteLine (m); - - throw new NotSupportedException (m, e); - } - } - - void ActivateViaReflection (JniObjectReference reference, ConstructorInfo cinfo, object?[]? argumentValues) - { - var declType = GetDeclaringType (cinfo); - -#pragma warning disable IL2072 - var self = (IJavaPeerable) System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject (declType); -#pragma warning restore IL2072 - self.SetPeerReference (reference); - - cinfo.Invoke (self, argumentValues); - - [UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = "🤷‍♂️")] - [return: DynamicallyAccessedMembers (Constructors)] - Type GetDeclaringType (ConstructorInfo cinfo) => - cinfo.DeclaringType ?? throw new NotSupportedException ("Do not know the type to create!"); - } - public override List GetSurfacedPeers () { if (RegisteredInstances == null)