• 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.AnnotationRunPrecedence.MIDDLE;
20 import static com.android.bedstead.nene.packages.CommonPackages.FEATURE_DEVICE_ADMIN;
21 
22 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
23 import com.android.bedstead.harrier.annotations.FailureMode;
24 import com.android.bedstead.harrier.annotations.RequireFeature;
25 
26 import java.lang.annotation.ElementType;
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 that a device owner is available on the device.
33  *
34  * <p>Your test configuration may be configured so that this test is only run on a device which has
35  * a device owner. Otherwise, you can use {@code Devicestate} to ensure that the device enters
36  * the correct state for the method. If using {@code Devicestate}, you can use
37  * {@code Devicestate#deviceOwner()} to interact with the device owner.
38  *
39  * <p>When running on a device with a headless system user, enforcing this with {@code Devicestate}
40  * will also result in the profile owner of the current user being set to the same device policy
41  * controller.
42  *
43  * <p>If {@code Devicestate} is required to set the device owner (because there isn't one already)
44  * then all users and accounts may be removed from the device.
45  */
46 @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE})
47 @Retention(RetentionPolicy.RUNTIME)
48 @RequireFeature(FEATURE_DEVICE_ADMIN)
49 public @interface EnsureHasDeviceOwner {
50 
51     int DO_PO_WEIGHT = MIDDLE;
52 
53      /** Behaviour if the device owner cannot be set. */
failureMode()54     FailureMode failureMode() default FailureMode.FAIL;
55 
56     /**
57      * Whether this DPC should be returned by calls to {@code Devicestate#dpc()} or
58      * {@code Devicestate#policyManager()}}.
59      *
60      * <p>Only one policy manager per test should be marked as primary.
61      */
isPrimary()62     boolean isPrimary() default false;
63 
64     /**
65      * Affiliation ids to be set for the device owner.
66      */
affiliationIds()67     String[] affiliationIds() default {};
68 
69     /**
70      * Weight sets the order that annotations will be resolved.
71      *
72      * <p>Annotations with a lower weight will be resolved before annotations with a higher weight.
73      *
74      * <p>If there is an order requirement between annotations, ensure that the weight of the
75      * annotation which must be resolved first is lower than the one which must be resolved later.
76      *
77      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
78      */
weight()79     int weight() default DO_PO_WEIGHT;
80 }
81