• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 android.annotation;
17 
18 import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
19 import static java.lang.annotation.ElementType.CONSTRUCTOR;
20 import static java.lang.annotation.ElementType.FIELD;
21 import static java.lang.annotation.ElementType.METHOD;
22 import static java.lang.annotation.ElementType.TYPE;
23 
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 import java.lang.annotation.Target;
27 
28 /**
29  * Indicates an API is part of a feature that is guarded by an aconfig flag, and only available if
30  * the flag is enabled.
31  * <p>
32  * Unless the API has been finalized and has become part of the SDK, callers of the annotated API
33  * must check that the flag is enabled before making any assumptions about the existence of the API.
34  * <p>
35  * Example:
36  * <code><pre>
37  *     import com.example.foobar.Flags;
38  *
39  *     &#64;FlaggedApi(Flags.FLAG_FOOBAR)
40  *     public void foobar() { ... }
41  * </pre></code>
42  * Usage example:
43  * <code><pre>
44  *     public void codeThatUsesFoobarApi() {
45  *         if (Flags.foobar()) {
46  *             foobar();
47  *         } else {
48  *             // gracefully handle absence of the foobar API.
49  *         }
50  *     }
51  * </pre></code>
52  * @hide
53  */
54 @Target({TYPE, METHOD, CONSTRUCTOR, FIELD, ANNOTATION_TYPE})
55 @Retention(RetentionPolicy.CLASS)
56 public @interface FlaggedApi {
57     /**
58      * The aconfig flag used to guard the feature this API is part of. Use the aconfig
59      * auto-generated constant to refer to the flag, e.g. @FlaggedApi(Flags.FLAG_FOOBAR).
60      */
value()61     String value();
62 }
63