Skip to content

Commit d540536

Browse files
authored
feat: better detection of Android environment
Closes: xerial#1210
1 parent 1f66a8d commit d540536

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/main/java/org/sqlite/util/OSInfo.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// --------------------------------------
2525
package org.sqlite.util;
2626

27+
import java.io.File;
2728
import java.io.IOException;
2829
import java.nio.file.Files;
2930
import java.nio.file.Path;
@@ -114,7 +115,21 @@ public static String getOSName() {
114115
}
115116

116117
public static boolean isAndroid() {
117-
return isAndroidRuntime() || isAndroidTermux();
118+
return isAndroidRuntime() || isAndroidTermux() || isRunningAndroid();
119+
}
120+
121+
private static boolean isRunningAndroid() {
122+
// This file is guaranteed to be present on every android version since 1.6 (Donut, API 4),
123+
// see https://developer.android.com/ndk/guides/stable_apis#graphics
124+
// We don't use libc/libm/libdl because that has changed what directory its pointing to and
125+
// OEMs implement the symlink that allows backwards compatibility
126+
// for apps that use the old path differently, which may cause this check to fail because
127+
// common undocumented behaviour. See
128+
// https://developer.android.com/about/versions/10/behavior-changes-all#bionic
129+
File androidGLES = new File("/system/lib/libGLESv1_CM");
130+
File android64GLES = new File("/system/lib64/libGLESv1_CM");
131+
132+
return android64GLES.exists() || androidGLES.exists();
118133
}
119134

120135
public static boolean isAndroidRuntime() {

src/test/java/org/sqlite/util/OSInfoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ public void testIsAndroidTermux() throws Exception {
133133
}
134134

135135
@Nested
136-
@SetSystemProperty(key = "java.runtime.name", value = "Java for Android")
137-
@SetSystemProperty(key = "os.name", value = "Linux for Android")
136+
@SetSystemProperty(key = "java.runtime.name", value = "Android Runtime")
137+
@SetSystemProperty(key = "os.name", value = "Linux")
138138
class AndroidRuntime {
139139

140140
@Test

0 commit comments

Comments
 (0)