blob: 1af48cb63079b391ae8f770a16f7171ceebe1025 [file] [log] [blame]
Mathew Inwood2e615902018-06-26 14:06:27 +01001/*
2 * Copyright (C) 2018 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 */
16package android.annotation;
17
18import static java.lang.annotation.ElementType.CONSTRUCTOR;
19import static java.lang.annotation.ElementType.FIELD;
20import static java.lang.annotation.ElementType.METHOD;
Paul Duffined4d7c22018-12-07 10:40:38 +000021import static java.lang.annotation.ElementType.TYPE;
Mathew Inwood2e615902018-06-26 14:06:27 +010022import static java.lang.annotation.RetentionPolicy.CLASS;
23
Paul Duffined4d7c22018-12-07 10:40:38 +000024import java.lang.annotation.Repeatable;
Mathew Inwood2e615902018-06-26 14:06:27 +010025import java.lang.annotation.Retention;
26import java.lang.annotation.Target;
27
28/**
Mathew Inwoodf653d932018-12-07 11:15:49 +000029 * Indicates that this non-SDK interface is used by apps. A non-SDK interface is a
30 * class member (field or method) that is not part of the public SDK. Since the
31 * member is not part of the SDK, usage by apps is not supported.
Mathew Inwood2e615902018-06-26 14:06:27 +010032 *
Mathew Inwoodf653d932018-12-07 11:15:49 +000033 * <h2>If you are an Android App developer</h2>
34 *
35 * This annotation indicates that you may be able to access the member, but that
36 * this access is discouraged and not supported by Android. If there is a value
37 * for {@link #maxTargetSdk()} on the annotation, access will be restricted based
38 * on the {@code targetSdkVersion} value set in your manifest.
39 *
40 * <p>Fields and methods annotated with this are likely to be restricted, changed
41 * or removed in future Android releases. If you rely on these members for
42 * functionality that is not otherwise supported by Android, consider filing a
43 * <a href="http://g.co/dev/appcompat">feature request</a>.
44 *
45 * <h2>If you are an Android OS developer</h2>
46 *
47 * This annotation acts as a heads up that changing a given method or field
Mathew Inwood2e615902018-06-26 14:06:27 +010048 * may affect apps, potentially breaking them when the next Android version is
49 * released. In some cases, for members that are heavily used, this annotation
50 * may imply restrictions on changes to the member.
51 *
Mathew Inwood8ea86542018-08-28 10:52:51 +010052 * <p>This annotation also results in access to the member being permitted by the
Mathew Inwoodf653d932018-12-07 11:15:49 +000053 * runtime, with a warning being generated in debug builds. Which apps can access
54 * the member is determined by the value of {@link #maxTargetSdk()}.
Mathew Inwood2e615902018-06-26 14:06:27 +010055 *
Mathew Inwood8ea86542018-08-28 10:52:51 +010056 * <p>For more details, see go/UnsupportedAppUsage.
Mathew Inwood2e615902018-06-26 14:06:27 +010057 *
58 * {@hide}
59 */
60@Retention(CLASS)
Paul Duffined4d7c22018-12-07 10:40:38 +000061@Target({CONSTRUCTOR, METHOD, FIELD, TYPE})
62@Repeatable(UnsupportedAppUsage.Container.class)
Mathew Inwood2e615902018-06-26 14:06:27 +010063public @interface UnsupportedAppUsage {
64
65 /**
66 * Associates a bug tracking the work to add a public alternative to this API. Optional.
67 *
68 * @return ID of the associated tracking bug
69 */
70 long trackingBug() default 0;
71
72 /**
Mathew Inwoodd991a402018-08-16 10:41:36 +010073 * Indicates that usage of this API is limited to apps based on their target SDK version.
74 *
Mathew Inwood8ea86542018-08-28 10:52:51 +010075 * <p>Access to the API is allowed if the targetSdkVersion in the apps manifest is no greater
76 * than this value. Access checks are performed at runtime.
Mathew Inwoodd991a402018-08-16 10:41:36 +010077 *
Mathew Inwood8ea86542018-08-28 10:52:51 +010078 * <p>This is used to give app developers a grace period to migrate off a non-SDK interface.
79 * When making Android version N, existing APIs can have a maxTargetSdk of N-1 added to them.
Mathew Inwoodd991a402018-08-16 10:41:36 +010080 * Developers must then migrate off the API when their app is updated in future, but it will
81 * continue working in the meantime.
82 *
Mathew Inwood8ea86542018-08-28 10:52:51 +010083 * <p>Possible values are:
Mathew Inwoodd991a402018-08-16 10:41:36 +010084 * <ul>
85 * <li>
Neil Fuller24224892019-10-18 17:41:56 +010086 * An API level like {@link android.os.Build.VERSION_CODES#O} - in which case the API is
87 * available up to and including the specified release. Or, in other words, the API is
88 * blacklisted (unavailable) from the next API level from the one specified.
Mathew Inwoodd991a402018-08-16 10:41:36 +010089 * </li>
90 * <li>
91 * absent (default value) - All apps can access this API, but doing so may result in
92 * warnings in the log, UI warnings (on developer builds) and/or strictmode violations.
93 * The API is likely to be further restricted in future.
94 * </li>
95 *
96 * </ul>
97 *
Mathew Inwoodd991a402018-08-16 10:41:36 +010098 * @return The maximum value for an apps targetSdkVersion in order to access this API.
99 */
100 int maxTargetSdk() default Integer.MAX_VALUE;
101
102 /**
Mathew Inwood2e615902018-06-26 14:06:27 +0100103 * For debug use only. The expected dex signature to be generated for this API, used to verify
104 * parts of the build process.
105 *
106 * @return A dex API signature.
107 */
108 String expectedSignature() default "";
Paul Duffined4d7c22018-12-07 10:40:38 +0000109
110 /**
111 * The signature of an implicit (not present in the source) member that forms part of the
112 * hiddenapi.
113 *
114 * <p>Allows access to non-SDK API elements that are not represented in the input source to be
115 * managed.
116 *
117 * <p>This must only be used when applying the annotation to a type, using it in any other
118 * situation is an error.
119 *
120 * @return A dex API signature.
121 */
122 String implicitMember() default "";
123
124 /**
Andrei Onea75025042019-04-29 16:45:41 +0100125 * Public API alternatives to this API.
126 *
127 * <p>If non-empty, the string must be a description of the public API alternative(s) to this
128 * API. The explanation must contain at least one Javadoc link tag to public API methods or
129 * fields. e.g.:
130 * {@literal @UnsupportedAppUsage(publicAlternatives="Use {@link foo.bar.Baz#bat()} instead.")}
131 *
132 * <p>Any elements that can be deduced can be omitted, e.g.:
133 * <ul>
134 * <li>
135 * the class, if it's the same as for the annotated element.
136 * </li>
137 * <li>
138 * the package name, if it's the same as for the annotated element.
139 * </li>
140 * <li>
141 * the method parameters, if there is only one method with that name in the given
142 * package and class.
143 * </li>
144 * </ul>
145 * @return A Javadoc-formatted string.
146 */
147 @SuppressWarnings("JavadocReference")
148 String publicAlternatives() default "";
149
150 /**
Mathew Inwood2867ddf2019-11-29 15:30:52 +0000151 * Override the default source position when generating an index of the annotations.
152 *
153 * <p>This is intended for use by tools that generate java source code, to point to the
154 * original source position of the annotation, rather than the position within the generated
155 * code. It should never be set manually.
156 *
157 * <p>The format of the value is "path/to/file:startline:startcol:endline:endcol" indicating
158 * the position of the annotation itself.
159 */
160 String overrideSourcePosition() default "";
161
162 /**
Paul Duffined4d7c22018-12-07 10:40:38 +0000163 * Container for {@link UnsupportedAppUsage} that allows it to be applied repeatedly to types.
164 */
165 @Retention(CLASS)
166 @Target(TYPE)
167 @interface Container {
168 UnsupportedAppUsage[] value();
169 }
Mathew Inwood2e615902018-06-26 14:06:27 +0100170}