blob: c13e1f1acb9a18343d42cd977f2fee3f55af5f2f [file] [log] [blame]
Victor Hsiehc9821f12020-08-07 11:32:29 -07001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
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 ANDROID_INSTALLD_RUN_DEX2OAT_H
18#define ANDROID_INSTALLD_RUN_DEX2OAT_H
19
20#include <memory>
21#include <string>
22
23#include "execv_helper.h"
24
25namespace android {
26namespace installd {
27
Victor Hsiehcb35a062020-08-13 16:11:13 -070028class UniqueFile;
29
Victor Hsiehc9821f12020-08-07 11:32:29 -070030class RunDex2Oat {
31 public:
32 explicit RunDex2Oat(const char* dex2oat_bin, ExecVHelper* execv_helper);
33 virtual ~RunDex2Oat();
34
Victor Hsiehcb35a062020-08-13 16:11:13 -070035 void Initialize(const UniqueFile& output_oat,
36 const UniqueFile& output_vdex,
37 const UniqueFile& output_image,
38 const UniqueFile& input_dex,
39 const UniqueFile& input_vdex,
40 const UniqueFile& dex_metadata,
41 const UniqueFile& profile,
42 const char* class_loader_context,
43 const std::string& class_loader_context_fds,
Victor Hsiehc9821f12020-08-07 11:32:29 -070044 int swap_fd,
45 const char* instruction_set,
46 const char* compiler_filter,
47 bool debuggable,
48 bool post_bootcomplete,
49 bool for_restore,
Victor Hsiehc9821f12020-08-07 11:32:29 -070050 int target_sdk_version,
51 bool enable_hidden_api_checks,
52 bool generate_compact_dex,
Jiakai Zhang202524b2021-12-22 16:40:52 +000053 bool use_jitzygote,
Martin Stjernholm02570a72022-11-01 13:56:46 +000054 bool background_job_compile,
Victor Hsiehc9821f12020-08-07 11:32:29 -070055 const char* compilation_reason);
56
57 void Exec(int exit_code);
58
59 protected:
Jiakai Zhang202524b2021-12-22 16:40:52 +000060 void PrepareBootImageFlags(bool use_jitzygote);
Victor Hsiehcb35a062020-08-13 16:11:13 -070061 void PrepareInputFileFlags(const UniqueFile& output_oat,
62 const UniqueFile& output_vdex,
63 const UniqueFile& output_image,
64 const UniqueFile& input_dex,
65 const UniqueFile& input_vdex,
66 const UniqueFile& dex_metadata,
67 const UniqueFile& profile,
Victor Hsiehb3459402020-07-07 12:34:54 -070068 int swap_fd,
69 const char* class_loader_context,
70 const std::string& class_loader_context_fds);
Victor Hsiehcb35a062020-08-13 16:11:13 -070071 void PrepareCompilerConfigFlags(const UniqueFile& input_vdex,
72 const UniqueFile& output_vdex,
Victor Hsiehb3459402020-07-07 12:34:54 -070073 const char* instruction_set,
74 const char* compiler_filter,
75 bool debuggable,
76 int target_sdk_version,
77 bool enable_hidden_api_checks,
78 bool generate_compact_dex,
79 const char* compilation_reason);
Martin Stjernholm02570a72022-11-01 13:56:46 +000080 void PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete,
81 bool for_restore,
82 bool background_job_compile);
Victor Hsiehb3459402020-07-07 12:34:54 -070083
Victor Hsiehc9821f12020-08-07 11:32:29 -070084 virtual std::string GetProperty(const std::string& key, const std::string& default_value);
85 virtual bool GetBoolProperty(const std::string& key, bool default_value);
86
87 private:
88 void AddArg(const std::string& arg);
89 void AddRuntimeArg(const std::string& arg);
90
91 std::string MapPropertyToArg(const std::string& property,
92 const std::string& format,
93 const std::string& default_value = "");
94
95 std::string MapPropertyToArgWithBackup(const std::string& property,
96 const std::string& backupProperty,
97 const std::string& format,
98 const std::string& default_value = "");
99
100 const std::string dex2oat_bin_;
101 ExecVHelper* execv_helper_; // not owned
102};
103
104} // namespace installd
105} // namespace android
106
107#endif // ANDROID_INSTALLD_RUN_DEX2OAT_H