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

Commit 1fb56cba authored by Mark Punzalan's avatar Mark Punzalan Committed by Android (Google) Code Review
Browse files

Merge "Fix OverlayRemountedTest for HSUM" into main

parents 4385272c f054f76d
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -38,12 +38,15 @@ public class OverlayRemountedTestBase extends BaseHostJUnit4Test {
    protected final SystemPreparer mPreparer = new SystemPreparer(mTemporaryFolder,
            this::getDevice);

    private int mCurrentUserId;

    @Rule
    public final RuleChain ruleChain = RuleChain.outerRule(mTemporaryFolder).around(mPreparer);

    @Before
    public void startBefore() throws DeviceNotAvailableException {
        getDevice().waitForDeviceAvailable();
        mCurrentUserId = getDevice().getCurrentUser();
    }

    /** Builds the full name of a resource in the form package:type/entry. */
@@ -58,7 +61,8 @@ public class OverlayRemountedTestBase extends BaseHostJUnit4Test {
        final long endMillis = System.currentTimeMillis() + ASSERT_RESOURCE_TIMEOUT_MS;
        while (System.currentTimeMillis() <= endMillis) {
            result = getDevice().executeShellCommand(
                    String.format("cmd overlay lookup %s %s", TARGET_PACKAGE, resourceName));
                    String.format("cmd overlay lookup --user %d %s %s", mCurrentUserId,
                            TARGET_PACKAGE, resourceName));
            if (result.equals(expectedValue + "\n") ||
                    result.endsWith("-> " + expectedValue + "\n")) {
                return;
@@ -70,6 +74,7 @@ public class OverlayRemountedTestBase extends BaseHostJUnit4Test {
            }
        }

        fail(String.format("expected: <[%s]> in: <[%s]>", expectedValue, result));
        fail(String.format("expected: <[%s]> in: <[%s]>\nOverlay dump:\n%s", expectedValue, result,
                getDevice().executeShellCommand("cmd overlay dump " + OVERLAY_PACKAGE)));
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -73,9 +73,10 @@ public class RegenerateIdmapTest extends OverlayRemountedTestBase {
    public void testIdmapPoliciesChanged() throws Exception {
        final String targetResource = resourceName(TARGET_PACKAGE, "bool",
                "signature_policy_overlaid");
        final String overlayPath = "/product/overlay/TestOverlay.apk";

        mPreparer.pushResourceFile(TARGET_APK, "/product/app/OverlayTarget.apk")
                .pushResourceFile(OVERLAY_APK, "/product/overlay/TestOverlay.apk")
                .pushResourceFile(OVERLAY_APK, overlayPath)
                .reboot()
                .setOverlayEnabled(OVERLAY_PACKAGE, false);

@@ -87,7 +88,9 @@ public class RegenerateIdmapTest extends OverlayRemountedTestBase {

        // Replace the overlay with a version of the overlay that is signed with the same signature
        // as the target.
        mPreparer.pushResourceFile(OVERLAY_SIGNATURE_APK, "/product/overlay/TestOverlay.apk")
        mPreparer.remount()
                .deleteFile(overlayPath)
                .pushResourceFile(OVERLAY_SIGNATURE_APK, overlayPath)
                .reboot();

        // The idmap should have been recreated with the signature policy fulfilled.
+17 −25
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.internal.util.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.android.tradefed.device.DeviceNotAvailableException;
@@ -66,6 +65,8 @@ public class SystemPreparer extends ExternalResource {
    // to manually verify the device state.
    private boolean mDebugSkipAfterReboot;

    private int mCurrentUserId;

    public SystemPreparer(TemporaryFolder hostTempFolder, DeviceProvider deviceProvider) {
        this(hostTempFolder, RebootStrategy.FULL, null, deviceProvider);
    }
@@ -88,6 +89,11 @@ public class SystemPreparer extends ExternalResource {
        mDebugSkipAfterReboot = debugSkipAfterReboot;
    }

    @Override
    protected void before() throws Throwable {
        mCurrentUserId = mDeviceProvider.getDevice().getCurrentUser();
    }

    /** Copies a file within the host test jar to a path on device. */
    public SystemPreparer pushResourceFile(String filePath, String outputPath)
            throws DeviceNotAvailableException, IOException {
@@ -140,24 +146,6 @@ public class SystemPreparer extends ExternalResource {
        return this;
    }

    /** Stages multiple APEXs within the host test jar onto the device. */
    public SystemPreparer stageMultiplePackages(String[] resourcePaths, String[] packageNames)
            throws DeviceNotAvailableException, IOException {
        assertEquals(resourcePaths.length, packageNames.length);
        final ITestDevice device = mDeviceProvider.getDevice();
        final String[] adbCommandLine = new String[resourcePaths.length + 2];
        adbCommandLine[0] = "install-multi-package";
        adbCommandLine[1] = "--staged";
        for (int i = 0; i < resourcePaths.length; i++) {
            final File tmpFile = copyResourceToTemp(resourcePaths[i]);
            adbCommandLine[i + 2] = tmpFile.getAbsolutePath();
            mInstalledPackages.add(packageNames[i]);
        }
        final String output = device.executeAdbCommand(adbCommandLine);
        assertTrue(output.contains("Success. Reboot device to apply staged session"));
        return this;
    }

    /** Sets the enable state of an overlay package. */
    public SystemPreparer setOverlayEnabled(String packageName, boolean enabled)
            throws DeviceNotAvailableException {
@@ -166,11 +154,14 @@ public class SystemPreparer extends ExternalResource {

        // Wait for the overlay to change its enabled state.
        final long endMillis = System.currentTimeMillis() + OVERLAY_ENABLE_TIMEOUT_MS;
        String result;
        String result = null;
        while (System.currentTimeMillis() <= endMillis) {
            device.executeShellCommand(String.format("cmd overlay %s %s", enable, packageName));
            result = device.executeShellCommand("cmd overlay dump isenabled "
                    + packageName);
            device.executeShellCommand(
                    String.format("cmd overlay %s --user %d %s", enable, mCurrentUserId,
                            packageName));
            result = device.executeShellCommand(
                    String.format("cmd overlay dump --user %d isenabled %s", mCurrentUserId,
                            packageName));
            if (((enabled) ? "true\n" : "false\n").equals(result)) {
                return this;
            }
@@ -181,8 +172,9 @@ public class SystemPreparer extends ExternalResource {
            }
        }

        throw new IllegalStateException(String.format("Failed to %s overlay %s:\n%s", enable,
                packageName, device.executeShellCommand("cmd overlay list")));
        throw new IllegalStateException(String.format(
                "Failed to %s overlay %s. Last result:\n%s\nOverlay list:\n%s",
                enable, packageName, result, device.executeShellCommand("cmd overlay list")));
    }

    /** Restarts the device and waits until after boot is completed. */