8
8
import io .sentry .android .core .AndroidLogger ;
9
9
import io .sentry .android .core .SentryAndroidOptions ;
10
10
import org .jetbrains .annotations .NotNull ;
11
+ import org .jetbrains .annotations .Nullable ;
11
12
import org .json .JSONObject ;
12
13
13
14
public final class RNSentrySDK {
@@ -20,24 +21,30 @@ private RNSentrySDK() {
20
21
throw new AssertionError ("Utility class should not be instantiated" );
21
22
}
22
23
24
+ /** Passing a custom SDK initializer is intended for internal testing use only. */
25
+ interface SdkInit {
26
+ void init (Context context , Sentry .OptionsConfiguration <SentryAndroidOptions > config );
27
+ }
28
+
23
29
static void init (
24
30
@ NotNull final Context context ,
25
31
@ NotNull Sentry .OptionsConfiguration <SentryAndroidOptions > configuration ,
26
32
@ NotNull String configurationFile ,
27
- @ NotNull ILogger logger ) {
33
+ @ NotNull ILogger logger ,
34
+ @ Nullable SdkInit sdkInit ) {
28
35
try {
29
36
JSONObject jsonObject =
30
37
RNSentryJsonUtils .getOptionsFromConfigurationFile (context , configurationFile , logger );
31
38
if (jsonObject == null ) {
32
- RNSentryStart .startWithConfiguration (context , configuration );
39
+ RNSentryStart .startWithConfiguration (context , configuration , sdkInit );
33
40
return ;
34
41
}
35
42
ReadableMap rnOptions = RNSentryJsonConverter .convertToWritable (jsonObject );
36
43
if (rnOptions == null ) {
37
- RNSentryStart .startWithConfiguration (context , configuration );
44
+ RNSentryStart .startWithConfiguration (context , configuration , sdkInit );
38
45
return ;
39
46
}
40
- RNSentryStart .startWithOptions (context , rnOptions , configuration , logger );
47
+ RNSentryStart .startWithOptions (context , rnOptions , configuration , logger , sdkInit );
41
48
} catch (Exception e ) {
42
49
logger .log (
43
50
SentryLevel .ERROR , "Failed to start Sentry with options from configuration file." , e );
@@ -54,7 +61,7 @@ static void init(
54
61
public static void init (
55
62
@ NotNull final Context context ,
56
63
@ NotNull Sentry .OptionsConfiguration <SentryAndroidOptions > configuration ) {
57
- init (context , configuration , CONFIGURATION_FILE , logger );
64
+ init (context , configuration , CONFIGURATION_FILE , logger , null );
58
65
}
59
66
60
67
/**
@@ -63,6 +70,6 @@ public static void init(
63
70
* @param context Android Context
64
71
*/
65
72
public static void init (@ NotNull final Context context ) {
66
- init (context , options -> {}, CONFIGURATION_FILE , logger );
73
+ init (context , options -> {}, CONFIGURATION_FILE , logger , null );
67
74
}
68
75
}
0 commit comments