1 /* 2 * Copyright (C) 2007 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 com.android.internal.telephony; 18 19 import android.compat.annotation.UnsupportedAppUsage; 20 import android.os.Build; 21 22 import com.android.telephony.Rlog; 23 24 /** 25 * {@hide} 26 */ 27 public class CommandException extends RuntimeException { 28 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 29 private Error mError; 30 31 public enum Error { 32 INVALID_RESPONSE, 33 @UnsupportedAppUsage 34 RADIO_NOT_AVAILABLE, 35 @UnsupportedAppUsage 36 GENERIC_FAILURE, 37 @UnsupportedAppUsage 38 PASSWORD_INCORRECT, 39 SIM_PIN2, 40 @UnsupportedAppUsage 41 SIM_PUK2, 42 @UnsupportedAppUsage 43 REQUEST_NOT_SUPPORTED, 44 OP_NOT_ALLOWED_DURING_VOICE_CALL, 45 OP_NOT_ALLOWED_BEFORE_REG_NW, 46 @UnsupportedAppUsage 47 SMS_FAIL_RETRY, 48 SIM_ABSENT, 49 SUBSCRIPTION_NOT_AVAILABLE, 50 MODE_NOT_SUPPORTED, 51 FDN_CHECK_FAILURE, 52 ILLEGAL_SIM_OR_ME, 53 MISSING_RESOURCE, 54 NO_SUCH_ELEMENT, 55 SUBSCRIPTION_NOT_SUPPORTED, 56 DIAL_MODIFIED_TO_USSD, 57 DIAL_MODIFIED_TO_SS, 58 DIAL_MODIFIED_TO_DIAL, 59 USSD_MODIFIED_TO_DIAL, 60 USSD_MODIFIED_TO_SS, 61 USSD_MODIFIED_TO_USSD, 62 SS_MODIFIED_TO_DIAL, 63 SS_MODIFIED_TO_DIAL_VIDEO, 64 SS_MODIFIED_TO_USSD, 65 SS_MODIFIED_TO_SS, 66 SIM_ALREADY_POWERED_OFF, 67 SIM_ALREADY_POWERED_ON, 68 SIM_DATA_NOT_AVAILABLE, 69 SIM_SAP_CONNECT_FAILURE, 70 SIM_SAP_MSG_SIZE_TOO_LARGE, 71 SIM_SAP_MSG_SIZE_TOO_SMALL, 72 SIM_SAP_CONNECT_OK_CALL_ONGOING, 73 LCE_NOT_SUPPORTED, 74 NO_MEMORY, 75 INTERNAL_ERR, 76 SYSTEM_ERR, 77 MODEM_ERR, 78 INVALID_STATE, 79 NO_RESOURCES, 80 SIM_ERR, 81 INVALID_ARGUMENTS, 82 INVALID_SIM_STATE, 83 INVALID_MODEM_STATE, 84 INVALID_CALL_ID, 85 NO_SMS_TO_ACK, 86 NETWORK_ERR, 87 REQUEST_RATE_LIMITED, 88 SIM_BUSY, 89 SIM_FULL, 90 NETWORK_REJECT, 91 OPERATION_NOT_ALLOWED, 92 EMPTY_RECORD, 93 INVALID_SMS_FORMAT, 94 ENCODING_ERR, 95 INVALID_SMSC_ADDRESS, 96 NO_SUCH_ENTRY, 97 NETWORK_NOT_READY, 98 NOT_PROVISIONED, 99 NO_SUBSCRIPTION, 100 NO_NETWORK_FOUND, 101 DEVICE_IN_USE, 102 ABORTED, 103 OEM_ERROR_1, 104 OEM_ERROR_2, 105 OEM_ERROR_3, 106 OEM_ERROR_4, 107 OEM_ERROR_5, 108 OEM_ERROR_6, 109 OEM_ERROR_7, 110 OEM_ERROR_8, 111 OEM_ERROR_9, 112 OEM_ERROR_10, 113 OEM_ERROR_11, 114 OEM_ERROR_12, 115 OEM_ERROR_13, 116 OEM_ERROR_14, 117 OEM_ERROR_15, 118 OEM_ERROR_16, 119 OEM_ERROR_17, 120 OEM_ERROR_18, 121 OEM_ERROR_19, 122 OEM_ERROR_20, 123 OEM_ERROR_21, 124 OEM_ERROR_22, 125 OEM_ERROR_23, 126 OEM_ERROR_24, 127 OEM_ERROR_25, 128 REQUEST_CANCELLED, 129 SIMULTANEOUS_SMS_AND_CALL_NOT_ALLOWED, 130 ACCESS_BARRED, 131 BLOCKED_DUE_TO_CALL, 132 RF_HARDWARE_ISSUE, 133 NO_RF_CALIBRATION_INFO, 134 } 135 136 @UnsupportedAppUsage CommandException(Error e)137 public CommandException(Error e) { 138 super(e.toString()); 139 mError = e; 140 } 141 CommandException(Error e, String errString)142 public CommandException(Error e, String errString) { 143 super(errString); 144 mError = e; 145 } 146 147 @UnsupportedAppUsage 148 public static CommandException fromRilErrno(int ril_errno)149 fromRilErrno(int ril_errno) { 150 switch(ril_errno) { 151 case RILConstants.SUCCESS: return null; 152 case RILConstants.RIL_ERRNO_INVALID_RESPONSE: 153 return new CommandException(Error.INVALID_RESPONSE); 154 case RILConstants.RADIO_NOT_AVAILABLE: 155 return new CommandException(Error.RADIO_NOT_AVAILABLE); 156 case RILConstants.GENERIC_FAILURE: 157 return new CommandException(Error.GENERIC_FAILURE); 158 case RILConstants.PASSWORD_INCORRECT: 159 return new CommandException(Error.PASSWORD_INCORRECT); 160 case RILConstants.SIM_PIN2: 161 return new CommandException(Error.SIM_PIN2); 162 case RILConstants.SIM_PUK2: 163 return new CommandException(Error.SIM_PUK2); 164 case RILConstants.REQUEST_NOT_SUPPORTED: 165 return new CommandException(Error.REQUEST_NOT_SUPPORTED); 166 case RILConstants.OP_NOT_ALLOWED_DURING_VOICE_CALL: 167 return new CommandException(Error.OP_NOT_ALLOWED_DURING_VOICE_CALL); 168 case RILConstants.OP_NOT_ALLOWED_BEFORE_REG_NW: 169 return new CommandException(Error.OP_NOT_ALLOWED_BEFORE_REG_NW); 170 case RILConstants.SMS_SEND_FAIL_RETRY: 171 return new CommandException(Error.SMS_FAIL_RETRY); 172 case RILConstants.SIM_ABSENT: 173 return new CommandException(Error.SIM_ABSENT); 174 case RILConstants.SUBSCRIPTION_NOT_AVAILABLE: 175 return new CommandException(Error.SUBSCRIPTION_NOT_AVAILABLE); 176 case RILConstants.MODE_NOT_SUPPORTED: 177 return new CommandException(Error.MODE_NOT_SUPPORTED); 178 case RILConstants.FDN_CHECK_FAILURE: 179 return new CommandException(Error.FDN_CHECK_FAILURE); 180 case RILConstants.ILLEGAL_SIM_OR_ME: 181 return new CommandException(Error.ILLEGAL_SIM_OR_ME); 182 case RILConstants.MISSING_RESOURCE: 183 return new CommandException(Error.MISSING_RESOURCE); 184 case RILConstants.NO_SUCH_ELEMENT: 185 return new CommandException(Error.NO_SUCH_ELEMENT); 186 case RILConstants.SUBSCRIPTION_NOT_SUPPORTED: 187 return new CommandException(Error.SUBSCRIPTION_NOT_SUPPORTED); 188 case RILConstants.DIAL_MODIFIED_TO_USSD: 189 return new CommandException(Error.DIAL_MODIFIED_TO_USSD); 190 case RILConstants.DIAL_MODIFIED_TO_SS: 191 return new CommandException(Error.DIAL_MODIFIED_TO_SS); 192 case RILConstants.DIAL_MODIFIED_TO_DIAL: 193 return new CommandException(Error.DIAL_MODIFIED_TO_DIAL); 194 case RILConstants.USSD_MODIFIED_TO_DIAL: 195 return new CommandException(Error.USSD_MODIFIED_TO_DIAL); 196 case RILConstants.USSD_MODIFIED_TO_SS: 197 return new CommandException(Error.USSD_MODIFIED_TO_SS); 198 case RILConstants.USSD_MODIFIED_TO_USSD: 199 return new CommandException(Error.USSD_MODIFIED_TO_USSD); 200 case RILConstants.SS_MODIFIED_TO_DIAL: 201 return new CommandException(Error.SS_MODIFIED_TO_DIAL); 202 case RILConstants.SS_MODIFIED_TO_USSD: 203 return new CommandException(Error.SS_MODIFIED_TO_USSD); 204 case RILConstants.SS_MODIFIED_TO_SS: 205 return new CommandException(Error.SS_MODIFIED_TO_SS); 206 case RILConstants.SIM_ALREADY_POWERED_OFF: 207 return new CommandException(Error.SIM_ALREADY_POWERED_OFF); 208 case RILConstants.SIM_ALREADY_POWERED_ON: 209 return new CommandException(Error.SIM_ALREADY_POWERED_ON); 210 case RILConstants.SIM_DATA_NOT_AVAILABLE: 211 return new CommandException(Error.SIM_DATA_NOT_AVAILABLE); 212 case RILConstants.SIM_SAP_CONNECT_FAILURE: 213 return new CommandException(Error.SIM_SAP_CONNECT_FAILURE); 214 case RILConstants.SIM_SAP_MSG_SIZE_TOO_LARGE: 215 return new CommandException(Error.SIM_SAP_MSG_SIZE_TOO_LARGE); 216 case RILConstants.SIM_SAP_MSG_SIZE_TOO_SMALL: 217 return new CommandException(Error.SIM_SAP_MSG_SIZE_TOO_SMALL); 218 case RILConstants.SIM_SAP_CONNECT_OK_CALL_ONGOING: 219 return new CommandException(Error.SIM_SAP_CONNECT_OK_CALL_ONGOING); 220 case RILConstants.LCE_NOT_SUPPORTED: 221 return new CommandException(Error.LCE_NOT_SUPPORTED); 222 case RILConstants.NO_MEMORY: 223 return new CommandException(Error.NO_MEMORY); 224 case RILConstants.INTERNAL_ERR: 225 return new CommandException(Error.INTERNAL_ERR); 226 case RILConstants.SYSTEM_ERR: 227 return new CommandException(Error.SYSTEM_ERR); 228 case RILConstants.MODEM_ERR: 229 return new CommandException(Error.MODEM_ERR); 230 case RILConstants.INVALID_STATE: 231 return new CommandException(Error.INVALID_STATE); 232 case RILConstants.NO_RESOURCES: 233 return new CommandException(Error.NO_RESOURCES); 234 case RILConstants.SIM_ERR: 235 return new CommandException(Error.SIM_ERR); 236 case RILConstants.INVALID_ARGUMENTS: 237 return new CommandException(Error.INVALID_ARGUMENTS); 238 case RILConstants.INVALID_SIM_STATE: 239 return new CommandException(Error.INVALID_SIM_STATE); 240 case RILConstants.INVALID_MODEM_STATE: 241 return new CommandException(Error.INVALID_MODEM_STATE); 242 case RILConstants.INVALID_CALL_ID: 243 return new CommandException(Error.INVALID_CALL_ID); 244 case RILConstants.NO_SMS_TO_ACK: 245 return new CommandException(Error.NO_SMS_TO_ACK); 246 case RILConstants.NETWORK_ERR: 247 return new CommandException(Error.NETWORK_ERR); 248 case RILConstants.REQUEST_RATE_LIMITED: 249 return new CommandException(Error.REQUEST_RATE_LIMITED); 250 case RILConstants.SIM_BUSY: 251 return new CommandException(Error.SIM_BUSY); 252 case RILConstants.SIM_FULL: 253 return new CommandException(Error.SIM_FULL); 254 case RILConstants.NETWORK_REJECT: 255 return new CommandException(Error.NETWORK_REJECT); 256 case RILConstants.OPERATION_NOT_ALLOWED: 257 return new CommandException(Error.OPERATION_NOT_ALLOWED); 258 case RILConstants.EMPTY_RECORD: 259 return new CommandException(Error.EMPTY_RECORD); 260 case RILConstants.INVALID_SMS_FORMAT: 261 return new CommandException(Error.INVALID_SMS_FORMAT); 262 case RILConstants.ENCODING_ERR: 263 return new CommandException(Error.ENCODING_ERR); 264 case RILConstants.INVALID_SMSC_ADDRESS: 265 return new CommandException(Error.INVALID_SMSC_ADDRESS); 266 case RILConstants.NO_SUCH_ENTRY: 267 return new CommandException(Error.NO_SUCH_ENTRY); 268 case RILConstants.NETWORK_NOT_READY: 269 return new CommandException(Error.NETWORK_NOT_READY); 270 case RILConstants.NOT_PROVISIONED: 271 return new CommandException(Error.NOT_PROVISIONED); 272 case RILConstants.NO_SUBSCRIPTION: 273 return new CommandException(Error.NO_SUBSCRIPTION); 274 case RILConstants.NO_NETWORK_FOUND: 275 return new CommandException(Error.NO_NETWORK_FOUND); 276 case RILConstants.DEVICE_IN_USE: 277 return new CommandException(Error.DEVICE_IN_USE); 278 case RILConstants.ABORTED: 279 return new CommandException(Error.ABORTED); 280 case RILConstants.INVALID_RESPONSE: 281 return new CommandException(Error.INVALID_RESPONSE); 282 case RILConstants.OEM_ERROR_1: 283 return new CommandException(Error.OEM_ERROR_1); 284 case RILConstants.OEM_ERROR_2: 285 return new CommandException(Error.OEM_ERROR_2); 286 case RILConstants.OEM_ERROR_3: 287 return new CommandException(Error.OEM_ERROR_3); 288 case RILConstants.OEM_ERROR_4: 289 return new CommandException(Error.OEM_ERROR_4); 290 case RILConstants.OEM_ERROR_5: 291 return new CommandException(Error.OEM_ERROR_5); 292 case RILConstants.OEM_ERROR_6: 293 return new CommandException(Error.OEM_ERROR_6); 294 case RILConstants.OEM_ERROR_7: 295 return new CommandException(Error.OEM_ERROR_7); 296 case RILConstants.OEM_ERROR_8: 297 return new CommandException(Error.OEM_ERROR_8); 298 case RILConstants.OEM_ERROR_9: 299 return new CommandException(Error.OEM_ERROR_9); 300 case RILConstants.OEM_ERROR_10: 301 return new CommandException(Error.OEM_ERROR_10); 302 case RILConstants.OEM_ERROR_11: 303 return new CommandException(Error.OEM_ERROR_11); 304 case RILConstants.OEM_ERROR_12: 305 return new CommandException(Error.OEM_ERROR_12); 306 case RILConstants.OEM_ERROR_13: 307 return new CommandException(Error.OEM_ERROR_13); 308 case RILConstants.OEM_ERROR_14: 309 return new CommandException(Error.OEM_ERROR_14); 310 case RILConstants.OEM_ERROR_15: 311 return new CommandException(Error.OEM_ERROR_15); 312 case RILConstants.OEM_ERROR_16: 313 return new CommandException(Error.OEM_ERROR_16); 314 case RILConstants.OEM_ERROR_17: 315 return new CommandException(Error.OEM_ERROR_17); 316 case RILConstants.OEM_ERROR_18: 317 return new CommandException(Error.OEM_ERROR_18); 318 case RILConstants.OEM_ERROR_19: 319 return new CommandException(Error.OEM_ERROR_19); 320 case RILConstants.OEM_ERROR_20: 321 return new CommandException(Error.OEM_ERROR_20); 322 case RILConstants.OEM_ERROR_21: 323 return new CommandException(Error.OEM_ERROR_21); 324 case RILConstants.OEM_ERROR_22: 325 return new CommandException(Error.OEM_ERROR_22); 326 case RILConstants.OEM_ERROR_23: 327 return new CommandException(Error.OEM_ERROR_23); 328 case RILConstants.OEM_ERROR_24: 329 return new CommandException(Error.OEM_ERROR_24); 330 case RILConstants.OEM_ERROR_25: 331 return new CommandException(Error.OEM_ERROR_25); 332 case RILConstants.REQUEST_CANCELLED: 333 return new CommandException(Error.REQUEST_CANCELLED); 334 case RILConstants.SIMULTANEOUS_SMS_AND_CALL_NOT_ALLOWED: 335 return new CommandException(Error.SIMULTANEOUS_SMS_AND_CALL_NOT_ALLOWED); 336 case RILConstants.ACCESS_BARRED: 337 return new CommandException(Error.ACCESS_BARRED); 338 case RILConstants.BLOCKED_DUE_TO_CALL: 339 return new CommandException(Error.BLOCKED_DUE_TO_CALL); 340 case RILConstants.RF_HARDWARE_ISSUE: 341 return new CommandException(Error.RF_HARDWARE_ISSUE); 342 case RILConstants.NO_RF_CALIBRATION_INFO: 343 return new CommandException(Error.NO_RF_CALIBRATION_INFO); 344 345 default: 346 Rlog.e("GSM", "Unrecognized RIL errno " + ril_errno); 347 return new CommandException(Error.INVALID_RESPONSE); 348 } 349 } 350 351 @UnsupportedAppUsage getCommandError()352 public Error getCommandError() { 353 return mError; 354 } 355 356 357 358 } 359