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

Commit 2ee2bcfd authored by Alan Stokes's avatar Alan Stokes Committed by Android (Google) Code Review
Browse files

Merge "Don't hold install lock while hashing dynamic code files."

parents 3d375dbd 60876386
Loading
Loading
Loading
Loading
+13 −15
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.util.PackageUtils;
import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.pm.Installer;
import com.android.server.pm.Installer.InstallerException;
@@ -53,21 +52,18 @@ public class DexLogger {

    private final IPackageManager mPackageManager;
    private final PackageDynamicCodeLoading mPackageDynamicCodeLoading;
    private final Object mInstallLock;
    @GuardedBy("mInstallLock")
    private final Installer mInstaller;

    public DexLogger(IPackageManager pms, Installer installer, Object installLock) {
        this(pms, installer, installLock, new PackageDynamicCodeLoading());
    public DexLogger(IPackageManager pms, Installer installer) {
        this(pms, installer, new PackageDynamicCodeLoading());
    }

    @VisibleForTesting
    DexLogger(IPackageManager pms, Installer installer, Object installLock,
    DexLogger(IPackageManager pms, Installer installer,
            PackageDynamicCodeLoading packageDynamicCodeLoading) {
        mPackageManager = pms;
        mPackageDynamicCodeLoading = packageDynamicCodeLoading;
        mInstaller = installer;
        mInstallLock = installLock;
    }

    public Set<String> getAllPackagesWithDynamicCodeLoading() {
@@ -131,15 +127,17 @@ public class DexLogger {
            }

            byte[] hash = null;
            synchronized (mInstallLock) {
            try {
                // Note that we do not take the install lock here. Hashing should never interfere
                // with app update/compilation/removal. We may get anomalous results if a file
                // changes while we hash it, but that can happen anyway and is harmless for our
                // purposes.
                hash = mInstaller.hashSecondaryDexFile(filePath, packageName, appInfo.uid,
                        appInfo.volumeUuid, storageFlags);
            } catch (InstallerException e) {
                Slog.e(TAG, "Got InstallerException when hashing file " + filePath
                        + ": " + e.getMessage());
            }
            }

            String fileName = new File(filePath).getName();
            String message = PackageUtils.computeSha256Digest(fileName.getBytes());
+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ public class DexManager {
        mPackageDexOptimizer = pdo;
        mInstaller = installer;
        mInstallLock = installLock;
        mDexLogger = new DexLogger(pms, installer, installLock);
        mDexLogger = new DexLogger(pms, installer);
    }

    public DexLogger getDexLogger() {
+1 −2
Original line number Diff line number Diff line
@@ -77,7 +77,6 @@ public class DexLoggerTests {

    @Mock IPackageManager mPM;
    @Mock Installer mInstaller;
    private final Object mInstallLock = new Object();

    private PackageDynamicCodeLoading mPackageDynamicCodeLoading;
    private DexLogger mDexLogger;
@@ -103,7 +102,7 @@ public class DexLoggerTests {
        };

        // For test purposes capture log messages as well as sending to the event log.
        mDexLogger = new DexLogger(mPM, mInstaller, mInstallLock, mPackageDynamicCodeLoading) {
        mDexLogger = new DexLogger(mPM, mInstaller, mPackageDynamicCodeLoading) {
            @Override
                void writeDclEvent(int uid, String message) {
                    super.writeDclEvent(uid, message);