21
|
1 |
/*
|
|
2 |
* Copyright (c) 2006-2008 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: Wraps removable drive functionality
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include <filemanagerengine.rsg>
|
|
22 |
#include "CFileManagerRemovableDriveHandler.h"
|
|
23 |
#include "MFileManagerProcessObserver.h"
|
|
24 |
#include "CFileManagerUtils.h"
|
|
25 |
#include "CFileManagerEngine.h"
|
|
26 |
#include <coreapplicationuisdomainpskeys.h>
|
|
27 |
#include <coemain.h>
|
|
28 |
#include <apgwgnam.h>
|
|
29 |
#include <apgtask.h>
|
|
30 |
#include <bautils.h>
|
|
31 |
#include <tz.h>
|
|
32 |
#include <babackup.h>
|
|
33 |
#include <pathinfo.h>
|
|
34 |
#include <sysutil.h>
|
|
35 |
#ifdef RD_MULTIPLE_DRIVE
|
|
36 |
#include <driveinfo.h>
|
|
37 |
#endif // RD_MULTIPLE_DRIVE
|
|
38 |
#include <e32property.h>
|
|
39 |
#include <centralrepository.h>
|
|
40 |
#include "CMMCScBkupEngine.h"
|
|
41 |
#include "MMCScBkupOperations.h"
|
|
42 |
#include "CMMCScBkupOperationParameters.h"
|
|
43 |
#include "CFileManagerItemProperties.h"
|
|
44 |
#include "CFileManagerBackupSettings.h"
|
|
45 |
#include "FileManagerPrivateCRKeys.h"
|
|
46 |
#include "BkupEngine.hrh"
|
|
47 |
#include "FileManagerDebug.h"
|
|
48 |
#include "CFileManagerCommonDefinitions.h"
|
|
49 |
#include "FileManagerUID.h"
|
|
50 |
#include "filemanagerprivatepskeys.h"
|
|
51 |
|
|
52 |
|
|
53 |
// CONSTANTS
|
|
54 |
const TInt KEjectScanInterval = 1000000; // 1 second
|
|
55 |
const TInt KEjectScanRoundsMax = 7;
|
|
56 |
NONSHARABLE_CLASS(TMaskLookup)
|
|
57 |
{
|
|
58 |
public:
|
|
59 |
TUint32 iBkupMask;
|
|
60 |
TUint32 iFmgrMask;
|
|
61 |
};
|
|
62 |
|
|
63 |
const TMaskLookup KMaskLookup[] = {
|
|
64 |
{ EBUCatSettings, EFileManagerBackupContentSettings },
|
|
65 |
{ EBUCatMessages, EFileManagerBackupContentMessages },
|
|
66 |
{ EBUCatContacts, EFileManagerBackupContentContacts },
|
|
67 |
{ EBUCatCalendar, EFileManagerBackupContentCalendar },
|
|
68 |
{ EBUCatBookmarks, EFileManagerBackupContentBookmarks },
|
|
69 |
{ EBUCatUserFiles, EFileManagerBackupContentUserFiles }
|
|
70 |
};
|
|
71 |
const TUint32 KMaskLookupLen =
|
|
72 |
sizeof( KMaskLookup ) / sizeof( KMaskLookup[ 0 ] );
|
|
73 |
|
|
74 |
const TInt KForcedFormatTimeout = 1000000;
|
|
75 |
const TInt KAppCloseTimeout = 1000000;
|
|
76 |
const TInt KFileManagerAppUid = 0x101F84EB;
|
|
77 |
|
|
78 |
NONSHARABLE_CLASS(TFileManagerVolumeNameStore)
|
|
79 |
{
|
|
80 |
public:
|
|
81 |
inline TFileManagerVolumeNameStore() : iDrive( KErrNotFound ), iName( KNullDesC ) {};
|
|
82 |
|
|
83 |
TInt iDrive; // The drive using the store
|
|
84 |
TFileName iName; // Use the same length than TVolumeInfo
|
|
85 |
};
|
|
86 |
|
|
87 |
typedef TPckg< TFileManagerVolumeNameStore > TFileManagerVolumeNameStorePckg;
|
|
88 |
|
|
89 |
|
|
90 |
// ======== MEMBER FUNCTIONS ========
|
|
91 |
|
|
92 |
// ---------------------------------------------------------------------------
|
|
93 |
// CFileManagerRemovableDriveHandler::CFileManagerRemovableDriveHandler
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
CFileManagerRemovableDriveHandler::CFileManagerRemovableDriveHandler(
|
|
97 |
RFs& aFs,
|
|
98 |
CFileManagerUtils& aUtils,
|
|
99 |
CFileManagerEngine& aEngine ) :
|
|
100 |
CActive( CActive::EPriorityStandard ),
|
|
101 |
iFs( aFs ),
|
|
102 |
iUtils( aUtils ),
|
|
103 |
iEngine( aEngine )
|
|
104 |
{
|
|
105 |
}
|
|
106 |
|
|
107 |
// ---------------------------------------------------------------------------
|
|
108 |
// CFileManagerRemovableDriveHandler::ConstructL
|
|
109 |
// ---------------------------------------------------------------------------
|
|
110 |
//
|
|
111 |
void CFileManagerRemovableDriveHandler::ConstructL()
|
|
112 |
{
|
|
113 |
CActiveScheduler::Add( this );
|
|
114 |
iBkupEngine = CMMCScBkupEngine::NewL( iFs );
|
|
115 |
PublishBurStatus( EFileManagerBkupStatusUnset );
|
|
116 |
}
|
|
117 |
|
|
118 |
// ---------------------------------------------------------------------------
|
|
119 |
// CFileManagerRemovableDriveHandler::NewL
|
|
120 |
// ---------------------------------------------------------------------------
|
|
121 |
//
|
|
122 |
CFileManagerRemovableDriveHandler* CFileManagerRemovableDriveHandler::NewL(
|
|
123 |
RFs& aFs,
|
|
124 |
CFileManagerUtils& aUtils,
|
|
125 |
CFileManagerEngine& aEngine )
|
|
126 |
{
|
|
127 |
CFileManagerRemovableDriveHandler* self =
|
|
128 |
new( ELeave ) CFileManagerRemovableDriveHandler(
|
|
129 |
aFs, aUtils, aEngine );
|
|
130 |
|
|
131 |
CleanupStack::PushL( self );
|
|
132 |
self->ConstructL();
|
|
133 |
CleanupStack::Pop( self );
|
|
134 |
|
|
135 |
return self;
|
|
136 |
}
|
|
137 |
|
|
138 |
// ---------------------------------------------------------------------------
|
|
139 |
// CFileManagerRemovableDriveHandler::~CFileManagerRemovableDriveHandler
|
|
140 |
// ---------------------------------------------------------------------------
|
|
141 |
//
|
|
142 |
CFileManagerRemovableDriveHandler::~CFileManagerRemovableDriveHandler()
|
|
143 |
{
|
|
144 |
Cancel();
|
|
145 |
delete iBSWrapper;
|
|
146 |
delete iEjectScanPeriodic;
|
|
147 |
delete iBkupEngine;
|
|
148 |
iFormatter.Close();
|
|
149 |
PublishBurStatus( EFileManagerBkupStatusUnset );
|
|
150 |
}
|
|
151 |
|
|
152 |
// ---------------------------------------------------------------------------
|
|
153 |
// CFileManagerRemovableDriveHandler::EjectScanAndShutdownApps
|
|
154 |
// ---------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
TInt CFileManagerRemovableDriveHandler::EjectScanAndShutdownApps( TAny* ptr )
|
|
157 |
{
|
|
158 |
CFileManagerRemovableDriveHandler* self =
|
|
159 |
static_cast< CFileManagerRemovableDriveHandler* >( ptr );
|
|
160 |
TRAPD( err, self->DoEjectScanAndShutdownL() );
|
|
161 |
if ( err != KErrNone )
|
|
162 |
{
|
|
163 |
self->EjectComplete( err );
|
|
164 |
}
|
|
165 |
return KErrNone;
|
|
166 |
}
|
|
167 |
|
|
168 |
// ---------------------------------------------------------------------------
|
|
169 |
// CFileManagerRemovableDriveHandler::DoEjectScanAndShutdownL
|
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
//
|
|
172 |
void CFileManagerRemovableDriveHandler::DoEjectScanAndShutdownL()
|
|
173 |
{
|
|
174 |
RWsSession wsSession;
|
|
175 |
User::LeaveIfError( wsSession.Connect() );
|
|
176 |
CleanupClosePushL( wsSession );
|
|
177 |
|
|
178 |
const TInt KDefaultWgIdArraySize = 4;
|
|
179 |
CArrayFixFlat<TInt>* wgIds = new( ELeave ) CArrayFixFlat< TInt >(
|
|
180 |
KDefaultWgIdArraySize );
|
|
181 |
CleanupStack::PushL( wgIds );
|
|
182 |
User::LeaveIfError( wsSession.WindowGroupList( 0, wgIds ) );
|
|
183 |
TInt last( wgIds->Count() - 1 );
|
|
184 |
TInt appsToShutDown( 0 );
|
|
185 |
|
|
186 |
for ( TInt i( last ); i >= 0; i-- )
|
|
187 |
{
|
|
188 |
CApaWindowGroupName* doomedApp =
|
|
189 |
CApaWindowGroupName::NewLC( wsSession, wgIds->At( i ) );
|
|
190 |
TBool systemApp( doomedApp->IsSystem() );
|
|
191 |
TBool hiddenApp( doomedApp->Hidden() );
|
|
192 |
|
|
193 |
if ( !systemApp && !hiddenApp && doomedApp->AppUid().iUid != KFileManagerAppUid )
|
|
194 |
{
|
|
195 |
appsToShutDown++;
|
|
196 |
TApaTask* task = new (ELeave) TApaTask( wsSession );
|
|
197 |
CleanupDeletePushL( task );
|
|
198 |
task->SetWgId( wgIds->At( i ) );
|
|
199 |
|
|
200 |
if ( !iEjectScanRounds )
|
|
201 |
{
|
|
202 |
// applications are kindly requested to close themselves
|
|
203 |
// on the first round
|
|
204 |
task->EndTask();
|
|
205 |
}
|
|
206 |
else if ( iEjectScanRounds >= KEjectScanRoundsMax )
|
|
207 |
{
|
|
208 |
task->KillTask();
|
|
209 |
}
|
|
210 |
CleanupStack::PopAndDestroy( task );
|
|
211 |
}
|
|
212 |
CleanupStack::PopAndDestroy( doomedApp );
|
|
213 |
}
|
|
214 |
CleanupStack::PopAndDestroy( wgIds );
|
|
215 |
|
|
216 |
if ( !appsToShutDown || iEjectScanRounds >= KEjectScanRoundsMax )
|
|
217 |
{
|
|
218 |
EjectComplete( KErrNone );
|
|
219 |
}
|
|
220 |
iEjectScanRounds++;
|
|
221 |
|
|
222 |
CleanupStack::PopAndDestroy( &wsSession );
|
|
223 |
}
|
|
224 |
|
|
225 |
// ---------------------------------------------------------------------------
|
|
226 |
// CFileManagerRemovableDriveHandler::EjectComplete
|
|
227 |
// ---------------------------------------------------------------------------
|
|
228 |
//
|
|
229 |
void CFileManagerRemovableDriveHandler::EjectComplete( TInt aErr )
|
|
230 |
{
|
|
231 |
delete iEjectScanPeriodic;
|
|
232 |
iEjectScanPeriodic = NULL;
|
|
233 |
iLastError = aErr;
|
|
234 |
|
|
235 |
TRAP_IGNORE( InformFinishL() );
|
|
236 |
|
|
237 |
RProperty::Set(
|
|
238 |
KPSUidCoreApplicationUIs,
|
|
239 |
KCoreAppUIsMmcRemovedWithoutEject,
|
|
240 |
ECoreAppUIsEjectCommandNotUsed );
|
|
241 |
}
|
|
242 |
|
|
243 |
// ---------------------------------------------------------------------------
|
|
244 |
// CFileManagerRemovableDriveHandler::InformStartL
|
|
245 |
// ---------------------------------------------------------------------------
|
|
246 |
//
|
|
247 |
void CFileManagerRemovableDriveHandler::InformStartL( TInt aTotalCount )
|
|
248 |
{
|
|
249 |
iLastError = KErrNone;
|
|
250 |
if ( iObserver )
|
|
251 |
{
|
|
252 |
iObserver->ProcessStartedL( iProcess, aTotalCount );
|
|
253 |
}
|
|
254 |
}
|
|
255 |
|
|
256 |
// ---------------------------------------------------------------------------
|
|
257 |
// CFileManagerRemovableDriveHandler::InformUpdateL
|
|
258 |
// ---------------------------------------------------------------------------
|
|
259 |
//
|
|
260 |
void CFileManagerRemovableDriveHandler::InformUpdateL( TInt aCount )
|
|
261 |
{
|
|
262 |
if ( iObserver )
|
|
263 |
{
|
|
264 |
iObserver->ProcessAdvanceL( aCount );
|
|
265 |
}
|
|
266 |
}
|
|
267 |
|
|
268 |
// ---------------------------------------------------------------------------
|
|
269 |
// CFileManagerRemovableDriveHandler::InformFinishL
|
|
270 |
// ---------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
void CFileManagerRemovableDriveHandler::InformFinishL()
|
|
273 |
{
|
|
274 |
iEngine.ClearDriveInfo();
|
|
275 |
PublishBurStatus( EFileManagerBkupStatusUnset );
|
|
276 |
iProcess = MFileManagerProcessObserver::ENoProcess;
|
|
277 |
if ( iObserver )
|
|
278 |
{
|
|
279 |
iObserver->ProcessFinishedL( iLastError, KNullDesC );
|
|
280 |
}
|
|
281 |
}
|
|
282 |
|
|
283 |
// ---------------------------------------------------------------------------
|
|
284 |
// CFileManagerRemovableDriveHandler::InformError
|
|
285 |
// ---------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
void CFileManagerRemovableDriveHandler::InformError( TInt aErr )
|
|
288 |
{
|
|
289 |
iLastError = aErr;
|
|
290 |
if ( iObserver )
|
|
291 |
{
|
|
292 |
iObserver->Error( aErr );
|
|
293 |
}
|
|
294 |
}
|
|
295 |
|
|
296 |
// ---------------------------------------------------------------------------
|
|
297 |
// CFileManagerRemovableDriveHandler::HandleBkupEngineEventL
|
|
298 |
// ---------------------------------------------------------------------------
|
|
299 |
//
|
|
300 |
TInt CFileManagerRemovableDriveHandler::HandleBkupEngineEventL(
|
|
301 |
MMMCScBkupEngineObserver::TEvent aEvent, TInt aAssociatedData )
|
|
302 |
{
|
|
303 |
TInt ret( KErrNone );
|
|
304 |
switch( aEvent )
|
|
305 |
{
|
|
306 |
case MMMCScBkupEngineObserver::ECommonOperationStarting:
|
|
307 |
{
|
|
308 |
iFinalValue = KMaxTInt;
|
|
309 |
InformStartL( KMaxTInt );
|
|
310 |
break;
|
|
311 |
}
|
|
312 |
case MMMCScBkupEngineObserver::ECommonSizeOfTaskUnderstood:
|
|
313 |
{
|
|
314 |
iFinalValue = aAssociatedData;
|
|
315 |
InformStartL( aAssociatedData );
|
|
316 |
break;
|
|
317 |
}
|
|
318 |
case MMMCScBkupEngineObserver::ECommonOperationPrepareEnded:
|
|
319 |
{
|
|
320 |
PublishBurStatus( EFileManagerBkupStatusUnset );
|
|
321 |
// In order to show finished dialog prior SysAp's note,
|
|
322 |
// inform observer already at prepare-ended state.
|
|
323 |
if( iProcess == MFileManagerProcessObserver::ERestoreProcess )
|
|
324 |
{
|
|
325 |
if ( iFinalValue )
|
|
326 |
{
|
|
327 |
InformUpdateL( iFinalValue );
|
|
328 |
}
|
|
329 |
InformFinishL();
|
|
330 |
}
|
|
331 |
break;
|
|
332 |
}
|
|
333 |
case MMMCScBkupEngineObserver::ECommonOperationEnded:
|
|
334 |
{
|
|
335 |
PublishBurStatus( EFileManagerBkupStatusUnset );
|
|
336 |
if( iProcess != MFileManagerProcessObserver::ERestoreProcess )
|
|
337 |
{
|
|
338 |
if ( iFinalValue )
|
|
339 |
{
|
|
340 |
InformUpdateL( iFinalValue );
|
|
341 |
}
|
|
342 |
InformFinishL();
|
|
343 |
}
|
|
344 |
break;
|
|
345 |
}
|
|
346 |
case MMMCScBkupEngineObserver::ECommonOperationError:
|
|
347 |
{
|
|
348 |
iLastError = aAssociatedData;
|
|
349 |
break;
|
|
350 |
}
|
|
351 |
case MMMCScBkupEngineObserver::ECommonProgress:
|
|
352 |
{
|
|
353 |
InformUpdateL( aAssociatedData );
|
|
354 |
break;
|
|
355 |
}
|
|
356 |
case MMMCScBkupEngineObserver::EBackupAnalysingData:
|
|
357 |
{
|
|
358 |
if ( iObserver &&
|
|
359 |
iProcess == MFileManagerProcessObserver::EBackupProcess )
|
|
360 |
{
|
|
361 |
ret = iObserver->NotifyL(
|
|
362 |
MFileManagerProcessObserver::ENotifyBackupMemoryLow,
|
|
363 |
aAssociatedData );
|
|
364 |
}
|
|
365 |
break;
|
|
366 |
}
|
|
367 |
default:
|
|
368 |
{
|
|
369 |
break;
|
|
370 |
}
|
|
371 |
}
|
|
372 |
return ret;
|
|
373 |
}
|
|
374 |
|
|
375 |
// ---------------------------------------------------------------------------
|
|
376 |
// CFileManagerRemovableDriveHandler::SetObserver
|
|
377 |
// ---------------------------------------------------------------------------
|
|
378 |
//
|
|
379 |
void CFileManagerRemovableDriveHandler::SetObserver(
|
|
380 |
MFileManagerProcessObserver* aObserver )
|
|
381 |
{
|
|
382 |
iObserver = aObserver;
|
|
383 |
}
|
|
384 |
|
|
385 |
// ---------------------------------------------------------------------------
|
|
386 |
// CFileManagerRemovableDriveHandler::BackupFileNameLC
|
|
387 |
// ---------------------------------------------------------------------------
|
|
388 |
//
|
|
389 |
HBufC* CFileManagerRemovableDriveHandler::BackupFileNameLC(
|
|
390 |
TBool aFullPath ) const
|
|
391 |
{
|
|
392 |
HBufC* file = CCoeEnv::Static()->AllocReadResourceLC(
|
|
393 |
R_TEXT_MMC_BACKUP_FILE );
|
|
394 |
if ( !aFullPath )
|
|
395 |
{
|
|
396 |
return file; // Get just name
|
|
397 |
}
|
|
398 |
// Get full path
|
|
399 |
#ifdef RD_MULTIPLE_DRIVE
|
|
400 |
TInt drive( 0 );
|
|
401 |
User::LeaveIfError( DriveInfo::GetDefaultDrive(
|
|
402 |
DriveInfo::EDefaultRemovableMassStorage, drive ) );
|
|
403 |
TDriveUnit driveUnit( drive );
|
|
404 |
#else // RD_MULTIPLE_DRIVE
|
|
405 |
TDriveUnit driveUnit( PathInfo::MemoryCardRootPath() );
|
|
406 |
#endif // RD_MULTIPLE_DRIVE
|
|
407 |
HBufC* fileAndPath = HBufC::NewLC( KMaxFileName );
|
|
408 |
TPtr ptr( fileAndPath->Des() );
|
|
409 |
TPtr filePtr( file->Des() );
|
|
410 |
ptr.Copy( driveUnit.Name() );
|
|
411 |
ptr.Append( filePtr );
|
|
412 |
CleanupStack::Pop( fileAndPath );
|
|
413 |
CleanupStack::PopAndDestroy( file );
|
|
414 |
CleanupStack::PushL( fileAndPath );
|
|
415 |
return fileAndPath;
|
|
416 |
}
|
|
417 |
|
|
418 |
// ---------------------------------------------------------------------------
|
|
419 |
// CFileManagerRemovableDriveHandler::StartFormatL()
|
|
420 |
// ---------------------------------------------------------------------------
|
|
421 |
//
|
|
422 |
void CFileManagerRemovableDriveHandler::StartFormatL(
|
|
423 |
const TInt aDrive )
|
|
424 |
{
|
|
425 |
TInt err( KErrNone );
|
|
426 |
|
|
427 |
iDrive = aDrive;
|
|
428 |
iProcess = MFileManagerProcessObserver::EFormatProcess;
|
|
429 |
iFinalValue = 0;
|
|
430 |
|
|
431 |
TRAP( err, InformStartL( 0 ) );
|
|
432 |
if ( err == KErrNone )
|
|
433 |
{
|
|
434 |
// Close apps and then start format
|
|
435 |
TRAP( err, CloseAppsL() );
|
|
436 |
}
|
|
437 |
if ( err != KErrNone )
|
|
438 |
{
|
|
439 |
EndFormatProcessL( err );
|
|
440 |
}
|
|
441 |
}
|
|
442 |
|
|
443 |
// ---------------------------------------------------------------------------
|
|
444 |
// CFileManagerRemovableDriveHandler::StartEjectL()
|
|
445 |
// ---------------------------------------------------------------------------
|
|
446 |
//
|
|
447 |
void CFileManagerRemovableDriveHandler::StartEjectL()
|
|
448 |
{
|
|
449 |
TRAPD( err, StartEjectScanL() );
|
|
450 |
if ( err != KErrNone )
|
|
451 |
{
|
|
452 |
iProcess = MFileManagerProcessObserver::ENoProcess;
|
|
453 |
User::Leave( err );
|
|
454 |
}
|
|
455 |
}
|
|
456 |
|
|
457 |
// ---------------------------------------------------------------------------
|
|
458 |
// CFileManagerRemovableDriveHandler::StartEjectScanL()
|
|
459 |
// ---------------------------------------------------------------------------
|
|
460 |
//
|
|
461 |
void CFileManagerRemovableDriveHandler::StartEjectScanL()
|
|
462 |
{
|
|
463 |
iProcess = MFileManagerProcessObserver::EEjectProcess;
|
|
464 |
InformStartL( 0 );
|
|
465 |
|
|
466 |
RProperty::Set(
|
|
467 |
KPSUidCoreApplicationUIs,
|
|
468 |
KCoreAppUIsMmcRemovedWithoutEject,
|
|
469 |
ECoreAppUIsEjectCommandUsed );
|
|
470 |
|
|
471 |
iEjectScanRounds = 0;
|
|
472 |
iEjectScanPeriodic = CPeriodic::NewL( CActive::EPriorityLow );
|
|
473 |
iEjectScanPeriodic->Start(
|
|
474 |
KEjectScanInterval,
|
|
475 |
KEjectScanInterval,
|
|
476 |
TCallBack( EjectScanAndShutdownApps, this ) );
|
|
477 |
}
|
|
478 |
|
|
479 |
// ---------------------------------------------------------------------------
|
|
480 |
// CFileManagerRemovableDriveHandler::CancelProcess()
|
|
481 |
// ---------------------------------------------------------------------------
|
|
482 |
//
|
|
483 |
void CFileManagerRemovableDriveHandler::CancelProcess()
|
|
484 |
{
|
|
485 |
switch( iProcess )
|
|
486 |
{
|
|
487 |
case MFileManagerProcessObserver::EFormatProcess:
|
|
488 |
{
|
|
489 |
Cancel();
|
|
490 |
break;
|
|
491 |
}
|
|
492 |
case MFileManagerProcessObserver::EBackupProcess: // FALLTHROUGH
|
|
493 |
case MFileManagerProcessObserver::ERestoreProcess:
|
|
494 |
case MFileManagerProcessObserver::ESchBackupProcess:
|
|
495 |
{
|
|
496 |
PublishBurStatus( EFileManagerBkupStatusUnset );
|
|
497 |
iBkupEngine->CancelOperation();
|
|
498 |
break;
|
|
499 |
}
|
|
500 |
default:
|
|
501 |
{
|
|
502 |
break;
|
|
503 |
}
|
|
504 |
}
|
|
505 |
}
|
|
506 |
|
|
507 |
// ---------------------------------------------------------------------------
|
|
508 |
// CFileManagerRemovableDriveHandler::BackupFileExistsL()
|
|
509 |
// ---------------------------------------------------------------------------
|
|
510 |
//
|
|
511 |
TBool CFileManagerRemovableDriveHandler::BackupFileExistsL(
|
|
512 |
const TInt /*aDrive*/ )
|
|
513 |
{
|
|
514 |
HBufC* backupFile = BackupFileNameLC( ETrue );
|
|
515 |
TBool ret( iBkupEngine->ValidArchiveForRestore( *backupFile ) );
|
|
516 |
CleanupStack::PopAndDestroy( backupFile );
|
|
517 |
return ret;
|
|
518 |
}
|
|
519 |
|
|
520 |
// ---------------------------------------------------------------------------
|
|
521 |
// CFileManagerRemovableDriveHandler::StartBackupL()
|
|
522 |
// ---------------------------------------------------------------------------
|
|
523 |
//
|
|
524 |
void CFileManagerRemovableDriveHandler::StartBackupL(
|
|
525 |
MFileManagerProcessObserver::TFileManagerProcess aProcess )
|
|
526 |
{
|
|
527 |
if ( aProcess != MFileManagerProcessObserver::EBackupProcess &&
|
|
528 |
aProcess != MFileManagerProcessObserver::ESchBackupProcess )
|
|
529 |
{
|
|
530 |
User::Leave( KErrNotSupported );
|
|
531 |
}
|
|
532 |
|
|
533 |
CCoeEnv* coeEnv = CCoeEnv::Static();
|
|
534 |
|
|
535 |
// Create backup params - ownership is transferred to
|
|
536 |
// secure backup engine
|
|
537 |
TResourceReader driveReader;
|
|
538 |
coeEnv->CreateResourceReaderLC(
|
|
539 |
driveReader,
|
|
540 |
R_FILEMANAGER_BACKUP_RESTORE_DRIVES_AND_OPERATIONS );
|
|
541 |
TResourceReader categoryReader;
|
|
542 |
coeEnv->CreateResourceReaderLC(
|
|
543 |
categoryReader,
|
|
544 |
R_FILEMANAGER_BACKUP_CATEGORIES );
|
|
545 |
|
|
546 |
#ifdef RD_FILE_MANAGER_BACKUP
|
|
547 |
|
|
548 |
CFileManagerBackupSettings& settings( iEngine.BackupSettingsL() );
|
|
549 |
TUint32 bkupContent( FmgrToBkupMask( settings.Content() ) );
|
|
550 |
TInt drive( settings.TargetDrive() );
|
|
551 |
|
|
552 |
CMMCScBkupOpParamsBackupFull* params =
|
|
553 |
CMMCScBkupOpParamsBackupFull::NewL(
|
|
554 |
driveReader,
|
|
555 |
categoryReader,
|
|
556 |
TDriveNumber( drive ),
|
|
557 |
bkupContent );
|
|
558 |
|
|
559 |
#else // RD_FILE_MANAGER_BACKUP
|
|
560 |
|
|
561 |
HBufC* backupFile = BackupFileNameLC( ETrue );
|
|
562 |
TInt drive = TDriveUnit( *backupFile );
|
|
563 |
CleanupStack::PopAndDestroy( backupFile );
|
|
564 |
|
|
565 |
CMMCScBkupOpParamsBackupFull* params =
|
|
566 |
CMMCScBkupOpParamsBackupFull::NewL( driveReader,
|
|
567 |
categoryReader,
|
|
568 |
TDriveNumber( drive ),
|
|
569 |
EBUCatAllInOne );
|
|
570 |
|
|
571 |
#endif // RD_FILE_MANAGER_BACKUP
|
|
572 |
|
|
573 |
CleanupStack::PopAndDestroy(); // categoryReader
|
|
574 |
CleanupStack::PopAndDestroy(); // driveReader
|
|
575 |
|
|
576 |
CleanupStack::PushL( params );
|
|
577 |
TBool diskFull( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, 0, drive ) );
|
|
578 |
CleanupStack::Pop( params );
|
|
579 |
|
|
580 |
if ( diskFull )
|
|
581 |
{
|
|
582 |
iProcess = aProcess;
|
|
583 |
TRAP_IGNORE( InformStartL( KMaxTInt ) );
|
|
584 |
iLastError = KErrDiskFull;
|
|
585 |
TRAP_IGNORE( InformFinishL() );
|
|
586 |
iProcess = MFileManagerProcessObserver::ENoProcess;
|
|
587 |
delete params;
|
|
588 |
}
|
|
589 |
else
|
|
590 |
{
|
|
591 |
// Start the process - engine owns the parameters immediately
|
|
592 |
iProcess = aProcess;
|
|
593 |
|
|
594 |
PublishBurStatus( EFileManagerBkupStatusBackup );
|
|
595 |
TRAPD( err, iBkupEngine->StartOperationL(
|
|
596 |
EMMCScBkupOperationTypeFullBackup, *this, params ) );
|
|
597 |
if ( err != KErrNone )
|
|
598 |
{
|
|
599 |
PublishBurStatus( EFileManagerBkupStatusUnset );
|
|
600 |
iProcess = MFileManagerProcessObserver::ENoProcess;
|
|
601 |
User::Leave( err );
|
|
602 |
}
|
|
603 |
}
|
|
604 |
}
|
|
605 |
|
|
606 |
// ---------------------------------------------------------------------------
|
|
607 |
// CFileManagerRemovableDriveHandler::StartRestoreL()
|
|
608 |
// ---------------------------------------------------------------------------
|
|
609 |
//
|
|
610 |
void CFileManagerRemovableDriveHandler::StartRestoreL()
|
|
611 |
{
|
|
612 |
TBool diskFull( SysUtil::DiskSpaceBelowCriticalLevelL(
|
|
613 |
&iFs, 0, KFmgrSystemDrive ) );
|
|
614 |
if ( diskFull )
|
|
615 |
{
|
|
616 |
iProcess = MFileManagerProcessObserver::ERestoreProcess;
|
|
617 |
TRAP_IGNORE( InformStartL( KMaxTInt ) );
|
|
618 |
iLastError = KErrDiskFull;
|
|
619 |
TRAP_IGNORE( InformFinishL() );
|
|
620 |
iProcess = MFileManagerProcessObserver::ENoProcess;
|
|
621 |
return;
|
|
622 |
}
|
|
623 |
|
|
624 |
CFileManagerBackupSettings& bkupSettings( iEngine.BackupSettingsL() );
|
|
625 |
|
|
626 |
// Create restore params - ownership is transferred to
|
|
627 |
// secure backup engine
|
|
628 |
TResourceReader driveReader;
|
|
629 |
CCoeEnv::Static()->CreateResourceReaderLC(
|
|
630 |
driveReader,
|
|
631 |
R_FILEMANAGER_BACKUP_RESTORE_DRIVES_AND_OPERATIONS );
|
|
632 |
|
|
633 |
#ifdef RD_FILE_MANAGER_BACKUP
|
|
634 |
|
|
635 |
CMMCScBkupOpParamsRestoreFull* params =
|
|
636 |
CMMCScBkupOpParamsRestoreFull::NewL(
|
|
637 |
driveReader,
|
|
638 |
EBUCatAllSeparately );
|
|
639 |
CleanupStack::PopAndDestroy(); // driveReader
|
|
640 |
CleanupStack::PushL( params );
|
|
641 |
|
|
642 |
// Get list of all archives
|
|
643 |
RPointerArray< CMMCScBkupArchiveInfo > archives;
|
|
644 |
TCleanupItem cleanupItem( ResetAndDestroyArchives, &archives );
|
|
645 |
CleanupStack::PushL( cleanupItem );
|
|
646 |
iBkupEngine->ListArchivesL(
|
|
647 |
archives,
|
|
648 |
params,
|
|
649 |
bkupSettings.AllowedDriveAttMatchMask() );
|
|
650 |
|
|
651 |
// Get user set restore selection
|
|
652 |
RArray< CFileManagerRestoreSettings::TInfo > selection;
|
|
653 |
CleanupClosePushL( selection );
|
|
654 |
CFileManagerRestoreSettings& rstSettings( iEngine.RestoreSettingsL() );
|
|
655 |
rstSettings.GetSelectionL( selection );
|
|
656 |
|
|
657 |
// Remove non user selected archives
|
|
658 |
TInt i( 0 );
|
|
659 |
while ( i < archives.Count() )
|
|
660 |
{
|
|
661 |
TBool remove( ETrue );
|
|
662 |
|
|
663 |
// Compare archives category and drive
|
|
664 |
CMMCScBkupArchiveInfo* archiveInfo = archives[ i ];
|
|
665 |
TUint32 fmgrContent(
|
|
666 |
BkupToFmgrMask( archiveInfo->Category().iFlags ) );
|
|
667 |
TInt drive( archiveInfo->Drive() );
|
|
668 |
|
|
669 |
TInt count( selection.Count() );
|
|
670 |
for( TInt j( 0 ); j < count; ++j )
|
|
671 |
{
|
|
672 |
const CFileManagerRestoreSettings::TInfo& info( selection[ j ] );
|
|
673 |
if ( ( drive == info.iDrive ) && ( fmgrContent & info.iContent ) )
|
|
674 |
{
|
|
675 |
// Found user selected archive
|
|
676 |
// Do not check this archive again
|
|
677 |
selection.Remove( j );
|
|
678 |
remove = EFalse;
|
|
679 |
break;
|
|
680 |
}
|
|
681 |
}
|
|
682 |
if ( remove )
|
|
683 |
{
|
|
684 |
// Remove non selected archive
|
|
685 |
archives.Remove( i );
|
|
686 |
delete archiveInfo;
|
|
687 |
}
|
|
688 |
else
|
|
689 |
{
|
|
690 |
// Move to next archive
|
|
691 |
++i;
|
|
692 |
}
|
|
693 |
}
|
|
694 |
|
|
695 |
CleanupStack::PopAndDestroy( &selection );
|
|
696 |
params->SetArchiveInfosL( archives );
|
|
697 |
CleanupStack::Pop( &archives );
|
|
698 |
archives.Close();
|
|
699 |
CleanupStack::Pop( params );
|
|
700 |
|
|
701 |
#else // RD_FILE_MANAGER_BACKUP
|
|
702 |
|
|
703 |
CMMCScBkupOpParamsRestoreFull* params =
|
|
704 |
CMMCScBkupOpParamsRestoreFull::NewL( driveReader, EBUCatAllInOne );
|
|
705 |
CleanupStack::PopAndDestroy(); // driveReader
|
|
706 |
|
|
707 |
// Get list of all archives
|
|
708 |
RPointerArray< CMMCScBkupArchiveInfo > archives;
|
|
709 |
TCleanupItem cleanupItem( ResetAndDestroyArchives, &archives );
|
|
710 |
CleanupStack::PushL( cleanupItem );
|
|
711 |
iBkupEngine->ListArchivesL(
|
|
712 |
archives,
|
|
713 |
params,
|
|
714 |
bkupSettings.AllowedDriveAttMatchMask() );
|
|
715 |
params->SetArchiveInfosL( archives );
|
|
716 |
CleanupStack::Pop( &archives );
|
|
717 |
|
|
718 |
#endif // RD_FILE_MANAGER_BACKUP
|
|
719 |
|
|
720 |
// Start the process - engine owns the parameters immediately
|
|
721 |
iProcess = MFileManagerProcessObserver::ERestoreProcess;
|
|
722 |
PublishBurStatus( EFileManagerBkupStatusRestore );
|
|
723 |
TRAPD( err, iBkupEngine->StartOperationL(
|
|
724 |
EMMCScBkupOperationTypeFullRestore, *this, params ) );
|
|
725 |
if ( err != KErrNone )
|
|
726 |
{
|
|
727 |
PublishBurStatus( EFileManagerBkupStatusUnset );
|
|
728 |
iProcess = MFileManagerProcessObserver::ENoProcess;
|
|
729 |
User::Leave( err );
|
|
730 |
}
|
|
731 |
}
|
|
732 |
|
|
733 |
// ---------------------------------------------------------------------------
|
|
734 |
// CFileManagerRemovableDriveHandler::GetRestoreInfoArrayL
|
|
735 |
// ---------------------------------------------------------------------------
|
|
736 |
//
|
|
737 |
void CFileManagerRemovableDriveHandler::GetRestoreInfoArrayL(
|
|
738 |
RArray< CFileManagerRestoreSettings::TInfo >& aArray,
|
|
739 |
const TInt aDrive )
|
|
740 |
{
|
|
741 |
|
|
742 |
CleanupClosePushL( aArray );
|
|
743 |
|
|
744 |
CFileManagerBackupSettings& settings( iEngine.BackupSettingsL() );
|
|
745 |
aArray.Reset();
|
|
746 |
|
|
747 |
TResourceReader driveReader;
|
|
748 |
CCoeEnv::Static()->CreateResourceReaderLC(
|
|
749 |
driveReader,
|
|
750 |
R_FILEMANAGER_BACKUP_RESTORE_DRIVES_AND_OPERATIONS );
|
|
751 |
|
|
752 |
CMMCScBkupOpParamsRestoreFull* params =
|
|
753 |
CMMCScBkupOpParamsRestoreFull::NewL(
|
|
754 |
driveReader, EBUCatAllSeparately );
|
|
755 |
CleanupStack::PopAndDestroy(); // driveReader
|
|
756 |
CleanupStack::PushL( params );
|
|
757 |
|
|
758 |
// Get list of all archives
|
|
759 |
RPointerArray< CMMCScBkupArchiveInfo > archives;
|
|
760 |
TCleanupItem cleanupItem( ResetAndDestroyArchives, &archives );
|
|
761 |
CleanupStack::PushL( cleanupItem );
|
|
762 |
iBkupEngine->ListArchivesL(
|
|
763 |
archives,
|
|
764 |
params,
|
|
765 |
settings.AllowedDriveAttMatchMask(),
|
|
766 |
aDrive );
|
|
767 |
|
|
768 |
// Prepare time zone conversion
|
|
769 |
RTz tz;
|
|
770 |
User::LeaveIfError( tz.Connect() );
|
|
771 |
CleanupClosePushL( tz );
|
|
772 |
|
|
773 |
// Fill restore info
|
|
774 |
CFileManagerRestoreSettings::TInfo info;
|
|
775 |
TInt count( archives.Count() );
|
|
776 |
aArray.ReserveL( count );
|
|
777 |
|
|
778 |
for( TInt i( 0 ); i < count; ++i )
|
|
779 |
{
|
|
780 |
// Content
|
|
781 |
CMMCScBkupArchiveInfo& archiveInfo( *archives[ i ] );
|
|
782 |
info.iContent = BkupToFmgrMask( archiveInfo.Category().iFlags );
|
|
783 |
|
|
784 |
// Local time
|
|
785 |
info.iTime = archiveInfo.DateTime();
|
|
786 |
User::LeaveIfError( tz.ConvertToLocalTime( info.iTime ) );
|
|
787 |
|
|
788 |
// Drive
|
|
789 |
info.iDrive = archiveInfo.Drive();
|
|
790 |
|
|
791 |
aArray.AppendL( info );
|
|
792 |
}
|
|
793 |
|
|
794 |
CleanupStack::PopAndDestroy( &tz );
|
|
795 |
CleanupStack::PopAndDestroy( &archives );
|
|
796 |
CleanupStack::PopAndDestroy( params );
|
|
797 |
CleanupStack::Pop( &aArray ) ;
|
|
798 |
|
|
799 |
}
|
|
800 |
|
|
801 |
// ---------------------------------------------------------------------------
|
|
802 |
// CFileManagerRemovableDriveHandler::DoCancel
|
|
803 |
// ---------------------------------------------------------------------------
|
|
804 |
//
|
|
805 |
void CFileManagerRemovableDriveHandler::DoCancel()
|
|
806 |
{
|
|
807 |
switch( iProcess )
|
|
808 |
{
|
|
809 |
case MFileManagerProcessObserver::EFormatProcess:
|
|
810 |
{
|
|
811 |
TRAP_IGNORE( EndFormatProcessL( KErrCancel ) );
|
|
812 |
break;
|
|
813 |
}
|
|
814 |
default:
|
|
815 |
{
|
|
816 |
break;
|
|
817 |
}
|
|
818 |
}
|
|
819 |
}
|
|
820 |
|
|
821 |
// ---------------------------------------------------------------------------
|
|
822 |
// CFileManagerRemovableDriveHandler::RunL
|
|
823 |
// ---------------------------------------------------------------------------
|
|
824 |
//
|
|
825 |
void CFileManagerRemovableDriveHandler::RunL()
|
|
826 |
{
|
|
827 |
TInt err( iStatus.Int() );
|
|
828 |
switch( iProcess )
|
|
829 |
{
|
|
830 |
case MFileManagerProcessObserver::EFormatProcess:
|
|
831 |
{
|
|
832 |
if( err != KErrNone )
|
|
833 |
{
|
|
834 |
if ( !iFinalValue && err == KErrInUse )
|
|
835 |
{
|
|
836 |
// Some app remained open, try still to start format
|
|
837 |
StartFormatProcessL();
|
|
838 |
}
|
|
839 |
else
|
|
840 |
{
|
|
841 |
// Format failed
|
|
842 |
EndFormatProcessL( err );
|
|
843 |
}
|
|
844 |
}
|
|
845 |
else if( !iFinalValue )
|
|
846 |
{
|
|
847 |
// Apps have been closed. Start format.
|
|
848 |
StartFormatProcessL();
|
|
849 |
}
|
|
850 |
else if( iFormatCountBuf() > 0 )
|
|
851 |
{
|
|
852 |
// Update observer and format next track
|
|
853 |
InformUpdateL( iFinalValue - iFormatCountBuf() );
|
|
854 |
iFormatter.Next( iFormatCountBuf, iStatus );
|
|
855 |
SetActive( );
|
|
856 |
}
|
|
857 |
else
|
|
858 |
{
|
|
859 |
// Format complete
|
|
860 |
EndFormatProcessL( KErrNone );
|
|
861 |
}
|
|
862 |
break;
|
|
863 |
}
|
|
864 |
default:
|
|
865 |
{
|
|
866 |
break;
|
|
867 |
}
|
|
868 |
}
|
|
869 |
}
|
|
870 |
|
|
871 |
// ---------------------------------------------------------------------------
|
|
872 |
// CFileManagerRemovableDriveHandler::RunError
|
|
873 |
// ---------------------------------------------------------------------------
|
|
874 |
//
|
|
875 |
TInt CFileManagerRemovableDriveHandler::RunError( TInt aError )
|
|
876 |
{
|
|
877 |
switch( iProcess )
|
|
878 |
{
|
|
879 |
case MFileManagerProcessObserver::EFormatProcess:
|
|
880 |
{
|
|
881 |
TRAP_IGNORE( EndFormatProcessL( aError ) );
|
|
882 |
break;
|
|
883 |
}
|
|
884 |
default:
|
|
885 |
{
|
|
886 |
break;
|
|
887 |
}
|
|
888 |
}
|
|
889 |
return KErrNone;
|
|
890 |
}
|
|
891 |
|
|
892 |
// ---------------------------------------------------------------------------
|
|
893 |
// CFileManagerRemovableDriveHandler::EndFormatProcessL
|
|
894 |
// ---------------------------------------------------------------------------
|
|
895 |
//
|
|
896 |
void CFileManagerRemovableDriveHandler::EndFormatProcessL( TInt aErr )
|
|
897 |
{
|
|
898 |
iFormatter.Close();
|
|
899 |
iLastError = aErr;
|
|
900 |
if( aErr == KErrNone )
|
|
901 |
{
|
|
902 |
// Restore the volume name stored before format operation.
|
|
903 |
TRAPD( err, RestoreVolumeNameL( iDrive ) );
|
|
904 |
LOG_IF_ERROR1( err,
|
|
905 |
"FileManagerRemovableDriveHandler::EndFormatProcessL-RestoreVolumeName %d",
|
|
906 |
err );
|
|
907 |
iUtils.CreateDefaultFolders( iDrive );
|
|
908 |
}
|
|
909 |
else if ( aErr != KErrCancel )
|
|
910 |
{
|
|
911 |
InformError( aErr );
|
|
912 |
}
|
|
913 |
TRAPD( err, RestartAppsL() );
|
|
914 |
LOG_IF_ERROR1( err,
|
|
915 |
"FileManagerRemovableDriveHandler::EndFormatProcessL-Restart apps %d",
|
|
916 |
err );
|
|
917 |
InformFinishL();
|
|
918 |
|
|
919 |
}
|
|
920 |
|
|
921 |
// ---------------------------------------------------------------------------
|
|
922 |
// CFileManagerRemovableDriveHandler::StartFormatProcessL
|
|
923 |
// ---------------------------------------------------------------------------
|
|
924 |
//
|
|
925 |
void CFileManagerRemovableDriveHandler::StartFormatProcessL()
|
|
926 |
{
|
|
927 |
// Store the current volume name over format operation.
|
|
928 |
TRAPD( err, StoreVolumeNameL( iDrive ) );
|
|
929 |
LOG_IF_ERROR1(
|
|
930 |
err,
|
|
931 |
"FileManagerRemovableDriveHandler::StartFormatProcessL-StoreVolumeName %d",
|
|
932 |
err );
|
|
933 |
TDriveName driveName( TDriveUnit( iDrive ).Name() );
|
|
934 |
// Resolve drive character and open formatter
|
|
935 |
iFormatter.Close();
|
|
936 |
err = iFormatter.Open(
|
|
937 |
iFs, driveName, EFullFormat, iFinalValue );
|
|
938 |
// Forced format for locked card
|
|
939 |
if ( err == KErrLocked )
|
|
940 |
{
|
|
941 |
// Erase password and try again
|
|
942 |
err = iFs.ErasePassword( iDrive );
|
|
943 |
if (err == KErrNone)
|
|
944 |
{
|
|
945 |
err = iFormatter.Open(iFs, driveName, EFullFormat , iFinalValue );
|
|
946 |
}
|
|
947 |
}
|
|
948 |
if (err == KErrInUse)
|
|
949 |
{
|
|
950 |
TBool reallyFormat = ETrue;
|
|
951 |
if (reallyFormat)
|
|
952 |
{
|
|
953 |
err = iFormatter.Open(
|
|
954 |
iFs, driveName, EFullFormat | EForceFormat, iFinalValue );
|
|
955 |
}
|
|
956 |
}
|
|
957 |
TFullName fsName;
|
|
958 |
if (err == KErrNone)
|
|
959 |
{
|
|
960 |
err = iFs.FileSystemName( fsName, iDrive );
|
|
961 |
|
|
962 |
if ( err == KErrNone && fsName.Length() > 0 )
|
|
963 |
{
|
|
964 |
// Prevent SysAp shutting down applications
|
|
965 |
RProperty::Set(
|
|
966 |
KPSUidCoreApplicationUIs,
|
|
967 |
KCoreAppUIsMmcRemovedWithoutEject,
|
|
968 |
ECoreAppUIsEjectCommandUsed );
|
|
969 |
}
|
|
970 |
else
|
|
971 |
{
|
|
972 |
// Don't continue with format if there is no file system name
|
|
973 |
// or file system name could not be obtained.
|
|
974 |
err = KErrCancel;
|
|
975 |
}
|
|
976 |
}
|
|
977 |
|
|
978 |
// On successful open of RFormat::Open(), iFinalValue contains the number of
|
|
979 |
// tracks to be formatted
|
|
980 |
|
|
981 |
if ( iFinalValue && err == KErrNone )
|
|
982 |
{
|
|
983 |
TRAP( err, InformStartL( iFinalValue ) );
|
|
984 |
if ( err == KErrNone )
|
|
985 |
{
|
|
986 |
iFormatCountBuf = iFinalValue;
|
|
987 |
iFormatter.Next( iFormatCountBuf, iStatus );
|
|
988 |
SetActive();
|
|
989 |
}
|
|
990 |
}
|
|
991 |
if ( !iFinalValue || err != KErrNone )
|
|
992 |
{
|
|
993 |
EndFormatProcessL( err );
|
|
994 |
}
|
|
995 |
}
|
|
996 |
// ---------------------------------------------------------------------------
|
|
997 |
// CFileManagerRemovableDriveHandler::CloseAppsL
|
|
998 |
// ---------------------------------------------------------------------------
|
|
999 |
//
|
|
1000 |
void CFileManagerRemovableDriveHandler::CloseAppsL()
|
|
1001 |
{
|
|
1002 |
delete iBSWrapper;
|
|
1003 |
iBSWrapper = NULL;
|
|
1004 |
|
|
1005 |
iBSWrapper = CBaBackupSessionWrapper::NewL();
|
|
1006 |
|
|
1007 |
TBackupOperationAttributes atts(
|
|
1008 |
MBackupObserver::EReleaseLockNoAccess,
|
|
1009 |
MBackupOperationObserver::EStart );
|
|
1010 |
iBSWrapper->NotifyBackupOperationL( atts );
|
|
1011 |
iBSWrapper->CloseAll( MBackupObserver::EReleaseLockNoAccess, iStatus );
|
|
1012 |
SetActive();
|
|
1013 |
|
|
1014 |
// Memory card formatting cannot be executed if there are open files on it.
|
|
1015 |
// It has been detected, that in some cases memory card using applications
|
|
1016 |
// have no time to close file handles before formatting is tried to be executed.
|
|
1017 |
// To address this issue, we need to add a delay here after client-notification
|
|
1018 |
// about pending format and real formatting procedure.
|
|
1019 |
User::After( KAppCloseTimeout );
|
|
1020 |
}
|
|
1021 |
|
|
1022 |
// ---------------------------------------------------------------------------
|
|
1023 |
// CFileManagerRemovableDriveHandler::RestartAppsL
|
|
1024 |
// ---------------------------------------------------------------------------
|
|
1025 |
//
|
|
1026 |
void CFileManagerRemovableDriveHandler::RestartAppsL()
|
|
1027 |
{
|
|
1028 |
if ( !iBSWrapper )
|
|
1029 |
{
|
|
1030 |
return;
|
|
1031 |
}
|
|
1032 |
|
|
1033 |
TBackupOperationAttributes atts(
|
|
1034 |
MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd );
|
|
1035 |
iBSWrapper->NotifyBackupOperationL( atts );
|
|
1036 |
iBSWrapper->RestartAll();
|
|
1037 |
|
|
1038 |
// Get rid of the wrapper instance
|
|
1039 |
delete iBSWrapper;
|
|
1040 |
iBSWrapper = NULL;
|
|
1041 |
}
|
|
1042 |
|
|
1043 |
// ---------------------------------------------------------------------------
|
|
1044 |
// CFileManagerRemovableDriveHandler::ResetAndDestroyArchives
|
|
1045 |
// ---------------------------------------------------------------------------
|
|
1046 |
//
|
|
1047 |
void CFileManagerRemovableDriveHandler::ResetAndDestroyArchives( TAny* aPtr )
|
|
1048 |
{
|
|
1049 |
RPointerArray< CMMCScBkupArchiveInfo >* archive =
|
|
1050 |
static_cast< RPointerArray< CMMCScBkupArchiveInfo >* >( aPtr );
|
|
1051 |
archive->ResetAndDestroy();
|
|
1052 |
archive->Close();
|
|
1053 |
}
|
|
1054 |
|
|
1055 |
// ---------------------------------------------------------------------------
|
|
1056 |
// CFileManagerRemovableDriveHandler::BkupToFmgrMask
|
|
1057 |
// ---------------------------------------------------------------------------
|
|
1058 |
//
|
|
1059 |
TUint32 CFileManagerRemovableDriveHandler::BkupToFmgrMask(
|
|
1060 |
const TUint32 aBkupMask )
|
|
1061 |
{
|
|
1062 |
TUint32 ret( 0 );
|
|
1063 |
|
|
1064 |
for( TInt i( 0 ); i < KMaskLookupLen; ++i )
|
|
1065 |
{
|
|
1066 |
if ( aBkupMask & KMaskLookup[ i ].iBkupMask )
|
|
1067 |
{
|
|
1068 |
ret |= KMaskLookup[ i ].iFmgrMask;
|
|
1069 |
}
|
|
1070 |
}
|
|
1071 |
return ret;
|
|
1072 |
}
|
|
1073 |
|
|
1074 |
#ifdef RD_FILE_MANAGER_BACKUP
|
|
1075 |
// ---------------------------------------------------------------------------
|
|
1076 |
// CFileManagerRemovableDriveHandler::FmgrToBkupMask
|
|
1077 |
// ---------------------------------------------------------------------------
|
|
1078 |
//
|
|
1079 |
TUint32 CFileManagerRemovableDriveHandler::FmgrToBkupMask(
|
|
1080 |
const TUint32 aFmrgMask )
|
|
1081 |
{
|
|
1082 |
TUint32 ret( 0 );
|
|
1083 |
|
|
1084 |
for( TInt i( 0 ); i < KMaskLookupLen; ++i )
|
|
1085 |
{
|
|
1086 |
if ( ( aFmrgMask & EFileManagerBackupContentAll ) ||
|
|
1087 |
( aFmrgMask & KMaskLookup[ i ].iFmgrMask ) )
|
|
1088 |
{
|
|
1089 |
ret |= KMaskLookup[ i ].iBkupMask;
|
|
1090 |
}
|
|
1091 |
}
|
|
1092 |
return ret;
|
|
1093 |
}
|
|
1094 |
#endif // RD_FILE_MANAGER_BACKUP
|
|
1095 |
|
|
1096 |
// ---------------------------------------------------------------------------
|
|
1097 |
// CFileManagerRemovableDriveHandler::IsProcessOngoing
|
|
1098 |
// ---------------------------------------------------------------------------
|
|
1099 |
//
|
|
1100 |
TBool CFileManagerRemovableDriveHandler::IsProcessOngoing() const
|
|
1101 |
{
|
|
1102 |
return iProcess != MFileManagerProcessObserver::ENoProcess;
|
|
1103 |
}
|
|
1104 |
|
|
1105 |
// -----------------------------------------------------------------------------
|
|
1106 |
// CFileManagerEngine::PublishBurStatus()
|
|
1107 |
//
|
|
1108 |
// -----------------------------------------------------------------------------
|
|
1109 |
//
|
|
1110 |
void CFileManagerRemovableDriveHandler::PublishBurStatus( TInt aType )
|
|
1111 |
{
|
|
1112 |
_LIT_SECURITY_POLICY_S0( KFileManagerBkupWritePolicy, KFileManagerUID3 );
|
|
1113 |
_LIT_SECURITY_POLICY_PASS( KFileManagerBkupReadPolicy );
|
|
1114 |
|
|
1115 |
TInt err( RProperty::Set(
|
|
1116 |
KPSUidFileManagerStatus, KFileManagerBkupStatus, aType ) );
|
|
1117 |
if ( err != KErrNone )
|
|
1118 |
{
|
|
1119 |
err = RProperty::Define(
|
|
1120 |
KPSUidFileManagerStatus, KFileManagerBkupStatus,
|
|
1121 |
RProperty::EInt, KFileManagerBkupReadPolicy,
|
|
1122 |
KFileManagerBkupWritePolicy );
|
|
1123 |
if ( err == KErrNone || err == KErrAlreadyExists )
|
|
1124 |
{
|
|
1125 |
err = RProperty::Set(
|
|
1126 |
KPSUidFileManagerStatus, KFileManagerBkupStatus, aType );
|
|
1127 |
}
|
|
1128 |
}
|
|
1129 |
LOG_IF_ERROR1(
|
|
1130 |
err, "FileManagerRemovableDriveHandler::PublishBurStatus-err=%d", err )
|
|
1131 |
}
|
|
1132 |
|
|
1133 |
// -----------------------------------------------------------------------------
|
|
1134 |
// CFileManagerEngine::IsMassStorageDrive()
|
|
1135 |
//
|
|
1136 |
// -----------------------------------------------------------------------------
|
|
1137 |
//
|
|
1138 |
#ifdef RD_MULTIPLE_DRIVE
|
|
1139 |
|
|
1140 |
TBool CFileManagerRemovableDriveHandler::IsInternalMassStorage( TInt aDrive )
|
|
1141 |
{
|
|
1142 |
FUNC_LOG;
|
|
1143 |
|
|
1144 |
TBool ret( EFalse );
|
|
1145 |
TUint driveStatus( 0 );
|
|
1146 |
DriveInfo::GetDriveStatus( iFs, aDrive, driveStatus );
|
|
1147 |
if ( ( driveStatus & DriveInfo::EDriveInternal ) &&
|
|
1148 |
( driveStatus & DriveInfo::EDriveExternallyMountable ) )
|
|
1149 |
{
|
|
1150 |
ret = ETrue;
|
|
1151 |
}
|
|
1152 |
INFO_LOG2(
|
|
1153 |
"FileManagerRemovableDriveHandler::IsInternalMassStorage-drive=%d,ret=%d",
|
|
1154 |
aDrive, ret );
|
|
1155 |
return ret;
|
|
1156 |
}
|
|
1157 |
|
|
1158 |
#else // RD_MULTIPLE_DRIVE
|
|
1159 |
|
|
1160 |
TBool CFileManagerRemovableDriveHandler::IsInternalMassStorage( TInt /*aDrive*/ )
|
|
1161 |
{
|
|
1162 |
FUNC_LOG;
|
|
1163 |
|
|
1164 |
TInt ret( EFalse );
|
|
1165 |
return ret;
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
#endif // RD_MULTIPLE_DRIVE
|
|
1169 |
|
|
1170 |
// -----------------------------------------------------------------------------
|
|
1171 |
// CFileManagerEngine::StoreVolumeNameL()
|
|
1172 |
//
|
|
1173 |
// -----------------------------------------------------------------------------
|
|
1174 |
//
|
|
1175 |
void CFileManagerRemovableDriveHandler::StoreVolumeNameL( TInt aDrive )
|
|
1176 |
{
|
|
1177 |
FUNC_LOG;
|
|
1178 |
|
|
1179 |
if ( IsInternalMassStorage( aDrive ) )
|
|
1180 |
{
|
|
1181 |
TVolumeInfo volumeInfo;
|
|
1182 |
User::LeaveIfError( iFs.Volume( volumeInfo, aDrive ) );
|
|
1183 |
CRepository* cenRep = CRepository::NewLC( KCRUidFileManagerSettings );
|
|
1184 |
TFileManagerVolumeNameStore volumeStore;
|
|
1185 |
TFileManagerVolumeNameStorePckg volumeStorePckg( volumeStore );
|
|
1186 |
volumeStore.iDrive = aDrive;
|
|
1187 |
volumeStore.iName.Copy( volumeInfo.iName );
|
|
1188 |
User::LeaveIfError( cenRep->Set(
|
|
1189 |
KFileManagerStoredInternalMassStorageVolumeName, volumeStorePckg ) );
|
|
1190 |
CleanupStack::PopAndDestroy( cenRep );
|
|
1191 |
INFO_LOG2(
|
|
1192 |
"FileManagerRemovableDriveHandler::StoreVolumeNameL-drive=%d,name=%S",
|
|
1193 |
aDrive, &volumeStore.iName );
|
|
1194 |
}
|
|
1195 |
}
|
|
1196 |
|
|
1197 |
// -----------------------------------------------------------------------------
|
|
1198 |
// CFileManagerEngine::RestoreVolumeNameL()
|
|
1199 |
//
|
|
1200 |
// -----------------------------------------------------------------------------
|
|
1201 |
//
|
|
1202 |
void CFileManagerRemovableDriveHandler::RestoreVolumeNameL( TInt aDrive )
|
|
1203 |
{
|
|
1204 |
FUNC_LOG;
|
|
1205 |
|
|
1206 |
if ( IsInternalMassStorage( aDrive ) )
|
|
1207 |
{
|
|
1208 |
TFileName volumeName;
|
|
1209 |
CRepository* cenRep = CRepository::NewLC( KCRUidFileManagerSettings );
|
|
1210 |
TFileManagerVolumeNameStore volumeStore;
|
|
1211 |
TFileManagerVolumeNameStorePckg volumeStorePckg( volumeStore );
|
|
1212 |
TInt err( cenRep->Get(
|
|
1213 |
KFileManagerStoredInternalMassStorageVolumeName, volumeStorePckg ) );
|
|
1214 |
if ( err == KErrNone && volumeStore.iDrive == aDrive )
|
|
1215 |
{
|
|
1216 |
volumeName.Copy( volumeStore.iName );
|
|
1217 |
}
|
|
1218 |
if ( !volumeName.Length() )
|
|
1219 |
{
|
|
1220 |
User::LeaveIfError( cenRep->Get(
|
|
1221 |
KFileManagerDefaultInternalMassStorageVolumeName, volumeName ) );
|
|
1222 |
}
|
|
1223 |
if ( volumeName.Length() > 0 )
|
|
1224 |
{
|
|
1225 |
User::LeaveIfError( iFs.SetVolumeLabel( volumeName, aDrive ) );
|
|
1226 |
}
|
|
1227 |
CleanupStack::PopAndDestroy( cenRep );
|
|
1228 |
INFO_LOG2(
|
|
1229 |
"FileManagerRemovableDriveHandler::RestoreVolumeNameL-drive=%d,name=%S",
|
|
1230 |
aDrive, &volumeName );
|
|
1231 |
}
|
|
1232 |
}
|
|
1233 |
|
|
1234 |
// ---------------------------------------------------------------------------
|
|
1235 |
// CFileManagerRemovableDriveHandler::ListArchivesL
|
|
1236 |
// ---------------------------------------------------------------------------
|
|
1237 |
//
|
|
1238 |
void CFileManagerRemovableDriveHandler::ListArchivesL(
|
|
1239 |
RPointerArray< CMMCScBkupArchiveInfo >& aArchives,
|
|
1240 |
const CFileManagerBackupSettings& aBackupSettings )
|
|
1241 |
{
|
|
1242 |
aArchives.ResetAndDestroy();
|
|
1243 |
TResourceReader driveReader;
|
|
1244 |
CCoeEnv::Static()->CreateResourceReaderLC(
|
|
1245 |
driveReader,
|
|
1246 |
R_FILEMANAGER_BACKUP_RESTORE_DRIVES_AND_OPERATIONS );
|
|
1247 |
CMMCScBkupOpParamsRestoreFull* params =
|
|
1248 |
CMMCScBkupOpParamsRestoreFull::NewL(
|
|
1249 |
driveReader, EBUCatAllSeparately );
|
|
1250 |
CleanupStack::PopAndDestroy(); // driveReader
|
|
1251 |
CleanupStack::PushL( params );
|
|
1252 |
iBkupEngine->ListArchivesL(
|
|
1253 |
aArchives, params, aBackupSettings.AllowedDriveAttMatchMask() );
|
|
1254 |
CleanupStack::PopAndDestroy( params );
|
|
1255 |
}
|
|
1256 |
|
|
1257 |
// ---------------------------------------------------------------------------
|
|
1258 |
// CFileManagerRemovableDriveHandler::LatestBackupTimeL
|
|
1259 |
// ---------------------------------------------------------------------------
|
|
1260 |
//
|
|
1261 |
void CFileManagerRemovableDriveHandler::LatestBackupTimeL(
|
|
1262 |
TTime& aBackupTime )
|
|
1263 |
{
|
|
1264 |
aBackupTime = 0;
|
|
1265 |
CFileManagerBackupSettings& bkupSettings( iEngine.BackupSettingsL() );
|
|
1266 |
RPointerArray< CMMCScBkupArchiveInfo > archives;
|
|
1267 |
TCleanupItem cleanupItem( ResetAndDestroyArchives, &archives );
|
|
1268 |
CleanupStack::PushL( cleanupItem );
|
|
1269 |
ListArchivesL( archives, bkupSettings );
|
|
1270 |
|
|
1271 |
// Find the latest archive
|
|
1272 |
TBool found( EFalse );
|
|
1273 |
TInt count( archives.Count() );
|
|
1274 |
for( TInt i( 0 ); i < count; ++i )
|
|
1275 |
{
|
|
1276 |
TTime time( archives[ i ]->DateTime() );
|
|
1277 |
if ( time > aBackupTime )
|
|
1278 |
{
|
|
1279 |
aBackupTime = time;
|
|
1280 |
found = ETrue;
|
|
1281 |
}
|
|
1282 |
}
|
|
1283 |
CleanupStack::PopAndDestroy( &archives );
|
|
1284 |
if ( !found )
|
|
1285 |
{
|
|
1286 |
User::Leave( KErrNotFound );
|
|
1287 |
}
|
|
1288 |
}
|
|
1289 |
|
|
1290 |
// ---------------------------------------------------------------------------
|
|
1291 |
// CFileManagerRemovableDriveHandler::DeleteBackupsL
|
|
1292 |
// ---------------------------------------------------------------------------
|
|
1293 |
//
|
|
1294 |
void CFileManagerRemovableDriveHandler::DeleteBackupsL()
|
|
1295 |
{
|
|
1296 |
CFileManagerBackupSettings& bkupSettings( iEngine.BackupSettingsL() );
|
|
1297 |
RPointerArray< CMMCScBkupArchiveInfo > archives;
|
|
1298 |
TCleanupItem cleanupItem( ResetAndDestroyArchives, &archives );
|
|
1299 |
CleanupStack::PushL( cleanupItem );
|
|
1300 |
ListArchivesL( archives, bkupSettings );
|
|
1301 |
|
|
1302 |
// Get the user set selection
|
|
1303 |
RArray< CFileManagerRestoreSettings::TInfo > selection;
|
|
1304 |
CleanupClosePushL( selection );
|
|
1305 |
CFileManagerRestoreSettings& rstSettings( iEngine.RestoreSettingsL() );
|
|
1306 |
rstSettings.GetSelectionL( selection );
|
|
1307 |
|
|
1308 |
// Delete selected archives
|
|
1309 |
TInt archivesCount( archives.Count() );
|
|
1310 |
for ( TInt i( 0 ); i < archivesCount; ++i )
|
|
1311 |
{
|
|
1312 |
CMMCScBkupArchiveInfo* archiveInfo = archives[ i ];
|
|
1313 |
TUint32 fmgrContent(
|
|
1314 |
BkupToFmgrMask( archiveInfo->Category().iFlags ) );
|
|
1315 |
TInt drive( archiveInfo->Drive() );
|
|
1316 |
TInt selectionCount( selection.Count() );
|
|
1317 |
for( TInt j( 0 ); j < selectionCount; ++j )
|
|
1318 |
{
|
|
1319 |
const CFileManagerRestoreSettings::TInfo& info( selection[ j ] );
|
|
1320 |
if ( ( drive == info.iDrive ) && ( fmgrContent & info.iContent ) )
|
|
1321 |
{
|
|
1322 |
TPtrC fullPath( archiveInfo->FileName() );
|
|
1323 |
User::LeaveIfError(
|
|
1324 |
CFileManagerUtils::RemoveReadOnlyAttribute(
|
|
1325 |
iFs, fullPath ) );
|
|
1326 |
User::LeaveIfError( iFs.Delete( fullPath ) );
|
|
1327 |
selection.Remove( j ); // Do not check again
|
|
1328 |
break;
|
|
1329 |
}
|
|
1330 |
}
|
|
1331 |
}
|
|
1332 |
CleanupStack::PopAndDestroy( &selection );
|
|
1333 |
CleanupStack::PopAndDestroy( &archives );
|
|
1334 |
}
|
|
1335 |
|
|
1336 |
|
|
1337 |
// End of File
|