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 an error is caused by the app providing the function.
23  *
24  * For example, the app crashed when the system is executing the request.
25  */
26 public abstract class AppFunctionAppException
27 internal constructor(errorCode: Int, errorMessage: String? = null, extras: Bundle) :
28     AppFunctionException(errorCode, errorMessage, extras)
29 
30 /**
31  * Thrown when an unknown error occurred while processing the call in the AppFunctionService.
32  *
33  * This error is thrown when the service is connected in the remote application but an unexpected
34  * error is thrown from the bound application.
35  */
36 public class AppFunctionAppUnknownException
37 internal constructor(errorMessage: String? = null, extras: Bundle) :
38     AppFunctionAppException(ERROR_APP_UNKNOWN_ERROR, errorMessage, extras) {
39 
40     public constructor(errorMessage: String? = null) : this(errorMessage, Bundle.EMPTY)
41 }
42 
43 /**
44  * Thrown when the app lacks the necessary permission to fulfill the request.
45  *
46  * This occurs when the app attempts an operation requiring user-granted permission that has not
47  * been provided. For example, creating a calendar event requires access to the calendar content. If
48  * the user hasn't granted this permission, this error should be thrown.
49  *
50  * This is different from [AppFunctionDeniedException] in that the required permission is missing
51  * from the target app, as opposed to the caller.
52  */
53 public class AppFunctionPermissionRequiredException
54 internal constructor(errorMessage: String? = null, extras: Bundle) :
55     AppFunctionAppException(ERROR_PERMISSION_REQUIRED, errorMessage, extras) {
56 
57     public constructor(errorMessage: String? = null) : this(errorMessage, Bundle.EMPTY)
58 }
59 
60 /**
61  * Thrown when an app receives a request to perform an unsupported action.
62  *
63  * For example, a clock app might support updating timer properties such as label but may not allow
64  * updating the timer's duration once the timer has already started.
65  */
66 public class AppFunctionNotSupportedException
67 internal constructor(errorMessage: String? = null, extras: Bundle) :
68     AppFunctionAppException(ERROR_NOT_SUPPORTED, errorMessage, extras) {
69 
70     public constructor(errorMessage: String? = null) : this(errorMessage, Bundle.EMPTY)
71 }
72