iaupdate/IAD/engine/controller/src/iaupdateutils.cpp
changeset 0 ba25891c3a9e
child 18 3ba40be8e484
child 25 98b66e4fb0be
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "iaupdateutils.h"
       
    21 
       
    22 #include "iaupdateversion.h"
       
    23 #include "iaupdatenode.h"
       
    24 #include "iaupdatebasenode.h"
       
    25 #include "iaupdatefwversionfilehandler.h"
       
    26 #include "iaupdatedebug.h"
       
    27 
       
    28 #include <swi/sisregistrysession.h>
       
    29 #include <swi/sisregistryentry.h>
       
    30 #include <swi/sisregistrypackage.h>
       
    31 #include <sysutil.h>
       
    32 #include <sysversioninfo.h> 
       
    33 
       
    34 #include <ncdnode.h>
       
    35 #include <ncdnodepurchase.h>
       
    36 #include <ncdnodecontentinfo.h>
       
    37 #include <ncdpurchaseoption.h>
       
    38 
       
    39 #include <catalogsutils.h>
       
    40 
       
    41 
       
    42 //Constants
       
    43 const TInt KSpaceMarginal( 100 * 1024 );
       
    44 const TInt KSizeMultiplier( 1 );
       
    45 const TText KVersionSeparator( '.' );
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // IAUpdateUtils::DesHexToIntL
       
    50 // 
       
    51 // -----------------------------------------------------------------------------
       
    52 //  
       
    53 EXPORT_C TInt IAUpdateUtils::DesHexToIntL( const TDesC& aDes )
       
    54     {
       
    55     TLex lex( aDes );
       
    56     TInt position = aDes.LocateF( 'x' );
       
    57     if ( position != KErrNotFound ) 
       
    58         {
       
    59         // Hex format is of type '0xABC' or 'xABC'
       
    60         // Skip over the x-part.
       
    61         lex.Assign( aDes.Mid( position+1 ) );
       
    62         }
       
    63     TUint value;
       
    64     User::LeaveIfError( lex.Val( value, EHex ) );
       
    65     return value;
       
    66     }    
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // IAUpdateUtils::DesHexToIntL
       
    71 // 
       
    72 // -----------------------------------------------------------------------------
       
    73 //  
       
    74 
       
    75 EXPORT_C void IAUpdateUtils::DesToVersionL( 
       
    76     const TDesC& aVersion, 
       
    77     TInt8& aMajor, TInt8& aMinor, TInt16& aBuild )
       
    78     {
       
    79     // Initialize temporary variables with the original values.
       
    80         // These will be replaced with new ones if values are found from the string.
       
    81     TInt8 major( aMajor );
       
    82     TInt8 minor( aMinor );
       
    83     TInt16 build( aBuild );
       
    84     
       
    85     if ( aVersion != KNullDesC )
       
    86         // because version may be omitted (service back nodes), empty strings are skipped  
       
    87         {
       
    88         TBool majorSet( EFalse );
       
    89         TBool minorSet( EFalse );
       
    90         TBool buildSet( EFalse );
       
    91         
       
    92         TLex lex( aVersion );
       
    93         lex.Mark();
       
    94         for( ;; )
       
    95             {
       
    96             if( lex.Eos() || lex.Peek() == KVersionSeparator )
       
    97                 {
       
    98                 TInt value( 0 );
       
    99                 TPtrC data( lex.MarkedToken() );
       
   100                 TLex num;
       
   101                 num.Assign( data );
       
   102                 User::LeaveIfError( num.Val( value ) );
       
   103 
       
   104                 if( !majorSet )
       
   105                     {
       
   106                     major = value;
       
   107                     majorSet = ETrue;
       
   108                     }
       
   109                 else if( !minorSet )
       
   110                     {
       
   111                     minor = value;
       
   112                     minorSet = ETrue;
       
   113                     }
       
   114                 else if( !buildSet )
       
   115                     {
       
   116                     build = value;
       
   117                     buildSet = ETrue;
       
   118                     // all values received now, exit loop.
       
   119                     break;
       
   120                     }
       
   121                     
       
   122                 if( lex.Eos() )
       
   123                     {
       
   124                     break;
       
   125                     }
       
   126                 else
       
   127                     {
       
   128                     lex.SkipAndMark( 1 );
       
   129                     }
       
   130                 }
       
   131             else 
       
   132                 {
       
   133                 lex.Inc();
       
   134                 }
       
   135             }
       
   136         }
       
   137         
       
   138     // Now replace original values with the parsed temporary values.
       
   139     aMajor = major;
       
   140     aMinor = minor;
       
   141     aBuild = build;
       
   142     }
       
   143 
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // IAUpdateUtils::AppPackageUidL
       
   147 // 
       
   148 // -----------------------------------------------------------------------------
       
   149 //  
       
   150 EXPORT_C TUid IAUpdateUtils::AppPackageUidL( const TUid& aUid )
       
   151     {
       
   152     // This is not actually neede here. But, create it so we can use
       
   153     // other version of the AppPackageUidL
       
   154     TIAUpdateVersion version;
       
   155     TUid appUid = AppPackageUidL( aUid, version );    
       
   156     return appUid;
       
   157     }
       
   158 
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // IAUpdateUtils::AppPackageUidL
       
   162 // 
       
   163 // -----------------------------------------------------------------------------
       
   164 //  
       
   165 EXPORT_C TUid IAUpdateUtils::AppPackageUidL( 
       
   166     const TUid& aUid, TIAUpdateVersion &aVersion )
       
   167     {
       
   168     TUid packageUid( TUid::Null() );
       
   169     
       
   170     Swi::RSisRegistrySession registrySession;
       
   171     Swi::RSisRegistryEntry entry;
       
   172         
       
   173     Swi::CSisRegistryPackage* sisRegistryPackage = NULL;
       
   174     TInt err = KErrNone;
       
   175     TBool entryFound = EFalse;
       
   176     
       
   177     User::LeaveIfError( registrySession.Connect() );
       
   178     CleanupClosePushL( registrySession );
       
   179     
       
   180     TRAP( err, sisRegistryPackage = registrySession.SidToPackageL( aUid ) );
       
   181         
       
   182     if ( err == KErrNone )
       
   183         {
       
   184         CleanupStack::PushL( sisRegistryPackage );
       
   185             
       
   186         if ( entry.OpenL( registrySession, *sisRegistryPackage ) == KErrNone )
       
   187             {
       
   188             entryFound = ETrue;
       
   189 
       
   190             // The sid was found from this package
       
   191             packageUid = sisRegistryPackage->Uid();
       
   192             }
       
   193         }
       
   194     else if ( entry.Open( registrySession, aUid ) == KErrNone )
       
   195         {
       
   196         entryFound = ETrue;
       
   197         
       
   198         // The given uid was already the package UID
       
   199         packageUid = aUid;
       
   200         }
       
   201         
       
   202     
       
   203     if ( entryFound )
       
   204         {
       
   205         CleanupClosePushL( entry );        
       
   206         
       
   207         if ( entry.IsPresentL() )
       
   208             {
       
   209             aVersion = entry.VersionL();
       
   210             
       
   211             RPointerArray< Swi::CSisRegistryPackage > augs;
       
   212             CleanupResetAndDestroyPushL( augs );
       
   213 
       
   214             entry.AugmentationsL( augs );
       
   215             
       
   216             for ( TInt i = 0; i < augs.Count(); ++i )
       
   217                 {
       
   218                 Swi::RSisRegistryEntry augEntry;
       
   219                 TIAUpdateVersion augVersion;
       
   220                 
       
   221                 if ( augEntry.OpenL( registrySession, *augs[i] ) == KErrNone )
       
   222                     {
       
   223                     CleanupClosePushL( augEntry );
       
   224                     
       
   225                     if ( augEntry.IsPresentL() )
       
   226                         {
       
   227                         augVersion = augEntry.VersionL();
       
   228                         
       
   229                         if( augVersion > aVersion )
       
   230                             {
       
   231                             aVersion = augEntry.VersionL();
       
   232                             }
       
   233                         }
       
   234                     
       
   235                     CleanupStack::PopAndDestroy( &augEntry );
       
   236                     }
       
   237                 }
       
   238             
       
   239             CleanupStack::PopAndDestroy( &augs );
       
   240             }
       
   241         else
       
   242             {
       
   243             entryFound = EFalse;
       
   244 
       
   245             packageUid = TUid::Null();            
       
   246             }
       
   247     	      	
       
   248         CleanupStack::PopAndDestroy( &entry );
       
   249         }
       
   250         
       
   251     if ( sisRegistryPackage )
       
   252         {
       
   253         CleanupStack::PopAndDestroy( sisRegistryPackage );
       
   254         }
       
   255         
       
   256     CleanupStack::PopAndDestroy( &registrySession );
       
   257 
       
   258     return packageUid;
       
   259     }
       
   260 
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // IAUpdateUtils::IsAppInstalledL
       
   264 // 
       
   265 // -----------------------------------------------------------------------------
       
   266 //  
       
   267 EXPORT_C TBool IAUpdateUtils::IsAppInstalledL( const TUid& aUid )
       
   268     {
       
   269     // This is not actually neede here. But, create it so we can use
       
   270     // other version of the IsAppInstalledL
       
   271     TIAUpdateVersion version;
       
   272     TBool isInstalled( IsAppInstalledL( aUid, version ) );
       
   273     return isInstalled;
       
   274     }
       
   275     
       
   276     
       
   277 // -----------------------------------------------------------------------------
       
   278 // IAUpdateUtils::IsAppInstalledL
       
   279 // 
       
   280 // -----------------------------------------------------------------------------
       
   281 //  
       
   282 EXPORT_C TBool IAUpdateUtils::IsAppInstalledL( 
       
   283     const TUid& aUid, TIAUpdateVersion &aVersion )
       
   284     {
       
   285     if ( AppPackageUidL( aUid, aVersion ) != TUid::Null() )
       
   286         {
       
   287         return ETrue;
       
   288         }
       
   289     else 
       
   290         {
       
   291         return EFalse;
       
   292         }
       
   293     }
       
   294 
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // IAUpdateUtils::SpaceAvailableInInternalDrivesL
       
   298 // 
       
   299 // -----------------------------------------------------------------------------
       
   300 //  
       
   301 EXPORT_C TBool IAUpdateUtils::SpaceAvailableInInternalDrivesL( 
       
   302     RPointerArray<MIAUpdateNode>& aNodes )
       
   303     {
       
   304     TBool enoughSpaceFound = ETrue; 
       
   305     // packages are cached in C drive. Needed cache size is a size of the biggest package
       
   306     TInt sizeOfBiggest = 0;
       
   307     TInt i = 0;
       
   308     RFs fs;
       
   309     User::LeaveIfError( fs.Connect() );
       
   310     CleanupClosePushL( fs );  
       
   311     TInt64 freeOnC = FreeDiskSpace( fs, EDriveC );
       
   312     TInt64 freeOnE = FreeDiskSpace( fs, EDriveE );
       
   313 
       
   314     if ( freeOnC >= freeOnE )
       
   315         {
       
   316         for ( i = 0; i < aNodes.Count(); ++i )
       
   317             {
       
   318             MIAUpdateNode* node( aNodes[ i ] );
       
   319             MIAUpdateBaseNode& baseNode( node->Base() );
       
   320             if ( baseNode.ContentSizeL() > sizeOfBiggest )
       
   321                 {
       
   322                 sizeOfBiggest = baseNode.ContentSizeL();
       
   323                 }
       
   324             }
       
   325         }
       
   326   
       
   327 	TDriveUnit driveUnit( EDriveC );
       
   328 	if ( SysUtil::DiskSpaceBelowCriticalLevelL( &fs, sizeOfBiggest, driveUnit ) ) 
       
   329 	    { // no space even for package caching
       
   330 		enoughSpaceFound = EFalse;
       
   331 	    }
       
   332 	else
       
   333 	    {
       
   334         TInt sizeNeededInDrive = sizeOfBiggest + KSpaceMarginal; //size of the biggest package is included in C drive
       
   335         for ( i = 0; i < aNodes.Count() && enoughSpaceFound; ++i )
       
   336             {
       
   337             TDriveUnit installedDrive;
       
   338             MIAUpdateNode* node( aNodes[ i ] );
       
   339             MIAUpdateBaseNode& baseNode( node->Base() );
       
   340             if ( !IAUpdateUtils::InstalledDriveL( baseNode.Uid(), installedDrive ) )
       
   341                 { //let's assume that already installed package does not need extra space
       
   342         	    sizeNeededInDrive += ( baseNode.ContentSizeL() * KSizeMultiplier );       
       
   343                 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &fs, sizeNeededInDrive, driveUnit ) )
       
   344                     { // not enough space in a drive, try the next internal drive 
       
   345                     enoughSpaceFound = EFalse;
       
   346                     //
       
   347                     // other drives than C are not scanned...installation is always to C.                     //
       
   348                     //
       
   349                     //TBool nextInternalDrive = ETrue;
       
   350                     //while ( nextInternalDrive )
       
   351                     //    {
       
   352             	    //    if ( NextInternalDriveL( fs, driveUnit, driveUnit ) )
       
   353             	    //        {
       
   354             	    //        sizeNeededInDrive = KSpaceMarginal + 
       
   355             	    //               ( baseNode.ContentSizeL() * KSizeMultiplier );
       
   356             		//        if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &fs, 
       
   357             		//                                                     sizeNeededInDrive, 
       
   358             		//                                                     driveUnit ) )
       
   359             		//            { 
       
   360             		//	        nextInternalDrive = EFalse;
       
   361             		//            }
       
   362              	    //        }
       
   363              	    //    else
       
   364              	    //        { //all internal drives scanned, just give up now
       
   365              	    //        nextInternalDrive = EFalse;
       
   366              	    //        enoughSpaceFound = EFalse;	
       
   367              	    //        }    
       
   368                     //    }
       
   369                     }
       
   370         	    }
       
   371             }
       
   372         }
       
   373     CleanupStack::PopAndDestroy( &fs );
       
   374     return enoughSpaceFound;
       
   375     }
       
   376 
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // IAUpdateUtils::IsInstalledL
       
   380 // 
       
   381 // -----------------------------------------------------------------------------
       
   382 // 
       
   383 EXPORT_C TBool IAUpdateUtils::IsInstalledL( 
       
   384     const TUid& aPUid, const TDesC& aExecutable )
       
   385     {
       
   386     Swi::RSisRegistrySession registrySession;
       
   387     Swi::RSisRegistryEntry entry;
       
   388     User::LeaveIfError( registrySession.Connect() );
       
   389     CleanupClosePushL( registrySession );
       
   390     TInt exeFound = EFalse;
       
   391     if ( entry.Open( registrySession, aPUid ) == KErrNone )
       
   392         {
       
   393         CleanupClosePushL( entry );
       
   394     	RPointerArray<HBufC> files; 
       
   395         entry.FilesL( files );
       
   396     	for( TInt i = 0; !exeFound && i < files.Count(); i++)
       
   397     	    {
       
   398     	    TFileName fullName = *files[i];	
       
   399             TParse parse;
       
   400             parse.Set( fullName, NULL, NULL);    
       
   401             if ( parse.NameAndExt().CompareF( aExecutable ) == 0 )
       
   402     		    {
       
   403     			exeFound = ETrue;
       
   404     		    }
       
   405     	    }
       
   406     	files.ResetAndDestroy();    
       
   407         CleanupStack::PopAndDestroy( &entry );
       
   408         }
       
   409     CleanupStack::PopAndDestroy( &registrySession );
       
   410     return exeFound;
       
   411     }
       
   412 
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // IAUpdateUtils::SilentInstallOptionsL
       
   416 // 
       
   417 // ---------------------------------------------------------------------------
       
   418 //
       
   419 EXPORT_C SwiUI::TInstallOptions IAUpdateUtils::SilentInstallOptionsL( 
       
   420     const TUid& aUid, TInt aSize )
       
   421     {
       
   422     SwiUI::TInstallOptions options;
       
   423 
       
   424     // Upgrades are allowed        
       
   425     options.iUpgrade = SwiUI::EPolicyAllowed;
       
   426 
       
   427     // Install all if optional packets exist.
       
   428     options.iOptionalItems = SwiUI::EPolicyAllowed;
       
   429 
       
   430     // Prevent online cert revocation check.
       
   431     options.iOCSP = SwiUI::EPolicyNotAllowed;
       
   432     
       
   433     // See iOCSP setting above
       
   434     options.iIgnoreOCSPWarnings = SwiUI::EPolicyAllowed;
       
   435 
       
   436     // Do not allow installation of uncertified packages.
       
   437     options.iUntrusted = SwiUI::EPolicyNotAllowed;
       
   438 
       
   439     // If filetexts are included in SIS package. Then, show them.
       
   440     options.iPackageInfo = SwiUI::EPolicyUserConfirm;
       
   441     
       
   442     // Automatically grant user capabilities.
       
   443     // See also iUntrusted above.
       
   444     options.iCapabilities = SwiUI::EPolicyAllowed;
       
   445 
       
   446     // Open application will be closed.
       
   447     options.iKillApp = SwiUI::EPolicyAllowed;
       
   448     
       
   449     // Files can be overwritten.
       
   450     options.iOverwrite = SwiUI::EPolicyAllowed;
       
   451     
       
   452     // This only affects Java applications.
       
   453     options.iDownload = SwiUI::EPolicyAllowed;
       
   454     
       
   455     // Where to save.
       
   456     TDriveUnit driveUnit = IAUpdateUtils::DriveToInstallL( aUid, aSize );
       
   457     TDriveName driveName = driveUnit.Name();
       
   458     options.iDrive = driveName[0];
       
   459     
       
   460     // Choose the phone language.
       
   461     options.iLang = User::Language();
       
   462     
       
   463     // If language is asked, then use the current phone language.
       
   464     options.iUsePhoneLang = ETrue;
       
   465     
       
   466     // Does not affect SISX. This is for Java.
       
   467     options.iUpgradeData = SwiUI::EPolicyAllowed;
       
   468 
       
   469     return options;
       
   470     }
       
   471 
       
   472 
       
   473 // -----------------------------------------------------------------------------
       
   474 // IAUpdateUtils::InstalledDriveL
       
   475 // 
       
   476 // -----------------------------------------------------------------------------
       
   477 // 
       
   478 TBool IAUpdateUtils::InstalledDriveL( 
       
   479     const TUid& aUid, TDriveUnit& aLocationDrive )
       
   480     {
       
   481     TBool installed = EFalse;
       
   482 	Swi::RSisRegistrySession registrySession;
       
   483 	User::LeaveIfError( registrySession.Connect() );
       
   484     CleanupClosePushL( registrySession );
       
   485     Swi::RSisRegistryEntry entry;
       
   486     TInt ret = entry.Open( registrySession, aUid );
       
   487     if ( ( ret != KErrNone ) && ( ret != KErrNotFound ) )
       
   488         {
       
   489     	User::LeaveIfError( ret );
       
   490         }
       
   491     if ( ret == KErrNone )
       
   492         {
       
   493     	CleanupClosePushL( entry );  
       
   494         if ( ( !entry.IsInRomL() ) && ( entry.IsPresentL() ) )
       
   495             { //only interested in a drive available for installation just now
       
   496             installed = ETrue;
       
   497     	    TUint drivesMask = entry.InstalledDrivesL();
       
   498             if( drivesMask )
       
   499                 {
       
   500                 // Select the highest drive as location drive. That's the case when 
       
   501                 // all installation is not in same drive
       
   502                 TInt drive = EDriveA;
       
   503                 while( drivesMask >>= 1 )
       
   504                     {
       
   505                     drive++;
       
   506                     }
       
   507                 aLocationDrive = drive;
       
   508                 }
       
   509             else
       
   510                 {
       
   511                 // No installed files, select C: as location drive
       
   512                 aLocationDrive = EDriveC;
       
   513                 }
       
   514             }
       
   515         CleanupStack::PopAndDestroy( &entry );
       
   516         }
       
   517     else
       
   518         {
       
   519         entry.Close();	
       
   520         }
       
   521     
       
   522     CleanupStack::PopAndDestroy( &registrySession ); 
       
   523 	return installed;
       
   524     }
       
   525 
       
   526 
       
   527 // -----------------------------------------------------------------------------
       
   528 // IAUpdateUtils::NextInternalDriveL
       
   529 // 
       
   530 // -----------------------------------------------------------------------------
       
   531 // 
       
   532 
       
   533 TBool IAUpdateUtils::NextInternalDriveL( 
       
   534     RFs& aFs, 
       
   535     TDriveUnit aCurrentDrive, 
       
   536     TDriveUnit& aNextDrive )
       
   537    {
       
   538    TBool nextInternalDrive = EFalse;
       
   539    
       
   540    TInt driveCount = 0; 
       
   541    TDriveList driveList;
       
   542    User::LeaveIfError( DriveInfo::GetUserVisibleDrives( aFs,
       
   543                                                         driveList, 
       
   544                                                         driveCount) ); 
       
   545 
       
   546    TUint driveStatus = 0;
       
   547    for ( TInt j = aCurrentDrive + 1; j < KMaxDrives && !nextInternalDrive; j++ )
       
   548        {
       
   549        if ( driveList[j] )
       
   550            {
       
   551     	   User::LeaveIfError( DriveInfo::GetDriveStatus( aFs, 
       
   552     	                                                  j, 
       
   553     	                                                  driveStatus ) );
       
   554     	   if ( driveStatus & DriveInfo::EDriveInternal )
       
   555     	       {
       
   556     	       nextInternalDrive = ETrue;
       
   557     	       aNextDrive = j;
       
   558     	       }
       
   559 	       }
       
   560        }
       
   561         	   
       
   562    return nextInternalDrive;
       
   563    }
       
   564 
       
   565 
       
   566 // -----------------------------------------------------------------------------
       
   567 // IAUpdateUtils::DriveToInstallL
       
   568 // 
       
   569 // -----------------------------------------------------------------------------
       
   570 //   
       
   571 TDriveUnit IAUpdateUtils::DriveToInstallL( const TUid& /*aUid*/, TInt /*aSize*/ )
       
   572     {
       
   573     
       
   574 	/*TDriveUnit preferredDriveUnit;
       
   575 	TDriveUnit targetDriveUnit( EDriveC );
       
   576 	//preferred drive is same as a drive of previous installation
       
   577 	if ( !InstalledDriveL( aUid, preferredDriveUnit ) )
       
   578 	    {
       
   579 		preferredDriveUnit = BiggestInternalDriveL();
       
   580 	    }
       
   581 	    
       
   582 	if ( !InternalDriveWithSpaceL( aSize * KSizeMultiplier + KSpaceMarginal, 
       
   583 	                               preferredDriveUnit, 
       
   584 	                               targetDriveUnit ) )
       
   585 	    { //try again without space marginal
       
   586 		if ( !InternalDriveWithSpaceL( aSize * KSizeMultiplier, preferredDriveUnit, targetDriveUnit ) )
       
   587 		    { //no space with estimated size, let's try to preferred drive
       
   588 			targetDriveUnit = preferredDriveUnit;
       
   589 		    }
       
   590 	    }*/
       
   591 	    
       
   592 	// installation drive is alvays "C"
       
   593     TDriveUnit targetDriveUnit( EDriveC );
       
   594     return targetDriveUnit;
       
   595     }
       
   596 
       
   597 
       
   598 // -----------------------------------------------------------------------------
       
   599 // IAUpdateUtils::BiggestInternalDriveL
       
   600 // 
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 TDriveUnit IAUpdateUtils::BiggestInternalDriveL()
       
   604     {
       
   605     RFs fs;
       
   606 	User::LeaveIfError( fs.Connect() );
       
   607 	CleanupClosePushL( fs ); 
       
   608 	TInt driveCount = 0; 
       
   609 	TDriveList driveList;
       
   610 	User::LeaveIfError( DriveInfo::GetUserVisibleDrives( 
       
   611                                          fs, 
       
   612                                          driveList, 
       
   613                                          driveCount) ); 
       
   614     TUint driveStatus = 0;
       
   615     TDriveUnit driveUnit( EDriveC );
       
   616     TInt size( 0 );
       
   617 	for ( TInt index(0); index < KMaxDrives; index++ )
       
   618     	{
       
   619     	if ( driveList[index] )
       
   620     	    {
       
   621     	  	User::LeaveIfError( DriveInfo::GetDriveStatus( fs, 
       
   622     	                                                   index, 
       
   623     	                                                   driveStatus ) );
       
   624     	    if ( driveStatus & DriveInfo::EDriveInternal )
       
   625     	        {
       
   626     	        TVolumeInfo volumeInfo;
       
   627     	        User::LeaveIfError( fs.Volume( volumeInfo, index ) );
       
   628     	        if ( volumeInfo.iSize > size )
       
   629     	            {
       
   630     	        	driveUnit = index;
       
   631     	        	size = volumeInfo.iSize;
       
   632     	            }
       
   633      	        }
       
   634     	    }	
       
   635 	    }
       
   636 	CleanupStack::PopAndDestroy( &fs );
       
   637 	return driveUnit;    
       
   638     }
       
   639 
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 // IAUpdateUtils::InternalDriveWithSpaceL
       
   643 // 
       
   644 // -----------------------------------------------------------------------------
       
   645 //   
       
   646 TBool IAUpdateUtils::InternalDriveWithSpaceL( 
       
   647     TInt aSize, 
       
   648     TDriveUnit aPreferredDriveUnit, 
       
   649     TDriveUnit& aTargetDriveUnit )
       
   650     {
       
   651 	TBool enoughSpaceFound = EFalse;
       
   652 	RFs fs;
       
   653 	User::LeaveIfError( fs.Connect() );
       
   654 	CleanupClosePushL( fs ); 
       
   655 	//check preferred drive first, that's default drive
       
   656 	aTargetDriveUnit = aPreferredDriveUnit;
       
   657 	if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &fs, aSize, aPreferredDriveUnit ) )
       
   658         {
       
   659 		enoughSpaceFound = ETrue;
       
   660 	    }
       
   661 	else
       
   662 	    { //go through other internal drives
       
   663 	    TInt driveCount = 0; 
       
   664 	    TDriveList driveList;
       
   665 	    User::LeaveIfError( DriveInfo::GetUserVisibleDrives( 
       
   666                                          fs, 
       
   667                                          driveList, 
       
   668                                          driveCount) ); 
       
   669         TUint driveStatus = 0;
       
   670 	    for ( TInt index(0); index < KMaxDrives && !enoughSpaceFound; index++ )
       
   671     	    {
       
   672     	    if ( driveList[index]  && aPreferredDriveUnit != index )
       
   673     	        {
       
   674     	    	User::LeaveIfError( DriveInfo::GetDriveStatus( fs, 
       
   675     	                                                       index, 
       
   676     	                                                       driveStatus ) );
       
   677     	        if ( driveStatus & DriveInfo::EDriveInternal )
       
   678     	            {
       
   679     	        	if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &fs, 
       
   680     	        	                                             aSize, 
       
   681     	        	                                             index ) )
       
   682     	        	    {
       
   683     	        		aTargetDriveUnit = index;
       
   684     	        		enoughSpaceFound = ETrue;
       
   685     	        	    }
       
   686     	            }
       
   687     	        }
       
   688     	    }	
       
   689 	    }
       
   690 	
       
   691 	CleanupStack::PopAndDestroy( &fs );
       
   692     return enoughSpaceFound;
       
   693     }
       
   694 
       
   695 // -----------------------------------------------------------------------------
       
   696 // IAUpdateUtils::SaveCurrentFwVersionIfNeededL
       
   697 // 
       
   698 // -----------------------------------------------------------------------------
       
   699 // 
       
   700 void IAUpdateUtils::SaveCurrentFwVersionIfNeededL()
       
   701     {
       
   702     IAUPDATE_TRACE("[IAUPDATE] IAUpdateUtils::SaveCurrentFwVersionIfNeededL() begin");
       
   703     TBuf<KSysVersionInfoTextLength> info;
       
   704     RFs fs;
       
   705     User::LeaveIfError( fs.Connect() );
       
   706     CleanupClosePushL(fs);
       
   707     TInt ret = SysVersionInfo::GetVersionInfo(SysVersionInfo::EFWVersion,
       
   708                 info, fs);
       
   709     CleanupStack::PopAndDestroy( &fs ); 
       
   710     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateUtils::SaveCurrentFwVersionIfNeededL() ret: %d", ret );
       
   711     if ( ret != KErrNotSupported )
       
   712         {
       
   713         User::LeaveIfError( ret );
       
   714         CIAUpdateFwVersionFileHandler* fwVersionFileHandler = CIAUpdateFwVersionFileHandler::NewLC();
       
   715         if ( *fwVersionFileHandler->FwVersionL() != info )
       
   716             {
       
   717             IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateUtils::SaveCurrentFwVersionIfNeededL() Current firmware version in a phone: %S", &info );
       
   718             fwVersionFileHandler->SetFwVersionL( info );
       
   719             IAUPDATE_TRACE("[IAUPDATE] IAUpdateUtils::SaveCurrentFwVersionIfNeededL() firmware version stored");
       
   720             }
       
   721         CleanupStack::PopAndDestroy( fwVersionFileHandler );
       
   722         }
       
   723     
       
   724     IAUPDATE_TRACE("[IAUPDATE] IAUpdateUtils::SaveCurrentFwVersionIfNeededL() end");
       
   725     }
       
   726 
       
   727 // -----------------------------------------------------------------------------
       
   728 // IAUpdateUtils::IsFirmwareChangedL()
       
   729 // 
       
   730 // -----------------------------------------------------------------------------
       
   731 // 
       
   732 TBool IAUpdateUtils::IsFirmwareChangedL() 
       
   733     {
       
   734     IAUPDATE_TRACE("[IAUPDATE] IAUpdateUtils::IsFirmwareChangedL() begin");
       
   735     TBool fwChanged = EFalse;
       
   736     TBuf<KSysVersionInfoTextLength> info;
       
   737     RFs fs;
       
   738     User::LeaveIfError( fs.Connect() );
       
   739     CleanupClosePushL( fs );
       
   740     TInt ret = SysVersionInfo::GetVersionInfo( SysVersionInfo::EFWVersion,
       
   741                     info, fs );
       
   742     CleanupStack::PopAndDestroy( &fs ); 
       
   743     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateUtils::IsFirmwareChangedL() ret: %d", ret );
       
   744     if ( ret != KErrNotSupported )
       
   745         {
       
   746         User::LeaveIfError( ret );
       
   747         IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateUtils::IsFirmwareChangedL() Current firmware version in a phone: %S", &info );
       
   748     
       
   749         CIAUpdateFwVersionFileHandler* fwVersionFileHandler = CIAUpdateFwVersionFileHandler::NewLC();
       
   750         if ( *fwVersionFileHandler->FwVersionL() != info && *fwVersionFileHandler->FwVersionL() != KNullDesC )
       
   751             {
       
   752             fwChanged = ETrue;
       
   753             }
       
   754         CleanupStack::PopAndDestroy( fwVersionFileHandler );
       
   755         }
       
   756     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateUtils::IsFirmwareChangedL() fwChanged: %d", fwChanged );
       
   757     return( fwChanged );
       
   758     }
       
   759     
       
   760  
       
   761 // ---------------------------------------------------------------------------
       
   762 // IAUpdateUtils::FreeDiskSpace
       
   763 // ---------------------------------------------------------------------------
       
   764 // 
       
   765 TInt64 IAUpdateUtils::FreeDiskSpace( RFs& aFs, TInt aDriveNumber )
       
   766     {
       
   767     IAUPDATE_TRACE("[IAUPDATE] IAUpdateUtils::FreeDiskSpace() begin");
       
   768     TInt64 freeSpace = 0;
       
   769     TVolumeInfo volumeInfo;
       
   770     
       
   771     if ( aFs.Volume( volumeInfo, aDriveNumber ) == KErrNone)
       
   772         {
       
   773         freeSpace = volumeInfo.iFree;
       
   774         }
       
   775     
       
   776     IAUPDATE_TRACE_2("[IAUPDATE]IAUpdateUtils::FreeDiskSpace() drive: %d free space: %d kB", 
       
   777                     aDriveNumber, freeSpace / 1024 );
       
   778     
       
   779     IAUPDATE_TRACE("[IAUPDATE] IAUpdateUtils::FreeDiskSpace() end");
       
   780     return freeSpace;
       
   781     }  
       
   782     
       
   783 
       
   784