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

Commit be983bc3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "BinaryTransparencyService: Fix getOriginalApexPreinstalledLocation"

parents 0e2fdeaa 00001111
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @hide
@@ -104,6 +105,9 @@ public class BinaryTransparencyService extends SystemService {
    @VisibleForTesting
    static final String BUNDLE_CONTENT_DIGEST = "content-digest";

    static final String APEX_PRELOAD_LOCATION = "/system/apex/";
    static final String APEX_PRELOAD_LOCATION_ERROR = "could-not-be-determined";

    // used for indicating any type of error during MBA measurement
    static final int MBA_STATUS_ERROR = 0;
    // used for indicating factory condition preloads
@@ -1110,18 +1114,22 @@ public class BinaryTransparencyService extends SystemService {
        }
    }

    // TODO(b/259349011): Need to be more robust against package name mismatch in the filename
    @NonNull
    private String getOriginalApexPreinstalledLocation(String packageName,
                                                   String currentInstalledLocation) {
        if (currentInstalledLocation.contains("/decompressed/")) {
            String resultPath = "system/apex" + packageName + ".capex";
            File f = new File(resultPath);
            if (f.exists()) {
                return resultPath;
        // get a listing of all apex files in /system/apex/
        Set<String> originalApexs = Stream.of(new File(APEX_PRELOAD_LOCATION).listFiles())
                                        .filter(f -> !f.isDirectory())
                                        .map(File::getName)
                                        .collect(Collectors.toSet());

        for (String originalApex : originalApexs) {
            if (originalApex.startsWith(packageName)) {
                return APEX_PRELOAD_LOCATION + originalApex;
            }
            return "/system/apex/" + packageName + ".next.capex";
        }
        return "/system/apex" + packageName + "apex";

        return APEX_PRELOAD_LOCATION_ERROR;
    }

    /**