javamanager/javacaptain/extensionplugins/scrupdater/src/scrupdater.cpp
changeset 47 f40128debb5d
child 48 e0d6e9bd3ca7
equal deleted inserted replaced
35:85266cc22c7f 47:f40128debb5d
       
     1 /*
       
     2 * Copyright (c) 2010 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:  ScrUpdater is Java Captain Symbian plugin that updates
       
    15 *               presence information of Java Applications in USIF SCR
       
    16 *               when removable drive is added or removed to the device.
       
    17 *
       
    18 */
       
    19 
       
    20 #include <apgcli.h>
       
    21 #include <e32base.h>
       
    22 #include <f32file.h>
       
    23 
       
    24 #include "javaprocessconstants.h"
       
    25 #include "javasymbianoslayer.h"
       
    26 #include "javauids.h"
       
    27 #include "logger.h"
       
    28 #include "coreinterface.h"
       
    29 #include "booteventprovidermessages.h"
       
    30 #include "mmceventprovidermessages.h"
       
    31 
       
    32 #include "scrupdater.h"
       
    33 
       
    34 using namespace Usif;
       
    35 
       
    36 /**
       
    37  * Return pointer to ExtensionPluginInterface implementation for this
       
    38  * extension dll
       
    39  */
       
    40 java::captain::ExtensionPluginInterface* getExtensionPlugin()
       
    41 {
       
    42     return new java::captain::ScrUpdater();
       
    43 }
       
    44 
       
    45 namespace java
       
    46 {
       
    47 namespace captain
       
    48 {
       
    49 
       
    50 using java::fileutils::driveInfo;
       
    51 using java::fileutils::DriveListenerInterface;
       
    52 
       
    53 /**
       
    54  * Empty contructor
       
    55  */
       
    56 ScrUpdater::ScrUpdater() : mCore(0)
       
    57 {
       
    58 }
       
    59 
       
    60 /**
       
    61  * Empty destructor
       
    62  */
       
    63 ScrUpdater::~ScrUpdater()
       
    64 {
       
    65 }
       
    66 
       
    67 /**
       
    68  * Implement PluginInterface method
       
    69  */
       
    70 void ScrUpdater::startPlugin(CoreInterface* core)
       
    71 {
       
    72     LOG(EJavaCaptain, EInfo, "ScrUpdater plugin started");
       
    73 
       
    74     mCore = core;
       
    75 }
       
    76 
       
    77 /**
       
    78  * Implement PluginInterface method
       
    79  */
       
    80 void ScrUpdater::stopPlugin()
       
    81 {
       
    82     mCore = 0;
       
    83 }
       
    84 
       
    85 /**
       
    86  * Implement ExtensionPluginInterface method
       
    87  */
       
    88 EventConsumerInterface* ScrUpdater::getEventConsumer()
       
    89 {
       
    90     return this;
       
    91 }
       
    92 
       
    93 /**
       
    94  * Handle Java Captain events sent by Boot event provider or
       
    95  * MMC event provider.
       
    96  *
       
    97  * Implement EventConsumerInterface method
       
    98  */
       
    99 void ScrUpdater::event(const std::string& eventProvider,
       
   100                        java::comms::CommsMessage& aMsg)
       
   101 {
       
   102     if (eventProvider == BOOT_EVENT_PROVIDER)
       
   103     {
       
   104         int bootType = NORMAL_BOOT_C;
       
   105         getBootMessageParams(aMsg, bootType);
       
   106         LOG1(
       
   107             EJavaCaptain,
       
   108             EInfo,
       
   109             "ScrUpdater::event() boot event received (type=%d)",
       
   110             bootType);
       
   111         switch (bootType)
       
   112         {
       
   113             case IAD_BOOT_C:
       
   114             case FIRST_DEVICE_BOOT_C:
       
   115             case NORMAL_BOOT_C:
       
   116             {
       
   117                 // Update presence information
       
   118                 TRAPD(err, initializeScrPresenceInfoL())
       
   119                 if (KErrNone != err)
       
   120                 {
       
   121                     ELOG1(EJavaCaptain, "initializeScrPresenceInfoL: leaved (%d)", err);
       
   122                 }
       
   123             }
       
   124             break;
       
   125 
       
   126             default:
       
   127             {
       
   128                 WLOG1(EJavaCaptain,
       
   129                     "DriveListenerInterface: event() unknown boot event (type=%d)", bootType);
       
   130             }
       
   131             break;
       
   132         }
       
   133     }
       
   134     else if (eventProvider == MMC_EVENT_PROVIDER)
       
   135     {
       
   136         int operation = 0;
       
   137         driveInfo di;
       
   138         getMmcChangedMessageParams(aMsg, operation, di);
       
   139         LOG1(
       
   140             EJavaCaptain,
       
   141             EInfo,
       
   142             "ScrUpdater::event() mmc event received (operation=%d)",
       
   143             operation);
       
   144 
       
   145         switch (operation)
       
   146         {
       
   147             case DriveListenerInterface::REMOVABLE_MEDIA_REMOVED_C:
       
   148             {
       
   149                 // All Java applications in the removed drive are set
       
   150                 // to 'not present' state
       
   151                 TRAPD(err, removeScrPresencesL(&di));
       
   152                 if (KErrNone != err)
       
   153                 {
       
   154                     ELOG1(EJavaCaptain, "removeScrPresencesL leaved (%d)", err);
       
   155                 }
       
   156             }
       
   157             break;
       
   158 
       
   159             case DriveListenerInterface::REMOVABLE_MEDIA_INSERTED_C:
       
   160             {
       
   161                 // Those Java applications in the drive to where the media
       
   162                 // (e.g. memory card) was added are set to 'present' state
       
   163                 // IF the media id is correct (in other words if the same
       
   164                 // memory card that they have been installed to is added
       
   165                 // to the drive).
       
   166                 TRAPD(err, addScrPresencesL(&di));
       
   167                 if (KErrNone != err)
       
   168                 {
       
   169                     ELOG1(EJavaCaptain, "addScrPresencesL leaved (%d)", err);
       
   170                 }
       
   171             }
       
   172             break;
       
   173         }
       
   174     }
       
   175 }
       
   176 
       
   177 /**
       
   178  * Set the presence state of all Java applications installed
       
   179  * to the removable drive specified in aInfo to not present
       
   180  */
       
   181 void ScrUpdater::removeScrPresencesL(driveInfo *aInfo)
       
   182 {
       
   183     __UHEAP_MARK;
       
   184     LOG1WSTR(EJavaCaptain, EInfo,
       
   185         "removeScrPresencesL: driveInfo root path is %s", aInfo->iRootPath);
       
   186 
       
   187     RSoftwareComponentRegistry *pScr = createScrL();
       
   188     CleanupStack::PushL(pScr);
       
   189 
       
   190     // Get ids of all Java components in scr
       
   191     RArray<TComponentId> componentIdList;
       
   192     CComponentFilter *pJavaSwTypeFilter = CComponentFilter::NewLC();
       
   193     pJavaSwTypeFilter->SetSoftwareTypeL(Usif::KSoftwareTypeJava);
       
   194 
       
   195     pScr->GetComponentIdsL(componentIdList, pJavaSwTypeFilter);
       
   196     CleanupStack::PopAndDestroy(pJavaSwTypeFilter);
       
   197     CleanupClosePushL(componentIdList);
       
   198 
       
   199     // For each component check whether it has been installed
       
   200     // to the removed drive
       
   201     TInt  nComponents = componentIdList.Count();
       
   202     TUint removedDrive = (TUint)(aInfo->iRootPath[0]);
       
   203     // Now removedDrive contains the drive letter, convert it to drive number 0-25
       
   204     if ((removedDrive > 64) && (removedDrive < 91))
       
   205     {
       
   206         // 'A' - 'Z'
       
   207         removedDrive -= 65;
       
   208     }
       
   209     else if ((removedDrive > 96) && (removedDrive < 123))
       
   210     {
       
   211         // 'a' - 'z'
       
   212         removedDrive -= 97;
       
   213     }
       
   214     else
       
   215     {
       
   216         ELOG1WSTR(EJavaCaptain,
       
   217             "removeScrPresencesL: Unexpected root path in remove drive info %s",
       
   218             aInfo->iRootPath);
       
   219         CleanupStack::PopAndDestroy(pScr);
       
   220         return;
       
   221     }
       
   222 
       
   223     LOG2(EJavaCaptain, EInfo, "Number of Java components is %d, removed drive is %d",
       
   224         nComponents, removedDrive);
       
   225 
       
   226     TBool fPresenceChange = EFalse;
       
   227     RArray<TApaAppUpdateInfo> removedApps;
       
   228     CleanupClosePushL(removedApps);
       
   229 
       
   230     for (TInt nInd = 0; nInd < nComponents; nInd++)
       
   231     {
       
   232         CComponentEntry *pEntry = CComponentEntry::NewLC();
       
   233         if (!(pScr->GetComponentL(componentIdList[nInd], *pEntry)))
       
   234         {
       
   235             ELOG1(EJavaCaptain,
       
   236                 "removeScrPresencesL: SCR GetComponentIdsL returned id %d "
       
   237                 "but GetComponentL does not find it", componentIdList[nInd]);
       
   238             CleanupStack::PopAndDestroy(pEntry);
       
   239             continue;
       
   240         }
       
   241 
       
   242         TInt nInstalledDrives = pEntry->InstalledDrives().Length();
       
   243         if (nInstalledDrives <= removedDrive)
       
   244         {
       
   245             // SCR InstalledDrives should be array of 26 elements (value 0 or 1)
       
   246             ELOG2(EJavaCaptain,
       
   247                 "removeScrPresencesL: The length of InstalledDrives array (%d) "
       
   248                 "is smaller than removedDrive (%d)", nInstalledDrives, removedDrive);
       
   249             CleanupStack::PopAndDestroy(pEntry);
       
   250             continue;
       
   251         }
       
   252 
       
   253         LOG1(EJavaCaptain, EInfo, "Java component id %d", componentIdList[nInd]);
       
   254 
       
   255         if (pEntry->InstalledDrives()[removedDrive])
       
   256         {
       
   257             // This component has been installed to the drive
       
   258             // that has just been removed
       
   259             pScr->SetIsComponentPresentL(componentIdList[nInd], EFalse);
       
   260 
       
   261             LOG1(EJavaCaptain, EInfo,
       
   262                 "removeScrPresencesL: set component %d to not present",
       
   263                 componentIdList[nInd]);
       
   264 
       
   265             fPresenceChange = ETrue;
       
   266 
       
   267             // Gather the Uids of all applications that are no longer present
       
   268             RArray<TUid> appsInComponent;
       
   269             CleanupClosePushL(appsInComponent);
       
   270             pScr->GetAppUidsForComponentL(
       
   271                 componentIdList[nInd], appsInComponent);
       
   272             for (TInt nInd2 = 0; nInd2 < appsInComponent.Count(); nInd2++)
       
   273             {
       
   274                 TApaAppUpdateInfo appInfo;
       
   275                 appInfo.iAppUid = appsInComponent[nInd2];
       
   276                 appInfo.iAction = TApaAppUpdateInfo::EAppNotPresent;
       
   277                 (void)removedApps.Append(appInfo);
       
   278             }
       
   279             CleanupStack::PopAndDestroy(&appsInComponent);
       
   280         }
       
   281 
       
   282         CleanupStack::PopAndDestroy(pEntry);
       
   283     }
       
   284 
       
   285     // Tell AppArc which applications are no longer present
       
   286     while (fPresenceChange)
       
   287     {
       
   288         if (removedApps.Count() == 0)
       
   289         {
       
   290             ELOG(EJavaCaptain, "removeScrPresencesL: Uids of the removed apps are not known");
       
   291             break;
       
   292         }
       
   293 
       
   294         RApaLsSession apaSession;
       
   295         TInt err = apaSession.Connect();
       
   296         if (KErrNone != err)
       
   297         {
       
   298             ELOG1(EJavaCaptain, "removeScrPresencesL: Error %d when connecting AppArc", err);
       
   299             break;
       
   300         }
       
   301         else
       
   302         {
       
   303             CleanupClosePushL(apaSession);
       
   304             apaSession.UpdateAppListL(removedApps);
       
   305             CleanupStack::PopAndDestroy(); // closes apaSession
       
   306             fPresenceChange = EFalse;
       
   307         }
       
   308     }
       
   309 
       
   310     CleanupStack::PopAndDestroy(); // Close removedApps
       
   311     CleanupStack::PopAndDestroy(); // Close componentIdList
       
   312     CleanupStack::PopAndDestroy(pScr);
       
   313     __UHEAP_MARKEND;
       
   314 }
       
   315 
       
   316 
       
   317 /**
       
   318  * Set the presence state of all Java applications installed
       
   319  * to the removable drive specified in aInfo to present
       
   320  */
       
   321 void ScrUpdater::addScrPresencesL(driveInfo *aInfo)
       
   322 {
       
   323     __UHEAP_MARK;
       
   324     LOG1WSTR(EJavaCaptain, EInfo,
       
   325         "addScrPresencesL: driveInfo root path is %s", aInfo->iRootPath);
       
   326 
       
   327     RSoftwareComponentRegistry *pScr = createScrL();
       
   328     CleanupStack::PushL(pScr);
       
   329 
       
   330     // Get ids of all Java components in scr
       
   331     RArray<TComponentId> componentIdList;
       
   332     CComponentFilter *pJavaSwTypeFilter = CComponentFilter::NewLC();
       
   333     pJavaSwTypeFilter->SetSoftwareTypeL(Usif::KSoftwareTypeJava);
       
   334 
       
   335     pScr->GetComponentIdsL(componentIdList, pJavaSwTypeFilter);
       
   336     CleanupStack::PopAndDestroy(pJavaSwTypeFilter);
       
   337     CleanupClosePushL(componentIdList);
       
   338 
       
   339     // For each component check whether it has been installed
       
   340     // to the added drive AND whether the media id is correct
       
   341     // (in other words if the actual memory card where the component
       
   342     // has been installed to is added to the drive).
       
   343     TInt  nComponents  = componentIdList.Count();
       
   344     TUint addedMediaId = (TUint)(aInfo->iId);
       
   345     TUint addedDrive   = (TUint)(aInfo->iRootPath[0]);
       
   346     // Now addedDrive contains the drive letter, convert it to drive number 0-25
       
   347     if ((addedDrive > 64) && (addedDrive < 91))
       
   348     {
       
   349         // 'A' - 'Z'
       
   350         addedDrive -= 65;
       
   351     }
       
   352     else if ((addedDrive > 96) && (addedDrive < 123))
       
   353     {
       
   354         // 'a' - 'z'
       
   355         addedDrive -= 97;
       
   356     }
       
   357     else
       
   358     {
       
   359         ELOG1WSTR(EJavaCaptain,
       
   360             "addScrPresencesL: Unexpected root path in add drive info %s",
       
   361             aInfo->iRootPath);
       
   362         CleanupStack::PopAndDestroy(pScr);
       
   363         return;
       
   364     }
       
   365 
       
   366     LOG2(EJavaCaptain, EInfo, "Number of Java components is %d, added drive is %d",
       
   367         nComponents, addedDrive);
       
   368 
       
   369     TBool fPresenceChange = EFalse;
       
   370     RArray<TApaAppUpdateInfo> addedApps;
       
   371     CleanupClosePushL(addedApps);
       
   372 
       
   373     for (TInt nInd = 0; nInd < nComponents; nInd++)
       
   374     {
       
   375         CComponentEntry *pEntry = CComponentEntry::NewLC();
       
   376         if (!(pScr->GetComponentL(componentIdList[nInd], *pEntry)))
       
   377         {
       
   378             ELOG1(EJavaCaptain,
       
   379                 "addScrPresencesL: SCR GetComponentIdsL returned id %d "
       
   380                 "but GetComponentL does not find it", componentIdList[nInd]);
       
   381             CleanupStack::PopAndDestroy(pEntry);
       
   382             continue;
       
   383         }
       
   384 
       
   385         // When Java Installer registers Java app to SCR it stores also
       
   386         // the media id using SetComponentPropertyL(TComponentId aComponentId,
       
   387         // _L("Media-Id")), TInt64 aValue);  (aValue is actually 32 bit int)
       
   388         CIntPropertyEntry* pMediaIdProperty = (CIntPropertyEntry *)
       
   389             pScr->GetComponentPropertyL(componentIdList[nInd],_L("Media-Id"));
       
   390         if (NULL == pMediaIdProperty)
       
   391         {
       
   392             ELOG1(EJavaCaptain,
       
   393                 "addScrPresencesL: media_id property not found for component %d",
       
   394                 componentIdList[nInd]);
       
   395             CleanupStack::PopAndDestroy(pEntry);
       
   396             continue;
       
   397         }
       
   398         CleanupStack::PushL(pMediaIdProperty);
       
   399 
       
   400         TInt nInstalledDrives = pEntry->InstalledDrives().Length();
       
   401         if (nInstalledDrives <= addedDrive)
       
   402         {
       
   403             // SCR InstalledDrives should be array of 26 elements (value 0 or 1)
       
   404             ELOG2(EJavaCaptain,
       
   405                 "addScrPresencesL: The length of InstalledDrives array (%d) "
       
   406                 "is smaller than addedDrive (%d)", nInstalledDrives, addedDrive);
       
   407             CleanupStack::PopAndDestroy(pEntry);
       
   408             continue;
       
   409         }
       
   410 
       
   411         LOG1(EJavaCaptain, EInfo, "Java component id %d", componentIdList[nInd]);
       
   412 
       
   413         if (pEntry->InstalledDrives()[addedDrive])
       
   414         {
       
   415             // This component has been installed to the drive
       
   416             // that has just been added.
       
   417             // Now check whether the media id of the added media
       
   418             // is OK for this component.
       
   419             if (addedMediaId == pMediaIdProperty->IntValue())
       
   420             {
       
   421                 pScr->SetIsComponentPresentL(componentIdList[nInd], ETrue);
       
   422 
       
   423                 LOG1(EJavaCaptain, EInfo,
       
   424                     "addScrPresencesL: set component %d to present",
       
   425                     componentIdList[nInd]);
       
   426 
       
   427                 fPresenceChange = ETrue;
       
   428 
       
   429                 // Gather the Uids of all 'new' applications that are now present
       
   430                 RArray<TUid> appsInComponent;
       
   431                 CleanupClosePushL(appsInComponent);
       
   432                 pScr->GetAppUidsForComponentL(
       
   433                     componentIdList[nInd], appsInComponent);
       
   434                 for (TInt nInd2 = 0; nInd2 < appsInComponent.Count(); nInd2++)
       
   435                 {
       
   436                     TApaAppUpdateInfo appInfo;
       
   437                     appInfo.iAppUid = appsInComponent[nInd2];
       
   438                     appInfo.iAction = TApaAppUpdateInfo::EAppPresent;
       
   439                     (void)addedApps.Append(appInfo);
       
   440                 }
       
   441                 CleanupStack::PopAndDestroy(&appsInComponent);
       
   442             }
       
   443         }
       
   444 
       
   445         CleanupStack::PopAndDestroy(pMediaIdProperty);
       
   446         CleanupStack::PopAndDestroy(pEntry);
       
   447     }
       
   448 
       
   449     // Tell AppArc which 'new' applications are now present
       
   450     while (fPresenceChange)
       
   451     {
       
   452         if (addedApps.Count() == 0)
       
   453         {
       
   454             ELOG(EJavaCaptain, "addScrPresencesL: Uids of the 'new' apps are not known");
       
   455             break;
       
   456         }
       
   457 
       
   458         RApaLsSession apaSession;
       
   459         TInt err = apaSession.Connect();
       
   460         if (KErrNone != err)
       
   461         {
       
   462             ELOG1(EJavaCaptain, "addScrPresencesL: Error %d when connecting AppArc", err);
       
   463             break;
       
   464         }
       
   465         else
       
   466         {
       
   467             CleanupClosePushL(apaSession);
       
   468             apaSession.UpdateAppListL(addedApps);
       
   469             CleanupStack::PopAndDestroy(); // closes apaSession
       
   470             fPresenceChange = EFalse;
       
   471         }
       
   472     }
       
   473 
       
   474     CleanupStack::PopAndDestroy(); // Close addedApps
       
   475     CleanupStack::PopAndDestroy(); // Close componentIdList
       
   476     CleanupStack::PopAndDestroy(pScr);
       
   477     __UHEAP_MARKEND;
       
   478 }
       
   479 
       
   480 
       
   481 /**
       
   482  * Loop through all removable drives and get the media id of
       
   483  * the memory card or other removable media in the drive and update
       
   484  * presence information of all Java applications installed
       
   485  * to removable drives accordingly.
       
   486  */
       
   487 void ScrUpdater::initializeScrPresenceInfoL()
       
   488 {
       
   489     __UHEAP_MARK;
       
   490     RFs fs;
       
   491     User::LeaveIfError(fs.Connect());
       
   492     CleanupClosePushL(fs);
       
   493 
       
   494     // Which drives are present and what is the media id of
       
   495     // each removable volume
       
   496     TInt  err = KErrNone;
       
   497     TInt  err2 = KErrNone;
       
   498     TBool drivePresent[EDriveZ + 1];
       
   499     TUint driveMediaId[EDriveZ + 1];
       
   500     TVolumeInfo volumeInfo;
       
   501     TDriveInfo  driveInfo;
       
   502 
       
   503     for (TInt nInd = EDriveA; nInd < EDriveZ; nInd++)
       
   504     {
       
   505         err = fs.Volume(volumeInfo, nInd);
       
   506         if (KErrNone == err)
       
   507         {
       
   508             drivePresent[nInd] = ETrue;
       
   509             driveMediaId[nInd] = volumeInfo.iUniqueID;
       
   510             // If the media is not removable, media id is not checked
       
   511             err2 = fs.Drive(driveInfo, nInd);
       
   512             if (KErrNone != err2)
       
   513             {
       
   514                 ELOG1(EJavaCaptain,
       
   515                     "initializeScrPresenceInfoL: error (%d) when trying to get drive info",
       
   516                     err2);
       
   517                 User::Leave(err2);
       
   518             }
       
   519             else
       
   520             {
       
   521                 if (!(driveInfo.iDriveAtt & KDriveAttRemovable))
       
   522                 {
       
   523                     driveMediaId[nInd] = 0;
       
   524                 }
       
   525             }
       
   526         }
       
   527         else if (KErrNotReady == err)
       
   528         {
       
   529             // no volume in this drive
       
   530             drivePresent[nInd] = EFalse;
       
   531             driveMediaId[nInd] = 0;
       
   532         }
       
   533         else
       
   534         {
       
   535             ELOG1(EJavaCaptain,
       
   536                 "initializeScrPresenceInfoL: error (%d) when trying to get volume info",
       
   537                 err);
       
   538             User::Leave(err);
       
   539         }
       
   540     }
       
   541     CleanupStack::PopAndDestroy(); // close RFs
       
   542 
       
   543 
       
   544     RSoftwareComponentRegistry *pScr = createScrL();
       
   545     CleanupStack::PushL(pScr);
       
   546 
       
   547     // Get ids of all Java components in scr
       
   548     RArray<TComponentId> componentIdList;
       
   549     CComponentFilter *pJavaSwTypeFilter = CComponentFilter::NewLC();
       
   550     pJavaSwTypeFilter->SetSoftwareTypeL(Usif::KSoftwareTypeJava);
       
   551 
       
   552     pScr->GetComponentIdsL(componentIdList, pJavaSwTypeFilter);
       
   553     CleanupStack::PopAndDestroy(pJavaSwTypeFilter);
       
   554     CleanupClosePushL(componentIdList);
       
   555 
       
   556     // For each component check whether the drive it has been installed
       
   557     // to is present AND whether the media id is correct
       
   558     TInt  nComponents  = componentIdList.Count();
       
   559 
       
   560     LOG1(EJavaCaptain, EInfo, "initializeScrPresenceInfoL: Number of Java components is %d",
       
   561         nComponents);
       
   562 
       
   563     for (TInt nInd = 0; nInd < nComponents; nInd++)
       
   564     {
       
   565         CComponentEntry *pEntry = CComponentEntry::NewLC();
       
   566         if (!(pScr->GetComponentL(componentIdList[nInd], *pEntry)))
       
   567         {
       
   568             ELOG1(EJavaCaptain,
       
   569                 "initializeScrPresenceInfoL: SCR GetComponentIdsL returned id %d "
       
   570                 "but GetComponentL does not find it", componentIdList[nInd]);
       
   571             CleanupStack::PopAndDestroy(pEntry);
       
   572             continue;
       
   573         }
       
   574 
       
   575         CIntPropertyEntry* pMediaIdProperty = (CIntPropertyEntry *)
       
   576             pScr->GetComponentPropertyL(componentIdList[nInd],_L("Media-Id"));
       
   577         if (NULL == pMediaIdProperty)
       
   578         {
       
   579             ELOG1(EJavaCaptain,
       
   580                 "initializeScrPresenceInfoL: media_id property not found for component %d",
       
   581                 componentIdList[nInd]);
       
   582             CleanupStack::PopAndDestroy(pEntry);
       
   583             continue;
       
   584         }
       
   585         CleanupStack::PushL(pMediaIdProperty);
       
   586 
       
   587         TInt nInstalledDrives = pEntry->InstalledDrives().Length();
       
   588         if (nInstalledDrives > (EDriveZ + 1))
       
   589         {
       
   590             WLOG2(EJavaCaptain,
       
   591                 "initializeScrPresenceInfoL: too big (%d) installed drives array for "
       
   592                 "component %d", nInstalledDrives, componentIdList[nInd]);
       
   593             nInstalledDrives = EDriveZ;
       
   594         }
       
   595         // When Java components are installed, only one installed drive
       
   596         // and corresponding media id are registered.
       
   597         TInt installationDrive = -1;
       
   598 
       
   599         for (TInt driveNumber = EDriveA; driveNumber < nInstalledDrives; driveNumber++)
       
   600         {
       
   601             if (pEntry->InstalledDrives()[driveNumber])
       
   602             {
       
   603                 installationDrive = driveNumber;
       
   604                 break;
       
   605             }
       
   606         }
       
   607 
       
   608         if (installationDrive == -1)
       
   609         {
       
   610             ELOG1(EJavaCaptain,
       
   611                 "initializeScrPresenceInfoL: component (id %d) did not have installed drive info",
       
   612                 componentIdList[nInd]);
       
   613             CleanupStack::PopAndDestroy(pMediaIdProperty);
       
   614             CleanupStack::PopAndDestroy(pEntry);
       
   615             continue;
       
   616         }
       
   617 
       
   618         if (drivePresent[installationDrive])
       
   619         {
       
   620             // Check also the media id
       
   621             if (driveMediaId[installationDrive] == pMediaIdProperty->IntValue())
       
   622             {
       
   623                 LOG1(EJavaCaptain, EInfo,
       
   624                     "initializeScrPresenceInfoL: set component %d to present",
       
   625                     componentIdList[nInd]);
       
   626 
       
   627                 pScr->SetIsComponentPresentL(componentIdList[nInd], ETrue);
       
   628             }
       
   629             else
       
   630             {
       
   631                 LOG1(EJavaCaptain, EInfo,
       
   632                     "initializeScrPresenceInfoL: set component %d to NOT present",
       
   633                     componentIdList[nInd]);
       
   634 
       
   635                 pScr->SetIsComponentPresentL(componentIdList[nInd], EFalse);
       
   636             }
       
   637         }
       
   638         else
       
   639         {
       
   640             LOG1(EJavaCaptain, EInfo,
       
   641                 "initializeScrPresenceInfoL: set component %d to NOT present",
       
   642                 componentIdList[nInd]);
       
   643 
       
   644             // drive is not present -> Java component installed to that
       
   645             // drive is not present
       
   646             pScr->SetIsComponentPresentL(componentIdList[nInd], EFalse);
       
   647         }
       
   648 
       
   649         CleanupStack::PopAndDestroy(pMediaIdProperty);
       
   650         CleanupStack::PopAndDestroy(pEntry);
       
   651     }
       
   652 
       
   653     CleanupStack::PopAndDestroy(); // Close componentIdList
       
   654     CleanupStack::PopAndDestroy(pScr); // Also closes RSoftwareComponentRegistry
       
   655 
       
   656     __UHEAP_MARKEND;
       
   657 }
       
   658 
       
   659 
       
   660 /**
       
   661  * Creates an instance of RSoftwareComponentRegistry and connects to it.
       
   662  */
       
   663 RSoftwareComponentRegistry *ScrUpdater::createScrL()
       
   664 {
       
   665     RSoftwareComponentRegistry *pScr = new RSoftwareComponentRegistry;
       
   666     if (NULL == pScr)
       
   667     {
       
   668         ELOG(EJavaInstaller,
       
   669             "CreateScrL: Creating RSoftwareComponentRegistry failed");
       
   670         User::Leave(KErrGeneral);
       
   671     }
       
   672     TInt err = pScr->Connect();
       
   673     if (KErrNone != err)
       
   674     {
       
   675         ELOG1(EJavaInstaller,
       
   676             "CreateScrL: Connecting to RSoftwareComponentRegistry failed, error %d",
       
   677             err);
       
   678         delete pScr;
       
   679         User::Leave(err);
       
   680     }
       
   681 
       
   682     return pScr;
       
   683 }
       
   684 
       
   685 
       
   686 } // namespace captain
       
   687 } // namespace java