forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentryNdk.java
More file actions
112 lines (100 loc) · 4.04 KB
/
SentryNdk.java
File metadata and controls
112 lines (100 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package io.sentry.android.ndk;
import io.sentry.android.core.NdkHandlerStrategy;
import io.sentry.android.core.SentryAndroidOptions;
import io.sentry.ndk.NativeModuleListLoader;
import io.sentry.ndk.NdkOptions;
import io.sentry.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ApiStatus.Internal
public final class SentryNdk {
private static final @NotNull CountDownLatch loadLibraryLatch = new CountDownLatch(1);
private SentryNdk() {}
static {
new Thread(
() -> {
try {
//noinspection UnstableApiUsage
io.sentry.ndk.SentryNdk.loadNativeLibraries();
} catch (Throwable t) {
// ignored
// if loadLibrary() fails, the later init() will throw an exception anyway
} finally {
loadLibraryLatch.countDown();
}
},
"SentryNdkLoadLibs")
.start();
}
/**
* Init the NDK integration
*
* @param options the SentryAndroidOptions
*/
public static void init(@NotNull final SentryAndroidOptions options) {
SentryNdkUtil.addPackage(options.getSdkVersion());
try {
if (loadLibraryLatch.await(2000, TimeUnit.MILLISECONDS)) {
final @NotNull NdkOptions ndkOptions =
new NdkOptions(
Objects.requireNonNull(options.getDsn(), "DSN is required for sentry-ndk"),
options.isDebug(),
Objects.requireNonNull(
options.getOutboxPath(), "outbox path is required for sentry-ndk"),
options.getRelease(),
options.getEnvironment(),
options.getDist(),
options.getMaxBreadcrumbs(),
options.getNativeSdkName());
final int handlerStrategy = options.getNdkHandlerStrategy();
if (handlerStrategy == NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_DEFAULT.getValue()) {
ndkOptions.setNdkHandlerStrategy(
io.sentry.ndk.NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_DEFAULT);
} else if (handlerStrategy
== NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_CHAIN_AT_START.getValue()) {
ndkOptions.setNdkHandlerStrategy(
io.sentry.ndk.NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_CHAIN_AT_START);
}
final @Nullable Double tracesSampleRate = options.getTracesSampleRate();
if (tracesSampleRate == null) {
ndkOptions.setTracesSampleRate(0.0f);
} else {
ndkOptions.setTracesSampleRate(tracesSampleRate.floatValue());
}
//noinspection UnstableApiUsage
final int initResult = io.sentry.ndk.SentryNdk.init(ndkOptions);
if (initResult != 0) {
throw new IllegalStateException(
"Failed to initialize Sentry NDK. Native init returned code " + initResult);
}
// only add scope sync observer if the scope sync is enabled.
if (options.isEnableScopeSync()) {
options.addScopeObserver(new NdkScopeObserver(options));
}
options.setDebugImagesLoader(new DebugImagesLoader(options, new NativeModuleListLoader()));
} else {
throw new IllegalStateException("Timeout waiting for Sentry NDK library to load");
}
} catch (InterruptedException e) {
throw new IllegalStateException(
"Thread interrupted while waiting for NDK libs to be loaded", e);
}
}
/** Closes the NDK integration */
public static void close() {
try {
if (loadLibraryLatch.await(2000, TimeUnit.MILLISECONDS)) {
//noinspection UnstableApiUsage
io.sentry.ndk.SentryNdk.close();
} else {
throw new IllegalStateException("Timeout waiting for Sentry NDK library to load");
}
} catch (InterruptedException e) {
throw new IllegalStateException(
"Thread interrupted while waiting for NDK libs to be loaded", e);
}
}
}