Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 84029a8e authored by Ben Murdoch's avatar Ben Murdoch
Browse files

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
parent 12136979
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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();
}