1 /* 2 * Copyright (C) 2015 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 androidx.annotation; 17 18 import java.lang.annotation.Retention; 19 import java.lang.annotation.Target; 20 21 import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 22 import static java.lang.annotation.ElementType.CONSTRUCTOR; 23 import static java.lang.annotation.ElementType.FIELD; 24 import static java.lang.annotation.ElementType.METHOD; 25 import static java.lang.annotation.ElementType.PARAMETER; 26 import static java.lang.annotation.RetentionPolicy.CLASS; 27 28 /** Stub only annotation. Do not use directly. */ 29 @Retention(CLASS) 30 @Target({ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, PARAMETER}) 31 public @interface RequiresPermission { 32 /** 33 * The name of the permission that is required, if precisely one permission is required. If more 34 * than one permission is required, specify either {@link #allOf()} or {@link #anyOf()} instead. 35 * 36 * <p>If specified, {@link #anyOf()} and {@link #allOf()} must both be null. 37 */ value()38 String value() default ""; 39 40 /** 41 * Specifies a list of permission names that are all required. 42 * 43 * <p>If specified, {@link #anyOf()} and {@link #value()} must both be null. 44 */ allOf()45 String[] allOf() default {}; 46 47 /** 48 * Specifies a list of permission names where at least one is required 49 * 50 * <p>If specified, {@link #allOf()} and {@link #value()} must both be null. 51 */ anyOf()52 String[] anyOf() default {}; 53 54 /** 55 * If true, the permission may not be required in all cases (e.g. it may only be enforced on 56 * certain platforms, or for certain call parameters, etc. 57 */ conditional()58 boolean conditional() default false; 59 60 // STUBS ONLY: historical API range for when this permission applies. 61 // Used for merged annotations. apis()62 String apis() default ""; 63 64 /** 65 * Specifies that the given permission is required for read operations. 66 * 67 * <p>When specified on a parameter, the annotation indicates that the method requires a 68 * permission which depends on the value of the parameter (and typically the corresponding field 69 * passed in will be one of a set of constants which have been annotated with a 70 * {@code @RequiresPermission} annotation.) 71 */ 72 @Target({FIELD, METHOD, PARAMETER}) 73 @interface Read { value()74 RequiresPermission value() default @RequiresPermission; 75 } 76 77 /** 78 * Specifies that the given permission is required for write operations. 79 * 80 * <p>When specified on a parameter, the annotation indicates that the method requires a 81 * permission which depends on the value of the parameter (and typically the corresponding field 82 * passed in will be one of a set of constants which have been annotated with a 83 * {@code @RequiresPermission} annotation.) 84 */ 85 @Target({FIELD, METHOD, PARAMETER}) 86 @interface Write { value()87 RequiresPermission value() default @RequiresPermission; 88 } 89 } 90