|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "cntsimutility.h" |
|
18 #include <mmtsy_names.h> |
|
19 #include <startupdomainpskeys.h> |
|
20 #include <e32property.h> |
|
21 |
|
22 CntSimUtility::CntSimUtility(StoreType type, int& error, QObject *parent) |
|
23 : QObject(parent), |
|
24 m_etelStoreInfoPckg(m_etelStoreInfo), |
|
25 m_serviceTablePckg(m_serviceTable), |
|
26 m_asyncWorker(NULL), |
|
27 m_activeRequest(ENoActiveRequest), |
|
28 m_securitySettings(NULL) |
|
29 { |
|
30 #ifdef __WINS__ |
|
31 error = KErrNotSupported; |
|
32 return; |
|
33 #endif |
|
34 |
|
35 error = m_etelServer.Connect(); |
|
36 if (error == KErrNone) { |
|
37 error = m_etelServer.LoadPhoneModule(KMmTsyModuleName); |
|
38 } |
|
39 if (error == KErrNone) { |
|
40 RTelServer::TPhoneInfo info; |
|
41 error = m_etelServer.GetPhoneInfo(0, info); |
|
42 if (error == KErrNone) { |
|
43 error = m_etelPhone.Open(m_etelServer, info.iName); |
|
44 } |
|
45 } |
|
46 if (error == KErrNone) { |
|
47 // open specified Etel store |
|
48 if (type == AdnStore) { |
|
49 error = m_etelStore.Open(m_etelPhone, KETelIccAdnPhoneBook); |
|
50 } |
|
51 else if (type == SdnStore) { |
|
52 error = m_etelStore.Open(m_etelPhone, KETelIccSdnPhoneBook); |
|
53 } |
|
54 else if (type == FdnStore) { |
|
55 error = m_etelStore.Open(m_etelPhone, KETelIccFdnPhoneBook); |
|
56 } |
|
57 else { |
|
58 error = KErrNotSupported; |
|
59 } |
|
60 } |
|
61 |
|
62 if (error == KErrNone) { |
|
63 error = m_customPhone.Open(m_etelPhone); |
|
64 } |
|
65 |
|
66 if (error == KErrNone) { |
|
67 TRAP(error, |
|
68 m_asyncWorker = new (ELeave)AsyncWorker(this); |
|
69 TSecUi::InitializeLibL(); |
|
70 m_securitySettings = CSecuritySettings::NewL(); |
|
71 ); |
|
72 } |
|
73 } |
|
74 |
|
75 CntSimUtility::~CntSimUtility() |
|
76 { |
|
77 m_etelStore.Close(); |
|
78 m_etelPhone.Close(); |
|
79 m_etelServer.Close(); |
|
80 |
|
81 delete m_asyncWorker; |
|
82 delete m_securitySettings; |
|
83 TSecUi::UnInitializeLib(); |
|
84 } |
|
85 |
|
86 CntSimUtility::SimInfo CntSimUtility::getSimInfo(int& error) |
|
87 { |
|
88 TRequestStatus requestStatus; |
|
89 m_etelStore.GetInfo(requestStatus, (TDes8&)m_etelStoreInfoPckg); |
|
90 User::WaitForRequest(requestStatus); |
|
91 error = requestStatus.Int(); |
|
92 SimInfo results; |
|
93 |
|
94 if (error == KErrNone) { |
|
95 results.totalEntries = m_etelStoreInfo.iTotalEntries; |
|
96 results.usedEntries = m_etelStoreInfo.iUsedEntries; |
|
97 results.maxNumLength = m_etelStoreInfo.iMaxNumLength; |
|
98 results.maxTextLength = m_etelStoreInfo.iMaxTextLength; |
|
99 results.maxSecondNames = m_etelStoreInfo.iMaxSecondNames; |
|
100 results.maxTextLengthSecondName = m_etelStoreInfo.iMaxTextLengthSecondName; |
|
101 results.maxAdditionalNumbers = m_etelStoreInfo.iMaxAdditionalNumbers; |
|
102 results.maxNumLengthAdditionalNumber = m_etelStoreInfo.iMaxNumLengthAdditionalNumber; |
|
103 results.maxTextLengthAdditionalNumber = m_etelStoreInfo.iMaxTextLengthAdditionalNumber; |
|
104 results.maxGroupNames = m_etelStoreInfo.iMaxGroupNames; |
|
105 results.maxTextLengthGroupName = m_etelStoreInfo.iMaxTextLengthGroupName; |
|
106 results.maxEmailAddr = m_etelStoreInfo.iMaxEmailAddr; |
|
107 results.maxTextLengthEmailAddr = m_etelStoreInfo.iMaxTextLengthEmailAddr; |
|
108 } |
|
109 return results; |
|
110 } |
|
111 |
|
112 CntSimUtility::AvailableStores CntSimUtility::getAvailableStores(int& error) |
|
113 { |
|
114 AvailableStores availableStores; |
|
115 if (!isSimInserted()) { |
|
116 error = KErrNone; |
|
117 return availableStores; |
|
118 } |
|
119 |
|
120 m_serviceTableType = RMobilePhone::ESIMServiceTable; |
|
121 unsigned long int iccCaps; |
|
122 TRequestStatus requestStatus; |
|
123 |
|
124 int result = m_etelPhone.GetIccAccessCaps(iccCaps); |
|
125 if (result == KErrNone && (iccCaps & RMobilePhone::KCapsUSimAccessSupported)) { |
|
126 m_serviceTableType = RMobilePhone::EUSIMServiceTable; |
|
127 } |
|
128 |
|
129 m_etelPhone.GetServiceTable(requestStatus, m_serviceTableType, m_serviceTablePckg); |
|
130 User::WaitForRequest(requestStatus); |
|
131 error = requestStatus.Int(); |
|
132 |
|
133 if (error == KErrNone) { |
|
134 //parse service table to find what stores are supported |
|
135 ParseServiceTable(&availableStores); |
|
136 } |
|
137 return availableStores; |
|
138 } |
|
139 |
|
140 bool CntSimUtility::verifyPin2Code() |
|
141 { |
|
142 bool verified = false; |
|
143 TRAP_IGNORE(verified = m_securitySettings->AskPin2L();); |
|
144 return verified; |
|
145 } |
|
146 |
|
147 bool CntSimUtility::isFdnActive() |
|
148 { |
|
149 RMobilePhone::TMobilePhoneFdnStatus fdnStatus; |
|
150 (void)m_etelPhone.GetFdnStatus(fdnStatus); |
|
151 if (fdnStatus == RMobilePhone::EFdnActive || |
|
152 fdnStatus == RMobilePhone::EFdnPermanentlyActive) { |
|
153 return true; |
|
154 } |
|
155 return false; |
|
156 } |
|
157 |
|
158 int CntSimUtility::setFdnStatus(bool activated) |
|
159 { |
|
160 RMobilePhone::TMobilePhoneFdnSetting fdnStatus = RMobilePhone::EFdnSetOff; |
|
161 if (activated) { |
|
162 fdnStatus = RMobilePhone::EFdnSetOn; |
|
163 } |
|
164 TRequestStatus status; |
|
165 m_etelPhone.SetFdnSetting(status, fdnStatus); |
|
166 User::WaitForRequest(status); |
|
167 return status.Int(); |
|
168 } |
|
169 |
|
170 bool CntSimUtility::startGetSimInfo() |
|
171 { |
|
172 if(m_asyncWorker->IsActive()) { |
|
173 return false; |
|
174 } |
|
175 |
|
176 m_etelStore.GetInfo(m_asyncWorker->iStatus, (TDes8&)m_etelStoreInfoPckg); |
|
177 m_asyncWorker->SetActive(); |
|
178 m_activeRequest = EGetInfo; |
|
179 return true; |
|
180 } |
|
181 |
|
182 bool CntSimUtility::startGetAvailableStores() |
|
183 { |
|
184 if(m_asyncWorker->IsActive()) { |
|
185 return false; |
|
186 } |
|
187 |
|
188 if (!isSimInserted()) { |
|
189 AvailableStores availableStores; |
|
190 emit availableStoresReady(availableStores, KErrNone); |
|
191 return true; |
|
192 } |
|
193 |
|
194 m_serviceTableType = RMobilePhone::ESIMServiceTable; |
|
195 unsigned long int iccCaps; |
|
196 TRequestStatus requestStatus; |
|
197 |
|
198 int result = m_etelPhone.GetIccAccessCaps(iccCaps); |
|
199 if (result == KErrNone && (iccCaps & RMobilePhone::KCapsUSimAccessSupported)) { |
|
200 m_serviceTableType = RMobilePhone::EUSIMServiceTable; |
|
201 } |
|
202 m_etelPhone.GetServiceTable(m_asyncWorker->iStatus, m_serviceTableType, m_serviceTablePckg); |
|
203 m_asyncWorker->SetActive(); |
|
204 m_activeRequest = EGetAvailableStores; |
|
205 return true; |
|
206 } |
|
207 |
|
208 bool CntSimUtility::notifyAdnCacheStatus() |
|
209 { |
|
210 if(m_asyncWorker->IsActive()) { |
|
211 return false; |
|
212 } |
|
213 CacheStatus cacheStatus; |
|
214 |
|
215 //check current cache status |
|
216 TRequestStatus requestStatus; |
|
217 RMmCustomAPI::TPndCacheStatus pndStatus; |
|
218 TName storeName; |
|
219 storeName.Copy(KETelIccAdnPhoneBook); |
|
220 m_customPhone.GetPndCacheStatus(requestStatus, pndStatus, storeName); |
|
221 User::WaitForRequest(requestStatus); |
|
222 if (requestStatus.Int() != KErrNone) { |
|
223 return false; |
|
224 } |
|
225 |
|
226 if (pndStatus == RMmCustomAPI::ECacheReady || |
|
227 pndStatus == RMmCustomAPI::ECacheNotUsed) { |
|
228 cacheStatus = ECacheReady; |
|
229 emit adnCacheStatusReady(cacheStatus, KErrNone); |
|
230 return true; |
|
231 } |
|
232 else if (pndStatus == RMmCustomAPI::ECacheFailed) { |
|
233 cacheStatus = ECacheFailed; |
|
234 emit adnCacheStatusReady(cacheStatus, KErrNone); |
|
235 return true; |
|
236 } |
|
237 else if (pndStatus == RMmCustomAPI::ECacheNotReady) { |
|
238 //wait for cache notification |
|
239 m_customPhone.NotifyPndCacheReady(m_asyncWorker->iStatus, m_etelStoreNameCached); |
|
240 m_asyncWorker->SetActive(); |
|
241 m_activeRequest = EGetCacheStatus; |
|
242 return true; |
|
243 } |
|
244 else { |
|
245 return false; |
|
246 } |
|
247 } |
|
248 |
|
249 void CntSimUtility::RequestCompleted(int error) |
|
250 { |
|
251 if (m_activeRequest == EGetInfo) { |
|
252 SimInfo results; |
|
253 if (error == KErrNone) { |
|
254 results.totalEntries = m_etelStoreInfo.iTotalEntries; |
|
255 results.usedEntries = m_etelStoreInfo.iUsedEntries; |
|
256 results.maxNumLength = m_etelStoreInfo.iMaxNumLength; |
|
257 results.maxTextLength = m_etelStoreInfo.iMaxTextLength; |
|
258 results.maxSecondNames = m_etelStoreInfo.iMaxSecondNames; |
|
259 results.maxTextLengthSecondName = m_etelStoreInfo.iMaxTextLengthSecondName; |
|
260 results.maxAdditionalNumbers = m_etelStoreInfo.iMaxAdditionalNumbers; |
|
261 results.maxNumLengthAdditionalNumber = m_etelStoreInfo.iMaxNumLengthAdditionalNumber; |
|
262 results.maxTextLengthAdditionalNumber = m_etelStoreInfo.iMaxTextLengthAdditionalNumber; |
|
263 results.maxGroupNames = m_etelStoreInfo.iMaxGroupNames; |
|
264 results.maxTextLengthGroupName = m_etelStoreInfo.iMaxTextLengthGroupName; |
|
265 results.maxEmailAddr = m_etelStoreInfo.iMaxEmailAddr; |
|
266 results.maxTextLengthEmailAddr = m_etelStoreInfo.iMaxTextLengthEmailAddr; |
|
267 } |
|
268 emit simInfoReady(results, error); |
|
269 }//EGetInfo |
|
270 else if (m_activeRequest == EGetAvailableStores) { |
|
271 AvailableStores availableStores; |
|
272 if (error == KErrNone) { |
|
273 //parse service table to find what stores are supported |
|
274 ParseServiceTable(&availableStores); |
|
275 } |
|
276 emit availableStoresReady(availableStores, error); |
|
277 }//EGetAvailableStores |
|
278 else if (m_activeRequest == EGetCacheStatus) { |
|
279 if ( m_etelStoreNameCached.Compare(KETelIccAdnPhoneBook) == 0) { |
|
280 //ADN cache is ready |
|
281 CacheStatus cacheStatus; |
|
282 if (error != KErrNone) { |
|
283 cacheStatus = ECacheFailed; |
|
284 emit adnCacheStatusReady(cacheStatus, error); |
|
285 } |
|
286 else { |
|
287 cacheStatus = ECacheReady; |
|
288 emit adnCacheStatusReady(cacheStatus, error); |
|
289 } |
|
290 } |
|
291 else { |
|
292 //another store is cached, continue listening for ADN cache |
|
293 notifyAdnCacheStatus(); |
|
294 } |
|
295 }//EGetCacheStatus |
|
296 |
|
297 if (!m_asyncWorker->IsActive()) { |
|
298 m_activeRequest = ENoActiveRequest; |
|
299 } |
|
300 } |
|
301 |
|
302 void CntSimUtility::ParseServiceTable(AvailableStores* availableStores) const |
|
303 { |
|
304 availableStores->SimPresent = true; |
|
305 if (m_serviceTableType == RMobilePhone::EUSIMServiceTable) { |
|
306 //ADN store is always present if SIM card is inserted |
|
307 availableStores->AdnStorePresent = true; |
|
308 |
|
309 if (m_serviceTable.iServices1To8 & RMobilePhone::KUstSDN ) { |
|
310 availableStores->SdnStorePresent = true; |
|
311 } |
|
312 else { |
|
313 availableStores->SdnStorePresent = false; |
|
314 } |
|
315 |
|
316 if (m_serviceTable.iServices1To8 & RMobilePhone::KUstFDN) { |
|
317 availableStores->FdnStorePresent = true; |
|
318 } |
|
319 else { |
|
320 availableStores->FdnStorePresent = false; |
|
321 } |
|
322 } |
|
323 else if (m_serviceTableType == RMobilePhone::ESIMServiceTable) { |
|
324 //ADN store is always present if SIM card is inserted |
|
325 availableStores->AdnStorePresent = true; |
|
326 |
|
327 if (m_serviceTable.iServices17To24 & RMobilePhone::KSstSDN) { |
|
328 availableStores->SdnStorePresent = true; |
|
329 } |
|
330 else { |
|
331 availableStores->SdnStorePresent = false; |
|
332 } |
|
333 |
|
334 if (m_serviceTable.iServices1To8 & RMobilePhone::KSstFDN) { |
|
335 availableStores->FdnStorePresent = true; |
|
336 } |
|
337 else { |
|
338 availableStores->FdnStorePresent = false; |
|
339 } |
|
340 } |
|
341 } |
|
342 |
|
343 bool CntSimUtility::isSimInserted() const |
|
344 { |
|
345 bool result = false; |
|
346 |
|
347 RProperty property; |
|
348 int simStatus = KErrNotFound; |
|
349 |
|
350 int ret = property.Get(KPSUidStartup, KPSSimStatus, simStatus); |
|
351 if (simStatus == ESimUsable && ret == KErrNone) { |
|
352 result = true; |
|
353 } |
|
354 |
|
355 property.Close(); |
|
356 return result; |
|
357 } |