diff options
author | 2018-02-01 17:03:23 +0000 | |
---|---|---|
committer | 2018-02-02 14:48:53 +0000 | |
commit | cc3b8aeff19f39afb8d4f2c198ee6cd2ec132d22 (patch) | |
tree | ca4e5818981a6f9f33375331ad6e7f2bae170232 | |
parent | ad87a6900094bbd4cf1d01f979ae6611543f76dc (diff) |
[installd] Pass .dm files to dexopt
Test: installd_otapreopt_test installd_dexopt_test
Bug: 30934496
Change-Id: I3cb5b3f96205688203a134023492d8ff80524ab6
-rw-r--r-- | cmds/installd/InstalldNativeService.cpp | 22 | ||||
-rw-r--r-- | cmds/installd/InstalldNativeService.h | 3 | ||||
-rw-r--r-- | cmds/installd/binder/android/os/IInstalld.aidl | 3 | ||||
-rw-r--r-- | cmds/installd/dexopt.cpp | 24 | ||||
-rw-r--r-- | cmds/installd/dexopt.h | 3 | ||||
-rw-r--r-- | cmds/installd/otapreopt.cpp | 3 | ||||
-rw-r--r-- | cmds/installd/otapreopt_parameters.cpp | 4 | ||||
-rw-r--r-- | cmds/installd/otapreopt_parameters.h | 1 | ||||
-rw-r--r-- | cmds/installd/tests/installd_dexopt_test.cpp | 18 | ||||
-rw-r--r-- | cmds/installd/tests/installd_otapreopt_test.cpp | 13 |
10 files changed, 74 insertions, 20 deletions
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp index a2c85427d3..a477707865 100644 --- a/cmds/installd/InstalldNativeService.cpp +++ b/cmds/installd/InstalldNativeService.cpp @@ -1895,13 +1895,18 @@ binder::Status InstalldNativeService::destroyProfileSnapshot(const std::string& return ok(); } +static const char* getCStr(const std::unique_ptr<std::string>& data, + const char* default_value = nullptr) { + return data == nullptr ? default_value : data->c_str(); +} binder::Status InstalldNativeService::dexopt(const std::string& apkPath, int32_t uid, const std::unique_ptr<std::string>& packageName, const std::string& instructionSet, int32_t dexoptNeeded, const std::unique_ptr<std::string>& outputPath, int32_t dexFlags, const std::string& compilerFilter, const std::unique_ptr<std::string>& uuid, const std::unique_ptr<std::string>& classLoaderContext, const std::unique_ptr<std::string>& seInfo, bool downgrade, int32_t targetSdkVersion, - const std::unique_ptr<std::string>& profileName) { + const std::unique_ptr<std::string>& profileName, + const std::unique_ptr<std::string>& dexMetadataPath) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); if (packageName && *packageName != "*") { @@ -1910,17 +1915,18 @@ binder::Status InstalldNativeService::dexopt(const std::string& apkPath, int32_t std::lock_guard<std::recursive_mutex> lock(mLock); const char* apk_path = apkPath.c_str(); - const char* pkgname = packageName ? packageName->c_str() : "*"; + const char* pkgname = getCStr(packageName, "*"); const char* instruction_set = instructionSet.c_str(); - const char* oat_dir = outputPath ? outputPath->c_str() : nullptr; + const char* oat_dir = getCStr(outputPath); const char* compiler_filter = compilerFilter.c_str(); - const char* volume_uuid = uuid ? uuid->c_str() : nullptr; - const char* class_loader_context = classLoaderContext ? classLoaderContext->c_str() : nullptr; - const char* se_info = seInfo ? seInfo->c_str() : nullptr; - const char* profile_name = profileName ? profileName->c_str() : nullptr; + const char* volume_uuid = getCStr(uuid); + const char* class_loader_context = getCStr(classLoaderContext); + const char* se_info = getCStr(seInfo); + const char* profile_name = getCStr(profileName); + const char* dm_path = getCStr(dexMetadataPath); int res = android::installd::dexopt(apk_path, uid, pkgname, instruction_set, dexoptNeeded, oat_dir, dexFlags, compiler_filter, volume_uuid, class_loader_context, se_info, - downgrade, targetSdkVersion, profile_name); + downgrade, targetSdkVersion, profile_name, dm_path); return res ? error(res, "Failed to dexopt") : ok(); } diff --git a/cmds/installd/InstalldNativeService.h b/cmds/installd/InstalldNativeService.h index 5bf8ae2a54..22b1d1219f 100644 --- a/cmds/installd/InstalldNativeService.h +++ b/cmds/installd/InstalldNativeService.h @@ -85,7 +85,8 @@ public: const std::string& compilerFilter, const std::unique_ptr<std::string>& uuid, const std::unique_ptr<std::string>& classLoaderContext, const std::unique_ptr<std::string>& seInfo, bool downgrade, - int32_t targetSdkVersion, const std::unique_ptr<std::string>& profileName); + int32_t targetSdkVersion, const std::unique_ptr<std::string>& profileName, + const std::unique_ptr<std::string>& dexMetadataPath); binder::Status rmdex(const std::string& codePath, const std::string& instructionSet); diff --git a/cmds/installd/binder/android/os/IInstalld.aidl b/cmds/installd/binder/android/os/IInstalld.aidl index 3133b4f15c..e07c847d6b 100644 --- a/cmds/installd/binder/android/os/IInstalld.aidl +++ b/cmds/installd/binder/android/os/IInstalld.aidl @@ -52,7 +52,8 @@ interface IInstalld { @utf8InCpp String compilerFilter, @nullable @utf8InCpp String uuid, @nullable @utf8InCpp String sharedLibraries, @nullable @utf8InCpp String seInfo, boolean downgrade, int targetSdkVersion, - @nullable @utf8InCpp String profileName); + @nullable @utf8InCpp String profileName, + @nullable @utf8InCpp String dexMetadataPath); void rmdex(@utf8InCpp String codePath, @utf8InCpp String instructionSet); diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp index 013a3c1421..3ec8018ce6 100644 --- a/cmds/installd/dexopt.cpp +++ b/cmds/installd/dexopt.cpp @@ -223,7 +223,8 @@ static void run_dex2oat(int zip_fd, int oat_fd, int input_vdex_fd, int output_vd const char* input_file_name, const char* output_file_name, int swap_fd, const char* instruction_set, const char* compiler_filter, bool debuggable, bool post_bootcomplete, bool background_job_compile, int profile_fd, - const char* class_loader_context, int target_sdk_version, bool disable_hidden_api_checks) { + const char* class_loader_context, int target_sdk_version, bool disable_hidden_api_checks, + int dex_metadata_fd) { static const unsigned int MAX_INSTRUCTION_SET_LEN = 7; if (strlen(instruction_set) >= MAX_INSTRUCTION_SET_LEN) { @@ -420,6 +421,7 @@ static void run_dex2oat(int zip_fd, int oat_fd, int input_vdex_fd, int output_vd sprintf(base_dir, "--classpath-dir=%s", apk_dir.c_str()); } + std::string dex_metadata_fd_arg = "--dm-fd=" + std::to_string(dex_metadata_fd); ALOGV("Running %s in=%s out=%s\n", dex2oat_bin, relative_input_file_name, output_file_name); @@ -450,7 +452,8 @@ static void run_dex2oat(int zip_fd, int oat_fd, int input_vdex_fd, int output_vd + (disable_cdex ? 1 : 0) + (generate_minidebug_info ? 1 : 0) + (target_sdk_version != 0 ? 2 : 0) - + (disable_hidden_api_checks ? 2 : 0)]; + + (disable_hidden_api_checks ? 2 : 0) + + (dex_metadata_fd > -1 ? 1 : 0)]; int i = 0; argv[i++] = dex2oat_bin; argv[i++] = zip_fd_arg; @@ -529,6 +532,9 @@ static void run_dex2oat(int zip_fd, int oat_fd, int input_vdex_fd, int output_vd argv[i++] = "-Xno-hidden-api-checks"; } + if (dex_metadata_fd > -1) { + argv[i++] = dex_metadata_fd_arg.c_str(); + } // Do not add after dex2oat_flags, they should override others for debugging. argv[i] = NULL; @@ -1846,7 +1852,8 @@ static bool process_secondary_dex_dexopt(const std::string& dex_path, const char int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* instruction_set, int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter, const char* volume_uuid, const char* class_loader_context, const char* se_info, - bool downgrade, int target_sdk_version, const char* profile_name) { + bool downgrade, int target_sdk_version, const char* profile_name, + const char* dex_metadata_path) { CHECK(pkgname != nullptr); CHECK(pkgname[0] != 0); if ((dexopt_flags & ~DEXOPT_MASK) != 0) { @@ -1937,6 +1944,14 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins Dex2oatFileWrapper reference_profile_fd = maybe_open_reference_profile( pkgname, dex_path, profile_name, profile_guided, is_public, uid, is_secondary_dex); + unique_fd dex_metadata_fd; + if (dex_metadata_path != nullptr) { + dex_metadata_fd.reset(TEMP_FAILURE_RETRY(open(dex_metadata_path, O_RDONLY | O_NOFOLLOW))); + if (dex_metadata_fd.get() < 0) { + PLOG(ERROR) << "Failed to open dex metadata file " << dex_metadata_path; + } + } + ALOGV("DexInv: --- BEGIN '%s' ---\n", dex_path); pid_t pid = fork(); @@ -1966,7 +1981,8 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins reference_profile_fd.get(), class_loader_context, target_sdk_version, - disable_hidden_api_checks); + disable_hidden_api_checks, + dex_metadata_fd.get()); _exit(68); /* only get here on exec failure */ } else { int res = wait_child(pid); diff --git a/cmds/installd/dexopt.h b/cmds/installd/dexopt.h index 93cf545c76..ae1412e854 100644 --- a/cmds/installd/dexopt.h +++ b/cmds/installd/dexopt.h @@ -105,7 +105,8 @@ bool hash_secondary_dex_file(const std::string& dex_path, int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set, int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter, const char* volume_uuid, const char* class_loader_context, const char* se_info, - bool downgrade, int target_sdk_version, const char* profile_name); + bool downgrade, int target_sdk_version, const char* profile_name, + const char* dexMetadataPath); bool calculate_oat_file_path_default(char path[PKG_PATH_MAX], const char *oat_dir, const char *apk_path, const char *instruction_set); diff --git a/cmds/installd/otapreopt.cpp b/cmds/installd/otapreopt.cpp index 52674b15b3..72d01a5c87 100644 --- a/cmds/installd/otapreopt.cpp +++ b/cmds/installd/otapreopt.cpp @@ -581,7 +581,8 @@ private: parameters_.se_info, parameters_.downgrade, parameters_.target_sdk_version, - parameters_.profile_name); + parameters_.profile_name, + parameters_.dex_metadata_path); } int RunPreopt() { diff --git a/cmds/installd/otapreopt_parameters.cpp b/cmds/installd/otapreopt_parameters.cpp index b8e631079e..5b5f5223aa 100644 --- a/cmds/installd/otapreopt_parameters.cpp +++ b/cmds/installd/otapreopt_parameters.cpp @@ -228,6 +228,7 @@ bool OTAPreoptParameters::ReadArgumentsPostV1(uint32_t version, const char** arg case 3: num_args_expected = 12; break; case 4: num_args_expected = 13; break; case 5: num_args_expected = 14; break; + case 6: num_args_expected = 15; break; default: LOG(ERROR) << "Don't know how to read arguments for version " << version; return false; @@ -330,6 +331,9 @@ bool OTAPreoptParameters::ReadArgumentsPostV1(uint32_t version, const char** arg profile_name = ParseNull(param); break; + case 14: + dex_metadata_path = ParseNull(param); + default: CHECK(false) << "Should not get here. Did you call ReadArguments " << "with the right expectation?"; diff --git a/cmds/installd/otapreopt_parameters.h b/cmds/installd/otapreopt_parameters.h index eb5dd857a9..0f3bb8c981 100644 --- a/cmds/installd/otapreopt_parameters.h +++ b/cmds/installd/otapreopt_parameters.h @@ -45,6 +45,7 @@ class OTAPreoptParameters { bool downgrade; int target_sdk_version; const char* profile_name; + const char* dex_metadata_path; std::string target_slot; diff --git a/cmds/installd/tests/installd_dexopt_test.cpp b/cmds/installd/tests/installd_dexopt_test.cpp index 052fcfcb90..ea52c0e7b5 100644 --- a/cmds/installd/tests/installd_dexopt_test.cpp +++ b/cmds/installd/tests/installd_dexopt_test.cpp @@ -263,6 +263,7 @@ protected: bool downgrade = false; int32_t target_sdk_version = 0; // default std::unique_ptr<std::string> profile_name_ptr = nullptr; + std::unique_ptr<std::string> dm_path_ptr = nullptr; binder::Status result = service_->dexopt(path, uid, @@ -277,7 +278,8 @@ protected: se_info_ptr, downgrade, target_sdk_version, - profile_name_ptr); + profile_name_ptr, + dm_path_ptr); ASSERT_EQ(should_binder_call_succeed, result.isOk()); int expected_access = should_dex_be_compiled ? 0 : -1; std::string odex = GetSecondaryDexArtifact(path, "odex"); @@ -331,9 +333,10 @@ protected: const char* oat_dir, int32_t uid, int32_t dexopt_needed, + const char* dm_path = nullptr, bool downgrade = false) { return CompilePrimaryDex( - compiler_filter, dex_flags, oat_dir, uid, dexopt_needed, downgrade, true); + compiler_filter, dex_flags, oat_dir, uid, dexopt_needed, dm_path, downgrade, true); } void CompilePrimaryDexFail(std::string compiler_filter, @@ -341,9 +344,10 @@ protected: const char* oat_dir, int32_t uid, int32_t dexopt_needed, + const char* dm_path = nullptr, bool downgrade = false) { return CompilePrimaryDex( - compiler_filter, dex_flags, oat_dir, uid, dexopt_needed, downgrade, false); + compiler_filter, dex_flags, oat_dir, uid, dexopt_needed, dm_path, downgrade, false); } void CompilePrimaryDex(std::string compiler_filter, @@ -351,6 +355,7 @@ protected: const char* oat_dir, int32_t uid, int32_t dexopt_needed, + const char* dm_path, bool downgrade, bool should_binder_call_succeed) { std::unique_ptr<std::string> package_name_ptr(new std::string(package_name_)); @@ -360,6 +365,10 @@ protected: std::unique_ptr<std::string> se_info_ptr(new std::string(se_info_)); int32_t target_sdk_version = 0; // default std::unique_ptr<std::string> profile_name_ptr(new std::string("primary.prof")); + std::unique_ptr<std::string> dm_path_ptr = nullptr; + if (dm_path != nullptr) { + dm_path_ptr.reset(new std::string(dm_path)); + } bool prof_result; binder::Status prof_binder_result = service_->prepareAppProfile( @@ -382,7 +391,8 @@ protected: se_info_ptr, downgrade, target_sdk_version, - profile_name_ptr); + profile_name_ptr, + dm_path_ptr); ASSERT_EQ(should_binder_call_succeed, result.isOk()); if (!should_binder_call_succeed) { diff --git a/cmds/installd/tests/installd_otapreopt_test.cpp b/cmds/installd/tests/installd_otapreopt_test.cpp index 3bcc362436..1e8ae42565 100644 --- a/cmds/installd/tests/installd_otapreopt_test.cpp +++ b/cmds/installd/tests/installd_otapreopt_test.cpp @@ -85,6 +85,11 @@ protected: } else { ASSERT_STREQ(params.profile_name, "primary.prof"); } + if (version > 5) { + ASSERT_STREQ(params.dex_metadata_path, ParseNull(args[i++])); + } else { + ASSERT_STREQ(params.dex_metadata_path, nullptr); + } } const char* getVersionCStr(uint32_t version) { @@ -94,6 +99,7 @@ protected: case 3: return "3"; case 4: return "4"; case 5: return "5"; + case 6: return "6"; } return nullptr; } @@ -129,6 +135,9 @@ protected: if (version > 4) { args.push_back("split_a.prof"); // profile_name } + if (version > 5) { + args.push_back("dex_metadata.dm"); // dex_metadata_path + } args.push_back(nullptr); // we have to end with null. return args; } @@ -165,6 +174,10 @@ TEST_F(OTAPreoptTest, ReadArgumentsV5) { VerifyReadArguments(5, true); } +TEST_F(OTAPreoptTest, ReadArgumentsV6) { + VerifyReadArguments(6, true); +} + TEST_F(OTAPreoptTest, ReadArgumentsFailToManyArgs) { OTAPreoptParameters params; std::vector<const char*> args = getArgs(5, true); |