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 | #define LOG_TAG "installd" |
| 17 | |
| 18 | #include "run_dex2oat.h" |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <android-base/file.h> |
| 25 | #include <android-base/logging.h> |
| 26 | #include <android-base/properties.h> |
| 27 | #include <android-base/scopeguard.h> |
| 28 | #include <android-base/stringprintf.h> |
| 29 | #include <android-base/strings.h> |
| 30 | #include <log/log.h> |
| 31 | #include <server_configurable_flags/get_flags.h> |
| 32 | |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 33 | #include "unique_file.h" |
| 34 | |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 35 | using android::base::Basename; |
| 36 | using android::base::StringPrintf; |
| 37 | |
| 38 | namespace android { |
| 39 | namespace installd { |
| 40 | |
| 41 | namespace { |
| 42 | |
| 43 | // Should minidebug info be included in compiled artifacts? Even if this value is |
| 44 | // "true," usage might still be conditional to other constraints, e.g., system |
| 45 | // property overrides. |
| 46 | static constexpr bool kEnableMinidebugInfo = true; |
| 47 | |
| 48 | static constexpr const char* kMinidebugInfoSystemProperty = "dalvik.vm.dex2oat-minidebuginfo"; |
| 49 | static constexpr bool kMinidebugInfoSystemPropertyDefault = false; |
| 50 | static constexpr const char* kMinidebugDex2oatFlag = "--generate-mini-debug-info"; |
| 51 | static constexpr const char* kDisableCompactDexFlag = "--compact-dex-level=none"; |
| 52 | |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 53 | std::vector<std::string> SplitBySpaces(const std::string& str) { |
| 54 | if (str.empty()) { |
| 55 | return {}; |
| 56 | } |
| 57 | return android::base::Split(str, " "); |
| 58 | } |
| 59 | |
| 60 | } // namespace |
| 61 | |
| 62 | RunDex2Oat::RunDex2Oat(const char* dex2oat_bin, ExecVHelper* execv_helper) |
| 63 | : dex2oat_bin_(dex2oat_bin), execv_helper_(execv_helper) {} |
| 64 | |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 65 | void RunDex2Oat::Initialize(const UniqueFile& output_oat, |
| 66 | const UniqueFile& output_vdex, |
| 67 | const UniqueFile& output_image, |
| 68 | const UniqueFile& input_dex, |
| 69 | const UniqueFile& input_vdex, |
| 70 | const UniqueFile& dex_metadata, |
| 71 | const UniqueFile& profile, |
| 72 | const char* class_loader_context, |
| 73 | const std::string& class_loader_context_fds, |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 74 | int swap_fd, |
| 75 | const char* instruction_set, |
| 76 | const char* compiler_filter, |
| 77 | bool debuggable, |
| 78 | bool post_bootcomplete, |
| 79 | bool for_restore, |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 80 | int target_sdk_version, |
| 81 | bool enable_hidden_api_checks, |
| 82 | bool generate_compact_dex, |
Jiakai Zhang | 202524b | 2021-12-22 16:40:52 +0000 | [diff] [blame] | 83 | bool use_jitzygote, |
Martin Stjernholm | 02570a7 | 2022-11-01 13:56:46 +0000 | [diff] [blame^] | 84 | bool background_job_compile, |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 85 | const char* compilation_reason) { |
Jiakai Zhang | 202524b | 2021-12-22 16:40:52 +0000 | [diff] [blame] | 86 | PrepareBootImageFlags(use_jitzygote); |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 87 | |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 88 | PrepareInputFileFlags(output_oat, output_vdex, output_image, input_dex, input_vdex, |
| 89 | dex_metadata, profile, swap_fd, class_loader_context, |
| 90 | class_loader_context_fds); |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 91 | |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 92 | PrepareCompilerConfigFlags(input_vdex, output_vdex, instruction_set, compiler_filter, |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 93 | debuggable, target_sdk_version, enable_hidden_api_checks, |
| 94 | generate_compact_dex, compilation_reason); |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 95 | |
Martin Stjernholm | 02570a7 | 2022-11-01 13:56:46 +0000 | [diff] [blame^] | 96 | PrepareCompilerRuntimeAndPerfConfigFlags(post_bootcomplete, for_restore, |
| 97 | background_job_compile); |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 98 | |
| 99 | const std::string dex2oat_flags = GetProperty("dalvik.vm.dex2oat-flags", ""); |
| 100 | std::vector<std::string> dex2oat_flags_args = SplitBySpaces(dex2oat_flags); |
| 101 | ALOGV("dalvik.vm.dex2oat-flags=%s\n", dex2oat_flags.c_str()); |
| 102 | |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 103 | // Do not add args after dex2oat_flags, they should override others for debugging. |
| 104 | for (auto it = dex2oat_flags_args.begin(); it != dex2oat_flags_args.end(); ++it) { |
| 105 | AddArg(*it); |
| 106 | } |
| 107 | |
| 108 | execv_helper_->PrepareArgs(dex2oat_bin_); |
| 109 | } |
| 110 | |
| 111 | RunDex2Oat::~RunDex2Oat() {} |
| 112 | |
Jiakai Zhang | 202524b | 2021-12-22 16:40:52 +0000 | [diff] [blame] | 113 | void RunDex2Oat::PrepareBootImageFlags(bool use_jitzygote) { |
| 114 | if (use_jitzygote) { |
| 115 | // Don't pass a boot image because JIT Zygote should decide which image to use. Typically, |
| 116 | // it does not use any boot image on disk. |
| 117 | AddArg("--force-jit-zygote"); |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 118 | } else { |
Jiakai Zhang | 202524b | 2021-12-22 16:40:52 +0000 | [diff] [blame] | 119 | AddArg(MapPropertyToArg("dalvik.vm.boot-image", "--boot-image=%s")); |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 120 | } |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 123 | void RunDex2Oat::PrepareInputFileFlags(const UniqueFile& output_oat, |
| 124 | const UniqueFile& output_vdex, |
| 125 | const UniqueFile& output_image, |
| 126 | const UniqueFile& input_dex, |
| 127 | const UniqueFile& input_vdex, |
| 128 | const UniqueFile& dex_metadata, |
| 129 | const UniqueFile& profile, |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 130 | int swap_fd, |
| 131 | const char* class_loader_context, |
| 132 | const std::string& class_loader_context_fds) { |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 133 | std::string input_basename = Basename(input_dex.path()); |
| 134 | LOG(VERBOSE) << "Running " << dex2oat_bin_ << " in=" << input_basename << " out=" |
| 135 | << output_oat.path(); |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 136 | |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 137 | AddArg(StringPrintf("--zip-fd=%d", input_dex.fd())); |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 138 | AddArg(StringPrintf("--zip-location=%s", input_basename.c_str())); |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 139 | AddArg(StringPrintf("--oat-fd=%d", output_oat.fd())); |
| 140 | AddArg(StringPrintf("--oat-location=%s", output_oat.path().c_str())); |
| 141 | AddArg(StringPrintf("--input-vdex-fd=%d", input_vdex.fd())); |
| 142 | AddArg(StringPrintf("--output-vdex-fd=%d", output_vdex.fd())); |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 143 | |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 144 | if (output_image.fd() >= 0) { |
| 145 | AddArg(StringPrintf("--app-image-fd=%d", output_image.fd())); |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 146 | AddArg(MapPropertyToArg("dalvik.vm.appimageformat", "--image-format=%s")); |
| 147 | } |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 148 | if (dex_metadata.fd() > -1) { |
| 149 | AddArg("--dm-fd=" + std::to_string(dex_metadata.fd())); |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 150 | } |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 151 | if (profile.fd() != -1) { |
| 152 | AddArg(StringPrintf("--profile-file-fd=%d", profile.fd())); |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 153 | } |
| 154 | if (swap_fd >= 0) { |
| 155 | AddArg(StringPrintf("--swap-fd=%d", swap_fd)); |
| 156 | } |
| 157 | |
| 158 | // Get the directory of the apk to pass as a base classpath directory. |
| 159 | { |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 160 | std::string apk_dir(input_dex.path()); |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 161 | size_t dir_index = apk_dir.rfind('/'); |
| 162 | if (dir_index != std::string::npos) { |
| 163 | apk_dir = apk_dir.substr(0, dir_index); |
| 164 | AddArg(StringPrintf("--classpath-dir=%s", apk_dir.c_str())); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if (class_loader_context != nullptr) { |
| 169 | AddArg(StringPrintf("--class-loader-context=%s", class_loader_context)); |
| 170 | if (!class_loader_context_fds.empty()) { |
| 171 | AddArg(StringPrintf("--class-loader-context-fds=%s", |
| 172 | class_loader_context_fds.c_str())); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 177 | void RunDex2Oat::PrepareCompilerConfigFlags(const UniqueFile& input_vdex, |
| 178 | const UniqueFile& output_vdex, |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 179 | const char* instruction_set, |
| 180 | const char* compiler_filter, |
| 181 | bool debuggable, |
| 182 | int target_sdk_version, |
| 183 | bool enable_hidden_api_checks, |
| 184 | bool generate_compact_dex, |
| 185 | const char* compilation_reason) { |
| 186 | // Disable cdex if update input vdex is true since this combination of options is not |
| 187 | // supported. |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 188 | const bool disable_cdex = !generate_compact_dex || (input_vdex.fd() == output_vdex.fd()); |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 189 | if (disable_cdex) { |
| 190 | AddArg(kDisableCompactDexFlag); |
| 191 | } |
Victor Hsieh | cb35a06 | 2020-08-13 16:11:13 -0700 | [diff] [blame] | 192 | |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 193 | // ISA related |
| 194 | { |
| 195 | AddArg(StringPrintf("--instruction-set=%s", instruction_set)); |
| 196 | |
| 197 | const std::string dex2oat_isa_features_key = |
| 198 | StringPrintf("dalvik.vm.isa.%s.features", instruction_set); |
| 199 | std::string instruction_set_features_arg = |
| 200 | MapPropertyToArg(dex2oat_isa_features_key, "--instruction-set-features=%s"); |
| 201 | AddArg(instruction_set_features_arg); |
| 202 | |
| 203 | const std::string dex2oat_isa_variant_key = |
| 204 | StringPrintf("dalvik.vm.isa.%s.variant", instruction_set); |
| 205 | std::string instruction_set_variant_arg = |
| 206 | MapPropertyToArg(dex2oat_isa_variant_key, "--instruction-set-variant=%s"); |
| 207 | AddArg(instruction_set_variant_arg); |
| 208 | } |
| 209 | |
| 210 | // Compute compiler filter. |
| 211 | { |
| 212 | std::string dex2oat_compiler_filter_arg; |
| 213 | { |
| 214 | // If we are booting without the real /data, don't spend time compiling. |
| 215 | std::string vold_decrypt = GetProperty("vold.decrypt", ""); |
| 216 | bool skip_compilation = vold_decrypt == "trigger_restart_min_framework" || |
| 217 | vold_decrypt == "1"; |
| 218 | |
| 219 | bool have_dex2oat_relocation_skip_flag = false; |
| 220 | if (skip_compilation) { |
| 221 | dex2oat_compiler_filter_arg = "--compiler-filter=extract"; |
| 222 | have_dex2oat_relocation_skip_flag = true; |
| 223 | } else if (compiler_filter != nullptr) { |
| 224 | dex2oat_compiler_filter_arg = StringPrintf("--compiler-filter=%s", |
| 225 | compiler_filter); |
| 226 | } |
| 227 | if (have_dex2oat_relocation_skip_flag) { |
| 228 | AddRuntimeArg("-Xnorelocate"); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | if (dex2oat_compiler_filter_arg.empty()) { |
| 233 | dex2oat_compiler_filter_arg = MapPropertyToArg("dalvik.vm.dex2oat-filter", |
| 234 | "--compiler-filter=%s"); |
| 235 | } |
| 236 | AddArg(dex2oat_compiler_filter_arg); |
| 237 | |
| 238 | if (compilation_reason != nullptr) { |
| 239 | AddArg(std::string("--compilation-reason=") + compilation_reason); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | AddArg(MapPropertyToArg("dalvik.vm.dex2oat-max-image-block-size", |
| 244 | "--max-image-block-size=%s")); |
| 245 | |
| 246 | AddArg(MapPropertyToArg("dalvik.vm.dex2oat-very-large", |
| 247 | "--very-large-app-threshold=%s")); |
| 248 | |
| 249 | std::string resolve_startup_string_arg = MapPropertyToArg( |
| 250 | "persist.device_config.runtime.dex2oat_resolve_startup_strings", |
| 251 | "--resolve-startup-const-strings=%s"); |
| 252 | if (resolve_startup_string_arg.empty()) { |
| 253 | // If empty, fall back to system property. |
| 254 | resolve_startup_string_arg = |
| 255 | MapPropertyToArg("dalvik.vm.dex2oat-resolve-startup-strings", |
| 256 | "--resolve-startup-const-strings=%s"); |
| 257 | } |
| 258 | AddArg(resolve_startup_string_arg); |
| 259 | |
| 260 | // Debug related |
| 261 | { |
| 262 | // Check whether all apps should be compiled debuggable. |
| 263 | if (!debuggable) { |
| 264 | debuggable = GetProperty("dalvik.vm.always_debuggable", "") == "1"; |
| 265 | } |
| 266 | if (debuggable) { |
| 267 | AddArg("--debuggable"); |
| 268 | } |
| 269 | |
| 270 | const bool generate_debug_info = GetBoolProperty("debug.generate-debug-info", false); |
| 271 | if (generate_debug_info) { |
| 272 | AddArg("--generate-debug-info"); |
| 273 | } |
| 274 | { |
| 275 | bool generate_minidebug_info = kEnableMinidebugInfo && |
| 276 | GetBoolProperty(kMinidebugInfoSystemProperty, |
| 277 | kMinidebugInfoSystemPropertyDefault); |
| 278 | if (generate_minidebug_info) { |
| 279 | AddArg(kMinidebugDex2oatFlag); |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
Orion Hodson | 2b12e7c | 2021-07-01 12:12:40 +0100 | [diff] [blame] | 284 | // On-device signing related. odsign sets the system property odsign.verification.success if |
| 285 | // AOT artifacts have the expected signatures. |
| 286 | const bool trust_art_apex_data_files = GetBoolProperty("odsign.verification.success", false); |
| 287 | if (!trust_art_apex_data_files) { |
| 288 | AddRuntimeArg("-Xdeny-art-apex-data-files"); |
| 289 | } |
| 290 | |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 291 | if (target_sdk_version != 0) { |
| 292 | AddRuntimeArg(StringPrintf("-Xtarget-sdk-version:%d", target_sdk_version)); |
| 293 | } |
| 294 | |
| 295 | if (enable_hidden_api_checks) { |
| 296 | AddRuntimeArg("-Xhidden-api-policy:enabled"); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | void RunDex2Oat::PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete, |
Martin Stjernholm | 02570a7 | 2022-11-01 13:56:46 +0000 | [diff] [blame^] | 301 | bool for_restore, |
| 302 | bool background_job_compile) { |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 303 | // CPU set |
| 304 | { |
| 305 | std::string cpu_set_format = "--cpu-set=%s"; |
| 306 | std::string dex2oat_cpu_set_arg = post_bootcomplete |
| 307 | ? (for_restore |
| 308 | ? MapPropertyToArgWithBackup( |
| 309 | "dalvik.vm.restore-dex2oat-cpu-set", |
| 310 | "dalvik.vm.dex2oat-cpu-set", |
| 311 | cpu_set_format) |
Martin Stjernholm | 02570a7 | 2022-11-01 13:56:46 +0000 | [diff] [blame^] | 312 | : (background_job_compile |
| 313 | ? MapPropertyToArgWithBackup( |
| 314 | "dalvik.vm.background-dex2oat-cpu-set", |
| 315 | "dalvik.vm.dex2oat-cpu-set", |
| 316 | cpu_set_format) |
| 317 | : MapPropertyToArg("dalvik.vm.dex2oat-cpu-set", cpu_set_format))) |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 318 | : MapPropertyToArg("dalvik.vm.boot-dex2oat-cpu-set", cpu_set_format); |
| 319 | AddArg(dex2oat_cpu_set_arg); |
| 320 | } |
| 321 | |
| 322 | // Number of threads |
| 323 | { |
| 324 | std::string threads_format = "-j%s"; |
| 325 | std::string dex2oat_threads_arg = post_bootcomplete |
| 326 | ? (for_restore |
| 327 | ? MapPropertyToArgWithBackup( |
| 328 | "dalvik.vm.restore-dex2oat-threads", |
| 329 | "dalvik.vm.dex2oat-threads", |
| 330 | threads_format) |
Martin Stjernholm | 02570a7 | 2022-11-01 13:56:46 +0000 | [diff] [blame^] | 331 | : (background_job_compile |
| 332 | ? MapPropertyToArgWithBackup( |
| 333 | "dalvik.vm.background-dex2oat-threads", |
| 334 | "dalvik.vm.dex2oat-threads", |
| 335 | threads_format) |
| 336 | : MapPropertyToArg("dalvik.vm.dex2oat-threads", threads_format))) |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 337 | : MapPropertyToArg("dalvik.vm.boot-dex2oat-threads", threads_format); |
| 338 | AddArg(dex2oat_threads_arg); |
| 339 | } |
| 340 | |
| 341 | AddRuntimeArg(MapPropertyToArg("dalvik.vm.dex2oat-Xms", "-Xms%s")); |
| 342 | AddRuntimeArg(MapPropertyToArg("dalvik.vm.dex2oat-Xmx", "-Xmx%s")); |
Calin Juravle | 380fff7 | 2021-06-17 15:37:08 -0700 | [diff] [blame] | 343 | |
| 344 | // Enable compiling dex files in isolation on low ram devices. |
| 345 | // It takes longer but reduces the memory footprint. |
| 346 | if (GetBoolProperty("ro.config.low_ram", false)) { |
| 347 | AddArg("--compile-individually"); |
| 348 | } |
Victor Hsieh | b345940 | 2020-07-07 12:34:54 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 351 | void RunDex2Oat::Exec(int exit_code) { |
Victor Hsieh | c9821f1 | 2020-08-07 11:32:29 -0700 | [diff] [blame] | 352 | execv_helper_->Exec(exit_code); |
| 353 | } |
| 354 | |
| 355 | void RunDex2Oat::AddArg(const std::string& arg) { |
| 356 | execv_helper_->AddArg(arg); |
| 357 | } |
| 358 | |
| 359 | void RunDex2Oat::AddRuntimeArg(const std::string& arg) { |
| 360 | execv_helper_->AddRuntimeArg(arg); |
| 361 | } |
| 362 | |
| 363 | std::string RunDex2Oat::GetProperty(const std::string& key, |
| 364 | const std::string& default_value) { |
| 365 | return android::base::GetProperty(key, default_value); |
| 366 | } |
| 367 | |
| 368 | bool RunDex2Oat::GetBoolProperty(const std::string& key, bool default_value) { |
| 369 | return android::base::GetBoolProperty(key, default_value); |
| 370 | } |
| 371 | |
| 372 | std::string RunDex2Oat::MapPropertyToArg(const std::string& property, |
| 373 | const std::string& format, |
| 374 | const std::string& default_value) { |
| 375 | std::string prop = GetProperty(property, default_value); |
| 376 | if (!prop.empty()) { |
| 377 | return StringPrintf(format.c_str(), prop.c_str()); |
| 378 | } |
| 379 | return ""; |
| 380 | } |
| 381 | |
| 382 | std::string RunDex2Oat::MapPropertyToArgWithBackup( |
| 383 | const std::string& property, |
| 384 | const std::string& backupProperty, |
| 385 | const std::string& format, |
| 386 | const std::string& default_value) { |
| 387 | std::string value = GetProperty(property, default_value); |
| 388 | if (!value.empty()) { |
| 389 | return StringPrintf(format.c_str(), value.c_str()); |
| 390 | } |
| 391 | return MapPropertyToArg(backupProperty, format, default_value); |
| 392 | } |
| 393 | |
| 394 | } // namespace installd |
| 395 | } // namespace android |