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