Skip to content

Commit

Permalink
SkipNul, remove additional unique event and make application cache th…
Browse files Browse the repository at this point in the history
…read safe
  • Loading branch information
Konrad Dysput committed Nov 7, 2024
1 parent 330769b commit ef6cd02
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package backtraceio.library;

import android.content.Context;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import backtraceio.library.common.ApplicationMetadataCache;

@RunWith(AndroidJUnit4.class)
public class ApplicationCacheTest {
private Context context;

@Before
public void setUp() {
context = InstrumentationRegistry.getInstrumentation().getContext();
// prepare instance
ApplicationMetadataCache.getInstance(context);
}

@Test
public void shouldCorrectlyRetrieveApplicationName() {
ApplicationMetadataCache cache = ApplicationMetadataCache.getInstance(context);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ApplicationMetadataCache {

private static final transient String LOG_TAG = ApplicationMetadataCache.class.getSimpleName();

private static ApplicationMetadataCache instance;
private static volatile ApplicationMetadataCache instance;

/**
* Cached application name
Expand All @@ -36,7 +36,11 @@ public class ApplicationMetadataCache {
*/
public static ApplicationMetadataCache getInstance(Context context) {
if (instance == null) {
instance = new ApplicationMetadataCache(context);
synchronized (ApplicationMetadataCache.class) {
if (instance == null) {
instance = new ApplicationMetadataCache(context);
}
}
}
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public static ReportDataAttributes getReportAttributes(Map<String, Object> attri
* Divide custom user attributes into primitive and complex attributes and add to this object
*
* @param attributes client's attributes
* @param skipNullable define attributes behavior on nullable value. By default all nullable attributes
* @param skipNull define attributes behavior on nullable value. By default all nullable attributes
* will be included in the report. For some features like metrics, we don't want to send
* nullable values, because they can generate invalid behavior/incorrect information.
* @return Report data attributes divided into attributes and annotations
*/
public static ReportDataAttributes getReportAttributes(Map<String, Object> attributes, boolean skipNullable) {
public static ReportDataAttributes getReportAttributes(Map<String, Object> attributes, boolean skipNull) {
ReportDataAttributes reportDataAttributes = new ReportDataAttributes();

if (attributes == null) {
Expand All @@ -36,7 +36,7 @@ public static ReportDataAttributes getReportAttributes(Map<String, Object> attri
String key = entry.getKey();
Object value = entry.getValue();
if (value == null) {
if (!skipNullable) {
if (!skipNull) {
reportDataAttributes.addAttribute(key, null);
}
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void enable(BacktraceMetricsSettings settings, String uniqueEventName) {
ApplicationMetadataCache applicationMetadata = ApplicationMetadataCache.getInstance(this.getContext());
this.applicationName = applicationMetadata.getApplicationName();
this.applicationVersion = applicationMetadata.getApplicationVersion();
setStartupUniqueEventName(uniqueEventName);

final long startMetricsSetup = DebugHelper.getCurrentTimeMillis();

setStartupUniqueEventName(uniqueEventName);
Expand Down

0 comments on commit ef6cd02

Please sign in to comment.