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

Commit f9e1c302 authored by Winson's avatar Winson
Browse files

Move domain state ints to DomainVerificationInfo

Hides the internal values and exposes a smaller set of defined values
for each specific case the domain verification agent might be
interested in.

These values are only for the public API output and all other classes
should continue to use the internal DomainVerificationState.

Bug: 181100856

Test: atest com.android.server.pm.test.verify.domain

Change-Id: I2b16d14bbf3a70e4c2e3f4b358af8671aed71490
parent 0c4110e0
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -2835,21 +2835,22 @@ package android.content.pm.verify.domain {
    method @NonNull public String getPackageName();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.verify.domain.DomainVerificationInfo> CREATOR;
    field public static final int STATE_FIRST_VERIFIER_DEFINED = 1024; // 0x400
    field public static final int STATE_MODIFIABLE_UNVERIFIED = 3; // 0x3
    field public static final int STATE_MODIFIABLE_VERIFIED = 4; // 0x4
    field public static final int STATE_NO_RESPONSE = 0; // 0x0
    field public static final int STATE_SUCCESS = 1; // 0x1
    field public static final int STATE_UNMODIFIABLE = 2; // 0x2
  }
  public final class DomainVerificationManager {
    method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.DOMAIN_VERIFICATION_AGENT, android.Manifest.permission.UPDATE_DOMAIN_VERIFICATION_USER_SELECTION}) public android.content.pm.verify.domain.DomainVerificationInfo getDomainVerificationInfo(@NonNull String) throws android.content.pm.PackageManager.NameNotFoundException;
    method @NonNull @RequiresPermission(android.Manifest.permission.UPDATE_DOMAIN_VERIFICATION_USER_SELECTION) public java.util.List<android.content.pm.verify.domain.DomainOwner> getOwnersForDomain(@NonNull String);
    method public static boolean isStateModifiable(int);
    method public static boolean isStateVerified(int);
    method @NonNull @RequiresPermission(android.Manifest.permission.DOMAIN_VERIFICATION_AGENT) public java.util.List<java.lang.String> queryValidVerificationPackageNames();
    method @RequiresPermission(android.Manifest.permission.UPDATE_DOMAIN_VERIFICATION_USER_SELECTION) public void setDomainVerificationLinkHandlingAllowed(@NonNull String, boolean) throws android.content.pm.PackageManager.NameNotFoundException;
    method @RequiresPermission(android.Manifest.permission.DOMAIN_VERIFICATION_AGENT) public void setDomainVerificationStatus(@NonNull java.util.UUID, @NonNull java.util.Set<java.lang.String>, int) throws android.content.pm.PackageManager.NameNotFoundException;
    method @RequiresPermission(android.Manifest.permission.UPDATE_DOMAIN_VERIFICATION_USER_SELECTION) public void setDomainVerificationUserSelection(@NonNull java.util.UUID, @NonNull java.util.Set<java.lang.String>, boolean) throws android.content.pm.PackageManager.NameNotFoundException;
    field public static final String EXTRA_VERIFICATION_REQUEST = "android.content.pm.verify.domain.extra.VERIFICATION_REQUEST";
    field public static final int STATE_FIRST_VERIFIER_DEFINED = 1024; // 0x400
    field public static final int STATE_NO_RESPONSE = 0; // 0x0
    field public static final int STATE_SUCCESS = 1; // 0x1
  }
  public final class DomainVerificationRequest implements android.os.Parcelable {
+92 −30
Original line number Diff line number Diff line
@@ -43,9 +43,50 @@ import java.util.UUID;
 */
@SystemApi
@DataClass(genAidl = true, genHiddenConstructor = true, genParcelable = true, genToString = true,
        genEqualsHashCode = true)
        genEqualsHashCode = true, genHiddenConstDefs = true)
public final class DomainVerificationInfo implements Parcelable {

