| Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2016 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 DEXOPT_H_ | 
|  | 18 | #define DEXOPT_H_ | 
|  | 19 |  | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 20 | #include "installd_constants.h" | 
|  | 21 |  | 
| Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 22 | #include <sys/types.h> | 
|  | 23 |  | 
| Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 24 | #include <cutils/multiuser.h> | 
|  | 25 |  | 
| Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 26 | namespace android { | 
|  | 27 | namespace installd { | 
|  | 28 |  | 
| Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 29 | /* dexopt needed flags matching those in dalvik.system.DexFile */ | 
| Calin Juravle | 80a2125 | 2017-01-17 14:43:25 -0800 | [diff] [blame] | 30 | static constexpr int NO_DEXOPT_NEEDED            = 0; | 
| Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 31 | static constexpr int DEX2OAT_FROM_SCRATCH        = 1; | 
|  | 32 | static constexpr int DEX2OAT_FOR_BOOT_IMAGE      = 2; | 
|  | 33 | static constexpr int DEX2OAT_FOR_FILTER          = 3; | 
| Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 34 |  | 
| Roland Levillain | 67a14f6 | 2019-01-23 15:59:50 +0000 | [diff] [blame] | 35 | #define ANDROID_RUNTIME_APEX_BIN "/apex/com.android.runtime/bin" | 
|  | 36 | // Location of binaries in the Android Runtime APEX. | 
|  | 37 | static constexpr const char* kDex2oatPath = ANDROID_RUNTIME_APEX_BIN "/dex2oat"; | 
|  | 38 | static constexpr const char* kDex2oatDebugPath = ANDROID_RUNTIME_APEX_BIN "/dex2oatd"; | 
| Calin Juravle | f74a737 | 2019-02-28 20:29:41 -0800 | [diff] [blame] | 39 | static constexpr const char* kProfmanPath = ANDROID_RUNTIME_APEX_BIN "/profman"; | 
| Roland Levillain | 67a14f6 | 2019-01-23 15:59:50 +0000 | [diff] [blame] | 40 | static constexpr const char* kProfmanDebugPath = ANDROID_RUNTIME_APEX_BIN "/profmand"; | 
|  | 41 | static constexpr const char* kDexoptanalyzerPath = ANDROID_RUNTIME_APEX_BIN "/dexoptanalyzer"; | 
|  | 42 | static constexpr const char* kDexoptanalyzerDebugPath = ANDROID_RUNTIME_APEX_BIN "/dexoptanalyzerd"; | 
|  | 43 | #undef ANDROID_RUNTIME_APEX_BIN | 
|  | 44 |  | 
| Calin Juravle | 824a64d | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 45 | // Clear the reference profile identified by the given profile name. | 
|  | 46 | bool clear_primary_reference_profile(const std::string& pkgname, const std::string& profile_name); | 
|  | 47 | // Clear the current profile identified by the given profile name (for single user). | 
|  | 48 | bool clear_primary_current_profile(const std::string& pkgname, const std::string& profile_name, | 
|  | 49 | userid_t user); | 
|  | 50 | // Clear all current profiles identified by the given profile name (all users). | 
|  | 51 | bool clear_primary_current_profiles(const std::string& pkgname, const std::string& profile_name); | 
| Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 52 |  | 
| Calin Juravle | 114f081 | 2017-03-08 19:05:07 -0800 | [diff] [blame] | 53 | // Decide if profile guided compilation is needed or not based on existing profiles. | 
| Calin Juravle | 824a64d | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 54 | // The analysis is done for a single profile name (which corresponds to a single code path). | 
| Calin Juravle | 114f081 | 2017-03-08 19:05:07 -0800 | [diff] [blame] | 55 | // Returns true if there is enough information in the current profiles that makes it | 
|  | 56 | // worth to recompile the package. | 
|  | 57 | // If the return value is true all the current profiles would have been merged into | 
|  | 58 | // the reference profiles accessible with open_reference_profile(). | 
| Calin Juravle | 824a64d | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 59 | bool analyze_primary_profiles(uid_t uid, | 
|  | 60 | const std::string& pkgname, | 
|  | 61 | const std::string& profile_name); | 
| Calin Juravle | 114f081 | 2017-03-08 19:05:07 -0800 | [diff] [blame] | 62 |  | 
| Calin Juravle | 824a64d | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 63 | // Create a snapshot of the profile information for the given package profile. | 
| Calin Juravle | 0d0a492 | 2018-01-23 19:54:11 -0800 | [diff] [blame] | 64 | // If appId is -1, the method creates the profile snapshot for the boot image. | 
|  | 65 | // | 
| Calin Juravle | 2959173 | 2017-11-20 17:46:19 -0800 | [diff] [blame] | 66 | // The profile snapshot is the aggregation of all existing profiles (all current user | 
|  | 67 | // profiles & the reference profile) and is meant to capture the all the profile information | 
|  | 68 | // without performing a merge into the reference profile which might impact future dex2oat | 
|  | 69 | // compilations. | 
|  | 70 | // The snapshot is created next to the reference profile of the package and the | 
|  | 71 | // ownership is assigned to AID_SYSTEM. | 
|  | 72 | // The snapshot location is reference_profile_location.snapshot. If a snapshot is already | 
|  | 73 | // there, it will be truncated and overwritten. | 
| Calin Juravle | 0d0a492 | 2018-01-23 19:54:11 -0800 | [diff] [blame] | 74 | // | 
|  | 75 | // The classpath acts as filter: only profiling data belonging to elements of the classpath | 
|  | 76 | // will end up in the snapshot. | 
|  | 77 | bool create_profile_snapshot(int32_t app_id, | 
|  | 78 | const std::string& package, | 
|  | 79 | const std::string& profile_name, | 
|  | 80 | const std::string& classpath); | 
| Calin Juravle | 2959173 | 2017-11-20 17:46:19 -0800 | [diff] [blame] | 81 |  | 
| Calin Juravle | 408cd4a | 2018-01-20 23:34:18 -0800 | [diff] [blame] | 82 | bool dump_profiles(int32_t uid, | 
|  | 83 | const std::string& pkgname, | 
|  | 84 | const std::string& profile_name, | 
|  | 85 | const std::string& code_path); | 
| Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 86 |  | 
| Mathieu Chartier | f966f2a | 2017-05-10 12:48:37 -0700 | [diff] [blame] | 87 | bool copy_system_profile(const std::string& system_profile, | 
|  | 88 | uid_t packageUid, | 
| Calin Juravle | 824a64d | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 89 | const std::string& pkgname, | 
|  | 90 | const std::string& profile_name); | 
| Mathieu Chartier | f966f2a | 2017-05-10 12:48:37 -0700 | [diff] [blame] | 91 |  | 
| Calin Juravle | c3b049e | 2018-01-18 22:32:58 -0800 | [diff] [blame] | 92 | // Prepare the app profile for the given code path: | 
|  | 93 | //  - create the current profile using profile_name | 
|  | 94 | //  - merge the profile from the dex metadata file (if present) into | 
|  | 95 | //    the reference profile. | 
|  | 96 | bool prepare_app_profile(const std::string& package_name, | 
|  | 97 | userid_t user_id, | 
|  | 98 | appid_t app_id, | 
|  | 99 | const std::string& profile_name, | 
|  | 100 | const std::string& code_path, | 
|  | 101 | const std::unique_ptr<std::string>& dex_metadata); | 
|  | 102 |  | 
| Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 103 | bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path); | 
|  | 104 |  | 
| Calin Juravle | c9eab38 | 2017-01-25 01:17:17 -0800 | [diff] [blame] | 105 | bool reconcile_secondary_dex_file(const std::string& dex_path, | 
|  | 106 | const std::string& pkgname, int uid, const std::vector<std::string>& isas, | 
|  | 107 | const std::unique_ptr<std::string>& volumeUuid, int storage_flag, | 
|  | 108 | /*out*/bool* out_secondary_dex_exists); | 
|  | 109 |  | 
| Alan Stokes | a25d90c | 2017-10-16 10:56:00 +0100 | [diff] [blame] | 110 | bool hash_secondary_dex_file(const std::string& dex_path, | 
|  | 111 | const std::string& pkgname, int uid, const std::unique_ptr<std::string>& volume_uuid, | 
|  | 112 | int storage_flag, std::vector<uint8_t>* out_secondary_dex_hash); | 
|  | 113 |  | 
| Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 114 | int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set, | 
|  | 115 | int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter, | 
| Calin Juravle | 52c4582 | 2017-07-13 22:50:21 -0700 | [diff] [blame] | 116 | const char* volume_uuid, const char* class_loader_context, const char* se_info, | 
| Calin Juravle | 62c5a37 | 2018-02-01 17:03:23 +0000 | [diff] [blame] | 117 | bool downgrade, int target_sdk_version, const char* profile_name, | 
| Andreas Gampe | 023b224 | 2018-02-28 16:03:25 -0800 | [diff] [blame] | 118 | const char* dexMetadataPath, const char* compilation_reason, std::string* error_msg); | 
| Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 119 |  | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 120 | bool calculate_oat_file_path_default(char path[PKG_PATH_MAX], const char *oat_dir, | 
|  | 121 | const char *apk_path, const char *instruction_set); | 
|  | 122 |  | 
|  | 123 | bool calculate_odex_file_path_default(char path[PKG_PATH_MAX], const char *apk_path, | 
|  | 124 | const char *instruction_set); | 
|  | 125 |  | 
|  | 126 | bool create_cache_path_default(char path[PKG_PATH_MAX], const char *src, | 
|  | 127 | const char *instruction_set); | 
|  | 128 |  | 
| Calin Juravle | 824a64d | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 129 | bool move_ab(const char* apk_path, const char* instruction_set, const char* output_path); | 
|  | 130 |  | 
| Calin Juravle | f74a737 | 2019-02-28 20:29:41 -0800 | [diff] [blame] | 131 | const char* select_execution_binary( | 
|  | 132 | const char* binary, | 
|  | 133 | const char* debug_binary, | 
|  | 134 | bool background_job_compile, | 
|  | 135 | bool is_debug_runtime, | 
|  | 136 | bool is_release, | 
|  | 137 | bool is_debuggable_build); | 
|  | 138 |  | 
| Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 139 | }  // namespace installd | 
|  | 140 | }  // namespace android | 
|  | 141 |  | 
|  | 142 | #endif  // DEXOPT_H_ |