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 | 1b9d9a6 | 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; |
| 34 | static constexpr int DEX2OAT_FOR_RELOCATION = 4; |
Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 35 | |
Calin Juravle | cfcd6aa | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 36 | // Clear the reference profile identified by the given profile name. |
| 37 | bool clear_primary_reference_profile(const std::string& pkgname, const std::string& profile_name); |
| 38 | // Clear the current profile identified by the given profile name (for single user). |
| 39 | bool clear_primary_current_profile(const std::string& pkgname, const std::string& profile_name, |
| 40 | userid_t user); |
| 41 | // Clear all current profiles identified by the given profile name (all users). |
| 42 | 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] | 43 | |
Calin Juravle | 114f081 | 2017-03-08 19:05:07 -0800 | [diff] [blame] | 44 | // Decide if profile guided compilation is needed or not based on existing profiles. |
Calin Juravle | cfcd6aa | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 45 | // 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] | 46 | // Returns true if there is enough information in the current profiles that makes it |
| 47 | // worth to recompile the package. |
| 48 | // If the return value is true all the current profiles would have been merged into |
| 49 | // the reference profiles accessible with open_reference_profile(). |
Calin Juravle | cfcd6aa | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 50 | bool analyze_primary_profiles(uid_t uid, |
| 51 | const std::string& pkgname, |
| 52 | const std::string& profile_name); |
Calin Juravle | 114f081 | 2017-03-08 19:05:07 -0800 | [diff] [blame] | 53 | |
Calin Juravle | cfcd6aa | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 54 | // Create a snapshot of the profile information for the given package profile. |
Calin Juravle | e61189e | 2018-01-23 19:54:11 -0800 | [diff] [blame] | 55 | // If appId is -1, the method creates the profile snapshot for the boot image. |
| 56 | // |
Calin Juravle | 2959173 | 2017-11-20 17:46:19 -0800 | [diff] [blame] | 57 | // The profile snapshot is the aggregation of all existing profiles (all current user |
| 58 | // profiles & the reference profile) and is meant to capture the all the profile information |
| 59 | // without performing a merge into the reference profile which might impact future dex2oat |
| 60 | // compilations. |
| 61 | // The snapshot is created next to the reference profile of the package and the |
| 62 | // ownership is assigned to AID_SYSTEM. |
| 63 | // The snapshot location is reference_profile_location.snapshot. If a snapshot is already |
| 64 | // there, it will be truncated and overwritten. |
Calin Juravle | e61189e | 2018-01-23 19:54:11 -0800 | [diff] [blame] | 65 | // |
| 66 | // The classpath acts as filter: only profiling data belonging to elements of the classpath |
| 67 | // will end up in the snapshot. |
| 68 | bool create_profile_snapshot(int32_t app_id, |
| 69 | const std::string& package, |
| 70 | const std::string& profile_name, |
| 71 | const std::string& classpath); |
Calin Juravle | 2959173 | 2017-11-20 17:46:19 -0800 | [diff] [blame] | 72 | |
Calin Juravle | 562de81 | 2018-01-20 23:34:18 -0800 | [diff] [blame] | 73 | bool dump_profiles(int32_t uid, |
| 74 | const std::string& pkgname, |
| 75 | const std::string& profile_name, |
| 76 | const std::string& code_path); |
Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 77 | |
Mathieu Chartier | f966f2a | 2017-05-10 12:48:37 -0700 | [diff] [blame] | 78 | bool copy_system_profile(const std::string& system_profile, |
| 79 | uid_t packageUid, |
Calin Juravle | cfcd6aa | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 80 | const std::string& pkgname, |
| 81 | const std::string& profile_name); |
Mathieu Chartier | f966f2a | 2017-05-10 12:48:37 -0700 | [diff] [blame] | 82 | |
Calin Juravle | bc5ab87 | 2018-01-18 22:32:58 -0800 | [diff] [blame] | 83 | // Prepare the app profile for the given code path: |
| 84 | // - create the current profile using profile_name |
| 85 | // - merge the profile from the dex metadata file (if present) into |
| 86 | // the reference profile. |
| 87 | bool prepare_app_profile(const std::string& package_name, |
| 88 | userid_t user_id, |
| 89 | appid_t app_id, |
| 90 | const std::string& profile_name, |
| 91 | const std::string& code_path, |
| 92 | const std::unique_ptr<std::string>& dex_metadata); |
| 93 | |
Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 94 | bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path); |
| 95 | |
Calin Juravle | c9eab38 | 2017-01-25 01:17:17 -0800 | [diff] [blame] | 96 | bool reconcile_secondary_dex_file(const std::string& dex_path, |
| 97 | const std::string& pkgname, int uid, const std::vector<std::string>& isas, |
| 98 | const std::unique_ptr<std::string>& volumeUuid, int storage_flag, |
| 99 | /*out*/bool* out_secondary_dex_exists); |
| 100 | |
Alan Stokes | 753dc71 | 2017-10-16 10:56:00 +0100 | [diff] [blame] | 101 | bool hash_secondary_dex_file(const std::string& dex_path, |
| 102 | const std::string& pkgname, int uid, const std::unique_ptr<std::string>& volume_uuid, |
| 103 | int storage_flag, std::vector<uint8_t>* out_secondary_dex_hash); |
| 104 | |
Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 105 | int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set, |
| 106 | int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter, |
Calin Juravle | 1d66761 | 2017-07-13 22:50:21 -0700 | [diff] [blame] | 107 | const char* volume_uuid, const char* class_loader_context, const char* se_info, |
Calin Juravle | cc3b8ae | 2018-02-01 17:03:23 +0000 | [diff] [blame] | 108 | bool downgrade, int target_sdk_version, const char* profile_name, |
Calin Juravle | dcccd83 | 2018-02-13 18:31:32 -0800 | [diff] [blame^] | 109 | const char* dexMetadataPath, const char* compilation_reason); |
Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 110 | |
Jeff Sharkey | 1b9d9a6 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 111 | bool calculate_oat_file_path_default(char path[PKG_PATH_MAX], const char *oat_dir, |
| 112 | const char *apk_path, const char *instruction_set); |
| 113 | |
| 114 | bool calculate_odex_file_path_default(char path[PKG_PATH_MAX], const char *apk_path, |
| 115 | const char *instruction_set); |
| 116 | |
| 117 | bool create_cache_path_default(char path[PKG_PATH_MAX], const char *src, |
| 118 | const char *instruction_set); |
| 119 | |
Calin Juravle | cfcd6aa | 2018-01-18 20:23:17 -0800 | [diff] [blame] | 120 | bool move_ab(const char* apk_path, const char* instruction_set, const char* output_path); |
| 121 | |
Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 122 | } // namespace installd |
| 123 | } // namespace android |
| 124 | |
| 125 | #endif // DEXOPT_H_ |