1/*
2 * Copyright (C) 2006 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.cat;
18
19
20/**
21 * Class for errors in the Result object.
22 *
23 * {@hide}
24 */
25public class ResultException extends CatException {
26    private ResultCode mResult;
27    private int mAdditionalInfo;
28    private String mExplanation;
29
30    public ResultException(ResultCode result) {
31        super();
32
33        // ETSI TS 102 223, 8.12 -- For the general results '20', '21', '26',
34        // '38', '39', '3A', '3C', and '3D', it is mandatory for the terminal
35        // to provide a specific cause value as additional information.
36        switch (result) {
37            case TERMINAL_CRNTLY_UNABLE_TO_PROCESS:    // 0x20
38            case NETWORK_CRNTLY_UNABLE_TO_PROCESS:     // 0x21
39            case LAUNCH_BROWSER_ERROR:                 // 0x26
40            case MULTI_CARDS_CMD_ERROR:                // 0x38
41            case USIM_CALL_CONTROL_PERMANENT:          // 0x39
42            case BIP_ERROR:                            // 0x3a
43            case FRAMES_ERROR:                         // 0x3c
44            case MMS_ERROR:                            // 0x3d
45                throw new AssertionError(
46                        "For result code, " + result +
47                        ", additional information must be given!");
48        }
49
50        mResult = result;
51        mAdditionalInfo = -1;
52        mExplanation = "";
53    }
54
55    public ResultException(ResultCode result, String explanation) {
56        this(result);
57        mExplanation = explanation;
58    }
59
60    public ResultException(ResultCode result, int additionalInfo) {
61        this(result);
62
63        if (additionalInfo < 0) {
64            throw new AssertionError(
65                    "Additional info must be greater than zero!");
66        }
67
68        mAdditionalInfo = additionalInfo;
69    }
70
71    public ResultException(ResultCode result, int additionalInfo, String explanation) {
72        this(result, additionalInfo);
73        mExplanation = explanation;
74    }
75
76    public ResultCode result() {
77        return mResult;
78    }
79
80    public boolean hasAdditionalInfo() {
81        return mAdditionalInfo >= 0;
82    }
83
84    public int additionalInfo() {
85        return mAdditionalInfo;
86    }
87
88    public String explanation() {
89        return mExplanation;
90    }
91
92    @Override
93    public String toString() {
94        return "result=" + mResult + " additionalInfo=" + mAdditionalInfo +
95                " explantion=" + mExplanation;
96    }
97}
98