aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp')
-rw-r--r--src/java/com/jogamp/common/os/AndroidVersion.java97
-rw-r--r--src/java/com/jogamp/common/os/Platform.java37
-rw-r--r--src/java/com/jogamp/common/util/VersionUtil.java14
3 files changed, 138 insertions, 10 deletions
diff --git a/src/java/com/jogamp/common/os/AndroidVersion.java b/src/java/com/jogamp/common/os/AndroidVersion.java
new file mode 100644
index 0000000..b5a7cfa
--- /dev/null
+++ b/src/java/com/jogamp/common/os/AndroidVersion.java
@@ -0,0 +1,97 @@
+package com.jogamp.common.os;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.jogamp.common.util.ReflectionUtil;
+
+public class AndroidVersion {
+ public static final boolean isAvailable;
+
+ /** All SDK version map, where SDK_INT is the key to the current running version */
+ public static final Map<Integer, String> VERSION_CODES;
+
+ /** Development codename, or the string "REL" for official release */
+ public static final String CODENAME;
+
+ /** internal build value used by the underlying source control. */
+ public static final String INCREMENTAL;
+
+ /** official build version string */
+ public static final String RELEASE;
+
+ /** SDK Version number, key to VERSION_CODES */
+ public static final int SDK_INT;
+
+ /** SDK Version string */
+ public static final String SDK_NAME;
+
+ static final String androidBuildVersion = "android.os.Build$VERSION";
+ static final String androidBuildVersionCodes = "android.os.Build$VERSION_CODES";
+
+ static {
+ final ClassLoader cl = AndroidVersion.class.getClassLoader();
+ Class abvClass = null;
+ Object abvObject= null;
+ Class abvcClass = null;
+ Object abvcObject= null;
+ try {
+ abvClass = ReflectionUtil.getClass(androidBuildVersion, true, cl);
+ abvObject = abvClass.newInstance();
+ abvcClass = ReflectionUtil.getClass(androidBuildVersionCodes, true, cl);
+ abvcObject = abvcClass.newInstance();
+ } catch (Exception e) { e.printStackTrace(); /* n/a */ }
+ isAvailable = null != abvObject ;
+ if(isAvailable) {
+ CODENAME = getString(abvClass, abvObject, "CODENAME");
+ INCREMENTAL = getString(abvClass, abvObject, "INCREMENTAL");
+ RELEASE = getString(abvClass, abvObject, "RELEASE");
+ SDK_INT = getInt(abvClass, abvObject, "SDK_INT");
+ VERSION_CODES = getVersionCodes(abvcClass, abvcObject);
+ String sdk_name = VERSION_CODES.get(new Integer(SDK_INT));
+ SDK_NAME = ( null != sdk_name ) ? sdk_name : "SDK_"+SDK_INT ;
+ } else {
+ CODENAME = null;
+ INCREMENTAL = null;
+ RELEASE = null;
+ SDK_INT = -1;
+ VERSION_CODES = new HashMap<Integer, String>();
+ SDK_NAME = null;
+ }
+ }
+
+ private static final Map<Integer, String> getVersionCodes(Class cls, Object obj) {
+ HashMap<Integer, String> map = new HashMap<Integer, String>();
+ Field[] fields = cls.getFields();
+ for(int i=0; i<fields.length; i++) {
+ try {
+ final int version = fields[i].getInt(obj);
+ final String version_name = fields[i].getName();
+ // System.err.println(i+": "+version+": "+version_name);
+ map.put(new Integer(version), version_name);
+ } catch (Exception e) { e.printStackTrace(); /* n/a */ }
+ }
+ return map;
+ }
+
+ private static final String getString(Class cls, Object obj, String name) {
+ try {
+ Field f = cls.getField(name);
+ return (String) f.get(obj);
+ } catch (Exception e) { e.printStackTrace(); /* n/a */ }
+ return null;
+ }
+
+ private static final int getInt(Class cls, Object obj, String name) {
+ try {
+ Field f = cls.getField(name);
+ return f.getInt(obj);
+ } catch (Exception e) { e.printStackTrace(); /* n/a */ }
+ return -1;
+ }
+
+ // android.os.Build.VERSION
+}
diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java
index 4db5b09..6c23f07 100644
--- a/src/java/com/jogamp/common/os/Platform.java
+++ b/src/java/com/jogamp/common/os/Platform.java
@@ -54,6 +54,8 @@ public class Platform {
public static final String ARCH_lower;
public static final String JAVA_VENDOR;
public static final String JAVA_VENDOR_URL;
+ public static final String JAVA_VM_NAME;
+ public static final String JAVA_RUNTIME_NAME;
public static final String JAVA_VERSION;
public static final String NEWLINE;
@@ -142,7 +144,8 @@ public class Platform {
JAVA_VENDOR_URL = System.getProperty("java.vendor.url");
JAVA_VERSION = System.getProperty("java.version");
NEWLINE = System.getProperty("line.separator");
-
+ JAVA_VM_NAME = System.getProperty("java.vm.name");
+ JAVA_RUNTIME_NAME = getJavaRuntimeNameImpl();
JAVA_SE = initIsJavaSE();
LITTLE_ENDIAN = queryIsLittleEndianImpl();
@@ -227,6 +230,9 @@ public class Platform {
}
private static OSType getOSTypeImpl() throws RuntimeException {
+ if ( AndroidVersion.isAvailable ) {
+ return OSType.ANDROID;
+ }
if ( OS_lower.startsWith("linux") ) {
return OSType.LINUX;
}
@@ -254,15 +260,18 @@ public class Platform {
}
throw new RuntimeException("Please port OS detection to your platform (" + OS_lower + "/" + ARCH_lower + ")");
}
-
- private static boolean initIsJavaSE() {
+
+ private static String getJavaRuntimeNameImpl() {
// the fast path, check property Java SE instead of traversing through the ClassLoader
- String java_runtime_name = (String) AccessController.doPrivileged(new PrivilegedAction() {
+ return (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty("java.runtime.name");
}
});
- if(java_runtime_name.indexOf("Java SE") != -1) {
+ }
+
+ private static boolean initIsJavaSE() {
+ if(JAVA_RUNTIME_NAME.indexOf("Java SE") != -1) {
return true;
}
@@ -294,8 +303,9 @@ public class Platform {
/**
* Returns the OS name.
+ * <p>In case of {@link OSType#ANDROID}, see {@link #getOSType()}, the OS name is Linux</p>
*/
- public static String getOS() {
+ public static String getOSName() {
return OS;
}
@@ -316,6 +326,7 @@ public class Platform {
/**
* Returns the OS type.
+ * <p>In case of {@link OSType#ANDROID} the OS name, see {@link #getOSName()}, is Linux</p>
*/
public static OSType getOSType() {
return OS_TYPE;
@@ -343,6 +354,20 @@ public class Platform {
}
/**
+ * Returns the JAVA VM name.
+ */
+ public static String getJavaVMName() {
+ return JAVA_VM_NAME;
+ }
+
+ /**
+ * Returns the JAVA runtime name.
+ */
+ public static String getJavaRuntimeName() {
+ return JAVA_RUNTIME_NAME;
+ }
+
+ /**
* Returns the JAVA vendor url.
*/
public static String getJavaVendorURL() {
diff --git a/src/java/com/jogamp/common/util/VersionUtil.java b/src/java/com/jogamp/common/util/VersionUtil.java
index 1589755..b8b7932 100644
--- a/src/java/com/jogamp/common/util/VersionUtil.java
+++ b/src/java/com/jogamp/common/util/VersionUtil.java
@@ -28,6 +28,7 @@
package com.jogamp.common.util;
+import com.jogamp.common.os.AndroidVersion;
import com.jogamp.common.os.Platform;
import java.io.IOException;
@@ -53,16 +54,21 @@ public class VersionUtil {
sb.append(SEPERATOR).append(Platform.getNewline());
// environment
- sb.append("Platform: ").append(Platform.getOS()).append(' ').append(Platform.getOSVersion()).append(" (os), ");
+ sb.append("Platform: ").append(Platform.getOSType()).append(" / ").append(Platform.getOSName()).append(' ').append(Platform.getOSVersion()).append(" (os), ");
sb.append(Platform.getArch()).append(" (arch) ").append(Runtime.getRuntime().availableProcessors()).append(" cores");
sb.append(Platform.getNewline());
+ if( Platform.OSType.ANDROID == Platform.getOSType() && AndroidVersion.isAvailable) {
+ sb.append("Platform: Android Version: ").append(AndroidVersion.CODENAME).append(", ");
+ sb.append(AndroidVersion.RELEASE).append(" [").append(AndroidVersion.RELEASE).append("], SDK: ").append(AndroidVersion.SDK_INT).append(", ").append(AndroidVersion.SDK_NAME);
+ sb.append(Platform.getNewline());
+ }
Platform.getMachineDescription().toString(sb).append(Platform.getNewline());
// JVM/JRE
- sb.append("Platform: Java ").append(Platform.getJavaVersion()).append(", ").append(System.getProperty("java.vm.name")).append(", ");
- sb.append(Platform.getJavaVendor()).append(", ").append(Platform.getJavaVendorURL()).append(", is JavaSE: ").append(Platform.isJavaSE());
-
+ sb.append("Platform: Java Version: ").append(Platform.getJavaVersion()).append(", VM: ").append(Platform.getJavaVMName());
+ sb.append(", Runtime: ").append(Platform.getJavaRuntimeName()).append(Platform.getNewline());
+ sb.append("Platform: Java Vendor: ").append(Platform.getJavaVendor()).append(", ").append(Platform.getJavaVendorURL()).append(", is JavaSE: ").append(Platform.isJavaSE());
sb.append(Platform.getNewline()).append(SEPERATOR);
return sb;