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