diff --git a/build-tools/jnienv-gen/Generator.cs b/build-tools/jnienv-gen/Generator.cs index 14a290c98e4..bfbe2f8e94d 100644 --- a/build-tools/jnienv-gen/Generator.cs +++ b/build-tools/jnienv-gen/Generator.cs @@ -521,7 +521,7 @@ public string ApiName public ParamInfo [] Parameters; // If true, then we initialize the binding on the static ctor, we dont lazy-define it - public bool Prebind; + public bool Prebind = false; // If there is a custom wrapper in JNIEnv (so an automatic one shouldn't be generated) public bool CustomWrapper; diff --git a/src/Microsoft.Android.Runtime.NativeAOT/Microsoft.Android.Runtime.NativeAOT.csproj b/src/Microsoft.Android.Runtime.NativeAOT/Microsoft.Android.Runtime.NativeAOT.csproj index 44ab97c6194..169b9624f38 100644 --- a/src/Microsoft.Android.Runtime.NativeAOT/Microsoft.Android.Runtime.NativeAOT.csproj +++ b/src/Microsoft.Android.Runtime.NativeAOT/Microsoft.Android.Runtime.NativeAOT.csproj @@ -16,6 +16,10 @@ true + + + + diff --git a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs index 918b8377b54..88b8abd8f12 100644 --- a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs +++ b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; -using System.Runtime.CompilerServices; -using System.Runtime.Versioning; using System.Threading; using System.Reflection; @@ -126,7 +124,7 @@ public override JniObjectReference CreateLocalReference (JniObjectReference valu { var r = base.CreateLocalReference (value, ref localReferenceCount); - if (RuntimeFeature.ObjectReferenceLogging) { + if (AndroidRuntimeFeature.ObjectReferenceLogging) { if (Logger.LogLocalRef) { var tname = Thread.CurrentThread.Name; var tid = Thread.CurrentThread.ManagedThreadId; @@ -140,7 +138,7 @@ public override JniObjectReference CreateLocalReference (JniObjectReference valu public override void DeleteLocalReference (ref JniObjectReference value, ref int localReferenceCount) { - if (RuntimeFeature.ObjectReferenceLogging) { + if (AndroidRuntimeFeature.ObjectReferenceLogging) { if (Logger.LogLocalRef) { var tname = Thread.CurrentThread.Name; var tid = Thread.CurrentThread.ManagedThreadId; @@ -154,7 +152,7 @@ public override void DeleteLocalReference (ref JniObjectReference value, ref int public override void CreatedLocalReference (JniObjectReference value, ref int localReferenceCount) { base.CreatedLocalReference (value, ref localReferenceCount); - if (RuntimeFeature.ObjectReferenceLogging) { + if (AndroidRuntimeFeature.ObjectReferenceLogging) { if (Logger.LogLocalRef) { var tname = Thread.CurrentThread.Name; var tid = Thread.CurrentThread.ManagedThreadId; @@ -167,7 +165,7 @@ public override void CreatedLocalReference (JniObjectReference value, ref int lo public override IntPtr ReleaseLocalReference (ref JniObjectReference value, ref int localReferenceCount) { var r = base.ReleaseLocalReference (ref value, ref localReferenceCount); - if (RuntimeFeature.ObjectReferenceLogging) { + if (AndroidRuntimeFeature.ObjectReferenceLogging) { if (Logger.LogLocalRef) { var tname = Thread.CurrentThread.Name; var tid = Thread.CurrentThread.ManagedThreadId; @@ -183,7 +181,7 @@ public override IntPtr ReleaseLocalReference (ref JniObjectReference value, ref public override void WriteLocalReferenceLine (string format, params object?[] args) { - if (!RuntimeFeature.ObjectReferenceLogging) { + if (!AndroidRuntimeFeature.ObjectReferenceLogging) { return; } if (!Logger.LogLocalRef) { @@ -196,7 +194,7 @@ public override void WriteLocalReferenceLine (string format, params object?[] ar public override void WriteGlobalReferenceLine (string format, params object?[] args) { - if (!RuntimeFeature.ObjectReferenceLogging) { + if (!AndroidRuntimeFeature.ObjectReferenceLogging) { return; } if (!Logger.LogGlobalRef) { @@ -212,7 +210,7 @@ public override JniObjectReference CreateGlobalReference (JniObjectReference val var r = base.CreateGlobalReference (value); int gc; - if (RuntimeFeature.ObjectReferenceLogging) { + if (AndroidRuntimeFeature.ObjectReferenceLogging) { if (Logger.LogGlobalRef) { var ctype = GetObjectRefType (value.Type); var ntype = GetObjectRefType (r.Type); @@ -251,7 +249,7 @@ static byte GetObjectRefType (JniObjectReferenceType type) public override void DeleteGlobalReference (ref JniObjectReference value) { - if (RuntimeFeature.ObjectReferenceLogging) { + if (AndroidRuntimeFeature.ObjectReferenceLogging) { if (Logger.LogGlobalRef) { var ctype = GetObjectRefType (value.Type); var tname = Thread.CurrentThread.Name; @@ -272,7 +270,7 @@ public override JniObjectReference CreateWeakGlobalReference (JniObjectReference { var r = base.CreateWeakGlobalReference (value); - if (RuntimeFeature.ObjectReferenceLogging) { + if (AndroidRuntimeFeature.ObjectReferenceLogging) { if (Logger.LogGlobalRef) { var ctype = GetObjectRefType (value.Type); var ntype = GetObjectRefType (r.Type); @@ -292,7 +290,7 @@ public override JniObjectReference CreateWeakGlobalReference (JniObjectReference public override void DeleteWeakGlobalReference (ref JniObjectReference value) { - if (RuntimeFeature.ObjectReferenceLogging) { + if (AndroidRuntimeFeature.ObjectReferenceLogging) { if (Logger.LogGlobalRef) { var ctype = GetObjectRefType (value.Type); var tname = Thread.CurrentThread.Name; @@ -868,7 +866,7 @@ public override void FinalizePeer (IJavaPeerable value) value.GetType ().ToString (), value.PeerReference.ToString (), value.JniIdentityHashCode, - RuntimeHelpers.GetHashCode (value))); + System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode (value))); } // FIXME: need hash cleanup mechanism. diff --git a/src/Mono.Android/Android.Runtime/AndroidRuntimeInternal.cs b/src/Mono.Android/Android.Runtime/AndroidRuntimeInternal.cs index 1d9848cd4db..c15735beeff 100644 --- a/src/Mono.Android/Android.Runtime/AndroidRuntimeInternal.cs +++ b/src/Mono.Android/Android.Runtime/AndroidRuntimeInternal.cs @@ -15,11 +15,11 @@ public static class AndroidRuntimeInternal static AndroidRuntimeInternal () { - if (RuntimeFeature.IsMonoRuntime) { + if (AndroidRuntimeFeature.IsMonoRuntime) { mono_unhandled_exception = MonoUnhandledException; - } else if (RuntimeFeature.IsCoreClrRuntime) { + } else if (AndroidRuntimeFeature.IsCoreClrRuntime) { mono_unhandled_exception = CoreClrUnhandledException; - } else if (RuntimeFeature.IsNativeAotRuntime) { + } else if (AndroidRuntimeFeature.IsNativeAotRuntime) { mono_unhandled_exception = CoreClrUnhandledException; } else { throw new NotSupportedException ("Internal error: unknown runtime not supported"); diff --git a/src/Mono.Android/Android.Runtime/JNIEnv.cs b/src/Mono.Android/Android.Runtime/JNIEnv.cs index ebfc81cc39b..638e1757f1a 100644 --- a/src/Mono.Android/Android.Runtime/JNIEnv.cs +++ b/src/Mono.Android/Android.Runtime/JNIEnv.cs @@ -26,7 +26,7 @@ public static partial class JNIEnv { static Array ArrayCreateInstance (Type elementType, int length) { - if (RuntimeFeature.TrimmableTypeMap) { + if (AndroidRuntimeFeature.TrimmableTypeMap) { if (System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) { // CoreCLR runtime type loader can construct any T[] dynamically. // IsDynamicCodeSupported is a [FeatureGuard] so this branch is @@ -134,11 +134,11 @@ internal static void PropagateUncaughtException (IntPtr env, IntPtr javaThreadPt Logger.Log (LogLevel.Info, "MonoDroid", "UNHANDLED EXCEPTION:"); Logger.Log (LogLevel.Info, "MonoDroid", javaException.ToString ()); - if (RuntimeFeature.IsMonoRuntime) { + if (AndroidRuntimeFeature.IsMonoRuntime) { MonoDroidUnhandledException (innerException ?? javaException); - } else if (RuntimeFeature.IsCoreClrRuntime) { + } else if (AndroidRuntimeFeature.IsCoreClrRuntime) { ExceptionHandling.RaiseAppDomainUnhandledExceptionEvent (innerException ?? javaException); - } else if (RuntimeFeature.IsNativeAotRuntime) { + } else if (AndroidRuntimeFeature.IsNativeAotRuntime) { ExceptionHandling.RaiseAppDomainUnhandledExceptionEvent (innerException ?? javaException); } else { throw new NotSupportedException ("Internal error: unknown runtime not supported"); @@ -441,7 +441,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)); } @@ -471,7 +471,7 @@ static unsafe IntPtr monovm_typemap_managed_to_java (Type type, byte* mvidptr) internal static unsafe string? TypemapManagedToJava (Type type) { - if (RuntimeFeature.TrimmableTypeMap) { + if (AndroidRuntimeFeature.TrimmableTypeMap) { // The trimmable typemap doesn't use the native typemap tables. // Delegate to the managed TrimmableTypeMap instead. return TrimmableTypeMap.Instance.TryGetJniNameForManagedType (type, out var jniName) ? jniName : null; @@ -491,9 +491,9 @@ static unsafe IntPtr monovm_typemap_managed_to_java (Type type, byte* mvidptr) IntPtr ret; fixed (byte* mvidptr = mvid_data) { - if (RuntimeFeature.IsMonoRuntime) { + if (AndroidRuntimeFeature.IsMonoRuntime) { ret = monovm_typemap_managed_to_java (type, mvidptr); - } else if (RuntimeFeature.IsCoreClrRuntime) { + } else if (AndroidRuntimeFeature.IsCoreClrRuntime) { ret = RuntimeNativeMethods.clr_typemap_managed_to_java (type.FullName, (IntPtr)mvidptr); } else { throw new NotSupportedException ("Internal error: unknown runtime not supported"); @@ -696,7 +696,7 @@ public static void CopyArray (IntPtr src, string[] dest) // FIXME: Since a Dictionary 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) => { @@ -718,7 +718,7 @@ static TValue GetConverter(Dictionary 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); diff --git a/src/Mono.Android/Android.Runtime/JNIEnvInit.cs b/src/Mono.Android/Android.Runtime/JNIEnvInit.cs index c2e7ea913ca..1ad4da0130d 100644 --- a/src/Mono.Android/Android.Runtime/JNIEnvInit.cs +++ b/src/Mono.Android/Android.Runtime/JNIEnvInit.cs @@ -9,7 +9,6 @@ using Java.Interop.Tools.TypeNameMappings; using Microsoft.Android.Runtime; -using RuntimeFeature = Microsoft.Android.Runtime.RuntimeFeature; namespace Android.Runtime { @@ -108,10 +107,10 @@ internal static void InitializeBeforeRuntimeCreation (JnienvInitializeArgs args) // Only used for NativeAOT after the runtime has been created. MonoVM and CoreCLR use Initialize(). internal static void InitializeNativeAotRuntime (JniRuntime runtime, JnienvInitializeArgs args) { - if (!RuntimeFeature.IsNativeAotRuntime) { + if (!AndroidRuntimeFeature.IsNativeAotRuntime) { throw new NotSupportedException ("JNIEnvInit.InitializeNativeAotRuntime can only be used to initialize NativeAOT."); } - if (RuntimeFeature.IsMonoRuntime || RuntimeFeature.IsCoreClrRuntime) { + if (AndroidRuntimeFeature.IsMonoRuntime || AndroidRuntimeFeature.IsCoreClrRuntime) { throw new NotSupportedException ("Internal error: NativeAOT cannot be enabled with MonoVM or CoreCLR."); } @@ -125,11 +124,11 @@ internal static void InitializeNativeAotRuntime (JniRuntime runtime, JnienvIniti [UnmanagedCallersOnly] internal static unsafe void Initialize (JnienvInitializeArgs* args) { - if (RuntimeFeature.IsNativeAotRuntime) { + if (AndroidRuntimeFeature.IsNativeAotRuntime) { throw new NotSupportedException ("JNIEnvInit.Initialize cannot be used to initialize NativeAOT."); } - if (RuntimeFeature.IsMonoRuntime == RuntimeFeature.IsCoreClrRuntime) { - throw new NotSupportedException ("Internal error: exactly one of RuntimeFeature.IsMonoRuntime or RuntimeFeature.IsCoreClrRuntime must be enabled."); + if (AndroidRuntimeFeature.IsMonoRuntime == AndroidRuntimeFeature.IsCoreClrRuntime) { + throw new NotSupportedException ("Internal error: exactly one of AndroidRuntimeFeature.IsMonoRuntime or AndroidRuntimeFeature.IsCoreClrRuntime must be enabled."); } IntPtr total_timing_sequence = IntPtr.Zero; @@ -157,7 +156,7 @@ internal static unsafe void Initialize (JnienvInitializeArgs* args) args->propagateUncaughtExceptionFn = (IntPtr)(delegate* unmanaged)&PropagateUncaughtException; - if (!RuntimeFeature.TrimmableTypeMap) { + if (!AndroidRuntimeFeature.TrimmableTypeMap) { args->registerJniNativesFn = (IntPtr)(delegate* unmanaged)&RegisterJniNatives; } RunStartupHooksIfNeeded (); @@ -170,11 +169,11 @@ internal static unsafe void Initialize (JnienvInitializeArgs* args) internal static JniRuntime.JniTypeManager CreateTypeManager (JnienvInitializeArgs args) { - if (RuntimeFeature.TrimmableTypeMap) { + if (AndroidRuntimeFeature.TrimmableTypeMap) { return new TrimmableTypeMapTypeManager (); } - if (RuntimeFeature.IsNativeAotRuntime || RuntimeFeature.ManagedTypeMap) { + if (AndroidRuntimeFeature.IsNativeAotRuntime || AndroidRuntimeFeature.ManagedTypeMap) { return new ManagedTypeManager (); } @@ -183,15 +182,15 @@ internal static JniRuntime.JniTypeManager CreateTypeManager (JnienvInitializeArg internal static JniRuntime.JniValueManager CreateValueManager () { - if (RuntimeFeature.IsMonoRuntime) { + if (AndroidRuntimeFeature.IsMonoRuntime) { return new AndroidValueManager (); } - if (RuntimeFeature.IsCoreClrRuntime) { + if (AndroidRuntimeFeature.IsCoreClrRuntime) { return new JavaMarshalValueManager (); } - if (RuntimeFeature.IsNativeAotRuntime) { + if (AndroidRuntimeFeature.IsNativeAotRuntime) { return new JavaMarshalValueManager (); } @@ -217,14 +216,14 @@ static void InitializeCommonState (JnienvInitializeArgs args) static void InitializeTrimmableTypeMapDataIfNeeded () { - if (RuntimeFeature.TrimmableTypeMap) { + if (AndroidRuntimeFeature.TrimmableTypeMap) { InitializeTrimmableTypeMapData (); } } static void RegisterTrimmableTypeMapNativeMethodsIfNeeded () { - if (RuntimeFeature.TrimmableTypeMap) { + if (AndroidRuntimeFeature.TrimmableTypeMap) { // TypeMapLoader.Initialize() only loads managed typemap data. Registering // mono.android.Runtime natives requires JniRuntime.Current and its ClassLoader. TrimmableTypeMap.RegisterNativeMethods (); @@ -242,9 +241,9 @@ static void InitializeTrimmableTypeMapData () static void RunStartupHooksIfNeeded () { // Return if startup hooks are disabled or not CoreCLR - if (!RuntimeFeature.IsCoreClrRuntime) + if (!AndroidRuntimeFeature.IsCoreClrRuntime) return; - if (!RuntimeFeature.StartupHookSupport) + if (!AndroidRuntimeFeature.StartupHookSupport) return; RunStartupHooks (); diff --git a/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs b/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs index df7f992d442..0ee447ed999 100644 --- a/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs +++ b/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs @@ -115,7 +115,7 @@ internal unsafe static partial class RuntimeNativeMethods [LibraryImport (RuntimeConstants.InternalDllName, StringMarshalling = StringMarshalling.Utf8)] [UnmanagedCallConv (CallConvs = new[] { typeof (CallConvCdecl) })] - internal static partial IntPtr clr_typemap_managed_to_java (string fullName, IntPtr mvid); + internal static partial IntPtr clr_typemap_managed_to_java (string? fullName, IntPtr mvid); [LibraryImport (RuntimeConstants.InternalDllName, StringMarshalling = StringMarshalling.Utf8)] [UnmanagedCallConv (CallConvs = new[] { typeof (CallConvCdecl) })] diff --git a/src/Mono.Android/Java.Interop/JavaConvert.cs b/src/Mono.Android/Java.Interop/JavaConvert.cs index ba46b155c00..d4ac7fc4472 100644 --- a/src/Mono.Android/Java.Interop/JavaConvert.cs +++ b/src/Mono.Android/Java.Interop/JavaConvert.cs @@ -81,7 +81,7 @@ params Type [] typeArguments if (target.IsArray) return (h, t) => JNIEnv.GetArray (h, t, target.GetElementType ()); - if (RuntimeFeature.TrimmableTypeMap) { + if (AndroidRuntimeFeature.TrimmableTypeMap) { var factoryConverter = TryGetFactoryBasedConverter (target); if (factoryConverter != null) return factoryConverter; @@ -148,7 +148,7 @@ params Type [] typeArguments if (!typeof (IJavaPeerable).IsAssignableFrom (elementType)) return null; - if (RuntimeFeature.TrimmableTypeMap) { + if (AndroidRuntimeFeature.TrimmableTypeMap) { return TrimmableTypeMap.Instance?.GetContainerFactory (elementType); } @@ -198,7 +198,7 @@ public ArrayElementConverter (Array array) return JNIEnv.GetArray (handle, transfer, elementType.GetElementType ()); if (elementType != null && typeof (IJavaPeerable).IsAssignableFrom (elementType)) { - if (RuntimeFeature.TrimmableTypeMap) + if (AndroidRuntimeFeature.TrimmableTypeMap) return FromJniHandleWithTrimmableTypeMapping (handle, transfer, elementType); return Java.Lang.Object.GetObject (handle, transfer, elementType); } diff --git a/src/Mono.Android/Java.Interop/TypeManager.cs b/src/Mono.Android/Java.Interop/TypeManager.cs index cc0b22936bd..d952ad440bd 100644 --- a/src/Mono.Android/Java.Interop/TypeManager.cs +++ b/src/Mono.Android/Java.Interop/TypeManager.cs @@ -2,10 +2,8 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Reflection; -using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using Java.Interop.Tools.TypeNameMappings; using Android.Runtime; using Microsoft.Android.Runtime; @@ -238,7 +236,11 @@ static Type monovm_typemap_java_to_managed (string java_type_name) return null; } - string managedAssemblyName = Marshal.PtrToStringAnsi (managedAssemblyNamePointer); + string? managedAssemblyName = Marshal.PtrToStringAnsi (managedAssemblyNamePointer); + if (string.IsNullOrEmpty (managedAssemblyName)) { + return null; + } + Assembly assembly = Assembly.Load (managedAssemblyName); Type? ret = null; foreach (Module module in assembly.Modules) { @@ -262,20 +264,24 @@ static Type monovm_typemap_java_to_managed (string java_type_name) } } - static Type? GetJavaToManagedTypeCore (string class_name) + static Type? GetJavaToManagedTypeCore (string? class_name) { + if (class_name is null) { + return null; + } + if (TypeManagerMapDictionaries.JniToManaged.TryGetValue (class_name, out Type? type)) { return type; } - if (RuntimeFeature.TrimmableTypeMap) { + if (AndroidRuntimeFeature.TrimmableTypeMap) { throw new System.Diagnostics.UnreachableException ( $"{nameof (TypeManager)}.{nameof (GetJavaToManagedTypeCore)} should not be used when " + - $"{nameof (RuntimeFeature.TrimmableTypeMap)} is enabled. The trimmable path should resolve " + + $"{nameof (AndroidRuntimeFeature.TrimmableTypeMap)} is enabled. The trimmable path should resolve " + $"types through {nameof (TrimmableTypeMapTypeManager)}."); - } else if (RuntimeFeature.IsMonoRuntime) { + } else if (AndroidRuntimeFeature.IsMonoRuntime) { type = monovm_typemap_java_to_managed (class_name); - } else if (RuntimeFeature.IsCoreClrRuntime) { + } else if (AndroidRuntimeFeature.IsCoreClrRuntime) { type = clr_typemap_java_to_managed (class_name); } else { throw new NotSupportedException ("Internal error: unknown runtime not supported"); @@ -370,7 +376,7 @@ static Type monovm_typemap_java_to_managed (string java_type_name) var message = $"Handle 0x{handle:x} is of type '{JNIEnv.GetClassNameFromInstance (handle)}' which is not assignable to '{typeSig.SimpleReference}'"; Logger.Log (LogLevel.Debug, "monodroid-assembly", message); } - if (RuntimeFeature.IsAssignableFromCheck) { + if (AndroidRuntimeFeature.IsAssignableFromCheck) { return null; } } diff --git a/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs b/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs index 458ad77202a..b812a7a5bf6 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs @@ -244,7 +244,7 @@ public override void FinalizePeer (IJavaPeerable value) public override void ActivatePeer (JniObjectReference reference, [DynamicallyAccessedMembers (Constructors)] Type type, ConstructorInfo cinfo, object?[]? argumentValues) { - if (RuntimeFeature.TrimmableTypeMap) + if (AndroidRuntimeFeature.TrimmableTypeMap) throw new PlatformNotSupportedException ("Activating Java peers is not supported when TrimmableTypeMap is enabled."); base.ActivatePeer (reference, type, cinfo, argumentValues); @@ -500,7 +500,7 @@ void ProcessContext (HandleContext* context) return null; } - if (RuntimeFeature.TrimmableTypeMap) { + if (AndroidRuntimeFeature.TrimmableTypeMap) { try { // Mirror legacy GetPeerType: callers commonly request universal // interfaces / boxes (IJavaPeerable, object, Exception) — map these @@ -533,7 +533,7 @@ void ProcessContext (HandleContext* context) throw new NotSupportedException ( $"No generated {nameof (JavaPeerProxy)} was found for Java type '{javaType}' " + - $"with targetType '{targetName}' while {nameof (RuntimeFeature.TrimmableTypeMap)} is enabled. " + + $"with targetType '{targetName}' while {nameof (AndroidRuntimeFeature.TrimmableTypeMap)} is enabled. " + $"This indicates a missing trimmable typemap proxy or association and should be fixed in the generator."); } finally { JniObjectReference.Dispose (ref reference, transfer); diff --git a/src/Mono.Android/Microsoft.Android.Runtime/RuntimeFeature.cs b/src/Mono.Android/Microsoft.Android.Runtime/RuntimeFeature.cs index 5d20f9e5ac4..0086d0947e2 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/RuntimeFeature.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/RuntimeFeature.cs @@ -3,7 +3,7 @@ namespace Microsoft.Android.Runtime; -static class RuntimeFeature +static class AndroidRuntimeFeature { const bool ManagedTypeMapEnabledByDefault = false; const bool IsMonoRuntimeEnabledByDefault = true; diff --git a/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs b/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs index 915daa0e248..e660c364fde 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs @@ -27,7 +27,7 @@ public class TrimmableTypeMap internal static TrimmableTypeMap Instance => s_instance ?? throw new InvalidOperationException ( - "TrimmableTypeMap has not been initialized. Ensure RuntimeFeature.TrimmableTypeMap is enabled and the JNI runtime is initialized."); + "TrimmableTypeMap has not been initialized. Ensure AndroidRuntimeFeature.TrimmableTypeMap is enabled and the JNI runtime is initialized."); readonly ITypeMap _typeMap; readonly ConcurrentDictionary _proxyCache = new (); @@ -138,7 +138,7 @@ internal static unsafe void RegisterNativeMethods () if (s_instance is null) { throw new InvalidOperationException ( - "TrimmableTypeMap has not been initialized. Ensure RuntimeFeature.TrimmableTypeMap is enabled and the JNI runtime is initialized."); + "TrimmableTypeMap has not been initialized. Ensure AndroidRuntimeFeature.TrimmableTypeMap is enabled and the JNI runtime is initialized."); } using var runtimeClass = new JniType ("mono/android/Runtime"u8); diff --git a/src/Mono.Android/Mono.Android.csproj b/src/Mono.Android/Mono.Android.csproj index 611ef7edf07..1918821f5c7 100644 --- a/src/Mono.Android/Mono.Android.csproj +++ b/src/Mono.Android/Mono.Android.csproj @@ -366,7 +366,6 @@ - diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/InlineData.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/InlineData.cs index 80652d9ef45..c43dde88783 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/InlineData.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/InlineData.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Globalization; using Xamarin.ProjectTools; namespace Xamarin.Android.Build.Tests diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/AndroidSdkResolver.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/AndroidSdkResolver.cs index d4106453efe..f02c0631536 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/AndroidSdkResolver.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/AndroidSdkResolver.cs @@ -16,7 +16,9 @@ public static class AndroidSdkResolver static string GetPathFromRegistry (string valueName) { if (TestEnvironment.IsWindows) { +#pragma warning disable CA1416 // This call site is reachable on all platforms. 'Registry.GetValue(string, string?, object?)' is only supported on: 'windows'. return (string) Microsoft.Win32.Registry.GetValue ("HKEY_CURRENT_USER\\SOFTWARE\\Novell\\Mono for Android", valueName, null); +#pragma warning restore CA1416 } return null; } diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/SolutionBuilder.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/SolutionBuilder.cs index 9201694a794..19ee6b7eecd 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/SolutionBuilder.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/SolutionBuilder.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; using System.IO; -using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace Xamarin.ProjectTools { @@ -20,6 +20,7 @@ public SolutionBuilder (string solutionName) : base() Projects = new List (); } + [MemberNotNull(nameof(SolutionPath))] public void Save () { ArgumentNullException.ThrowIfNull (SolutionPath); diff --git a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK.csproj b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK.csproj index 78baa0560b1..b418f7ac95c 100644 --- a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK.csproj +++ b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK.csproj @@ -1,7 +1,7 @@ - $(NoWarn);CA1305 + $(NoWarn);CA1305;CS1591 netstandard2.0 diff --git a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/AndroidSDKInstaller.cs b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/AndroidSDKInstaller.cs index a41e12d46fc..bcea26e5b2c 100644 --- a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/AndroidSDKInstaller.cs +++ b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/AndroidSDKInstaller.cs @@ -43,6 +43,7 @@ public class AndroidSDKInstaller : IParserErrorHandler /// Google repository only: URL of the addon manifest (optional) /// Google repository only: base URL of the repository /// If true, load local manifest when offline + /// Custom licenses storage (optional) public AndroidSDKInstaller (IHelpers helpers, AndroidManifestType manifestType = AndroidManifestType.Xamarin, Uri manifestURL = null, Uri googleAddonsListURL = null, Uri googleRepositoryBaseURL = null, bool useManifestCaching = false, ILicensesStorage licensesStorage = null) { CommonUtilities.Helpers = helpers ?? new Helper(); @@ -163,7 +164,7 @@ public AndroidSdkInstance FindInstance (string forPath) /// /// /// - /// If is true then the method will start a full detection cycle. This means that the + /// If is true then the method will start a full detection cycle. This means that the /// will be modified - all of its components will be replaced with fresh instances. This is to ensure that /// the metadata in the components is 100% accurate. By default full detection is not performed. /// @@ -454,6 +455,7 @@ public IList GetInstallationSet (AndroidSdkInstance instance, /// Android SDK instance. /// Components to install /// Throw an exception if any component with invalid archives is found, if set to true + /// Progress monitor public void Install (AndroidSdkInstance instance, IList componentsToInstall, bool throwIfInvalidComponentsFound = true, IProgressMonitor monitor = null) { @@ -746,6 +748,8 @@ public bool IsLicenseAccepted(AndroidSdkInstance instance, License license) /// list of licenses to accept /// cancellation token /// log file path + /// custom Java SDK path (optional) + /// if true, throws an exception if license validation failed, otherwise it will just log the error and return public Task AcceptLicensesAsync(AndroidSdkInstance instance, IEnumerable licenses, CancellationToken token, string javaSdkPath = null, string logPath = null, bool throwsErrorIfValidationFailed = false) { if (instance != null) { diff --git a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/AndroidLicensesStorage.cs b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/AndroidLicensesStorage.cs index 76418c5d64e..e066cebc739 100644 --- a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/AndroidLicensesStorage.cs +++ b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/AndroidLicensesStorage.cs @@ -84,6 +84,7 @@ protected virtual string GetLicenseHash(string licensePath) /// list of licenses to accept /// cancellation token /// log file path + /// if true, throws an exception if the validation of arguments fails, if set to false the method returns without accepting any license public Task AcceptLicensesAsync( string androidSdkPath, string javaSdkPath, diff --git a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/Archive.cs b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/Archive.cs index 29ec9a9ebbd..c54262ebaaa 100644 --- a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/Archive.cs +++ b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/Archive.cs @@ -22,7 +22,7 @@ public class Archive : ArchiveBase, IEquatable { /// /// Gets the collection of patches for this archive. This library currently does not support applying these - /// patches, instead it always downloads the full archive from the specified + /// patches, instead it always downloads the full archive from the specified Url /// /// The list of patches (if any) public IList Patches { get; set; } diff --git a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/HttpClientProvider.cs b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/HttpClientProvider.cs index bd8aae936b7..ded80caa922 100644 --- a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/HttpClientProvider.cs +++ b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/HttpClientProvider.cs @@ -27,6 +27,8 @@ public static void SetHttpClientFactory (Func factory) /// /// The HttpClient. /// The request url. + /// The cookie container to use, or null to not use cookies. + /// The decompression methods to support. public static HttpClient CreateHttpClient (Uri uri, CookieContainer cookieContainer = null, DecompressionMethods automaticDecompression = DecompressionMethods.None) { if (httpClientFactory != null) diff --git a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/DirectorySizeMonitoringTimer.cs b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/DirectorySizeMonitoringTimer.cs index 21d4e131638..61318fe6e85 100644 --- a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/DirectorySizeMonitoringTimer.cs +++ b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/DirectorySizeMonitoringTimer.cs @@ -133,7 +133,7 @@ public static ulong CalculateTotalSize (ZipFile zipFile) /// Move operation will take different time depending on number of files in an archive /// so we split the 100% installation progress according these values (unzip + move = 100%) /// - /// + /// The path to the archive file. /// Amount of percents for the Move part of the installation public static int CalculateMoveProgressSplit (string archivePath) { diff --git a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/IProgressMonitor.cs b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/IProgressMonitor.cs index d8d9fcdc9c3..d042e73a568 100644 --- a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/IProgressMonitor.cs +++ b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/IProgressMonitor.cs @@ -58,6 +58,10 @@ public interface IProgressMonitorWithTotalProgress : ICancellableProgressMonitor /// Reports the total progress of all the download and installation steps /// /// Overall progress percentage from 0.0 to 1.0 + /// Total number of main components + /// Index of the current main component + /// Total number of sub-components + /// Index of the current sub-component void ReportTotalProgress (double loadPercentage, int mainComponentsCount, int mainComponentIndex, int subComponentsCount, int subComponentIndex); diff --git a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/JavaDependencyInstaller.cs b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/JavaDependencyInstaller.cs index cbe0eaa7434..a09b614b795 100644 --- a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/JavaDependencyInstaller.cs +++ b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/JavaDependencyInstaller.cs @@ -72,7 +72,7 @@ public bool IsJdkPathValid () // If the requested path is not writable, request a different path try { Directory.CreateDirectory (JdkPath); - using (File.Create (Path.Combine (JdkPath, "tmp"), 1, FileOptions.DeleteOnClose)); + using var _ = File.Create (Path.Combine (JdkPath, "tmp"), 1, FileOptions.DeleteOnClose); } catch (Exception) { return false; } diff --git a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Repository.cs b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Repository.cs index 3935879336b..4b6ec7d8bcf 100644 --- a/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Repository.cs +++ b/src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Repository.cs @@ -236,7 +236,6 @@ public string GetNamespaceUri(string nsName) /// If it fails, tries to load local cached manifest; /// If local manifest is loaded, sets IsOffline to true and returns it. /// - /// /// protected string LoadManifest() { diff --git a/src/Xamarin.Installer.Common/Xamarin.Installer.Common.csproj b/src/Xamarin.Installer.Common/Xamarin.Installer.Common.csproj index 67146b6d8a1..ad36d3a1ce1 100644 --- a/src/Xamarin.Installer.Common/Xamarin.Installer.Common.csproj +++ b/src/Xamarin.Installer.Common/Xamarin.Installer.Common.csproj @@ -1,7 +1,7 @@ - $(NoWarn);CA1305 + $(NoWarn);CA1305;CS1591 12