Skip to content

Commit

Permalink
Merge 0b10611 into 897fb06
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Jun 20, 2018
2 parents 897fb06 + 0b10611 commit f9b2c54
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 402 deletions.
26 changes: 26 additions & 0 deletions sdk/src/androidTest/java/com/bugsnag/android/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
Expand Down Expand Up @@ -334,4 +335,29 @@ public void testDeviceDataSummary() {
assertNotEquals(client.getDeviceDataSummary(), deviceData);
}

@Test
public void testPopulateDeviceMetadata() {
Client client = generateClient();
MetaData metaData = new MetaData();
Map<String, Object> app = metaData.getTab("device");
assertEquals(0, app.size());

client.populateDeviceMetaData(metaData);
assertEquals(14, app.size());

assertNotNull(app.get("batteryLevel"));
assertNotNull(app.get("charging"));
assertNotNull(app.get("locationStatus"));
assertNotNull(app.get("networkAccess"));
assertNotNull(app.get("time"));
assertNotNull(app.get("brand"));
assertNotNull(app.get("apiLevel"));
assertNotNull(app.get("osBuild"));
assertNotNull(app.get("locale"));
assertNotNull(app.get("screenDensity"));
assertNotNull(app.get("dpi"));
assertNotNull(app.get("emulator"));
assertNotNull(app.get("screenResolution"));
assertNotNull(app.get("cpuAbi"));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bugsnag.android;

import static com.bugsnag.android.BugsnagTestUtils.generateClient;
import static com.bugsnag.android.BugsnagTestUtils.streamableToJson;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -11,6 +12,7 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -25,7 +27,13 @@ public class DeviceDataSummaryTest {

@Before
public void setUp() throws Exception {
deviceData = new DeviceDataSummary();
DeviceDataCollector deviceDataCollector = new DeviceDataCollector(generateClient());
deviceData = deviceDataCollector.generateDeviceDataSummary();
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
Expand Down
11 changes: 9 additions & 2 deletions sdk/src/androidTest/java/com/bugsnag/android/DeviceDataTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bugsnag.android;

import static com.bugsnag.android.BugsnagTestUtils.generateClient;
import static com.bugsnag.android.BugsnagTestUtils.getSharedPrefs;
import static com.bugsnag.android.BugsnagTestUtils.streamableToJson;
import static org.junit.Assert.assertEquals;
Expand All @@ -13,6 +14,7 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -28,8 +30,13 @@ public class DeviceDataTest {

@Before
public void setUp() throws Exception {
SharedPreferences sharedPref = getSharedPrefs(InstrumentationRegistry.getContext());
deviceData = new DeviceData(InstrumentationRegistry.getContext(), sharedPref);
DeviceDataCollector deviceDataCollector = new DeviceDataCollector(generateClient());
deviceData = deviceDataCollector.generateDeviceData();
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
Expand Down
11 changes: 9 additions & 2 deletions sdk/src/androidTest/java/com/bugsnag/android/ErrorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bugsnag.android;

import static com.bugsnag.android.BugsnagTestUtils.generateClient;
import static com.bugsnag.android.BugsnagTestUtils.generateSession;
import static com.bugsnag.android.BugsnagTestUtils.generateSessionTracker;
import static com.bugsnag.android.BugsnagTestUtils.streamableToJson;
Expand All @@ -18,6 +19,7 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -44,6 +46,11 @@ public void setUp() throws Exception {
error = new Error.Builder(config, exception, null).build();
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testShouldIgnoreClass() {
config.setIgnoreClasses(new String[]{"java.io.IOException"});
Expand Down Expand Up @@ -375,8 +382,8 @@ public void testErrorMetaData() {

@Test
public void testSetDeviceId() throws Throwable {
Context context = InstrumentationRegistry.getContext();
DeviceData deviceData = new DeviceData(context, BugsnagTestUtils.getSharedPrefs(context));
DeviceDataCollector deviceDataCollector = new DeviceDataCollector(generateClient());
DeviceData deviceData = deviceDataCollector.generateDeviceData();
error.setDeviceData(deviceData);
assertEquals(deviceData, error.getDeviceData());

Expand Down
32 changes: 21 additions & 11 deletions sdk/src/main/java/com/bugsnag/android/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ public class Client extends Observable implements Observer {

@NonNull
protected final Configuration config;
private final Context appContext;
final Context appContext;

@NonNull
protected final AppData appData;

@NonNull
protected final DeviceData deviceData;

DeviceDataCollector deviceDataCollector;

@NonNull
final Breadcrumbs breadcrumbs;

Expand All @@ -83,7 +85,7 @@ public class Client extends Observable implements Observer {

private final EventReceiver eventReceiver;
final SessionTracker sessionTracker;
private SharedPreferences sharedPref;
SharedPreferences sharedPrefs;

/**
* Initialize a Bugsnag client
Expand Down Expand Up @@ -143,10 +145,11 @@ public Client(@NonNull Context androidContext, @NonNull Configuration configurat
eventReceiver = new EventReceiver(this);

// Set up and collect constant app and device diagnostics
sharedPref = appContext.getSharedPreferences(SHARED_PREF_KEY, Context.MODE_PRIVATE);
sharedPrefs = appContext.getSharedPreferences(SHARED_PREF_KEY, Context.MODE_PRIVATE);

deviceDataCollector = new DeviceDataCollector(this);
appData = new AppData(appContext, config, sessionTracker);
deviceData = new DeviceData(appContext, sharedPref);
deviceData = deviceDataCollector.generateDeviceData();

// Set up breadcrumbs
breadcrumbs = new Breadcrumbs();
Expand All @@ -156,9 +159,9 @@ public Client(@NonNull Context androidContext, @NonNull Configuration configurat

if (config.getPersistUserBetweenSessions()) {
// Check to see if a user was stored in the SharedPreferences
user.setId(sharedPref.getString(USER_ID_KEY, deviceData.getId()));
user.setName(sharedPref.getString(USER_NAME_KEY, null));
user.setEmail(sharedPref.getString(USER_EMAIL_KEY, null));
user.setId(sharedPrefs.getString(USER_ID_KEY, deviceData.getId()));
user.setName(sharedPrefs.getString(USER_NAME_KEY, null));
user.setEmail(sharedPrefs.getString(USER_EMAIL_KEY, null));
} else {
user.setId(deviceData.getId());
}
Expand Down Expand Up @@ -573,13 +576,18 @@ public AppDataSummary getAppDataSummary() {
@NonNull
@InternalApi
public DeviceData getDeviceData() {
return new DeviceData(appContext, sharedPref);
return deviceDataCollector.generateDeviceData();
}

@NonNull
@InternalApi
public DeviceDataSummary getDeviceDataSummary() {
return new DeviceDataSummary();
return deviceDataCollector.generateDeviceDataSummary();
}

@InternalApi
public void populateDeviceMetaData(@NonNull MetaData metaData) {
deviceDataCollector.populateDeviceMetaData(metaData);
}

/**
Expand Down Expand Up @@ -930,12 +938,14 @@ void notify(@NonNull Error error,
}

// Capture the state of the app and device and attach diagnostics to the error
DeviceData errorDeviceData = deviceDataCollector.generateDeviceData();
error.setDeviceData(errorDeviceData);
deviceDataCollector.populateDeviceMetaData(error.getMetaData());

error.setAppData(appData);
error.setDeviceData(deviceData);

// add additional info that belongs in metadata
appData.addAppMetaData(error.getMetaData());
deviceData.addDeviceMetaData(error.getMetaData());

// Attach breadcrumbs to the error
error.setBreadcrumbs(breadcrumbs);
Expand Down

0 comments on commit f9b2c54

Please sign in to comment.