Skip to content

Remove obsolete System.AndroidPlatform methods and native implementations #10385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
147 changes: 0 additions & 147 deletions src/Mono.Android/Android.Runtime/AndroidEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,85 +228,6 @@ static void NotifyTimeZoneChanged ()
}
}

// This is invoked by
// System.Drawing!System.Drawing.GraphicsAndroid.FromAndroidSurface ()
// DO NOT REMOVE
//
// Exception audit:
//
// Verdict
// No need to wrap thrown exceptions in a BCL class
//
// Rationale
// No longer called by the indicated caller, however we keep it for backward compatibility.
[global::System.Runtime.Versioning.ObsoletedOSPlatform ("android31.0")]
static void GetDisplayDPI (out float x_dpi, out float y_dpi)
{
var wm = Application.Context.GetSystemService (Context.WindowService).JavaCast <IWindowManager> ();
var metrics = new DisplayMetrics ();
#if ANDROID_17
wm?.DefaultDisplay?.GetRealMetrics (metrics);
#else
wm.DefaultDisplay.GetMetrics (metrics);
#endif
x_dpi = metrics.Xdpi;
y_dpi = metrics.Ydpi;
}

// This is invoked by
// System.Core!System.AndroidPlatform.GetDefaultTimeZone ()
// DO NOT REMOVE
//
// Exception audit:
//
// Verdict
// No need to wrap thrown exceptions in a BCL class
//
// Rationale
// Java code (invoked from our native runtime) will always return the default timezone and no
// exceptions are documented for the Java API.
//
static string GetDefaultTimeZone ()
{
IntPtr id = RuntimeNativeMethods._monodroid_timezone_get_default_id ();
try {
return Marshal.PtrToStringAnsi (id)!;
} finally {
RuntimeNativeMethods.monodroid_free (id);
}
}

// This is invoked by
// mscorlib.dll!System.AndroidPlatform.GetDefaultSyncContext()
// DO NOT REMOVE
static SynchronizationContext? GetDefaultSyncContext ()
{
var looper = Android.OS.Looper.MainLooper;
try {
if (Android.OS.Looper.MyLooper() == looper)
return Android.App.Application.SynchronizationContext;
} catch (System.Exception ex) {
Logger.Log (LogLevel.Warn, "MonoAndroid", $"GetDefaultSyncContext caught a Java exception: {ex}");
}
return null;
}

// These are invoked by
// System.dll!System.AndroidPlatform.getifaddrs
// DO NOT REMOVE
static int GetInterfaceAddresses (out IntPtr ifap)
{
return RuntimeNativeMethods._monodroid_getifaddrs (out ifap);
}

// These are invoked by
// System.dll!System.AndroidPlatform.freeifaddrs
// DO NOT REMOVE
static void FreeInterfaceAddresses (IntPtr ifap)
{
RuntimeNativeMethods._monodroid_freeifaddrs (ifap);
}

static void DetectCPUAndArchitecture (out ushort builtForCPU, out ushort runningOnCPU, out bool is64bit)
{
ushort built_for_cpu = 0;
Expand All @@ -319,18 +240,6 @@ static void DetectCPUAndArchitecture (out ushort builtForCPU, out ushort running
is64bit = _is64bit != 0;
}

// This is invoked by
// System.dll!System.AndroidPlatform.GetDefaultProxy()
// DO NOT REMOVE
static IWebProxy GetDefaultProxy ()
{
#if ANDROID_14
return new _Proxy ();
#else
return null;
#endif
}

// This is invoked by
// System.Net.Http.dll!System.Net.Http.HttpClient.cctor
// DO NOT REMOVE
Expand Down Expand Up @@ -395,61 +304,5 @@ static Type GetFallbackHttpMessageHandlerType ()
return handlerType;
}

class _Proxy : IWebProxy {
readonly ProxySelector selector = ProxySelector.Default!;

// Exception audit:
//
// Verdict
// Exception wrapping required
//
// Rationale
// Java code may throw URISyntaxException which we map to the managed UriFormatException
//
static URI CreateJavaUri (Uri destination)
{
try {
return new URI (destination.Scheme, destination.UserInfo, destination.Host, destination.Port, destination.AbsolutePath, destination.Query, destination.Fragment);
} catch (Java.Lang.Throwable ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
throw new UriFormatException (ex.Message, ex);
}
}

public Uri GetProxy (Uri destination)
{
IList<Java.Net.Proxy> list;
using (var uri = CreateJavaUri (destination))
list = selector.Select (uri)!;
if (list.Count < 1)
return destination;

var proxy = list [0];
if (proxy.Equals (Proxy.NoProxy))
return destination;

var address = proxy.Address () as InetSocketAddress;
if (address == null) // FIXME
return destination;

return new Uri (FormattableString.Invariant ($"http://{address.HostString}:{address.Port}/"));
}

public bool IsBypassed (Uri host)
{
IList<Java.Net.Proxy> list;
using (var uri = CreateJavaUri (host))
list = selector.Select (uri)!;

if (list.Count < 1)
return true;

return list [0].Equals (Proxy.NoProxy);
}

public ICredentials? Credentials {
get;
set;
}
}
}
}
8 changes: 0 additions & 8 deletions src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ internal unsafe static class RuntimeNativeMethods
[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr _monodroid_lookup_replacement_method_info (string jniSourceType, string jniMethodName, string jniMethodSignature);

[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr _monodroid_timezone_get_default_id ();

[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern int _monodroid_getifaddrs (out IntPtr ifap);

[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern void _monodroid_freeifaddrs (IntPtr ifap);

[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern void _monodroid_detect_cpu_and_architecture (ref ushort built_for_cpu, ref ushort running_on_cpu, ref byte is64bit);
Expand Down
1 change: 0 additions & 1 deletion src/native/clr/host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ set(XAMARIN_MONODROID_SOURCES
os-bridge.cc
runtime-util.cc
typemap.cc
xamarin_getifaddrs.cc
)

if(DEBUG_BUILD)
Expand Down
20 changes: 0 additions & 20 deletions src/native/clr/host/internal-pinvokes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,3 @@ void _monodroid_detect_cpu_and_architecture (uint16_t *built_for_cpu, uint16_t *
*is64bit = _64bit;
}

void* _monodroid_timezone_get_default_id ()
{
JNIEnv *env = OSBridge::ensure_jnienv ();
jmethodID getDefault = env->GetStaticMethodID (Host::get_java_class_TimeZone (), "getDefault", "()Ljava/util/TimeZone;");
jmethodID getID = env->GetMethodID (Host::get_java_class_TimeZone (), "getID", "()Ljava/lang/String;");
jobject d = env->CallStaticObjectMethod (Host::get_java_class_TimeZone (), getDefault);
jstring id = reinterpret_cast<jstring> (env->CallObjectMethod (d, getID));
const char *mutf8 = env->GetStringUTFChars (id, nullptr);
if (mutf8 == nullptr) {
log_error (LOG_DEFAULT, "Failed to convert Java TimeZone ID to UTF8 (out of memory?)"sv);
env->DeleteLocalRef (id);
env->DeleteLocalRef (d);
return nullptr;
}
char *def_id = strdup (mutf8);
env->ReleaseStringUTFChars (id, mutf8);
env->DeleteLocalRef (id);
env->DeleteLocalRef (d);
return def_id;
}
Loading
Loading