    // Implementation note: the following states are OUTPUT only. Any value that is synonymous with
    // a value in DomainVerificationState must be the EXACT same integer, so that state
    // transformation does not have to occur when sending input into the system, assuming that the
    // system only accepts those synonymous values. The public API values declared here are only
    // used when exiting the system server to prepare this data object for consumption by the
    // verification agent. These constants should only be referenced inside public API classes.
    // The server must use DomainVerificationState.

    /**
     * No response has been recorded by either the system or any verification agent.
     */
    public static final int STATE_NO_RESPONSE = DomainVerificationState.STATE_NO_RESPONSE;

    /**
     * The domain has been explicitly verified.
     */
    public static final int STATE_SUCCESS = DomainVerificationState.STATE_SUCCESS;

    /**
     * Indicates the host cannot be modified by the verification agent.
     */
    public static final int STATE_UNMODIFIABLE = 2;

    /**
     * Indicates the host can be modified by the verification agent and is not considered verified.
     */
    public static final int STATE_MODIFIABLE_UNVERIFIED = 3;

    /**
     * Indicates the host can be modified by the verification agent and is considered verified.
     */
    public static final int STATE_MODIFIABLE_VERIFIED = 4;

    /**
     * The first available custom response code. This and any greater integer, along with {@link
     * #STATE_SUCCESS} are the only values settable by the verification agent. All custom values
     * will be treated as if the domain is unverified.
     */
    public static final int STATE_FIRST_VERIFIER_DEFINED =
            DomainVerificationState.STATE_FIRST_VERIFIER_DEFINED;

