diff -r 7333d7932ef7 -r 8b7f4e561641 ncdengine/provider/deviceinteraction/src/ncdinstallationserviceimpl.cpp --- a/ncdengine/provider/deviceinteraction/src/ncdinstallationserviceimpl.cpp Tue Aug 31 15:21:33 2010 +0300 +++ b/ncdengine/provider/deviceinteraction/src/ncdinstallationserviceimpl.cpp Wed Sep 01 12:22:02 2010 +0100 @@ -32,6 +32,16 @@ #include #include +#ifdef USE_OLD_JAVA_API + #include + #include +#else + #include + #include + + using namespace Java; +#endif + #include "ncdinstallationserviceobserver.h" #include "ncdactiveoperationobserver.h" #include "ncdsilentinstallactiveobserver.h" @@ -45,7 +55,21 @@ const TUint KFileOpenFlags = EFileShareReadersOrWriters; -//const TInt KWidgetBundleIdLength = KMaxFileName + 1; +#ifdef __SERIES60_31__ + + const TInt32 KPSUidJavaLatestInstallation = KUidJmiLatestInstallation; + +#else + + // Defined originally in /mw/java/inc/javauids.h + // This should become available at some point in javadomainpskeys.h + //const TInt32 KPSUidJavaLatestInstallation = 0x10282567; + #include + +#endif + +// length taken from WidgetRegistryData.h +const TInt KWidgetBundleIdLength = KWidgetRegistryVal + 1; // ======== CALLBACK FUNCTION ======== @@ -107,13 +131,10 @@ delete iInstallationCompleteCallback; delete iJadFileName; delete iRecognizedMime; - - delete iResults; - delete iArguments; - +#ifdef USE_OLD_JAVA_API + iMIDletUids.Close(); +#endif iApaLs.Close(); - - if( iThemes ) { iThemes->ResetAndDestroy(); @@ -124,7 +145,17 @@ CancelInstall(); iRomUids.Close(); - iScrSession.Close(); + if ( iWidgetRegistry.Handle() ) + { + // decreases widget server's refcount but this cannot be called + // if Connect has not been called or we'll get a KERN-EXEC 0 + iWidgetRegistry.Disconnect(); + } + else + { + iWidgetRegistry.Close(); + } + iInstalledWidgets.ResetAndDestroy(); iInstalledWidgetsInfos.ResetAndDestroy(); } @@ -143,18 +174,13 @@ void CNcdInstallationService::ConstructL() { DLTRACEIN(("")); - - iResults = 0; - iArguments = 0; - iDocHandler = CDocumentHandler::NewL(); iDocHandler->SetExitObserver( this ); User::LeaveIfError( iFs.Connect() ); User::LeaveIfError( iFs.ShareProtected() ); User::LeaveIfError( iRegistrySession.Connect() ); - User::LeaveIfError( iAknsSrv.Connect() ); - User::LeaveIfError( iScrSession.Connect()); + User::LeaveIfError( iAknsSrv.Connect() ); iInstallationCompleteCallback = new(ELeave) CAsyncCallBack( TCallBack( InstallationCompleteCallback, this ), @@ -233,7 +259,7 @@ void CNcdInstallationService::SilentInstallL( RFile& aFile, const TDesC& aMimeType, const TNcdItemPurpose& aPurpose, - const Usif::COpaqueNamedParams* aInstallOptionsPckg ) + const SwiUI::TInstallOptionsPckg& aInstallOptionsPckg ) { DLTRACEIN(("")); @@ -243,7 +269,7 @@ iSilentInstallActiveObserver = CNcdSilentInstallActiveObserver::NewL( *this ); } - InstallL( aFile, aMimeType, aPurpose, aInstallOptionsPckg ); + InstallL( aFile, aMimeType, aPurpose, &aInstallOptionsPckg ); DLTRACEOUT(("")); } @@ -256,7 +282,7 @@ void CNcdInstallationService::SilentInstallJavaL( RFile& aFile, const TDesC& aMimeType, const TDesC8& aDescriptorData, - const Usif::COpaqueNamedParams* aInstallOptionsPckg ) + const SwiUI::TInstallOptionsPckg& aInstallOptionsPckg ) { DLTRACEIN(("")); @@ -266,7 +292,7 @@ iSilentInstallActiveObserver = CNcdSilentInstallActiveObserver::NewL( *this ); } - InstallJavaL( aFile, aMimeType, aDescriptorData, aInstallOptionsPckg ); + InstallJavaL( aFile, aMimeType, aDescriptorData, &aInstallOptionsPckg ); DLTRACEOUT(("")); } @@ -276,7 +302,7 @@ // --------------------------------------------------------------------------- // void CNcdInstallationService::SilentInstallWidgetL( RFile& aFile, - const Usif::COpaqueNamedParams* aInstallOptionsPckg ) + const SwiUI::TInstallOptionsPckg& aInstallOptionsPckg ) { DLTRACEIN(("")); @@ -286,7 +312,7 @@ iSilentInstallActiveObserver = CNcdSilentInstallActiveObserver::NewL( *this ); } - InstallWidgetL( aFile, aInstallOptionsPckg ); + InstallWidgetL( aFile, &aInstallOptionsPckg ); DLTRACEOUT(("")); } @@ -349,6 +375,11 @@ iJadFileName = NULL; } +#ifdef USE_OLD_JAVA_API + // Clean the array. + iMIDletUids.Reset(); +#endif + // Reset information flags. InstallationFinishedSetup( aError ); } @@ -479,54 +510,47 @@ // // --------------------------------------------------------------------------- // +#ifdef USE_OLD_JAVA_API TBool CNcdInstallationService::JavaAppExistsL( const TUid& aUid ) { DLTRACEIN(("")); - TBool retVal = EFalse; - Usif::TComponentId compId = 0; - - // Get component id - TRAPD( ret, compId = iScrSession.GetComponentIdForAppL( aUid ) ); - if ( ret == KErrNotFound ) - { - return EFalse; - } - else if (ret != KErrNone ) - { - User::Leave( ret ); - } - - Usif::CComponentEntry* entry = Usif::CComponentEntry::NewLC(); - TRAPD(err, iScrSession.GetComponentL(compId, *entry)); + MJavaRegistry* javaRegistry = MJavaRegistry::CreateL(); + CleanupReleasePushL( *javaRegistry ); - if ( err == KErrNotFound ) + TRAPD( err, { - retVal = EFalse; - } - else if (err != KErrNone ) - { - User::Leave( err ); - } - else - { - // type == Java ? - if ( entry->SoftwareType().Compare( Usif::KSoftwareTypeJava ) == 0 ) - { - retVal = ETrue; - } - else - { - retVal = EFalse; - } - } - CleanupStack::PopAndDestroy(entry); - return retVal; + // Leaves with KErrNotFound if not found + MJavaRegistryMIDletEntry* midletEntry = javaRegistry->MIDletEntryL( + aUid ); + midletEntry->Release(); + }); + + LeaveIfNotErrorL( err, KErrNotFound ); + CleanupStack::PopAndDestroy( javaRegistry ); + return err == KErrNone; } +#else + +TBool CNcdInstallationService::JavaAppExistsL( + const TUid& aUid ) + { + DLTRACEIN(("")); + + CJavaRegistry* javaRegistry = CJavaRegistry::NewLC(); + + TBool exists = javaRegistry->RegistryEntryExistsL( aUid ); + + CleanupStack::PopAndDestroy( javaRegistry ); + return exists; + } + +#endif + // Check via widget registry API TNcdApplicationStatus CNcdInstallationService::IsWidgetInstalledL(const TDesC& aIdentifier, const TCatalogsVersion& aVersion) { @@ -900,7 +924,7 @@ iInstaller.Close(); - if ( aError == KErrCancel ) + if ( aError == SwiUI::KSWInstErrUserCancel ) { DLTRACE(("User cancelled, converting error to KErrAbort" ) ); aError = KErrAbort; @@ -949,7 +973,9 @@ if ( iInstallError != KErrNone ) { DLTRACE(("Notify install error")); - +#ifdef USE_OLD_JAVA_API + iMIDletUids.Reset(); +#endif iObserver->InstallationCompleteL( KNullDesC, TUid(), iInstallError ); return; } @@ -1289,7 +1315,7 @@ void CNcdInstallationService::InstallL( RFile& aFile, const TDesC& aMimeType, const TNcdItemPurpose& aPurpose, - const Usif::COpaqueNamedParams* aSilentInstallOptions ) + const SwiUI::TInstallOptionsPckg* aSilentInstallOptionsPckg ) { DLTRACEIN(( _L("iBusy=%d, MIME: %S"),iBusy, &aMimeType )); DASSERT( iObserver ); @@ -1335,7 +1361,7 @@ aFile, *iRecognizedMime, KNullDesC8, - aSilentInstallOptions ); + aSilentInstallOptionsPckg ); return; } else if ( MatchWidget( aFile, aMimeType ) ) @@ -1343,7 +1369,7 @@ DLTRACE(("Widget")); InstallWidgetL( aFile, - aSilentInstallOptions ); + aSilentInstallOptionsPckg ); return; } @@ -1385,25 +1411,13 @@ // Start application installation. DLINFO(( "Calling doc handler Open" )); - if ( !aSilentInstallOptions ) + if ( !aSilentInstallOptionsPckg ) { DLINFO(("Normal install")); InitializeInstallerL(); - //iCancelCode = SwiUI::ERequestInstallHandle; + iCancelCode = SwiUI::ERequestInstallHandle; - if ( !iArguments ) - { - iArguments = Usif::COpaqueNamedParams::NewL(); - } - if ( !iResults ) - { - iResults = Usif::COpaqueNamedParams::NewL(); - } - - iArguments->AddIntL( Usif::KSifInParam_InstallSilently, EFalse ); - - iInstaller.Install( aFile, *iArguments, *iResults, iInstallStatusObserver->iStatus ); - //iInstaller.Install( iInstallStatusObserver->iStatus, aFile ); + iInstaller.Install( iInstallStatusObserver->iStatus, aFile ); iInstallStatusObserver->StartToObserve(); } else @@ -1413,7 +1427,7 @@ // of the silent install and it will forward the information for the callback // function of this class object. iSilentInstallActiveObserver->StartToObserveL( aFile, - aSilentInstallOptions ); + *aSilentInstallOptionsPckg ); } iBusy = ETrue; @@ -1484,7 +1498,7 @@ void CNcdInstallationService::InstallJavaL( RFile& aFile, const TDesC& /*aMimeType*/, const TDesC8& aDescriptorData, - const Usif::COpaqueNamedParams* aSilentInstallOptions ) + const SwiUI::TInstallOptionsPckg* aSilentInstallOptionsPckg ) { DLTRACEIN((_L("iBusy=%d, descriptor=%d"),iBusy, aDescriptorData.Length() )); DASSERT( iObserver ); @@ -1498,6 +1512,15 @@ iInstallError = KErrNone; +#ifdef USE_OLD_JAVA_API + // Store installed java app uids before installation to see + // which one is a new java app later. + MJavaRegistry* javaRegistry = MJavaRegistry::CreateL(); + CleanupReleasePushL( *javaRegistry ); + iMIDletUids.Reset(); + javaRegistry->InstalledMIDletUidsL( iMIDletUids ); + CleanupStack::PopAndDestroy( javaRegistry ); +#endif // In platform security systems JAR and JAD has to be in same folder // to get the installation process work correctly. @@ -1519,7 +1542,7 @@ iInstallType = EJavaInstall; TDataType dataType; - if ( aSilentInstallOptions == NULL ) + if ( aSilentInstallOptionsPckg == NULL ) { DLINFO(("Normal install")); InitializeInstallerL(); @@ -1527,40 +1550,15 @@ { DLTRACE(("Installing JAD+JAR")); // JAD+JAR install - //iCancelCode = SwiUI::ERequestInstall; - if ( !iArguments ) - { - iArguments = Usif::COpaqueNamedParams::NewL(); - } - if ( !iResults ) - { - iResults = Usif::COpaqueNamedParams::NewL(); - } - - iArguments->AddIntL( Usif::KSifInParam_InstallSilently, EFalse ); - - iInstaller.Install( *iJadFileName, *iArguments, *iResults, iInstallStatusObserver->iStatus ); - //iInstaller.Install( iInstallStatusObserver->iStatus, *iJadFileName ); + iCancelCode = SwiUI::ERequestInstall; + iInstaller.Install( iInstallStatusObserver->iStatus, *iJadFileName ); } else { DLTRACE(("Installing JAR")); // JAR install - //iCancelCode = SwiUI::ERequestInstallHandle; - if ( !iArguments ) - { - iArguments = Usif::COpaqueNamedParams::NewL(); - } - if ( !iResults ) - { - iResults = Usif::COpaqueNamedParams::NewL(); - } - - iArguments->AddIntL( Usif::KSifInParam_InstallSilently, EFalse ); - - iInstaller.Install( aFile, *iArguments, *iResults, iInstallStatusObserver->iStatus ); - - //iInstaller.Install( iInstallStatusObserver->iStatus, aFile ); + iCancelCode = SwiUI::ERequestInstallHandle; + iInstaller.Install( iInstallStatusObserver->iStatus, aFile ); } iInstallStatusObserver->StartToObserve(); @@ -1576,7 +1574,7 @@ // of the silent install and it will forward the information for the callback // function of this class object. iSilentInstallActiveObserver->StartToObserveL( *iJadFileName, - aSilentInstallOptions ); + *aSilentInstallOptionsPckg ); } else { @@ -1586,7 +1584,7 @@ // of the silent install and it will forward the information for the callback // function of this class object. iSilentInstallActiveObserver->StartToObserveL( aFile, - aSilentInstallOptions ); + *aSilentInstallOptionsPckg ); } } @@ -1602,7 +1600,7 @@ // void CNcdInstallationService::InstallWidgetL( RFile& aFile, - const Usif::COpaqueNamedParams* aSilentInstallOptions ) + const SwiUI::TInstallOptionsPckg* aSilentInstallOptionsPckg ) { DLTRACEIN(("")); @@ -1616,24 +1614,13 @@ // Start application installation. DLINFO(( "Calling doc handler Open" )); - if ( !aSilentInstallOptions ) + if ( !aSilentInstallOptionsPckg ) { DLINFO(("Normal install")); InitializeInstallerL(); - //iCancelCode = SwiUI::ERequestInstallHandle; - if ( !iArguments ) - { - iArguments = Usif::COpaqueNamedParams::NewL(); - } - if ( !iResults ) - { - iResults = Usif::COpaqueNamedParams::NewL(); - } - - iArguments->AddIntL( Usif::KSifInParam_InstallSilently, EFalse ); - iInstaller.Install(aFile, *iArguments, *iResults, iInstallStatusObserver->iStatus ); - - //iInstaller.Install( iInstallStatusObserver->iStatus, aFile ); + iCancelCode = SwiUI::ERequestInstallHandle; + + iInstaller.Install( iInstallStatusObserver->iStatus, aFile ); iInstallStatusObserver->StartToObserve(); } else @@ -1643,7 +1630,7 @@ // of the silent install and it will forward the information for the callback // function of this class object. iSilentInstallActiveObserver->StartToObserveL( aFile, - aSilentInstallOptions ); + *aSilentInstallOptionsPckg ); } iBusy = ETrue; @@ -1660,13 +1647,10 @@ DeletePtr( iInstallStatusObserver ); iInstallStatusObserver = CNcdActiveOperationObserver::NewL( *this ); - User::LeaveIfError( iInstaller.Connect() ); - /* if ( !iInstaller.Handle() ) { User::LeaveIfError( iInstaller.Connect() ); } - */ } @@ -1677,13 +1661,11 @@ void CNcdInstallationService::CancelInstall() { DLTRACEIN(("")); - //if ( iInstallStatusObserver && - // iInstaller.Handle() ) - if ( iInstallStatusObserver ) + if ( iInstallStatusObserver && + iInstaller.Handle() ) { DLTRACE(("Cancelling installation")); - iInstaller.CancelOperation(); - //iInstaller.CancelAsyncRequest( iCancelCode ); + iInstaller.CancelAsyncRequest( iCancelCode ); } DeletePtr( iInstallStatusObserver ); @@ -1840,7 +1822,7 @@ { DLTRACEIN(("")); -/* TApaAppInfo info; + TApaAppInfo info; ConnectApaLsL(); User::LeaveIfError( iApaLs.GetAllApps() ); @@ -1868,8 +1850,7 @@ { appErr = iApaLs.GetNextApp( info ); if ( appErr == KErrNone ) - { - DLTRACE(("After GetNextApp")); + { // App is considered a ROM app if its not found either // in SIS registry or midlet registry // Note: ROM apps can be in SIS registry also but that doesn't @@ -1912,7 +1893,7 @@ while( appErr == KErrNone && retryCount >= 0 ); iApaLs.Close(); - CleanupStack::PopAndDestroy( &midletUids );*/ + CleanupStack::PopAndDestroy( &midletUids ); DLTRACEOUT(("ROM apps: %d", iRomUids.Count() )); } @@ -1922,39 +1903,30 @@ // Gets a list of installed midlet UIDs // --------------------------------------------------------------------------- // +#ifdef USE_OLD_JAVA_API void CNcdInstallationService::MidletUidsL( RArray& aUids ) { + DLTRACEIN(("")); + MJavaRegistry* javaRegistry = MJavaRegistry::CreateL(); + CleanupReleasePushL( *javaRegistry ); + javaRegistry->InstalledMIDletUidsL( aUids ); + CleanupStack::PopAndDestroy( javaRegistry ); + } - // Get ids of all java components in scr - RArray javaComponentIdList; - CleanupClosePushL( javaComponentIdList ); - - Usif::CComponentFilter *pJavaSwTypeFilter = Usif::CComponentFilter::NewLC(); - pJavaSwTypeFilter->SetSoftwareTypeL( Usif::KSoftwareTypeJava ); - iScrSession.GetComponentIdsL( javaComponentIdList, pJavaSwTypeFilter ); - CleanupStack::PopAndDestroy( pJavaSwTypeFilter ); +#else - - // Get components - TInt aUidIndex = 0; - for ( TInt i = 0; i < javaComponentIdList.Count(); ++i ) - { - RArray midletUids; - CleanupClosePushL( midletUids ); - iScrSession.GetAppUidsForComponentL( javaComponentIdList[i], midletUids ); - for ( TInt j = 0; j < midletUids.Count(); ++j ) - { - aUids[aUidIndex] = aUids[j]; - aUidIndex++; - } - CleanupStack::PopAndDestroy(); // midletUids - } - - CleanupStack::PopAndDestroy(); // javaComponentIdList - +void CNcdInstallationService::MidletUidsL( RArray& aUids ) + { + DLTRACEIN(("")); + CJavaRegistry* javaRegistry = CJavaRegistry::NewLC(); + javaRegistry->GetRegistryEntryUidsL( aUids ); + CleanupStack::PopAndDestroy( javaRegistry ); } +#endif + + // --------------------------------------------------------------------------- // Checks if the application is in ROM // --------------------------------------------------------------------------- @@ -1965,6 +1937,122 @@ return iRomUids.Find( aUid ) != KErrNotFound; } + +// --------------------------------------------------------------------------- +// Returns the UID of the latest installed midlet, NULL UID if none have +// been installed since the last device restart +// --------------------------------------------------------------------------- +// +#ifdef USE_OLD_JAVA_API + +TUid CNcdInstallationService::LatestMidletUidL( + MJavaRegistry& aJavaRegistry ) const + { + DLTRACEIN(("")); + TInt suiteUid = 0; + + // Get UID for the latest installed Midlet suite + // KPSUidJavaLatestInstallation = 0x10282567 + // Ignoring error in case the key or read policy change so that client + // doesn't behave strangely + RProperty::Get( KUidSystemCategory, + KPSUidJavaLatestInstallation, suiteUid ); + + DLTRACE(("JMI UID: %x", suiteUid )); + + if ( !suiteUid ) + { + return KNullUid; + } + + // Get entry for the installed suite + MJavaRegistrySuiteEntry* suite = aJavaRegistry.SuiteEntryL( + TUid::Uid( suiteUid ) ); + CleanupReleasePushL( *suite ); + RArray suiteUids; + CleanupClosePushL( suiteUids ); + + TUid midletUid = KNullUid; + suite->MIDletUidsL( suiteUids ); + + // Take first midlet UID from the suite + if ( suiteUids.Count() ) + { + midletUid = suiteUids[0]; + } + DLTRACE(("Midlets in suite: %d", suite->NumberOfMIDletsL() )); + CleanupStack::PopAndDestroy( &suiteUids ); + DLTRACE(("InstalledAppsEntryUid: %x", midletUid.iUid )); + + CleanupStack::PopAndDestroy( suite ); + return midletUid; + } + +#else + +TUid CNcdInstallationService::LatestMidletUidL( + CJavaRegistry& aJavaRegistry ) const + { + DLTRACEIN(("")); + TInt suiteUid = 0; + + // Get UID for the latest installed Midlet suite + // KPSUidJavaLatestInstallation = 0x10282567 + // Ignoring error in case the key or read policy change so that client + // doesn't behave strangely + RProperty::Get( KUidSystemCategory, + KPSUidJavaLatestInstallation, suiteUid ); + + DLTRACE(("JMI UID: %x", suiteUid )); + + if ( !suiteUid ) + { + return KNullUid; + } + + // Get entry for the installed suite + CJavaRegistryEntry* suite = aJavaRegistry.RegistryEntryL( + TUid::Uid( suiteUid ) ); + + if ( !suite ) + { + return KNullUid; + } + + CleanupStack::PushL( suite ); + + DASSERT( suite->Type() < EGeneralApplication && + suite->Type() >= EGeneralPackage ); + + CJavaRegistryPackageEntry* entry = + static_cast( suite ); + + TUid midletUid = KNullUid; + TInt count = entry->NumberOfEmbeddedEntries(); + TBool appFound = EFalse; + TInt index = 0; + + // Find the first application from the suite + while ( index < count && !appFound ) + { + CJavaRegistryEntry* app = entry->EmbeddedEntryByNumberL( index ); + if ( app->Type() >= EGeneralApplication ) + { + midletUid = app->Uid(); + appFound = ETrue; + DLTRACE(( "Found app: %x", midletUid.iUid )); + } + delete app; + ++index; + } + + CleanupStack::PopAndDestroy( suite ); + return midletUid; + } + + +#endif + // --------------------------------------------------------------------------- // Returns true if the MIME type matches a Java application or descriptor // --------------------------------------------------------------------------- @@ -1977,35 +2065,75 @@ } - +#ifdef USE_OLD_JAVA_API TUid CNcdInstallationService::InstalledMidletUidL() { - - //Usif::COpaqueNamedParams* iResults = 0; // to be removed + DLTRACEIN(("")); + RArray MIDletUids; + CleanupClosePushL( MIDletUids ); - RArray appUids; - TUid midletUid = KNullUid; - TInt compId = 0; - - // Get component id - TRAPD ( err, iResults->IntByNameL( Usif::KSifOutParam_ComponentId )); - if ( err == KErrNotFound ) + MJavaRegistry* javaRegistry = MJavaRegistry::CreateL(); + CleanupReleasePushL( *javaRegistry ); + javaRegistry->InstalledMIDletUidsL( MIDletUids ); + TUid MIDletUid = KNullUid; + // Search for new uids in Java registry. + for ( TInt i = 0 ; i < MIDletUids.Count() ; i++ ) { - return midletUid; + if ( iMIDletUids.Find( MIDletUids[i] ) == KErrNotFound ) + { + // A new uid found, this is the installed midlet's uid + MIDletUid = MIDletUids[i]; + break; + } + } + + // We didn't get any new UID so we have to check Java installer's + // P&S key for the installed suite UID and the get the midlet UID + // from that. This happens when a midlet with predefined UID, + // eg. WidSets, is reinstalled. Midlet UIDs are predefined with + // the attribute Nokia-MIDlet-UID- in a JAD or JAR manifest + if ( MIDletUid == KNullUid ) + { + MIDletUid = LatestMidletUidL( *javaRegistry ); } - // Get components - CleanupClosePushL( appUids ); - iScrSession.GetAppUidsForComponentL( compId, appUids ); + CleanupStack::PopAndDestroy( javaRegistry ); + CleanupStack::PopAndDestroy( &MIDletUids ); + + iMIDletUids.Reset(); + return MIDletUid; + } + +#else // USE_OLD_JAVA_API + +TUid CNcdInstallationService::InstalledMidletUidL() + { + DLTRACEIN(("")); + CJavaRegistry* registry = CJavaRegistry::NewLC(); + TUid midletUid = LatestMidletUidL( *registry ); + CleanupStack::PopAndDestroy( registry ); + return midletUid; + } + +#endif // USE_OLD_JAVA_API + + +// --------------------------------------------------------------------------- +// Populates the list of installed widgets +// --------------------------------------------------------------------------- +// +void CNcdInstallationService::PopulateInstalledWidgetUidsL() + { + DLTRACEIN(("")); + + if ( !iWidgetRegistry.Handle() ) + { + User::LeaveIfError( iWidgetRegistry.Connect() ); + } - // return first midlet uid, if exists - if ( appUids.Count() != 0 ) - { - midletUid = appUids[0]; - } - CleanupStack::PopAndDestroy(); // appUids - return midletUid; + iInstalledWidgets.ResetAndDestroy(); + User::LeaveIfError( iWidgetRegistry.InstalledWidgetsL( iInstalledWidgets ) ); } // --------------------------------------------------------------------------- @@ -2017,44 +2145,38 @@ { DLTRACEIN(("")); - // Get ids of all widget components in scr - RArray widgetComponentIdList; - Usif::CComponentFilter *pWidgetSwTypeFilter = Usif::CComponentFilter::NewLC(); - pWidgetSwTypeFilter->SetSoftwareTypeL(Usif::KSoftwareTypeWidget); - - iScrSession.GetComponentIdsL(widgetComponentIdList, pWidgetSwTypeFilter); + // Get the list of installed widget uids + PopulateInstalledWidgetUidsL(); - CleanupStack::PopAndDestroy(pWidgetSwTypeFilter); - CleanupClosePushL(widgetComponentIdList); + const TInt count = iInstalledWidgets.Count(); - const TInt count = widgetComponentIdList.Count(); - - // Create array with id & version infos + // Create array with UID & Version infos for ( TInt i = 0; i < count; ++i ) { CExtendedWidgetInfo* tempInfo = new ( ELeave ) CExtendedWidgetInfo(); CleanupStack::PushL( tempInfo ); - // Get widget - Usif::TComponentId compId = widgetComponentIdList[i]; - Usif::CComponentEntry* entry = Usif::CComponentEntry::NewLC(); - iScrSession.GetComponentL(compId, *entry); + CWidgetInfo* widgetInfo = iInstalledWidgets[i]; - // Fill id & version - tempInfo->iUid.iUid= compId; - *(tempInfo->iVersion) = entry->Version(); + CWidgetPropertyValue* version = iWidgetRegistry.GetWidgetPropertyValueL + (widgetInfo->iUid, EBundleVersion ); + CleanupStack::PushL( version ); + + // Fill info + tempInfo->iUid = widgetInfo->iUid; + if (!version->iValue.s) + *(tempInfo->iVersion) = KDefVersion; + else + *(tempInfo->iVersion) = *(version->iValue.s); // Append to arrayt aWidgets.AppendL( tempInfo ); - - CleanupStack::PopAndDestroy(entry); + + CleanupStack::PopAndDestroy( version ); CleanupStack::Pop( tempInfo ); } - - - CleanupStack::PopAndDestroy(); // widgetComponentIdList - DLTRACEOUT(("")); + DLTRACEOUT(("")); } @@ -2062,13 +2184,26 @@ // Gets the name of widget that was installed last // --------------------------------------------------------------------------- // - HBufC* CNcdInstallationService::InstalledWidgetNameLC() { DLTRACEIN(("")); - // Not currently suported - return NULL; + TUid widgetUid = InstalledWidgetUidL(); + + if ( widgetUid == KNullUid ) + { + DLERROR(("No widget uid")); + // No new UID was found, so we assume user canceled the installation. + // Installer does not give any error code in that case. + return NULL; + } + + HBufC* bundleId = HBufC::NewLC( KWidgetBundleIdLength ); + TPtr des( bundleId->Des() ); + iWidgetRegistry.GetWidgetBundleId( widgetUid, des ); + + DLTRACEOUT(( _L("Widget bundle id: %S"), bundleId )); + return bundleId; } @@ -2178,48 +2313,30 @@ // --------------------------------------------------------------------------- -//Calling widget registry API to check if a widget with given uid is installed -//already +// // --------------------------------------------------------------------------- // TBool CNcdInstallationService::WidgetExistsL( const TUid& aUid ) { DLTRACEIN(("")); - - TBool retVal = EFalse; - - // Get entry - Usif::TComponentId compId = aUid.iUid; - Usif::CComponentEntry* entry = Usif::CComponentEntry::NewLC(); - TRAPD(err, iScrSession.GetComponentL(compId, *entry)); - - if ( err == KErrNotFound || !retVal ) - { - retVal = EFalse; - } - else if (err != KErrNone ) + + if ( !iWidgetRegistry.Handle() ) { - User::Leave( err ); + User::LeaveIfError( iWidgetRegistry.Connect() ); } - else + + if ( iWidgetRegistry.IsWidget( aUid ) ) { - // widget ?? - if ( entry->SoftwareType().Compare( Usif::KSoftwareTypeWidget ) == 0 ) - { - retVal = ETrue; - } - else - { - retVal = EFalse; - } + TBuf id; + iWidgetRegistry.GetWidgetBundleId( aUid, id ); + return iWidgetRegistry.WidgetExistsL( id ); } - CleanupStack::PopAndDestroy(entry); - return retVal; + return EFalse; } // --------------------------------------------------------------------------- //Calling widget registry API to check if a widget with given uid is installed -//already. Returns the version of the installed widget. +//already // --------------------------------------------------------------------------- // TBool CNcdInstallationService::WidgetExistsL( @@ -2227,40 +2344,33 @@ { DLTRACEIN(("")); - TBool retVal = EFalse; + if ( !iWidgetRegistry.Handle() ) + { + User::LeaveIfError( iWidgetRegistry.Connect() ); + } - // Get entry - Usif::TComponentId compId = aUid.iUid; - Usif::CComponentEntry* entry = Usif::CComponentEntry::NewLC(); - TRAPD(err, retVal= iScrSession.GetComponentL(compId, *entry)); - - if ( err == KErrNotFound || !retVal ) - { - retVal = EFalse; - } - else if (err != KErrNone ) + if ( iWidgetRegistry.IsWidget( aUid ) ) { - User::Leave( err ); - } - else - { - // widget ?? - if ( entry->SoftwareType().Compare( Usif::KSoftwareTypeWidget ) == 0 ) + TBuf id; + iWidgetRegistry.GetWidgetBundleId( aUid, id ); + if (iWidgetRegistry.WidgetExistsL( id )) { - retVal = ETrue; - // Get version - TPtrC entryVersion = entry->Version(); - TCatalogsVersion::ConvertL( aVersion, entryVersion ); + CWidgetPropertyValue* version = + iWidgetRegistry.GetWidgetPropertyValueL(aUid, EBundleVersion ); + CleanupStack::PushL( version ); + TCatalogsVersion::ConvertL( aVersion, *(version->iValue.s) ); + CleanupStack::PopAndDestroy( version ); + return (ETrue); } else { - retVal = EFalse; + return (EFalse); } } - CleanupStack::PopAndDestroy(entry); - return retVal; - + else + return(EFalse); + } // --------------------------------------------------------------------------- @@ -2273,44 +2383,44 @@ { DLTRACEIN(("")); - TBool retVal = EFalse; - Usif::TComponentId compId = 0; - - // Get widget component id by identifier - TRAPD( err, compId = - iScrSession.GetComponentIdL( aIdentifier, Usif::KSoftwareTypeWidget )); + if ( !iWidgetRegistry.Handle() ) + { + User::LeaveIfError( iWidgetRegistry.Connect() ); + } + + RPointerArray widgetInfoArr; - if ( err == KErrNotFound ) - { - retVal = EFalse; - } - else if (err != KErrNone ) - { - User::Leave( err ); - } - else + CleanupResetAndDestroyPushL( widgetInfoArr ); + TInt err = iWidgetRegistry.InstalledWidgetsL(widgetInfoArr); + + for( TInt i( widgetInfoArr.Count() - 1 ); i >= 0; --i ) { - // Widget found - retVal = ETrue; + CWidgetInfo* widgetInfo( widgetInfoArr[i] ); + CWidgetPropertyValue* bundleId = + iWidgetRegistry.GetWidgetPropertyValueL + (widgetInfo->iUid, EBundleIdentifier ); + CleanupStack::PushL( bundleId ); - // Get entry - Usif::CComponentEntry* entry = Usif::CComponentEntry::NewLC(); - retVal = iScrSession.GetComponentL(compId, *entry); - - // Get version - if ( retVal ) + if( aIdentifier.Compare( *(bundleId->iValue.s) )== 0 ) { - TPtrC entryVersion = entry->Version(); - TCatalogsVersion::ConvertL( aVersion, entryVersion ); + CWidgetPropertyValue* version = + iWidgetRegistry.GetWidgetPropertyValueL + (widgetInfo->iUid, EBundleVersion ); + CleanupStack::PushL( version ); + TCatalogsVersion::ConvertL( aVersion, *(version->iValue.s) ); + + CleanupStack::PopAndDestroy( version ); + CleanupStack::PopAndDestroy( bundleId ); + CleanupStack::PopAndDestroy( &widgetInfoArr ); + + return ETrue; } - - CleanupStack::PopAndDestroy(entry); + CleanupStack::PopAndDestroy( bundleId ); } - - return retVal; + CleanupStack::PopAndDestroy( &widgetInfoArr ); + return EFalse; } - // --------------------------------------------------------------------------- // Calling widget registry API to return the Uid of the widget // with given identifier. @@ -2322,13 +2432,15 @@ TUid id = TUid::Uid(0); - Usif::TComponentId compId = iScrSession.GetComponentIdL(aIdentifier, Usif::KSoftwareTypeNative); + if ( !iWidgetRegistry.Handle() ) + { + User::LeaveIfError( iWidgetRegistry.Connect() ); + } - id.iUid = compId; - + id.iUid = iWidgetRegistry.GetWidgetUidL( aIdentifier); + return id; - }