未验证 提交 5d0817a2 编写于 作者: F Filip Navara 提交者: GitHub

Return iOS version in Environment.OSVersion on Mac Catalyst (#50990)

* Return iOS version in Environment.OSVersion on Mac Catalyst.
Implement OperatingSystem.IsMacCatalyst and OperatingSystem.IsMacCatalystVersionAtLeast.

* Address feedback

* Ensure NSThread is in multi-threaded mode before using autorelease pool
上级 5a3da7d9
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Runtime.InteropServices;
internal static partial class Interop
{
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_iOSSupportVersion")]
internal static extern string iOSSupportVersion();
}
}
......@@ -47,6 +47,14 @@ else ()
pal_log.c)
endif ()
if (CLR_CMAKE_TARGET_MACCATALYST)
set(NATIVE_SOURCES ${NATIVE_SOURCES}
pal_iossupportversion.m)
else ()
list (APPEND NATIVE_SOURCES
pal_iossupportversion.c)
endif ()
if (NOT CLR_CMAKE_TARGET_BROWSER)
list (APPEND NATIVE_SOURCES pal_networkchange.c)
endif ()
......
......@@ -10,6 +10,7 @@
#include "pal_errno.h"
#include "pal_interfaceaddresses.h"
#include "pal_io.h"
#include "pal_iossupportversion.h"
#include "pal_log.h"
#include "pal_memory.h"
#include "pal_mount.h"
......@@ -237,6 +238,7 @@ static const Entry s_sysNative[] =
DllImportEntry(SystemNative_LowLevelMonitor_Create)
DllImportEntry(SystemNative_CreateAutoreleasePool)
DllImportEntry(SystemNative_DrainAutoreleasePool)
DllImportEntry(SystemNative_iOSSupportVersion)
};
EXTERN_C const void* SystemResolveDllImport(const char* name);
......
......@@ -15,3 +15,9 @@ PALEXPORT void* SystemNative_CreateAutoreleasePool(void);
* Drains and releases a pool created by SystemNative_CreateAutoreleasePool.
*/
PALEXPORT void SystemNative_DrainAutoreleasePool(void* pool);
/**
* Ensure that NSThread is in multi-threading mode when POSIX APIs are used to
* start new threads.
*/
void EnsureNSThreadIsMultiThreaded(void);
......@@ -15,7 +15,7 @@
}
@end
void* SystemNative_CreateAutoreleasePool(void)
void EnsureNSThreadIsMultiThreaded(void)
{
if (![NSThread isMultiThreaded])
{
......@@ -30,7 +30,11 @@ void* SystemNative_CreateAutoreleasePool(void)
[NSThread detachNewThreadSelector:@selector(noop:) toTarget:placeholderObject withObject:nil];
}
assert([NSThread isMultiThreaded]);
}
void* SystemNative_CreateAutoreleasePool(void)
{
EnsureNSThreadIsMultiThreaded();
return [[NSAutoreleasePool alloc] init];
}
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "pal_iossupportversion.h"
#include <stdlib.h>
#include "pal_utilities.h"
// These functions should not be used, but they need to be defined
// to satisfy the tooling we used to enable redirecting P/Invokes
// for the single file scenario.
const char* SystemNative_iOSSupportVersion(void)
{
assert_err(false, "iOS support not available on this platform.", EINVAL);
return NULL;
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#pragma once
#include "pal_compiler.h"
#include "pal_types.h"
PALEXPORT const char* SystemNative_iOSSupportVersion(void);
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "pal_iossupportversion.h"
#include "pal_autoreleasepool.h"
#import <Foundation/Foundation.h>
const char* SystemNative_iOSSupportVersion()
{
EnsureNSThreadIsMultiThreaded();
@autoreleasepool
{
NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
NSString *iOSSupportVersion = (NSString *)[plist objectForKey:@"iOSSupportVersion"];
return strdup([iOSSupportVersion UTF8String]);
}
}
......@@ -1847,7 +1847,8 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\RuntimeEventSourceHelper.Unix.cs" Condition="'$(FeaturePerfTracing)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.NoRegistry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.UnixOrBrowser.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSVersion.OSX.cs" Condition="'$(IsOSXLike)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSVersion.OSX.cs" Condition="'$(IsOSXLike)' == 'true' AND '$(TargetsMacCatalyst)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSVersion.MacCatalyst.cs" Condition="'$(TargetsMacCatalyst)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.GetFolderPathCore.Unix.cs" Condition="'$(IsiOSLike)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CalendarData.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CultureData.Unix.cs" />
......@@ -1924,6 +1925,10 @@
<Compile Include="$(CommonPath)Interop\OSX\System.Native\Interop.AutoreleasePool.cs"
Link="Common\Interop\OSX\System.Native\Interop.AutoreleasePool.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsMacCatalyst)' == 'true'">
<Compile Include="$(CommonPath)Interop\OSX\System.Native\Interop.iOSSupportVersion.cs"
Link="Common\Interop\OSX\System.Native\Interop.iOSSupportVersion.cs" />
</ItemGroup>
<ItemGroup Condition="'$(SupportsX86Intrinsics)' == 'true'">
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Aes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Avx.cs" />
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System
{
public static partial class Environment
{
private static OperatingSystem GetOSVersion()
{
Version version = new Version(Interop.Sys.iOSSupportVersion());
return new OperatingSystem(PlatformID.Unix, version);
}
}
}
......@@ -203,7 +203,6 @@ public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0)
public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0)
=> IsMacOS() && IsOSVersionAtLeast(major, minor, build, 0);
/* Commented out for now, until we're ready to make changes to the public API
/// <summary>
/// Indicates whether the current application is running on Mac Catalyst.
/// </summary>
......@@ -215,11 +214,10 @@ public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0
#endif
/// <summary>
/// Check for the Mac Catalyst version (returned by 'libobjc.get_operatingSystemVersion') with a >= version comparison. Used to guard APIs that were added in the given Mac Catalyst release.
/// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a >= version comparison. Used to guard APIs that were added in the given Mac Catalyst release.
/// </summary>
public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0)
=> IsMacCatalyst() && IsOSVersionAtLeast(major, minor, build, 0);
*/
/// <summary>
/// Indicates whether the current application is running on tvOS.
......
......@@ -3107,6 +3107,8 @@ public sealed partial class OperatingSystem : System.ICloneable, System.Runtime.
public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) { throw null; }
public static bool IsMacOS() { throw null; }
public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) { throw null; }
public static bool IsMacCatalyst() { throw null; }
public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) { throw null; }
public static bool IsTvOS() { throw null; }
public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) { throw null; }
public static bool IsWatchOS() { throw null; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册