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

Commit 753dc288 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "Allow purging of asset bitmaps" into gingerbread

parents abf7b814 fe5f9cfa
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,