-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
native-lib.cpp
95 lines (76 loc) 路 2.91 KB
/
native-lib.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <jni.h>
#include <string>
#include <unistd.h>
#include "client/crashpad_client.h"
#include "client/crash_report_database.h"
#include "client/settings.h"
void stackFrame1(void);
void stackFrame2(void);
void stackFrame3(void);
void crash(void);
using namespace base;
using namespace crashpad;
using namespace std;
extern "C" JNIEXPORT jboolean JNICALL
Java_com_example_androidcrasher_MainActivity_initializeCrashpad(
JNIEnv* env,
jobject /* this */,
jstring appDataDir,
jstring libDir
) {
// Device file paths
string nativeLibraryDir = env->GetStringUTFChars(libDir, 0);
string dataDir = env->GetStringUTFChars(appDataDir, 0);
// Crashpad file paths
FilePath handler(nativeLibraryDir + "/libcrashpad_handler.so");
FilePath reportsDir(dataDir + "/crashpad");
FilePath metricsDir(dataDir + "/crashpad");
// Crashpad upload URL for BugSplat database
string url = "http://fred.bugsplat.com/post/bp/crash/crashpad.php";
// Crashpad annotations
map<string, string> annotations;
annotations["format"] = "minidump"; // Required: Crashpad setting to save crash as a minidump
annotations["database"] = "fred"; // Required: BugSplat appName
annotations["product"] = "AndroidCrasher"; // Required: BugSplat appName
annotations["version"] = "1.0.1"; // Required: BugSplat appVersion
annotations["key"] = "Samplekey"; // Optional: BugSplat key field
annotations["user"] = "fred@bugsplat.com"; // Optional: BugSplat user email
annotations["list_annotations"] = "Sample comment"; // Optional: BugSplat crash description
// Crashpad arguments
vector<string> arguments;
arguments.push_back("--no-rate-limit");
// Crashpad local database
unique_ptr<CrashReportDatabase> crashReportDatabase = CrashReportDatabase::Initialize(reportsDir);
if (crashReportDatabase == NULL) return false;
// Enable automated crash uploads
Settings *settings = crashReportDatabase->GetSettings();
if (settings == NULL) return false;
settings->SetUploadsEnabled(true);
// File paths of attachments to be uploaded with the minidump file at crash time - default bundle limit is 20MB
vector<FilePath> attachments;
FilePath attachment(dataDir + "/files/attachment.txt");
attachments.push_back(attachment);
// Start Crashpad crash handler
static CrashpadClient *client = new CrashpadClient();
bool status = client->StartHandlerAtCrash(handler, reportsDir, metricsDir, url, annotations, arguments, attachments);
return status;
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_example_androidcrasher_MainActivity_crash(
JNIEnv* env,
jobject /* this */) {
stackFrame1();
return true;
}
void stackFrame1() {
stackFrame2();
}
void stackFrame2() {
stackFrame3();
}
void stackFrame3() {
crash();
}
void crash() {
*(volatile int *)0 = 0;
}