Skip to content

Commit

Permalink
Changes to make diff in AndroidEnvironment smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpeppers committed Mar 11, 2024
1 parent 6399051 commit e4bbe8c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Mono.Android/Android.Runtime/AndroidEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,27 @@ static Type TypeGetType (string typeName) =>

static bool IsAcceptableHttpMessageHandlerType (Type handlerType)
{
if (Type.GetType ("System.Net.Http.HttpClientHandler, System.Net.Http", throwOnError: false) is Type httpClientHandlerType &&
httpClientHandlerType.IsAssignableFrom (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 (Type.GetType ("System.Net.Http.HttpMessageHandler, System.Net.Http", throwOnError: false) is Type httpMessageHandlerType &&
httpMessageHandlerType.IsAssignableFrom (handlerType)) {
return true;
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;
}

// Was not an acceptable type
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: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Expand Down

0 comments on commit e4bbe8c

Please sign in to comment.