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