Skip to content

Commit eadd3bd

Browse files
authored
[Mono.Android] Unbind Cursor.setNotificationUris() (#5124)
Fixes: #5027 Context: dotnet/java-interop#699 The [`Cursor.setnotificationUris(ContentResolver, List<Uri>)`][0] interface default method was added in API-29. This introduces an issue when implementing `Android.Database.ICursor` in API-30+: when binding a Java class that implements `Cursor`: // Java public class MyCursor implements android.database.Cursor { // … } In the binding `generator` emits for `MyCursor`, the Java-to-managed marshal method to support `Cursor.setNotificationUris()` does not compile, as it tries to use a generic type -- `IList<T>` -- without providing any generic type parameters: // C# binding public partial class MyCursor : Java.Lang.Object, ICursor { static void n_SetNotificationUris_1 (IntPtr jnienv, IntPtr native__this, IntPtr native_cr, IntPtr native_uris) { var __this = Java.Lang.Object.GetObject<MyCursor> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); var cr = Java.Lang.Object.GetObject<ContentResolver> (native_cr, JniHandleOwnership.DoNotTransfer); var uris = (System.Collections.Generic.IList`1) Java.Lang.Object.GetObject<System.Collections.Generic.IList`1> (native_uris, JniHandleOwnership.DoNotTransfer); __this.SetNotificationUris (cr, uris); } } We had thought that dotnet/java-interop@262743b47 addressed this issue, but we were mistaken. The `generator` fix for this scenario seems tricky, so as a workaround for now we can simply remove the `Cursor.setNotificationUris()` default method so users can implement the interface. (Although the method was added in API-29, we don't support Default Interface Members in API-29, so it was ignored. Thus, this problem doesn't show up until API-30+ is used.) [0]: https://developer.android.com/reference/android/database/Cursor#setNotificationUris(android.content.ContentResolver,%20java.util.List%3Candroid.net.Uri%3E)
1 parent b17f8aa commit eadd3bd

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Mono.Android/metadata

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,10 @@
16261626
<attr path="/api/package[@name='android.database']/class[@name='CursorJoiner']/method[@name='iterator' and count(parameter)=0]" name="return-not-null">true</attr>
16271627
<attr api-since="24" path="/api/package[@name='android.icu.text']/class[@name='UnicodeSet']/method[@name='iterator' and count(parameter)=0]" name="return-not-null">true</attr>
16281628

1629+
<!-- If you try to implement ICursor in API-30+, we generate an invalid invoker for this method due to the
1630+
generic parameters. Since this is a default method we can just remove it until that bug is fixed.
1631+
https://github.com/xamarin/java.interop/issues/699 -->
1632+
<remove-node api-since="30" path="/api/package[@name='android.database']/interface[@name='Cursor']/method[@name='setNotificationUris' and count(parameter)=2 and parameter[1][@type='android.content.ContentResolver'] and parameter[2][@type='java.util.List&lt;android.net.Uri&gt;']]" />
16291633

16301634
<!--
16311635
***********************************************************************

0 commit comments

Comments
 (0)