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.util.Log; 22 23 /** 24 * {@hide} 25 */ 26 public class CommandException extends RuntimeException { 27 private Error e; 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 ILLEGAL_SIM_OR_ME, 41 } 42 43 public CommandException(Error e) { 44 super(e.toString()); 45 this.e = e; 46 } 47 48 public static CommandException 49 fromRilErrno(int ril_errno) { 50 switch(ril_errno) { 51 case RILConstants.SUCCESS: return null; 52 case RILConstants.RIL_ERRNO_INVALID_RESPONSE: 53 return new CommandException(Error.INVALID_RESPONSE); 54 case RILConstants.RADIO_NOT_AVAILABLE: 55 return new CommandException(Error.RADIO_NOT_AVAILABLE); 56 case RILConstants.GENERIC_FAILURE: 57 return new CommandException(Error.GENERIC_FAILURE); 58 case RILConstants.PASSWORD_INCORRECT: 59 return new CommandException(Error.PASSWORD_INCORRECT); 60 case RILConstants.SIM_PIN2: 61 return new CommandException(Error.SIM_PIN2); 62 case RILConstants.SIM_PUK2: 63 return new CommandException(Error.SIM_PUK2); 64 case RILConstants.REQUEST_NOT_SUPPORTED: 65 return new CommandException(Error.REQUEST_NOT_SUPPORTED); 66 case RILConstants.OP_NOT_ALLOWED_DURING_VOICE_CALL: 67 return new CommandException(Error.OP_NOT_ALLOWED_DURING_VOICE_CALL); 68 case RILConstants.OP_NOT_ALLOWED_BEFORE_REG_NW: 69 return new CommandException(Error.OP_NOT_ALLOWED_BEFORE_REG_NW); 70 case RILConstants.SMS_SEND_FAIL_RETRY: 71 return new CommandException(Error.SMS_FAIL_RETRY); 72 case RILConstants.ILLEGAL_SIM_OR_ME: 73 return new CommandException(Error.ILLEGAL_SIM_OR_ME); 74 default: 75 Log.e("GSM", "Unrecognized RIL errno " + ril_errno); 76 return new CommandException(Error.INVALID_RESPONSE); 77 } 78 } 79 80 public Error getCommandError() { 81 return e; 82 } 83 84 85 86 } 87