88import io .sentry .android .core .AndroidLogger ;
99import io .sentry .android .core .SentryAndroidOptions ;
1010import org .jetbrains .annotations .NotNull ;
11+ import org .jetbrains .annotations .Nullable ;
1112import org .json .JSONObject ;
1213
1314public final class RNSentrySDK {
@@ -20,24 +21,30 @@ private RNSentrySDK() {
2021 throw new AssertionError ("Utility class should not be instantiated" );
2122 }
2223
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+
2329 static void init (
2430 @ NotNull final Context context ,
2531 @ NotNull Sentry .OptionsConfiguration <SentryAndroidOptions > configuration ,
2632 @ NotNull String configurationFile ,
27- @ NotNull ILogger logger ) {
33+ @ NotNull ILogger logger ,
34+ @ Nullable SdkInit sdkInit ) {
2835 try {
2936 JSONObject jsonObject =
3037 RNSentryJsonUtils .getOptionsFromConfigurationFile (context , configurationFile , logger );
3138 if (jsonObject == null ) {
32- RNSentryStart .startWithConfiguration (context , configuration );
39+ RNSentryStart .startWithConfiguration (context , configuration , sdkInit );
3340 return ;
3441 }
3542 ReadableMap rnOptions = RNSentryJsonConverter .convertToWritable (jsonObject );
3643 if (rnOptions == null ) {
37- RNSentryStart .startWithConfiguration (context , configuration );
44+ RNSentryStart .startWithConfiguration (context , configuration , sdkInit );
3845 return ;
3946 }
40- RNSentryStart .startWithOptions (context , rnOptions , configuration , logger );
47+ RNSentryStart .startWithOptions (context , rnOptions , configuration , logger , sdkInit );
4148 } catch (Exception e ) {
4249 logger .log (
4350 SentryLevel .ERROR , "Failed to start Sentry with options from configuration file." , e );
@@ -54,7 +61,7 @@ static void init(
5461 public static void init (
5562 @ NotNull final Context context ,
5663 @ NotNull Sentry .OptionsConfiguration <SentryAndroidOptions > configuration ) {
57- init (context , configuration , CONFIGURATION_FILE , logger );
64+ init (context , configuration , CONFIGURATION_FILE , logger , null );
5865 }
5966
6067 /**
@@ -63,6 +70,6 @@ public static void init(
6370 * @param context Android Context
6471 */
6572 public static void init (@ NotNull final Context context ) {
66- init (context , options -> {}, CONFIGURATION_FILE , logger );
73+ init (context , options -> {}, CONFIGURATION_FILE , logger , null );
6774 }
6875}
0 commit comments