1 /* 2 * Copyright 2023 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.core.telecom 18 19 import androidx.annotation.IntDef 20 import androidx.annotation.RestrictTo 21 22 /** This class defines exceptions that can be thrown when using [androidx.core.telecom] APIs. */ 23 public class CallException(@CallErrorCode public val code: Int = ERROR_UNKNOWN) : 24 RuntimeException() { 25 toStringnull26 override fun toString(): String { 27 return "CallException(code=[$code])" 28 } 29 equalsnull30 override fun equals(other: Any?): Boolean { 31 return other is CallException && code == other.code 32 } 33 hashCodenull34 override fun hashCode(): Int { 35 return code.hashCode() 36 } 37 38 public companion object { 39 @RestrictTo(RestrictTo.Scope.LIBRARY) 40 @Retention(AnnotationRetention.SOURCE) 41 @IntDef( 42 ERROR_UNKNOWN, 43 ERROR_CANNOT_HOLD_CURRENT_ACTIVE_CALL, 44 ERROR_CALL_IS_NOT_BEING_TRACKED, 45 ERROR_CALL_CANNOT_BE_SET_TO_ACTIVE, 46 ERROR_CALL_NOT_PERMITTED_AT_PRESENT_TIME, 47 ERROR_OPERATION_TIMED_OUT, 48 ERROR_CALL_DOES_NOT_SUPPORT_HOLD, 49 ERROR_BLUETOOTH_DEVICE_IS_NULL 50 ) 51 public annotation class CallErrorCode 52 53 /** The operation has failed due to an unknown or unspecified error. */ 54 public const val ERROR_UNKNOWN: Int = 1 55 56 /** 57 * The operation has failed due to Telecom failing to hold the current active call for the 58 * call attempting to become the new active call. The client should end the current active 59 * call and re-try the failed operation. 60 */ 61 public const val ERROR_CANNOT_HOLD_CURRENT_ACTIVE_CALL: Int = 2 62 63 /** 64 * The operation has failed because Telecom has already removed the call from the server 65 * side and destroyed all the objects associated with it. The client should re-add the call. 66 */ 67 public const val ERROR_CALL_IS_NOT_BEING_TRACKED: Int = 3 68 69 /** 70 * The operation has failed because Telecom cannot set the requested call as the current 71 * active call. The client should end the current active call and re-try the operation. 72 */ 73 public const val ERROR_CALL_CANNOT_BE_SET_TO_ACTIVE: Int = 4 74 75 /** 76 * The operation has failed because there is either no PhoneAccount registered with Telecom 77 * for the given operation, or the limit of calls has been reached. The client should end 78 * the current active call and re-try the failed operation. 79 */ 80 public const val ERROR_CALL_NOT_PERMITTED_AT_PRESENT_TIME: Int = 5 81 82 /** The operation has failed because the operation failed to complete before the timeout */ 83 public const val ERROR_OPERATION_TIMED_OUT: Int = 6 84 85 /** 86 * The [CallControlScope.setInactive] or [CallsManager.addCall#onSetInactive] failed because 87 * the [CallAttributesCompat.SUPPORTS_SET_INACTIVE] was not set. Please re-add the call with 88 * the [CallAttributesCompat.SUPPORTS_SET_INACTIVE] if the call should be able to hold. 89 */ 90 public const val ERROR_CALL_DOES_NOT_SUPPORT_HOLD: Int = 7 91 92 /** 93 * Telecom was not able to switch the audio route to Bluetooth because the Bluetooth device 94 * is null. The user should reconnect the Bluetooth device and retry the audio route switch. 95 */ 96 public const val ERROR_BLUETOOTH_DEVICE_IS_NULL: Int = 8 97 fromTelecomCodenull98 internal fun fromTelecomCode(code: Int): Int { 99 when (code) { 100 1 -> return ERROR_UNKNOWN 101 2 -> return ERROR_CANNOT_HOLD_CURRENT_ACTIVE_CALL 102 3 -> return ERROR_CALL_IS_NOT_BEING_TRACKED 103 4 -> return ERROR_CALL_CANNOT_BE_SET_TO_ACTIVE 104 5 -> return ERROR_CALL_NOT_PERMITTED_AT_PRESENT_TIME 105 6 -> return ERROR_OPERATION_TIMED_OUT 106 } 107 return ERROR_UNKNOWN 108 } 109 } 110 } 111