ncdengine/provider/deviceinteraction/src/ncdinstallationserviceimpl.cpp
changeset 25 98b66e4fb0be
parent 24 84a16765cd86
child 29 26b6f0522fd8
--- a/ncdengine/provider/deviceinteraction/src/ncdinstallationserviceimpl.cpp	Fri Mar 19 09:33:35 2010 +0200
+++ b/ncdengine/provider/deviceinteraction/src/ncdinstallationserviceimpl.cpp	Fri Apr 16 15:05:20 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2006-2008 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -74,8 +74,6 @@
 // length taken from WidgetRegistryData.h
 const TInt KWidgetBundleIdLength = KWidgetRegistryVal + 1;    
 
-_LIT( KWidgetExtension, ".wgz" );
-
 // ======== CALLBACK FUNCTION ========
  
 static TInt InstallationCompleteCallback( TAny* aData )
@@ -165,6 +163,7 @@
         iWidgetRegistry.Close();
         }
     iInstalledWidgets.ResetAndDestroy();
+    iInstalledWidgetsInfos.ResetAndDestroy();
     }
 
 // ---------------------------------------------------------------------------
@@ -305,7 +304,25 @@
     DLTRACEOUT((""));
     }
 
+// ---------------------------------------------------------------------------
+// Installs widget silently.
+// ---------------------------------------------------------------------------
+//
+void CNcdInstallationService::SilentInstallWidgetL( RFile& aFile,
+                                                    const SwiUI::TInstallOptionsPckg& aInstallOptionsPckg )
+    {
+    DLTRACEIN((""));
+    
+    if ( iSilentInstallActiveObserver == NULL )
+        {
+        DLINFO(("Create active observer for silent install"));
+        iSilentInstallActiveObserver = CNcdSilentInstallActiveObserver::NewL( *this );        
+        }
 
+    InstallWidgetL( aFile, &aInstallOptionsPckg );
+    
+    DLTRACEOUT((""));
+    }
 // ---------------------------------------------------------------------------
 // Cancell silent install.
 // ---------------------------------------------------------------------------
@@ -549,7 +566,54 @@
 
 #endif
 
-  
+// Check via widget registry API
+TNcdApplicationStatus CNcdInstallationService::IsWidgetInstalledL(const TDesC& aIdentifier, const TCatalogsVersion& aVersion)
+    {
+    DLTRACEIN((""));
+    
+    TNcdApplicationStatus status( ENcdApplicationNotInstalled );
+    
+    if ( aIdentifier.Length() == 0 )
+        {
+        DLTRACEOUT(("Null identifier"));
+        return status;
+        }
+    
+    
+    TCatalogsVersion installedVersion;
+    
+    //check widget existance and get version number if it is installed
+    if ( WidgetExistsL( aIdentifier, installedVersion ) )
+        {
+        status = ENcdApplicationInstalled;
+        }
+           
+    //compare the version
+    if ( status == ENcdApplicationInstalled &&
+         aVersion != TCatalogsVersion() ) 
+            {
+            DLINFO(("Installed widget version: %d.%d.%d, comparing to: %d.%d.%d",
+                installedVersion.iMajor,
+                installedVersion.iMinor,
+                installedVersion.iBuild,
+                aVersion.iMajor,
+                aVersion.iMinor,
+                aVersion.iBuild ));
+                
+            if ( installedVersion > aVersion ) 
+                {
+                status = ENcdApplicationNewerVersionInstalled;
+                }
+            else if ( !( installedVersion == aVersion ) ) 
+                {
+                status = ENcdApplicationOlderVersionInstalled;
+                }
+            }
+        
+        DLTRACEOUT(("widget Status: %d", status));
+        return status;    
+    }
+
 // ---------------------------------------------------------------------------
 // Checks the application status
 // ---------------------------------------------------------------------------
