Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1258)

Unified Diff: base/android/java/src/org/chromium/base/SysUtils.java

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
}
}

Powered by Google App Engine
This is Rietveld 408576698