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

Commit e38d5719 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "verification_service_implementation" into main

* changes:
  [ADI][23/N] allow verifier to see all session infos
  [ADI][22/N] remove verifier override option
  [ADI][21/N] fix NPE when stageDir is null
  [ADI][20/N] protect the verifier app
  [ADI][19/N] support lite verification mode
  [ADI][18/N] Add VERIFICATION_USER_ACTION_NEEDED_REASON constants
parents 8de73bd5 f4790709
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13122,6 +13122,7 @@ package android.content.pm {
    field @FlaggedApi("android.content.pm.archiving") public static final String EXTRA_UNARCHIVE_STATUS = "android.content.pm.extra.UNARCHIVE_STATUS";
    field @FlaggedApi("android.content.pm.verification_service") public static final String EXTRA_VERIFICATION_EXTENSION_RESPONSE = "android.content.pm.extra.VERIFICATION_EXTENSION_RESPONSE";
    field @FlaggedApi("android.content.pm.verification_service") public static final String EXTRA_VERIFICATION_FAILURE_REASON = "android.content.pm.extra.VERIFICATION_FAILURE_REASON";
    field @FlaggedApi("android.content.pm.verification_service") public static final String EXTRA_VERIFICATION_LITE_PERFORMED = "android.content.pm.extra.VERIFICATION_LITE_PERFORMED";
    field public static final int PACKAGE_SOURCE_DOWNLOADED_FILE = 4; // 0x4
    field public static final int PACKAGE_SOURCE_LOCAL_FILE = 3; // 0x3
    field public static final int PACKAGE_SOURCE_OTHER = 1; // 0x1
+7 −1
Original line number Diff line number Diff line
@@ -4378,10 +4378,14 @@ package android.content.pm {
    ctor public PackageInstaller.VerificationUserConfirmationInfo();
    ctor public PackageInstaller.VerificationUserConfirmationInfo(int, int);
    method public int describeContents();
    method public int getVerificationFailureReason();
    method public int getVerificationPolicy();
    method public int getVerificationUserActionNeededReason();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.PackageInstaller.VerificationUserConfirmationInfo> CREATOR;
    field public static final int VERIFICATION_USER_ACTION_NEEDED_REASON_LITE_VERIFICATION = 3; // 0x3
    field public static final int VERIFICATION_USER_ACTION_NEEDED_REASON_NETWORK_UNAVAILABLE = 1; // 0x1
    field public static final int VERIFICATION_USER_ACTION_NEEDED_REASON_PACKAGE_BLOCKED = 2; // 0x2
    field public static final int VERIFICATION_USER_ACTION_NEEDED_REASON_UNKNOWN = 0; // 0x0
  }
  public class PackageItemInfo {
@@ -4810,6 +4814,7 @@ package android.content.pm.verify.pkg {
    method public int describeContents();
    method public int getAslStatus();
    method @NonNull public String getFailureMessage();
    method public boolean isLite();
    method public boolean isVerified();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.verify.pkg.VerificationStatus> CREATOR;
@@ -4823,6 +4828,7 @@ package android.content.pm.verify.pkg {
    method @NonNull public android.content.pm.verify.pkg.VerificationStatus build();
    method @NonNull public android.content.pm.verify.pkg.VerificationStatus.Builder setAslStatus(int);
    method @NonNull public android.content.pm.verify.pkg.VerificationStatus.Builder setFailureMessage(@NonNull String);
    method @NonNull public android.content.pm.verify.pkg.VerificationStatus.Builder setLite(boolean);
    method @NonNull public android.content.pm.verify.pkg.VerificationStatus.Builder setVerified(boolean);
  }
+95 −20
Original line number Diff line number Diff line
@@ -443,12 +443,36 @@ public class PackageInstaller {
    public static final String EXTRA_WARNINGS = "android.content.pm.extra.WARNINGS";

    /**
     * When verification is blocked as part of the installation, additional reason for the block
     * will be provided to the installer with a {@link VerificationFailedReason} as part of the
     * When an installation fails because the verification was incomplete or blocked,
     * this extra provides a code that explains the reason, such
     * as {@link #VERIFICATION_FAILED_REASON_NETWORK_UNAVAILABLE}. It is included in the
     * installation result returned via the {@link IntentSender} in
     * {@link Session#commit(IntentSender)}. This extra is provided only when the installation has
     * failed. Installers can use this extra to check if the installation failure was caused by a
     * verification failure.
     * {@link Session#commit(IntentSender)}. However, along with this reason code, installers can
     * receive different status codes from {@link #EXTRA_STATUS} depending on their target SDK and
     * privileged status:
     * <p>
     *      Non-privileged installers targeting 36 or less will first receive the
     *      {@link #STATUS_PENDING_USER_ACTION} status code without this reason code. They will be
     *      forced through the user action flow to allow the OS to inform the user of such
     *      verification context before continuing to fail the install. If the user has the option
     *      to bypass the verification result and chooses to do so, the installation will proceed.
     *      Otherwise, the installer will receive the {@link #STATUS_FAILURE_ABORTED} status code
     *      along with this reason code that explains why the verification had failed.
     * </p>
     * <p>
     *     Privileged installer targeting 36 or less will directly receive the
     *     {@link #STATUS_FAILURE_ABORTED} status code. This is because they are not expected to
     *     have the capability of handling the {@link #STATUS_PENDING_USER_ACTION} flow, so the
     *     installation will directly fail. This reason code will be supplied to them for
     *     providing additional information.
     * </p>
     * <p>
     *     All installers targeting 37 and higher will receive a {@link #STATUS_FAILURE_ABORTED}
     *     status code along with this reason code, so the installers can explain the failure to the
     *     user accordingly. An {@link Intent#EXTRA_INTENT} will also be populated with an intent
     *     that can provide additional context where appropriate, should the installer prefer to
     *     defer to the OS to explain the failure to the user.
     * </p>
     */
    @FlaggedApi(Flags.FLAG_VERIFICATION_SERVICE)
    public static final String EXTRA_VERIFICATION_FAILURE_REASON =
@@ -462,6 +486,16 @@ public class PackageInstaller {
    public static final String EXTRA_VERIFICATION_EXTENSION_RESPONSE =
            "android.content.pm.extra.VERIFICATION_EXTENSION_RESPONSE";

    /**
     * An extra containing a boolean indicating whether the lite verification was performed on
     * the app to be installed. It is included in the installation result returned via the
     * {@link IntentSender} in {@link Session#commit(IntentSender)} when the installation failed.
     */
    @FlaggedApi(Flags.FLAG_VERIFICATION_SERVICE)
    public static final String EXTRA_VERIFICATION_LITE_PERFORMED =
            "android.content.pm.extra.VERIFICATION_LITE_PERFORMED";


    /**
     * Streaming installation pending.
     * Caller should make sure DataLoader is able to prepare image and reinitiate the operation.
@@ -850,22 +884,29 @@ public class PackageInstaller {
    @SystemApi
    public static final int VERIFICATION_POLICY_NONE = 0; // platform default
    /**
     * Only block installations on {@link #VERIFICATION_FAILED_REASON_PACKAGE_BLOCKED}.
     * Only block installations when the verification status says the package is blocked,
     * and ask the user if they'd like to install anyway when the verification cannot complete for
     * any other reason. In case of a network issue, the user also has the option to retry the
     * verification.
     * @hide
     */
    @FlaggedApi(Flags.FLAG_VERIFICATION_SERVICE)
    @SystemApi
    public static final int VERIFICATION_POLICY_BLOCK_FAIL_OPEN = 1;
    /**
     * Only block installations on {@link #VERIFICATION_FAILED_REASON_PACKAGE_BLOCKED} and ask the
     * user if they'd like to install anyway when the verification is blocked for other reason.
     * Only block installations when the verification result says the package is blocked,
     * and ask the user if they'd like to install anyway when the verification cannot complete for
     * any other reason. In case of a network issue, the user also has the option to retry the
     * verification.
     * @hide
     */
    @FlaggedApi(Flags.FLAG_VERIFICATION_SERVICE)
    @SystemApi
    public static final int VERIFICATION_POLICY_BLOCK_FAIL_WARN = 2;
    /**
     * Block installations whose verification status is blocked for any reason.
     * Block installations when the verification result says the package is blocked or when the
     * verification cannot be conducted because of unknown reasons. In case of a network issue,
     * the user has the option to retry the verification.
     * @hide
     */
    @FlaggedApi(Flags.FLAG_VERIFICATION_SERVICE)
@@ -4981,32 +5022,66 @@ public class PackageInstaller {
    }

    /**
     * Details about an incomplete or failed verification.
     * Details about an incomplete or failed verification that requires user intervention.
     *
     * @hide
     */
    @FlaggedApi(Flags.FLAG_VERIFICATION_SERVICE)
    @SystemApi
    public static final class VerificationUserConfirmationInfo implements Parcelable {
        /**
         * Verification requires user intervention because of unknown reasons, such as when the
         * verifier times out or cannot be connected.
         */
        public static final int VERIFICATION_USER_ACTION_NEEDED_REASON_UNKNOWN = 0;

        /**
         * Verification requires user intervention because the network is unavailable.
         */
        public static final int VERIFICATION_USER_ACTION_NEEDED_REASON_NETWORK_UNAVAILABLE = 1;

        /**
         * Verification requires user intervention because the package is blocked.
         */
        public static final int VERIFICATION_USER_ACTION_NEEDED_REASON_PACKAGE_BLOCKED = 2;

        /**
         * Verification requires user intervention because only the lite version of the
         * verification was completed on the request, not the full verification.
         */
        public static final int VERIFICATION_USER_ACTION_NEEDED_REASON_LITE_VERIFICATION = 3;

        /**
         * @hide
         */
        @IntDef(value = {
                VERIFICATION_USER_ACTION_NEEDED_REASON_UNKNOWN,
                VERIFICATION_USER_ACTION_NEEDED_REASON_NETWORK_UNAVAILABLE,
                VERIFICATION_USER_ACTION_NEEDED_REASON_PACKAGE_BLOCKED,
                VERIFICATION_USER_ACTION_NEEDED_REASON_LITE_VERIFICATION
        })
        @Retention(RetentionPolicy.SOURCE)
        public @interface UserActionNeededReason {
        }

        @VerificationPolicy
        private int mVerificationPolicy;

        @VerificationFailedReason
        private int mVerificationFailureReason;
        @UserActionNeededReason
        private int mVerificationUserActionNeededReason;

        public VerificationUserConfirmationInfo() {
        }

        public VerificationUserConfirmationInfo(@VerificationPolicy int policy,
                @VerificationFailedReason int failureReason) {
                @UserActionNeededReason int reason) {
            mVerificationPolicy = policy;
            mVerificationFailureReason = failureReason;
            mVerificationUserActionNeededReason = reason;
        }

        private VerificationUserConfirmationInfo(@NonNull Parcel in) {
            mVerificationPolicy = in.readInt();
            mVerificationFailureReason = in.readInt();
            mVerificationUserActionNeededReason = in.readInt();
        }

        @VerificationPolicy
@@ -5014,9 +5089,9 @@ public class PackageInstaller {
            return mVerificationPolicy;
        }

        @VerificationFailedReason
        public int getVerificationFailureReason() {
            return mVerificationFailureReason;
        @UserActionNeededReason
        public int getVerificationUserActionNeededReason() {
            return mVerificationUserActionNeededReason;
        }

        @Override
@@ -5027,7 +5102,7 @@ public class PackageInstaller {
        @Override
        public void writeToParcel(@NonNull Parcel dest, int flags) {
            dest.writeInt(mVerificationPolicy);
            dest.writeInt(mVerificationFailureReason);
            dest.writeInt(mVerificationUserActionNeededReason);
        }

        public static final @NonNull Parcelable.Creator<VerificationUserConfirmationInfo>
@@ -5047,7 +5122,7 @@ public class PackageInstaller {
        public String toString() {
            return "VerificationUserConfirmationInfo{"
                    + "verificationPolicy=" + mVerificationPolicy
                    + ", vericationFailureReason=" + mVerificationFailureReason
                    + ", verificationUserActionReason=" + mVerificationUserActionNeededReason
                    + '}';
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -60,8 +60,8 @@ public final class VerificationSession implements Parcelable {
     * @hide
     */
    @IntDef(prefix = {"VERIFICATION_INCOMPLETE_"}, value = {
            VERIFICATION_INCOMPLETE_NETWORK_UNAVAILABLE,
            VERIFICATION_INCOMPLETE_UNKNOWN,
            VERIFICATION_INCOMPLETE_NETWORK_UNAVAILABLE,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface VerificationIncompleteReason {
+42 −11
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;

/**
 * This class is used by the verifier to describe the status of the verification request, whether
@@ -67,12 +68,19 @@ public final class VerificationStatus implements Parcelable {
    @Retention(RetentionPolicy.SOURCE)
    public @interface VerifierStatusAsl {}

    private boolean mIsVerified;
    private @VerifierStatusAsl int mAslStatus;
    private final boolean mIsVerified;
    private final boolean mIsLite;
    private final @VerifierStatusAsl int mAslStatus;
    @NonNull
    private String mFailuresMessage = "";

    private VerificationStatus() {}
    private final String mFailuresMessage;

    private VerificationStatus(boolean isVerified, boolean isLite, @VerifierStatusAsl int aslStatus,
            @NonNull String failuresMessage) {
        mIsVerified = isVerified;
        mIsLite = isLite;
        mAslStatus = aslStatus;
        mFailuresMessage = failuresMessage;
    }

    /**
     * @return whether the status is set to verified or not.
@@ -81,6 +89,13 @@ public final class VerificationStatus implements Parcelable {
        return mIsVerified;
    }

    /**
     * @return true when the only the lite variation of the verification was conducted.
     */
    public boolean isLite() {
        return mIsLite;
    }

    /**
     * @return the failure message associated with the failure status.
     */
@@ -100,14 +115,27 @@ public final class VerificationStatus implements Parcelable {
     * Builder to construct a {@link VerificationStatus} object.
     */
    public static final class Builder {
        final VerificationStatus mStatus = new VerificationStatus();
        private boolean mIsVerified = false;
        private boolean mIsLite = false;
        private @VerifierStatusAsl int mAslStatus = VERIFIER_STATUS_ASL_UNDEFINED;
        private String mFailuresMessage = "";

        /**
         * Set in the status whether the verification has succeeded or failed.
         */
        @NonNull
        public Builder setVerified(boolean verified) {
            mStatus.mIsVerified = verified;
        public Builder setVerified(boolean isVerified) {
            mIsVerified = isVerified;
            return this;
        }

        /**
         * Set in the status whether the lite variation of the verification was conducted
         * instead of the full verification.
         */
        @NonNull
        public Builder setLite(boolean isLite) {
            mIsLite = isLite;
            return this;
        }

@@ -116,7 +144,8 @@ public final class VerificationStatus implements Parcelable {
         */
        @NonNull
        public Builder setFailureMessage(@NonNull String failureMessage) {
            mStatus.mFailuresMessage = failureMessage;
            Objects.requireNonNull(failureMessage, "failureMessage cannot be null");
            mFailuresMessage = failureMessage;
            return this;
        }

@@ -125,7 +154,7 @@ public final class VerificationStatus implements Parcelable {
         */
        @NonNull
        public Builder setAslStatus(@VerifierStatusAsl int aslStatus) {
            mStatus.mAslStatus = aslStatus;
            mAslStatus = aslStatus;
            return this;
        }

@@ -134,12 +163,13 @@ public final class VerificationStatus implements Parcelable {
         */
        @NonNull
        public VerificationStatus build() {
            return mStatus;
            return new VerificationStatus(mIsVerified, mIsLite, mAslStatus, mFailuresMessage);
        }
    }

    private VerificationStatus(Parcel in) {
        mIsVerified = in.readBoolean();
        mIsLite = in.readBoolean();
        mAslStatus = in.readInt();
        mFailuresMessage = in.readString8();
    }
@@ -147,6 +177,7 @@ public final class VerificationStatus implements Parcelable {
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeBoolean(mIsVerified);
        dest.writeBoolean(mIsLite);
        dest.writeInt(mAslStatus);
        dest.writeString8(mFailuresMessage);
    }
Loading