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.UserType.INSTRUMENTED_USER; 20 import static com.android.bedstead.harrier.annotations.enterprise.EnsureHasDeviceOwner.DO_PO_WEIGHT; 21 import static com.android.bedstead.nene.packages.CommonPackages.FEATURE_DEVICE_ADMIN; 22 23 import com.android.bedstead.harrier.UserType; 24 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence; 25 import com.android.bedstead.harrier.annotations.RequireFeature; 26 import com.android.bedstead.harrier.annotations.RequireNotInstantApp; 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 requires that a profile owner is set. 36 * 37 * <p>You can use {@code Devicestate} to ensure that the device enters 38 * the correct state for the method. If using {@code Devicestate}, you can use 39 * {@code Devicestate#profileOwner()} to interact with the profile owner. 40 */ 41 @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE}) 42 @Retention(RetentionPolicy.RUNTIME) 43 @RequireFeature(FEATURE_DEVICE_ADMIN) 44 // TODO(b/206441366): Add instant app support 45 @RequireNotInstantApp(reason = "Instant Apps cannot run Enterprise Tests") 46 public @interface EnsureHasProfileOwner { 47 /** Which user type the profile owner should be installed on. */ onUser()48 UserType onUser() default INSTRUMENTED_USER; 49 50 String DEFAULT_KEY = "profileOwner"; 51 52 /** 53 * The key used to identify this DPC. 54 * 55 * <p>This can be used with {@link AdditionalQueryParameters} to modify the requirements for 56 * the DPC. */ key()57 String key() default DEFAULT_KEY; 58 59 /** 60 * Requirements for the DPC 61 * 62 * <p>Defaults to the default version of RemoteDPC. 63 */ dpc()64 Query dpc() default @Query(); 65 66 /** 67 * Whether this DPC should be returned by calls to {@code Devicestate#dpc()}. 68 * 69 * <p>Only one policy manager per test should be marked as primary. 70 */ isPrimary()71 boolean isPrimary() default false; 72 73 /** 74 * If true, uses the {@code DevicePolicyManager#getParentProfileInstance(ComponentName)} 75 * instance of the dpc when calling to .dpc() 76 * 77 * <p>Only used if {@link #isPrimary()} is true. 78 */ useParentInstance()79 boolean useParentInstance() default false; 80 81 /** 82 * Affiliation ids to be set for the profile owner. 83 */ affiliationIds()84 String[] affiliationIds() default {}; 85 86 /** 87 * Weight sets the order that annotations will be resolved. 88 * 89 * <p>Annotations with a lower weight will be resolved before annotations with a higher weight. 90 * 91 * <p>If there is an order requirement between annotations, ensure that the weight of the 92 * annotation which must be resolved first is lower than the one which must be resolved later. 93 * 94 * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}. 95 */ weight()96 int weight() default DO_PO_WEIGHT; 97 } 98