mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 07:39:00 -04:00
Improved Architecture class.
This commit is contained in:
parent
54f2a1e464
commit
baf48509c5
@ -7,6 +7,7 @@ import java.util.Locale;
|
||||
|
||||
public class Architecture
|
||||
{
|
||||
public static int UNSUPPORTED_ARCH = -1;
|
||||
public static int ARCH_ARM64 = 0x1;
|
||||
public static int ARCH_ARM = 0x2;
|
||||
public static int ARCH_X86 = 0x4;
|
||||
@ -31,17 +32,46 @@ public class Architecture
|
||||
|
||||
/**
|
||||
* Tells the device supported architecture
|
||||
* As of now, the function may just fail to detect ARM emulation from zenfones
|
||||
*
|
||||
* @return ARCH_ARM || ARCH_ARM64 || ARCH_X86 || ARCH_86_64
|
||||
*/
|
||||
public static int getDeviceArchitecture(){
|
||||
if(is64BitsDevice()){
|
||||
return archAsInt(Build.SUPPORTED_64_BIT_ABIS[0]);
|
||||
if(isx86Device()){
|
||||
return is64BitsDevice() ? ARCH_X86_64 : ARCH_X86;
|
||||
}
|
||||
return archAsInt(Build.SUPPORTED_32_BIT_ABIS[0]);
|
||||
return is64BitsDevice() ? ARCH_ARM64 : ARCH_ARM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell is the device is based on an x86 processor.
|
||||
* It doesn't tell if the device is 64 or 32 bits.
|
||||
* @return Whether or not the device is x86 based.
|
||||
*/
|
||||
public static boolean isx86Device(){
|
||||
//We check the whole range of supported ABIs,
|
||||
//Since zenfones can place arm before their native instruction set.
|
||||
if(is64BitsDevice()){
|
||||
for(String str : Build.SUPPORTED_64_BIT_ABIS){
|
||||
if(archAsInt(str) == ARCH_X86_64) return true;
|
||||
}
|
||||
}else{
|
||||
for(String str : Build.SUPPORTED_32_BIT_ABIS){
|
||||
if(archAsInt(str) == ARCH_X86) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell is the device is based on an arm processor.
|
||||
* It doesn't tell if the device is 64 or 32 bits.
|
||||
* @return Whether or not the device is arm based.
|
||||
*/
|
||||
public static boolean isArmDevice(){
|
||||
return !isx86Device();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert an architecture from a String to an int.
|
||||
* @param arch The architecture as a String
|
||||
@ -50,11 +80,11 @@ public class Architecture
|
||||
public static int archAsInt(String arch){
|
||||
arch = arch.toLowerCase();
|
||||
if(arch.equals("arm64-v8a") || arch.equals("aarch64")) return ARCH_ARM64;
|
||||
if(arch.contains("armeabi")) return ARCH_ARM;
|
||||
if(arch.contains("armeabi") ||arch.contains("armv7")) return ARCH_ARM;
|
||||
if(arch.equals("x86_64")) return ARCH_X86_64;
|
||||
if(arch.equals("x86") || (arch.startsWith("i") && arch.endsWith("86"))) return ARCH_X86;
|
||||
//Shouldn't happen
|
||||
return -1;
|
||||
return UNSUPPORTED_ARCH;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user