filemanager/bkupengine/src/CMMCScBkupStateArchiveOpSystemData.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: CMMCScBkupStateArchiveOpSystemData implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "CMMCScBkupStateArchiveOpSystemData.h"
       
    20 
       
    21 // User includes
       
    22 #include "MMCScBkupLogger.h"
       
    23 #include "CMMCScBkupDataOwnerCollection.h"
       
    24 #include "CMMCScBkupDataOwnerInfo.h"
       
    25 #include "MMCScBkupSBEUtils.h"
       
    26 #include "CMMCScBkupArchive.h"
       
    27 #include "CMMCScBkupArchiveFooter.h"
       
    28 #include "CMMCScBkupIndexWithIdentifier.h"
       
    29 #include "MMMCScBkupArchiveDataInterface.h"
       
    30 
       
    31 
       
    32 
       
    33 // ========================= MEMBER FUNCTIONS ================================
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CMMCScBkupStateArchiveOpSystemData::CMMCScBkupStateArchiveOpSystemData()
       
    37 // 
       
    38 // C++ constructor.
       
    39 // ---------------------------------------------------------------------------
       
    40 CMMCScBkupStateArchiveOpSystemData::CMMCScBkupStateArchiveOpSystemData( MMMCScBkupDriver& aDriver )
       
    41 :   CMMCScBkupStateOpAware( aDriver ), iIndexValueCurrent( -1 )
       
    42     {
       
    43     __LOG1("CMMCScBkupStateArchiveOpSystemData::CMMCScBkupStateArchiveOpSystemData() - 0x%08x", StateId().iUid );
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CMMCScBkupStateArchiveOpSystemData::~CMMCScBkupStateArchiveOpSystemData()
       
    49 // 
       
    50 // Destructor.
       
    51 // ---------------------------------------------------------------------------
       
    52 CMMCScBkupStateArchiveOpSystemData::~CMMCScBkupStateArchiveOpSystemData()
       
    53     {
       
    54     Cancel();
       
    55     //
       
    56     delete iBackupTransferObject;
       
    57     delete iRestoreTransferObject;
       
    58     }
       
    59 
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CMMCScBkupStateArchiveOpSystemData::NewL()
       
    63 // 
       
    64 // 
       
    65 // ---------------------------------------------------------------------------
       
    66 CMMCScBkupStateArchiveOpSystemData* CMMCScBkupStateArchiveOpSystemData::NewL( MMMCScBkupDriver& aDriver )
       
    67     {
       
    68     CMMCScBkupStateArchiveOpSystemData* self = new(ELeave) CMMCScBkupStateArchiveOpSystemData( aDriver );
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CMMCScBkupStateArchiveOpSystemData::StateId()
       
    75 // 
       
    76 // 
       
    77 // ---------------------------------------------------------------------------
       
    78 TMMCScBkupStateId CMMCScBkupStateArchiveOpSystemData::StateId() const
       
    79     {
       
    80     return KMMCScBkupStateIdArchiveOpSystemData;
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CMMCScBkupStateArchiveOpSystemData::NextStateBackupId()
       
    86 // 
       
    87 // 
       
    88 // ---------------------------------------------------------------------------
       
    89 TMMCScBkupStateId CMMCScBkupStateArchiveOpSystemData::NextStateBackupId( TBool /*aPartial*/ ) const
       
    90     {
       
    91     return KMMCScBkupStateIdArchiveOpJavaData;
       
    92     }
       
    93 
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CMMCScBkupStateArchiveOpSystemData::NextStateRestoreId()
       
    97 // 
       
    98 // 
       
    99 // ---------------------------------------------------------------------------
       
   100 TMMCScBkupStateId CMMCScBkupStateArchiveOpSystemData::NextStateRestoreId( TBool /*aPartial*/ ) const
       
   101     {
       
   102     return KMMCScBkupStateIdArchiveOpJavaData;
       
   103     }
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CMMCScBkupStateArchiveOpSystemData::PerformStateInitBackupL()
       
   108 // 
       
   109 // 
       
   110 // ---------------------------------------------------------------------------
       
   111 void CMMCScBkupStateArchiveOpSystemData::PerformStateInitBackupL( TBool /*aPartial*/ )
       
   112     {
       
   113     __DEBUG_TESTING_SKIP_BACKUP_SYS_DATA;
       
   114 
       
   115     iBackupTransferObject = CMMCScBkupWriteDataTransferRequest< TPackageDataType >::NewL(
       
   116                                     Driver(), 
       
   117                                     *this,
       
   118                                     EMMCScBkupOwnerDataTypeSystemData,
       
   119                                     EPackageTransferDerivedType,
       
   120                                     ESystemData
       
   121                                     );
       
   122     CompleteSelf();
       
   123     }
       
   124 
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CMMCScBkupStateArchiveOpSystemData::PerformStateInitRestoreL()
       
   128 // 
       
   129 // 
       
   130 // ---------------------------------------------------------------------------
       
   131 void CMMCScBkupStateArchiveOpSystemData::PerformStateInitRestoreL( TBool /*aPartial*/ )
       
   132     {
       
   133     __LOG("CMMCScBkupStateArchiveOpSystemData::PerformStateInitRestoreL() - START" );
       
   134     __DEBUG_TESTING_SKIP_RESTORE_SYS_DATA;
       
   135 
       
   136     iRestoreTransferObject = CMMCScBkupReadDataTransferRequest< TPackageDataType >::NewL(
       
   137                                     Driver(),
       
   138                                     EMMCScBkupOwnerDataTypeSystemData,
       
   139                                     ESystemData
       
   140                                     );
       
   141 
       
   142     CompleteSelf();
       
   143     __LOG("CMMCScBkupStateArchiveOpSystemData::PerformStateInitRestoreL() - END" );
       
   144     }
       
   145 
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepBackupL()
       
   149 // 
       
   150 // 
       
   151 // ---------------------------------------------------------------------------
       
   152 void CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepBackupL( TBool /*aPartial*/ )
       
   153     {
       
   154     CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners();
       
   155     const TInt count = dataOwners.Count();
       
   156     //
       
   157     while ( ++iIndexValueCurrent < count )
       
   158         {
       
   159         CMMCScBkupDataOwnerInfo& owner = dataOwners.Owner( iIndexValueCurrent );
       
   160         //
       
   161         if  ( owner.CompletionStatus( EMMCScBkupOwnerDataTypeSystemData ) == EFalse )
       
   162             {
       
   163             // Request all the system data (on all supported drives) for this
       
   164             // particular data owner
       
   165             __ASSERT_ALWAYS( iBackupTransferObject->IsActive() == EFalse, User::Invariant() );
       
   166             iBackupTransferObject->RequestL( owner, 
       
   167                                              iStatus,
       
   168                                              Driver().DrvParamsBase().DriveAndOperations() );
       
   169             SetActive();
       
   170             break; // while loop
       
   171             }
       
   172         }
       
   173     }
       
   174 
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepRestoreL()
       
   178 // 
       
   179 // 
       
   180 // ---------------------------------------------------------------------------
       
   181 void CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepRestoreL( TBool /*aPartial*/ )
       
   182     {
       
   183     CMMCScBkupIndexBase& indexBase = Driver().DrvArchive().Footer().IndexByType( EMMCScBkupOwnerDataTypeSystemData );
       
   184     CMMCScBkupIndexWithIdentifier<  TInt32 >& index = static_cast< CMMCScBkupIndexWithIdentifier< TInt32 >& >( indexBase );
       
   185     const TInt count = index.Count();
       
   186     __LOG1("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepRestoreL() - START - %d data owners...", count );
       
   187     //
       
   188     if  ( ++iIndexValueCurrent < count )
       
   189         {
       
   190         __LOG2("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepRestoreL() - getting system data index record [%03d/%03d]", iIndexValueCurrent + 1, count);
       
   191         const CMMCScBkupIndexEntry< TInt32 >& entry = index.At( iIndexValueCurrent );
       
   192         iSecureId = entry.Identifier();
       
   193 
       
   194         __LOG("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepRestoreL() - getting sub-entries for index record...");
       
   195         const RArray< TMMCScBkupArchiveDriveAndVector >& subEntries = entry.Entries();
       
   196         __LOG1("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepRestoreL() - got %d sub-entries for index record", subEntries.Count());
       
   197 #ifdef __MMCSCBKUPLOGGING_ENABLED__
       
   198         for(TInt i=0; i<subEntries.Count(); i++)
       
   199             {
       
   200             const TMMCScBkupArchiveDriveAndVector& item = subEntries[i];
       
   201             __LOG4("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepRestoreL() - subentry[%2d] = %c:\\ [Offset: %8d, Length: %d] ", i, item.iDrive + 'A', item.iVector.Offset(), item.iVector.Length() );
       
   202             }
       
   203 #endif
       
   204         
       
   205         // Get the associated data owner
       
   206         CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners();
       
   207 
       
   208         __LOG1("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepRestoreL() - trying to supply system data for SID: 0x%08x", entry.Identifier() );
       
   209 
       
   210         // The owner in question should be a package type object. 
       
   211         CMMCScBkupDataOwnerInfo& owner = dataOwners.OwnerL( entry.Identifier() );
       
   212 
       
   213         if  ( owner.CompletionStatus( EMMCScBkupOwnerDataTypeSystemData ) == EFalse )
       
   214             {
       
   215             // The owner in question should be a package type object. 
       
   216             const TSBDerivedType ownersDerivedType = owner.Owner().Identifier().DerivedTypeL();
       
   217             __ASSERT_ALWAYS( ownersDerivedType == EPackageDerivedType || ownersDerivedType == EPackageTransferDerivedType, User::Invariant() );
       
   218 
       
   219 #ifdef __MMCSCBKUPLOGGING_ENABLED__
       
   220             const TUid packageUid = MMCScBkupSBEUtils::PackageIdFromGenericL( owner.Owner().Identifier() );
       
   221             __LOG2("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousStateStepRestoreL() - trying to restore SYSTEM DATA for SID: 0x%08x, packageUID: 0x%08x", entry.Identifier(), packageUid.iUid );
       
   222 #endif
       
   223 
       
   224             // Safety check
       
   225             __ASSERT_ALWAYS( iRestoreTransferObject->IsActive() == EFalse, User::Invariant() );
       
   226 
       
   227             // Request all the system data (on all supported drives) for this
       
   228             // particular data owner
       
   229             iRestoreTransferObject->RequestL( owner, 
       
   230                                               iStatus,
       
   231                                               subEntries );
       
   232             SetActive();
       
   233             }
       
   234         else
       
   235             {
       
   236             CompleteSelf();
       
   237             }
       
   238         }
       
   239     }
       
   240 
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousErrorCleanupBackup()
       
   244 // 
       
   245 // 
       
   246 // ---------------------------------------------------------------------------
       
   247 TBool CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousErrorCleanupBackup( TBool /*aPartial*/, TInt aError )
       
   248     {
       
   249     (void) aError;
       
   250     __LOG1("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousErrorCleanupBackup() - error: %d", aError );
       
   251 
       
   252     // Reset state and move to next item. Treat the current (badly behaving) item
       
   253     // as completed/processed.
       
   254     CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners();
       
   255     if  ( iIndexValueCurrent < dataOwners.Count() )
       
   256         {
       
   257         CMMCScBkupDataOwnerInfo& owner = dataOwners.Owner( iIndexValueCurrent );
       
   258         owner.SetCompletionStatus( EMMCScBkupOwnerDataTypeSystemData, ETrue );
       
   259 
       
   260         __LOGFILE2("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousErrorCleanupBackup() - **** - error: %d, SID: 0x%08x - system data skipped for DO", aError, owner.SecureId().iId );
       
   261         }
       
   262 
       
   263     CompleteSelf();
       
   264     return ETrue;
       
   265     }
       
   266 
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousErrorCleanupRestore()
       
   270 // 
       
   271 // 
       
   272 // ---------------------------------------------------------------------------
       
   273 TBool CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousErrorCleanupRestore( TBool /*aPartial*/, TInt aError )
       
   274     {
       
   275     (void) aError;
       
   276     __LOGFILE1("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousErrorCleanupRestore() - **** - error: %d", aError );
       
   277 
       
   278     // If system data restore phase returns "not supported", let's treat it as 
       
   279     // such an error, that other data types for this data owner are not
       
   280     // allowed to restore either.
       
   281     
       
   282     if( aError == KErrNotSupported || aError == KErrAlreadyExists )
       
   283         {
       
   284         CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners();
       
   285         CMMCScBkupDataOwnerInfo* owner = NULL;
       
   286         TRAPD( err, owner = &dataOwners.OwnerL( iSecureId ) );
       
   287         if( err == KErrNone && owner )
       
   288             {
       
   289             owner->SetCompletionStatus( EMMCScBkupOwnerDataTypeJavaData, ETrue );
       
   290             owner->SetCompletionStatus( EMMCScBkupOwnerDataTypePublicData, ETrue );
       
   291             owner->SetCompletionStatus( EMMCScBkupOwnerDataTypeSystemData, ETrue );
       
   292             owner->SetCompletionStatus( EMMCScBkupOwnerDataTypeActiveData, ETrue );
       
   293             owner->SetCompletionStatus( EMMCScBkupOwnerDataTypePassiveData, ETrue );
       
   294 
       
   295             __LOGFILE2("CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousErrorCleanupRestore() - **** - error: %d, SID: 0x%08x - all data types skipped for DO", aError, owner->SecureId().iId );
       
   296             }
       
   297         }
       
   298     
       
   299     CompleteSelf();
       
   300     return ETrue;
       
   301     }
       
   302 
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousCancellation()
       
   306 // 
       
   307 // 
       
   308 // ---------------------------------------------------------------------------
       
   309 void CMMCScBkupStateArchiveOpSystemData::PerformAsynchronousCancellation()
       
   310     {
       
   311     if  (iBackupTransferObject)
       
   312         {
       
   313         iBackupTransferObject->Cancel();
       
   314         }
       
   315     if  (iRestoreTransferObject)
       
   316         {
       
   317         iRestoreTransferObject->Cancel();
       
   318         }
       
   319     }
       
   320 
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // CMMCScBkupStateArchiveOpSystemData::PerformLastRightsBackupL()
       
   324 // 
       
   325 // 
       
   326 // ---------------------------------------------------------------------------
       
   327 void CMMCScBkupStateArchiveOpSystemData::PerformLastRightsBackupL( TBool /*aPartial*/ )
       
   328     {
       
   329     CMMCScBkupIndexBase& index = Driver().DrvArchive().Footer().IndexByType( EMMCScBkupOwnerDataTypeSystemData );
       
   330     index.StoreL( Driver() );
       
   331     }
       
   332 
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CMMCScBkupStateArchiveOpSystemData::PerformLastRightsRestoreL()
       
   336 // 
       
   337 // 
       
   338 // ---------------------------------------------------------------------------
       
   339 void CMMCScBkupStateArchiveOpSystemData::PerformLastRightsRestoreL( TBool /*aPartial*/ )
       
   340     {
       
   341     Driver().DrvSecureBackupClient().AllSystemFilesRestored();
       
   342     }
       
   343 
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // CMMCScBkupStateArchiveOpSystemData::AddIndexRecordL()
       
   347 // 
       
   348 // 
       
   349 // ---------------------------------------------------------------------------
       
   350 void CMMCScBkupStateArchiveOpSystemData::AddIndexRecordL( CMMCScBkupArchiveFooter& aFooter, CMMCScBkupDataOwnerInfo& aDataOwner, const TMMCScBkupArchiveVector& aInfo, TDriveNumber aDrive )
       
   351     {
       
   352     CMMCScBkupIndexBase& indexBase = aFooter.IndexByType( EMMCScBkupOwnerDataTypeSystemData );
       
   353     CMMCScBkupIndexWithIdentifier< TInt32 >& index = static_cast< CMMCScBkupIndexWithIdentifier< TInt32 >& >( indexBase );
       
   354     index.AddIndexRecordL( aInfo, aDrive, aDataOwner.SecureId().iId );
       
   355     }
       
   356 
       
   357 
       
   358 
       
   359 
       
   360 
       
   361 
       
   362 
       
   363 
       
   364 
       
   365 
       
   366 
       
   367