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

Commit 1f5d9af0 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Additional hand-migration to TypedXml interface.

Previous changes have applied mechanical refactorings, but this change
hand-migrates the remaining logic which was too complex to identify.

This change should have no behavior change; famous last words.

Bug: 171832118
Test: manual
Exempt-From-Owner-Approval: trivial refactoring
Change-Id: If2d4b1a354481a83edb4bbcfa22f690b7f5e97c3
parent 42bd7605
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ public class Xml {
     *
     * @hide
     */
    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static @NonNull TypedXmlPullParser newFastPullParser() {
        return XmlUtils.makeTyped(newPullParser());
    }
@@ -206,6 +207,7 @@ public class Xml {
     *
     * @hide
     */
    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static @NonNull TypedXmlSerializer newFastSerializer() {
        return XmlUtils.makeTyped(new FastXmlSerializer());
    }
+15 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import java.util.Set;
public class XmlUtils {
    private static final String STRING_ARRAY_SEPARATOR = ":";

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    private static class ForcedTypedXmlSerializer extends XmlSerializerWrapper
            implements TypedXmlSerializer {
        public ForcedTypedXmlSerializer(XmlSerializer wrapped) {
@@ -133,6 +134,7 @@ public class XmlUtils {
        }
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    private static class ForcedTypedXmlPullParser extends XmlPullParserWrapper
            implements TypedXmlPullParser {
        public ForcedTypedXmlPullParser(XmlPullParser wrapped) {
@@ -1715,6 +1717,7 @@ public class XmlUtils {
        }
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static int readIntAttribute(XmlPullParser in, String name, int defaultValue) {
        if (in instanceof TypedXmlPullParser) {
            return ((TypedXmlPullParser) in).getAttributeInt(null, name, defaultValue);
@@ -1730,6 +1733,7 @@ public class XmlUtils {
        }
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static int readIntAttribute(XmlPullParser in, String name) throws IOException {
        if (in instanceof TypedXmlPullParser) {
            try {
@@ -1746,6 +1750,7 @@ public class XmlUtils {
        }
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static void writeIntAttribute(XmlSerializer out, String name, int value)
            throws IOException {
        if (out instanceof TypedXmlSerializer) {
@@ -1755,6 +1760,7 @@ public class XmlUtils {
        out.attribute(null, name, Integer.toString(value));
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static long readLongAttribute(XmlPullParser in, String name, long defaultValue) {
        if (in instanceof TypedXmlPullParser) {
            return ((TypedXmlPullParser) in).getAttributeLong(null, name, defaultValue);
@@ -1770,6 +1776,7 @@ public class XmlUtils {
        }
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static long readLongAttribute(XmlPullParser in, String name) throws IOException {
        if (in instanceof TypedXmlPullParser) {
            try {
@@ -1786,6 +1793,7 @@ public class XmlUtils {
        }
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static void writeLongAttribute(XmlSerializer out, String name, long value)
            throws IOException {
        if (out instanceof TypedXmlSerializer) {
@@ -1795,6 +1803,7 @@ public class XmlUtils {
        out.attribute(null, name, Long.toString(value));
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static float readFloatAttribute(XmlPullParser in, String name) throws IOException {
        if (in instanceof TypedXmlPullParser) {
            try {
@@ -1811,6 +1820,7 @@ public class XmlUtils {
        }
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static void writeFloatAttribute(XmlSerializer out, String name, float value)
            throws IOException {
        if (out instanceof TypedXmlSerializer) {
@@ -1820,10 +1830,12 @@ public class XmlUtils {
        out.attribute(null, name, Float.toString(value));
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static boolean readBooleanAttribute(XmlPullParser in, String name) {
        return readBooleanAttribute(in, name, false);
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static boolean readBooleanAttribute(XmlPullParser in, String name,
            boolean defaultValue) {
        if (in instanceof TypedXmlPullParser) {
@@ -1837,6 +1849,7 @@ public class XmlUtils {
        }
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static void writeBooleanAttribute(XmlSerializer out, String name, boolean value)
            throws IOException {
        if (out instanceof TypedXmlSerializer) {
@@ -1869,6 +1882,7 @@ public class XmlUtils {
        }
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static byte[] readByteArrayAttribute(XmlPullParser in, String name) {
        if (in instanceof TypedXmlPullParser) {
            try {
@@ -1885,6 +1899,7 @@ public class XmlUtils {
        }
    }

    @SuppressWarnings("AndroidFrameworkEfficientXml")
    public static void writeByteArrayAttribute(XmlSerializer out, String name, byte[] value)
            throws IOException {
        if (value != null) {
+24 −0
Original line number Diff line number Diff line
@@ -292,6 +292,30 @@ public class EfficientXml {
        }
    }

    class BooleanToStringTrue {
        @BeforeTemplate
        void before(TypedXmlSerializer out, String n) throws Exception {
            out.attribute(null, n, "true");
        }

        @AfterTemplate
        void after(TypedXmlSerializer out, String n) throws Exception {
            out.attributeBoolean(null, n, true);
        }
    }

    class BooleanToStringFalse {
        @BeforeTemplate
        void before(TypedXmlSerializer out, String n) throws Exception {
            out.attribute(null, n, "false");
        }

        @AfterTemplate
        void after(TypedXmlSerializer out, String n) throws Exception {
            out.attributeBoolean(null, n, false);
        }
    }

    class BooleanFromString {
        @BeforeTemplate
        boolean beforeParse(TypedXmlPullParser in, String n) throws Exception {
+1 −1
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ public final class SensorPrivacyService extends SystemService {
                XmlUtils.beginDocument(parser, XML_TAG_SENSOR_PRIVACY);
                parser.next();
                String tagName = parser.getName();
                enabled = Boolean.valueOf(parser.getAttributeValue(null, XML_ATTRIBUTE_ENABLED));
                enabled = parser.getAttributeBoolean(null, XML_ATTRIBUTE_ENABLED, false);
            } catch (IOException | XmlPullParserException e) {
                Log.e(TAG, "Caught an exception reading the state from storage: ", e);
                // Delete the file to prevent the same error on subsequent calls and assume sensor
Loading