| Index: base/android/java/src/org/chromium/base/SysUtils.java
|
| diff --git a/base/android/java/src/org/chromium/base/SysUtils.java b/base/android/java/src/org/chromium/base/SysUtils.java
|
| index 1c8378c1255dfe7dbe836e1f84e01ac0e1a88864..0d0420422044840f9bf024ff0c3a5f09b30c8c0f 100644
|
| --- a/base/android/java/src/org/chromium/base/SysUtils.java
|
| +++ b/base/android/java/src/org/chromium/base/SysUtils.java
|
| @@ -4,6 +4,8 @@
|
|
|
| package org.chromium.base;
|
|
|
| +import android.app.ActivityManager;
|
| +import android.content.Context;
|
| import android.os.Build;
|
| import android.os.StrictMode;
|
| import android.util.Log;
|
| @@ -22,7 +24,10 @@ public class SysUtils {
|
| Build.VERSION_CODES.JELLY_BEAN_MR2;
|
|
|
| // A device reporting strictly more total memory in megabytes cannot be considered 'low-end'.
|
| - private static final long ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB = 512;
|
| + private static final int ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB = 512;
|
| +
|
| + // Number of kilobytes in a megabyte.
|
| + private static final int KBS_IN_MB = 1024;
|
|
|
| private static final String TAG = "SysUtils";
|
|
|
| @@ -35,7 +40,7 @@ public class SysUtils {
|
| * @return Amount of physical memory in kilobytes, or 0 if there was
|
| * an error trying to access the information.
|
| */
|
| - private static int amountOfPhysicalMemoryKB() {
|
| + private static int amountOfPhysicalMemoryMB() {
|
| // Extract total memory RAM size by parsing /proc/meminfo, note that
|
| // this is exactly what the implementation of sysconf(_SC_PHYS_PAGES)
|
| // does. However, it can't be called because this method must be
|
| @@ -68,12 +73,12 @@ public class SysUtils {
|
|
|
| int totalMemoryKB = Integer.parseInt(m.group(1));
|
| // Sanity check.
|
| - if (totalMemoryKB <= 1024) {
|
| + if (totalMemoryKB <= KBS_IN_MB) {
|
| Log.w(TAG, "Invalid /proc/meminfo total size in kB: " + m.group(1));
|
| break;
|
| }
|
|
|
| - return totalMemoryKB;
|
| + return totalMemoryKB / KBS_IN_MB;
|
| }
|
|
|
| } finally {
|
| @@ -115,7 +120,22 @@ public class SysUtils {
|
| return false;
|
| }
|
|
|
| - int ramSizeKB = amountOfPhysicalMemoryKB();
|
| - return (ramSizeKB > 0 && ramSizeKB / 1024 < ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB);
|
| + Context context = ApplicationStatus.getApplicationContext();
|
| + if (context != null) {
|
| + ActivityManager activityManager = (ActivityManager)
|
| + context.getSystemService(Context.ACTIVITY_SERVICE);
|
| + if (activityManager.isLowRamDevice()) {
|
| + return true;
|
| + }
|
| + } else {
|
| + Log.e(TAG, "ApplicationContext is null in ApplicationStatus");
|
| + }
|
| +
|
| + int ramSizeMB = amountOfPhysicalMemoryMB();
|
| + if (ramSizeMB <= 0) {
|
| + return false;
|
| + }
|
| +
|
| + return ramSizeMB < ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB;
|
| }
|
| }
|
|
|