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

Commit 21575915 authored by Felka Chang's avatar Felka Chang Committed by Android (Google) Code Review
Browse files

Merge "Fix fail verification without cleaning child session data"

parents 7f2f943a 33025c45
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -2112,6 +2112,11 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        Slog.e(TAG, "Failed to verify session " + sessionId + " [" + msgWithErrorCode + "]");
        // Session is sealed and committed but could not be verified, we need to destroy it.
        destroyInternal();
        if (isMultiPackage()) {
            for (PackageInstallerSession childSession : getChildSessions()) {
                childSession.destroyInternal();
            }
        }
        if (isStaged()) {
            mStagedSession.setSessionFailed(
                    SessionInfo.STAGED_SESSION_VERIFICATION_FAILED, msgWithErrorCode);
+7 −0
Original line number Diff line number Diff line
@@ -20,6 +20,13 @@

    <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/>

    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
        <option name="run-command"
            value="pm uninstall com.android.cts.install.lib.testapp.A" />
        <option name="teardown-command"
            value="pm uninstall com.android.cts.install.lib.testapp.A" />
    </target_preparer>

    <test class="com.android.tradefed.testtype.HostTest">
        <option name="jar" value="PackageManagerServiceHostTests.jar" />
    </test>
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.server.pm.test

import com.android.tradefed.testtype.DeviceJUnit4ClassRunner
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test
import com.google.common.truth.Truth
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import kotlin.jvm.JvmField

@RunWith(DeviceJUnit4ClassRunner::class)
class PackageInstallerSessionTest : BaseHostJUnit4Test() {
    companion object {
        private const val DEVICE_SIDE = "PackageManagerServiceDeviceSideTests.apk"
    }

    @Rule
    @JvmField
    val tempFolder = TemporaryFolder()

    @Test
    fun verify_parentSessionFail_childSessionFiles_shouldBeDestroyed() {
        runDeviceTest("com.android.server.pm.PackageInstallerSessionTest",
                "verify_parentSessionFail_childSessionFiles_shouldBeDestroyed")
    }

    /**
     * Run a device side test from com.android.server.pm.test.deviceside.DeviceSide
     *
     * @param method the method to run
     */
    fun runDeviceTest(testClassName: String, method: String) {
        val deviceSideFile = HostUtils.copyResourceToHostFile(DEVICE_SIDE, tempFolder.newFile())
        Truth.assertThat(device.installPackage(deviceSideFile, true)).isNull()
        runDeviceTests(device, "com.android.server.pm.test.deviceside",
                testClassName, method)
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ android_test_helper_app {
    ],
    static_libs: [
        "androidx.annotation_annotation",
        "commands-helper",
        "cts-install-lib",
        "junit",
        "junit-params",
        "androidx.test.ext.junit",
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@
    package="com.android.server.pm.test.deviceside">

    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
    <uses-permission android:name="android.permission.INSTALL_PACKAGES" />
    <uses-permission android:name="android.permission.DELETE_PACKAGES" />

    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
Loading