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

Commit d160817d authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[ADI][38/N] bypass multi-package (temporary workaround)

Temporary workaround to fix presubmit failures. A complete
implementation will be added in a follow-up CL to support developer
verification on children sessions in a multi-package installation
session.

FLAG: android.content.pm.verification_service
BUG: 360129657
FIXES: 431203117
Test: atest CtsPackageInstallSessionTestCases

Change-Id: I819bdcbf1ea5e23bfe81fd1e73fd0d51464e1a9e
parent 8714560b
Loading
Loading
Loading
Loading
+29 −15
Original line number Original line Diff line number Diff line
@@ -189,6 +189,7 @@ import android.util.ExceptionUtils;
import android.util.IntArray;
import android.util.IntArray;
import android.util.Log;
import android.util.Log;
import android.util.MathUtils;
import android.util.MathUtils;
import android.util.Pair;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.apk.ApkSignatureVerifier;
import android.util.apk.ApkSignatureVerifier;
@@ -3028,24 +3029,26 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            onSessionVerificationFailure(e.error, errorMsg, /* extras= */ null);
            onSessionVerificationFailure(e.error, errorMsg, /* extras= */ null);
        }
        }
        if (shouldUseVerificationService()) {
        if (shouldUseVerificationService()) {
            final SigningInfo signingInfo;
            final List<SharedLibraryInfo> declaredLibraries;
            synchronized (mLock) {
                signingInfo = new SigningInfo(mSigningDetails);
                declaredLibraries =
                        mPackageLite == null ? null : mPackageLite.getDeclaredLibraries();
            }
            // Send the request to the verifier and wait for its response before the rest of
            // Send the request to the verifier and wait for its response before the rest of
            // the installation can proceed.
            // the installation can proceed.
            if (!mDeveloperVerifierController.startVerificationSession(mPm::snapshotComputer,
            if (isMultiPackage()) {
                    userId, sessionId, getPackageName(),
                // TODO(b/360129657) perform developer verification on each children session before
                    stageDir == null ? Uri.EMPTY : Uri.fromFile(stageDir), signingInfo,
                // moving on to the next installation stage.
                resumeVerify();
            } else { // Not a parent session
                final var infoPair = getSigningInfoAndDeclaredLibraries();
                final SigningInfo signingInfo = infoPair.first;
                final List<SharedLibraryInfo> declaredLibraries = infoPair.second;
                if (!mDeveloperVerifierController.startVerificationSession(
                        mPm::snapshotComputer, userId, sessionId, getPackageName(),
                        Uri.fromFile(stageDir), signingInfo,
                        declaredLibraries, mCurrentVerificationPolicy.get(),
                        declaredLibraries, mCurrentVerificationPolicy.get(),
                        /* extensionParams= */ params.extensionParams,
                        /* extensionParams= */ params.extensionParams,
                        mDeveloperVerifierCallback, /* retry= */ false)) {
                        mDeveloperVerifierCallback, /* retry= */ false)) {
                    // A verifier is installed but cannot be connected. Maybe notify user.
                    // A verifier is installed but cannot be connected. Maybe notify user.
                    mDeveloperVerifierCallback.onConnectionInfeasible();
                    mDeveloperVerifierCallback.onConnectionInfeasible();
                }
                }
            }
            synchronized (mMetrics) {
            synchronized (mMetrics) {
                mMetrics.onDeveloperVerificationRequestSent();
                mMetrics.onDeveloperVerificationRequestSent();
            }
            }
@@ -3055,6 +3058,17 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        }
        }
    }
    }


    private Pair<SigningInfo, List<SharedLibraryInfo>> getSigningInfoAndDeclaredLibraries() {
        final SigningInfo signingInfo;
        final List<SharedLibraryInfo> declaredLibraries;
        synchronized (mLock) {
            signingInfo = new SigningInfo(mSigningDetails);
            declaredLibraries =
                    mPackageLite == null ? null : mPackageLite.getDeclaredLibraries();
        }
        return new Pair<>(signingInfo, declaredLibraries);
    }

    private boolean shouldUseVerificationService() {
    private boolean shouldUseVerificationService() {
        if (!Flags.verificationService()) {
        if (!Flags.verificationService()) {
            // Feature is not enabled.
            // Feature is not enabled.