Last active
October 24, 2017 03:27
-
-
Save jaredrummler/a48dee45ce146d33c35f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright (C) 2015 Jared Rummler <jared.rummler@gmail.com | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| package com.jrummyapps.android.os; | |
| import android.os.Build; | |
| import android.text.TextUtils; | |
| /** | |
| * <a href="https://developer.android.com/ndk/guides/abis.html">Application Binary Interface</a> | |
| */ | |
| public enum ABI { | |
| /** | |
| * <p>This ABI is for ARM-based CPUs that support at least the ARMv5TE instruction set.</p> | |
| * | |
| * <p>Supported Instruction Sets:</p> | |
| * | |
| * <ul> | |
| * <li>ARMV5TE and later</li> | |
| * <li>Thumb-1</li> | |
| * </ul> | |
| * | |
| * <b>Notes:</b> No hard float. | |
| */ | |
| ARMEABI("armeabi"), | |
| /** | |
| * <p>This ABI extends armeabi to include several CPU instruction set extensions</p> | |
| * | |
| * <p>Supported Instruction Sets:</p> | |
| * | |
| * <ul> | |
| * <li>armeabi</li> | |
| * <li>Thumb-2</li> | |
| * <li>VFPv3-D16</li> | |
| * <li>Other, optional</li> | |
| * </ul> | |
| * | |
| * <b>Notes:</b> Hard float when specified as armeabi-v7a-hard. Incompatible with ARMv5, v6 | |
| * devices. | |
| */ | |
| ARMEABI_V7A("armeabi-v7a"), | |
| /** | |
| * <p>This ABI extends armeabi to include several CPU instruction set extensions</p> | |
| * | |
| * <p>Supported Instruction Sets:</p> | |
| * | |
| * <ul> | |
| * <li>armeabi</li> | |
| * <li>Thumb-2</li> | |
| * <li>VFPv3-D16</li> | |
| * <li>Other, optional</li> | |
| * </ul> | |
| * | |
| * <b>Notes:</b> Hard float when specified as armeabi-v7a-hard. Incompatible with ARMv5, v6 | |
| * devices. | |
| */ | |
| ARMEABI_V7A_HARD("armeabi-v7a-hard"), | |
| /** | |
| * <p>This ABI is for ARMv8-based CPUs that support AArch64. It also includes the NEON and VFPv4 | |
| * instruction sets.</p> | |
| * | |
| * <p>Supported Instruction Set:</p> | |
| * | |
| * <ul> | |
| * <li>AArch-64</li> | |
| * </ul> | |
| */ | |
| ARM64_V8A("arm64-v8a"), | |
| /** | |
| * <p>This ABI is for CPUs supporting the instruction set commonly referred to as "x86" or | |
| * "IA-32".</p> | |
| * | |
| * <p>Supported Instruction Sets:</p> | |
| * | |
| * <ul> | |
| * <li>x86 (IA-32)</li> | |
| * <li>MMX</li> | |
| * <li>SSE/2/3</li> | |
| * <li>SSSE3</li> | |
| * </ul> | |
| * | |
| * <b>Notes:</b> No support for MOVBE or SSE4. | |
| */ | |
| X86("x86"), | |
| /** | |
| * <p>This ABI is for CPUs supporting the instruction set commonly referred to as "x86-64".</p> | |
| * | |
| * <p>Supported Instruction Sets:</p> | |
| * | |
| * <ul> | |
| * <li>x86-64</li> | |
| * <li>MMX</li> | |
| * <li>SSE/2/3</li> | |
| * <li>SSSE3</li> | |
| * <li>SSE4.1, 4.2</li> | |
| * <li>POPCNT</li> | |
| * </ul> | |
| */ | |
| X86_64("x86_64"), | |
| /** | |
| * <p>This ABI is for MIPS-based CPUs that support at least the MIPS32r1 instruction set.</p> | |
| * | |
| * <p>Supported Instruction Set:</p> | |
| * | |
| * <ul> | |
| * <li>MIPS32r1 and later</li> | |
| * </ul> | |
| * | |
| * <b>Notes:</b> Uses hard-float, and assumes a CPU:FPU clock ratio of 2:1 for maximum | |
| * compatibility. Provides neither micromips nor MIPS16. | |
| */ | |
| MIPS("mips"), | |
| /** | |
| * <p>This ABI is for MIPS64 R6.</p> | |
| * | |
| * <p>Supported Instruction Set:</p> | |
| * | |
| * <ul> | |
| * <li>MIPS64r6</li> | |
| * </ul> | |
| */ | |
| MIPS64("mips64"); | |
| /** | |
| * @return an ordered list of ABIs supported by this device. The most preferred ABI is the first | |
| * element in the list. | |
| */ | |
| public static String[] getSupportedAbis() { | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
| return Build.SUPPORTED_ABIS; | |
| } | |
| String abi1 = Build.CPU_ABI; | |
| String abi2 = Build.CPU_ABI2; | |
| if (!TextUtils.isEmpty(abi2)) { | |
| return new String[]{abi1, abi2}; | |
| } | |
| return new String[]{abi1}; | |
| } | |
| /** | |
| * @return the preferred ABI | |
| */ | |
| public static ABI getAbi() { | |
| String[] abis = getSupportedAbis(); | |
| for (String name : abis) { | |
| for (ABI abi : values()) { | |
| if (name.equals(abi.name)) { | |
| return abi; | |
| } | |
| } | |
| } | |
| return ABI.ARMEABI; | |
| } | |
| /** | |
| * @return {@code true} if the device has a 64 bit processor | |
| */ | |
| public static boolean is64Bit() { | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
| String[] abis = Build.SUPPORTED_64_BIT_ABIS; | |
| return abis != null && abis.length > 0; | |
| } | |
| return getAbi().name.contains("64"); | |
| } | |
| /** application binary interface name */ | |
| public final String name; | |
| ABI(String name) { | |
| this.name = name; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment