Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: do not set free memory and is low memory fields when it's a NDK hard crash #1399

Merged
merged 8 commits into from Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
* Fix: set correct transaction status for unhandled exceptions in SentryTracingFilter (#1406)
* Fix: handle network errors in SentrySpanClientHttpRequestInterceptor (#1407)
* Fix: set scope on transaction (#1409)
* Fix: Do not set free memory and is low memory fields when it's a NDK hard crash (#1399)
* Fix: Apply user from the scope to transaction (#1424)
* Fix: Pass maxBreadcrumbs config. to sentry-native (#1425)

Expand Down
Expand Up @@ -139,7 +139,9 @@ public DefaultAndroidEventProcessor(
@Override
public @NotNull SentryEvent process(
final @NotNull SentryEvent event, final @Nullable Object hint) {
if (ApplyScopeUtils.shouldApplyScopeData(hint)) {
final boolean applyScopeData = ApplyScopeUtils.shouldApplyScopeData(hint);

if (applyScopeData) {
processNonCachedEvent(event);
} else {
logger.log(
Expand All @@ -157,7 +159,7 @@ public DefaultAndroidEventProcessor(
}

if (event.getContexts().getDevice() == null) {
event.getContexts().setDevice(getDevice());
event.getContexts().setDevice(getDevice(applyScopeData));
}

mergeOS(event);
Expand Down Expand Up @@ -302,7 +304,7 @@ private void setArchitectures(final @NotNull Device device) {

// we can get some inspiration here
// https://github.com/flutter/plugins/blob/master/packages/device_info/android/src/main/java/io/flutter/plugins/deviceinfo/DeviceInfoPlugin.java
private @NotNull Device getDevice() {
private @NotNull Device getDevice(final boolean applyScopeData) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Maybe we can find a better name for applyScopeData. We use it to control whether we add free and low memory. The name could reflect that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the naming cant be related to free memory, because the same flag would be used to every nonstatic data that cant be applied after the restart, so it's pretty much how we call on every integration that has such check, applyScopeData

// TODO: missing usable memory

Device device = new Device();
Expand All @@ -320,6 +322,7 @@ private void setArchitectures(final @NotNull Device device) {
device.setCharging(isCharging(batteryIntent));
device.setBatteryTemperature(getBatteryTemperature(batteryIntent));
}

Boolean connected;
switch (ConnectivityChecker.getConnectionStatus(context, logger)) {
case NOT_CONNECTED:
Expand Down Expand Up @@ -347,8 +350,10 @@ private void setArchitectures(final @NotNull Device device) {
if (memInfo != null) {
// in bytes
device.setMemorySize(getMemorySize(memInfo));
device.setFreeMemory(memInfo.availMem);
device.setLowMemory(memInfo.lowMemory);
if (applyScopeData) {
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
device.setFreeMemory(memInfo.availMem);
device.setLowMemory(memInfo.lowMemory);
}
// there are runtime.totalMemory() and runtime.freeMemory(), but I kept the same for
// compatibility
}
Expand Down Expand Up @@ -377,6 +382,7 @@ private void setArchitectures(final @NotNull Device device) {
}

device.setBootTime(getBootTime());

device.setTimezone(getTimeZone());

if (device.getId() == null) {
Expand All @@ -385,6 +391,7 @@ private void setArchitectures(final @NotNull Device device) {
if (device.getLanguage() == null) {
device.setLanguage(Locale.getDefault().toString()); // eg en_US
}

if (device.getConnectionType() == null) {
// wifi, ethernet or cellular, null if none
device.setConnectionType(
Expand Down
Expand Up @@ -290,4 +290,26 @@ class DefaultAndroidEventProcessorTest {
assertSame(osNoName, (event.contexts["os_1"] as OperatingSystem))
assertEquals("Android", event.contexts.operatingSystem!!.name)
}

@Test
fun `When hint is Cached, memory data should not be applied`() {
val sut = fixture.getSut(context)

var event = SentryEvent()
event = sut.process(event, CachedEvent())

assertNull(event.contexts.device!!.freeMemory)
assertNull(event.contexts.device!!.isLowMemory)
}

@Test
fun `When hint is not Cached, memory data should be applied`() {
val sut = fixture.getSut(context)

var event = SentryEvent()
event = sut.process(event, null)

assertNotNull(event.contexts.device!!.freeMemory)
assertNotNull(event.contexts.device!!.isLowMemory)
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
}
}