diff options
Diffstat (limited to 'dexopt_chroot_setup')
-rw-r--r-- | dexopt_chroot_setup/Android.bp | 111 | ||||
-rw-r--r-- | dexopt_chroot_setup/README.md | 10 | ||||
-rw-r--r-- | dexopt_chroot_setup/binder/Android.bp | 56 | ||||
-rw-r--r-- | dexopt_chroot_setup/binder/com/android/server/art/IDexoptChrootSetup.aidl | 21 | ||||
-rw-r--r-- | dexopt_chroot_setup/dexopt_chroot_setup.cc | 52 | ||||
-rw-r--r-- | dexopt_chroot_setup/dexopt_chroot_setup.h | 35 | ||||
-rw-r--r-- | dexopt_chroot_setup/dexopt_chroot_setup_fuzzer.cc | 31 | ||||
-rw-r--r-- | dexopt_chroot_setup/dexopt_chroot_setup_main.cc | 43 | ||||
-rw-r--r-- | dexopt_chroot_setup/dexopt_chroot_setup_test.cc | 41 |
9 files changed, 400 insertions, 0 deletions
diff --git a/dexopt_chroot_setup/Android.bp b/dexopt_chroot_setup/Android.bp new file mode 100644 index 0000000000..93e012a594 --- /dev/null +++ b/dexopt_chroot_setup/Android.bp @@ -0,0 +1,111 @@ +// +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "art_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["art_license"], +} + +cc_defaults { + name: "dexopt_chroot_setup_defaults", + defaults: ["art_defaults"], + srcs: [ + "dexopt_chroot_setup.cc", + ], + shared_libs: [ + "libbase", + "libbinder_ndk", + ], + static_libs: [ + "dexopt_chroot_setup-aidl-ndk", + ], +} + +art_cc_binary { + name: "dexopt_chroot_setup", + defaults: ["dexopt_chroot_setup_defaults"], + srcs: [ + "dexopt_chroot_setup_main.cc", + ], + shared_libs: [ + "libart", + "libartbase", + ], + apex_available: [ + "com.android.art", + "com.android.art.debug", + ], +} + +art_cc_defaults { + name: "art_dexopt_chroot_setup_tests_defaults", + defaults: ["dexopt_chroot_setup_defaults"], + static_libs: [ + "libgmock", + ], + srcs: [ + "dexopt_chroot_setup_test.cc", + ], +} + +// Version of ART gtest `art_dexopt_chroot_setup_tests` bundled with the ART +// APEX on target. +// +// This test requires the full libbinder_ndk implementation on host, which is +// not available as a prebuilt on the thin master-art branch. Hence it won't +// work there, and there's a conditional in Android.gtest.mk to exclude it from +// test-art-host-gtest. +art_cc_test { + name: "art_dexopt_chroot_setup_tests", + defaults: [ + "art_gtest_defaults", + "art_dexopt_chroot_setup_tests_defaults", + ], +} + +// Standalone version of ART gtest `art_dexopt_chroot_setup_tests`, not bundled +// with the ART APEX on target. +art_cc_test { + name: "art_standalone_dexopt_chroot_setup_tests", + defaults: [ + "art_standalone_gtest_defaults", + "art_dexopt_chroot_setup_tests_defaults", + ], +} + +cc_fuzz { + name: "dexopt_chroot_setup_fuzzer", + defaults: [ + "service_fuzzer_defaults", + "art_module_source_build_defaults", + "dexopt_chroot_setup_defaults", + ], + host_supported: true, + srcs: ["dexopt_chroot_setup_fuzzer.cc"], + shared_libs: [ + "libart", + "libartbase", + "liblog", + ], + fuzz_config: { + cc: [ + "art-module-team@google.com", + ], + }, +} diff --git a/dexopt_chroot_setup/README.md b/dexopt_chroot_setup/README.md new file mode 100644 index 0000000000..71401248d6 --- /dev/null +++ b/dexopt_chroot_setup/README.md @@ -0,0 +1,10 @@ +## dexopt_chroot_setup + +dexopt_chroot_setup is a component of ART Service. It sets up the chroot +environment for Pre-reboot Dexopt, to dexopt apps on a best-effort basis before +the reboot after a Mainline update or an OTA update is downloaded, to support +seamless updates. + +It requires elevated permissions that are not available to system_server, such +as mounting filesystems. It publishes a binder interface that is internal to ART +Service's Java code. diff --git a/dexopt_chroot_setup/binder/Android.bp b/dexopt_chroot_setup/binder/Android.bp new file mode 100644 index 0000000000..629a783062 --- /dev/null +++ b/dexopt_chroot_setup/binder/Android.bp @@ -0,0 +1,56 @@ +// +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "art_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["art_license"], +} + +aidl_interface { + name: "dexopt_chroot_setup-aidl", + srcs: [ + "com/android/server/art/*.aidl", + ], + host_supported: true, + backend: { + java: { + enabled: true, + apex_available: [ + "com.android.art", + "com.android.art.debug", + ], + }, + cpp: { + enabled: false, + }, + ndk: { + enabled: true, + apex_available: [ + "com.android.art", + "com.android.art.debug", + ], + }, + }, + unstable: true, + visibility: [ + "//system/tools/aidl/build", + "//art:__subpackages__", + ], + min_sdk_version: "31", +} diff --git a/dexopt_chroot_setup/binder/com/android/server/art/IDexoptChrootSetup.aidl b/dexopt_chroot_setup/binder/com/android/server/art/IDexoptChrootSetup.aidl new file mode 100644 index 0000000000..f38fceade8 --- /dev/null +++ b/dexopt_chroot_setup/binder/com/android/server/art/IDexoptChrootSetup.aidl @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.art; + +/** @hide */ +interface IDexoptChrootSetup { +} diff --git a/dexopt_chroot_setup/dexopt_chroot_setup.cc b/dexopt_chroot_setup/dexopt_chroot_setup.cc new file mode 100644 index 0000000000..c9a1c735c2 --- /dev/null +++ b/dexopt_chroot_setup/dexopt_chroot_setup.cc @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dexopt_chroot_setup.h" + +#include "aidl/com/android/server/art/BnDexoptChrootSetup.h" +#include "android-base/errors.h" +#include "android-base/result.h" +#include "android/binder_auto_utils.h" +#include "android/binder_manager.h" +#include "android/binder_process.h" + +namespace art { +namespace dexopt_chroot_setup { + +namespace { + +using ::android::base::Error; +using ::android::base::Result; +using ::ndk::ScopedAStatus; + +constexpr const char* kServiceName = "dexopt_chroot_setup"; + +} // namespace + +Result<void> DexoptChrootSetup::Start() { + ScopedAStatus status = ScopedAStatus::fromStatus( + AServiceManager_registerLazyService(this->asBinder().get(), kServiceName)); + if (!status.isOk()) { + return Error() << status.getDescription(); + } + + ABinderProcess_startThreadPool(); + + return {}; +} + +} // namespace dexopt_chroot_setup +} // namespace art diff --git a/dexopt_chroot_setup/dexopt_chroot_setup.h b/dexopt_chroot_setup/dexopt_chroot_setup.h new file mode 100644 index 0000000000..858c71711d --- /dev/null +++ b/dexopt_chroot_setup/dexopt_chroot_setup.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_DEXOPT_CHROOT_SETUP_DEXOPT_CHROOT_SETUP_H_ +#define ART_DEXOPT_CHROOT_SETUP_DEXOPT_CHROOT_SETUP_H_ + +#include "aidl/com/android/server/art/BnDexoptChrootSetup.h" +#include "android-base/result.h" + +namespace art { +namespace dexopt_chroot_setup { + +// A service that sets up the chroot environment for Pre-reboot Dexopt. +class DexoptChrootSetup : public aidl::com::android::server::art::BnDexoptChrootSetup { + public: + android::base::Result<void> Start(); +}; + +} // namespace dexopt_chroot_setup +} // namespace art + +#endif // ART_DEXOPT_CHROOT_SETUP_DEXOPT_CHROOT_SETUP_H_ diff --git a/dexopt_chroot_setup/dexopt_chroot_setup_fuzzer.cc b/dexopt_chroot_setup/dexopt_chroot_setup_fuzzer.cc new file mode 100644 index 0000000000..fe3663e38e --- /dev/null +++ b/dexopt_chroot_setup/dexopt_chroot_setup_fuzzer.cc @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dexopt_chroot_setup.h" +#include "fuzzbinder/libbinder_ndk_driver.h" +#include "fuzzer/FuzzedDataProvider.h" + +using ::android::fuzzService; +using ::art::dexopt_chroot_setup::DexoptChrootSetup; +using ::ndk::SharedRefBase; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + auto dexopt_chroot_setup = SharedRefBase::make<DexoptChrootSetup>(); + + fuzzService(dexopt_chroot_setup->asBinder().get(), FuzzedDataProvider(data, size)); + + return 0; +} diff --git a/dexopt_chroot_setup/dexopt_chroot_setup_main.cc b/dexopt_chroot_setup/dexopt_chroot_setup_main.cc new file mode 100644 index 0000000000..5e74783619 --- /dev/null +++ b/dexopt_chroot_setup/dexopt_chroot_setup_main.cc @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdlib.h> + +#include "android-base/logging.h" +#include "android-base/macros.h" +#include "android/binder_interface_utils.h" +#include "android/binder_process.h" +#include "dexopt_chroot_setup.h" + +int main([[maybe_unused]] int argc, char* argv[]) { + android::base::InitLogging(argv); + + auto dexopt_chroot_setup = + ndk::SharedRefBase::make<art::dexopt_chroot_setup::DexoptChrootSetup>(); + + LOG(INFO) << "Starting dexopt_chroot_setup"; + + if (android::base::Result<void> ret = dexopt_chroot_setup->Start(); !ret.ok()) { + LOG(ERROR) << "Unable to start dexopt_chroot_setup: " << ret.error(); + exit(1); + } + + ABinderProcess_joinThreadPool(); + + LOG(INFO) << "dexopt_chroot_setup shutting down"; + + return 0; +} diff --git a/dexopt_chroot_setup/dexopt_chroot_setup_test.cc b/dexopt_chroot_setup/dexopt_chroot_setup_test.cc new file mode 100644 index 0000000000..ba42fc53ea --- /dev/null +++ b/dexopt_chroot_setup/dexopt_chroot_setup_test.cc @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dexopt_chroot_setup.h" + +#include "base/common_art_test.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace art { +namespace dexopt_chroot_setup { +namespace { + +class DexoptChrootSetupTest : public CommonArtTest { + protected: + void SetUp() override { + CommonArtTest::SetUp(); + dexopt_chroot_setup_ = ndk::SharedRefBase::make<DexoptChrootSetup>(); + } + + std::shared_ptr<DexoptChrootSetup> dexopt_chroot_setup_; +}; + +TEST_F(DexoptChrootSetupTest, HelloWorld) { EXPECT_NE(dexopt_chroot_setup_, nullptr); } + +} // namespace +} // namespace dexopt_chroot_setup +} // namespace art |