1 /* 2 * Copyright 2025 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 17 package androidx.appfunctions 18 19 import android.os.Bundle 20 21 /** 22 * Thrown when the error is caused by the app requesting a function execution. 23 * 24 * For example, the caller provided invalid parameters in the execution request e.g. an invalid 25 * function ID. 26 */ 27 public abstract class AppFunctionRequestException 28 internal constructor(errorCode: Int, errorMessage: String? = null, extras: Bundle) : 29 AppFunctionException(errorCode, errorMessage, extras) 30 31 /** 32 * Thrown when the caller does not have the permission to execute an app function. 33 * 34 * This is different from [AppFunctionPermissionRequiredException] in that the caller is missing 35 * this specific permission, as opposed to the target app missing a permission. 36 */ 37 public class AppFunctionDeniedException 38 internal constructor(errorMessage: String? = null, extras: Bundle) : 39 AppFunctionRequestException(ERROR_DENIED, errorMessage, extras) { 40 41 public constructor(errorMessage: String? = null) : this(errorMessage, Bundle.EMPTY) 42 } 43 44 /** 45 * Thrown when the caller supplied invalid arguments to ExecuteAppFunctionRequest's parameters. 46 * 47 * This error may be considered similar to [IllegalArgumentException]. 48 */ 49 // TODO(b/389738031): add reference to ExecuteAppFunctionRequest's builder when it is added. 50 public class AppFunctionInvalidArgumentException 51 internal constructor(errorMessage: String? = null, extras: Bundle) : 52 AppFunctionRequestException(ERROR_INVALID_ARGUMENT, errorMessage, extras) { 53 54 public constructor(errorMessage: String? = null) : this(errorMessage, Bundle.EMPTY) 55 } 56 57 /** 58 * Thrown when the caller tried to execute a disabled app function. An app function can be enabled 59 * at runtime through the AppFunctionManager or by setting enabledByDefault=true in the AppFunction 60 * annotation. 61 */ 62 // TODO(b/389738031): add reference to setAppFunctionEnabled and @AppFunction when they are added. 63 public class AppFunctionDisabledException 64 internal constructor(errorMessage: String? = null, extras: Bundle) : 65 AppFunctionRequestException(ERROR_DISABLED, errorMessage, extras) { 66 67 public constructor(errorMessage: String? = null) : this(errorMessage, Bundle.EMPTY) 68 } 69 70 /** Thrown when the caller tries to execute a function that does not exist. */ 71 public class AppFunctionFunctionNotFoundException 72 internal constructor(errorMessage: String? = null, extras: Bundle) : 73 AppFunctionRequestException(ERROR_FUNCTION_NOT_FOUND, errorMessage, extras) { 74 75 public constructor(errorMessage: String? = null) : this(errorMessage, Bundle.EMPTY) 76 } 77 78 /** Thrown when the caller tried to request a resource/entity that does not exist. */ 79 public class AppFunctionElementNotFoundException 80 internal constructor(errorMessage: String? = null, extras: Bundle) : 81 AppFunctionRequestException(ERROR_RESOURCE_NOT_FOUND, errorMessage, extras) { 82 83 public constructor(errorMessage: String? = null) : this(errorMessage, Bundle.EMPTY) 84 } 85 86 /** Thrown when the caller exceeded the allowed request rate. */ 87 public class AppFunctionLimitExceededException 88 internal constructor(errorMessage: String? = null, extras: Bundle) : 89 AppFunctionRequestException(ERROR_LIMIT_EXCEEDED, errorMessage, extras) { 90 91 public constructor(errorMessage: String? = null) : this(errorMessage, Bundle.EMPTY) 92 } 93 94 /** 95 * Thrown when the caller tried to create a resource/entity that already exists or has conflicts 96 * with existing resource/entity. 97 */ 98 public class AppFunctionElementAlreadyExistsException 99 internal constructor(errorMessage: String? = null, extras: Bundle) : 100 AppFunctionRequestException(ERROR_RESOURCE_ALREADY_EXISTS, errorMessage, extras) { 101 102 public constructor(errorMessage: String? = null) : this(errorMessage, Bundle.EMPTY) 103 } 104