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

Commit 1fba3501 authored by Xavier Ducrohet's avatar Xavier Ducrohet Committed by Android (Google) Code Review
Browse files

Merge "Layoutlib: Properly dispose of bitmap delegate."

parents 71d4ecb1 5a09488a
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -162,8 +162,7 @@ public class Bitmap_Delegate {
    }

    /*package*/ static void nativeDestructor(int nativeBitmap) {
        // FIXME implement native delegate
        throw new UnsupportedOperationException("Native delegate needed for Bitmap");
        sManager.removeDelegate(nativeBitmap);
    }

    /*package*/ static void nativeRecycle(int nativeBitmap) {
+10 −78
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.tools.layoutlib.create.OverrideMethod;

import android.graphics.Bitmap;
import android.graphics.Typeface_Delegate;
import android.util.Finalizers;

import java.lang.ref.SoftReference;
import java.lang.reflect.Field;
@@ -114,19 +115,12 @@ public final class Bridge extends LayoutBridge {
     */
    @Override
    public boolean init(String fontOsLocation, Map<String, Map<String, Integer>> enumValueMap) {
        BridgeAssetManager.initSystem();
        sEnumValueMap = enumValueMap;

        return sinit(fontOsLocation, enumValueMap);
    }
        Finalizers.init();

    @Override
    public boolean dispose() {
        BridgeAssetManager.clearSystem();
        return true;
    }
        BridgeAssetManager.initSystem();

    private static synchronized boolean sinit(String fontOsLocation,
            Map<String, Map<String, Integer>> enumValueMap) {

        // When DEBUG_LAYOUT is set and is not 0 or false, setup a default listener
        // on static (native) methods which prints the signature on the console and
@@ -165,8 +159,6 @@ public final class Bridge extends LayoutBridge {
            return false;
        }

        sEnumValueMap = enumValueMap;

        // now parse com.android.internal.R (and only this one as android.R is a subset of
        // the internal version), and put the content in the maps.
        try {
@@ -214,6 +206,12 @@ public final class Bridge extends LayoutBridge {
        return true;
    }

    @Override
    public boolean dispose() {
        BridgeAssetManager.clearSystem();
        return true;
    }

    /**
     * Sets a 9 patch in a project cache or in the framework cache.
     * @param value the path of the 9 patch
@@ -423,70 +421,4 @@ public final class Bridge extends LayoutBridge {

        return null;
    }


    // ---------- OBSOLETE API METHODS ----------

    /*
     * For compatilibty purposes, we implement the old deprecated version of computeLayout.
     * (non-Javadoc)
     * @see com.android.layoutlib.api.ILayoutBridge#computeLayout(com.android.layoutlib.api.IXmlPullParser, java.lang.Object, int, int, java.lang.String, java.util.Map, java.util.Map, com.android.layoutlib.api.IProjectCallback, com.android.layoutlib.api.ILayoutLog)
     */
    @Deprecated
    public com.android.layoutlib.api.ILayoutResult computeLayout(IXmlPullParser layoutDescription,
            Object projectKey,
            int screenWidth, int screenHeight, String themeName,
            Map<String, Map<String, IResourceValue>> projectResources,
            Map<String, Map<String, IResourceValue>> frameworkResources,
            IProjectCallback customViewLoader, ILayoutLog logger) {
        throw new UnsupportedOperationException();
    }

    /*
     * For compatilibty purposes, we implement the old deprecated version of computeLayout.
     * (non-Javadoc)
     * @see com.android.layoutlib.api.ILayoutBridge#computeLayout(com.android.layoutlib.api.IXmlPullParser, java.lang.Object, int, int, java.lang.String, boolean, java.util.Map, java.util.Map, com.android.layoutlib.api.IProjectCallback, com.android.layoutlib.api.ILayoutLog)
     */
    @Deprecated
    public com.android.layoutlib.api.ILayoutResult computeLayout(IXmlPullParser layoutDescription,
            Object projectKey,
            int screenWidth, int screenHeight, String themeName, boolean isProjectTheme,
            Map<String, Map<String, IResourceValue>> projectResources,
            Map<String, Map<String, IResourceValue>> frameworkResources,
            IProjectCallback customViewLoader, ILayoutLog logger) {
        throw new UnsupportedOperationException();
    }

    /*
     * For compatilibty purposes, we implement the old deprecated version of computeLayout.
     * (non-Javadoc)
     * @see com.android.layoutlib.api.ILayoutBridge#computeLayout(com.android.layoutlib.api.IXmlPullParser, java.lang.Object, int, int, int, float, float, java.lang.String, boolean, java.util.Map, java.util.Map, com.android.layoutlib.api.IProjectCallback, com.android.layoutlib.api.ILayoutLog)
     */
    @Deprecated
    public com.android.layoutlib.api.ILayoutResult computeLayout(IXmlPullParser layoutDescription,
            Object projectKey,
            int screenWidth, int screenHeight, int density, float xdpi, float ydpi,
            String themeName, boolean isProjectTheme,
            Map<String, Map<String, IResourceValue>> projectResources,
            Map<String, Map<String, IResourceValue>> frameworkResources,
            IProjectCallback customViewLoader, ILayoutLog logger) {
        throw new UnsupportedOperationException();
    }

    /*
     * (non-Javadoc)
     * @see com.android.layoutlib.api.ILayoutBridge#computeLayout(com.android.layoutlib.api.IXmlPullParser, java.lang.Object, int, int, boolean, int, float, float, java.lang.String, boolean, java.util.Map, java.util.Map, com.android.layoutlib.api.IProjectCallback, com.android.layoutlib.api.ILayoutLog)
     */
    @Deprecated
    public com.android.layoutlib.api.ILayoutResult computeLayout(IXmlPullParser layoutDescription,
            Object projectKey,
            int screenWidth, int screenHeight, boolean renderFullSize,
            int density, float xdpi, float ydpi,
            String themeName, boolean isProjectTheme,
            Map<String, Map<String, IResourceValue>> projectResources,
            Map<String, Map<String, IResourceValue>> frameworkResources,
            IProjectCallback customViewLoader, ILayoutLog logger) {
        throw new UnsupportedOperationException();
    }

}
+5 −11
Original line number Diff line number Diff line
@@ -59,10 +59,8 @@ public final class DelegateManager<T> {
     * @return the delegate or null if not found.
     */
    public T getDelegate(int native_object) {
        synchronized (mDelegates) {
        return mDelegates.get(native_object);
    }
    }

    /**
     * Adds a delegate to the manager and returns the native int used to identify it.
@@ -70,20 +68,16 @@ public final class DelegateManager<T> {
     * @return a unique native int to identify the delegate
     */
    public int addDelegate(T newDelegate) {
        synchronized (mDelegates) {
        int native_object = ++mDelegateCounter;
        mDelegates.put(native_object, newDelegate);
        return native_object;
    }
    }

    /**
     * Removes the delegate matching the given native int.
     * @param native_object the native int.
     */
    public void removeDelegate(int native_object) {
        synchronized (mDelegates) {
        mDelegates.remove(native_object);
    }
}
}