From f87314d983d0a1269bea111186b654c4cb4440db Mon Sep 17 00:00:00 2001 From: Lukas Kurz Date: Fri, 17 Nov 2023 16:56:06 +0100 Subject: [PATCH] `net8.0` --- .github/workflows/codeql.yml | 2 +- .github/workflows/test.yml | 2 +- Nearby Sharing Windows/FileUtils.cs | 2 +- .../Layout/BottomSheetBehaviorCallback.cs | 26 ++++++-------- Nearby Sharing Windows/MainActivity.cs | 2 +- .../Nearby Sharing Windows.csproj | 10 +++--- .../QuickSettings/ReceiveTileService.cs | 2 +- Nearby Sharing Windows/SendActivity.cs | 14 ++++---- Nearby Sharing Windows/UIHelper.cs | 34 +++++++++++-------- ...icrosoft.ConnectedDevices.NearShare.csproj | 2 +- .../CdpSession.cs | 9 ++--- .../ConnectedDevicesPlatform.cs | 2 +- .../Encryption/CdpCryptor.cs | 2 +- .../Encryption/CdpEncryptionParams.cs | 4 +-- .../Encryption/CdpNonce.cs | 7 +--- .../Exceptions/CdpException.cs | 3 +- .../Exceptions/CdpProtocolException.cs | 3 +- .../Exceptions/CdpSecurityException.cs | 3 +- .../Exceptions/CdpSessionException.cs | 3 +- .../Extensions.cs | 2 +- .../Internal/ConcurrentList.cs | 2 +- .../Internal/UpgradeHandler.cs | 24 ++++++------- .../Messages/CommonHeaders.cs | 4 +-- .../TransportUpgrade/EndpointMetadata.cs | 5 ++- .../AppControl/LaunchUriForTargetRequest.cs | 2 +- ...ShortDev.Microsoft.ConnectedDevices.csproj | 2 +- ShortDev.Networking/EndianBuffer.cs | 2 ++ .../ShortDev.Networking.csproj | 2 +- Test/Test.csproj | 2 +- global.json | 6 ---- lib/ShortDev.Android | 2 +- lib/ShortDev.Android.Preferences | 2 +- .../SerializationTest.cs | 9 ++--- ...Dev.Microsoft.ConnectedDevices.Test.csproj | 2 +- .../TestValueGenerator.cs | 2 +- 35 files changed, 89 insertions(+), 113 deletions(-) delete mode 100644 global.json diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index ab67c51..96fd887 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -43,7 +43,7 @@ jobs: - name: Setup .NET Core SDK uses: actions/setup-dotnet@v3 with: - dotnet-version: '7.0.x' + dotnet-version: '8.0.x' include-prerelease: true - name: Install Workloads diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 366b1da..a0c2724 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: - name: Setup .NET Core SDK uses: actions/setup-dotnet@v3 with: - dotnet-version: '7.0.x' + dotnet-version: '8.0.x' include-prerelease: true - name: Test diff --git a/Nearby Sharing Windows/FileUtils.cs b/Nearby Sharing Windows/FileUtils.cs index 6c9283d..03dac70 100644 --- a/Nearby Sharing Windows/FileUtils.cs +++ b/Nearby Sharing Windows/FileUtils.cs @@ -19,7 +19,7 @@ public static CdpFileProvider CreateNearShareFileFromContentUri(this ContentReso public static string QueryContentName(this ContentResolver resolver, AndroidUri contentUri) { - using var returnCursor = resolver.Query(contentUri, new[] { IOpenableColumns.DisplayName }, null, null, null) ?? throw new InvalidOperationException("Could not open content cursor"); + using var returnCursor = resolver.Query(contentUri, [IOpenableColumns.DisplayName], null, null, null) ?? throw new InvalidOperationException("Could not open content cursor"); returnCursor.MoveToFirst(); return returnCursor.GetString(0) ?? throw new IOException("Could not query content name"); } diff --git a/Nearby Sharing Windows/Layout/BottomSheetBehaviorCallback.cs b/Nearby Sharing Windows/Layout/BottomSheetBehaviorCallback.cs index e17a324..1ca5989 100644 --- a/Nearby Sharing Windows/Layout/BottomSheetBehaviorCallback.cs +++ b/Nearby Sharing Windows/Layout/BottomSheetBehaviorCallback.cs @@ -1,23 +1,17 @@ -using Android.App; -using Android.Views; +using Android.Views; using Google.Android.Material.BottomSheet; -namespace Nearby_Sharing_Windows.Layout +namespace Nearby_Sharing_Windows.Layout; + +public class BottomSheetBehaviorCallback(Activity activity) : BottomSheetBehavior.BottomSheetCallback { - public class BottomSheetBehaviorCallback : BottomSheetBehavior.BottomSheetCallback - { - public Activity Activity { get; private set; } - public BottomSheetBehaviorCallback(Activity activity) - { - this.Activity = activity; - } + public Activity Activity { get; private set; } = activity; - public override void OnSlide(View bottomSheet, float newState) { } + public override void OnSlide(View bottomSheet, float newState) { } - public override void OnStateChanged(View p0, int p1) - { - if (p1 == BottomSheetBehavior.StateHidden) - Activity.Finish(); - } + public override void OnStateChanged(View p0, int p1) + { + if (p1 == BottomSheetBehavior.StateHidden) + Activity.Finish(); } } \ No newline at end of file diff --git a/Nearby Sharing Windows/MainActivity.cs b/Nearby Sharing Windows/MainActivity.cs index 3e27ac8..71761f6 100644 --- a/Nearby Sharing Windows/MainActivity.cs +++ b/Nearby Sharing Windows/MainActivity.cs @@ -73,7 +73,7 @@ protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result { intent.SetAction(Intent.ActionSendMultiple); - List uriList = new(); + List uriList = []; for (int i = 0; i < clipData.ItemCount; i++) { var item = clipData.GetItemAt(i); diff --git a/Nearby Sharing Windows/Nearby Sharing Windows.csproj b/Nearby Sharing Windows/Nearby Sharing Windows.csproj index f47410b..2379767 100644 --- a/Nearby Sharing Windows/Nearby Sharing Windows.csproj +++ b/Nearby Sharing Windows/Nearby Sharing Windows.csproj @@ -1,6 +1,6 @@  - net7.0-android33.0 + net8.0-android34.0 Exe 21 preview @@ -18,11 +18,11 @@ aab - + - - - + + + diff --git a/Nearby Sharing Windows/QuickSettings/ReceiveTileService.cs b/Nearby Sharing Windows/QuickSettings/ReceiveTileService.cs index ecafd97..e4888be 100644 --- a/Nearby Sharing Windows/QuickSettings/ReceiveTileService.cs +++ b/Nearby Sharing Windows/QuickSettings/ReceiveTileService.cs @@ -3,7 +3,7 @@ namespace Nearby_Sharing_Windows.QuickSettings; -[IntentFilter(new[] { ActionQsTile })] +[IntentFilter([ActionQsTile])] [Service(Label = "Receive", Exported = true, Icon = "@drawable/quick_settings_tile_icon", Permission = "android.permission.BIND_QUICK_SETTINGS_TILE")] // [MetaData(MetaDataActiveTile, Value = "true")] public sealed class ReceiveTileService : TileService diff --git a/Nearby Sharing Windows/SendActivity.cs b/Nearby Sharing Windows/SendActivity.cs index 69402b4..12ca14b 100644 --- a/Nearby Sharing Windows/SendActivity.cs +++ b/Nearby Sharing Windows/SendActivity.cs @@ -20,9 +20,9 @@ namespace Nearby_Sharing_Windows; -[IntentFilter(new[] { Intent.ActionProcessText }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataMimeType = "text/plain", Label = "@string/share_text")] -[IntentFilter(new[] { Intent.ActionSend, Intent.ActionSendMultiple }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataMimeType = "*/*", Label = "@string/share_file")] -[IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataMimeType = "text/plain", Label = "@string/share_url")] +[IntentFilter([Intent.ActionProcessText], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "text/plain", Label = "@string/share_text")] +[IntentFilter([Intent.ActionSend, Intent.ActionSendMultiple], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "*/*", Label = "@string/share_file")] +[IntentFilter([Intent.ActionSend], Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable], DataMimeType = "text/plain", Label = "@string/share_url")] [Activity(Label = "@string/app_name", Exported = true, Theme = "@style/AppTheme.TranslucentOverlay", ConfigurationChanges = UIHelper.ConfigChangesFlags)] public sealed class SendActivity : AppCompatActivity, View.IOnApplyWindowInsetsListener { @@ -67,8 +67,8 @@ protected override void OnCreate(Bundle? savedInstanceState) (int)WindowInsetsControllerAppearance.LightNavigationBars, (int)WindowInsetsControllerAppearance.LightNavigationBars ); - else - Window!.DecorView.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.LightNavigationBar; + else if (OperatingSystem.IsAndroidVersionAtLeast(26)) + Window!.DecorView.SystemUiFlags = SystemUiFlags.LightNavigationBar; Window!.DecorView.SetOnApplyWindowInsetsListener(this); cancelButton.Click += CancelButton_Click; @@ -148,7 +148,7 @@ void InitializePlatform() NearShareSender = new NearShareSender(Platform); } - readonly List RemoteSystems = new(); + readonly List RemoteSystems = []; private void Platform_DeviceDiscovered(ICdpTransport sender, CdpDevice device, BLeBeacon advertisement) { if (!RemoteSystems.Contains(device)) @@ -266,7 +266,7 @@ private async void SendData(CdpDevice remoteSystem) { ArgumentNullException.ThrowIfNull(Intent); - if (Intent.Action == Intent.ActionProcessText) + if (Intent.Action == Intent.ActionProcessText && OperatingSystem.IsAndroidVersionAtLeast(23)) { return ( files: new[] { SendText(Intent.GetStringExtra(Intent.ExtraProcessText)) }, diff --git a/Nearby Sharing Windows/UIHelper.cs b/Nearby Sharing Windows/UIHelper.cs index 66a66b2..e70f890 100644 --- a/Nearby Sharing Windows/UIHelper.cs +++ b/Nearby Sharing Windows/UIHelper.cs @@ -7,6 +7,7 @@ using AndroidX.Core.App; using Google.Android.Material.Dialog; using Nearby_Sharing_Windows.Settings; +using System.Runtime.Versioning; using CompatToolbar = AndroidX.AppCompat.Widget.Toolbar; namespace Nearby_Sharing_Windows; @@ -103,16 +104,22 @@ public static void SetupToolBar(AppCompatActivity activity, string? subtitle = n } #region Permissions - private static readonly string[] _sendPermissions = new[] - { + private static readonly string[] _sendPermissions = [ ManifestPermission.AccessFineLocation, - ManifestPermission.AccessCoarseLocation, - // Api level 31 + ManifestPermission.AccessCoarseLocation + ]; + [SupportedOSPlatform("android31.0")] + private static readonly string[] _sendPermissionsApi31 = [ + .. _sendPermissions, ManifestPermission.BluetoothScan, ManifestPermission.BluetoothConnect - }; + ]; public static void RequestSendPermissions(Activity activity) - => ActivityCompat.RequestPermissions(activity, _sendPermissions, 0); + => ActivityCompat.RequestPermissions( + activity, + OperatingSystem.IsAndroidVersionAtLeast(31) ? _sendPermissionsApi31 : _sendPermissions, + 0 + ); private static readonly string[] _receivePermissions = [ ManifestPermission.AccessFineLocation, @@ -123,6 +130,7 @@ public static void RequestSendPermissions(Activity activity) ManifestPermission.ReadExternalStorage, ManifestPermission.WriteExternalStorage ]; + [SupportedOSPlatform("android31.0")] private static readonly string[] _receivePermissionsApi31 = [ .. _receivePermissions, ManifestPermission.BluetoothScan, @@ -130,15 +138,11 @@ public static void RequestSendPermissions(Activity activity) ManifestPermission.BluetoothAdvertise, ]; public static void RequestReceivePermissions(Activity activity) - { - if (OperatingSystem.IsAndroidVersionAtLeast(31)) - { - ActivityCompat.RequestPermissions(activity, _receivePermissionsApi31, 0); - return; - } - - ActivityCompat.RequestPermissions(activity, _receivePermissions, 0); - } + => ActivityCompat.RequestPermissions( + activity, + OperatingSystem.IsAndroidVersionAtLeast(31) ? _receivePermissionsApi31 : _receivePermissions, + 0 + ); #endregion public static ISpanned LoadHtmlAsset(Activity activity, string assetPath) diff --git a/ShortDev.Microsoft.ConnectedDevices.NearShare/ShortDev.Microsoft.ConnectedDevices.NearShare.csproj b/ShortDev.Microsoft.ConnectedDevices.NearShare/ShortDev.Microsoft.ConnectedDevices.NearShare.csproj index 0476923..bc35d98 100644 --- a/ShortDev.Microsoft.ConnectedDevices.NearShare/ShortDev.Microsoft.ConnectedDevices.NearShare.csproj +++ b/ShortDev.Microsoft.ConnectedDevices.NearShare/ShortDev.Microsoft.ConnectedDevices.NearShare.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 preview enable enable diff --git a/ShortDev.Microsoft.ConnectedDevices/CdpSession.cs b/ShortDev.Microsoft.ConnectedDevices/CdpSession.cs index 002b5fc..66d7742 100644 --- a/ShortDev.Microsoft.ConnectedDevices/CdpSession.cs +++ b/ShortDev.Microsoft.ConnectedDevices/CdpSession.cs @@ -48,7 +48,7 @@ private CdpSession(ConnectedDevicesPlatform platform, CdpDevice device, SessionI } #region Registration - static readonly AutoKeyRegistry _sessionRegistry = new(); + static readonly AutoKeyRegistry _sessionRegistry = []; internal static CdpSession GetOrCreate(ConnectedDevicesPlatform platform, CdpDevice device, CommonHeader header) { ArgumentNullException.ThrowIfNull(device); @@ -635,7 +635,7 @@ CdpMessage GetOrCreateMessage(CommonHeader header) #endregion #region Channels - readonly AutoKeyRegistry _channelRegistry = new(); + readonly AutoKeyRegistry _channelRegistry = []; public async Task StartClientChannelAsync(string appId, string appName, CdpAppBase handler, CancellationToken cancellationToken = default) { @@ -700,10 +700,7 @@ internal void ThrowIfWrongMode(bool shouldBeHost) public bool IsDisposed { get; private set; } = false; private void ThrowIfDisposed() - { - if (IsDisposed) - throw new ObjectDisposedException(nameof(CdpSession)); - } + => ObjectDisposedException.ThrowIf(IsDisposed, this); public void Dispose() { diff --git a/ShortDev.Microsoft.ConnectedDevices/ConnectedDevicesPlatform.cs b/ShortDev.Microsoft.ConnectedDevices/ConnectedDevicesPlatform.cs index 5b70786..0793a71 100644 --- a/ShortDev.Microsoft.ConnectedDevices/ConnectedDevicesPlatform.cs +++ b/ShortDev.Microsoft.ConnectedDevices/ConnectedDevicesPlatform.cs @@ -248,7 +248,7 @@ bool TryGetKnownSocket(EndpointInfo endpoint, [MaybeNullWhen(false)] out CdpSock public CdpDeviceInfo GetCdpDeviceInfo() { - List endpoints = new(); + List endpoints = []; foreach (var (_, transport) in _transports) { try diff --git a/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpCryptor.cs b/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpCryptor.cs index 1ccb1ee..d6d4620 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpCryptor.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpCryptor.cs @@ -136,7 +136,7 @@ public void Read(ref EndianReader reader, CommonHeader header) var encryptedPayload = reader.ReadBytes(payloadSize); - scoped Span hmac = Span.Empty; + scoped Span hmac = []; if (header.HasFlag(MessageFlags.HasHMAC)) { hmac = stackalloc byte[Constants.HMacSize]; diff --git a/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpEncryptionParams.cs b/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpEncryptionParams.cs index 6206191..8c11856 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpEncryptionParams.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpEncryptionParams.cs @@ -6,8 +6,8 @@ namespace ShortDev.Microsoft.ConnectedDevices.Encryption; public sealed class CdpEncryptionParams { - public static readonly byte[] SecretPrepend = new byte[] { 0x0D6, 0x37, 0x0F1, 0x0AA, 0x0E2, 0x0F0, 0x41, 0x8C }; - public static readonly byte[] SecretAppend = new byte[] { 0x0A8, 0x0F8, 0x1A, 0x57, 0x4E, 0x22, 0x8A, 0x0B7 }; + public static readonly byte[] SecretPrepend = [0x0D6, 0x37, 0x0F1, 0x0AA, 0x0E2, 0x0F0, 0x41, 0x8C]; + public static readonly byte[] SecretAppend = [0x0A8, 0x0F8, 0x1A, 0x57, 0x4E, 0x22, 0x8A, 0x0B7]; public static CdpEncryptionParams Default { get; } = new(); public static CdpEncryptionParams FromCurveType(CurveType curveType) diff --git a/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpNonce.cs b/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpNonce.cs index 66169ea..d029934 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpNonce.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Encryption/CdpNonce.cs @@ -3,16 +3,11 @@ namespace ShortDev.Microsoft.ConnectedDevices.Encryption; -public readonly struct CdpNonce +public readonly record struct CdpNonce(ulong Value) { - public readonly ulong Value; - public override string ToString() => Value.ToString(); - public CdpNonce(ulong value) - => Value = value; - public static unsafe CdpNonce Create() { using RandomNumberGenerator cryptographicRandom = RandomNumberGenerator.Create(); diff --git a/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpException.cs b/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpException.cs index 167e507..20c762d 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpException.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpException.cs @@ -2,7 +2,6 @@ namespace ShortDev.Microsoft.ConnectedDevices.Exceptions; -public class CdpException : Exception +public class CdpException(string msg) : Exception(msg) { - public CdpException(string msg) : base(msg) { } } diff --git a/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpProtocolException.cs b/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpProtocolException.cs index bdd4d89..f375e80 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpProtocolException.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpProtocolException.cs @@ -1,6 +1,5 @@ namespace ShortDev.Microsoft.ConnectedDevices.Exceptions; -public sealed class CdpProtocolException : CdpException +public sealed class CdpProtocolException(string msg) : CdpException(msg) { - public CdpProtocolException(string msg) : base(msg) { } } diff --git a/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpSecurityException.cs b/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpSecurityException.cs index 1545b91..0a0f6be 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpSecurityException.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpSecurityException.cs @@ -1,6 +1,5 @@ namespace ShortDev.Microsoft.ConnectedDevices.Exceptions; -public sealed class CdpSecurityException : CdpException +public sealed class CdpSecurityException(string msg) : CdpException(msg) { - public CdpSecurityException(string msg) : base(msg) { } } diff --git a/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpSessionException.cs b/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpSessionException.cs index a4846c3..2487f81 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpSessionException.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Exceptions/CdpSessionException.cs @@ -1,6 +1,5 @@ namespace ShortDev.Microsoft.ConnectedDevices.Exceptions; -public sealed class CdpSessionException : CdpException +public sealed class CdpSessionException(string msg) : CdpException(msg) { - public CdpSessionException(string msg) : base(msg) { } } diff --git a/ShortDev.Microsoft.ConnectedDevices/Extensions.cs b/ShortDev.Microsoft.ConnectedDevices/Extensions.cs index c95c06b..bfc9651 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Extensions.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Extensions.cs @@ -39,7 +39,7 @@ public static void DisposeAll(params IEnumerable[] disposables) public static void DisposeAll(this IEnumerable disposables) where T : IDisposable { - List exceptions = new(); + List exceptions = []; foreach (var disposable in disposables) { diff --git a/ShortDev.Microsoft.ConnectedDevices/Internal/ConcurrentList.cs b/ShortDev.Microsoft.ConnectedDevices/Internal/ConcurrentList.cs index 8f47be3..2f97cc6 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Internal/ConcurrentList.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Internal/ConcurrentList.cs @@ -4,7 +4,7 @@ namespace ShortDev.Microsoft.ConnectedDevices.Internal; internal sealed class ConcurrentList { - readonly List _data = new(); + readonly List _data = []; public void Add(T item) { diff --git a/ShortDev.Microsoft.ConnectedDevices/Internal/UpgradeHandler.cs b/ShortDev.Microsoft.ConnectedDevices/Internal/UpgradeHandler.cs index ba67ffe..8e40035 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Internal/UpgradeHandler.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Internal/UpgradeHandler.cs @@ -165,14 +165,14 @@ void HandleUpgradeRequest(CdpSocket socket, ref EndianReader reader) }.Write(writer); new UpgradeResponse() { - Endpoints = new[] - { + Endpoints = + [ EndpointInfo.FromTcp(localIp) - }, - MetaData = new[] - { + ], + MetaData = + [ EndpointMetadata.Tcp - } + ] }.Write(writer); }); } @@ -245,10 +245,10 @@ void SendUpgradeRequest(CdpSocket socket, Guid upgradeId) new UpgradeRequest() { UpgradeId = upgradeId, - Endpoints = new[] - { + Endpoints = + [ EndpointMetadata.Tcp - } + ] }.Write(writer); }); } @@ -295,10 +295,10 @@ async void FindNewEndpoint() ConnectionMode = ConnectionMode.Proximal, MessageType = ConnectionType.UpgradeFinalization }.Write(writer); - EndpointMetadata.WriteArray(writer, new[] - { + EndpointMetadata.WriteArray(writer, + [ EndpointMetadata.Tcp - }); + ]); }); // Cancel after timeout if upgrade has not finished yet diff --git a/ShortDev.Microsoft.ConnectedDevices/Messages/CommonHeaders.cs b/ShortDev.Microsoft.ConnectedDevices/Messages/CommonHeaders.cs index 3b9ec7f..33f69ba 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Messages/CommonHeaders.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Messages/CommonHeaders.cs @@ -50,7 +50,7 @@ public static bool TryParse(ref EndianReader reader, out CommonHeader? result, o AdditionalHeaderType nextHeaderType; byte nextHeaderSize; - List additionalHeaders = new(); + List additionalHeaders = []; while (true) { nextHeaderType = (AdditionalHeaderType)reader.ReadByte(); @@ -151,7 +151,7 @@ public void Write(EndianWriter writer) /// If an additional header record is included, this value indicates the type.
/// Some values are implementation-specific. /// - public List AdditionalHeaders { get; set; } = new(); + public List AdditionalHeaders { get; set; } = []; /// diff --git a/ShortDev.Microsoft.ConnectedDevices/Messages/Connection/TransportUpgrade/EndpointMetadata.cs b/ShortDev.Microsoft.ConnectedDevices/Messages/Connection/TransportUpgrade/EndpointMetadata.cs index 7a768d7..23e49fe 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Messages/Connection/TransportUpgrade/EndpointMetadata.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Messages/Connection/TransportUpgrade/EndpointMetadata.cs @@ -1,13 +1,12 @@ using ShortDev.Microsoft.ConnectedDevices.Transports; using ShortDev.Networking; -using System; namespace ShortDev.Microsoft.ConnectedDevices.Messages.Connection.TransportUpgrade; public record class EndpointMetadata(CdpTransportType Type, byte[] Data) : ICdpPayload, ICdpArraySerializable { - public static EndpointMetadata Tcp { get; } = new(CdpTransportType.Tcp, Array.Empty()); - public static EndpointMetadata WifiDirect { get; } = new(CdpTransportType.WifiDirect, Array.Empty()); + public static EndpointMetadata Tcp { get; } = new(CdpTransportType.Tcp, []); + public static EndpointMetadata WifiDirect { get; } = new(CdpTransportType.WifiDirect, []); public static EndpointMetadata Parse(ref EndianReader reader) { diff --git a/ShortDev.Microsoft.ConnectedDevices/Messages/Session/AppControl/LaunchUriForTargetRequest.cs b/ShortDev.Microsoft.ConnectedDevices/Messages/Session/AppControl/LaunchUriForTargetRequest.cs index 8988eef..2ea94ae 100644 --- a/ShortDev.Microsoft.ConnectedDevices/Messages/Session/AppControl/LaunchUriForTargetRequest.cs +++ b/ShortDev.Microsoft.ConnectedDevices/Messages/Session/AppControl/LaunchUriForTargetRequest.cs @@ -54,7 +54,7 @@ public static LaunchUriForTargetRequest Parse(ref EndianReader reader) /// BOND.NET serialized data that is passed as a value set to the app launched by the call.
/// (Optional) ///
- public byte[] InputData { get; init; } = Array.Empty(); + public byte[] InputData { get; init; } = []; public void Write(EndianWriter writer) { diff --git a/ShortDev.Microsoft.ConnectedDevices/ShortDev.Microsoft.ConnectedDevices.csproj b/ShortDev.Microsoft.ConnectedDevices/ShortDev.Microsoft.ConnectedDevices.csproj index 3cfa348..25c52ff 100644 --- a/ShortDev.Microsoft.ConnectedDevices/ShortDev.Microsoft.ConnectedDevices.csproj +++ b/ShortDev.Microsoft.ConnectedDevices/ShortDev.Microsoft.ConnectedDevices.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 preview enable Nullable diff --git a/ShortDev.Networking/EndianBuffer.cs b/ShortDev.Networking/EndianBuffer.cs index 7dd73c6..581c1ae 100644 --- a/ShortDev.Networking/EndianBuffer.cs +++ b/ShortDev.Networking/EndianBuffer.cs @@ -1,5 +1,6 @@ using System; using System.Buffers; +using System.Diagnostics.CodeAnalysis; namespace ShortDev.Networking; @@ -19,6 +20,7 @@ public EndianBuffer(byte[] data) _writer.Write(data); } + [SuppressMessage("Style", "IDE0302:Simplify collection initialization", Justification = "Seems like this allocates a new array instead of using stackalloc!")] public void Write(byte value) { Span buffer = stackalloc byte[1]; diff --git a/ShortDev.Networking/ShortDev.Networking.csproj b/ShortDev.Networking/ShortDev.Networking.csproj index bb8cd30..7642814 100644 --- a/ShortDev.Networking/ShortDev.Networking.csproj +++ b/ShortDev.Networking/ShortDev.Networking.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 latest enable true diff --git a/Test/Test.csproj b/Test/Test.csproj index 60b6ed1..723165b 100644 --- a/Test/Test.csproj +++ b/Test/Test.csproj @@ -2,7 +2,7 @@ Exe - net7.0-windows10.0.19041.0 + net8.0-windows10.0.19041.0 enable enable true diff --git a/global.json b/global.json deleted file mode 100644 index ece2da4..0000000 --- a/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "sdk": { - "version": "7.0.0", - "rollForward": "latestFeature" - } -} \ No newline at end of file diff --git a/lib/ShortDev.Android b/lib/ShortDev.Android index 36a07af..d686875 160000 --- a/lib/ShortDev.Android +++ b/lib/ShortDev.Android @@ -1 +1 @@ -Subproject commit 36a07af0d8370bb60b9959ba2721a27d4b1c6c38 +Subproject commit d686875244ec36e651aa6c847f3ca007f6f2263e diff --git a/lib/ShortDev.Android.Preferences b/lib/ShortDev.Android.Preferences index 5b707b3..aa61b18 160000 --- a/lib/ShortDev.Android.Preferences +++ b/lib/ShortDev.Android.Preferences @@ -1 +1 @@ -Subproject commit 5b707b3dcd4fb0005c801d336e390385175dfac1 +Subproject commit aa61b180b29827daa338a62b6279d89abe22487e diff --git a/tests/ShortDev.Microsoft.ConnectedDevices.Test/SerializationTest.cs b/tests/ShortDev.Microsoft.ConnectedDevices.Test/SerializationTest.cs index ef27d70..c3ab8f3 100644 --- a/tests/ShortDev.Microsoft.ConnectedDevices.Test/SerializationTest.cs +++ b/tests/ShortDev.Microsoft.ConnectedDevices.Test/SerializationTest.cs @@ -6,19 +6,14 @@ namespace ShortDev.Microsoft.ConnectedDevices.Test; -public sealed class SerializationTest +public sealed class SerializationTest(ITestOutputHelper output) { static SerializationTest() { TestValueGenerator.TryRegisterTypeFactory(() => ConnectedDevicesPlatform.CreateDeviceCertificate(CdpEncryptionParams.Default)); } - private readonly ITestOutputHelper _output; - - public SerializationTest(ITestOutputHelper output) - { - _output = output; - } + private readonly ITestOutputHelper _output = output; public static IEnumerable GenerateMsgTypes() { diff --git a/tests/ShortDev.Microsoft.ConnectedDevices.Test/ShortDev.Microsoft.ConnectedDevices.Test.csproj b/tests/ShortDev.Microsoft.ConnectedDevices.Test/ShortDev.Microsoft.ConnectedDevices.Test.csproj index 7f959dc..5a24822 100644 --- a/tests/ShortDev.Microsoft.ConnectedDevices.Test/ShortDev.Microsoft.ConnectedDevices.Test.csproj +++ b/tests/ShortDev.Microsoft.ConnectedDevices.Test/ShortDev.Microsoft.ConnectedDevices.Test.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable diff --git a/tests/ShortDev.Microsoft.ConnectedDevices.Test/TestValueGenerator.cs b/tests/ShortDev.Microsoft.ConnectedDevices.Test/TestValueGenerator.cs index 265972c..b0d2e1b 100644 --- a/tests/ShortDev.Microsoft.ConnectedDevices.Test/TestValueGenerator.cs +++ b/tests/ShortDev.Microsoft.ConnectedDevices.Test/TestValueGenerator.cs @@ -12,7 +12,7 @@ public static T RandomValue() public static object RandomValue(Type type) => RandomValueInternal(type, depth: 0); - static readonly Dictionary> _factories = new(); + static readonly Dictionary> _factories = []; public static bool TryRegisterTypeFactory(Func factory) { var type = typeof(T);