1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 package com.android.systemui.plugins.annotations
15 
16 /**
17  * This annotation marks denotes that an interface should use a proxy layer to protect the plugin
18  * host from crashing due to [LinkageError]s originating within the plugin's implementation.
19  */
20 @Target(AnnotationTarget.CLASS)
21 @Retention(AnnotationRetention.BINARY)
22 annotation class ProtectedInterface
23 
24 /**
25  * This annotation specifies any additional imports that the processor will require when generating
26  * the proxy implementation for the target interface. The interface in question must still be
27  * annotated with [ProtectedInterface].
28  */
29 @Repeatable
30 @Target(AnnotationTarget.CLASS)
31 @Retention(AnnotationRetention.BINARY)
32 annotation class GeneratedImport(val extraImport: String)
33 
34 /**
35  * This annotation provides default values to return when the proxy implementation catches a
36  * [LinkageError]. The string specified should be a simple but valid java statement. In most cases
37  * it should be a return statement of the appropriate type, but in some cases throwing a known
38  * exception type may be preferred.
39  *
40  * This annotation is not required for methods that return void, but will behave the same way.
41  */
42 @Target(
43     AnnotationTarget.FUNCTION,
44     AnnotationTarget.PROPERTY,
45     AnnotationTarget.PROPERTY_GETTER,
46     AnnotationTarget.PROPERTY_SETTER,
47 )
48 @Retention(AnnotationRetention.BINARY)
49 annotation class ProtectedReturn(val statement: String)
50 
51 /**
52  * Some very simple properties and methods need not be protected by the proxy implementation. This
53  * annotation can be used to omit the normal try-catch wrapper the proxy is using. These members
54  * will instead be a direct passthrough.
55  *
56  * It should only be used for members where the plugin implementation is expected to be exceedingly
57  * simple. Any member marked with this annotation should be no more complex than kotlin's automatic
58  * properties, and make no other method calls whatsoever.
59  */
60 @Target(
61     AnnotationTarget.FUNCTION,
62     AnnotationTarget.PROPERTY,
63     AnnotationTarget.PROPERTY_GETTER,
64     AnnotationTarget.PROPERTY_SETTER,
65 )
66 @Retention(AnnotationRetention.BINARY)
67 annotation class SimpleProperty
68