1 /* 2 * Copyright (C) 2024 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 package com.android.bedstead.enterprise.annotations 17 18 import com.android.bedstead.harrier.UserType.INSTRUMENTED_USER 19 20 import com.android.bedstead.harrier.annotations.AnnotationPriorityRunPrecedence 21 import com.android.bedstead.harrier.annotations.RequireFeature 22 import com.android.bedstead.harrier.annotations.RequireNotInstantApp 23 import com.android.bedstead.harrier.UserType 24 import com.android.bedstead.harrier.annotations.UsesAnnotationExecutor 25 import com.android.bedstead.nene.packages.CommonPackages 26 import com.android.queryable.annotations.Query 27 import java.lang.annotation.Repeatable 28 29 /** 30 * Mark that a test requires that a device admin is available on the device. 31 * 32 * <p>Your test configuration may be configured so that this test is only run on a device which has 33 * a device admin. Otherwise, you can use {@code DeviceState} to ensure that the device enters 34 * the correct state for the method. If using {@code DeviceState}, you can use 35 * {@code DeviceState#deviceAdmin()} to interact with the device admin. 36 */ 37 @Target( 38 AnnotationTarget.FUNCTION, 39 AnnotationTarget.ANNOTATION_CLASS, 40 AnnotationTarget.CLASS) 41 @Retention(AnnotationRetention.RUNTIME) 42 @RequireFeature(CommonPackages.FEATURE_DEVICE_ADMIN) 43 @RequireNotInstantApp(reason = "Instant Apps cannot run Enterprise Tests") 44 @Repeatable(EnsureHasDeviceAdminGroup::class) 45 @UsesAnnotationExecutor(UsesAnnotationExecutor.ENTERPRISE) 46 annotation class EnsureHasDeviceAdmin( 47 /** A key which uniquely identifies the device admin for the test. */ 48 val key: String = DEFAULT_KEY, 49 /** Which user type the device admin should be installed on. */ 50 val onUser: UserType = INSTRUMENTED_USER, 51 /** 52 * Whether this device admin should be returned by calls to `Devicestate#dpc()`. 53 * 54 * 55 * Only one policy manager per test should be marked as primary. 56 */ 57 val isPrimary: Boolean = false, 58 /** 59 * Requirements for the Device Admin 60 */ 61 val dpc: Query = Query(), 62 /** 63 * Weight sets the order that annotations will be resolved. 64 * 65 * 66 * Annotations with a lower weight will be resolved before annotations with a higher weight. 67 * 68 * 69 * If there is an order requirement between annotations, ensure that the weight of the 70 * annotation which must be resolved first is lower than the one which must be resolved later. 71 * 72 * 73 * Weight can be set to a `AnnotationPriorityRunPrecedence` constant, or to any [int]. 74 */ 75 val weight: Int = ENSURE_HAS_DEVICE_ADMIN_WEIGHT) { 76 companion object { 77 const val ENSURE_HAS_DEVICE_ADMIN_WEIGHT = AnnotationPriorityRunPrecedence.MIDDLE 78 const val DEFAULT_KEY = "remoteDeviceAdmin" 79 } 80 } 81