|
1 /* |
|
2 * Copyright (c) 2004-2008 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: Implementation of the CPhoneApplicationExit class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cphoneapplicationexit.h" |
|
22 #include "cphonecenrepproxy.h" |
|
23 #include "cphoneviewcontroller.h" |
|
24 #include "telephonyvariant.hrh" |
|
25 #include "telprivatecrkeys.h" |
|
26 #include "phonelogger.h" |
|
27 |
|
28 #include <w32std.h> |
|
29 #include <e32hal.h> |
|
30 #include <apgwgnam.h> |
|
31 #include <apgtask.h> |
|
32 #include <apgcli.h> |
|
33 #include <avkon.hrh> |
|
34 #include <telephonyvariant.hrh> |
|
35 #include <gfxtranseffect/gfxtranseffect.h> |
|
36 #include <akntranseffect.h> |
|
37 |
|
38 // CONSTANTS |
|
39 |
|
40 // MODULE DATA STRUCTURES |
|
41 |
|
42 /** |
|
43 * Abstract base class to handle rules when certain application should be |
|
44 * closed. |
|
45 * @since 2.6 |
|
46 */ |
|
47 class CPhoneApplicationExit::CElement : public CBase |
|
48 { |
|
49 public: // New functions |
|
50 |
|
51 /** |
|
52 * Checks if this application should be accepted to be closed. |
|
53 * @param aUid uid of the application. |
|
54 * @return ETrue if should be closed, otherwise EFalse. |
|
55 */ |
|
56 virtual TBool AcceptL( const TUid& aUid ) const = 0; |
|
57 }; |
|
58 |
|
59 /** |
|
60 * Element to handle any application and low memory cases. |
|
61 * @since 2.6 |
|
62 */ |
|
63 class CPhoneApplicationExit::CElementBasic : |
|
64 public CPhoneApplicationExit::CElement |
|
65 { |
|
66 public: // Constructors |
|
67 |
|
68 /** |
|
69 * Enumerates types. |
|
70 */ |
|
71 enum TTypeOfElement |
|
72 { |
|
73 // Any application. |
|
74 EExitAnyApp, |
|
75 // Only when low memory. |
|
76 EExitWhenLowMemory |
|
77 }; |
|
78 |
|
79 /** |
|
80 * Constructor. |
|
81 * @param aType type of element. |
|
82 */ |
|
83 CElementBasic( TTypeOfElement aType ); |
|
84 |
|
85 public: // New functions |
|
86 |
|
87 /** |
|
88 * Checks if system is low in memory. |
|
89 * @return ETrue if system is low in memory. |
|
90 */ |
|
91 static TBool IsLowMemory(); |
|
92 |
|
93 public: // Functions from base classes |
|
94 |
|
95 /** |
|
96 * @see CPhoneApplicationExit::CElement::AcceptL. |
|
97 */ |
|
98 virtual TBool AcceptL( const TUid& aUid ) const; |
|
99 |
|
100 private: |
|
101 |
|
102 // Type of element. |
|
103 TTypeOfElement iType; |
|
104 |
|
105 }; |
|
106 |
|
107 /** |
|
108 * Element to handle applications UID of which are included in UID range. |
|
109 * @since 2.6 |
|
110 */ |
|
111 class CPhoneApplicationExit::CElementUid : |
|
112 public CPhoneApplicationExit::CElement |
|
113 { |
|
114 public: // Constructors |
|
115 |
|
116 /** |
|
117 * Constructor. |
|
118 * @param aStart start of range. |
|
119 * @param aEnd end of range. |
|
120 */ |
|
121 CElementUid( const TUid& aStart, const TUid& aEnd ); |
|
122 |
|
123 public: // Functions from base classes |
|
124 |
|
125 /** |
|
126 * @see CPhoneApplicationExit::CElement::AcceptL. |
|
127 */ |
|
128 virtual TBool AcceptL( const TUid& aUid ) const; |
|
129 |
|
130 private: |
|
131 |
|
132 // Start of the range. |
|
133 TUid iStart; |
|
134 |
|
135 // End of the range. |
|
136 TUid iEnd; |
|
137 |
|
138 }; |
|
139 |
|
140 /** |
|
141 * Element to handle applications on specific drive. |
|
142 * @since 2.6 |
|
143 */ |
|
144 class CPhoneApplicationExit::CElementDrive : |
|
145 public CPhoneApplicationExit::CElement |
|
146 { |
|
147 public: // Constructors |
|
148 |
|
149 /** |
|
150 * Constructor. |
|
151 * @param aDrive drive. |
|
152 */ |
|
153 CElementDrive( const TChar& aDrive ); |
|
154 |
|
155 public: // Functions from base classes |
|
156 |
|
157 /** |
|
158 * @see CPhoneApplicationExit::CElement::AcceptL. |
|
159 */ |
|
160 virtual TBool AcceptL( const TUid& aUid ) const; |
|
161 |
|
162 private: |
|
163 |
|
164 /** |
|
165 * Checks if application has been installed on specified drive. |
|
166 * @param aUid application UID. |
|
167 * @return ETrue if application has been installed on specified drive. |
|
168 */ |
|
169 TBool CheckApplicationDriveL( |
|
170 const TUid& aUid ) const; |
|
171 |
|
172 private: |
|
173 |
|
174 // Drive. |
|
175 TChar iDrive; |
|
176 |
|
177 }; |
|
178 |
|
179 // ============================ MEMBER FUNCTIONS =============================== |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CPhoneApplicationExit::CPhoneApplicationExit |
|
183 // C++ default constructor can NOT contain any code, that |
|
184 // might leave. |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 CPhoneApplicationExit::CPhoneApplicationExit( |
|
188 CPhoneViewController* aViewController, |
|
189 RWsSession& aWsSession, |
|
190 const TInt aUikonWgId ) : |
|
191 iViewController( aViewController ), |
|
192 iWsSession( aWsSession ), |
|
193 iUikonWgId( aUikonWgId ) |
|
194 { |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CPhoneApplicationExit::NewL |
|
199 // Two-phased constructor. |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 CPhoneApplicationExit* CPhoneApplicationExit::NewL( |
|
203 CPhoneViewController* aViewController, |
|
204 RWsSession& aWsSession, |
|
205 const TInt aUikonWgId ) |
|
206 { |
|
207 CPhoneApplicationExit* self = |
|
208 new ( ELeave ) CPhoneApplicationExit( |
|
209 aViewController, |
|
210 aWsSession, |
|
211 aUikonWgId ); |
|
212 |
|
213 return self; |
|
214 } |
|
215 |
|
216 // Destructor |
|
217 CPhoneApplicationExit::~CPhoneApplicationExit() |
|
218 { |
|
219 iCloseList.ResetAndDestroy(); |
|
220 iCloseList.Close(); |
|
221 |
|
222 iDontCloseList.ResetAndDestroy(); |
|
223 iDontCloseList.Close(); |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CPhoneApplicationExit::ExitApplication |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 TInt CPhoneApplicationExit::ExitApplication() |
|
231 { |
|
232 TRAPD( err, ExitApplicationL() ); |
|
233 #ifdef __PHENG_DEBUG_INFO__ |
|
234 if ( err != KErrNone ) |
|
235 { |
|
236 __PHONELOG1( EBasic, EPhoneUIView, "CPhoneApplicationExit::ExitApplication err=%d", err ); |
|
237 } |
|
238 #endif |
|
239 return err; |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CPhoneApplicationExit::ExitApplicationL |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CPhoneApplicationExit::ExitApplicationL() |
|
247 { |
|
248 __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneApplicationExit::ExitApplicationL()" ); |
|
249 TInt foregroundWindowGroupId = iWsSession.GetFocusWindowGroup(); |
|
250 if ( foregroundWindowGroupId == iUikonWgId ) |
|
251 { |
|
252 foregroundWindowGroupId = |
|
253 iViewController->ForegroundApplicationWindowGroupId(); |
|
254 } |
|
255 if ( foregroundWindowGroupId == |
|
256 iViewController->ApplicationWindowGroupId() ) |
|
257 { |
|
258 // No need to send event to itself. |
|
259 __PHONELOG( EBasic, EPhoneUIView, "CPhoneApplicationExit::ExitApplicationL Phone is foreground application so don't close it" ); |
|
260 if ( IsApplicationClosingEnabled() ) |
|
261 { |
|
262 ReadListsL(); |
|
263 } |
|
264 return; |
|
265 } |
|
266 __PHONELOG1( EBasic, EPhoneUIView, "CPhoneApplicationExit::ExitApplicationL foregroundWindowGroupId=%d", foregroundWindowGroupId ); |
|
267 |
|
268 CApaWindowGroupName* wgName = |
|
269 CApaWindowGroupName::NewLC( |
|
270 iWsSession, |
|
271 foregroundWindowGroupId ); |
|
272 |
|
273 if ( IsApplicationClosingEnabled() ) |
|
274 { |
|
275 __PHONELOG1( EBasic, EPhoneUIView, "CPhoneApplicationExit::ExitApplicationL Application closing is enabled wgName->AppUid().iUid=%d", wgName->AppUid().iUid ); |
|
276 |
|
277 if ( CheckApplicationClosingL( wgName->AppUid() ) ) |
|
278 { |
|
279 // Transition effects end key handling |
|
280 // This call makes it possible to show application exit effect |
|
281 // whenever exiting application with the end key |
|
282 GfxTransEffect::BeginFullScreen( |
|
283 AknTransEffect::EApplicationExit, |
|
284 TRect(), |
|
285 AknTransEffect::EParameterType, |
|
286 AknTransEffect::GfxTransParam( wgName->AppUid(), |
|
287 AknTransEffect::TParameter::EActivateExplicitCancel | |
|
288 AknTransEffect::TParameter::EEndCheck ) ); |
|
289 |
|
290 __PHONELOG( EBasic, EPhoneUIView, "CPhoneApplicationExit::ExitApplicationL Send exit event" ); |
|
291 TWsEvent event; |
|
292 event.SetType( KAknUidValueEndKeyCloseEvent ); |
|
293 event.SetTimeNow(); |
|
294 |
|
295 iWsSession.SendEventToWindowGroup( |
|
296 foregroundWindowGroupId, |
|
297 event ); |
|
298 } |
|
299 } |
|
300 else |
|
301 { |
|
302 __PHONELOG( EBasic, EPhoneUIView, "CPhoneApplicationExit::ExitApplicationL Application closing is NOT enabled" ); |
|
303 |
|
304 // If the application is not system and system has low memory, then |
|
305 // stop the application. |
|
306 if ( !wgName->IsSystem() && CElementBasic::IsLowMemory() ) |
|
307 { |
|
308 __PHONELOG( EBasic, EPhoneUIView, "CPhoneApplicationExit::ExitApplicationL Close non-system app because of low memory" ); |
|
309 // Close application |
|
310 TApaTask task( iWsSession ); |
|
311 task.SetWgId( foregroundWindowGroupId ); |
|
312 task.EndTask(); |
|
313 } |
|
314 } |
|
315 |
|
316 CleanupStack::PopAndDestroy( wgName ); |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CPhoneApplicationExit::CheckApplicationClosingL |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 TBool CPhoneApplicationExit::CheckApplicationClosingL( |
|
324 const TUid& aUid ) |
|
325 { |
|
326 ReadListsL(); |
|
327 |
|
328 return |
|
329 IsIncludedToCloseListL( aUid ) && !IsIncludedToDontCloseListL( aUid ); |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CPhoneApplicationExit::IsIncludedToCloseListL |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 TBool CPhoneApplicationExit::IsIncludedToCloseListL( |
|
337 const TUid& aUid ) const |
|
338 { |
|
339 __PHONELOG( EBasic, EPhoneUIView, "CPhoneApplicationExit::IsIncludedToCloseList()" ); |
|
340 |
|
341 TBool result = |
|
342 CheckListL( |
|
343 iCloseList, |
|
344 aUid ); |
|
345 |
|
346 __PHONELOG1( EBasic, EPhoneUIView, "CPhoneApplicationExit::IsIncludedToCloseList() result=%d", result ); |
|
347 |
|
348 return result; |
|
349 } |
|
350 |
|
351 // ----------------------------------------------------------------------------- |
|
352 // CPhoneApplicationExit::IsIncludedToDontCloseListL |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 TBool CPhoneApplicationExit::IsIncludedToDontCloseListL( |
|
356 const TUid& aUid ) const |
|
357 { |
|
358 __PHONELOG( EBasic, EPhoneUIView, "CPhoneApplicationExit::IsIncludedToDontCloseList()" ); |
|
359 |
|
360 TBool result = |
|
361 CheckListL( |
|
362 iDontCloseList, |
|
363 aUid ); |
|
364 |
|
365 __PHONELOG1( EBasic, EPhoneUIView, "CPhoneApplicationExit::IsIncludedToDontCloseList() result=%d", result ); |
|
366 |
|
367 return result; |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // CPhoneApplicationExit::CheckListL |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 TBool CPhoneApplicationExit::CheckListL( |
|
375 const RPointerArray< CElement >& aTarget, |
|
376 const TUid& aUid ) const |
|
377 { |
|
378 TBool result = EFalse; |
|
379 |
|
380 const TInt count = aTarget.Count(); |
|
381 |
|
382 for ( TInt i = 0; i < count && !result; i++ ) |
|
383 { |
|
384 result = aTarget[ i ]->AcceptL( aUid ); |
|
385 } |
|
386 |
|
387 return result; |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CPhoneApplicationExit::ReadListsL |
|
392 // ----------------------------------------------------------------------------- |
|
393 // |
|
394 void CPhoneApplicationExit::ReadListsL() |
|
395 { |
|
396 if ( !iListsRead ) |
|
397 { |
|
398 iCloseList.ResetAndDestroy(); |
|
399 iDontCloseList.ResetAndDestroy(); |
|
400 |
|
401 // Acquire buffer for reading operations. |
|
402 HBufC* tempBuffer = HBufC::NewLC( KPhoneTemporaryBufferMaxLength ); |
|
403 tempBuffer->Des().Zero(); |
|
404 TPtr ptr( tempBuffer->Des() ); |
|
405 |
|
406 TInt err = KErrNone; |
|
407 // Read "close" list. |
|
408 err = CPhoneCenRepProxy::Instance()->GetString( |
|
409 KCRUidTelPrivateVariation, |
|
410 KTelAppsCloseList, |
|
411 ptr ); |
|
412 if ( err == KErrNone ) |
|
413 { |
|
414 BuildListL( iCloseList, ptr, ETrue ); |
|
415 } |
|
416 if ( err == KErrNotFound ) |
|
417 { |
|
418 // Not defined. |
|
419 err = KErrNone; |
|
420 } |
|
421 User::LeaveIfError( err ); |
|
422 |
|
423 // Read "don't close" list. |
|
424 err = CPhoneCenRepProxy::Instance()->GetString( |
|
425 KCRUidTelPrivateVariation, |
|
426 KTelAppsKeepList, |
|
427 ptr ); |
|
428 if ( err == KErrNone ) |
|
429 { |
|
430 BuildListL( iDontCloseList, ptr, EFalse ); |
|
431 } |
|
432 if ( err == KErrNotFound ) |
|
433 { |
|
434 // Not defined. |
|
435 err = KErrNone; |
|
436 } |
|
437 User::LeaveIfError( err ); |
|
438 |
|
439 // By default, applications are closed on OOM. |
|
440 if ( !iCloseList.Count() && !iDontCloseList.Count() ) |
|
441 { |
|
442 CElement* element = |
|
443 new ( ELeave ) CElementBasic( |
|
444 CElementBasic::EExitWhenLowMemory ); |
|
445 CleanupStack::PushL( element ); |
|
446 User::LeaveIfError( iCloseList.Append( element ) ); |
|
447 CleanupStack::Pop( element ); |
|
448 } |
|
449 |
|
450 CleanupStack::PopAndDestroy( tempBuffer ); |
|
451 iListsRead = ETrue; |
|
452 |
|
453 } |
|
454 } |
|
455 |
|
456 // ----------------------------------------------------------------------------- |
|
457 // CPhoneApplicationExit::BuildListL |
|
458 // ----------------------------------------------------------------------------- |
|
459 // |
|
460 void CPhoneApplicationExit::BuildListL( |
|
461 RPointerArray< CElement >& aTarget, |
|
462 const TDesC& aSource, |
|
463 TBool aOomAllowed ) |
|
464 { |
|
465 aTarget.ResetAndDestroy(); |
|
466 |
|
467 TLex lexer( aSource ); |
|
468 lexer.SkipSpace(); |
|
469 |
|
470 TUid start; |
|
471 TUid end; |
|
472 TChar drive; |
|
473 |
|
474 TInt length = lexer.Remainder().Length(); |
|
475 while ( length ) |
|
476 { |
|
477 lexer.SkipSpace(); |
|
478 |
|
479 CElement* element = NULL; |
|
480 |
|
481 if ( ParseString( lexer, KPhoneApplicationAnyApp ) ) |
|
482 { |
|
483 element = |
|
484 new ( ELeave ) CElementBasic( |
|
485 CElementBasic::EExitAnyApp ); |
|
486 } |
|
487 else if ( ParseString( lexer, KPhoneApplicationOom ) ) |
|
488 { |
|
489 if ( aOomAllowed ) |
|
490 { |
|
491 element = |
|
492 new ( ELeave ) CElementBasic( |
|
493 CElementBasic::EExitWhenLowMemory ); |
|
494 } |
|
495 } |
|
496 else if ( ParseDrive( lexer, drive ) ) |
|
497 { |
|
498 element = new ( ELeave ) CElementDrive( drive ); |
|
499 } |
|
500 else if ( ParseUid( lexer, start, end ) ) |
|
501 { |
|
502 |
|
503 element = new ( ELeave ) CElementUid( start, end ); |
|
504 } |
|
505 else |
|
506 { |
|
507 // No proceeding, stop. |
|
508 length = 0; |
|
509 } |
|
510 |
|
511 if ( element ) |
|
512 { |
|
513 CleanupStack::PushL( element ); |
|
514 User::LeaveIfError( aTarget.Append( element ) ); |
|
515 CleanupStack::Pop( element ); |
|
516 } |
|
517 |
|
518 if ( length ) |
|
519 { |
|
520 const TInt oldLength = length; |
|
521 length = lexer.Remainder().Length(); |
|
522 |
|
523 if ( length == oldLength ) |
|
524 { |
|
525 // No proceeding, stop. |
|
526 length = 0; |
|
527 } |
|
528 } |
|
529 } |
|
530 } |
|
531 |
|
532 // ----------------------------------------------------------------------------- |
|
533 // CPhoneApplicationExit::ParseString |
|
534 // ----------------------------------------------------------------------------- |
|
535 // |
|
536 TBool CPhoneApplicationExit::ParseString( |
|
537 TLex& aLexer, |
|
538 const TDesC& aString ) |
|
539 { |
|
540 TBool result = EFalse; |
|
541 TLexMark startMark; |
|
542 aLexer.Mark( startMark ); |
|
543 const TInt length = aString.Length(); |
|
544 |
|
545 TInt i; |
|
546 for ( i = 0; |
|
547 i < length && ( aString[ i ] == TUint( aLexer.Peek() ) ); |
|
548 i++ ) |
|
549 { |
|
550 aLexer.Inc(); |
|
551 } |
|
552 |
|
553 result = ( ( i == length ) && CheckEnd( aLexer ) ); |
|
554 |
|
555 if ( !result ) |
|
556 { |
|
557 aLexer.UnGetToMark( startMark ); |
|
558 } |
|
559 return result; |
|
560 } |
|
561 |
|
562 // ----------------------------------------------------------------------------- |
|
563 // CPhoneApplicationExit::ParseUid |
|
564 // ----------------------------------------------------------------------------- |
|
565 // |
|
566 TBool CPhoneApplicationExit::ParseUid( |
|
567 TLex& aLexer, |
|
568 TUid& aUidStart, |
|
569 TUid& aUidEnd ) |
|
570 { |
|
571 TBool result = EFalse; |
|
572 TLexMark startMark; |
|
573 |
|
574 // Read first UID. |
|
575 aLexer.Mark( startMark ); |
|
576 while ( aLexer.Peek().IsHexDigit() ) |
|
577 { |
|
578 aLexer.Inc(); |
|
579 } |
|
580 TPtrC token = aLexer.MarkedToken( startMark ); |
|
581 if ( token.Length() ) |
|
582 { |
|
583 TUint uid = 0; |
|
584 result = ( TLex( token ).Val( uid, EHex ) == KErrNone ); |
|
585 if ( result ) |
|
586 { |
|
587 aUidStart.iUid = uid; |
|
588 aUidEnd.iUid = uid; |
|
589 } |
|
590 } |
|
591 |
|
592 if ( result ) |
|
593 { |
|
594 TLexMark afterUid; |
|
595 aLexer.Mark( afterUid ); |
|
596 aLexer.SkipSpace(); |
|
597 |
|
598 // Check range separator. |
|
599 if ( aLexer.Peek() == KPhoneApplicationRangeSeparator ) |
|
600 { |
|
601 // Now there must be another UID as well. |
|
602 result = EFalse; |
|
603 aLexer.Inc(); // skip separator character |
|
604 aLexer.SkipSpace(); |
|
605 |
|
606 // Read second UID. |
|
607 TLexMark mark; |
|
608 aLexer.Mark( mark ); |
|
609 while ( aLexer.Peek().IsHexDigit() ) |
|
610 { |
|
611 aLexer.Inc(); |
|
612 } |
|
613 |
|
614 TPtrC token = aLexer.MarkedToken( mark ); |
|
615 if ( token.Length() ) |
|
616 { |
|
617 TUint uid = 0; |
|
618 result = ( TLex( token ).Val( uid, EHex ) == KErrNone ); |
|
619 if ( result ) |
|
620 { |
|
621 result = CheckEnd( aLexer ); |
|
622 aUidEnd.iUid = uid; |
|
623 } |
|
624 } |
|
625 } |
|
626 else |
|
627 { |
|
628 // Only one UID, next must be space. |
|
629 aLexer.UnGetToMark( afterUid ); |
|
630 result = CheckEnd( aLexer ); |
|
631 } |
|
632 } |
|
633 |
|
634 if ( !result ) |
|
635 { |
|
636 aLexer.UnGetToMark( startMark ); |
|
637 } |
|
638 |
|
639 return result; |
|
640 } |
|
641 |
|
642 // ----------------------------------------------------------------------------- |
|
643 // CPhoneApplicationExit::ParseDrive |
|
644 // ----------------------------------------------------------------------------- |
|
645 // |
|
646 TBool CPhoneApplicationExit::ParseDrive( |
|
647 TLex& aLexer, |
|
648 TChar& aChar ) |
|
649 { |
|
650 TBool result = EFalse; |
|
651 TChar ch = aLexer.Peek(); |
|
652 |
|
653 if ( ch.IsAlpha() ) |
|
654 { |
|
655 aLexer.Inc(); |
|
656 if ( aLexer.Peek() == KPhoneApplicationDriveIdentifier ) |
|
657 { |
|
658 aLexer.Inc(); |
|
659 aChar = ch; |
|
660 result = CheckEnd( aLexer ); |
|
661 if ( !result ) |
|
662 { |
|
663 aLexer.UnGet(); // drive identifier |
|
664 aLexer.UnGet(); // drive letter |
|
665 } |
|
666 } |
|
667 else |
|
668 { |
|
669 aLexer.UnGet(); // drive letter |
|
670 } |
|
671 } |
|
672 |
|
673 return result; |
|
674 } |
|
675 |
|
676 // ----------------------------------------------------------------------------- |
|
677 // CPhoneApplicationExit::CheckEnd |
|
678 // ----------------------------------------------------------------------------- |
|
679 // |
|
680 inline TBool CPhoneApplicationExit::CheckEnd( TLex& aLexer ) |
|
681 { |
|
682 return ( aLexer.Eos() || aLexer.Peek().IsSpace() ); |
|
683 } |
|
684 |
|
685 // ----------------------------------------------------------------------------- |
|
686 // CPhoneApplicationExit::IsApplicationClosingEnabled |
|
687 // ----------------------------------------------------------------------------- |
|
688 // |
|
689 TBool CPhoneApplicationExit::IsApplicationClosingEnabled() const |
|
690 { |
|
691 return CPhoneCenRepProxy::Instance()->IsTelephonyFeatureSupported( |
|
692 KTelephonyLVFlagCloseApplications ); |
|
693 } |
|
694 |
|
695 // Implementation of CPhoneApplicationExit::CElementBasic. |
|
696 |
|
697 // ----------------------------------------------------------------------------- |
|
698 // CPhoneApplicationExit::CElementBasic::CElementBasic |
|
699 // ----------------------------------------------------------------------------- |
|
700 // |
|
701 CPhoneApplicationExit::CElementBasic::CElementBasic( TTypeOfElement aType ) : |
|
702 iType( aType ) |
|
703 { |
|
704 } |
|
705 |
|
706 // ----------------------------------------------------------------------------- |
|
707 // CPhoneApplicationExit::CElementBasic::IsLowMemory |
|
708 // ----------------------------------------------------------------------------- |
|
709 // |
|
710 TBool CPhoneApplicationExit::CElementBasic::IsLowMemory() |
|
711 { |
|
712 // Fetch amount of free memory. |
|
713 TMemoryInfoV1Buf memory; |
|
714 UserHal::MemoryInfo( memory ); |
|
715 TInt freeRam = (TInt)( memory().iFreeRamInBytes ); |
|
716 TInt oomRamLowThreshold = 0; |
|
717 /* MIGRATION NOTE - need new method to TelUtils for static get of one |
|
718 value. |
|
719 CRepository* cenRep = NULL; |
|
720 TRAPD( error, cenRep = CRepository::NewL( KCRUidUiklaf ) ); |
|
721 if ( error == KErrNoMemory ) |
|
722 { |
|
723 return ETrue; |
|
724 } |
|
725 else if ( error != KErrNone ) |
|
726 { |
|
727 // Error; don't know OOM status. |
|
728 return EFalse; |
|
729 } |
|
730 cenRep->Get( KUikOOMRamLowThreshold, oomRamLowThreshold ); |
|
731 delete cenRep;*/ |
|
732 return ( freeRam < oomRamLowThreshold ); |
|
733 } |
|
734 |
|
735 // ----------------------------------------------------------------------------- |
|
736 // CPhoneApplicationExit::CElementBasic::AcceptL |
|
737 // ----------------------------------------------------------------------------- |
|
738 // |
|
739 TBool CPhoneApplicationExit::CElementBasic::AcceptL( |
|
740 const TUid& /*aUid*/ ) const |
|
741 { |
|
742 TBool result = EFalse; |
|
743 switch ( iType ) |
|
744 { |
|
745 case EExitAnyApp: |
|
746 result = ETrue; |
|
747 break; |
|
748 |
|
749 case EExitWhenLowMemory: |
|
750 result = IsLowMemory(); |
|
751 break; |
|
752 |
|
753 default: |
|
754 break; |
|
755 } |
|
756 return result; |
|
757 } |
|
758 |
|
759 // Implementation of CPhoneApplicationExit::CElementUid. |
|
760 |
|
761 // ----------------------------------------------------------------------------- |
|
762 // CPhoneApplicationExit::CElementUid::CElementUid |
|
763 // ----------------------------------------------------------------------------- |
|
764 // |
|
765 CPhoneApplicationExit::CElementUid::CElementUid( |
|
766 const TUid& aStart, |
|
767 const TUid& aEnd ) : |
|
768 iStart( aStart ), |
|
769 iEnd( aEnd ) |
|
770 { |
|
771 } |
|
772 |
|
773 // ----------------------------------------------------------------------------- |
|
774 // CPhoneApplicationExit::CElementUid::AcceptL |
|
775 // ----------------------------------------------------------------------------- |
|
776 // |
|
777 TBool CPhoneApplicationExit::CElementUid::AcceptL( const TUid& aUid ) const |
|
778 { |
|
779 return ( iStart.iUid <= aUid.iUid && aUid.iUid <= iEnd.iUid ); |
|
780 } |
|
781 |
|
782 // Implementation of CPhoneApplicationExit::CElementDrive. |
|
783 |
|
784 // ----------------------------------------------------------------------------- |
|
785 // CPhoneApplicationExit::CElementDrive::CElementDrive |
|
786 // ----------------------------------------------------------------------------- |
|
787 // |
|
788 CPhoneApplicationExit::CElementDrive::CElementDrive( const TChar& aDrive ) : |
|
789 iDrive( aDrive ) |
|
790 { |
|
791 } |
|
792 |
|
793 // ----------------------------------------------------------------------------- |
|
794 // CPhoneApplicationExit::CElementDrive::AcceptL |
|
795 // ----------------------------------------------------------------------------- |
|
796 // |
|
797 TBool CPhoneApplicationExit::CElementDrive::AcceptL( const TUid& aUid ) const |
|
798 { |
|
799 return CheckApplicationDriveL( aUid ); |
|
800 } |
|
801 |
|
802 // ----------------------------------------------------------------------------- |
|
803 // CPhoneApplicationExit::CElementDrive::CheckApplicationDriveL |
|
804 // ----------------------------------------------------------------------------- |
|
805 // |
|
806 TBool CPhoneApplicationExit::CElementDrive::CheckApplicationDriveL( |
|
807 const TUid& aUid ) const |
|
808 { |
|
809 RApaLsSession session; |
|
810 User::LeaveIfError( session.Connect() ); |
|
811 CleanupClosePushL( session ); |
|
812 |
|
813 TApaAppInfo* appInfo = new ( ELeave ) TApaAppInfo; |
|
814 CleanupStack::PushL( appInfo ); |
|
815 |
|
816 TBool result = EFalse; |
|
817 TInt count = KPhoneApplicationRetryCount; |
|
818 while ( count ) |
|
819 { |
|
820 TInt err = session.GetAppInfo( *appInfo, aUid ); |
|
821 |
|
822 if ( err == KErrNone ) |
|
823 { |
|
824 count = 0; |
|
825 result = ETrue; |
|
826 } |
|
827 else if ( err == KErrNotFound ) |
|
828 { |
|
829 count = 0; |
|
830 result = EFalse; |
|
831 } |
|
832 else |
|
833 { |
|
834 User::LeaveIfError( err ); |
|
835 |
|
836 // GetAppInfo may return positive value indicating that |
|
837 // application information is not ready. |
|
838 count--; |
|
839 User::After( KPhoneApplicationRetryInterval ); |
|
840 } |
|
841 } |
|
842 |
|
843 if ( result ) |
|
844 { |
|
845 result = EFalse; |
|
846 if ( appInfo->iFullName.Length() ) |
|
847 { |
|
848 // First character is drive |
|
849 TChar drive( appInfo->iFullName[ 0 ] ); |
|
850 drive.UpperCase(); |
|
851 |
|
852 TChar targetDrive( iDrive ); |
|
853 targetDrive.UpperCase(); |
|
854 |
|
855 result = ( drive == targetDrive ); |
|
856 } |
|
857 } |
|
858 |
|
859 CleanupStack::PopAndDestroy( appInfo ); |
|
860 CleanupStack::PopAndDestroy(); // CleanupClosePushL |
|
861 return result; |
|
862 } |
|
863 |
|
864 // End of File |