1414import android .view .Window ;
1515import androidx .annotation .RequiresApi ;
1616import io .sentry .ILogger ;
17- import io .sentry .ISentryLifecycleToken ;
1817import io .sentry .SentryLevel ;
1918import io .sentry .SentryOptions ;
2019import io .sentry .SentryUUID ;
2120import io .sentry .android .core .BuildInfoProvider ;
2221import io .sentry .android .core .ContextUtils ;
23- import io .sentry .util .AutoClosableReentrantLock ;
2422import io .sentry .util .Objects ;
2523import java .lang .ref .WeakReference ;
2624import java .lang .reflect .Field ;
@@ -40,8 +38,7 @@ public final class SentryFrameMetricsCollector implements Application.ActivityLi
4038
4139 private final @ NotNull BuildInfoProvider buildInfoProvider ;
4240 private final @ NotNull Set <Window > trackedWindows = new CopyOnWriteArraySet <>();
43- private final @ NotNull AutoClosableReentrantLock trackedWindowsLock =
44- new AutoClosableReentrantLock ();
41+
4542 private final @ NotNull ILogger logger ;
4643 private @ Nullable Handler handler ;
4744 private @ Nullable WeakReference <Window > currentWindow ;
@@ -292,11 +289,7 @@ private void stopTrackingWindow(final @NotNull Window window) {
292289 try {
293290 // Re-check if we should still remove the listener for this window
294291 // in case trackCurrentWindow was called in the meantime
295- final boolean shouldRemove ;
296- try (final @ NotNull ISentryLifecycleToken ignored = trackedWindowsLock .acquire ()) {
297- shouldRemove = trackedWindows .contains (window ) && trackedWindows .remove (window );
298- }
299- if (shouldRemove ) {
292+ if (trackedWindows .remove (window )) {
300293 windowFrameMetricsManager .removeOnFrameMetricsAvailableListener (
301294 window , frameMetricsAvailableListener );
302295 }
@@ -330,13 +323,7 @@ private void trackCurrentWindow() {
330323 new Handler (Looper .getMainLooper ())
331324 .post (
332325 () -> {
333- // Re-check if we should still track this window
334- // in case stopTrackingWindow was called for the same Window in the meantime
335- final boolean shouldAdd ;
336- try (final @ NotNull ISentryLifecycleToken ignored = trackedWindowsLock .acquire ()) {
337- shouldAdd = !trackedWindows .contains (window ) && trackedWindows .add (window );
338- }
339- if (shouldAdd ) {
326+ if (trackedWindows .add (window )) {
340327 try {
341328 windowFrameMetricsManager .addOnFrameMetricsAvailableListener (
342329 window , frameMetricsAvailableListener , handler );
@@ -411,6 +398,9 @@ default void addOnFrameMetricsAvailableListener(
411398 default void removeOnFrameMetricsAvailableListener (
412399 final @ NotNull Window window ,
413400 final @ Nullable Window .OnFrameMetricsAvailableListener frameMetricsAvailableListener ) {
401+ if (frameMetricsAvailableListener == null ) {
402+ return ;
403+ }
414404 window .removeOnFrameMetricsAvailableListener (frameMetricsAvailableListener );
415405 }
416406 }
0 commit comments