From baf48509c5cd84d8fe09de5cba66785c86f07251 Mon Sep 17 00:00:00 2001 From: SerpentSpirale Date: Wed, 11 Aug 2021 14:28:32 +0200 Subject: [PATCH] Improved Architecture class. --- .../net/kdt/pojavlaunch/Architecture.java | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Architecture.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Architecture.java index 6769afbb0..bc14657fd 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Architecture.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Architecture.java @@ -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; } }