Prevent crash from unknown mime type
Some devices may have codecs for mime types that are not known to us.
Test: make cts -j123 && cts-tradefed run cts-dev -m \
CtsMediaTestCases --compatibility:module-arg \
CtsMediaTestCases:include-annotation:\
android.platform.test.annotations.RequiresDevice
Bug: 65449180
Change-Id: Idc5ed5ac0e26d8bf26f576003d1370222af10c08
diff --git a/media/libstagefright/xmlparser/MediaCodecsXmlParser.cpp b/media/libstagefright/xmlparser/MediaCodecsXmlParser.cpp
index bbd1807..ffd30ea 100644
--- a/media/libstagefright/xmlparser/MediaCodecsXmlParser.cpp
+++ b/media/libstagefright/xmlparser/MediaCodecsXmlParser.cpp
@@ -986,6 +986,12 @@
for (const auto& type : typeMap) {
const auto& typeName = type.first;
const char* roleName = GetComponentRole(isEncoder, typeName.data());
+ if (roleName == nullptr) {
+ ALOGE("Cannot find the role for %s of type %s",
+ isEncoder ? "an encoder" : "a decoder",
+ typeName.data());
+ continue;
+ }
const auto& typeAttributeMap = type.second;
auto roleIterator = mRoleMap.find(roleName);