Skip to content

DROID-3097 App | Tech | Catch sigsys signals #1835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 25, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ ktlint
.idea/*.xml
signing.properties
app/release
.kotlin/
.kotlin/
app/.cxx
13 changes: 13 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 30 additions & 0 deletions app/src/main/cpp/signal_handler.c
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
}
}