blob: 6022b9523e20f8e7895a8ea69d472aa070537ba3 [file] [log] [blame]
Jiakai Zhang3ba3edf2021-08-11 08:25:40 +00001/*
Jiakai Zhangb91dad22021-08-16 03:20:07 +00002 * Copyright (C) 2021 The Android Open Source Project
Jiakai Zhang3ba3edf2021-08-11 08:25:40 +00003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_ODREFRESH_ODREFRESH_H_
18#define ART_ODREFRESH_ODREFRESH_H_
19
20#include <ctime>
Jiakai Zhangb91dad22021-08-16 03:20:07 +000021#include <memory>
Jiakai Zhang3ba3edf2021-08-11 08:25:40 +000022#include <optional>
23#include <string>
24#include <vector>
25
26#include "com_android_apex.h"
27#include "com_android_art.h"
Jiakai Zhangb91dad22021-08-16 03:20:07 +000028#include "exec_utils.h"
Jiakai Zhang3ba3edf2021-08-11 08:25:40 +000029#include "odr_artifacts.h"
30#include "odr_config.h"
31#include "odr_metrics.h"
32#include "odrefresh/odrefresh.h"
33
34namespace art {
35namespace odrefresh {
36
37class OnDeviceRefresh final {
38 public:
39 explicit OnDeviceRefresh(const OdrConfig& config);
40
Jiakai Zhangb91dad22021-08-16 03:20:07 +000041 // Constructor with injections. For testing and internal use only.
42 OnDeviceRefresh(const OdrConfig& config,
43 const std::string& cache_info_filename,
44 std::unique_ptr<ExecUtils> exec_utils);
45
Jiakai Zhang3ba3edf2021-08-11 08:25:40 +000046 // Returns the exit code, a list of ISAs that boot extensions should be compiled for, and a
47 // boolean indicating whether the system server should be compiled.
48 WARN_UNUSED ExitCode
49 CheckArtifactsAreUpToDate(OdrMetrics& metrics,
50 /*out*/ std::vector<InstructionSet>* compile_boot_extensions,
51 /*out*/ bool* compile_system_server) const;
52
53 WARN_UNUSED ExitCode Compile(OdrMetrics& metrics,
54 const std::vector<InstructionSet>& compile_boot_extensions,
55 bool compile_system_server) const;
56
57 // Verify all artifacts are up-to-date.
58 //
59 // This method checks artifacts can be loaded by the runtime.
60 //
61 // Returns ExitCode::kOkay if artifacts are up-to-date, ExitCode::kCompilationRequired
62 // otherwise.
63 //
64 // NB This is the main function used by the --verify command-line option.
65 WARN_UNUSED ExitCode VerifyArtifactsAreUpToDate() const;
66
67 WARN_UNUSED bool RemoveArtifactsDirectory() const;
68
69 private:
70 time_t GetExecutionTimeUsed() const;
71
72 time_t GetExecutionTimeRemaining() const;
73
74 time_t GetSubprocessTimeout() const;
75
76 // Gets the `ApexInfo` for active APEXes.
77 std::optional<std::vector<com::android::apex::ApexInfo>> GetApexInfoList() const;
78
79 // Reads the ART APEX cache information (if any) found in `kOdrefreshArtifactDirectory`.
80 std::optional<com::android::art::CacheInfo> ReadCacheInfo() const;
81
82 // Write ART APEX cache information to `kOnDeviceRefreshOdrefreshArtifactDirectory`.
83 void WriteCacheInfo() const;
84
85 void ReportNextBootAnimationProgress(uint32_t current_compilation) const;
86
87 std::vector<com::android::art::Component> GenerateBootClasspathComponents() const;
88
89 std::vector<com::android::art::Component> GenerateBootExtensionCompilableComponents() const;
90
91 std::vector<com::android::art::Component> GenerateSystemServerComponents() const;
92
93 std::string GetBootImageExtensionImage(bool on_system) const;
94
95 std::string GetBootImageExtensionImagePath(bool on_system, const InstructionSet isa) const;
96
97 std::string GetSystemServerImagePath(bool on_system, const std::string& jar_path) const;
98
99 WARN_UNUSED bool RemoveSystemServerArtifactsFromData() const;
100
101 // Remove boot extension artifacts from /data.
102 WARN_UNUSED bool RemoveBootExtensionArtifactsFromData(InstructionSet isa) const;
103
104 WARN_UNUSED bool RemoveArtifacts(const OdrArtifacts& artifacts) const;
105
106 // Checks whether all boot extension artifacts are present. Returns true if all are present, false
107 // otherwise.
108 WARN_UNUSED bool BootExtensionArtifactsExist(bool on_system,
109 const InstructionSet isa,
110 /*out*/ std::string* error_msg) const;
111
112 // Checks whether all system_server artifacts are present. The artifacts are checked in their
113 // order of compilation. Returns true if all are present, false otherwise.
114 WARN_UNUSED bool SystemServerArtifactsExist(bool on_system,
115 /*out*/ std::string* error_msg) const;
116
117 WARN_UNUSED bool CheckBootExtensionArtifactsAreUpToDate(
118 OdrMetrics& metrics,
119 const InstructionSet isa,
120 const com::android::apex::ApexInfo& art_apex_info,
121 const std::optional<com::android::art::CacheInfo>& cache_info,
122 /*out*/ bool* cleanup_required) const;
123
124 WARN_UNUSED bool CheckSystemServerArtifactsAreUpToDate(
125 OdrMetrics& metrics,
126 const std::vector<com::android::apex::ApexInfo>& apex_info_list,
127 const std::optional<com::android::art::CacheInfo>& cache_info,
128 /*out*/ bool* cleanup_required) const;
129
130 // Check the validity of boot class path extension artifacts.
131 //
132 // Returns true if artifacts exist and are valid according to dexoptanalyzer.
133 WARN_UNUSED bool VerifyBootExtensionArtifactsAreUpToDate(const InstructionSet isa,
134 bool on_system) const;
135
136 // Verify whether boot extension artifacts for `isa` are valid on system partition or in
137 // apexdata. This method has the side-effect of removing boot classpath extension artifacts on
138 // /data, if there are valid artifacts on /system, or if the artifacts on /data are not valid.
139 // Returns true if valid boot externsion artifacts are valid.
140 WARN_UNUSED bool VerifyBootExtensionArtifactsAreUpToDate(InstructionSet isa) const;
141
142 WARN_UNUSED bool VerifySystemServerArtifactsAreUpToDate(bool on_system) const;
143
144 // Verify the validity of system server artifacts on both /system and /data.
145 // This method has the side-effect of removing system server artifacts on /data, if there are
146 // valid artifacts on /system, or if the artifacts on /data are not valid.
147 // Returns true if valid artifacts are found.
148 WARN_UNUSED bool VerifySystemServerArtifactsAreUpToDate() const;
149
150 WARN_UNUSED bool CompileBootExtensionArtifacts(const InstructionSet isa,
151 const std::string& staging_dir,
152 OdrMetrics& metrics,
153 uint32_t* dex2oat_invocation_count,
154 std::string* error_msg) const;
155
156 WARN_UNUSED bool CompileSystemServerArtifacts(const std::string& staging_dir,
157 OdrMetrics& metrics,
158 uint32_t* dex2oat_invocation_count,
159 std::string* error_msg) const;
160
161 // Configuration to use.
162 const OdrConfig& config_;
163
164 // Path to cache information file that is used to speed up artifact checking.
165 const std::string cache_info_filename_;
166
167 // List of boot extension components that should be compiled.
168 std::vector<std::string> boot_extension_compilable_jars_;
169
170 // List of system_server components that should be compiled.
171 std::vector<std::string> systemserver_compilable_jars_;
172
173 // List of all boot classpath components. Used as the dependencies for compiling the
174 // system_server.
175 std::vector<std::string> boot_classpath_jars_;
176
177 const time_t start_time_;
178
Jiakai Zhangb91dad22021-08-16 03:20:07 +0000179 std::unique_ptr<ExecUtils> exec_utils_;
180
Jiakai Zhang3ba3edf2021-08-11 08:25:40 +0000181 DISALLOW_COPY_AND_ASSIGN(OnDeviceRefresh);
182};
183
184} // namespace odrefresh
185} // namespace art
186
187#endif // ART_ODREFRESH_ODREFRESH_H_