1212import io .sentry .Integration ;
1313import io .sentry .SentryLevel ;
1414import io .sentry .SentryOptions ;
15+ import io .sentry .android .core .internal .util .AndroidCurrentDateProvider ;
16+ import io .sentry .android .core .internal .util .Debouncer ;
1517import io .sentry .android .core .internal .util .DeviceOrientations ;
1618import io .sentry .protocol .Device ;
1719import io .sentry .util .Objects ;
2426public final class AppComponentsBreadcrumbsIntegration
2527 implements Integration , Closeable , ComponentCallbacks2 {
2628
29+ private static final long DEBOUNCE_WAIT_TIME_MS = 60 * 1000 ;
30+ // pre-allocate hint to avoid creating it every time for the low memory case
31+ private static final @ NotNull Hint EMPTY_HINT = new Hint ();
32+
2733 private final @ NotNull Context context ;
2834 private @ Nullable IScopes scopes ;
2935 private @ Nullable SentryAndroidOptions options ;
3036
37+ private final @ NotNull Debouncer trimMemoryDebouncer =
38+ new Debouncer (AndroidCurrentDateProvider .getInstance (), DEBOUNCE_WAIT_TIME_MS , 0 );
39+
3140 public AppComponentsBreadcrumbsIntegration (final @ NotNull Context context ) {
3241 this .context =
3342 Objects .requireNonNull (ContextUtils .getApplicationContext (context ), "Context is required" );
@@ -109,6 +118,11 @@ public void onTrimMemory(final int level) {
109118 return ;
110119 }
111120
121+ if (trimMemoryDebouncer .checkForDebounce ()) {
122+ // if we received trim_memory within 1 minute time, ignore this call
123+ return ;
124+ }
125+
112126 final long now = System .currentTimeMillis ();
113127 executeInBackground (() -> captureLowMemoryBreadcrumb (now , level ));
114128 }
@@ -122,7 +136,7 @@ private void captureLowMemoryBreadcrumb(final long timeMs, final int level) {
122136 breadcrumb .setData ("action" , "LOW_MEMORY" );
123137 breadcrumb .setData ("level" , level );
124138 breadcrumb .setLevel (SentryLevel .WARNING );
125- scopes .addBreadcrumb (breadcrumb );
139+ scopes .addBreadcrumb (breadcrumb , EMPTY_HINT );
126140 }
127141 }
128142
0 commit comments