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            default:
49                break;
50        }
51
52        mResult = result;
53        mAdditionalInfo = -1;
54        mExplanation = "";
55    }
56
57    public ResultException(ResultCode result, String explanation) {
58        this(result);
59        mExplanation = explanation;
60    }
61
62    public ResultException(ResultCode result, int additionalInfo) {
63        this(result);
64
65        if (additionalInfo < 0) {
66            throw new AssertionError(
67                    "Additional info must be greater than zero!");
68        }
69
70        mAdditionalInfo = additionalInfo;
71    }
72
73    public ResultException(ResultCode result, int additionalInfo, String explanation) {
74        this(result, additionalInfo);
75        mExplanation = explanation;
76    }
77
78    public ResultCode result() {
79        return mResult;
80    }
81
82    public boolean hasAdditionalInfo() {
83        return mAdditionalInfo >= 0;
84    }
85
86    public int additionalInfo() {
87        return mAdditionalInfo;
88    }
89
90    public String explanation() {
91        return mExplanation;
92    }
93
94    @Override
95    public String toString() {
96        return "result=" + mResult + " additionalInfo=" + mAdditionalInfo +
97                " explantion=" + mExplanation;
98    }
99}
100