Last active
March 25, 2022 18:53
-
-
Save andreymusth/14a3ab6afcf042b4f018160b68c84219 to your computer and use it in GitHub Desktop.
This file contains 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
public class SharedConfig { | |
private static int devicePerformanceClass; | |
public final static int PERFORMANCE_CLASS_LOW = 0; | |
public final static int PERFORMANCE_CLASS_AVERAGE = 1; | |
public final static int PERFORMANCE_CLASS_HIGH = 2; | |
public static int getDevicePerformanceClass() { | |
if (devicePerformanceClass == -1) { | |
int androidVersion = Build.VERSION.SDK_INT; | |
int cpuCount = Runtime.getRuntime().availableProcessors(); | |
int memoryClass = ((ActivityManager) ApplicationLoader.applicationContext.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); | |
int totalCpuFreq = 0; | |
int freqResolved = 0; | |
for (int i = 0; i < cpuCount; i++) { | |
try { | |
RandomAccessFile reader = new RandomAccessFile(String.format(Locale.ENGLISH, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i), "r"); | |
String line = reader.readLine(); | |
if (line != null) { | |
totalCpuFreq += Utilities.parseInt(line) / 1000; | |
freqResolved++; | |
} | |
reader.close(); | |
} catch (Throwable ignore) {} | |
} | |
int maxCpuFreq = freqResolved == 0 ? -1 : (int) Math.ceil(totalCpuFreq / (float) freqResolved); | |
if (androidVersion < 21 || cpuCount <= 2 || memoryClass <= 100 || cpuCount <= 4 && maxCpuFreq != -1 && maxCpuFreq <= 1250 || cpuCount <= 4 && maxCpuFreq <= 1600 && memoryClass <= 128 && androidVersion <= 21 || cpuCount <= 4 && maxCpuFreq <= 1300 && memoryClass <= 128 && androidVersion <= 24) { | |
devicePerformanceClass = PERFORMANCE_CLASS_LOW; | |
} else if (cpuCount < 8 || memoryClass <= 160 || maxCpuFreq != -1 && maxCpuFreq <= 2050 || maxCpuFreq == -1 && cpuCount == 8 && androidVersion <= 23) { | |
devicePerformanceClass = PERFORMANCE_CLASS_AVERAGE; | |
} else { | |
devicePerformanceClass = PERFORMANCE_CLASS_HIGH; | |
} | |
if (BuildVars.LOGS_ENABLED) { | |
FileLog.d("device performance info (cpu_count = " + cpuCount + ", freq = " + maxCpuFreq + ", memoryClass = " + memoryClass + ", android version " + androidVersion + ")"); | |
} | |
} | |
return devicePerformanceClass; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment