blob: de3c9f28218dbcf0705d4cbe106008f57716ca33 [file] [log] [blame]
Calin Juravledea3fd82017-07-17 15:12:01 -07001/*
2 * Copyright (C) 2017 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
17package com.android.server.pm.dex;
18
19import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason;
20
21/**
22 * Options used for dexopt invocations.
23 */
24public final class DexoptOptions {
25 // When set, the profiles will be checked for updates before calling dexopt. If
26 // the apps profiles didn't update in a meaningful way (decided by the compiler), dexopt
27 // will be skipped.
28 // Currently this only affects the optimization of primary apks. Secondary dex files
29 // will always check the profiles for updates.
30 public static final int DEXOPT_CHECK_FOR_PROFILES_UPDATES = 1 << 0;
31
32 // When set, dexopt will execute unconditionally (even if not needed).
33 public static final int DEXOPT_FORCE = 1 << 1;
34
35 // Whether or not the invocation of dexopt is done after the boot is completed. This is used
36 // in order to adjust the priority of the compilation thread.
37 public static final int DEXOPT_BOOT_COMPLETE = 1 << 2;
38
39 // When set, the dexopt invocation will optimize only the secondary dex files. If false, dexopt
40 // will only consider the primary apk.
41 public static final int DEXOPT_ONLY_SECONDARY_DEX = 1 << 3;
42
43 // When set, dexopt will optimize only dex files that are used by other apps.
44 // Currently, this flag is ignored for primary apks.
45 public static final int DEXOPT_ONLY_SHARED_DEX = 1 << 4;
46
47 // When set, dexopt will attempt to scale down the optimizations previously applied in order
48 // save disk space.
49 public static final int DEXOPT_DOWNGRADE = 1 << 5;
50
Calin Juravlefad6dc12017-08-03 19:48:37 -070051 // When set, dexopt will compile the dex file as a shared library even if it is not actually
52 // used by other apps. This is used to force the compilation or shared libraries declared
53 // with in the manifest with ''uses-library' before we have a chance to detect they are
54 // actually shared at runtime.
55 public static final int DEXOPT_AS_SHARED_LIBRARY = 1 << 6;
56
David Sehr11c22e32017-10-25 14:28:29 -070057 // When set, indicates that dexopt is invoked from the background service.
58 public static final int DEXOPT_IDLE_BACKGROUND_JOB = 1 << 9;
59
Calin Juravle29c772c2018-02-01 17:20:51 +000060 // When set, indicates that dexopt is invoked from the install time flow and
61 // should get the dex metdata file if present.
62 public static final int DEXOPT_INSTALL_WITH_DEX_METADATA_FILE = 1 << 10;
63
Calin Juravledea3fd82017-07-17 15:12:01 -070064 // The name of package to optimize.
65 private final String mPackageName;
66
67 // The intended target compiler filter. Note that dexopt might adjust the filter before the
68 // execution based on factors like: vmSafeMode and packageUsedByOtherApps.
69 private final String mCompilerFilter;
70
71 // The set of flags for the dexopt options. It's a mix of the DEXOPT_* flags.
72 private final int mFlags;
73
Calin Juravlecaed6002017-07-17 15:23:21 -070074 // When not null, dexopt will optimize only the split identified by this name.
75 // It only applies for primary apk and it's always null if mOnlySecondaryDex is true.
76 private final String mSplitName;
77
Calin Juravleb9816172018-02-12 12:00:44 -080078 // The reason for invoking dexopt (see PackageManagerService.REASON_* constants).
79 // A -1 value denotes an unknown reason.
80 private final int mCompilationReason;
81
Calin Juravledea3fd82017-07-17 15:12:01 -070082 public DexoptOptions(String packageName, String compilerFilter, int flags) {
Calin Juravleb9816172018-02-12 12:00:44 -080083 this(packageName, /*compilationReason*/ -1, compilerFilter, /*splitName*/ null, flags);
Calin Juravlecaed6002017-07-17 15:23:21 -070084 }
85
Calin Juravleb9816172018-02-12 12:00:44 -080086 public DexoptOptions(String packageName, int compilationReason, int flags) {
87 this(packageName, compilationReason, getCompilerFilterForReason(compilationReason),
88 /*splitName*/ null, flags);
Calin Juravlecaed6002017-07-17 15:23:21 -070089 }
90
Calin Juravleb9816172018-02-12 12:00:44 -080091 public DexoptOptions(String packageName, int compilationReason, String compilerFilter,
92 String splitName, int flags) {
Calin Juravledea3fd82017-07-17 15:12:01 -070093 int validityMask =
94 DEXOPT_CHECK_FOR_PROFILES_UPDATES |
95 DEXOPT_FORCE |
96 DEXOPT_BOOT_COMPLETE |
97 DEXOPT_ONLY_SECONDARY_DEX |
98 DEXOPT_ONLY_SHARED_DEX |
Calin Juravlefad6dc12017-08-03 19:48:37 -070099 DEXOPT_DOWNGRADE |
David Sehr11c22e32017-10-25 14:28:29 -0700100 DEXOPT_AS_SHARED_LIBRARY |
Calin Juravle29c772c2018-02-01 17:20:51 +0000101 DEXOPT_IDLE_BACKGROUND_JOB |
102 DEXOPT_INSTALL_WITH_DEX_METADATA_FILE;
Calin Juravledea3fd82017-07-17 15:12:01 -0700103 if ((flags & (~validityMask)) != 0) {
104 throw new IllegalArgumentException("Invalid flags : " + Integer.toHexString(flags));
105 }
106
107 mPackageName = packageName;
108 mCompilerFilter = compilerFilter;
109 mFlags = flags;
Calin Juravlecaed6002017-07-17 15:23:21 -0700110 mSplitName = splitName;
Calin Juravleb9816172018-02-12 12:00:44 -0800111 mCompilationReason = compilationReason;
Calin Juravledea3fd82017-07-17 15:12:01 -0700112 }
113
114 public String getPackageName() {
115 return mPackageName;
116 }
117
118 public boolean isCheckForProfileUpdates() {
119 return (mFlags & DEXOPT_CHECK_FOR_PROFILES_UPDATES) != 0;
120 }
121
122 public String getCompilerFilter() {
123 return mCompilerFilter;
124 }
125
126 public boolean isForce() {
127 return (mFlags & DEXOPT_FORCE) != 0;
128 }
129
130 public boolean isBootComplete() {
131 return (mFlags & DEXOPT_BOOT_COMPLETE) != 0;
132 }
133
134 public boolean isDexoptOnlySecondaryDex() {
135 return (mFlags & DEXOPT_ONLY_SECONDARY_DEX) != 0;
136 }
137
138 public boolean isDexoptOnlySharedDex() {
139 return (mFlags & DEXOPT_ONLY_SHARED_DEX) != 0;
140 }
141
142 public boolean isDowngrade() {
143 return (mFlags & DEXOPT_DOWNGRADE) != 0;
144 }
Calin Juravlecaed6002017-07-17 15:23:21 -0700145
Calin Juravlefad6dc12017-08-03 19:48:37 -0700146 public boolean isDexoptAsSharedLibrary() {
147 return (mFlags & DEXOPT_AS_SHARED_LIBRARY) != 0;
148 }
149
David Sehr11c22e32017-10-25 14:28:29 -0700150 public boolean isDexoptIdleBackgroundJob() {
151 return (mFlags & DEXOPT_IDLE_BACKGROUND_JOB) != 0;
152 }
153
Calin Juravle29c772c2018-02-01 17:20:51 +0000154 public boolean isDexoptInstallWithDexMetadata() {
155 return (mFlags & DEXOPT_INSTALL_WITH_DEX_METADATA_FILE) != 0;
156 }
157
Calin Juravlecaed6002017-07-17 15:23:21 -0700158 public String getSplitName() {
159 return mSplitName;
160 }
Calin Juravlefad6dc12017-08-03 19:48:37 -0700161
162 public int getFlags() {
163 return mFlags;
164 }
Calin Juravleb9816172018-02-12 12:00:44 -0800165
166 public int getCompilationReason() {
167 return mCompilationReason;
168 }
Calin Juravledea3fd82017-07-17 15:12:01 -0700169}