diff options
| -rw-r--r-- | artd/artd.cc | 15 | ||||
| -rw-r--r-- | artd/artd.h | 7 | ||||
| -rw-r--r-- | artd/artd_test.cc | 21 |
3 files changed, 39 insertions, 4 deletions
diff --git a/artd/artd.cc b/artd/artd.cc index 41309f91a6..56a410487e 100644 --- a/artd/artd.cc +++ b/artd/artd.cc @@ -2009,10 +2009,25 @@ Result<void> Artd::PreRebootInitDeriveClasspath(const std::string& path) { return ErrnoErrorf("Failed to create '{}'", path); } + if (pre_reboot_build_props_ == nullptr) { + pre_reboot_build_props_ = std::make_unique<BuildSystemProperties>( + OR_RETURN(BuildSystemProperties::Create("/system/build.prop"))); + } + std::string sdk_version = pre_reboot_build_props_->GetOrEmpty("ro.build.version.sdk"); + std::string codename = pre_reboot_build_props_->GetOrEmpty("ro.build.version.codename"); + std::string known_codenames = + pre_reboot_build_props_->GetOrEmpty("ro.build.version.known_codenames"); + if (sdk_version.empty() || codename.empty() || known_codenames.empty()) { + return Errorf("Failed to read system properties"); + } + CmdlineBuilder args = OR_RETURN(GetArtExecCmdlineBuilder()); args.Add("--keep-fds=%d", output->Fd()) .Add("--") .Add("/apex/com.android.sdkext/bin/derive_classpath") + .Add("--override-device-sdk-version=%s", sdk_version) + .Add("--override-device-codename=%s", codename) + .Add("--override-device-known-codenames=%s", known_codenames) .Add("/proc/self/fd/%d", output->Fd()); LOG(INFO) << "Running derive_classpath: " << Join(args.Get(), /*separator=*/" "); diff --git a/artd/artd.h b/artd/artd.h index 8ce82e0dd5..fd601302d9 100644 --- a/artd/artd.h +++ b/artd/artd.h @@ -138,7 +138,8 @@ class Artd : public aidl::com::android::server::art::BnArtd { std::function<MountFn> mount_func = mount, std::function<decltype(Restorecon)> restorecon_func = Restorecon, std::optional<std::string> pre_reboot_tmp_dir = std::nullopt, - std::optional<std::string> init_environ_rc_path = std::nullopt) + std::optional<std::string> init_environ_rc_path = std::nullopt, + std::unique_ptr<art::tools::SystemProperties> pre_reboot_build_props = nullptr) : options_(std::move(options)), props_(std::move(props)), exec_utils_(std::move(exec_utils)), @@ -148,7 +149,8 @@ class Artd : public aidl::com::android::server::art::BnArtd { mount_(std::move(mount_func)), restorecon_(std::move(restorecon_func)), pre_reboot_tmp_dir_(std::move(pre_reboot_tmp_dir)), - init_environ_rc_path_(std::move(init_environ_rc_path)) {} + init_environ_rc_path_(std::move(init_environ_rc_path)), + pre_reboot_build_props_(std::move(pre_reboot_build_props)) {} ndk::ScopedAStatus isAlive(bool* _aidl_return) override; @@ -379,6 +381,7 @@ class Artd : public aidl::com::android::server::art::BnArtd { const std::function<decltype(Restorecon)> restorecon_; const std::optional<std::string> pre_reboot_tmp_dir_; const std::optional<std::string> init_environ_rc_path_; + std::unique_ptr<art::tools::SystemProperties> pre_reboot_build_props_; }; // A class for getting system properties from a `build.prop` file. diff --git a/artd/artd_test.cc b/artd/artd_test.cc index 0a06a0917d..8fecb084ae 100644 --- a/artd/artd_test.cc +++ b/artd/artd_test.cc @@ -2820,6 +2820,17 @@ class ArtdPreRebootTest : public ArtdTest { ON_CALL(*mock_props_, GetProperty).WillByDefault(Return("")); auto mock_exec_utils = std::make_unique<MockExecUtils>(); mock_exec_utils_ = mock_exec_utils.get(); + auto mock_pre_reboot_build_props = std::make_unique<NiceMock<MockSystemProperties>>(); + mock_pre_reboot_build_props_ = mock_pre_reboot_build_props.get(); + + ON_CALL(*mock_pre_reboot_build_props_, GetProperty).WillByDefault(Return("")); + ON_CALL(*mock_pre_reboot_build_props_, GetProperty("ro.build.version.sdk")) + .WillByDefault(Return("35")); + ON_CALL(*mock_pre_reboot_build_props_, GetProperty("ro.build.version.codename")) + .WillByDefault(Return("Baklava")); + ON_CALL(*mock_pre_reboot_build_props_, GetProperty("ro.build.version.known_codenames")) + .WillByDefault(Return("VanillaIceCream,Baklava")); + artd_ = ndk::SharedRefBase::make<Artd>(Options{.is_pre_reboot = true}, std::move(mock_props), std::move(mock_exec_utils), @@ -2829,7 +2840,8 @@ class ArtdPreRebootTest : public ArtdTest { mock_mount_.AsStdFunction(), mock_restorecon_.AsStdFunction(), pre_reboot_tmp_dir_, - init_environ_rc_path_); + init_environ_rc_path_, + std::move(mock_pre_reboot_build_props)); ON_CALL(mock_restorecon_, Call).WillByDefault(Return(Result<void>())); @@ -2852,6 +2864,7 @@ class ArtdPreRebootTest : public ArtdTest { const std::optional<OutputArtifacts::PermissionSettings::SeContext>&, bool)> mock_restorecon_; + MockSystemProperties* mock_pre_reboot_build_props_; }; TEST_F(ArtdPreRebootTest, preRebootInit) { @@ -2871,7 +2884,11 @@ TEST_F(ArtdPreRebootTest, preRebootInit) { AllOf(WhenSplitBy("--", AllOf(Contains(art_root_ + "/bin/art_exec"), Contains("--drop-capabilities")), - Contains("/apex/com.android.sdkext/bin/derive_classpath")), + AllOf(Contains("/apex/com.android.sdkext/bin/derive_classpath"), + Contains(Flag("--override-device-sdk-version=", "35")), + Contains(Flag("--override-device-codename=", "Baklava")), + Contains(Flag("--override-device-known-codenames=", + "VanillaIceCream,Baklava")))), HasKeepFdsFor("/proc/self/fd/")), _, _)) |