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