CommandException.java revision a8467dd0c524787104b1ccdddc5e8af10ba729ed
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
17package com.android.internal.telephony;
18
19import com.android.internal.telephony.RILConstants;
20
21import android.telephony.Rlog;
22
23/**
24 * {@hide}
25 */
26public class CommandException extends RuntimeException {
27    private Error mError;
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        MISSING_RESOURCE,
46        NO_SUCH_ELEMENT,
47        SUBSCRIPTION_NOT_SUPPORTED,
48    }
49
50    public CommandException(Error e) {
51        super(e.toString());
52        mError = e;
53    }
54
55    public static CommandException
56    fromRilErrno(int ril_errno) {
57        switch(ril_errno) {
58            case RILConstants.SUCCESS:                       return null;
59            case RILConstants.RIL_ERRNO_INVALID_RESPONSE:
60                return new CommandException(Error.INVALID_RESPONSE);
61            case RILConstants.RADIO_NOT_AVAILABLE:
62                return new CommandException(Error.RADIO_NOT_AVAILABLE);
63            case RILConstants.GENERIC_FAILURE:
64                return new CommandException(Error.GENERIC_FAILURE);
65            case RILConstants.PASSWORD_INCORRECT:
66                return new CommandException(Error.PASSWORD_INCORRECT);
67            case RILConstants.SIM_PIN2:
68                return new CommandException(Error.SIM_PIN2);
69            case RILConstants.SIM_PUK2:
70                return new CommandException(Error.SIM_PUK2);
71            case RILConstants.REQUEST_NOT_SUPPORTED:
72                return new CommandException(Error.REQUEST_NOT_SUPPORTED);
73            case RILConstants.OP_NOT_ALLOWED_DURING_VOICE_CALL:
74                return new CommandException(Error.OP_NOT_ALLOWED_DURING_VOICE_CALL);
75            case RILConstants.OP_NOT_ALLOWED_BEFORE_REG_NW:
76                return new CommandException(Error.OP_NOT_ALLOWED_BEFORE_REG_NW);
77            case RILConstants.SMS_SEND_FAIL_RETRY:
78                return new CommandException(Error.SMS_FAIL_RETRY);
79            case RILConstants.SIM_ABSENT:
80                return new CommandException(Error.SIM_ABSENT);
81            case RILConstants.SUBSCRIPTION_NOT_AVAILABLE:
82                return new CommandException(Error.SUBSCRIPTION_NOT_AVAILABLE);
83            case RILConstants.MODE_NOT_SUPPORTED:
84                return new CommandException(Error.MODE_NOT_SUPPORTED);
85            case RILConstants.FDN_CHECK_FAILURE:
86                return new CommandException(Error.FDN_CHECK_FAILURE);
87            case RILConstants.ILLEGAL_SIM_OR_ME:
88                return new CommandException(Error.ILLEGAL_SIM_OR_ME);
89            case RILConstants.MISSING_RESOURCE:
90                return new CommandException(Error.MISSING_RESOURCE);
91            case RILConstants.NO_SUCH_ELEMENT:
92                return new CommandException(Error.NO_SUCH_ELEMENT);
93            case RILConstants.SUBSCRIPTION_NOT_SUPPORTED:
94                return new CommandException(Error.SUBSCRIPTION_NOT_SUPPORTED);
95            default:
96                Rlog.e("GSM", "Unrecognized RIL errno " + ril_errno);
97                return new CommandException(Error.INVALID_RESPONSE);
98        }
99    }
100
101    public Error getCommandError() {
102        return mError;
103    }
104
105
106
107}
108