Loading cmds/installd/dexopt.cpp +10 −4 Original line number Original line Diff line number Diff line Loading @@ -2117,14 +2117,20 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins // Create a swap file if necessary. // Create a swap file if necessary. unique_fd swap_fd = maybe_open_dexopt_swap_file(out_oat_path); unique_fd swap_fd = maybe_open_dexopt_swap_file(out_oat_path); // Create the app image file if needed. Dex2oatFileWrapper image_fd = maybe_open_app_image( out_oat_path, generate_app_image, is_public, uid, is_secondary_dex); // Open the reference profile if needed. // Open the reference profile if needed. Dex2oatFileWrapper reference_profile_fd = maybe_open_reference_profile( Dex2oatFileWrapper reference_profile_fd = maybe_open_reference_profile( pkgname, dex_path, profile_name, profile_guided, is_public, uid, is_secondary_dex); pkgname, dex_path, profile_name, profile_guided, is_public, uid, is_secondary_dex); if (reference_profile_fd.get() == -1) { // We don't create an app image without reference profile since there is no speedup from // loading it in that case and instead will be a small overhead. generate_app_image = false; } // Create the app image file if needed. Dex2oatFileWrapper image_fd = maybe_open_app_image( out_oat_path, generate_app_image, is_public, uid, is_secondary_dex); unique_fd dex_metadata_fd; unique_fd dex_metadata_fd; if (dex_metadata_path != nullptr) { if (dex_metadata_path != nullptr) { dex_metadata_fd.reset(TEMP_FAILURE_RETRY(open(dex_metadata_path, O_RDONLY | O_NOFOLLOW))); dex_metadata_fd.reset(TEMP_FAILURE_RETRY(open(dex_metadata_path, O_RDONLY | O_NOFOLLOW))); Loading cmds/installd/tests/Android.bp +2 −0 Original line number Original line Diff line number Diff line Loading @@ -89,6 +89,8 @@ cc_test { "libinstalld", "libinstalld", "liblog", "liblog", "liblogwrap", "liblogwrap", "libziparchive", "libz", ], ], test_config: "installd_dexopt_test.xml", test_config: "installd_dexopt_test.xml", } } Loading cmds/installd/tests/installd_dexopt_test.cpp +38 −6 Original line number Original line Diff line number Diff line Loading @@ -41,6 +41,7 @@ #include "globals.h" #include "globals.h" #include "tests/test_utils.h" #include "tests/test_utils.h" #include "utils.h" #include "utils.h" #include "ziparchive/zip_writer.h" using android::base::ReadFully; using android::base::ReadFully; using android::base::unique_fd; using android::base::unique_fd; Loading Loading @@ -195,6 +196,7 @@ protected: std::unique_ptr<std::string> volume_uuid_; std::unique_ptr<std::string> volume_uuid_; std::string package_name_; std::string package_name_; std::string apk_path_; std::string apk_path_; std::string empty_dm_file_; std::string app_apk_dir_; std::string app_apk_dir_; std::string app_private_dir_ce_; std::string app_private_dir_ce_; std::string app_private_dir_de_; std::string app_private_dir_de_; Loading Loading @@ -260,6 +262,26 @@ protected: << " : " << error_msg; << " : " << error_msg; } } // Create an empty dm file. empty_dm_file_ = apk_path_ + ".dm"; { int fd = open(empty_dm_file_.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (fd < 0) { return ::testing::AssertionFailure() << "Could not open " << empty_dm_file_; } FILE* file = fdopen(fd, "wb"); if (file == nullptr) { return ::testing::AssertionFailure() << "Null file for " << empty_dm_file_ << " fd=" << fd; } ZipWriter writer(file); // Add vdex to zip. writer.StartEntry("primary.prof", ZipWriter::kCompress); writer.FinishEntry(); writer.Finish(); close(fd); } // Create the app user data. // Create the app user data. status = service_->createAppData( status = service_->createAppData( volume_uuid_, volume_uuid_, Loading Loading @@ -479,7 +501,7 @@ protected: bool prof_result; bool prof_result; ASSERT_BINDER_SUCCESS(service_->prepareAppProfile( ASSERT_BINDER_SUCCESS(service_->prepareAppProfile( package_name_, kTestUserId, kTestAppId, *profile_name_ptr, apk_path_, package_name_, kTestUserId, kTestAppId, *profile_name_ptr, apk_path_, /*dex_metadata*/ nullptr, &prof_result)); dm_path_ptr, &prof_result)); ASSERT_TRUE(prof_result); ASSERT_TRUE(prof_result); binder::Status result = service_->dexopt(apk_path_, binder::Status result = service_->dexopt(apk_path_, Loading Loading @@ -645,7 +667,9 @@ TEST_F(DexoptTest, DexoptPrimaryProfileNonPublic) { DEXOPT_BOOTCOMPLETE | DEXOPT_PROFILE_GUIDED | DEXOPT_GENERATE_APP_IMAGE, DEXOPT_BOOTCOMPLETE | DEXOPT_PROFILE_GUIDED | DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), app_oat_dir_.c_str(), kTestAppGid, kTestAppGid, DEX2OAT_FROM_SCRATCH); DEX2OAT_FROM_SCRATCH, /*binder_result=*/nullptr, empty_dm_file_.c_str()); } } TEST_F(DexoptTest, DexoptPrimaryProfilePublic) { TEST_F(DexoptTest, DexoptPrimaryProfilePublic) { Loading @@ -655,7 +679,9 @@ TEST_F(DexoptTest, DexoptPrimaryProfilePublic) { DEXOPT_GENERATE_APP_IMAGE, DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), app_oat_dir_.c_str(), kTestAppGid, kTestAppGid, DEX2OAT_FROM_SCRATCH); DEX2OAT_FROM_SCRATCH, /*binder_result=*/nullptr, empty_dm_file_.c_str()); } } TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) { TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) { Loading @@ -665,7 +691,9 @@ TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) { DEXOPT_GENERATE_APP_IMAGE, DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), app_oat_dir_.c_str(), kTestAppGid, kTestAppGid, DEX2OAT_FROM_SCRATCH); DEX2OAT_FROM_SCRATCH, /*binder_result=*/nullptr, empty_dm_file_.c_str()); } } TEST_F(DexoptTest, ResolveStartupConstStrings) { TEST_F(DexoptTest, ResolveStartupConstStrings) { Loading @@ -684,7 +712,9 @@ TEST_F(DexoptTest, ResolveStartupConstStrings) { DEXOPT_GENERATE_APP_IMAGE, DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), app_oat_dir_.c_str(), kTestAppGid, kTestAppGid, DEX2OAT_FROM_SCRATCH); DEX2OAT_FROM_SCRATCH, /*binder_result=*/nullptr, empty_dm_file_.c_str()); run_cmd_and_process_output( run_cmd_and_process_output( "oatdump --header-only --oat-file=" + odex, "oatdump --header-only --oat-file=" + odex, [&](const std::string& line) { [&](const std::string& line) { Loading @@ -701,7 +731,9 @@ TEST_F(DexoptTest, ResolveStartupConstStrings) { DEXOPT_GENERATE_APP_IMAGE, DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), app_oat_dir_.c_str(), kTestAppGid, kTestAppGid, DEX2OAT_FROM_SCRATCH); DEX2OAT_FROM_SCRATCH, /*binder_result=*/nullptr, empty_dm_file_.c_str()); run_cmd_and_process_output( run_cmd_and_process_output( "oatdump --header-only --oat-file=" + odex, "oatdump --header-only --oat-file=" + odex, [&](const std::string& line) { [&](const std::string& line) { Loading Loading
cmds/installd/dexopt.cpp +10 −4 Original line number Original line Diff line number Diff line Loading @@ -2117,14 +2117,20 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins // Create a swap file if necessary. // Create a swap file if necessary. unique_fd swap_fd = maybe_open_dexopt_swap_file(out_oat_path); unique_fd swap_fd = maybe_open_dexopt_swap_file(out_oat_path); // Create the app image file if needed. Dex2oatFileWrapper image_fd = maybe_open_app_image( out_oat_path, generate_app_image, is_public, uid, is_secondary_dex); // Open the reference profile if needed. // Open the reference profile if needed. Dex2oatFileWrapper reference_profile_fd = maybe_open_reference_profile( Dex2oatFileWrapper reference_profile_fd = maybe_open_reference_profile( pkgname, dex_path, profile_name, profile_guided, is_public, uid, is_secondary_dex); pkgname, dex_path, profile_name, profile_guided, is_public, uid, is_secondary_dex); if (reference_profile_fd.get() == -1) { // We don't create an app image without reference profile since there is no speedup from // loading it in that case and instead will be a small overhead. generate_app_image = false; } // Create the app image file if needed. Dex2oatFileWrapper image_fd = maybe_open_app_image( out_oat_path, generate_app_image, is_public, uid, is_secondary_dex); unique_fd dex_metadata_fd; unique_fd dex_metadata_fd; if (dex_metadata_path != nullptr) { if (dex_metadata_path != nullptr) { dex_metadata_fd.reset(TEMP_FAILURE_RETRY(open(dex_metadata_path, O_RDONLY | O_NOFOLLOW))); dex_metadata_fd.reset(TEMP_FAILURE_RETRY(open(dex_metadata_path, O_RDONLY | O_NOFOLLOW))); Loading
cmds/installd/tests/Android.bp +2 −0 Original line number Original line Diff line number Diff line Loading @@ -89,6 +89,8 @@ cc_test { "libinstalld", "libinstalld", "liblog", "liblog", "liblogwrap", "liblogwrap", "libziparchive", "libz", ], ], test_config: "installd_dexopt_test.xml", test_config: "installd_dexopt_test.xml", } } Loading
cmds/installd/tests/installd_dexopt_test.cpp +38 −6 Original line number Original line Diff line number Diff line Loading @@ -41,6 +41,7 @@ #include "globals.h" #include "globals.h" #include "tests/test_utils.h" #include "tests/test_utils.h" #include "utils.h" #include "utils.h" #include "ziparchive/zip_writer.h" using android::base::ReadFully; using android::base::ReadFully; using android::base::unique_fd; using android::base::unique_fd; Loading Loading @@ -195,6 +196,7 @@ protected: std::unique_ptr<std::string> volume_uuid_; std::unique_ptr<std::string> volume_uuid_; std::string package_name_; std::string package_name_; std::string apk_path_; std::string apk_path_; std::string empty_dm_file_; std::string app_apk_dir_; std::string app_apk_dir_; std::string app_private_dir_ce_; std::string app_private_dir_ce_; std::string app_private_dir_de_; std::string app_private_dir_de_; Loading Loading @@ -260,6 +262,26 @@ protected: << " : " << error_msg; << " : " << error_msg; } } // Create an empty dm file. empty_dm_file_ = apk_path_ + ".dm"; { int fd = open(empty_dm_file_.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (fd < 0) { return ::testing::AssertionFailure() << "Could not open " << empty_dm_file_; } FILE* file = fdopen(fd, "wb"); if (file == nullptr) { return ::testing::AssertionFailure() << "Null file for " << empty_dm_file_ << " fd=" << fd; } ZipWriter writer(file); // Add vdex to zip. writer.StartEntry("primary.prof", ZipWriter::kCompress); writer.FinishEntry(); writer.Finish(); close(fd); } // Create the app user data. // Create the app user data. status = service_->createAppData( status = service_->createAppData( volume_uuid_, volume_uuid_, Loading Loading @@ -479,7 +501,7 @@ protected: bool prof_result; bool prof_result; ASSERT_BINDER_SUCCESS(service_->prepareAppProfile( ASSERT_BINDER_SUCCESS(service_->prepareAppProfile( package_name_, kTestUserId, kTestAppId, *profile_name_ptr, apk_path_, package_name_, kTestUserId, kTestAppId, *profile_name_ptr, apk_path_, /*dex_metadata*/ nullptr, &prof_result)); dm_path_ptr, &prof_result)); ASSERT_TRUE(prof_result); ASSERT_TRUE(prof_result); binder::Status result = service_->dexopt(apk_path_, binder::Status result = service_->dexopt(apk_path_, Loading Loading @@ -645,7 +667,9 @@ TEST_F(DexoptTest, DexoptPrimaryProfileNonPublic) { DEXOPT_BOOTCOMPLETE | DEXOPT_PROFILE_GUIDED | DEXOPT_GENERATE_APP_IMAGE, DEXOPT_BOOTCOMPLETE | DEXOPT_PROFILE_GUIDED | DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), app_oat_dir_.c_str(), kTestAppGid, kTestAppGid, DEX2OAT_FROM_SCRATCH); DEX2OAT_FROM_SCRATCH, /*binder_result=*/nullptr, empty_dm_file_.c_str()); } } TEST_F(DexoptTest, DexoptPrimaryProfilePublic) { TEST_F(DexoptTest, DexoptPrimaryProfilePublic) { Loading @@ -655,7 +679,9 @@ TEST_F(DexoptTest, DexoptPrimaryProfilePublic) { DEXOPT_GENERATE_APP_IMAGE, DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), app_oat_dir_.c_str(), kTestAppGid, kTestAppGid, DEX2OAT_FROM_SCRATCH); DEX2OAT_FROM_SCRATCH, /*binder_result=*/nullptr, empty_dm_file_.c_str()); } } TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) { TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) { Loading @@ -665,7 +691,9 @@ TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) { DEXOPT_GENERATE_APP_IMAGE, DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), app_oat_dir_.c_str(), kTestAppGid, kTestAppGid, DEX2OAT_FROM_SCRATCH); DEX2OAT_FROM_SCRATCH, /*binder_result=*/nullptr, empty_dm_file_.c_str()); } } TEST_F(DexoptTest, ResolveStartupConstStrings) { TEST_F(DexoptTest, ResolveStartupConstStrings) { Loading @@ -684,7 +712,9 @@ TEST_F(DexoptTest, ResolveStartupConstStrings) { DEXOPT_GENERATE_APP_IMAGE, DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), app_oat_dir_.c_str(), kTestAppGid, kTestAppGid, DEX2OAT_FROM_SCRATCH); DEX2OAT_FROM_SCRATCH, /*binder_result=*/nullptr, empty_dm_file_.c_str()); run_cmd_and_process_output( run_cmd_and_process_output( "oatdump --header-only --oat-file=" + odex, "oatdump --header-only --oat-file=" + odex, [&](const std::string& line) { [&](const std::string& line) { Loading @@ -701,7 +731,9 @@ TEST_F(DexoptTest, ResolveStartupConstStrings) { DEXOPT_GENERATE_APP_IMAGE, DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), app_oat_dir_.c_str(), kTestAppGid, kTestAppGid, DEX2OAT_FROM_SCRATCH); DEX2OAT_FROM_SCRATCH, /*binder_result=*/nullptr, empty_dm_file_.c_str()); run_cmd_and_process_output( run_cmd_and_process_output( "oatdump --header-only --oat-file=" + odex, "oatdump --header-only --oat-file=" + odex, [&](const std::string& line) { [&](const std::string& line) { Loading