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
diff --git a/core/java/android/webkit/JniUtil.java b/core/java/android/webkit/JniUtil.java
index 620973e..4264e9d 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 @@
                 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();
 }