override fun onCreate(owner: LifecycleOwner) {
if (isMainProcess) {
@@ -69,6 +71,10 @@
override fun onVpnProcessCreated() {
if (!isMainProcess) {
asyncLoadNativeLibrary()
thread {
Thread.sleep(2000)
jni_crash()
}
} else {
logcat(ERROR) { "ndk-crash: onCreate wrongly called in the main process" }
}
Index: anrs/anrs-impl/src/main/cpp/jni.cpp
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
Task/Issue URL: https://app.asana.com/0/488551667048375/1207420696563461/f
Description
Load native crash library off class instance construction
Steps to test this PR
Test
Native crash handler init pixel sent on main
shows in logcatNative crash handler successfully initialized on main
shows in logcatNative crash handler init pixel sent on vpn
shows in logcatNative crash handler successfully initialized on vpn
shows in logcatNative crash handler init pixel sent on main
shows in logcatNative crash handler successfully initialized on main
shows in logcatadb shell am force-stop com.duckduckgo.mobile.android.debug
Native crash handler init pixel sent on main
shows in logcatNative crash handler successfully initialized on main
shows in logcatNative crash handler init pixel sent on vpn
shows in logcatNative crash handler successfully initialized on vpn
shows in logcatadb shell am force-stop com.duckduckgo.mobile.android.debug
and re-launch appNative crash handler init pixel sent on main
shows in logcatNative crash handler successfully initialized on main
shows in logcatTest main process crash
[x] Apply the following patch, rebuild and fresh install
private external fun jni_crash()
override fun onCreate(owner: LifecycleOwner) { if (isMainProcess) { asyncLoadNativeLibrary()
} } else { logcat(ERROR) { "ndk-crash: onCreate wrongly called in a secondary process" } } Index: anrs/anrs-impl/src/main/cpp/jni.cpp IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
diff --git a/anrs/anrs-impl/src/main/cpp/jni.cpp b/anrs/anrs-impl/src/main/cpp/jni.cpp --- a/anrs/anrs-impl/src/main/cpp/jni.cpp (revision 3eb803331a644de40af37e35fc0b355770961350) +++ b/anrs/anrs-impl/src/main/cpp/jni.cpp (date 1716897983303) @@ -74,3 +74,19 @@ jobject / this /) { native_crash_handler_fini(); }
+// Our custom test exception. Anything "publicly" inheriting std::exception will work +class MyException : public std::exception { +public:
+extern "C" JNIEXPORT void JNICALL +Java_com_duckduckgo_app_anr_ndk_NativeCrashInit_jni_1crash(
Native crash handler init pixel sent on main
shows in logcatNative crash handler successfully initialized on main
shows in logcatNative crash pixel sent on main
shows in logcatTest crash in vpn process
[x] Apply the following patch, rebuild and fresh install
private external fun jni_crash()
override fun onCreate(owner: LifecycleOwner) { if (isMainProcess) { @@ -69,6 +71,10 @@ override fun onVpnProcessCreated() { if (!isMainProcess) { asyncLoadNativeLibrary()
} } else { logcat(ERROR) { "ndk-crash: onCreate wrongly called in the main process" } } Index: anrs/anrs-impl/src/main/cpp/jni.cpp IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
diff --git a/anrs/anrs-impl/src/main/cpp/jni.cpp b/anrs/anrs-impl/src/main/cpp/jni.cpp --- a/anrs/anrs-impl/src/main/cpp/jni.cpp (revision 3eb803331a644de40af37e35fc0b355770961350) +++ b/anrs/anrs-impl/src/main/cpp/jni.cpp (date 1716990529535) @@ -74,3 +74,19 @@ jobject / this /) { native_crash_handler_fini(); }
+// Our custom test exception. Anything "publicly" inheriting std::exception will work +class MyException : public std::exception { +public:
+extern "C" JNIEXPORT void JNICALL +Java_com_duckduckgo_app_anr_ndk_NativeCrashInit_jni_1crash(
Native crash handler init pixel sent on vpn
shows in logcatNative crash handler successfully initialized on vpn
shows in logcatNative crash pixel sent on vpn
shows in logcat (The VPN will automatically try to re-start, creating and endless loop, expected)