Skip to content

Commit 5732ed1

Browse files
committed
rebased on 6.x.x
added ser/deser logic to ProfilingTraceData (+ tests) several updates for v6
1 parent 499df1f commit 5732ed1

File tree

10 files changed

+159
-43
lines changed

10 files changed

+159
-43
lines changed

sentry-android-core/api/sentry-android-core.api

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ public final class io/sentry/android/core/BuildConfig {
5959
}
6060

6161
public final class io/sentry/android/core/BuildInfoProvider {
62-
public fun <init> ()V
62+
public fun <init> (Lio/sentry/ILogger;)V
6363
public fun getBuildTags ()Ljava/lang/String;
64+
public fun getManufacturer ()Ljava/lang/String;
65+
public fun getModel ()Ljava/lang/String;
6466
public fun getSdkInfoVersion ()I
67+
public fun getVersionRelease ()Ljava/lang/String;
68+
public fun isEmulator ()Ljava/lang/Boolean;
6569
}
6670

6771
public abstract class io/sentry/android/core/EnvelopeFileObserverIntegration : io/sentry/Integration, java/io/Closeable {
@@ -108,6 +112,8 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
108112
public fun enableAllAutoBreadcrumbs (Z)V
109113
public fun getAnrTimeoutIntervalMillis ()J
110114
public fun getDebugImagesLoader ()Lio/sentry/android/core/IDebugImagesLoader;
115+
public fun getProfilingTracesDirPath ()Ljava/lang/String;
116+
public fun getProfilingTracesIntervalMillis ()I
111117
public fun isAnrEnabled ()Z
112118
public fun isAnrReportInDebug ()Z
113119
public fun isEnableActivityLifecycleBreadcrumbs ()Z
@@ -128,6 +134,8 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
128134
public fun setEnableAutoActivityLifecycleTracing (Z)V
129135
public fun setEnableSystemEventBreadcrumbs (Z)V
130136
public fun setEnableUserInteractionBreadcrumbs (Z)V
137+
public fun setProfilingTracesDirPath (Ljava/lang/String;)V
138+
public fun setProfilingTracesIntervalMillis (I)V
131139
}
132140

