|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of Midp2BackupPlugin with USIF |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <connect/sbdefs.h> |
|
19 #include <s32mem.h> |
|
20 #include <s32file.h> |
|
21 #include <f32file.h> |
|
22 #include <apgcli.h> |
|
23 |
|
24 #include "midp2backuppluginusif.h" |
|
25 #include "midp2backupdataids.h" |
|
26 #include "javastoragebackuputil.h" |
|
27 #include "javaversionbackuputil.h" |
|
28 #include "javascrbackuputil.h" |
|
29 |
|
30 #include "javastoragenames.h" |
|
31 #include "javastorageentry.h" |
|
32 #include "javastorage.h" |
|
33 |
|
34 |
|
35 #include "javacommonutils.h" |
|
36 #include "logger.h" |
|
37 |
|
38 |
|
39 using namespace std; |
|
40 using namespace java::storage; |
|
41 using namespace java::backup; |
|
42 |
|
43 // ======== MEMBER FUNCTIONS ======== |
|
44 |
|
45 CMidp2BackupPlugin::CMidp2BackupPlugin() |
|
46 { |
|
47 LOG(EBackup, EInfo, "CMidp2BackupPlugin constructor"); |
|
48 } |
|
49 |
|
50 void CMidp2BackupPlugin::ConstructL() |
|
51 { |
|
52 LOG(EBackup, EInfo, "CMidp2BackupPlugin::ConstructL"); |
|
53 |
|
54 iIconDescIndex = 0; |
|
55 iBufferSpaceLeft = 0; |
|
56 iFirstCallToGetBackupDataSection = ETrue; |
|
57 iStorageDataBackup = ETrue; |
|
58 iScrDataBackup = ETrue; |
|
59 iStorageDataRestore = ETrue; |
|
60 iJavaVersionInfoWritten = EFalse; |
|
61 iRestoreState = EVersion; |
|
62 |
|
63 User::LeaveIfError(iFs.Connect()); |
|
64 // to share file handles with AppArc |
|
65 User::LeaveIfError(iFs.ShareProtected()); |
|
66 |
|
67 iStorageBackupUtil = CStorageBackupUtil::NewL(); |
|
68 |
|
69 //iAppArcUtil = CAppArcBackupUtil::NewL(iFs); |
|
70 |
|
71 iScrBackupUtil = CScrBackupUtil::NewL(); |
|
72 } |
|
73 |
|
74 CMidp2BackupPlugin* CMidp2BackupPlugin::NewL() |
|
75 { |
|
76 LOG(EBackup, EInfo, "CMidp2BackupPlugin::NewL"); |
|
77 |
|
78 CMidp2BackupPlugin* self = new(ELeave) CMidp2BackupPlugin(); |
|
79 CleanupStack::PushL(self); |
|
80 self->ConstructL(); |
|
81 CleanupStack::Pop(); |
|
82 |
|
83 return self; |
|
84 } |
|
85 |
|
86 CMidp2BackupPlugin::~CMidp2BackupPlugin() |
|
87 { |
|
88 LOG(EBackup, EInfo, "CMidp2BackupPlugin destructor"); |
|
89 |
|
90 iFs.Close(); |
|
91 iIconUidArray.Close(); |
|
92 //delete iAppArcUtil; |
|
93 delete iIconDesc; |
|
94 delete iRestoreIconDesc; |
|
95 delete iStorageBackupUtil; |
|
96 } |
|
97 |
|
98 // from base class CBackupPlugin |
|
99 |
|
100 void CMidp2BackupPlugin::PrepareForBURL(TInt aBackupStateValue) |
|
101 { |
|
102 (void)aBackupStateValue; // Just to suppress a warning in release builds |
|
103 LOG1(EBackup, EInfo, "CMidp2BackupPlugin::PrepareForBURL, BUR state: %d", aBackupStateValue); |
|
104 } |
|
105 |
|
106 void CMidp2BackupPlugin::ReceiveSnapshotDataL(TDriveNumber /* aDrive */, TDesC8& /* aBuffer */, TBool /* aLastSection */) |
|
107 { |
|
108 JELOG2(EBackup); |
|
109 User::Leave(KErrNotSupported); |
|
110 } |
|
111 |
|
112 TUint CMidp2BackupPlugin::GetExpectedDataSize(TDriveNumber /* aDrive */) |
|
113 { |
|
114 JELOG2(EBackup); |
|
115 return 0; |
|
116 } |
|
117 |
|
118 void CMidp2BackupPlugin::GetSnapshotDataL(TDriveNumber /* aDrive */, TPtr8& /* aBuffer */, TBool& /* aFinished */) |
|
119 { |
|
120 JELOG2(EBackup); |
|
121 User::Leave(KErrNotSupported); |
|
122 } |
|
123 |
|
124 void CMidp2BackupPlugin::InitialiseGetBackupDataL(TDriveNumber aDrive) |
|
125 { |
|
126 LOG(EBackup, EInfo, "CMidp2BackupPlugin::InitialiseGetBackupDataL"); |
|
127 iDrive = aDrive; |
|
128 } |
|
129 |
|
130 void CMidp2BackupPlugin::GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinished) |
|
131 { |
|
132 LOG(EBackup, EInfo, "CMidp2BackupPlugin::GetBackupDataSectionL"); |
|
133 |
|
134 iBufferSpaceLeft = aBuffer.MaxLength(); |
|
135 RDesWriteStream stream(aBuffer); |
|
136 CleanupClosePushL(stream); |
|
137 |
|
138 if (!iJavaVersionInfoWritten) |
|
139 { |
|
140 JavaVersionBackupUtil::WriteJavaVersionL(stream); |
|
141 iJavaVersionInfoWritten = ETrue; |
|
142 iBufferSpaceLeft -= 8; |
|
143 } |
|
144 |
|
145 if (iStorageDataBackup) |
|
146 { |
|
147 iStorageBackupUtil->BackupStorageDataL(stream, iStorageDataBackup, iBufferSpaceLeft); |
|
148 aFinished = EFalse; |
|
149 } |
|
150 else if(iScrDataBackup) |
|
151 { |
|
152 iScrBackupUtil->BackupScrDataL(stream,iScrDataBackup,iBufferSpaceLeft); |
|
153 aFinished = EFalse; |
|
154 } |
|
155 |
|
156 CleanupStack::PopAndDestroy(&stream); |
|
157 } |
|
158 |
|
159 |
|
160 void CMidp2BackupPlugin::InitialiseRestoreBaseDataL(TDriveNumber aDrive) |
|
161 { |
|
162 LOG(EBackup, EInfo, "CMidp2BackupPlugin::InitialiseRestoreBaseDataL"); |
|
163 iDrive = aDrive; |
|
164 } |
|
165 |
|
166 void CMidp2BackupPlugin::RestoreBaseDataSectionL(TDesC8& aBuffer, TBool aFinished) |
|
167 { |
|
168 LOG(EBackup, EInfo, "CMidp2BackupPlugin::RestoreBaseDataSectionL"); |
|
169 |
|
170 iBufferSpaceLeft = aBuffer.Size(); |
|
171 RDesReadStream stream(aBuffer); |
|
172 CleanupClosePushL(stream); |
|
173 TBool versionCheck = ETrue; |
|
174 |
|
175 if (((iRestoreState == EVersion) || (iRestoreState == EInstall)) && iBufferSpaceLeft >= 8) |
|
176 { |
|
177 if (iRestoreState == EInstall) |
|
178 { |
|
179 versionCheck = EFalse; |
|
180 } |
|
181 TUint ret = JavaVersionBackupUtil::CheckJavaVersionL(stream,iDrive,versionCheck); |
|
182 if (1==ret) |
|
183 { |
|
184 // Here set the satus to restore finished, so that control goes back to SBE & SBE calls B&R for another drive |
|
185 iRestoreState = EInstall; |
|
186 } |
|
187 else |
|
188 { |
|
189 /* version information has been written to stream. |
|
190 So change restore state to restore storage data */ |
|
191 iRestoreState = EStorage; |
|
192 } |
|
193 // version information is of length 8 bytes. |
|
194 iBufferSpaceLeft -= 8; |
|
195 } |
|
196 |
|
197 if (iRestoreState == EStorage) |
|
198 { |
|
199 iStorageBackupUtil -> RestoreStorageDataL(stream, iRestoreState, iBufferSpaceLeft); |
|
200 } |
|
201 |
|
202 if(iRestoreState == EScr) |
|
203 { |
|
204 iScrBackupUtil->RestoreScrDataL(stream,iRestoreState,iBufferSpaceLeft); |
|
205 } |
|
206 // Only at first call |
|
207 if ((iRestoreState != EScr && iRestoreState != EVersion) && (iRestoreState != EInstall)) |
|
208 {/* |
|
209 if (iRestoreState == EAppArc) |
|
210 { |
|
211 // Making AppArc deregistrations |
|
212 TRAPD(err, iAppArcUtil->DeregisterAppsL(iDrive)); |
|
213 |
|
214 if (err) |
|
215 { |
|
216 ELOG(EBackup, "Leave in deregistering apps"); |
|
217 } |
|
218 } |
|
219 |
|
220 // Process the data buffer for restore |
|
221 ProcessBufferL(stream); |
|
222 |
|
223 if (aFinished) |
|
224 { |
|
225 // Set state to EStorage |
|
226 iRestoreState = EStorage; |
|
227 } |
|
228 */ } |
|
229 |
|
230 aFinished = ETrue; |
|
231 CleanupStack::PopAndDestroy(&stream); |
|
232 } |
|
233 |
|
234 void CMidp2BackupPlugin::InitialiseRestoreIncrementDataL(TDriveNumber /* aDrive */) |
|
235 { |
|
236 JELOG2(EBackup); |
|
237 User::Leave(KErrNotSupported); |
|
238 } |
|
239 |
|
240 void CMidp2BackupPlugin::RestoreIncrementDataSectionL(TDesC8& /* aBuffer */, TBool /* aFinished */) |
|
241 { |
|
242 JELOG2(EBackup); |
|
243 User::Leave(KErrNotSupported); |
|
244 } |
|
245 |
|
246 void CMidp2BackupPlugin::RestoreComplete(TDriveNumber /* aDrive */) |
|
247 { |
|
248 LOG(EBackup, EInfo, "CMidp2BackupPlugin::RestoreComplete"); |
|
249 } |
|
250 |
|
251 TUint CMidp2BackupPlugin::MmcIdL() |
|
252 { |
|
253 LOG(EBackup, EInfo, "CMidp2BackupPlugin::MmcIdL()"); |
|
254 |
|
255 TVolumeInfo* volumeInfo = new(ELeave) TVolumeInfo(); |
|
256 |
|
257 TInt err = iFs.Volume(*volumeInfo, iDrive); |
|
258 |
|
259 if (!err) |
|
260 { |
|
261 TUint mmcId = volumeInfo->iUniqueID; |
|
262 return mmcId; |
|
263 } |
|
264 else |
|
265 { |
|
266 return 0; |
|
267 } |
|
268 |
|
269 |
|
270 } |
|
271 /* |
|
272 void CMidp2BackupPlugin::ProcessBufferL(RDesReadStream& stream) |
|
273 { |
|
274 LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessBuffer()"); |
|
275 |
|
276 // Cycle until there's data in the buffer |
|
277 while (iBufferSpaceLeft > 0) |
|
278 { |
|
279 switch (iRestoreState) |
|
280 { |
|
281 case EAppArc: |
|
282 ProcessFirstBufferL(stream, iBufferSpaceLeft); |
|
283 break; |
|
284 |
|
285 case EInIcon: |
|
286 ProcessInIconL(stream, iBufferSpaceLeft); |
|
287 break; |
|
288 |
|
289 case EInSize: |
|
290 ProcessInSizeL(stream, iBufferSpaceLeft); |
|
291 break; |
|
292 |
|
293 default: |
|
294 CleanupStack::PopAndDestroy(&stream); |
|
295 User::Leave(KErrNotSupported); |
|
296 } |
|
297 } |
|
298 } |
|
299 */ |
|
300 |
|
301 _LIT(KStarWildCard, "*.*"); |
|
302 |
|
303 void CMidp2BackupPlugin::RestoreMmcRegistryL() |
|
304 { |
|
305 LOG(EBackup, EInfo, "CMidp2BackupPlugin::RestoreMmcRegistry()"); |
|
306 |
|
307 /* If backed up MMC is not the same as the current MMC, copy the entries |
|
308 from the directory of the backed up MMC to the directory |
|
309 of the current MMC */ |
|
310 TUint32 mmc = MmcIdL(); |
|
311 |
|
312 if (iBackupMmc != mmc) |
|
313 { |
|
314 // Create path to old place |
|
315 TPath path_old; |
|
316 CreateMmcPath(path_old, iDrive, iBackupMmc); |
|
317 |
|
318 // Create path to new place |
|
319 TPath path_new; |
|
320 CreateMmcPath(path_new, iDrive, mmc); |
|
321 |
|
322 // Get old files list |
|
323 CFileMan* fileMan = CFileMan::NewL(iFs); |
|
324 |
|
325 CleanupStack::PushL(fileMan); |
|
326 |
|
327 // Copy to new place |
|
328 iFs.MkDir(path_new); |
|
329 path_old.Append(KStarWildCard); |
|
330 TInt err = fileMan->Copy(path_old, path_new); |
|
331 |
|
332 ILOG1(EBackup, "File copy, status: %d", err); |
|
333 |
|
334 User::LeaveIfError(err); |
|
335 |
|
336 CleanupStack::PopAndDestroy(); |
|
337 } |
|
338 } |
|
339 |
|
340 _LIT(KPrivatePath, "C:\\private\\"); |
|
341 |
|
342 void CMidp2BackupPlugin::CreateMmcPath(TDes& aPathName, TInt aDrive, TUint aUniqueId) |
|
343 { |
|
344 LOG(EBackup, EInfo, "CMidp2BackupPlugin::CreateMmcPath()"); |
|
345 |
|
346 aPathName.Zero(); |
|
347 aPathName.Append(KPrivatePath); |
|
348 aPathName.AppendNum(KRegistryServerUid, EHex); |
|
349 aPathName.Append(KPathDelimiter); |
|
350 |
|
351 // append drive name |
|
352 TDriveUnit driveUnit(aDrive); |
|
353 aPathName.Append(driveUnit.Name().Left(1)); |
|
354 aPathName.Append(KPathDelimiter); |
|
355 |
|
356 TUint64 id = aUniqueId; |
|
357 aPathName.AppendNum(id, EHex); |
|
358 aPathName.Append(KPathDelimiter); |
|
359 } |
|
360 /* |
|
361 TBool CMidp2BackupPlugin::NextIcon(TUid& aCurrentUid, HBufC*& aFullFileName) |
|
362 { |
|
363 LOG(EBackup, EInfo, "CMidp2BackupPlugin::NextIcon()"); |
|
364 |
|
365 if (iIconUidArray.Count() > iIconFilePointer) |
|
366 { |
|
367 aCurrentUid = iIconUidArray[iIconFilePointer]; |
|
368 iAppArcUtil->GetIconFilename(iIconUidArray[iIconFilePointer], aFullFileName); |
|
369 iIconFilePointer++; |
|
370 return ETrue; |
|
371 } |
|
372 else |
|
373 { |
|
374 // There are no more icon files |
|
375 return EFalse; |
|
376 } |
|
377 } |
|
378 |
|
379 void CMidp2BackupPlugin::ProcessFirstBufferL(RDesReadStream& aStream, TInt& aBufferSpaceLeft) |
|
380 { |
|
381 LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessFirstBuffer()"); |
|
382 |
|
383 if (iDrive >= EDriveE && iDrive <= EDriveZ) |
|
384 { |
|
385 // Read MMC id and restore MMC entries if needed |
|
386 iBackupMmc = aStream.ReadUint32L(); |
|
387 aBufferSpaceLeft -= sizeof(iBackupMmc); |
|
388 LOG1(EBackup, EInfo, "Read MMC Id: %u", iBackupMmc); |
|
389 RestoreMmcRegistryL(); |
|
390 } |
|
391 if (aBufferSpaceLeft >= sizeof(TInt32)) |
|
392 { |
|
393 iIconFileSizeLeft = aStream.ReadInt32L(); |
|
394 aBufferSpaceLeft -= sizeof(iIconFileSizeLeft); |
|
395 iRestoreIconDesc = HBufC8::NewL(iIconFileSizeLeft); |
|
396 iRestoreState = EInIcon; |
|
397 } |
|
398 else |
|
399 { |
|
400 // No more data to read |
|
401 aBufferSpaceLeft = 0; |
|
402 } |
|
403 } |
|
404 |
|
405 void CMidp2BackupPlugin::ProcessInIconL(RDesReadStream& aStream, TInt& aBufferSpaceLeft) |
|
406 { |
|
407 LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessInIcon()"); |
|
408 |
|
409 TPtr8 restoreIconPtr = iRestoreIconDesc->Des(); |
|
410 HBufC8* tempDesc = HBufC8::NewL(iIconFileSizeLeft); |
|
411 CleanupStack::PushL(tempDesc); |
|
412 TPtr8 tempPtr = tempDesc->Des(); |
|
413 |
|
414 // Icon cannot be read fully |
|
415 if (iIconFileSizeLeft > aBufferSpaceLeft) |
|
416 { |
|
417 aStream.ReadL(tempPtr, aBufferSpaceLeft); |
|
418 restoreIconPtr.Append(tempPtr); |
|
419 iIconFileSizeLeft -= aBufferSpaceLeft; |
|
420 aBufferSpaceLeft = 0; |
|
421 iRestoreState = EInIcon; |
|
422 } |
|
423 // Icon can be read fully |
|
424 else |
|
425 { |
|
426 aStream.ReadL(tempPtr, iIconFileSizeLeft); |
|
427 restoreIconPtr.Append(tempPtr); |
|
428 aBufferSpaceLeft -= iIconFileSizeLeft; |
|
429 iRestoreState = EInSize; |
|
430 |
|
431 TRAPD(err, iAppArcUtil->RegisterAppL(restoreIconPtr, iDrive)); |
|
432 |
|
433 if (err) |
|
434 { |
|
435 ELOG(EBackup, "Registerin application to AppArc failed."); |
|
436 } |
|
437 } |
|
438 |
|
439 CleanupStack::PopAndDestroy(tempDesc); |
|
440 } |
|
441 |
|
442 void CMidp2BackupPlugin::ProcessInSizeL(RDesReadStream& aStream, TInt& aBufferSpaceLeft) |
|
443 { |
|
444 LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessInSize()"); |
|
445 |
|
446 if (aBufferSpaceLeft >= sizeof(TInt32)) |
|
447 { |
|
448 if (iSizeBuffer.Size() != 0) |
|
449 { |
|
450 // Read leftover part of size |
|
451 TInt readData = sizeof(TInt32) - iSizeBuffer.Size(); |
|
452 aStream.ReadL(iSizeBuffer, readData); |
|
453 RMemReadStream sizeStream(iSizeBuffer.Ptr(), 4); |
|
454 CleanupClosePushL(sizeStream); |
|
455 iIconFileSizeLeft = sizeStream.ReadInt32L(); |
|
456 CleanupStack::PopAndDestroy(&sizeStream); |
|
457 aBufferSpaceLeft -= sizeof(readData); |
|
458 } |
|
459 else |
|
460 { |
|
461 // Read size in full |
|
462 iIconFileSizeLeft = aStream.ReadInt32L(); |
|
463 aBufferSpaceLeft -= sizeof(iIconFileSizeLeft); |
|
464 } |
|
465 |
|
466 delete iRestoreIconDesc; |
|
467 iRestoreIconDesc = NULL; |
|
468 iRestoreIconDesc = HBufC8::NewL(iIconFileSizeLeft); |
|
469 iRestoreState = EInIcon; |
|
470 } |
|
471 else |
|
472 { |
|
473 // Read first byte(s) of size |
|
474 aStream.ReadL(iSizeBuffer, aBufferSpaceLeft); |
|
475 aBufferSpaceLeft = 0; |
|
476 } |
|
477 } |
|
478 |
|
479 void CMidp2BackupPlugin::ResetIconArray() |
|
480 { |
|
481 LOG(EBackup, EInfo, "CMidp2BackupPlugin::ResetIconArray()"); |
|
482 |
|
483 // Remove all entries |
|
484 while (iIconUidArray.Count()) |
|
485 { |
|
486 iIconUidArray.Remove(0); |
|
487 } |
|
488 } |
|
489 */ |
|
490 |