Skip to content
Closed
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
7 changes: 5 additions & 2 deletions src/Mono.Android/Android.Animation/AnimatorSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Android.Animation
{
public partial class AnimatorSet
{
static Delegate cb_setDuration_SetDuration_J_Landroid_animation_Animator_;
static Delegate? cb_setDuration_SetDuration_J_Landroid_animation_Animator_;

[Register ("setDuration", "(J)Landroid/animation/Animator;", "GetSetDuration_JHandler")]
public override unsafe Android.Animation.Animator SetDuration (long duration)
Expand All @@ -16,7 +16,8 @@ public override unsafe Android.Animation.Animator SetDuration (long duration)
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (duration);
var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, __args);
return global::Java.Lang.Object.GetObject<Android.Animation.Animator> (__rm.Handle, JniHandleOwnership.TransferLocalRef);
var __ret = global::Java.Lang.Object.GetObject<Android.Animation.Animator> (__rm.Handle, JniHandleOwnership.TransferLocalRef);
return __ret ?? throw new InvalidOperationException ("Unable to marshal the return value to a managed Android.Animation.Animator instance.");
} finally {
}
}
Expand All @@ -35,6 +36,8 @@ static IntPtr n_SetDuration_J (IntPtr jnienv, IntPtr native__this, long duration

try {
var __this = global::Java.Lang.Object.GetObject<Android.Animation.AnimatorSet> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
if (__this is null)
throw new InvalidOperationException ("Unable to marshal the native handle to a managed Android.Animation.AnimatorSet instance.");
return JNIEnv.ToLocalJniHandle (__this.SetDuration (duration));
} catch (global::System.Exception __e) {
__r.OnUserUnhandledException (ref __envp, __e);
Expand Down
7 changes: 5 additions & 2 deletions src/Mono.Android/Android.Animation/ValueAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Android.Animation
{
public partial class ValueAnimator
{
static Delegate cb_setDuration_SetDuration_J_Landroid_animation_Animator_;
static Delegate? cb_setDuration_SetDuration_J_Landroid_animation_Animator_;

[Register ("setDuration", "(J)Landroid/animation/Animator;", "GetSetDuration_JHandler")]
public override unsafe Android.Animation.Animator SetDuration (long duration)
Expand All @@ -16,7 +16,8 @@ public override unsafe Android.Animation.Animator SetDuration (long duration)
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (duration);
var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, __args);
return global::Java.Lang.Object.GetObject<Android.Animation.Animator> (__rm.Handle, JniHandleOwnership.TransferLocalRef);
var __ret = global::Java.Lang.Object.GetObject<Android.Animation.Animator> (__rm.Handle, JniHandleOwnership.TransferLocalRef);
return __ret ?? throw new InvalidOperationException ("Unable to marshal the return value to a managed Android.Animation.Animator instance.");
} finally {
}
}
Expand All @@ -35,6 +36,8 @@ static IntPtr n_SetDuration_J (IntPtr jnienv, IntPtr native__this, long duration

try {
var __this = global::Java.Lang.Object.GetObject<Android.Animation.ValueAnimator> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
if (__this is null)
throw new InvalidOperationException ("Unable to marshal the native handle to a managed Android.Animation.ValueAnimator instance.");
return JNIEnv.ToLocalJniHandle (__this.SetDuration (duration));
} catch (global::System.Exception __e) {
__r.OnUserUnhandledException (ref __envp, __e);
Expand Down
8 changes: 4 additions & 4 deletions src/Mono.Android/Android.App/AlertDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public partial class Builder {

public event EventHandler<Android.Widget.AdapterView.ItemSelectedEventArgs> ItemSelected {
add {
AndroidEventHelper.AddEventHandler<AdapterView.IOnItemSelectedListener, AdapterView.IOnItemSelectedListenerImplementor>(
EventHelper.AddEventHandler<AdapterView.IOnItemSelectedListener, AdapterView.IOnItemSelectedListenerImplementor>(
ref weak_implementor_SetOnItemSelectedListener,
CreateItemSelectedImplementor,
__SetOnItemSelectedListener,
__h => __h.OnItemSelectedHandler += value);
}
remove {
AndroidEventHelper.RemoveEventHandler<AdapterView.IOnItemSelectedListener, AdapterView.IOnItemSelectedListenerImplementor>(
EventHelper.RemoveEventHandler<AdapterView.IOnItemSelectedListener, AdapterView.IOnItemSelectedListenerImplementor>(
ref weak_implementor_SetOnItemSelectedListener,
AdapterView.IOnItemSelectedListenerImplementor.__IsEmpty,
__SetOnItemSelectedListener,
Expand All @@ -34,14 +34,14 @@ public event EventHandler<Android.Widget.AdapterView.ItemSelectedEventArgs> Item

public event EventHandler<Android.Widget.AdapterView.NothingSelectedEventArgs> NothingSelected {
add {
AndroidEventHelper.AddEventHandler<AdapterView.IOnItemSelectedListener, AdapterView.IOnItemSelectedListenerImplementor>(
EventHelper.AddEventHandler<AdapterView.IOnItemSelectedListener, AdapterView.IOnItemSelectedListenerImplementor>(
ref weak_implementor_SetOnItemSelectedListener,
CreateItemSelectedImplementor,
__SetOnItemSelectedListener,
__h => __h.OnNothingSelectedHandler += value);
}
remove {
AndroidEventHelper.RemoveEventHandler<AdapterView.IOnItemSelectedListener, AdapterView.IOnItemSelectedListenerImplementor>(
EventHelper.RemoveEventHandler<AdapterView.IOnItemSelectedListener, AdapterView.IOnItemSelectedListenerImplementor>(
ref weak_implementor_SetOnItemSelectedListener,
AdapterView.IOnItemSelectedListenerImplementor.__IsEmpty,
__SetOnItemSelectedListener,
Expand Down
4 changes: 2 additions & 2 deletions src/Mono.Android/Android.App/SyncContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static bool EnsureLooper ([NotNullWhen (true)]Looper? looper, SendOrPostCallback
return true;
}

public override void Post (SendOrPostCallback d, object state)
public override void Post (SendOrPostCallback d, object? state)
{
var looper = Application.Context?.MainLooper;
if (!EnsureLooper (looper, d))
Expand All @@ -35,7 +35,7 @@ public override void Post (SendOrPostCallback d, object state)
}
}

public override void Send (SendOrPostCallback d, object state)
public override void Send (SendOrPostCallback d, object? state)
{
var looper = Looper.MainLooper;
if (!EnsureLooper (looper, d))
Expand Down
2 changes: 2 additions & 0 deletions src/Mono.Android/Android.Bluetooth/BluetoothDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ public sealed partial class BluetoothDevice
{
// These methods were obsoleted as a warning in API-31
[global::System.Obsolete ("This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.")]
[global::System.Runtime.Versioning.ObsoletedOSPlatformAttribute ("android37.0")]
[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android26.0")]
public unsafe Android.Bluetooth.BluetoothGatt? ConnectGatt (Android.Content.Context? context, bool autoConnect, Android.Bluetooth.BluetoothGattCallback? @callback, [global::Android.Runtime.GeneratedEnum] Android.Bluetooth.BluetoothTransports transport, [global::Android.Runtime.GeneratedEnum] Android.Bluetooth.LE.ScanSettingsPhy phy)
=> ConnectGatt (context, autoConnect, @callback, transport, (Android.Bluetooth.BluetoothPhy) phy);

[global::System.Obsolete ("This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.")]
[global::System.Runtime.Versioning.ObsoletedOSPlatformAttribute ("android37.0")]
[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android26.0")]
public unsafe Android.Bluetooth.BluetoothGatt? ConnectGatt (Android.Content.Context? context, bool autoConnect, Android.Bluetooth.BluetoothGattCallback? @callback, [global::Android.Runtime.GeneratedEnum] Android.Bluetooth.BluetoothTransports transport, [global::Android.Runtime.GeneratedEnum] Android.Bluetooth.LE.ScanSettingsPhy phy, Android.OS.Handler? handler)
=> ConnectGatt (context, autoConnect, @callback, transport, (Android.Bluetooth.BluetoothPhy) phy, handler);
Expand Down
10 changes: 5 additions & 5 deletions src/Mono.Android/Android.Content.Res/IXmlResourceParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public partial interface IXmlResourceParser : Android.Util.IAttributeSet, IXmlPu
{
#region These members are dare defined here to avoid conflicts between IAttributeSet and IXmlPullParser.

int AttributeCount { get; }
new int AttributeCount { get; }

string PositionDescription { get; }
new string PositionDescription { get; }

string GetAttributeName (int pos);
string GetAttributeValue (int pos);
string? GetAttributeValue (string? ns, string? name);
new string GetAttributeName (int pos);
new string GetAttributeValue (int pos);
new string? GetAttributeValue (string? ns, string? name);
#endregion
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mono.Android/Android.Graphics/AndroidBitmapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override int GetHashCode ()
}

/// <inheritdoc />
public override bool Equals (object value)
public override bool Equals (object? value)
{
if (!(value is AndroidBitmapInfo))
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/Mono.Android/Android.Graphics/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public override string ToString ()
return FormattableString.Invariant ($"Color [A={A}, R={R}, G={G}, B={B}]");
}

public override bool Equals (object obj)
public override bool Equals (object? obj)
{
if (!(obj is Color))
return false;
Expand Down Expand Up @@ -440,7 +440,7 @@ public override Type MarshalType {
get { return typeof (int); }
}

public override Color CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type targetType)
public override Color CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type? targetType)
{
throw new NotImplementedException ();
}
Expand All @@ -457,7 +457,7 @@ public override void DestroyGenericArgumentState (Color value, ref JniValueMarsh

[RequiresDynamicCode (ExpressionRequiresUnreferencedCode)]
[RequiresUnreferencedCode (ExpressionRequiresUnreferencedCode)]
public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type targetType)
public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type? targetType)
{
var c = typeof (Color).GetConstructor (new[]{typeof (int)})!;
var v = Expression.Variable (typeof (Color), sourceValue.Name + "_val");
Expand Down
2 changes: 1 addition & 1 deletion src/Mono.Android/Android.OS/AsyncTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class AsyncTask<
> : AsyncTask {

static IntPtr java_class_handle;
internal static IntPtr class_ref {
internal static new IntPtr class_ref {
get {
return JNIEnv.FindClass ("android/os/AsyncTask", ref java_class_handle);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Mono.Android/Android.Runtime/InputStreamAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ public override int Read ()
return BaseStream.ReadByte ();
}

public override int Read (byte[] bytes)
public override int Read (byte[]? bytes)
{
ArgumentNullException.ThrowIfNull (bytes);
return Read (bytes, 0, bytes.Length);
}

public override int Read (byte[] bytes, int offset, int length)
public override int Read (byte[]? bytes, int offset, int length)
{
ArgumentNullException.ThrowIfNull (bytes);
int res = BaseStream.Read (bytes, offset, length);
if (res == 0)
return -1;
Expand Down
34 changes: 21 additions & 13 deletions src/Mono.Android/Android.Runtime/JNIEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ public static partial class JNIEnv {

static Array ArrayCreateInstance (Type elementType, int length)
{
if (RuntimeFeature.TrimmableTypeMap) {
if (RuntimeFeature.IsCoreClrRuntime) {
// CoreCLR runtime type loader can construct any T[] dynamically.
// IsDynamicCodeSupported is a [FeatureGuard] so this branch is
// dead-coded under PublishAot.
return Array.CreateInstance (elementType, length);
}
if (System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) {
return Array.CreateInstance (elementType, length);
}

if (RuntimeFeature.TrimmableTypeMap) {
if (RuntimeFeature.IsNativeAotRuntime) {
// NativeAOT: resolve via per-rank typemap + generated array proxy.
if (TrimmableTypeMap.Instance.TryGetArrayProxy (elementType, additionalRank: 1, out var arrayProxy)) {
Expand All @@ -47,9 +44,18 @@ static Array ArrayCreateInstance (Type elementType, int length)
$"ensure the mapping is emitted for that rank (for example by increasing _AndroidTrimmableTypeMapMaxArrayRank) or report an issue.");
}

#pragma warning disable IL3050 // legacy fallback path
return Array.CreateInstance (elementType, length);
#pragma warning restore IL3050
if (RuntimeFeature.ManagedTypeMap) {
return ArrayCreateInstanceWithSuppression (elementType, length);

[UnconditionalSuppressMessage ("Trimming", "IL3050:RequiresDynamicCode",
Justification = "Temporarily suppressed for the \"ManagedTypeMap\".")]
Array ArrayCreateInstanceWithSuppression (Type elementType, int length)
{
return Array.CreateInstance (elementType, length);
}
}

throw new NotSupportedException ($"It is not possible to create an array with element type '{elementType}'.");
}

static int GetArrayRank (Type elementType)
Expand Down Expand Up @@ -433,7 +439,7 @@ public static unsafe IntPtr NewObject (IntPtr jclass, IntPtr jmethod, params JVa
return NewObject (jclass, jmethod, p);
}

public static string GetClassNameFromInstance (IntPtr jobject)
public static string? GetClassNameFromInstance (IntPtr jobject)
{
return JniEnvironment.Types.GetJniTypeNameFromInstance (new JniObjectReference (jobject));
}
Expand Down Expand Up @@ -486,6 +492,8 @@ static unsafe IntPtr monovm_typemap_managed_to_java (Type type, byte* mvidptr)
if (RuntimeFeature.IsMonoRuntime) {
ret = monovm_typemap_managed_to_java (type, mvidptr);
} else if (RuntimeFeature.IsCoreClrRuntime) {
if (type.FullName is null)
return null;
ret = RuntimeNativeMethods.clr_typemap_managed_to_java (type.FullName, (IntPtr)mvidptr);
} else {
throw new NotSupportedException ("Internal error: unknown runtime not supported");
Expand Down Expand Up @@ -695,7 +703,7 @@ public static void CopyArray (IntPtr src, string[] dest)
// FIXME: Since a Dictionary<Type, Func> is used here, the trimmer will not be able to properly analyze `Type t`
// error IL2111: Method 'lambda expression' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method.
[UnconditionalSuppressMessage ("Trimming", "IL2067", Justification = "FIXME: https://github.com/xamarin/xamarin-android/issues/8724")]
static object? GetObject (IntPtr e, Type t) =>
static object? GetObject (IntPtr e, Type? t) =>
Java.Lang.Object.GetObject (e, JniHandleOwnership.TransferLocalRef, t);
} },
{ typeof (Array), (type, source, index) => {
Expand All @@ -717,7 +725,7 @@ static TValue GetConverter<TValue>(Dictionary<Type, TValue> dict, Type? elementT
}

if (array != IntPtr.Zero) {
string type = GetClassNameFromInstance (array);
string? type = GetClassNameFromInstance (array);
if (type == null || type.Length < 1 || type [0] != '[')
throw new InvalidOperationException ("Unsupported java array type: " + type);

Expand Down
4 changes: 2 additions & 2 deletions src/Mono.Android/Android.Runtime/JavaCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,12 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
return GetEnumerator ()!;
}

public IEnumerator<T?> GetEnumerator ()
public new IEnumerator<T?> GetEnumerator ()
{
return System.Linq.Extensions.ToEnumerator_Dispose<T> (Iterator());
}

public static ICollection<T>? FromJniHandle (IntPtr handle, JniHandleOwnership transfer)
public new static ICollection<T>? FromJniHandle (IntPtr handle, JniHandleOwnership transfer)
{
if (handle == IntPtr.Zero)
return null;
Expand Down
8 changes: 4 additions & 4 deletions src/Mono.Android/Android.Runtime/JavaDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,11 @@ public V this [K key] {
}
}

public ICollection<K> Keys {
public new ICollection<K> Keys {
get { return new JavaSet<K> (GetKeys (), JniHandleOwnership.TransferLocalRef); }
}

public ICollection<V> Values {
public new ICollection<V> Values {
get { return new JavaCollection<V> (GetValues (), JniHandleOwnership.TransferLocalRef); }
}

Expand Down Expand Up @@ -588,7 +588,7 @@ IEnumerator IEnumerable.GetEnumerator ()
return GetEnumerator ();
}

public IEnumerator<KeyValuePair<K, V>> GetEnumerator ()
public new IEnumerator<KeyValuePair<K, V>> GetEnumerator ()
{
foreach (K key in Keys)
#pragma warning disable CS8604 // Possible null reference argument.
Expand Down Expand Up @@ -640,7 +640,7 @@ public bool TryGetValue (K key, out V value)
return ContainsKey (key);
}

public static IDictionary<K, V>? FromJniHandle (IntPtr handle, JniHandleOwnership transfer)
public new static IDictionary<K, V>? FromJniHandle (IntPtr handle, JniHandleOwnership transfer)
{
if (handle == IntPtr.Zero)
return null;
Expand Down
8 changes: 4 additions & 4 deletions src/Mono.Android/Android.Runtime/JavaList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public virtual bool ContainsAll (JavaList collection)
return true;
}

public virtual bool Equals (Java.Lang.Object obj)
public virtual new bool Equals (Java.Lang.Object obj)
{
var collection = obj as JavaList;
if (collection == null || Count != collection.Count)
Expand Down Expand Up @@ -785,7 +785,7 @@ internal unsafe void InternalSet (int location, T value)

// C#'s IList<T> allows nulls but is not annotated as MaybeNull.
[MaybeNull]
public T this [int index] {
public new T this [int index] {
[return: MaybeNull]
#pragma warning disable CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member because of nullability attributes.
get {
Expand Down Expand Up @@ -879,7 +879,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
return GetEnumerator ()!;
}

public IEnumerator<T?> GetEnumerator ()
public new IEnumerator<T?> GetEnumerator ()
{
return System.Linq.Extensions.ToEnumerator_Dispose<T> (Iterator ());
}
Expand Down Expand Up @@ -960,7 +960,7 @@ public bool Remove (T item)
return true;
}

public static IList<T>? FromJniHandle (IntPtr handle, JniHandleOwnership transfer)
public new static IList<T>? FromJniHandle (IntPtr handle, JniHandleOwnership transfer)
{
if (handle == IntPtr.Zero)
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/Mono.Android/Android.Runtime/JavaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ public override int GetHashCode ()
return inst.GetHashCode ();
}

public override string? ToString ()
public override string ToString ()
{
if (inst == null)
return "";
return inst.ToString ();
return inst.ToString () ?? "";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mono.Android/Android.Runtime/JavaProxyThrowable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Android.Runtime {

sealed class JavaProxyThrowable : Java.Lang.Error {

public readonly Exception InnerException;
public readonly new Exception InnerException;

JavaProxyThrowable (string message, Exception innerException)
: base (message)
Expand Down
Loading