• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     }
41 
CommandException(Error e)42     public CommandException(Error e) {
43         super(e.toString());
44         this.e = e;
45     }
46 
47     public static CommandException
fromRilErrno(int ril_errno)48     fromRilErrno(int ril_errno) {
49         switch(ril_errno) {
50             case RILConstants.SUCCESS:                       return null;
51             case RILConstants.RIL_ERRNO_INVALID_RESPONSE:
52                 return new CommandException(Error.INVALID_RESPONSE);
53             case RILConstants.RADIO_NOT_AVAILABLE:
54                 return new CommandException(Error.RADIO_NOT_AVAILABLE);
55             case RILConstants.GENERIC_FAILURE:
56                 return new CommandException(Error.GENERIC_FAILURE);
57             case RILConstants.PASSWORD_INCORRECT:
58                 return new CommandException(Error.PASSWORD_INCORRECT);
59             case RILConstants.SIM_PIN2:
60                 return new CommandException(Error.SIM_PIN2);
61             case RILConstants.SIM_PUK2:
62                 return new CommandException(Error.SIM_PUK2);
63             case RILConstants.REQUEST_NOT_SUPPORTED:
64                 return new CommandException(Error.REQUEST_NOT_SUPPORTED);
65             case RILConstants.OP_NOT_ALLOWED_DURING_VOICE_CALL:
66                 return new CommandException(Error.OP_NOT_ALLOWED_DURING_VOICE_CALL);
67             case RILConstants.OP_NOT_ALLOWED_BEFORE_REG_NW:
68                 return new CommandException(Error.OP_NOT_ALLOWED_BEFORE_REG_NW);
69             case RILConstants.SMS_SEND_FAIL_RETRY:
70                 return new CommandException(Error.SMS_FAIL_RETRY);
71             default:
72                 Log.e("GSM", "Unrecognized RIL errno " + ril_errno);
73                 return new CommandException(Error.INVALID_RESPONSE);
74         }
75     }
76 
getCommandError()77     public Error getCommandError() {
78         return e;
79     }
80 
81 
82 
83 }
84