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

fix: DeviceName exception during initialization #1365

Merged
merged 5 commits into from
Jun 22, 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
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;
vaind marked this conversation as resolved.
Show resolved Hide resolved
}
}

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