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.compat.annotation.UnsupportedAppUsage; 22 import android.os.ServiceManager; 23 24 import com.android.internal.telephony.uicc.AdnRecord; 25 import com.android.telephony.Rlog; 26 27 import java.util.List; 28 29 public class UiccPhoneBookController extends IIccPhoneBook.Stub { 30 private static final String TAG = "UiccPhoneBookController"; 31 32 /* only one UiccPhoneBookController exists */ 33 @UnsupportedAppUsage UiccPhoneBookController()34 public UiccPhoneBookController() { 35 if (ServiceManager.getService("simphonebook") == null) { 36 ServiceManager.addService("simphonebook", this); 37 } 38 } 39 40 @Override 41 public boolean updateAdnRecordsInEfBySearch(int efid, String oldTag, String oldPhoneNumber, String newTag, String newPhoneNumber, String pin2)42 updateAdnRecordsInEfBySearch (int efid, String oldTag, String oldPhoneNumber, 43 String newTag, String newPhoneNumber, String pin2) throws android.os.RemoteException { 44 return updateAdnRecordsInEfBySearchForSubscriber(getDefaultSubscription(), efid, oldTag, 45 oldPhoneNumber, newTag, newPhoneNumber, pin2); 46 } 47 48 @Override 49 public boolean updateAdnRecordsInEfBySearchForSubscriber(int subId, int efid, String oldTag, String oldPhoneNumber, String newTag, String newPhoneNumber, String pin2)50 updateAdnRecordsInEfBySearchForSubscriber(int subId, int efid, String oldTag, 51 String oldPhoneNumber, String newTag, String newPhoneNumber, 52 String pin2) throws android.os.RemoteException { 53 IccPhoneBookInterfaceManager iccPbkIntMgr = 54 getIccPhoneBookInterfaceManager(subId); 55 if (iccPbkIntMgr != null) { 56 return iccPbkIntMgr.updateAdnRecordsInEfBySearch(efid, oldTag, 57 oldPhoneNumber, newTag, newPhoneNumber, pin2); 58 } else { 59 Rlog.e(TAG,"updateAdnRecordsInEfBySearch iccPbkIntMgr is" + 60 " null for Subscription:"+subId); 61 return false; 62 } 63 } 64 65 @Override 66 public boolean updateAdnRecordsInEfByIndex(int efid, String newTag, String newPhoneNumber, int index, String pin2)67 updateAdnRecordsInEfByIndex(int efid, String newTag, 68 String newPhoneNumber, int index, String pin2) throws android.os.RemoteException { 69 return updateAdnRecordsInEfByIndexForSubscriber(getDefaultSubscription(), efid, newTag, 70 newPhoneNumber, index, pin2); 71 } 72 73 @Override 74 public boolean updateAdnRecordsInEfByIndexForSubscriber(int subId, int efid, String newTag, String newPhoneNumber, int index, String pin2)75 updateAdnRecordsInEfByIndexForSubscriber(int subId, int efid, String newTag, 76 String newPhoneNumber, int index, String pin2) throws android.os.RemoteException { 77 IccPhoneBookInterfaceManager iccPbkIntMgr = 78 getIccPhoneBookInterfaceManager(subId); 79 if (iccPbkIntMgr != null) { 80 return iccPbkIntMgr.updateAdnRecordsInEfByIndex(efid, newTag, 81 newPhoneNumber, index, pin2); 82 } else { 83 Rlog.e(TAG,"updateAdnRecordsInEfByIndex iccPbkIntMgr is" + 84 " null for Subscription:"+subId); 85 return false; 86 } 87 } 88 89 @Override getAdnRecordsSize(int efid)90 public int[] getAdnRecordsSize(int efid) throws android.os.RemoteException { 91 return getAdnRecordsSizeForSubscriber(getDefaultSubscription(), efid); 92 } 93 94 @Override 95 public int[] getAdnRecordsSizeForSubscriber(int subId, int efid)96 getAdnRecordsSizeForSubscriber(int subId, int efid) throws android.os.RemoteException { 97 IccPhoneBookInterfaceManager iccPbkIntMgr = 98 getIccPhoneBookInterfaceManager(subId); 99 if (iccPbkIntMgr != null) { 100 return iccPbkIntMgr.getAdnRecordsSize(efid); 101 } else { 102 Rlog.e(TAG,"getAdnRecordsSize iccPbkIntMgr is" + 103 " null for Subscription:"+subId); 104 return null; 105 } 106 } 107 108 @Override getAdnRecordsInEf(int efid)109 public List<AdnRecord> getAdnRecordsInEf(int efid) throws android.os.RemoteException { 110 return getAdnRecordsInEfForSubscriber(getDefaultSubscription(), efid); 111 } 112 113 @Override getAdnRecordsInEfForSubscriber(int subId, int efid)114 public List<AdnRecord> getAdnRecordsInEfForSubscriber(int subId, int efid) 115 throws android.os.RemoteException { 116 IccPhoneBookInterfaceManager iccPbkIntMgr = 117 getIccPhoneBookInterfaceManager(subId); 118 if (iccPbkIntMgr != null) { 119 return iccPbkIntMgr.getAdnRecordsInEf(efid); 120 } else { 121 Rlog.e(TAG,"getAdnRecordsInEf iccPbkIntMgr is" + 122 "null for Subscription:"+subId); 123 return null; 124 } 125 } 126 127 /** 128 * get phone book interface manager object based on subscription. 129 **/ 130 @UnsupportedAppUsage 131 private IccPhoneBookInterfaceManager getIccPhoneBookInterfaceManager(int subId)132 getIccPhoneBookInterfaceManager(int subId) { 133 134 int phoneId = SubscriptionController.getInstance().getPhoneId(subId); 135 try { 136 return PhoneFactory.getPhone(phoneId).getIccPhoneBookInterfaceManager(); 137 } catch (NullPointerException e) { 138 Rlog.e(TAG, "Exception is :"+e.toString()+" For subscription :"+subId ); 139 e.printStackTrace(); //To print stack trace 140 return null; 141 } catch (ArrayIndexOutOfBoundsException e) { 142 Rlog.e(TAG, "Exception is :"+e.toString()+" For subscription :"+subId ); 143 e.printStackTrace(); 144 return null; 145 } 146 } 147 148 @UnsupportedAppUsage getDefaultSubscription()149 private int getDefaultSubscription() { 150 return PhoneFactory.getDefaultSubscription(); 151 } 152 } 153