1010import com .getcapacitor .annotation .CapacitorPlugin ;
1111
1212import io .sentry .Breadcrumb ;
13- import io .sentry .HubAdapter ;
13+ import io .sentry .IScope ;
1414import io .sentry .Integration ;
15+ import io .sentry .ScopesAdapter ;
1516import io .sentry .Sentry ;
1617import io .sentry .SentryEvent ;
1718import io .sentry .SentryLevel ;
2526import io .sentry .protocol .User ;
2627import java .io .File ;
2728import java .io .FileOutputStream ;
28- import java .io . UnsupportedEncodingException ;
29+ import java .nio . charset . StandardCharsets ;
2930import java .util .HashMap ;
3031import java .util .Iterator ;
3132import java .util .List ;
@@ -62,9 +63,9 @@ public void load() {
6263
6364 @ PluginMethod
6465 public void initNativeSdk (final PluginCall call ) {
65- JSObject capOptions = call .getObject ("options" );
66+ JSObject capOptions = call .getObject ("options" );
6667
67- SentryAndroid .init (
68+ SentryAndroid .init (
6869 this .getContext (),
6970 options -> {
7071 SdkVersion sdkVersion = options .getSdkVersion ();
@@ -74,7 +75,7 @@ public void initNativeSdk(final PluginCall call) {
7475 sdkVersion .setName (ANDROID_SDK_NAME );
7576 }
7677
77- if (capOptions .has ("debug" ) && capOptions .getBool ("debug" )) {
78+ if (capOptions .has ("debug" ) && capOptions .getBool ("debug" )) {
7879 options .setDebug (true );
7980 logger .setLevel (Level .INFO );
8081 }
@@ -83,7 +84,7 @@ public void initNativeSdk(final PluginCall call) {
8384 options .setNativeSdkName (NATIVE_SDK_NAME );
8485 options .setSdkVersion (sdkVersion );
8586
86- String dsn = capOptions .getString ("dsn" ) != null ? capOptions .getString ("dsn" ) : "" ;
87+ String dsn = capOptions .getString ("dsn" ) != null ? capOptions .getString ("dsn" ) : "" ;
8788 logger .info (String .format ("Starting with DSN: '%s'" , dsn ));
8889 options .setDsn (dsn );
8990
@@ -212,9 +213,9 @@ public void crash(PluginCall call) {
212213 @ PluginMethod
213214 public void fetchNativeRelease (PluginCall call ) {
214215 JSObject release = new JSObject ();
215- release .put ("id" , this . packageInfo .packageName );
216- release .put ("version" , this . packageInfo .versionName );
217- release .put ("build" , String .valueOf (this . packageInfo .versionCode )); // Requires API 28
216+ release .put ("id" , packageInfo .packageName );
217+ release .put ("version" , packageInfo .versionName );
218+ release .put ("build" , String .valueOf (packageInfo .versionCode )); // Requires API 28
218219 call .resolve (release );
219220 }
220221
@@ -227,7 +228,7 @@ public void captureEnvelope(PluginCall call) {
227228 bytes [i ] = (byte ) rawIntegers .getInt (i );
228229 }
229230
230- final String outboxPath = HubAdapter .getInstance ().getOptions ().getOutboxPath ();
231+ final String outboxPath = ScopesAdapter .getInstance ().getOptions ().getOutboxPath ();
231232
232233 if (outboxPath == null || outboxPath .isEmpty ()) {
233234 logger .info ("Error when writing envelope, no outbox path is present." );
@@ -259,9 +260,9 @@ public void getStringBytesLength(PluginCall call) {
259260 String payload = call .getString ("string" );
260261 try {
261262 JSObject resp = new JSObject ();
262- resp .put ("value" , payload .getBytes ("UTF-8" ).length );
263+ resp .put ("value" , payload .getBytes (StandardCharsets . UTF_8 ).length );
263264 call .resolve (resp );
264- } catch (UnsupportedEncodingException e ) {
265+ } catch (Exception e ) {
265266 call .reject (String .valueOf (e ));
266267 }
267268 } else {
@@ -300,9 +301,6 @@ public void addBreadcrumb(final PluginCall breadcrumb) {
300301 case "debug" :
301302 breadcrumbInstance .setLevel (SentryLevel .DEBUG );
302303 break ;
303- case "error" :
304- breadcrumbInstance .setLevel (SentryLevel .ERROR );
305- break ;
306304 default :
307305 breadcrumbInstance .setLevel (SentryLevel .ERROR );
308306 break ;
@@ -328,9 +326,7 @@ public void addBreadcrumb(final PluginCall breadcrumb) {
328326
329327 @ PluginMethod
330328 public void clearBreadcrumbs (PluginCall call ) {
331- Sentry .configureScope (scope -> {
332- scope .clearBreadcrumbs ();
333- });
329+ Sentry .configureScope (IScope ::clearBreadcrumbs );
334330 }
335331
336332 @ PluginMethod
@@ -399,17 +395,13 @@ public void addPackages(SentryEvent event, SdkVersion sdk) {
399395 SdkVersion eventSdk = event .getSdk ();
400396 if (eventSdk != null && eventSdk .getName ().equals ("sentry.javascript.capacitor" ) && sdk != null ) {
401397 Set <SentryPackage > sentryPackages = sdk .getPackageSet ();
402- if (sentryPackages != null ) {
403- for (SentryPackage sentryPackage : sentryPackages ) {
404- eventSdk .addPackage (sentryPackage .getName (), sentryPackage .getVersion ());
405- }
398+ for (SentryPackage sentryPackage : sentryPackages ) {
399+ eventSdk .addPackage (sentryPackage .getName (), sentryPackage .getVersion ());
406400 }
407401
408402 Set <String > integrations = sdk .getIntegrationSet ();
409- if (integrations != null ) {
410- for (String integration : integrations ) {
411- eventSdk .addIntegration (integration );
412- }
403+ for (String integration : integrations ) {
404+ eventSdk .addIntegration (integration );
413405 }
414406
415407 event .setSdk (eventSdk );
0 commit comments