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
20#include <sys/types.h>
21
22#include <cutils/multiuser.h>
23
24namespace android {
25namespace installd {
26
27/* dexopt needed flags matching those in dalvik.system.DexFile */
28static constexpr int NO_DEXOPT_NEEDED            = 0;
29static constexpr int DEX2OAT_FROM_SCRATCH        = 1;
30static constexpr int DEX2OAT_FOR_BOOT_IMAGE      = 2;
31static constexpr int DEX2OAT_FOR_FILTER          = 3;
32static constexpr int DEX2OAT_FOR_RELOCATION      = 4;
33static constexpr int PATCHOAT_FOR_RELOCATION     = 5;
34
35// Clear the reference profile for the primary apk of the given package.
36bool clear_primary_reference_profile(const std::string& pkgname);
37// Clear the current profile for the primary apk of the given package and user.
38bool clear_primary_current_profile(const std::string& pkgname, userid_t user);
39// Clear all current profile for the primary apk of the given package.
40bool clear_primary_current_profiles(const std::string& pkgname);
41
42bool move_ab(const char* apk_path, const char* instruction_set, const char* output_path);
43
44// Decide if profile guided compilation is needed or not based on existing profiles.
45// The analysis is done for the primary apks (base + splits) of the given package.
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().
50bool analyze_primary_profiles(uid_t uid, const std::string& pkgname);
51
52bool dump_profiles(int32_t uid, const std::string& pkgname, const char* code_paths);
53
54bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path);
55
56bool reconcile_secondary_dex_file(const std::string& dex_path,
57        const std::string& pkgname, int uid, const std::vector<std::string>& isas,
58        const std::unique_ptr<std::string>& volumeUuid, int storage_flag,
59        /*out*/bool* out_secondary_dex_exists);
60
61int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set,
62        int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter,
63        const char* volume_uuid, const char* shared_libraries, const char* se_info);
64
65}  // namespace installd
66}  // namespace android
67
68#endif  // DEXOPT_H_
69