This source file includes following definitions.
- amountOfPhysicalMemoryKB
- isLowEndDevice
- isLowEndStateInitialized
- detectLowEndDevice
package org.chromium.base;
import android.os.Build;
import android.util.Log;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SysUtils {
private static final int ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD =
Build.VERSION_CODES.JELLY_BEAN_MR2;
private static final long ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB = 512;
private static final String TAG = "SysUtils";
private static Boolean sLowEndDevice;
private SysUtils() { }
@CalledByNative
public static int amountOfPhysicalMemoryKB() {
Pattern pattern = Pattern.compile("^MemTotal:\\s+([0-9]+) kB$");
try {
FileReader fileReader = new FileReader("/proc/meminfo");
try {
BufferedReader reader = new BufferedReader(fileReader);
try {
String line;
for (;;) {
line = reader.readLine();
if (line == null) {
Log.w(TAG, "/proc/meminfo lacks a MemTotal entry?");
break;
}
Matcher m = pattern.matcher(line);
if (!m.find()) continue;
int totalMemoryKB = Integer.parseInt(m.group(1));
if (totalMemoryKB <= 1024) {
Log.w(TAG, "Invalid /proc/meminfo total size in kB: " + m.group(1));
break;
}
return totalMemoryKB;
}
} finally {
reader.close();
}
} finally {
fileReader.close();
}
} catch (Exception e) {
Log.w(TAG, "Cannot get total physical size from /proc/meminfo", e);
}
return 0;
}
@CalledByNative
public static boolean isLowEndDevice() {
if (sLowEndDevice == null) {
sLowEndDevice = detectLowEndDevice();
}
return sLowEndDevice.booleanValue();
}
public static boolean isLowEndStateInitialized() {
return (sLowEndDevice != null);
}
private static boolean detectLowEndDevice() {
if (CommandLine.isInitialized()) {
if (CommandLine.getInstance().hasSwitch(BaseSwitches.ENABLE_LOW_END_DEVICE_MODE)) {
return true;
}
if (CommandLine.getInstance().hasSwitch(BaseSwitches.DISABLE_LOW_END_DEVICE_MODE)) {
return false;
}
}
if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) {
return false;
}
int ramSizeKB = amountOfPhysicalMemoryKB();
return (ramSizeKB > 0 && ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB);
}
}