Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/skills/tests/references/test-catalog.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -122,7 +122,7 @@ Device: **Yes**
| Test Area | Project | Notes |
|-----------|---------|-------|
| **runtime** (all) | `tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj` | Core runtime tests |
| **networking** | Same project — tests in `Xamarin.Android.Net/` and `System.Net/` | `AndroidMessageHandlerTests`, `AndroidClientHandlerTests`, `HttpClientIntegrationTests` |
| **networking** | Same project — tests in `Xamarin.Android.Net/` and `System.Net/` | `AndroidMessageHandlerTests`, `AndroidMessageHandlerIntegrationTests` |
| **java interop (on-device)** | Same project — tests in `Java.Interop/` | `JnienvTest`, `JavaListTest` |
| **android app** | Same project — tests in `Android.App/` | `Application`, `Activity` tests |
| **android views** | Same project — tests in `Android.Views/` | Layout inflater, view tests |
Expand All@@ -138,10 +138,10 @@ Device: **Yes**

The `Mono.Android.NET-Tests.csproj` dynamically excludes categories based on runtime:
- **CoreCLR runtime**: Excludes `CoreCLRIgnore`, `NTLM`
- **NativeAOT runtime**: Excludes `NativeAOTIgnore`, `SSL`, `NTLM`, `AndroidClientHandler`, `Export`, `NativeTypeMap`
- **NativeAOT runtime**: Excludes `NativeAOTIgnore`, `SSL`, `NTLM`, `Export`, `NativeTypeMap`
- **LLVM**: Excludes `LLVMIgnore`, `InetAccess`, `NetworkInterfaces`

Other categories: `SSL`, `InetAccess`, `AndroidClientHandler`, `JavaList`, `RuntimeConfig`, `Intune`, `NTLM`
Other categories: `SSL`, `InetAccess`, `JavaList`, `RuntimeConfig`, `Intune`, `NTLM`

Command:
```bash
Expand Down
6 changes: 0 additions & 6 deletions Documentation/docs-mobile/TOC.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -258,12 +258,6 @@
href: messages/xa1028.md
- name: XA1029
href: messages/xa1029.md
- name: XA1031
href: messages/xa1031.md
- name: XA1032
href: messages/xa1032.md
- name: XA1033
href: messages/xa1033.md
- name: XA1035
href: messages/xa1035.md
- name: XA1036
Expand Down
53 changes: 2 additions & 51 deletions Documentation/docs-mobile/building-apps/build-properties.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -601,58 +601,9 @@ The default value is `true`. When set to `false`, disables the generation of `Re

## AndroidHttpClientHandlerType

