Installd: Amend dexopt binder logging
Separate dexoptanalyzer validation errors into different return
codes and add specific error messages. Also fix name style.
Test: mmma frameworks/native/cmds/installd
Test: installd_dexopt_test
Change-Id: Ie795897d112ded630de65c2ac7d7ee1a4b2a20a5
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp
index aaceb9d..1882771 100644
--- a/cmds/installd/dexopt.cpp
+++ b/cmds/installd/dexopt.cpp
@@ -1649,9 +1649,14 @@
enum DexoptAnalyzerSkipCodes {
// The dexoptanalyzer was not invoked because of validation or IO errors.
- SECONDARY_DEX_DEXOPTANALYZER_SKIPPED = 200,
+ // Specific errors are encoded in the name.
+ kSecondaryDexDexoptAnalyzerSkippedValidatePath = 200,
+ kSecondaryDexDexoptAnalyzerSkippedOpenZip = 201,
+ kSecondaryDexDexoptAnalyzerSkippedPrepareDir = 202,
+ kSecondaryDexDexoptAnalyzerSkippedOpenOutput = 203,
+ kSecondaryDexDexoptAnalyzerSkippedFailExec = 204,
// The dexoptanalyzer was not invoked because the dex file does not exist anymore.
- SECONDARY_DEX_DEXOPTANALYZER_SKIPPED_NO_FILE = 201,
+ kSecondaryDexDexoptAnalyzerSkippedNoFile = 205,
};
// Verifies the result of analyzing secondary dex files from process_secondary_dex_dexopt.
@@ -1686,12 +1691,25 @@
// Use a second switch for enum switch-case analysis.
switch (static_cast<DexoptAnalyzerSkipCodes>(result)) {
- case SECONDARY_DEX_DEXOPTANALYZER_SKIPPED_NO_FILE:
+ case kSecondaryDexDexoptAnalyzerSkippedNoFile:
// If the file does not exist there's no need for dexopt.
*dexopt_needed_out = NO_DEXOPT_NEEDED;
return true;
- case SECONDARY_DEX_DEXOPTANALYZER_SKIPPED:
- *error_msg = "Dexoptanalyzer was skipped";
+
+ case kSecondaryDexDexoptAnalyzerSkippedValidatePath:
+ *error_msg = "Dexoptanalyzer path validation failed";
+ return false;
+ case kSecondaryDexDexoptAnalyzerSkippedOpenZip:
+ *error_msg = "Dexoptanalyzer open zip failed";
+ return false;
+ case kSecondaryDexDexoptAnalyzerSkippedPrepareDir:
+ *error_msg = "Dexoptanalyzer dir preparation failed";
+ return false;
+ case kSecondaryDexDexoptAnalyzerSkippedOpenOutput:
+ *error_msg = "Dexoptanalyzer open output failed";
+ return false;
+ case kSecondaryDexDexoptAnalyzerSkippedFailExec:
+ *error_msg = "Dexoptanalyzer failed to execute";
return false;
}
@@ -1814,7 +1832,7 @@
// Validate the path structure.
if (!validate_secondary_dex_path(pkgname, dex_path, volume_uuid, uid, storage_flag)) {
LOG(ERROR) << "Could not validate secondary dex path " << dex_path;
- _exit(SECONDARY_DEX_DEXOPTANALYZER_SKIPPED);
+ _exit(kSecondaryDexDexoptAnalyzerSkippedValidatePath);
}
// Open the dex file.
@@ -1822,15 +1840,15 @@
zip_fd.reset(open(dex_path.c_str(), O_RDONLY));
if (zip_fd.get() < 0) {
if (errno == ENOENT) {
- _exit(SECONDARY_DEX_DEXOPTANALYZER_SKIPPED_NO_FILE);
+ _exit(kSecondaryDexDexoptAnalyzerSkippedNoFile);
} else {
- _exit(SECONDARY_DEX_DEXOPTANALYZER_SKIPPED);
+ _exit(kSecondaryDexDexoptAnalyzerSkippedOpenZip);
}
}
// Prepare the oat directories.
if (!prepare_secondary_dex_oat_dir(dex_path, uid, instruction_set)) {
- _exit(SECONDARY_DEX_DEXOPTANALYZER_SKIPPED);
+ _exit(kSecondaryDexDexoptAnalyzerSkippedPrepareDir);
}
// Open the vdex/oat files if any.
@@ -1842,7 +1860,7 @@
true /* is_secondary_dex */,
&oat_file_fd,
&vdex_file_fd)) {
- _exit(SECONDARY_DEX_DEXOPTANALYZER_SKIPPED);
+ _exit(kSecondaryDexDexoptAnalyzerSkippedOpenOutput);
}
// Analyze profiles.
@@ -1859,7 +1877,7 @@
downgrade,
class_loader_context);
PLOG(ERROR) << "Failed to exec dexoptanalyzer";
- _exit(SECONDARY_DEX_DEXOPTANALYZER_SKIPPED);
+ _exit(kSecondaryDexDexoptAnalyzerSkippedFailExec);
}
/* parent */
@@ -1887,7 +1905,7 @@
// Note that dexoptanalyzer is executed even if force compilation is enabled (because it
// makes the code simpler; force compilation is only needed during tests).
if (success &&
- (result != SECONDARY_DEX_DEXOPTANALYZER_SKIPPED_NO_FILE) &&
+ (result != kSecondaryDexDexoptAnalyzerSkippedNoFile) &&
((dexopt_flags & DEXOPT_FORCE) != 0)) {
*dexopt_needed_out = DEX2OAT_FROM_SCRATCH;
}
diff --git a/cmds/installd/tests/installd_dexopt_test.cpp b/cmds/installd/tests/installd_dexopt_test.cpp
index a2338e0..668e604 100644
--- a/cmds/installd/tests/installd_dexopt_test.cpp
+++ b/cmds/installd/tests/installd_dexopt_test.cpp
@@ -499,7 +499,8 @@
binder::Status status;
CompileSecondaryDex(secondary_dex_ce_, DEXOPT_STORAGE_DE,
/*binder_ok*/ false, /*compile_ok*/ false, &status);
- EXPECT_STREQ(status.toString8().c_str(), "Status(-8): '-1: Dexoptanalyzer was skipped'");
+ EXPECT_STREQ(status.toString8().c_str(),
+ "Status(-8): '-1: Dexoptanalyzer path validation failed'");
}
TEST_F(DexoptTest, DexoptSecondaryAppOwnershipValidationError) {
@@ -507,7 +508,8 @@
binder::Status status;
CompileSecondaryDex("/data/data/random.app/secondary.jar", DEXOPT_STORAGE_CE,
/*binder_ok*/ false, /*compile_ok*/ false, &status);
- EXPECT_STREQ(status.toString8().c_str(), "Status(-8): '-1: Dexoptanalyzer was skipped'");
+ EXPECT_STREQ(status.toString8().c_str(),
+ "Status(-8): '-1: Dexoptanalyzer path validation failed'");
}
TEST_F(DexoptTest, DexoptSecondaryAcessViaDifferentUidError) {
@@ -515,7 +517,7 @@
binder::Status status;
CompileSecondaryDex(secondary_dex_ce_, DEXOPT_STORAGE_CE,
/*binder_ok*/ false, /*compile_ok*/ false, &status, kSystemUid);
- EXPECT_STREQ(status.toString8().c_str(), "Status(-8): '-1: Dexoptanalyzer was skipped'");
+ EXPECT_STREQ(status.toString8().c_str(), "Status(-8): '-1: Dexoptanalyzer open zip failed'");
}
TEST_F(DexoptTest, DexoptPrimaryPublic) {