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

Commit fe5f9cfa authored by nadlabak's avatar nadlabak
Browse files

Allow purging of asset bitmaps

Allow the system to reclaim more free RAM when needed on 'low' memory devices
(e.g. Droid/Milestone) that are struggling with 2.3. This option enabled
efectively restores the froyo way of forcePurgeable BitmapFactory asset
handling.

Change-Id: If454e92743bf91efae42a8e4bcc2d2e7f9b90e91
parent 55343310
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include "Utils.h"

#include <android_runtime/AndroidRuntime.h>
#include <cutils/properties.h>
#include <utils/Asset.h>
#include <utils/ResourceTypes.h>
#include <netinet/in.h>
@@ -44,6 +45,8 @@ static jfieldID gFileDescriptor_descriptor;

using namespace android;

bool mPurgeableAssets;

class NinePatchPeeker : public SkImageDecoder::Peeker {
    SkImageDecoder* fHost;
public:
@@ -398,8 +401,8 @@ static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz,
                                 jobject options) { // BitmapFactory$Options
    SkStream* stream;
    Asset* asset = reinterpret_cast<Asset*>(native_asset);
    bool forcePurgeable = optionsPurgeable(env, options);
    if (forcePurgeable) {
    bool forcePurgeable = mPurgeableAssets;
    if (forcePurgeable || optionsPurgeable(env, options)) {
        // if we could "ref/reopen" the asset, we may not need to copy it here
        // and we could assume optionsShareable, since assets are always RO
        stream = copyAssetToStream(asset);
@@ -566,6 +569,10 @@ int register_android_graphics_BitmapFactory(JNIEnv* env) {
    gFileDescriptor_class = make_globalref(env, "java/io/FileDescriptor");
    gFileDescriptor_descriptor = getFieldIDCheck(env, gFileDescriptor_class, "descriptor", "I");

    char value[PROPERTY_VALUE_MAX];
    property_get("persist.sys.purgeable_assets", value, "0");
    mPurgeableAssets = atoi(value) == 1;

    int ret = AndroidRuntime::registerNativeMethods(env,
                                    "android/graphics/BitmapFactory$Options",
                                    gOptionsMethods,