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

Commit 4aee186a authored by Victor Hsieh's avatar Victor Hsieh Committed by Android (Google) Code Review
Browse files

Merge "Test to ensure allowlisted non-system app doesn't break" into main

parents 9ac78626 a1d81b58
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -58,6 +58,7 @@ java_test_host {
        ":PackageManagerTestOverlayTarget",
        ":PackageManagerTestOverlayTarget",
        ":PackageManagerTestOverlayTargetNoOverlayable",
        ":PackageManagerTestOverlayTargetNoOverlayable",
        ":PackageManagerTestAppDeclaresStaticLibrary",
        ":PackageManagerTestAppDeclaresStaticLibrary",
        ":PackageManagerTestAppDifferentPkgName",
        ":PackageManagerTestAppStub",
        ":PackageManagerTestAppStub",
        ":PackageManagerTestAppUsesStaticLibrary",
        ":PackageManagerTestAppUsesStaticLibrary",
        ":PackageManagerTestAppVersion1",
        ":PackageManagerTestAppVersion1",
+28 −5
Original line number Original line Diff line number Diff line
@@ -44,6 +44,10 @@ class TamperedUpdatedSystemPackageTest : BaseHostJUnit4Test() {
        private const val VERSION_TWO_ALT_KEY = "PackageManagerTestAppVersion2AltKey.apk"
        private const val VERSION_TWO_ALT_KEY = "PackageManagerTestAppVersion2AltKey.apk"
        private const val VERSION_TWO_ALT_KEY_IDSIG =
        private const val VERSION_TWO_ALT_KEY_IDSIG =
                "PackageManagerTestAppVersion2AltKey.apk.idsig"
                "PackageManagerTestAppVersion2AltKey.apk.idsig"

        private const val ANOTHER_PKG_NAME = "com.android.server.pm.test.test_app2"
        private const val ANOTHER_PKG = "PackageManagerTestAppDifferentPkgName.apk"

        private const val STRICT_SIGNATURE_CONFIG_PATH =
        private const val STRICT_SIGNATURE_CONFIG_PATH =
                "/system/etc/sysconfig/preinstalled-packages-strict-signature.xml"
                "/system/etc/sysconfig/preinstalled-packages-strict-signature.xml"
        private const val TIMESTAMP_REFERENCE_FILE_PATH = "/data/local/tmp/timestamp.ref"
        private const val TIMESTAMP_REFERENCE_FILE_PATH = "/data/local/tmp/timestamp.ref"
@@ -74,6 +78,7 @@ class TamperedUpdatedSystemPackageTest : BaseHostJUnit4Test() {
    @After
    @After
    fun removeApk() {
    fun removeApk() {
        device.uninstallPackage(TEST_PKG_NAME)
        device.uninstallPackage(TEST_PKG_NAME)
        device.uninstallPackage(ANOTHER_PKG_NAME)
    }
    }


    @Before
    @Before
@@ -90,7 +95,9 @@ class TamperedUpdatedSystemPackageTest : BaseHostJUnit4Test() {
                    .readText()
                    .readText()
                    .replace(
                    .replace(
                        "</config>",
                        "</config>",
                            "<require-strict-signature package=\"${TEST_PKG_NAME}\"/></config>"
                            "<require-strict-signature package=\"${TEST_PKG_NAME}\"/>" +
                            "<require-strict-signature package=\"${ANOTHER_PKG_NAME}\"/>" +
                            "</config>"
                    )
                    )
            writeText(newConfigText)
            writeText(newConfigText)
        }
        }
@@ -146,10 +153,7 @@ class TamperedUpdatedSystemPackageTest : BaseHostJUnit4Test() {
                tempFolder.newFile()
                tempFolder.newFile()
        )
        )
        assertThat(device.installPackage(versionTwoFile, true)).isNull()
        assertThat(device.installPackage(versionTwoFile, true)).isNull()
        val baseApkPath = device.executeShellCommand("pm path ${TEST_PKG_NAME}")
        val baseApkPath = getBaseApkPath(TEST_PKG_NAME)
                .lineSequence()
                .first()
                .replace("package:", "")
        assertThat(baseApkPath).doesNotContain(productPath.toString())
        assertThat(baseApkPath).doesNotContain(productPath.toString())
        preparer.pushResourceFile(VERSION_TWO_ALT_KEY_IDSIG, baseApkPath.toString() + ".idsig")
        preparer.pushResourceFile(VERSION_TWO_ALT_KEY_IDSIG, baseApkPath.toString() + ".idsig")


@@ -175,4 +179,23 @@ class TamperedUpdatedSystemPackageTest : BaseHostJUnit4Test() {
        assertThat(device.executeShellCommand("pm path ${TEST_PKG_NAME}"))
        assertThat(device.executeShellCommand("pm path ${TEST_PKG_NAME}"))
                .contains(productPath.toString())
                .contains(productPath.toString())
    }
    }

    @Test
    fun allowlistedPackageIsNotASystemApp() {
        // If an allowlisted package isn't a system app, make sure install and boot still works
        // normally.
        assertThat(device.installJavaResourceApk(tempFolder, ANOTHER_PKG, /* reinstall */ false))
                .isNull()
        assertThat(getBaseApkPath(ANOTHER_PKG_NAME)).startsWith("/data/app/")

        preparer.reboot()
        assertThat(getBaseApkPath(ANOTHER_PKG_NAME)).startsWith("/data/app/")
    }

    private fun getBaseApkPath(pkgName: String): String {
        return device.executeShellCommand("pm path $pkgName")
                .lineSequence()
                .first()
                .replace("package:", "")
    }
}
}
+8 −0
Original line number Original line Diff line number Diff line
@@ -76,3 +76,11 @@ android_test_helper_app {
    certificate: ":FrameworksServicesTests_keyset_A_cert",
    certificate: ":FrameworksServicesTests_keyset_A_cert",
    v4_signature: true,
    v4_signature: true,
}
}

android_test_helper_app {
    name: "PackageManagerTestAppDifferentPkgName",
    manifest: "AndroidManifestDifferentPkgName.xml",
    srcs: [
        "src/**/*.kt",
    ],
}
+33 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ 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.
  -->
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.server.pm.test.test_app2"
    android:versionCode="1"
    >

    <permission
        android:name="com.android.server.pm.test.test_app.TEST_PERMISSION"
        android:protectionLevel="normal"
        />

    <application>
        <activity android:name="com.android.server.pm.test.test_app.TestActivity"
            android:label="PackageManagerTestApp" />
    </application>

</manifest>