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 com.android.internal.telephony.RILConstants; 20 21 import android.telephony.Rlog; 22 23 /** 24 * {@hide} 25 */ 26 public class CommandException extends RuntimeException { 27 private Error mError; 28 29 public enum Error { 30 INVALID_RESPONSE, 31 RADIO_NOT_AVAILABLE, 32 GENERIC_FAILURE, 33 PASSWORD_INCORRECT, 34 SIM_PIN2, 35 SIM_PUK2, 36 REQUEST_NOT_SUPPORTED, 37 OP_NOT_ALLOWED_DURING_VOICE_CALL, 38 OP_NOT_ALLOWED_BEFORE_REG_NW, 39 SMS_FAIL_RETRY, 40 SIM_ABSENT, 41 SUBSCRIPTION_NOT_AVAILABLE, 42 MODE_NOT_SUPPORTED, 43 FDN_CHECK_FAILURE, 44 ILLEGAL_SIM_OR_ME, 45 MISSING_RESOURCE, 46 NO_SUCH_ELEMENT, 47 SUBSCRIPTION_NOT_SUPPORTED, 48 DIAL_MODIFIED_TO_USSD, 49 DIAL_MODIFIED_TO_SS, 50 DIAL_MODIFIED_TO_DIAL, 51 USSD_MODIFIED_TO_DIAL, 52 USSD_MODIFIED_TO_SS, 53 USSD_MODIFIED_TO_USSD, 54 SS_MODIFIED_TO_DIAL, 55 SS_MODIFIED_TO_USSD, 56 SS_MODIFIED_TO_SS, 57 } 58 59 public CommandException(Error e) { 60 super(e.toString()); 61 mError = e; 62 } 63 64 public static CommandException 65 fromRilErrno(int ril_errno) { 66 switch(ril_errno) { 67 case RILConstants.SUCCESS: return null; 68 case RILConstants.RIL_ERRNO_INVALID_RESPONSE: 69 return new CommandException(Error.INVALID_RESPONSE); 70 case RILConstants.RADIO_NOT_AVAILABLE: 71 return new CommandException(Error.RADIO_NOT_AVAILABLE); 72 case RILConstants.GENERIC_FAILURE: 73 return new CommandException(Error.GENERIC_FAILURE); 74 case RILConstants.PASSWORD_INCORRECT: 75 return new CommandException(Error.PASSWORD_INCORRECT); 76 case RILConstants.SIM_PIN2: 77 return new CommandException(Error.SIM_PIN2); 78 case RILConstants.SIM_PUK2: 79 return new CommandException(Error.SIM_PUK2); 80 case RILConstants.REQUEST_NOT_SUPPORTED: 81 return new CommandException(Error.REQUEST_NOT_SUPPORTED); 82 case RILConstants.OP_NOT_ALLOWED_DURING_VOICE_CALL: 83 return new CommandException(Error.OP_NOT_ALLOWED_DURING_VOICE_CALL); 84 case RILConstants.OP_NOT_ALLOWED_BEFORE_REG_NW: 85 return new CommandException(Error.OP_NOT_ALLOWED_BEFORE_REG_NW); 86 case RILConstants.SMS_SEND_FAIL_RETRY: 87 return new CommandException(Error.SMS_FAIL_RETRY); 88 case RILConstants.SIM_ABSENT: 89 return new CommandException(Error.SIM_ABSENT); 90 case RILConstants.SUBSCRIPTION_NOT_AVAILABLE: 91 return new CommandException(Error.SUBSCRIPTION_NOT_AVAILABLE); 92 case RILConstants.MODE_NOT_SUPPORTED: 93 return new CommandException(Error.MODE_NOT_SUPPORTED); 94 case RILConstants.FDN_CHECK_FAILURE: 95 return new CommandException(Error.FDN_CHECK_FAILURE); 96 case RILConstants.ILLEGAL_SIM_OR_ME: 97 return new CommandException(Error.ILLEGAL_SIM_OR_ME); 98 case RILConstants.MISSING_RESOURCE: 99 return new CommandException(Error.MISSING_RESOURCE); 100 case RILConstants.NO_SUCH_ELEMENT: 101 return new CommandException(Error.NO_SUCH_ELEMENT); 102 case RILConstants.SUBSCRIPTION_NOT_SUPPORTED: 103 return new CommandException(Error.SUBSCRIPTION_NOT_SUPPORTED); 104 case RILConstants.DIAL_MODIFIED_TO_USSD: 105 return new CommandException(Error.DIAL_MODIFIED_TO_USSD); 106 case RILConstants.DIAL_MODIFIED_TO_SS: 107 return new CommandException(Error.DIAL_MODIFIED_TO_SS); 108 case RILConstants.DIAL_MODIFIED_TO_DIAL: 109 return new CommandException(Error.DIAL_MODIFIED_TO_DIAL); 110 case RILConstants.USSD_MODIFIED_TO_DIAL: 111 return new CommandException(Error.USSD_MODIFIED_TO_DIAL); 112 case RILConstants.USSD_MODIFIED_TO_SS: 113 return new CommandException(Error.USSD_MODIFIED_TO_SS); 114 case RILConstants.USSD_MODIFIED_TO_USSD: 115 return new CommandException(Error.USSD_MODIFIED_TO_USSD); 116 case RILConstants.SS_MODIFIED_TO_DIAL: 117 return new CommandException(Error.SS_MODIFIED_TO_DIAL); 118 case RILConstants.SS_MODIFIED_TO_USSD: 119 return new CommandException(Error.SS_MODIFIED_TO_USSD); 120 case RILConstants.SS_MODIFIED_TO_SS: 121 return new CommandException(Error.SS_MODIFIED_TO_SS); 122 default: 123 Rlog.e("GSM", "Unrecognized RIL errno " + ril_errno); 124 return new CommandException(Error.INVALID_RESPONSE); 125 } 126 } 127 128 public Error getCommandError() { 129 return mError; 130 } 131 132 133 134 } 135