Home | History | Annotate | Download | only in telephony
      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         SIM_ABSENT,
     41         SUBSCRIPTION_NOT_AVAILABLE,
     42         MODE_NOT_SUPPORTED,
     43         FDN_CHECK_FAILURE,
     44         ILLEGAL_SIM_OR_ME,
     45     }
     46 
     47     public CommandException(Error e) {
     48         super(e.toString());
     49         this.e = e;
     50     }
     51 
     52     public static CommandException
     53     fromRilErrno(int ril_errno) {
     54         switch(ril_errno) {
     55             case RILConstants.SUCCESS:                       return null;
     56             case RILConstants.RIL_ERRNO_INVALID_RESPONSE:
     57                 return new CommandException(Error.INVALID_RESPONSE);
     58             case RILConstants.RADIO_NOT_AVAILABLE:
     59                 return new CommandException(Error.RADIO_NOT_AVAILABLE);
     60             case RILConstants.GENERIC_FAILURE:
     61                 return new CommandException(Error.GENERIC_FAILURE);
     62             case RILConstants.PASSWORD_INCORRECT:
     63                 return new CommandException(Error.PASSWORD_INCORRECT);
     64             case RILConstants.SIM_PIN2:
     65                 return new CommandException(Error.SIM_PIN2);
     66             case RILConstants.SIM_PUK2:
     67                 return new CommandException(Error.SIM_PUK2);
     68             case RILConstants.REQUEST_NOT_SUPPORTED:
     69                 return new CommandException(Error.REQUEST_NOT_SUPPORTED);
     70             case RILConstants.OP_NOT_ALLOWED_DURING_VOICE_CALL:
     71                 return new CommandException(Error.OP_NOT_ALLOWED_DURING_VOICE_CALL);
     72             case RILConstants.OP_NOT_ALLOWED_BEFORE_REG_NW:
     73                 return new CommandException(Error.OP_NOT_ALLOWED_BEFORE_REG_NW);
     74             case RILConstants.SMS_SEND_FAIL_RETRY:
     75                 return new CommandException(Error.SMS_FAIL_RETRY);
     76             case RILConstants.SIM_ABSENT:
     77                 return new CommandException(Error.SIM_ABSENT);
     78             case RILConstants.SUBSCRIPTION_NOT_AVAILABLE:
     79                 return new CommandException(Error.SUBSCRIPTION_NOT_AVAILABLE);
     80             case RILConstants.MODE_NOT_SUPPORTED:
     81                 return new CommandException(Error.MODE_NOT_SUPPORTED);
     82             case RILConstants.FDN_CHECK_FAILURE:
     83                 return new CommandException(Error.FDN_CHECK_FAILURE);
     84             case RILConstants.ILLEGAL_SIM_OR_ME:
     85                 return new CommandException(Error.ILLEGAL_SIM_OR_ME);
     86             default:
     87                 Log.e("GSM", "Unrecognized RIL errno " + ril_errno);
     88                 return new CommandException(Error.INVALID_RESPONSE);
     89         }
     90     }
     91 
     92     public Error getCommandError() {
     93         return e;
     94     }
     95 
     96 
     97 
     98 }
     99