-
-
Notifications
You must be signed in to change notification settings - Fork 220
Allow some mobile options to be modified from defaults #1857
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
Changes from all commits
657f7c2
7e212b4
5edd36c
0d153ca
b4c947a
94c7b0d
198aab7
4c46440
d09fa5f
95a4bbe
cdb888a
8455400
6efe7b3
efd721f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Sentry.PlatformAbstractions | ||
{ | ||
internal static class DeviceInfo | ||
{ | ||
#if ANDROID | ||
public const string PlatformName = "Android"; | ||
#elif IOS | ||
public const string PlatformName = "iOS"; | ||
#elif MACCATALYST | ||
public const string PlatformName = "Mac Catalyst"; | ||
#endif | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,27 +3,27 @@ | |
using Sentry.Android; | ||
using Sentry.Android.Callbacks; | ||
using Sentry.Android.Extensions; | ||
using Sentry.Extensibility; | ||
using Sentry.Protocol; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Sentry; | ||
|
||
public static partial class SentrySdk | ||
{ | ||
private static AndroidContext? AndroidContext; | ||
private static AndroidContext AppContext { get; set; } = Application.Context; | ||
|
||
/// <summary> | ||
/// Initializes the SDK for Android, with an optional configuration options callback. | ||
/// </summary> | ||
/// <param name="context">The Android application context.</param> | ||
/// <param name="configureOptions">The configuration options callback.</param> | ||
/// <returns>An object that should be disposed when the application terminates.</returns> | ||
[Obsolete("It is no longer required to provide the application context when calling Init. " + | ||
"This method may be removed in a future major release.")] | ||
public static IDisposable Init(AndroidContext context, Action<SentryOptions>? configureOptions) | ||
{ | ||
var options = new SentryOptions(); | ||
configureOptions?.Invoke(options); | ||
return Init(context, options); | ||
AppContext = context; | ||
return Init(configureOptions); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -32,40 +32,26 @@ public static IDisposable Init(AndroidContext context, Action<SentryOptions>? co | |
/// <param name="context">The Android application context.</param> | ||
/// <param name="options">The configuration options instance.</param> | ||
/// <returns>An object that should be disposed when the application terminates.</returns> | ||
[Obsolete("It is no longer required to provide the application context when calling Init. " + | ||
"This method may be removed in a future major release.")] | ||
public static IDisposable Init(AndroidContext context, SentryOptions options) | ||
{ | ||
AndroidContext = context; | ||
AppContext = context; | ||
return Init(options); | ||
} | ||
|
||
private static void InitSentryAndroidSdk(SentryOptions options) | ||
{ | ||
// Set options for the managed SDK that don't depend on the Android SDK | ||
options.AutoSessionTracking = true; | ||
options.IsGlobalModeEnabled = true; | ||
|
||
// Set default release and distribution | ||
options.Release ??= GetDefaultReleaseString(); | ||
options.Distribution ??= GetDefaultDistributionString(); | ||
|
||
// "Best" mode throws permission exception on Android | ||
options.DetectStartupTime = StartupTimeDetectionMode.Fast; | ||
|
||
// Make sure we capture managed exceptions from the Android environment | ||
AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironment_UnhandledExceptionRaiser; | ||
|
||
// Now initialize the Android SDK if we have been given an AndroidContext | ||
var context = AndroidContext; | ||
if (context == null) | ||
{ | ||
options.LogWarning("Running on Android, but did not initialize Sentry with an AndroidContext. " + | ||
"The embedded Sentry Android SDK is disabled. " + | ||
"Call SentrySdk.Init(AndroidContext, SentryOptions) instead."); | ||
return; | ||
} | ||
|
||
// Now initialize the Android SDK | ||
SentryAndroidOptions? androidOptions = null; | ||
SentryAndroid.Init(context, new JavaLogger(options), | ||
SentryAndroid.Init(AppContext, new JavaLogger(options), | ||
new OptionsConfigurationCallback(o => | ||
{ | ||
// Capture the android options reference on the outer scope | ||
|
@@ -179,7 +165,7 @@ private static void InitSentryAndroidSdk(SentryOptions options) | |
o.AddIgnoredExceptionForType(JavaClass.ForName("android.runtime.JavaProxyThrowable")); | ||
})); | ||
|
||
// Set options for the managed SDK that depend on the Android SDK | ||
// Set options for the managed SDK that depend on the Android SDK. (The user will not be able to modify these.) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
does this mean "there is no API what the user can use to modify these" or "we ignore/overwrite the options the user sets"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It means, we set these options ourselves during init, ignoring whatever the user provided. These should be limited to what is needed to make the native and managed SDKs work together. |
||
options.AddEventProcessor(new AndroidEventProcessor(androidOptions!)); | ||
options.CrashedLastRun = () => Java.Sentry.IsCrashedLastRun()?.BooleanValue() is true; | ||
options.EnableScopeSync = true; | ||
|
@@ -201,29 +187,27 @@ private static void AndroidEnvironment_UnhandledExceptionRaiser(object? _, Raise | |
|
||
private static string? GetDefaultReleaseString() | ||
{ | ||
var context = AndroidContext ?? Application.Context; | ||
var packageName = context.PackageName; | ||
var packageName = AppContext.PackageName; | ||
if (packageName == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var packageInfo = context.PackageManager?.GetPackageInfo(packageName, PackageInfoFlags.Permissions); | ||
var packageInfo = AppContext.PackageManager?.GetPackageInfo(packageName, PackageInfoFlags.Permissions); | ||
return packageInfo == null ? null : $"{packageName}@{packageInfo.VersionName}+{packageInfo.GetVersionCode()}"; | ||
} | ||
|
||
private static string? GetDefaultDistributionString() => GetAndroidPackageVersionCode()?.ToString(); | ||
|
||
private static long? GetAndroidPackageVersionCode() | ||
{ | ||
var context = AndroidContext ?? Application.Context; | ||
var packageName = context.PackageName; | ||
var packageName = AppContext.PackageName; | ||
if (packageName == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var packageInfo = context.PackageManager?.GetPackageInfo(packageName, PackageInfoFlags.Permissions); | ||
var packageInfo = AppContext.PackageManager?.GetPackageInfo(packageName, PackageInfoFlags.Permissions); | ||
return packageInfo?.GetVersionCode(); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.