From a81e6d47521098ec6473c345109b5cb63a381621 Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 23 Jan 2025 01:56:31 +0100 Subject: [PATCH] Workaround Go issue causing the app to crash on older Android versions * Fix app crashes when using Go > 1.23 and Android < 12 * See https://github.com/golang/go/issues/70508 --- tray/CMakeLists.txt | 11 ++++++ tray/android/signalhandler.cpp | 36 +++++++++++++++++++ .../martchus/syncthingtray/Activity.java | 6 ++++ 3 files changed, 53 insertions(+) create mode 100644 tray/android/signalhandler.cpp diff --git a/tray/CMakeLists.txt b/tray/CMakeLists.txt index d7309fdb..b10056ec 100644 --- a/tray/CMakeLists.txt +++ b/tray/CMakeLists.txt @@ -412,10 +412,21 @@ if (ANDROID) endif () if (USE_LIBSYNCTHING) + # bundle internal Syncthing library set_property( TARGET ${META_TARGET_NAME} APPEND PROPERTY QT_ANDROID_EXTRA_LIBS "${SYNCTHINGINTERNAL_LIBRARY_PATH}") + + # workaround https://github.com/golang/go/issues/70508 + set(ANDROID_SIGNAL_HANDLER_LIBRARY "androidsignalhandler") + add_library("${ANDROID_SIGNAL_HANDLER_LIBRARY}" MODULE android/signalhandler.cpp) + find_library(ANDROID_LOG_LIB log) + target_link_libraries("${ANDROID_SIGNAL_HANDLER_LIBRARY}" "${ANDROID_LOG_LIB}") + set_property( + TARGET ${META_TARGET_NAME} + APPEND + PROPERTY QT_ANDROID_EXTRA_LIBS "${CMAKE_CURRENT_BINARY_DIR}/lib${ANDROID_SIGNAL_HANDLER_LIBRARY}.so") endif () set(QT_ANDROID_SIGN_APK ON) diff --git a/tray/android/signalhandler.cpp b/tray/android/signalhandler.cpp new file mode 100644 index 00000000..ed19b38b --- /dev/null +++ b/tray/android/signalhandler.cpp @@ -0,0 +1,36 @@ +#include +#include + +#include + +#define ST_LIB_LOG_TAG "SyncthingLibrary" +#define ST_LIB_LOG_INF(...) __android_log_print(ANDROID_LOG_INFO, ST_LIB_LOG_TAG, __VA_ARGS__) + +static void handleSigsys(int signum, siginfo_t *info, void *context) +{ + // ignore the signal to prevent the app from crashing + ST_LIB_LOG_INF("SIGSYS signal received and ignored"); +} + +static void initSigsysHandler() +{ + struct sigaction sa; + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = handleSigsys; + sigemptyset(&sa.sa_mask); + if (sigaction(SIGSYS, &sa, nullptr) == -1) { + ST_LIB_LOG_INF("Failed to set up SIGSYS handler"); + } else { + ST_LIB_LOG_INF("SIGSYS handler set up successfully"); + } +} + +extern "C" { + +JNIEXPORT void JNICALL +Java_io_github_martchus_syncthingtray_Activity_initSigsysHandler(JNIEnv *env, jobject thiz) +{ + initSigsysHandler(); +} + +} diff --git a/tray/android/src/io/github/martchus/syncthingtray/Activity.java b/tray/android/src/io/github/martchus/syncthingtray/Activity.java index becfdfd1..4aa6a6c7 100644 --- a/tray/android/src/io/github/martchus/syncthingtray/Activity.java +++ b/tray/android/src/io/github/martchus/syncthingtray/Activity.java @@ -130,6 +130,11 @@ public int fontWeightAdjustment() { @Override public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "Creating"); + + // workaround https://github.com/golang/go/issues/70508 + System.loadLibrary("androidsignalhandler"); + initSigsysHandler(); + super.onCreate(savedInstanceState); // read font scale as Qt does not handle this automatically on Android @@ -200,4 +205,5 @@ private void sendAndroidIntentToQtQuickApp(String page, boolean fromNotification private static native void handleAndroidIntent(String page, boolean fromNotification); private static native void stopLibSyncthing(); + private static native void initSigsysHandler(); }