28import java.lang.reflect.Field;
29import java.util.HashMap;
31import org.jau.lang.ReflectionUtil;
32import org.jau.sys.PlatformTypes.ABIType;
33import org.jau.sys.PlatformTypes.CPUType;
63 private static final String androidBuild =
"android.os.Build";
64 private static final String androidBuildVersion =
"android.os.Build$VERSION";
65 private static final String androidBuildVersionCodes =
"android.os.Build$VERSION_CODES";
69 Class<?> abClass =
null;
70 Object abObject=
null;
71 Class<?> abvClass =
null;
72 Object abvObject=
null;
73 Class<?> abvcClass =
null;
74 Object abvcObject=
null;
76 final boolean isDalvikVm =
"Dalvik".equals(System.getProperty(
"java.vm.name"));
81 abObject = abClass.getDeclaredConstructor().newInstance();
83 abvObject = abvClass.getDeclaredConstructor().newInstance();
85 abvcObject = abvcClass.getDeclaredConstructor().newInstance();
86 }
catch (
final Exception e) { }
88 isAvailable = isDalvikVm &&
null != abObject &&
null != abvObject;
90 CPU_ABI_NAME = getString(abClass, abObject,
"CPU_ABI",
true);
91 CPU_ABI2_NAME = getString(abClass, abObject,
"CPU_ABI2",
true);
92 CODENAME = getString(abvClass, abvObject,
"CODENAME",
false);
93 INCREMENTAL = getString(abvClass, abvObject,
"INCREMENTAL",
false);
94 RELEASE = getString(abvClass, abvObject,
"RELEASE",
false);
95 SDK_INT = getInt(abvClass, abvObject,
"SDK_INT");
96 final String sdk_name;
97 if(
null != abvcObject ) {
98 final HashMap<Integer, String> version_codes = getVersionCodes(abvcClass, abvcObject);
99 sdk_name = version_codes.get(
SDK_INT);
142 private static final HashMap<Integer, String> getVersionCodes(
final Class<?> cls,
final Object obj) {
143 final Field[] fields = cls.getFields();
144 final HashMap<Integer, String> map =
new HashMap<Integer, String>( 3 * fields.length / 2, 0.75f );
145 for(
int i=0; i<fields.length; i++) {
147 final int version = fields[i].getInt(obj);
148 final String version_name = fields[i].getName();
150 map.put(Integer.valueOf(version), version_name);
151 }
catch (
final Exception e) { e.printStackTrace(); }
156 private static final String getString(
final Class<?> cls,
final Object obj,
final String name,
final boolean lowerCase) {
158 final Field f = cls.getField(name);
159 final String s = (String) f.get(obj);
160 if( lowerCase &&
null != s ) {
161 return s.toLowerCase();
165 }
catch (
final Exception e) { e.printStackTrace(); }
169 private static final int getInt(
final Class<?> cls,
final Object obj,
final String name) {
171 final Field f = cls.getField(name);
172 return f.getInt(obj);
173 }
catch (
final Exception e) { e.printStackTrace(); }
Utility methods to simplify reflection access.
static final Class<?> getClass(final String clazzName, final boolean initializeClazz, final ClassLoader cl)
Loads and returns the class or null.
static final int SDK_INT
SDK Version number, key to VERSION_CODES.
static final boolean isAvailable
static final String CPU_ABI2_NAME
The name of the second instruction set (CPU type + ABI convention) of native code.
static final CPUType CPU2
static final String SDK_NAME
SDK Version string.
static final String CPU_ABI_NAME
The name of the instruction set (CPU type + ABI convention) of native code.
static final ABIType ABI2
static final String RELEASE
official build version string
static final String INCREMENTAL
internal build value used by the underlying source control.
static final String CODENAME
Development codename, or the string "REL" for official release.