Loading services/core/java/com/android/server/pm/SettingsXml.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -83,7 +83,7 @@ public class SettingsXml { @Override @Override public void close() throws IOException { public void close() throws IOException { mWriteSection.closeCompletely(); mWriteSection.closeCompletely(); mXmlSerializer.endDocument(); mXmlSerializer.flush(); } } } } Loading services/core/java/com/android/server/pm/verify/domain/DomainVerificationLegacySettings.java +0 −1 Original line number Original line Diff line number Diff line Loading @@ -32,7 +32,6 @@ import com.android.server.pm.SettingsXml; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.io.IOException; import java.util.Map; /** /** * Reads and writes the old {@link android.content.pm.IntentFilterVerificationInfo} so that it can * Reads and writes the old {@link android.content.pm.IntentFilterVerificationInfo} so that it can Loading services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationPersistenceTest.kt +24 −3 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,7 @@ import com.google.common.truth.Truth.assertWithMessage import org.junit.Rule import org.junit.Rule import org.junit.Test import org.junit.Test import org.junit.rules.TemporaryFolder import org.junit.rules.TemporaryFolder import org.xmlpull.v1.XmlPullParser import java.io.File import java.io.File import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets import java.util.UUID import java.util.UUID Loading @@ -41,21 +42,41 @@ class DomainVerificationPersistenceTest { internal fun File.writeXml(block: (serializer: TypedXmlSerializer) -> Unit) = apply { internal fun File.writeXml(block: (serializer: TypedXmlSerializer) -> Unit) = apply { outputStream().use { outputStream().use { // Explicitly use string based XML so it can printed in the test failure output // This must use the binary serializer the mirror the production behavior, as Xml.newFastSerializer() // there are slight differences with the string based one. Xml.newBinarySerializer() .apply { .apply { setOutput(it, StandardCharsets.UTF_8.name()) setOutput(it, StandardCharsets.UTF_8.name()) startDocument(null, true) startDocument(null, true) setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", 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(block) .apply { startTag(null, "trailing-tag") endTag(null, "trailing-tag") endTag(null, "wrapper-tag") } .endDocument() .endDocument() } } } } internal fun <T> File.readXml(block: (parser: TypedXmlPullParser) -> T) = internal fun <T> File.readXml(block: (parser: TypedXmlPullParser) -> T) = inputStream().use { 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") } } } } } Loading Loading
services/core/java/com/android/server/pm/SettingsXml.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -83,7 +83,7 @@ public class SettingsXml { @Override @Override public void close() throws IOException { public void close() throws IOException { mWriteSection.closeCompletely(); mWriteSection.closeCompletely(); mXmlSerializer.endDocument(); mXmlSerializer.flush(); } } } } Loading
services/core/java/com/android/server/pm/verify/domain/DomainVerificationLegacySettings.java +0 −1 Original line number Original line Diff line number Diff line Loading @@ -32,7 +32,6 @@ import com.android.server.pm.SettingsXml; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.io.IOException; import java.util.Map; /** /** * Reads and writes the old {@link android.content.pm.IntentFilterVerificationInfo} so that it can * Reads and writes the old {@link android.content.pm.IntentFilterVerificationInfo} so that it can Loading
services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/verify/domain/DomainVerificationPersistenceTest.kt +24 −3 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,7 @@ import com.google.common.truth.Truth.assertWithMessage import org.junit.Rule import org.junit.Rule import org.junit.Test import org.junit.Test import org.junit.rules.TemporaryFolder import org.junit.rules.TemporaryFolder import org.xmlpull.v1.XmlPullParser import java.io.File import java.io.File import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets import java.util.UUID import java.util.UUID Loading @@ -41,21 +42,41 @@ class DomainVerificationPersistenceTest { internal fun File.writeXml(block: (serializer: TypedXmlSerializer) -> Unit) = apply { internal fun File.writeXml(block: (serializer: TypedXmlSerializer) -> Unit) = apply { outputStream().use { outputStream().use { // Explicitly use string based XML so it can printed in the test failure output // This must use the binary serializer the mirror the production behavior, as Xml.newFastSerializer() // there are slight differences with the string based one. Xml.newBinarySerializer() .apply { .apply { setOutput(it, StandardCharsets.UTF_8.name()) setOutput(it, StandardCharsets.UTF_8.name()) startDocument(null, true) startDocument(null, true) setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", 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(block) .apply { startTag(null, "trailing-tag") endTag(null, "trailing-tag") endTag(null, "wrapper-tag") } .endDocument() .endDocument() } } } } internal fun <T> File.readXml(block: (parser: TypedXmlPullParser) -> T) = internal fun <T> File.readXml(block: (parser: TypedXmlPullParser) -> T) = inputStream().use { 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") } } } } } Loading