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

Commit df0c47e5 authored by Diego Perez's avatar Diego Perez
Browse files

Do not log errors while loading string arrays

When arrays contain references, if we can not resolve them, just return
the reference string. This matches the behaviour of resource resolution
in BridgeTypeArray.

Bug: http://b.android.com/228620
Test: Updates existing tests
Change-Id: Ia324f18d9128b8abf2ba676a83d4b424914e2c88
parent 7d7ef840
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -405,9 +405,6 @@ public class Resources_Delegate {
            rv = resources.mContext.getRenderResources().resolveResValue(rv);
            if (rv != null) {
                return rv.getValue();
            } else {
                Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE,
                        "Unable to resolve resource " + ref, null);
            }
        }
        // Not a reference.
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
        <!-- theme ref in android NS. value = @string/candidates_style = <u>candidates</u> -->
        <item>?android:attr/candidatesTextStyleSpans</item>
        <item>@android:string/unknownName</item>  <!-- value = Unknown -->
        <item>?EC</item>
    </string-array>

    <!-- resources that the above array can refer to -->
+37 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import java.util.concurrent.TimeUnit;

import com.google.android.collect.Lists;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -313,6 +314,12 @@ public class Main {
        sBridge = new Bridge();
        sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation,
                ConfigGenerator.getEnumMap(attrs), getLayoutLog());
        Bridge.getLock().lock();
        try {
            Bridge.setLog(getLayoutLog());
        } finally {
            Bridge.getLock().unlock();
        }
    }

    @Before
@@ -624,6 +631,36 @@ public class Main {
        assertEquals("app_name", resources.getResourceEntryName(id));
    }

    @Test
    public void testStringEscaping() throws Exception {
        // Setup
        // Create the layout pull parser for our resources (empty.xml can not be part of the test
        // app as it won't compile).
        LayoutPullParser parser = new LayoutPullParser("/empty.xml");
        // Create LayoutLibCallback.
        LayoutLibTestCallback layoutLibCallback =
                new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
        layoutLibCallback.initResources();
        SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_4,
                layoutLibCallback, "AppTheme", true, RenderingMode.NORMAL, 22);
        AssetManager assetManager = AssetManager.getSystem();
        DisplayMetrics metrics = new DisplayMetrics();
        Configuration configuration = RenderAction.getConfiguration(params);
        Resources resources = new Resources(assetManager, metrics, configuration);
        resources.mLayoutlibCallback = params.getLayoutlibCallback();
        resources.mContext =
                new BridgeContext(params.getProjectKey(), metrics, params.getResources(),
                        params.getAssets(), params.getLayoutlibCallback(), configuration,
                        params.getTargetSdkVersion(), params.isRtlSupported());

        int id = resources.mLayoutlibCallback.getResourceId(ResourceType.ARRAY, "string_array");
        String[] strings = resources.getStringArray(id);
        assertArrayEquals(
                new String[]{"mystring", "Hello world!", "candidates", "Unknown", "?EC"},
                strings);
        assertTrue(sRenderMessages.isEmpty());
    }

    @NonNull
    private LayoutPullParser createLayoutPullParser(String layoutPath) {
        return new LayoutPullParser(APP_TEST_RES + "/layout/" + layoutPath);