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

Commit b72810e1 authored by Jooyung Han's avatar Jooyung Han
Browse files

BinaryTransparencyService: Fix data apex check

In previous CL (6314b162), the check of
downloaded APEX was incorrect. Before the CL, the check was based on the
path prefix (/data/apex), which identifies "downloaded APEX'.

To support a new APEX feature (mount_before_data), which doesn't use
/data/apex for downloaded APEX, the check should be fixed. The CL
changed the check to use "flags & FLAG_SYSTEM", but somehow, the flag
FLAG_SYSTEM is not set for pre-installed APEXes.

In this CL, the check is modified to check a new path
prefix(/dev/block/dm-) to support mount_before_data.

Verified this manually. The newly installed APEX shows more information
about preinstalled APEX.

  APEX Info [Format: package_name,package_version,content_digest_algorithm:content_digest]:
  com.google.android.runtime,1,CHUNKED_SHA512:14462bbfb243cb2592cc70ecf1d2082ce7274cdb0c2e635d0ea5b33570b259e1f937325c0509c5ba8de7205c910e7ff991a661eeada164088726dc6b73c41a4a
  Is a module: false
  --- Package Installation Info ---
  Current install location: /dev/block/dm-13
  |--> Pre-installed package install location: /system/apex/com.android.runtime.apex
  |--> Pre-installed package content digest: 99147f6e0805bcd51f943fda02cfba89a70212607d2a0755dd3b13ac423659dbb212c05d61857f2df4f3f9fd91f2f6309b3f1b64feb64e00ecf3e1d2d3f1759f
  |--> Pre-installed package content digest algorithm: CHUNKED_SHA512

Bug: 430161238
Test: BinaryTransparencyHostTest
Test: verified with `adb shell cmd transparency get apex_info -v` after
      installing an apex. (See above)
Flag: com.android.apex.flags.mount_before_data
Change-Id: Ia6abcee63fc9248f1aeeb95513f34fca46012771
parent 0e62272f
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -612,7 +612,11 @@ public class BinaryTransparencyService extends SystemService {
                    pw.println("--- Package Installation Info ---");
                    pw.println("Current install location: "
                            + packageInfo.applicationInfo.sourceDir);
                    if (packageInfo.applicationInfo.sourceDir.startsWith("/data/apex/")) {
                    // Print more information for downloaded APEX
                    String sourceDir = packageInfo.applicationInfo.sourceDir;
                    if (packageInfo.isApex
                            && (sourceDir.startsWith("/data/apex")
                                    || sourceDir.startsWith("/dev/block/dm-"))) {
                        String origPackageFilepath = getOriginalApexPreinstalledLocation(
                                packageInfo.packageName);
                        pw.println("|--> Pre-installed package install location: "
+3 −2
Original line number Diff line number Diff line
@@ -189,9 +189,10 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test {
    private void uninstallRebootlessApexThenReboot() throws DeviceNotAvailableException {
        // Reboot only if the APEX is not the pre-install one.
        CommandResult result = getDevice().executeShellV2Command(
                "pm list packages -f --apex-only |grep com.android.apex.cts.shim");
                "pm list packages -f --apex-only --show-versioncode "
                + " | grep com.android.apex.cts.shim");
        assertTrue(result.getStatus() == CommandStatus.SUCCESS);
        if (result.getStdout().contains("/data/apex/active/")) {
        if (result.getStdout().contains("versionCode:2")) {
            uninstallPackage("com.android.apex.cts.shim");
            getDevice().reboot();