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

Commit d04f1442 authored by Jooyung Han's avatar Jooyung Han Committed by Android (Google) Code Review
Browse files

Merge "PackageCacher: cache key for block-device APEX" into main

parents dd45586c 63de76b5
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -75,11 +75,30 @@ public class PackageCacher implements IPackageCacher {
     * Returns the cache key for a specified {@code packageFile} and {@code flags}.
     */
    private String getCacheKey(File packageFile, int flags) {
        StringBuilder sb = new StringBuilder(packageFile.getName());
        String name = packageFile.getName();
        String absPath = packageFile.getAbsolutePath();

        // In case the package is an APEX which is from a device-mapper block
        // device created by apexd, the filename (dm-NN) can be different on
        // each boot. Hence, we use the device-mapper name instead, which is
        // stable across reboots.
        if (absPath.startsWith("/dev/block/dm-")) {
            try {
                name = IoUtils.readFileAsString("/sys/block/" + name + "/dm/name").trim();
                // The device name represents the file. No need to append the hash of the full path.
                absPath = null;
            } catch (IOException e) {
                Slog.w("Error while reading device name of " + name, e);
            }
        }

        StringBuilder sb = new StringBuilder(name);
        sb.append('-');
        sb.append(flags);
        if (absPath != null) {
            sb.append('-');
        sb.append(packageFile.getAbsolutePath().hashCode());
            sb.append(absPath.hashCode());
        }

        return sb.toString();
    }