Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion backtrace-library/src/main/cpp/backends/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ void AddAttribute(jstring key, jstring value) {
#endif
}

void AddAttachment(jstring attachment) {
#ifdef CRASHPAD_BACKEND
AddAttachmentCrashpad(attachment);
#else
__android_log_print(ANDROID_LOG_ERROR, "Backtrace-Android",
"AddAttachment not supported on this backend");
#endif
}

void Disable() {
#ifdef CRASHPAD_BACKEND
DisableCrashpad();
Expand All @@ -116,4 +125,4 @@ void Disable() {
"Disable not supported on this backend");
#endif
}
}
}
23 changes: 23 additions & 0 deletions backtrace-library/src/main/cpp/backends/crashpad-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,29 @@ void AddAttributeCrashpad(jstring key, jstring value) {
env->ReleaseStringUTFChars(value, crashpadValue);
}

void AddAttachmentCrashpad(jstring jattachment) {
if (initialized == false || client == nullptr) {
__android_log_print(ANDROID_LOG_WARN, "Backtrace-Android",
"Crashpad integration isn't available. Please initialize the Crashpad integration first.");
return;
}
JNIEnv *env = GetJniEnv();
if (env == nullptr) {
__android_log_print(ANDROID_LOG_ERROR, "Backtrace-Android", "Unable to obtain JNI environment.");
return;
}

if (jattachment) {
jboolean isCopy;
const char *attachment = env->GetStringUTFChars(jattachment, &isCopy);

if (attachment != nullptr) {
client->AddAttachment(attachment);
env->ReleaseStringUTFChars(jattachment, attachment);
}
}
}

void DisableCrashpad() {
if (database == nullptr) {
__android_log_print(ANDROID_LOG_ERROR, "Backtrace-Android",
Expand Down
8 changes: 7 additions & 1 deletion backtrace-library/src/main/cpp/backtrace-native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ Java_backtraceio_library_BacktraceDatabase_addAttribute(JNIEnv *env, jobject thi
AddAttribute(name, value);
}

JNIEXPORT void JNICALL
Java_backtraceio_library_BacktraceDatabase_addAttachment(JNIEnv *env, jobject thiz,
jstring jattachment) {
AddAttachment(jattachment);
}

JNIEXPORT void JNICALL
Java_backtraceio_library_base_BacktraceBase_dumpWithoutCrash__Ljava_lang_String_2(JNIEnv *env,
jobject thiz,
Expand All @@ -186,4 +192,4 @@ Java_backtraceio_library_nativeCalls_BacktraceCrashHandler_handleCrash(JNIEnv *e
jobjectArray args) {
return CaptureCrash(args);
}
}
}
1 change: 1 addition & 0 deletions backtrace-library/src/main/cpp/include/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ bool CaptureCrash(jobjectArray args);
void DumpWithoutCrash(jstring message, jboolean set_main_thread_as_faulting_thread);

void AddAttribute(jstring key, jstring value);
void AddAttachment(jstring jattachment);

void Disable();
}
Expand Down
1 change: 1 addition & 0 deletions backtrace-library/src/main/cpp/include/crashpad-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ bool CaptureCrashCrashpad(jobjectArray args);
void DumpWithoutCrashCrashpad(jstring message, jboolean set_main_thread_as_faulting_thread);

void AddAttributeCrashpad(jstring key, jstring value);
void AddAttachmentCrashpad(jstring jattachment);

void DisableCrashpad();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public class BacktraceDatabase implements Database {
*/
public native void addAttribute(String name, String value);

/**
* Add a file attachment to native reports.
*
* @param attachmentPath the file path to attach to native reports
*/
public native void addAttachment(String attachmentPath);

/**
* Disable Backtrace-native integration
*/
Expand Down Expand Up @@ -255,6 +262,14 @@ public Boolean addNativeAttribute(String key, Object value) {
return true;
}

public Boolean addNativeAttachment(String attachmentPath) {
if (!_enabledNativeIntegration || attachmentPath == null) {
return false;
}
addAttachment(attachmentPath);
return true;
}

public void start() {
if (databaseSettings == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ public BacktraceBase(Context context, BacktraceCredentials credentials) {
* @param context context of current state of the application
* @param credentials Backtrace credentials to access Backtrace API
* @param attachments File attachment paths to consider for reports
* @note Attachments for native crashes must be specified here, and cannot be
* changed during runtime
*/
public BacktraceBase(Context context, BacktraceCredentials credentials, List<String> attachments) {
this(context, credentials, (Database) null, attachments);
Expand All @@ -127,8 +125,6 @@ public BacktraceBase(Context context, BacktraceCredentials credentials, Map<Stri
* @param credentials Backtrace credentials to access Backtrace API
* @param attributes additional information about current application
* @param attachments File attachment paths to consider for reports
* @note Attachments for native crashes must be specified here, and cannot be
* changed during runtime
*/
public BacktraceBase(
Context context,
Expand Down Expand Up @@ -157,8 +153,6 @@ public BacktraceBase(
* @param credentials Backtrace credentials to access Backtrace API
* @param databaseSettings Backtrace database settings
* @param attachments File attachment paths to consider for reports
* @note Attachments for native crashes must be specified here, and cannot be
* changed during runtime
*/
public BacktraceBase(
Context context,
Expand Down Expand Up @@ -192,8 +186,6 @@ public BacktraceBase(
* @param databaseSettings Backtrace database settings
* @param attributes additional information about current application
* @param attachments File attachment paths to consider for reports
* @note Attachments for native crashes must be specified here, and cannot be
* changed during runtime
*/
public BacktraceBase(
Context context,
Expand Down Expand Up @@ -222,8 +214,6 @@ public BacktraceBase(Context context, BacktraceCredentials credentials, Database
* @param credentials Backtrace credentials to access Backtrace API
* @param database Backtrace database
* @param attachments File attachment paths to consider for reports
* @note Attachments for native crashes must be specified here, and cannot be
* changed during runtime
*/
public BacktraceBase(
Context context, BacktraceCredentials credentials, Database database, List<String> attachments) {
Expand Down Expand Up @@ -251,8 +241,6 @@ public BacktraceBase(
* @param database Backtrace database
* @param attributes additional information about current application
* @param attachments File attachment paths to consider for reports
* @note Attachments for native crashes must be specified here, and cannot be
* changed during runtime
*/
public BacktraceBase(
Context context,
Expand Down Expand Up @@ -336,6 +324,10 @@ public void enableProguard() {
*/
public void addAttachment(String attachmentPath) {
this.attachments.add(attachmentPath);

if (database != null) {
database.addNativeAttachment(attachmentPath);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,12 @@ Boolean setupNativeIntegration(
* @return true, if attribute was added to the native report. Otherwise false.
*/
Boolean addNativeAttribute(String key, Object value);

/**
* If the native integration is enabled then adds a file attachment to be included
* with native crash reports.
* @param attachmentPath the file path to attach to native reports.
* @return whether the attachment was added to the native report or not.
*/
Boolean addNativeAttachment(String attachmentPath);
}
Loading