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; 18 19 /** 20 * {@hide} 21 */ 22 public class 23 IccIoResult { 24 public int sw1; 25 public int sw2; 26 27 public byte[] payload; 28 29 public IccIoResult(int sw1, int sw2, byte[] payload) { 30 this.sw1 = sw1; 31 this.sw2 = sw2; 32 this.payload = payload; 33 } 34 35 public IccIoResult(int sw1, int sw2, String hexString) { 36 this(sw1, sw2, IccUtils.hexStringToBytes(hexString)); 37 } 38 39 public String toString() { 40 return "IccIoResponse sw1:0x" + Integer.toHexString(sw1) + " sw2:0x" 41 + Integer.toHexString(sw2); 42 } 43 44 /** 45 * true if this operation was successful 46 * See GSM 11.11 Section 9.4 47 * (the fun stuff is absent in 51.011) 48 */ 49 public boolean success() { 50 return sw1 == 0x90 || sw1 == 0x91 || sw1 == 0x9e || sw1 == 0x9f; 51 } 52 53 /** 54 * Returns exception on error or null if success 55 */ 56 public IccException getException() { 57 if (success()) return null; 58 59 switch (sw1) { 60 case 0x94: 61 if (sw2 == 0x08) { 62 return new IccFileTypeMismatch(); 63 } else { 64 return new IccFileNotFound(); 65 } 66 default: 67 return new IccException("sw1:" + sw1 + " sw2:" + sw2); 68 } 69 } 70 } 71