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 @Override 47 public boolean 48 updateAdnRecordsInEfBySearch (int efid, String oldTag, String oldPhoneNumber, 49 String newTag, String newPhoneNumber, String pin2) throws android.os.RemoteException { 50 return updateAdnRecordsInEfBySearchForSubscriber(getDefaultSubscription(), efid, oldTag, 51 oldPhoneNumber, newTag, newPhoneNumber, pin2); 52 } 53 54 @Override 55 public boolean 56 updateAdnRecordsInEfBySearchForSubscriber(int subId, int efid, String oldTag, 57 String oldPhoneNumber, String newTag, String newPhoneNumber, 58 String pin2) throws android.os.RemoteException { 59 IccPhoneBookInterfaceManagerProxy iccPbkIntMgrProxy = 60 getIccPhoneBookInterfaceManagerProxy(subId); 61 if (iccPbkIntMgrProxy != null) { 62 return iccPbkIntMgrProxy.updateAdnRecordsInEfBySearch(efid, oldTag, 63 oldPhoneNumber, newTag, newPhoneNumber, pin2); 64 } else { 65 Rlog.e(TAG,"updateAdnRecordsInEfBySearch iccPbkIntMgrProxy is" + 66 " null for Subscription:"+subId); 67 return false; 68 } 69 } 70 71 @Override 72 public boolean 73 updateAdnRecordsInEfByIndex(int efid, String newTag, 74 String newPhoneNumber, int index, String pin2) throws android.os.RemoteException { 75 return updateAdnRecordsInEfByIndexForSubscriber(getDefaultSubscription(), efid, newTag, 76 newPhoneNumber, index, pin2); 77 } 78 79 @Override 80 public boolean 81 updateAdnRecordsInEfByIndexForSubscriber(int subId, int efid, String newTag, 82 String newPhoneNumber, int index, String pin2) throws android.os.RemoteException { 83 IccPhoneBookInterfaceManagerProxy iccPbkIntMgrProxy = 84 getIccPhoneBookInterfaceManagerProxy(subId); 85 if (iccPbkIntMgrProxy != null) { 86 return iccPbkIntMgrProxy.updateAdnRecordsInEfByIndex(efid, newTag, 87 newPhoneNumber, index, pin2); 88 } else { 89 Rlog.e(TAG,"updateAdnRecordsInEfByIndex iccPbkIntMgrProxy is" + 90 " null for Subscription:"+subId); 91 return false; 92 } 93 } 94 95 @Override 96 public int[] getAdnRecordsSize(int efid) throws android.os.RemoteException { 97 return getAdnRecordsSizeForSubscriber(getDefaultSubscription(), efid); 98 } 99 100 @Override 101 public int[] 102 getAdnRecordsSizeForSubscriber(int subId, int efid) throws android.os.RemoteException { 103 IccPhoneBookInterfaceManagerProxy iccPbkIntMgrProxy = 104 getIccPhoneBookInterfaceManagerProxy(subId); 105 if (iccPbkIntMgrProxy != null) { 106 return iccPbkIntMgrProxy.getAdnRecordsSize(efid); 107 } else { 108 Rlog.e(TAG,"getAdnRecordsSize iccPbkIntMgrProxy is" + 109 " null for Subscription:"+subId); 110 return null; 111 } 112 } 113 114 @Override 115 public List<AdnRecord> getAdnRecordsInEf(int efid) throws android.os.RemoteException { 116 return getAdnRecordsInEfForSubscriber(getDefaultSubscription(), efid); 117 } 118 119 @Override 120 public List<AdnRecord> getAdnRecordsInEfForSubscriber(int subId, int efid) 121 throws android.os.RemoteException { 122 IccPhoneBookInterfaceManagerProxy iccPbkIntMgrProxy = 123 getIccPhoneBookInterfaceManagerProxy(subId); 124 if (iccPbkIntMgrProxy != null) { 125 return iccPbkIntMgrProxy.getAdnRecordsInEf(efid); 126 } else { 127 Rlog.e(TAG,"getAdnRecordsInEf iccPbkIntMgrProxy is" + 128 "null for Subscription:"+subId); 129 return null; 130 } 131 } 132 133 /** 134 * get phone book interface manager proxy object based on subscription. 135 **/ 136 private IccPhoneBookInterfaceManagerProxy 137 getIccPhoneBookInterfaceManagerProxy(int subId) { 138 139 int phoneId = SubscriptionController.getInstance().getPhoneId(subId); 140 try { 141 return ((PhoneProxy)mPhone[(int)phoneId]).getIccPhoneBookInterfaceManagerProxy(); 142 } catch (NullPointerException e) { 143 Rlog.e(TAG, "Exception is :"+e.toString()+" For subscription :"+subId ); 144 e.printStackTrace(); //To print stack trace 145 return null; 146 } catch (ArrayIndexOutOfBoundsException e) { 147 Rlog.e(TAG, "Exception is :"+e.toString()+" For subscription :"+subId ); 148 e.printStackTrace(); 149 return null; 150 } 151 } 152 153 private int getDefaultSubscription() { 154 return PhoneFactory.getDefaultSubscription(); 155 } 156 } 157