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

Commit 09943af9 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Test that upgrading target apk invalidates idmap

This change adds tests that run in presubmit to verify that updating
the target APK invalidates the idmap for overlays targeting the
target.

Bug: 147794117
Bug: 150877400
Test: atest PackagedUpgradedTest
Change-Id: I0268ea99dc7beb4bbc7009a67d9929e2d82862cb
parent a9093052
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -3,5 +3,10 @@
    {
      "name" : "idmap2_tests"
    }
  ],
  "imports": [
    {
      "path": "frameworks/base/services/core/java/com/android/server/om"
    }
  ]
}
+2 −0
Original line number Diff line number Diff line
@@ -24,5 +24,7 @@ java_test_host {
        ":OverlayRemountedTest_SharedLibrary",
        ":OverlayRemountedTest_SharedLibraryOverlay",
        ":OverlayRemountedTest_Target",
        ":OverlayRemountedTest_TargetUpgrade",
        ":OverlayRemountedTest_Overlay",
    ],
}
+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.overlaytest.remounted;

import static org.junit.Assert.fail;

import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;

import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;

public class OverlayRemountedTestBase extends BaseHostJUnit4Test {
    static final long ASSERT_RESOURCE_TIMEOUT_MS = 30000;

    static final String TARGET_APK = "OverlayRemountedTest_Target.apk";
    static final String TARGET_PACKAGE = "com.android.overlaytest.remounted.target";
    static final String TARGET_UPGRADE_APK = "OverlayRemountedTest_TargetUpgrade.apk";
    static final String OVERLAY_APK = "OverlayRemountedTest_Overlay.apk";
    static final String OVERLAY_PACKAGE = "com.android.overlaytest.remounted.target.overlay";
    static final String SHARED_LIBRARY_APK =
            "OverlayRemountedTest_SharedLibrary.apk";
    static final String SHARED_LIBRARY_PACKAGE =
            "com.android.overlaytest.remounted.shared_library";
    static final String SHARED_LIBRARY_OVERLAY_APK =
            "OverlayRemountedTest_SharedLibraryOverlay.apk";
    static final String SHARED_LIBRARY_OVERLAY_PACKAGE =
            "com.android.overlaytest.remounted.shared_library.overlay";

    private final TemporaryFolder mTemporaryFolder = new TemporaryFolder();
    protected final SystemPreparer mPreparer = new SystemPreparer(mTemporaryFolder,
            this::getDevice);

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

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

    /** Builds the full name of a resource in the form package:type/entry. */
    String resourceName(String pkg, String type, String entry) {
        return String.format("%s:%s/%s", pkg, type, entry);
    }

    void assertResource(String resourceName, String expectedValue)
            throws DeviceNotAvailableException {
        String result = null;

        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));
            if (result.equals(expectedValue + "\n") ||
                    result.endsWith("-> " + expectedValue + "\n")) {
                return;
            }

            try {
                Thread.sleep(200);
            } catch (InterruptedException ignore) {
            }
        }

        fail(String.format("expected: <[%s]> in: <[%s]>", expectedValue, result));
    }
}
+4 −47
Original line number Diff line number Diff line
@@ -16,42 +16,13 @@

package com.android.overlaytest.remounted;

import static org.junit.Assert.assertTrue;

import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;

@RunWith(DeviceJUnit4ClassRunner.class)
public class OverlaySharedLibraryTest extends BaseHostJUnit4Test {
    private static final String TARGET_APK = "OverlayRemountedTest_Target.apk";
    private static final String TARGET_PACKAGE = "com.android.overlaytest.remounted.target";
    private static final String SHARED_LIBRARY_APK =
            "OverlayRemountedTest_SharedLibrary.apk";
    private static final String SHARED_LIBRARY_PACKAGE =
            "com.android.overlaytest.remounted.shared_library";
    private static final String SHARED_LIBRARY_OVERLAY_APK =
            "OverlayRemountedTest_SharedLibraryOverlay.apk";
    private static final String SHARED_LIBRARY_OVERLAY_PACKAGE =
            "com.android.overlaytest.remounted.shared_library.overlay";

    public final TemporaryFolder temporaryFolder = new TemporaryFolder();
    public final SystemPreparer preparer = new SystemPreparer(temporaryFolder, this::getDevice);

    @Rule
    public final RuleChain ruleChain = RuleChain.outerRule(temporaryFolder).around(preparer);

    @Before
    public void startBefore() throws DeviceNotAvailableException {
        getDevice().waitForDeviceAvailable();
    }
public class OverlaySharedLibraryTest extends OverlayRemountedTestBase {

    @Test
    public void testSharedLibrary() throws Exception {
@@ -60,7 +31,7 @@ public class OverlaySharedLibraryTest extends BaseHostJUnit4Test {
        final String libraryResource = resourceName(SHARED_LIBRARY_PACKAGE, "bool",
                "shared_library_overlaid");

        preparer.pushResourceFile(SHARED_LIBRARY_APK, "/product/app/SharedLibrary.apk")
        mPreparer.pushResourceFile(SHARED_LIBRARY_APK, "/product/app/SharedLibrary.apk")
                .installResourceApk(SHARED_LIBRARY_OVERLAY_APK, SHARED_LIBRARY_OVERLAY_PACKAGE)
                .reboot()
                .setOverlayEnabled(SHARED_LIBRARY_OVERLAY_PACKAGE, false)
@@ -71,7 +42,7 @@ public class OverlaySharedLibraryTest extends BaseHostJUnit4Test {
        assertResource(libraryResource, "false");

        // Overlay the shared library resource.
        preparer.setOverlayEnabled(SHARED_LIBRARY_OVERLAY_PACKAGE, true);
        mPreparer.setOverlayEnabled(SHARED_LIBRARY_OVERLAY_PACKAGE, true);
        assertResource(targetResource, "true");
        assertResource(libraryResource, "true");
    }
@@ -83,7 +54,7 @@ public class OverlaySharedLibraryTest extends BaseHostJUnit4Test {
        final String libraryResource = resourceName(SHARED_LIBRARY_PACKAGE, "bool",
                "shared_library_overlaid");

        preparer.pushResourceFile(SHARED_LIBRARY_APK, "/product/app/SharedLibrary.apk")
        mPreparer.pushResourceFile(SHARED_LIBRARY_APK, "/product/app/SharedLibrary.apk")
                .installResourceApk(SHARED_LIBRARY_OVERLAY_APK, SHARED_LIBRARY_OVERLAY_PACKAGE)
                .setOverlayEnabled(SHARED_LIBRARY_OVERLAY_PACKAGE, true)
                .reboot()
@@ -92,18 +63,4 @@ public class OverlaySharedLibraryTest extends BaseHostJUnit4Test {
        assertResource(targetResource, "true");
        assertResource(libraryResource, "true");
    }

    /** Builds the full name of a resource in the form package:type/entry. */
    String resourceName(String pkg, String type, String entry) {
        return String.format("%s:%s/%s", pkg, type, entry);
    }

    void assertResource(String resourceName, String expectedValue)
            throws DeviceNotAvailableException {
        final String result = getDevice().executeShellCommand(
                String.format("cmd overlay lookup %s %s", TARGET_PACKAGE, resourceName));
        assertTrue(String.format("expected: <[%s]> in: <[%s]>", expectedValue, result),
                result.equals(expectedValue + "\n") ||
                result.endsWith("-> " + expectedValue + "\n"));
    }
}
Loading