filemanager/bkupengine/src/MMCScBkupSBEUtils.cpp
branchRCL_3
changeset 38 491b3ed49290
parent 36 95243422089a
child 39 65326cf895ed
equal deleted inserted replaced
36:95243422089a 38:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2005 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: MMCScBkupSBEUtils implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "MMCScBkupSBEUtils.h"
       
    20 
       
    21 // System includes
       
    22 #include <e32property.h>
       
    23 #include <connect/sbdefs.h>
       
    24 #include "CMMCScBkupDataOwnerInfo.h"
       
    25 
       
    26 // Namespaces
       
    27 using namespace conn;
       
    28 
       
    29 
       
    30 
       
    31 // ========================= MEMBER FUNCTIONS ================================
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // MMCScBkupSBEUtils::SecureIdFromGenericL()
       
    35 // 
       
    36 // 
       
    37 // ---------------------------------------------------------------------------
       
    38 TSecureId MMCScBkupSBEUtils::SecureIdFromGenericL(const CSBGenericDataType& aGeneric)
       
    39     {
       
    40     TSecureId ret = 0;
       
    41     CSBGenericDataType* nonConstOriginal = const_cast<CSBGenericDataType*>(&aGeneric);
       
    42     const TSBDerivedType type = aGeneric.DerivedTypeL();
       
    43     //
       
    44     switch(type)
       
    45         {
       
    46     case ESIDDerivedType:
       
    47         {
       
    48         CSBSecureId* temp = CSBSecureId::NewL( nonConstOriginal );
       
    49         CleanupStack::PushL( temp );
       
    50         ret = temp->SecureIdL();
       
    51         CleanupStack::PopAndDestroy( temp );
       
    52         break;
       
    53         }
       
    54     case ESIDTransferDerivedType:
       
    55         {
       
    56         // First make a generic transfer type object...
       
    57         CSBGenericTransferType* transferTypeTemp = CSBGenericTransferType::NewL( nonConstOriginal->Externalise() );
       
    58         CleanupStack::PushL(transferTypeTemp);
       
    59 
       
    60         // Now make instance transfer type
       
    61         CSBSIDTransferType* temp = CSBSIDTransferType::NewL( transferTypeTemp );
       
    62         CleanupStack::PushL(temp);
       
    63 
       
    64         // Now get the result
       
    65         ret = temp->SecureIdL();
       
    66 
       
    67         // Tidy up
       
    68         CleanupStack::PopAndDestroy(2, transferTypeTemp);
       
    69         break;
       
    70         }
       
    71     case EPackageDerivedType:
       
    72         {
       
    73         CSBPackageId* temp = CSBPackageId::NewL( nonConstOriginal );
       
    74         CleanupStack::PushL( temp );
       
    75         ret = temp->SecureIdL();
       
    76         CleanupStack::PopAndDestroy( temp );
       
    77         break;
       
    78         }
       
    79     case EPackageTransferDerivedType:
       
    80     case EJavaDerivedType:
       
    81     case EJavaTransferDerivedType:
       
    82     default:
       
    83         __BREAKPOINT();
       
    84         User::Leave(KErrNotSupported);
       
    85         break;
       
    86        }
       
    87     //
       
    88     return ret;
       
    89     }
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // MMCScBkupSBEUtils::PackageIdFromGenericL()
       
    94 // 
       
    95 // 
       
    96 // ---------------------------------------------------------------------------
       
    97 TUid MMCScBkupSBEUtils::PackageIdFromGenericL(const CSBGenericDataType& aGeneric)
       
    98     {
       
    99     TUid ret = KNullUid;
       
   100     CSBGenericDataType* nonConstOriginal = const_cast<CSBGenericDataType*>(&aGeneric);
       
   101     const TSBDerivedType type = aGeneric.DerivedTypeL();
       
   102     //
       
   103     switch(type)
       
   104         {
       
   105     case EPackageDerivedType:
       
   106         {
       
   107         CSBPackageId* temp = CSBPackageId::NewL( nonConstOriginal );
       
   108         CleanupStack::PushL(temp);
       
   109         ret = temp->PackageIdL();
       
   110         CleanupStack::PopAndDestroy(temp);
       
   111         break;
       
   112         }
       
   113     case EPackageTransferDerivedType:
       
   114         {
       
   115         // First make a generic transfer type object...
       
   116         CSBGenericTransferType* transferTypeTemp = CSBGenericTransferType::NewL( nonConstOriginal->Externalise() );
       
   117         CleanupStack::PushL(transferTypeTemp);
       
   118 
       
   119         // Now make instance transfer type
       
   120         CSBPackageTransferType* temp = CSBPackageTransferType::NewL( transferTypeTemp );
       
   121         CleanupStack::PushL(temp);
       
   122 
       
   123         // Now get the result
       
   124         ret = temp->PackageIdL();
       
   125 
       
   126         // Tidy up
       
   127         CleanupStack::PopAndDestroy(2, transferTypeTemp);
       
   128         break;
       
   129         }
       
   130     case ESIDDerivedType:
       
   131     case ESIDTransferDerivedType:
       
   132     case EJavaDerivedType:
       
   133     case EJavaTransferDerivedType:
       
   134     default:
       
   135         __BREAKPOINT();
       
   136         User::Leave(KErrNotSupported);
       
   137         break;
       
   138        }
       
   139     //
       
   140     return ret;
       
   141     }
       
   142 
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // MMCScBkupSBEUtils::JavaHashFromGenericLC()
       
   146 // 
       
   147 // 
       
   148 // ---------------------------------------------------------------------------
       
   149 HBufC* MMCScBkupSBEUtils::JavaHashFromGenericLC(const CSBGenericDataType& aGeneric)
       
   150     {
       
   151     HBufC* ret = NULL;
       
   152     CSBGenericDataType* nonConstOriginal = const_cast<CSBGenericDataType*>(&aGeneric);
       
   153     const TSBDerivedType type = aGeneric.DerivedTypeL();
       
   154     //
       
   155     switch(type)
       
   156         {
       
   157     case EJavaDerivedType:
       
   158         {
       
   159         CSBJavaId* temp = CSBJavaId::NewL( nonConstOriginal );
       
   160         CleanupStack::PushL(temp);
       
   161         ret = temp->SuiteHashL().AllocL();
       
   162         CleanupStack::PopAndDestroy(temp);
       
   163         CleanupStack::PushL( ret );
       
   164         break;
       
   165         }
       
   166     case EJavaTransferDerivedType:
       
   167         {
       
   168         // First make a generic transfer type object...
       
   169         CSBGenericTransferType* transferTypeTemp = CSBGenericTransferType::NewL( nonConstOriginal->Externalise() );
       
   170         CleanupStack::PushL(transferTypeTemp);
       
   171 
       
   172         // Now make a instance transfer type
       
   173         CSBJavaTransferType* temp = CSBJavaTransferType::NewL( transferTypeTemp );
       
   174         CleanupStack::PushL(temp);
       
   175 
       
   176         // Now get the result
       
   177         ret = temp->SuiteHashL().AllocL();
       
   178 
       
   179         // Tidy up
       
   180         CleanupStack::PopAndDestroy(2, transferTypeTemp);
       
   181         CleanupStack::PushL( ret );
       
   182         break;
       
   183         }
       
   184     case ESIDDerivedType:
       
   185     case ESIDTransferDerivedType:
       
   186     case EPackageDerivedType:
       
   187     case EPackageTransferDerivedType:
       
   188     default:
       
   189         __BREAKPOINT();
       
   190         User::Leave(KErrNotSupported);
       
   191         break;
       
   192        }
       
   193     //
       
   194     if  ( ret == NULL )
       
   195         {
       
   196         ret = KNullDesC().AllocLC();
       
   197         }
       
   198     //
       
   199     return ret;
       
   200     }
       
   201 
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // MMCScBkupSBEUtils::CopyLC()
       
   205 // 
       
   206 // 
       
   207 // ---------------------------------------------------------------------------
       
   208 CSBGenericDataType* MMCScBkupSBEUtils::CopyLC(const CSBGenericDataType& aToBeCopied)
       
   209     {
       
   210     CSBGenericDataType* ret = NULL;
       
   211 
       
   212     // Have to do this through poor implementation of SBE API 
       
   213     CSBGenericDataType* nonConstOriginal = const_cast<CSBGenericDataType*>(&aToBeCopied);
       
   214     //
       
   215     const TSBDerivedType type = nonConstOriginal->DerivedTypeL();
       
   216     switch(type)
       
   217         {
       
   218     case ESIDDerivedType:
       
   219         ret = CSBSecureId::NewL(nonConstOriginal);
       
   220         break;
       
   221     case EPackageDerivedType:
       
   222         ret = CSBPackageId::NewL(nonConstOriginal);
       
   223         break;
       
   224     case EJavaDerivedType:
       
   225         ret = CSBJavaId::NewL(nonConstOriginal);
       
   226         break;
       
   227     case ESIDTransferDerivedType:
       
   228     case EPackageTransferDerivedType:
       
   229     case EJavaTransferDerivedType:
       
   230         {
       
   231         // Must first create a generic transfer type object... sigh...
       
   232         CSBGenericTransferType* transferType = CSBGenericTransferType::NewL( nonConstOriginal->Externalise() );
       
   233         CleanupStack::PushL( transferType ); 
       
   234         if ( ESIDTransferDerivedType == type )
       
   235             {
       
   236             ret = CSBSIDTransferType::NewL( transferType );
       
   237             }
       
   238         else if ( EPackageTransferDerivedType == type )
       
   239             {
       
   240             ret = CSBPackageTransferType::NewL( transferType );
       
   241             }
       
   242         // Type is EJavaTransferDerivedType
       
   243         else
       
   244             {
       
   245             ret = CSBJavaTransferType::NewL( transferType );
       
   246             }
       
   247         CleanupStack::PopAndDestroy( transferType );
       
   248         }
       
   249     default:
       
   250         break;
       
   251        }
       
   252     //
       
   253     if  (!ret)
       
   254         {
       
   255         __BREAKPOINT();
       
   256         User::Leave(KErrNotSupported);
       
   257         }
       
   258     CleanupStack::PushL(ret);
       
   259     return ret;
       
   260     }
       
   261 
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // MMCScBkupSBEUtils::TransferTypeLC()
       
   265 // 
       
   266 // 
       
   267 // ---------------------------------------------------------------------------
       
   268 CSBGenericTransferType* MMCScBkupSBEUtils::TransferTypeLC( const CSBGenericDataType& aDT, TDriveNumber aDrive, 
       
   269     TTransferDataType aTransferType, TInt aVersion )
       
   270     {
       
   271     CSBGenericTransferType* ret = NULL;
       
   272 
       
   273     // Have to do this through poor implementation of SBE API 
       
   274     CSBGenericDataType* nonConstOriginal = const_cast< CSBGenericDataType* >( &aDT );
       
   275     //
       
   276     const TSBDerivedType type = nonConstOriginal->DerivedTypeL();
       
   277     switch( type )
       
   278         {
       
   279     case ESIDDerivedType:
       
   280     case ESIDTransferDerivedType:
       
   281         {
       
   282         const TSecureId secureId = SecureIdFromGenericL( aDT );
       
   283         ret = CSBSIDTransferType::NewL( secureId, aDrive, aTransferType );
       
   284         break;
       
   285         }
       
   286 
       
   287     case EPackageDerivedType:
       
   288         {
       
   289         TSecureId secureId = SecureIdFromGenericL( aDT );
       
   290         if( secureId.iId == KNullUid.iUid && aVersion > CMMCScBkupDataOwnerInfo::EStreamFormatVersionFirst )
       
   291             {
       
   292             secureId = MMCScBkupSBEUtils::PackageIdFromGenericL( aDT );
       
   293             }
       
   294         ret = CSBSIDTransferType::NewL( secureId, aDrive, aTransferType );
       
   295         break;
       
   296         }
       
   297 
       
   298     default:
       
   299     case EPackageTransferDerivedType:
       
   300     case EJavaDerivedType:
       
   301     case EJavaTransferDerivedType:
       
   302         __BREAKPOINT();
       
   303         User::Leave( KErrNotSupported );
       
   304         break;
       
   305         }
       
   306     //
       
   307     CleanupStack::PushL( ret );
       
   308     return ret;
       
   309     }
       
   310 
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // MMCScBkupSBEUtils::TransferTypeLC()
       
   314 // 
       
   315 // 
       
   316 // ---------------------------------------------------------------------------
       
   317 CSBGenericTransferType* MMCScBkupSBEUtils::TransferTypeLC(const CSBGenericDataType& aDT, TDriveNumber aDrive, 
       
   318     TPackageDataType aDataType, TInt /*aVersion*/)
       
   319     {
       
   320     CSBGenericTransferType* ret = NULL;
       
   321 
       
   322     // Have to do this through poor implementation of SBE API 
       
   323     CSBGenericDataType* nonConstOriginal = const_cast<CSBGenericDataType*>(&aDT);
       
   324     //
       
   325     const TSBDerivedType type = nonConstOriginal->DerivedTypeL();
       
   326     switch(type)
       
   327         {
       
   328     case EPackageDerivedType:
       
   329     case EPackageTransferDerivedType:
       
   330         {
       
   331         const TUid packageId = PackageIdFromGenericL(aDT);
       
   332         ret = CSBPackageTransferType::NewL(packageId, aDrive, aDataType);
       
   333         break;
       
   334         }
       
   335 
       
   336     default:
       
   337     case ESIDDerivedType:
       
   338     case ESIDTransferDerivedType:
       
   339     case EJavaDerivedType:
       
   340     case EJavaTransferDerivedType:
       
   341         __BREAKPOINT();
       
   342         User::Leave(KErrNotSupported);
       
   343         break;
       
   344         }
       
   345     //
       
   346     CleanupStack::PushL(ret);
       
   347     return ret;
       
   348     }
       
   349 
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // MMCScBkupSBEUtils::TransferTypeLC()
       
   353 // 
       
   354 // 
       
   355 // ---------------------------------------------------------------------------
       
   356 CSBGenericTransferType* MMCScBkupSBEUtils::TransferTypeLC(const CSBGenericDataType& aDT, TDriveNumber aDrive, 
       
   357     TJavaTransferType aDataType, TInt /*aVersion*/)
       
   358     {
       
   359     CSBGenericTransferType* ret = NULL;
       
   360 
       
   361     // Have to do this through poor implementation of SBE API 
       
   362     CSBGenericDataType* nonConstOriginal = const_cast<CSBGenericDataType*>(&aDT);
       
   363     //
       
   364     const TSBDerivedType type = nonConstOriginal->DerivedTypeL();
       
   365     switch(type)
       
   366         {
       
   367     case EJavaDerivedType:
       
   368     case EJavaTransferDerivedType:
       
   369         {
       
   370         HBufC* hash = JavaHashFromGenericLC( aDT );
       
   371         ret = CSBJavaTransferType::NewL( *hash, aDrive, aDataType );
       
   372         CleanupStack::PopAndDestroy( hash );
       
   373         break;
       
   374         }
       
   375 
       
   376     default:
       
   377     case ESIDDerivedType:
       
   378     case ESIDTransferDerivedType:
       
   379     case EPackageDerivedType:
       
   380     case EPackageTransferDerivedType:
       
   381         __BREAKPOINT();
       
   382         User::Leave(KErrNotSupported);
       
   383         break;
       
   384         }
       
   385     //
       
   386     CleanupStack::PushL(ret);
       
   387     return ret;
       
   388     }
       
   389 
       
   390 
       
   391 // ---------------------------------------------------------------------------
       
   392 // MMCScBkupSBEUtils::PhoneIsInBackupOrRestoreModeL()
       
   393 // 
       
   394 // 
       
   395 // ---------------------------------------------------------------------------
       
   396 TBool MMCScBkupSBEUtils::PhoneIsInBackupOrRestoreModeL()
       
   397     {
       
   398     TBool backupInProgress = EFalse;
       
   399     //
       
   400     TInt value = 0;
       
   401     const TInt error = RProperty::Get( KUidSystemCategory, KUidBackupRestoreKey, value );
       
   402     User::LeaveIfError( error );
       
   403     //
       
   404     const TBURPartType partType = static_cast< TBURPartType >( value & KBURPartTypeMask );
       
   405     if  (value != 0)
       
   406         {
       
   407         switch(partType)
       
   408             {
       
   409         case EBURUnset:
       
   410         case EBURNormal:
       
   411             break;
       
   412         case EBURBackupFull:
       
   413         case EBURBackupPartial:
       
   414         case EBURRestoreFull:
       
   415         case EBURRestorePartial:
       
   416             backupInProgress = ETrue;
       
   417             break;
       
   418             }
       
   419         }
       
   420     //
       
   421     return backupInProgress;
       
   422     }
       
   423 
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // MMCScBkupSBEUtils::EndBackupOrRestoreL()
       
   427 // 
       
   428 // 
       
   429 // ---------------------------------------------------------------------------
       
   430 void MMCScBkupSBEUtils::EndBackupOrRestoreL( CSBEClient& aSBEClient )
       
   431     {
       
   432     TDriveList nullDriveList;
       
   433     aSBEClient.SetBURModeL( nullDriveList, EBURNormal, ENoBackup);
       
   434     }
       
   435 
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // MMCScBkupSBEUtils::HasSystemDataL()
       
   439 // 
       
   440 // 
       
   441 // ---------------------------------------------------------------------------
       
   442 TBool MMCScBkupSBEUtils::HasSystemDataL( const CDataOwnerInfo& aDataOwner )
       
   443     {
       
   444     const TSBDerivedType type = aDataOwner.Identifier().DerivedTypeL();
       
   445     const TBool systemDataType = ( type == EPackageDerivedType || 
       
   446                                    type == EPackageTransferDerivedType );
       
   447     const TBool hasSystemData = ( aDataOwner.CommonSettings() & EHasSystemFiles );
       
   448     //
       
   449     return ( systemDataType && hasSystemData );
       
   450     }
       
   451 
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // MMCScBkupSBEUtils::HasJavaDataL()
       
   455 // 
       
   456 // 
       
   457 // ---------------------------------------------------------------------------
       
   458 TBool MMCScBkupSBEUtils::HasJavaDataL( const CDataOwnerInfo& aDataOwner )
       
   459     {
       
   460     const TSBDerivedType type = aDataOwner.Identifier().DerivedTypeL();
       
   461     const TBool javaDataType = ( type == EJavaDerivedType || 
       
   462                                  type == EJavaTransferDerivedType );
       
   463     const TBool hasSystemData = ( aDataOwner.CommonSettings() & EHasSystemFiles );
       
   464 
       
   465     // Java abuses the "has system files flag" - this has been confirmed
       
   466     // with Symbian.
       
   467     return ( javaDataType && hasSystemData );
       
   468     }
       
   469 
       
   470 
       
   471 // ---------------------------------------------------------------------------
       
   472 // MMCScBkupSBEUtils::HasPassiveDataL()
       
   473 // 
       
   474 // 
       
   475 // ---------------------------------------------------------------------------
       
   476 TBool MMCScBkupSBEUtils::HasPassiveDataL( const CDataOwnerInfo& aDataOwner )
       
   477     {
       
   478     const TSBDerivedType type = aDataOwner.Identifier().DerivedTypeL();
       
   479     const TBool passiveDataType = ( type == ESIDDerivedType || 
       
   480                                     type == ESIDTransferDerivedType ||
       
   481                                     type == EPackageDerivedType || 
       
   482                                     type == EPackageTransferDerivedType );
       
   483     const TBool hasPassiveData = ( aDataOwner.CommonSettings() & EPassiveBUR );
       
   484     //
       
   485     return ( passiveDataType && hasPassiveData );
       
   486     }
       
   487 
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 // MMCScBkupSBEUtils::HasActiveDataL()
       
   491 // 
       
   492 // 
       
   493 // ---------------------------------------------------------------------------
       
   494 TBool MMCScBkupSBEUtils::HasActiveDataL( const CDataOwnerInfo& aDataOwner )
       
   495     {
       
   496     const TSBDerivedType type = aDataOwner.Identifier().DerivedTypeL();
       
   497     const TBool activeDataType = ( type == ESIDDerivedType || 
       
   498                                    type == ESIDTransferDerivedType ||
       
   499                                    type == EPackageDerivedType || 
       
   500                                    type == EPackageTransferDerivedType );
       
   501     const TBool hasActiveData = ( aDataOwner.CommonSettings() & EActiveBUR );
       
   502     //
       
   503     return ( activeDataType && hasActiveData );
       
   504     }
       
   505 
       
   506 
       
   507 // ---------------------------------------------------------------------------
       
   508 // MMCScBkupSBEUtils::HasPublicDataL()
       
   509 // 
       
   510 // 
       
   511 // ---------------------------------------------------------------------------
       
   512 TBool MMCScBkupSBEUtils::HasPublicDataL( const CDataOwnerInfo& aDataOwner )
       
   513     {
       
   514     const TSBDerivedType type = aDataOwner.Identifier().DerivedTypeL();
       
   515     const TBool publicDataType = ( type == ESIDDerivedType || 
       
   516                                    type == ESIDTransferDerivedType ||
       
   517                                    type == EPackageDerivedType || 
       
   518                                    type == EPackageTransferDerivedType );
       
   519     const TBool hasPublicData = ( aDataOwner.PassiveSettings() & EHasPublicFiles );
       
   520     //
       
   521     return ( hasPublicData && publicDataType );
       
   522     }
       
   523