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