• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  * Copyright (c) 2011-2013, 2021 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.content.ContentValues;
23 import android.os.Build;
24 import android.os.TelephonyServiceManager.ServiceRegisterer;
25 import android.telephony.TelephonyFrameworkInitializer;
26 
27 import com.android.internal.telephony.subscription.SubscriptionManagerService;
28 import com.android.internal.telephony.uicc.AdnCapacity;
29 import com.android.internal.telephony.uicc.AdnRecord;
30 import com.android.telephony.Rlog;
31 
32 import java.util.List;
33 
34 public class UiccPhoneBookController extends IIccPhoneBook.Stub {
35     private static final String TAG = "UiccPhoneBookController";
36 
37     /* only one UiccPhoneBookController exists */
38     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
UiccPhoneBookController()39     public UiccPhoneBookController() {
40         ServiceRegisterer iccPhoneBookServiceRegisterer = TelephonyFrameworkInitializer
41                 .getTelephonyServiceManager()
42                 .getIccPhoneBookServiceRegisterer();
43         if (iccPhoneBookServiceRegisterer.get() == null) {
44             iccPhoneBookServiceRegisterer.register(this);
45         }
46     }
47 
48     @Override
49     public boolean
updateAdnRecordsInEfBySearch(int efid, String oldTag, String oldPhoneNumber, String newTag, String newPhoneNumber, String pin2)50     updateAdnRecordsInEfBySearch (int efid, String oldTag, String oldPhoneNumber,
51             String newTag, String newPhoneNumber, String pin2) throws android.os.RemoteException {
52         ContentValues values = new ContentValues();
53         values.put(IccProvider.STR_TAG, oldTag);
54         values.put(IccProvider.STR_NUMBER, oldPhoneNumber);
55         values.put(IccProvider.STR_NEW_TAG, newTag);
56         values.put(IccProvider.STR_NEW_NUMBER, newPhoneNumber);
57         return updateAdnRecordsInEfBySearchForSubscriber(getDefaultSubscription(),
58                 efid, values, pin2);
59     }
60 
61     @Override
62     public boolean
updateAdnRecordsInEfByIndexForSubscriber(int subId, int efid, ContentValues values, int index, String pin2)63     updateAdnRecordsInEfByIndexForSubscriber(int subId, int efid, ContentValues values,
64             int index, String pin2) throws android.os.RemoteException {
65         IccPhoneBookInterfaceManager iccPbkIntMgr =
66                              getIccPhoneBookInterfaceManager(subId);
67         if (iccPbkIntMgr != null) {
68             return iccPbkIntMgr.updateAdnRecordsInEfByIndex(efid, values,
69                     index, pin2);
70         } else {
71             Rlog.e(TAG,"updateAdnRecordsInEfByIndex iccPbkIntMgr is" +
72                       " null for Subscription:"+subId);
73             return false;
74         }
75     }
76 
77     @Override
getAdnRecordsSize(int efid)78     public int[] getAdnRecordsSize(int efid) throws android.os.RemoteException {
79         return getAdnRecordsSizeForSubscriber(getDefaultSubscription(), efid);
80     }
81 
82     @Override
83     public int[]
getAdnRecordsSizeForSubscriber(int subId, int efid)84     getAdnRecordsSizeForSubscriber(int subId, int efid) throws android.os.RemoteException {
85         IccPhoneBookInterfaceManager iccPbkIntMgr =
86                              getIccPhoneBookInterfaceManager(subId);
87         if (iccPbkIntMgr != null) {
88             return iccPbkIntMgr.getAdnRecordsSize(efid);
89         } else {
90             Rlog.e(TAG,"getAdnRecordsSize iccPbkIntMgr is" +
91                       " null for Subscription:"+subId);
92             return null;
93         }
94     }
95 
96     @Override
getAdnRecordsInEf(int efid)97     public List<AdnRecord> getAdnRecordsInEf(int efid) throws android.os.RemoteException {
98         return getAdnRecordsInEfForSubscriber(getDefaultSubscription(), efid);
99     }
100 
101     @Override
getAdnRecordsInEfForSubscriber(int subId, int efid)102     public List<AdnRecord> getAdnRecordsInEfForSubscriber(int subId, int efid)
103            throws android.os.RemoteException {
104         IccPhoneBookInterfaceManager iccPbkIntMgr =
105                              getIccPhoneBookInterfaceManager(subId);
106         if (iccPbkIntMgr != null) {
107             return iccPbkIntMgr.getAdnRecordsInEf(efid);
108         } else {
109             Rlog.e(TAG,"getAdnRecordsInEf iccPbkIntMgr is" +
110                       "null for Subscription:"+subId);
111             return null;
112         }
113     }
114 
115     @Override
getAdnRecordsCapacityForSubscriber(int subId)116     public AdnCapacity getAdnRecordsCapacityForSubscriber(int subId)
117            throws android.os.RemoteException {
118         IccPhoneBookInterfaceManager iccPbkIntMgr = getIccPhoneBookInterfaceManager(subId);
119         if (iccPbkIntMgr != null) {
120             return iccPbkIntMgr.getAdnRecordsCapacity();
121         } else {
122             Rlog.e(TAG, "getAdnRecordsCapacity iccPbkIntMgr is null for Subscription:" + subId);
123             return null;
124         }
125     }
126 
127     @Override
128     public boolean
updateAdnRecordsInEfBySearchForSubscriber(int subId, int efid, ContentValues values, String pin2)129     updateAdnRecordsInEfBySearchForSubscriber(int subId, int efid,
130             ContentValues values, String pin2)
131             throws android.os.RemoteException {
132         IccPhoneBookInterfaceManager iccPbkIntMgr = getIccPhoneBookInterfaceManager(subId);
133         if (iccPbkIntMgr != null) {
134             return iccPbkIntMgr.updateAdnRecordsInEfBySearchForSubscriber(
135                 efid, values, pin2);
136         } else {
137             Rlog.e(TAG,"updateAdnRecordsInEfBySearchForSubscriber " +
138                 "iccPbkIntMgr is null for Subscription:"+subId);
139             return false;
140         }
141     }
142 
143     /**
144      * get phone book interface manager object based on subscription.
145      **/
146     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
147     private IccPhoneBookInterfaceManager
getIccPhoneBookInterfaceManager(int subId)148             getIccPhoneBookInterfaceManager(int subId) {
149 
150         int phoneId = SubscriptionManagerService.getInstance().getPhoneId(subId);
151         try {
152             return PhoneFactory.getPhone(phoneId).getIccPhoneBookInterfaceManager();
153         } catch (NullPointerException e) {
154             Rlog.e(TAG, "Exception is :"+e.toString()+" For subscription :"+subId );
155             e.printStackTrace(); //To print stack trace
156             return null;
157         } catch (ArrayIndexOutOfBoundsException e) {
158             Rlog.e(TAG, "Exception is :"+e.toString()+" For subscription :"+subId );
159             e.printStackTrace();
160             return null;
161         }
162     }
163 
164     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
getDefaultSubscription()165     private int getDefaultSubscription() {
166         return PhoneFactory.getDefaultSubscription();
167     }
168 }
169