ncdengine/provider/deviceinteraction/src/ncdinstallationserviceimpl.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
    30 #include <Oma2Agent.h>
    30 #include <Oma2Agent.h>
    31 #include <s32file.h>
    31 #include <s32file.h>
    32 #include <e32property.h>
    32 #include <e32property.h>
    33 #include <sacls.h>
    33 #include <sacls.h>
    34 
    34 
       
    35 #ifdef USE_OLD_JAVA_API
       
    36     #include <mjavaregistry.h>
       
    37     #include <swi/minstalledappsregistry.h>
       
    38 #else
       
    39     #include <javaregistry.h>
       
    40     #include <javaregistrypackageentry.h>
       
    41 
       
    42     using namespace Java;
       
    43 #endif
       
    44 
    35 #include "ncdinstallationserviceobserver.h"
    45 #include "ncdinstallationserviceobserver.h"
    36 #include "ncdactiveoperationobserver.h"
    46 #include "ncdactiveoperationobserver.h"
    37 #include "ncdsilentinstallactiveobserver.h"
    47 #include "ncdsilentinstallactiveobserver.h"
    38 #include "ncderrors.h"
    48 #include "ncderrors.h"
    39 #include "catalogsutils.h"
    49 #include "catalogsutils.h"
    43 _LIT( KJadFileExtension, ".jad" );
    53 _LIT( KJadFileExtension, ".jad" );
    44 const TInt KDelayWhenAppListInvalid = 500000;
    54 const TInt KDelayWhenAppListInvalid = 500000;
    45 
    55 
    46 const TUint KFileOpenFlags = EFileShareReadersOrWriters;
    56 const TUint KFileOpenFlags = EFileShareReadersOrWriters;
    47 
    57 
    48 //const TInt KWidgetBundleIdLength = KMaxFileName + 1; 
    58 #ifdef __SERIES60_31__
       
    59 
       
    60     const TInt32 KPSUidJavaLatestInstallation = KUidJmiLatestInstallation;
       
    61 
       
    62 #else
       
    63 
       
    64     // Defined originally in /mw/java/inc/javauids.h
       
    65     // This should become available at some point in javadomainpskeys.h
       
    66     //const TInt32 KPSUidJavaLatestInstallation = 0x10282567;
       
    67     #include <javadomainpskeys.h>
       
    68 
       
    69 #endif
       
    70 
       
    71 // length taken from WidgetRegistryData.h
       
    72 const TInt KWidgetBundleIdLength = KWidgetRegistryVal + 1;    
    49 
    73 
    50 // ======== CALLBACK FUNCTION ========
    74 // ======== CALLBACK FUNCTION ========
    51  
    75  
    52 static TInt InstallationCompleteCallback( TAny* aData )
    76 static TInt InstallationCompleteCallback( TAny* aData )
    53     {
    77     {
   105     iFs.Close();
   129     iFs.Close();
   106     iAknsSrv.Close();
   130     iAknsSrv.Close();
   107     delete iInstallationCompleteCallback;
   131     delete iInstallationCompleteCallback;
   108     delete iJadFileName;
   132     delete iJadFileName;
   109     delete iRecognizedMime;
   133     delete iRecognizedMime;
   110     
   134 #ifdef USE_OLD_JAVA_API    
   111     delete iResults;
   135     iMIDletUids.Close();
   112     delete iArguments;
   136 #endif    
   113     
       
   114     iApaLs.Close();
   137     iApaLs.Close();
   115     
       
   116     
       
   117     if( iThemes )
   138     if( iThemes )
   118         {
   139         {
   119         iThemes->ResetAndDestroy();
   140         iThemes->ResetAndDestroy();
   120         delete iThemes;        
   141         delete iThemes;        
   121         }
   142         }
   122     
   143     
   123     // Deletes iInstallStatusObserver and closes iInstaller
   144     // Deletes iInstallStatusObserver and closes iInstaller
   124     CancelInstall(); 
   145     CancelInstall(); 
   125     iRomUids.Close();
   146     iRomUids.Close();
   126     
   147     
   127     iScrSession.Close();
   148     if ( iWidgetRegistry.Handle() )
       
   149         {
       
   150         // decreases widget server's refcount but this cannot be called
       
   151         // if Connect has not been called or we'll get a KERN-EXEC 0
       
   152         iWidgetRegistry.Disconnect();
       
   153         }
       
   154     else
       
   155         {
       
   156         iWidgetRegistry.Close();
       
   157         }
       
   158     iInstalledWidgets.ResetAndDestroy();
   128     iInstalledWidgetsInfos.ResetAndDestroy();
   159     iInstalledWidgetsInfos.ResetAndDestroy();
   129     }
   160     }
   130 
   161 
   131 // ---------------------------------------------------------------------------
   162 // ---------------------------------------------------------------------------
   132 // Constructor.
   163 // Constructor.
   141 // ---------------------------------------------------------------------------
   172 // ---------------------------------------------------------------------------
   142 //
   173 //
   143 void CNcdInstallationService::ConstructL()
   174 void CNcdInstallationService::ConstructL()
   144     {
   175     {
   145     DLTRACEIN((""));
   176     DLTRACEIN((""));
   146     
       
   147     iResults = 0;
       
   148     iArguments = 0;
       
   149     
       
   150     iDocHandler = CDocumentHandler::NewL();
   177     iDocHandler = CDocumentHandler::NewL();
   151     iDocHandler->SetExitObserver( this );
   178     iDocHandler->SetExitObserver( this );
   152     
   179     
   153     User::LeaveIfError( iFs.Connect() );
   180     User::LeaveIfError( iFs.Connect() );
   154     User::LeaveIfError( iFs.ShareProtected() );
   181     User::LeaveIfError( iFs.ShareProtected() );
   155     User::LeaveIfError( iRegistrySession.Connect() );
   182     User::LeaveIfError( iRegistrySession.Connect() );
   156     User::LeaveIfError( iAknsSrv.Connect() );
   183     User::LeaveIfError( iAknsSrv.Connect() ); 
   157     User::LeaveIfError( iScrSession.Connect());
       
   158 
   184 
   159     iInstallationCompleteCallback = new(ELeave) CAsyncCallBack( 
   185     iInstallationCompleteCallback = new(ELeave) CAsyncCallBack( 
   160         TCallBack( InstallationCompleteCallback, this ),
   186         TCallBack( InstallationCompleteCallback, this ),
   161         CActive::EPriorityStandard );  
   187         CActive::EPriorityStandard );  
   162               
   188               
   231 // ---------------------------------------------------------------------------
   257 // ---------------------------------------------------------------------------
   232 //
   258 //
   233 void CNcdInstallationService::SilentInstallL( RFile& aFile,
   259 void CNcdInstallationService::SilentInstallL( RFile& aFile,
   234                                         const TDesC& aMimeType,
   260                                         const TDesC& aMimeType,
   235                                         const TNcdItemPurpose& aPurpose,
   261                                         const TNcdItemPurpose& aPurpose,
   236                                         const Usif::COpaqueNamedParams* aInstallOptionsPckg )
   262                                         const SwiUI::TInstallOptionsPckg& aInstallOptionsPckg )
   237     {
   263     {
   238     DLTRACEIN((""));
   264     DLTRACEIN((""));
   239 
   265 
   240     if ( iSilentInstallActiveObserver == NULL )
   266     if ( iSilentInstallActiveObserver == NULL )
   241         {
   267         {
   242         DLINFO(("Create active observer for silent install"));
   268         DLINFO(("Create active observer for silent install"));
   243         iSilentInstallActiveObserver = CNcdSilentInstallActiveObserver::NewL( *this );        
   269         iSilentInstallActiveObserver = CNcdSilentInstallActiveObserver::NewL( *this );        
   244         }
   270         }
   245 
   271 
   246     InstallL( aFile, aMimeType, aPurpose, aInstallOptionsPckg );
   272     InstallL( aFile, aMimeType, aPurpose, &aInstallOptionsPckg );
   247 
   273 
   248     DLTRACEOUT(("")); 
   274     DLTRACEOUT(("")); 
   249     }
   275     }
   250 
   276 
   251 
   277 
   254 // ---------------------------------------------------------------------------
   280 // ---------------------------------------------------------------------------
   255 //
   281 //
   256 void CNcdInstallationService::SilentInstallJavaL( RFile& aFile,
   282 void CNcdInstallationService::SilentInstallJavaL( RFile& aFile,
   257                                             const TDesC& aMimeType,
   283                                             const TDesC& aMimeType,
   258                                             const TDesC8& aDescriptorData,
   284                                             const TDesC8& aDescriptorData,
   259                                             const Usif::COpaqueNamedParams* aInstallOptionsPckg )
   285                                             const SwiUI::TInstallOptionsPckg& aInstallOptionsPckg )
   260     {
   286     {
   261     DLTRACEIN((""));
   287     DLTRACEIN((""));
   262 
   288 
   263     if ( iSilentInstallActiveObserver == NULL )
   289     if ( iSilentInstallActiveObserver == NULL )
   264         {
   290         {
   265         DLINFO(("Create active observer for silent install"));
   291         DLINFO(("Create active observer for silent install"));
   266         iSilentInstallActiveObserver = CNcdSilentInstallActiveObserver::NewL( *this );        
   292         iSilentInstallActiveObserver = CNcdSilentInstallActiveObserver::NewL( *this );        
   267         }
   293         }
   268 
   294 
   269     InstallJavaL( aFile, aMimeType, aDescriptorData, aInstallOptionsPckg );
   295     InstallJavaL( aFile, aMimeType, aDescriptorData, &aInstallOptionsPckg );
   270 
   296 
   271     DLTRACEOUT((""));
   297     DLTRACEOUT((""));
   272     }
   298     }
   273 
   299 
   274 // ---------------------------------------------------------------------------
   300 // ---------------------------------------------------------------------------
   275 // Installs widget silently.
   301 // Installs widget silently.
   276 // ---------------------------------------------------------------------------
   302 // ---------------------------------------------------------------------------
   277 //
   303 //
   278 void CNcdInstallationService::SilentInstallWidgetL( RFile& aFile,
   304 void CNcdInstallationService::SilentInstallWidgetL( RFile& aFile,
   279                                                     const Usif::COpaqueNamedParams* aInstallOptionsPckg )
   305                                                     const SwiUI::TInstallOptionsPckg& aInstallOptionsPckg )
   280     {
   306     {
   281     DLTRACEIN((""));
   307     DLTRACEIN((""));
   282     
   308     
   283     if ( iSilentInstallActiveObserver == NULL )
   309     if ( iSilentInstallActiveObserver == NULL )
   284         {
   310         {
   285         DLINFO(("Create active observer for silent install"));
   311         DLINFO(("Create active observer for silent install"));
   286         iSilentInstallActiveObserver = CNcdSilentInstallActiveObserver::NewL( *this );        
   312         iSilentInstallActiveObserver = CNcdSilentInstallActiveObserver::NewL( *this );        
   287         }
   313         }
   288 
   314 
   289     InstallWidgetL( aFile, aInstallOptionsPckg );
   315     InstallWidgetL( aFile, &aInstallOptionsPckg );
   290     
   316     
   291     DLTRACEOUT((""));
   317     DLTRACEOUT((""));
   292     }
   318     }
   293 // ---------------------------------------------------------------------------
   319 // ---------------------------------------------------------------------------
   294 // Cancell silent install.
   320 // Cancell silent install.
   347             BaflUtils::DeleteFile( iFs, *iJadFileName ); // NOTE, error ignored
   373             BaflUtils::DeleteFile( iFs, *iJadFileName ); // NOTE, error ignored
   348             delete iJadFileName;
   374             delete iJadFileName;
   349             iJadFileName = NULL;
   375             iJadFileName = NULL;
   350             }
   376             }
   351         
   377         
       
   378 #ifdef USE_OLD_JAVA_API        
       
   379         // Clean the array.
       
   380         iMIDletUids.Reset();
       
   381 #endif        
       
   382 
   352         // Reset information flags.            
   383         // Reset information flags.            
   353         InstallationFinishedSetup( aError );
   384         InstallationFinishedSetup( aError );
   354         }
   385         }
   355     }
   386     }
   356 
   387 
   477 // ---------------------------------------------------------------------------
   508 // ---------------------------------------------------------------------------
   478 // Open java suite entry
   509 // Open java suite entry
   479 //
   510 //
   480 // ---------------------------------------------------------------------------
   511 // ---------------------------------------------------------------------------
   481 //
   512 //
       
   513 #ifdef USE_OLD_JAVA_API
   482 
   514 
   483 TBool CNcdInstallationService::JavaAppExistsL( 
   515 TBool CNcdInstallationService::JavaAppExistsL( 
   484     const TUid& aUid )
   516     const TUid& aUid )
   485     {
   517     {
   486     DLTRACEIN((""));
   518     DLTRACEIN((""));
   487 
   519 
   488     TBool retVal = EFalse;
   520     MJavaRegistry* javaRegistry = MJavaRegistry::CreateL();
   489     Usif::TComponentId compId = 0;
   521     CleanupReleasePushL( *javaRegistry );
   490         
   522     
   491     // Get component id
   523     TRAPD( err, 
   492     TRAPD( ret, compId = iScrSession.GetComponentIdForAppL( aUid ) ); 
   524         {
   493     if ( ret == KErrNotFound )
   525         // Leaves with KErrNotFound if not found
   494         {
   526         MJavaRegistryMIDletEntry* midletEntry = javaRegistry->MIDletEntryL(
   495         return EFalse;
   527             aUid );    
   496         }
   528         midletEntry->Release();
   497     else if  (ret != KErrNone )
   529         });
   498         {
   530     
   499         User::Leave( ret );
   531     LeaveIfNotErrorL( err, KErrNotFound );
   500         }
   532     
   501          
   533     CleanupStack::PopAndDestroy( javaRegistry );
   502     Usif::CComponentEntry* entry = Usif::CComponentEntry::NewLC();
   534     return err == KErrNone;
   503     TRAPD(err, iScrSession.GetComponentL(compId, *entry));
   535     }
   504     
   536 
   505     if ( err == KErrNotFound )
   537 #else
   506         {
   538 
   507         retVal = EFalse;
   539 TBool CNcdInstallationService::JavaAppExistsL( 
   508         }
   540     const TUid& aUid )
   509     else if  (err != KErrNone )
   541     {
   510         {
   542     DLTRACEIN((""));
   511         User::Leave( err );
   543 
   512         }
   544     CJavaRegistry* javaRegistry = CJavaRegistry::NewLC();    
   513     else
   545 
   514         {
   546     TBool exists = javaRegistry->RegistryEntryExistsL( aUid );
   515         // type == Java ?
   547     
   516         if ( entry->SoftwareType().Compare( Usif::KSoftwareTypeJava ) == 0 )
   548     CleanupStack::PopAndDestroy( javaRegistry );
   517             {
   549     return exists;
   518             retVal = ETrue;
   550     }
   519             }
   551 
   520         else
   552 #endif
   521             {
       
   522             retVal = EFalse;
       
   523             }
       
   524         }
       
   525     CleanupStack::PopAndDestroy(entry);
       
   526     return retVal;
       
   527     
       
   528     }
       
   529 
   553 
   530 // Check via widget registry API
   554 // Check via widget registry API
   531 TNcdApplicationStatus CNcdInstallationService::IsWidgetInstalledL(const TDesC& aIdentifier, const TCatalogsVersion& aVersion)
   555 TNcdApplicationStatus CNcdInstallationService::IsWidgetInstalledL(const TDesC& aIdentifier, const TCatalogsVersion& aVersion)
   532     {
   556     {
   533     DLTRACEIN((""));
   557     DLTRACEIN((""));
   898     {    
   922     {    
   899     DLTRACEIN(("aError: %d", aError));
   923     DLTRACEIN(("aError: %d", aError));
   900     
   924     
   901     iInstaller.Close();
   925     iInstaller.Close();
   902     
   926     
   903     if ( aError == KErrCancel ) 
   927     if ( aError == SwiUI::KSWInstErrUserCancel ) 
   904         {
   928         {
   905         DLTRACE(("User cancelled, converting error to KErrAbort" ) );
   929         DLTRACE(("User cancelled, converting error to KErrAbort" ) );
   906         aError = KErrAbort;        
   930         aError = KErrAbort;        
   907         }
   931         }
   908     
   932     
   947             }
   971             }
   948 
   972 
   949         if ( iInstallError != KErrNone ) 
   973         if ( iInstallError != KErrNone ) 
   950             {        
   974             {        
   951             DLTRACE(("Notify install error"));
   975             DLTRACE(("Notify install error"));
   952 
   976 #ifdef USE_OLD_JAVA_API            
       
   977             iMIDletUids.Reset();
       
   978 #endif            
   953             iObserver->InstallationCompleteL( KNullDesC, TUid(), iInstallError );       
   979             iObserver->InstallationCompleteL( KNullDesC, TUid(), iInstallError );       
   954             return; 
   980             return; 
   955             }
   981             }
   956 
   982 
   957         TUid midletUid = InstalledMidletUidL();
   983         TUid midletUid = InstalledMidletUidL();
  1287 // ---------------------------------------------------------------------------
  1313 // ---------------------------------------------------------------------------
  1288 //
  1314 //
  1289 void CNcdInstallationService::InstallL( RFile& aFile,
  1315 void CNcdInstallationService::InstallL( RFile& aFile,
  1290                                         const TDesC& aMimeType,
  1316                                         const TDesC& aMimeType,
  1291                                         const TNcdItemPurpose& aPurpose,
  1317                                         const TNcdItemPurpose& aPurpose,
  1292                                         const Usif::COpaqueNamedParams* aSilentInstallOptions )
  1318                                         const SwiUI::TInstallOptionsPckg* aSilentInstallOptionsPckg )
  1293     {
  1319     {
  1294     DLTRACEIN(( _L("iBusy=%d, MIME: %S"),iBusy, &aMimeType ));    
  1320     DLTRACEIN(( _L("iBusy=%d, MIME: %S"),iBusy, &aMimeType ));    
  1295     DASSERT( iObserver );
  1321     DASSERT( iObserver );
  1296     DASSERT( iDocHandler );
  1322     DASSERT( iDocHandler );
  1297 
  1323 
  1333         DLTRACE(("Java"));
  1359         DLTRACE(("Java"));
  1334         InstallJavaL( 
  1360         InstallJavaL( 
  1335             aFile, 
  1361             aFile, 
  1336             *iRecognizedMime, 
  1362             *iRecognizedMime, 
  1337             KNullDesC8, 
  1363             KNullDesC8, 
  1338             aSilentInstallOptions );
  1364             aSilentInstallOptionsPckg );
  1339         return;
  1365         return;
  1340         }
  1366         }
  1341     else if ( MatchWidget( aFile, aMimeType ) )
  1367     else if ( MatchWidget( aFile, aMimeType ) )
  1342         {
  1368         {
  1343         DLTRACE(("Widget"));
  1369         DLTRACE(("Widget"));
  1344         InstallWidgetL( 
  1370         InstallWidgetL( 
  1345             aFile,
  1371             aFile,
  1346             aSilentInstallOptions );
  1372             aSilentInstallOptionsPckg );
  1347         return;
  1373         return;
  1348         }
  1374         }
  1349     
  1375     
  1350     // Handle SIS(X) and DRM content which has a suitable purpose
  1376     // Handle SIS(X) and DRM content which has a suitable purpose
  1351     if ( aMimeType.MatchF( KMimeTypeMatchSymbianInstall ) != KErrNotFound
  1377     if ( aMimeType.MatchF( KMimeTypeMatchSymbianInstall ) != KErrNotFound
  1383         
  1409         
  1384         TDataType dataType;    
  1410         TDataType dataType;    
  1385         // Start application installation.
  1411         // Start application installation.
  1386         DLINFO(( "Calling doc handler Open" ));
  1412         DLINFO(( "Calling doc handler Open" ));
  1387 
  1413 
  1388         if ( !aSilentInstallOptions )
  1414         if ( !aSilentInstallOptionsPckg )
  1389             {
  1415             {
  1390             DLINFO(("Normal install"));
  1416             DLINFO(("Normal install"));
  1391             InitializeInstallerL();
  1417             InitializeInstallerL();
  1392             //iCancelCode = SwiUI::ERequestInstallHandle;
  1418             iCancelCode = SwiUI::ERequestInstallHandle;
  1393             
  1419             
  1394             if ( !iArguments )
  1420             iInstaller.Install( iInstallStatusObserver->iStatus, aFile );
  1395                 {
       
  1396                 iArguments = Usif::COpaqueNamedParams::NewL();
       
  1397                 }
       
  1398             if ( !iResults )
       
  1399                {
       
  1400                iResults = Usif::COpaqueNamedParams::NewL();
       
  1401                }
       
  1402             
       
  1403             iArguments->AddIntL( Usif::KSifInParam_InstallSilently, EFalse );
       
  1404             
       
  1405             iInstaller.Install( aFile, *iArguments, *iResults, iInstallStatusObserver->iStatus ); 
       
  1406             //iInstaller.Install( iInstallStatusObserver->iStatus, aFile );
       
  1407             iInstallStatusObserver->StartToObserve();            
  1421             iInstallStatusObserver->StartToObserve();            
  1408             }
  1422             }
  1409         else
  1423         else
  1410             {
  1424             {
  1411             DLINFO(("Silent install"));        
  1425             DLINFO(("Silent install"));        
  1412             // Set the observer active because it will be informed about the completion
  1426             // Set the observer active because it will be informed about the completion
  1413             // of the silent install and it will forward the information for the callback
  1427             // of the silent install and it will forward the information for the callback
  1414             // function of this class object.
  1428             // function of this class object.
  1415             iSilentInstallActiveObserver->StartToObserveL( aFile,
  1429             iSilentInstallActiveObserver->StartToObserveL( aFile,
  1416                                                            aSilentInstallOptions );
  1430                                                            *aSilentInstallOptionsPckg );
  1417             }
  1431             }
  1418             
  1432             
  1419         iBusy = ETrue;
  1433         iBusy = ETrue;
  1420  
  1434  
  1421         }
  1435         }
  1482 // ---------------------------------------------------------------------------
  1496 // ---------------------------------------------------------------------------
  1483 //
  1497 //
  1484 void CNcdInstallationService::InstallJavaL( RFile& aFile,
  1498 void CNcdInstallationService::InstallJavaL( RFile& aFile,
  1485                                             const TDesC& /*aMimeType*/,
  1499                                             const TDesC& /*aMimeType*/,
  1486                                             const TDesC8& aDescriptorData,
  1500                                             const TDesC8& aDescriptorData,
  1487                                             const Usif::COpaqueNamedParams* aSilentInstallOptions )
  1501                                             const SwiUI::TInstallOptionsPckg* aSilentInstallOptionsPckg )
  1488     {
  1502     {
  1489     DLTRACEIN((_L("iBusy=%d, descriptor=%d"),iBusy, aDescriptorData.Length() ));
  1503     DLTRACEIN((_L("iBusy=%d, descriptor=%d"),iBusy, aDescriptorData.Length() ));
  1490     DASSERT( iObserver );
  1504     DASSERT( iObserver );
  1491 
  1505 
  1492     // Check if some installation is already in progress.
  1506     // Check if some installation is already in progress.
  1496         User::Leave( KErrInUse );
  1510         User::Leave( KErrInUse );
  1497         }
  1511         }
  1498 
  1512 
  1499     iInstallError = KErrNone;
  1513     iInstallError = KErrNone;
  1500     
  1514     
       
  1515 #ifdef USE_OLD_JAVA_API
       
  1516     // Store installed java app uids before installation to see
       
  1517     // which one is a new java app later.
       
  1518     MJavaRegistry* javaRegistry = MJavaRegistry::CreateL();
       
  1519     CleanupReleasePushL( *javaRegistry );
       
  1520     iMIDletUids.Reset();
       
  1521     javaRegistry->InstalledMIDletUidsL( iMIDletUids );
       
  1522     CleanupStack::PopAndDestroy( javaRegistry );
       
  1523 #endif
  1501     
  1524     
  1502     // In platform security systems JAR and JAD has to be in same folder
  1525     // In platform security systems JAR and JAD has to be in same folder
  1503     // to get the installation process work correctly.
  1526     // to get the installation process work correctly.
  1504     // First form the JAD filename from the JAR filename.
  1527     // First form the JAD filename from the JAR filename.
  1505 
  1528 
  1517 
  1540 
  1518     
  1541     
  1519     iInstallType = EJavaInstall;
  1542     iInstallType = EJavaInstall;
  1520     TDataType dataType;    
  1543     TDataType dataType;    
  1521             
  1544             
  1522     if ( aSilentInstallOptions == NULL )
  1545     if ( aSilentInstallOptionsPckg == NULL )
  1523         {
  1546         {
  1524         DLINFO(("Normal install"));
  1547         DLINFO(("Normal install"));
  1525         InitializeInstallerL();
  1548         InitializeInstallerL();
  1526         if( iJadFileName )
  1549         if( iJadFileName )
  1527             {
  1550             {
  1528             DLTRACE(("Installing JAD+JAR"));
  1551             DLTRACE(("Installing JAD+JAR"));
  1529             // JAD+JAR install
  1552             // JAD+JAR install
  1530             //iCancelCode = SwiUI::ERequestInstall;
  1553             iCancelCode = SwiUI::ERequestInstall;
  1531             if ( !iArguments )
  1554             iInstaller.Install( iInstallStatusObserver->iStatus, *iJadFileName );
  1532                 {
       
  1533                 iArguments = Usif::COpaqueNamedParams::NewL();
       
  1534                 }
       
  1535             if ( !iResults )
       
  1536                 {
       
  1537                 iResults = Usif::COpaqueNamedParams::NewL();
       
  1538                 }
       
  1539              
       
  1540              iArguments->AddIntL( Usif::KSifInParam_InstallSilently, EFalse );
       
  1541                         
       
  1542             iInstaller.Install( *iJadFileName, *iArguments, *iResults, iInstallStatusObserver->iStatus ); 
       
  1543             //iInstaller.Install( iInstallStatusObserver->iStatus, *iJadFileName );
       
  1544             }
  1555             }
  1545         else
  1556         else
  1546             {
  1557             {
  1547             DLTRACE(("Installing JAR"));
  1558             DLTRACE(("Installing JAR"));
  1548             // JAR install
  1559             // JAR install
  1549             //iCancelCode = SwiUI::ERequestInstallHandle;
  1560             iCancelCode = SwiUI::ERequestInstallHandle;
  1550             if ( !iArguments )
  1561             iInstaller.Install( iInstallStatusObserver->iStatus, aFile );
  1551                 {
       
  1552                 iArguments = Usif::COpaqueNamedParams::NewL();
       
  1553                 }
       
  1554             if ( !iResults )
       
  1555                {
       
  1556                iResults = Usif::COpaqueNamedParams::NewL();
       
  1557                }
       
  1558             
       
  1559              iArguments->AddIntL( Usif::KSifInParam_InstallSilently, EFalse );
       
  1560              
       
  1561              iInstaller.Install( aFile, *iArguments, *iResults, iInstallStatusObserver->iStatus ); 
       
  1562             
       
  1563             //iInstaller.Install( iInstallStatusObserver->iStatus, aFile );
       
  1564             }
  1562             }
  1565         
  1563         
  1566         iInstallStatusObserver->StartToObserve();
  1564         iInstallStatusObserver->StartToObserve();
  1567         }
  1565         }
  1568     else
  1566     else
  1574             // JAD+JAR install
  1572             // JAD+JAR install
  1575             // Set the observer active because it will be informed about the completion
  1573             // Set the observer active because it will be informed about the completion
  1576             // of the silent install and it will forward the information for the callback
  1574             // of the silent install and it will forward the information for the callback
  1577             // function of this class object.
  1575             // function of this class object.
  1578             iSilentInstallActiveObserver->StartToObserveL( *iJadFileName,
  1576             iSilentInstallActiveObserver->StartToObserveL( *iJadFileName,
  1579                                                            aSilentInstallOptions );
  1577                                                            *aSilentInstallOptionsPckg );
  1580             }
  1578             }
  1581         else
  1579         else
  1582             {
  1580             {
  1583             DLINFO(("Silent jar"));
  1581             DLINFO(("Silent jar"));
  1584             // JAR install
  1582             // JAR install
  1585             // Set the observer active because it will be informed about the completion
  1583             // Set the observer active because it will be informed about the completion
  1586             // of the silent install and it will forward the information for the callback
  1584             // of the silent install and it will forward the information for the callback
  1587             // function of this class object.
  1585             // function of this class object.
  1588             iSilentInstallActiveObserver->StartToObserveL( aFile,
  1586             iSilentInstallActiveObserver->StartToObserveL( aFile,
  1589                                                            aSilentInstallOptions );
  1587                                                            *aSilentInstallOptionsPckg );
  1590             }        
  1588             }        
  1591         }
  1589         }
  1592 
  1590 
  1593     iBusy = ETrue;
  1591     iBusy = ETrue;
  1594 
  1592 
  1600 // Installs Widgets files in normal or in silent way.
  1598 // Installs Widgets files in normal or in silent way.
  1601 // ---------------------------------------------------------------------------
  1599 // ---------------------------------------------------------------------------
  1602 //
  1600 //
  1603 void CNcdInstallationService::InstallWidgetL( 
  1601 void CNcdInstallationService::InstallWidgetL( 
  1604     RFile& aFile,
  1602     RFile& aFile,
  1605     const Usif::COpaqueNamedParams* aSilentInstallOptions )
  1603     const SwiUI::TInstallOptionsPckg* aSilentInstallOptionsPckg )
  1606     {
  1604     {
  1607     DLTRACEIN((""));    
  1605     DLTRACEIN((""));    
  1608     
  1606     
  1609     iInstallType = EWidgetInstall;
  1607     iInstallType = EWidgetInstall;
  1610 
  1608 
  1614 
  1612 
  1615     TDataType dataType;    
  1613     TDataType dataType;    
  1616     // Start application installation.
  1614     // Start application installation.
  1617     DLINFO(( "Calling doc handler Open" ));
  1615     DLINFO(( "Calling doc handler Open" ));
  1618 
  1616 
  1619     if ( !aSilentInstallOptions )
  1617     if ( !aSilentInstallOptionsPckg )
  1620         {
  1618         {
  1621         DLINFO(("Normal install"));
  1619         DLINFO(("Normal install"));
  1622         InitializeInstallerL();
  1620         InitializeInstallerL();
  1623         //iCancelCode = SwiUI::ERequestInstallHandle;
  1621         iCancelCode = SwiUI::ERequestInstallHandle;
  1624         if ( !iArguments )
  1622         
  1625             {
  1623         iInstaller.Install( iInstallStatusObserver->iStatus, aFile );
  1626             iArguments = Usif::COpaqueNamedParams::NewL();
       
  1627             }
       
  1628         if ( !iResults )
       
  1629            {
       
  1630            iResults = Usif::COpaqueNamedParams::NewL();
       
  1631            }
       
  1632                     
       
  1633         iArguments->AddIntL( Usif::KSifInParam_InstallSilently, EFalse );
       
  1634         iInstaller.Install(aFile, *iArguments, *iResults, iInstallStatusObserver->iStatus  );
       
  1635          
       
  1636         //iInstaller.Install( iInstallStatusObserver->iStatus, aFile );
       
  1637         iInstallStatusObserver->StartToObserve();            
  1624         iInstallStatusObserver->StartToObserve();            
  1638         }
  1625         }
  1639     else
  1626     else
  1640         {
  1627         {
  1641         DLINFO(("Silent install"));        
  1628         DLINFO(("Silent install"));        
  1642         // Set the observer active because it will be informed about the completion
  1629         // Set the observer active because it will be informed about the completion
  1643         // of the silent install and it will forward the information for the callback
  1630         // of the silent install and it will forward the information for the callback
  1644         // function of this class object.
  1631         // function of this class object.
  1645         iSilentInstallActiveObserver->StartToObserveL( aFile,
  1632         iSilentInstallActiveObserver->StartToObserveL( aFile,
  1646                                                        aSilentInstallOptions );
  1633                                                        *aSilentInstallOptionsPckg );
  1647         }
  1634         }
  1648         
  1635         
  1649     iBusy = ETrue;
  1636     iBusy = ETrue;
  1650 
  1637 
  1651     }
  1638     }
  1658     {
  1645     {
  1659     DLTRACEIN((""));
  1646     DLTRACEIN((""));
  1660     DeletePtr( iInstallStatusObserver );
  1647     DeletePtr( iInstallStatusObserver );
  1661     iInstallStatusObserver = CNcdActiveOperationObserver::NewL( *this );
  1648     iInstallStatusObserver = CNcdActiveOperationObserver::NewL( *this );
  1662     
  1649     
  1663     User::LeaveIfError( iInstaller.Connect() );
       
  1664     /*
       
  1665     if ( !iInstaller.Handle() ) 
  1650     if ( !iInstaller.Handle() ) 
  1666         {
  1651         {
  1667         User::LeaveIfError( iInstaller.Connect() );
  1652         User::LeaveIfError( iInstaller.Connect() );
  1668         }
  1653         }
  1669     */
       
  1670     }
  1654     }
  1671     
  1655     
  1672 
  1656 
  1673 // ---------------------------------------------------------------------------
  1657 // ---------------------------------------------------------------------------
  1674 // Cancels installation
  1658 // Cancels installation
  1675 // ---------------------------------------------------------------------------
  1659 // ---------------------------------------------------------------------------
  1676 //
  1660 //
  1677 void CNcdInstallationService::CancelInstall()
  1661 void CNcdInstallationService::CancelInstall()
  1678     {
  1662     {
  1679     DLTRACEIN((""));
  1663     DLTRACEIN((""));
  1680     //if ( iInstallStatusObserver &&
  1664     if ( iInstallStatusObserver &&
  1681     //     iInstaller.Handle() ) 
  1665          iInstaller.Handle() ) 
  1682     if ( iInstallStatusObserver )
       
  1683         {
  1666         {
  1684         DLTRACE(("Cancelling installation"));
  1667         DLTRACE(("Cancelling installation"));
  1685         iInstaller.CancelOperation();
  1668         iInstaller.CancelAsyncRequest( iCancelCode );
  1686         //iInstaller.CancelAsyncRequest( iCancelCode );
       
  1687         }
  1669         }
  1688     
  1670     
  1689     DeletePtr( iInstallStatusObserver );
  1671     DeletePtr( iInstallStatusObserver );
  1690     iInstaller.Close();
  1672     iInstaller.Close();
  1691     }
  1673     }
  1838 //
  1820 //
  1839 void CNcdInstallationService::InitializeRomApplicationListL()
  1821 void CNcdInstallationService::InitializeRomApplicationListL()
  1840     {
  1822     {
  1841     DLTRACEIN((""));
  1823     DLTRACEIN((""));
  1842         
  1824         
  1843 /*    TApaAppInfo info;
  1825     TApaAppInfo info;
  1844     ConnectApaLsL();    
  1826     ConnectApaLsL();    
  1845     User::LeaveIfError( iApaLs.GetAllApps() );
  1827     User::LeaveIfError( iApaLs.GetAllApps() );
  1846     
  1828     
  1847     iRomUids.Reset();
  1829     iRomUids.Reset();
  1848     
  1830     
  1866 
  1848 
  1867     do
  1849     do
  1868         {       
  1850         {       
  1869         appErr = iApaLs.GetNextApp( info );
  1851         appErr = iApaLs.GetNextApp( info );
  1870         if ( appErr == KErrNone )
  1852         if ( appErr == KErrNone )
  1871             {
  1853             {            
  1872             DLTRACE(("After GetNextApp"));
       
  1873             // App is considered a ROM app if its not found either
  1854             // App is considered a ROM app if its not found either
  1874             // in SIS registry or midlet registry
  1855             // in SIS registry or midlet registry
  1875             // Note: ROM apps can be in SIS registry also but that doesn't
  1856             // Note: ROM apps can be in SIS registry also but that doesn't
  1876             // matter because we just want to get a list of apps that are
  1857             // matter because we just want to get a list of apps that are
  1877             // not found anywhere else but apparc
  1858             // not found anywhere else but apparc
  1910             }
  1891             }
  1911         }
  1892         }
  1912     while( appErr == KErrNone && retryCount >= 0 );
  1893     while( appErr == KErrNone && retryCount >= 0 );
  1913         
  1894         
  1914     iApaLs.Close();
  1895     iApaLs.Close();
  1915     CleanupStack::PopAndDestroy( &midletUids );*/    
  1896     CleanupStack::PopAndDestroy( &midletUids );    
  1916     
  1897     
  1917     DLTRACEOUT(("ROM apps: %d", iRomUids.Count() ));
  1898     DLTRACEOUT(("ROM apps: %d", iRomUids.Count() ));
  1918     }
  1899     }
  1919 
  1900 
  1920 
  1901 
  1921 // ---------------------------------------------------------------------------
  1902 // ---------------------------------------------------------------------------
  1922 // Gets a list of installed midlet UIDs
  1903 // Gets a list of installed midlet UIDs
  1923 // ---------------------------------------------------------------------------
  1904 // ---------------------------------------------------------------------------
  1924 //
  1905 //
       
  1906 #ifdef USE_OLD_JAVA_API
  1925 
  1907 
  1926 void CNcdInstallationService::MidletUidsL( RArray<TUid>& aUids )
  1908 void CNcdInstallationService::MidletUidsL( RArray<TUid>& aUids )
  1927     {
  1909     {
  1928 
  1910     DLTRACEIN((""));
  1929     // Get ids of all java components in scr
  1911     MJavaRegistry* javaRegistry = MJavaRegistry::CreateL();
  1930     RArray<Usif::TComponentId> javaComponentIdList;
  1912     CleanupReleasePushL( *javaRegistry );
  1931     CleanupClosePushL( javaComponentIdList );
  1913     javaRegistry->InstalledMIDletUidsL( aUids );
  1932     
  1914     CleanupStack::PopAndDestroy( javaRegistry );    
  1933     Usif::CComponentFilter *pJavaSwTypeFilter = Usif::CComponentFilter::NewLC();
  1915     }
  1934     pJavaSwTypeFilter->SetSoftwareTypeL( Usif::KSoftwareTypeJava );
  1916 
  1935     iScrSession.GetComponentIdsL( javaComponentIdList, pJavaSwTypeFilter );
  1917 #else
  1936     CleanupStack::PopAndDestroy( pJavaSwTypeFilter );
  1918 
  1937 
  1919 void CNcdInstallationService::MidletUidsL( RArray<TUid>& aUids )
  1938     
  1920     {
  1939     // Get components
  1921     DLTRACEIN((""));
  1940     TInt aUidIndex = 0;
  1922     CJavaRegistry* javaRegistry = CJavaRegistry::NewLC();
  1941     for ( TInt i = 0; i < javaComponentIdList.Count(); ++i )
  1923     javaRegistry->GetRegistryEntryUidsL( aUids );          
  1942         {
  1924     CleanupStack::PopAndDestroy( javaRegistry );    
  1943         RArray<TUid> midletUids;
  1925     }
  1944         CleanupClosePushL( midletUids );
  1926 
  1945         iScrSession.GetAppUidsForComponentL( javaComponentIdList[i], midletUids );
  1927 #endif
  1946         for ( TInt j = 0; j < midletUids.Count(); ++j )
  1928 
  1947             {
       
  1948             aUids[aUidIndex] = aUids[j];
       
  1949             aUidIndex++;
       
  1950             }
       
  1951         CleanupStack::PopAndDestroy(); // midletUids
       
  1952         }
       
  1953     
       
  1954     CleanupStack::PopAndDestroy(); // javaComponentIdList
       
  1955     
       
  1956     }
       
  1957 
  1929 
  1958 // ---------------------------------------------------------------------------
  1930 // ---------------------------------------------------------------------------
  1959 // Checks if the application is in ROM
  1931 // Checks if the application is in ROM
  1960 // ---------------------------------------------------------------------------
  1932 // ---------------------------------------------------------------------------
  1961 //
  1933 //
  1962 TBool CNcdInstallationService::IsRomApplication( const TUid& aUid ) const
  1934 TBool CNcdInstallationService::IsRomApplication( const TUid& aUid ) const
  1963     {
  1935     {
  1964     DLTRACEIN(("UID: %x", aUid.iUid ));
  1936     DLTRACEIN(("UID: %x", aUid.iUid ));
  1965     return iRomUids.Find( aUid ) != KErrNotFound;    
  1937     return iRomUids.Find( aUid ) != KErrNotFound;    
  1966     }
  1938     }
       
  1939 
       
  1940 
       
  1941 // ---------------------------------------------------------------------------
       
  1942 // Returns the UID of the latest installed midlet, NULL UID if none have
       
  1943 // been installed since the last device restart
       
  1944 // ---------------------------------------------------------------------------
       
  1945 //
       
  1946 #ifdef USE_OLD_JAVA_API
       
  1947 
       
  1948 TUid CNcdInstallationService::LatestMidletUidL( 
       
  1949     MJavaRegistry& aJavaRegistry ) const
       
  1950     {
       
  1951     DLTRACEIN((""));
       
  1952     TInt suiteUid = 0;            
       
  1953     
       
  1954     // Get UID for the latest installed Midlet suite
       
  1955     // KPSUidJavaLatestInstallation = 0x10282567
       
  1956     // Ignoring error in case the key or read policy change so that client
       
  1957     // doesn't behave strangely
       
  1958     RProperty::Get( KUidSystemCategory, 
       
  1959         KPSUidJavaLatestInstallation, suiteUid );
       
  1960     
       
  1961     DLTRACE(("JMI UID: %x", suiteUid ));
       
  1962 
       
  1963     if ( !suiteUid )  
       
  1964         {
       
  1965         return KNullUid;
       
  1966         }
       
  1967     
       
  1968     // Get entry for the installed suite
       
  1969     MJavaRegistrySuiteEntry* suite = aJavaRegistry.SuiteEntryL( 
       
  1970         TUid::Uid( suiteUid ) );
       
  1971     CleanupReleasePushL( *suite );        
       
  1972     RArray<TUid> suiteUids;
       
  1973     CleanupClosePushL( suiteUids );
       
  1974 
       
  1975     TUid midletUid = KNullUid; 
       
  1976     suite->MIDletUidsL( suiteUids );
       
  1977     
       
  1978     // Take first midlet UID from the suite
       
  1979     if ( suiteUids.Count() ) 
       
  1980         {
       
  1981         midletUid = suiteUids[0];
       
  1982         }
       
  1983     DLTRACE(("Midlets in suite: %d", suite->NumberOfMIDletsL() ));
       
  1984     CleanupStack::PopAndDestroy( &suiteUids );
       
  1985     DLTRACE(("InstalledAppsEntryUid: %x", midletUid.iUid ));
       
  1986 
       
  1987     CleanupStack::PopAndDestroy( suite );    
       
  1988     return midletUid;
       
  1989     }
       
  1990 
       
  1991 #else
       
  1992 
       
  1993 TUid CNcdInstallationService::LatestMidletUidL( 
       
  1994     CJavaRegistry& aJavaRegistry ) const
       
  1995     {
       
  1996     DLTRACEIN((""));
       
  1997     TInt suiteUid = 0;            
       
  1998     
       
  1999     // Get UID for the latest installed Midlet suite
       
  2000     // KPSUidJavaLatestInstallation = 0x10282567
       
  2001     // Ignoring error in case the key or read policy change so that client
       
  2002     // doesn't behave strangely
       
  2003     RProperty::Get( KUidSystemCategory, 
       
  2004         KPSUidJavaLatestInstallation, suiteUid );
       
  2005     
       
  2006     DLTRACE(("JMI UID: %x", suiteUid ));
       
  2007 
       
  2008     if ( !suiteUid )  
       
  2009         {
       
  2010         return KNullUid;
       
  2011         }
       
  2012     
       
  2013     // Get entry for the installed suite
       
  2014     CJavaRegistryEntry* suite = aJavaRegistry.RegistryEntryL( 
       
  2015         TUid::Uid( suiteUid ) );
       
  2016     
       
  2017     if ( !suite )
       
  2018         {
       
  2019         return KNullUid;
       
  2020         }
       
  2021     
       
  2022     CleanupStack::PushL( suite );        
       
  2023     
       
  2024     DASSERT( suite->Type() < EGeneralApplication && 
       
  2025              suite->Type() >= EGeneralPackage );
       
  2026     
       
  2027     CJavaRegistryPackageEntry* entry = 
       
  2028         static_cast<CJavaRegistryPackageEntry*>( suite );
       
  2029     
       
  2030     TUid midletUid = KNullUid;
       
  2031     TInt count = entry->NumberOfEmbeddedEntries(); 
       
  2032     TBool appFound = EFalse;
       
  2033     TInt index = 0;
       
  2034     
       
  2035     // Find the first application from the suite
       
  2036     while ( index < count && !appFound )
       
  2037         {
       
  2038         CJavaRegistryEntry* app = entry->EmbeddedEntryByNumberL( index );
       
  2039         if ( app->Type() >= EGeneralApplication ) 
       
  2040             {
       
  2041             midletUid = app->Uid();
       
  2042             appFound = ETrue;
       
  2043             DLTRACE(( "Found app: %x", midletUid.iUid ));
       
  2044             }
       
  2045         delete app;
       
  2046         ++index;
       
  2047         }
       
  2048     
       
  2049     CleanupStack::PopAndDestroy( suite );    
       
  2050     return midletUid;
       
  2051     }
       
  2052 
       
  2053 
       
  2054 #endif
  1967 
  2055 
  1968 // ---------------------------------------------------------------------------
  2056 // ---------------------------------------------------------------------------
  1969 // Returns true if the MIME type matches a Java application or descriptor
  2057 // Returns true if the MIME type matches a Java application or descriptor
  1970 // ---------------------------------------------------------------------------
  2058 // ---------------------------------------------------------------------------
  1971 //
  2059 //
  1975              aMime.MatchF( KMimeTypeMatch2JavaApplication ) != KErrNotFound ||
  2063              aMime.MatchF( KMimeTypeMatch2JavaApplication ) != KErrNotFound ||
  1976              aMime.MatchF( KMimeTypeMatchJad ) != KErrNotFound );        
  2064              aMime.MatchF( KMimeTypeMatchJad ) != KErrNotFound );        
  1977     }
  2065     }
  1978 
  2066 
  1979 
  2067 
  1980 
  2068 #ifdef USE_OLD_JAVA_API
  1981 
  2069 
  1982 TUid CNcdInstallationService::InstalledMidletUidL()
  2070 TUid CNcdInstallationService::InstalledMidletUidL()
  1983     {
  2071     {
  1984 
  2072     DLTRACEIN((""));
  1985     //Usif::COpaqueNamedParams* iResults = 0; // to be removed
  2073     RArray<TUid> MIDletUids;
  1986     
  2074     CleanupClosePushL( MIDletUids );
  1987     RArray<TUid> appUids;
  2075     
  1988     TUid midletUid = KNullUid;
  2076     MJavaRegistry* javaRegistry = MJavaRegistry::CreateL();
  1989     TInt compId = 0;
  2077     CleanupReleasePushL( *javaRegistry );
  1990     
  2078     javaRegistry->InstalledMIDletUidsL( MIDletUids );
  1991     // Get component id
  2079     TUid MIDletUid = KNullUid;
  1992     TRAPD ( err, iResults->IntByNameL( Usif::KSifOutParam_ComponentId ));
  2080     // Search for new uids in Java registry.
  1993     if ( err == KErrNotFound )
  2081     for ( TInt i = 0 ; i < MIDletUids.Count() ; i++ )
  1994         {
  2082         {
  1995         return midletUid;
  2083         if ( iMIDletUids.Find( MIDletUids[i] ) == KErrNotFound )
  1996         }
  2084             {
  1997     
  2085             // A new uid found, this is the installed midlet's uid
  1998     // Get components
  2086             MIDletUid = MIDletUids[i];
  1999     CleanupClosePushL( appUids );
  2087             break;
  2000     iScrSession.GetAppUidsForComponentL( compId, appUids );
  2088             }
  2001     
  2089         }
  2002     // return first midlet uid, if exists
  2090 
  2003     if ( appUids.Count() != 0 )
  2091     // We didn't get any new UID so we have to check Java installer's
  2004         {
  2092     // P&S key for the installed suite UID and the get the midlet UID
  2005         midletUid = appUids[0];
  2093     // from that. This happens when a midlet with predefined UID, 
  2006         }
  2094     // eg. WidSets, is reinstalled. Midlet UIDs are predefined with
  2007     CleanupStack::PopAndDestroy(); // appUids 
  2095     // the attribute Nokia-MIDlet-UID-<n> in a JAD or JAR manifest
       
  2096     if ( MIDletUid == KNullUid ) 
       
  2097         {
       
  2098         MIDletUid = LatestMidletUidL( *javaRegistry );
       
  2099         }
       
  2100     
       
  2101     CleanupStack::PopAndDestroy( javaRegistry );
       
  2102     CleanupStack::PopAndDestroy( &MIDletUids );
       
  2103 
       
  2104     iMIDletUids.Reset();
       
  2105     return MIDletUid;
       
  2106     }
       
  2107 
       
  2108 #else // USE_OLD_JAVA_API
       
  2109 
       
  2110 TUid CNcdInstallationService::InstalledMidletUidL()
       
  2111     {
       
  2112     DLTRACEIN((""));
       
  2113     CJavaRegistry* registry = CJavaRegistry::NewLC();
       
  2114     TUid midletUid = LatestMidletUidL( *registry );
       
  2115     CleanupStack::PopAndDestroy( registry );
  2008     return midletUid;
  2116     return midletUid;
       
  2117     }
       
  2118 
       
  2119 #endif // USE_OLD_JAVA_API
       
  2120 
       
  2121 
       
  2122 // ---------------------------------------------------------------------------
       
  2123 // Populates the list of installed widgets
       
  2124 // ---------------------------------------------------------------------------
       
  2125 //
       
  2126 void CNcdInstallationService::PopulateInstalledWidgetUidsL() 
       
  2127     {
       
  2128     DLTRACEIN((""));
       
  2129 
       
  2130     if ( !iWidgetRegistry.Handle() )
       
  2131         {
       
  2132         User::LeaveIfError( iWidgetRegistry.Connect() );
       
  2133         }
       
  2134     
       
  2135     iInstalledWidgets.ResetAndDestroy();
       
  2136     User::LeaveIfError( iWidgetRegistry.InstalledWidgetsL( iInstalledWidgets ) );    
  2009     }
  2137     }
  2010 
  2138 
  2011 // ---------------------------------------------------------------------------
  2139 // ---------------------------------------------------------------------------
  2012 // Populates the list of installed widgets
  2140 // Populates the list of installed widgets
  2013 // ---------------------------------------------------------------------------
  2141 // ---------------------------------------------------------------------------
  2015 void CNcdInstallationService::PopulateInstalledWidgetsL
  2143 void CNcdInstallationService::PopulateInstalledWidgetsL
  2016          (RExtendedWidgetInfoArray& aWidgets) 
  2144          (RExtendedWidgetInfoArray& aWidgets) 
  2017     {
  2145     {
  2018     DLTRACEIN((""));
  2146     DLTRACEIN((""));
  2019     
  2147     
  2020     // Get ids of all widget components in scr
  2148     // Get the list of installed widget uids 
  2021     RArray<Usif::TComponentId> widgetComponentIdList;
  2149     PopulateInstalledWidgetUidsL();
  2022     Usif::CComponentFilter *pWidgetSwTypeFilter = Usif::CComponentFilter::NewLC();
  2150     
  2023     pWidgetSwTypeFilter->SetSoftwareTypeL(Usif::KSoftwareTypeWidget);
  2151     const TInt count = iInstalledWidgets.Count();
  2024 
  2152     
  2025     iScrSession.GetComponentIdsL(widgetComponentIdList, pWidgetSwTypeFilter);
  2153     // Create array with UID & Version infos
  2026     
       
  2027     CleanupStack::PopAndDestroy(pWidgetSwTypeFilter);
       
  2028     CleanupClosePushL(widgetComponentIdList);
       
  2029     
       
  2030     const TInt count = widgetComponentIdList.Count();
       
  2031     
       
  2032     // Create array with id & version infos
       
  2033     for ( TInt i = 0; i < count; ++i )
  2154     for ( TInt i = 0; i < count; ++i )
  2034         {
  2155         {
  2035         CExtendedWidgetInfo* tempInfo = new ( ELeave ) CExtendedWidgetInfo();
  2156         CExtendedWidgetInfo* tempInfo = new ( ELeave ) CExtendedWidgetInfo();
  2036         CleanupStack::PushL( tempInfo );
  2157         CleanupStack::PushL( tempInfo );
  2037         
  2158         
  2038         // Get widget
  2159         CWidgetInfo* widgetInfo = iInstalledWidgets[i];
  2039         Usif::TComponentId compId = widgetComponentIdList[i];
  2160         
  2040         Usif::CComponentEntry* entry = Usif::CComponentEntry::NewLC();
  2161         CWidgetPropertyValue* version = iWidgetRegistry.GetWidgetPropertyValueL
  2041         iScrSession.GetComponentL(compId, *entry);
  2162             (widgetInfo->iUid, EBundleVersion );
  2042         
  2163         CleanupStack::PushL( version );
  2043         // Fill id & version
  2164 
  2044         tempInfo->iUid.iUid= compId;
  2165         // Fill info
  2045         *(tempInfo->iVersion) = entry->Version();
  2166         tempInfo->iUid = widgetInfo->iUid;
       
  2167         if (!version->iValue.s)
       
  2168             *(tempInfo->iVersion) = KDefVersion;
       
  2169         else
       
  2170             *(tempInfo->iVersion) = *(version->iValue.s);
  2046         
  2171         
  2047         // Append to arrayt
  2172         // Append to arrayt
  2048         aWidgets.AppendL( tempInfo );
  2173         aWidgets.AppendL( tempInfo );
  2049         
  2174 
  2050         CleanupStack::PopAndDestroy(entry);
  2175         CleanupStack::PopAndDestroy( version );
  2051         CleanupStack::Pop( tempInfo );
  2176         CleanupStack::Pop( tempInfo );
  2052         }
  2177         }
  2053     
       
  2054     
       
  2055     CleanupStack::PopAndDestroy(); // widgetComponentIdList
       
  2056    
  2178    
  2057     DLTRACEOUT((""));
  2179         DLTRACEOUT((""));
  2058 
  2180 
  2059     }
  2181     }
  2060 
  2182 
  2061 // ---------------------------------------------------------------------------
  2183 // ---------------------------------------------------------------------------
  2062 // Gets the name of widget that was installed last
  2184 // Gets the name of widget that was installed last
  2063 // ---------------------------------------------------------------------------
  2185 // ---------------------------------------------------------------------------
  2064 //
  2186 //
  2065 
       
  2066 HBufC* CNcdInstallationService::InstalledWidgetNameLC()
  2187 HBufC* CNcdInstallationService::InstalledWidgetNameLC()
  2067     {
  2188     {
  2068     DLTRACEIN((""));
  2189     DLTRACEIN((""));
  2069     
  2190     
  2070     // Not currently suported
  2191     TUid widgetUid = InstalledWidgetUidL();
  2071     return NULL;
  2192     
       
  2193     if ( widgetUid == KNullUid )
       
  2194         {
       
  2195         DLERROR(("No widget uid"));
       
  2196         // No new UID was found, so we assume user canceled the installation.
       
  2197         // Installer does not give any error code in that case.
       
  2198         return NULL;
       
  2199         }
       
  2200 
       
  2201     HBufC* bundleId = HBufC::NewLC( KWidgetBundleIdLength );
       
  2202     TPtr des( bundleId->Des() );
       
  2203     iWidgetRegistry.GetWidgetBundleId( widgetUid, des );            
       
  2204 
       
  2205     DLTRACEOUT(( _L("Widget bundle id: %S"), bundleId ));
       
  2206     return bundleId;
  2072     }
  2207     }
  2073     
  2208     
  2074 
  2209 
  2075 // ---------------------------------------------------------------------------
  2210 // ---------------------------------------------------------------------------
  2076 // Gets the UID of the widget that was just installed 
  2211 // Gets the UID of the widget that was just installed 
  2176     iObserver->InstallationCompleteL( KNullDesC, uid, iInstallError );
  2311     iObserver->InstallationCompleteL( KNullDesC, uid, iInstallError );
  2177     }
  2312     }
  2178 
  2313 
  2179 
  2314 
  2180 // ---------------------------------------------------------------------------
  2315 // ---------------------------------------------------------------------------
       
  2316 //   
       
  2317 // ---------------------------------------------------------------------------
       
  2318 //
       
  2319 TBool CNcdInstallationService::WidgetExistsL( const TUid& aUid )
       
  2320     {
       
  2321     DLTRACEIN((""));
       
  2322 
       
  2323     if ( !iWidgetRegistry.Handle() )
       
  2324         {
       
  2325         User::LeaveIfError( iWidgetRegistry.Connect() );
       
  2326         }
       
  2327     
       
  2328     if ( iWidgetRegistry.IsWidget( aUid ) )
       
  2329         {
       
  2330         TBuf<KWidgetBundleIdLength> id;
       
  2331         iWidgetRegistry.GetWidgetBundleId( aUid, id );
       
  2332         return iWidgetRegistry.WidgetExistsL( id );
       
  2333         }
       
  2334     return EFalse;         
       
  2335     }
       
  2336 
       
  2337 // ---------------------------------------------------------------------------
  2181 //Calling widget registry API to check if a widget with given uid is installed 
  2338 //Calling widget registry API to check if a widget with given uid is installed 
  2182 //already
  2339 //already
  2183 // ---------------------------------------------------------------------------
  2340 // ---------------------------------------------------------------------------
  2184 //
  2341 //
  2185 TBool CNcdInstallationService::WidgetExistsL( const TUid& aUid )
       
  2186     {
       
  2187     DLTRACEIN((""));
       
  2188     
       
  2189     TBool retVal = EFalse;
       
  2190         
       
  2191     // Get entry 
       
  2192     Usif::TComponentId compId = aUid.iUid;
       
  2193     Usif::CComponentEntry* entry = Usif::CComponentEntry::NewLC();
       
  2194     TRAPD(err, iScrSession.GetComponentL(compId, *entry));
       
  2195     
       
  2196     if ( err == KErrNotFound || !retVal )
       
  2197         {
       
  2198         retVal = EFalse;
       
  2199         }
       
  2200     else if  (err != KErrNone )
       
  2201         {
       
  2202         User::Leave( err );
       
  2203         }
       
  2204     else
       
  2205         {
       
  2206         // widget ??
       
  2207         if ( entry->SoftwareType().Compare( Usif::KSoftwareTypeWidget ) == 0 )
       
  2208             {
       
  2209             retVal = ETrue;
       
  2210             }
       
  2211         else
       
  2212             {
       
  2213             retVal = EFalse;
       
  2214             }
       
  2215         }
       
  2216     CleanupStack::PopAndDestroy(entry);
       
  2217     return retVal;
       
  2218     }
       
  2219 
       
  2220 // ---------------------------------------------------------------------------
       
  2221 //Calling widget registry API to check if a widget with given uid is installed 
       
  2222 //already. Returns the version of the installed widget.
       
  2223 // ---------------------------------------------------------------------------
       
  2224 //
       
  2225 TBool CNcdInstallationService::WidgetExistsL( 
  2342 TBool CNcdInstallationService::WidgetExistsL( 
  2226         const TUid& aUid, TCatalogsVersion& aVersion )
  2343         const TUid& aUid, TCatalogsVersion& aVersion )
  2227     {
  2344     {
  2228     DLTRACEIN((""));
  2345     DLTRACEIN((""));
  2229     
  2346     
  2230     TBool retVal = EFalse;
  2347     if ( !iWidgetRegistry.Handle() )
  2231     
  2348         {
  2232     // Get entry 
  2349         User::LeaveIfError( iWidgetRegistry.Connect() );
  2233     Usif::TComponentId compId = aUid.iUid;
  2350         }
  2234     Usif::CComponentEntry* entry = Usif::CComponentEntry::NewLC();
  2351     
  2235     TRAPD(err, retVal= iScrSession.GetComponentL(compId, *entry));
  2352     if ( iWidgetRegistry.IsWidget( aUid ) )
  2236     
  2353         {
  2237     if ( err == KErrNotFound || !retVal )
  2354         TBuf<KWidgetBundleIdLength> id;
  2238         {
  2355         iWidgetRegistry.GetWidgetBundleId( aUid, id );
  2239         retVal = EFalse;
  2356         if (iWidgetRegistry.WidgetExistsL( id ))
  2240         }
  2357             {
  2241     else if  (err != KErrNone )
  2358             // Get version
  2242         {
  2359             CWidgetPropertyValue* version = 
  2243         User::Leave( err );
  2360                 iWidgetRegistry.GetWidgetPropertyValueL(aUid, EBundleVersion );
       
  2361             CleanupStack::PushL( version );
       
  2362             TCatalogsVersion::ConvertL( aVersion, *(version->iValue.s) );
       
  2363             CleanupStack::PopAndDestroy( version ); 
       
  2364             return (ETrue);
       
  2365             }
       
  2366         else
       
  2367             {
       
  2368             return (EFalse);
       
  2369             }
  2244         }
  2370         }
  2245     else
  2371     else
  2246         {
  2372        return(EFalse);
  2247         // widget ??
  2373 
  2248         if ( entry->SoftwareType().Compare( Usif::KSoftwareTypeWidget ) == 0 )
       
  2249             {
       
  2250             retVal = ETrue;
       
  2251         
       
  2252             // Get version
       
  2253             TPtrC entryVersion = entry->Version();
       
  2254             TCatalogsVersion::ConvertL( aVersion, entryVersion );
       
  2255             }
       
  2256         else
       
  2257             {
       
  2258             retVal = EFalse;
       
  2259             }
       
  2260         }
       
  2261     CleanupStack::PopAndDestroy(entry);
       
  2262     return retVal;
       
  2263     
       
  2264     }
  2374     }
  2265     
  2375     
  2266 // ---------------------------------------------------------------------------
  2376 // ---------------------------------------------------------------------------
  2267 // Calling widget registry API to check if a widget with given identifier is 
  2377 // Calling widget registry API to check if a widget with given identifier is 
  2268 // installed already
  2378 // installed already
  2271 TBool CNcdInstallationService::WidgetExistsL
  2381 TBool CNcdInstallationService::WidgetExistsL
  2272           ( const TDesC& aIdentifier, TCatalogsVersion& aVersion )
  2382           ( const TDesC& aIdentifier, TCatalogsVersion& aVersion )
  2273     {
  2383     {
  2274     DLTRACEIN((""));
  2384     DLTRACEIN((""));
  2275     
  2385     
  2276     TBool retVal = EFalse;
  2386     if ( !iWidgetRegistry.Handle() )
  2277     Usif::TComponentId compId = 0;
  2387           {
  2278     
  2388           User::LeaveIfError( iWidgetRegistry.Connect() );
  2279     // Get widget component id by identifier
  2389           }
  2280     TRAPD( err, compId = 
  2390 
  2281            iScrSession.GetComponentIdL( aIdentifier, Usif::KSoftwareTypeWidget ));
  2391     RPointerArray<CWidgetInfo> widgetInfoArr;
  2282     
  2392     
  2283     if ( err == KErrNotFound )
  2393     CleanupResetAndDestroyPushL( widgetInfoArr );
  2284         {
  2394     TInt err = iWidgetRegistry.InstalledWidgetsL(widgetInfoArr);
  2285         retVal = EFalse;
  2395     
  2286         }
  2396     for( TInt i( widgetInfoArr.Count() - 1 ); i >= 0; --i ) 
  2287     else if  (err != KErrNone )
  2397         {
  2288         {
  2398         CWidgetInfo* widgetInfo( widgetInfoArr[i] );                  
  2289         User::Leave( err );
  2399         CWidgetPropertyValue* bundleId = 
  2290         }
  2400             iWidgetRegistry.GetWidgetPropertyValueL
  2291     else
  2401                 (widgetInfo->iUid, EBundleIdentifier );
  2292         {
  2402         CleanupStack::PushL( bundleId );
  2293         // Widget found
  2403         
  2294         retVal = ETrue;
  2404         if( aIdentifier.Compare( *(bundleId->iValue.s) )== 0 )
  2295         
  2405             {
  2296         // Get entry 
  2406             CWidgetPropertyValue* version = 
  2297         Usif::CComponentEntry* entry = Usif::CComponentEntry::NewLC();
  2407                 iWidgetRegistry.GetWidgetPropertyValueL
  2298         retVal = iScrSession.GetComponentL(compId, *entry);
  2408                     (widgetInfo->iUid, EBundleVersion );
  2299         
  2409             CleanupStack::PushL( version );
  2300         // Get version
  2410             TCatalogsVersion::ConvertL( aVersion, *(version->iValue.s) );
  2301         if ( retVal )
  2411             
  2302             {
  2412             CleanupStack::PopAndDestroy( version );
  2303             TPtrC entryVersion = entry->Version();
  2413             CleanupStack::PopAndDestroy( bundleId );
  2304             TCatalogsVersion::ConvertL( aVersion, entryVersion );
  2414             CleanupStack::PopAndDestroy( &widgetInfoArr );
  2305             }
  2415                         
  2306     
  2416             return ETrue;
  2307         CleanupStack::PopAndDestroy(entry);
  2417             }
  2308         }
  2418         CleanupStack::PopAndDestroy( bundleId );
  2309     
  2419         }
  2310     return retVal;
  2420     CleanupStack::PopAndDestroy( &widgetInfoArr );
  2311     }
  2421     return EFalse;
  2312 
  2422     }
  2313 
  2423 
  2314 // ---------------------------------------------------------------------------
  2424 // ---------------------------------------------------------------------------
  2315 //  Calling widget registry API to return the Uid of the widget
  2425 //  Calling widget registry API to return the Uid of the widget
  2316 //  with given identifier.
  2426 //  with given identifier.
  2317 // ---------------------------------------------------------------------------
  2427 // ---------------------------------------------------------------------------
  2320     {
  2430     {
  2321     DLTRACEIN((""));
  2431     DLTRACEIN((""));
  2322     
  2432     
  2323     TUid id = TUid::Uid(0);
  2433     TUid id = TUid::Uid(0);
  2324     
  2434     
  2325     Usif::TComponentId compId = iScrSession.GetComponentIdL(aIdentifier, Usif::KSoftwareTypeNative);
  2435    if ( !iWidgetRegistry.Handle() )
  2326     
  2436           {
  2327     id.iUid = compId;
  2437           User::LeaveIfError( iWidgetRegistry.Connect() );
  2328     
  2438           }
       
  2439     
       
  2440     id.iUid = iWidgetRegistry.GetWidgetUidL( aIdentifier);
       
  2441 
  2329     return id;
  2442     return id;
  2330     
  2443     
  2331     
  2444     }
  2332     }
  2445 
  2333 
  2446     
  2334