Fix otapreopt parameters reading

The code was missing a break in the switch statement and was always
failing the default CHECK.

Also, move the logging to standard error to make it obvious the test
failed (instead of relying on the exit code which can be easily missed).

(cherry picked from commit fd0c5b1aef5814b91f656341089d11291762a250)

Test: installd_otapreopt_test
Bug: 71993124
Merged-In: Iaf29ebc9b930981bf3b75c33e63e940139421e1d
Change-Id: Iaf29ebc9b930981bf3b75c33e63e940139421e1d
diff --git a/cmds/installd/otapreopt_parameters.cpp b/cmds/installd/otapreopt_parameters.cpp
index 5b5f522..1f85728 100644
--- a/cmds/installd/otapreopt_parameters.cpp
+++ b/cmds/installd/otapreopt_parameters.cpp
@@ -218,6 +218,9 @@
     // Set the profile name to the primary apk profile.
     profile_name = "primary.prof";
 
+    // By default we don't have a dex metadata file.
+    dex_metadata_path = nullptr;
+
     return true;
 }
 
@@ -272,6 +275,9 @@
     // Set the profile name to the primary apk profile.
     profile_name = "primary.prof";
 
+    // By default we don't have a dex metadata file.
+    dex_metadata_path = nullptr;
+
     for (size_t param_index = 0; param_index < num_args_actual; ++param_index) {
         const char* param = argv[dexopt_index + 1 + param_index];
         switch (param_index) {
@@ -332,11 +338,14 @@
                 break;
 
             case 14:
-                 dex_metadata_path = ParseNull(param);
+                dex_metadata_path = ParseNull(param);
+                break;
 
             default:
-                CHECK(false) << "Should not get here. Did you call ReadArguments "
-                        << "with the right expectation?";
+                LOG(FATAL) << "Should not get here. Did you call ReadArguments "
+                        << "with the right expectation? index=" << param_index
+                        << " num_args=" << num_args_actual;
+                return false;
         }
     }
 
diff --git a/cmds/installd/tests/installd_otapreopt_test.cpp b/cmds/installd/tests/installd_otapreopt_test.cpp
index 1e8ae42..8b8dde1 100644
--- a/cmds/installd/tests/installd_otapreopt_test.cpp
+++ b/cmds/installd/tests/installd_otapreopt_test.cpp
@@ -39,8 +39,8 @@
 class OTAPreoptTest : public testing::Test {
 protected:
     virtual void SetUp() {
-        setenv("ANDROID_LOG_TAGS", "*:v", 1);
-        android::base::InitLogging(nullptr);
+        setenv("ANDROID_LOG_TAGS", "*:f", 1);
+        android::base::InitLogging(nullptr, android::base::StderrLogger);
     }
 
     void verifyPackageParameters(const OTAPreoptParameters& params,
@@ -68,7 +68,7 @@
         if (version > 1) {
             ASSERT_STREQ(params.se_info, ParseNull(args[i++]));
         } else {
-            ASSERT_STREQ(params.se_info, nullptr);
+            ASSERT_EQ(params.se_info, nullptr);
         }
         if (version > 2) {
             ASSERT_EQ(params.downgrade, ParseBool(args[i++]));
@@ -88,7 +88,7 @@
         if (version > 5) {
             ASSERT_STREQ(params.dex_metadata_path, ParseNull(args[i++]));
         } else {
-            ASSERT_STREQ(params.dex_metadata_path, nullptr);
+            ASSERT_EQ(params.dex_metadata_path, nullptr);
         }
     }