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

Commit 8afe3c41 authored by Victor Gabriel Savu's avatar Victor Gabriel Savu Committed by Android (Google) Code Review
Browse files

Merge "Move @PolicyDefinition inside the type specific one" into main

parents 973f82f2 8ea1f832
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -92,8 +92,9 @@ public final class PolicyIdentifier<T> {
     */
     */
    @FlaggedApi(FLAG_POLICY_STREAMLINING)
    @FlaggedApi(FLAG_POLICY_STREAMLINING)
    @NonNull
    @NonNull
    @PolicyDefinition
    @BooleanPolicyDefinition(
    @BooleanPolicyDefinition
            base = @PolicyDefinition
    )
    public static final PolicyIdentifier<Boolean> SCREEN_CAPTURE_DISABLED = new PolicyIdentifier<>(
    public static final PolicyIdentifier<Boolean> SCREEN_CAPTURE_DISABLED = new PolicyIdentifier<>(
            SCREEN_CAPTURE_DISABLED_KEY);
            SCREEN_CAPTURE_DISABLED_KEY);
}
}
+4 −0
Original line number Original line Diff line number Diff line
@@ -27,4 +27,8 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.SOURCE)
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.FIELD})
@Target({ElementType.FIELD})
public @interface BooleanPolicyDefinition {
public @interface BooleanPolicyDefinition {
    /**
     * Base data for all policies.
     */
    PolicyDefinition base();
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,11 @@ package android.processor.devicepolicy;
 * Metadata for a enum policy. Represented by an Integer.
 * Metadata for a enum policy. Represented by an Integer.
 */
 */
public @interface EnumPolicyDefinition {
public @interface EnumPolicyDefinition {
    /**
     * Base data for all policies.
     */
    PolicyDefinition base();

    /**
    /**
     * Indicates which IntDef represents this enum.
     * Indicates which IntDef represents this enum.
     */
     */
+2 −6
Original line number Original line Diff line number Diff line
@@ -16,24 +16,20 @@


package android.processor.devicepolicy;
package android.processor.devicepolicy;


import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


/**
/**
 * Define a policy.
 * Define a policy.
 * <p>
 * <p>
 * Can only be applied to fields inside {@link android.app.admin.PolicyIdentifier}.
 * Can only be applied to fields inside {@link android.app.admin.PolicyIdentifier} by nesting it in
 * a type specific annotation such as {@link EnumPolicyDefinition}.
 * The field must be static final and have a type of {@link android.app.admin.PolicyIdentifier}.
 * The field must be static final and have a type of {@link android.app.admin.PolicyIdentifier}.
 * In addition to this annotation, a type specific one must be present such as
 * {@link BooleanPolicyDefinition}.
 * </p>
 * </p>
 *
 *
 *  The name of the policy is taken from the field name.
 *  The name of the policy is taken from the field name.
 *  The type is the parameter passed to {@link android.app.admin.PolicyIdentifier}.
 *  The type is the parameter passed to {@link android.app.admin.PolicyIdentifier}.
 */
 */
@Retention(RetentionPolicy.SOURCE)
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.FIELD})
public @interface PolicyDefinition {
public @interface PolicyDefinition {
}
}
+9 −4
Original line number Original line Diff line number Diff line
@@ -27,7 +27,7 @@ import javax.lang.model.type.TypeMirror
 * Since this annotation holds no data and we don't export any type-specific information, this only
 * Since this annotation holds no data and we don't export any type-specific information, this only
 * contains type-specific checks.
 * contains type-specific checks.
 */
 */
class BooleanProcessor(processingEnv: ProcessingEnvironment) : Processor(processingEnv) {
class BooleanProcessor(processingEnv: ProcessingEnvironment) : Processor<BooleanPolicyDefinition>(processingEnv) {
    private companion object {
    private companion object {
        const val SIMPLE_TYPE_BOOLEAN = "java.lang.Boolean"
        const val SIMPLE_TYPE_BOOLEAN = "java.lang.Boolean"
    }
    }
@@ -41,8 +41,9 @@ class BooleanProcessor(processingEnv: ProcessingEnvironment) : Processor(process
     *
     *
     * @return null if the element does not have a @BooleanPolicyDefinition or on error, {@link BooleanPolicyMetadata} otherwise.
     * @return null if the element does not have a @BooleanPolicyDefinition or on error, {@link BooleanPolicyMetadata} otherwise.
     */
     */
    fun process(element: Element): BooleanPolicyMetadata? {
    override fun processMetadata(element: Element): Pair<PolicyMetadata, PolicyDefinition>? {
        element.getAnnotation(BooleanPolicyDefinition::class.java) ?: return null
        val booleanDefinition = element.getAnnotation(BooleanPolicyDefinition::class.java)
            ?: throw IllegalStateException("Processor should only be called on elements with @BooleanPolicyMetadata")


        if (!processingEnv.typeUtils.isSameType(policyType(element), booleanType)) {
        if (!processingEnv.typeUtils.isSameType(policyType(element), booleanType)) {
            printError(
            printError(
@@ -51,7 +52,11 @@ class BooleanProcessor(processingEnv: ProcessingEnvironment) : Processor(process
            )
            )
        }
        }


        return BooleanPolicyMetadata()
        return Pair(BooleanPolicyMetadata(), booleanDefinition.base)
    }

    override fun annotationClass(): Class<BooleanPolicyDefinition> {
        return BooleanPolicyDefinition::class.java
    }
    }
}
}


Loading