summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-08-10 13:02:00 +0100
committerBen Murdoch <benm@google.com>2011-08-12 17:22:15 +0100
commit84029a8e06c072c6e504ec8c3fe19b56e410cf82 (patch)
treedc62e2994f98231d46e799a81628ced30b4d3122 /core/java
parent1213697980d58d4285cc77a5dd80a453f008a077 (diff)
Add a function to query the available memory on the device.
This function is called over JNI to determine wheter a particular size of memory allocation will leave us in a low memory state. Bug: 5142892 Change-Id: I3d0f85075497c2a374cd866b0223eecaaa4b5f46
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/webkit/JniUtil.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/java/android/webkit/JniUtil.java b/core/java/android/webkit/JniUtil.java
index 620973e421d5..4264e9da354f 100644
--- a/core/java/android/webkit/JniUtil.java
+++ b/core/java/android/webkit/JniUtil.java
@@ -16,6 +16,7 @@
package android.webkit;
+import android.app.ActivityManager;
import android.content.Context;
import android.net.Uri;
import android.provider.Settings;
@@ -175,5 +176,16 @@ class JniUtil {
Settings.Secure.WEB_AUTOFILL_QUERY_URL);
}
+ private static boolean canSatisfyMemoryAllocation(long bytesRequested) {
+ checkInitialized();
+ ActivityManager manager = (ActivityManager) sContext.getSystemService(
+ Context.ACTIVITY_SERVICE);
+ ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
+ manager.getMemoryInfo(memInfo);
+ long leftToAllocate = memInfo.availMem - memInfo.threshold;
+ return !memInfo.lowMemory && bytesRequested < leftToAllocate;
+ }
+
+
private static native boolean nativeUseChromiumHttpStack();
}