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

Commit e5a02a2f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Do not force endDocument for domain verify settings" into sc-dev am: 66c9982c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13762970

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I2d4ba7b1b104241234de1209c9e1f7bae7c68543
parents 0416ccb4 66c9982c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public class SettingsXml {
        @Override
        public void close() throws IOException {
            mWriteSection.closeCompletely();
            mXmlSerializer.endDocument();
            mXmlSerializer.flush();
        }
    }

+0 −1
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import com.android.server.pm.SettingsXml;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.Map;

/**
 * Reads and writes the old {@link android.content.pm.IntentFilterVerificationInfo} so that it can
+24 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.google.common.truth.Truth.assertWithMessage
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.xmlpull.v1.XmlPullParser
import java.io.File
import java.nio.charset.StandardCharsets
import java.util.UUID
@@ -41,21 +42,41 @@ class DomainVerificationPersistenceTest {

        internal fun File.writeXml(block: (serializer: TypedXmlSerializer) -> Unit) = apply {
            outputStream().use {
                // Explicitly use string based XML so it can printed in the test failure output
                Xml.newFastSerializer()
                // This must use the binary serializer the mirror the production behavior, as
                // there are slight differences with the string based one.
                Xml.newBinarySerializer()
                    .apply {
                        setOutput(it, StandardCharsets.UTF_8.name())
                        startDocument(null, true)
                        setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true)
                        // Write a wrapping tag to ensure the domain verification settings didn't
                        // close out the document, allowing other settings to be written
                        startTag(null, "wrapper-tag")
                    }
                    .apply(block)
                    .apply {
                        startTag(null, "trailing-tag")
                        endTag(null, "trailing-tag")
                        endTag(null, "wrapper-tag")
                    }
                    .endDocument()
            }
        }

        internal fun <T> File.readXml(block: (parser: TypedXmlPullParser) -> T) =
            inputStream().use {
                block(Xml.resolvePullParser(it))
                val parser = Xml.resolvePullParser(it)
                assertThat(parser.nextTag()).isEqualTo(XmlPullParser.START_TAG)
                assertThat(parser.name).isEqualTo("wrapper-tag")
                assertThat(parser.nextTag()).isEqualTo(XmlPullParser.START_TAG)
                block(parser).also {
                    assertThat(parser.nextTag()).isEqualTo(XmlPullParser.START_TAG)
                    assertThat(parser.name).isEqualTo("trailing-tag")
                    assertThat(parser.nextTag()).isEqualTo(XmlPullParser.END_TAG)
                    assertThat(parser.name).isEqualTo("trailing-tag")
                    assertThat(parser.nextTag()).isEqualTo(XmlPullParser.END_TAG)
                    assertThat(parser.name).isEqualTo("wrapper-tag")
                }
            }
    }