blob: 0db11e1e7be9d34126f4c456a8cb679e4a225e6c [file] [log] [blame]
Jeff Sharkey6c2c0562016-12-07 12:12:00 -07001/*
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 Sharkeyc1149c92017-09-21 14:51:09 -060020#include "installd_constants.h"
21
Jeff Sharkey6c2c0562016-12-07 12:12:00 -070022#include <sys/types.h>
23
Jeff Sharkey90aff262016-12-12 14:28:24 -070024#include <cutils/multiuser.h>
25
Jeff Sharkey6c2c0562016-12-07 12:12:00 -070026namespace android {
27namespace installd {
28
Jeff Sharkey90aff262016-12-12 14:28:24 -070029/* dexopt needed flags matching those in dalvik.system.DexFile */
Calin Juravle80a21252017-01-17 14:43:25 -080030static constexpr int NO_DEXOPT_NEEDED = 0;
Jeff Sharkey90aff262016-12-12 14:28:24 -070031static constexpr int DEX2OAT_FROM_SCRATCH = 1;
32static constexpr int DEX2OAT_FOR_BOOT_IMAGE = 2;
33static constexpr int DEX2OAT_FOR_FILTER = 3;
Jeff Sharkey90aff262016-12-12 14:28:24 -070034
Calin Juravle824a64d2018-01-18 20:23:17 -080035// Clear the reference profile identified by the given profile name.
36bool clear_primary_reference_profile(const std::string& pkgname, const std::string& profile_name);
37// Clear the current profile identified by the given profile name (for single user).
38bool clear_primary_current_profile(const std::string& pkgname, const std::string& profile_name,
39 userid_t user);
40// Clear all current profiles identified by the given profile name (all users).
41bool clear_primary_current_profiles(const std::string& pkgname, const std::string& profile_name);
Jeff Sharkey90aff262016-12-12 14:28:24 -070042
Calin Juravle114f0812017-03-08 19:05:07 -080043// Decide if profile guided compilation is needed or not based on existing profiles.
Calin Juravle824a64d2018-01-18 20:23:17 -080044// The analysis is done for a single profile name (which corresponds to a single code path).
Calin Juravle114f0812017-03-08 19:05:07 -080045// Returns true if there is enough information in the current profiles that makes it
46// worth to recompile the package.
47// If the return value is true all the current profiles would have been merged into
48// the reference profiles accessible with open_reference_profile().
Calin Juravle824a64d2018-01-18 20:23:17 -080049bool analyze_primary_profiles(uid_t uid,
50 const std::string& pkgname,
51 const std::string& profile_name);
Calin Juravle114f0812017-03-08 19:05:07 -080052
Calin Juravle824a64d2018-01-18 20:23:17 -080053// Create a snapshot of the profile information for the given package profile.
Calin Juravle0d0a4922018-01-23 19:54:11 -080054// If appId is -1, the method creates the profile snapshot for the boot image.
55//
Calin Juravle29591732017-11-20 17:46:19 -080056// The profile snapshot is the aggregation of all existing profiles (all current user
57// profiles & the reference profile) and is meant to capture the all the profile information
58// without performing a merge into the reference profile which might impact future dex2oat
59// compilations.
60// The snapshot is created next to the reference profile of the package and the
61// ownership is assigned to AID_SYSTEM.
62// The snapshot location is reference_profile_location.snapshot. If a snapshot is already
63// there, it will be truncated and overwritten.
Calin Juravle0d0a4922018-01-23 19:54:11 -080064//
65// The classpath acts as filter: only profiling data belonging to elements of the classpath
66// will end up in the snapshot.
67bool create_profile_snapshot(int32_t app_id,
68 const std::string& package,
69 const std::string& profile_name,
70 const std::string& classpath);
Calin Juravle29591732017-11-20 17:46:19 -080071
Calin Juravle408cd4a2018-01-20 23:34:18 -080072bool dump_profiles(int32_t uid,
73 const std::string& pkgname,
74 const std::string& profile_name,
75 const std::string& code_path);
Jeff Sharkey90aff262016-12-12 14:28:24 -070076
Mathieu Chartierf966f2a2017-05-10 12:48:37 -070077bool copy_system_profile(const std::string& system_profile,
78 uid_t packageUid,
Calin Juravle824a64d2018-01-18 20:23:17 -080079 const std::string& pkgname,
80 const std::string& profile_name);
Mathieu Chartierf966f2a2017-05-10 12:48:37 -070081
Calin Juravlec3b049e2018-01-18 22:32:58 -080082// Prepare the app profile for the given code path:
83// - create the current profile using profile_name
84// - merge the profile from the dex metadata file (if present) into
85// the reference profile.
86bool prepare_app_profile(const std::string& package_name,
87 userid_t user_id,
88 appid_t app_id,
89 const std::string& profile_name,
90 const std::string& code_path,
91 const std::unique_ptr<std::string>& dex_metadata);
92
Jeff Sharkey90aff262016-12-12 14:28:24 -070093bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path);
94
Calin Juravlec9eab382017-01-25 01:17:17 -080095bool reconcile_secondary_dex_file(const std::string& dex_path,
96 const std::string& pkgname, int uid, const std::vector<std::string>& isas,
97 const std::unique_ptr<std::string>& volumeUuid, int storage_flag,
98 /*out*/bool* out_secondary_dex_exists);
99
Alan Stokesa25d90c2017-10-16 10:56:00 +0100100bool hash_secondary_dex_file(const std::string& dex_path,
101 const std::string& pkgname, int uid, const std::unique_ptr<std::string>& volume_uuid,
102 int storage_flag, std::vector<uint8_t>* out_secondary_dex_hash);
103
Jeff Sharkey6c2c0562016-12-07 12:12:00 -0700104int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set,
105 int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter,
Calin Juravle52c45822017-07-13 22:50:21 -0700106 const char* volume_uuid, const char* class_loader_context, const char* se_info,
Calin Juravle62c5a372018-02-01 17:03:23 +0000107 bool downgrade, int target_sdk_version, const char* profile_name,
Andreas Gampe023b2242018-02-28 16:03:25 -0800108 const char* dexMetadataPath, const char* compilation_reason, std::string* error_msg);
Jeff Sharkey6c2c0562016-12-07 12:12:00 -0700109
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600110bool calculate_oat_file_path_default(char path[PKG_PATH_MAX], const char *oat_dir,
111 const char *apk_path, const char *instruction_set);
112
113bool calculate_odex_file_path_default(char path[PKG_PATH_MAX], const char *apk_path,
114 const char *instruction_set);
115
116bool create_cache_path_default(char path[PKG_PATH_MAX], const char *src,
117 const char *instruction_set);
118
Calin Juravle824a64d2018-01-18 20:23:17 -0800119bool move_ab(const char* apk_path, const char* instruction_set, const char* output_path);
120
Jeff Sharkey6c2c0562016-12-07 12:12:00 -0700121} // namespace installd
122} // namespace android
123
124#endif // DEXOPT_H_