Skip to content

Commit

Permalink
Ref: Make ActivityFramesTracker public to be used by Hybrid SDKs (#1931)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Mar 2, 2022
1 parent fdf6b8c commit ae7a016
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* Ref: Make ActivityFramesTracker public to be used by Hybrid SDKs (#1931)
* Bump: AGP to 7.1.2 (#1930)

## 5.6.2-beta.2
Expand Down
13 changes: 13 additions & 0 deletions sentry-android-core/api/sentry-android-core.api
@@ -1,3 +1,11 @@
public final class io/sentry/android/core/ActivityFramesTracker {
public fun <init> (Lio/sentry/android/core/LoadClass;)V
public fun addActivity (Landroid/app/Activity;)V
public fun setMetrics (Landroid/app/Activity;Lio/sentry/protocol/SentryId;)V
public fun stop ()V
public fun takeMetrics (Lio/sentry/protocol/SentryId;)Ljava/util/Map;
}

public final class io/sentry/android/core/ActivityLifecycleIntegration : android/app/Application$ActivityLifecycleCallbacks, io/sentry/Integration, java/io/Closeable {
public fun <init> (Landroid/app/Application;Lio/sentry/android/core/IBuildInfoProvider;Lio/sentry/android/core/ActivityFramesTracker;)V
public fun close ()V
Expand Down Expand Up @@ -72,6 +80,11 @@ public abstract interface class io/sentry/android/core/IDebugImagesLoader {
public abstract fun loadDebugImages ()Ljava/util/List;
}

public final class io/sentry/android/core/LoadClass {
public fun <init> ()V
public fun loadClass (Ljava/lang/String;)Ljava/lang/Class;
}

public final class io/sentry/android/core/NdkIntegration : io/sentry/Integration, java/io/Closeable {
public static final field SENTRY_NDK_CLASS_NAME Ljava/lang/String;
public fun <init> (Ljava/lang/Class;)V
Expand Down
Expand Up @@ -12,15 +12,20 @@
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;

final class ActivityFramesTracker {
/**
* A class that tracks slow and frozen frames using the FrameMetricsAggregator class from
* androidx.core package. It also checks if the FrameMetricsAggregator class is available at
* runtime.
*/
public final class ActivityFramesTracker {

private @Nullable FrameMetricsAggregator frameMetricsAggregator = null;
private boolean androidXAvailable = true;

private final @NotNull Map<SentryId, Map<String, @NotNull MeasurementValue>>
activityMeasurements = new ConcurrentHashMap<>();

ActivityFramesTracker(final @NotNull LoadClass loadClass) {
public ActivityFramesTracker(final @NotNull LoadClass loadClass) {
androidXAvailable = checkAndroidXAvailability(loadClass);
if (androidXAvailable) {
frameMetricsAggregator = new FrameMetricsAggregator();
Expand All @@ -47,15 +52,16 @@ private boolean isFrameMetricsAggregatorAvailable() {
}

@SuppressWarnings("NullAway")
synchronized void addActivity(final @NotNull Activity activity) {
public synchronized void addActivity(final @NotNull Activity activity) {
if (!isFrameMetricsAggregatorAvailable()) {
return;
}
frameMetricsAggregator.add(activity);
}

@SuppressWarnings("NullAway")
synchronized void setMetrics(final @NotNull Activity activity, final @NotNull SentryId sentryId) {
public synchronized void setMetrics(
final @NotNull Activity activity, final @NotNull SentryId sentryId) {
if (!isFrameMetricsAggregatorAvailable()) {
return;
}
Expand Down Expand Up @@ -112,7 +118,7 @@ synchronized void setMetrics(final @NotNull Activity activity, final @NotNull Se
}

@Nullable
synchronized Map<String, @NotNull MeasurementValue> takeMetrics(
public synchronized Map<String, @NotNull MeasurementValue> takeMetrics(
final @NotNull SentryId sentryId) {
if (!isFrameMetricsAggregatorAvailable()) {
return null;
Expand All @@ -125,7 +131,7 @@ synchronized void setMetrics(final @NotNull Activity activity, final @NotNull Se
}

@SuppressWarnings("NullAway")
synchronized void stop() {
public synchronized void stop() {
if (isFrameMetricsAggregatorAvailable()) {
frameMetricsAggregator.stop();
}
Expand Down
Expand Up @@ -3,7 +3,7 @@
import org.jetbrains.annotations.NotNull;

/** An Adapter for making Class.forName testable */
final class LoadClass {
public final class LoadClass {

/**
* Try to load a class via reflection
Expand Down

0 comments on commit ae7a016

Please sign in to comment.