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

Commit 0635e374 authored by Song Chun Fan's avatar Song Chun Fan Committed by Android (Google) Code Review
Browse files

Merge "[ADI][62/N] not connect to verifier service for sessions restored on reboot" into main

parents 2aa603f3 55aaf2a6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1153,7 +1153,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
                null, null, false, false, false, false, null, SessionInfo.INVALID_ID,
                false, false, false, PackageManager.INSTALL_UNKNOWN, "", null,
                mDeveloperVerifierController, verificationPolicy, verificationPolicy,
                mInstallDependencyHelper);
                mInstallDependencyHelper, /* restoredOnReboot= */ false);

        synchronized (mSessions) {
            mSessions.put(sessionId, session);
+6 −5
Original line number Diff line number Diff line
@@ -1290,7 +1290,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            @NonNull DeveloperVerifierController developerVerifierController,
            @PackageInstaller.DeveloperVerificationPolicy int initialVerificationPolicy,
            @PackageInstaller.DeveloperVerificationPolicy int currentVerificationPolicy,
            InstallDependencyHelper installDependencyHelper) {
            InstallDependencyHelper installDependencyHelper, boolean restoredOnReboot) {
        mCallback = callback;
        mContext = context;
        mPm = pm;
@@ -1392,12 +1392,12 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                createdMillis, committedMillis, committed, childSessionIds, parentSessionId,
                sessionErrorCode, mInitialVerificationPolicy);

        if (shouldUseVerificationService()) {
            // Start binding to the verification service, if not bound already.
        // Proactively bind to the verification service if it's not already bound, for newly
        // created sessions. Notify verifier about package name if it has been set in the session.
        if (!restoredOnReboot && shouldUseVerificationService()) {
            mDeveloperVerifierController.bindToVerifierServiceIfNeeded(mPm::snapshotComputer,
                    userId, mDeveloperVerifierCallback);
            if (!TextUtils.isEmpty(params.appPackageName)) {
                // Opportunistically notify verifier about package name so no need to check results.
                mDeveloperVerifierController.notifyPackageNameAvailable(params.appPackageName,
                        userId);
            }
@@ -7058,6 +7058,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                childSessionIdsArray, parentSessionId, isReady, isFailed, isApplied,
                sessionErrorCode, sessionErrorMessage, preVerifiedDomains,
                developerVerifierController,
                initialVerificationPolicy, currentVerificationPolicy, installDependencyHelper);
                initialVerificationPolicy, currentVerificationPolicy, installDependencyHelper,
                /* restoredOnReboot= */ true);
    }
}
+36 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.server.pm

import android.content.Context
import android.content.pm.Flags
import android.content.pm.PackageInstaller
import android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED
import android.content.pm.PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN
@@ -30,6 +31,9 @@ import android.os.PersistableBundle
import android.os.Process
import android.os.UserHandle
import android.platform.test.annotations.Presubmit
import android.platform.test.annotations.RequiresFlagsEnabled
import android.platform.test.flag.junit.CheckFlagsRule
import android.platform.test.flag.junit.DeviceFlagsValueProvider
import android.util.AtomicFile
import android.util.Slog
import android.util.Xml
@@ -49,12 +53,15 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyLong
import org.mockito.ArgumentMatchers.anyString
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
import org.xmlpull.v1.XmlPullParser
import org.xmlpull.v1.XmlPullParserException
@@ -62,6 +69,8 @@ import org.xmlpull.v1.XmlPullParserException
@Presubmit
class PackageInstallerSessionTest {

    @get:Rule val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule()

    companion object {
        private const val TAG_SESSIONS = "sessions"
        private const val TEST_KEY_FOR_EXTENSION_PARAMS = "testKey"
@@ -351,6 +360,30 @@ class PackageInstallerSessionTest {
            updateOwnerName, mSnapshot)).isTrue()
    }

    @RequiresFlagsEnabled(Flags.FLAG_VERIFICATION_SERVICE)
    @Test
    fun testShouldBindToVerifierOnNewlyCreatedSession() {
        val verifierPackageName = "verifierPackageName"
        whenever(mMockDeveloperVerifierController.verifierPackageName).thenReturn(
            verifierPackageName)

        createSession()
        verify(mMockDeveloperVerifierController).bindToVerifierServiceIfNeeded(
            any(), anyInt(), any())
    }

    @RequiresFlagsEnabled(Flags.FLAG_VERIFICATION_SERVICE)
    @Test
    fun testShouldNotBindToVerifierOnRestoredSession() {
        val verifierPackageName = "verifierPackageName"
        whenever(mMockDeveloperVerifierController.verifierPackageName).thenReturn(
            verifierPackageName)

        createSession(restoredOnReboot = true)
        verify(mMockDeveloperVerifierController, never()).bindToVerifierServiceIfNeeded(
            any(), anyInt(), any())
    }

    private fun createSession(
        staged: Boolean = false,
        sessionId: Int = 123,
@@ -358,6 +391,7 @@ class PackageInstallerSessionTest {
        parentSessionId: Int = PackageInstaller.SessionInfo.INVALID_ID,
        childSessionIds: List<Int> = emptyList(),
        installerPackageName: String = "testInstaller",
        restoredOnReboot: Boolean = false,
        block: (SessionParams) -> Unit = {},
    ): PackageInstallerSession {
        val bundle = PersistableBundle()
@@ -409,7 +443,8 @@ class PackageInstallerSessionTest {
            /* VerifierController */ mMockDeveloperVerifierController,
            /* initialVerificationPolicy */ DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_OPEN,
            /* currentVerificationPolicy */ DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED,
            /* installDependencyHelper */ null
            /* installDependencyHelper */ null,
            /* restoredOnReboot= */ restoredOnReboot
        )
    }

+2 −1
Original line number Diff line number Diff line
@@ -767,7 +767,8 @@ public class StagingManagerTest {
                PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED,
                /* currentVerificationPolicy */
                PackageInstaller.DEVELOPER_VERIFICATION_POLICY_BLOCK_FAIL_CLOSED,
                /* installDependencyHelper */ null);
                /* installDependencyHelper */ null,
                /* restoredOnReboot= */ false);

        StagingManager.StagedSession stagedSession = spy(session.mStagedSession);
        doReturn(packageName).when(stagedSession).getPackageName();