33#include < string>
44#include < unistd.h>
55#include " client/crashpad_client.h"
6+ #include " client/crashpad_info.h"
67#include " client/crash_report_database.h"
78#include " client/settings.h"
9+ #include " client/simple_string_dictionary.h"
810#include " include/bugsplat_utils.h"
911
1012using namespace base ;
1113using namespace crashpad ;
1214using namespace std ;
1315
16+ static SimpleStringDictionary* g_simple_annotations = nullptr ;
17+
1418// Forward declarations of JNI functions
1519extern " C" JNIEXPORT jboolean JNICALL
1620Java_com_bugsplat_android_BugSplatBridge_jniInitBugSplat (JNIEnv *env, jclass clazz,
@@ -25,6 +29,14 @@ Java_com_bugsplat_android_BugSplatBridge_jniInitBugSplat(JNIEnv *env, jclass cla
2529extern " C" JNIEXPORT void JNICALL
2630Java_com_bugsplat_android_BugSplatBridge_jniCrash (JNIEnv *env, jclass clazz);
2731
32+ extern " C" JNIEXPORT void JNICALL
33+ Java_com_bugsplat_android_BugSplatBridge_jniSetAttribute (JNIEnv *env, jclass clazz,
34+ jstring key, jstring value);
35+
36+ extern " C" JNIEXPORT void JNICALL
37+ Java_com_bugsplat_android_BugSplatBridge_jniRemoveAttribute (JNIEnv *env, jclass clazz,
38+ jstring key);
39+
2840// JNI implementation
2941extern " C" JNIEXPORT jboolean JNICALL
3042Java_com_bugsplat_android_BugSplatBridge_jniInitBugSplat (JNIEnv *env, jclass clazz,
@@ -50,7 +62,7 @@ Java_com_bugsplat_android_BugSplatBridge_jniInitBugSplat(JNIEnv *env, jclass cla
5062 string url = " https://" + databaseString + " .bugsplat.com/post/bp/crash/crashpad.php" ;
5163 __android_log_print (ANDROID_LOG_INFO, " bugsplat-android" , " Url: %s" , url.c_str ());
5264
53- // Crashpad annotations
65+ // Crashpad annotations (passed to StartHandlerAtCrash for upload metadata)
5466 map<string, string> annotations;
5567 annotations[" format" ] = " minidump" ;
5668 annotations[" database" ] = databaseString;
@@ -60,6 +72,15 @@ Java_com_bugsplat_android_BugSplatBridge_jniInitBugSplat(JNIEnv *env, jclass cla
6072 // Create custom attributes
6173 createAttributes (env, attributes_map, annotations);
6274
75+ // Register a SimpleStringDictionary on CrashpadInfo for runtime-updatable annotations.
76+ // Unlike the annotations map passed to StartHandlerAtCrash, these live in process memory
77+ // and can be modified at any time — the crash handler reads them directly at crash time.
78+ g_simple_annotations = new SimpleStringDictionary ();
79+ for (const auto & entry : annotations) {
80+ g_simple_annotations->SetKeyValue (entry.first , entry.second );
81+ }
82+ CrashpadInfo::GetCrashpadInfo ()->set_simple_annotations (g_simple_annotations);
83+
6384 // Crashpad arguments
6485 vector<string> arguments;
6586 arguments.emplace_back (" --no-rate-limit" );
@@ -147,6 +168,38 @@ void createAttributes(JNIEnv *env, jobject attributes_map, map<string, string>&
147168 env->DeleteLocalRef (entrySet);
148169}
149170
171+ extern " C" JNIEXPORT void JNICALL
172+ Java_com_bugsplat_android_BugSplatBridge_jniSetAttribute (JNIEnv *env, jclass clazz,
173+ jstring key, jstring value) {
174+ if (g_simple_annotations == nullptr ) {
175+ __android_log_print (ANDROID_LOG_WARN, " bugsplat-android" , " setAttribute called before init" );
176+ return ;
177+ }
178+
179+ const char * keyStr = env->GetStringUTFChars (key, nullptr );
180+ const char * valueStr = env->GetStringUTFChars (value, nullptr );
181+
182+ g_simple_annotations->SetKeyValue (keyStr, valueStr);
183+
184+ env->ReleaseStringUTFChars (key, keyStr);
185+ env->ReleaseStringUTFChars (value, valueStr);
186+ }
187+
188+ extern " C" JNIEXPORT void JNICALL
189+ Java_com_bugsplat_android_BugSplatBridge_jniRemoveAttribute (JNIEnv *env, jclass clazz,
190+ jstring key) {
191+ if (g_simple_annotations == nullptr ) {
192+ __android_log_print (ANDROID_LOG_WARN, " bugsplat-android" , " removeAttribute called before init" );
193+ return ;
194+ }
195+
196+ const char * keyStr = env->GetStringUTFChars (key, nullptr );
197+
198+ g_simple_annotations->RemoveKey (keyStr);
199+
200+ env->ReleaseStringUTFChars (key, keyStr);
201+ }
202+
150203vector<FilePath> createAttachments (JNIEnv *env, jobjectArray attachments) {
151204 vector<FilePath> attachmentPaths;
152205
0 commit comments