301 |
302 |
302 //AppClose Actions should always have a unique prioirity determined by the application's z order. |
303 //AppClose Actions should always have a unique prioirity determined by the application's z order. |
303 TInt err = iActionRefs.InsertInOrder(ref, ComparePriorities); |
304 TInt err = iActionRefs.InsertInOrder(ref, ComparePriorities); |
304 if ((err != KErrNone) && (err != KErrAlreadyExists)) |
305 if ((err != KErrNone) && (err != KErrAlreadyExists)) |
305 { |
306 { |
|
307 TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, err = %d", appId, wgId, err); |
306 User::Leave(err); |
308 User::Leave(err); |
307 } |
309 } |
308 TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, wgIndex = %d", appId, wgId, wgIndex); |
310 TRACES3("BuildActionListL: Adding app to action list, Uid = %x, wgId = %d, wgIndex = %d", appId, wgId, wgIndex); |
309 } |
311 } |
310 |
312 |
350 continue; |
352 continue; |
351 } |
353 } |
352 |
354 |
353 TActionRef ref = iActionRefs[iCurrentActionIndex]; |
355 TActionRef ref = iActionRefs[iCurrentActionIndex]; |
354 CGOomAction* action = NULL; |
356 CGOomAction* action = NULL; |
355 if (ref.Type() == TActionRef::EAppClose) |
357 if (ref.Type() == TActionRef::EAppClose ) |
356 { |
358 { |
357 action = iCloseAppActions[numberOfRunningActions]; |
359 iAppIndex%=iCloseAppActions.Count(); |
|
360 TRACES2("Proceeding with app action from index %d, out of %d", iAppIndex, iCloseAppActions.Count() ); |
|
361 action = iCloseAppActions[iAppIndex]; |
|
362 iAppIndex++; |
358 static_cast<CGOomCloseApp*>(action)->Reconfigure(ref); |
363 static_cast<CGOomCloseApp*>(action)->Reconfigure(ref); |
|
364 |
|
365 ref.iAppPlugin = action; |
359 |
366 |
360 //Double checking again if this app is now in foreground, if yes then we dont kill |
367 //Double checking again if this app is now in foreground, if yes then we dont kill |
361 CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(iWs, iWs.GetFocusWindowGroup()); |
368 CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(iWs, iWs.GetFocusWindowGroup()); |
362 |
369 |
363 TInt32 fgApp = wgName->AppUid().iUid; |
370 TInt32 fgApp = wgName->AppUid().iUid; |
364 TInt32 appId = iMonitor.GetWindowGroupList()->AppIdfromWgId(ref.WgId(), ETrue); |
371 TInt32 appId = iMonitor.GetWindowGroupList()->AppIdfromWgId(ref.WgId(), ETrue); |
365 |
372 |
366 CleanupStack::PopAndDestroy(); |
|
367 if(appId == fgApp) |
373 if(appId == fgApp) |
368 { |
374 { |
369 TRACES1("Foreground App wgid %x, spared by GOOM", appId); |
375 TRACES1("Foreground App wgid %x, spared by GOOM", appId); |
370 |
376 |
371 iCurrentActionIndex++; |
377 iCurrentActionIndex++; |
|
378 CleanupStack::PopAndDestroy(); |
372 continue; |
379 continue; |
|
380 } |
|
381 |
|
382 //check if this is not parent of foreground app |
|
383 TBool spared = EFalse; |
|
384 TRACES1("CGOomActionList::FreeMemory - Going to kill Appid %x ",appId); |
|
385 TInt prevWgId = 0; |
|
386 while(prevWgId != KErrNotFound) |
|
387 { |
|
388 wgName->FindByAppUid(wgName->AppUid(), iWs, prevWgId); |
|
389 |
|
390 if(prevWgId == KErrNotFound) |
|
391 break; |
|
392 |
|
393 TInt parentId = 0; |
|
394 TRAPD(err, parentId = iMonitor.GetWindowGroupList()->FindParentIdL(prevWgId)); |
|
395 TRACES2("CGOomActionList::FreeMemory - Foreground App wgid %d, parent wgid %d",prevWgId, parentId); |
|
396 if( err == KErrNone && parentId != 0) |
|
397 { |
|
398 TInt32 parentAppId = iMonitor.GetWindowGroupList()->AppIdfromWgId(parentId, ETrue); |
|
399 if(parentAppId == appId) |
|
400 { |
|
401 TRACES3("Parent App %x (wgId %d), of Foreground App %x, spared by GOOM", parentAppId, parentId, fgApp); |
|
402 spared = ETrue; |
|
403 break; |
|
404 } |
|
405 } |
|
406 } |
|
407 CleanupStack::PopAndDestroy(); |
|
408 if(spared) |
|
409 { |
|
410 iCurrentActionIndex++; |
|
411 if (iCurrentActionIndex >= iActionRefs.Count()) |
|
412 { |
|
413 StateChanged(); |
|
414 return; |
|
415 } |
|
416 else |
|
417 { |
|
418 continue; |
|
419 } |
373 } |
420 } |
374 } |
421 } |
375 else |
422 else |
376 { |
423 { |
377 action = &(ref.RunPlugin()); |
424 action = &(ref.RunPlugin()); |
577 void CGOomActionList::AppNotExiting(TInt aWgId) |
623 void CGOomActionList::AppNotExiting(TInt aWgId) |
578 { |
624 { |
579 FUNC_LOG; |
625 FUNC_LOG; |
580 |
626 |
581 TInt index = iCloseAppActions.Count(); |
627 TInt index = iCloseAppActions.Count(); |
|
628 TRACES1("CGOomCloseApp::AppNotExiting: count of actions %d",index); |
|
629 |
582 while (index--) |
630 while (index--) |
583 { |
631 { |
584 CGOomCloseApp* action = iCloseAppActions[index]; |
632 CGOomCloseApp* action = iCloseAppActions[index]; |
|
633 TRACES3("CGOomCloseApp::AppNotExiting: %d %d %d", aWgId, action->WgId(), action->IsRunning()); |
|
634 |
585 if ( (action->WgId() == aWgId) && (action->IsRunning()) ) |
635 if ( (action->WgId() == aWgId) && (action->IsRunning()) ) |
586 { |
636 { |
587 TRACES1("CGOomCloseApp::AppNotExiting: App with window group id %d has not responded to the close event", aWgId); |
637 TRACES1("CGOomCloseApp::AppNotExiting: App with window group id %d has not responded to the close event", aWgId); |
588 action->CloseAppEvent(); |
638 action->CloseAppEvent(); |
589 } |
639 } |
596 { |
646 { |
597 FUNC_LOG; |
647 FUNC_LOG; |
598 |
648 |
599 TBool allActionsComplete = ETrue; |
649 TBool allActionsComplete = ETrue; |
600 |
650 |
601 // Note that the actions themselves are responsible for timing out if necessary. |
651 TInt index = iActionRefs.Count(); |
602 TInt index = iCloseAppActions.Count(); |
652 while ((index--) && (allActionsComplete)) |
603 while ((index--) && (allActionsComplete)) |
653 { |
604 { |
654 if (iActionRefs[index].IsRunning()) |
605 if (iCloseAppActions[index]->IsRunning()) |
655 { |
606 { |
656 TRACES1("CGOomActionList::StateChanged. Action %d STILL RUNNING.", index); |
607 TRACES1("CGOomActionList::StateChanged. CloseAppAction %d STILL RUNNING. PROBLEM !!! YOU SHOULD NEVER SEE THIS", index); |
|
608 allActionsComplete = EFalse; |
|
609 } |
|
610 } |
|
611 |
|
612 index = iRunPluginActions.Count(); |
|
613 while ((index--) && (allActionsComplete)) |
|
614 { |
|
615 if (iRunPluginActions[index]->IsRunning()) |
|
616 { |
|
617 TRACES1("CGOomActionList::StateChanged. PluginAction %d STILL RUNNING. PROBLEM !!! YOU SHOULD NEVER SEE THIS", index); |
|
618 allActionsComplete = EFalse; |
657 allActionsComplete = EFalse; |
619 } |
658 } |
620 } |
659 } |
621 |
660 |
622 TRACES1("CGOomActionList::StateChanged. Current Target = %d", iCurrentTarget); |
661 TRACES1("CGOomActionList::StateChanged. Current Target = %d", iCurrentTarget); |
630 TRACES1("CGOomActionList::StateChanged. Free Memory = %d", freeMemory); |
669 TRACES1("CGOomActionList::StateChanged. Free Memory = %d", freeMemory); |
631 if (!freeMemoryAboveTarget) |
670 if (!freeMemoryAboveTarget) |
632 // If we are still below the good-memory-threshold then continue running actions |
671 // If we are still below the good-memory-threshold then continue running actions |
633 { |
672 { |
634 TRACES2("CGOomActionList::StateChanged: Finished Action %d out of %d",iCurrentActionIndex, iActionRefs.Count()); |
673 TRACES2("CGOomActionList::StateChanged: Finished Action %d out of %d",iCurrentActionIndex, iActionRefs.Count()); |
635 |
674 |
636 |
675 if (iCurrentActionIndex < iActionRefs.Count()-1) |
637 if (iCurrentActionIndex >= iActionRefs.Count()) |
|
638 { |
676 { |
639 if(iRunningKillAppActions) |
677 // launch more actions, potential recursion !! |
640 { |
678 iCurrentActionIndex++; |
641 iRunningKillAppActions = EFalse; |
679 return FreeMemory(iMaxPriority); |
642 // There are no more actions to try, so we give up |
680 } |
643 TRACES1("CGOomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory); |
681 |
644 |
682 if(iRunningKillAppActions) |
645 /* Do not call memory good immidiately after freeing memory for some app |
683 { |
646 if (freeMemory >= iCurrentTarget && !iMonitor.NeedToPostponeMemGood()) |
684 iRunningKillAppActions = EFalse; |
647 { |
685 // There are no more actions to try, so we give up |
648 MemoryGood(); |
686 TRACES1("CGOomActionList::StateChanged: All current actions complete, below good threshold with no more actions available. freeMemory=%d", freeMemory); |
649 } |
687 |
650 */ |
688 if (!iTryOptional && !iOptionalTried && freeMemory < 25*1024*1024 ) // magic, should read this from config |
651 if (!iTryOptional && !iOptionalTried && freeMemory < 25*1024*1024 ) // magic, should read this from config |
689 { |
652 { |
690 iTryOptional = ETrue; |
653 iTryOptional = ETrue; |
691 iOptionalTried = ETrue; |
654 iOptionalTried = EFalse; |
692 iMonitor.RunCloseAppActions(iMaxPriority); |
655 iMonitor.RunCloseAppActions(iMaxPriority); |
|
656 } |
|
657 else |
|
658 { |
|
659 iTryOptional = EFalse; |
|
660 iServer.CloseAppsFinished(freeMemory, EFalse); |
|
661 iMonitor.WaitAndSynchroniseMemoryState(); |
|
662 } |
|
663 } |
693 } |
664 else |
694 else |
665 { |
695 { |
666 TRACES1("CGOomActionList::StateChanged: All current Plugin actions complete, below good threshold, Time to kill bad guys. freeMemory=%d", freeMemory); |
696 iTryOptional = EFalse; |
667 iRunningKillAppActions = ETrue; |
697 iServer.CloseAppsFinished(freeMemory, EFalse); |
668 iMonitor.RunCloseAppActions(iMaxPriority); |
698 iMonitor.WaitAndSynchroniseMemoryState(); |
669 } |
699 } |
670 |
|
671 } |
700 } |
672 else |
701 else |
673 { |
702 { |
674 // There are still more actions to try, so we continue |
703 TRACES1("CGOomActionList::StateChanged: All current Plugin actions complete, below good threshold, Time to kill bad guys. freeMemory=%d", freeMemory); |
675 TRACES1("CGOomActionList::StateChanged: All current actions complete, running more actions. freeMemory=%d", freeMemory); |
704 iRunningKillAppActions = ETrue; |
676 FreeMemory(iMaxPriority); |
705 iMonitor.RunCloseAppActions(iMaxPriority); |
677 } |
706 } |
|
707 |
678 } |
708 } |
679 else |
709 else |
680 { |
710 { |
681 TRACES1("CGOomActionList::StateChanged: All current actions complete, memory good. freeMemory=%d", freeMemory); |
711 TRACES1("CGOomActionList::StateChanged: All current actions complete, memory good. freeMemory=%d", freeMemory); |
682 /* Do not call memory good immidiately after freeing memory for some app |
|
683 if(freeMemory > iMonitor.GetGoodThreshold() && !iMonitor.NeedToPostponeMemGood()) |
|
684 { |
|
685 MemoryGood(); |
|
686 } |
|
687 */ |
|
688 iRunningKillAppActions = EFalse; |
712 iRunningKillAppActions = EFalse; |
689 iServer.CloseAppsFinished(freeMemory, ETrue); |
713 iServer.CloseAppsFinished(freeMemory, ETrue); |
690 iMonitor.WaitAndSynchroniseMemoryState(); |
714 iMonitor.WaitAndSynchroniseMemoryState(); |
691 } |
715 } |
692 } |
716 } |