xref: /aosp_15_r20/art/odrefresh/odrefresh.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2021 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_ODREFRESH_ODREFRESH_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_ODREFRESH_ODREFRESH_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include <ctime>
21*795d594fSAndroid Build Coastguard Worker #include <functional>
22*795d594fSAndroid Build Coastguard Worker #include <memory>
23*795d594fSAndroid Build Coastguard Worker #include <optional>
24*795d594fSAndroid Build Coastguard Worker #include <set>
25*795d594fSAndroid Build Coastguard Worker #include <string>
26*795d594fSAndroid Build Coastguard Worker #include <unordered_set>
27*795d594fSAndroid Build Coastguard Worker #include <vector>
28*795d594fSAndroid Build Coastguard Worker 
29*795d594fSAndroid Build Coastguard Worker #include "android-base/function_ref.h"
30*795d594fSAndroid Build Coastguard Worker #include "android-base/result.h"
31*795d594fSAndroid Build Coastguard Worker #include "base/os.h"
32*795d594fSAndroid Build Coastguard Worker #include "com_android_apex.h"
33*795d594fSAndroid Build Coastguard Worker #include "com_android_art.h"
34*795d594fSAndroid Build Coastguard Worker #include "exec_utils.h"
35*795d594fSAndroid Build Coastguard Worker #include "odr_artifacts.h"
36*795d594fSAndroid Build Coastguard Worker #include "odr_config.h"
37*795d594fSAndroid Build Coastguard Worker #include "odr_metrics.h"
38*795d594fSAndroid Build Coastguard Worker #include "odrefresh/odrefresh.h"
39*795d594fSAndroid Build Coastguard Worker #include "tools/cmdline_builder.h"
40*795d594fSAndroid Build Coastguard Worker 
41*795d594fSAndroid Build Coastguard Worker namespace art {
42*795d594fSAndroid Build Coastguard Worker namespace odrefresh {
43*795d594fSAndroid Build Coastguard Worker 
44*795d594fSAndroid Build Coastguard Worker class OnDeviceRefresh;
45*795d594fSAndroid Build Coastguard Worker 
46*795d594fSAndroid Build Coastguard Worker struct BootImages {
47*795d594fSAndroid Build Coastguard Worker   static constexpr int kMaxCount = 2;
48*795d594fSAndroid Build Coastguard Worker 
49*795d594fSAndroid Build Coastguard Worker   bool primary_boot_image : 1;
50*795d594fSAndroid Build Coastguard Worker   bool boot_image_mainline_extension : 1;
51*795d594fSAndroid Build Coastguard Worker 
52*795d594fSAndroid Build Coastguard Worker   int Count() const;
53*795d594fSAndroid Build Coastguard Worker 
54*795d594fSAndroid Build Coastguard Worker   OdrMetrics::BcpCompilationType GetTypeForMetrics() const;
55*795d594fSAndroid Build Coastguard Worker };
56*795d594fSAndroid Build Coastguard Worker 
57*795d594fSAndroid Build Coastguard Worker struct CompilationOptions {
58*795d594fSAndroid Build Coastguard Worker   // If not empty, generate the boot images for ISAs in the list.
59*795d594fSAndroid Build Coastguard Worker   std::vector<std::pair<InstructionSet, BootImages>> boot_images_to_generate_for_isas;
60*795d594fSAndroid Build Coastguard Worker 
61*795d594fSAndroid Build Coastguard Worker   // If not empty, compile the system server jars in the list.
62*795d594fSAndroid Build Coastguard Worker   std::set<std::string> system_server_jars_to_compile;
63*795d594fSAndroid Build Coastguard Worker 
64*795d594fSAndroid Build Coastguard Worker   static CompilationOptions CompileAll(const OnDeviceRefresh& odr);
65*795d594fSAndroid Build Coastguard Worker 
66*795d594fSAndroid Build Coastguard Worker   int CompilationUnitCount() const;
67*795d594fSAndroid Build Coastguard Worker };
68*795d594fSAndroid Build Coastguard Worker 
69*795d594fSAndroid Build Coastguard Worker struct CompilationResult {
70*795d594fSAndroid Build Coastguard Worker   OdrMetrics::Status status = OdrMetrics::Status::kOK;
71*795d594fSAndroid Build Coastguard Worker   std::string error_msg;
72*795d594fSAndroid Build Coastguard Worker   int64_t elapsed_time_ms = 0;
73*795d594fSAndroid Build Coastguard Worker   std::optional<ExecResult> dex2oat_result;
74*795d594fSAndroid Build Coastguard Worker 
75*795d594fSAndroid Build Coastguard Worker   static CompilationResult Ok() { return {}; }
76*795d594fSAndroid Build Coastguard Worker 
77*795d594fSAndroid Build Coastguard Worker   static CompilationResult Dex2oatOk(int64_t elapsed_time_ms, const ExecResult& dex2oat_result) {
78*795d594fSAndroid Build Coastguard Worker     return {.elapsed_time_ms = elapsed_time_ms, .dex2oat_result = dex2oat_result};
79*795d594fSAndroid Build Coastguard Worker   }
80*795d594fSAndroid Build Coastguard Worker 
81*795d594fSAndroid Build Coastguard Worker   static CompilationResult Error(OdrMetrics::Status status, const std::string& error_msg) {
82*795d594fSAndroid Build Coastguard Worker     return {.status = status, .error_msg = error_msg};
83*795d594fSAndroid Build Coastguard Worker   }
84*795d594fSAndroid Build Coastguard Worker 
85*795d594fSAndroid Build Coastguard Worker   static CompilationResult Dex2oatError(const std::string& error_msg,
86*795d594fSAndroid Build Coastguard Worker                                         int64_t elapsed_time_ms,
87*795d594fSAndroid Build Coastguard Worker                                         const ExecResult& dex2oat_result) {
88*795d594fSAndroid Build Coastguard Worker     return {.status = OdrMetrics::Status::kDex2OatError,
89*795d594fSAndroid Build Coastguard Worker             .error_msg = error_msg,
90*795d594fSAndroid Build Coastguard Worker             .elapsed_time_ms = elapsed_time_ms,
91*795d594fSAndroid Build Coastguard Worker             .dex2oat_result = dex2oat_result};
92*795d594fSAndroid Build Coastguard Worker   }
93*795d594fSAndroid Build Coastguard Worker 
94*795d594fSAndroid Build Coastguard Worker   bool IsOk() { return status == OdrMetrics::Status::kOK; }
95*795d594fSAndroid Build Coastguard Worker 
96*795d594fSAndroid Build Coastguard Worker   void Merge(const CompilationResult& other) {
97*795d594fSAndroid Build Coastguard Worker     // Accumulate the compilation time.
98*795d594fSAndroid Build Coastguard Worker     elapsed_time_ms += other.elapsed_time_ms;
99*795d594fSAndroid Build Coastguard Worker 
100*795d594fSAndroid Build Coastguard Worker     // Only keep the first failure.
101*795d594fSAndroid Build Coastguard Worker     if (status == OdrMetrics::Status::kOK) {
102*795d594fSAndroid Build Coastguard Worker       status = other.status;
103*795d594fSAndroid Build Coastguard Worker       error_msg = other.error_msg;
104*795d594fSAndroid Build Coastguard Worker       dex2oat_result = other.dex2oat_result;
105*795d594fSAndroid Build Coastguard Worker     }
106*795d594fSAndroid Build Coastguard Worker   }
107*795d594fSAndroid Build Coastguard Worker };
108*795d594fSAndroid Build Coastguard Worker 
109*795d594fSAndroid Build Coastguard Worker class PreconditionCheckResult {
110*795d594fSAndroid Build Coastguard Worker  public:
111*795d594fSAndroid Build Coastguard Worker   static PreconditionCheckResult NoneOk(OdrMetrics::Trigger trigger) {
112*795d594fSAndroid Build Coastguard Worker     return PreconditionCheckResult(trigger,
113*795d594fSAndroid Build Coastguard Worker                                    /*primary_boot_image_ok=*/false,
114*795d594fSAndroid Build Coastguard Worker                                    /*boot_image_mainline_extension_ok=*/false,
115*795d594fSAndroid Build Coastguard Worker                                    /*system_server_ok=*/false);
116*795d594fSAndroid Build Coastguard Worker   }
117*795d594fSAndroid Build Coastguard Worker   static PreconditionCheckResult BootImageMainlineExtensionNotOk(OdrMetrics::Trigger trigger) {
118*795d594fSAndroid Build Coastguard Worker     return PreconditionCheckResult(trigger,
119*795d594fSAndroid Build Coastguard Worker                                    /*primary_boot_image_ok=*/true,
120*795d594fSAndroid Build Coastguard Worker                                    /*boot_image_mainline_extension_ok=*/false,
121*795d594fSAndroid Build Coastguard Worker                                    /*system_server_ok=*/false);
122*795d594fSAndroid Build Coastguard Worker   }
123*795d594fSAndroid Build Coastguard Worker   static PreconditionCheckResult SystemServerNotOk(OdrMetrics::Trigger trigger) {
124*795d594fSAndroid Build Coastguard Worker     return PreconditionCheckResult(trigger,
125*795d594fSAndroid Build Coastguard Worker                                    /*primary_boot_image_ok=*/true,
126*795d594fSAndroid Build Coastguard Worker                                    /*boot_image_mainline_extension_ok=*/true,
127*795d594fSAndroid Build Coastguard Worker                                    /*system_server_ok=*/false);
128*795d594fSAndroid Build Coastguard Worker   }
129*795d594fSAndroid Build Coastguard Worker   static PreconditionCheckResult AllOk() {
130*795d594fSAndroid Build Coastguard Worker     return PreconditionCheckResult(/*trigger=*/std::nullopt,
131*795d594fSAndroid Build Coastguard Worker                                    /*primary_boot_image_ok=*/true,
132*795d594fSAndroid Build Coastguard Worker                                    /*boot_image_mainline_extension_ok=*/true,
133*795d594fSAndroid Build Coastguard Worker                                    /*system_server_ok=*/true);
134*795d594fSAndroid Build Coastguard Worker   }
135*795d594fSAndroid Build Coastguard Worker   bool IsAllOk() const { return !trigger_.has_value(); }
136*795d594fSAndroid Build Coastguard Worker   OdrMetrics::Trigger GetTrigger() const { return trigger_.value(); }
137*795d594fSAndroid Build Coastguard Worker   bool IsPrimaryBootImageOk() const { return primary_boot_image_ok_; }
138*795d594fSAndroid Build Coastguard Worker   bool IsBootImageMainlineExtensionOk() const { return boot_image_mainline_extension_ok_; }
139*795d594fSAndroid Build Coastguard Worker   bool IsSystemServerOk() const { return system_server_ok_; }
140*795d594fSAndroid Build Coastguard Worker 
141*795d594fSAndroid Build Coastguard Worker  private:
142*795d594fSAndroid Build Coastguard Worker   // Use static factory methods instead.
143*795d594fSAndroid Build Coastguard Worker   PreconditionCheckResult(std::optional<OdrMetrics::Trigger> trigger,
144*795d594fSAndroid Build Coastguard Worker                           bool primary_boot_image_ok,
145*795d594fSAndroid Build Coastguard Worker                           bool boot_image_mainline_extension_ok,
146*795d594fSAndroid Build Coastguard Worker                           bool system_server_ok)
147*795d594fSAndroid Build Coastguard Worker       : trigger_(trigger),
148*795d594fSAndroid Build Coastguard Worker         primary_boot_image_ok_(primary_boot_image_ok),
149*795d594fSAndroid Build Coastguard Worker         boot_image_mainline_extension_ok_(boot_image_mainline_extension_ok),
150*795d594fSAndroid Build Coastguard Worker         system_server_ok_(system_server_ok) {}
151*795d594fSAndroid Build Coastguard Worker 
152*795d594fSAndroid Build Coastguard Worker   // Indicates why the precondition is not okay, or `std::nullopt` if it's okay.
153*795d594fSAndroid Build Coastguard Worker   std::optional<OdrMetrics::Trigger> trigger_;
154*795d594fSAndroid Build Coastguard Worker   bool primary_boot_image_ok_;
155*795d594fSAndroid Build Coastguard Worker   bool boot_image_mainline_extension_ok_;
156*795d594fSAndroid Build Coastguard Worker   bool system_server_ok_;
157*795d594fSAndroid Build Coastguard Worker };
158*795d594fSAndroid Build Coastguard Worker 
159*795d594fSAndroid Build Coastguard Worker class OnDeviceRefresh final {
160*795d594fSAndroid Build Coastguard Worker  public:
161*795d594fSAndroid Build Coastguard Worker   explicit OnDeviceRefresh(
162*795d594fSAndroid Build Coastguard Worker       const OdrConfig& config,
163*795d594fSAndroid Build Coastguard Worker       android::base::function_ref<int(const char*, const char*)> setfilecon,
164*795d594fSAndroid Build Coastguard Worker       android::base::function_ref<int(const char*, unsigned int)> restorecon);
165*795d594fSAndroid Build Coastguard Worker 
166*795d594fSAndroid Build Coastguard Worker   // Constructor with injections. For testing and internal use only.
167*795d594fSAndroid Build Coastguard Worker   OnDeviceRefresh(
168*795d594fSAndroid Build Coastguard Worker       const OdrConfig& config,
169*795d594fSAndroid Build Coastguard Worker       android::base::function_ref<int(const char*, const char*)> setfilecon,
170*795d594fSAndroid Build Coastguard Worker       android::base::function_ref<int(const char*, unsigned int)> restorecon,
171*795d594fSAndroid Build Coastguard Worker       const std::string& cache_info_filename,
172*795d594fSAndroid Build Coastguard Worker       std::unique_ptr<ExecUtils> exec_utils,
173*795d594fSAndroid Build Coastguard Worker       android::base::function_ref<bool()> check_compilation_space);
174*795d594fSAndroid Build Coastguard Worker 
175*795d594fSAndroid Build Coastguard Worker   // Returns the exit code and specifies what should be compiled in `compilation_options`.
176*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED ExitCode
177*795d594fSAndroid Build Coastguard Worker   CheckArtifactsAreUpToDate(OdrMetrics& metrics,
178*795d594fSAndroid Build Coastguard Worker                             /*out*/ CompilationOptions* compilation_options) const;
179*795d594fSAndroid Build Coastguard Worker 
180*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED ExitCode Compile(OdrMetrics& metrics, CompilationOptions compilation_options) const;
181*795d594fSAndroid Build Coastguard Worker 
182*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED bool RemoveArtifactsDirectory() const;
183*795d594fSAndroid Build Coastguard Worker 
184*795d594fSAndroid Build Coastguard Worker   // Returns a set of all system server jars.
185*795d594fSAndroid Build Coastguard Worker   std::set<std::string> AllSystemServerJars() const {
186*795d594fSAndroid Build Coastguard Worker     return {all_systemserver_jars_.begin(), all_systemserver_jars_.end()};
187*795d594fSAndroid Build Coastguard Worker   }
188*795d594fSAndroid Build Coastguard Worker 
189*795d594fSAndroid Build Coastguard Worker   const OdrConfig& Config() const { return config_; }
190*795d594fSAndroid Build Coastguard Worker 
191*795d594fSAndroid Build Coastguard Worker  private:
192*795d594fSAndroid Build Coastguard Worker   time_t GetExecutionTimeUsed() const;
193*795d594fSAndroid Build Coastguard Worker 
194*795d594fSAndroid Build Coastguard Worker   time_t GetExecutionTimeRemaining() const;
195*795d594fSAndroid Build Coastguard Worker 
196*795d594fSAndroid Build Coastguard Worker   time_t GetSubprocessTimeout() const;
197*795d594fSAndroid Build Coastguard Worker 
198*795d594fSAndroid Build Coastguard Worker   android::base::Result<std::string> CreateStagingDirectory() const;
199*795d594fSAndroid Build Coastguard Worker 
200*795d594fSAndroid Build Coastguard Worker   // Gets the `ApexInfo` for active APEXes.
201*795d594fSAndroid Build Coastguard Worker   std::optional<std::vector<com::android::apex::ApexInfo>> GetApexInfoList() const;
202*795d594fSAndroid Build Coastguard Worker 
203*795d594fSAndroid Build Coastguard Worker   // Reads the ART APEX cache information (if any) found in the output artifact directory.
204*795d594fSAndroid Build Coastguard Worker   android::base::Result<com::android::art::CacheInfo> ReadCacheInfo() const;
205*795d594fSAndroid Build Coastguard Worker 
206*795d594fSAndroid Build Coastguard Worker   // Writes ART APEX cache information to `kOnDeviceRefreshOdrefreshArtifactDirectory`.
207*795d594fSAndroid Build Coastguard Worker   android::base::Result<void> WriteCacheInfo() const;
208*795d594fSAndroid Build Coastguard Worker 
209*795d594fSAndroid Build Coastguard Worker   std::vector<com::android::art::Component> GenerateBootClasspathComponents() const;
210*795d594fSAndroid Build Coastguard Worker 
211*795d594fSAndroid Build Coastguard Worker   std::vector<com::android::art::Component> GenerateDex2oatBootClasspathComponents() const;
212*795d594fSAndroid Build Coastguard Worker 
213*795d594fSAndroid Build Coastguard Worker   std::vector<com::android::art::SystemServerComponent> GenerateSystemServerComponents() const;
214*795d594fSAndroid Build Coastguard Worker 
215*795d594fSAndroid Build Coastguard Worker   // Returns the list of BCP jars in the ART module.
216*795d594fSAndroid Build Coastguard Worker   std::vector<std::string> GetArtBcpJars() const;
217*795d594fSAndroid Build Coastguard Worker 
218*795d594fSAndroid Build Coastguard Worker   // Returns the list of BCP jars for the boot image framework extension.
219*795d594fSAndroid Build Coastguard Worker   std::vector<std::string> GetFrameworkBcpJars() const;
220*795d594fSAndroid Build Coastguard Worker 
221*795d594fSAndroid Build Coastguard Worker   // Returns the list of BCP jars for the boot image mainline extension.
222*795d594fSAndroid Build Coastguard Worker   std::vector<std::string> GetMainlineBcpJars() const;
223*795d594fSAndroid Build Coastguard Worker 
224*795d594fSAndroid Build Coastguard Worker   // Returns the symbolic primary boot image location (without ISA). If `minimal` is true, returns
225*795d594fSAndroid Build Coastguard Worker   // the symbolic location of the minimal boot image.
226*795d594fSAndroid Build Coastguard Worker   std::string GetPrimaryBootImage(bool on_system, bool minimal) const;
227*795d594fSAndroid Build Coastguard Worker 
228*795d594fSAndroid Build Coastguard Worker   // Returns the real primary boot image location (with ISA).  If `minimal` is true, returns the
229*795d594fSAndroid Build Coastguard Worker   // real location of the minimal boot image.
230*795d594fSAndroid Build Coastguard Worker   std::string GetPrimaryBootImagePath(bool on_system, bool minimal, InstructionSet isa) const;
231*795d594fSAndroid Build Coastguard Worker 
232*795d594fSAndroid Build Coastguard Worker   // Returns the symbolic boot image framework extension location (without ISA). Note that this only
233*795d594fSAndroid Build Coastguard Worker   // applies to boot images on /system.
234*795d594fSAndroid Build Coastguard Worker   std::string GetSystemBootImageFrameworkExtension() const;
235*795d594fSAndroid Build Coastguard Worker 
236*795d594fSAndroid Build Coastguard Worker   // Returns the real boot image framework extension location (with ISA). Note that this only
237*795d594fSAndroid Build Coastguard Worker   // applies to boot images on /system.
238*795d594fSAndroid Build Coastguard Worker   std::string GetSystemBootImageFrameworkExtensionPath(InstructionSet isa) const;
239*795d594fSAndroid Build Coastguard Worker 
240*795d594fSAndroid Build Coastguard Worker   // Returns the symbolic boot image mainline extension location (without ISA).
241*795d594fSAndroid Build Coastguard Worker   std::string GetBootImageMainlineExtension(bool on_system) const;
242*795d594fSAndroid Build Coastguard Worker 
243*795d594fSAndroid Build Coastguard Worker   // Returns the real boot image mainline extension location (with ISA).
244*795d594fSAndroid Build Coastguard Worker   std::string GetBootImageMainlineExtensionPath(bool on_system, InstructionSet isa) const;
245*795d594fSAndroid Build Coastguard Worker 
246*795d594fSAndroid Build Coastguard Worker   // Returns the best combination of symbolic boot image locations (without ISA) based on file
247*795d594fSAndroid Build Coastguard Worker   // existence.
248*795d594fSAndroid Build Coastguard Worker   std::vector<std::string> GetBestBootImages(InstructionSet isa,
249*795d594fSAndroid Build Coastguard Worker                                              bool include_mainline_extension) const;
250*795d594fSAndroid Build Coastguard Worker 
251*795d594fSAndroid Build Coastguard Worker   std::string GetSystemServerImagePath(bool on_system, const std::string& jar_path) const;
252*795d594fSAndroid Build Coastguard Worker 
253*795d594fSAndroid Build Coastguard Worker   // Removes files that are not in the list.
254*795d594fSAndroid Build Coastguard Worker   android::base::Result<void> CleanupArtifactDirectory(
255*795d594fSAndroid Build Coastguard Worker       OdrMetrics& metrics, const std::vector<std::string>& artifacts_to_keep) const;
256*795d594fSAndroid Build Coastguard Worker 
257*795d594fSAndroid Build Coastguard Worker   // Loads artifacts to memory and writes them back. This is a workaround for old versions of
258*795d594fSAndroid Build Coastguard Worker   // odsign, which encounters "file exists" error when it adds existing artifacts to fs-verity. This
259*795d594fSAndroid Build Coastguard Worker   // function essentially removes existing artifacts from fs-verity to avoid the error.
260*795d594fSAndroid Build Coastguard Worker   android::base::Result<void> RefreshExistingArtifacts() const;
261*795d594fSAndroid Build Coastguard Worker 
262*795d594fSAndroid Build Coastguard Worker   // Returns whether the primary boot image is present.
263*795d594fSAndroid Build Coastguard Worker   // If `on_system` is true, checks both the primary boot image and the framework extension on
264*795d594fSAndroid Build Coastguard Worker   // /system.
265*795d594fSAndroid Build Coastguard Worker   // If `minimal` is true, checks the minimal boot image.
266*795d594fSAndroid Build Coastguard Worker   // If `checked_artifacts` is present, adds checked artifacts to `checked_artifacts`.
267*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED bool PrimaryBootImageExist(
268*795d594fSAndroid Build Coastguard Worker       bool on_system,
269*795d594fSAndroid Build Coastguard Worker       bool minimal,
270*795d594fSAndroid Build Coastguard Worker       InstructionSet isa,
271*795d594fSAndroid Build Coastguard Worker       /*out*/ std::string* error_msg,
272*795d594fSAndroid Build Coastguard Worker       /*out*/ std::vector<std::string>* checked_artifacts = nullptr) const;
273*795d594fSAndroid Build Coastguard Worker 
274*795d594fSAndroid Build Coastguard Worker   // Returns whether the boot image mainline extension exists.
275*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED bool BootImageMainlineExtensionExist(
276*795d594fSAndroid Build Coastguard Worker       bool on_system,
277*795d594fSAndroid Build Coastguard Worker       InstructionSet isa,
278*795d594fSAndroid Build Coastguard Worker       /*out*/ std::string* error_msg,
279*795d594fSAndroid Build Coastguard Worker       /*out*/ std::vector<std::string>* checked_artifacts = nullptr) const;
280*795d594fSAndroid Build Coastguard Worker 
281*795d594fSAndroid Build Coastguard Worker   // Checks whether all system_server artifacts are present. The artifacts are checked in their
282*795d594fSAndroid Build Coastguard Worker   // order of compilation. Returns true if all are present, false otherwise.
283*795d594fSAndroid Build Coastguard Worker   // Adds the paths to the jars that are missing artifacts in `jars_with_missing_artifacts`.
284*795d594fSAndroid Build Coastguard Worker   // If `checked_artifacts` is present, adds checked artifacts to `checked_artifacts`.
285*795d594fSAndroid Build Coastguard Worker   bool SystemServerArtifactsExist(
286*795d594fSAndroid Build Coastguard Worker       bool on_system,
287*795d594fSAndroid Build Coastguard Worker       /*out*/ std::string* error_msg,
288*795d594fSAndroid Build Coastguard Worker       /*out*/ std::set<std::string>* jars_missing_artifacts,
289*795d594fSAndroid Build Coastguard Worker       /*out*/ std::vector<std::string>* checked_artifacts = nullptr) const;
290*795d594fSAndroid Build Coastguard Worker 
291*795d594fSAndroid Build Coastguard Worker   // Returns true if all of the system properties listed in `kSystemProperties` are set to the
292*795d594fSAndroid Build Coastguard Worker   // default values. This function is usually called when cache-info.xml does not exist (i.e.,
293*795d594fSAndroid Build Coastguard Worker   // compilation has not been done before).
294*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED bool CheckSystemPropertiesAreDefault() const;
295*795d594fSAndroid Build Coastguard Worker 
296*795d594fSAndroid Build Coastguard Worker   // Returns true if none of the system properties listed in `kSystemProperties` has changed since
297*795d594fSAndroid Build Coastguard Worker   // the last compilation. This function is usually called when cache-info.xml exists.
298*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED bool CheckSystemPropertiesHaveNotChanged(
299*795d594fSAndroid Build Coastguard Worker       const com::android::art::CacheInfo& cache_info) const;
300*795d594fSAndroid Build Coastguard Worker 
301*795d594fSAndroid Build Coastguard Worker   // Returns true if the system image is built with the right userfaultfd GC flag.
302*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED bool CheckBuildUserfaultFdGc() const;
303*795d594fSAndroid Build Coastguard Worker 
304*795d594fSAndroid Build Coastguard Worker   // Returns whether the precondition for using artifacts on /system is met. Note that this function
305*795d594fSAndroid Build Coastguard Worker   // does not check the artifacts.
306*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED PreconditionCheckResult
307*795d594fSAndroid Build Coastguard Worker   CheckPreconditionForSystem(const std::vector<com::android::apex::ApexInfo>& apex_info_list) const;
308*795d594fSAndroid Build Coastguard Worker 
309*795d594fSAndroid Build Coastguard Worker   // Returns whether the precondition for using artifacts on /data is met. Note that this function
310*795d594fSAndroid Build Coastguard Worker   // does not check the artifacts.
311*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED PreconditionCheckResult
312*795d594fSAndroid Build Coastguard Worker   CheckPreconditionForData(const std::vector<com::android::apex::ApexInfo>& apex_info_list) const;
313*795d594fSAndroid Build Coastguard Worker 
314*795d594fSAndroid Build Coastguard Worker   // Checks whether all boot classpath artifacts are up to date. Returns the boot images that need
315*795d594fSAndroid Build Coastguard Worker   // to be (re-)generated. If `checked_artifacts` is present, adds checked artifacts to
316*795d594fSAndroid Build Coastguard Worker   // `checked_artifacts`.
317*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED BootImages
318*795d594fSAndroid Build Coastguard Worker   CheckBootClasspathArtifactsAreUpToDate(OdrMetrics& metrics,
319*795d594fSAndroid Build Coastguard Worker                                          InstructionSet isa,
320*795d594fSAndroid Build Coastguard Worker                                          const PreconditionCheckResult& system_result,
321*795d594fSAndroid Build Coastguard Worker                                          const PreconditionCheckResult& data_result,
322*795d594fSAndroid Build Coastguard Worker                                          /*out*/ std::vector<std::string>* checked_artifacts) const;
323*795d594fSAndroid Build Coastguard Worker 
324*795d594fSAndroid Build Coastguard Worker   // Checks whether all system_server artifacts are up to date. The artifacts are checked in their
325*795d594fSAndroid Build Coastguard Worker   // order of compilation. Returns the paths to the jars that need to be compiled.
326*795d594fSAndroid Build Coastguard Worker   // If `checked_artifacts` is present, adds checked artifacts to `checked_artifacts`.
327*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED std::set<std::string> CheckSystemServerArtifactsAreUpToDate(
328*795d594fSAndroid Build Coastguard Worker       OdrMetrics& metrics,
329*795d594fSAndroid Build Coastguard Worker       const PreconditionCheckResult& system_result,
330*795d594fSAndroid Build Coastguard Worker       const PreconditionCheckResult& data_result,
331*795d594fSAndroid Build Coastguard Worker       /*out*/ std::vector<std::string>* checked_artifacts) const;
332*795d594fSAndroid Build Coastguard Worker 
333*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED CompilationResult
334*795d594fSAndroid Build Coastguard Worker   RunDex2oat(const std::string& staging_dir,
335*795d594fSAndroid Build Coastguard Worker              const std::string& debug_message,
336*795d594fSAndroid Build Coastguard Worker              InstructionSet isa,
337*795d594fSAndroid Build Coastguard Worker              const std::vector<std::string>& dex_files,
338*795d594fSAndroid Build Coastguard Worker              const std::vector<std::string>& boot_classpath,
339*795d594fSAndroid Build Coastguard Worker              const std::vector<std::string>& input_boot_images,
340*795d594fSAndroid Build Coastguard Worker              const OdrArtifacts& artifacts,
341*795d594fSAndroid Build Coastguard Worker              tools::CmdlineBuilder&& extra_args,
342*795d594fSAndroid Build Coastguard Worker              /*inout*/ std::vector<std::unique_ptr<File>>& readonly_files_raii) const;
343*795d594fSAndroid Build Coastguard Worker 
344*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED CompilationResult
345*795d594fSAndroid Build Coastguard Worker   RunDex2oatForBootClasspath(const std::string& staging_dir,
346*795d594fSAndroid Build Coastguard Worker                              const std::string& debug_name,
347*795d594fSAndroid Build Coastguard Worker                              InstructionSet isa,
348*795d594fSAndroid Build Coastguard Worker                              const std::vector<std::string>& dex_files,
349*795d594fSAndroid Build Coastguard Worker                              const std::vector<std::string>& boot_classpath,
350*795d594fSAndroid Build Coastguard Worker                              const std::vector<std::string>& input_boot_images,
351*795d594fSAndroid Build Coastguard Worker                              const std::string& output_path) const;
352*795d594fSAndroid Build Coastguard Worker 
353*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED CompilationResult
354*795d594fSAndroid Build Coastguard Worker   CompileBootClasspath(const std::string& staging_dir,
355*795d594fSAndroid Build Coastguard Worker                        InstructionSet isa,
356*795d594fSAndroid Build Coastguard Worker                        BootImages boot_images,
357*795d594fSAndroid Build Coastguard Worker                        const std::function<void()>& on_dex2oat_success) const;
358*795d594fSAndroid Build Coastguard Worker 
359*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED CompilationResult
360*795d594fSAndroid Build Coastguard Worker   RunDex2oatForSystemServer(const std::string& staging_dir,
361*795d594fSAndroid Build Coastguard Worker                             const std::string& dex_file,
362*795d594fSAndroid Build Coastguard Worker                             const std::vector<std::string>& classloader_context) const;
363*795d594fSAndroid Build Coastguard Worker 
364*795d594fSAndroid Build Coastguard Worker   WARN_UNUSED CompilationResult
365*795d594fSAndroid Build Coastguard Worker   CompileSystemServer(const std::string& staging_dir,
366*795d594fSAndroid Build Coastguard Worker                       const std::set<std::string>& system_server_jars_to_compile,
367*795d594fSAndroid Build Coastguard Worker                       const std::function<void()>& on_dex2oat_success) const;
368*795d594fSAndroid Build Coastguard Worker 
369*795d594fSAndroid Build Coastguard Worker   // Configuration to use.
370*795d594fSAndroid Build Coastguard Worker   const OdrConfig& config_;
371*795d594fSAndroid Build Coastguard Worker 
372*795d594fSAndroid Build Coastguard Worker   // Path to cache information file that is used to speed up artifact checking.
373*795d594fSAndroid Build Coastguard Worker   const std::string cache_info_filename_;
374*795d594fSAndroid Build Coastguard Worker 
375*795d594fSAndroid Build Coastguard Worker   // The raw list from DEX2OATBOOTCLASSPATH. This is the list of jars that should be compiled into
376*795d594fSAndroid Build Coastguard Worker   // the primary boot image.
377*795d594fSAndroid Build Coastguard Worker   std::vector<std::string> dex2oat_boot_classpath_jars_;
378*795d594fSAndroid Build Coastguard Worker 
379*795d594fSAndroid Build Coastguard Worker   // The raw list from BOOTCLASSPATH. This is the list of all BCP jars.
380*795d594fSAndroid Build Coastguard Worker   std::vector<std::string> boot_classpath_jars_;
381*795d594fSAndroid Build Coastguard Worker 
382*795d594fSAndroid Build Coastguard Worker   // Set of system_server components in SYSTEMSERVERCLASSPATH that should be compiled.
383*795d594fSAndroid Build Coastguard Worker   std::unordered_set<std::string> systemserver_classpath_jars_;
384*795d594fSAndroid Build Coastguard Worker 
385*795d594fSAndroid Build Coastguard Worker   // List of all system_server components, including those in SYSTEMSERVERCLASSPATH and those in
386*795d594fSAndroid Build Coastguard Worker   // STANDALONE_SYSTEMSERVER_JARS (jars that system_server loads dynamically using separate
387*795d594fSAndroid Build Coastguard Worker   // classloaders).
388*795d594fSAndroid Build Coastguard Worker   std::vector<std::string> all_systemserver_jars_;
389*795d594fSAndroid Build Coastguard Worker 
390*795d594fSAndroid Build Coastguard Worker   const time_t start_time_;
391*795d594fSAndroid Build Coastguard Worker 
392*795d594fSAndroid Build Coastguard Worker   std::unique_ptr<ExecUtils> exec_utils_;
393*795d594fSAndroid Build Coastguard Worker 
394*795d594fSAndroid Build Coastguard Worker   android::base::function_ref<bool()> check_compilation_space_;
395*795d594fSAndroid Build Coastguard Worker   android::base::function_ref<int(const char*, const char*)> setfilecon_;
396*795d594fSAndroid Build Coastguard Worker   android::base::function_ref<int(const char*, unsigned int)> restorecon_;
397*795d594fSAndroid Build Coastguard Worker 
398*795d594fSAndroid Build Coastguard Worker   DISALLOW_COPY_AND_ASSIGN(OnDeviceRefresh);
399*795d594fSAndroid Build Coastguard Worker };
400*795d594fSAndroid Build Coastguard Worker 
401*795d594fSAndroid Build Coastguard Worker }  // namespace odrefresh
402*795d594fSAndroid Build Coastguard Worker }  // namespace art
403*795d594fSAndroid Build Coastguard Worker 
404*795d594fSAndroid Build Coastguard Worker #endif  // ART_ODREFRESH_ODREFRESH_H_
405