Skip to content

Commit 0140ab8

Browse files
radekdoulikjonpryor
authored andcommitted
[Mono.Android] Make TypeManager a normal Java.Lang.Object (#1537)
Context: https://github.com/xamarin/xamarin-android/projects/1 The idea: use `jnimarshalmethod-gen.exe` to generate *JNI Marshal Methods* at packaging time, so that we can avoid using as much reflection for method registration, and *entirely avoid* using `System.Reflection.Emit` for marshal method registration. The problem: The Java type `mono.android.TypeManager` is Just Like every other `Java.Lang.Object` C# subclass, in that it's a Java `native` method that is registered with a C# delegate via `JNIEnv.RegisterJniNatives()`. *Unlike* every other `Java.Lang.Object` subclass, it wasn't actually a `Java.Lang.Object` subclass. It Just Happened To Work because it `JNIEnv.RegisterJniNatives()` used Reflection to find the registration methods/etc., but it was otherwise "unique". Being unique was fine, but in our desired new `jnimarshalmethod-gen.exe` World Order™, being unique *isn't* fine; it means it won't participate in packaging-time marshal method generation, thus requiring use of `System.Reflection.Emit`, which is undesirable. Add a new internal `Java.Interop.TypeManager.JavaTypeManager` type to use as the C# peer for `mono.android.TypeManager`, make `TypeManager.JavaTypeManager` a normal `Java.Lang.Object` subclass, then update `mono.android.TypeManager` to register `Java.Interop.TypeManager+JavaTypeManager`. This removes the "uniqueness" of `mono.android.TypeManager`, allowing it to be processed normally by `jnimarshalmethod-gen.exe`.
1 parent 648aff9 commit 0140ab8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Mono.Android/Java.Interop/TypeManager.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,5 +358,20 @@ public static void RegisterPackages (string[] packages, Converter<string, Type>[
358358
}
359359
}
360360
}
361+
362+
[Register ("mono/android/TypeManager", DoNotGenerateAcw = true)]
363+
internal class JavaTypeManager : Java.Lang.Object
364+
{
365+
[Register ("activate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)V", "")]
366+
static void n_Activate (IntPtr jnienv, IntPtr jclass, IntPtr typename_ptr, IntPtr signature_ptr, IntPtr jobject, IntPtr parameters_ptr)
367+
{
368+
TypeManager.n_Activate (jnienv, jclass, typename_ptr, signature_ptr, jobject, parameters_ptr);
369+
}
370+
371+
internal static Delegate GetActivateHandler ()
372+
{
373+
return TypeManager.GetActivateHandler ();
374+
}
375+
}
361376
}
362377
}

src/Mono.Android/java/mono/android/TypeManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public static void Activate (String typeName, String sig, Object instance, Objec
1313
String methods =
1414
"n_activate:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)V:GetActivateHandler\n" +
1515
"";
16-
mono.android.Runtime.register ("Java.Interop.TypeManager, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", TypeManager.class, methods);
16+
mono.android.Runtime.register ("Java.Interop.TypeManager+JavaTypeManager, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", TypeManager.class, methods);
1717
}
1818
}

0 commit comments

Comments
 (0)