mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3097 App | Tech | Catch sigsys signals (#1835)
Co-authored-by: Evgenii Kozlov <enklave.mare.balticum@protonmail.com> Co-authored-by: Evgenii Kozlov <ubuphobos@gmail.com>
This commit is contained in:
parent
c194c057ad
commit
80d2ffc8b5
5 changed files with 76 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -22,4 +22,5 @@ ktlint
|
|||
.idea/*.xml
|
||||
signing.properties
|
||||
app/release
|
||||
.kotlin/
|
||||
.kotlin/
|
||||
app/.cxx
|
||||
|
|
|
@ -53,6 +53,19 @@ android {
|
|||
buildConfigField "boolean", "LOG_EDITOR_CONTROL_PANEL", localProperties.getProperty("LOG_EDITOR_CONTROL_PANEL", "false")
|
||||
buildConfigField "boolean", "ENABLE_STRICT_MODE", "false"
|
||||
resValue "string", "SENTRY_DSN", config.sentryApiKey
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
// Specify any cpp flags if needed
|
||||
cppFlags "-std=c++11"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
// Provide the path to your CMakeLists.txt file
|
||||
path "src/main/cpp/CMakeLists.txt"
|
||||
}
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
|
|
18
app/src/main/cpp/CMakeLists.txt
Normal file
18
app/src/main/cpp/CMakeLists.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
# CMakeLists.txt
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
|
||||
add_library(
|
||||
signal_handler
|
||||
SHARED
|
||||
signal_handler.c
|
||||
)
|
||||
|
||||
find_library(
|
||||
log-lib
|
||||
log
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
signal_handler
|
||||
${log-lib}
|
||||
)
|
30
app/src/main/cpp/signal_handler.c
Normal file
30
app/src/main/cpp/signal_handler.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
// signal_handler.c
|
||||
#include <jni.h>
|
||||
#include <signal.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#define LOG_TAG "SignalHandler"
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
||||
|
||||
void sigsys_handler(int signum, siginfo_t *info, void *context) {
|
||||
LOGI("SIGSYS signal received and ignored.");
|
||||
// Ignore the signal to prevent the app from crashing
|
||||
}
|
||||
|
||||
void setup_sigsys_handler() {
|
||||
struct sigaction sa;
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sa.sa_sigaction = sigsys_handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
if (sigaction(SIGSYS, &sa, NULL) == -1) {
|
||||
LOGI("Failed to set up SIGSYS handler");
|
||||
} else {
|
||||
LOGI("SIGSYS handler set up successfully");
|
||||
}
|
||||
}
|
||||
|
||||
// Correctly named JNI function
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_anytypeio_anytype_app_AndroidApplication_00024SignalHandler_initSignalHandler(JNIEnv *env, jobject thiz) {
|
||||
setup_sigsys_handler();
|
||||
}
|
|
@ -50,11 +50,13 @@ class AndroidApplication : Application(), HasComponentDependencies {
|
|||
ComponentManager(main, this)
|
||||
}
|
||||
|
||||
|
||||
override fun onCreate() {
|
||||
if (BuildConfig.ENABLE_STRICT_MODE) {
|
||||
enableStrictMode()
|
||||
}
|
||||
super.onCreate()
|
||||
setupSignalHandler()
|
||||
main.inject(this)
|
||||
setupAnalytics()
|
||||
setupTimber()
|
||||
|
@ -111,10 +113,21 @@ class AndroidApplication : Application(), HasComponentDependencies {
|
|||
notificationManager.createNotificationChannel(notificationChannel)
|
||||
}
|
||||
|
||||
private fun setupSignalHandler() {
|
||||
SignalHandler.initSignalHandler()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val NOTIFICATION_CHANNEL_ID = "anytype_notification_channel"
|
||||
const val NOTIFICATION_CHANNEL_NAME = "Local Anytype notifications"
|
||||
const val NOTIFICATION_CHANNEL_DESCRIPTION = "Important notifications from Anytype, including collaboration events in multiplayer mode"
|
||||
}
|
||||
|
||||
object SignalHandler {
|
||||
init {
|
||||
System.loadLibrary(SIGNAL_HANDLER_LIB_NAME)
|
||||
}
|
||||
external fun initSignalHandler()
|
||||
const val SIGNAL_HANDLER_LIB_NAME = "signal_handler"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue