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; |
| 34 | static constexpr int DEX2OAT_FOR_RELOCATION = 4; |
Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 35 | |
Calin Juravle | 114f081 | 2017-03-08 19:05:07 -0800 | [diff] [blame] | 36 | // Clear the reference profile for the primary apk of the given package. |
| 37 | bool clear_primary_reference_profile(const std::string& pkgname); |
| 38 | // Clear the current profile for the primary apk of the given package and user. |
| 39 | bool clear_primary_current_profile(const std::string& pkgname, userid_t user); |
| 40 | // Clear all current profile for the primary apk of the given package. |
| 41 | bool clear_primary_current_profiles(const std::string& pkgname); |
Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 42 | |
| 43 | bool move_ab(const char* apk_path, const char* instruction_set, const char* output_path); |
| 44 | |
Calin Juravle | 114f081 | 2017-03-08 19:05:07 -0800 | [diff] [blame] | 45 | // Decide if profile guided compilation is needed or not based on existing profiles. |
| 46 | // The analysis is done for the primary apks (base + splits) of the given package. |
| 47 | // Returns true if there is enough information in the current profiles that makes it |
| 48 | // worth to recompile the package. |
| 49 | // If the return value is true all the current profiles would have been merged into |
| 50 | // the reference profiles accessible with open_reference_profile(). |
| 51 | bool analyze_primary_profiles(uid_t uid, const std::string& pkgname); |
| 52 | |
Calin Juravle | 2959173 | 2017-11-20 17:46:19 -0800 | [diff] [blame] | 53 | // Create a snapshot of the profile information for the given package and code path. |
| 54 | // The profile snapshot is the aggregation of all existing profiles (all current user |
| 55 | // profiles & the reference profile) and is meant to capture the all the profile information |
| 56 | // without performing a merge into the reference profile which might impact future dex2oat |
| 57 | // compilations. |
| 58 | // The snapshot is created next to the reference profile of the package and the |
| 59 | // ownership is assigned to AID_SYSTEM. |
| 60 | // The snapshot location is reference_profile_location.snapshot. If a snapshot is already |
| 61 | // there, it will be truncated and overwritten. |
Calin Juravle | c3596c3 | 2017-12-05 12:29:15 -0800 | [diff] [blame^] | 62 | bool create_profile_snapshot(int32_t app_id, const std::string& package, |
| 63 | const std::string& code_path); |
Calin Juravle | 2959173 | 2017-11-20 17:46:19 -0800 | [diff] [blame] | 64 | |
Calin Juravle | 76268c5 | 2017-03-09 13:19:42 -0800 | [diff] [blame] | 65 | bool dump_profiles(int32_t uid, const std::string& pkgname, const char* code_paths); |
Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 66 | |
Mathieu Chartier | f966f2a | 2017-05-10 12:48:37 -0700 | [diff] [blame] | 67 | bool copy_system_profile(const std::string& system_profile, |
| 68 | uid_t packageUid, |
| 69 | const std::string& data_profile_location); |
| 70 | |
Jeff Sharkey | 90aff26 | 2016-12-12 14:28:24 -0700 | [diff] [blame] | 71 | bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path); |
| 72 | |
Calin Juravle | c9eab38 | 2017-01-25 01:17:17 -0800 | [diff] [blame] | 73 | bool reconcile_secondary_dex_file(const std::string& dex_path, |
| 74 | const std::string& pkgname, int uid, const std::vector<std::string>& isas, |
| 75 | const std::unique_ptr<std::string>& volumeUuid, int storage_flag, |
| 76 | /*out*/bool* out_secondary_dex_exists); |
| 77 | |
Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 78 | int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set, |
| 79 | 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] | 80 | const char* volume_uuid, const char* class_loader_context, const char* se_info, |
Shubham Ajmera | 54ef862 | 2017-06-22 11:10:27 -0700 | [diff] [blame] | 81 | bool downgrade); |
Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 82 | |
Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 83 | bool calculate_oat_file_path_default(char path[PKG_PATH_MAX], const char *oat_dir, |
| 84 | const char *apk_path, const char *instruction_set); |
| 85 | |
| 86 | bool calculate_odex_file_path_default(char path[PKG_PATH_MAX], const char *apk_path, |
| 87 | const char *instruction_set); |
| 88 | |
| 89 | bool create_cache_path_default(char path[PKG_PATH_MAX], const char *src, |
| 90 | const char *instruction_set); |
| 91 | |
Jeff Sharkey | 6c2c056 | 2016-12-07 12:12:00 -0700 | [diff] [blame] | 92 | } // namespace installd |
| 93 | } // namespace android |
| 94 | |
| 95 | #endif // DEXOPT_H_ |