From a1832d2ef00d816b67cd24c11926f33a87c14ad6 Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Tue, 12 Nov 2024 17:17:21 +0100 Subject: [PATCH 1/8] fix (Laerdal.Dfu.csproj): add support for maccatalyst --- Laerdal.Dfu.sln | 1 + Laerdal.Dfu/Laerdal.Dfu.csproj | 50 ++- Laerdal.Dfu/Laerdal.Dfu.csproj.DotSettings | 5 + .../DfuInstallation.cs | 400 +++++++++--------- .../Specific/DfuLogger.cs | 62 +-- .../Specific/DfuNotificationActivity.cs | 58 +-- .../Specific/DfuProgressListener.cs | 228 +++++----- .../Specific/DfuService.cs | 74 ++-- .../DfuInstallation.cs | 258 +++++------ .../Specific/DfuLogger.cs | 20 +- .../Specific/DfuPeripheralSelectorDelegate.cs | 44 +- .../Specific/DfuProgressDelegate.cs | 44 +- .../Specific/DfuServiceDelegate.cs | 42 +- .../Laerdal.GenerateSignAndUploadSbom.sh | 4 +- .../Laerdal.SetupBuildEnvironment.sh | 4 +- 15 files changed, 659 insertions(+), 635 deletions(-) rename Laerdal.Dfu/{Platforms/Android => Platforms.Droid}/DfuInstallation.cs (97%) rename Laerdal.Dfu/{Platforms/Android => Platforms.Droid}/Specific/DfuLogger.cs (96%) rename Laerdal.Dfu/{Platforms/Android => Platforms.Droid}/Specific/DfuNotificationActivity.cs (97%) rename Laerdal.Dfu/{Platforms/Android => Platforms.Droid}/Specific/DfuProgressListener.cs (97%) rename Laerdal.Dfu/{Platforms/Android => Platforms.Droid}/Specific/DfuService.cs (97%) rename Laerdal.Dfu/{Platforms/iOS => Platforms.iOSandMacCatalyst}/DfuInstallation.cs (97%) rename Laerdal.Dfu/{Platforms/iOS => Platforms.iOSandMacCatalyst}/Specific/DfuLogger.cs (96%) rename Laerdal.Dfu/{Platforms/iOS => Platforms.iOSandMacCatalyst}/Specific/DfuPeripheralSelectorDelegate.cs (97%) rename Laerdal.Dfu/{Platforms/iOS => Platforms.iOSandMacCatalyst}/Specific/DfuProgressDelegate.cs (97%) rename Laerdal.Dfu/{Platforms/iOS => Platforms.iOSandMacCatalyst}/Specific/DfuServiceDelegate.cs (97%) mode change 100755 => 100644 Laerdal.Scripts/Laerdal.GenerateSignAndUploadSbom.sh diff --git a/Laerdal.Dfu.sln b/Laerdal.Dfu.sln index 2264f7b..78f986c 100644 --- a/Laerdal.Dfu.sln +++ b/Laerdal.Dfu.sln @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Misc", "_Misc", "{37EBD209 .github\workflows\github-actions.yml = .github\workflows\github-actions.yml .gitignore = .gitignore global.json = global.json + Laerdal.Scripts\Laerdal.GenerateSignAndUploadSbom.sh = Laerdal.Scripts\Laerdal.GenerateSignAndUploadSbom.sh EndProjectSection EndProject Global diff --git a/Laerdal.Dfu/Laerdal.Dfu.csproj b/Laerdal.Dfu/Laerdal.Dfu.csproj index fb4dd7c..032c7a2 100644 --- a/Laerdal.Dfu/Laerdal.Dfu.csproj +++ b/Laerdal.Dfu/Laerdal.Dfu.csproj @@ -14,7 +14,8 @@ $(TargetFrameworks)net8.0; $(TargetFrameworks)net8.0-ios; - $(TargetFrameworks)net8.0-android + $(TargetFrameworks)net8.0-android; + $(TargetFrameworks)net8.0-maccatalyst @@ -33,27 +34,39 @@ - 34 - 21.0 - 21.0 + 34 + 21.0 + 21.0 - 17.0 - 14.2 - 14.2 + 17.0 + 14.2 + 14.2 + + + 17.0 + 13.1 + 13.1 - - - + + + + - + + + + + + + - - + + - + true true @@ -81,11 +94,14 @@ - - + + + - + + + diff --git a/Laerdal.Dfu/Laerdal.Dfu.csproj.DotSettings b/Laerdal.Dfu/Laerdal.Dfu.csproj.DotSettings index 06347ba..e304b59 100644 --- a/Laerdal.Dfu/Laerdal.Dfu.csproj.DotSettings +++ b/Laerdal.Dfu/Laerdal.Dfu.csproj.DotSettings @@ -1,5 +1,10 @@  + True + True True + True + True + True True True True diff --git a/Laerdal.Dfu/Platforms/Android/DfuInstallation.cs b/Laerdal.Dfu/Platforms.Droid/DfuInstallation.cs similarity index 97% rename from Laerdal.Dfu/Platforms/Android/DfuInstallation.cs rename to Laerdal.Dfu/Platforms.Droid/DfuInstallation.cs index 7f165ee..d751140 100644 --- a/Laerdal.Dfu/Platforms/Android/DfuInstallation.cs +++ b/Laerdal.Dfu/Platforms.Droid/DfuInstallation.cs @@ -1,201 +1,201 @@ -using Android.App; -using Android.OS; - -using Java.Lang; - -using Laerdal.Dfu.Specific; - -using System; -using System.Globalization; -using System.Linq; - -namespace Laerdal.Dfu -{ - public partial class DfuInstallation - { - public Func CustomDfuServiceInitiatorConfiguration { get; set; } = (dfuInitiator) => dfuInitiator; - - private void SetInitiator() - { - DfuProgressListener = new DfuProgressListener(this); - DfuLogger = new DfuLogger(DeviceId); - - Initiator = new Laerdal.Dfu.Bindings.Android.DfuServiceInitiator(DeviceId).SetZip(FileUrl); - - // PacketsReceiptNotifications - Initiator = Initiator.SetPacketsReceiptNotificationsEnabled(PacketReceiptNotificationParameter.HasValue); - Initiator = Initiator.SetPacketsReceiptNotificationsValue(PacketReceiptNotificationParameter ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultPrnValue); - - // DataObjectPreparationDelay - Initiator = Initiator.SetPrepareDataObjectDelay((long) (DataObjectPreparationDelay ?? 0)); - - // DisableResume - if (DisableResume ?? false) - { - Initiator = Initiator.DisableResume(); - } - - // AlternativeAdvertisingName - if (!string.IsNullOrEmpty(AlternativeAdvertisingName)) - { - Initiator = Initiator.SetDeviceName(AlternativeAdvertisingName); - } - - // ForceScanningForNewAddressInLegacyDfu - if (ForceScanningForNewAddressInLegacyDfu.HasValue) - { - Initiator = Initiator.SetForceScanningForNewAddressInLegacyDfu(ForceScanningForNewAddressInLegacyDfu.Value); - } - - // EnableUnsafeExperimentalButtonlessServiceInSecureDfu - if (EnableUnsafeExperimentalButtonlessServiceInSecureDfu.HasValue) - { - Initiator = Initiator.SetUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(EnableUnsafeExperimentalButtonlessServiceInSecureDfu.Value); - } - - // ForceDfu - if (ForceDfu.HasValue) - { - Initiator = Initiator.SetForceDfu(ForceDfu.Value); - } - - // DisableMtuRequest - if (DisableMtuRequest ?? false) - { - Initiator = Initiator.DisableMtuRequest(); - } - - // DisableNotification - if (DisableNotification.HasValue) - { - Initiator = Initiator.SetDisableNotification(DisableNotification.Value); - } - - // MbrSize - Initiator = Initiator.SetMbrSize(MbrSize ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultMbrSize); - - // Scope - if (Scope.HasValue) - { - Initiator = Initiator.SetScope((int) Scope.Value); - } - - // Foreground - if (Foreground.HasValue) - { - Initiator = Initiator.SetForeground(Foreground.Value); - } - - // KeepBond - if (KeepBond.HasValue) - { - Initiator = Initiator.SetKeepBond(KeepBond.Value); - } - - // RestoreBond - if (RestoreBond.HasValue) - { - Initiator = Initiator.SetRestoreBond(RestoreBond.Value); - } - - // Mtu - if (Mtu.HasValue) - { - Initiator = Initiator.SetMtu(Mtu.Value); - } - - // NumberOfRetries - if (NumberOfRetries.HasValue) - { - Initiator = Initiator.SetNumberOfRetries(NumberOfRetries.Value); - } - - // For Oreo progress - if ((int) Build.VERSION.SdkInt >= 26) - { - Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.CreateDfuNotificationChannel(Android.App.Application.Context); - } - - Initiator = CustomDfuServiceInitiatorConfiguration?.Invoke(Initiator); - - // public DfuServiceInitiator SetCurrentMtu(int mtu) - // public DfuServiceInitiator SetCustomUuidsForButtonlessDfuWithBondSharing(UUID buttonlessDfuServiceUuid, UUID buttonlessDfuControlPointUuid) - // public DfuServiceInitiator SetCustomUuidsForButtonlessDfuWithoutBondSharing(UUID buttonlessDfuServiceUuid, UUID buttonlessDfuControlPointUuid) - // public DfuServiceInitiator SetCustomUuidsForExperimentalButtonlessDfu(UUID buttonlessDfuServiceUuid, UUID buttonlessDfuControlPointUuid) - // public DfuServiceInitiator SetCustomUuidsForLegacyDfu(UUID dfuServiceUuid, UUID dfuControlPointUuid, UUID dfuPacketUuid, UUID dfuVersionUuid) - // public DfuServiceInitiator SetCustomUuidsForSecureDfu(UUID dfuServiceUuid, UUID dfuControlPointUuid, UUID dfuPacketUuid) - } - - public Laerdal.Dfu.Bindings.Android.DfuServiceInitiator Initiator { get; private set; } - - public Laerdal.Dfu.Bindings.Android.DfuServiceController Controller { get; private set; } - - private DfuProgressListener DfuProgressListener { get; set;} - - private DfuLogger DfuLogger { get; set;} - - public DfuInstallation(string deviceId, string fileUrl) : base(deviceId, fileUrl) - { - } - - public DfuInstallation() : base() - { - } - - public override void Start() - { - if (Controller != null) - { - throw new System.Exception("Controller is already set."); - } - - SetInitiator(); - Controller = Initiator.Start(Android.App.Application.Context, Class.FromType(typeof(DfuService))); - } - - public override void Pause() - { - Controller?.Pause(); - } - - public override void Resume() - { - Controller?.Resume(); - } - - public override void Abort() - { - Controller?.Abort(); - } - - protected override void Dispose(bool disposing) - { - DfuProgressListener?.Dispose(); - if (disposing) - { - Initiator?.Dispose(); - Controller?.Dispose(); - DfuLogger?.Dispose(); - } - } - - public bool CheckDeviceAddress(string deviceAddress) - { - if (deviceAddress == DeviceId) - { - return true; - } - - var parsed = DeviceId.Split(':').Select(p => int.Parse(p, NumberStyles.HexNumber)).ToList(); - parsed[^1] += 1; - var deviceAddressPlusOne = string.Join(":", parsed.Select(p => p.ToString("X2"))); - - if (deviceAddress == deviceAddressPlusOne) - { - return true; - } - - return false; - } - } +using Android.App; +using Android.OS; + +using Java.Lang; + +using Laerdal.Dfu.Specific; + +using System; +using System.Globalization; +using System.Linq; + +namespace Laerdal.Dfu +{ + public partial class DfuInstallation + { + public Func CustomDfuServiceInitiatorConfiguration { get; set; } = (dfuInitiator) => dfuInitiator; + + private void SetInitiator() + { + DfuProgressListener = new DfuProgressListener(this); + DfuLogger = new DfuLogger(DeviceId); + + Initiator = new Laerdal.Dfu.Bindings.Android.DfuServiceInitiator(DeviceId).SetZip(FileUrl); + + // PacketsReceiptNotifications + Initiator = Initiator.SetPacketsReceiptNotificationsEnabled(PacketReceiptNotificationParameter.HasValue); + Initiator = Initiator.SetPacketsReceiptNotificationsValue(PacketReceiptNotificationParameter ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultPrnValue); + + // DataObjectPreparationDelay + Initiator = Initiator.SetPrepareDataObjectDelay((long) (DataObjectPreparationDelay ?? 0)); + + // DisableResume + if (DisableResume ?? false) + { + Initiator = Initiator.DisableResume(); + } + + // AlternativeAdvertisingName + if (!string.IsNullOrEmpty(AlternativeAdvertisingName)) + { + Initiator = Initiator.SetDeviceName(AlternativeAdvertisingName); + } + + // ForceScanningForNewAddressInLegacyDfu + if (ForceScanningForNewAddressInLegacyDfu.HasValue) + { + Initiator = Initiator.SetForceScanningForNewAddressInLegacyDfu(ForceScanningForNewAddressInLegacyDfu.Value); + } + + // EnableUnsafeExperimentalButtonlessServiceInSecureDfu + if (EnableUnsafeExperimentalButtonlessServiceInSecureDfu.HasValue) + { + Initiator = Initiator.SetUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(EnableUnsafeExperimentalButtonlessServiceInSecureDfu.Value); + } + + // ForceDfu + if (ForceDfu.HasValue) + { + Initiator = Initiator.SetForceDfu(ForceDfu.Value); + } + + // DisableMtuRequest + if (DisableMtuRequest ?? false) + { + Initiator = Initiator.DisableMtuRequest(); + } + + // DisableNotification + if (DisableNotification.HasValue) + { + Initiator = Initiator.SetDisableNotification(DisableNotification.Value); + } + + // MbrSize + Initiator = Initiator.SetMbrSize(MbrSize ?? Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.DefaultMbrSize); + + // Scope + if (Scope.HasValue) + { + Initiator = Initiator.SetScope((int) Scope.Value); + } + + // Foreground + if (Foreground.HasValue) + { + Initiator = Initiator.SetForeground(Foreground.Value); + } + + // KeepBond + if (KeepBond.HasValue) + { + Initiator = Initiator.SetKeepBond(KeepBond.Value); + } + + // RestoreBond + if (RestoreBond.HasValue) + { + Initiator = Initiator.SetRestoreBond(RestoreBond.Value); + } + + // Mtu + if (Mtu.HasValue) + { + Initiator = Initiator.SetMtu(Mtu.Value); + } + + // NumberOfRetries + if (NumberOfRetries.HasValue) + { + Initiator = Initiator.SetNumberOfRetries(NumberOfRetries.Value); + } + + // For Oreo progress + if ((int) Build.VERSION.SdkInt >= 26) + { + Laerdal.Dfu.Bindings.Android.DfuServiceInitiator.CreateDfuNotificationChannel(Android.App.Application.Context); + } + + Initiator = CustomDfuServiceInitiatorConfiguration?.Invoke(Initiator); + + // public DfuServiceInitiator SetCurrentMtu(int mtu) + // public DfuServiceInitiator SetCustomUuidsForButtonlessDfuWithBondSharing(UUID buttonlessDfuServiceUuid, UUID buttonlessDfuControlPointUuid) + // public DfuServiceInitiator SetCustomUuidsForButtonlessDfuWithoutBondSharing(UUID buttonlessDfuServiceUuid, UUID buttonlessDfuControlPointUuid) + // public DfuServiceInitiator SetCustomUuidsForExperimentalButtonlessDfu(UUID buttonlessDfuServiceUuid, UUID buttonlessDfuControlPointUuid) + // public DfuServiceInitiator SetCustomUuidsForLegacyDfu(UUID dfuServiceUuid, UUID dfuControlPointUuid, UUID dfuPacketUuid, UUID dfuVersionUuid) + // public DfuServiceInitiator SetCustomUuidsForSecureDfu(UUID dfuServiceUuid, UUID dfuControlPointUuid, UUID dfuPacketUuid) + } + + public Laerdal.Dfu.Bindings.Android.DfuServiceInitiator Initiator { get; private set; } + + public Laerdal.Dfu.Bindings.Android.DfuServiceController Controller { get; private set; } + + private DfuProgressListener DfuProgressListener { get; set;} + + private DfuLogger DfuLogger { get; set;} + + public DfuInstallation(string deviceId, string fileUrl) : base(deviceId, fileUrl) + { + } + + public DfuInstallation() : base() + { + } + + public override void Start() + { + if (Controller != null) + { + throw new System.Exception("Controller is already set."); + } + + SetInitiator(); + Controller = Initiator.Start(Android.App.Application.Context, Class.FromType(typeof(DfuService))); + } + + public override void Pause() + { + Controller?.Pause(); + } + + public override void Resume() + { + Controller?.Resume(); + } + + public override void Abort() + { + Controller?.Abort(); + } + + protected override void Dispose(bool disposing) + { + DfuProgressListener?.Dispose(); + if (disposing) + { + Initiator?.Dispose(); + Controller?.Dispose(); + DfuLogger?.Dispose(); + } + } + + public bool CheckDeviceAddress(string deviceAddress) + { + if (deviceAddress == DeviceId) + { + return true; + } + + var parsed = DeviceId.Split(':').Select(p => int.Parse(p, NumberStyles.HexNumber)).ToList(); + parsed[^1] += 1; + var deviceAddressPlusOne = string.Join(":", parsed.Select(p => p.ToString("X2"))); + + if (deviceAddress == deviceAddressPlusOne) + { + return true; + } + + return false; + } + } } \ No newline at end of file diff --git a/Laerdal.Dfu/Platforms/Android/Specific/DfuLogger.cs b/Laerdal.Dfu/Platforms.Droid/Specific/DfuLogger.cs similarity index 96% rename from Laerdal.Dfu/Platforms/Android/Specific/DfuLogger.cs rename to Laerdal.Dfu/Platforms.Droid/Specific/DfuLogger.cs index 3f4a58b..1d98048 100644 --- a/Laerdal.Dfu/Platforms/Android/Specific/DfuLogger.cs +++ b/Laerdal.Dfu/Platforms.Droid/Specific/DfuLogger.cs @@ -1,32 +1,32 @@ -using Android.App; -using Laerdal.Dfu.Enums; - -namespace Laerdal.Dfu.Specific -{ - public class DfuLogger : Java.Lang.Object, Laerdal.Dfu.Bindings.Android.IDfuLogListener - { - public string DeviceAddress { get; } - - public DfuLogger(string deviceAddress) - { - DeviceAddress = deviceAddress; - - Laerdal.Dfu.Bindings.Android.DfuServiceListenerHelper.RegisterLogListener(Android.App.Application.Context, this); - } - - protected override void Dispose(bool disposing) - { - Laerdal.Dfu.Bindings.Android.DfuServiceListenerHelper.UnregisterLogListener(Android.App.Application.Context, this); - - base.Dispose(disposing); - } - - public void OnLogEvent(string deviceAddress, int level, string message) - { - if (deviceAddress != DeviceAddress) - return; - - Events.OnDfuMessageReceived((DfuLogLevel) level, $"{deviceAddress} : {message}"); - } - } +using Android.App; +using Laerdal.Dfu.Enums; + +namespace Laerdal.Dfu.Specific +{ + public class DfuLogger : Java.Lang.Object, Laerdal.Dfu.Bindings.Android.IDfuLogListener + { + public string DeviceAddress { get; } + + public DfuLogger(string deviceAddress) + { + DeviceAddress = deviceAddress; + + Laerdal.Dfu.Bindings.Android.DfuServiceListenerHelper.RegisterLogListener(Android.App.Application.Context, this); + } + + protected override void Dispose(bool disposing) + { + Laerdal.Dfu.Bindings.Android.DfuServiceListenerHelper.UnregisterLogListener(Android.App.Application.Context, this); + + base.Dispose(disposing); + } + + public void OnLogEvent(string deviceAddress, int level, string message) + { + if (deviceAddress != DeviceAddress) + return; + + Events.OnDfuMessageReceived((DfuLogLevel) level, $"{deviceAddress} : {message}"); + } + } } \ No newline at end of file diff --git a/Laerdal.Dfu/Platforms/Android/Specific/DfuNotificationActivity.cs b/Laerdal.Dfu/Platforms.Droid/Specific/DfuNotificationActivity.cs similarity index 97% rename from Laerdal.Dfu/Platforms/Android/Specific/DfuNotificationActivity.cs rename to Laerdal.Dfu/Platforms.Droid/Specific/DfuNotificationActivity.cs index d47e148..aa8acec 100644 --- a/Laerdal.Dfu/Platforms/Android/Specific/DfuNotificationActivity.cs +++ b/Laerdal.Dfu/Platforms.Droid/Specific/DfuNotificationActivity.cs @@ -1,30 +1,30 @@ -using Android.App; -using Android.OS; - -namespace Laerdal.Dfu.Specific -{ - public class DfuNotificationActivity : Activity - { - protected override void OnCreate(Bundle savedInstanceState) - { - base.OnCreate(savedInstanceState); - - // Original Nordic-code below. We assume the app can take care of itself. - // Not very useful hooking up notification click to app... If you need it: make your own DfuService+DfuNotification - /* - // If this activity is the root activity of the task, the app is not running - if (IsTaskRoot) - { - // Start the app before finishing - var intent = new Intent(this, typeof(MainActivity)); - intent.SetFlags(ActivityFlags.NewTask); - intent.PutExtras(intent.Extras); - StartActivity(intent); - } - */ - - // Now finish, which will drop you to the activity at which you were at the top of the task stack - Finish(); - } - } +using Android.App; +using Android.OS; + +namespace Laerdal.Dfu.Specific +{ + public class DfuNotificationActivity : Activity + { + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + + // Original Nordic-code below. We assume the app can take care of itself. + // Not very useful hooking up notification click to app... If you need it: make your own DfuService+DfuNotification + /* + // If this activity is the root activity of the task, the app is not running + if (IsTaskRoot) + { + // Start the app before finishing + var intent = new Intent(this, typeof(MainActivity)); + intent.SetFlags(ActivityFlags.NewTask); + intent.PutExtras(intent.Extras); + StartActivity(intent); + } + */ + + // Now finish, which will drop you to the activity at which you were at the top of the task stack + Finish(); + } + } } \ No newline at end of file diff --git a/Laerdal.Dfu/Platforms/Android/Specific/DfuProgressListener.cs b/Laerdal.Dfu/Platforms.Droid/Specific/DfuProgressListener.cs similarity index 97% rename from Laerdal.Dfu/Platforms/Android/Specific/DfuProgressListener.cs rename to Laerdal.Dfu/Platforms.Droid/Specific/DfuProgressListener.cs index 2bab3af..7d3ac2c 100644 --- a/Laerdal.Dfu/Platforms/Android/Specific/DfuProgressListener.cs +++ b/Laerdal.Dfu/Platforms.Droid/Specific/DfuProgressListener.cs @@ -1,115 +1,115 @@ -using Android.App; -using Laerdal.Dfu.Enums; - -namespace Laerdal.Dfu.Specific -{ - public class DfuProgressListener : Laerdal.Dfu.Bindings.Android.DfuProgressListenerAdapter - { - private DfuInstallation DfuInstallation { get; } - - public DfuProgressListener(DfuInstallation dfuInstallation) - { - DfuInstallation = dfuInstallation; - Laerdal.Dfu.Bindings.Android.DfuServiceListenerHelper.RegisterProgressListener(Android.App.Application.Context, this); - } - - protected override void Dispose(bool disposing) - { - Laerdal.Dfu.Bindings.Android.DfuServiceListenerHelper.UnregisterProgressListener(Android.App.Application.Context, this); - base.Dispose(disposing); - } - - public override void OnError(string deviceAddress, - int error, - int errorType, - string message) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.OnDfuError((DfuError) error, message); - } - - public override void OnDeviceConnected(string deviceAddress) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.Connected; - } - - public override void OnDeviceConnecting(string deviceAddress) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.Connecting; - } - - public override void OnDeviceDisconnected(string deviceAddress) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.Disconnected; - } - - public override void OnDeviceDisconnecting(string deviceAddress) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.Disconnecting; - } - - public override void OnDfuAborted(string deviceAddress) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.Aborted; - } - - public override void OnDfuCompleted(string deviceAddress) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.Completed; - } - - public override void OnFirmwareValidating(string deviceAddress) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.Validating; - } - - public override void OnDfuProcessStarted(string deviceAddress) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.Started; - } - - public override void OnDfuProcessStarting(string deviceAddress) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.Starting; - } - - public override void OnEnablingDfuMode(string deviceAddress) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.EnablingDfuMode; - } - - public override void OnProgressChanged(string deviceAddress, - int percent, - float speed, - float avgSpeed, - int currentPart, - int partsTotal) - { - if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } - - DfuInstallation.State = DfuState.Uploading; - DfuInstallation.OnProgressChanged(percent / 100D, speed, avgSpeed); - } - } +using Android.App; +using Laerdal.Dfu.Enums; + +namespace Laerdal.Dfu.Specific +{ + public class DfuProgressListener : Laerdal.Dfu.Bindings.Android.DfuProgressListenerAdapter + { + private DfuInstallation DfuInstallation { get; } + + public DfuProgressListener(DfuInstallation dfuInstallation) + { + DfuInstallation = dfuInstallation; + Laerdal.Dfu.Bindings.Android.DfuServiceListenerHelper.RegisterProgressListener(Android.App.Application.Context, this); + } + + protected override void Dispose(bool disposing) + { + Laerdal.Dfu.Bindings.Android.DfuServiceListenerHelper.UnregisterProgressListener(Android.App.Application.Context, this); + base.Dispose(disposing); + } + + public override void OnError(string deviceAddress, + int error, + int errorType, + string message) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.OnDfuError((DfuError) error, message); + } + + public override void OnDeviceConnected(string deviceAddress) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.Connected; + } + + public override void OnDeviceConnecting(string deviceAddress) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.Connecting; + } + + public override void OnDeviceDisconnected(string deviceAddress) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.Disconnected; + } + + public override void OnDeviceDisconnecting(string deviceAddress) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.Disconnecting; + } + + public override void OnDfuAborted(string deviceAddress) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.Aborted; + } + + public override void OnDfuCompleted(string deviceAddress) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.Completed; + } + + public override void OnFirmwareValidating(string deviceAddress) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.Validating; + } + + public override void OnDfuProcessStarted(string deviceAddress) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.Started; + } + + public override void OnDfuProcessStarting(string deviceAddress) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.Starting; + } + + public override void OnEnablingDfuMode(string deviceAddress) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.EnablingDfuMode; + } + + public override void OnProgressChanged(string deviceAddress, + int percent, + float speed, + float avgSpeed, + int currentPart, + int partsTotal) + { + if (!DfuInstallation.CheckDeviceAddress(deviceAddress)) { return; } + + DfuInstallation.State = DfuState.Uploading; + DfuInstallation.OnProgressChanged(percent / 100D, speed, avgSpeed); + } + } } \ No newline at end of file diff --git a/Laerdal.Dfu/Platforms/Android/Specific/DfuService.cs b/Laerdal.Dfu/Platforms.Droid/Specific/DfuService.cs similarity index 97% rename from Laerdal.Dfu/Platforms/Android/Specific/DfuService.cs rename to Laerdal.Dfu/Platforms.Droid/Specific/DfuService.cs index 8905378..7ca77cf 100644 --- a/Laerdal.Dfu/Platforms/Android/Specific/DfuService.cs +++ b/Laerdal.Dfu/Platforms.Droid/Specific/DfuService.cs @@ -1,40 +1,40 @@ -using Android.App; -using Android.Content.PM; - -using Java.Lang; - -namespace Laerdal.Dfu.Specific +using Android.App; +using Android.Content.PM; + +using Java.Lang; + +namespace Laerdal.Dfu.Specific { - [Service(ForegroundServiceType = ForegroundService.TypeConnectedDevice)] - public class DfuService : Laerdal.Dfu.Bindings.Android.DfuBaseService - { - public DfuService() - { - - } - - protected override bool IsDebug => true; - - protected override Class NotificationTarget => Class.FromType(typeof(DfuNotificationActivity)); - - /* - * As a target activity the NotificationActivity is returned, not the MainActivity. This is because - * the notification must create a new task: - * - * intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - * - * when you press it. You can use NotificationActivity to check whether the new activity - * is a root activity (that means no other activity was open earlier) or that some - * other activity is already open. In the latter case the NotificationActivity will just be - * closed. The system will restore the previous activity. However, if the application has been - * closed during upload and you click the notification, a NotificationActivity will - * be launched as a root activity. It will create and start the main activity and - * terminate itself. - * - * This method may be used to restore the target activity in case the application - * was closed or is open. It may also be used to recreate an activity history using - * startActivities(...). - */ - } + [Service(ForegroundServiceType = ForegroundService.TypeConnectedDevice)] + public class DfuService : Laerdal.Dfu.Bindings.Android.DfuBaseService + { + public DfuService() + { + + } + + protected override bool IsDebug => true; + + protected override Class NotificationTarget => Class.FromType(typeof(DfuNotificationActivity)); + + /* + * As a target activity the NotificationActivity is returned, not the MainActivity. This is because + * the notification must create a new task: + * + * intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + * + * when you press it. You can use NotificationActivity to check whether the new activity + * is a root activity (that means no other activity was open earlier) or that some + * other activity is already open. In the latter case the NotificationActivity will just be + * closed. The system will restore the previous activity. However, if the application has been + * closed during upload and you click the notification, a NotificationActivity will + * be launched as a root activity. It will create and start the main activity and + * terminate itself. + * + * This method may be used to restore the target activity in case the application + * was closed or is open. It may also be used to recreate an activity history using + * startActivities(...). + */ + } } \ No newline at end of file diff --git a/Laerdal.Dfu/Platforms/iOS/DfuInstallation.cs b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs similarity index 97% rename from Laerdal.Dfu/Platforms/iOS/DfuInstallation.cs rename to Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs index 1c00c0a..f81820d 100644 --- a/Laerdal.Dfu/Platforms/iOS/DfuInstallation.cs +++ b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs @@ -1,130 +1,130 @@ -using CoreFoundation; - -using Foundation; - -using Laerdal.Dfu.Specific; - -namespace Laerdal.Dfu -{ - public partial class DfuInstallation - { - public static Func Queue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default); - public static Func DelegateQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default); - public static Func ProgressQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default); - public static Func LoggerQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default); - - public Func CustomDfuServiceInitiatorConfiguration { get; set; } = (dfuInitiator) => dfuInitiator; - - private void SetInitiator() - { - DfuProgressDelegate = new DfuProgressDelegate(this); - DfuServiceDelegate = new DfuServiceDelegate(this); - DfuPeripheralSelectorDelegate = new DfuPeripheralSelectorDelegate(this); - - Firmware = new Laerdal.Dfu.Bindings.iOS.DFUFirmware(new NSUrl(FileUrl, false), out NSError error); - - Initiator = new Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator(Queue.Invoke(), - DelegateQueue.Invoke(), - ProgressQueue.Invoke(), - LoggerQueue.Invoke(), - null) - { - Logger = new DfuLogger(), - WeakProgressDelegate = DfuProgressDelegate, - WeakDelegate = DfuServiceDelegate, - }; - Initiator = Initiator.WithFirmware(Firmware); - - // PacketsReceiptNotifications - if (PacketReceiptNotificationParameter.HasValue) - Initiator.PacketReceiptNotificationParameter = PacketReceiptNotificationParameter.Value; - - // DataObjectPreparationDelay - if (DataObjectPreparationDelay.HasValue) - Initiator.DataObjectPreparationDelay = DataObjectPreparationDelay.Value; - - // DisableResume - if (DisableResume.HasValue) - Initiator.DisableResume = DisableResume.Value; - - // AlternativeAdvertisingName - Initiator.AlternativeAdvertisingNameEnabled = !string.IsNullOrEmpty(AlternativeAdvertisingName); - Initiator.AlternativeAdvertisingName = AlternativeAdvertisingName; - - // ForceScanningForNewAddressInLegacyDfu - if (ForceScanningForNewAddressInLegacyDfu.HasValue) - Initiator.ForceScanningForNewAddressInLegacyDfu = ForceScanningForNewAddressInLegacyDfu.Value; - - // EnableUnsafeExperimentalButtonlessServiceInSecureDfu - if (EnableUnsafeExperimentalButtonlessServiceInSecureDfu.HasValue) - Initiator.ForceScanningForNewAddressInLegacyDfu = EnableUnsafeExperimentalButtonlessServiceInSecureDfu.Value; - - // ForceDfu - if (ForceDfu.HasValue) - Initiator.ForceDfu = ForceDfu.Value; - - // ConnectionTimeout - if (ConnectionTimeout.HasValue) - Initiator.ConnectionTimeout = ConnectionTimeout.Value; - - Initiator = CustomDfuServiceInitiatorConfiguration?.Invoke(Initiator); - - // public DFUUuidHelper UuidHelper {get; set;} - } - - public Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator Initiator { get; private set; } - - public Laerdal.Dfu.Bindings.iOS.DFUServiceController Controller { get; private set; } - - public Laerdal.Dfu.Bindings.iOS.DFUFirmware Firmware { get; private set;} - - private DfuProgressDelegate DfuProgressDelegate { get; set;} - - private DfuServiceDelegate DfuServiceDelegate { get; set;} - - private DfuPeripheralSelectorDelegate DfuPeripheralSelectorDelegate { get; set;} - - public DfuInstallation(string deviceId, string fileUrl) : base(deviceId, fileUrl) - { - } - - public DfuInstallation() : base() - { - } - - public override void Start() - { - if (Controller != null) - { - throw new System.Exception("Controller is already set."); - } - SetInitiator(); - Controller = Initiator.StartWithTargetWithIdentifier(new NSUuid(DeviceId)); - } - - public override void Pause() - { - Controller?.Pause(); - } - - public override void Resume() - { - Controller?.Resume(); - } - - public override void Abort() - { - Controller?.Abort(); - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - Initiator?.Dispose(); - Controller?.Dispose(); - Firmware?.Dispose(); - } - } - } +using CoreFoundation; + +using Foundation; + +using Laerdal.Dfu.Specific; + +namespace Laerdal.Dfu +{ + public partial class DfuInstallation + { + public static Func Queue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default); + public static Func DelegateQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default); + public static Func ProgressQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default); + public static Func LoggerQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default); + + public Func CustomDfuServiceInitiatorConfiguration { get; set; } = (dfuInitiator) => dfuInitiator; + + private void SetInitiator() + { + DfuProgressDelegate = new DfuProgressDelegate(this); + DfuServiceDelegate = new DfuServiceDelegate(this); + DfuPeripheralSelectorDelegate = new DfuPeripheralSelectorDelegate(this); + + Firmware = new Laerdal.Dfu.Bindings.iOS.DFUFirmware(new NSUrl(FileUrl, false), out NSError error); + + Initiator = new Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator(Queue.Invoke(), + DelegateQueue.Invoke(), + ProgressQueue.Invoke(), + LoggerQueue.Invoke(), + null) + { + Logger = new DfuLogger(), + WeakProgressDelegate = DfuProgressDelegate, + WeakDelegate = DfuServiceDelegate, + }; + Initiator = Initiator.WithFirmware(Firmware); + + // PacketsReceiptNotifications + if (PacketReceiptNotificationParameter.HasValue) + Initiator.PacketReceiptNotificationParameter = PacketReceiptNotificationParameter.Value; + + // DataObjectPreparationDelay + if (DataObjectPreparationDelay.HasValue) + Initiator.DataObjectPreparationDelay = DataObjectPreparationDelay.Value; + + // DisableResume + if (DisableResume.HasValue) + Initiator.DisableResume = DisableResume.Value; + + // AlternativeAdvertisingName + Initiator.AlternativeAdvertisingNameEnabled = !string.IsNullOrEmpty(AlternativeAdvertisingName); + Initiator.AlternativeAdvertisingName = AlternativeAdvertisingName; + + // ForceScanningForNewAddressInLegacyDfu + if (ForceScanningForNewAddressInLegacyDfu.HasValue) + Initiator.ForceScanningForNewAddressInLegacyDfu = ForceScanningForNewAddressInLegacyDfu.Value; + + // EnableUnsafeExperimentalButtonlessServiceInSecureDfu + if (EnableUnsafeExperimentalButtonlessServiceInSecureDfu.HasValue) + Initiator.ForceScanningForNewAddressInLegacyDfu = EnableUnsafeExperimentalButtonlessServiceInSecureDfu.Value; + + // ForceDfu + if (ForceDfu.HasValue) + Initiator.ForceDfu = ForceDfu.Value; + + // ConnectionTimeout + if (ConnectionTimeout.HasValue) + Initiator.ConnectionTimeout = ConnectionTimeout.Value; + + Initiator = CustomDfuServiceInitiatorConfiguration?.Invoke(Initiator); + + // public DFUUuidHelper UuidHelper {get; set;} + } + + public Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator Initiator { get; private set; } + + public Laerdal.Dfu.Bindings.iOS.DFUServiceController Controller { get; private set; } + + public Laerdal.Dfu.Bindings.iOS.DFUFirmware Firmware { get; private set;} + + private DfuProgressDelegate DfuProgressDelegate { get; set;} + + private DfuServiceDelegate DfuServiceDelegate { get; set;} + + private DfuPeripheralSelectorDelegate DfuPeripheralSelectorDelegate { get; set;} + + public DfuInstallation(string deviceId, string fileUrl) : base(deviceId, fileUrl) + { + } + + public DfuInstallation() : base() + { + } + + public override void Start() + { + if (Controller != null) + { + throw new System.Exception("Controller is already set."); + } + SetInitiator(); + Controller = Initiator.StartWithTargetWithIdentifier(new NSUuid(DeviceId)); + } + + public override void Pause() + { + Controller?.Pause(); + } + + public override void Resume() + { + Controller?.Resume(); + } + + public override void Abort() + { + Controller?.Abort(); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + Initiator?.Dispose(); + Controller?.Dispose(); + Firmware?.Dispose(); + } + } + } } \ No newline at end of file diff --git a/Laerdal.Dfu/Platforms/iOS/Specific/DfuLogger.cs b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuLogger.cs similarity index 96% rename from Laerdal.Dfu/Platforms/iOS/Specific/DfuLogger.cs rename to Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuLogger.cs index 91e8216..592f446 100644 --- a/Laerdal.Dfu/Platforms/iOS/Specific/DfuLogger.cs +++ b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuLogger.cs @@ -1,11 +1,11 @@ -namespace Laerdal.Dfu.Specific -{ - public class DfuLogger : Laerdal.Dfu.Bindings.iOS.LoggerDelegate - { - public override void Message(Laerdal.Dfu.Bindings.iOS.LogLevel level, string message) - { - Events.OnDfuMessageReceived((Laerdal.Dfu.Enums.DfuLogLevel) level, message); - } - } - +namespace Laerdal.Dfu.Specific +{ + public class DfuLogger : Laerdal.Dfu.Bindings.iOS.LoggerDelegate + { + public override void Message(Laerdal.Dfu.Bindings.iOS.LogLevel level, string message) + { + Events.OnDfuMessageReceived((Laerdal.Dfu.Enums.DfuLogLevel) level, message); + } + } + } \ No newline at end of file diff --git a/Laerdal.Dfu/Platforms/iOS/Specific/DfuPeripheralSelectorDelegate.cs b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuPeripheralSelectorDelegate.cs similarity index 97% rename from Laerdal.Dfu/Platforms/iOS/Specific/DfuPeripheralSelectorDelegate.cs rename to Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuPeripheralSelectorDelegate.cs index 20041ea..57c00ca 100644 --- a/Laerdal.Dfu/Platforms/iOS/Specific/DfuPeripheralSelectorDelegate.cs +++ b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuPeripheralSelectorDelegate.cs @@ -1,23 +1,23 @@ -using CoreBluetooth; -using Foundation; - -namespace Laerdal.Dfu.Specific -{ - public class DfuPeripheralSelectorDelegate : Laerdal.Dfu.Bindings.iOS.IDFUPeripheralSelectorDelegate - { - private DfuInstallation DfuInstallation { get; } - - public DfuPeripheralSelectorDelegate(DfuInstallation dfuInstallation) - { - DfuInstallation = dfuInstallation; - } - - public override bool Select(CBPeripheral peripheral, - NSDictionary advertisementData, - NSNumber rssi, - string name) - { - return DfuInstallation.DeviceId == peripheral.Identifier.ToString(); - } - } +using CoreBluetooth; +using Foundation; + +namespace Laerdal.Dfu.Specific +{ + public class DfuPeripheralSelectorDelegate : Laerdal.Dfu.Bindings.iOS.IDFUPeripheralSelectorDelegate + { + private DfuInstallation DfuInstallation { get; } + + public DfuPeripheralSelectorDelegate(DfuInstallation dfuInstallation) + { + DfuInstallation = dfuInstallation; + } + + public override bool Select(CBPeripheral peripheral, + NSDictionary advertisementData, + NSNumber rssi, + string name) + { + return DfuInstallation.DeviceId == peripheral.Identifier.ToString(); + } + } } \ No newline at end of file diff --git a/Laerdal.Dfu/Platforms/iOS/Specific/DfuProgressDelegate.cs b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuProgressDelegate.cs similarity index 97% rename from Laerdal.Dfu/Platforms/iOS/Specific/DfuProgressDelegate.cs rename to Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuProgressDelegate.cs index 4d23049..be10675 100644 --- a/Laerdal.Dfu/Platforms/iOS/Specific/DfuProgressDelegate.cs +++ b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuProgressDelegate.cs @@ -1,23 +1,23 @@ -using System; - -namespace Laerdal.Dfu.Specific -{ - public class DfuProgressDelegate : Laerdal.Dfu.Bindings.iOS.DFUProgressDelegate - { - private DfuInstallation DfuInstallation { get; } - - public DfuProgressDelegate(DfuInstallation dfuInstallation) - { - DfuInstallation = dfuInstallation; - } - - public override void OutOf(nint part, - nint totalParts, - nint progress, - double currentSpeedBytesPerSecond, - double avgSpeedBytesPerSecond) - { - DfuInstallation?.OnProgressChanged((int) progress / 100D, currentSpeedBytesPerSecond, avgSpeedBytesPerSecond); - } - } +using System; + +namespace Laerdal.Dfu.Specific +{ + public class DfuProgressDelegate : Laerdal.Dfu.Bindings.iOS.DFUProgressDelegate + { + private DfuInstallation DfuInstallation { get; } + + public DfuProgressDelegate(DfuInstallation dfuInstallation) + { + DfuInstallation = dfuInstallation; + } + + public override void OutOf(nint part, + nint totalParts, + nint progress, + double currentSpeedBytesPerSecond, + double avgSpeedBytesPerSecond) + { + DfuInstallation?.OnProgressChanged((int) progress / 100D, currentSpeedBytesPerSecond, avgSpeedBytesPerSecond); + } + } } \ No newline at end of file diff --git a/Laerdal.Dfu/Platforms/iOS/Specific/DfuServiceDelegate.cs b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuServiceDelegate.cs similarity index 97% rename from Laerdal.Dfu/Platforms/iOS/Specific/DfuServiceDelegate.cs rename to Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuServiceDelegate.cs index 109443d..e18e1d8 100644 --- a/Laerdal.Dfu/Platforms/iOS/Specific/DfuServiceDelegate.cs +++ b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/Specific/DfuServiceDelegate.cs @@ -1,22 +1,22 @@ -namespace Laerdal.Dfu.Specific -{ - public class DfuServiceDelegate : Laerdal.Dfu.Bindings.iOS.DFUServiceDelegate - { - private DfuInstallation DfuInstallation { get; } - - public DfuServiceDelegate(DfuInstallation dfuInstallation) - { - DfuInstallation = dfuInstallation; - } - - public override void DfuError(Laerdal.Dfu.Bindings.iOS.DFUError error, string message) - { - DfuInstallation?.OnDfuError((Laerdal.Dfu.Enums.DfuError) (long) error, message); - } - - public override void DfuStateDidChangeTo(Laerdal.Dfu.Bindings.iOS.DFUState state) - { - DfuInstallation.State = (Laerdal.Dfu.Enums.DfuState) (long) state; - } - } +namespace Laerdal.Dfu.Specific +{ + public class DfuServiceDelegate : Laerdal.Dfu.Bindings.iOS.DFUServiceDelegate + { + private DfuInstallation DfuInstallation { get; } + + public DfuServiceDelegate(DfuInstallation dfuInstallation) + { + DfuInstallation = dfuInstallation; + } + + public override void DfuError(Laerdal.Dfu.Bindings.iOS.DFUError error, string message) + { + DfuInstallation?.OnDfuError((Laerdal.Dfu.Enums.DfuError) (long) error, message); + } + + public override void DfuStateDidChangeTo(Laerdal.Dfu.Bindings.iOS.DFUState state) + { + DfuInstallation.State = (Laerdal.Dfu.Enums.DfuState) (long) state; + } + } } \ No newline at end of file diff --git a/Laerdal.Scripts/Laerdal.GenerateSignAndUploadSbom.sh b/Laerdal.Scripts/Laerdal.GenerateSignAndUploadSbom.sh old mode 100755 new mode 100644 index 6fd1b6c..d9a3b18 --- a/Laerdal.Scripts/Laerdal.GenerateSignAndUploadSbom.sh +++ b/Laerdal.Scripts/Laerdal.GenerateSignAndUploadSbom.sh @@ -17,7 +17,6 @@ declare sbom_signing_key_file_path="" declare dependency_tracker_url="" declare dependency_tracker_api_key_file_path="" - function parse_arguments() { while [[ $# -gt 0 ]]; do @@ -197,9 +196,10 @@ function install_tools() { function generate_sign_and_upload_sbom() { # set -x - # GENERATE SBOM + # GENERATE SBOM we intentionally disable package restore because the packages are already restored at this point dotnet-CycloneDX "${csproj_file_path}" \ --exclude-dev \ + --disable-package-restore \ --include-project-references \ \ --output "${output_directory_path}" \ diff --git a/Laerdal.Scripts/Laerdal.SetupBuildEnvironment.sh b/Laerdal.Scripts/Laerdal.SetupBuildEnvironment.sh index a4c4697..fa08d34 100755 --- a/Laerdal.Scripts/Laerdal.SetupBuildEnvironment.sh +++ b/Laerdal.Scripts/Laerdal.SetupBuildEnvironment.sh @@ -76,8 +76,10 @@ dotnet \ maui \ ios \ android \ + maccatalyst \ maui-ios \ - maui-android --version "${DOTNET_TARGET_WORKLOAD_VERSION}" + maui-android \ + maui-maccatalyst --version "${DOTNET_TARGET_WORKLOAD_VERSION}" declare exitCode=$? if [ $exitCode != 0 ]; then echo "##vso[task.logissue type=error]Failed to restore dotnet workloads." From 8d9751db03c37953554578b35abe91bad4598d48 Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Tue, 12 Nov 2024 18:31:36 +0100 Subject: [PATCH 2/8] clean (Laerdal.Dfu.csproj): trivial neutral consolidation of nugets --- Laerdal.Dfu/Laerdal.Dfu.csproj | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Laerdal.Dfu/Laerdal.Dfu.csproj b/Laerdal.Dfu/Laerdal.Dfu.csproj index 032c7a2..a818a8a 100644 --- a/Laerdal.Dfu/Laerdal.Dfu.csproj +++ b/Laerdal.Dfu/Laerdal.Dfu.csproj @@ -46,25 +46,25 @@ 17.0 13.1 - 13.1 + 13.1 - + - + - - + + @@ -97,12 +97,11 @@ - + - - + From 96e3f5866b9a8441de182674e0bb7ddcd68d7425 Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Tue, 12 Nov 2024 18:45:40 +0100 Subject: [PATCH 3/8] upgrade (Laerdal.Dfu.csproj): upgrade Laerdal.Dfu.Bindings.iOS nuget to 4.15.3.43972 --- Laerdal.Dfu/Laerdal.Dfu.csproj | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Laerdal.Dfu/Laerdal.Dfu.csproj b/Laerdal.Dfu/Laerdal.Dfu.csproj index a818a8a..6a8becf 100644 --- a/Laerdal.Dfu/Laerdal.Dfu.csproj +++ b/Laerdal.Dfu/Laerdal.Dfu.csproj @@ -96,12 +96,16 @@ - + - - - + + + + + + + From 96b2b6f8dd3fe6c782fa7cc2ea24542776a70924 Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Wed, 13 Nov 2024 19:32:40 +0100 Subject: [PATCH 4/8] feat (DfuInstallation.cs): all methods throw NotImplemented exceptions now --- Laerdal.Dfu/Laerdal.Dfu.csproj | 2 +- Laerdal.Dfu/Platforms.NetX/DfuInstallation.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Laerdal.Dfu/Laerdal.Dfu.csproj b/Laerdal.Dfu/Laerdal.Dfu.csproj index 6a8becf..eddb185 100644 --- a/Laerdal.Dfu/Laerdal.Dfu.csproj +++ b/Laerdal.Dfu/Laerdal.Dfu.csproj @@ -46,7 +46,7 @@ 17.0 13.1 - 13.1 + 13.1 diff --git a/Laerdal.Dfu/Platforms.NetX/DfuInstallation.cs b/Laerdal.Dfu/Platforms.NetX/DfuInstallation.cs index 63f107e..c1be179 100644 --- a/Laerdal.Dfu/Platforms.NetX/DfuInstallation.cs +++ b/Laerdal.Dfu/Platforms.NetX/DfuInstallation.cs @@ -8,30 +8,37 @@ public partial class DfuInstallation { public DfuInstallation(string deviceId, string fileUrl) : base(deviceId, fileUrl) { + throw new NotImplementedException(); } public DfuInstallation() : base() { + throw new NotImplementedException(); } - + public override void Start() { + throw new NotImplementedException(); } public override void Pause() { + throw new NotImplementedException(); } public override void Resume() { + throw new NotImplementedException(); } public override void Abort() { + throw new NotImplementedException(); } protected override void Dispose(bool disposing) { + throw new NotImplementedException(); } } } \ No newline at end of file From 6b449ef57a582017c3289b28e82d75ec9c95c48b Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Wed, 13 Nov 2024 19:48:55 +0100 Subject: [PATCH 5/8] feat (Laerdal.targets): print more properties in PrintBuildInfo for the sake of debugging --- Laerdal.Dfu/Laerdal.targets | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Laerdal.Dfu/Laerdal.targets b/Laerdal.Dfu/Laerdal.targets index 72ccb0c..ef8911b 100644 --- a/Laerdal.Dfu/Laerdal.targets +++ b/Laerdal.Dfu/Laerdal.targets @@ -76,16 +76,23 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + + From bf130271d9bcd417c6cdc48eefd07ae8fd2ca4d6 Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Wed, 13 Nov 2024 19:49:20 +0100 Subject: [PATCH 6/8] feat (Laerdal.Dfu.csproj): simplify the way we include/exclude folders for each target-framework --- Laerdal.Dfu/Laerdal.Dfu.csproj | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Laerdal.Dfu/Laerdal.Dfu.csproj b/Laerdal.Dfu/Laerdal.Dfu.csproj index eddb185..25a0ec6 100644 --- a/Laerdal.Dfu/Laerdal.Dfu.csproj +++ b/Laerdal.Dfu/Laerdal.Dfu.csproj @@ -49,22 +49,22 @@ 13.1 - + - - + + - - + + - - + + From c61d446485c30e6d7fd4caa2c40a5555e95b3a4d Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Wed, 13 Nov 2024 19:55:08 +0100 Subject: [PATCH 7/8] fix (Laerdal.Dfu.csproj): fix a bug which was causing the generated maccatalyst nuget to target an sdk version other than 17.0 which is the desired one --- Laerdal.Dfu/Laerdal.Dfu.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Laerdal.Dfu/Laerdal.Dfu.csproj b/Laerdal.Dfu/Laerdal.Dfu.csproj index 25a0ec6..def5edf 100644 --- a/Laerdal.Dfu/Laerdal.Dfu.csproj +++ b/Laerdal.Dfu/Laerdal.Dfu.csproj @@ -44,9 +44,9 @@ 14.2 - 17.0 - 13.1 - 13.1 + 17.0 + 13.1 + 13.1 From 8dd029b291b2e6abdae05347bec7bf3cb7107d7d Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Wed, 13 Nov 2024 20:31:54 +0100 Subject: [PATCH 8/8] clean (DfuInstallation.cs): trivial neutral reindentation --- .../DfuInstallation.cs | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs index f81820d..56518d1 100644 --- a/Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs +++ b/Laerdal.Dfu/Platforms.iOSandMacCatalyst/DfuInstallation.cs @@ -1,7 +1,5 @@ using CoreFoundation; - using Foundation; - using Laerdal.Dfu.Specific; namespace Laerdal.Dfu @@ -14,7 +12,7 @@ public partial class DfuInstallation public static Func LoggerQueue { get; set; } = () => DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default); public Func CustomDfuServiceInitiatorConfiguration { get; set; } = (dfuInitiator) => dfuInitiator; - + private void SetInitiator() { DfuProgressDelegate = new DfuProgressDelegate(this); @@ -22,12 +20,14 @@ private void SetInitiator() DfuPeripheralSelectorDelegate = new DfuPeripheralSelectorDelegate(this); Firmware = new Laerdal.Dfu.Bindings.iOS.DFUFirmware(new NSUrl(FileUrl, false), out NSError error); - - Initiator = new Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator(Queue.Invoke(), - DelegateQueue.Invoke(), - ProgressQueue.Invoke(), - LoggerQueue.Invoke(), - null) + + Initiator = new Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator( + queue: Queue.Invoke(), + loggerQueue: LoggerQueue.Invoke(), + delegateQueue: DelegateQueue.Invoke(), + progressQueue: ProgressQueue.Invoke(), + centralManagerOptions: null + ) { Logger = new DfuLogger(), WeakProgressDelegate = DfuProgressDelegate, @@ -38,7 +38,7 @@ private void SetInitiator() // PacketsReceiptNotifications if (PacketReceiptNotificationParameter.HasValue) Initiator.PacketReceiptNotificationParameter = PacketReceiptNotificationParameter.Value; - + // DataObjectPreparationDelay if (DataObjectPreparationDelay.HasValue) Initiator.DataObjectPreparationDelay = DataObjectPreparationDelay.Value; @@ -50,15 +50,15 @@ private void SetInitiator() // AlternativeAdvertisingName Initiator.AlternativeAdvertisingNameEnabled = !string.IsNullOrEmpty(AlternativeAdvertisingName); Initiator.AlternativeAdvertisingName = AlternativeAdvertisingName; - + // ForceScanningForNewAddressInLegacyDfu if (ForceScanningForNewAddressInLegacyDfu.HasValue) Initiator.ForceScanningForNewAddressInLegacyDfu = ForceScanningForNewAddressInLegacyDfu.Value; - + // EnableUnsafeExperimentalButtonlessServiceInSecureDfu if (EnableUnsafeExperimentalButtonlessServiceInSecureDfu.HasValue) Initiator.ForceScanningForNewAddressInLegacyDfu = EnableUnsafeExperimentalButtonlessServiceInSecureDfu.Value; - + // ForceDfu if (ForceDfu.HasValue) Initiator.ForceDfu = ForceDfu.Value; @@ -72,18 +72,18 @@ private void SetInitiator() // public DFUUuidHelper UuidHelper {get; set;} } - public Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator Initiator { get; private set; } + public Laerdal.Dfu.Bindings.iOS.DFUServiceInitiator Initiator { get; private set; } public Laerdal.Dfu.Bindings.iOS.DFUServiceController Controller { get; private set; } - public Laerdal.Dfu.Bindings.iOS.DFUFirmware Firmware { get; private set;} - - private DfuProgressDelegate DfuProgressDelegate { get; set;} + public Laerdal.Dfu.Bindings.iOS.DFUFirmware Firmware { get; private set; } + + private DfuProgressDelegate DfuProgressDelegate { get; set; } - private DfuServiceDelegate DfuServiceDelegate { get; set;} + private DfuServiceDelegate DfuServiceDelegate { get; set; } + + private DfuPeripheralSelectorDelegate DfuPeripheralSelectorDelegate { get; set; } - private DfuPeripheralSelectorDelegate DfuPeripheralSelectorDelegate { get; set;} - public DfuInstallation(string deviceId, string fileUrl) : base(deviceId, fileUrl) { } @@ -98,6 +98,7 @@ public override void Start() { throw new System.Exception("Controller is already set."); } + SetInitiator(); Controller = Initiator.StartWithTargetWithIdentifier(new NSUuid(DeviceId)); }