Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Mono.Android/Android.Runtime/AndroidRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<JniSurfacedPeerInfo> GetSurfacedPeers ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<JniSurfacedPeerInfo> GetSurfacedPeers ()
{
if (RegisteredInstances == null)
Expand Down