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