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

Upgrade to dotnet 8 (lts) #118

Merged
merged 1 commit into from
Nov 17, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Nearby Sharing Windows/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
26 changes: 10 additions & 16 deletions Nearby Sharing Windows/Layout/BottomSheetBehaviorCallback.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 1 addition & 1 deletion Nearby Sharing Windows/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result
{
intent.SetAction(Intent.ActionSendMultiple);

List<IParcelable> uriList = new();
List<IParcelable> uriList = [];
for (int i = 0; i < clipData.ItemCount; i++)
{
var item = clipData.GetItemAt(i);
Expand Down
10 changes: 5 additions & 5 deletions Nearby Sharing Windows/Nearby Sharing Windows.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-android33.0</TargetFramework>
<TargetFramework>net8.0-android34.0</TargetFramework>
<OutputType>Exe</OutputType>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<LangVersion>preview</LangVersion>
Expand All @@ -18,11 +18,11 @@
<AndroidPackageFormat>aab</AndroidPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Sentry" Version="3.31.0" />
<PackageReference Include="Sentry" Version="3.41.0" />
<PackageReference Include="ShortDev.Android.FluentIcons" Version="1.1.203" />
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.6.1.1" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.8.0.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.5" />
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.6.1.5" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.10.0.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.8.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\lib\ShortDev.Android.Preferences\ShortDev.Android.Preferences.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion Nearby Sharing Windows/QuickSettings/ReceiveTileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Nearby Sharing Windows/SendActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -148,7 +148,7 @@ void InitializePlatform()
NearShareSender = new NearShareSender(Platform);
}

readonly List<CdpDevice> RemoteSystems = new();
readonly List<CdpDevice> RemoteSystems = [];
private void Platform_DeviceDiscovered(ICdpTransport sender, CdpDevice device, BLeBeacon advertisement)
{
if (!RemoteSystems.Contains(device))
Expand Down Expand Up @@ -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)) },
Expand Down
34 changes: 19 additions & 15 deletions Nearby Sharing Windows/UIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -123,22 +130,19 @@ public static void RequestSendPermissions(Activity activity)
ManifestPermission.ReadExternalStorage,
ManifestPermission.WriteExternalStorage
];
[SupportedOSPlatform("android31.0")]
private static readonly string[] _receivePermissionsApi31 = [
.. _receivePermissions,
ManifestPermission.BluetoothScan,
ManifestPermission.BluetoothConnect,
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
9 changes: 3 additions & 6 deletions ShortDev.Microsoft.ConnectedDevices/CdpSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private CdpSession(ConnectedDevicesPlatform platform, CdpDevice device, SessionI
}

#region Registration
static readonly AutoKeyRegistry<uint, CdpSession> _sessionRegistry = new();
static readonly AutoKeyRegistry<uint, CdpSession> _sessionRegistry = [];
internal static CdpSession GetOrCreate(ConnectedDevicesPlatform platform, CdpDevice device, CommonHeader header)
{
ArgumentNullException.ThrowIfNull(device);
Expand Down Expand Up @@ -635,7 +635,7 @@ CdpMessage GetOrCreateMessage(CommonHeader header)
#endregion

#region Channels
readonly AutoKeyRegistry<ulong, CdpChannel> _channelRegistry = new();
readonly AutoKeyRegistry<ulong, CdpChannel> _channelRegistry = [];

public async Task<CdpChannel> StartClientChannelAsync(string appId, string appName, CdpAppBase handler, CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ bool TryGetKnownSocket(EndpointInfo endpoint, [MaybeNullWhen(false)] out CdpSock

public CdpDeviceInfo GetCdpDeviceInfo()
{
List<EndpointInfo> endpoints = new();
List<EndpointInfo> endpoints = [];
foreach (var (_, transport) in _transports)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void Read(ref EndianReader reader, CommonHeader header)

var encryptedPayload = reader.ReadBytes(payloadSize);

scoped Span<byte> hmac = Span<byte>.Empty;
scoped Span<byte> hmac = [];
if (header.HasFlag(MessageFlags.HasHMAC))
{
hmac = stackalloc byte[Constants.HMacSize];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions ShortDev.Microsoft.ConnectedDevices/Encryption/CdpNonce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}
Original file line number Diff line number Diff line change
@@ -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) { }
}
Original file line number Diff line number Diff line change
@@ -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) { }
}
Original file line number Diff line number Diff line change
@@ -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) { }
}
2 changes: 1 addition & 1 deletion ShortDev.Microsoft.ConnectedDevices/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void DisposeAll(params IEnumerable<IDisposable>[] disposables)

public static void DisposeAll<T>(this IEnumerable<T> disposables) where T : IDisposable
{
List<Exception> exceptions = new();
List<Exception> exceptions = [];

foreach (var disposable in disposables)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ShortDev.Microsoft.ConnectedDevices.Internal;

internal sealed class ConcurrentList<T>
{
readonly List<T> _data = new();
readonly List<T> _data = [];

public void Add(T item)
{
Expand Down
24 changes: 12 additions & 12 deletions ShortDev.Microsoft.ConnectedDevices/Internal/UpgradeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -245,10 +245,10 @@ void SendUpgradeRequest(CdpSocket socket, Guid upgradeId)
new UpgradeRequest()
{
UpgradeId = upgradeId,
Endpoints = new[]
{
Endpoints =
[
EndpointMetadata.Tcp
}
]
}.Write(writer);
});
}
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading