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.annotations.enterprise.EnsureHasDeviceOwner.DO_PO_WEIGHT; 20 21 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence; 22 import com.android.bedstead.harrier.annotations.RequireNotInstantApp; 23 24 import java.lang.annotation.ElementType; 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 import java.lang.annotation.Target; 28 29 /** 30 * Mark that a test requires that the given admin delegates the given scope to a test app. 31 * 32 * <p>You should use {@code DeviceState} to ensure that the device enters 33 * the correct state for the method. You can use {@code Devicestate#delegate()} to interact with 34 * the delegate. 35 */ 36 @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE}) 37 @Retention(RetentionPolicy.RUNTIME) 38 // TODO(b/206441366): Add instant app support 39 @RequireNotInstantApp(reason = "Instant Apps cannot run Enterprise Tests") 40 // TODO(b/219750042): If we leave over appops and permissions then the delegate will have them 41 public @interface EnsureHasDelegate { 42 43 /** The default key used for the testapp installed as delegate */ 44 String DELEGATE_KEY = "delegate"; 45 46 // TODO(276740719): Add support for customisable delegates 47 // /** 48 // * The key used to identify this delegate. 49 // * 50 // * <p>This can be used with {@link AdditionalQueryParameters} to modify the requirements for 51 // * the delegate. */ 52 // String key() default DELEGATE_KEY; 53 54 int ENSURE_HAS_DELEGATE_WEIGHT = DO_PO_WEIGHT + 1; // Should run after setting DO/PO 55 56 enum AdminType { 57 DEVICE_OWNER, 58 PROFILE_OWNER, 59 PRIMARY 60 } 61 62 // TODO(276740719): Add support for querying for the delegate 63 64 /** 65 * The admin that should delegate this scope. 66 * 67 * <p>If this is set to {@link AdminType#PRIMARY} and {@link #isPrimary()} is true, then the 68 * delegate will replace the primary dpc as primary without error. 69 */ admin()70 AdminType admin(); 71 72 /** The scope being delegated. */ scopes()73 String[] scopes(); 74 75 /** 76 * Whether this delegate should be returned by calls to {@code DeviceState#dpc()}. 77 * 78 * <p>Only one policy manager per test should be marked as primary. 79 */ isPrimary()80 boolean isPrimary() default false; 81 82 /** 83 * Weight sets the order that annotations will be resolved. 84 * 85 * <p>Annotations with a lower weight will be resolved before annotations with a higher weight. 86 * 87 * <p>If there is an order requirement between annotations, ensure that the weight of the 88 * annotation which must be resolved first is lower than the one which must be resolved later. 89 * 90 * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}. 91 */ weight()92 int weight() default ENSURE_HAS_DELEGATE_WEIGHT; 93 } 94