Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 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 | |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 28 | class UniqueFile; |
| 29 | |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 30 | class RunDex2Oat { |
| 31 | public: |
| 32 | explicit RunDex2Oat(const char* dex2oat_bin, ExecVHelper* execv_helper); |
| 33 | virtual ~RunDex2Oat(); |
| 34 | |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 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, |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 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, |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 50 | int target_sdk_version, |
| 51 | bool enable_hidden_api_checks, |
| 52 | bool generate_compact_dex, |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 53 | bool use_jitzygote_image, |
| 54 | const char* compilation_reason); |
| 55 | |
| 56 | void Exec(int exit_code); |
| 57 | |
| 58 | protected: |
Nicolas Geoffray | a69482e | 2021-03-29 10:53:55 +0100 | [diff] [blame] | 59 | void PrepareBootImageFlags(bool use_jitzygote_image); |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 60 | void PrepareInputFileFlags(const UniqueFile& output_oat, |
| 61 | const UniqueFile& output_vdex, |
| 62 | const UniqueFile& output_image, |
| 63 | const UniqueFile& input_dex, |
| 64 | const UniqueFile& input_vdex, |
| 65 | const UniqueFile& dex_metadata, |
| 66 | const UniqueFile& profile, |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 67 | int swap_fd, |
| 68 | const char* class_loader_context, |
| 69 | const std::string& class_loader_context_fds); |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 70 | void PrepareCompilerConfigFlags(const UniqueFile& input_vdex, |
| 71 | const UniqueFile& output_vdex, |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 72 | const char* instruction_set, |
| 73 | const char* compiler_filter, |
| 74 | bool debuggable, |
| 75 | int target_sdk_version, |
| 76 | bool enable_hidden_api_checks, |
| 77 | bool generate_compact_dex, |
| 78 | const char* compilation_reason); |
| 79 | void PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete, bool for_restore); |
| 80 | |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 81 | virtual std::string GetProperty(const std::string& key, const std::string& default_value); |
| 82 | virtual bool GetBoolProperty(const std::string& key, bool default_value); |
| 83 | |
| 84 | private: |
| 85 | void AddArg(const std::string& arg); |
| 86 | void AddRuntimeArg(const std::string& arg); |
| 87 | |
| 88 | std::string MapPropertyToArg(const std::string& property, |
| 89 | const std::string& format, |
| 90 | const std::string& default_value = ""); |
| 91 | |
| 92 | std::string MapPropertyToArgWithBackup(const std::string& property, |
| 93 | const std::string& backupProperty, |
| 94 | const std::string& format, |
| 95 | const std::string& default_value = ""); |
| 96 | |
| 97 | const std::string dex2oat_bin_; |
| 98 | ExecVHelper* execv_helper_; // not owned |
| 99 | }; |
| 100 | |
| 101 | } // namespace installd |
| 102 | } // namespace android |
| 103 | |
| 104 | #endif // ANDROID_INSTALLD_RUN_DEX2OAT_H |