Debian Codegraph @

libartservice/service/java/com/android/server/art/model/ArtFlags.java

raw
1 /*
2 * Copyright (C) 2022 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 package com.android.server.art.model;
18
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.app.job.JobScheduler;
23
24 import com.android.server.art.ArtManagerLocal;
25 import com.android.server.art.PriorityClass;
26 import com.android.server.art.ReasonMapping;
27 import com.android.server.pm.PackageManagerLocal;
28
29 import java.lang.annotation.Retention;
30 import java.lang.annotation.RetentionPolicy;
31
32 /** @hide */
33 @SystemApi(client = SystemApi.Client.SYSTEM_SERVER)
34 public class ArtFlags {
35 // Common flags.
36
37 /**
38 * Whether the operation is applied for primary dex'es (all APKs that are installed as part of
39 * the package, including the base APK and all other split APKs).
40 */
41 public static final int FLAG_FOR_PRIMARY_DEX = 1 << 0;
42 /**
43 * Whether the operation is applied for secondary dex'es (APKs/JARs that the app puts in its
44 * own data directory at runtime and loads with custom classloaders).
45 */
46 public static final int FLAG_FOR_SECONDARY_DEX = 1 << 1;
47
48 // Flags specific to `dexoptPackage`.
49
50 /**
51 * Whether to dexopt dependency libraries as well (dependencies that are declared by the app
52 * with <uses-library> tags and transitive dependencies).
53 */
54 public static final int FLAG_SHOULD_INCLUDE_DEPENDENCIES = 1 << 2;
55 /**
56 * Whether the intention is to downgrade the compiler filter. If true, the dexopt will
57 * be skipped if the target compiler filter is better than or equal to the compiler filter
58 * of the existing dexopt artifacts, or dexopt artifacts do not exist.
59 */
60 public static final int FLAG_SHOULD_DOWNGRADE = 1 << 3;
61 /**
62 * Whether to force dexopt. If true, the dexopt will be performed regardless of
63 * any existing dexopt artifacts.
64 */
65 public static final int FLAG_FORCE = 1 << 4;
66 /**
67 * If set, the dexopt will be performed for a single split. Otherwise, the dexopt
68 * will be performed for all splits. {@link DexoptParams.Builder#setSplitName()} can be used
69 * to specify the split to dexopt.
70 *
71 * When this flag is set, {@link #FLAG_FOR_PRIMARY_DEX} must be set, and {@link
72 * #FLAG_FOR_SECONDARY_DEX} and {@link #FLAG_SHOULD_INCLUDE_DEPENDENCIES} must not be set.
73 */
74 public static final int FLAG_FOR_SINGLE_SPLIT = 1 << 5;
75 /**
76 * If set, skips the dexopt if the remaining storage space is low. The threshold is
77 * controlled by the global settings {@code sys_storage_threshold_percentage} and {@code
78 * sys_storage_threshold_max_bytes}.
79 */
80 public static final int FLAG_SKIP_IF_STORAGE_LOW = 1 << 6;
81
82 /**
83 * Flags for {@link
84 * ArtManagerLocal#getDexoptStatus(PackageManagerLocal.FilteredSnapshot, String, int)}.
85 *
86 * @hide
87 */
88 // clang-format off
89 @IntDef(flag = true, prefix = "FLAG_", value = {
90 FLAG_FOR_PRIMARY_DEX,
91 FLAG_FOR_SECONDARY_DEX,
92 })
93 // clang-format on
94 @Retention(RetentionPolicy.SOURCE)
95 public @interface GetStatusFlags {}
96
97 /**
98 * Default flags that are used when {@link
99 * ArtManagerLocal#getDexoptStatus(PackageManagerLocal.FilteredSnapshot, String)} is
100 * called.
101 * Value: {@link #FLAG_FOR_PRIMARY_DEX}, {@link #FLAG_FOR_SECONDARY_DEX}.
102 */
103 public static @GetStatusFlags int defaultGetStatusFlags() {
104 return FLAG_FOR_PRIMARY_DEX | FLAG_FOR_SECONDARY_DEX;
105 }
106
107 /**
108 * Flags for {@link DexoptParams}.
109 *
110 * @hide
111 */
112 // clang-format off
113 @IntDef(flag = true, prefix = "FLAG_", value = {
114 FLAG_FOR_PRIMARY_DEX,
115 FLAG_FOR_SECONDARY_DEX,
116 FLAG_SHOULD_INCLUDE_DEPENDENCIES,
117 FLAG_SHOULD_DOWNGRADE,
118 FLAG_FORCE,
119 FLAG_FOR_SINGLE_SPLIT,
120 FLAG_SKIP_IF_STORAGE_LOW,
121 })
122 // clang-format on
123 @Retention(RetentionPolicy.SOURCE)
124 public @interface DexoptFlags {}
125
126 /**
127 * Default flags that are used when
128 * {@link DexoptParams.Builder#Builder(String)} is called.
129 *
130 * @hide
131 */
132 public static @DexoptFlags int defaultDexoptFlags(@NonNull String reason) {
133 switch (reason) {
134 case ReasonMapping.REASON_INSTALL:
135 case ReasonMapping.REASON_INSTALL_FAST:
136 case ReasonMapping.REASON_INSTALL_BULK:
137 case ReasonMapping.REASON_INSTALL_BULK_SECONDARY:
138 case ReasonMapping.REASON_INSTALL_BULK_DOWNGRADED:
139 case ReasonMapping.REASON_INSTALL_BULK_SECONDARY_DOWNGRADED:
140 return FLAG_FOR_PRIMARY_DEX;
141 case ReasonMapping.REASON_INACTIVE:
142 return FLAG_FOR_PRIMARY_DEX | FLAG_FOR_SECONDARY_DEX | FLAG_SHOULD_DOWNGRADE;
143 case ReasonMapping.REASON_FIRST_BOOT:
144 case ReasonMapping.REASON_BOOT_AFTER_OTA:
145 case ReasonMapping.REASON_BOOT_AFTER_MAINLINE_UPDATE:
146 return FLAG_FOR_PRIMARY_DEX | FLAG_SHOULD_INCLUDE_DEPENDENCIES;
147 case ReasonMapping.REASON_BG_DEXOPT:
148 return FLAG_FOR_PRIMARY_DEX | FLAG_FOR_SECONDARY_DEX
149 | FLAG_SHOULD_INCLUDE_DEPENDENCIES | FLAG_SKIP_IF_STORAGE_LOW;
150 case ReasonMapping.REASON_CMDLINE:
151 default:
152 return FLAG_FOR_PRIMARY_DEX | FLAG_FOR_SECONDARY_DEX
153 | FLAG_SHOULD_INCLUDE_DEPENDENCIES;
154 }
155 }
156
157 // Keep in sync with `PriorityClass` except for `PRIORITY_NONE`.
158 // Keep this in sync with `ArtShellCommand.printHelp` except for 'PRIORITY_NONE'.
159
160 /**
161 * Initial value. Not expected.
162 *
163 * @hide
164 */
165 public static final int PRIORITY_NONE = -1;
166 /** Indicates that the operation blocks boot. */
167 public static final int PRIORITY_BOOT = PriorityClass.BOOT;
168 /**
169 * Indicates that a human is waiting on the result and the operation is more latency sensitive
170 * than usual.
171 */
172 public static final int PRIORITY_INTERACTIVE_FAST = PriorityClass.INTERACTIVE_FAST;
173 /** Indicates that a human is waiting on the result. */
174 public static final int PRIORITY_INTERACTIVE = PriorityClass.INTERACTIVE;
175 /** Indicates that the operation runs in background. */
176 public static final int PRIORITY_BACKGROUND = PriorityClass.BACKGROUND;
177
178 /**
179 * Indicates the priority of an operation. The value affects the resource usage and the process
180 * priority. A higher value may result in faster execution but may consume more resources and
181 * compete for resources with other processes.
182 *
183 * @hide
184 */
185 // clang-format off
186 @IntDef(prefix = "PRIORITY_", value = {
187 PRIORITY_NONE,
188 PRIORITY_BOOT,
189 PRIORITY_INTERACTIVE_FAST,
190 PRIORITY_INTERACTIVE,
191 PRIORITY_BACKGROUND,
192 })
193 // clang-format on
194 @Retention(RetentionPolicy.SOURCE)
195 public @interface PriorityClassApi {}
196
197 /** The job has been successfully scheduled. */
198 public static final int SCHEDULE_SUCCESS = 0;
199
200 /** @see JobScheduler#RESULT_FAILURE */
201 public static final int SCHEDULE_JOB_SCHEDULER_FAILURE = 1;
202
203 /** The job is disabled by the system property {@code pm.dexopt.disable_bg_dexopt}. */
204 public static final int SCHEDULE_DISABLED_BY_SYSPROP = 2;
205
206 /**
207 * Indicates the result of scheduling a background dexopt job.
208 *
209 * @hide
210 */
211 // clang-format off
212 @IntDef(prefix = "SCHEDULE_", value = {
213 SCHEDULE_SUCCESS,
214 SCHEDULE_JOB_SCHEDULER_FAILURE,
215 SCHEDULE_DISABLED_BY_SYSPROP,
216 })
217 // clang-format on
218 @Retention(RetentionPolicy.SOURCE)
219 public @interface ScheduleStatus {}
220
221 private ArtFlags() {}
222 }