diff options
| -rw-r--r-- | cmds/installd/InstalldNativeService.cpp | 9 | ||||
| -rw-r--r-- | cmds/installd/tests/installd_dexopt_test.cpp | 22 |
2 files changed, 21 insertions, 10 deletions
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp index caac2e89a7..dd51898422 100644 --- a/cmds/installd/InstalldNativeService.cpp +++ b/cmds/installd/InstalldNativeService.cpp @@ -2107,10 +2107,15 @@ binder::Status InstalldNativeService::dexopt(const std::string& apkPath, int32_t CHECK_ARGUMENT_PATH(dexMetadataPath); std::lock_guard<std::recursive_mutex> lock(mLock); + const char* oat_dir = getCStr(outputPath); + const char* instruction_set = instructionSet.c_str(); + if (oat_dir != nullptr && !createOatDir(oat_dir, instruction_set).isOk()) { + // Can't create oat dir - let dexopt use cache dir. + oat_dir = nullptr; + } + const char* apk_path = apkPath.c_str(); const char* pkgname = getCStr(packageName, "*"); - const char* instruction_set = instructionSet.c_str(); - const char* oat_dir = getCStr(outputPath); const char* compiler_filter = compilerFilter.c_str(); const char* volume_uuid = getCStr(uuid); const char* class_loader_context = getCStr(classLoaderContext); diff --git a/cmds/installd/tests/installd_dexopt_test.cpp b/cmds/installd/tests/installd_dexopt_test.cpp index 13fd0677e5..73780eccbf 100644 --- a/cmds/installd/tests/installd_dexopt_test.cpp +++ b/cmds/installd/tests/installd_dexopt_test.cpp @@ -241,18 +241,14 @@ protected: } ::testing::AssertionResult create_mock_app() { - // Create the oat dir. - app_oat_dir_ = app_apk_dir_ + "/oat"; // For debug mode, the directory might already exist. Avoid erroring out. if (mkdir(app_apk_dir_, kSystemUid, kSystemGid, 0755) != 0 && !kDebug) { return ::testing::AssertionFailure() << "Could not create app dir " << app_apk_dir_ << " : " << strerror(errno); } - binder::Status status = service_->createOatDir(app_oat_dir_, kRuntimeIsa); - if (!status.isOk()) { - return ::testing::AssertionFailure() << "Could not create oat dir: " - << status.toString8().c_str(); - } + + // Initialize the oat dir path. + app_oat_dir_ = app_apk_dir_ + "/oat"; // Copy the primary apk. apk_path_ = app_apk_dir_ + "/base.jar"; @@ -283,7 +279,7 @@ protected: } // Create the app user data. - status = service_->createAppData( + binder::Status status = service_->createAppData( volume_uuid_, package_name_, kTestUserId, @@ -647,6 +643,16 @@ TEST_F(DexoptTest, DexoptPrimaryPublic) { DEX2OAT_FROM_SCRATCH); } +TEST_F(DexoptTest, DexoptPrimaryPublicCreateOatDir) { + LOG(INFO) << "DexoptPrimaryPublic"; + ASSERT_BINDER_SUCCESS(service_->createOatDir(app_oat_dir_, kRuntimeIsa)); + CompilePrimaryDexOk("verify", + DEXOPT_BOOTCOMPLETE | DEXOPT_PUBLIC, + app_oat_dir_.c_str(), + kTestAppGid, + DEX2OAT_FROM_SCRATCH); +} + TEST_F(DexoptTest, DexoptPrimaryFailedInvalidFilter) { LOG(INFO) << "DexoptPrimaryFailedInvalidFilter"; binder::Status status; |