• 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.enterprise;
18 
19 import static com.android.bedstead.harrier.annotations.enterprise.EnsureHasDevicePolicyManagerRoleHolder.ENSURE_HAS_DEVICE_POLICY_MANAGER_ROLE_HOLDER_WEIGHT;
20 
21 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
22 import com.android.bedstead.harrier.annotations.EnsureTestAppInstalled;
23 import com.android.queryable.annotations.IntegerQuery;
24 import com.android.queryable.annotations.Query;
25 import com.android.queryable.annotations.StringQuery;
26 
27 import java.lang.annotation.ElementType;
28 import java.lang.annotation.Retention;
29 import java.lang.annotation.RetentionPolicy;
30 import java.lang.annotation.Target;
31 
32 /**
33  * Mark that a test is testing a most important coexistence policy.
34  *
35  * <p>Tests can use {@code sDeviceState.testApp(MORE_IMPORTANT} and
36  * {@code sDeviceState.testApp(LESS_IMPORTANT} to get the different test apps to set the policy.
37  *
38  * <p>You can use {@code DeviceState} to ensure that the device enters the correct state for the
39  * method.
40  */
41 @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE})
42 @Retention(RetentionPolicy.RUNTIME)
43 @EnsureHasDeviceOwner // This will be the MORE_IMPORTANT, setup by DeviceState
44 @EnsureTestAppInstalled(key = MostImportantCoexistenceTest.LESS_IMPORTANT,
45         query = @Query(packageName = @StringQuery(
46                 isEqualTo = "com.android.bedstead.testapp.NotEmptyTestApp"),
47                 targetSdkVersion = @IntegerQuery(isGreaterThanOrEqualTo = 34)))
48 public @interface MostImportantCoexistenceTest {
49 
50     String MORE_IMPORTANT = "more_important";
51     String LESS_IMPORTANT = "less_important";
52 
53     /**
54      * The policy being tested.
55      *
56      * <p>This is only valid if the policy can be applied by a permission.
57      */
policy()58     Class<?> policy();
59 
60     /**
61      * Weight sets the order that annotations will be resolved.
62      *
63      * <p>Annotations with a lower weight will be resolved before annotations with a higher weight.
64      *
65      * <p>If there is an order requirement between annotations, ensure that the weight of the
66      * annotation which must be resolved first is lower than the one which must be resolved later.
67      *
68      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
69      */
weight()70     int weight() default ENSURE_HAS_DEVICE_POLICY_MANAGER_ROLE_HOLDER_WEIGHT + 1;
71 }
72