Skip to content

Commit

Permalink
fix implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Oct 20, 2020
1 parent 10669a9 commit 646859d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ public static void deliverReport(@Nullable byte[] releaseStageBytes,
}

private static String getApiKeyFromEventPath(String eventPath, ImmutableConfig config) {
int start = eventPath.indexOf("_");
int start = eventPath.indexOf("_") + 1;
int end = eventPath.lastIndexOf(".");

if (end > start && start != -1) {
if (end > start && start != 0) {
return eventPath.substring(start, end);
}
return config.getApiKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,17 @@ class EventFilenameTest {
"_683c6b92-b325-4987-80ad-77086509ca1e.json")
assertEquals("0000111122223333aaaabbbbcccc9999", eventStore.getApiKeyFromFilename(file))
}

@Test
fun apiKeyFromLegacyNdkFilename() {
`when`(file.name).thenReturn("1603191800142_7e1041e0-7f37-4cfb-9d29-0aa6930bbb72not-jvm.json")
assertNull(eventStore.getApiKeyFromFilename(file))
}

@Test
fun apiKeyFromNdkFilename() {
`when`(file.name).thenReturn("1603191800142_5d1ec8bd39a74caa1267142706a7fb20_" +
"7e1041e0-7f37-4cfb-9d29-0aa6930bbb72not-jvm.json")
assertEquals("5d1ec8bd39a74caa1267142706a7fb20", eventStore.getApiKeyFromFilename(file))
}
}
11 changes: 5 additions & 6 deletions bugsnag-plugin-android-ndk/src/main/jni/bugsnag_ndk.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,21 @@ JNIEXPORT void JNICALL Java_com_bugsnag_android_ndk_NativeBridge_install(
}

// populate metadata from Java layer
bugsnag_event event = bugsnag_env->next_event;
bsg_populate_event(env, &event);
bsg_populate_event(env, &bugsnag_env->next_event);
time(&bugsnag_env->start_time);
if (event.app.in_foreground) {
if (bugsnag_env->next_event.app.in_foreground) {
bugsnag_env->foreground_start_time = bugsnag_env->start_time;
}

// If set, save os build info to report info header
if (strlen(event.device.os_build) > 0) {
if (strlen(bugsnag_env->next_event.device.os_build) > 0) {
bsg_strncpy_safe(bugsnag_env->report_header.os_build,
event.device.os_build,
bugsnag_env->next_event.device.os_build,
sizeof(bugsnag_env->report_header.os_build));
}

const char *api_key = (*env)->GetStringUTFChars(env, _api_key, 0);
bugsnag_event_set_api_key(&event, (char *) api_key);
bsg_strncpy_safe(bugsnag_env->next_event.api_key, (char *) api_key, sizeof(bugsnag_env->next_event.api_key));
(*env)->ReleaseStringUTFChars(env, _api_key, api_key);

bsg_global_env = bugsnag_env;
Expand Down

0 comments on commit 646859d

Please sign in to comment.