    /**
     * A domain verification ID for use in later API calls. This represents the snapshot of the
     * domains for a package on device, and will be invalidated whenever the package changes.
@@ -74,16 +115,12 @@ public final class DomainVerificationInfo implements Parcelable {

    /**
     * Map of host names to their current state. State is an integer, which defaults to {@link
     * DomainVerificationManager#STATE_NO_RESPONSE}. State can be modified by the domain
     * verification agent (the intended consumer of this API), which can be equal to {@link
     * DomainVerificationManager#STATE_SUCCESS} when verified, or equal to or greater than {@link
     * DomainVerificationManager#STATE_FIRST_VERIFIER_DEFINED} for any unsuccessful response.
     * #STATE_NO_RESPONSE}. State can be modified by the domain verification agent (the intended
     * consumer of this API), which can be equal to {@link #STATE_SUCCESS} when verified, or equal
     * to or greater than {@link #STATE_FIRST_VERIFIER_DEFINED} for any unsuccessful response.
     * <p>
     * Any value non-inclusive between those 2 values are reserved for use by the system. The domain
     * verification agent may be able to act on these reserved values, and this ability can be
     * queried using {@link DomainVerificationManager#isStateModifiable(int)}. It is expected that
     * the agent attempt to verify all domains that it can modify the state of, even if it does not
     * understand the meaning of those values.
     * Hosts which cannot be edited will be assigned {@link #STATE_UNMODIFIABLE}. It is expected
     * that the agent attempt to verify all domains that it can modify the state of.
     */
    @NonNull
    private final Map<String, Integer> mHostToStateMap;
@@ -112,6 +149,39 @@ public final class DomainVerificationInfo implements Parcelable {
    //@formatter:off


    /** @hide */
    @android.annotation.IntDef(prefix = "STATE_", value = {
        STATE_NO_RESPONSE,
        STATE_SUCCESS,
        STATE_UNMODIFIABLE,
        STATE_MODIFIABLE_UNVERIFIED,
        STATE_MODIFIABLE_VERIFIED,
        STATE_FIRST_VERIFIER_DEFINED
    })
    @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
    @DataClass.Generated.Member
    public @interface State {}

    /** @hide */
    @DataClass.Generated.Member
    public static String stateToString(@State int value) {
        switch (value) {
            case STATE_NO_RESPONSE:
                    return "STATE_NO_RESPONSE";
            case STATE_SUCCESS:
                    return "STATE_SUCCESS";
            case STATE_UNMODIFIABLE:
                    return "STATE_UNMODIFIABLE";
            case STATE_MODIFIABLE_UNVERIFIED:
                    return "STATE_MODIFIABLE_UNVERIFIED";
            case STATE_MODIFIABLE_VERIFIED:
                    return "STATE_MODIFIABLE_VERIFIED";
            case STATE_FIRST_VERIFIER_DEFINED:
                    return "STATE_FIRST_VERIFIER_DEFINED";
            default: return Integer.toHexString(value);
        }
    }

    /**
     * Creates a new DomainVerificationInfo.
     *
@@ -134,16 +204,12 @@ public final class DomainVerificationInfo implements Parcelable {
     *   The package name that this data corresponds to.
     * @param hostToStateMap
     *   Map of host names to their current state. State is an integer, which defaults to {@link
     *   DomainVerificationManager#STATE_NO_RESPONSE}. State can be modified by the domain
     *   verification agent (the intended consumer of this API), which can be equal to {@link
     *   DomainVerificationManager#STATE_SUCCESS} when verified, or equal to or greater than {@link
     *   DomainVerificationManager#STATE_FIRST_VERIFIER_DEFINED} for any unsuccessful response.
     *   #STATE_NO_RESPONSE}. State can be modified by the domain verification agent (the intended
     *   consumer of this API), which can be equal to {@link #STATE_SUCCESS} when verified, or equal
     *   to or greater than {@link #STATE_FIRST_VERIFIER_DEFINED} for any unsuccessful response.
     *   <p>
     *   Any value non-inclusive between those 2 values are reserved for use by the system. The domain
     *   verification agent may be able to act on these reserved values, and this ability can be
     *   queried using {@link DomainVerificationManager#isStateModifiable(int)}. It is expected that
     *   the agent attempt to verify all domains that it can modify the state of, even if it does not
     *   understand the meaning of those values.
     *   Hosts which cannot be edited will be assigned {@link #STATE_UNMODIFIABLE}. It is expected
     *   that the agent attempt to verify all domains that it can modify the state of.
     * @hide
     */
    @DataClass.Generated.Member
@@ -195,16 +261,12 @@ public final class DomainVerificationInfo implements Parcelable {

    /**
     * Map of host names to their current state. State is an integer, which defaults to {@link
     * DomainVerificationManager#STATE_NO_RESPONSE}. State can be modified by the domain
     * verification agent (the intended consumer of this API), which can be equal to {@link
     * DomainVerificationManager#STATE_SUCCESS} when verified, or equal to or greater than {@link
     * DomainVerificationManager#STATE_FIRST_VERIFIER_DEFINED} for any unsuccessful response.
     * #STATE_NO_RESPONSE}. State can be modified by the domain verification agent (the intended
     * consumer of this API), which can be equal to {@link #STATE_SUCCESS} when verified, or equal
     * to or greater than {@link #STATE_FIRST_VERIFIER_DEFINED} for any unsuccessful response.
     * <p>
     * Any value non-inclusive between those 2 values are reserved for use by the system. The domain
     * verification agent may be able to act on these reserved values, and this ability can be
     * queried using {@link DomainVerificationManager#isStateModifiable(int)}. It is expected that
     * the agent attempt to verify all domains that it can modify the state of, even if it does not
     * understand the meaning of those values.
     * Hosts which cannot be edited will be assigned {@link #STATE_UNMODIFIABLE}. It is expected
     * that the agent attempt to verify all domains that it can modify the state of.
     */
    @DataClass.Generated.Member
    public @NonNull Map<String,Integer> getHostToStateMap() {
@@ -320,10 +382,10 @@ public final class DomainVerificationInfo implements Parcelable {
    };

    @DataClass.Generated(
            time = 1614721812023L,
            time = 1615317187669L,
            codegenVersion = "1.0.22",
            sourceFile = "frameworks/base/core/java/android/content/pm/verify/domain/DomainVerificationInfo.java",
            inputSignatures = "private final @android.annotation.NonNull @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForUUID.class) java.util.UUID mIdentifier\nprivate final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull java.util.Map<java.lang.String,java.lang.Integer> mHostToStateMap\nprivate  void parcelHostToStateMap(android.os.Parcel,int)\nprivate  java.util.Map<java.lang.String,java.lang.Integer> unparcelHostToStateMap(android.os.Parcel)\nclass DomainVerificationInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genAidl=true, genHiddenConstructor=true, genParcelable=true, genToString=true, genEqualsHashCode=true)")
            inputSignatures = "public static final  int STATE_NO_RESPONSE\npublic static final  int STATE_SUCCESS\npublic static final  int STATE_UNMODIFIABLE\npublic static final  int STATE_MODIFIABLE_UNVERIFIED\npublic static final  int STATE_MODIFIABLE_VERIFIED\npublic static final  int STATE_FIRST_VERIFIER_DEFINED\nprivate final @android.annotation.NonNull @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForUUID.class) java.util.UUID mIdentifier\nprivate final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull java.util.Map<java.lang.String,java.lang.Integer> mHostToStateMap\nprivate  void parcelHostToStateMap(android.os.Parcel,int)\nprivate  java.util.Map<java.lang.String,java.lang.Integer> unparcelHostToStateMap(android.os.Parcel)\nclass DomainVerificationInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genAidl=true, genHiddenConstructor=true, genParcelable=true, genToString=true, genEqualsHashCode=true, genHiddenConstDefs=true)")
    @Deprecated
    private void __metadata() {}

+1 −104
Original line number Diff line number Diff line
@@ -59,109 +59,6 @@ public final class DomainVerificationManager {
    public static final String EXTRA_VERIFICATION_REQUEST =
            "android.content.pm.verify.domain.extra.VERIFICATION_REQUEST";

    /**
     * No response has been recorded by either the system or any verification agent.
     *
     * @hide
     */
    @SystemApi
    public static final int STATE_NO_RESPONSE = DomainVerificationState.STATE_NO_RESPONSE;

    /**
     * The verification agent has explicitly verified the domain at some point.
     *
     * @hide
     */
    @SystemApi
    public static final int STATE_SUCCESS = DomainVerificationState.STATE_SUCCESS;

    /**
     * The first available custom response code. This and any greater integer, along with {@link
     * #STATE_SUCCESS} are the only values settable by the verification agent. All values will be
     * treated as if the domain is unverified.
     *
     * @hide
     */
    @SystemApi
    public static final int STATE_FIRST_VERIFIER_DEFINED =
            DomainVerificationState.STATE_FIRST_VERIFIER_DEFINED;

    /**
     * @hide
     */
    @NonNull
    public static String stateToDebugString(@DomainVerificationState.State int state) {
        switch (state) {
            case DomainVerificationState.STATE_NO_RESPONSE:
                return "none";
            case DomainVerificationState.STATE_SUCCESS:
                return "verified";
            case DomainVerificationState.STATE_APPROVED:
                return "approved";
            case DomainVerificationState.STATE_DENIED:
                return "denied";
            case DomainVerificationState.STATE_MIGRATED:
                return "migrated";
            case DomainVerificationState.STATE_RESTORED:
                return "restored";
            case DomainVerificationState.STATE_LEGACY_FAILURE:
                return "legacy_failure";
            case DomainVerificationState.STATE_SYS_CONFIG:
                return "system_configured";
            default:
                return String.valueOf(state);
        }
    }

    /**
     * Checks if a state considers the corresponding domain to be successfully verified. The domain
     * verification agent may use this to determine whether or not to re-verify a domain.
     *
     * @hide
     */
    @SystemApi
    public static boolean isStateVerified(@DomainVerificationState.State int state) {
        switch (state) {
            case DomainVerificationState.STATE_SUCCESS:
            case DomainVerificationState.STATE_APPROVED:
            case DomainVerificationState.STATE_MIGRATED:
            case DomainVerificationState.STATE_RESTORED:
            case DomainVerificationState.STATE_SYS_CONFIG:
                return true;
            case DomainVerificationState.STATE_NO_RESPONSE:
            case DomainVerificationState.STATE_DENIED:
            case DomainVerificationState.STATE_LEGACY_FAILURE:
            default:
                return false;
        }
    }

    /**
     * Checks if a state is modifiable by the domain verification agent. This is useful as the
     * platform may add new state codes in newer versions, and older verification agents can use
     * this method to determine if a state can be changed without having to be aware of what the new
     * state means.
     *
     * @hide
     */
    @SystemApi
    public static boolean isStateModifiable(@DomainVerificationState.State int state) {
        switch (state) {
            case DomainVerificationState.STATE_NO_RESPONSE:
            case DomainVerificationState.STATE_SUCCESS:
            case DomainVerificationState.STATE_MIGRATED:
            case DomainVerificationState.STATE_RESTORED:
            case DomainVerificationState.STATE_LEGACY_FAILURE:
                return true;
            case DomainVerificationState.STATE_APPROVED:
            case DomainVerificationState.STATE_DENIED:
            case DomainVerificationState.STATE_SYS_CONFIG:
                return false;
            default:
                return state >= DomainVerificationState.STATE_FIRST_VERIFIER_DEFINED;
        }
    }

    /**
     * @hide
     */
@@ -282,7 +179,7 @@ public final class DomainVerificationManager {
    @SystemApi
    @RequiresPermission(android.Manifest.permission.DOMAIN_VERIFICATION_AGENT)
    public void setDomainVerificationStatus(@NonNull UUID domainSetId, @NonNull Set<String> domains,
            @DomainVerificationState.State int state) throws NameNotFoundException {
            int state) throws NameNotFoundException {
        try {
            mDomainVerificationManager.setDomainVerificationStatus(domainSetId.toString(),
                    new DomainSet(domains), state);
+87 −10
Original line number Diff line number Diff line
@@ -17,15 +17,13 @@
package android.content.pm.verify.domain;

import android.annotation.IntDef;
import android.annotation.NonNull;

/**
 * @hide
 */
public interface DomainVerificationState {

    /**
     * @hide
     */
    @IntDef({
            STATE_NO_RESPONSE,
            STATE_SUCCESS,
@@ -42,12 +40,12 @@ public interface DomainVerificationState {

    // TODO(b/159952358): Document all the places that states need to be updated when one is added
    /**
     * @see DomainVerificationManager#STATE_NO_RESPONSE
     * @see DomainVerificationInfo#STATE_NO_RESPONSE
     */
    int STATE_NO_RESPONSE = 0;

    /**
     * @see DomainVerificationManager#STATE_SUCCESS
     * @see DomainVerificationInfo#STATE_SUCCESS
     */
    int STATE_SUCCESS = 1;

@@ -94,16 +92,37 @@ public interface DomainVerificationState {
    int STATE_SYS_CONFIG = 7;

    /**
     * @see DomainVerificationManager#STATE_FIRST_VERIFIER_DEFINED
     * @see DomainVerificationInfo#STATE_FIRST_VERIFIER_DEFINED
     */
    int STATE_FIRST_VERIFIER_DEFINED = 0b10000000000;

    @NonNull
    static String stateToDebugString(@DomainVerificationState.State int state) {
        switch (state) {
            case DomainVerificationState.STATE_NO_RESPONSE:
                return "none";
            case DomainVerificationState.STATE_SUCCESS:
                return "verified";
            case DomainVerificationState.STATE_APPROVED:
                return "approved";
            case DomainVerificationState.STATE_DENIED:
                return "denied";
            case DomainVerificationState.STATE_MIGRATED:
                return "migrated";
            case DomainVerificationState.STATE_RESTORED:
                return "restored";
            case DomainVerificationState.STATE_LEGACY_FAILURE:
                return "legacy_failure";
            case DomainVerificationState.STATE_SYS_CONFIG:
                return "system_configured";
            default:
                return String.valueOf(state);
        }
    }

    /**
     * For determining re-verify policy. This is hidden from the domain verification agent so that
     * no behavior is made based on the result.
     *
     * @hide
     */
    static boolean isDefault(@State int state) {
        switch (state) {
@@ -121,11 +140,52 @@ public interface DomainVerificationState {
        }
    }

    /**
     * Checks if a state considers the corresponding domain to be successfully verified. The domain
     * verification agent may use this to determine whether or not to re-verify a domain.
     */
    static boolean isVerified(@DomainVerificationState.State int state) {
        switch (state) {
            case DomainVerificationState.STATE_SUCCESS:
            case DomainVerificationState.STATE_APPROVED:
            case DomainVerificationState.STATE_MIGRATED:
            case DomainVerificationState.STATE_RESTORED:
            case DomainVerificationState.STATE_SYS_CONFIG:
                return true;
            case DomainVerificationState.STATE_NO_RESPONSE:
            case DomainVerificationState.STATE_DENIED:
            case DomainVerificationState.STATE_LEGACY_FAILURE:
            default:
                return false;
        }
    }

    /**
     * Checks if a state is modifiable by the domain verification agent. This is useful as the
     * platform may add new state codes in newer versions, and older verification agents can use
     * this method to determine if a state can be changed without having to be aware of what the new
     * state means.
     */
    static boolean isModifiable(@DomainVerificationState.State int state) {
        switch (state) {
            case DomainVerificationState.STATE_NO_RESPONSE:
            case DomainVerificationState.STATE_SUCCESS:
            case DomainVerificationState.STATE_MIGRATED:
            case DomainVerificationState.STATE_RESTORED:
            case DomainVerificationState.STATE_LEGACY_FAILURE:
                return true;
            case DomainVerificationState.STATE_APPROVED:
            case DomainVerificationState.STATE_DENIED:
            case DomainVerificationState.STATE_SYS_CONFIG:
                return false;
            default:
                return state >= DomainVerificationState.STATE_FIRST_VERIFIER_DEFINED;
        }
    }

    /**
     * Whether the state is migrated when updating a package. Generally this is only for states
     * that maintain verification state or were set by an explicit user or developer action.
     *
     * @hide
     */
    static boolean shouldMigrate(@State int state) {
        switch (state) {
@@ -143,4 +203,21 @@ public interface DomainVerificationState {
                return false;
        }
    }

    @DomainVerificationInfo.State
    static int convertToInfoState(@State int internalState) {
        if (internalState >= STATE_FIRST_VERIFIER_DEFINED) {
            return internalState;
        } else if (internalState == STATE_NO_RESPONSE) {
            return DomainVerificationInfo.STATE_NO_RESPONSE;
        } else if (internalState == STATE_SUCCESS) {
            return DomainVerificationInfo.STATE_SUCCESS;
        } else if (!isModifiable(internalState)) {
            return DomainVerificationInfo.STATE_UNMODIFIABLE;
        } else if (isVerified(internalState)) {
            return DomainVerificationInfo.STATE_MODIFIABLE_VERIFIED;
        } else {
            return DomainVerificationInfo.STATE_MODIFIABLE_UNVERIFIED;
        }
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.content.pm.verify.domain.DomainVerificationManager;
import android.content.pm.verify.domain.DomainVerificationState;
import android.os.UserHandle;
import android.util.ArrayMap;
@@ -151,7 +150,7 @@ public class DomainVerificationDebug {
                Integer state = reusedMap.valueAt(stateIndex);
                writer.print(domain);
                writer.print(": ");
                writer.println(DomainVerificationManager.stateToDebugString(state));
                writer.println(DomainVerificationState.stateToDebugString(state));
            }
            writer.decreaseIndent();
            writer.decreaseIndent();
Loading