Add options to rank OMX components after Codec2

This CL also puts C2 hardware components after C2 software components
instead of ranking them equal.

Test: adb shell setprop debug.stagefright.omx_default_rank 100
adb shell killall mediaserver
adb shell stagefright -p

Test: adb shell setprop debug.stagefright.omx_default_rank 1000
adb shell killall mediaserver
adb shell stagefright -p

Bug: 111425329
Change-Id: I2ab0e1f0c989c1a4f341c98de5059dc112deb025
diff --git a/media/sfplugin/Codec2InfoBuilder.cpp b/media/sfplugin/Codec2InfoBuilder.cpp
index 9d4c109..93f5b91 100644
--- a/media/sfplugin/Codec2InfoBuilder.cpp
+++ b/media/sfplugin/Codec2InfoBuilder.cpp
@@ -56,8 +56,6 @@
 
 namespace /* unnamed */ {
 
-uint32_t kOmxRankOverride = 1;
-
 bool hasPrefix(const std::string& s, const char* prefix) {
     size_t prefixLen = strlen(prefix);
     return s.compare(0, prefixLen, prefix) == 0;
@@ -259,6 +257,8 @@
 
 void buildOmxInfo(const MediaCodecsXmlParser& parser,
                   MediaCodecListWriter* writer) {
+    uint32_t omxRank = ::android::base::GetUintProperty(
+            "debug.stagefright.omx_default_rank", uint32_t(0x100));
     for (const MediaCodecsXmlParser::Codec& codec : parser.getCodecMap()) {
         const std::string &name = codec.first;
         if (!hasPrefix(codec.first, "OMX.")) {
@@ -271,7 +271,7 @@
         info->setName(name.c_str());
         info->setOwner("default");
         info->setEncoder(encoder);
-        info->setRank(kOmxRankOverride);
+        info->setRank(omxRank);
         for (const MediaCodecsXmlParser::Type& type : properties.typeMap) {
             const std::string &mime = type.first;
             std::unique_ptr<MediaCodecInfo::CapabilitiesWriter> caps =
@@ -312,8 +312,8 @@
     //   0 - Only OMX components are available.
     //   1 - Audio decoders and encoders with prefix "c2.android." are available
     //       and ranked first.
-    //       All other components with prefix "c2.android." are available but
-    //       ranked last.
+    //       All other components with prefix "c2.android." are available with
+    //       their normal ranks.
     //       Components with prefix "c2.vda." are available with their normal
     //       ranks.
     //       All other components with suffix ".avc.decoder" or ".avc.encoder"
@@ -375,7 +375,6 @@
                     rank = 1;
                     break;
                 }
-                rank = std::numeric_limits<decltype(rank)>::max();
                 break;
             }
             if (hasSuffix(trait.name, ".avc.decoder") ||