Skip to content

Commit

Permalink
Use complete Java.Interop (#1231)
Browse files Browse the repository at this point in the history
Start using complete Java.Interop, ie. `Debug` and `Release`
configurations instead of `XAIntegrationDebug` and
`XAIntegrationRelease`.

Add Java.Interop java sources to the list of sources to build
mono.android.jar. This is needed for `ManagedPeer` and other classes
with java counterparts.

Few updates to distinguish between `Android.Runtime.JavaObject` and
`Java.Interop.JavaObject`.

Added System.Collections reference is for `List<JniSurfacedPeerInfo>`
return type in `AndroidValueManager`.
  • Loading branch information
radekdoulik authored and jonpryor committed Jan 25, 2018
1 parent 0ec02f4 commit 7d32ef3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 189 deletions.
178 changes: 0 additions & 178 deletions Xamarin.Android.sln

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build-tools/scripts/JavaCallableWrappers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/>
<ItemGroup>
<_JavaSources Include="$(IntermediateOutputPath)jcw\src\**\*.java" />
<_JavaSources Include="$(JavaInteropSourceDirectory)\src\Java.Interop\java\com\xamarin\**\*.java" />
</ItemGroup>
<WriteLinesToFile
File="$(IntermediateOutputPath)jcw\classes.txt"
Expand Down
2 changes: 1 addition & 1 deletion external/Java.Interop
39 changes: 39 additions & 0 deletions src/Mono.Android/Android.Runtime/AndroidRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public AndroidRuntimeOptions (IntPtr jnienv, IntPtr vm, bool allocNewObjectSuppo
NewObjectRequired = !allocNewObjectSupported;
ObjectReferenceManager = new AndroidObjectReferenceManager ();
TypeManager = new AndroidTypeManager ();
ValueManager = new AndroidValueManager ();
}
}

Expand Down Expand Up @@ -225,5 +226,43 @@ protected override IEnumerable<string> GetSimpleReferences (Type type)
.Concat (Enumerable.Repeat (j, 1));
}
}

class AndroidValueManager : JniRuntime.JniValueManager {

public override void WaitForGCBridgeProcessing ()
{
JNIEnv.WaitForBridgeProcessing ();
}

public override void AddPeer (IJavaPeerable value)
{
throw new NotImplementedException ();
}

public override void RemovePeer (IJavaPeerable value)
{
throw new NotImplementedException ();
}

public override IJavaPeerable PeekPeer (JniObjectReference reference)
{
throw new NotImplementedException ();
}

public override void CollectPeers ()
{
throw new NotImplementedException ();
}

public override void FinalizePeer (IJavaPeerable value)
{
throw new NotImplementedException ();
}

public override List<JniSurfacedPeerInfo> GetSurfacedPeers ()
{
throw new NotImplementedException ();
}
}
}
#endif // JAVA_INTEROP
14 changes: 6 additions & 8 deletions src/Mono.Android/Java.Interop/JavaConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ public static T FromJavaObject<T>(IJavaObject value, out bool set)
set = true;
return value._JavaCast<T>();
}
var o = value as JavaObject;
if (o != null) {
if (value is Android.Runtime.JavaObject o) {
set = true;
if (o.Instance is T)
return (T) o.Instance;
Expand Down Expand Up @@ -255,8 +254,7 @@ public static object FromJavaObject (IJavaObject value, Type targetType = null)
return JavaObjectExtensions.JavaCast (value, targetType);
}

var o = value as JavaObject;
if (o != null) {
if (value is Android.Runtime.JavaObject o) {
if (targetType == null)
return o.Instance;
return Convert.ChangeType (o.Instance, targetType);
Expand Down Expand Up @@ -306,7 +304,7 @@ public static IJavaObject ToJavaObject<T>(T value)
Func<object, IJavaObject> converter = GetJavaObjectConverter (typeof (T));
if (converter != null)
return converter (value);
return new JavaObject (value);
return new Android.Runtime.JavaObject (value);
}

static Dictionary<Type, Func<object, IntPtr>> LocalJniHandleConverters = new Dictionary<Type, Func<object, IntPtr>> {
Expand Down Expand Up @@ -352,8 +350,8 @@ public static IJavaObject ToJavaObject<T>(T value)
using (var v = new Java.Lang.String (value.ToString ()))
return JNIEnv.ToLocalJniHandle (v);
} },
{ typeof (JavaObject), value => {
return value == null ? IntPtr.Zero : JNIEnv.ToLocalJniHandle (new JavaObject (value));
{ typeof (Android.Runtime.JavaObject), value => {
return value == null ? IntPtr.Zero : JNIEnv.ToLocalJniHandle (new Android.Runtime.JavaObject (value));
} },
};

Expand All @@ -364,7 +362,7 @@ static Func<object, IntPtr> GetLocalJniHandleConverter<T> (T value, Type sourceT
return converter;
if (value != null && LocalJniHandleConverters.TryGetValue (value.GetType (), out converter))
return converter;
return LocalJniHandleConverters [typeof (JavaObject)];
return LocalJniHandleConverters [typeof (Android.Runtime.JavaObject)];
}

public static TReturn WithLocalJniHandle<TValue, TReturn>(TValue value, Func<IntPtr, TReturn> action)
Expand Down
4 changes: 4 additions & 0 deletions src/Mono.Android/Mono.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<HintPath>$(OutputPath)..\v1.0\System.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Collections">
<HintPath>$(OutputPath)..\v1.0\Facades\System.Collections.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Core">
<HintPath>$(OutputPath)..\v1.0\System.Core.dll</HintPath>
<Private>False</Private>
Expand Down
3 changes: 1 addition & 2 deletions src/Mono.Android/Mono.Android.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
Outputs="$(OutputPath)\..\v1.0\Java.Interop.dll">
<MSBuild
Projects="$(JavaInteropFullPath)\src\Java.Interop\Java.Interop.csproj"
Properties="Configuration=XAIntegration$(Configuration)"
/>
<ItemGroup>
<Assembly Include="$(JavaInteropFullPath)\bin\XAIntegration$(Configuration)\*.dll*" />
<Assembly Include="$(JavaInteropFullPath)\bin\$(Configuration)\*.dll*" />
</ItemGroup>
<Copy
SourceFiles="@(Assembly)"
Expand Down

0 comments on commit 7d32ef3

Please sign in to comment.