133141
public final class io/sentry/android/core/SentryInitProvider : android/content/ContentProvider {

sentry-android-core/src/main/java/io/sentry/android/core/AndroidOptionsInitializer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ static void init(
6464
final @NotNull ILogger logger,
6565
final boolean isFragmentAvailable,
6666
final boolean isTimberAvailable) {
67-
init(options, context, logger, new BuildInfoProvider(logger), isFragmentAvailable, isTimberAvailable);
67+
init(
68+
options,
69+
context,
70+
logger,
71+
new BuildInfoProvider(logger),
72+
isFragmentAvailable,
73+
isTimberAvailable);
6874
}
6975

7076
/**

sentry-android-core/src/main/java/io/sentry/android/core/AndroidTransactionProfiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ final class AndroidTransactionProfiler implements ITransactionProfiler {
4646
private volatile @Nullable ProfilingTraceData timedOutProfilingData = null;
4747
private final @NotNull Context context;
4848
private final @NotNull SentryAndroidOptions options;
49-
private final @NotNull IBuildInfoProvider buildInfoProvider;
49+
private final @NotNull BuildInfoProvider buildInfoProvider;
5050
private final @Nullable PackageInfo packageInfo;
5151
private long transactionStartNanos = 0;
5252

5353
public AndroidTransactionProfiler(
5454
final @NotNull Context context,
5555
final @NotNull SentryAndroidOptions sentryAndroidOptions,
56-
final @NotNull IBuildInfoProvider buildInfoProvider) {
56+
final @NotNull BuildInfoProvider buildInfoProvider) {
5757
this.context = Objects.requireNonNull(context, "The application context is required");
5858
this.options = Objects.requireNonNull(sentryAndroidOptions, "SentryAndroidOptions is required");
5959
this.buildInfoProvider =

sentry-android-core/src/main/java/io/sentry/android/core/BuildInfoProvider.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,14 @@ public int getSdkInfoVersion() {
3030
return Build.TAGS;
3131
}
3232

33-
@Override
3433
public @Nullable String getManufacturer() {
3534
return Build.MANUFACTURER;
3635
}
3736

38-
@Override
3937
public @Nullable String getModel() {
4038
return Build.MODEL;
4139
}
4240

43-
@Override
4441
public @Nullable String getVersionRelease() {
4542
return Build.VERSION.RELEASE;
4643
}
@@ -51,7 +48,6 @@ public int getSdkInfoVersion() {
5148
*
5249
* @return true if the application is running in an emulator, false otherwise
5350
*/
54-
@Override
5551
public @Nullable Boolean isEmulator() {
5652
try {
5753
return (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))

sentry-android-core/src/test/java/io/sentry/android/core/AndroidOptionsInitializerTest.kt

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,24 @@ class AndroidOptionsInitializerTest {
145145

146146
@Test
147147
fun `profilingTracesDirPath should be set at initialization`() {
148-
val sentryOptions = SentryAndroidOptions()
149-
val mockContext = createMockContext()
150-
151-
AndroidOptionsInitializer.init(sentryOptions, mockContext)
148+
fixture.initSut()
152149

153-
assertTrue(sentryOptions.profilingTracesDirPath?.endsWith("${File.separator}cache${File.separator}sentry${File.separator}profiling_traces")!!)
154-
assertFalse(File(sentryOptions.profilingTracesDirPath!!).exists())
150+
assertTrue(
151+
fixture.sentryOptions.profilingTracesDirPath?.endsWith(
152+
"${File.separator}cache${File.separator}sentry${File.separator}profiling_traces"
153+
)!!
154+
)
155+
assertFalse(File(fixture.sentryOptions.profilingTracesDirPath!!).exists())
155156
}
156157

157158
@Test
158159
fun `profilingTracesDirPath should be created and cleared when profiling is enabled`() {
159-
val sentryOptions = SentryAndroidOptions()
160-
val mockContext = createMockContext()
161-
sentryOptions.isProfilingEnabled = true
162-
163-
AndroidOptionsInitializer.init(sentryOptions, mockContext)
160+
fixture.initSut(configureOptions = {
161+
isProfilingEnabled = true
162+
})
164163

165-
assertTrue(File(sentryOptions.profilingTracesDirPath!!).exists())
166-
assertTrue(File(sentryOptions.profilingTracesDirPath!!).list()!!.isEmpty())
164+
assertTrue(File(fixture.sentryOptions.profilingTracesDirPath!!).exists())
165+
assertTrue(File(fixture.sentryOptions.profilingTracesDirPath!!).list()!!.isEmpty())
167166
}
168167

169168
@Test
@@ -243,13 +242,10 @@ class AndroidOptionsInitializerTest {
243242

244243
@Test
245244
fun `init should set Android transaction profiler`() {
246-
val sentryOptions = SentryAndroidOptions()
247-
val mockContext = createMockContext()
248-
249-
AndroidOptionsInitializer.init(sentryOptions, mockContext)
245+
fixture.initSut()
250246

251-
assertNotNull(sentryOptions.transactionProfiler)
252-
assertTrue(sentryOptions.transactionProfiler is AndroidTransactionProfiler)
247+
assertNotNull(fixture.sentryOptions.transactionProfiler)
248+
assertTrue(fixture.sentryOptions.transactionProfiler is AndroidTransactionProfiler)
253249
}
254250

255251
@Test

sentry-android-core/src/test/java/io/sentry/android/core/AndroidTransactionProfilerTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class AndroidTransactionProfilerTest {
2323
private lateinit var context: Context
2424

2525
private val className = "io.sentry.android.core.AndroidTransactionProfiler"
26-
private val ctorTypes = arrayOf(Context::class.java, SentryAndroidOptions::class.java, IBuildInfoProvider::class.java)
26+
private val ctorTypes = arrayOf(Context::class.java, SentryAndroidOptions::class.java, BuildInfoProvider::class.java)
2727
private val fixture = Fixture()
2828
private lateinit var file: File
2929

3030
private class Fixture {
31-
val buildInfo = mock<IBuildInfoProvider> {
31+
val buildInfo = mock<BuildInfoProvider> {
3232
whenever(it.sdkInfoVersion).thenReturn(Build.VERSION_CODES.LOLLIPOP)
3333
}
3434
val options = SentryAndroidOptions().apply {
@@ -37,7 +37,7 @@ class AndroidTransactionProfilerTest {
3737
val transaction1 = SentryTracer(TransactionContext("", ""), mock())
3838
val transaction2 = SentryTracer(TransactionContext("", ""), mock())
3939

40-
fun getSut(context: Context, buildInfoProvider: IBuildInfoProvider = buildInfo): AndroidTransactionProfiler =
40+
fun getSut(context: Context, buildInfoProvider: BuildInfoProvider = buildInfo): AndroidTransactionProfiler =
4141
AndroidTransactionProfiler(context, options, buildInfoProvider)
4242
}
4343

@@ -78,7 +78,7 @@ class AndroidTransactionProfilerTest {
7878

7979
@Test
8080
fun `profiler works only on api 21+`() {
81-
val buildInfo = mock<IBuildInfoProvider> {
81+
val buildInfo = mock<BuildInfoProvider> {
8282
whenever(it.sdkInfoVersion).thenReturn(Build.VERSION_CODES.KITKAT)
8383
}
8484
val profiler = fixture.getSut(context, buildInfo)

0 commit comments

Comments
 (0)