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

Commit 304eae34 authored by Deepanshu Gupta's avatar Deepanshu Gupta Committed by The Android Automerger
Browse files

Don't keep LayoutlibCallback reference.

Switch to the newer API that enables keeping a reference only to the
ParserFactory which is a much leaner object as compared to
LayoutlibCallback.

Change-Id: I9b7afd93226db23786a00b2951cbf5ae5b8f3e5f
parent 700132dd
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.layoutlib.bridge.impl;

import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.ide.common.rendering.api.LayoutlibCallback;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -44,10 +43,11 @@ public class ParserFactory {

    // Used to get a new XmlPullParser from the client.
    @Nullable
    private static LayoutlibCallback sLayoutlibCallback;
    private static com.android.ide.common.rendering.api.ParserFactory sParserFactory;

    public static void setLayoutlibCallback(@Nullable LayoutlibCallback callback) {
        sLayoutlibCallback = callback;
    public static void setParserFactory(
            @Nullable com.android.ide.common.rendering.api.ParserFactory parserFactory) {
        sParserFactory = parserFactory;
    }

    @NonNull
@@ -77,10 +77,10 @@ public class ParserFactory {
    @NonNull
    public static XmlPullParser instantiateParser(@Nullable String name)
            throws XmlPullParserException {
        if (sLayoutlibCallback == null) {
        if (sParserFactory == null) {
            throw new XmlPullParserException("ParserFactory not initialized.");
        }
        XmlPullParser parser = sLayoutlibCallback.createParser(name);
        XmlPullParser parser = sParserFactory.createParser(name);
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        return parser;
    }
+2 −4
Original line number Diff line number Diff line
@@ -39,8 +39,6 @@ import android.view.inputmethod.InputMethodManager_Accessor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

import javax.swing.text.html.parser.Parser;

import static com.android.ide.common.rendering.api.Result.Status.ERROR_LOCK_INTERRUPTED;
import static com.android.ide.common.rendering.api.Result.Status.ERROR_TIMEOUT;
import static com.android.ide.common.rendering.api.Result.Status.SUCCESS;
@@ -102,7 +100,7 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso
        }

        // setup the ParserFactory
        ParserFactory.setLayoutlibCallback(mParams.getLayoutlibCallback());
        ParserFactory.setParserFactory(mParams.getLayoutlibCallback().getParserFactory());

        HardwareConfig hardwareConfig = mParams.getHardwareConfig();

@@ -276,7 +274,7 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso
            mContext.getRenderResources().setFrameworkResourceIdProvider(null);
            mContext.getRenderResources().setLogger(null);
        }
        ParserFactory.setLayoutlibCallback(null);
        ParserFactory.setParserFactory(null);

    }

+4 −74
Original line number Diff line number Diff line
@@ -17,15 +17,7 @@
package com.android.layoutlib.bridge.android;

import com.android.annotations.NonNull;
import com.android.ide.common.rendering.api.ActionBarCallback;
import com.android.ide.common.rendering.api.AdapterBinding;
import com.android.ide.common.rendering.api.ILayoutPullParser;
import com.android.ide.common.rendering.api.LayoutlibCallback;
import com.android.ide.common.rendering.api.ResourceReference;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.layoutlib.bridge.impl.ParserFactory;
import com.android.resources.ResourceType;
import com.android.util.Pair;

import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -41,7 +33,7 @@ public class BridgeXmlBlockParserTest {

    @BeforeClass
    public static void setUp() {
        ParserFactory.setLayoutlibCallback(new LayoutlibTestCallback());
        ParserFactory.setParserFactory(new ParserFactoryImpl());
    }

    @Test
@@ -129,78 +121,16 @@ public class BridgeXmlBlockParserTest {

    @AfterClass
    public static void tearDown() {
        ParserFactory.setLayoutlibCallback(null);
        ParserFactory.setParserFactory(null);
    }

    private static class LayoutlibTestCallback extends LayoutlibCallback {
    private static class ParserFactoryImpl
            extends com.android.ide.common.rendering.api.ParserFactory {

        @NonNull
        @Override
        public XmlPullParser createParser(String displayName) throws XmlPullParserException {
            return new KXmlParser();
        }

        @Override
        public boolean supports(int ideFeature) {
            throw new AssertionError();
        }

        @Override
        public Object loadView(String name, Class[] constructorSignature, Object[] constructorArgs)
                throws Exception {
            throw new AssertionError();
        }

        @Override
        public String getNamespace() {
            throw new AssertionError();
        }

        @Override
        @SuppressWarnings("deprecation")
        public Pair<ResourceType, String> resolveResourceId(int id) {
            throw new AssertionError();
        }

        @Override
        public String resolveResourceId(int[] id) {
            throw new AssertionError();
        }

        @Override
        public Integer getResourceId(ResourceType type, String name) {
            throw new AssertionError();
        }

        @Override
        @SuppressWarnings("deprecation")
        public ILayoutPullParser getParser(String layoutName) {
            throw new AssertionError();
        }

        @Override
        public ILayoutPullParser getParser(ResourceValue layoutResource) {
            throw new AssertionError();
        }

        @Override
        public Object getAdapterItemValue(ResourceReference adapterView, Object adapterCookie,
                ResourceReference itemRef, int fullPosition, int positionPerType,
                int fullParentPosition, int parentPositionPerType, ResourceReference viewRef,
                ViewAttribute viewAttribute, Object defaultValue) {
            throw new AssertionError();
        }

        @Override
        public AdapterBinding getAdapterBinding(ResourceReference adapterViewRef,
                Object adapterCookie,
                Object viewObject) {
            throw new AssertionError();
        }

        @Override
        public ActionBarCallback getActionBarCallback() {
            throw new AssertionError();
        }
    }
}