Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 8dc8912

Browse files
author
Manoel Aranda Neto
committed
Merge branch 'master' into feat/in_app_prefix
2 parents a2355e5 + ae54417 commit 8dc8912

File tree

14 files changed

+218
-16
lines changed

14 files changed

+218
-16
lines changed

sentry-android-core/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ android {
1313
defaultConfig {
1414
targetSdkVersion(Config.Android.targetSdkVersion)
1515
minSdkVersion(Config.Android.minSdkVersion)
16+
1617
javaCompileOptions {
1718
annotationProcessorOptions {
1819
includeCompileClasspath = true
@@ -60,6 +61,7 @@ android {
6061
}, this))
6162
}
6263
}
64+
6365
lintOptions {
6466
isWarningsAsErrors = true
6567
isCheckDependencies = true

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.sentry.core.ILogger;
88
import io.sentry.core.ISerializer;
99
import io.sentry.core.SentryEvent;
10+
import io.sentry.core.SentryLevel;
1011
import io.sentry.core.protocol.Device;
1112
import io.sentry.core.protocol.SentryId;
1213
import java.io.IOException;
@@ -38,6 +39,8 @@ private Gson provideGson() {
3839
Device.DeviceOrientation.class, new OrientationSerializerAdapter(logger))
3940
.registerTypeAdapter(
4041
Device.DeviceOrientation.class, new OrientationDeserializerAdapter(logger))
42+
.registerTypeAdapter(SentryLevel.class, new SentryLevelSerializerAdapter(logger))
43+
.registerTypeAdapter(SentryLevel.class, new SentryLevelDeserializerAdapter(logger))
4144
.registerTypeAdapterFactory(UnknownPropertiesTypeAdapterFactory.get())
4245
.create();
4346
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ private Long getMemorySize(ActivityManager.MemoryInfo memInfo) {
157157
// we can get some inspiration here
158158
// https://github.com/flutter/plugins/blob/master/packages/device_info/android/src/main/java/io/flutter/plugins/deviceinfo/DeviceInfoPlugin.java
159159
private Device getDevice() {
160+
// TODO: missing name and usable memory
161+
160162
Device device = new Device();
161163
device.setManufacturer(Build.MANUFACTURER);
162164
device.setBrand(Build.BRAND);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.sentry.android.core.adapters;
2+
3+
import static io.sentry.core.ILogger.log;
4+
5+
import com.google.gson.JsonDeserializationContext;
6+
import com.google.gson.JsonDeserializer;
7+
import com.google.gson.JsonElement;
8+
import com.google.gson.JsonParseException;
9+
import io.sentry.core.ILogger;
10+
import io.sentry.core.SentryLevel;
11+
import java.lang.reflect.Type;
12+
import java.util.Locale;
13+
14+
public class SentryLevelDeserializerAdapter implements JsonDeserializer<SentryLevel> {
15+
16+
private final ILogger logger;
17+
18+
public SentryLevelDeserializerAdapter(ILogger logger) {
19+
this.logger = logger;
20+
}
21+
22+
@Override
23+
public SentryLevel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
24+
throws JsonParseException {
25+
try {
26+
return json == null ? null : SentryLevel.valueOf(json.getAsString().toUpperCase(Locale.ROOT));
27+
} catch (Exception e) {
28+
log(logger, SentryLevel.ERROR, "Error when deserializing SentryLevel", e);
29+
}
30+
return null;
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.sentry.android.core.adapters;
2+
3+
import static io.sentry.core.ILogger.log;
4+
5+
import com.google.gson.JsonElement;
6+
import com.google.gson.JsonPrimitive;
7+
import com.google.gson.JsonSerializationContext;
8+
import com.google.gson.JsonSerializer;
9+
import io.sentry.core.ILogger;
10+
import io.sentry.core.SentryLevel;
11+
import java.lang.reflect.Type;
12+
import java.util.Locale;
13+
14+
public class SentryLevelSerializerAdapter implements JsonSerializer<SentryLevel> {
15+
16+
private final ILogger logger;
17+
18+
public SentryLevelSerializerAdapter(ILogger logger) {
19+
this.logger = logger;
20+
}
21+
22+
@Override
23+
public JsonElement serialize(SentryLevel src, Type typeOfSrc, JsonSerializationContext context) {
24+
try {
25+
return src == null ? null : new JsonPrimitive(src.name().toLowerCase(Locale.ROOT));
26+
} catch (Exception e) {
27+
log(logger, SentryLevel.ERROR, "Error when serializing SentryLevel", e);
28+
}
29+
return null;
30+
}
31+
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.google.gson.internal.LinkedTreeMap
66
import com.nhaarman.mockitokotlin2.mock
77
import io.sentry.core.DateUtils
88
import io.sentry.core.SentryEvent
9+
import io.sentry.core.SentryLevel
910
import io.sentry.core.protocol.Contexts
1011
import io.sentry.core.protocol.Device
1112
import java.io.StringWriter
@@ -200,6 +201,33 @@ class AndroidSerializerTest {
200201
assertEquals(Device.DeviceOrientation.LANDSCAPE, Device.DeviceOrientation.valueOf(orientation.toUpperCase())) // here too
201202
}
202203

204+
@Test
205+
fun `when serializing a SentryLevel, it should become a sentry level string`() {
206+
val sentryEvent = generateEmptySentryEvent()
207+
sentryEvent.eventId = null
208+
sentryEvent.timestamp = null
209+
sentryEvent.level = SentryLevel.DEBUG
210+
211+
val expected = "{\"level\":\"debug\"}"
212+
213+
val actual = serializeToString(sentryEvent)
214+
215+
assertEquals(expected, actual)
216+
}
217+
218+
@Test
219+
fun `when deserializing a sentry level string, it should become a SentryLevel`() {
220+
val sentryEvent = generateEmptySentryEvent()
221+
sentryEvent.eventId = null
222+
sentryEvent.timestamp = null
223+
224+
val jsonEvent = "{\"level\":\"debug\"}"
225+
226+
val actual = serializer.deserializeEvent(jsonEvent)
227+
228+
assertEquals(SentryLevel.DEBUG, actual.level)
229+
}
230+
203231
private fun generateEmptySentryEvent(): SentryEvent {
204232
return SentryEvent().apply {
205233
contexts = null

sentry-android-ndk/build.gradle.kts

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11

22
plugins {
33
id("com.android.library")
4+
kotlin("android")
5+
jacoco
46
}
57

68
android {
79
compileSdkVersion(Config.Android.compileSdkVersion)
810
buildToolsVersion(Config.Android.buildToolsVersion)
9-
compileOptions {
10-
sourceCompatibility = JavaVersion.VERSION_1_8
11-
targetCompatibility = JavaVersion.VERSION_1_8
12-
}
11+
1312
defaultConfig {
1413
targetSdkVersion(Config.Android.targetSdkVersion)
14+
minSdkVersion(Config.Android.minSdkVersionNdk)
15+
1516
javaCompileOptions {
1617
annotationProcessorOptions {
1718
includeCompileClasspath = true
1819
}
1920
}
2021

21-
minSdkVersion(Config.Android.minSdkVersionNdk)
22+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
23+
24+
versionName = "$version"
25+
2226
externalNativeBuild {
2327
val sentryNativeSrc = if (File("${project.projectDir}/sentry-native-local").exists()) {
2428
"sentry-native-local"
@@ -28,9 +32,10 @@ android {
2832
cmake {
2933
arguments.add(0, "-DANDROID_STL=c++_static")
3034
arguments.add(0, "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON")
31-
arguments.add(0, "-DSENTRY_NATIVE_SRC=" + sentryNativeSrc)
35+
arguments.add(0, "-DSENTRY_NATIVE_SRC=$sentryNativeSrc")
3236
}
3337
}
38+
3439
ndk {
3540
val platform = System.getenv("ABI")
3641
if (platform == null || platform.toLowerCase() == "all") {
@@ -40,14 +45,64 @@ android {
4045
}
4146
}
4247

43-
missingDimensionStrategy(Config.Flavors.dimension, Config.Flavors.production)
48+
// replace with https://issuetracker.google.com/issues/72050365 once released.
49+
libraryVariants.all {
50+
generateBuildConfigProvider?.configure {
51+
enabled = false
52+
}
53+
}
4454
}
4555

4656
externalNativeBuild {
4757
cmake {
4858
setPath("CMakeLists.txt")
4959
}
5060
}
61+
62+
buildTypes {
63+
getByName("debug")
64+
getByName("release") {
65+
consumerProguardFiles("proguard-rules.pro")
66+
}
67+
}
68+
69+
compileOptions {
70+
sourceCompatibility = JavaVersion.VERSION_1_8
71+
targetCompatibility = JavaVersion.VERSION_1_8
72+
}
73+
74+
// due https://github.com/gradle/gradle/issues/11083
75+
// kotlinOptions {
76+
// jvmTarget = JavaVersion.VERSION_1_8.toString()
77+
// }
78+
withGroovyBuilder {
79+
"kotlinOptions" {
80+
setProperty("jvmTarget", JavaVersion.VERSION_1_8.toString())
81+
}
82+
}
83+
84+
testOptions {
85+
animationsDisabled = true
86+
unitTests.apply {
87+
isReturnDefaultValues = true
88+
isIncludeAndroidResources = true
89+
all(KotlinClosure1<Any, Test>({
90+
(this as Test).also { testTask ->
91+
testTask.extensions
92+
.getByType(JacocoTaskExtension::class.java)
93+
.isIncludeNoLocationClasses = true
94+
}
95+
}, this))
96+
}
97+
}
98+
99+
lintOptions {
100+
isWarningsAsErrors = true
101+
isCheckDependencies = true
102+
103+
// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks.
104+
isCheckReleaseBuilds = false
105+
}
51106
}
52107

53108
dependencies {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# how to set proguard rules for ndk https://proandroiddev.com/debugging-native-crashes-in-android-apps-2b86fd7113d8

sentry-android/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ android {
99
defaultConfig {
1010
targetSdkVersion(Config.Android.targetSdkVersion)
1111
minSdkVersion(Config.Android.minSdkVersionNdk)
12+
13+
versionName = "$version"
1214
}
1315

1416
compileOptions {

sentry-core/src/main/java/io/sentry/core/Sentry.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,35 @@ public static SentryId captureException(Throwable throwable) {
7474
return getCurrentHub().captureException(throwable);
7575
}
7676

77-
public void addBreadcrumb(Breadcrumb breadcrumb) {
77+
public static void addBreadcrumb(Breadcrumb breadcrumb) {
7878
getCurrentHub().addBreadcrumb(breadcrumb);
7979
}
8080

81-
public SentryId getLastEventId() {
81+
public static SentryId getLastEventId() {
8282
return getCurrentHub().getLastEventId();
8383
}
8484

85-
public void pushScope() {
85+
public static void pushScope() {
8686
getCurrentHub().pushScope();
8787
}
8888

89-
public void popScope() {
89+
public static void popScope() {
9090
getCurrentHub().popScope();
9191
}
9292

93-
public void withScope(ScopeCallback callback) {
93+
public static void withScope(ScopeCallback callback) {
9494
getCurrentHub().withScope(callback);
9595
}
9696

97-
public void configureScope(ScopeCallback callback) {
97+
public static void configureScope(ScopeCallback callback) {
9898
getCurrentHub().configureScope(callback);
9999
}
100100

101-
public void bindClient(SentryClient client) {
101+
public static void bindClient(SentryClient client) {
102102
getCurrentHub().bindClient(client);
103103
}
104104

105-
public void flush(int timeoutMills) {
105+
public static void flush(int timeoutMills) {
106106
getCurrentHub().flush(timeoutMills);
107107
}
108108

0 commit comments

Comments
 (0)