Skip to content

Commit df51e35

Browse files
committed
android: fix crash with Android <12 and go 1.23
Due to golang/go#70508, the BitBoxApp crashes on versions of Android older than 12 if upgrading to Go 1.23. Therefore we are applying the workaround described at golang/go#70508 (comment) which is to intercept and ignore SIGSYS signals.
1 parent 8b71d87 commit df51e35

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
.DS_Store
99
.idea
10+
.cxx/
1011

1112

1213
### Vim ###

frontends/android/BitBoxApp/app/build.gradle

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ android {
1010
versionCode 59
1111
versionName "android-4.47.0"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13+
externalNativeBuild {
14+
cmake {
15+
cppFlags '-std=c++11'
16+
}
17+
}
1318
}
1419
buildTypes {
1520
release {
@@ -23,6 +28,12 @@ android {
2328
}
2429
}
2530
namespace 'ch.shiftcrypto.bitboxapp'
31+
externalNativeBuild {
32+
cmake {
33+
path file('src/main/cpp/CMakeLists.txt')
34+
version '3.31.6'
35+
}
36+
}
2637
}
2738

2839
dependencies {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(signal_handler)
4+
5+
add_library( # Specifies the name of the library.
6+
signal_handler
7+
8+
# Sets the library as a shared library.
9+
SHARED
10+
11+
# Provides a relative path to your source file(s).
12+
signal_handler.c
13+
)
14+
15+
find_library(
16+
log-lib
17+
log
18+
)
19+
20+
target_link_libraries(
21+
signal_handler
22+
${log-lib}
23+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// signal_handler.c
2+
#include <jni.h>
3+
#include <signal.h>
4+
#include <android/log.h>
5+
6+
#define LOG_TAG "SignalHandler"
7+
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
8+
9+
void sigsys_handler(int signum, siginfo_t *info, void *context) {
10+
LOGI("SIGSYS signal received and ignored.");
11+
}
12+
13+
void setup_sigsys_handler() {
14+
struct sigaction sa;
15+
sa.sa_flags = SA_SIGINFO;
16+
sa.sa_sigaction = sigsys_handler;
17+
sigemptyset(&sa.sa_mask);
18+
if (sigaction(SIGSYS, &sa, NULL) == -1) {
19+
LOGI("Failed to set up SIGSYS handler");
20+
} else {
21+
LOGI("SIGSYS handler set up successfully");
22+
}
23+
24+
}
25+
26+
JNIEXPORT void JNICALL Java_ch_shiftcrypto_bitboxapp_MainActivity_initsignalhandler(JNIEnv *env, jobject thisObj) {
27+
setup_sigsys_handler();
28+
}

frontends/android/BitBoxApp/app/src/main/java/ch/shiftcrypto/bitboxapp/MainActivity.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
import mobileserver.Mobileserver;
6161

6262
public class MainActivity extends AppCompatActivity {
63+
static {
64+
System.loadLibrary("signal_handler");
65+
}
66+
public native void initsignalhandler();
6367
private final int PERMISSIONS_REQUEST_CAMERA_QRCODE = 0;
6468
private static final String ACTION_USB_PERMISSION = "ch.shiftcrypto.bitboxapp.USB_PERMISSION";
6569
// The WebView is configured with this as the base URL. The purpose is so that requests made
@@ -123,13 +127,12 @@ public void onReceive(Context context, Intent intent) {
123127
@Override
124128
public void onReceive(Context context, Intent intent) {
125129
Mobileserver.usingMobileDataChanged();
126-
}
130+
}
127131
};
128132

129133

130-
131134
@Override
132-
public void onConfigurationChanged(Configuration newConfig){
135+
public void onConfigurationChanged(Configuration newConfig) {
133136
int currentNightMode = newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK;
134137
switch (currentNightMode) {
135138
case Configuration.UI_MODE_NIGHT_NO:
@@ -172,6 +175,8 @@ protected void onCreate(Bundle savedInstanceState) {
172175
super.onCreate(savedInstanceState);
173176
Util.log("lifecycle: onCreate");
174177

178+
initsignalhandler();
179+
175180
getSupportActionBar().hide(); // hide title bar with app name.
176181
onConfigurationChanged(getResources().getConfiguration());
177182
setContentView(R.layout.activity_main);

scripts/docker_install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ gem install --no-document fpm
101101
# Needed for Android.
102102
apt-get install -y --no-install-recommends openjdk-17-jdk
103103
# Keep versions in sync with build.gradle and frontends/android/Makefile.
104-
/opt/android-sdk/cmdline-tools/tools/bin/sdkmanager "ndk;21.2.6472646" "platforms;android-34" "build-tools;34.0.0" "platform-tools"
104+
/opt/android-sdk/cmdline-tools/tools/bin/sdkmanager "ndk;21.2.6472646" "platforms;android-34" "build-tools;34.0.0" "platform-tools" "cmake;3.31.6"

0 commit comments

Comments
 (0)