xref: /aosp_15_r20/art/dexopt_chroot_setup/dexopt_chroot_setup.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2024 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_DEXOPT_CHROOT_SETUP_DEXOPT_CHROOT_SETUP_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_DEXOPT_CHROOT_SETUP_DEXOPT_CHROOT_SETUP_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include <optional>
21*795d594fSAndroid Build Coastguard Worker #include <string>
22*795d594fSAndroid Build Coastguard Worker 
23*795d594fSAndroid Build Coastguard Worker #include "aidl/com/android/server/art/BnDexoptChrootSetup.h"
24*795d594fSAndroid Build Coastguard Worker #include "android-base/result.h"
25*795d594fSAndroid Build Coastguard Worker #include "android-base/thread_annotations.h"
26*795d594fSAndroid Build Coastguard Worker 
27*795d594fSAndroid Build Coastguard Worker namespace art {
28*795d594fSAndroid Build Coastguard Worker namespace dexopt_chroot_setup {
29*795d594fSAndroid Build Coastguard Worker 
30*795d594fSAndroid Build Coastguard Worker // A comma-separated list, where each entry is a colon-separated pair of a partition name in the
31*795d594fSAndroid Build Coastguard Worker // super image and a mount point. E.g.,
32*795d594fSAndroid Build Coastguard Worker // some_partition_1:/some_mount_point_1,some_partition_2:/some_mount_point_2
33*795d594fSAndroid Build Coastguard Worker constexpr const char* kAdditionalPartitionsSysprop =
34*795d594fSAndroid Build Coastguard Worker     "dalvik.vm.pr_dexopt_additional_system_partitions";
35*795d594fSAndroid Build Coastguard Worker 
36*795d594fSAndroid Build Coastguard Worker // A service that sets up the chroot environment for Pre-reboot Dexopt.
37*795d594fSAndroid Build Coastguard Worker class DexoptChrootSetup : public aidl::com::android::server::art::BnDexoptChrootSetup {
38*795d594fSAndroid Build Coastguard Worker  public:
39*795d594fSAndroid Build Coastguard Worker   ndk::ScopedAStatus setUp(const std::optional<std::string>& in_otaSlot,
40*795d594fSAndroid Build Coastguard Worker                            bool in_mapSnapshotsForOta) override;
41*795d594fSAndroid Build Coastguard Worker 
42*795d594fSAndroid Build Coastguard Worker   ndk::ScopedAStatus init() override;
43*795d594fSAndroid Build Coastguard Worker 
44*795d594fSAndroid Build Coastguard Worker   ndk::ScopedAStatus tearDown(bool in_allowConcurrent) override;
45*795d594fSAndroid Build Coastguard Worker 
46*795d594fSAndroid Build Coastguard Worker   android::base::Result<void> Start();
47*795d594fSAndroid Build Coastguard Worker 
48*795d594fSAndroid Build Coastguard Worker  private:
49*795d594fSAndroid Build Coastguard Worker   android::base::Result<void> SetUpChroot(const std::optional<std::string>& ota_slot,
50*795d594fSAndroid Build Coastguard Worker                                           bool map_snapshots_for_ota) const REQUIRES(mu_);
51*795d594fSAndroid Build Coastguard Worker 
52*795d594fSAndroid Build Coastguard Worker   android::base::Result<void> InitChroot() const REQUIRES(mu_);
53*795d594fSAndroid Build Coastguard Worker 
54*795d594fSAndroid Build Coastguard Worker   android::base::Result<void> TearDownChroot() const REQUIRES(mu_);
55*795d594fSAndroid Build Coastguard Worker 
56*795d594fSAndroid Build Coastguard Worker   std::mutex mu_;
57*795d594fSAndroid Build Coastguard Worker };
58*795d594fSAndroid Build Coastguard Worker 
59*795d594fSAndroid Build Coastguard Worker std::string PathInChroot(std::string_view path);
60*795d594fSAndroid Build Coastguard Worker 
61*795d594fSAndroid Build Coastguard Worker android::base::Result<std::string> ConstructLinkerConfigCompatEnvSection(
62*795d594fSAndroid Build Coastguard Worker     const std::string& art_linker_config_content);
63*795d594fSAndroid Build Coastguard Worker 
64*795d594fSAndroid Build Coastguard Worker }  // namespace dexopt_chroot_setup
65*795d594fSAndroid Build Coastguard Worker }  // namespace art
66*795d594fSAndroid Build Coastguard Worker 
67*795d594fSAndroid Build Coastguard Worker #endif  // ART_DEXOPT_CHROOT_SETUP_DEXOPT_CHROOT_SETUP_H_
68