Skip to content

Commit

Permalink
fix: DeviceName exception during initialization (#1365)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes authored Jun 22, 2023
1 parent 3fa8e58 commit fa10316
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- The SDK no longer causes an exception during initialiation on Android API level 32 and newer ([#1365](https://github.com/getsentry/sentry-unity/pull/1365))
- Suspending Android native support for Mono builds to prevent C# exceptions form causing crashes ([#1362](https://github.com/getsentry/sentry-unity/pull/1362))
- Fixed an issue where the debug image UUID normalization would malform the UUID leading to a failed symbolication ([#1361](https://github.com/getsentry/sentry-unity/pull/1361))

Expand Down
28 changes: 27 additions & 1 deletion src/Sentry.Unity/SystemInfoAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading;
using UnityEngine;
using UnityEngine.UIElements;

namespace Sentry.Unity
{
Expand Down Expand Up @@ -56,7 +57,32 @@ private SentrySystemInfoAdapter()
public bool? SupportsVibration => SystemInfo.supportsVibration;
public Lazy<string>? DeviceType => new(() => SystemInfo.deviceType.ToString());
public string? CpuDescription => SystemInfo.processorType;
public string? DeviceName => SystemInfo.deviceName;
public string? DeviceName
{
get
{
// Workaround for https://github.com/getsentry/sentry-unity/issues/1322 -
if (Application.platform == RuntimePlatform.Android)
{
using var version = new AndroidJavaClass("android.os.Build$VERSION");
var sdkVersion = version.GetStatic<int>("SDK_INT");
if (sdkVersion >= 32)
{
try
{
return SystemInfo.deviceName;
}
catch
{
// Unity's built-in fallback
return "<unknown>";
}
}
}

return SystemInfo.deviceName;
}
}

public Lazy<string> DeviceUniqueIdentifier => new(() => SystemInfo.deviceUniqueIdentifier);
public Lazy<string> DeviceModel => new(() => SystemInfo.deviceModel);
Expand Down

0 comments on commit fa10316

Please sign in to comment.