Skip to content
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

[SafetyKit] Added support for Xcode 15.2 #15907

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/Foundation/NSObject.mac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public partial class NSObject {
static IntPtr th = Dlfcn.dlopen (Constants.ThreadNetworkLibrary, 1);
static IntPtr ni = Dlfcn.dlopen (Constants.NearbyInteractionLibrary, 1);
static IntPtr sm = Dlfcn.dlopen (Constants.ServiceManagementLibrary, 1);
static IntPtr sa = Dlfcn.dlopen (Constants.SafetyKitLibrary, 1);

#if !NET
[Obsolete ("Use PlatformAssembly for easier code sharing across platforms.")]
Expand Down
51 changes: 51 additions & 0 deletions src/SafetyKit/SAEnums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// SafetyKit enumerations
//
// Author:
// Israel Soto (issoto@microsoft.com)
//
// Copyright 2022 Microsoft Corporation.
//

#nullable enable

using System;
using ObjCRuntime;
using Foundation;

namespace SafetyKit {

[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), NoTV]
[Native]
public enum SAAuthorizationStatus : long {
NotDetermined = 0,
Denied,
Authorized,
}

[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), NoTV]
[Native]
public enum SACrashDetectionEventResponse : long {
Attempted,
Disabled,
}

[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), NoTV]
[Native]
public enum SAEmergencyResponseManagerVoiceCallStatus : long {
Dialing,
Active,
Disconnected,
Failed,
}

[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), NoTV]
[ErrorDomain ("SAErrorDomain")]
[Native]
public enum SAErrorCode : long {
NotAuthorized = 1,
NotAllowed,
InvalidArgument,
OperationFailed,
}
}
6 changes: 3 additions & 3 deletions src/bgen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4123,7 +4123,7 @@ string GetReturnType (AsyncMethodInfo minfo)
return "Task";
var ttype = GetAsyncTaskType (minfo);
if (minfo.HasNSError && (ttype == "bool"))
ttype = "Tuple<bool,NSError>";
ttype = minfo.IsNSErrorNullable ? "Tuple<bool,NSError?>" : "Tuple<bool,NSError>";
return "Task<" + ttype + ">";
}

Expand Down Expand Up @@ -4215,7 +4215,7 @@ void GenerateAsyncMethod (MemberInformation original_minfo, AsyncMethodKind asyn
ttype = GetAsyncTaskType (minfo);
tuple = (minfo.HasNSError && (ttype == "bool"));
if (tuple)
ttype = "Tuple<bool,NSError>";
ttype = minfo.IsNSErrorNullable ? "Tuple<bool,NSError?>" : "Tuple<bool,NSError>";
}
print ("var tcs = new TaskCompletionSource<{0}> ();", ttype);
bool ignoreResult = !is_void &&
Expand Down Expand Up @@ -4247,7 +4247,7 @@ void GenerateAsyncMethod (MemberInformation original_minfo, AsyncMethodKind asyn
else if (tuple) {
var cond_name = minfo.AsyncCompletionParams [0].Name;
var var_name = minfo.AsyncCompletionParams.Last ().Name;
print ("tcs.SetResult (new Tuple<bool,NSError> ({0}_, {1}_));", cond_name, var_name);
print ("tcs.SetResult (new {2} ({0}_, {1}_));", cond_name, var_name, ttype);
} else if (minfo.IsSingleArgAsync)
print ("tcs.SetResult ({0}_!);", minfo.AsyncCompletionParams [0].Name);
else
Expand Down
5 changes: 4 additions & 1 deletion src/bgen/Models/AsyncMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class AsyncMethodInfo : MemberInformation {
public ParameterInfo [] AsyncInitialParams { get; }
public ParameterInfo [] AsyncCompletionParams { get; }
public bool HasNSError { get; }
public bool IsNSErrorNullable { get; }
public bool IsVoidAsync { get; }
public bool IsSingleArgAsync { get; }
public MethodInfo MethodInfo { get; }
Expand All @@ -24,8 +25,10 @@ public AsyncMethodInfo (Generator generator, IMemberGatherer gather, Type type,
var cbParams = lastType.GetMethod ("Invoke")?.GetParameters () ?? Array.Empty<ParameterInfo> ();
AsyncCompletionParams = cbParams;

if (cbParams.LastOrDefault ()?.ParameterType.Name == "NSError") {
var lastParam = cbParams.LastOrDefault ();
if (lastParam is not null && lastParam.ParameterType.Name == "NSError") {
HasNSError = true;
IsNSErrorNullable = generator.AttributeManager.HasAttribute<NullAllowedAttribute> (lastParam);
cbParams = cbParams.DropLast ();
}

Expand Down
5 changes: 5 additions & 0 deletions src/build/generator-frameworks.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ partial class Frameworks {
"QuickLookThumbnailing",
"ReplayKit",
"SafariServices",
"SafetyKit",
"SceneKit",
"ScreenTime",
"Security",
Expand Down Expand Up @@ -251,6 +252,7 @@ partial class Frameworks {
"QuickLookUI",
"ReplayKit",
"SafariServices",
"SafetyKit",
"SceneKit",
"ScreenCaptureKit",
"ScreenTime",
Expand Down Expand Up @@ -320,6 +322,7 @@ partial class Frameworks {
"OSLog",
"PassKit",
"PushKit",
"SafetyKit",
"SceneKit",
"Security",
"ShazamKit",
Expand Down Expand Up @@ -677,6 +680,7 @@ partial class Frameworks {
bool? _QuickLookUI;
bool? _ReplayKit;
bool? _SafariServices;
bool? _SafetyKit;
bool? _SceneKit;
bool? _ScreenCaptureKit;
bool? _ScreenTime;
Expand Down Expand Up @@ -842,6 +846,7 @@ partial class Frameworks {
public bool HaveQuickLookUI { get { if (!_QuickLookUI.HasValue) _QuickLookUI = GetValue ("QuickLookUI"); return _QuickLookUI.Value; } }
public bool HaveReplayKit { get { if (!_ReplayKit.HasValue) _ReplayKit = GetValue ("ReplayKit"); return _ReplayKit.Value; } }
public bool HaveSafariServices { get { if (!_SafariServices.HasValue) _SafariServices = GetValue ("SafariServices"); return _SafariServices.Value; } }
public bool HaveSafetyKit { get { if (!_SafetyKit.HasValue) _SafetyKit = GetValue ("SafetyKit"); return _SafetyKit.Value; } }
public bool HaveSceneKit { get { if (!_SceneKit.HasValue) _SceneKit = GetValue ("SceneKit"); return _SceneKit.Value; } }
public bool HaveScreenCaptureKit { get { if (!_ScreenCaptureKit.HasValue) _ScreenCaptureKit = GetValue ("ScreenCaptureKit"); return _ScreenCaptureKit.Value; } }
public bool HaveScreenTime { get { if (!_ScreenTime.HasValue) _ScreenTime = GetValue ("ScreenTime"); return _ScreenTime.Value; } }
Expand Down
8 changes: 8 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,11 @@ SAFARISERVICES_CORE_SOURCES = \

SAFARISERVICES_SOURCES = \

# SafetyKit

SAFETYKIT_API_SOURCES = \
SafetyKit/SAEnums.cs \

# SceneKit

SCENEKIT_API_SOURCES = \
Expand Down Expand Up @@ -2131,6 +2136,7 @@ MACOS_FRAMEWORKS = \
QuickLookUI \
ReplayKit \
SafariServices \
SafetyKit \
ScreenCaptureKit \
ScreenTime \
ScriptingBridge \
Expand Down Expand Up @@ -2245,6 +2251,7 @@ IOS_FRAMEWORKS = \
QuickLookThumbnailing \
ReplayKit \
SafariServices \
SafetyKit \
ScreenTime \
Security \
SensitiveContentAnalysis \
Expand Down Expand Up @@ -2291,6 +2298,7 @@ WATCHOS_FRAMEWORKS = \
NearbyInteraction \
PassKit \
PushKit \
SafetyKit \
Security \
UIKit XKit \
UserNotifications \
Expand Down
1 change: 1 addition & 0 deletions src/rsp/dotnet/ios-defines-dotnet.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
-d:HAS_QUICKLOOKTHUMBNAILING
-d:HAS_REPLAYKIT
-d:HAS_SAFARISERVICES
-d:HAS_SAFETYKIT
-d:HAS_SCENEKIT
-d:HAS_SCREENTIME
-d:HAS_SECURITY
Expand Down
1 change: 1 addition & 0 deletions src/rsp/dotnet/macos-defines-dotnet.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
-d:HAS_QUICKLOOKUI
-d:HAS_REPLAYKIT
-d:HAS_SAFARISERVICES
-d:HAS_SAFETYKIT
-d:HAS_SCENEKIT
-d:HAS_SCREENCAPTUREKIT
-d:HAS_SCREENTIME
Expand Down
1 change: 1 addition & 0 deletions src/rsp/ios-defines.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
-d:HAS_QUICKLOOKTHUMBNAILING
-d:HAS_REPLAYKIT
-d:HAS_SAFARISERVICES
-d:HAS_SAFETYKIT
-d:HAS_SCENEKIT
-d:HAS_SCREENTIME
-d:HAS_SECURITY
Expand Down
1 change: 1 addition & 0 deletions src/rsp/macos-defines.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
-d:HAS_QUICKLOOKUI
-d:HAS_REPLAYKIT
-d:HAS_SAFARISERVICES
-d:HAS_SAFETYKIT
-d:HAS_SCENEKIT
-d:HAS_SCREENCAPTUREKIT
-d:HAS_SCREENTIME
Expand Down
1 change: 1 addition & 0 deletions src/rsp/watchos-defines.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
-d:HAS_OSLOG
-d:HAS_PASSKIT
-d:HAS_PUSHKIT
-d:HAS_SAFETYKIT
-d:HAS_SCENEKIT
-d:HAS_SECURITY
-d:HAS_SHAZAMKIT
Expand Down
103 changes: 103 additions & 0 deletions src/safetykit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// SafetyKit C# bindings
//
// Authors:
// Israel Soto <issoto@microsoft.com>
//
// Copyright 2022 Microsoft Corporation.
//

using System;
using CoreLocation;
using Foundation;
using ObjCRuntime;

#if !NET
using NativeHandle = System.IntPtr;
#endif

namespace SafetyKit {

[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), NoTV]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface SACrashDetectionEvent : NSSecureCoding, NSCopying {
[Export ("date")]
NSDate Date { get; }

[Export ("response")]
SACrashDetectionEventResponse Response { get; }

[NullAllowed, Export ("location")]
CLLocation Location { get; }
}

delegate void SACrashDetectionManagerRequestAuthorizationCompletionHandler (SAAuthorizationStatus status, [NullAllowed] NSError error);

[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), NoTV]
[BaseType (typeof (NSObject))]
interface SACrashDetectionManager {
[Static]
[Export ("available")]
bool Available { [Bind ("isAvailable")] get; }

[Export ("authorizationStatus")]
SAAuthorizationStatus AuthorizationStatus { get; }

[Wrap ("WeakDelegate")]
[NullAllowed]
ISACrashDetectionDelegate Delegate { get; set; }

[NullAllowed, Export ("delegate", ArgumentSemantic.Weak)]
NSObject WeakDelegate { get; set; }

[Async]
[Export ("requestAuthorizationWithCompletionHandler:")]
void RequestAuthorization (SACrashDetectionManagerRequestAuthorizationCompletionHandler handler);
}

interface ISACrashDetectionDelegate { }

[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), NoTV]
#if NET
[Protocol, Model]
#else
[Protocol, Model (AutoGeneratedName = true)]
#endif
[BaseType (typeof (NSObject))]
interface SACrashDetectionDelegate {
[Export ("crashDetectionManager:didDetectEvent:")]
void DidDetectEvent (SACrashDetectionManager crashDetectionManager, SACrashDetectionEvent @event);
}

delegate void SAEmergencyResponseManagerDialVoiceCallCompletionHandler (bool requestAccepted, [NullAllowed] NSError error);

[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), NoTV]
[BaseType (typeof (NSObject))]
interface SAEmergencyResponseManager {
[Wrap ("WeakDelegate")]
[NullAllowed]
ISAEmergencyResponseDelegate Delegate { get; set; }

[NullAllowed, Export ("delegate", ArgumentSemantic.Weak)]
NSObject WeakDelegate { get; set; }

[Async]
[Export ("dialVoiceCallToPhoneNumber:completionHandler:")]
void DialVoiceCall (string phoneNumber, SAEmergencyResponseManagerDialVoiceCallCompletionHandler handler);
}

interface ISAEmergencyResponseDelegate { }

[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), NoTV]
#if NET
[Protocol, Model]
#else
[Protocol, Model (AutoGeneratedName = true)]
#endif
[BaseType (typeof (NSObject))]
interface SAEmergencyResponseDelegate {
[Export ("emergencyResponseManager:didUpdateVoiceCallStatus:")]
void DidUpdateVoiceCallStatus (SAEmergencyResponseManager emergencyResponseManager, SAEmergencyResponseManagerVoiceCallStatus voiceCallStatus);
}
}
1 change: 1 addition & 0 deletions tests/mtouch/RegistrarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ public void MT4134 ()
new { Framework = "BackgroundAssets", Version = "16.0" },
new { Framework = "MetalFX", Version = "16.0" },
new { Framework = "PushToTalk", Version = "16.0" },
new { Framework = "SafetyKit", Version = "16.0" },
new { Framework = "SharedWithYou", Version = "16.0" },
new { Framework = "SharedWithYouCore", Version = "16.0" },
new { Framework = "Cinematic", Version = "17.0" },
Expand Down
21 changes: 0 additions & 21 deletions tests/xtro-sharpie/api-annotations-dotnet/iOS-SafetyKit.todo

This file was deleted.

21 changes: 0 additions & 21 deletions tests/xtro-sharpie/api-annotations-dotnet/macOS-SafetyKit.todo

This file was deleted.

Loading