GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
AndroidVersion.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.common.os;
29
30import java.lang.reflect.Field;
31
32import com.jogamp.common.os.Platform.ABIType;
33import com.jogamp.common.os.Platform.CPUType;
34import com.jogamp.common.util.IntObjectHashMap;
35import com.jogamp.common.util.ReflectionUtil;
36
37public class AndroidVersion {
38 public static final boolean isAvailable;
39
40 /** The name of the instruction set (CPU type + ABI convention) of native code. API-4. All lower case.*/
41 public static final String CPU_ABI;
42 public static final CPUType CPU_TYPE;
43 public static final ABIType ABI_TYPE;
44
45 /** The name of the second instruction set (CPU type + ABI convention) of native code. API-8. All lower case.*/
46 public static final String CPU_ABI2;
47 public static final CPUType CPU_TYPE2;
48 public static final ABIType ABI_TYPE2;
49
50 /** Development codename, or the string "REL" for official release */
51 public static final String CODENAME;
52
53 /** internal build value used by the underlying source control. */
54 public static final String INCREMENTAL;
55
56 /** official build version string */
57 public static final String RELEASE;
58
59 /** SDK Version number, key to VERSION_CODES */
60 public static final int SDK_INT;
61
62 /** SDK Version string */
63 public static final String SDK_NAME;
64
65 private static final String androidBuild = "android.os.Build";
66 private static final String androidBuildVersion = "android.os.Build$VERSION";
67 private static final String androidBuildVersionCodes = "android.os.Build$VERSION_CODES";
68
69 static {
70 final ClassLoader cl = AndroidVersion.class.getClassLoader();
71 Class<?> abClass = null;
72 Object abObject= null;
73 Class<?> abvClass = null;
74 Object abvObject= null;
75 Class<?> abvcClass = null;
76 Object abvcObject= null;
77
78 final boolean isDalvikVm = "Dalvik".equals(System.getProperty("java.vm.name"));
79
80 if (isDalvikVm) {
81 try {
82 abClass = ReflectionUtil.getClass(androidBuild, true, cl);
83 abObject = abClass.newInstance();
84 abvClass = ReflectionUtil.getClass(androidBuildVersion, true, cl);
85 abvObject = abvClass.newInstance();
86 abvcClass = ReflectionUtil.getClass(androidBuildVersionCodes, true, cl);
87 abvcObject = abvcClass.newInstance();
88 } catch (final Exception e) { /* n/a */ }
89 }
90 isAvailable = isDalvikVm && null != abObject && null != abvObject;
91 if(isAvailable) {
92 CPU_ABI = getString(abClass, abObject, "CPU_ABI", true);
93 CPU_ABI2 = getString(abClass, abObject, "CPU_ABI2", true);
94 CODENAME = getString(abvClass, abvObject, "CODENAME", false);
95 INCREMENTAL = getString(abvClass, abvObject, "INCREMENTAL", false);
96 RELEASE = getString(abvClass, abvObject, "RELEASE", false);
97 SDK_INT = getInt(abvClass, abvObject, "SDK_INT");
98 final String sdk_name;
99 if( null != abvcObject ) {
100 final IntObjectHashMap version_codes = getVersionCodes(abvcClass, abvcObject);
101 sdk_name = (String) version_codes.get(SDK_INT);
102 } else {
103 sdk_name = null;
104 }
105 SDK_NAME = ( null != sdk_name ) ? sdk_name : "SDK_"+SDK_INT ;
106
107 /**
108 * <p>
109 * FIXME: Where is a comprehensive list of known 'android.os.Build.CPU_ABI' and 'android.os.Build.CPU_ABI2' strings ?<br/>
110 * Fount this one: <code>http://www.kandroid.org/ndk/docs/CPU-ARCH-ABIS.html</code>
111 * <pre>
112 * lib/armeabi/libfoo.so
113 * lib/armeabi-v7a/libfoo.so
114 * lib/arm64-v8a/libfoo.so
115 * lib/x86/libfoo.so
116 * lib/mips/libfoo.so
117 * </pre>
118 * </p>
119 */
122 if( null != CPU_ABI2 && CPU_ABI2.length() > 0 ) {
125 } else {
126 CPU_TYPE2 = null;
127 ABI_TYPE2 = null;
128 }
129 } else {
130 CPU_ABI = null;
131 CPU_ABI2 = null;
132 CODENAME = null;
133 INCREMENTAL = null;
134 RELEASE = null;
135 SDK_INT = -1;
136 SDK_NAME = null;
137 CPU_TYPE = null;
138 ABI_TYPE = null;
139 CPU_TYPE2 = null;
140 ABI_TYPE2 = null;
141 }
142 }
143
144 private static final IntObjectHashMap getVersionCodes(final Class<?> cls, final Object obj) {
145 final Field[] fields = cls.getFields();
146 final IntObjectHashMap map = new IntObjectHashMap( 3 * fields.length / 2, 0.75f );
147 for(int i=0; i<fields.length; i++) {
148 try {
149 final int version = fields[i].getInt(obj);
150 final String version_name = fields[i].getName();
151 // System.err.println(i+": "+version+": "+version_name);
152 map.put(new Integer(version), version_name);
153 } catch (final Exception e) { e.printStackTrace(); /* n/a */ }
154 }
155 return map;
156 }
157
158 private static final String getString(final Class<?> cls, final Object obj, final String name, final boolean lowerCase) {
159 try {
160 final Field f = cls.getField(name);
161 final String s = (String) f.get(obj);
162 if( lowerCase && null != s ) {
163 return s.toLowerCase();
164 } else {
165 return s;
166 }
167 } catch (final Exception e) { e.printStackTrace(); /* n/a */ }
168 return null;
169 }
170
171 private static final int getInt(final Class<?> cls, final Object obj, final String name) {
172 try {
173 final Field f = cls.getField(name);
174 return f.getInt(obj);
175 } catch (final Exception e) { e.printStackTrace(); /* n/a */ }
176 return -1;
177 }
178
179 // android.os.Build.VERSION
180}
static final String CPU_ABI
The name of the instruction set (CPU type + ABI convention) of native code.
static final int SDK_INT
SDK Version number, key to VERSION_CODES.
static final String CODENAME
Development codename, or the string "REL" for official release.
static final String SDK_NAME
SDK Version string.
static final String CPU_ABI2
The name of the second instruction set (CPU type + ABI convention) of native code.
static final String INCREMENTAL
internal build value used by the underlying source control.
static final String RELEASE
official build version string
Utility class for querying platform specific properties.
Definition: Platform.java:58
Fast HashMap for primitive data.
Object put(final int key, final Object value)
Maps the key to the specified value.
Object get(final int key)
Returns the value to which the specified key is mapped, or getKeyNotFoundValue if this map contains n...
static final Class<?> getClass(final String clazzName, final boolean initializeClazz, final ClassLoader cl)
Loads and returns the class or null.
static final ABIType query(final CPUType cpuType, final String cpuABILower)
Definition: Platform.java:237
static final CPUType query(final String cpuABILower)
Definition: Platform.java:147