• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.harrier.annotations;
18 
19 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.MIDDLE;
20 
21 import com.android.bedstead.harrier.UserType;
22 import com.android.bedstead.harrier.annotations.enterprise.AdditionalQueryParameters;
23 import com.android.queryable.annotations.Query;
24 
25 import java.lang.annotation.ElementType;
26 import java.lang.annotation.Repeatable;
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 import java.lang.annotation.Target;
30 
31 /**
32  * Mark that a test requires the given test app to be installed on the given user.
33  *
34  * <p>You should use {@code DeviceState} to ensure that the device enters
35  * the correct state for the method.
36  */
37 @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE})
38 @Retention(RetentionPolicy.RUNTIME)
39 @Repeatable(EnsureTestAppInstalledGroup.class)
40 public @interface EnsureTestAppInstalled {
41 
42     int ENSURE_TEST_APP_INSTALLED_WEIGHT = MIDDLE;
43 
44     String DEFAULT_KEY = "testApp";
45 
46     /**
47      * A key which uniquely identifies the test app for the test.
48      *
49      * <p>This can be used with e.g. {@code DeviceState#testApp} and
50      * {@link AdditionalQueryParameters}.
51      */
key()52     String key() default DEFAULT_KEY;
53 
54     /** Query specifying the testapp. Defaults to any test app. */
query()55     Query query() default @Query();
56 
57     /** The user the testApp should be installed on. */
onUser()58     UserType onUser() default UserType.INSTRUMENTED_USER;
59 
60     /**
61      * Whether this testApp should be returned by calls to {@code DeviceState#dpc()}.
62      *
63      * <p>Only one policy manager per test should be marked as primary.
64      */
isPrimary()65     boolean isPrimary() default false;
66 
67     /**
68      * Weight sets the order that annotations will be resolved.
69      *
70      * <p>Annotations with a lower weight will be resolved before annotations with a higher weight.
71      *
72      * <p>If there is an order requirement between annotations, ensure that the weight of the
73      * annotation which must be resolved first is lower than the one which must be resolved later.
74      *
75      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
76      */
weight()77     int weight() default ENSURE_TEST_APP_INSTALLED_WEIGHT;
78 }
79