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

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

Revert "[6/N] allow adb installs to bypass verifier"

This reverts commit 425d3d5a.

BUG: 374797861
Test: n/a
FLAG: android.content.pm.verification_service

Change-Id: Id47f43eba8c22d56327e4c46abf0f1ccb66f4d81
parent 9b47940e
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -2935,8 +2935,6 @@ public class PackageInstaller {
        /** {@hide} */
        public @Nullable String dexoptCompilerFilter = null;
        /** {@hide} */
        public boolean forceVerification;
        /** {@hide} */
        public boolean isAutoInstallDependenciesEnabled = true;

        private final ArrayMap<String, Integer> mPermissionStates;
@@ -2992,7 +2990,6 @@ public class PackageInstaller {
            developmentInstallFlags = source.readInt();
            unarchiveId = source.readInt();
            dexoptCompilerFilter = source.readString();
            forceVerification = source.readBoolean();
            isAutoInstallDependenciesEnabled = source.readBoolean();
        }

@@ -3030,7 +3027,6 @@ public class PackageInstaller {
            ret.developmentInstallFlags = developmentInstallFlags;
            ret.unarchiveId = unarchiveId;
            ret.dexoptCompilerFilter = dexoptCompilerFilter;
            ret.forceVerification = forceVerification;
            ret.isAutoInstallDependenciesEnabled = isAutoInstallDependenciesEnabled;
            return ret;
        }
@@ -3740,14 +3736,6 @@ public class PackageInstaller {
            return grantedPermissions.toArray(ArrayUtils.emptyArray(String.class));
        }

        /**
         * Used by adb installations to force enable the verification for this install.
         * {@hide}
         */
        public void setForceVerification() {
            this.forceVerification = true;
        }

        /**
         * Optionally indicate whether missing SDK or static shared library dependencies should be
         * automatically fetched and installed when installing an app that wants to use these
@@ -3800,7 +3788,6 @@ public class PackageInstaller {
            pw.printHexPair("developmentInstallFlags", developmentInstallFlags);
            pw.printPair("unarchiveId", unarchiveId);
            pw.printPair("dexoptCompilerFilter", dexoptCompilerFilter);
            pw.printPair("forceVerification", forceVerification);
            pw.printPair("isAutoInstallDependenciesEnabled", isAutoInstallDependenciesEnabled);
            pw.println();
        }
@@ -3848,7 +3835,6 @@ public class PackageInstaller {
            dest.writeInt(developmentInstallFlags);
            dest.writeInt(unarchiveId);
            dest.writeString(dexoptCompilerFilter);
            dest.writeBoolean(forceVerification);
            dest.writeBoolean(isAutoInstallDependenciesEnabled);
        }

+29 −49
Original line number Diff line number Diff line
@@ -235,6 +235,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    private static final String TAG = "PackageInstallerSession";
@@ -1283,9 +1284,9 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            }
        }

        if (shouldUseVerificationService()) {
        if (Flags.verificationService()) {
            // Start binding to the verification service, if not bound already.
            mVerifierController.bindToVerifierServiceIfNeeded(mPm::snapshotComputer, userId);
            mVerifierController.bindToVerifierServiceIfNeeded(() -> pm.snapshotComputer(), userId);
            if (!TextUtils.isEmpty(params.appPackageName)) {
                mVerifierController.notifyPackageNameAvailable(params.appPackageName);
            }
@@ -2887,7 +2888,9 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            setSessionFailed(e.error, errorMsg);
            onSessionVerificationFailure(e.error, errorMsg, /* extras= */ null);
        }
        if (shouldUseVerificationService()) {
        if (Flags.verificationService()) {
            final Supplier<Computer> snapshotSupplier = mPm::snapshotComputer;
            if (mVerifierController.isVerifierInstalled(snapshotSupplier, userId)) {
                final SigningInfo signingInfo;
                final List<SharedLibraryInfo> declaredLibraries;
                synchronized (mLock) {
@@ -2897,7 +2900,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                }
                // Send the request to the verifier and wait for its response before the rest of
                // the installation can proceed.
            if (!mVerifierController.startVerificationSession(mPm::snapshotComputer, userId,
                if (!mVerifierController.startVerificationSession(snapshotSupplier, userId,
                        sessionId, getPackageName(), Uri.fromFile(stageDir), signingInfo,
                        declaredLibraries, mVerificationPolicy.get(), /* extensionParams= */ null,
                        new VerifierCallback(), /* retry= */ false)) {
@@ -2907,36 +2910,13 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                            /* extras= */ null);
                }
            } else {
            // No need to check with verifier. Proceed with the rest of the verification.
                // Verifier is not installed. Let the installation pass for now.
                resumeVerify();
            }
        } else {
            // New verification feature is not enabled. Proceed to the rest of the verification.
            resumeVerify();
        }

    private boolean shouldUseVerificationService() {
        if (!Flags.verificationService()) {
            // Feature is not enabled.
            return false;
        }
        if ((params.installFlags & PackageManager.INSTALL_FROM_ADB) != 0) {
            // adb installs are exempted from verification unless explicitly requested
            if (!params.forceVerification) {
                return false;
            }
        }
        final String verifierPackageName = mVerifierController.getVerifierPackageName(
                mPm::snapshotComputer, userId);
        if (verifierPackageName == null) {
            // Feature is enabled but no verifier installed.
            return false;
        }
        synchronized (mLock) {
            if (verifierPackageName.equals(mPackageName)) {
                // The verifier itself is being updated. Skip.
                Slog.w(TAG, "Skipping verification service because the verifier is being updated");
                return false;
            }
        }
        return true;
    }

    private void resumeVerify() {
@@ -5657,7 +5637,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            }
        } catch (InstallerException ignored) {
        }
        if (shouldUseVerificationService()
        if (Flags.verificationService()
                && !TextUtils.isEmpty(params.appPackageName)
                && !isCommitted()) {
            // Only notify for the cancellation if the verification request has not
+0 −4
Original line number Diff line number Diff line
@@ -3599,9 +3599,6 @@ class PackageManagerShellCommand extends ShellCommand {
                            .setCompilerFilter(sessionParams.dexoptCompilerFilter)
                            .build();
                    break;
                case "--force-verification":
                    sessionParams.setForceVerification();
                    break;
                case "--disable-auto-install-dependencies":
                    if (Flags.sdkDependencyInstaller()) {
                        sessionParams.setEnableAutoInstallDependencies(false);
@@ -4815,7 +4812,6 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("          https://source.android.com/docs/core/runtime/configure"
                + "#compiler_filters");
        pw.println("          or 'skip'");
        pw.println("      --force-verification: if set, enable the verification for this install");
        if (Flags.sdkDependencyInstaller()) {
            pw.println("      --disable-auto-install-dependencies: if set, any missing shared");
            pw.println("          library dependencies will not be auto-installed");
+11 −1
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ public final class VerificationStatusTracker {
    private final @CurrentTimeMillisLong long mMaxTimeoutTime;
    @NonNull
    private final VerifierController.Injector mInjector;
    // Record the package name associated with the verification result
    @NonNull
    private final String mPackageName;

    /**
     * By default, the timeout time is the default timeout duration plus the current time (when
@@ -38,8 +41,10 @@ public final class VerificationStatusTracker {
     * can be extended via {@link #extendTimeRemaining} to the maximum allowed.
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED)
    public VerificationStatusTracker(long defaultTimeoutMillis, long maxExtendedTimeoutMillis,
    public VerificationStatusTracker(@NonNull String packageName,
            long defaultTimeoutMillis, long maxExtendedTimeoutMillis,
            @NonNull VerifierController.Injector injector) {
        mPackageName = packageName;
        mStartTime = injector.getCurrentTimeMillis();
        mTimeoutTime = mStartTime + defaultTimeoutMillis;
        mMaxTimeoutTime = mStartTime + maxExtendedTimeoutMillis;
@@ -88,4 +93,9 @@ public final class VerificationStatusTracker {
    public boolean isTimeout() {
        return mInjector.getCurrentTimeMillis() >= mTimeoutTime;
    }

    @NonNull
    public String getPackageName() {
        return mPackageName;
    }
}
+8 −14
Original line number Diff line number Diff line
@@ -139,16 +139,15 @@ public class VerifierController {
    }

    /**
     * Used by the installation session to get the package name of the installed verifier.
     * Used by the installation session to check if a verifier is installed.
     */
    @Nullable
    public String getVerifierPackageName(Supplier<Computer> snapshotSupplier, int userId) {
    public boolean isVerifierInstalled(Supplier<Computer> snapshotSupplier, int userId) {
        if (isVerifierConnected()) {
            // Verifier is connected or is being connected, so it must be installed.
            return mRemoteServiceComponentName.getPackageName();
            return true;
        }
        // Verifier has been disconnected, or it hasn't been connected. Check if it's installed.
        return mInjector.getVerifierPackageName(snapshotSupplier.get(), userId);
        return mInjector.isVerifierInstalled(snapshotSupplier.get(), userId);
    }

    /**
@@ -332,7 +331,7 @@ public class VerifierController {
        final long defaultTimeoutMillis = mInjector.getVerificationRequestTimeoutMillis();
        final long maxExtendedTimeoutMillis = mInjector.getMaxVerificationExtendedTimeoutMillis();
        final VerificationStatusTracker tracker = new VerificationStatusTracker(
                defaultTimeoutMillis, maxExtendedTimeoutMillis, mInjector);
                packageName, defaultTimeoutMillis, maxExtendedTimeoutMillis, mInjector);
        synchronized (mVerificationStatus) {
            mVerificationStatus.put(verificationId, tracker);
        }
@@ -543,15 +542,10 @@ public class VerifierController {
        }

        /**
         * Return the package name of the verifier installed on this device.
         * Check if a verifier is installed on this device.
         */
        @Nullable
        public String getVerifierPackageName(Computer snapshot, int userId) {
            final ComponentName componentName = resolveVerifierComponentName(snapshot, userId);
            if (componentName == null) {
                return null;
            }
            return componentName.getPackageName();
        public boolean isVerifierInstalled(Computer snapshot, int userId) {
            return resolveVerifierComponentName(snapshot, userId) != null;
        }

        /**
Loading