Skip to content

Commit

Permalink
Merge pull request #224 from bugsnag/session-tracking-manifest-config
Browse files Browse the repository at this point in the history
Parse manifest meta-data for auto capture sessions config
  • Loading branch information
fractalwrench authored Jan 17, 2018
2 parents cbdd3da + 87b87de commit de0ef73
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
3 changes: 3 additions & 0 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<meta-data
android:name="com.bugsnag.android.PERSIST_USER_BETWEEN_SESSIONS"
android:value="${bugsnagPersistUserBetweenSessions}" />
<meta-data
android:name="com.bugsnag.android.AUTO_CAPTURE_SESSIONS"
android:value="false" />

</application>

Expand Down
26 changes: 10 additions & 16 deletions sdk/src/androidTest/java/com/bugsnag/android/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
import org.junit.runner.RunWith;

import static com.bugsnag.android.BugsnagTestUtils.getSharedPrefs;
import static com.bugsnag.android.Client.MF_APP_VERSION;
import static com.bugsnag.android.Client.MF_BUILD_UUID;
import static com.bugsnag.android.Client.MF_ENABLE_EXCEPTION_HANDLER;
import static com.bugsnag.android.Client.MF_ENDPOINT;
import static com.bugsnag.android.Client.MF_PERSIST_USER_BETWEEN_SESSIONS;
import static com.bugsnag.android.Client.MF_RELEASE_STAGE;
import static com.bugsnag.android.Client.MF_SEND_THREADS;
import static com.bugsnag.android.Client.MF_SESSIONS_ENDPOINT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

Expand Down Expand Up @@ -189,14 +181,15 @@ public void testFullManifestConfig() {
String sessionEndpoint = "http://session-example.com";

Bundle data = new Bundle();
data.putString(MF_BUILD_UUID, buildUuid);
data.putString(MF_APP_VERSION, appVersion);
data.putString(MF_RELEASE_STAGE, releaseStage);
data.putString(MF_SESSIONS_ENDPOINT, sessionEndpoint);
data.putString(MF_ENDPOINT, endpoint);
data.putBoolean(MF_SEND_THREADS, false);
data.putBoolean(MF_ENABLE_EXCEPTION_HANDLER, false);
data.putBoolean(MF_PERSIST_USER_BETWEEN_SESSIONS, true);
data.putString("com.bugsnag.android.BUILD_UUID", buildUuid);
data.putString("com.bugsnag.android.APP_VERSION", appVersion);
data.putString("com.bugsnag.android.RELEASE_STAGE", releaseStage);
data.putString("com.bugsnag.android.SESSIONS_ENDPOINT", sessionEndpoint);
data.putString("com.bugsnag.android.ENDPOINT", endpoint);
data.putBoolean("com.bugsnag.android.SEND_THREADS", false);
data.putBoolean("com.bugsnag.android.ENABLE_EXCEPTION_HANDLER", false);
data.putBoolean("com.bugsnag.android.PERSIST_USER_BETWEEN_SESSIONS", true);
data.putBoolean("com.bugsnag.android.AUTO_CAPTURE_SESSIONS", true);

Configuration newConfig = Client.populateConfigFromManifest(new Configuration("api-key"), data);
assertEquals(buildUuid, newConfig.getBuildUUID());
Expand All @@ -207,6 +200,7 @@ public void testFullManifestConfig() {
assertEquals(false, newConfig.getSendThreads());
assertEquals(false, newConfig.getEnableExceptionHandler());
assertEquals(true, newConfig.getPersistUserBetweenSessions());
assertEquals(true, newConfig.shouldAutoCaptureSessions());
}

}
2 changes: 2 additions & 0 deletions sdk/src/main/java/com/bugsnag/android/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class Client extends Observable implements Observer {
static final String MF_SEND_THREADS = BUGSNAG_NAMESPACE + ".SEND_THREADS";
static final String MF_ENABLE_EXCEPTION_HANDLER = BUGSNAG_NAMESPACE + ".ENABLE_EXCEPTION_HANDLER";
static final String MF_PERSIST_USER_BETWEEN_SESSIONS = BUGSNAG_NAMESPACE + ".PERSIST_USER_BETWEEN_SESSIONS";
static final String MF_AUTO_CAPTURE_SESSIONS = BUGSNAG_NAMESPACE + ".AUTO_CAPTURE_SESSIONS";


@NonNull
Expand Down Expand Up @@ -331,6 +332,7 @@ static Configuration populateConfigFromManifest(@NonNull Configuration config, @

config.setSendThreads(data.getBoolean(MF_SEND_THREADS, true));
config.setPersistUserBetweenSessions(data.getBoolean(MF_PERSIST_USER_BETWEEN_SESSIONS, false));
config.setAutoCaptureSessions(data.getBoolean(MF_AUTO_CAPTURE_SESSIONS, false));
config.setEnableExceptionHandler(data.getBoolean(MF_ENABLE_EXCEPTION_HANDLER, true));
return config;
}
Expand Down

0 comments on commit de0ef73

Please sign in to comment.