1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.bedstead.permissions.annotations
18 
19 import com.android.bedstead.harrier.annotations.AnnotationPriorityRunPrecedence
20 import com.android.bedstead.harrier.annotations.FailureMode
21 import com.android.bedstead.harrier.annotations.UsesAnnotationExecutor
22 import com.google.auto.value.AutoAnnotation
23 
24 /**
25  * Ensure that the given permission is granted before running the test.
26  */
27 @Target(
28     AnnotationTarget.FUNCTION,
29     AnnotationTarget.PROPERTY_GETTER,
30     AnnotationTarget.PROPERTY_SETTER,
31     AnnotationTarget.ANNOTATION_CLASS,
32     AnnotationTarget.CLASS,
33 )
34 @Retention(AnnotationRetention.RUNTIME)
35 @UsesAnnotationExecutor(UsesAnnotationExecutor.PERMISSIONS)
36 annotation class EnsureHasPermission(
37 
38     vararg val value: String,
39 
40     val failureMode: FailureMode = FailureMode.FAIL,
41 
42     /** The minimum version where this permission is required. */
43     val minVersion: Int = 0,
44 
45     /** The maximum version where this permission is required. */
46     val maxVersion: Int = Int.MAX_VALUE,
47 
48     /**
49      * Priority sets the order that annotations will be resolved.
50      *
51      *
52      * Annotations with a lower priority will be resolved before annotations with a higher
53      * priority.
54      *
55      *
56      * If there is an order requirement between annotations, ensure that the priority of the
57      * annotation which must be resolved first is lower than the one which must be resolved later.
58      *
59      *
60      * Priority can be set to a [AnnotationPriorityRunPrecedence] constant, or to any [int].
61      */
62     val priority: Int = AnnotationPriorityRunPrecedence.EARLY
63 )
64 
65 /**
66  * Return an instance of the generated class that conforms to the specification of
67  * [EnsureHasPermission]. See [AutoAnnotation].
68  */
69 @AutoAnnotation
ensureHasPermissionnull70 fun ensureHasPermission(vararg value: String): EnsureHasPermission {
71     return AutoAnnotation_EnsureHasPermissionKt_ensureHasPermission(value)
72 }
73