@@ -596,9 +660,10 @@
     // SIS app not found, try to get java
     if ( err == KErrNotFound &&
          ( JavaAppExistsL( aUid ) ||
-           WidgetExistsL( aUid ) ) )
+           WidgetExistsL( aUid, installedVersion ) ) ) 
         {
         status = ENcdApplicationInstalled;
+        err = KErrNone;
         }
         
     LeaveIfNotErrorL( err, KErrNotFound );  
@@ -1558,10 +1623,10 @@
     
     iInstallType = EWidgetInstall;
 
-    // Get the list of installed widget uids so that we can
+    // Get the list of installed widgets so that we can
     // get the uid of the new widget after installation
-    PopulateInstalledWidgetUidsL();
-    
+    PopulateInstalledWidgetsL(iInstalledWidgetsInfos);
+
     TDataType dataType;    
     // Start application installation.
     DLINFO(( "Calling doc handler Open" ));
@@ -1671,6 +1736,19 @@
             aError = KErrCancel;
             }
         }
+    else if ( iInstallType == EWidgetInstall )
+        {    
+        // Set the midlet UID for the aAppUid variable.
+        aAppUid = InstalledWidgetUidL();
+        
+        if ( aAppUid == KNullUid )
+            {
+            DLINFO(("Installed widget was not found"));
+            // Because the new widget was not found, we can suppose that the
+            // application was not installed. So, set the error as KErrCancel.
+            aError = KErrCancel;
+            }
+        }
     else if ( iInstallType == ESisInstall )
         {
         // Get theme name if such was installed
@@ -2089,6 +2167,49 @@
     User::LeaveIfError( iWidgetRegistry.InstalledWidgetsL( iInstalledWidgets ) );    
     }
 
+// ---------------------------------------------------------------------------
+// Populates the list of installed widgets
+// ---------------------------------------------------------------------------
+//
+void CNcdInstallationService::PopulateInstalledWidgetsL
+         (RExtendedWidgetInfoArray& aWidgets) 
+    {
+    DLTRACEIN((""));
+    
+    // Get the list of installed widget uids 
+    PopulateInstalledWidgetUidsL();
+    
+    const TInt count = iInstalledWidgets.Count();
+    
+    // Create array with UID & Version infos
+    for ( TInt i = 0; i < count; ++i )
+        {
+        CExtendedWidgetInfo* tempInfo = new ( ELeave ) CExtendedWidgetInfo();
+        CleanupStack::PushL( tempInfo );
+        
+        CWidgetInfo* widgetInfo = iInstalledWidgets[i];
+        
+        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( version );
+        CleanupStack::Pop( tempInfo );
+        }
+   
+        DLTRACEOUT((""));
+
+    }
 
 // ---------------------------------------------------------------------------
 // Gets the name of widget that was installed last
