Skip to content

Commit

Permalink
Fix: apply device non static data only if not hard crash
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Apr 14, 2021
1 parent 4bc4353 commit d741298
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
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) {
// TODO: missing usable memory

Device device = new Device();
Expand All @@ -314,12 +316,15 @@ private void setArchitectures(final @NotNull Device device) {
device.setModelId(Build.ID);
setArchitectures(device);

// likely to be applied only if applyScopeData
Intent batteryIntent = getBatteryIntent();
if (batteryIntent != null) {
device.setBatteryLevel(getBatteryLevel(batteryIntent));
device.setCharging(isCharging(batteryIntent));
device.setBatteryTemperature(getBatteryTemperature(batteryIntent));
}

// likely to be applied only if applyScopeData
Boolean connected;
switch (ConnectivityChecker.getConnectionStatus(context, logger)) {
case NOT_CONNECTED:
Expand Down Expand Up @@ -347,12 +352,15 @@ 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) {
device.setFreeMemory(memInfo.availMem);
device.setLowMemory(memInfo.lowMemory);
}
// there are runtime.totalMemory() and runtime.freeMemory(), but I kept the same for
// compatibility
}

// likely to be applied only if applyScopeData
// this way of getting the size of storage might be problematic for storages bigger than 2GB
// check the use of https://developer.android.com/reference/java/io/File.html#getFreeSpace%28%29
File internalStorageFile = context.getExternalFilesDir(null);
Expand All @@ -362,6 +370,7 @@ private void setArchitectures(final @NotNull Device device) {
device.setFreeStorage(getUnusedInternalStorage(internalStorageStat));
}

// likely to be applied only if applyScopeData
StatFs externalStorageStat = getExternalStorageStat(internalStorageFile);
if (externalStorageStat != null) {
device.setExternalStorageSize(getTotalExternalStorage(externalStorageStat));
Expand All @@ -376,7 +385,9 @@ private void setArchitectures(final @NotNull Device device) {
device.setScreenDpi(displayMetrics.densityDpi);
}

// likely to be applied only if applyScopeData
device.setBootTime(getBootTime());

device.setTimezone(getTimeZone());

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

// likely to be applied only if applyScopeData
if (device.getConnectionType() == null) {
// wifi, ethernet or cellular, null if none
device.setConnectionType(
Expand Down

0 comments on commit d741298

Please sign in to comment.