1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2022 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_ARTD_ARTD_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_ARTD_ARTD_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include <sys/inotify.h> 21*795d594fSAndroid Build Coastguard Worker #include <sys/mount.h> 22*795d594fSAndroid Build Coastguard Worker #include <sys/poll.h> 23*795d594fSAndroid Build Coastguard Worker #include <sys/stat.h> 24*795d594fSAndroid Build Coastguard Worker #include <sys/types.h> 25*795d594fSAndroid Build Coastguard Worker 26*795d594fSAndroid Build Coastguard Worker #include <csignal> 27*795d594fSAndroid Build Coastguard Worker #include <cstdint> 28*795d594fSAndroid Build Coastguard Worker #include <functional> 29*795d594fSAndroid Build Coastguard Worker #include <memory> 30*795d594fSAndroid Build Coastguard Worker #include <mutex> 31*795d594fSAndroid Build Coastguard Worker #include <optional> 32*795d594fSAndroid Build Coastguard Worker #include <string> 33*795d594fSAndroid Build Coastguard Worker #include <unordered_map> 34*795d594fSAndroid Build Coastguard Worker #include <unordered_set> 35*795d594fSAndroid Build Coastguard Worker #include <utility> 36*795d594fSAndroid Build Coastguard Worker #include <vector> 37*795d594fSAndroid Build Coastguard Worker 38*795d594fSAndroid Build Coastguard Worker #include "aidl/com/android/server/art/BnArtd.h" 39*795d594fSAndroid Build Coastguard Worker #include "aidl/com/android/server/art/BnArtdCancellationSignal.h" 40*795d594fSAndroid Build Coastguard Worker #include "aidl/com/android/server/art/BnArtdNotification.h" 41*795d594fSAndroid Build Coastguard Worker #include "android-base/result.h" 42*795d594fSAndroid Build Coastguard Worker #include "android-base/thread_annotations.h" 43*795d594fSAndroid Build Coastguard Worker #include "android-base/unique_fd.h" 44*795d594fSAndroid Build Coastguard Worker #include "android/binder_auto_utils.h" 45*795d594fSAndroid Build Coastguard Worker #include "base/os.h" 46*795d594fSAndroid Build Coastguard Worker #include "base/pidfd.h" 47*795d594fSAndroid Build Coastguard Worker #include "exec_utils.h" 48*795d594fSAndroid Build Coastguard Worker #include "oat/oat_file_assistant_context.h" 49*795d594fSAndroid Build Coastguard Worker #include "tools/cmdline_builder.h" 50*795d594fSAndroid Build Coastguard Worker #include "tools/system_properties.h" 51*795d594fSAndroid Build Coastguard Worker 52*795d594fSAndroid Build Coastguard Worker namespace art { 53*795d594fSAndroid Build Coastguard Worker namespace artd { 54*795d594fSAndroid Build Coastguard Worker 55*795d594fSAndroid Build Coastguard Worker // Define these function types instead of getting them from C headers because those from glibc C 56*795d594fSAndroid Build Coastguard Worker // headers contain the unwanted `noexcept`. 57*795d594fSAndroid Build Coastguard Worker using KillFn = int(pid_t, int); 58*795d594fSAndroid Build Coastguard Worker using FstatFn = int(int, struct stat*); 59*795d594fSAndroid Build Coastguard Worker using PollFn = int(struct pollfd*, nfds_t, int); 60*795d594fSAndroid Build Coastguard Worker using MountFn = int(const char*, const char*, const char*, uint32_t, const void*); 61*795d594fSAndroid Build Coastguard Worker 62*795d594fSAndroid Build Coastguard Worker android::base::Result<void> Restorecon( 63*795d594fSAndroid Build Coastguard Worker const std::string& path, 64*795d594fSAndroid Build Coastguard Worker const std::optional< 65*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::OutputArtifacts::PermissionSettings::SeContext>& 66*795d594fSAndroid Build Coastguard Worker se_context, 67*795d594fSAndroid Build Coastguard Worker bool recurse); 68*795d594fSAndroid Build Coastguard Worker 69*795d594fSAndroid Build Coastguard Worker struct Options { 70*795d594fSAndroid Build Coastguard Worker // If true, this artd instance is for Pre-reboot Dexopt. It runs in a chroot environment that is 71*795d594fSAndroid Build Coastguard Worker // set up by dexopt_chroot_setup. 72*795d594fSAndroid Build Coastguard Worker bool is_pre_reboot = false; 73*795d594fSAndroid Build Coastguard Worker }; 74*795d594fSAndroid Build Coastguard Worker 75*795d594fSAndroid Build Coastguard Worker class ArtdCancellationSignal : public aidl::com::android::server::art::BnArtdCancellationSignal { 76*795d594fSAndroid Build Coastguard Worker public: ArtdCancellationSignal(std::function<KillFn> kill_func)77*795d594fSAndroid Build Coastguard Worker explicit ArtdCancellationSignal(std::function<KillFn> kill_func) : kill_(std::move(kill_func)) {} 78*795d594fSAndroid Build Coastguard Worker 79*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus cancel() override; 80*795d594fSAndroid Build Coastguard Worker 81*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getType(int64_t* _aidl_return) override; 82*795d594fSAndroid Build Coastguard Worker 83*795d594fSAndroid Build Coastguard Worker // Returns callbacks to be provided to `ExecUtils`, to register/unregister the process with this 84*795d594fSAndroid Build Coastguard Worker // cancellation signal. 85*795d594fSAndroid Build Coastguard Worker ExecCallbacks CreateExecCallbacks(); 86*795d594fSAndroid Build Coastguard Worker 87*795d594fSAndroid Build Coastguard Worker bool IsCancelled(); 88*795d594fSAndroid Build Coastguard Worker 89*795d594fSAndroid Build Coastguard Worker private: 90*795d594fSAndroid Build Coastguard Worker std::mutex mu_; 91*795d594fSAndroid Build Coastguard Worker // True if cancellation has been signaled. 92*795d594fSAndroid Build Coastguard Worker bool is_cancelled_ GUARDED_BY(mu_) = false; 93*795d594fSAndroid Build Coastguard Worker // The pids of currently running child processes that are bound to this signal. 94*795d594fSAndroid Build Coastguard Worker std::unordered_set<pid_t> pids_ GUARDED_BY(mu_); 95*795d594fSAndroid Build Coastguard Worker 96*795d594fSAndroid Build Coastguard Worker std::function<KillFn> kill_; 97*795d594fSAndroid Build Coastguard Worker }; 98*795d594fSAndroid Build Coastguard Worker 99*795d594fSAndroid Build Coastguard Worker class ArtdNotification : public aidl::com::android::server::art::BnArtdNotification { 100*795d594fSAndroid Build Coastguard Worker public: ArtdNotification()101*795d594fSAndroid Build Coastguard Worker ArtdNotification() : done_(true) {} ArtdNotification(std::function<PollFn> poll_func,const std::string & path,android::base::unique_fd && inotify_fd,android::base::unique_fd && pidfd)102*795d594fSAndroid Build Coastguard Worker ArtdNotification(std::function<PollFn> poll_func, 103*795d594fSAndroid Build Coastguard Worker const std::string& path, 104*795d594fSAndroid Build Coastguard Worker android::base::unique_fd&& inotify_fd, 105*795d594fSAndroid Build Coastguard Worker android::base::unique_fd&& pidfd) 106*795d594fSAndroid Build Coastguard Worker : poll_(poll_func), 107*795d594fSAndroid Build Coastguard Worker path_(std::move(path)), 108*795d594fSAndroid Build Coastguard Worker inotify_fd_(std::move(inotify_fd)), 109*795d594fSAndroid Build Coastguard Worker pidfd_(std::move(pidfd)), 110*795d594fSAndroid Build Coastguard Worker done_(false) {} 111*795d594fSAndroid Build Coastguard Worker 112*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus wait(int in_timeoutMs, bool* _aidl_return) EXCLUDES(mu_) override; 113*795d594fSAndroid Build Coastguard Worker 114*795d594fSAndroid Build Coastguard Worker virtual ~ArtdNotification(); 115*795d594fSAndroid Build Coastguard Worker 116*795d594fSAndroid Build Coastguard Worker private: 117*795d594fSAndroid Build Coastguard Worker void CleanUp() EXCLUDES(mu_); 118*795d594fSAndroid Build Coastguard Worker 119*795d594fSAndroid Build Coastguard Worker const std::function<PollFn> poll_; 120*795d594fSAndroid Build Coastguard Worker 121*795d594fSAndroid Build Coastguard Worker std::mutex mu_; 122*795d594fSAndroid Build Coastguard Worker std::string path_ GUARDED_BY(mu_); 123*795d594fSAndroid Build Coastguard Worker android::base::unique_fd inotify_fd_ GUARDED_BY(mu_); 124*795d594fSAndroid Build Coastguard Worker android::base::unique_fd pidfd_ GUARDED_BY(mu_); 125*795d594fSAndroid Build Coastguard Worker bool done_ GUARDED_BY(mu_); 126*795d594fSAndroid Build Coastguard Worker bool is_called_ GUARDED_BY(mu_) = false; 127*795d594fSAndroid Build Coastguard Worker }; 128*795d594fSAndroid Build Coastguard Worker 129*795d594fSAndroid Build Coastguard Worker class Artd : public aidl::com::android::server::art::BnArtd { 130*795d594fSAndroid Build Coastguard Worker public: 131*795d594fSAndroid Build Coastguard Worker explicit Artd(Options&& options, 132*795d594fSAndroid Build Coastguard Worker std::unique_ptr<art::tools::SystemProperties> props = 133*795d594fSAndroid Build Coastguard Worker std::make_unique<art::tools::SystemProperties>(), 134*795d594fSAndroid Build Coastguard Worker std::unique_ptr<ExecUtils> exec_utils = std::make_unique<ExecUtils>(), 135*795d594fSAndroid Build Coastguard Worker std::function<KillFn> kill_func = kill, 136*795d594fSAndroid Build Coastguard Worker std::function<FstatFn> fstat_func = fstat, 137*795d594fSAndroid Build Coastguard Worker std::function<PollFn> poll_func = poll, 138*795d594fSAndroid Build Coastguard Worker std::function<MountFn> mount_func = mount, 139*795d594fSAndroid Build Coastguard Worker std::function<decltype(Restorecon)> restorecon_func = Restorecon, 140*795d594fSAndroid Build Coastguard Worker std::optional<std::string> pre_reboot_tmp_dir = std::nullopt, 141*795d594fSAndroid Build Coastguard Worker std::optional<std::string> init_environ_rc_path = std::nullopt) options_(std::move (options))142*795d594fSAndroid Build Coastguard Worker : options_(std::move(options)), 143*795d594fSAndroid Build Coastguard Worker props_(std::move(props)), 144*795d594fSAndroid Build Coastguard Worker exec_utils_(std::move(exec_utils)), 145*795d594fSAndroid Build Coastguard Worker kill_(std::move(kill_func)), 146*795d594fSAndroid Build Coastguard Worker fstat_(std::move(fstat_func)), 147*795d594fSAndroid Build Coastguard Worker poll_(std::move(poll_func)), 148*795d594fSAndroid Build Coastguard Worker mount_(std::move(mount_func)), 149*795d594fSAndroid Build Coastguard Worker restorecon_(std::move(restorecon_func)), 150*795d594fSAndroid Build Coastguard Worker pre_reboot_tmp_dir_(std::move(pre_reboot_tmp_dir)), 151*795d594fSAndroid Build Coastguard Worker init_environ_rc_path_(std::move(init_environ_rc_path)) {} 152*795d594fSAndroid Build Coastguard Worker 153*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus isAlive(bool* _aidl_return) override; 154*795d594fSAndroid Build Coastguard Worker 155*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus deleteArtifacts( 156*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::ArtifactsPath& in_artifactsPath, 157*795d594fSAndroid Build Coastguard Worker int64_t* _aidl_return) override; 158*795d594fSAndroid Build Coastguard Worker 159*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getDexoptStatus( 160*795d594fSAndroid Build Coastguard Worker const std::string& in_dexFile, 161*795d594fSAndroid Build Coastguard Worker const std::string& in_instructionSet, 162*795d594fSAndroid Build Coastguard Worker const std::optional<std::string>& in_classLoaderContext, 163*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::GetDexoptStatusResult* _aidl_return) override; 164*795d594fSAndroid Build Coastguard Worker 165*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus isProfileUsable(const aidl::com::android::server::art::ProfilePath& in_profile, 166*795d594fSAndroid Build Coastguard Worker const std::string& in_dexFile, 167*795d594fSAndroid Build Coastguard Worker bool* _aidl_return) override; 168*795d594fSAndroid Build Coastguard Worker 169*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus copyAndRewriteProfile( 170*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::ProfilePath& in_src, 171*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::OutputProfile* in_dst, 172*795d594fSAndroid Build Coastguard Worker const std::string& in_dexFile, 173*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::CopyAndRewriteProfileResult* _aidl_return) override; 174*795d594fSAndroid Build Coastguard Worker 175*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus copyAndRewriteEmbeddedProfile( 176*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::OutputProfile* in_dst, 177*795d594fSAndroid Build Coastguard Worker const std::string& in_dexFile, 178*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::CopyAndRewriteProfileResult* _aidl_return) override; 179*795d594fSAndroid Build Coastguard Worker 180*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus commitTmpProfile( 181*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::ProfilePath::TmpProfilePath& in_profile) override; 182*795d594fSAndroid Build Coastguard Worker 183*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus deleteProfile( 184*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::ProfilePath& in_profile) override; 185*795d594fSAndroid Build Coastguard Worker 186*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getProfileVisibility( 187*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::ProfilePath& in_profile, 188*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::FileVisibility* _aidl_return) override; 189*795d594fSAndroid Build Coastguard Worker 190*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus mergeProfiles( 191*795d594fSAndroid Build Coastguard Worker const std::vector<aidl::com::android::server::art::ProfilePath>& in_profiles, 192*795d594fSAndroid Build Coastguard Worker const std::optional<aidl::com::android::server::art::ProfilePath>& in_referenceProfile, 193*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::OutputProfile* in_outputProfile, 194*795d594fSAndroid Build Coastguard Worker const std::vector<std::string>& in_dexFiles, 195*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::MergeProfileOptions& in_options, 196*795d594fSAndroid Build Coastguard Worker bool* _aidl_return) override; 197*795d594fSAndroid Build Coastguard Worker 198*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getArtifactsVisibility( 199*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::ArtifactsPath& in_artifactsPath, 200*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::FileVisibility* _aidl_return) override; 201*795d594fSAndroid Build Coastguard Worker 202*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getDexFileVisibility( 203*795d594fSAndroid Build Coastguard Worker const std::string& in_dexFile, 204*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::FileVisibility* _aidl_return) override; 205*795d594fSAndroid Build Coastguard Worker 206*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getDmFileVisibility( 207*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::DexMetadataPath& in_dmFile, 208*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::FileVisibility* _aidl_return) override; 209*795d594fSAndroid Build Coastguard Worker 210*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getDexoptNeeded( 211*795d594fSAndroid Build Coastguard Worker const std::string& in_dexFile, 212*795d594fSAndroid Build Coastguard Worker const std::string& in_instructionSet, 213*795d594fSAndroid Build Coastguard Worker const std::optional<std::string>& in_classLoaderContext, 214*795d594fSAndroid Build Coastguard Worker const std::string& in_compilerFilter, 215*795d594fSAndroid Build Coastguard Worker int32_t in_dexoptTrigger, 216*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::GetDexoptNeededResult* _aidl_return) override; 217*795d594fSAndroid Build Coastguard Worker 218*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus dexopt( 219*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::OutputArtifacts& in_outputArtifacts, 220*795d594fSAndroid Build Coastguard Worker const std::string& in_dexFile, 221*795d594fSAndroid Build Coastguard Worker const std::string& in_instructionSet, 222*795d594fSAndroid Build Coastguard Worker const std::optional<std::string>& in_classLoaderContext, 223*795d594fSAndroid Build Coastguard Worker const std::string& in_compilerFilter, 224*795d594fSAndroid Build Coastguard Worker const std::optional<aidl::com::android::server::art::ProfilePath>& in_profile, 225*795d594fSAndroid Build Coastguard Worker const std::optional<aidl::com::android::server::art::VdexPath>& in_inputVdex, 226*795d594fSAndroid Build Coastguard Worker const std::optional<aidl::com::android::server::art::DexMetadataPath>& in_dmFile, 227*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::PriorityClass in_priorityClass, 228*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::DexoptOptions& in_dexoptOptions, 229*795d594fSAndroid Build Coastguard Worker const std::shared_ptr<aidl::com::android::server::art::IArtdCancellationSignal>& 230*795d594fSAndroid Build Coastguard Worker in_cancellationSignal, 231*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::ArtdDexoptResult* _aidl_return) override; 232*795d594fSAndroid Build Coastguard Worker 233*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus createCancellationSignal( 234*795d594fSAndroid Build Coastguard Worker std::shared_ptr<aidl::com::android::server::art::IArtdCancellationSignal>* _aidl_return) 235*795d594fSAndroid Build Coastguard Worker override; 236*795d594fSAndroid Build Coastguard Worker 237*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus cleanup( 238*795d594fSAndroid Build Coastguard Worker const std::vector<aidl::com::android::server::art::ProfilePath>& in_profilesToKeep, 239*795d594fSAndroid Build Coastguard Worker const std::vector<aidl::com::android::server::art::ArtifactsPath>& in_artifactsToKeep, 240*795d594fSAndroid Build Coastguard Worker const std::vector<aidl::com::android::server::art::VdexPath>& in_vdexFilesToKeep, 241*795d594fSAndroid Build Coastguard Worker const std::vector<aidl::com::android::server::art::RuntimeArtifactsPath>& 242*795d594fSAndroid Build Coastguard Worker in_runtimeArtifactsToKeep, 243*795d594fSAndroid Build Coastguard Worker bool in_keepPreRebootStagedFiles, 244*795d594fSAndroid Build Coastguard Worker int64_t* _aidl_return) override; 245*795d594fSAndroid Build Coastguard Worker 246*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus cleanUpPreRebootStagedFiles() override; 247*795d594fSAndroid Build Coastguard Worker 248*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus isInDalvikCache(const std::string& in_dexFile, bool* _aidl_return) override; 249*795d594fSAndroid Build Coastguard Worker 250*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus deleteRuntimeArtifacts( 251*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::RuntimeArtifactsPath& in_runtimeArtifactsPath, 252*795d594fSAndroid Build Coastguard Worker int64_t* _aidl_return) override; 253*795d594fSAndroid Build Coastguard Worker 254*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getArtifactsSize( 255*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::ArtifactsPath& in_artifactsPath, 256*795d594fSAndroid Build Coastguard Worker int64_t* _aidl_return) override; 257*795d594fSAndroid Build Coastguard Worker 258*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getVdexFileSize(const aidl::com::android::server::art::VdexPath& in_vdexPath, 259*795d594fSAndroid Build Coastguard Worker int64_t* _aidl_return) override; 260*795d594fSAndroid Build Coastguard Worker 261*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getRuntimeArtifactsSize( 262*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::RuntimeArtifactsPath& in_runtimeArtifactsPath, 263*795d594fSAndroid Build Coastguard Worker int64_t* _aidl_return) override; 264*795d594fSAndroid Build Coastguard Worker 265*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus getProfileSize(const aidl::com::android::server::art::ProfilePath& in_profile, 266*795d594fSAndroid Build Coastguard Worker int64_t* _aidl_return) override; 267*795d594fSAndroid Build Coastguard Worker 268*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus initProfileSaveNotification( 269*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::ProfilePath::PrimaryCurProfilePath& in_profilePath, 270*795d594fSAndroid Build Coastguard Worker int in_pid, 271*795d594fSAndroid Build Coastguard Worker std::shared_ptr<aidl::com::android::server::art::IArtdNotification>* _aidl_return) override; 272*795d594fSAndroid Build Coastguard Worker 273*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus commitPreRebootStagedFiles( 274*795d594fSAndroid Build Coastguard Worker const std::vector<aidl::com::android::server::art::ArtifactsPath>& in_artifacts, 275*795d594fSAndroid Build Coastguard Worker const std::vector<aidl::com::android::server::art::ProfilePath::WritableProfilePath>& 276*795d594fSAndroid Build Coastguard Worker in_profiles, 277*795d594fSAndroid Build Coastguard Worker bool* _aidl_return) override; 278*795d594fSAndroid Build Coastguard Worker 279*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus checkPreRebootSystemRequirements(const std::string& in_chrootDir, 280*795d594fSAndroid Build Coastguard Worker bool* _aidl_return) override; 281*795d594fSAndroid Build Coastguard Worker 282*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus preRebootInit( 283*795d594fSAndroid Build Coastguard Worker const std::shared_ptr<aidl::com::android::server::art::IArtdCancellationSignal>& 284*795d594fSAndroid Build Coastguard Worker in_cancellationSignal, 285*795d594fSAndroid Build Coastguard Worker bool* _aidl_return) override; 286*795d594fSAndroid Build Coastguard Worker 287*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus validateDexPath(const std::string& in_dexFile, 288*795d594fSAndroid Build Coastguard Worker std::optional<std::string>* _aidl_return) override; 289*795d594fSAndroid Build Coastguard Worker 290*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus validateClassLoaderContext(const std::string& in_dexFile, 291*795d594fSAndroid Build Coastguard Worker const std::string& in_classLoaderContext, 292*795d594fSAndroid Build Coastguard Worker std::optional<std::string>* _aidl_return) override; 293*795d594fSAndroid Build Coastguard Worker 294*795d594fSAndroid Build Coastguard Worker android::base::Result<void> Start(); 295*795d594fSAndroid Build Coastguard Worker 296*795d594fSAndroid Build Coastguard Worker private: 297*795d594fSAndroid Build Coastguard Worker android::base::Result<OatFileAssistantContext*> GetOatFileAssistantContext() 298*795d594fSAndroid Build Coastguard Worker EXCLUDES(ofa_context_mu_); 299*795d594fSAndroid Build Coastguard Worker 300*795d594fSAndroid Build Coastguard Worker android::base::Result<const std::vector<std::string>*> GetBootImageLocations() 301*795d594fSAndroid Build Coastguard Worker EXCLUDES(cache_mu_); 302*795d594fSAndroid Build Coastguard Worker 303*795d594fSAndroid Build Coastguard Worker android::base::Result<const std::vector<std::string>*> GetBootClassPath() EXCLUDES(cache_mu_); 304*795d594fSAndroid Build Coastguard Worker 305*795d594fSAndroid Build Coastguard Worker bool UseJitZygote() EXCLUDES(cache_mu_); 306*795d594fSAndroid Build Coastguard Worker bool UseJitZygoteLocked() REQUIRES(cache_mu_); 307*795d594fSAndroid Build Coastguard Worker 308*795d594fSAndroid Build Coastguard Worker const std::string& GetUserDefinedBootImageLocations() EXCLUDES(cache_mu_); 309*795d594fSAndroid Build Coastguard Worker const std::string& GetUserDefinedBootImageLocationsLocked() REQUIRES(cache_mu_); 310*795d594fSAndroid Build Coastguard Worker 311*795d594fSAndroid Build Coastguard Worker bool DenyArtApexDataFiles() EXCLUDES(cache_mu_); 312*795d594fSAndroid Build Coastguard Worker bool DenyArtApexDataFilesLocked() REQUIRES(cache_mu_); 313*795d594fSAndroid Build Coastguard Worker 314*795d594fSAndroid Build Coastguard Worker android::base::Result<int> ExecAndReturnCode(const std::vector<std::string>& arg_vector, 315*795d594fSAndroid Build Coastguard Worker int timeout_sec, 316*795d594fSAndroid Build Coastguard Worker const ExecCallbacks& callbacks = ExecCallbacks(), 317*795d594fSAndroid Build Coastguard Worker ProcessStat* stat = nullptr) const; 318*795d594fSAndroid Build Coastguard Worker 319*795d594fSAndroid Build Coastguard Worker android::base::Result<std::string> GetProfman(); 320*795d594fSAndroid Build Coastguard Worker 321*795d594fSAndroid Build Coastguard Worker android::base::Result<tools::CmdlineBuilder> GetArtExecCmdlineBuilder(); 322*795d594fSAndroid Build Coastguard Worker 323*795d594fSAndroid Build Coastguard Worker bool ShouldUseDex2Oat64(); 324*795d594fSAndroid Build Coastguard Worker 325*795d594fSAndroid Build Coastguard Worker bool ShouldUseDebugBinaries(); 326*795d594fSAndroid Build Coastguard Worker 327*795d594fSAndroid Build Coastguard Worker android::base::Result<std::string> GetDex2Oat(); 328*795d594fSAndroid Build Coastguard Worker 329*795d594fSAndroid Build Coastguard Worker bool ShouldCreateSwapFileForDexopt(); 330*795d594fSAndroid Build Coastguard Worker 331*795d594fSAndroid Build Coastguard Worker void AddBootImageFlags(/*out*/ art::tools::CmdlineBuilder& args); 332*795d594fSAndroid Build Coastguard Worker 333*795d594fSAndroid Build Coastguard Worker void AddCompilerConfigFlags(const std::string& instruction_set, 334*795d594fSAndroid Build Coastguard Worker const std::string& compiler_filter, 335*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::PriorityClass priority_class, 336*795d594fSAndroid Build Coastguard Worker const aidl::com::android::server::art::DexoptOptions& dexopt_options, 337*795d594fSAndroid Build Coastguard Worker /*out*/ art::tools::CmdlineBuilder& args); 338*795d594fSAndroid Build Coastguard Worker 339*795d594fSAndroid Build Coastguard Worker void AddPerfConfigFlags(aidl::com::android::server::art::PriorityClass priority_class, 340*795d594fSAndroid Build Coastguard Worker /*out*/ art::tools::CmdlineBuilder& art_exec_args, 341*795d594fSAndroid Build Coastguard Worker /*out*/ art::tools::CmdlineBuilder& args); 342*795d594fSAndroid Build Coastguard Worker 343*795d594fSAndroid Build Coastguard Worker android::base::Result<struct stat> Fstat(const art::File& file) const; 344*795d594fSAndroid Build Coastguard Worker 345*795d594fSAndroid Build Coastguard Worker // Creates a new dir at `source` and bind-mounts it at `target`. 346*795d594fSAndroid Build Coastguard Worker android::base::Result<void> BindMountNewDir(const std::string& source, 347*795d594fSAndroid Build Coastguard Worker const std::string& target) const; 348*795d594fSAndroid Build Coastguard Worker 349*795d594fSAndroid Build Coastguard Worker android::base::Result<void> BindMount(const std::string& source, const std::string& target) const; 350*795d594fSAndroid Build Coastguard Worker 351*795d594fSAndroid Build Coastguard Worker ndk::ScopedAStatus CopyAndRewriteProfileImpl( 352*795d594fSAndroid Build Coastguard Worker File src, 353*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::OutputProfile* dst_aidl, 354*795d594fSAndroid Build Coastguard Worker const std::string& dex_path, 355*795d594fSAndroid Build Coastguard Worker aidl::com::android::server::art::CopyAndRewriteProfileResult* aidl_return); 356*795d594fSAndroid Build Coastguard Worker 357*795d594fSAndroid Build Coastguard Worker android::base::Result<void> PreRebootInitClearEnvs(); 358*795d594fSAndroid Build Coastguard Worker android::base::Result<void> PreRebootInitSetEnvFromFile(const std::string& path); 359*795d594fSAndroid Build Coastguard Worker android::base::Result<void> PreRebootInitDeriveClasspath(const std::string& path); 360*795d594fSAndroid Build Coastguard Worker android::base::Result<bool> PreRebootInitBootImages(ArtdCancellationSignal* cancellation_signal); 361*795d594fSAndroid Build Coastguard Worker 362*795d594fSAndroid Build Coastguard Worker std::mutex cache_mu_; 363*795d594fSAndroid Build Coastguard Worker std::optional<std::vector<std::string>> cached_boot_image_locations_ GUARDED_BY(cache_mu_); 364*795d594fSAndroid Build Coastguard Worker std::optional<std::vector<std::string>> cached_boot_class_path_ GUARDED_BY(cache_mu_); 365*795d594fSAndroid Build Coastguard Worker std::optional<bool> cached_use_jit_zygote_ GUARDED_BY(cache_mu_); 366*795d594fSAndroid Build Coastguard Worker std::optional<std::string> cached_user_defined_boot_image_locations_ GUARDED_BY(cache_mu_); 367*795d594fSAndroid Build Coastguard Worker std::optional<bool> cached_deny_art_apex_data_files_ GUARDED_BY(cache_mu_); 368*795d594fSAndroid Build Coastguard Worker 369*795d594fSAndroid Build Coastguard Worker std::mutex ofa_context_mu_; 370*795d594fSAndroid Build Coastguard Worker std::unique_ptr<OatFileAssistantContext> ofa_context_ GUARDED_BY(ofa_context_mu_); 371*795d594fSAndroid Build Coastguard Worker 372*795d594fSAndroid Build Coastguard Worker const Options options_; 373*795d594fSAndroid Build Coastguard Worker const std::unique_ptr<art::tools::SystemProperties> props_; 374*795d594fSAndroid Build Coastguard Worker const std::unique_ptr<ExecUtils> exec_utils_; 375*795d594fSAndroid Build Coastguard Worker const std::function<KillFn> kill_; 376*795d594fSAndroid Build Coastguard Worker const std::function<FstatFn> fstat_; 377*795d594fSAndroid Build Coastguard Worker const std::function<PollFn> poll_; 378*795d594fSAndroid Build Coastguard Worker const std::function<MountFn> mount_; 379*795d594fSAndroid Build Coastguard Worker const std::function<decltype(Restorecon)> restorecon_; 380*795d594fSAndroid Build Coastguard Worker const std::optional<std::string> pre_reboot_tmp_dir_; 381*795d594fSAndroid Build Coastguard Worker const std::optional<std::string> init_environ_rc_path_; 382*795d594fSAndroid Build Coastguard Worker }; 383*795d594fSAndroid Build Coastguard Worker 384*795d594fSAndroid Build Coastguard Worker // A class for getting system properties from a `build.prop` file. 385*795d594fSAndroid Build Coastguard Worker // Note that this class ignores import statements and only reads properties from the given file 386*795d594fSAndroid Build Coastguard Worker // itself. To read properties from an imported file, insatiate this class with the imported file 387*795d594fSAndroid Build Coastguard Worker // directly. 388*795d594fSAndroid Build Coastguard Worker class BuildSystemProperties : public tools::SystemProperties { 389*795d594fSAndroid Build Coastguard Worker public: 390*795d594fSAndroid Build Coastguard Worker // Creates an instance and loads system properties from the `build.prop` file specified at the 391*795d594fSAndroid Build Coastguard Worker // given path. 392*795d594fSAndroid Build Coastguard Worker static android::base::Result<BuildSystemProperties> Create(const std::string& filename); 393*795d594fSAndroid Build Coastguard Worker 394*795d594fSAndroid Build Coastguard Worker protected: 395*795d594fSAndroid Build Coastguard Worker std::string GetProperty(const std::string& key) const override; 396*795d594fSAndroid Build Coastguard Worker 397*795d594fSAndroid Build Coastguard Worker private: BuildSystemProperties(std::unordered_map<std::string,std::string> && system_properties)398*795d594fSAndroid Build Coastguard Worker explicit BuildSystemProperties(std::unordered_map<std::string, std::string>&& system_properties) 399*795d594fSAndroid Build Coastguard Worker : system_properties_(std::move(system_properties)) {} 400*795d594fSAndroid Build Coastguard Worker 401*795d594fSAndroid Build Coastguard Worker const std::unordered_map<std::string, std::string> system_properties_; 402*795d594fSAndroid Build Coastguard Worker }; 403*795d594fSAndroid Build Coastguard Worker 404*795d594fSAndroid Build Coastguard Worker } // namespace artd 405*795d594fSAndroid Build Coastguard Worker } // namespace art 406*795d594fSAndroid Build Coastguard Worker 407*795d594fSAndroid Build Coastguard Worker #endif // ART_ARTD_ARTD_H_ 408