• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
25 namespace android {
26 namespace installd {
27 
28 class UniqueFile;
29 
30 class RunDex2Oat {
31   public:
32     explicit RunDex2Oat(const char* dex2oat_bin, ExecVHelper* execv_helper);
33     virtual ~RunDex2Oat();
34 
35     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,
44                     int swap_fd,
45                     const char* instruction_set,
46                     const char* compiler_filter,
47                     bool debuggable,
48                     bool post_bootcomplete,
49                     bool for_restore,
50                     int target_sdk_version,
51                     bool enable_hidden_api_checks,
52                     bool generate_compact_dex,
53                     bool use_jitzygote,
54                     bool background_job_compile,
55                     const char* compilation_reason);
56 
57     void Exec(int exit_code);
58 
59   protected:
60     void PrepareBootImageFlags(bool use_jitzygote);
61     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,
68                                int swap_fd,
69                                const char* class_loader_context,
70                                const std::string& class_loader_context_fds);
71     void PrepareCompilerConfigFlags(const UniqueFile& input_vdex,
72                                     const UniqueFile& output_vdex,
73                                     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);
80     void PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete,
81                                                   bool for_restore,
82                                                   bool background_job_compile);
83 
84     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
108