@@ -2125,25 +2246,33 @@
     {
     DLTRACEIN((""));
     
-    RWidgetInfoArray widgets;
+    RExtendedWidgetInfoArray widgets;
+    PopulateInstalledWidgetsL(widgets);
     CleanupResetAndDestroyPushL( widgets );
         
-    User::LeaveIfError( iWidgetRegistry.InstalledWidgetsL( widgets ) );
+
     DLINFO(("widget count: %d", widgets.Count() ));
     
     TUid uid( KNullUid );
     
     const TInt count = widgets.Count();
-    const TInt installedCount = iInstalledWidgets.Count();
+    const TInt installedCount = iInstalledWidgetsInfos.Count();
     
     // Try to find a widget that was not installed earlier.
     for ( TInt i = 0; i < count; ++i )
         {
         TBool wasInstalled = EFalse;
-        CWidgetInfo* widgetInfo = widgets[ i ];
+        CExtendedWidgetInfo * widgetInfo = widgets[ i ];
         for ( TInt j = 0; j < installedCount; j++ )
             {
-            if ( iInstalledWidgets[ j ]->iUid == widgetInfo->iUid )
+          
+            TCatalogsVersion versionBefore, versionAfter;
+            TCatalogsVersion::ConvertL
+                ( versionBefore, *(iInstalledWidgetsInfos[ j ]->iVersion) );
+            TCatalogsVersion::ConvertL( versionAfter, *(widgetInfo->iVersion) );
+            
+            if ( iInstalledWidgetsInfos[ j ]->iUid == widgetInfo->iUid &&
+                 versionBefore >= versionAfter) 
                 {
                 wasInstalled = ETrue;
                 break;
@@ -2235,3 +2364,114 @@
         }
     return EFalse;         
     }
+
+// ---------------------------------------------------------------------------
+//Calling widget registry API to check if a widget with given uid is installed 
+//already
+// ---------------------------------------------------------------------------
+//
+TBool CNcdInstallationService::WidgetExistsL( 
+        const TUid& aUid, TCatalogsVersion& aVersion )
+    {
+    DLTRACEIN((""));
+    
+    if ( !iWidgetRegistry.Handle() )
+        {
+        User::LeaveIfError( iWidgetRegistry.Connect() );
+        }
+    
+    if ( iWidgetRegistry.IsWidget( aUid ) )
+        {
+        TBuf<KWidgetBundleIdLength> id;
+        iWidgetRegistry.GetWidgetBundleId( aUid, id );
+        if (iWidgetRegistry.WidgetExistsL( id ))
+            {
+            // Get version
+            CWidgetPropertyValue* version = 
+                iWidgetRegistry.GetWidgetPropertyValueL(aUid, EBundleVersion );
+            CleanupStack::PushL( version );
+            TCatalogsVersion::ConvertL( aVersion, *(version->iValue.s) );
+            CleanupStack::PopAndDestroy( version ); 
+            return (ETrue);
+            }
+        else
+            {
+            return (EFalse);
+            }
+        }
+    else
+       return(EFalse);
+
+    }
+    
+// ---------------------------------------------------------------------------
+// Calling widget registry API to check if a widget with given identifier is 
+// installed already
+// ---------------------------------------------------------------------------
+//
+TBool CNcdInstallationService::WidgetExistsL
+          ( const TDesC& aIdentifier, TCatalogsVersion& aVersion )
+    {
+    DLTRACEIN((""));
+    
+    if ( !iWidgetRegistry.Handle() )
+          {
+          User::LeaveIfError( iWidgetRegistry.Connect() );
+          }
+
+    RPointerArray<CWidgetInfo> widgetInfoArr;
+    
+    CleanupResetAndDestroyPushL( widgetInfoArr );
+    TInt err = iWidgetRegistry.InstalledWidgetsL(widgetInfoArr);
+    
+    for( TInt i( widgetInfoArr.Count() - 1 ); i >= 0; --i ) 
+        {
+        CWidgetInfo* widgetInfo( widgetInfoArr[i] );                  
+        CWidgetPropertyValue* bundleId = 
+            iWidgetRegistry.GetWidgetPropertyValueL
+                (widgetInfo->iUid, EBundleIdentifier );
+        CleanupStack::PushL( bundleId );
+        
+        if( aIdentifier.Compare( *(bundleId->iValue.s) )== 0 )
+            {
+            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( bundleId );
+        }
+    CleanupStack::PopAndDestroy( &widgetInfoArr );
+    return EFalse;
+    }
+
+// ---------------------------------------------------------------------------
+//  Calling widget registry API to return the Uid of the widget
+//  with given identifier.
+// ---------------------------------------------------------------------------
+//
+TUid CNcdInstallationService::WidgetUidL( const TDesC& aIdentifier)
+    {
+    DLTRACEIN((""));
+    
+    TUid id = TUid::Uid(0);
+    
+   if ( !iWidgetRegistry.Handle() )
+          {
+          User::LeaveIfError( iWidgetRegistry.Connect() );
+          }
+    
+    id.iUid = iWidgetRegistry.GetWidgetUidL( aIdentifier);
+
+    return id;
+    
+    }
+
+