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