launcher/src/launcherengine.cpp
branchRCL_3
changeset 22 fad26422216a
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
       
     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 
       
    18 
       
    19 
       
    20 #include <aknnotewrappers.h>
       
    21 #include <avkon.hrh>
       
    22 #include <AknWaitDialog.h>
       
    23 #include <AknGlobalNote.h>
       
    24 #include <coeutils.h> 
       
    25 #include <AknCommonDialogs.h>
       
    26 #include <eikprogi.h>
       
    27 
       
    28 #include <launcher.rsg>
       
    29 
       
    30 #include "launcherappui.h"
       
    31 #include "launcherengine.h"
       
    32 #include "launcher.hrh"
       
    33 #include "launcherviewapps.h"
       
    34 #include "launcherviewoutput.h"
       
    35 #include "launchercontainerapps.h"
       
    36 #include "launchercontaineroutput.h"
       
    37 #include "launcherdllparser.h"
       
    38 #include "launcherxmlparser.h"
       
    39 
       
    40 #include <CMessageData.h>
       
    41 #include <e32std.h>
       
    42 #include <w32std.h>
       
    43 #include <apgtask.h>
       
    44 #include <bautils.h>
       
    45 #include <s32file.h>
       
    46 #include <pathinfo.h> 
       
    47 #include <e32cmn.h>
       
    48 
       
    49 #include "launchertraces.h"
       
    50 #include "e32image.h"
       
    51 
       
    52 _LIT(KLogFileName, "LauncherLog.txt");
       
    53 _LIT(KBCLogFileName, "LauncherBCLog.txt");
       
    54 _LIT(KSystemDllsFileName, "SystemDlls.txt");
       
    55 _LIT(KRequiredDllsFileName, "RequiredDlls.xml");
       
    56 _LIT(KDotXML,".xml");
       
    57 _LIT(KDotLauncherXML,".launcherxml");
       
    58 
       
    59 _LIT(KFileSeparator, "\t");
       
    60 _LIT(KFileNewLine, "\r\n");
       
    61 
       
    62 const TInt KMaxAppsArraySize=250;
       
    63 const TInt KMaxDllArraySize=5000;
       
    64 const TInt KLauncherLogBufferSize = 4096;
       
    65 
       
    66 // After this many issues, issues are buffered and printed 
       
    67 // in the end of analysis
       
    68 const TInt KBigBufferUsageThreshold=10;
       
    69 
       
    70 // Buffer allocation unit
       
    71 const TInt KBigBufferAllocBytes=1024;
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 
       
    75 CLauncherEngine* CLauncherEngine::NewL(CLauncherAppUi* aAppUi)
       
    76     {
       
    77     CLauncherEngine* self = new(ELeave) CLauncherEngine;
       
    78     CleanupStack::PushL(self);
       
    79     self->ConstructL(aAppUi);
       
    80     CleanupStack::Pop();
       
    81     return self;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 
       
    86 CLauncherEngine::CLauncherEngine() : CActive(EActivePriorityIpcEventsHigh)
       
    87     {
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 
       
    92 template <typename T>
       
    93 void AppendLogBufferL(const T& aText, HBufC8*& aBuf)
       
    94     {
       
    95     if( aBuf == 0 )
       
    96         {
       
    97         aBuf = HBufC8::NewL(KLauncherLogBufferSize);
       
    98         }
       
    99     
       
   100     TInt currentMaxLength = aBuf->Des().MaxLength();
       
   101     if( aBuf->Des().Length() + aText.Length() > currentMaxLength )
       
   102         {
       
   103         TInt increaseSize = Max(aText.Length(), KLauncherLogBufferSize);                
       
   104         aBuf = aBuf->ReAllocL(aBuf->Des().MaxLength() + increaseSize );
       
   105         }
       
   106     aBuf->Des().Append(aText);        
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 
       
   111 void CLauncherEngine::ConstructL(CLauncherAppUi* aAppUi)
       
   112     {
       
   113     LOGSTRING("Launcher: CLauncherEngine::ConstructL");
       
   114 
       
   115     iAppUi = aAppUi;
       
   116     iEnv = CEikonEnv::Static();
       
   117     iLaunchingIsActive = EFalse;
       
   118     iDLLAnalysisIsActive = EFalse;
       
   119     iSkipHiddenAndEmbedOnly = ETrue;
       
   120 
       
   121     User::LeaveIfError(iTimer.CreateLocal());
       
   122 
       
   123     User::LeaveIfError(iLs.Connect());
       
   124     User::LeaveIfError(iWs.Connect());
       
   125 
       
   126     iAppThreadChecker = CAppThreadChecker::NewL(this);
       
   127     iAppRunningChecker = CAppRunningChecker::NewL(this);
       
   128 
       
   129     iAllAppsArray = new(ELeave) CDesCArrayFlat(KMaxAppsArraySize);
       
   130     iAppsArray = new(ELeave) CDesCArrayFlat(KMaxAppsArraySize);
       
   131     iSystemDllArray = new(ELeave) CDesCArrayFlat(KMaxDllArraySize);
       
   132 
       
   133     iLogWriteBuf = HBufC8::NewL(KLauncherLogBufferSize);
       
   134 
       
   135     iLogFilePath = PathInfo::PhoneMemoryRootPath();
       
   136     iLogFilePath.Append( KLogFileName );
       
   137     
       
   138     iBCLogFilePath = PathInfo::PhoneMemoryRootPath();
       
   139     iBCLogFilePath.Append( KBCLogFileName );
       
   140 
       
   141     iSystemDllsFilePath = PathInfo::PhoneMemoryRootPath();
       
   142     iSystemDllsFilePath.Append( KSystemDllsFileName );
       
   143 
       
   144     iRequiredDllsFilePath = PathInfo::PhoneMemoryRootPath();
       
   145     iRequiredDllsFilePath.Append( KRequiredDllsFileName );
       
   146             
       
   147     iDLLParser = CLauncherDLLParser::NewL();
       
   148 
       
   149     CActiveScheduler::Add(this);
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 
       
   154 CLauncherEngine::~CLauncherEngine()
       
   155     {
       
   156     LOGSTRING("Launcher: CLauncherEngine::~CLauncherEngine");
       
   157 
       
   158     Cancel();
       
   159 
       
   160     // close the log
       
   161     iLogFile.Close();
       
   162     iBCLogFile.Close();
       
   163     if (iLogWriteBuf)
       
   164         delete iLogWriteBuf;
       
   165 
       
   166     if (iAppRunningChecker)
       
   167         delete iAppRunningChecker;
       
   168     
       
   169     if (iAppThreadChecker)
       
   170         delete iAppThreadChecker;
       
   171 
       
   172     if (iSystemDllArray)
       
   173         {
       
   174         iSystemDllArray->Reset();
       
   175         delete iSystemDllArray;
       
   176         }
       
   177 
       
   178     if (iAppsArray)
       
   179         {
       
   180         iAppsArray->Reset();
       
   181         delete iAppsArray;
       
   182         }
       
   183 
       
   184     if (iAllAppsArray)
       
   185         {
       
   186         iAllAppsArray->Reset();
       
   187         delete iAllAppsArray;
       
   188         }
       
   189     
       
   190     delete iXMLParser;
       
   191     delete iDLLParser;
       
   192     delete iDLLElement;
       
   193     delete iBCIssuesBigBuffer;            
       
   194     
       
   195     iWs.Close();
       
   196     iLs.Close();
       
   197     iTimer.Close();
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 
       
   202 void CLauncherEngine::SetContainerApps(CLauncherContainerApps* aContainerApps)
       
   203     {
       
   204     iContainerApps = aContainerApps;
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 
       
   209 void CLauncherEngine::SetContainerOutput(CLauncherContainerOutput* aContainerOutput)
       
   210     {
       
   211     iContainerOutput = aContainerOutput;
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 
       
   216 
       
   217 TInt CLauncherEngine::FindFilesRecursiveL(const TDesC& aFileName, const TDesC& aPath)
       
   218     {
       
   219     TInt err = KErrNone;
       
   220     CDirScan* scan = CDirScan::NewLC(iEnv->FsSession());
       
   221     scan->SetScanDataL(aPath, KEntryAttDir, ESortNone);
       
   222     CDir* dirEntries = NULL;
       
   223 
       
   224     for(;;)
       
   225         {
       
   226         TRAP(err, scan->NextL(dirEntries));
       
   227         if (!dirEntries  || (err!=KErrNone))
       
   228             break;
       
   229 
       
   230         for (TInt i=0; i<dirEntries->Count(); i++) 
       
   231             {
       
   232             TFileName path(scan->FullPath());
       
   233             path.Append((*dirEntries)[i].iName);
       
   234             path.Append(_L("\\"));
       
   235             FindFiles(aFileName, path);
       
   236             }
       
   237         delete(dirEntries);
       
   238         }
       
   239 
       
   240     CleanupStack::PopAndDestroy(scan);
       
   241     return err;
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 
       
   246 TInt CLauncherEngine::FindFiles(const TDesC& aFileName, const TDesC& aPath)
       
   247     {
       
   248     TFindFile fileFinder(iEnv->FsSession());
       
   249     CDir* fileList; 
       
   250     TInt err = fileFinder.FindWildByDir(aFileName, aPath, fileList);
       
   251 
       
   252     while (err == KErrNone)
       
   253         {
       
   254         for (TInt i=0; i<fileList->Count(); i++)
       
   255             {
       
   256             TParse fullentry;
       
   257             fullentry.Set((*fileList)[i].iName, &fileFinder.File(), NULL);
       
   258 
       
   259             TRAP(err, iSystemDllArray->AppendL(fullentry.NameAndExt())); 
       
   260             }
       
   261 
       
   262         delete fileList;
       
   263         err = fileFinder.FindWild(fileList);
       
   264         }
       
   265     return err;
       
   266     }
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 
       
   270 CDesCArray* CLauncherEngine::ListOfAllAppsL()
       
   271     {
       
   272     LOGSTRING("Launcher: CLauncherEngine::ListOfAllAppsL");
       
   273 
       
   274     // show wait dialog
       
   275     CAknGlobalNote* waitDialog = CAknGlobalNote::NewLC();
       
   276     waitDialog->SetSoftkeys(R_AVKON_SOFTKEYS_EMPTY);
       
   277     TInt dialogId = waitDialog->ShowNoteL(EAknGlobalWaitNote, _L("Initializing"));
       
   278 
       
   279 
       
   280     // find all DLLs from the system
       
   281     iSystemDllArray->Reset();
       
   282     TRAP_IGNORE( FindFiles(_L("*.dll"), _L("\\sys\\bin\\")) );
       
   283 
       
   284     // write the list of DLLs to a file
       
   285     RFile dllFile;
       
   286     if (dllFile.Replace(iEnv->FsSession(), iSystemDllsFilePath, EFileWrite) == KErrNone)
       
   287         {
       
   288         TBuf8<KMaxFileName> dllName;
       
   289 
       
   290         for (TInt i=0; i<iSystemDllArray->MdcaCount(); i++)
       
   291             {
       
   292             dllName.Copy( iSystemDllArray->MdcaPoint(i) );
       
   293             dllName.Append( KFileNewLine );
       
   294 
       
   295             dllFile.Write( dllName );
       
   296             }
       
   297 
       
   298         dllFile.Close();
       
   299         }
       
   300 
       
   301     // reset the apps list
       
   302     iAllAppsArray->Reset();
       
   303 
       
   304     // search all apps
       
   305     TApaAppInfo appInfo;
       
   306     iLs.GetAllApps();
       
   307 
       
   308     while (iLs.GetNextApp(appInfo) == KErrNone)
       
   309         {
       
   310         iAllAppsArray->AppendL(appInfo.iFullName);
       
   311         }
       
   312 
       
   313 
       
   314     // remove launcher.app / launcher.exe from the list
       
   315     for (TInt i=0; i<iAllAppsArray->MdcaCount(); i++)
       
   316         {
       
   317         if (iAllAppsArray->MdcaPoint(i).FindF(_L("\\Launcher.")) != KErrNotFound)
       
   318             {
       
   319             iAllAppsArray->Delete(i);
       
   320             iAllAppsArray->Compress();
       
   321             break;
       
   322             }
       
   323         }
       
   324 
       
   325     // sort the elements
       
   326     iAllAppsArray->Sort();
       
   327 
       
   328     // remove the wait dialog
       
   329     waitDialog->CancelNoteL(dialogId);
       
   330     CleanupStack::PopAndDestroy(); //waitDialog;
       
   331        
       
   332     return iAllAppsArray;
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 
       
   337 void CLauncherEngine::StartAppLaunchingL(const CArrayFix<TInt>* aSelectedApps, TBool aAutoClose)
       
   338     {
       
   339     LOGSTRING("Launcher: CLauncherEngine::StartAppLaunchingL");
       
   340 
       
   341     // check that we have something to launch
       
   342     if (aSelectedApps->Count() <= 0)
       
   343         {
       
   344         _LIT(message, "Nothing selected");
       
   345         CAknErrorNote* errorNote = new(ELeave) CAknErrorNote;
       
   346         errorNote->ExecuteLD(message);
       
   347         }
       
   348     else
       
   349         {
       
   350         // update the list of applications to be tested
       
   351         iAppsArray->Reset();
       
   352 
       
   353         TInt ref(0);
       
   354         TKeyArrayFix key(0, ECmpTUint16);
       
   355         TInt index(0);
       
   356 
       
   357         for (TInt i=0; i<iAllAppsArray->MdcaCount(); i++)
       
   358             {
       
   359             ref = i;
       
   360 
       
   361             // if the application is selected, append it to the apps array
       
   362             if (aSelectedApps->Find(ref, key, index) == 0)  
       
   363                 {
       
   364                 iAppsArray->AppendL(iAllAppsArray->MdcaPoint(i));
       
   365                 }
       
   366             }
       
   367 
       
   368 
       
   369         // to make sure that our algorithm works correctly
       
   370         if (iAppsArray->MdcaCount() != aSelectedApps->Count())
       
   371             {
       
   372             _LIT(message, "Something went wrong...");
       
   373             CAknErrorNote* errorNote = new(ELeave) CAknErrorNote;
       
   374             errorNote->ExecuteLD(message);
       
   375             return;
       
   376             }
       
   377 
       
   378         
       
   379         // init
       
   380         Cancel();
       
   381         iLaunchingIsActive = ETrue;
       
   382         iAutoClose = aAutoClose;
       
   383         iAppLaunchCounter = 0;
       
   384         iFailedCases = 0;
       
   385         iOkCases = 0;
       
   386         iSkippedCases = 0;
       
   387         iTotalNumberOfCases = iAppsArray->MdcaCount();
       
   388         iCurrentAppUid = KNullUid;
       
   389 
       
   390         // open the log file for writing
       
   391         if (iLogFile.Open(iEnv->FsSession(), iLogFilePath, EFileWrite) != KErrNone)
       
   392             {
       
   393             iEnv->FsSession().MkDirAll(iLogFilePath);
       
   394             iLogFile.Replace(iEnv->FsSession(), iLogFilePath, EFileWrite);
       
   395             }
       
   396         else
       
   397             {
       
   398             // file opens correctly, seek to the end
       
   399             TInt fileSize=0;
       
   400             iLogFile.Size(fileSize);
       
   401             iLogFile.Seek(ESeekCurrent, fileSize);
       
   402             }
       
   403 
       
   404         ChangeFocusToOutputView();
       
   405 
       
   406         iContainerOutput->PrintTextL(_L("New test started.\n"));
       
   407 
       
   408         // start the first launch!
       
   409         IssueLaunch();
       
   410 
       
   411         }
       
   412     }
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 
       
   416 void CLauncherEngine::IssueLaunch()
       
   417     {
       
   418     LOGSTRING("Launcher: CLauncherEngine::IssueLaunch");
       
   419 
       
   420     __ASSERT_ALWAYS(!IsActive(), User::Panic(_L("Timing error?"), 100));
       
   421 
       
   422     // this should keep the backlight on
       
   423     User::ResetInactivityTime();
       
   424 
       
   425     // some delay
       
   426     iTimer.After(iStatus, 1000000);    
       
   427     SetActive();
       
   428     }
       
   429 
       
   430 // ---------------------------------------------------------------------------
       
   431 
       
   432 void CLauncherEngine::RunL()
       
   433     {
       
   434     LOGSTRING("Launcher: CLauncherEngine::RunL");  
       
   435     TInt err = iStatus.Int();
       
   436     User::LeaveIfError(err);
       
   437     
       
   438     if( iDLLAnalysisIsActive )
       
   439         {
       
   440         if( iWaitDialog == 0)
       
   441             {
       
   442             TEntry entry;
       
   443             User::LeaveIfError(iEnv->FsSession().Entry(iRequiredDllsFilePath, entry));
       
   444             TInt fileSize = entry.iSize;
       
   445 
       
   446             // init progress bar
       
   447             iWaitDialog = new(ELeave) CAknProgressDialog((reinterpret_cast<CEikDialog**>(&iWaitDialog)), ETrue);
       
   448             iWaitDialog->SetCallback(this);
       
   449             iWaitDialog->PrepareLC(R_GENERAL_PROGRESS_NOTE);
       
   450             iWaitDialog->SetCurrentLabelL( EAknCtNote, _L("Analysing DLLs"));
       
   451             iProgressInfo = iWaitDialog->GetProgressInfoL();
       
   452             iProgressInfo->SetFinalValue( fileSize );
       
   453             iWaitDialog->RunLD();
       
   454             iWaitDialog->MakeVisible( ETrue );
       
   455             }
       
   456         
       
   457         iBCLogFile.Write(iLogWriteBuf->Des());
       
   458         iLogWriteBuf->Des().Zero();
       
   459         return;
       
   460         }
       
   461     else
       
   462         {
       
   463         // write full app path to the log file
       
   464         WriteInitialStuffToTheLogL(iAppsArray->MdcaPoint(iAppLaunchCounter), iLogFile);
       
   465 
       
   466         // get the uid of the current app
       
   467         iCurrentAppUid = KNullUid;
       
   468         TApaAppInfo appInfo;
       
   469         iLs.GetAllApps();
       
   470         while (iLs.GetNextApp(appInfo) == KErrNone)
       
   471             {
       
   472             if (appInfo.iFullName.CompareF( iAppsArray->MdcaPoint(iAppLaunchCounter) ) == 0)
       
   473                 {
       
   474                 iCurrentAppUid = appInfo.iUid;
       
   475                 break;
       
   476                 }
       
   477             }
       
   478 
       
   479         if (iCurrentAppUid == KNullUid)
       
   480             {        
       
   481             iLogWriteBuf->Des().Append(_L("[WARN: App has no UID] "));
       
   482             }
       
   483 
       
   484         // parse the filename
       
   485         TParse nameParser;
       
   486         nameParser.SetNoWild(iAppsArray->MdcaPoint(iAppLaunchCounter), NULL, NULL);
       
   487         iCurrentAppNameAndExt.Copy(nameParser.Drive());
       
   488         iCurrentAppNameAndExt.Append(nameParser.NameAndExt());
       
   489 
       
   490         // do not try to launch these apps
       
   491         if (iAppsArray->MdcaPoint(iAppLaunchCounter).FindF(_L("\\Launcher.")) != KErrNotFound
       
   492             || iAppsArray->MdcaPoint(iAppLaunchCounter).FindF(_L("\\Phone.")) != KErrNotFound
       
   493             || iAppsArray->MdcaPoint(iAppLaunchCounter).FindF(_L("\\Startup.")) != KErrNotFound  
       
   494             || iAppsArray->MdcaPoint(iAppLaunchCounter).FindF(_L("\\SplashScreen.")) != KErrNotFound  
       
   495             || iAppsArray->MdcaPoint(iAppLaunchCounter).FindF(_L("\\eshell.")) != KErrNotFound)  
       
   496             {
       
   497             iContainerOutput->PrintTextL(iCurrentAppNameAndExt);
       
   498             iContainerOutput->PrintTextL(_L(": SKIPPED automatically\n"));
       
   499 
       
   500             iLogWriteBuf->Des().Append(_L("[SKIPPED automatically] "));
       
   501             iLogWriteBuf->Des().Append(KFileNewLine);
       
   502             iLogFile.Write(iLogWriteBuf->Des());
       
   503 
       
   504             iSkippedCases++;
       
   505             CheckForMoreAppsL();
       
   506             }
       
   507 
       
   508         else
       
   509             {
       
   510 
       
   511             // dependency check not needed if the app is in the ROM/ROFS, because they'll be checked automatically
       
   512             // when the rom image is built
       
   513             
       
   514             if (iCurrentAppNameAndExt[0] != 'Z' && iCurrentAppNameAndExt[0] != 'z')
       
   515                 {
       
   516 
       
   517                 if (iCurrentAppNameAndExt[2] == '[')  // this is quite likely a Java application, no dependency test needed 
       
   518                     {
       
   519                     iLogWriteBuf->Des().Append(_L("[Dependency check not done] "));
       
   520                     }
       
   521                 else
       
   522                     {  // otherwise check depencies
       
   523                 
       
   524                     #ifdef __WINS__
       
   525                     
       
   526                         // emulator not supported
       
   527 
       
   528                     #else
       
   529 
       
   530                         // ELF binaries
       
   531 
       
   532                         CDesCArray* missingDllArray = NULL;
       
   533 
       
   534                         TRAPD(err, missingDllArray = DependencyCheckForE32ImageL());
       
   535 
       
   536                         // some error happened while processing the E32 image
       
   537                         if (err != KErrNone)
       
   538                             {
       
   539                             iContainerOutput->PrintTextL(iCurrentAppNameAndExt);
       
   540                             iContainerOutput->PrintTextL(_L(": unable to read import table!\n"));
       
   541 
       
   542                             iLogWriteBuf->Des().Append(_L("[Unable to read import table!] "));
       
   543                             }
       
   544 
       
   545                         // print missing dependencies
       
   546                         else if (err==KErrNone && missingDllArray)
       
   547                             {
       
   548                             if (missingDllArray->MdcaCount() > 0)
       
   549                                 {
       
   550                                 iContainerOutput->PrintTextL(iCurrentAppNameAndExt);
       
   551                                 iContainerOutput->PrintTextL(_L(": missing dependencies: "));
       
   552                                 iLogWriteBuf->Des().Append(_L("[Missing dependencies: "));
       
   553 
       
   554                                 for (TInt k=0; k<missingDllArray->MdcaCount(); k++)
       
   555                                     {
       
   556                                     iContainerOutput->PrintTextL(missingDllArray->MdcaPoint(k));
       
   557                                     iContainerOutput->PrintTextL(_L(" "));
       
   558 
       
   559                                     iLogWriteBuf->Des().Append(missingDllArray->MdcaPoint(k));
       
   560                                     iLogWriteBuf->Des().Append(_L(" "));
       
   561                                     }
       
   562 
       
   563                                 iContainerOutput->PrintTextL(_L("\n"));
       
   564                                 iLogWriteBuf->Des().Append(_L("] "));
       
   565                                 }
       
   566                             }
       
   567 
       
   568                         if (missingDllArray)
       
   569                             delete missingDllArray;
       
   570 
       
   571                     #endif
       
   572 
       
   573                     }  // if '['
       
   574                 }  // if 'Z'
       
   575 
       
   576 
       
   577 
       
   578             // check if the app is already running
       
   579             TApaTaskList taskList(iWs);
       
   580             TApaTask thisTask = taskList.FindApp(iCurrentAppUid);
       
   581             if (thisTask.Exists())
       
   582                 {
       
   583                 iLogWriteBuf->Des().Append(_L(" [OK: App already running]"));
       
   584                 iLogWriteBuf->Des().Append(KFileNewLine);
       
   585                 iLogFile.Write(iLogWriteBuf->Des());
       
   586 
       
   587                 iOkCases++;
       
   588                 CheckForMoreAppsL();
       
   589                 }
       
   590             
       
   591             else
       
   592                 {
       
   593                 // check the program's capabilities
       
   594                 TApaAppCapabilityBuf buf;
       
   595                 iLs.GetAppCapability(buf, iCurrentAppUid);
       
   596                 TApaAppCapability cap = buf();
       
   597 
       
   598                 // if it's embeddable only, don't launch if setting is enabled
       
   599                 if (cap.iEmbeddability == TApaAppCapability::EEmbeddableOnly && SkipHiddenAndEmbedOnly())  
       
   600                     {
       
   601                     iContainerOutput->PrintTextL(iCurrentAppNameAndExt);
       
   602                     iContainerOutput->PrintTextL(_L(": SKIPPED: embeddable only\n"));
       
   603 
       
   604                     iLogWriteBuf->Des().Append(_L("[SKIPPED: embeddable only] "));
       
   605                     iLogWriteBuf->Des().Append(KFileNewLine);
       
   606                     iLogFile.Write(iLogWriteBuf->Des());
       
   607 
       
   608                     iSkippedCases++;
       
   609                     CheckForMoreAppsL();
       
   610                     }
       
   611             
       
   612                 // if it's hidden, don't launch if setting is enabled
       
   613                 else if (cap.iAppIsHidden && SkipHiddenAndEmbedOnly())  
       
   614                     {
       
   615                     iContainerOutput->PrintTextL(iCurrentAppNameAndExt);
       
   616                     iContainerOutput->PrintTextL(_L(": SKIPPED: hidden\n"));
       
   617 
       
   618                     iLogWriteBuf->Des().Append(_L("[SKIPPED: hidden] "));
       
   619                     iLogWriteBuf->Des().Append(KFileNewLine);
       
   620                     iLogFile.Write(iLogWriteBuf->Des());
       
   621 
       
   622                     iSkippedCases++;
       
   623                     CheckForMoreAppsL();
       
   624                     }
       
   625 
       
   626                 // otherwise do the normal launch test
       
   627                 else
       
   628                     {
       
   629                     LaunchApplicationL();
       
   630                     }
       
   631                 
       
   632                 } //if (thisTask.Exists())
       
   633             
       
   634             } //if (iAppsArray->MdcaPoint(iAppLaunchCounter).FindF
       
   635         }
       
   636     }
       
   637 
       
   638 // ---------------------------------------------------------------------------
       
   639 
       
   640 void CLauncherEngine::CheckIfAppIsRunningL()
       
   641     {
       
   642     LOGSTRING("Launcher: CLauncherEngine::CheckIfAppIsRunningL");
       
   643 
       
   644     // cancel the death notifier since it isn't needed anymore
       
   645     if( iCurrentAppThread.Handle() != 0 )
       
   646         {
       
   647         iCurrentAppThread.LogonCancel(iAppThreadChecker->iStatus);
       
   648         }
       
   649 
       
   650     // cancel checkers
       
   651     iAppThreadChecker->Cancel();
       
   652     iAppRunningChecker->Cancel(); 
       
   653 
       
   654 
       
   655 
       
   656     // check from the window server if the app is running
       
   657     TApaTaskList taskList(iWs);
       
   658     TApaTask thisTask = taskList.FindApp(iCurrentAppUid);
       
   659 
       
   660     if( !thisTask.Exists() ) // application not running -> FAIL
       
   661         {
       
   662         // check from the thread why it quit
       
   663         CheckWhyThreadDiedL();
       
   664 
       
   665         // --> CheckForMoreApps() and all the other stuff called from CheckWhyThreadDied() !
       
   666 
       
   667         }
       
   668     else
       
   669         {
       
   670         // app is running!
       
   671         iOkCases++;
       
   672 
       
   673         // close handle to the thread        
       
   674         iCurrentAppThread.Close();
       
   675 
       
   676 
       
   677         iLogWriteBuf->Des().Append(_L(" [OK]"));
       
   678         iLogWriteBuf->Des().Append(KFileNewLine);        
       
   679         iLogFile.Write(iLogWriteBuf->Des());
       
   680 
       
   681 
       
   682         // close the running application if needed
       
   683         if (iAutoClose)
       
   684             {
       
   685             // since the application is still open, let's close it
       
   686             thisTask.EndTask();
       
   687             //User::After(1000);
       
   688             //thisTask.SendSystemEvent(EApaSystemEventShutdown);
       
   689             //thisTask.KillTask();
       
   690             //User::After(1000);
       
   691             }
       
   692 
       
   693         // this app is done now, move to the next one!
       
   694         CheckForMoreAppsL();
       
   695                 
       
   696         }    
       
   697     }
       
   698 
       
   699 // ---------------------------------------------------------------------------
       
   700 
       
   701 void CLauncherEngine::CheckWhyThreadDiedL()
       
   702     {
       
   703     LOGSTRING("Launcher: CLauncherEngine::CheckWhyThreadDiedL");
       
   704 
       
   705     // cancel the death notifier since it isn't needed anymore
       
   706     if( iCurrentAppThread.Handle() != 0 )
       
   707         {
       
   708         iCurrentAppThread.LogonCancel(iAppThreadChecker->iStatus);
       
   709         }
       
   710 
       
   711     // make sure all checkers are cancelled
       
   712     iAppRunningChecker->Cancel(); 
       
   713     iAppThreadChecker->Cancel(); 
       
   714 
       
   715     TBuf<256> outputText;
       
   716     outputText.Append(_L("App.Closed. "));
       
   717 
       
   718 
       
   719     if (iCurrentAppThread.ExitType() == EExitKill)
       
   720         {
       
   721         outputText.Append(_L("\"EExitKill\""));
       
   722         }
       
   723     else if (iCurrentAppThread.ExitType() == EExitTerminate)
       
   724         {
       
   725         outputText.Append(_L("\"EExitTerminate\""));
       
   726         }
       
   727     else if (iCurrentAppThread.ExitType() == EExitPanic)
       
   728         {
       
   729         outputText.Append(_L("\"EExitPanic\""));
       
   730         }
       
   731     else if (iCurrentAppThread.ExitType() == EExitPending)
       
   732         {
       
   733         outputText.Append(_L("\"EExitPending\""));
       
   734         }
       
   735     else // unknown reason
       
   736         {
       
   737         outputText.Append(_L("\"Exit_Unknown_Reason\""));
       
   738         }        
       
   739     
       
   740     outputText.Append(_L(" code:"));
       
   741     TInt exitReason = iCurrentAppThread.ExitReason();
       
   742     outputText.AppendNum(exitReason);
       
   743     outputText.Append(_L(" \""));
       
   744 
       
   745     TPtrC exitCategory = iCurrentAppThread.ExitCategory();
       
   746     outputText.Append(exitCategory);
       
   747 
       
   748     outputText.Append(_L("\""));
       
   749 
       
   750 
       
   751     // print to screen
       
   752     iContainerOutput->PrintTextL(iCurrentAppNameAndExt);
       
   753     iContainerOutput->PrintTextL(_L(": "));
       
   754     iContainerOutput->PrintTextL(outputText);
       
   755     iContainerOutput->PrintTextL(_L("\n"));
       
   756 
       
   757     // write to the log also
       
   758     iLogWriteBuf->Des().Append(_L(" [FAIL: "));
       
   759     iLogWriteBuf->Des().Append(outputText);
       
   760     iLogWriteBuf->Des().Append(_L("]"));
       
   761     iLogWriteBuf->Des().Append(KFileNewLine);
       
   762     
       
   763     iLogFile.Write(iLogWriteBuf->Des());
       
   764 
       
   765     // close handle to the thread
       
   766     //iCurrentAppThread.Close();    <-- not safe the close the handle because of the "App.Closed" dialog
       
   767     //                                  somehow takes ownership of the thread or something
       
   768 
       
   769     // nothing to do anymore, move to the next app
       
   770     iFailedCases++;
       
   771     CheckForMoreAppsL();
       
   772     }
       
   773 
       
   774 // ---------------------------------------------------------------------------
       
   775 
       
   776 void CLauncherEngine::CheckForMoreAppsL()
       
   777     {
       
   778     LOGSTRING("Launcher: CLauncherEngine::CheckForMoreAppsL");
       
   779 
       
   780     // make sure the launcher app is in the foreground
       
   781     TApaTaskList taskList(iWs);
       
   782     TUid launcherAppUid;
       
   783     launcherAppUid.iUid = 0x101FB74F;
       
   784     TApaTask launcherTask = taskList.FindApp(launcherAppUid);
       
   785     launcherTask.BringToForeground();
       
   786 
       
   787 
       
   788     // check if we have more test to be executed
       
   789     if ( iAppLaunchCounter >= iTotalNumberOfCases-1 )
       
   790         {
       
   791         
       
   792         // all done, show stats
       
   793         TBuf<200> message;
       
   794         message.Append( _L("Done: ") );
       
   795         message.AppendNum( iOkCases );
       
   796         message.Append( _L(" ok, ") );
       
   797         message.AppendNum( iFailedCases );
       
   798         message.Append( _L(" failed, ") );
       
   799         message.AppendNum( iSkippedCases );
       
   800         message.Append( _L(" skipped.") );
       
   801 
       
   802         // print the message to the output screen
       
   803         iContainerOutput->PrintTextL(message);
       
   804         iContainerOutput->PrintTextL(_L("\n\n"));
       
   805 
       
   806         //write same stuff to the log
       
   807         WriteInitialStuffToTheLogL(message, iLogFile);
       
   808         iLogWriteBuf->Des().Copy(KFileNewLine);
       
   809         iLogWriteBuf->Des().Append(KFileNewLine);        
       
   810         iLogFile.Write(iLogWriteBuf->Des());
       
   811 
       
   812         // close the log
       
   813         iLogFile.Close();
       
   814 
       
   815         iLaunchingIsActive = EFalse;
       
   816 
       
   817         _LIT(KAllDoneMessage, "All apps launched");
       
   818         CAknConfirmationNote* confirmationNote = new(ELeave) CAknConfirmationNote;
       
   819         confirmationNote->ExecuteLD(KAllDoneMessage);
       
   820 
       
   821         }
       
   822     else
       
   823         {
       
   824         // more apps to be launched, maintain requests
       
   825         iAppLaunchCounter++;
       
   826         IssueLaunch();
       
   827         }
       
   828   
       
   829     }
       
   830 
       
   831 // ---------------------------------------------------------------------------
       
   832 
       
   833 void CLauncherEngine::DoCancel()
       
   834     {
       
   835     LOGSTRING("Launcher: CLauncherEngine::DoCancel");
       
   836     
       
   837     if( iXMLParser )
       
   838         {
       
   839         iXMLParser->Cancel();
       
   840         }
       
   841     iTimer.Cancel();
       
   842     }
       
   843 
       
   844 // ---------------------------------------------------------------------------
       
   845 
       
   846 void CLauncherEngine::LaunchApplicationL()
       
   847     {
       
   848     LOGSTRING("Launcher: CLauncherEngine::LaunchApplication");
       
   849     LOGSTRING3("Launcher: Trying to launch %S, UID: %d", &iCurrentAppNameAndExt, iCurrentAppUid.iUid);
       
   850 
       
   851     TRAPD(err, DoLaunchApplicationL());
       
   852     
       
   853     if (err!=KErrNone)
       
   854         {
       
   855         iLogWriteBuf->Des().Append(_L("[FAIL: Cannot launch the app] "));        
       
   856         
       
   857         iContainerOutput->PrintTextL(iCurrentAppNameAndExt);
       
   858         iContainerOutput->PrintTextL(_L(": cannot launch\n"));
       
   859 
       
   860         // write the buffer to the log
       
   861         iLogWriteBuf->Des().Append(KFileNewLine);        
       
   862         iLogFile.Write(iLogWriteBuf->Des());
       
   863 
       
   864         // this application isn't even launchable, go to next one
       
   865         iFailedCases++;
       
   866         CheckForMoreAppsL();        
       
   867         }
       
   868     
       
   869     }
       
   870 // ---------------------------------------------------------------------------
       
   871 
       
   872 void CLauncherEngine::DoLaunchApplicationL()
       
   873     {
       
   874     LOGSTRING("Launcher: CLauncherEngine::DoLaunchApplicationL");
       
   875 
       
   876     // create a new handle
       
   877     RThread newThreadHandle;
       
   878     iCurrentAppThread = newThreadHandle;
       
   879 
       
   880 
       
   881     // Find the task with uid3
       
   882     TApaTaskList tasklist(iWs);
       
   883     TApaTask task=tasklist.FindApp(iCurrentAppUid);
       
   884 
       
   885     if (task.Exists())
       
   886         // Task exists, bring it to foreground
       
   887         {
       
   888         task.BringToForeground();
       
   889         }
       
   890     else
       
   891         // Task doesn't exist, launch a new instance of an application
       
   892         {
       
   893         TApaAppInfo appInfo;
       
   894         User::LeaveIfError(iLs.GetAppInfo(appInfo, iCurrentAppUid));
       
   895         TApaAppCapabilityBuf capBuf;
       
   896         User::LeaveIfError(iLs.GetAppCapability(capBuf, iCurrentAppUid));
       
   897         TApaAppCapability& caps = capBuf();
       
   898 
       
   899         CApaCommandLine* cmdLine=CApaCommandLine::NewLC();
       
   900         cmdLine->SetExecutableNameL(appInfo.iFullName);
       
   901 
       
   902         if ( caps.iLaunchInBackground )
       
   903             // Apps capability defines that the app is launched in background
       
   904             {
       
   905             cmdLine->SetCommandL(EApaCommandBackground);
       
   906             }
       
   907         else
       
   908             {
       
   909             cmdLine->SetCommandL(EApaCommandRun);
       
   910             }
       
   911 
       
   912         // start the app
       
   913         User::LeaveIfError(iLs.StartApp(*cmdLine, iCurrentAppThreadId));
       
   914 
       
   915         // activate thread checker active object
       
   916         iAppThreadChecker->ActivateChecking();
       
   917 
       
   918         // now open a handle to the thread and register death notifier
       
   919         TInt err = iCurrentAppThread.Open(iCurrentAppThreadId);
       
   920         if (err == KErrNone)
       
   921             iCurrentAppThread.Logon(iAppThreadChecker->iStatus);
       
   922         else
       
   923             {
       
   924             iCurrentAppThread.Close();
       
   925             TRequestStatus* status = &iAppThreadChecker->iStatus;
       
   926             User::RequestComplete(status, KErrNone);
       
   927             iAppThreadChecker->Cancel();
       
   928             User::Leave(err);                
       
   929             }
       
   930 
       
   931         CleanupStack::PopAndDestroy(); // cmdLine
       
   932         }
       
   933 
       
   934     // the application is now running, start a check to see if it's still alive
       
   935     iAppRunningChecker->StartTesting(); 
       
   936 
       
   937     }
       
   938 
       
   939 // ---------------------------------------------------------------------------
       
   940 
       
   941 void CLauncherEngine::StopLaunchingL()
       
   942     {
       
   943     LOGSTRING("Launcher: CLauncherEngine::StopLaunchingL");
       
   944 
       
   945     //write to the log
       
   946     WriteInitialStuffToTheLogL(_L("Cancelled by the user !!! "), iLogFile);
       
   947     iLogWriteBuf->Des().Copy(KFileNewLine);
       
   948     iLogWriteBuf->Des().Append(KFileNewLine);
       
   949     iLogFile.Write(iLogWriteBuf->Des());
       
   950 
       
   951     // close the log
       
   952     iLogFile.Close();
       
   953 
       
   954     // print to the screen
       
   955     iContainerOutput->PrintTextL(_L("Launching cancelled.\n\n"));
       
   956 
       
   957     // cancel all active objects
       
   958     if( iCurrentAppThread.Handle() != 0 )
       
   959         {
       
   960         iCurrentAppThread.LogonCancel(iAppThreadChecker->iStatus);
       
   961         }
       
   962     Cancel();
       
   963     iAppRunningChecker->Cancel(); 
       
   964     iAppThreadChecker->Cancel(); 
       
   965     
       
   966     iLaunchingIsActive = EFalse;
       
   967 
       
   968     _LIT(KMessage, "Launching cancelled");
       
   969     CAknInformationNote* confirmationNote = new(ELeave) CAknInformationNote;
       
   970     confirmationNote->ExecuteLD(KMessage);
       
   971     }
       
   972 
       
   973 // ---------------------------------------------------------------------------
       
   974 
       
   975 CDesCArray* CLauncherEngine::DependencyCheckForE32ImageL()
       
   976     {
       
   977     LOGSTRING("Launcher: CLauncherEngine::DependencyCheckForE32ImageL");
       
   978 
       
   979     // create an empty array for the missing dll names
       
   980     CDesCArray* missingDllArray = new(ELeave) CDesCArrayFlat(100);
       
   981     CleanupStack::PushL(missingDllArray);
       
   982 
       
   983     // get a list of DLLs from the E32 image file
       
   984     E32ImageReader* reader = E32ImageReader::NewLC();
       
   985     CDesCArray* dllArray = reader->ListOfDLLsL( iAppsArray->MdcaPoint(iAppLaunchCounter) );
       
   986     CleanupStack::PopAndDestroy(); // reader
       
   987     CleanupStack::PushL(dllArray);
       
   988 
       
   989     // compare system DLL and image DLL arrays
       
   990     TInt pos(0);
       
   991     for (TInt j=0; j<dllArray->MdcaCount(); j++)
       
   992         {
       
   993         if (iSystemDllArray->Find(dllArray->MdcaPoint(j), pos, ECmpFolded) != 0)  
       
   994             {
       
   995             // DLL not found, append the name to the list of missing DLLs
       
   996             missingDllArray->AppendL(dllArray->MdcaPoint(j));  
       
   997             }
       
   998         }
       
   999 
       
  1000     CleanupStack::PopAndDestroy(); // dllArray
       
  1001     CleanupStack::Pop();  // missingDllArray
       
  1002 
       
  1003     LOGSTRING("Launcher: CLauncherEngine::DependencyCheckForE32ImageL returns");
       
  1004 
       
  1005     return missingDllArray;
       
  1006     }
       
  1007 
       
  1008 // ---------------------------------------------------------------------------
       
  1009 
       
  1010 void CLauncherEngine::WriteInitialStuffToTheLogL(const TDesC& aOwnData, RFile& aFile)
       
  1011     {
       
  1012     LOGSTRING("Launcher: CLauncherEngine::WriteInitialStuffToTheLog");
       
  1013 
       
  1014     TTime time;
       
  1015     time.HomeTime();
       
  1016     TBuf<32> currentTime;
       
  1017     TBuf<32> currentDate;
       
  1018 
       
  1019     // current date            
       
  1020     _LIT(KCurrentDate,"%D%M%Y%/0%1%/1%2%/2%3%/3");
       
  1021     time.FormatL(currentDate, KCurrentDate);    
       
  1022     iLogWriteBuf->Des().Copy(currentDate);    
       
  1023     AppendLogBufferL(KFileSeparator(), iLogWriteBuf);
       
  1024 
       
  1025     // current time
       
  1026     _LIT(KCurrentTime,"%-B%:0%J%:1%T%:2%S%:3%+B");
       
  1027     time.FormatL(currentTime, KCurrentTime);    
       
  1028     AppendLogBufferL(currentTime, iLogWriteBuf);
       
  1029     AppendLogBufferL(KFileSeparator(), iLogWriteBuf);
       
  1030 
       
  1031     // available RAM memory
       
  1032     TMemoryInfoV1Buf memory;
       
  1033     UserHal::MemoryInfo(memory);
       
  1034     iLogWriteBuf->Des().AppendNum(memory().iFreeRamInBytes);  
       
  1035     AppendLogBufferL(KFileSeparator(), iLogWriteBuf);
       
  1036 
       
  1037     // own data, eg. application name
       
  1038     AppendLogBufferL(aOwnData, iLogWriteBuf);
       
  1039     AppendLogBufferL(KFileSeparator(), iLogWriteBuf);
       
  1040     AppendLogBufferL(KFileNewLine(), iLogWriteBuf);    
       
  1041 
       
  1042     // write the buffer to the file
       
  1043     aFile.Write(iLogWriteBuf->Des()); 
       
  1044 
       
  1045     // clear the buffer
       
  1046     iLogWriteBuf->Des().Copy(_L(""));
       
  1047     }
       
  1048 
       
  1049 // ---------------------------------------------------------------------------
       
  1050 
       
  1051 TInt CLauncherEngine::DeleteLogFile()
       
  1052     {
       
  1053     LOGSTRING("Launcher: CLauncherEngine::DeleteLogFile");
       
  1054     return BaflUtils::DeleteFile(iEnv->FsSession(), iLogFilePath);
       
  1055     }
       
  1056 
       
  1057 // ---------------------------------------------------------------------------
       
  1058 
       
  1059 TInt CLauncherEngine::DeleteBCLogFile()
       
  1060     {
       
  1061     LOGSTRING("Launcher: CLauncherEngine::DeleteBCLogFile");
       
  1062     return BaflUtils::DeleteFile(iEnv->FsSession(), iBCLogFilePath);
       
  1063     }
       
  1064 
       
  1065 // ---------------------------------------------------------------------------
       
  1066 
       
  1067 TBool CLauncherEngine::LogFileExists()
       
  1068     {
       
  1069     LOGSTRING("Launcher: CLauncherEngine::LogFileExists");
       
  1070     return BaflUtils::FileExists(iEnv->FsSession(), iLogFilePath);
       
  1071     }
       
  1072 
       
  1073 // ---------------------------------------------------------------------------
       
  1074 
       
  1075 TBool CLauncherEngine::BCLogFileExists()
       
  1076     {
       
  1077     LOGSTRING("Launcher: CLauncherEngine::BCLogFileExists");
       
  1078     return BaflUtils::FileExists(iEnv->FsSession(), iBCLogFilePath);
       
  1079     }
       
  1080 
       
  1081 // ---------------------------------------------------------------------------
       
  1082 
       
  1083 void CLauncherEngine::DialogDismissedL( TInt aButtonId )
       
  1084     {
       
  1085     LOGSTRING2("Launcher: CLauncherEngine::DialogDismissedL - Button id: %d", aButtonId);    
       
  1086     iWaitDialog = 0;
       
  1087     iDLLAnalysisIsActive = EFalse;
       
  1088     _LIT(KAnalysisCancelled, "DLL Analysis cancelled");
       
  1089     if( IsActive() )
       
  1090         {
       
  1091         Cancel();
       
  1092         }
       
  1093     if( iXMLParser )
       
  1094         {
       
  1095         iXMLParser->Cancel();
       
  1096         }
       
  1097     if( aButtonId == EAknSoftkeyCancel )
       
  1098         {
       
  1099         iContainerOutput->PrintTextL( KNewLine );
       
  1100         iContainerOutput->PrintTextL( KAnalysisCancelled );
       
  1101         iContainerOutput->PrintTextL( KNewLine );
       
  1102         if( iLogWriteBuf )
       
  1103             {
       
  1104             AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1105             AppendLogBufferL(KAnalysisCancelled(), iLogWriteBuf);
       
  1106             AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1107             if( iBCLogFile.SubSessionHandle() != 0)
       
  1108                 {
       
  1109                 iBCLogFile.Write(iLogWriteBuf->Des());
       
  1110                 }
       
  1111             iLogWriteBuf->Des().Zero();
       
  1112             }
       
  1113         iBCLogFile.Close();
       
  1114         }        
       
  1115     }
       
  1116 
       
  1117 // ---------------------------------------------------------------------------
       
  1118 
       
  1119 TBool CLauncherEngine::SelectRequiredDLLsFileL()
       
  1120     {
       
  1121     LOGSTRING("Launcher: CLauncherEngine::SelectRequiredDLLsFile");
       
  1122     _LIT(KMessage, "Please, select input file for BC analysis");
       
  1123     CAknInformationNote* infoNote = new(ELeave) CAknInformationNote(ETrue);
       
  1124     infoNote->ExecuteLD(KMessage);    
       
  1125     return AknCommonDialogs::RunSelectDlgLD( iRequiredDllsFilePath, R_MEMORY_SELECTION_DIALOG, R_FILE_SELECTION_DIALOG);
       
  1126     }
       
  1127 
       
  1128 // ---------------------------------------------------------------------------
       
  1129 
       
  1130 void CLauncherEngine::DoBCAnalysisL()
       
  1131     {
       
  1132     LOGSTRING("Launcher: CLauncherEngine::DoBCAnalysisL");
       
  1133     if( iXMLParser == 0 )
       
  1134         {
       
  1135         iXMLParser = CLauncherXMLParser::NewL(iEnv->FsSession());
       
  1136         }
       
  1137     
       
  1138     delete iWaitDialog;
       
  1139     iWaitDialog = 0;    
       
  1140     iXMLParser->ParseL(iRequiredDllsFilePath,this);
       
  1141     iDLLAnalysisIsActive = ETrue;
       
  1142     
       
  1143     // some delay
       
  1144     iTimer.After(iStatus, 500000);
       
  1145     SetActive();
       
  1146     }
       
  1147 
       
  1148 // ---------------------------------------------------------------------------
       
  1149 
       
  1150 void CLauncherEngine::AnalyseDLLsL()
       
  1151     {
       
  1152     LOGSTRING("Launcher: CLauncherEngine::AnalyseDLLsL");
       
  1153     _LIT(KStartSeparator, "******************************");
       
  1154     _LIT(KStartingAnalysis, "Starting BC Analysis for DLLs.");    
       
  1155     _LIT(KInputFileSelected, "Input file selected: ");
       
  1156     
       
  1157     // Reset found issues counter and buffer
       
  1158     iFoundBCIssues = 0;    
       
  1159     delete iBCIssuesBigBuffer;
       
  1160     iBCIssuesBigBuffer = 0;
       
  1161     
       
  1162     // Reset log writing buffer:
       
  1163     iLogWriteBuf->Des().Zero();
       
  1164                 
       
  1165     if( IsActive() )
       
  1166         {
       
  1167         Cancel();
       
  1168         }           
       
  1169    
       
  1170     if( !SelectRequiredDLLsFileL() )
       
  1171         {        
       
  1172         return; // Input file selection cancelled
       
  1173         }
       
  1174     
       
  1175     // open the log file for writing
       
  1176     if (iBCLogFile.Open(iEnv->FsSession(), iBCLogFilePath, EFileWrite) != KErrNone)
       
  1177         {
       
  1178         iEnv->FsSession().MkDirAll(iLogFilePath);
       
  1179         iBCLogFile.Replace(iEnv->FsSession(), iBCLogFilePath, EFileWrite);
       
  1180         }
       
  1181     else
       
  1182         {
       
  1183         // file opens correctly, seek to the end
       
  1184         TInt fileSize=0;
       
  1185         iBCLogFile.Size(fileSize);
       
  1186         iBCLogFile.Seek(ESeekCurrent, fileSize);
       
  1187         }
       
  1188     
       
  1189     AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1190     AppendLogBufferL(KStartSeparator(), iLogWriteBuf);
       
  1191     AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1192     iBCLogFile.Write(iLogWriteBuf->Des());
       
  1193     iLogWriteBuf->Des().Zero();
       
  1194     
       
  1195     // Resolve file type. Should we use XML parsing or just compare DLL list
       
  1196     TBool xmlParsing =
       
  1197         KDotXML().Compare(iRequiredDllsFilePath.Right(KDotXML().Length())) == 0 ||
       
  1198         KDotLauncherXML().Compare(iRequiredDllsFilePath.Right(KDotLauncherXML().Length())) == 0;
       
  1199     
       
  1200     // Log analysis starting time and selected input file:
       
  1201     WriteInitialStuffToTheLogL(KStartingAnalysis, iBCLogFile);    
       
  1202     AppendLogBufferL(KInputFileSelected(), iLogWriteBuf);
       
  1203     AppendLogBufferL(iRequiredDllsFilePath, iLogWriteBuf);
       
  1204     AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1205     iBCLogFile.Write(iLogWriteBuf->Des());
       
  1206     iLogWriteBuf->Des().Zero();
       
  1207     
       
  1208     if( xmlParsing )
       
  1209         {
       
  1210         ChangeFocusToOutputView();
       
  1211         DoBCAnalysisL();
       
  1212         }
       
  1213     else
       
  1214         {
       
  1215         DoCompareDLLListsL();
       
  1216         }
       
  1217     }
       
  1218 
       
  1219 // ---------------------------------------------------------------------------
       
  1220 
       
  1221 void CLauncherEngine::DoCompareDLLListsL()
       
  1222     {
       
  1223     LOGSTRING("Launcher: CLauncherEngine::DoCompareDLLListsL");
       
  1224     RFile file;
       
  1225     CleanupClosePushL(file);
       
  1226     
       
  1227     if(file.Open(iEnv->FsSession(), iRequiredDllsFilePath, EFileRead) != KErrNone)
       
  1228         {
       
  1229         ChangeFocusToOutputView();
       
  1230 
       
  1231         TBuf<200> msg;
       
  1232         msg.Format(_L("Unable to open %S for reading!\n\n"), &iRequiredDllsFilePath);
       
  1233         iContainerOutput->PrintTextL( msg );
       
  1234         }
       
  1235     else
       
  1236         {
       
  1237         CDesCArray* requiredDllArray = new(ELeave) CDesCArrayFlat(KMaxDllArraySize);
       
  1238         CleanupStack::PushL(requiredDllArray);
       
  1239 
       
  1240         // read all lines the text file
       
  1241         TFileName dllName;
       
  1242         TInt i(0);
       
  1243         while( ReadLineFromFileL(file, dllName) == KErrNone && i<KMaxDllArraySize )
       
  1244             {
       
  1245             dllName.TrimAll();
       
  1246 
       
  1247             if (dllName.Length() > 1)
       
  1248                 requiredDllArray->AppendL(dllName);
       
  1249             
       
  1250             i++;
       
  1251             }
       
  1252 
       
  1253         if (requiredDllArray->MdcaCount() == 0)
       
  1254             {
       
  1255             ChangeFocusToOutputView();
       
  1256 
       
  1257             TBuf<200> msg;
       
  1258             msg.Format(_L("File %S is empty!\n\n"), &iRequiredDllsFilePath);
       
  1259             iContainerOutput->PrintTextL( msg );
       
  1260             }
       
  1261         else
       
  1262             {
       
  1263             // compare the arrays and print any missing items
       
  1264             CDesCArray* missingDllArray = new(ELeave) CDesCArrayFlat(KMaxDllArraySize);
       
  1265             CleanupStack::PushL(missingDllArray);
       
  1266 
       
  1267             TInt pos(0);
       
  1268             for (TInt j=0; j<requiredDllArray->MdcaCount(); j++)
       
  1269                 {
       
  1270                 if (iSystemDllArray->Find(requiredDllArray->MdcaPoint(j), pos, ECmpFolded) != 0)  
       
  1271                     {
       
  1272                     // DLL not found, append the name to the list of missing DLLs
       
  1273                     missingDllArray->AppendL(requiredDllArray->MdcaPoint(j));  
       
  1274                     }
       
  1275                 }
       
  1276 
       
  1277             if (missingDllArray->MdcaCount() == 0)
       
  1278                 {
       
  1279                 _LIT(KMessage, "No missing files found");
       
  1280                 AppendLogBufferL(KMessage(), iLogWriteBuf);
       
  1281                 CAknInformationNote* note = new(ELeave) CAknInformationNote;
       
  1282                 note->ExecuteLD(KMessage);
       
  1283                 }
       
  1284             else
       
  1285                 {
       
  1286                 ChangeFocusToOutputView();
       
  1287                 _LIT(KMissingFiles, "Missing files:\n");
       
  1288 
       
  1289                 iContainerOutput->PrintTextL( KMissingFiles );
       
  1290                 AppendLogBufferL(KMissingFiles(), iLogWriteBuf);
       
  1291                 
       
  1292                 for (TInt i=0; i<missingDllArray->MdcaCount(); i++)
       
  1293                     {
       
  1294                     iContainerOutput->PrintTextL( missingDllArray->MdcaPoint(i) );                    
       
  1295                     iContainerOutput->PrintTextL( _L("\n") );           
       
  1296                     AppendLogBufferL(missingDllArray->MdcaPoint(i), iLogWriteBuf);
       
  1297                     AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1298                     }
       
  1299 
       
  1300                 iContainerOutput->PrintTextL( _L("\n") );
       
  1301                 }
       
  1302 
       
  1303             CleanupStack::PopAndDestroy(); // missingDllArray            
       
  1304             }
       
  1305 
       
  1306         CleanupStack::PopAndDestroy(); // requiredDllArray
       
  1307         }
       
  1308 
       
  1309     CleanupStack::PopAndDestroy(); //file
       
  1310     iBCLogFile.Write(iLogWriteBuf->Des());
       
  1311     iLogWriteBuf->Des().Zero();
       
  1312     iBCLogFile.Close();
       
  1313     }
       
  1314 
       
  1315 // ---------------------------------------------------------------------------
       
  1316 
       
  1317 void CLauncherEngine::ParsingProgressedL(TInt aBytes)
       
  1318     {
       
  1319     LOGSTRING2("Launcher: CLauncherEngine::ParsingProgressedL - Bytes: %d", aBytes);
       
  1320     if (iProgressInfo && aBytes > 0 )
       
  1321         {
       
  1322         iProgressInfo->SetAndDraw(aBytes);
       
  1323         }
       
  1324     }
       
  1325 
       
  1326 // ---------------------------------------------------------------------------
       
  1327 
       
  1328 void CLauncherEngine::DocumentParsedL(TInt aErrorCode)
       
  1329     {            
       
  1330     LOGSTRING2("Launcher: CLauncherEngine::DocumentParsedL (Error code: %d)", aErrorCode);
       
  1331         
       
  1332     iDLLAnalysisIsActive = EFalse;
       
  1333     _LIT(KParseError, "Parse error: ");
       
  1334     _LIT(KNoIssues, "No binary compatibility issues found");
       
  1335     
       
  1336     if( IsActive() )
       
  1337         {
       
  1338         Cancel();
       
  1339         }
       
  1340             
       
  1341     if( iWaitDialog )
       
  1342         {
       
  1343         iWaitDialog->ProcessFinishedL();
       
  1344         iWaitDialog = 0;
       
  1345         }
       
  1346         
       
  1347     if( aErrorCode != KErrNone )
       
  1348         {
       
  1349         TBuf<16> errorCodeString;
       
  1350         errorCodeString.AppendNum(aErrorCode);
       
  1351         iContainerOutput->PrintTextL( KNewLine );
       
  1352         iContainerOutput->PrintTextL( KParseError );
       
  1353         iContainerOutput->PrintTextL( errorCodeString );
       
  1354         iContainerOutput->PrintTextL( KNewLine );        
       
  1355         AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1356         AppendLogBufferL(KParseError(), iLogWriteBuf);
       
  1357         AppendLogBufferL(errorCodeString, iLogWriteBuf);
       
  1358         AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1359         }
       
  1360     else if(iFoundBCIssues == 0)
       
  1361         {
       
  1362         iContainerOutput->PrintTextL( KNoIssues );
       
  1363         iContainerOutput->PrintTextL( KNewLine );        
       
  1364         AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1365         AppendLogBufferL(KNoIssues(), iLogWriteBuf);
       
  1366         AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1367         }
       
  1368     else if( iBCIssuesBigBuffer && iBCIssuesBigBuffer->Des().Length() > 0 )
       
  1369         {
       
  1370         iContainerOutput->PrintTextL(iBCIssuesBigBuffer->Des());
       
  1371         delete iBCIssuesBigBuffer;
       
  1372         iBCIssuesBigBuffer = 0;
       
  1373         }
       
  1374     if( iLogWriteBuf->Length() > 0 && iBCLogFile.SubSessionHandle() != 0)
       
  1375         {
       
  1376         iBCLogFile.Write(iLogWriteBuf->Des());
       
  1377         }
       
  1378     WriteInitialStuffToTheLogL(_L("Analysis ready"), iBCLogFile);
       
  1379     iLogWriteBuf->Des().Zero();
       
  1380     iBCLogFile.Close();
       
  1381     }
       
  1382 
       
  1383 // ---------------------------------------------------------------------------
       
  1384 
       
  1385 void CLauncherEngine::ElementParsedL(const CLauncherDLLElement& aDllElement)
       
  1386     {
       
  1387     LOGSTRING("Launcher: CLauncherEngine::ElementParsedL");
       
  1388     User::ResetInactivityTime();
       
  1389     _LIT(KNewLine, "\n");
       
  1390     _LIT(KIndent, "    ");
       
  1391     _LIT(KIssuesFound, "Binary compatibility issues found:"); 
       
  1392     _LIT(KDLLMissing,"DLL is missing");
       
  1393     _LIT(KUID1Changed,"UID1 changed");
       
  1394     _LIT(KUID2Changed,"UID2 changed");
       
  1395     _LIT(KUID3Changed,"UID3 changed");
       
  1396     _LIT(KSIDChanged,"SID changed");
       
  1397     _LIT(KCapabilityChanged,"Capability changed");
       
  1398     
       
  1399     if( iDLLElement == 0 )
       
  1400         {
       
  1401         iDLLElement = CLauncherDLLElement::NewL();
       
  1402         }
       
  1403     
       
  1404     TFindFile fileFinder(iEnv->FsSession());
       
  1405     _LIT(KDLLPath, "\\sys\\bin\\");
       
  1406     TInt err = fileFinder.FindByPath(aDllElement.Name(), &KDLLPath); 
       
  1407     
       
  1408     TBuf<256> issueStr;
       
  1409     
       
  1410     if( err == KErrNotFound )
       
  1411         {
       
  1412         if( iFoundBCIssues++ == 0 )
       
  1413             {                        
       
  1414             iContainerOutput->PrintTextL( KIssuesFound );
       
  1415             iContainerOutput->PrintTextL( KNewLine );            
       
  1416             AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1417             AppendLogBufferL(KIssuesFound(), iLogWriteBuf);
       
  1418             AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1419             }
       
  1420         issueStr.Copy(aDllElement.Name());
       
  1421         issueStr.Append(KNewLine);
       
  1422         issueStr.Append(KIndent);
       
  1423         issueStr.Append(KDLLMissing);
       
  1424         issueStr.Append(KNewLine);
       
  1425                 
       
  1426         AppendLogBufferL(issueStr, iLogWriteBuf);
       
  1427         
       
  1428         TFileName dllName = aDllElement.Name();
       
  1429         LOGSTRING2("Launcher: DLL not found: %S", &dllName);
       
  1430         if( iFoundBCIssues > KBigBufferUsageThreshold )
       
  1431             {
       
  1432             if( iBCIssuesBigBuffer == 0)
       
  1433                 {
       
  1434                 iBCIssuesBigBuffer = HBufC::NewL(KBigBufferAllocBytes);
       
  1435                 }
       
  1436             TInt maxSize = iBCIssuesBigBuffer->Des().Length() + issueStr.Length();
       
  1437             if( maxSize >= iBCIssuesBigBuffer->Des().MaxLength())
       
  1438                 {
       
  1439                 iBCIssuesBigBuffer = iBCIssuesBigBuffer->ReAllocL(maxSize + KBigBufferAllocBytes );                
       
  1440                 }
       
  1441             TPtr ptr(iBCIssuesBigBuffer->Des());
       
  1442             ptr += issueStr;            
       
  1443             }
       
  1444         else
       
  1445             {
       
  1446             iContainerOutput->PrintTextL( issueStr);
       
  1447             }
       
  1448         }
       
  1449     else if( err == KErrNone)
       
  1450         {
       
  1451         // File is found, so let's try to open it:
       
  1452         RFile dllFile;
       
  1453         CleanupClosePushL(dllFile);        
       
  1454         if( dllFile.Open(iEnv->FsSession(), fileFinder.File(), EFileRead) == KErrNone )
       
  1455             {
       
  1456             // Parse DLL:
       
  1457             iDLLParser->ParseL(iEnv->FsSession(), dllFile, *iDLLElement);
       
  1458             CleanupStack::PopAndDestroy(); // dllFile            
       
  1459             RArray<CLauncherDLLElement::TDifference> diffs;
       
  1460             CleanupClosePushL(diffs);
       
  1461                         
       
  1462             // Compare DLLs:              
       
  1463             if( iDLLElement->CompareL(aDllElement, diffs))
       
  1464                 {                
       
  1465                 if( iFoundBCIssues++ == 0 )
       
  1466                     {
       
  1467                     iContainerOutput->PrintTextL( KIssuesFound );
       
  1468                     iContainerOutput->PrintTextL( KNewLine );                   
       
  1469                     AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1470                     AppendLogBufferL(KIssuesFound(), iLogWriteBuf);
       
  1471                     AppendLogBufferL(KFileNewLine(), iLogWriteBuf);
       
  1472                     }
       
  1473                 // Differencies found:
       
  1474                 for( TInt i = 0; i < diffs.Count(); ++i )
       
  1475                     {                
       
  1476                     // Print DLL name:
       
  1477                     if( i == 0 )
       
  1478                         {
       
  1479                         issueStr.Copy(aDllElement.Name());
       
  1480                         issueStr.Append(KNewLine);
       
  1481                         }
       
  1482                     
       
  1483                     // Print differencies:
       
  1484                     issueStr.Append(KIndent);
       
  1485                     switch(diffs[i])
       
  1486                         {
       
  1487                         case CLauncherDLLElement::EDifference_UID1:
       
  1488                             issueStr.Append(KUID1Changed);
       
  1489                             break;
       
  1490                         case CLauncherDLLElement::EDifference_UID2:
       
  1491                             issueStr.Append( KUID2Changed );
       
  1492                             break;
       
  1493                         case CLauncherDLLElement::EDifference_UID3:
       
  1494                             issueStr.Append( KUID3Changed );
       
  1495                             break;
       
  1496                         case CLauncherDLLElement::EDifference_SID:
       
  1497                             issueStr.Append( KSIDChanged );
       
  1498                             break;
       
  1499                         case CLauncherDLLElement::EDifference_Capability:
       
  1500                             issueStr.Append( KCapabilityChanged );
       
  1501                             break;
       
  1502                         }
       
  1503                     issueStr.Append( KNewLine );                    
       
  1504                     }
       
  1505                 AppendLogBufferL(issueStr, iLogWriteBuf);
       
  1506                 if( iFoundBCIssues > KBigBufferUsageThreshold )
       
  1507                     {
       
  1508                     // To improve performance, don't print issues to output anymore.
       
  1509                     // Instead, store the issues in buffer and print them when analysis is done.
       
  1510                     if( iBCIssuesBigBuffer == 0)
       
  1511                         {
       
  1512                         iBCIssuesBigBuffer = HBufC::NewL(KBigBufferAllocBytes);
       
  1513                         }
       
  1514                     TInt maxSize = iBCIssuesBigBuffer->Des().Length() + issueStr.Length();
       
  1515                     if( maxSize >= iBCIssuesBigBuffer->Des().MaxLength())
       
  1516                         {
       
  1517                         TInt increaseSize = Max(issueStr.Length(), KBigBufferAllocBytes);
       
  1518                         iBCIssuesBigBuffer = iBCIssuesBigBuffer->ReAllocL(maxSize + increaseSize );                            
       
  1519                         }
       
  1520                     TPtr ptr(iBCIssuesBigBuffer->Des());
       
  1521                     ptr += issueStr;
       
  1522                     }
       
  1523                 else
       
  1524                     {
       
  1525                     iContainerOutput->PrintTextL( issueStr);
       
  1526                     }
       
  1527                 }
       
  1528             CleanupStack::Pop(); // diffs
       
  1529             diffs.Close();            
       
  1530             }
       
  1531         else
       
  1532             {
       
  1533             CleanupStack::PopAndDestroy(); // dllFile
       
  1534             }
       
  1535         }
       
  1536     }
       
  1537 
       
  1538 // ---------------------------------------------------------------------------
       
  1539 
       
  1540 TInt CLauncherEngine::ReadLineFromFileL(RFile& aFile, TDes& aReadBuf)
       
  1541     {
       
  1542     LOGSTRING("Launcher: CLauncherEngine::ReadLineFromFile");
       
  1543 
       
  1544     _LIT8(KImcvCRLF, "\r\n");
       
  1545     TInt err(KErrNone);
       
  1546 
       
  1547     HBufC8* tempLine = HBufC8::NewLC(1000);
       
  1548     TPtr8 buffer = tempLine->Des();
       
  1549 
       
  1550     // clear the target buffer
       
  1551     aReadBuf.Zero();
       
  1552 
       
  1553     // get the current file position
       
  1554     TInt filePos(0);
       
  1555     aFile.Seek(ESeekCurrent, filePos);
       
  1556 
       
  1557     // read the buffer
       
  1558     err = aFile.Read(buffer);
       
  1559 
       
  1560     // check if it's the end of file
       
  1561     TInt s = buffer.Length();
       
  1562     if (s == 0)
       
  1563         err = KErrEof;
       
  1564 
       
  1565     if (err == KErrNone)
       
  1566         {
       
  1567         // copy to the lfcr and then set the file pointer to the point after that
       
  1568         TInt pos = buffer.Find(KImcvCRLF);
       
  1569         if (pos != -1)
       
  1570             {
       
  1571             TFileName tempBuf;
       
  1572             buffer.SetLength(pos);
       
  1573             tempBuf.Copy(buffer);
       
  1574             aReadBuf.Justify(tempBuf, pos, ELeft, ' ');
       
  1575             filePos += (pos+2);
       
  1576 
       
  1577             // set the file pointer back to after the lfcr
       
  1578             aFile.Seek(ESeekStart, filePos);
       
  1579             }
       
  1580         
       
  1581         // else fill the whole buffer
       
  1582         else
       
  1583             {
       
  1584             aReadBuf.Copy(buffer);
       
  1585             }
       
  1586         }
       
  1587 
       
  1588     CleanupStack::PopAndDestroy(); // tempLine
       
  1589     return err;
       
  1590     }
       
  1591 
       
  1592 // ---------------------------------------------------------------------------
       
  1593 
       
  1594 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
  1595 void CLauncherEngine::SendLogViaSendUiL(CSendUi* aSendUi)
       
  1596     {
       
  1597     LOGSTRING("Launcher: CLauncherEngine::SendLogViaSendUiL");
       
  1598 
       
  1599     CMessageData* messageData = CMessageData::NewL();
       
  1600     CleanupStack::PushL( messageData );
       
  1601     if( LogFileExists() )
       
  1602         {
       
  1603         messageData->AppendAttachmentL( iLogFilePath );
       
  1604         }
       
  1605     if( BCLogFileExists() )
       
  1606         {
       
  1607         messageData->AppendAttachmentL( iBCLogFilePath );
       
  1608         }
       
  1609     aSendUi->ShowQueryAndSendL( messageData, TSendingCapabilities(0, 0, TSendingCapabilities::ESupportsAttachments ));
       
  1610     CleanupStack::PopAndDestroy(); //messageData
       
  1611     }
       
  1612 #endif
       
  1613 
       
  1614 // ---------------------------------------------------------------------------
       
  1615 
       
  1616 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 )
       
  1617 void CLauncherEngine::SendListOfSystemDllsViaSendUiL(CSendUi* aSendUi)
       
  1618     {
       
  1619     LOGSTRING("Launcher: CLauncherEngine::SendListOfDllsViaSendUiL");
       
  1620 
       
  1621     if (BaflUtils::FileExists(iEnv->FsSession(), iSystemDllsFilePath))
       
  1622         {
       
  1623         CMessageData* messageData = CMessageData::NewL();
       
  1624         CleanupStack::PushL( messageData );
       
  1625         messageData->AppendAttachmentL( iSystemDllsFilePath );
       
  1626         aSendUi->ShowQueryAndSendL( messageData, TSendingCapabilities(0, 0, TSendingCapabilities::ESupportsAttachments ));
       
  1627         CleanupStack::PopAndDestroy(); //messageData
       
  1628         }
       
  1629     else
       
  1630         {
       
  1631         _LIT(message, "DLL list does not exist");
       
  1632         CAknErrorNote* errorNote = new(ELeave) CAknErrorNote;
       
  1633         errorNote->ExecuteLD(message);        
       
  1634         }
       
  1635     }
       
  1636 #endif
       
  1637 
       
  1638 // ---------------------------------------------------------------------------
       
  1639 
       
  1640 void CLauncherEngine::ChangeFocusToOutputView()
       
  1641     {
       
  1642     iAppUi->TabGroup()->SetActiveTabByIndex( 1 );
       
  1643     TRAP_IGNORE(iAppUi->ActivateLocalViewL( KView2Id ));
       
  1644     }
       
  1645 
       
  1646 
       
  1647 // ---------------------------------------------------------------------------
       
  1648 
       
  1649 //////////////////////////////////////////////////////////////////////////////////////
       
  1650 
       
  1651 // ---------------------------------------------------------------------------
       
  1652 
       
  1653 CAppRunningChecker* CAppRunningChecker::NewL(CLauncherEngine* aLauncherEngine)
       
  1654     {
       
  1655     LOGSTRING("Launcher: CAppRunningChecker::NewL");
       
  1656 
       
  1657     CAppRunningChecker* self = new(ELeave) CAppRunningChecker;
       
  1658     CleanupStack::PushL(self);
       
  1659     self->ConstructL(aLauncherEngine);
       
  1660     CleanupStack::Pop();
       
  1661     return self;
       
  1662     }
       
  1663 
       
  1664 // ---------------------------------------------------------------------------
       
  1665 
       
  1666 CAppRunningChecker::CAppRunningChecker() : CActive(EActivePriorityIpcEventsHigh)
       
  1667     {
       
  1668     }
       
  1669 
       
  1670 // ---------------------------------------------------------------------------
       
  1671 
       
  1672 void CAppRunningChecker::ConstructL(CLauncherEngine* aLauncherEngine)
       
  1673     {
       
  1674     LOGSTRING("Launcher: CAppRunningChecker::ConstructL");
       
  1675 
       
  1676     iEnv = CEikonEnv::Static();
       
  1677     User::LeaveIfError(iTimer.CreateLocal());
       
  1678 
       
  1679     iLauncherEngine = aLauncherEngine;
       
  1680 
       
  1681     CActiveScheduler::Add(this);
       
  1682     }
       
  1683 
       
  1684 // ---------------------------------------------------------------------------
       
  1685 
       
  1686 CAppRunningChecker::~CAppRunningChecker()
       
  1687     {
       
  1688     LOGSTRING("Launcher: CAppRunningChecker::~CAppRunningChecker");
       
  1689 
       
  1690     Cancel();
       
  1691 
       
  1692     iTimer.Close();
       
  1693     }
       
  1694 
       
  1695 // ---------------------------------------------------------------------------
       
  1696 
       
  1697 void CAppRunningChecker::StartTesting()
       
  1698     {
       
  1699     LOGSTRING("Launcher: CAppRunningChecker::StartTesting");
       
  1700 
       
  1701     __ASSERT_ALWAYS(!IsActive(), User::Panic(_L("Running Checker"), 200));
       
  1702 
       
  1703     // async delay of seven seconds
       
  1704     iTimer.After(iStatus, 7000000);    
       
  1705     SetActive();
       
  1706     }
       
  1707 
       
  1708 // ---------------------------------------------------------------------------
       
  1709 
       
  1710 void CAppRunningChecker::RunL()
       
  1711     {
       
  1712     LOGSTRING("Launcher: CAppRunningChecker::RunL");
       
  1713 
       
  1714     // check if the application is running
       
  1715     iLauncherEngine->CheckIfAppIsRunningL();
       
  1716     }
       
  1717 
       
  1718 // ---------------------------------------------------------------------------
       
  1719 
       
  1720 void CAppRunningChecker::DoCancel()
       
  1721     {
       
  1722     LOGSTRING("Launcher: CAppRunningChecker::DoCancel");
       
  1723     iTimer.Cancel();
       
  1724     }
       
  1725 
       
  1726 // ---------------------------------------------------------------------------
       
  1727 
       
  1728 //////////////////////////////////////////////////////////////////////////////////////
       
  1729 
       
  1730 // ---------------------------------------------------------------------------
       
  1731 
       
  1732 CAppThreadChecker* CAppThreadChecker::NewL(CLauncherEngine* aLauncherEngine)
       
  1733     {
       
  1734     LOGSTRING("Launcher: CAppThreadChecker::NewL");
       
  1735 
       
  1736     CAppThreadChecker* self = new(ELeave) CAppThreadChecker;
       
  1737     CleanupStack::PushL(self);
       
  1738     self->ConstructL(aLauncherEngine);
       
  1739     CleanupStack::Pop();
       
  1740     return self;
       
  1741     }
       
  1742 
       
  1743 // ---------------------------------------------------------------------------
       
  1744 
       
  1745 CAppThreadChecker::CAppThreadChecker() : CActive(EActivePriorityIpcEventsHigh)
       
  1746     {
       
  1747     }
       
  1748 
       
  1749 // ---------------------------------------------------------------------------
       
  1750 
       
  1751 void CAppThreadChecker::ConstructL(CLauncherEngine* aLauncherEngine)
       
  1752     {
       
  1753     LOGSTRING("Launcher: CAppThreadChecker::ConstructL");
       
  1754 
       
  1755     iEnv = CEikonEnv::Static();
       
  1756 
       
  1757     iLauncherEngine = aLauncherEngine;
       
  1758 
       
  1759     CActiveScheduler::Add(this);
       
  1760     }
       
  1761 
       
  1762 // ---------------------------------------------------------------------------
       
  1763 
       
  1764 CAppThreadChecker::~CAppThreadChecker()
       
  1765     {
       
  1766     LOGSTRING("Launcher: CAppThreadChecker::~CAppThreadChecker");
       
  1767 
       
  1768     Cancel();
       
  1769     }
       
  1770 
       
  1771 // ---------------------------------------------------------------------------
       
  1772 
       
  1773 void CAppThreadChecker::ActivateChecking()
       
  1774     {
       
  1775     LOGSTRING("Launcher: CAppThreadChecker::ActivateChecking");
       
  1776 
       
  1777     __ASSERT_ALWAYS(!IsActive(), User::Panic(_L("Thread Checker"), 300));
       
  1778 
       
  1779     SetActive();
       
  1780     }
       
  1781 
       
  1782 // ---------------------------------------------------------------------------
       
  1783 
       
  1784 void CAppThreadChecker::RunL()
       
  1785     {
       
  1786     LOGSTRING("Launcher: CAppThreadChecker::RunL");
       
  1787 
       
  1788     // check the state of the thread
       
  1789     iLauncherEngine->CheckWhyThreadDiedL();
       
  1790     }
       
  1791 
       
  1792 // ---------------------------------------------------------------------------
       
  1793 
       
  1794 void CAppThreadChecker::DoCancel()
       
  1795     {
       
  1796     LOGSTRING("Launcher: CAppThreadChecker::DoCancel");
       
  1797     }
       
  1798 
       
  1799 // ---------------------------------------------------------------------------
       
  1800