|
1 /* |
|
2 * Copyright (c) 2008-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: Implements base class for notifier implementations |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <eikenv.h> |
|
20 #include <bautils.h> |
|
21 #include <featmgr.h> |
|
22 #include <spentry.h> |
|
23 #include <spsettings.h> |
|
24 #include <spproperty.h> |
|
25 #include <cchuinotif.rsg> |
|
26 #include <StringLoader.h> |
|
27 #include <aknnotewrappers.h> |
|
28 #include <centralrepository.h> |
|
29 #include <cenrepnotifyhandler.h> |
|
30 #include <CoreApplicationUIsSDKCRKeys.h> // KCRUidCoreApplicationUIs, |
|
31 // KCoreAppUIsNetworkConnectionAllowed |
|
32 #include "cchuilogger.h" |
|
33 #include "cchuinotifier.h" |
|
34 #include "cchuinotifconnectionhandler.h" |
|
35 |
|
36 _LIT( KResourceDir, "\\resource\\apps\\" ); |
|
37 _LIT( KResourceFileName, "cchuinotif.r??" ); |
|
38 |
|
39 // SCP-plugin uid for Sip VoIP |
|
40 const TInt32 KSipVoIPSubServicePlugId = 0x1027545A; |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 CCCHUiNotifierBase::CCCHUiNotifierBase(): CActive(EPriorityStandard) |
|
45 { |
|
46 CActiveScheduler::Add(this); |
|
47 } |
|
48 |
|
49 void CCCHUiNotifierBase::ConstructL() |
|
50 { |
|
51 CCHUIDEBUG( "CCCHUiNotifierBase::ConstructL - IN" ); |
|
52 |
|
53 iEikEnv = CEikonEnv::Static(); |
|
54 |
|
55 // load the resource file |
|
56 CCHUIDEBUG( "ConstructL - load resource"); |
|
57 |
|
58 HBufC* resourceFile = ScanFileL( iEikEnv->FsSession(), |
|
59 TFileName( KResourceFileName ), TFileName( KResourceDir ) ); |
|
60 |
|
61 if ( resourceFile ) |
|
62 { |
|
63 CCHUIDEBUG( "ConstructL - resource ready, adding"); |
|
64 |
|
65 CleanupStack::PushL( resourceFile ); |
|
66 iResourceFileFlag = iEikEnv->AddResourceFileL( |
|
67 *resourceFile ); |
|
68 CleanupStack::PopAndDestroy( resourceFile ); |
|
69 |
|
70 CCHUIDEBUG( "ConstructL - resource added"); |
|
71 } |
|
72 |
|
73 iSettings = CSPSettings::NewL(); |
|
74 |
|
75 CCHUIDEBUG( "CCCHUiNotifierBase::ConstructL - OUT" ); |
|
76 } |
|
77 |
|
78 CCCHUiNotifierBase::~CCCHUiNotifierBase() |
|
79 { |
|
80 CCHUIDEBUG( "CCCHUiNotifierBase::~CCCHUiNotifierBase - IN" ); |
|
81 Cancel(); |
|
82 |
|
83 delete iSettings; |
|
84 CompleteMessage( KErrDied ); |
|
85 iEikEnv->DeleteResourceFile( iResourceFileFlag ); |
|
86 |
|
87 CCHUIDEBUG( "CCCHUiNotifierBase::~CCCHUiNotifierBase - OUT" ); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CompleteMessage. |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CCCHUiNotifierBase::CompleteMessage( TInt aErr ) |
|
95 { |
|
96 CCHUIDEBUG2( "CCCHUiNotifierBase::CompleteMessage - err: %d", aErr ); |
|
97 |
|
98 if( !iMessage.IsNull() ) |
|
99 { |
|
100 CCHUIDEBUG( "CompleteMessage - do complete"); |
|
101 iMessage.Complete( aErr ); |
|
102 } |
|
103 |
|
104 iReplySlot = NULL; |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // From class MEikSrvNotifierBase2. |
|
109 // Cancelling method. |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CCCHUiNotifierBase::Cancel() |
|
113 { |
|
114 CCHUIDEBUG( "CCCHUiNotifierBase::Cancel - IN" ); |
|
115 |
|
116 // Complete with KErrCancel |
|
117 CompleteMessage(KErrCancel); |
|
118 CActive::Cancel(); |
|
119 |
|
120 CCHUIDEBUG( "CCCHUiNotifierBase::Cancel - OUT" ); |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // RunL |
|
125 // From CActive. |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 void CCCHUiNotifierBase::RunL( ) |
|
129 { |
|
130 CCHUIDEBUG( "CCCHUiNotifierBase::RunL" ); |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // From class MEikSrvNotifierBase2. |
|
135 // Release itself. Call to destructor. |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void CCCHUiNotifierBase::Release() |
|
139 { |
|
140 CCHUIDEBUG( "CCCHUiNotifierBase::Release"); |
|
141 delete this; |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // From class MEikSrvNotifierBase2. |
|
146 // Return registered information. |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 CCCHUiNotifierBase::TNotifierInfo CCCHUiNotifierBase::Info() const |
|
150 { |
|
151 CCHUIDEBUG( "CCCHUiNotifierBase::Info"); |
|
152 return iInfo; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // From class MEikSrvNotifierBase2. |
|
157 // Synchronic notifier launch. Does nothing here. |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 TPtrC8 CCCHUiNotifierBase::StartL( const TDesC8& /*aBuffer*/ ) |
|
161 { |
|
162 CCHUIDEBUG( "CCCHUiNotifierBase::StartL"); |
|
163 TPtrC8 ret( KNullDesC8 ); |
|
164 return ret; |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // From class MEikSrvNotifierBase2. |
|
169 // Asynchronic notifier launch. |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CCCHUiNotifierBase::StartL( |
|
173 const TDesC8& aBuffer, |
|
174 TInt aReplySlot, |
|
175 const RMessagePtr2& aMessage ) |
|
176 { |
|
177 CCHUIDEBUG( "CCCHUiNotifierBase::StartL2 - IN"); |
|
178 iMessage = aMessage; |
|
179 iReplySlot = aReplySlot; |
|
180 |
|
181 SetActive(); |
|
182 |
|
183 iStatus = KRequestPending; |
|
184 TRequestStatus* stat = &iStatus; |
|
185 User::RequestComplete(stat, KErrNone); |
|
186 |
|
187 CCHUIDEBUG( "CCCHUiNotifierBase::StartL2 - OUT"); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // From class MEikSrvNotifierBase2. |
|
192 // Notifier update. Not supported. |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 TPtrC8 CCCHUiNotifierBase::UpdateL( const TDesC8& /*aBuffer*/ ) |
|
196 { |
|
197 CCHUIDEBUG( "CCCHUiNotifierBase::UpdateL"); |
|
198 TPtrC8 ret( KNullDesC8 ); |
|
199 return ret; |
|
200 } |
|
201 |
|
202 // ---------------------------------------------------------- |
|
203 // CCCHUiNotifierBase::DoCancel |
|
204 // This method will be called by framework (CActive) |
|
205 // if active object is still active. |
|
206 // Does nothing here. |
|
207 // ---------------------------------------------------------- |
|
208 // |
|
209 void CCCHUiNotifierBase::DoCancel() |
|
210 { |
|
211 CCHUIDEBUG( "CCCHUiNotifierBase::DoCancel - IN"); |
|
212 |
|
213 // Complete request when active object is still active |
|
214 TRequestStatus* stat = &iStatus; |
|
215 if (iStatus != KErrCancel) |
|
216 { |
|
217 User::RequestComplete(stat, KErrNone); |
|
218 } |
|
219 |
|
220 CCHUIDEBUG( "CCCHUiNotifierBase::DoCancel - OUT"); |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // Scan resource file. |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 HBufC* CCCHUiNotifierBase::ScanFileL( |
|
228 RFs& aSession, |
|
229 const TDesC& aFileName, |
|
230 const TDesC& aFilePath ) |
|
231 { |
|
232 CCHUIDEBUG( "CCCHUiNotifierBase::ScanFileL"); |
|
233 |
|
234 TFindFile search( aSession ); |
|
235 CDir* dirlist; |
|
236 HBufC* fullName = NULL; |
|
237 TFileName filename( aFileName ); |
|
238 TInt err = search.FindWildByDir( filename, aFilePath, dirlist ); |
|
239 |
|
240 CCHUIDEBUG2( "ScanFileL - FindWildByDir err: %d", err ); |
|
241 |
|
242 if ( err == KErrNone ) |
|
243 { |
|
244 CCHUIDEBUG2( "ScanFileL - dir list count: %d", dirlist->Count() ); |
|
245 |
|
246 if ( 0 < dirlist->Count() ) |
|
247 { |
|
248 CCHUIDEBUG( "ScanFileL - Parsing full entry" ); |
|
249 |
|
250 TParse fullentry; |
|
251 fullentry.Set( (*dirlist)[0].iName, &search.File(), NULL ); |
|
252 TFileName nearestFile( fullentry.FullName() ); |
|
253 BaflUtils::NearestLanguageFile( aSession, nearestFile ); |
|
254 fullName = HBufC::NewL( nearestFile.Length() ); |
|
255 fullName->Des().Copy( nearestFile ); |
|
256 } |
|
257 delete dirlist; |
|
258 |
|
259 CCHUIDEBUG2( "ScanFileL - full name: %S", fullName ); |
|
260 } |
|
261 |
|
262 return fullName; |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------------------------- |
|
266 // Resolves service name. |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 void CCCHUiNotifierBase::GetServiceNameL( |
|
270 TUint aServiceId, TDes& aServiceName ) |
|
271 { |
|
272 CCHUIDEBUG( "CCCHUiNotifierBase::GetServiceNameL" ); |
|
273 CSPEntry* entry = CSPEntry::NewLC(); |
|
274 TRAPD( err, iSettings->FindEntryL( aServiceId, *entry ) ); |
|
275 if ( !err ) |
|
276 { |
|
277 aServiceName = entry->GetServiceName(); |
|
278 } |
|
279 CleanupStack::PopAndDestroy( entry ); |
|
280 CCHUIDEBUG( "CCCHUiNotifierBase::GetServiceNameL OUT" ); |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // Resolves current connection name. |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 void CCCHUiNotifierBase::CurrentConnectionNameL( |
|
288 TUint aServiceId, TUint aIapId, RBuf& aIapName ) |
|
289 { |
|
290 CCHUIDEBUG( "CCCHUiNotifierBase::CurrentConnectionNameL - IN" ); |
|
291 |
|
292 CCchUiNotifConnectionHandler* connHandler = |
|
293 CCchUiNotifConnectionHandler::NewLC(); |
|
294 |
|
295 RBuf serviceName; |
|
296 CleanupClosePushL( serviceName ); |
|
297 serviceName.CreateL( KServiceNameLength ); |
|
298 GetServiceNameL( aServiceId, serviceName ); |
|
299 |
|
300 // get connection name |
|
301 connHandler->ConnectionNameL( aIapId, serviceName, aIapName ); |
|
302 |
|
303 CleanupStack::PopAndDestroy( &serviceName ); |
|
304 CleanupStack::PopAndDestroy( connHandler ); |
|
305 |
|
306 CCHUIDEBUG( "CCCHUiNotifierBase::CurrentConnectionNameL - OUT" ); |
|
307 } |
|
308 |
|
309 // --------------------------------------------------------------------------- |
|
310 // Resolves if service is SIP/VoIP. |
|
311 // --------------------------------------------------------------------------- |
|
312 // |
|
313 TBool CCCHUiNotifierBase::IsSIPVoIPL( TUint aServiceId ) |
|
314 { |
|
315 CCHUIDEBUG( "CCCHUiNotifierBase::IsSIPVoIPL" ); |
|
316 |
|
317 TInt uid( 0 ); |
|
318 TBool sipVoIP( EFalse ); |
|
319 |
|
320 CSPProperty* property = CSPProperty::NewLC(); |
|
321 |
|
322 User::LeaveIfError( iSettings->FindPropertyL( |
|
323 aServiceId, EPropertyVoIPSubServicePluginId , *property ) ); |
|
324 |
|
325 User::LeaveIfError( property->GetValue( uid ) ); |
|
326 |
|
327 if ( KSipVoIPSubServicePlugId == uid ) |
|
328 { |
|
329 sipVoIP = ETrue; |
|
330 } |
|
331 |
|
332 CleanupStack::PopAndDestroy( property ); |
|
333 |
|
334 CCHUIDEBUG2( "CCCHUiNotifierBase::IsSIPVoIPL: %d", sipVoIP ); |
|
335 |
|
336 return sipVoIP; |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // Checks if phone is in offline mode. |
|
341 // ----------------------------------------------------------------------------- |
|
342 // |
|
343 TBool CCCHUiNotifierBase::IsPhoneOfflineL() const |
|
344 { |
|
345 CCHUIDEBUG( "CCCHUiNotifierBase::IsPhoneOfflineL" ); |
|
346 |
|
347 if ( FeatureManager::FeatureSupported( KFeatureIdOfflineMode ) ) |
|
348 { |
|
349 CRepository* repository = CRepository::NewLC(KCRUidCoreApplicationUIs); |
|
350 TInt connAllowed = ECoreAppUIsNetworkConnectionAllowed; |
|
351 repository->Get( KCoreAppUIsNetworkConnectionAllowed, connAllowed ); |
|
352 CleanupStack::PopAndDestroy( repository ); |
|
353 if ( !connAllowed ) |
|
354 { |
|
355 CCHUIDEBUG( "IsPhoneOfflineL - phone is in offline" ); |
|
356 return ETrue; |
|
357 } |
|
358 } |
|
359 |
|
360 CCHUIDEBUG( "IsPhoneOfflineL - phone is not in offline" ); |
|
361 return EFalse; |
|
362 } |
|
363 |
|
364 // ----------------------------------------------------------------------------- |
|
365 // Checks if there are GPRS IAPs available in Internet SNAP. |
|
366 // ----------------------------------------------------------------------------- |
|
367 // |
|
368 TBool CCCHUiNotifierBase::IsGprsIapsAvailableL() const |
|
369 { |
|
370 CCHUIDEBUG( "CCCHUiNotifierBase::IsGprsIapsAvailableL" ); |
|
371 |
|
372 TBool available( EFalse ); |
|
373 |
|
374 CCchUiNotifConnectionHandler* connHandler = |
|
375 CCchUiNotifConnectionHandler::NewLC(); |
|
376 |
|
377 RArray<TUint32> gprsIapIds; |
|
378 CleanupClosePushL( gprsIapIds ); |
|
379 |
|
380 // Array for iap names. No use here, we need just iap count. |
|
381 CDesCArray* iapNames = new (ELeave) CDesCArrayFlat( 3 ); |
|
382 CleanupStack::PushL( iapNames ); |
|
383 |
|
384 TRAPD( err, connHandler->GetGprsAccessPointsL( *iapNames, gprsIapIds ) ); |
|
385 |
|
386 if ( gprsIapIds.Count() && !err ) |
|
387 { |
|
388 CCHUIDEBUG( "IsGprsIapsAvailableL - gprs iaps available" ); |
|
389 available = ETrue; |
|
390 } |
|
391 |
|
392 CleanupStack::PopAndDestroy( iapNames ); |
|
393 CleanupStack::PopAndDestroy( &gprsIapIds ); |
|
394 CleanupStack::PopAndDestroy( connHandler ); |
|
395 |
|
396 CCHUIDEBUG( "IsGprsIapsAvailableL gprs iaps not available" ); |
|
397 return available; |
|
398 } |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // Checks if connection is used by other services. |
|
402 // ----------------------------------------------------------------------------- |
|
403 // |
|
404 TBool CCCHUiNotifierBase::ConnectionUsedByOthersL( |
|
405 TUint aServiceId, TInt aIapId ) |
|
406 { |
|
407 CCHUIDEBUG( "CCCHUiNotifierBase::ConnectionUsedByOthersL" ); |
|
408 |
|
409 TBool usedByOthers( EFalse ); |
|
410 |
|
411 RArray<TUint32> destIds; |
|
412 CleanupClosePushL( destIds ); |
|
413 |
|
414 CCchUiNotifConnectionHandler* connHandler = |
|
415 CCchUiNotifConnectionHandler::NewLC(); |
|
416 |
|
417 RBuf serviceName; |
|
418 CleanupClosePushL( serviceName ); |
|
419 serviceName.CreateL( KServiceNameLength ); |
|
420 GetServiceNameL( aServiceId, serviceName ); |
|
421 |
|
422 CCHUIDEBUG( "ConnectionUsedByOthersL - get destinations" ); |
|
423 |
|
424 // Get all but our services destinations. |
|
425 connHandler->GetDestinationsL( serviceName, destIds ); |
|
426 |
|
427 CleanupStack::PopAndDestroy( &serviceName ); |
|
428 |
|
429 for ( TInt i( 0 ) ; i < destIds.Count() ; i++ ) |
|
430 { |
|
431 RArray<TUint32> iapIds; |
|
432 CleanupClosePushL( iapIds ); |
|
433 |
|
434 connHandler->GetAccessPointsFromSnapL( iapIds, destIds[ i ] ); |
|
435 |
|
436 TInt index = iapIds.Find( aIapId ); |
|
437 |
|
438 if ( KErrNotFound != index ) |
|
439 { |
|
440 CCHUIDEBUG( |
|
441 "ConnectionUsedByOthersL - iap is used by other service(s)" ); |
|
442 |
|
443 usedByOthers = ETrue; |
|
444 } |
|
445 |
|
446 CleanupStack::PopAndDestroy( &iapIds ); |
|
447 } |
|
448 |
|
449 CleanupStack::PopAndDestroy( connHandler ); |
|
450 CleanupStack::PopAndDestroy( &destIds ); |
|
451 |
|
452 return usedByOthers; |
|
453 } |
|
454 |