Skip to content

Commit 62bfe56

Browse files
committed
handle SIGABRT only on API level > 25
execute SIGABRT test only for API level > 25
1 parent 2f1d755 commit 62bfe56

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

test-app/app/src/main/assets/app/tests/exceptionHandlingTests.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,20 +337,20 @@ describe("Tests exception handling ", function () {
337337
expect(errMsg).toContain("Cannot compile /data/data/com.tns.testapplication/files/app/tests/syntaxErrors.js");
338338
expect(errMsg).toContain("SyntaxError: Unexpected token =");
339339
expect(errMsg).toContain("File: \"file:///data/data/com.tns.testapplication/files/app/tests/syntaxErrors.js, line: 3, column: 10");
340-
341-
342-
343340
});
344341

345-
it("Should handle SIGABRT and throw a NativeScript exception when incorrectly calling JNI methods", function () {
346-
let myClassInstance = new com.tns.tests.MyTestBaseClass3();
347-
// public void callMeWithAString(java.lang.String[] stringArr, Runnable arbitraryInterface)
348-
try {
349-
myClassInstance.callMeWithAString("stringVal", new java.lang.Runnable({ run: () => {} }))
350-
} catch (e) {
351-
android.util.Log.d("~~~~~", "~~~~~~~~ " + e.toString());
352-
353-
expect(e.toString()).toContain("SIGABRT");
354-
}
355-
});
342+
// run this test only for API level bigger than 25 as we have handling there
343+
if(android.os.Build.VERSION.SDK_INT > 25) {
344+
it("Should handle SIGABRT and throw a NativeScript exception when incorrectly calling JNI methods", function () {
345+
let myClassInstance = new com.tns.tests.MyTestBaseClass3();
346+
// public void callMeWithAString(java.lang.String[] stringArr, Runnable arbitraryInterface)
347+
try {
348+
myClassInstance.callMeWithAString("stringVal", new java.lang.Runnable({ run: () => {} }))
349+
} catch (e) {
350+
android.util.Log.d("~~~~~", "~~~~~~~~ " + e.toString());
351+
352+
expect(e.toString()).toContain("SIGABRT");
353+
}
354+
});
355+
}
356356
});

test-app/runtime/src/main/cpp/Runtime.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,29 @@ void Runtime::Init(JavaVM* vm, void* reserved) {
5353
JEnv::Init(s_jvm);
5454
}
5555

56-
// handle SIGABRT
57-
struct sigaction action;
58-
action.sa_handler = SIGABRT_handler;
59-
sigaction(SIGABRT, &action, NULL);
56+
if(m_androidVersion > 25) {
57+
// handle SIGABRT only on API level > 25 as the handling is not so efficient in older versions
58+
struct sigaction action;
59+
action.sa_handler = SIGABRT_handler;
60+
sigaction(SIGABRT, &action, NULL);
61+
}
6062

6163
DEBUG_WRITE("JNI_ONLoad END");
6264
}
6365

66+
int Runtime::GetAndroidVersion() {
67+
char sdkVersion[PROP_VALUE_MAX];
68+
__system_property_get("ro.build.version.sdk", sdkVersion);
69+
70+
stringstream strValue;
71+
strValue << sdkVersion;
72+
73+
unsigned int intValue;
74+
strValue >> intValue;
75+
76+
return intValue;
77+
}
78+
6479
Runtime::Runtime(JNIEnv* env, jobject runtime, int id)
6580
: m_env(env), m_id(id), m_isolate(nullptr), m_lastUsedMemory(0), m_gcFunc(nullptr), m_runGC(false) {
6681
m_runtime = m_env.NewGlobalRef(runtime);
@@ -403,15 +418,11 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
403418

404419
m_startupData = new StartupData();
405420

406-
// Retrieve the device android Sdk version
407-
char sdkVersion[PROP_VALUE_MAX];
408-
__system_property_get("ro.build.version.sdk", sdkVersion);
409-
410421
void* snapshotPtr = nullptr;
411422
string snapshotPath;
412423

413424
// If device isn't running on Sdk 17
414-
if (strcmp(sdkVersion, string("17").c_str()) != 0) {
425+
if (m_androidVersion != 17) {
415426
snapshotPath = "libsnapshot.so";
416427
} else {
417428
// If device is running on android Sdk 17
@@ -664,3 +675,4 @@ map<int, Runtime*> Runtime::s_id2RuntimeCache;
664675
map<Isolate*, Runtime*> Runtime::s_isolate2RuntimesCache;
665676
bool Runtime::s_mainThreadInitialized = false;
666677
v8::Platform* Runtime::platform = nullptr;
678+
int Runtime::m_androidVersion = Runtime::GetAndroidVersion();

test-app/runtime/src/main/cpp/Runtime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class Runtime {
8585

8686
v8::Isolate* PrepareV8Runtime(const std::string& filesPath, const std::string& nativeLibsDir, const std::string& packageName, bool isDebuggable, const std::string& callingDir, const std::string& profilerOutputDir);
8787
jobject ConvertJsValueToJavaObject(JEnv& env, const v8::Local<v8::Value>& value, int classReturnType);
88+
static int GetAndroidVersion();
89+
static int m_androidVersion;
8890

8991
static std::map<int, Runtime*> s_id2RuntimeCache;
9092

@@ -95,8 +97,6 @@ class Runtime {
9597
static jmethodID GET_USED_MEMORY_METHOD_ID;
9698

9799
static bool s_mainThreadInitialized;
98-
99-
100100
};
101101
}
102102

0 commit comments

Comments
 (0)