• 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.enterprise.annotations;
18 
19 import static com.android.bedstead.harrier.annotations.AnnotationPriorityRunPrecedence.REQUIRE_RUN_ON_PRECEDENCE;
20 import static com.android.bedstead.nene.packages.CommonPackages.FEATURE_DEVICE_ADMIN;
21 import static com.android.bedstead.nene.types.OptionalBoolean.ANY;
22 import static com.android.bedstead.nene.types.OptionalBoolean.TRUE;
23 
24 import com.android.bedstead.harrier.annotations.AnnotationPriorityRunPrecedence;
25 import com.android.bedstead.harrier.annotations.Postsubmit;
26 import com.android.bedstead.harrier.annotations.RequireFeature;
27 import com.android.bedstead.harrier.annotations.UsesAnnotationExecutor;
28 import com.android.bedstead.harrier.annotations.enterprise.AdditionalQueryParameters;
29 import com.android.bedstead.nene.types.OptionalBoolean;
30 import com.android.queryable.annotations.Query;
31 
32 import java.lang.annotation.ElementType;
33 import java.lang.annotation.Retention;
34 import java.lang.annotation.RetentionPolicy;
35 import java.lang.annotation.Target;
36 
37 /**
38  * Mark that a test method should run within a work profile.
39  *
40  * <p>Your test configuration should be such that this test is only run where a work profile is
41  * created and the test is being run within that user.
42  *
43  * <p>Optionally, you can guarantee that these methods do not run outside of a work
44  * profile by using {@code Devicestate}.
45  *
46  * <p>This annotation by default opts a test into multi-user presubmit. New tests should also be
47  * annotated {@link Postsubmit} until they are shown to meet the multi-user presubmit requirements.
48  */
49 @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE})
50 @Retention(RetentionPolicy.RUNTIME)
51 @RequireFeature(FEATURE_DEVICE_ADMIN)
52 @UsesAnnotationExecutor(UsesAnnotationExecutor.ENTERPRISE)
53 public @interface RequireRunOnWorkProfile {
installInstrumentedAppInParent()54     OptionalBoolean installInstrumentedAppInParent() default ANY;
55 
56     String DEFAULT_KEY = "profileOwner";
57 
58     /**
59      * The key used to identify the profile owner.
60      *
61      * <p>This can be used with {@link AdditionalQueryParameters} to modify the requirements for
62      * the DPC. */
dpcKey()63     String dpcKey() default DEFAULT_KEY;
64 
65     /**
66      * Requirements for the Profile Owner.
67      *
68      * <p>Defaults to the default version of RemoteDPC.
69      */
dpc()70     Query dpc() default @Query();
71 
72     /**
73      * Whether the profile owner's DPC should be returned by calls to {@code Devicestate#dpc()}.
74      *
75      * <p>Only one device policy controller per test should be marked as primary.
76      */
dpcIsPrimary()77     boolean dpcIsPrimary() default false;
78 
79     /** Whether the work profile device will be in COPE mode. */
isOrganizationOwned()80     boolean isOrganizationOwned() default false;
81 
82     /**
83      * Affiliation ids to be set for the profile owner.
84      */
affiliationIds()85     String[] affiliationIds() default {};
86 
87     /**
88      * Should we ensure that we are switched to the parent of the profile.
89      *
90      * <p>ANY will be treated as TRUE if no other annotation has forced a switch.
91      */
switchedToParentUser()92     OptionalBoolean switchedToParentUser() default TRUE;
93 
94      /**
95      * Priority sets the order that annotations will be resolved.
96      *
97      * <p>Annotations with a lower priority will be resolved before annotations with a higher
98      * priority.
99      *
100      * <p>If there is an order requirement between annotations, ensure that the priority of the
101      * annotation which must be resolved first is lower than the one which must be resolved later.
102      *
103      * <p>Priority can be set to a {@link AnnotationPriorityRunPrecedence} constant, or to any {@link int}.
104      */
priority()105     int priority() default REQUIRE_RUN_ON_PRECEDENCE;
106 
107     String PROFILE_TYPE = "android.os.usertype.profile.MANAGED";
108 }
109