libstagefright: export profiling results directly to xml.

Bug: 19620911
Change-Id: Icdeb1c30816d6de120ea0acd0880b3a9614bea8f
diff --git a/include/media/stagefright/MediaCodecList.h b/include/media/stagefright/MediaCodecList.h
index 9d1d675..ce34338 100644
--- a/include/media/stagefright/MediaCodecList.h
+++ b/include/media/stagefright/MediaCodecList.h
@@ -54,7 +54,7 @@
     static sp<IMediaCodecList> getLocalInstance();
 
     // only to be used in getLocalInstance
-    void updateDetailsForMultipleCodecs(const KeyedVector<AString, CodecSettings>& updates);
+    void parseTopLevelXMLFile(const char *path, bool ignore_errors = false);
 
 private:
     class BinderDeathObserver : public IBinder::DeathRecipient {
@@ -97,7 +97,6 @@
 
     status_t initCheck() const;
     void parseXMLFile(const char *path);
-    void parseTopLevelXMLFile(const char *path, bool ignore_errors = false);
 
     static void StartElementHandlerWrapper(
             void *me, const char *name, const char **attrs);
diff --git a/media/libstagefright/MediaCodecList.cpp b/media/libstagefright/MediaCodecList.cpp
index 26798ae..6a6f99d 100644
--- a/media/libstagefright/MediaCodecList.cpp
+++ b/media/libstagefright/MediaCodecList.cpp
@@ -44,8 +44,6 @@
 
 static MediaCodecList *gCodecList = NULL;
 
-static const char *kProfilingResults = "/data/misc/media/media_codecs_profiling_results.xml";
-
 static bool parseBoolean(const char *s) {
     if (!strcasecmp(s, "true") || !strcasecmp(s, "yes") || !strcasecmp(s, "y")) {
         return true;
@@ -61,7 +59,6 @@
 // static
 sp<IMediaCodecList> MediaCodecList::getLocalInstance() {
     bool profilingNeeded = false;
-    KeyedVector<AString, CodecSettings> updates;
     Vector<sp<MediaCodecInfo>> infos;
 
     {
@@ -85,13 +82,13 @@
     }
 
     if (profilingNeeded) {
-        profileCodecs(infos, &updates);
+        profileCodecs(infos);
     }
 
     {
         Mutex::Autolock autoLock(sInitMutex);
-        if (updates.size() > 0) {
-            gCodecList->updateDetailsForMultipleCodecs(updates);
+        if (profilingNeeded) {
+            gCodecList->parseTopLevelXMLFile(kProfilingResults, true /* ignore_errors */);
         }
 
         return sCodecList;
@@ -141,19 +138,6 @@
     parseTopLevelXMLFile(kProfilingResults, true/* ignore_errors */);
 }
 
-void MediaCodecList::updateDetailsForMultipleCodecs(
-        const KeyedVector<AString, CodecSettings>& updates) {
-    if (updates.size() == 0) {
-        return;
-    }
-
-    exportResultsToXML(kProfilingResults, updates);
-
-    for (size_t i = 0; i < updates.size(); ++i) {
-        applyCodecSettings(updates.keyAt(i), updates.valueAt(i), &mCodecInfos);
-    }
-}
-
 void MediaCodecList::parseTopLevelXMLFile(const char *codecs_xml, bool ignore_errors) {
     // get href_base
     char *href_base_end = strrchr(codecs_xml, '/');
diff --git a/media/libstagefright/MediaCodecListOverrides.cpp b/media/libstagefright/MediaCodecListOverrides.cpp
index 265b1ea..535db09 100644
--- a/media/libstagefright/MediaCodecListOverrides.cpp
+++ b/media/libstagefright/MediaCodecListOverrides.cpp
@@ -30,6 +30,8 @@
 
 namespace android {
 
+const char *kProfilingResults = "/data/misc/media/media_codecs_profiling_results.xml";
+
 // a limit to avoid allocating unreasonable number of codec instances in the measurement.
 // this should be in sync with the MAX_SUPPORTED_INSTANCES defined in MediaCodecInfo.java.
 static const int kMaxInstances = 32;
@@ -171,20 +173,6 @@
     return codecs.size();
 }
 
-static void printLongString(const char *buf, size_t size) {
-    AString print;
-    const char *start = buf;
-    size_t len;
-    size_t totalLen = size;
-    while (totalLen > 0) {
-        len = (totalLen > 500) ? 500 : totalLen;
-        print.setTo(start, len);
-        ALOGV("%s", print.c_str());
-        totalLen -= len;
-        start += len;
-    }
-}
-
 bool splitString(const AString &s, const AString &delimiter, AString *s1, AString *s2) {
     ssize_t pos = s.find(delimiter.c_str());
     if (pos < 0) {
@@ -207,9 +195,18 @@
     return true;
 }
 
+void profileCodecs(const Vector<sp<MediaCodecInfo>> &infos) {
+    CodecSettings global_results;  // TODO: add global results.
+    KeyedVector<AString, CodecSettings> encoder_results;
+    KeyedVector<AString, CodecSettings> decoder_results;
+    profileCodecs(infos, &encoder_results, &decoder_results);
+    exportResultsToXML(kProfilingResults, global_results, encoder_results, decoder_results);
+}
+
 void profileCodecs(
         const Vector<sp<MediaCodecInfo>> &infos,
-        KeyedVector<AString, CodecSettings> *results,
+        KeyedVector<AString, CodecSettings> *encoder_results,
+        KeyedVector<AString, CodecSettings> *decoder_results,
         bool forceToMeasure) {
     KeyedVector<AString, sp<MediaCodecInfo::Capabilities>> codecsNeedMeasure;
     for (size_t i = 0; i < infos.size(); ++i) {
@@ -240,157 +237,86 @@
                 AString key = name;
                 key.append(" ");
                 key.append(mimes[i]);
-                key.append(" ");
-                key.append(info->isEncoder() ? "encoder" : "decoder");
-                results->add(key, settings);
+
+                if (info->isEncoder()) {
+                    encoder_results->add(key, settings);
+                } else {
+                    decoder_results->add(key, settings);
+                }
             }
         }
     }
 }
 
-void applyCodecSettings(
-        const AString& codecInfo,
-        const CodecSettings &settings,
-        Vector<sp<MediaCodecInfo>> *infos) {
-    AString name;
-    AString mime;
-    AString type;
-    if (!splitString(codecInfo, " ", &name, &mime, &type)) {
-        return;
-    }
-
-    for (size_t i = 0; i < infos->size(); ++i) {
-        const sp<MediaCodecInfo> &info = infos->itemAt(i);
-        if (name != info->getCodecName()) {
-            continue;
-        }
-
-        Vector<AString> mimes;
-        info->getSupportedMimes(&mimes);
-        for (size_t j = 0; j < mimes.size(); ++j) {
-            if (mimes[j] != mime) {
-                continue;
-            }
-            const sp<MediaCodecInfo::Capabilities> &caps = info->getCapabilitiesFor(mime.c_str());
-            for (size_t k = 0; k < settings.size(); ++k) {
-                caps->getDetails()->setString(
-                        settings.keyAt(k).c_str(), settings.valueAt(k).c_str());
-            }
-        }
-    }
-}
-
-void exportResultsToXML(const char *fileName, const KeyedVector<AString, CodecSettings>& results) {
-#if LOG_NDEBUG == 0
-    ALOGE("measurement results");
+static AString globalResultsToXml(const CodecSettings& results) {
+    AString ret;
     for (size_t i = 0; i < results.size(); ++i) {
-        ALOGE("key %s", results.keyAt(i).c_str());
-        const CodecSettings &settings = results.valueAt(i);
-        for (size_t j = 0; j < settings.size(); ++j) {
-            ALOGE("name %s value %s", settings.keyAt(j).c_str(), settings.valueAt(j).c_str());
-        }
+        AString setting = AStringPrintf(
+                "        <Setting name=\"%s\" value=\"%s\" />\n",
+                results.keyAt(i).c_str(),
+                results.valueAt(i).c_str());
+        ret.append(setting);
     }
-#endif
+    return ret;
+}
 
-    AString overrides;
-    FILE *f = fopen(fileName, "rb");
-    if (f != NULL) {
-        fseek(f, 0, SEEK_END);
-        long size = ftell(f);
-        rewind(f);
-
-        char *buf = (char *)malloc(size);
-        if (fread(buf, size, 1, f) == 1) {
-            overrides.setTo(buf, size);
-            if (!LOG_NDEBUG) {
-                ALOGV("Existing overrides:");
-                printLongString(buf, size);
-            }
-        } else {
-            ALOGE("Failed to read %s", fileName);
-        }
-        fclose(f);
-        free(buf);
-    }
-
+static AString codecResultsToXml(const KeyedVector<AString, CodecSettings>& results) {
+    AString ret;
     for (size_t i = 0; i < results.size(); ++i) {
         AString name;
         AString mime;
-        AString type;
-        if (!splitString(results.keyAt(i), " ", &name, &mime, &type)) {
+        if (!splitString(results.keyAt(i), " ", &name, &mime)) {
             continue;
         }
-        name = AStringPrintf("\"%s\"", name.c_str());
-        mime = AStringPrintf("\"%s\"", mime.c_str());
-        ALOGV("name(%s) mime(%s) type(%s)", name.c_str(), mime.c_str(), type.c_str());
-        ssize_t posCodec = overrides.find(name.c_str());
-        size_t posInsert = 0;
-        if (posCodec < 0) {
-            AString encodersDecoders = (type == "encoder") ? "<Encoders>" : "<Decoders>";
-            AString encodersDecodersEnd = (type == "encoder") ? "</Encoders>" : "</Decoders>";
-            ssize_t posEncodersDecoders = overrides.find(encodersDecoders.c_str());
-            if (posEncodersDecoders < 0) {
-                AString mediaCodecs = "<MediaCodecs>";
-                ssize_t posMediaCodec = overrides.find(mediaCodecs.c_str());
-                if (posMediaCodec < 0) {
-                    posMediaCodec = overrides.size();
-                    overrides.insert("\n<MediaCodecs>\n</MediaCodecs>\n", posMediaCodec);
-                    posMediaCodec = overrides.find(mediaCodecs.c_str(), posMediaCodec);
-                }
-                posEncodersDecoders = posMediaCodec + mediaCodecs.size();
-                AString codecs = AStringPrintf(
-                        "\n    %s\n    %s", encodersDecoders.c_str(), encodersDecodersEnd.c_str());
-                overrides.insert(codecs.c_str(), posEncodersDecoders);
-                posEncodersDecoders = overrides.find(encodersDecoders.c_str(), posEncodersDecoders);
-            }
-            posCodec = posEncodersDecoders + encodersDecoders.size();
-            AString codec = AStringPrintf(
-                        "\n        <MediaCodec name=%s type=%s update=\"true\" >\n        </MediaCodec>",
-                        name.c_str(),
-                        mime.c_str());
-            overrides.insert(codec.c_str(), posCodec);
-            posCodec = overrides.find(name.c_str());
-        }
-
-        // insert to existing entry
-        ssize_t posMime = overrides.find(mime.c_str(), posCodec);
-        ssize_t posEnd = overrides.find(">", posCodec);
-        if (posEnd < 0) {
-            ALOGE("Format error in overrides file.");
-            return;
-        }
-        if (posMime < 0 || posMime > posEnd) {
-            // new mime for an existing component
-            AString codecEnd = "</MediaCodec>";
-            posInsert = overrides.find(codecEnd.c_str(), posCodec) + codecEnd.size();
-            AString codec = AStringPrintf(
-                    "\n        <MediaCodec name=%s type=%s update=\"true\" >\n        </MediaCodec>",
-                    name.c_str(),
-                    mime.c_str());
-            overrides.insert(codec.c_str(), posInsert);
-            posInsert = overrides.find(">", posInsert) + 1;
-        } else {
-            posInsert = posEnd + 1;
-        }
-
+        AString codec =
+                AStringPrintf("        <MediaCodec name=\"%s\" type=\"%s\" update=\"true\" >\n",
+                              name.c_str(),
+                              mime.c_str());
+        ret.append(codec);
         CodecSettings settings = results.valueAt(i);
         for (size_t i = 0; i < settings.size(); ++i) {
             // WARNING: we assume all the settings are "Limit". Currently we have only one type
             // of setting in this case, which is "max-supported-instances".
-            AString strInsert = AStringPrintf(
-                    "\n            <Limit name=\"%s\" value=\"%s\" />",
+            AString setting = AStringPrintf(
+                    "            <Limit name=\"%s\" value=\"%s\" />\n",
                     settings.keyAt(i).c_str(),
                     settings.valueAt(i).c_str());
-            overrides.insert(strInsert, posInsert);
+            ret.append(setting);
         }
+        ret.append("        </MediaCodec>\n");
+    }
+    return ret;
+}
+
+void exportResultsToXML(
+        const char *fileName,
+        const CodecSettings& global_results,
+        const KeyedVector<AString, CodecSettings>& encoder_results,
+        const KeyedVector<AString, CodecSettings>& decoder_results) {
+    if (global_results.size() == 0 && encoder_results.size() == 0 && decoder_results.size() == 0) {
+        return;
     }
 
-    if (!LOG_NDEBUG) {
-        ALOGV("New overrides:");
-        printLongString(overrides.c_str(), overrides.size());
+    AString overrides;
+    overrides.append("<MediaCodecs>\n");
+    if (global_results.size() > 0) {
+        overrides.append("    <Settings>\n");
+        overrides.append(globalResultsToXml(global_results));
+        overrides.append("    </Settings>\n");
     }
+    if (encoder_results.size() > 0) {
+        overrides.append("    <Encoders>\n");
+        overrides.append(codecResultsToXml(encoder_results));
+        overrides.append("    </Encoders>\n");
+    }
+    if (decoder_results.size() > 0) {
+        overrides.append("    <Decoders>\n");
+        overrides.append(codecResultsToXml(decoder_results));
+        overrides.append("    </Decoders>\n");
+    }
+    overrides.append("</MediaCodecs>\n");
 
-    f = fopen(fileName, "wb");
+    FILE *f = fopen(fileName, "wb");
     if (f == NULL) {
         ALOGE("Failed to open %s for writing.", fileName);
         return;
diff --git a/media/libstagefright/MediaCodecListOverrides.h b/media/libstagefright/MediaCodecListOverrides.h
index c6cc2ea..c4758fa 100644
--- a/media/libstagefright/MediaCodecListOverrides.h
+++ b/media/libstagefright/MediaCodecListOverrides.h
@@ -26,24 +26,27 @@
 
 namespace android {
 
+extern const char *kProfilingResults;
+
 struct MediaCodecInfo;
 
 bool splitString(const AString &s, const AString &delimiter, AString *s1, AString *s2);
 
-bool splitString(
-        const AString &s, const AString &delimiter, AString *s1, AString *s2, AString *s3);
+// profile codecs and save the result to xml file named kProfilingResults.
+void profileCodecs(const Vector<sp<MediaCodecInfo>> &infos);
 
+// profile codecs and save the result to encoder_results and decoder_results.
 void profileCodecs(
         const Vector<sp<MediaCodecInfo>> &infos,
-        KeyedVector<AString, CodecSettings> *results,
-        bool forceToMeasure = false);  // forceToMeasure is mainly for testing
+        KeyedVector<AString, CodecSettings> *encoder_results,
+        KeyedVector<AString, CodecSettings> *decoder_results,
+        bool forceToMeasure = false);
 
-void applyCodecSettings(
-        const AString& codecInfo,
-        const CodecSettings &settings,
-        Vector<sp<MediaCodecInfo>> *infos);
-
-void exportResultsToXML(const char *fileName, const KeyedVector<AString, CodecSettings>& results);
+void exportResultsToXML(
+        const char *fileName,
+        const CodecSettings& global_results,
+        const KeyedVector<AString, CodecSettings>& encoder_results,
+        const KeyedVector<AString, CodecSettings>& decoder_results);
 
 }  // namespace android
 
diff --git a/media/libstagefright/tests/MediaCodecListOverrides_test.cpp b/media/libstagefright/tests/MediaCodecListOverrides_test.cpp
index 170cde3..146a244 100644
--- a/media/libstagefright/tests/MediaCodecListOverrides_test.cpp
+++ b/media/libstagefright/tests/MediaCodecListOverrides_test.cpp
@@ -31,29 +31,8 @@
 static const char kTestOverridesStr[] =
 "<MediaCodecs>\n"
 "    <Settings>\n"
-"        <Setting name=\"max-max-supported-instances\" value=\"8\" update=\"true\" />\n"
-"    </Settings>\n"
-"    <Encoders>\n"
-"        <MediaCodec name=\"OMX.qcom.video.encoder.mpeg4\" type=\"video/mp4v-es\" update=\"true\" >\n"
-"            <Quirk name=\"requires-allocate-on-input-ports\" />\n"
-"            <Limit name=\"bitrate\" range=\"1-20000000\" />\n"
-"            <Feature name=\"can-swap-width-height\" />\n"
-"        </MediaCodec>\n"
-"    </Encoders>\n"
-"    <Decoders>\n"
-"        <MediaCodec name=\"OMX.qcom.video.decoder.avc\" type=\"video/avc\" update=\"true\" >\n"
-"            <Quirk name=\"requires-allocate-on-input-ports\" />\n"
-"            <Limit name=\"size\" min=\"64x64\" max=\"1920x1088\" />\n"
-"        </MediaCodec>\n"
-"        <MediaCodec name=\"OMX.qcom.video.decoder.mpeg2\" type=\"different_mime\" update=\"true\" >\n"
-"        </MediaCodec>\n"
-"    </Decoders>\n"
-"</MediaCodecs>\n";
-
-static const char kTestOverridesStrNew1[] =
-"<MediaCodecs>\n"
-"    <Settings>\n"
-"        <Setting name=\"max-max-supported-instances\" value=\"8\" update=\"true\" />\n"
+"        <Setting name=\"supports-multiple-secure-codecs\" value=\"false\" />\n"
+"        <Setting name=\"supports-secure-with-non-secure-codec\" value=\"true\" />\n"
 "    </Settings>\n"
 "    <Encoders>\n"
 "        <MediaCodec name=\"OMX.qcom.video.encoder.avc\" type=\"video/avc\" update=\"true\" >\n"
@@ -61,57 +40,21 @@
 "        </MediaCodec>\n"
 "        <MediaCodec name=\"OMX.qcom.video.encoder.mpeg4\" type=\"video/mp4v-es\" update=\"true\" >\n"
 "            <Limit name=\"max-supported-instances\" value=\"4\" />\n"
-"            <Quirk name=\"requires-allocate-on-input-ports\" />\n"
-"            <Limit name=\"bitrate\" range=\"1-20000000\" />\n"
-"            <Feature name=\"can-swap-width-height\" />\n"
 "        </MediaCodec>\n"
 "    </Encoders>\n"
 "    <Decoders>\n"
-"        <MediaCodec name=\"OMX.qcom.video.decoder.mpeg4\" type=\"video/mp4v-es\" update=\"true\" >\n"
-"            <Limit name=\"max-supported-instances\" value=\"3\" />\n"
+"        <MediaCodec name=\"OMX.qcom.video.decoder.avc.secure\" type=\"video/avc\" update=\"true\" >\n"
+"            <Limit name=\"max-supported-instances\" value=\"1\" />\n"
 "        </MediaCodec>\n"
 "        <MediaCodec name=\"OMX.qcom.video.decoder.h263\" type=\"video/3gpp\" update=\"true\" >\n"
 "            <Limit name=\"max-supported-instances\" value=\"4\" />\n"
 "        </MediaCodec>\n"
-"        <MediaCodec name=\"OMX.qcom.video.decoder.avc.secure\" type=\"video/avc\" update=\"true\" >\n"
-"            <Limit name=\"max-supported-instances\" value=\"1\" />\n"
-"        </MediaCodec>\n"
-"        <MediaCodec name=\"OMX.qcom.video.decoder.avc\" type=\"video/avc\" update=\"true\" >\n"
-"            <Quirk name=\"requires-allocate-on-input-ports\" />\n"
-"            <Limit name=\"size\" min=\"64x64\" max=\"1920x1088\" />\n"
-"        </MediaCodec>\n"
-"        <MediaCodec name=\"OMX.qcom.video.decoder.mpeg2\" type=\"different_mime\" update=\"true\" >\n"
-"        </MediaCodec>\n"
 "        <MediaCodec name=\"OMX.qcom.video.decoder.mpeg2\" type=\"video/mpeg2\" update=\"true\" >\n"
 "            <Limit name=\"max-supported-instances\" value=\"3\" />\n"
 "        </MediaCodec>\n"
-"    </Decoders>\n"
-"</MediaCodecs>\n";
-
-static const char kTestOverridesStrNew2[] =
-"\n"
-"<MediaCodecs>\n"
-"    <Encoders>\n"
-"        <MediaCodec name=\"OMX.qcom.video.encoder.mpeg4\" type=\"video/mp4v-es\" update=\"true\" >\n"
-"            <Limit name=\"max-supported-instances\" value=\"4\" />\n"
-"        </MediaCodec>\n"
-"        <MediaCodec name=\"OMX.qcom.video.encoder.avc\" type=\"video/avc\" update=\"true\" >\n"
-"            <Limit name=\"max-supported-instances\" value=\"4\" />\n"
-"        </MediaCodec>\n"
-"    </Encoders>\n"
-"    <Decoders>\n"
 "        <MediaCodec name=\"OMX.qcom.video.decoder.mpeg4\" type=\"video/mp4v-es\" update=\"true\" >\n"
 "            <Limit name=\"max-supported-instances\" value=\"3\" />\n"
 "        </MediaCodec>\n"
-"        <MediaCodec name=\"OMX.qcom.video.decoder.mpeg2\" type=\"video/mpeg2\" update=\"true\" >\n"
-"            <Limit name=\"max-supported-instances\" value=\"3\" />\n"
-"        </MediaCodec>\n"
-"        <MediaCodec name=\"OMX.qcom.video.decoder.h263\" type=\"video/3gpp\" update=\"true\" >\n"
-"            <Limit name=\"max-supported-instances\" value=\"4\" />\n"
-"        </MediaCodec>\n"
-"        <MediaCodec name=\"OMX.qcom.video.decoder.avc.secure\" type=\"video/avc\" update=\"true\" >\n"
-"            <Limit name=\"max-supported-instances\" value=\"1\" />\n"
-"        </MediaCodec>\n"
 "    </Decoders>\n"
 "</MediaCodecs>\n";
 
@@ -119,53 +62,6 @@
 public:
     MediaCodecListOverridesTest() {}
 
-    void verifyOverrides(const KeyedVector<AString, CodecSettings> &overrides) {
-        EXPECT_EQ(3u, overrides.size());
-
-        EXPECT_TRUE(overrides.keyAt(0) == "OMX.qcom.video.decoder.avc video/avc decoder");
-        const CodecSettings &settings0 = overrides.valueAt(0);
-        EXPECT_EQ(1u, settings0.size());
-        EXPECT_TRUE(settings0.keyAt(0) == "max-supported-instances");
-        EXPECT_TRUE(settings0.valueAt(0) == "4");
-
-        EXPECT_TRUE(overrides.keyAt(1) == "OMX.qcom.video.encoder.avc video/avc encoder");
-        const CodecSettings &settings1 = overrides.valueAt(1);
-        EXPECT_EQ(1u, settings1.size());
-        EXPECT_TRUE(settings1.keyAt(0) == "max-supported-instances");
-        EXPECT_TRUE(settings1.valueAt(0) == "3");
-
-        EXPECT_TRUE(overrides.keyAt(2) == "global");
-        const CodecSettings &settings2 = overrides.valueAt(2);
-        EXPECT_EQ(3u, settings2.size());
-        EXPECT_TRUE(settings2.keyAt(0) == "max-max-supported-instances");
-        EXPECT_TRUE(settings2.valueAt(0) == "8");
-        EXPECT_TRUE(settings2.keyAt(1) == "supports-multiple-secure-codecs");
-        EXPECT_TRUE(settings2.valueAt(1) == "false");
-        EXPECT_TRUE(settings2.keyAt(2) == "supports-secure-with-non-secure-codec");
-        EXPECT_TRUE(settings2.valueAt(2) == "true");
-    }
-
-    void verifySetting(const sp<AMessage> &details, const char *name, const char *value) {
-        AString value1;
-        EXPECT_TRUE(details->findString(name, &value1));
-        EXPECT_TRUE(value1 == value);
-    }
-
-    void createTestInfos(Vector<sp<MediaCodecInfo>> *infos) {
-        const char *name = "OMX.qcom.video.decoder.avc";
-        const bool encoder = false;
-        const char *mime = "video/avc";
-        sp<MediaCodecInfo> info = new MediaCodecInfo(name, encoder, mime);
-        infos->push_back(info);
-        const sp<MediaCodecInfo::Capabilities> caps = info->getCapabilitiesFor(mime);
-        const sp<AMessage> details = caps->getDetails();
-        details->setString("cap1", "value1");
-        details->setString("max-max-supported-instances", "16");
-
-        info = new MediaCodecInfo("anothercodec", true, "anothermime");
-        infos->push_back(info);
-    }
-
     void addMaxInstancesSetting(
             const AString &key,
             const AString &value,
@@ -175,16 +71,34 @@
         results->add(key, settings);
     }
 
-    void exportTestResultsToXML(const char *fileName) {
-        KeyedVector<AString, CodecSettings> r;
-        addMaxInstancesSetting("OMX.qcom.video.decoder.avc.secure video/avc decoder", "1", &r);
-        addMaxInstancesSetting("OMX.qcom.video.decoder.h263 video/3gpp decoder", "4", &r);
-        addMaxInstancesSetting("OMX.qcom.video.decoder.mpeg2 video/mpeg2 decoder", "3", &r);
-        addMaxInstancesSetting("OMX.qcom.video.decoder.mpeg4 video/mp4v-es decoder", "3", &r);
-        addMaxInstancesSetting("OMX.qcom.video.encoder.avc video/avc encoder", "4", &r);
-        addMaxInstancesSetting("OMX.qcom.video.encoder.mpeg4 video/mp4v-es encoder", "4", &r);
+    void verifyProfileResults(const KeyedVector<AString, CodecSettings> &results) {
+        EXPECT_LT(0u, results.size());
+        for (size_t i = 0; i < results.size(); ++i) {
+            AString key = results.keyAt(i);
+            CodecSettings settings = results.valueAt(i);
+            EXPECT_EQ(1u, settings.size());
+            EXPECT_TRUE(settings.keyAt(0) == "max-supported-instances");
+            AString valueS = settings.valueAt(0);
+            int32_t value = strtol(valueS.c_str(), NULL, 10);
+            EXPECT_LT(0, value);
+            ALOGV("profileCodecs results %s %s", key.c_str(), valueS.c_str());
+        }
+    }
 
-        exportResultsToXML(fileName, r);
+    void exportTestResultsToXML(const char *fileName) {
+        CodecSettings gR;
+        gR.add("supports-multiple-secure-codecs", "false");
+        gR.add("supports-secure-with-non-secure-codec", "true");
+        KeyedVector<AString, CodecSettings> eR;
+        addMaxInstancesSetting("OMX.qcom.video.encoder.avc video/avc", "4", &eR);
+        addMaxInstancesSetting("OMX.qcom.video.encoder.mpeg4 video/mp4v-es", "4", &eR);
+        KeyedVector<AString, CodecSettings> dR;
+        addMaxInstancesSetting("OMX.qcom.video.decoder.avc.secure video/avc", "1", &dR);
+        addMaxInstancesSetting("OMX.qcom.video.decoder.h263 video/3gpp", "4", &dR);
+        addMaxInstancesSetting("OMX.qcom.video.decoder.mpeg2 video/mpeg2", "3", &dR);
+        addMaxInstancesSetting("OMX.qcom.video.decoder.mpeg4 video/mp4v-es", "3", &dR);
+
+        exportResultsToXML(fileName, gR, eR, dR);
     }
 };
 
@@ -198,18 +112,6 @@
     EXPECT_TRUE(splitString(s, delimiter, &s1, &s2));
     EXPECT_TRUE(s1 == "abc");
     EXPECT_TRUE(s2 == "123");
-
-    s = "abc123xyz";
-    delimiter = ",";
-    AString s3;
-    EXPECT_FALSE(splitString(s, delimiter, &s1, &s2, &s3));
-    s = "abc,123xyz";
-    EXPECT_FALSE(splitString(s, delimiter, &s1, &s2, &s3));
-    s = "abc,123,xyz";
-    EXPECT_TRUE(splitString(s, delimiter, &s1, &s2, &s3));
-    EXPECT_TRUE(s1 == "abc");
-    EXPECT_TRUE(s2 == "123" );
-    EXPECT_TRUE(s3 == "xyz");
 }
 
 // TODO: the codec component never returns OMX_EventCmdComplete in unit test.
@@ -219,76 +121,14 @@
     for (size_t i = 0; i < list->countCodecs(); ++i) {
         infos.push_back(list->getCodecInfo(i));
     }
-    KeyedVector<AString, CodecSettings> results;
-    profileCodecs(infos, &results, true /* forceToMeasure */);
-    EXPECT_LT(0u, results.size());
-    for (size_t i = 0; i < results.size(); ++i) {
-        AString key = results.keyAt(i);
-        CodecSettings settings = results.valueAt(i);
-        EXPECT_EQ(1u, settings.size());
-        EXPECT_TRUE(settings.keyAt(0) == "max-supported-instances");
-        AString valueS = settings.valueAt(0);
-        int32_t value = strtol(valueS.c_str(), NULL, 10);
-        EXPECT_LT(0, value);
-        ALOGV("profileCodecs results %s %s", key.c_str(), valueS.c_str());
-    }
+    KeyedVector<AString, CodecSettings> encoder_results;
+    KeyedVector<AString, CodecSettings> decoder_results;
+    profileCodecs(infos, &encoder_results, &decoder_results, true /* forceToMeasure */);
+    verifyProfileResults(encoder_results);
+    verifyProfileResults(decoder_results);
 }
 
-TEST_F(MediaCodecListOverridesTest, applyCodecSettings) {
-    AString codecInfo = "OMX.qcom.video.decoder.avc video/avc decoder";
-    Vector<sp<MediaCodecInfo>> infos;
-    createTestInfos(&infos);
-    CodecSettings settings;
-    settings.add("max-supported-instances", "3");
-    settings.add("max-max-supported-instances", "8");
-    applyCodecSettings(codecInfo, settings, &infos);
-
-    EXPECT_EQ(2u, infos.size());
-    EXPECT_TRUE(AString(infos[0]->getCodecName()) == "OMX.qcom.video.decoder.avc");
-    const sp<AMessage> details = infos[0]->getCapabilitiesFor("video/avc")->getDetails();
-    verifySetting(details, "max-supported-instances", "3");
-    verifySetting(details, "max-max-supported-instances", "8");
-
-    EXPECT_TRUE(AString(infos[1]->getCodecName()) == "anothercodec");
-    EXPECT_EQ(0u, infos[1]->getCapabilitiesFor("anothermime")->getDetails()->countEntries());
-}
-
-TEST_F(MediaCodecListOverridesTest, exportResultsToExistingFile) {
-    const char *fileName = "/sdcard/mediacodec_list_overrides_test.xml";
-    remove(fileName);
-
-    FILE *f = fopen(fileName, "wb");
-    if (f == NULL) {
-        ALOGW("Failed to open %s for writing.", fileName);
-        return;
-    }
-    EXPECT_EQ(
-            strlen(kTestOverridesStr),
-            fwrite(kTestOverridesStr, 1, strlen(kTestOverridesStr), f));
-    fclose(f);
-
-    exportTestResultsToXML(fileName);
-
-    // verify
-    AString overrides;
-    f = fopen(fileName, "rb");
-    ASSERT_TRUE(f != NULL);
-    fseek(f, 0, SEEK_END);
-    long size = ftell(f);
-    rewind(f);
-
-    char *buf = (char *)malloc(size);
-    EXPECT_EQ((size_t)1, fread(buf, size, 1, f));
-    overrides.setTo(buf, size);
-    fclose(f);
-    free(buf);
-
-    EXPECT_TRUE(overrides == kTestOverridesStrNew1);
-
-    remove(fileName);
-}
-
-TEST_F(MediaCodecListOverridesTest, exportResultsToEmptyFile) {
+TEST_F(MediaCodecListOverridesTest, exportTestResultsToXML) {
     const char *fileName = "/sdcard/mediacodec_list_overrides_test.xml";
     remove(fileName);
 
@@ -308,7 +148,7 @@
     fclose(f);
     free(buf);
 
-    EXPECT_TRUE(overrides == kTestOverridesStrNew2);
+    EXPECT_TRUE(overrides == kTestOverridesStr);
 
     remove(fileName);
 }