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 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 requires that a profile owner is set. 34 * 35 * <p>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#profileOwner()} to interact with the profile owner. 38 */ 39 @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE}) 40 @Retention(RetentionPolicy.RUNTIME) 41 @RequireFeature(FEATURE_DEVICE_ADMIN) 42 public @interface EnsureHasProfileOwner { 43 /** Which user type the work profile should be attached to. */ onUser()44 UserType onUser() default INSTRUMENTED_USER; 45 46 /** 47 * Whether this DPC should be returned by calls to {@code Devicestate#dpc()} or 48 * {@code Devicestate#policyManager()}}. 49 * 50 * <p>Only one policy manager per test should be marked as primary. 51 */ isPrimary()52 boolean isPrimary() default false; 53 54 /** 55 * If true, uses the {@code DevicePolicyManager#getParentProfileInstance(ComponentName)} 56 * instance of the dpc when calling to .dpc() 57 * 58 * <p>Only used if {@link #isPrimary()} is true. 59 */ useParentInstance()60 boolean useParentInstance() default false; 61 62 /** 63 * Affiliation ids to be set for the profile owner. 64 */ affiliationIds()65 String[] affiliationIds() default {}; 66 67 /** 68 * Weight sets the order that annotations will be resolved. 69 * 70 * <p>Annotations with a lower weight will be resolved before annotations with a higher weight. 71 * 72 * <p>If there is an order requirement between annotations, ensure that the weight of the 73 * annotation which must be resolved first is lower than the one which must be resolved later. 74 * 75 * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}. 76 */ weight()77 int weight() default DO_PO_WEIGHT; 78 } 79