Controls the default
`System.Net.Http.HttpMessageHandler` implementation which will be used by
the `System.Net.Http.HttpClient` default constructor. The value is an
assembly-qualified type name of an `HttpMessageHandler` subclass, suitable
for use with
[`System.Type.GetType(string)`](/dotnet/api/system.type.gettype#System_Type_GetType_System_String_).

In .NET 6 and newer, this property has effect only when used together
with [`$(UseNativeHttpHandler)=true`][feature-switches].
The most common values for this property are:

- `Xamarin.Android.Net.AndroidMessageHandler`: Use the Android Java APIs
to perform HTTP requests. It is similar to the legacy
`Xamarin.Android.Net.AndroidClientHandler` with several improvements.
It supports HTTP 1.1 and TLS 1.2. It is the default HTTP message handler.

- `System.Net.Http.SocketsHttpHandler, System.Net.Http`: The default message
handler in .NET. It supports HTTP/2, TLS 1.2, and it is the recommended
HTTP message handler to use with [Grpc.Net.Client](https://www.nuget.org/packages/Grpc.Net.Client).
This value is equivalent to `$(UseNativeHttpHandler)=false`.

- Unset/the empty string, which is equivalent to
`System.Net.Http.HttpClientHandler, System.Net.Http`

Corresponds to the **Default** option in the Visual Studio
property pages.

The new project wizard selects this option for new projects when the
**Minimum Android Version** is configured to **Android 4.4.87** or
lower in Visual Studio or when **Target Platforms** is set to **Modern
Development** or **Maximum Compatibility** in Visual Studio for Mac.

- `System.Net.Http.HttpClientHandler, System.Net.Http`: Use the managed
`HttpMessageHandler`.

Corresponds to the **Managed** option in the Visual Studio
property pages.

> [!NOTE]
> In .NET 6, the type you specify must not be
> `Xamarin.Android.Net.AndroidClientHandler` or `System.Net.Http.HttpClientHandler`
> or inherit from either of these classes. If you are migrating from
> "classic" Xamarin.Android, use `AndroidMessageHandler` or derive your
> custom handler from it instead.

> [!NOTE]
> Support for the `$(AndroidHttpClientHandlerType)` property works by setting the
> [`XA_HTTP_CLIENT_HANDLER_TYPE` environment variable](/xamarin/android/deploy-test/environment).
> A `$XA_HTTP_CLIENT_HANDLER_TYPE` value found in a file
> with a Build action of
> [`@(AndroidEnvironment)`](build-items.md#androidenvironment)
> will take precedence.
> This property is not supported in .NET 11. Remove it from your project file
> and use `UseNativeHttpHandler` instead.
Comment thread
simonrozsival marked this conversation as resolved.

## AndroidIgnoreAllJniPreload

Expand Down
3 changes: 0 additions & 3 deletions Documentation/docs-mobile/messages/index.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -139,9 +139,6 @@ or 'Help->Report a Problem' in Visual Studio for Mac.
+ [XA1027](xa1027.md): The 'EnableProguard' MSBuild property is set to 'true' and the 'AndroidLinkTool' MSBuild property is empty, so 'AndroidLinkTool' will default to 'proguard'.
+ [XA1028](xa1028.md): The 'AndroidEnableProguard' MSBuild property is set to 'true' and the 'AndroidLinkTool' MSBuild property is empty, so 'AndroidLinkTool' will default to 'proguard'.
+ [XA1029](xa1029.md): The 'AotAssemblies' MSBuild property is deprecated. Edit the project file in a text editor to remove this property, and use the 'RunAOTCompilation' MSBuild property instead.
+ [XA1031](xa1031.md): The 'AndroidHttpClientHandlerType' has an invalid value.
+ [XA1032](xa1032.md):Failed to resolve '{0}' from '{1}'. Please check your `AndroidHttpClientHandlerType` setting.
+ [XA1033](xa1033.md): Could not resolve '{0}'. Please check your `AndroidHttpClientHandlerType` setting.
+ [XA1035](xa1035.md): The 'BundleAssemblies' property is deprecated and it has no effect on the application build. Equivalent functionality is implemented by the 'AndroidUseAssemblyStore' and 'AndroidEnableAssemblyCompression' properties.
+ [XA1036](xa1036.md): AndroidManifest.xml //uses-sdk/@android:minSdkVersion '29' does not match the $(SupportedOSPlatformVersion) value '21' in the project file (if there is no $(SupportedOSPlatformVersion) value in the project file, then a default value has been assumed).
Either change the value in the AndroidManifest.xml to match the $(SupportedOSPlatformVersion) value, or remove the value in the AndroidManifest.xml (and add a $(SupportedOSPlatformVersion) value to the project file if it doesn't already exist).
Expand Down
28 changes: 0 additions & 28 deletions Documentation/docs-mobile/messages/xa1031.md

This file was deleted.

22 changes: 0 additions & 22 deletions Documentation/docs-mobile/messages/xa1032.md

This file was deleted.

22 changes: 0 additions & 22 deletions Documentation/docs-mobile/messages/xa1033.md

This file was deleted.

34 changes: 3 additions & 31 deletions src/Microsoft.Android.Sdk.ILLink/MarkJavaObjects.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,11 +16,10 @@ public class MarkJavaObjects : BaseMarkHandler
public override void Initialize (LinkContext context, MarkContext markContext)
{
base.Initialize (context, markContext);
context.TryGetCustomData ("AndroidHttpClientHandlerType", out string androidHttpClientHandlerType);
context.TryGetCustomData ("AndroidCustomViewMapFile", out string androidCustomViewMapFile);
var customViewMap = MonoAndroidHelper.LoadCustomViewMapFile (androidCustomViewMapFile);

markContext.RegisterMarkAssemblyAction (assembly => ProcessAssembly (assembly, androidHttpClientHandlerType, customViewMap));
markContext.RegisterMarkAssemblyAction (assembly => ProcessAssembly (assembly, customViewMap));
markContext.RegisterMarkTypeAction (type => ProcessType (type));
}

Expand All@@ -29,28 +28,16 @@ bool IsActiveFor (AssemblyDefinition assembly)
if (MonoAndroidHelper.IsFrameworkAssembly (assembly))
return false;

return assembly.MainModule.HasTypeReference ("System.Net.Http.HttpMessageHandler") ||
assembly.MainModule.HasTypeReference ("Java.Lang.Object") ||
return assembly.MainModule.HasTypeReference ("Java.Lang.Object") ||
assembly.MainModule.HasTypeReference ("Android.Util.IAttributeSet");
}

public void ProcessAssembly (AssemblyDefinition assembly, string androidHttpClientHandlerType, Dictionary<string, HashSet<string>> customViewMap)
public void ProcessAssembly (AssemblyDefinition assembly, Dictionary<string, HashSet<string>> customViewMap)
Comment thread
simonrozsival marked this conversation as resolved.
{
if (!IsActiveFor (assembly))
return;

foreach (var type in assembly.MainModule.Types) {
// Custom HttpMessageHandler
if (!string.IsNullOrEmpty (androidHttpClientHandlerType) &&
androidHttpClientHandlerType.StartsWith (type.Name, StringComparison.Ordinal)) {
var assemblyQualifiedName = type.GetPartialAssemblyQualifiedName (Context);
if (assemblyQualifiedName == androidHttpClientHandlerType) {
Annotations.Mark (type);
PreservePublicParameterlessConstructors (type);
continue;
}
}

// Continue if not an IJavaObject
if (!type.ImplementsIJavaObject (cache))
continue;
Expand DownExpand Up@@ -118,21 +105,6 @@ void PreserveJavaObjectImplementation (TypeDefinition type)
PreserveInterfaces (type);
}

void PreservePublicParameterlessConstructors (TypeDefinition type)
{
if (!type.HasMethods)
return;

foreach (var constructor in type.Methods)
{
if (!constructor.IsConstructor || constructor.IsStatic || !constructor.IsPublic || constructor.HasParameters)
continue;

PreserveMethod (type, constructor);
break; // We can stop when found
}
}

void PreserveAttributeSetConstructor (TypeDefinition type)
{
if (!type.HasMethods)
Expand Down
61 changes: 1 addition & 60 deletions src/Mono.Android/Android.Runtime/AndroidEnvironment.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,8 +26,6 @@ public static partial class AndroidEnvironment {
static IX509TrustManager? sslTrustManager;
static KeyStore? certStore;
static object lock_ = new object ();
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
static Type? httpMessageHandlerType;

static void SetupTrustManager ()
{
Expand DownExpand Up@@ -253,66 +251,9 @@ static void DetectCPUAndArchitecture (out ushort builtForCPU, out ushort running
// This is invoked by
// System.Net.Http.dll!System.Net.Http.HttpClient.cctor
// DO NOT REMOVE
[DynamicDependency (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor, typeof (Xamarin.Android.Net.AndroidMessageHandler))]
static HttpMessageHandler GetHttpMessageHandler ()
{
[UnconditionalSuppressMessage ("Trimming", "IL2057", Justification = "Preserved by the MarkJavaObjects trimmer step.")]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
static Type? TypeGetType (string typeName) =>
Type.GetType (typeName, throwOnError: false);

if (httpMessageHandlerType is null) {
var handlerTypeName = Environment.GetEnvironmentVariable ("XA_HTTP_CLIENT_HANDLER_TYPE")?.Trim ();
Type? handlerType = null;
if (!String.IsNullOrEmpty (handlerTypeName))
handlerType = TypeGetType (handlerTypeName);

if (handlerType is null || !IsAcceptableHttpMessageHandlerType (handlerType)) {
handlerType = GetFallbackHttpMessageHandlerType ();
}

httpMessageHandlerType = handlerType;
}

return (HttpMessageHandler) Activator.CreateInstance (httpMessageHandlerType)
?? throw new InvalidOperationException ($"Could not create an instance of HTTP message handler type {httpMessageHandlerType.AssemblyQualifiedName}");
}

static bool IsAcceptableHttpMessageHandlerType (Type handlerType)
{
if (Extends (handlerType, "System.Net.Http.HttpClientHandler, System.Net.Http")) {
// It's not possible to construct HttpClientHandler in this method because it would cause infinite recursion
// as HttpClientHandler's constructor calls the GetHttpMessageHandler function
Logger.Log (LogLevel.Warn, "MonoAndroid", $"The type {handlerType.AssemblyQualifiedName} cannot be used as the native HTTP handler because it is derived from System.Net.Htt.HttpClientHandler. Use a type that extends System.Net.Http.HttpMessageHandler instead.");
return false;
}
if (!Extends (handlerType, "System.Net.Http.HttpMessageHandler, System.Net.Http")) {
Logger.Log (LogLevel.Warn, "MonoAndroid", $"The type {handlerType.AssemblyQualifiedName} set as the default HTTP handler is invalid. Use a type that extends System.Net.Http.HttpMessageHandler.");
return false;
}

return true;
}

static bool Extends (
Type handlerType,
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
string baseTypeName)
{
var baseType = Type.GetType (baseTypeName, throwOnError: false);
return baseType?.IsAssignableFrom (handlerType) ?? false;
return new Xamarin.Android.Net.AndroidMessageHandler ();
}

[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
static Type GetFallbackHttpMessageHandlerType ()
{
const string typeName = "Xamarin.Android.Net.AndroidMessageHandler, Mono.Android";
var handlerType = Type.GetType (typeName, throwOnError: false)
?? throw new InvalidOperationException ($"The {typeName} was not found. The type was probably linked away.");

Logger.Log (LogLevel.Info, "MonoAndroid", $"Using {typeName} as the native HTTP message handler.");
return handlerType;
}

}
}
1 change: 0 additions & 1 deletion src/Mono.Android/Mono.Android.csproj
Original file line numberDiff line numberDiff line change
Expand Up@@ -379,7 +379,6 @@
<Compile Include="System.Drawing/SizeFConverter.cs" />
<Compile Include="System.IO\AndroidExtensions.cs" />
<Compile Include="System.Linq\Extensions.cs" />
<Compile Include="Xamarin.Android.Net\AndroidClientHandler.cs" />
<Compile Include="Xamarin.Android.Net\AndroidMessageHandler.cs" />
<Compile Include="Xamarin.Android.Net\AndroidHttpResponseMessage.cs" />
<Compile Include="Xamarin.Android.Net\AuthDigestHeaderParser.cs" />
Expand Down
Loading