1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. 4 * Not a Contribution. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package com.android.internal.telephony; 20 21 import android.os.ServiceManager; 22 import android.os.RemoteException; 23 import android.telephony.Rlog; 24 25 import com.android.internal.telephony.IccPhoneBookInterfaceManagerProxy; 26 import com.android.internal.telephony.IIccPhoneBook; 27 import com.android.internal.telephony.Phone; 28 import com.android.internal.telephony.uicc.AdnRecord; 29 30 import java.lang.ArrayIndexOutOfBoundsException; 31 import java.lang.NullPointerException; 32 import java.util.List; 33 34 public class UiccPhoneBookController extends IIccPhoneBook.Stub { 35 private static final String TAG = "UiccPhoneBookController"; 36 private Phone[] mPhone; 37 38 /* only one UiccPhoneBookController exists */ 39 public UiccPhoneBookController(Phone[] phone) { 40 if (ServiceManager.getService("simphonebook") == null) { 41 ServiceManager.addService("simphonebook", this); 42 } 43 mPhone = phone; 44 } 45 46 public boolean 47 updateAdnRecordsInEfBySearch (int efid, String oldTag, String oldPhoneNumber, 48 String newTag, String newPhoneNumber, String pin2) throws android.os.RemoteException { 49 return updateAdnRecordsInEfBySearchForSubscriber(getDefaultSubscription(), efid, oldTag, 50 oldPhoneNumber, newTag, newPhoneNumber, pin2); 51 } 52 53 public boolean 54 updateAdnRecordsInEfBySearchForSubscriber(long subId, int efid, String oldTag, 55 String oldPhoneNumber, String newTag, String newPhoneNumber, 56 String pin2) throws android.os.RemoteException { 57 IccPhoneBookInterfaceManagerProxy iccPbkIntMgrProxy = 58 getIccPhoneBookInterfaceManagerProxy(subId); 59 if (iccPbkIntMgrProxy != null) { 60 return iccPbkIntMgrProxy.updateAdnRecordsInEfBySearch(efid, oldTag, 61 oldPhoneNumber, newTag, newPhoneNumber, pin2); 62 } else { 63 Rlog.e(TAG,"updateAdnRecordsInEfBySearch iccPbkIntMgrProxy is" + 64 " null for Subscription:"+subId); 65 return false; 66 } 67 } 68 69 public boolean 70 updateAdnRecordsInEfByIndex(int efid, String newTag, 71 String newPhoneNumber, int index, String pin2) throws android.os.RemoteException { 72 return updateAdnRecordsInEfByIndexForSubscriber(getDefaultSubscription(), efid, newTag, 73 newPhoneNumber, index, pin2); 74 } 75 76 public boolean 77 updateAdnRecordsInEfByIndexForSubscriber(long subId, int efid, String newTag, 78 String newPhoneNumber, int index, String pin2) throws android.os.RemoteException { 79 IccPhoneBookInterfaceManagerProxy iccPbkIntMgrProxy = 80 getIccPhoneBookInterfaceManagerProxy(subId); 81 if (iccPbkIntMgrProxy != null) { 82 return iccPbkIntMgrProxy.updateAdnRecordsInEfByIndex(efid, newTag, 83 newPhoneNumber, index, pin2); 84 } else { 85 Rlog.e(TAG,"updateAdnRecordsInEfByIndex iccPbkIntMgrProxy is" + 86 " null for Subscription:"+subId); 87 return false; 88 } 89 } 90 91 public int[] getAdnRecordsSize(int efid) throws android.os.RemoteException { 92 return getAdnRecordsSizeForSubscriber(getDefaultSubscription(), efid); 93 } 94 95 public int[] 96 getAdnRecordsSizeForSubscriber(long subId, int efid) throws android.os.RemoteException { 97 IccPhoneBookInterfaceManagerProxy iccPbkIntMgrProxy = 98 getIccPhoneBookInterfaceManagerProxy(subId); 99 if (iccPbkIntMgrProxy != null) { 100 return iccPbkIntMgrProxy.getAdnRecordsSize(efid); 101 } else { 102 Rlog.e(TAG,"getAdnRecordsSize iccPbkIntMgrProxy is" + 103 " null for Subscription:"+subId); 104 return null; 105 } 106 } 107 108 public List<AdnRecord> getAdnRecordsInEf(int efid) throws android.os.RemoteException { 109 return getAdnRecordsInEfForSubscriber(getDefaultSubscription(), efid); 110 } 111 112 public List<AdnRecord> getAdnRecordsInEfForSubscriber(long subId, int efid) 113 throws android.os.RemoteException { 114 IccPhoneBookInterfaceManagerProxy iccPbkIntMgrProxy = 115 getIccPhoneBookInterfaceManagerProxy(subId); 116 if (iccPbkIntMgrProxy != null) { 117 return iccPbkIntMgrProxy.getAdnRecordsInEf(efid); 118 } else { 119 Rlog.e(TAG,"getAdnRecordsInEf iccPbkIntMgrProxy is" + 120 "null for Subscription:"+subId); 121 return null; 122 } 123 } 124 125 /** 126 * get phone book interface manager proxy object based on subscription. 127 **/ 128 private IccPhoneBookInterfaceManagerProxy 129 getIccPhoneBookInterfaceManagerProxy(long subId) { 130 131 long phoneId = SubscriptionController.getInstance().getPhoneId(subId); 132 try { 133 return ((PhoneProxy)mPhone[(int)phoneId]).getIccPhoneBookInterfaceManagerProxy(); 134 } catch (NullPointerException e) { 135 Rlog.e(TAG, "Exception is :"+e.toString()+" For subscription :"+subId ); 136 e.printStackTrace(); //To print stack trace 137 return null; 138 } catch (ArrayIndexOutOfBoundsException e) { 139 Rlog.e(TAG, "Exception is :"+e.toString()+" For subscription :"+subId ); 140 e.printStackTrace(); 141 return null; 142 } 143 } 144 145 private long getDefaultSubscription() { 146 return PhoneFactory.getDefaultSubscription(); 147 } 148 } 149