blob: 86f7380e331bf5e9a25f6792c95ced098d4bb754 [file] [log] [blame]
Calin Juravle03181622016-12-01 17:53:07 +00001/*
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
17package com.android.server.pm.dex;
18
19import android.util.AtomicFile;
20import android.util.Slog;
21import android.os.Build;
22
23import com.android.internal.annotations.GuardedBy;
Alan Stokes6dba50d2018-10-30 15:05:36 +000024import com.android.internal.annotations.VisibleForTesting;
Calin Juravle03181622016-12-01 17:53:07 +000025import com.android.internal.util.FastPrintWriter;
26import com.android.server.pm.AbstractStatsBase;
27import com.android.server.pm.PackageManagerServiceUtils;
28
29import java.io.BufferedReader;
Calin Juravle03181622016-12-01 17:53:07 +000030import java.io.FileNotFoundException;
31import java.io.FileOutputStream;
32import java.io.InputStreamReader;
33import java.io.IOException;
34import java.io.OutputStreamWriter;
35import java.io.Reader;
36import java.io.StringWriter;
37import java.io.Writer;
Calin Juravle535a4752017-02-03 16:55:49 -080038import java.util.Arrays;
Calin Juravle52a452c2017-08-04 01:42:17 -070039import java.util.Collection;
Calin Juravle535a4752017-02-03 16:55:49 -080040import java.util.Collections;
Calin Juravle03181622016-12-01 17:53:07 +000041import java.util.Iterator;
42import java.util.HashMap;
43import java.util.HashSet;
Calin Juravle535a4752017-02-03 16:55:49 -080044import java.util.List;
Calin Juravle03181622016-12-01 17:53:07 +000045import java.util.Map;
Narayan Kamath607223f2018-02-19 14:09:02 +000046import java.util.Objects;
Calin Juravle03181622016-12-01 17:53:07 +000047import java.util.Set;
48
49import dalvik.system.VMRuntime;
50import libcore.io.IoUtils;
51
52/**
53 * Stat file which store usage information about dex files.
54 */
55public class PackageDexUsage extends AbstractStatsBase<Void> {
56 private final static String TAG = "PackageDexUsage";
57
Calin Juravlef1ff36f2017-07-22 12:33:41 -070058 // We support previous version to ensure that the usage list remains valid cross OTAs.
Calin Juravle535a4752017-02-03 16:55:49 -080059 private final static int PACKAGE_DEX_USAGE_SUPPORTED_VERSION_1 = 1;
Calin Juravle52a452c2017-08-04 01:42:17 -070060 // Version 2 added:
61 // - the list of packages that load the dex files
62 // - class loader contexts for secondary dex files
63 // - usage for all code paths (including splits)
Calin Juravlef1ff36f2017-07-22 12:33:41 -070064 private final static int PACKAGE_DEX_USAGE_SUPPORTED_VERSION_2 = 2;
Calin Juravle535a4752017-02-03 16:55:49 -080065
Calin Juravle52a452c2017-08-04 01:42:17 -070066 private final static int PACKAGE_DEX_USAGE_VERSION = PACKAGE_DEX_USAGE_SUPPORTED_VERSION_2;
67
Calin Juravle03181622016-12-01 17:53:07 +000068 private final static String PACKAGE_DEX_USAGE_VERSION_HEADER =
69 "PACKAGE_MANAGER__PACKAGE_DEX_USAGE__";
70
71 private final static String SPLIT_CHAR = ",";
Calin Juravle52a452c2017-08-04 01:42:17 -070072 private final static String CODE_PATH_LINE_CHAR = "+";
Calin Juravle03181622016-12-01 17:53:07 +000073 private final static String DEX_LINE_CHAR = "#";
Calin Juravle535a4752017-02-03 16:55:49 -080074 private final static String LOADING_PACKAGE_CHAR = "@";
Calin Juravlef1ff36f2017-07-22 12:33:41 -070075
76 // One of the things we record about dex files is the class loader context that was used to
77 // load them. That should be stable but if it changes we don't keep track of variable contexts.
78 // Instead we put a special marker in the dex usage file in order to recognize the case and
79 // skip optimizations on that dex files.
80 /*package*/ static final String VARIABLE_CLASS_LOADER_CONTEXT =
81 "=VariableClassLoaderContext=";
Calin Juravlef1ff36f2017-07-22 12:33:41 -070082 // The markers used for unknown class loader contexts. This can happen if the dex file was
83 // recorded in a previous version and we didn't have a chance to update its usage.
84 /*package*/ static final String UNKNOWN_CLASS_LOADER_CONTEXT =
85 "=UnknownClassLoaderContext=";
86
Alan Stokes6dba50d2018-10-30 15:05:36 +000087 // The marker used for unsupported class loader contexts (no longer written, may occur in old
88 // files so discarded on read).
89 private static final String UNSUPPORTED_CLASS_LOADER_CONTEXT =
90 "=UnsupportedClassLoaderContext=";
91
Calin Juravle03181622016-12-01 17:53:07 +000092 // Map which structures the information we have on a package.
93 // Maps package name to package data (which stores info about UsedByOtherApps and
94 // secondary dex files.).
95 // Access to this map needs synchronized.
96 @GuardedBy("mPackageUseInfoMap")
Calin Juravle535a4752017-02-03 16:55:49 -080097 private final Map<String, PackageUseInfo> mPackageUseInfoMap;
Calin Juravle03181622016-12-01 17:53:07 +000098
Alan Stokes58aea512018-09-21 17:26:43 +010099 /* package */ PackageDexUsage() {
Calin Juravle03181622016-12-01 17:53:07 +0000100 super("package-dex-usage.list", "PackageDexUsage_DiskWriter", /*lock*/ false);
101 mPackageUseInfoMap = new HashMap<>();
102 }
103
104 /**
105 * Record a dex file load.
106 *
107 * Note this is called when apps load dex files and as such it should return
108 * as fast as possible.
109 *
Calin Juravle535a4752017-02-03 16:55:49 -0800110 * @param owningPackageName the package owning the dex path
Calin Juravle03181622016-12-01 17:53:07 +0000111 * @param dexPath the path of the dex files being loaded
112 * @param ownerUserId the user id which runs the code loading the dex files
113 * @param loaderIsa the ISA of the app loading the dex files
114 * @param isUsedByOtherApps whether or not this dex file was not loaded by its owning package
115 * @param primaryOrSplit whether or not the dex file is a primary/split dex. True indicates
116 * the file is either primary or a split. False indicates the file is secondary dex.
Calin Juravle535a4752017-02-03 16:55:49 -0800117 * @param loadingPackageName the package performing the load. Recorded only if it is different
118 * than {@param owningPackageName}.
Calin Juravle03181622016-12-01 17:53:07 +0000119 * @return true if the dex load constitutes new information, or false if this information
120 * has been seen before.
121 */
Alan Stokes58aea512018-09-21 17:26:43 +0100122 /* package */ boolean record(String owningPackageName, String dexPath, int ownerUserId,
Calin Juravle535a4752017-02-03 16:55:49 -0800123 String loaderIsa, boolean isUsedByOtherApps, boolean primaryOrSplit,
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700124 String loadingPackageName, String classLoaderContext) {
Calin Juravle03181622016-12-01 17:53:07 +0000125 if (!PackageManagerServiceUtils.checkISA(loaderIsa)) {
126 throw new IllegalArgumentException("loaderIsa " + loaderIsa + " is unsupported");
127 }
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700128 if (classLoaderContext == null) {
129 throw new IllegalArgumentException("Null classLoaderContext");
130 }
131
Calin Juravle03181622016-12-01 17:53:07 +0000132 synchronized (mPackageUseInfoMap) {
133 PackageUseInfo packageUseInfo = mPackageUseInfoMap.get(owningPackageName);
134 if (packageUseInfo == null) {
135 // This is the first time we see the package.
136 packageUseInfo = new PackageUseInfo();
137 if (primaryOrSplit) {
138 // If we have a primary or a split apk, set isUsedByOtherApps.
139 // We do not need to record the loaderIsa or the owner because we compile
140 // primaries for all users and all ISAs.
Calin Juravle52a452c2017-08-04 01:42:17 -0700141 packageUseInfo.mergeCodePathUsedByOtherApps(dexPath, isUsedByOtherApps,
142 owningPackageName, loadingPackageName);
Calin Juravle03181622016-12-01 17:53:07 +0000143 } else {
144 // For secondary dex files record the loaderISA and the owner. We'll need
145 // to know under which user to compile and for what ISA.
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700146 DexUseInfo newData = new DexUseInfo(isUsedByOtherApps, ownerUserId,
147 classLoaderContext, loaderIsa);
Calin Juravle535a4752017-02-03 16:55:49 -0800148 packageUseInfo.mDexUseInfoMap.put(dexPath, newData);
149 maybeAddLoadingPackage(owningPackageName, loadingPackageName,
150 newData.mLoadingPackages);
Calin Juravle03181622016-12-01 17:53:07 +0000151 }
152 mPackageUseInfoMap.put(owningPackageName, packageUseInfo);
153 return true;
154 } else {
155 // We already have data on this package. Amend it.
156 if (primaryOrSplit) {
157 // We have a possible update on the primary apk usage. Merge
158 // isUsedByOtherApps information and return if there was an update.
Calin Juravle52a452c2017-08-04 01:42:17 -0700159 return packageUseInfo.mergeCodePathUsedByOtherApps(
160 dexPath, isUsedByOtherApps, owningPackageName, loadingPackageName);
Calin Juravle03181622016-12-01 17:53:07 +0000161 } else {
162 DexUseInfo newData = new DexUseInfo(
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700163 isUsedByOtherApps, ownerUserId, classLoaderContext, loaderIsa);
Calin Juravle535a4752017-02-03 16:55:49 -0800164 boolean updateLoadingPackages = maybeAddLoadingPackage(owningPackageName,
165 loadingPackageName, newData.mLoadingPackages);
166
Calin Juravle03181622016-12-01 17:53:07 +0000167 DexUseInfo existingData = packageUseInfo.mDexUseInfoMap.get(dexPath);
168 if (existingData == null) {
169 // It's the first time we see this dex file.
170 packageUseInfo.mDexUseInfoMap.put(dexPath, newData);
171 return true;
172 } else {
173 if (ownerUserId != existingData.mOwnerUserId) {
174 // Oups, this should never happen, the DexManager who calls this should
175 // do the proper checks and not call record if the user does not own the
176 // dex path.
177 // Secondary dex files are stored in the app user directory. A change in
178 // owningUser for the same path means that something went wrong at some
179 // higher level, and the loaderUser was allowed to cross
180 // user-boundaries and access data from what we know to be the owner
181 // user.
182 throw new IllegalArgumentException("Trying to change ownerUserId for "
183 + " dex path " + dexPath + " from " + existingData.mOwnerUserId
184 + " to " + ownerUserId);
185 }
186 // Merge the information into the existing data.
187 // Returns true if there was an update.
Calin Juravle535a4752017-02-03 16:55:49 -0800188 return existingData.merge(newData) || updateLoadingPackages;
Calin Juravle03181622016-12-01 17:53:07 +0000189 }
190 }
191 }
192 }
193 }
194
195 /**
196 * Convenience method for sync reads which does not force the user to pass a useless
197 * (Void) null.
198 */
Alan Stokes58aea512018-09-21 17:26:43 +0100199 /* package */ void read() {
Calin Juravle03181622016-12-01 17:53:07 +0000200 read((Void) null);
201 }
202
203 /**
204 * Convenience method for async writes which does not force the user to pass a useless
205 * (Void) null.
206 */
Calin Juravle14876bd2017-07-28 16:13:35 -0700207 /*package*/ void maybeWriteAsync() {
208 maybeWriteAsync(null);
209 }
210
211 /*package*/ void writeNow() {
212 writeInternal(null);
Calin Juravle03181622016-12-01 17:53:07 +0000213 }
214
215 @Override
216 protected void writeInternal(Void data) {
217 AtomicFile file = getFile();
218 FileOutputStream f = null;
219
220 try {
221 f = file.startWrite();
222 OutputStreamWriter osw = new OutputStreamWriter(f);
223 write(osw);
224 osw.flush();
225 file.finishWrite(f);
226 } catch (IOException e) {
227 if (f != null) {
228 file.failWrite(f);
229 }
230 Slog.e(TAG, "Failed to write usage for dex files", e);
231 }
232 }
233
234 /**
235 * File format:
236 *
237 * file_magic_version
238 * package_name_1
Calin Juravle52a452c2017-08-04 01:42:17 -0700239 * +code_path1
Calin Juravle535a4752017-02-03 16:55:49 -0800240 * @ loading_package_1_1, loading_package_1_2...
Calin Juravle52a452c2017-08-04 01:42:17 -0700241 * +code_path2
242 * @ loading_package_2_1, loading_package_2_2...
Calin Juravle03181622016-12-01 17:53:07 +0000243 * #dex_file_path_1_1
244 * user_1_1, used_by_other_app_1_1, user_isa_1_1_1, user_isa_1_1_2
Calin Juravle52a452c2017-08-04 01:42:17 -0700245 * @ loading_package_1_1_1, loading_package_1_1_2...
246 * class_loader_context_1_1
Calin Juravle03181622016-12-01 17:53:07 +0000247 * #dex_file_path_1_2
248 * user_1_2, used_by_other_app_1_2, user_isa_1_2_1, user_isa_1_2_2
Calin Juravle52a452c2017-08-04 01:42:17 -0700249 * @ loading_package_1_2_1, loading_package_1_2_2...
250 * class_loader_context_1_2
Calin Juravle03181622016-12-01 17:53:07 +0000251 * ...
252 */
253 /* package */ void write(Writer out) {
254 // Make a clone to avoid locking while writing to disk.
255 Map<String, PackageUseInfo> packageUseInfoMapClone = clonePackageUseInfoMap();
256
257 FastPrintWriter fpw = new FastPrintWriter(out);
258
259 // Write the header.
260 fpw.print(PACKAGE_DEX_USAGE_VERSION_HEADER);
261 fpw.println(PACKAGE_DEX_USAGE_VERSION);
262
263 for (Map.Entry<String, PackageUseInfo> pEntry : packageUseInfoMapClone.entrySet()) {
264 // Write the package line.
265 String packageName = pEntry.getKey();
266 PackageUseInfo packageUseInfo = pEntry.getValue();
Calin Juravle52a452c2017-08-04 01:42:17 -0700267 fpw.println(packageName);
Calin Juravle03181622016-12-01 17:53:07 +0000268
Calin Juravle52a452c2017-08-04 01:42:17 -0700269 // Write the code paths used by other apps.
270 for (Map.Entry<String, Set<String>> codeEntry :
271 packageUseInfo.mCodePathsUsedByOtherApps.entrySet()) {
272 String codePath = codeEntry.getKey();
273 Set<String> loadingPackages = codeEntry.getValue();
274 fpw.println(CODE_PATH_LINE_CHAR + codePath);
275 fpw.println(LOADING_PACKAGE_CHAR + String.join(SPLIT_CHAR, loadingPackages));
276 }
Calin Juravle03181622016-12-01 17:53:07 +0000277
278 // Write dex file lines.
279 for (Map.Entry<String, DexUseInfo> dEntry : packageUseInfo.mDexUseInfoMap.entrySet()) {
280 String dexPath = dEntry.getKey();
281 DexUseInfo dexUseInfo = dEntry.getValue();
282 fpw.println(DEX_LINE_CHAR + dexPath);
283 fpw.print(String.join(SPLIT_CHAR, Integer.toString(dexUseInfo.mOwnerUserId),
Calin Juravle52a452c2017-08-04 01:42:17 -0700284 writeBoolean(dexUseInfo.mIsUsedByOtherApps)));
Calin Juravle03181622016-12-01 17:53:07 +0000285 for (String isa : dexUseInfo.mLoaderIsas) {
286 fpw.print(SPLIT_CHAR + isa);
287 }
288 fpw.println();
Calin Juravle52a452c2017-08-04 01:42:17 -0700289 fpw.println(LOADING_PACKAGE_CHAR
290 + String.join(SPLIT_CHAR, dexUseInfo.mLoadingPackages));
291 fpw.println(dexUseInfo.getClassLoaderContext());
Calin Juravle03181622016-12-01 17:53:07 +0000292 }
293 }
294 fpw.flush();
295 }
296
297 @Override
298 protected void readInternal(Void data) {
299 AtomicFile file = getFile();
300 BufferedReader in = null;
301 try {
302 in = new BufferedReader(new InputStreamReader(file.openRead()));
303 read(in);
304 } catch (FileNotFoundException expected) {
305 // The file may not be there. E.g. When we first take the OTA with this feature.
306 } catch (IOException e) {
307 Slog.w(TAG, "Failed to parse package dex usage.", e);
308 } finally {
309 IoUtils.closeQuietly(in);
310 }
311 }
312
313 /* package */ void read(Reader reader) throws IOException {
314 Map<String, PackageUseInfo> data = new HashMap<>();
315 BufferedReader in = new BufferedReader(reader);
316 // Read header, do version check.
317 String versionLine = in.readLine();
Calin Juravle535a4752017-02-03 16:55:49 -0800318 int version;
Calin Juravle03181622016-12-01 17:53:07 +0000319 if (versionLine == null) {
320 throw new IllegalStateException("No version line found.");
321 } else {
322 if (!versionLine.startsWith(PACKAGE_DEX_USAGE_VERSION_HEADER)) {
323 // TODO(calin): the caller is responsible to clear the file.
324 throw new IllegalStateException("Invalid version line: " + versionLine);
325 }
Calin Juravle535a4752017-02-03 16:55:49 -0800326 version = Integer.parseInt(
Calin Juravle03181622016-12-01 17:53:07 +0000327 versionLine.substring(PACKAGE_DEX_USAGE_VERSION_HEADER.length()));
Calin Juravle535a4752017-02-03 16:55:49 -0800328 if (!isSupportedVersion(version)) {
Calin Juravle03181622016-12-01 17:53:07 +0000329 throw new IllegalStateException("Unexpected version: " + version);
330 }
331 }
332
Calin Juravle52a452c2017-08-04 01:42:17 -0700333 String line;
Calin Juravle535a4752017-02-03 16:55:49 -0800334 String currentPackage = null;
335 PackageUseInfo currentPackageData = null;
Calin Juravle03181622016-12-01 17:53:07 +0000336
337 Set<String> supportedIsas = new HashSet<>();
338 for (String abi : Build.SUPPORTED_ABIS) {
339 supportedIsas.add(VMRuntime.getInstructionSet(abi));
340 }
Calin Juravle52a452c2017-08-04 01:42:17 -0700341 while ((line = in.readLine()) != null) {
342 if (line.startsWith(DEX_LINE_CHAR)) {
Calin Juravle03181622016-12-01 17:53:07 +0000343 // This is the start of the the dex lines.
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700344 // We expect 4 lines for each dex entry:
Calin Juravle03181622016-12-01 17:53:07 +0000345 // #dexPaths
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700346 // @loading_package_1,loading_package_2,...
347 // class_loader_context
Calin Juravle03181622016-12-01 17:53:07 +0000348 // onwerUserId,isUsedByOtherApps,isa1,isa2
Calin Juravle535a4752017-02-03 16:55:49 -0800349 if (currentPackage == null) {
Calin Juravle03181622016-12-01 17:53:07 +0000350 throw new IllegalStateException(
351 "Malformed PackageDexUsage file. Expected package line before dex line.");
352 }
353
Calin Juravle52a452c2017-08-04 01:42:17 -0700354 // Line 1 is the dex path.
355 String dexPath = line.substring(DEX_LINE_CHAR.length());
Calin Juravle535a4752017-02-03 16:55:49 -0800356
Calin Juravle52a452c2017-08-04 01:42:17 -0700357 // Line 2 is the dex data: (userId, isUsedByOtherApps, isa).
358 line = in.readLine();
359 if (line == null) {
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700360 throw new IllegalStateException("Could not find dexUseInfo line");
Calin Juravle03181622016-12-01 17:53:07 +0000361 }
Calin Juravle52a452c2017-08-04 01:42:17 -0700362 String[] elems = line.split(SPLIT_CHAR);
Calin Juravle03181622016-12-01 17:53:07 +0000363 if (elems.length < 3) {
Calin Juravle52a452c2017-08-04 01:42:17 -0700364 throw new IllegalStateException("Invalid PackageDexUsage line: " + line);
Calin Juravle03181622016-12-01 17:53:07 +0000365 }
Calin Juravle52a452c2017-08-04 01:42:17 -0700366
367 // In version 2 we added the loading packages and class loader context.
368 Set<String> loadingPackages = maybeReadLoadingPackages(in, version);
369 String classLoaderContext = maybeReadClassLoaderContext(in, version);
370
Alan Stokes6dba50d2018-10-30 15:05:36 +0000371 if (UNSUPPORTED_CLASS_LOADER_CONTEXT.equals(classLoaderContext)) {
372 // We used to record use of unsupported class loaders, but we no longer do.
373 // Discard such entries; they will be deleted when we next write the file.
374 continue;
375 }
376
Calin Juravle03181622016-12-01 17:53:07 +0000377 int ownerUserId = Integer.parseInt(elems[0]);
378 boolean isUsedByOtherApps = readBoolean(elems[1]);
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700379 DexUseInfo dexUseInfo = new DexUseInfo(isUsedByOtherApps, ownerUserId,
380 classLoaderContext, /*isa*/ null);
Calin Juravle535a4752017-02-03 16:55:49 -0800381 dexUseInfo.mLoadingPackages.addAll(loadingPackages);
Calin Juravle03181622016-12-01 17:53:07 +0000382 for (int i = 2; i < elems.length; i++) {
383 String isa = elems[i];
384 if (supportedIsas.contains(isa)) {
385 dexUseInfo.mLoaderIsas.add(elems[i]);
386 } else {
387 // Should never happen unless someone crafts the file manually.
388 // In theory it could if we drop a supported ISA after an OTA but we don't
389 // do that.
390 Slog.wtf(TAG, "Unsupported ISA when parsing PackageDexUsage: " + isa);
391 }
392 }
393 if (supportedIsas.isEmpty()) {
394 Slog.wtf(TAG, "Ignore dexPath when parsing PackageDexUsage because of " +
395 "unsupported isas. dexPath=" + dexPath);
396 continue;
397 }
Calin Juravle535a4752017-02-03 16:55:49 -0800398 currentPackageData.mDexUseInfoMap.put(dexPath, dexUseInfo);
Calin Juravle52a452c2017-08-04 01:42:17 -0700399 } else if (line.startsWith(CODE_PATH_LINE_CHAR)) {
400 // This is a code path used by other apps line.
401 if (version < PACKAGE_DEX_USAGE_SUPPORTED_VERSION_2) {
402 throw new IllegalArgumentException("Unexpected code path line when parsing " +
403 "PackageDexUseData: " + line);
404 }
405
406 // Expects 2 lines:
407 // +code_paths
408 // @loading_packages
409 String codePath = line.substring(CODE_PATH_LINE_CHAR.length());
410 Set<String> loadingPackages = maybeReadLoadingPackages(in, version);
411 currentPackageData.mCodePathsUsedByOtherApps.put(codePath, loadingPackages);
Calin Juravle03181622016-12-01 17:53:07 +0000412 } else {
413 // This is a package line.
Calin Juravle52a452c2017-08-04 01:42:17 -0700414 if (version >= PACKAGE_DEX_USAGE_SUPPORTED_VERSION_2) {
415 currentPackage = line;
416 currentPackageData = new PackageUseInfo();
417 } else {
418 // Old version (<2)
419 // We expect it to be: `packageName,isUsedByOtherApps`.
420 String[] elems = line.split(SPLIT_CHAR);
421 if (elems.length != 2) {
422 throw new IllegalStateException("Invalid PackageDexUsage line: " + line);
423 }
424 currentPackage = elems[0];
425 currentPackageData = new PackageUseInfo();
426 currentPackageData.mUsedByOtherAppsBeforeUpgrade = readBoolean(elems[1]);
Calin Juravle03181622016-12-01 17:53:07 +0000427 }
Calin Juravle535a4752017-02-03 16:55:49 -0800428 data.put(currentPackage, currentPackageData);
Calin Juravle03181622016-12-01 17:53:07 +0000429 }
430 }
431
432 synchronized (mPackageUseInfoMap) {
433 mPackageUseInfoMap.clear();
434 mPackageUseInfoMap.putAll(data);
435 }
436 }
437
438 /**
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700439 * Reads the class loader context encoding from the buffer {@code in} if
Calin Juravle535a4752017-02-03 16:55:49 -0800440 * {@code version} is at least {PACKAGE_DEX_USAGE_VERSION}.
441 */
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700442 private String maybeReadClassLoaderContext(BufferedReader in, int version) throws IOException {
443 String context = null;
Calin Juravle52a452c2017-08-04 01:42:17 -0700444 if (version >= PACKAGE_DEX_USAGE_SUPPORTED_VERSION_2) {
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700445 context = in.readLine();
446 if (context == null) {
447 throw new IllegalStateException("Could not find the classLoaderContext line.");
448 }
449 }
450 // The context might be empty if we didn't have the chance to update it after a version
451 // upgrade. In this case return the special marker so that we recognize this is an unknown
452 // context.
453 return context == null ? UNKNOWN_CLASS_LOADER_CONTEXT : context;
454 }
455
456 /**
457 * Reads the list of loading packages from the buffer {@code in} if
458 * {@code version} is at least {PACKAGE_DEX_USAGE_SUPPORTED_VERSION_2}.
459 */
Calin Juravle52a452c2017-08-04 01:42:17 -0700460 private Set<String> maybeReadLoadingPackages(BufferedReader in, int version)
Calin Juravle535a4752017-02-03 16:55:49 -0800461 throws IOException {
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700462 if (version >= PACKAGE_DEX_USAGE_SUPPORTED_VERSION_2) {
Calin Juravle535a4752017-02-03 16:55:49 -0800463 String line = in.readLine();
464 if (line == null) {
465 throw new IllegalStateException("Could not find the loadingPackages line.");
466 }
467 // We expect that most of the times the list of loading packages will be empty.
468 if (line.length() == LOADING_PACKAGE_CHAR.length()) {
Calin Juravle52a452c2017-08-04 01:42:17 -0700469 return Collections.emptySet();
Calin Juravle535a4752017-02-03 16:55:49 -0800470 } else {
Calin Juravle52a452c2017-08-04 01:42:17 -0700471 Set<String> result = new HashSet<>();
472 Collections.addAll(result,
Calin Juravle535a4752017-02-03 16:55:49 -0800473 line.substring(LOADING_PACKAGE_CHAR.length()).split(SPLIT_CHAR));
Calin Juravle52a452c2017-08-04 01:42:17 -0700474 return result;
Calin Juravle535a4752017-02-03 16:55:49 -0800475 }
476 } else {
Calin Juravle52a452c2017-08-04 01:42:17 -0700477 return Collections.emptySet();
Calin Juravle535a4752017-02-03 16:55:49 -0800478 }
479 }
480
481 /**
482 * Utility method which adds {@param loadingPackage} to {@param loadingPackages} only if it's
483 * not equal to {@param owningPackage}
484 */
485 private boolean maybeAddLoadingPackage(String owningPackage, String loadingPackage,
486 Set<String> loadingPackages) {
487 return !owningPackage.equals(loadingPackage) && loadingPackages.add(loadingPackage);
488 }
489
490 private boolean isSupportedVersion(int version) {
Calin Juravle52a452c2017-08-04 01:42:17 -0700491 return version == PACKAGE_DEX_USAGE_SUPPORTED_VERSION_1
492 || version == PACKAGE_DEX_USAGE_SUPPORTED_VERSION_2;
Calin Juravle535a4752017-02-03 16:55:49 -0800493 }
494
495 /**
Calin Juravle03181622016-12-01 17:53:07 +0000496 * Syncs the existing data with the set of available packages by removing obsolete entries.
497 */
Calin Juravle52a452c2017-08-04 01:42:17 -0700498 /*package*/ void syncData(Map<String, Set<Integer>> packageToUsersMap,
499 Map<String, Set<String>> packageToCodePaths) {
Calin Juravle03181622016-12-01 17:53:07 +0000500 synchronized (mPackageUseInfoMap) {
501 Iterator<Map.Entry<String, PackageUseInfo>> pIt =
502 mPackageUseInfoMap.entrySet().iterator();
503 while (pIt.hasNext()) {
504 Map.Entry<String, PackageUseInfo> pEntry = pIt.next();
505 String packageName = pEntry.getKey();
506 PackageUseInfo packageUseInfo = pEntry.getValue();
507 Set<Integer> users = packageToUsersMap.get(packageName);
508 if (users == null) {
509 // The package doesn't exist anymore, remove the record.
510 pIt.remove();
511 } else {
512 // The package exists but we can prune the entries associated with non existing
513 // users.
514 Iterator<Map.Entry<String, DexUseInfo>> dIt =
515 packageUseInfo.mDexUseInfoMap.entrySet().iterator();
516 while (dIt.hasNext()) {
517 DexUseInfo dexUseInfo = dIt.next().getValue();
518 if (!users.contains(dexUseInfo.mOwnerUserId)) {
519 // User was probably removed. Delete its dex usage info.
520 dIt.remove();
521 }
522 }
Calin Juravle52a452c2017-08-04 01:42:17 -0700523
524 // Sync the code paths.
525 Set<String> codePaths = packageToCodePaths.get(packageName);
526 Iterator<Map.Entry<String, Set<String>>> codeIt =
527 packageUseInfo.mCodePathsUsedByOtherApps.entrySet().iterator();
528 while (codeIt.hasNext()) {
529 if (!codePaths.contains(codeIt.next().getKey())) {
530 codeIt.remove();
531 }
532 }
533
534 // In case the package was marked as used by other apps in a previous version
535 // propagate the flag to all the code paths.
536 // See mUsedByOtherAppsBeforeUpgrade docs on why it is important to do it.
537 if (packageUseInfo.mUsedByOtherAppsBeforeUpgrade) {
538 for (String codePath : codePaths) {
539 packageUseInfo.mergeCodePathUsedByOtherApps(codePath, true, null, null);
540 }
541 } else if (!packageUseInfo.isAnyCodePathUsedByOtherApps()
542 && packageUseInfo.mDexUseInfoMap.isEmpty()) {
Calin Juravle03181622016-12-01 17:53:07 +0000543 // The package is not used by other apps and we removed all its dex files
544 // records. Remove the entire package record as well.
545 pIt.remove();
546 }
547 }
548 }
549 }
550 }
551
Calin Juravle1aa5f882017-01-25 01:05:50 -0800552 /**
Calin Juravle99dd37b2017-02-22 19:05:06 -0800553 * Clears the {@code usesByOtherApps} marker for the package {@code packageName}.
554 * @return true if the package usage info was updated.
555 */
Calin Juravle52a452c2017-08-04 01:42:17 -0700556 /*package*/ boolean clearUsedByOtherApps(String packageName) {
Calin Juravle99dd37b2017-02-22 19:05:06 -0800557 synchronized (mPackageUseInfoMap) {
558 PackageUseInfo packageUseInfo = mPackageUseInfoMap.get(packageName);
Calin Juravle52a452c2017-08-04 01:42:17 -0700559 if (packageUseInfo == null) {
Calin Juravle99dd37b2017-02-22 19:05:06 -0800560 return false;
561 }
Calin Juravle52a452c2017-08-04 01:42:17 -0700562 return packageUseInfo.clearCodePathUsedByOtherApps();
Calin Juravle99dd37b2017-02-22 19:05:06 -0800563 }
564 }
565
566 /**
567 * Remove the usage data associated with package {@code packageName}.
568 * @return true if the package usage was found and removed successfully.
569 */
Alan Stokes58aea512018-09-21 17:26:43 +0100570 /* package */ boolean removePackage(String packageName) {
Calin Juravle99dd37b2017-02-22 19:05:06 -0800571 synchronized (mPackageUseInfoMap) {
572 return mPackageUseInfoMap.remove(packageName) != null;
573 }
574 }
575
576 /**
Calin Juravle1aa5f882017-01-25 01:05:50 -0800577 * Remove all the records about package {@code packageName} belonging to user {@code userId}.
Calin Juravle99dd37b2017-02-22 19:05:06 -0800578 * If the package is left with no records of secondary dex usage and is not used by other
579 * apps it will be removed as well.
Calin Juravleb1097412017-01-26 18:53:23 -0800580 * @return true if the record was found and actually deleted,
581 * false if the record doesn't exist
Calin Juravle1aa5f882017-01-25 01:05:50 -0800582 */
Calin Juravle52a452c2017-08-04 01:42:17 -0700583 /*package*/ boolean removeUserPackage(String packageName, int userId) {
Calin Juravle1aa5f882017-01-25 01:05:50 -0800584 synchronized (mPackageUseInfoMap) {
585 PackageUseInfo packageUseInfo = mPackageUseInfoMap.get(packageName);
586 if (packageUseInfo == null) {
587 return false;
588 }
589 boolean updated = false;
590 Iterator<Map.Entry<String, DexUseInfo>> dIt =
591 packageUseInfo.mDexUseInfoMap.entrySet().iterator();
592 while (dIt.hasNext()) {
593 DexUseInfo dexUseInfo = dIt.next().getValue();
594 if (dexUseInfo.mOwnerUserId == userId) {
595 dIt.remove();
596 updated = true;
597 }
598 }
Calin Juravle99dd37b2017-02-22 19:05:06 -0800599 // If no secondary dex info is left and the package is not used by other apps
600 // remove the data since it is now useless.
Calin Juravle52a452c2017-08-04 01:42:17 -0700601 if (packageUseInfo.mDexUseInfoMap.isEmpty()
602 && !packageUseInfo.isAnyCodePathUsedByOtherApps()) {
Calin Juravle99dd37b2017-02-22 19:05:06 -0800603 mPackageUseInfoMap.remove(packageName);
604 updated = true;
605 }
Calin Juravle1aa5f882017-01-25 01:05:50 -0800606 return updated;
607 }
608 }
609
610 /**
611 * Remove the secondary dex file record belonging to the package {@code packageName}
612 * and user {@code userId}.
Calin Juravleb1097412017-01-26 18:53:23 -0800613 * @return true if the record was found and actually deleted,
614 * false if the record doesn't exist
Calin Juravle1aa5f882017-01-25 01:05:50 -0800615 */
Calin Juravle52a452c2017-08-04 01:42:17 -0700616 /*package*/ boolean removeDexFile(String packageName, String dexFile, int userId) {
Calin Juravle1aa5f882017-01-25 01:05:50 -0800617 synchronized (mPackageUseInfoMap) {
618 PackageUseInfo packageUseInfo = mPackageUseInfoMap.get(packageName);
619 if (packageUseInfo == null) {
620 return false;
621 }
622 return removeDexFile(packageUseInfo, dexFile, userId);
623 }
624 }
625
626 private boolean removeDexFile(PackageUseInfo packageUseInfo, String dexFile, int userId) {
627 DexUseInfo dexUseInfo = packageUseInfo.mDexUseInfoMap.get(dexFile);
628 if (dexUseInfo == null) {
629 return false;
630 }
631 if (dexUseInfo.mOwnerUserId == userId) {
632 packageUseInfo.mDexUseInfoMap.remove(dexFile);
633 return true;
634 }
635 return false;
636 }
637
Calin Juravle52a452c2017-08-04 01:42:17 -0700638 /*package*/ PackageUseInfo getPackageUseInfo(String packageName) {
Calin Juravle03181622016-12-01 17:53:07 +0000639 synchronized (mPackageUseInfoMap) {
Calin Juravle1aa5f882017-01-25 01:05:50 -0800640 PackageUseInfo useInfo = mPackageUseInfoMap.get(packageName);
641 // The useInfo contains a map for secondary dex files which could be modified
642 // concurrently after this method returns and thus outside the locking we do here.
643 // (i.e. the map is updated when new class loaders are created, which can happen anytime
644 // after this method returns)
645 // Make a defensive copy to be sure we don't get concurrent modifications.
646 return useInfo == null ? null : new PackageUseInfo(useInfo);
Calin Juravle03181622016-12-01 17:53:07 +0000647 }
648 }
649
Calin Juravle51f521c2017-01-25 18:00:05 -0800650 /**
651 * Return all packages that contain records of secondary dex files.
652 */
Calin Juravle52a452c2017-08-04 01:42:17 -0700653 /*package*/ Set<String> getAllPackagesWithSecondaryDexFiles() {
Calin Juravle51f521c2017-01-25 18:00:05 -0800654 Set<String> packages = new HashSet<>();
655 synchronized (mPackageUseInfoMap) {
656 for (Map.Entry<String, PackageUseInfo> entry : mPackageUseInfoMap.entrySet()) {
657 if (!entry.getValue().mDexUseInfoMap.isEmpty()) {
658 packages.add(entry.getKey());
659 }
660 }
661 }
662 return packages;
663 }
664
Alan Stokes58aea512018-09-21 17:26:43 +0100665 /* package */ void clear() {
Calin Juravle03181622016-12-01 17:53:07 +0000666 synchronized (mPackageUseInfoMap) {
667 mPackageUseInfoMap.clear();
668 }
669 }
Alan Stokes58aea512018-09-21 17:26:43 +0100670
Calin Juravle03181622016-12-01 17:53:07 +0000671 // Creates a deep copy of the class' mPackageUseInfoMap.
672 private Map<String, PackageUseInfo> clonePackageUseInfoMap() {
673 Map<String, PackageUseInfo> clone = new HashMap<>();
674 synchronized (mPackageUseInfoMap) {
675 for (Map.Entry<String, PackageUseInfo> e : mPackageUseInfoMap.entrySet()) {
676 clone.put(e.getKey(), new PackageUseInfo(e.getValue()));
677 }
678 }
679 return clone;
680 }
681
682 private String writeBoolean(boolean bool) {
683 return bool ? "1" : "0";
684 }
685
686 private boolean readBoolean(String bool) {
687 if ("0".equals(bool)) return false;
688 if ("1".equals(bool)) return true;
689 throw new IllegalArgumentException("Unknown bool encoding: " + bool);
690 }
691
Alan Stokes58aea512018-09-21 17:26:43 +0100692 /* package */ String dump() {
Calin Juravle03181622016-12-01 17:53:07 +0000693 StringWriter sw = new StringWriter();
694 write(sw);
695 return sw.toString();
696 }
697
698 /**
699 * Stores data on how a package and its dex files are used.
700 */
701 public static class PackageUseInfo {
Calin Juravle52a452c2017-08-04 01:42:17 -0700702 // The app's code paths that are used by other apps.
703 // The key is the code path and the value is the set of loading packages.
704 private final Map<String, Set<String>> mCodePathsUsedByOtherApps;
Calin Juravle03181622016-12-01 17:53:07 +0000705 // Map dex paths to their data (isUsedByOtherApps, owner id, loader isa).
706 private final Map<String, DexUseInfo> mDexUseInfoMap;
Calin Juravle52a452c2017-08-04 01:42:17 -0700707
708 // Keeps track of whether or not this package was used by other apps before
709 // we upgraded to VERSION 4 which records the info for each code path separately.
710 // This is unwanted complexity but without it we risk to profile guide compile
711 // something that supposed to be shared. For example:
712 // 1) we determine that chrome is used by another app
713 // 2) we take an OTA which upgrades the way we keep track of usage data
714 // 3) chrome doesn't get used until the background job executes
715 // 4) as part of the backgound job we now think that chrome is not used by others
716 // and we speed-profile.
717 // 5) as a result the next time someone uses chrome it will extract from apk since
718 // the compiled code will be private.
719 private boolean mUsedByOtherAppsBeforeUpgrade;
Calin Juravle03181622016-12-01 17:53:07 +0000720
Alan Stokes6dba50d2018-10-30 15:05:36 +0000721 /*package*/ PackageUseInfo() {
Calin Juravle52a452c2017-08-04 01:42:17 -0700722 mCodePathsUsedByOtherApps = new HashMap<>();
Calin Juravle03181622016-12-01 17:53:07 +0000723 mDexUseInfoMap = new HashMap<>();
724 }
725
726 // Creates a deep copy of the `other`.
Alan Stokes6dba50d2018-10-30 15:05:36 +0000727 private PackageUseInfo(PackageUseInfo other) {
Calin Juravle52a452c2017-08-04 01:42:17 -0700728 mCodePathsUsedByOtherApps = new HashMap<>();
729 for (Map.Entry<String, Set<String>> e : other.mCodePathsUsedByOtherApps.entrySet()) {
730 mCodePathsUsedByOtherApps.put(e.getKey(), new HashSet<>(e.getValue()));
731 }
732
Calin Juravle03181622016-12-01 17:53:07 +0000733 mDexUseInfoMap = new HashMap<>();
734 for (Map.Entry<String, DexUseInfo> e : other.mDexUseInfoMap.entrySet()) {
735 mDexUseInfoMap.put(e.getKey(), new DexUseInfo(e.getValue()));
736 }
737 }
738
Calin Juravle52a452c2017-08-04 01:42:17 -0700739 private boolean mergeCodePathUsedByOtherApps(String codePath, boolean isUsedByOtherApps,
740 String owningPackageName, String loadingPackage) {
741 if (!isUsedByOtherApps) {
742 // Nothing to update if the the code path is not used by other apps.
743 return false;
744 }
745
746 boolean newCodePath = false;
747 Set<String> loadingPackages = mCodePathsUsedByOtherApps.get(codePath);
748 if (loadingPackages == null) {
749 loadingPackages = new HashSet<>();
750 mCodePathsUsedByOtherApps.put(codePath, loadingPackages);
751 newCodePath = true;
752 }
753 boolean newLoadingPackage = loadingPackage != null
754 && !loadingPackage.equals(owningPackageName)
755 && loadingPackages.add(loadingPackage);
756 return newCodePath || newLoadingPackage;
Calin Juravle03181622016-12-01 17:53:07 +0000757 }
758
Calin Juravle52a452c2017-08-04 01:42:17 -0700759 public boolean isUsedByOtherApps(String codePath) {
760 return mCodePathsUsedByOtherApps.containsKey(codePath);
Calin Juravle03181622016-12-01 17:53:07 +0000761 }
762
763 public Map<String, DexUseInfo> getDexUseInfoMap() {
764 return mDexUseInfoMap;
765 }
Calin Juravle535a4752017-02-03 16:55:49 -0800766
Calin Juravle52a452c2017-08-04 01:42:17 -0700767 public Set<String> getLoadingPackages(String codePath) {
768 return mCodePathsUsedByOtherApps.getOrDefault(codePath, null);
769 }
770
771 public boolean isAnyCodePathUsedByOtherApps() {
772 return !mCodePathsUsedByOtherApps.isEmpty();
773 }
774
775 /**
776 * Clears the usedByOtherApps markers from all code paths.
777 * Returns whether or not there was an update.
778 */
779 /*package*/ boolean clearCodePathUsedByOtherApps() {
780 // Update mUsedByOtherAppsBeforeUpgrade as well to be consistent with
781 // the new data. This is not saved to disk so we don't need to return it.
782 mUsedByOtherAppsBeforeUpgrade = true;
783
784 if (mCodePathsUsedByOtherApps.isEmpty()) {
785 return false;
786 } else {
787 mCodePathsUsedByOtherApps.clear();
788 return true;
789 }
Calin Juravle535a4752017-02-03 16:55:49 -0800790 }
Calin Juravle03181622016-12-01 17:53:07 +0000791 }
792
793 /**
794 * Stores data about a loaded dex files.
795 */
796 public static class DexUseInfo {
797 private boolean mIsUsedByOtherApps;
798 private final int mOwnerUserId;
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700799 // The class loader context for the dex file. This encodes the class loader chain
800 // (class loader type + class path) in a format compatible to dex2oat.
801 // See {@code DexoptUtils.processContextForDexLoad}.
802 private String mClassLoaderContext;
803 // The instructions sets of the applications loading the dex file.
Calin Juravle03181622016-12-01 17:53:07 +0000804 private final Set<String> mLoaderIsas;
Calin Juravle535a4752017-02-03 16:55:49 -0800805 // Packages who load this dex file.
806 private final Set<String> mLoadingPackages;
Calin Juravle03181622016-12-01 17:53:07 +0000807
Alan Stokes6dba50d2018-10-30 15:05:36 +0000808 @VisibleForTesting
809 /* package */ DexUseInfo(boolean isUsedByOtherApps, int ownerUserId,
810 String classLoaderContext, String loaderIsa) {
Calin Juravle03181622016-12-01 17:53:07 +0000811 mIsUsedByOtherApps = isUsedByOtherApps;
812 mOwnerUserId = ownerUserId;
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700813 mClassLoaderContext = classLoaderContext;
Calin Juravle03181622016-12-01 17:53:07 +0000814 mLoaderIsas = new HashSet<>();
815 if (loaderIsa != null) {
816 mLoaderIsas.add(loaderIsa);
817 }
Calin Juravle535a4752017-02-03 16:55:49 -0800818 mLoadingPackages = new HashSet<>();
Calin Juravle03181622016-12-01 17:53:07 +0000819 }
820
821 // Creates a deep copy of the `other`.
Alan Stokes6dba50d2018-10-30 15:05:36 +0000822 private DexUseInfo(DexUseInfo other) {
Calin Juravle03181622016-12-01 17:53:07 +0000823 mIsUsedByOtherApps = other.mIsUsedByOtherApps;
824 mOwnerUserId = other.mOwnerUserId;
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700825 mClassLoaderContext = other.mClassLoaderContext;
Calin Juravle03181622016-12-01 17:53:07 +0000826 mLoaderIsas = new HashSet<>(other.mLoaderIsas);
Calin Juravle535a4752017-02-03 16:55:49 -0800827 mLoadingPackages = new HashSet<>(other.mLoadingPackages);
Calin Juravle03181622016-12-01 17:53:07 +0000828 }
829
830 private boolean merge(DexUseInfo dexUseInfo) {
831 boolean oldIsUsedByOtherApps = mIsUsedByOtherApps;
832 mIsUsedByOtherApps = mIsUsedByOtherApps || dexUseInfo.mIsUsedByOtherApps;
833 boolean updateIsas = mLoaderIsas.addAll(dexUseInfo.mLoaderIsas);
Calin Juravle535a4752017-02-03 16:55:49 -0800834 boolean updateLoadingPackages = mLoadingPackages.addAll(dexUseInfo.mLoadingPackages);
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700835
836 String oldClassLoaderContext = mClassLoaderContext;
837 if (UNKNOWN_CLASS_LOADER_CONTEXT.equals(mClassLoaderContext)) {
838 // Can happen if we read a previous version.
839 mClassLoaderContext = dexUseInfo.mClassLoaderContext;
Alan Stokes6dba50d2018-10-30 15:05:36 +0000840 } else if (!Objects.equals(mClassLoaderContext, dexUseInfo.mClassLoaderContext)) {
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700841 // We detected a context change.
842 mClassLoaderContext = VARIABLE_CLASS_LOADER_CONTEXT;
843 }
844
845 return updateIsas ||
846 (oldIsUsedByOtherApps != mIsUsedByOtherApps) ||
847 updateLoadingPackages
Narayan Kamath607223f2018-02-19 14:09:02 +0000848 || !Objects.equals(oldClassLoaderContext, mClassLoaderContext);
Calin Juravle03181622016-12-01 17:53:07 +0000849 }
850
851 public boolean isUsedByOtherApps() {
852 return mIsUsedByOtherApps;
853 }
854
Alan Stokes6dba50d2018-10-30 15:05:36 +0000855 /* package */ int getOwnerUserId() {
Calin Juravle03181622016-12-01 17:53:07 +0000856 return mOwnerUserId;
857 }
858
859 public Set<String> getLoaderIsas() {
860 return mLoaderIsas;
861 }
Calin Juravle535a4752017-02-03 16:55:49 -0800862
863 public Set<String> getLoadingPackages() {
864 return mLoadingPackages;
865 }
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700866
867 public String getClassLoaderContext() { return mClassLoaderContext; }
868
Alan Stokes6dba50d2018-10-30 15:05:36 +0000869 @VisibleForTesting
870 /* package */ boolean isUnknownClassLoaderContext() {
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700871 // The class loader context may be unknown if we loaded the data from a previous version
872 // which didn't save the context.
873 return UNKNOWN_CLASS_LOADER_CONTEXT.equals(mClassLoaderContext);
874 }
875
Alan Stokes6dba50d2018-10-30 15:05:36 +0000876 @VisibleForTesting
877 /* package */ boolean isVariableClassLoaderContext() {
Calin Juravlef1ff36f2017-07-22 12:33:41 -0700878 return VARIABLE_CLASS_LOADER_CONTEXT.equals(mClassLoaderContext);
879 }
Calin Juravle03181622016-12-01 17:53:07 +0000880 }
881}