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 the [Exception] types originating within the plugin's implementation. 19 */ 20 @Target(AnnotationTarget.CLASS) 21 @Retention(AnnotationRetention.BINARY) 22 annotation class ProtectedInterface(vararg val exTypes: String) { 23 companion object { 24 val Default = ProtectedInterface("java.lang.Exception", "java.lang.LinkageError") 25 } 26 } 27 28 /** 29 * This annotation specifies any additional imports that the processor will require when generating 30 * the proxy implementation for the target interface. The interface in question must still be 31 * annotated with [ProtectedInterface]. 32 */ 33 @Repeatable 34 @Target(AnnotationTarget.CLASS) 35 @Retention(AnnotationRetention.BINARY) 36 annotation class GeneratedImport(val extraImport: String) 37 38 /** 39 * This annotation provides default values to return when the proxy implementation catches a target 40 * [Exception]. The string specified should be a simple but valid java statement. In most cases it 41 * should be a return statement of the appropriate type, but in some cases throwing a known 42 * exception type may be preferred. 43 * 44 * This annotation is not required for methods that return void, but will behave the same way. 45 */ 46 @Target( 47 AnnotationTarget.FUNCTION, 48 AnnotationTarget.PROPERTY, 49 AnnotationTarget.PROPERTY_GETTER, 50 AnnotationTarget.PROPERTY_SETTER, 51 ) 52 @Retention(AnnotationRetention.BINARY) 53 annotation class ProtectedReturn(val statement: String) 54 55 /** 56 * Some very simple properties and methods need not be protected by the proxy implementation. This 57 * annotation can be used to omit the normal try-catch wrapper the proxy is using. These members 58 * will instead be a direct passthrough. 59 * 60 * It should only be used for members where the plugin implementation is expected to be exceedingly 61 * simple. Any member marked with this annotation should be no more complex than kotlin's automatic 62 * properties, and make no other method calls whatsoever. 63 */ 64 @Target( 65 AnnotationTarget.FUNCTION, 66 AnnotationTarget.PROPERTY, 67 AnnotationTarget.PROPERTY_GETTER, 68 AnnotationTarget.PROPERTY_SETTER, 69 ) 70 @Retention(AnnotationRetention.BINARY) 71 annotation class SimpleProperty 72