PackageDexOptimizer.java revision 0a267a884ed04d3baf77ed7e5f6467879d035d33
1/*
2 * Copyright (C) 2015 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;
18
19import android.annotation.Nullable;
20import android.content.Context;
21import android.content.pm.ApplicationInfo;
22import android.content.pm.PackageParser;
23import android.os.FileUtils;
24import android.os.PowerManager;
25import android.os.SystemClock;
26import android.os.SystemProperties;
27import android.os.UserHandle;
28import android.os.WorkSource;
29import android.util.Log;
30import android.util.Slog;
31
32import com.android.internal.annotations.GuardedBy;
33import com.android.internal.util.IndentingPrintWriter;
34import com.android.server.pm.Installer.InstallerException;
35import com.android.server.pm.dex.DexoptOptions;
36import com.android.server.pm.dex.DexoptUtils;
37
38import java.io.File;
39import java.io.IOException;
40import java.util.ArrayList;
41import java.util.List;
42import java.util.Set;
43
44import dalvik.system.DexFile;
45
46import static com.android.server.pm.Installer.DEXOPT_BOOTCOMPLETE;
47import static com.android.server.pm.Installer.DEXOPT_DEBUGGABLE;
48import static com.android.server.pm.Installer.DEXOPT_PROFILE_GUIDED;
49import static com.android.server.pm.Installer.DEXOPT_PUBLIC;
50import static com.android.server.pm.Installer.DEXOPT_SECONDARY_DEX;
51import static com.android.server.pm.Installer.DEXOPT_FORCE;
52import static com.android.server.pm.Installer.DEXOPT_STORAGE_CE;
53import static com.android.server.pm.Installer.DEXOPT_STORAGE_DE;
54import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
55import static com.android.server.pm.InstructionSets.getDexCodeInstructionSets;
56
57import static com.android.server.pm.PackageManagerService.WATCHDOG_TIMEOUT;
58
59import static dalvik.system.DexFile.getNonProfileGuidedCompilerFilter;
60import static dalvik.system.DexFile.getSafeModeCompilerFilter;
61import static dalvik.system.DexFile.isProfileGuidedCompilerFilter;
62
63/**
64 * Helper class for running dexopt command on packages.
65 */
66public class PackageDexOptimizer {
67    private static final String TAG = "PackageManager.DexOptimizer";
68    static final String OAT_DIR_NAME = "oat";
69    // TODO b/19550105 Remove error codes and use exceptions
70    public static final int DEX_OPT_SKIPPED = 0;
71    public static final int DEX_OPT_PERFORMED = 1;
72    public static final int DEX_OPT_FAILED = -1;
73    // One minute over PM WATCHDOG_TIMEOUT
74    private static final long WAKELOCK_TIMEOUT_MS = WATCHDOG_TIMEOUT + 1000 * 60;
75
76    /** Special library name that skips shared libraries check during compilation. */
77    public static final String SKIP_SHARED_LIBRARY_CHECK = "&";
78
79    @GuardedBy("mInstallLock")
80    private final Installer mInstaller;
81    private final Object mInstallLock;
82
83    @GuardedBy("mInstallLock")
84    private final PowerManager.WakeLock mDexoptWakeLock;
85    private volatile boolean mSystemReady;
86
87    PackageDexOptimizer(Installer installer, Object installLock, Context context,
88            String wakeLockTag) {
89        this.mInstaller = installer;
90        this.mInstallLock = installLock;
91
92        PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
93        mDexoptWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, wakeLockTag);
94    }
95
96    protected PackageDexOptimizer(PackageDexOptimizer from) {
97        this.mInstaller = from.mInstaller;
98        this.mInstallLock = from.mInstallLock;
99        this.mDexoptWakeLock = from.mDexoptWakeLock;
100        this.mSystemReady = from.mSystemReady;
101    }
102
103    static boolean canOptimizePackage(PackageParser.Package pkg) {
104        // We do not dexopt a package with no code.
105        if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) == 0) {
106            return false;
107        }
108
109        // We do not dexopt a priv-app package when pm.dexopt.priv-apps is false.
110        if (pkg.isPrivilegedApp()) {
111            return SystemProperties.getBoolean("pm.dexopt.priv-apps", true);
112        }
113
114        return true;
115    }
116
117    /**
118     * Performs dexopt on all code paths and libraries of the specified package for specified
119     * instruction sets.
120     *
121     * <p>Calls to {@link com.android.server.pm.Installer#dexopt} on {@link #mInstaller} are
122     * synchronized on {@link #mInstallLock}.
123     */
124    int performDexOpt(PackageParser.Package pkg, String[] sharedLibraries,
125            String[] instructionSets, CompilerStats.PackageStats packageStats,
126            boolean isUsedByOtherApps, DexoptOptions options) {
127        if (!canOptimizePackage(pkg)) {
128            return DEX_OPT_SKIPPED;
129        }
130        synchronized (mInstallLock) {
131            final long acquireTime = acquireWakeLockLI(pkg.applicationInfo.uid);
132            try {
133                return performDexOptLI(pkg, sharedLibraries, instructionSets,
134                        packageStats, isUsedByOtherApps, options);
135            } finally {
136                releaseWakeLockLI(acquireTime);
137            }
138        }
139    }
140
141    /**
142     * Performs dexopt on all code paths of the given package.
143     * It assumes the install lock is held.
144     */
145    @GuardedBy("mInstallLock")
146    private int performDexOptLI(PackageParser.Package pkg, String[] sharedLibraries,
147            String[] targetInstructionSets, CompilerStats.PackageStats packageStats,
148            boolean isUsedByOtherApps, DexoptOptions options) {
149        final String[] instructionSets = targetInstructionSets != null ?
150                targetInstructionSets : getAppDexInstructionSets(pkg.applicationInfo);
151        final String[] dexCodeInstructionSets = getDexCodeInstructionSets(instructionSets);
152        final List<String> paths = pkg.getAllCodePaths();
153        final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid);
154
155        final String compilerFilter = getRealCompilerFilter(pkg.applicationInfo,
156                options.getCompilerFilter(), isUsedByOtherApps);
157        final boolean profileUpdated = options.isCheckForProfileUpdates() &&
158                isProfileUpdated(pkg, sharedGid, compilerFilter);
159
160        // Get the dexopt flags after getRealCompilerFilter to make sure we get the correct flags.
161        final int dexoptFlags = getDexFlags(pkg, compilerFilter, options.isBootComplete());
162
163        // Get the class loader context dependencies.
164        // For each code path in the package, this array contains the class loader context that
165        // needs to be passed to dexopt in order to ensure correct optimizations.
166        String[] classLoaderContexts = DexoptUtils.getClassLoaderContexts(
167                pkg.applicationInfo, sharedLibraries);
168
169        int result = DEX_OPT_SKIPPED;
170        for (int i = 0; i < paths.size(); i++) {
171            // Skip paths that have no code.
172            if ((i == 0 && (pkg.applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) == 0) ||
173                    (i != 0 && (pkg.splitFlags[i - 1] & ApplicationInfo.FLAG_HAS_CODE) == 0)) {
174                continue;
175            }
176            // Append shared libraries with split dependencies for this split.
177            String path = paths.get(i);
178            if (options.getSplitName() != null) {
179                // We are asked to compile only a specific split. Check that the current path is
180                // what we are looking for.
181                if (!options.getSplitName().equals(new File(path).getName())) {
182                    continue;
183                }
184            }
185
186            for (String dexCodeIsa : dexCodeInstructionSets) {
187                int newResult = dexOptPath(pkg, path, dexCodeIsa, compilerFilter,
188                        profileUpdated, classLoaderContexts[i], dexoptFlags, sharedGid,
189                        packageStats, options.isDowngrade());
190                // The end result is:
191                //  - FAILED if any path failed,
192                //  - PERFORMED if at least one path needed compilation,
193                //  - SKIPPED when all paths are up to date
194                if ((result != DEX_OPT_FAILED) && (newResult != DEX_OPT_SKIPPED)) {
195                    result = newResult;
196                }
197            }
198        }
199        return result;
200    }
201
202    /**
203     * Performs dexopt on the {@code path} belonging to the package {@code pkg}.
204     *
205     * @return
206     *      DEX_OPT_FAILED if there was any exception during dexopt
207     *      DEX_OPT_PERFORMED if dexopt was performed successfully on the given path.
208     *      DEX_OPT_SKIPPED if the path does not need to be deopt-ed.
209     */
210    @GuardedBy("mInstallLock")
211    private int dexOptPath(PackageParser.Package pkg, String path, String isa,
212            String compilerFilter, boolean profileUpdated, String sharedLibrariesPath,
213            int dexoptFlags, int uid, CompilerStats.PackageStats packageStats, boolean downgrade) {
214        int dexoptNeeded = getDexoptNeeded(path, isa, compilerFilter, profileUpdated, downgrade);
215        if (Math.abs(dexoptNeeded) == DexFile.NO_DEXOPT_NEEDED) {
216            return DEX_OPT_SKIPPED;
217        }
218
219        // TODO(calin): there's no need to try to create the oat dir over and over again,
220        //              especially since it involve an extra installd call. We should create
221        //              if (if supported) on the fly during the dexopt call.
222        String oatDir = createOatDirIfSupported(pkg, isa);
223
224        Log.i(TAG, "Running dexopt (dexoptNeeded=" + dexoptNeeded + ") on: " + path
225                + " pkg=" + pkg.applicationInfo.packageName + " isa=" + isa
226                + " dexoptFlags=" + printDexoptFlags(dexoptFlags)
227                + " target-filter=" + compilerFilter + " oatDir=" + oatDir
228                + " sharedLibraries=" + sharedLibrariesPath);
229
230        try {
231            long startTime = System.currentTimeMillis();
232
233            // TODO: Consider adding 2 different APIs for primary and secondary dexopt.
234            // installd only uses downgrade flag for secondary dex files and ignores it for
235            // primary dex files.
236            mInstaller.dexopt(path, uid, pkg.packageName, isa, dexoptNeeded, oatDir, dexoptFlags,
237                    compilerFilter, pkg.volumeUuid, sharedLibrariesPath, pkg.applicationInfo.seInfo,
238                    false /* downgrade*/);
239
240            if (packageStats != null) {
241                long endTime = System.currentTimeMillis();
242                packageStats.setCompileTime(path, (int)(endTime - startTime));
243            }
244            return DEX_OPT_PERFORMED;
245        } catch (InstallerException e) {
246            Slog.w(TAG, "Failed to dexopt", e);
247            return DEX_OPT_FAILED;
248        }
249    }
250
251    /**
252     * Performs dexopt on the secondary dex {@code path} belonging to the app {@code info}.
253     *
254     * @return
255     *      DEX_OPT_FAILED if there was any exception during dexopt
256     *      DEX_OPT_PERFORMED if dexopt was performed successfully on the given path.
257     * NOTE that DEX_OPT_PERFORMED for secondary dex files includes the case when the dex file
258     * didn't need an update. That's because at the moment we don't get more than success/failure
259     * from installd.
260     *
261     * TODO(calin): Consider adding return codes to installd dexopt invocation (rather than
262     * throwing exceptions). Or maybe make a separate call to installd to get DexOptNeeded, though
263     * that seems wasteful.
264     */
265    public int dexOptSecondaryDexPath(ApplicationInfo info, String path, Set<String> isas,
266            String compilerFilter, boolean isUsedByOtherApps, boolean downgrade) {
267        synchronized (mInstallLock) {
268            final long acquireTime = acquireWakeLockLI(info.uid);
269            try {
270                return dexOptSecondaryDexPathLI(info, path, isas, compilerFilter,
271                        isUsedByOtherApps, downgrade);
272            } finally {
273                releaseWakeLockLI(acquireTime);
274            }
275        }
276    }
277
278    @GuardedBy("mInstallLock")
279    private long acquireWakeLockLI(final int uid) {
280        // During boot the system doesn't need to instantiate and obtain a wake lock.
281        // PowerManager might not be ready, but that doesn't mean that we can't proceed with
282        // dexopt.
283        if (!mSystemReady) {
284            return -1;
285        }
286        mDexoptWakeLock.setWorkSource(new WorkSource(uid));
287        mDexoptWakeLock.acquire(WAKELOCK_TIMEOUT_MS);
288        return SystemClock.elapsedRealtime();
289    }
290
291    @GuardedBy("mInstallLock")
292    private void releaseWakeLockLI(final long acquireTime) {
293        if (acquireTime < 0) {
294            return;
295        }
296        try {
297            if (mDexoptWakeLock.isHeld()) {
298                mDexoptWakeLock.release();
299            }
300            final long duration = SystemClock.elapsedRealtime() - acquireTime;
301            if (duration >= WAKELOCK_TIMEOUT_MS) {
302                Slog.wtf(TAG, "WakeLock " + mDexoptWakeLock.getTag()
303                        + " time out. Operation took " + duration + " ms. Thread: "
304                        + Thread.currentThread().getName());
305            }
306        } catch (Exception e) {
307            Slog.wtf(TAG, "Error while releasing " + mDexoptWakeLock.getTag() + " lock", e);
308        }
309    }
310
311    @GuardedBy("mInstallLock")
312    private int dexOptSecondaryDexPathLI(ApplicationInfo info, String path, Set<String> isas,
313            String compilerFilter, boolean isUsedByOtherApps, boolean downgrade) {
314        compilerFilter = getRealCompilerFilter(info, compilerFilter, isUsedByOtherApps);
315        // Get the dexopt flags after getRealCompilerFilter to make sure we get the correct flags.
316        // Secondary dex files are currently not compiled at boot.
317        int dexoptFlags = getDexFlags(info, compilerFilter, /* bootComplete */ true)
318                | DEXOPT_SECONDARY_DEX;
319        // Check the app storage and add the appropriate flags.
320        if (info.deviceProtectedDataDir != null &&
321                FileUtils.contains(info.deviceProtectedDataDir, path)) {
322            dexoptFlags |= DEXOPT_STORAGE_DE;
323        } else if (info.credentialProtectedDataDir != null &&
324                FileUtils.contains(info.credentialProtectedDataDir, path)) {
325            dexoptFlags |= DEXOPT_STORAGE_CE;
326        } else {
327            Slog.e(TAG, "Could not infer CE/DE storage for package " + info.packageName);
328            return DEX_OPT_FAILED;
329        }
330        Log.d(TAG, "Running dexopt on: " + path
331                + " pkg=" + info.packageName + " isa=" + isas
332                + " dexoptFlags=" + printDexoptFlags(dexoptFlags)
333                + " target-filter=" + compilerFilter);
334
335        try {
336            for (String isa : isas) {
337                // Reuse the same dexopt path as for the primary apks. We don't need all the
338                // arguments as some (dexopNeeded and oatDir) will be computed by installd because
339                // system server cannot read untrusted app content.
340                // TODO(calin): maybe add a separate call.
341                mInstaller.dexopt(path, info.uid, info.packageName, isa, /*dexoptNeeded*/ 0,
342                        /*oatDir*/ null, dexoptFlags,
343                        compilerFilter, info.volumeUuid, SKIP_SHARED_LIBRARY_CHECK, info.seInfoUser,
344                        downgrade);
345            }
346
347            return DEX_OPT_PERFORMED;
348        } catch (InstallerException e) {
349            Slog.w(TAG, "Failed to dexopt", e);
350            return DEX_OPT_FAILED;
351        }
352    }
353
354    /**
355     * Adjust the given dexopt-needed value. Can be overridden to influence the decision to
356     * optimize or not (and in what way).
357     */
358    protected int adjustDexoptNeeded(int dexoptNeeded) {
359        return dexoptNeeded;
360    }
361
362    /**
363     * Adjust the given dexopt flags that will be passed to the installer.
364     */
365    protected int adjustDexoptFlags(int dexoptFlags) {
366        return dexoptFlags;
367    }
368
369    /**
370     * Dumps the dexopt state of the given package {@code pkg} to the given {@code PrintWriter}.
371     */
372    void dumpDexoptState(IndentingPrintWriter pw, PackageParser.Package pkg) {
373        final String[] instructionSets = getAppDexInstructionSets(pkg.applicationInfo);
374        final String[] dexCodeInstructionSets = getDexCodeInstructionSets(instructionSets);
375
376        final List<String> paths = pkg.getAllCodePathsExcludingResourceOnly();
377
378        for (String instructionSet : dexCodeInstructionSets) {
379             pw.println("Instruction Set: " + instructionSet);
380             pw.increaseIndent();
381             for (String path : paths) {
382                  String status = null;
383                  try {
384                      status = DexFile.getDexFileStatus(path, instructionSet);
385                  } catch (IOException ioe) {
386                      status = "[Exception]: " + ioe.getMessage();
387                  }
388                  pw.println("path: " + path);
389                  pw.println("status: " + status);
390             }
391             pw.decreaseIndent();
392        }
393    }
394
395    /**
396     * Returns the compiler filter that should be used to optimize the package code.
397     * The target filter will be updated if the package code is used by other apps
398     * or if it has the safe mode flag set.
399     */
400    private String getRealCompilerFilter(ApplicationInfo info, String targetCompilerFilter,
401            boolean isUsedByOtherApps) {
402        int flags = info.flags;
403        boolean vmSafeMode = (flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0;
404        if (vmSafeMode) {
405            return getSafeModeCompilerFilter(targetCompilerFilter);
406        }
407
408        if (isProfileGuidedCompilerFilter(targetCompilerFilter) && isUsedByOtherApps) {
409            // If the dex files is used by other apps, we cannot use profile-guided compilation.
410            return getNonProfileGuidedCompilerFilter(targetCompilerFilter);
411        }
412
413        return targetCompilerFilter;
414    }
415
416    /**
417     * Computes the dex flags that needs to be pass to installd for the given package and compiler
418     * filter.
419     */
420    private int getDexFlags(PackageParser.Package pkg, String compilerFilter,
421            boolean bootComplete) {
422        return getDexFlags(pkg.applicationInfo, compilerFilter, bootComplete);
423    }
424
425    private int getDexFlags(ApplicationInfo info, String compilerFilter, boolean bootComplete) {
426        int flags = info.flags;
427        boolean debuggable = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
428        // Profile guide compiled oat files should not be public.
429        boolean isProfileGuidedFilter = isProfileGuidedCompilerFilter(compilerFilter);
430        boolean isPublic = !info.isForwardLocked() && !isProfileGuidedFilter;
431        int profileFlag = isProfileGuidedFilter ? DEXOPT_PROFILE_GUIDED : 0;
432        int dexFlags =
433                (isPublic ? DEXOPT_PUBLIC : 0)
434                | (debuggable ? DEXOPT_DEBUGGABLE : 0)
435                | profileFlag
436                | (bootComplete ? DEXOPT_BOOTCOMPLETE : 0);
437        return adjustDexoptFlags(dexFlags);
438    }
439
440    /**
441     * Assesses if there's a need to perform dexopt on {@code path} for the given
442     * configuration (isa, compiler filter, profile).
443     */
444    private int getDexoptNeeded(String path, String isa, String compilerFilter,
445            boolean newProfile, boolean downgrade) {
446        int dexoptNeeded;
447        try {
448            dexoptNeeded = DexFile.getDexOptNeeded(path, isa, compilerFilter, newProfile,
449                    downgrade);
450        } catch (IOException ioe) {
451            Slog.w(TAG, "IOException reading apk: " + path, ioe);
452            return DEX_OPT_FAILED;
453        }
454        return adjustDexoptNeeded(dexoptNeeded);
455    }
456
457    /**
458     * Checks if there is an update on the profile information of the {@code pkg}.
459     * If the compiler filter is not profile guided the method returns false.
460     *
461     * Note that this is a "destructive" operation with side effects. Under the hood the
462     * current profile and the reference profile will be merged and subsequent calls
463     * may return a different result.
464     */
465    private boolean isProfileUpdated(PackageParser.Package pkg, int uid, String compilerFilter) {
466        // Check if we are allowed to merge and if the compiler filter is profile guided.
467        if (!isProfileGuidedCompilerFilter(compilerFilter)) {
468            return false;
469        }
470        // Merge profiles. It returns whether or not there was an updated in the profile info.
471        try {
472            return mInstaller.mergeProfiles(uid, pkg.packageName);
473        } catch (InstallerException e) {
474            Slog.w(TAG, "Failed to merge profiles", e);
475        }
476        return false;
477    }
478
479    /**
480     * Creates oat dir for the specified package if needed and supported.
481     * In certain cases oat directory
482     * <strong>cannot</strong> be created:
483     * <ul>
484     *      <li>{@code pkg} is a system app, which is not updated.</li>
485     *      <li>Package location is not a directory, i.e. monolithic install.</li>
486     * </ul>
487     *
488     * @return Absolute path to the oat directory or null, if oat directory
489     * cannot be created.
490     */
491    @Nullable
492    private String createOatDirIfSupported(PackageParser.Package pkg, String dexInstructionSet) {
493        if (!pkg.canHaveOatDir()) {
494            return null;
495        }
496        File codePath = new File(pkg.codePath);
497        if (codePath.isDirectory()) {
498            // TODO(calin): why do we create this only if the codePath is a directory? (i.e for
499            //              cluster packages). It seems that the logic for the folder creation is
500            //              split between installd and here.
501            File oatDir = getOatDir(codePath);
502            try {
503                mInstaller.createOatDir(oatDir.getAbsolutePath(), dexInstructionSet);
504            } catch (InstallerException e) {
505                Slog.w(TAG, "Failed to create oat dir", e);
506                return null;
507            }
508            return oatDir.getAbsolutePath();
509        }
510        return null;
511    }
512
513    static File getOatDir(File codePath) {
514        return new File(codePath, OAT_DIR_NAME);
515    }
516
517    void systemReady() {
518        mSystemReady = true;
519    }
520
521    private String printDexoptFlags(int flags) {
522        ArrayList<String> flagsList = new ArrayList<>();
523
524        if ((flags & DEXOPT_BOOTCOMPLETE) == DEXOPT_BOOTCOMPLETE) {
525            flagsList.add("boot_complete");
526        }
527        if ((flags & DEXOPT_DEBUGGABLE) == DEXOPT_DEBUGGABLE) {
528            flagsList.add("debuggable");
529        }
530        if ((flags & DEXOPT_PROFILE_GUIDED) == DEXOPT_PROFILE_GUIDED) {
531            flagsList.add("profile_guided");
532        }
533        if ((flags & DEXOPT_PUBLIC) == DEXOPT_PUBLIC) {
534            flagsList.add("public");
535        }
536        if ((flags & DEXOPT_SECONDARY_DEX) == DEXOPT_SECONDARY_DEX) {
537            flagsList.add("secondary");
538        }
539        if ((flags & DEXOPT_FORCE) == DEXOPT_FORCE) {
540            flagsList.add("force");
541        }
542        if ((flags & DEXOPT_STORAGE_CE) == DEXOPT_STORAGE_CE) {
543            flagsList.add("storage_ce");
544        }
545        if ((flags & DEXOPT_STORAGE_DE) == DEXOPT_STORAGE_DE) {
546            flagsList.add("storage_de");
547        }
548
549        return String.join(",", flagsList);
550    }
551
552    /**
553     * A specialized PackageDexOptimizer that overrides already-installed checks, forcing a
554     * dexopt path.
555     */
556    public static class ForcedUpdatePackageDexOptimizer extends PackageDexOptimizer {
557
558        public ForcedUpdatePackageDexOptimizer(Installer installer, Object installLock,
559                Context context, String wakeLockTag) {
560            super(installer, installLock, context, wakeLockTag);
561        }
562
563        public ForcedUpdatePackageDexOptimizer(PackageDexOptimizer from) {
564            super(from);
565        }
566
567        @Override
568        protected int adjustDexoptNeeded(int dexoptNeeded) {
569            if (dexoptNeeded == DexFile.NO_DEXOPT_NEEDED) {
570                // Ensure compilation by pretending a compiler filter change on the
571                // apk/odex location (the reason for the '-'. A positive value means
572                // the 'oat' location).
573                return -DexFile.DEX2OAT_FOR_FILTER;
574            }
575            return dexoptNeeded;
576        }
577
578        @Override
579        protected int adjustDexoptFlags(int flags) {
580            // Add DEXOPT_FORCE flag to signal installd that it should force compilation
581            // and discard dexoptanalyzer result.
582            return flags | DEXOPT_FORCE;
583        }
584    }
585}
586