CommandException.java revision 40d1d394302d83eb56f66cf08daecc612c97cd28
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    }
48
49    public CommandException(Error e) {
50        super(e.toString());
51        mError = e;
52    }
53
54    public static CommandException
55    fromRilErrno(int ril_errno) {
56        switch(ril_errno) {
57            case RILConstants.SUCCESS:                       return null;
58            case RILConstants.RIL_ERRNO_INVALID_RESPONSE:
59                return new CommandException(Error.INVALID_RESPONSE);
60            case RILConstants.RADIO_NOT_AVAILABLE:
61                return new CommandException(Error.RADIO_NOT_AVAILABLE);
62            case RILConstants.GENERIC_FAILURE:
63                return new CommandException(Error.GENERIC_FAILURE);
64            case RILConstants.PASSWORD_INCORRECT:
65                return new CommandException(Error.PASSWORD_INCORRECT);
66            case RILConstants.SIM_PIN2:
67                return new CommandException(Error.SIM_PIN2);
68            case RILConstants.SIM_PUK2:
69                return new CommandException(Error.SIM_PUK2);
70            case RILConstants.REQUEST_NOT_SUPPORTED:
71                return new CommandException(Error.REQUEST_NOT_SUPPORTED);
72            case RILConstants.OP_NOT_ALLOWED_DURING_VOICE_CALL:
73                return new CommandException(Error.OP_NOT_ALLOWED_DURING_VOICE_CALL);
74            case RILConstants.OP_NOT_ALLOWED_BEFORE_REG_NW:
75                return new CommandException(Error.OP_NOT_ALLOWED_BEFORE_REG_NW);
76            case RILConstants.SMS_SEND_FAIL_RETRY:
77                return new CommandException(Error.SMS_FAIL_RETRY);
78            case RILConstants.SIM_ABSENT:
79                return new CommandException(Error.SIM_ABSENT);
80            case RILConstants.SUBSCRIPTION_NOT_AVAILABLE:
81                return new CommandException(Error.SUBSCRIPTION_NOT_AVAILABLE);
82            case RILConstants.MODE_NOT_SUPPORTED:
83                return new CommandException(Error.MODE_NOT_SUPPORTED);
84            case RILConstants.FDN_CHECK_FAILURE:
85                return new CommandException(Error.FDN_CHECK_FAILURE);
86            case RILConstants.ILLEGAL_SIM_OR_ME:
87                return new CommandException(Error.ILLEGAL_SIM_OR_ME);
88            case RILConstants.MISSING_RESOURCE:
89                return new CommandException(Error.MISSING_RESOURCE);
90            case RILConstants.NO_SUCH_ELEMENT:
91                return new CommandException(Error.NO_SUCH_ELEMENT);
92            default:
93                Rlog.e("GSM", "Unrecognized RIL errno " + ril_errno);
94                return new CommandException(Error.INVALID_RESPONSE);
95        }
96    }
97
98    public Error getCommandError() {
99        return mError;
100    }
101
102
103
104}
105