Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6a3b2d2b authored by David Brazdil's avatar David Brazdil
Browse files

Refactor return values of performDexOpt

PackageDexOptimizer.performDexOpt would return DEX_OPT_PERFORMED if
dexopt succeeded on the package and DEX_OPT_SKIPPED otherwise, even
if dexopt failed. This patch fixes that and cleans up the code.

PackageManagerService.performDexOpt* would return true only if
PackageDexOptimizer.performDexOpt returned DEX_OPT_PERFORMED.
Consequently, it would return false when dexopt was not needed. This
patch refactors the code to return true unless PackageDexOptimizer
returns DEX_OPT_FAILED and documents the behaviour.

Bug: 28082762
Change-Id: Ica73e67ab02025ef5619746bb8c465c96b72846b
parent 37a87698
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ class PackageDexOptimizer {
    // TODO b/19550105 Remove error codes and use exceptions
    static final int DEX_OPT_SKIPPED = 0;
    static final int DEX_OPT_PERFORMED = 1;
    static final int DEX_OPT_DEFERRED = 2;
    static final int DEX_OPT_FAILED = -1;

    private final Installer mInstaller;
@@ -170,6 +169,8 @@ class PackageDexOptimizer {
        final boolean debuggable = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;

        boolean performedDexOpt = false;
        boolean successfulDexOpt = true;

        final String[] dexCodeInstructionSets = getDexCodeInstructionSets(instructionSets);
        for (String dexCodeInstructionSet : dexCodeInstructionSets) {
            for (String path : paths) {
@@ -226,15 +227,20 @@ class PackageDexOptimizer {
                    performedDexOpt = true;
                } catch (InstallerException e) {
                    Slog.w(TAG, "Failed to dexopt", e);
                    successfulDexOpt = false;
                }
            }
        }

        // If we've gotten here, we're sure that no error occurred and that we haven't
        // deferred dex-opt. We've either dex-opted one more paths or instruction sets or
        // we've skipped all of them because they are up to date. In both cases this
        // package doesn't need dexopt any longer.
        if (successfulDexOpt) {
            // If we've gotten here, we're sure that no error occurred. We've either
            // dex-opted one or more paths or instruction sets or we've skipped
            // all of them because they are up to date. In both cases this package
            // doesn't need dexopt any longer.
            return performedDexOpt ? DEX_OPT_PERFORMED : DEX_OPT_SKIPPED;
        } else {
            return DEX_OPT_FAILED;
        }
    }

    /**
+3 −1
Original line number Diff line number Diff line
@@ -7147,6 +7147,8 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
    }
    // Run dexopt on a given package. Returns true if dexopt did not fail, i.e.
    // if the package can now be considered up to date for the given filter.
    private boolean performDexOptInternal(String packageName, String instructionSet,
                boolean checkProfiles, String targetCompilerFilter, boolean force) {
        PackageParser.Package p;
@@ -7167,7 +7169,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                final String[] instructionSets = new String[] { targetInstructionSet };
                int result = performDexOptInternalWithDependenciesLI(p, instructionSets,
                        checkProfiles, targetCompilerFilter, force);
                return result == PackageDexOptimizer.DEX_OPT_PERFORMED;
                return result != PackageDexOptimizer.DEX_OPT_FAILED;
            }
        } finally {
            Binder.restoreCallingIdentity(callingId);