transoding: Add xml parsing to ApplicationMediaCapabilities.

CTS-Coverage-Bug:172074159

Bug: 169849854
Test: Unit test

Change-Id: I4a8cabb850495cb14c51f25de607bdf47da8b26e
This commit is contained in:
hkuang
2020-10-30 10:06:51 -07:00
parent 474cac5066
commit bbb7628545
14 changed files with 575 additions and 1 deletions

View File

@@ -24175,6 +24175,7 @@ package android.location {
package android.media {
public final class ApplicationMediaCapabilities implements android.os.Parcelable {
method @NonNull public static android.media.ApplicationMediaCapabilities createFromXml(@NonNull org.xmlpull.v1.XmlPullParser);
method public int describeContents();
method @NonNull public java.util.List<java.lang.String> getSupportedHdrTypes();
method @NonNull public java.util.List<java.lang.String> getSupportedVideoMimeTypes();

View File

@@ -22,10 +22,16 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@@ -179,6 +185,20 @@ public final class ApplicationMediaCapabilities implements Parcelable {
return mIsSlowMotionSupported;
}
/**
* Creates {@link ApplicationMediaCapabilities} from an xml.
* @param xmlParser The underlying {@link XmlPullParser} that will read the xml.
* @return An ApplicationMediaCapabilities object.
* @throws UnsupportedOperationException if the capabilities in xml config are invalid or
* incompatible.
*/
@NonNull
public static ApplicationMediaCapabilities createFromXml(@NonNull XmlPullParser xmlParser) {
ApplicationMediaCapabilities.Builder builder = new ApplicationMediaCapabilities.Builder();
builder.parseXml(xmlParser);
return builder.build();
}
/**
* Builder class for {@link ApplicationMediaCapabilities} objects.
* Use this class to configure and create an ApplicationMediaCapabilities instance. Builder
@@ -195,12 +215,126 @@ public final class ApplicationMediaCapabilities implements Parcelable {
private boolean mIsSlowMotionSupported = false;
/* Map to save the format read from the xml. */
private Map<String, Boolean> mFormatSupportedMap = new HashMap<String, Boolean>();
/**
* Constructs a new Builder with all the supports default to false.
*/
public Builder() {
}
private void parseXml(@NonNull XmlPullParser xmlParser)
throws UnsupportedOperationException {
if (xmlParser == null) {
throw new IllegalArgumentException("XmlParser must not be null");
}
try {
while (xmlParser.next() != XmlPullParser.START_TAG) {
continue;
}
// Validates the tag is "media-capabilities".
if (!xmlParser.getName().equals("media-capabilities")) {
throw new UnsupportedOperationException("Invalid tag");
}
xmlParser.next();
while (xmlParser.getEventType() != XmlPullParser.END_TAG) {
while (xmlParser.getEventType() != XmlPullParser.START_TAG) {
if (xmlParser.getEventType() == XmlPullParser.END_DOCUMENT) {
return;
}
xmlParser.next();
}
// Validates the tag is "format".
if (xmlParser.getName().equals("format")) {
parseFormatTag(xmlParser);
} else {
throw new UnsupportedOperationException("Invalid tag");
}
while (xmlParser.getEventType() != XmlPullParser.END_TAG) {
xmlParser.next();
}
xmlParser.next();
}
} catch (XmlPullParserException xppe) {
throw new UnsupportedOperationException("Ill-formatted xml file");
} catch (java.io.IOException ioe) {
throw new UnsupportedOperationException("Unable to read xml file");
}
}
private void parseFormatTag(XmlPullParser xmlParser) {
String name = null;
String supported = null;
for (int i = 0; i < xmlParser.getAttributeCount(); i++) {
String attrName = xmlParser.getAttributeName(i);
if (attrName.equals("name")) {
name = xmlParser.getAttributeValue(i);
} else if (attrName.equals("supported")) {
supported = xmlParser.getAttributeValue(i);
} else {
throw new UnsupportedOperationException("Invalid attribute name " + attrName);
}
}
if (name != null && supported != null) {
if (!supported.equals("true") && !supported.equals("false")) {
throw new UnsupportedOperationException(
("Supported value must be either true or false"));
}
boolean isSupported = Boolean.parseBoolean(supported);
// Check if the format is already found before.
if (mFormatSupportedMap.get(name) != null && mFormatSupportedMap.get(name)
!= isSupported) {
throw new UnsupportedOperationException(
"Format: " + name + " has conflict supported value");
}
switch (name) {
case "HEVC":
if (isSupported) {
mSupportedVideoMimeTypes.add(MediaFormat.MIMETYPE_VIDEO_HEVC);
}
break;
case "HDR10":
if (isSupported) {
mSupportedHdrTypes.add(MediaFeature.HdrType.HDR10);
}
break;
case "HDR10Plus":
if (isSupported) {
mSupportedHdrTypes.add(MediaFeature.HdrType.HDR10_PLUS);
}
break;
case "Dolby-Vision":
if (isSupported) {
mSupportedHdrTypes.add(MediaFeature.HdrType.DOLBY_VISION);
}
break;
case "HLG":
if (isSupported) {
mSupportedHdrTypes.add(MediaFeature.HdrType.HLG);
}
break;
case "SlowMotion":
mIsSlowMotionSupported = isSupported;
break;
default:
throw new UnsupportedOperationException("Invalid format name " + name);
}
// Save the name and isSupported into the map for validate later.
mFormatSupportedMap.put(name, isSupported);
} else {
throw new UnsupportedOperationException(
"Format name and supported must both be specified");
}
}
/**
* Builds a {@link ApplicationMediaCapabilities} object.
*
@@ -213,6 +347,11 @@ public final class ApplicationMediaCapabilities implements Parcelable {
*/
@NonNull
public ApplicationMediaCapabilities build() {
Log.d(TAG,
"Building ApplicationMediaCapabilities with: " + mSupportedHdrTypes.toString()
+ " " + mSupportedVideoMimeTypes.toString() + " "
+ mIsSlowMotionSupported);
// If hdr is supported, application must also support hevc.
if (!mSupportedHdrTypes.isEmpty() && !mSupportedVideoMimeTypes.contains(
MediaFormat.MIMETYPE_VIDEO_HEVC)) {

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
<format android:name="HEVC" supported="true"/>
<format android:name="HEVC" supported="false"/>
</media-capabilities>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
<format />
</media-capabilities>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
<format android:name="HEVC"/>
</media-capabilities>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
<format android:name="HEVC" supported="true"/>
<format android:name="HDR10" supported="false"/>
<format android:name="SlowMotion" supported="false"/>
</media-capabilities>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
<format android:name="HEVC" supported="true"/>
<format android:name="HDR10" supported="true"/>
<format android:name="HDR10Plus" supported="true"/>
<format android:name="Dolby-Vision" supported="true"/>
<format android:name="HLG" supported="true"/>
<format android:name="SlowMotion" supported="true"/>
</media-capabilities>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
<format android:name="HDR10" supported="true"/>
<format android:name="SlowMotion" supported="false"/>
</media-capabilities>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
<format supported="true"/>
</media-capabilities>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
<format android:name="HEVC" supported="yes"/>
<format android:name="HDR10" supported="false"/>
<format android:name="SlowMotion" supported="false"/>
</media-capabilities>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<media-capability xmlns:android="http://schemas.android.com/apk/res/android">
<format android:name="HEVC" supported="true"/>
<format android:name="HDR10" supported="true"/>
<format android:name="SlowMotion" supported="true"/>
</media-capabilities>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<MediaCapability xmlns:android="http://schemas.android.com/apk/res/android">
<format android:name="HEVC" supported="true"/>
<format android:name="HDR10" supported="true"/>
<format android:name="SlowMotion" supported="true"/>
</MediaCapability>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
<format android:name="HEVC" supported="true"/>
<format android:name="HDR10" supported="false"/>
<format android:name="SlowMotion" supported="false"/>
</media-capabilities>

View File

@@ -26,28 +26,46 @@ package com.android.mediatranscodingtest;
adb install -r testcases/mediatranscodingtest/arm64/mediatranscodingtest.apk
adb shell am instrument -e class \
com.android.mediatranscodingtest.MediaCapabilityTest \
com.android.mediatranscodingtest.ApplicationMediaCapabilitiesTest \
-w com.android.mediatranscodingtest/.MediaTranscodingTestRunner
*
*/
import static org.testng.Assert.assertThrows;
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.media.ApplicationMediaCapabilities;
import android.media.MediaFeature;
import android.media.MediaFormat;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.util.Xml;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
public class ApplicationMediaCapabilitiesTest extends
ActivityInstrumentationTestCase2<MediaTranscodingTest> {
private static final String TAG = "MediaCapabilityTest";
private Context mContext;
public ApplicationMediaCapabilitiesTest() {
super("com.android.MediaCapabilityTest", MediaTranscodingTest.class);
}
public void setUp() throws Exception {
Log.d(TAG, "setUp");
super.setUp();
mContext = getInstrumentation().getContext();
}
@Test
public void testSetSupportHevc() throws Exception {
ApplicationMediaCapabilities capability =
@@ -95,4 +113,194 @@ public class ApplicationMediaCapabilitiesTest extends
MediaFeature.HdrType.HDR10_PLUS).build();
});
}
// Test read the application's xml from res/xml folder using the XmlResourceParser.
// <format android:name="HEVC" supported="true"/>
// <format android:name="HDR10" supported="false"/>
// <format android:name="SlowMotion" supported="false"/>
@Test
public void testReadMediaCapabilitiesXml() throws Exception {
XmlResourceParser parser = mContext.getResources().getXml(R.xml.mediacapabilities);
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
assertFalse(capability.isHdrTypeSupported(MediaFeature.HdrType.HDR10));
assertFalse(capability.isSlowMotionSupported());
assertTrue(capability.isVideoMimeTypeSupported(MediaFormat.MIMETYPE_VIDEO_HEVC));
}
// Test read the application's xml from res/xml folder using the XmlResourceParser.
// <format android:name="HEVC" supported="true"/>
// <format android:name="HDR10" supported="true"/>
// <format android:name="HDR10Plus" supported="true"/>
// <format android:name="Dolby-Vision" supported="true"/>
// <format android:name="HLG" supported="true"/>
// <format android:name="SlowMotion" supported="true"/>
@Test
public void testReadMediaCapabilitiesXmlWithSupportAllHdr() throws Exception {
InputStream xmlIs = mContext.getAssets().open("SupportAllHdr.xml");
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(xmlIs, StandardCharsets.UTF_8.name());
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
assertTrue(capability.isHdrTypeSupported(MediaFeature.HdrType.HDR10));
assertTrue(capability.isHdrTypeSupported(MediaFeature.HdrType.HDR10_PLUS));
assertTrue(capability.isHdrTypeSupported(MediaFeature.HdrType.DOLBY_VISION));
assertTrue(capability.isHdrTypeSupported(MediaFeature.HdrType.HLG));
assertTrue(capability.isSlowMotionSupported());
assertTrue(capability.isVideoMimeTypeSupported(MediaFormat.MIMETYPE_VIDEO_HEVC));
}
// Test read the xml from res/assets folder using the InputStream.
// <format android:name="HEVC" supported="true"/>
// <format android:name="HDR10" supported="false"/>
// <format android:name="SlowMotion" supported="false"/>
@Test
public void testReadFromCorrectXmlWithInputStreamInAssets() throws Exception {
InputStream xmlIs = mContext.getAssets().open("MediaCapabilities.xml");
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(xmlIs, StandardCharsets.UTF_8.name());
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
assertFalse(capability.isHdrTypeSupported(MediaFeature.HdrType.HDR10));
assertFalse(capability.isSlowMotionSupported());
assertTrue(capability.isVideoMimeTypeSupported(MediaFormat.MIMETYPE_VIDEO_HEVC));
}
// Test parsing invalid xml with wrong tag expect UnsupportedOperationException
// MediaCapability does not match MediaCapabilities at the end which will lead to
// exception with "Ill-formatted xml file"
// <MediaCapability xmlns:android="http://schemas.android.com/apk/res/android">
// <format android:name="HEVC" supported="true"/>
// <format android:name="HDR10" supported="true"/>
// <format android:name="SlowMotion" supported="true"/>
// </MediaCapabilities>
@Test
public void testReadFromWrongMediaCapabilityXml() throws Exception {
assertThrows(UnsupportedOperationException.class, () -> {
InputStream xmlIs = mContext.getAssets().open("WrongMediaCapabilityTag.xml");
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(xmlIs, StandardCharsets.UTF_8.name());
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
});
}
// Test invalid xml with wrong tag expect UnsupportedOperationException
// MediaCapability is wrong tag.
// <MediaCapability xmlns:android="http://schemas.android.com/apk/res/android">
// <format android:name="HEVC" supported="true"/>
// <format android:name="HDR10" supported="true"/>
// <format android:name="SlowMotion" supported="true"/>
// </MediaCapability>
@Test
public void testReadFromWrongMediaCapabilityXml2() throws Exception {
assertThrows(UnsupportedOperationException.class, () -> {
InputStream xmlIs = mContext.getAssets().open("WrongMediaCapabilityTag2.xml");
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(xmlIs, StandardCharsets.UTF_8.name());
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
});
}
// Test invalid attribute value of "support" with true->yes expect UnsupportedOperationException
// <MediaCapabilities xmlns:android="http://schemas.android.com/apk/res/android">
// <format android:name="HEVC" supported="yes"/>
// <format android:name="HDR10" supported="false"/>
// <format android:name="SlowMotion" supported="false"/>
// </MediaCapabilities>
@Test
public void testReadFromXmlWithWrongBoolean() throws Exception {
assertThrows(UnsupportedOperationException.class, () -> {
InputStream xmlIs = mContext.getAssets().open("WrongBooleanValue.xml");
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(xmlIs, StandardCharsets.UTF_8.name());
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
});
}
// Test parsing capabilities that support HDR10 but not support HEVC.
// Expect UnsupportedOperationException
// <MediaCapability xmlns:android="http://schemas.android.com/apk/res/android">
// <format android:name="HDR10" supported="true"/>
// <format android:name="SlowMotion" supported="false"/>
// </MediaCapabilities>
@Test
public void testReadXmlSupportHdrWithoutSupportHevc() throws Exception {
assertThrows(UnsupportedOperationException.class, () -> {
InputStream xmlIs = mContext.getAssets().open("SupportHdrWithoutHevc.xml");
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(xmlIs, StandardCharsets.UTF_8.name());
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
});
}
// Test parsing capabilities that has conflicted supported value.
// Expect UnsupportedOperationException
// <media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
// <format android:name="HEVC" supported="true"/>
// <format android:name="HEVC" supported="false"/>
// </media-capabilities>
@Test
public void testReadXmlConflictSupportedValue() throws Exception {
assertThrows(UnsupportedOperationException.class, () -> {
InputStream xmlIs = mContext.getAssets().open("ConflictSupportedValue.xml");
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(xmlIs, StandardCharsets.UTF_8.name());
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
});
}
// Test parsing capabilities that has empty format.
// Expect UnsupportedOperationException
// <media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
// <format/>
// </media-capabilities>
@Test
public void testReadXmlWithEmptyFormat() throws Exception {
assertThrows(UnsupportedOperationException.class, () -> {
InputStream xmlIs = mContext.getAssets().open("EmptyFormat.xml");
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(xmlIs, StandardCharsets.UTF_8.name());
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
});
}
// Test parsing capabilities that has empty format.
// Expect UnsupportedOperationException
// <media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
// <format android:name="HEVC"/>
// </media-capabilities>
@Test
public void testReadXmlFormatWithoutSupported() throws Exception {
assertThrows(UnsupportedOperationException.class, () -> {
InputStream xmlIs = mContext.getAssets().open("FormatWithoutSupported.xml");
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(xmlIs, StandardCharsets.UTF_8.name());
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
});
}
// Test parsing capabilities that has supported without the format name.
// Expect UnsupportedOperationException
// <media-capabilities xmlns:android="http://schemas.android.com/apk/res/android">
// <format supported="true"/>
// </media-capabilities>
@Test
public void testReadXmlSupportedWithoutFormat() throws Exception {
assertThrows(UnsupportedOperationException.class, () -> {
InputStream xmlIs = mContext.getAssets().open("SupportedWithoutFormat.xml");
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(xmlIs, StandardCharsets.UTF_8.name());
ApplicationMediaCapabilities capability = ApplicationMediaCapabilities.createFromXml(
parser);
});
}
}