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 CScrBackupUtil |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "javascrbackuputil.h" |
|
19 #include "midp2backupdataids.h" |
|
20 |
|
21 #include "logger.h" |
|
22 #include "javasymbianoslayer.h" // for CleanupResetAndDestroyPushL |
|
23 |
|
24 #include <scs/nullstream.h> |
|
25 #include <e32cmn.h> |
|
26 #include <apaid.h> //for TApaAppCapability::ENonNative |
|
27 #include <e32def.h> |
|
28 |
|
29 using namespace java::backup; |
|
30 using namespace Usif; |
|
31 |
|
32 // Properties registered to SCR. |
|
33 _LIT(KMIDletName, "MIDlet-Name"); |
|
34 _LIT(KUid, "Uid"); |
|
35 _LIT(KMediaId, "Media-Id"); |
|
36 _LIT(KMIDletInfoURL, "MIDlet-Info-URL"); |
|
37 _LIT(KMIDletDescription, "MIDlet-Description"); |
|
38 _LIT(KDownloadURL, "Download-URL"); |
|
39 _LIT(KSettingsPlugin, "SettingsName"); |
|
40 _LIT(KMIDletDeletionConformation, "MIDlet-Delete-Confirm"); |
|
41 |
|
42 _LIT(KDomainCategory,"Domain-Category"); |
|
43 |
|
44 |
|
45 CScrBackupUtil* CScrBackupUtil::NewL() |
|
46 { |
|
47 LOG(EBackup,EInfo," ---> CScrBackupUtil: NewL()"); |
|
48 |
|
49 CScrBackupUtil *self = CScrBackupUtil::NewLC(); |
|
50 |
|
51 CleanupStack::Pop(self); |
|
52 |
|
53 LOG(EBackup,EInfo," <--- CScrBackupUtil: NewL()"); |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 CScrBackupUtil* CScrBackupUtil::NewLC() |
|
59 { |
|
60 LOG(EBackup,EInfo," ---> CScrBackupUtil: NewLC"); |
|
61 CScrBackupUtil *self = new(ELeave) CScrBackupUtil(); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 LOG(EBackup,EInfo," <--- CScrBackupUtil: NewLC"); |
|
65 return self; |
|
66 } |
|
67 |
|
68 CScrBackupUtil::CScrBackupUtil():iPtrToWriteBuffer(NULL,0) |
|
69 { |
|
70 LOG(EBackup,EInfo," ---> CScrBackupUtil: CScrBackupUtil"); |
|
71 LOG(EBackup,EInfo," <--- CScrBackupUtil: CScrBackupUtil"); |
|
72 } |
|
73 |
|
74 |
|
75 void CScrBackupUtil::ConstructL() |
|
76 { |
|
77 LOG(EBackup,EInfo," ---> CScrBackupUtil: ConstructL "); |
|
78 |
|
79 //will be incremented as and when needed |
|
80 iRemainingInfo = HBufC8::NewL(4096);//TODO :need to change it to the total size of the the attribute |
|
81 //iPtrToWriteBuffer = ((const_cast<TUint8*>(iRemainingInfo->Ptr())));// need to do this coz when fun end and goes to fetch next 4096 bytes i lose it |
|
82 iPtrToWriteBuffer.Set(iRemainingInfo->Des()); |
|
83 iIsFristCall = ETrue; |
|
84 |
|
85 iState = EIsFetchCompleteInfo; |
|
86 iIsToWriteInStream = ETrue; |
|
87 LOG(EBackup,EInfo," <--- CScrBackupUtil: ConstructL()"); |
|
88 } |
|
89 void CScrBackupUtil::ConnectScrL() |
|
90 { |
|
91 LOG(EBackup,EInfo," ---> CScrBackupUtil: ConnectScrL()"); |
|
92 iScr = new RSoftwareComponentRegistry(); |
|
93 if (NULL == iScr) |
|
94 { |
|
95 ELOG(EBackup,"Creating RSoftwareComponentRegistry failed"); |
|
96 User::Leave(KErrGeneral); |
|
97 } |
|
98 |
|
99 TInt err = iScr->Connect(); |
|
100 if (KErrNone != err) |
|
101 { |
|
102 ELOG1(EBackup,"Connecting to RSoftwareComponentRegistry failed, error %d",err); |
|
103 //TODO need to see can we afford leaving here ;) |
|
104 User::Leave(err); |
|
105 } |
|
106 LOG(EBackup,EInfo," <--- CScrBackupUtil: ConnectScrL()"); |
|
107 } |
|
108 void CScrBackupUtil::ExtractUidAndComponentIdL(RArray<Usif::TComponentId>& componentIds,RArray<TInt>& uids,TInt& ComponentsCount) |
|
109 { |
|
110 LOG(EBackup,EInfo," ---> CScrBackupUtil: ExtractUidAndComponentId()"); |
|
111 CComponentFilter* filter; |
|
112 CPropertyEntry* property; |
|
113 filter = CComponentFilter::NewLC(); |
|
114 //Set the filter for software type Usif::KSoftwareTypeJava and ftech the Ids |
|
115 filter->SetSoftwareTypeL(Usif::KSoftwareTypeJava); |
|
116 TRAPD(error,iScr->GetComponentIdsL(componentIds,filter)); |
|
117 if(error) |
|
118 { |
|
119 ELOG(EBackup,"Failed to get the components ID"); |
|
120 } |
|
121 CleanupStack::PopAndDestroy(filter); |
|
122 // fetch the no. of component from the given RArray |
|
123 ComponentsCount = componentIds.Count(); |
|
124 // No use of Component Ids as such as they are used by SCR internally |
|
125 //so exctracted the UID of of each component |
|
126 for(TInt i = 0 ;i < ComponentsCount ; i++) |
|
127 { |
|
128 |
|
129 property = iScr->GetComponentPropertyL(componentIds.operator [](i),KUid()); |
|
130 if (property->PropertyType() == CPropertyEntry::EIntProperty) |
|
131 { |
|
132 TInt uid = ((CIntPropertyEntry*)property)->IntValue(); |
|
133 uids.AppendL(uid); |
|
134 |
|
135 } |
|
136 else |
|
137 { |
|
138 //Error |
|
139 } |
|
140 |
|
141 delete property; |
|
142 property = NULL; |
|
143 |
|
144 } |
|
145 LOG(EBackup,EInfo," <--- CScrBackupUtil: ExtractUidAndComponentId()"); |
|
146 } |
|
147 void CScrBackupUtil::BackupScrDataL(RDesWriteStream& aStream, TBool& aBackupNotFinished, TInt& aBufferSpaceLeft) |
|
148 { |
|
149 LOG(EBackup,EInfo," ---> CScrBackupUtil: BackupScrDataL()"); |
|
150 |
|
151 iBufferSpaceLeft = aBufferSpaceLeft ; |
|
152 |
|
153 if(iIsFristCall) |
|
154 { |
|
155 |
|
156 // to get no. of components need to keep a flag that its called only once |
|
157 ConnectScrL(); |
|
158 |
|
159 ExtractUidAndComponentIdL(iComponentIds,iUids,iNumberOfComponents); |
|
160 |
|
161 //write the no. of components so that it will help us in restoration time |
|
162 aStream.WriteInt32L(iNumberOfComponents); |
|
163 iBufferSpaceLeft -= sizeof(TInt32); |
|
164 |
|
165 //all the ids of the midlets that are to be backedup and the size of the rarray with holds the Ids |
|
166 TPckgBuf<RArray<TInt> > ids(iUids); |
|
167 TInt size = ComputeSizeL(ids); |
|
168 aStream.WriteInt32L(size); |
|
169 iBufferSpaceLeft -= sizeof(TInt32); |
|
170 |
|
171 aStream.WriteL(ids); |
|
172 |
|
173 iBufferSpaceLeft = iBufferSpaceLeft - size; |
|
174 |
|
175 iIsFristCall = EFalse; |
|
176 } |
|
177 |
|
178 for( i ; i < iComponentIds.Count() ;) |
|
179 { |
|
180 if(iState == EIsFetchCompleteInfo) |
|
181 { |
|
182 |
|
183 TInt at = iComponentIds.operator[](i); |
|
184 |
|
185 //Temp stream in which all attributes are backed up |
|
186 RDesWriteStream writeStream; |
|
187 writeStream.Open(iPtrToWriteBuffer); |
|
188 |
|
189 GetComponentInfoL(at,writeStream); |
|
190 |
|
191 writeStream.CommitL(); |
|
192 iLengthOfString = iPtrToWriteBuffer.Length(); |
|
193 |
|
194 iWriteToStream = ETrue; |
|
195 |
|
196 // write the size, Used while restoring |
|
197 aStream.WriteInt32L(iLengthOfString); |
|
198 iBufferSpaceLeft = iBufferSpaceLeft - sizeof(TInt); |
|
199 |
|
200 |
|
201 } |
|
202 if(iState == EIsWriteCompleteInfo) |
|
203 { |
|
204 |
|
205 //writing the remaining information into the new buffer |
|
206 if(iBufferToWriteNextTime) |
|
207 { |
|
208 aStream.WriteL(iPtrToWriteBuffer,iRemainingBuffer); |
|
209 aStream.CommitL(); |
|
210 LOG(EBackup, EInfo, "attributes written fully in the stream fetching for next component"); |
|
211 |
|
212 iBufferSpaceLeft = iBufferSpaceLeft - iRemainingBuffer; |
|
213 |
|
214 iBufferToWriteNextTime = EFalse; |
|
215 iState = EIsFetchCompleteInfo; |
|
216 |
|
217 iLengthOfString = 0; // to maintain the loop |
|
218 |
|
219 iWriteToStream = EFalse; |
|
220 i++; |
|
221 } |
|
222 // if the whole string cannot be writen, write part of it |
|
223 if (iLengthOfString > iBufferSpaceLeft && !iBufferToWriteNextTime) |
|
224 { |
|
225 |
|
226 iRemainingBuffer = iLengthOfString - iBufferSpaceLeft; |
|
227 |
|
228 aStream.WriteL(iPtrToWriteBuffer,iBufferSpaceLeft); |
|
229 aStream.CommitL(); |
|
230 |
|
231 iBufferToWriteNextTime = ETrue; |
|
232 break; |
|
233 } |
|
234 // else write the complete string |
|
235 else if(iWriteToStream) |
|
236 { aStream.WriteL(iPtrToWriteBuffer,iLengthOfString); |
|
237 |
|
238 aStream.CommitL(); |
|
239 iBufferSpaceLeft = iBufferSpaceLeft - iLengthOfString; |
|
240 iState = EIsFetchCompleteInfo; |
|
241 iLengthOfString = 0; // to maintain the loop |
|
242 i++; |
|
243 } |
|
244 |
|
245 } |
|
246 } |
|
247 // making it false to backup next component next time |
|
248 if(i >= iComponentIds.Count()) |
|
249 aBackupNotFinished = EFalse; |
|
250 |
|
251 } |
|
252 |
|
253 template <typename T> |
|
254 TInt CScrBackupUtil::ComputeSizeL(const T &aObject) |
|
255 { |
|
256 LOG(EBackup,EInfo," ---> computeSize() "); |
|
257 TInt size(0); |
|
258 RNullWriteStream nullstream; |
|
259 CleanupClosePushL(nullstream); |
|
260 nullstream << aObject; |
|
261 nullstream.CommitL(); |
|
262 size = nullstream.BytesWritten(); |
|
263 |
|
264 CleanupStack::PopAndDestroy(&nullstream); |
|
265 LOG(EBackup,EInfo," <--- computeSize() "); |
|
266 return size; |
|
267 |
|
268 |
|
269 } |
|
270 void CScrBackupUtil::GetComponentInfoL(TComponentId aComponentId ,RDesWriteStream& aStream ) |
|
271 { |
|
272 |
|
273 LOG(EBackup,EInfo," ---> GetComponentInfo() "); |
|
274 |
|
275 TInt j = 0 ; |
|
276 CPropertyEntry* property; |
|
277 CComponentEntry* entries = CComponentEntry::NewL(); |
|
278 CleanupStack::PushL(entries); |
|
279 TLanguage language =KNonLocalized; |
|
280 |
|
281 TBool result = iScr->GetComponentL(aComponentId,*entries,language); |
|
282 entries->ExternalizeL(aStream); |
|
283 |
|
284 CleanupStack::PopAndDestroy(entries); |
|
285 TBool isComponentPresent = iScr->IsComponentPresentL(aComponentId); |
|
286 aStream.WriteInt8L(isComponentPresent); |
|
287 |
|
288 |
|
289 // Localizable Component info |
|
290 RPointerArray<CLocalizableComponentInfo> localizableComponentInfo; |
|
291 iScr->GetComponentLocalizedInfoL(aComponentId,localizableComponentInfo); |
|
292 aStream.WriteInt32L(localizableComponentInfo.Count()); |
|
293 |
|
294 |
|
295 for(j ; j < localizableComponentInfo.Count(); j++) |
|
296 { |
|
297 (localizableComponentInfo.operator [](j))->ExternalizeL(aStream); |
|
298 |
|
299 } |
|
300 |
|
301 // Properties |
|
302 // extracted the UID |
|
303 property = iScr->GetComponentPropertyL(aComponentId,KUid()); |
|
304 if (NULL != property) |
|
305 { |
|
306 property->ExternalizeL(aStream); |
|
307 |
|
308 |
|
309 delete property; |
|
310 property = NULL; |
|
311 } |
|
312 else |
|
313 { |
|
314 // need to return or have to proceed |
|
315 } |
|
316 // Exctracted Domain - Category |
|
317 property = iScr->GetComponentPropertyL(aComponentId,KDomainCategory()); |
|
318 if (NULL != property) |
|
319 { |
|
320 property->ExternalizeL(aStream); |
|
321 |
|
322 delete property; |
|
323 property = NULL; |
|
324 } |
|
325 // Exctracted Media ID |
|
326 property = iScr->GetComponentPropertyL(aComponentId,KMediaId()); |
|
327 if (NULL != property) |
|
328 { |
|
329 property->ExternalizeL(aStream); |
|
330 |
|
331 |
|
332 delete property; |
|
333 property = NULL; |
|
334 } |
|
335 // Exctracted Setings plugin name |
|
336 property = iScr->GetComponentPropertyL(aComponentId,KSettingsPlugin()); |
|
337 if (NULL != property) |
|
338 { |
|
339 property->ExternalizeL(aStream); |
|
340 |
|
341 |
|
342 delete property; |
|
343 property = NULL; |
|
344 } |
|
345 |
|
346 // Optional Properties |
|
347 // extracted info URL |
|
348 property = iScr->GetComponentPropertyL(aComponentId,KMIDletInfoURL()); |
|
349 if (NULL != property) |
|
350 { |
|
351 property->ExternalizeL(aStream); |
|
352 |
|
353 |
|
354 delete property; |
|
355 property = NULL; |
|
356 } |
|
357 else // as its optional property so could be NULL |
|
358 { |
|
359 aStream.WriteInt8L(NULL); |
|
360 } |
|
361 |
|
362 // extracted midlet description |
|
363 property = iScr->GetComponentPropertyL(aComponentId,KMIDletDescription()); |
|
364 if (NULL != property) |
|
365 { |
|
366 property->ExternalizeL(aStream); |
|
367 |
|
368 |
|
369 delete property; |
|
370 property = NULL; |
|
371 } |
|
372 else // as its optional property so could be NULL |
|
373 { |
|
374 aStream.WriteInt8L(NULL); |
|
375 } |
|
376 // extracted midlet DeletionConformation |
|
377 property = iScr->GetComponentPropertyL(aComponentId,KMIDletDeletionConformation()); |
|
378 if (NULL != property) |
|
379 { |
|
380 property->ExternalizeL(aStream); |
|
381 |
|
382 |
|
383 delete property; |
|
384 property = NULL; |
|
385 } |
|
386 else // as its optional property so could be NULL |
|
387 { |
|
388 aStream.WriteInt8L(NULL); |
|
389 } |
|
390 //extracted midlet DN URL |
|
391 property = iScr->GetComponentPropertyL(aComponentId,KDownloadURL()); |
|
392 if (NULL != property) |
|
393 { |
|
394 property->ExternalizeL(aStream); |
|
395 |
|
396 |
|
397 delete property; |
|
398 property = NULL; |
|
399 } |
|
400 else // as its optional property so could be NULL |
|
401 { |
|
402 aStream.WriteInt8L(NULL); |
|
403 } |
|
404 |
|
405 |
|
406 // backing up files corresponds to component |
|
407 RSoftwareComponentRegistryFilesList fileList; |
|
408 CleanupClosePushL(fileList); |
|
409 TInt count = iScr->GetComponentFilesCountL(aComponentId); |
|
410 TInt k = 0; |
|
411 RPointerArray<HBufC> files; |
|
412 fileList.OpenListL(*iScr,aComponentId); |
|
413 fileList.NextFileSetL(count,files); |
|
414 aStream.WriteInt32L(files.Count()); |
|
415 CleanupStack::PopAndDestroy(&fileList);//filelist |
|
416 |
|
417 for( k ; k < files.Count(); k++) |
|
418 { |
|
419 HBufC* temp = files.operator [](k); |
|
420 aStream.WriteInt32L(temp->Length()); |
|
421 aStream.WriteL(temp->Des()); |
|
422 } |
|
423 |
|
424 |
|
425 RArray<TUid> noOfApps; |
|
426 HBufC* appIcon; |
|
427 TAppRegInfo appInfo; |
|
428 iScr->GetAppUidsForComponentL(aComponentId,noOfApps); |
|
429 RRegistrationInfoForApplication regInfoIcon; |
|
430 CleanupClosePushL(regInfoIcon); |
|
431 RApplicationRegistrationInfo regInfoCaption; |
|
432 CleanupClosePushL(regInfoCaption); |
|
433 |
|
434 |
|
435 //backing up the no. of apps |
|
436 aStream.WriteInt32L(noOfApps.Count()); |
|
437 |
|
438 |
|
439 for(j = 0 ; j < noOfApps.Count(); j++ ) |
|
440 { |
|
441 regInfoIcon.OpenL(*iScr,noOfApps.operator [](j)); |
|
442 regInfoCaption.OpenL(*iScr); |
|
443 |
|
444 //check if language is imp to give as an argument\ |
|
445 // Language extracted |
|
446 TLanguage language = regInfoIcon.ApplicationLanguageL(); |
|
447 // Language backed up |
|
448 aStream.WriteInt32L(language); |
|
449 |
|
450 // AppUID extracted |
|
451 TUid appUid = noOfApps[j]; |
|
452 // AppUID backed up |
|
453 aStream.WriteInt32L(appUid.iUid); |
|
454 |
|
455 //App caption extracted |
|
456 regInfoCaption.GetAppInfoL(appUid,appInfo,language); |
|
457 TAppCaption caption = appInfo.Caption(); |
|
458 caption.Trim();// would give the acctual size of content |
|
459 //App caption backed up |
|
460 aStream.WriteL(caption); |
|
461 |
|
462 //AppIcon path extracted |
|
463 regInfoIcon.GetAppIconL(appIcon); |
|
464 //AppIcon path backed up |
|
465 aStream.WriteL(appIcon->Des()); |
|
466 |
|
467 |
|
468 //need to backup no. of icons to needed for registrating application |
|
469 TInt noOfIcons = regInfoIcon.NumberOfOwnDefinedIconsL(); |
|
470 aStream.WriteInt32L(noOfIcons); |
|
471 } |
|
472 CleanupStack::PopAndDestroy();//regInfoIcon |
|
473 CleanupStack::PopAndDestroy();//regInfoCaption |
|
474 //regInfoIcon.Close(); |
|
475 //regInfoCaption.Close(); |
|
476 |
|
477 iState = EIsWriteCompleteInfo; |
|
478 |
|
479 LOG(EBackup,EInfo," <--- GetComponentInfo() "); |
|
480 |
|
481 } |
|
482 void CScrBackupUtil::RestoreScrDataL(RDesReadStream& aStream, TInt& aRestoreState, TInt& aBufferSpaceLeft) |
|
483 { |
|
484 LOG(EBackup,EInfo," ---> RestoreScrDataL() "); |
|
485 if(iIsFristCall) |
|
486 { |
|
487 ConnectScrL(); |
|
488 TInt j = 0; |
|
489 TInt presentComponentsCount; |
|
490 RArray<Usif::TComponentId> presentComponentsIds; |
|
491 iBufferSpaceLeft = aBufferSpaceLeft; |
|
492 //aStream.r |
|
493 //reading components count |
|
494 iNumberOfComponents = aStream.ReadInt32L(); |
|
495 iBufferSpaceLeft = iBufferSpaceLeft - sizeof(TInt32); |
|
496 |
|
497 //reading the size of the TPckgBuf<RArray<TComponentId>> |
|
498 TInt size = aStream.ReadInt32L(); |
|
499 iBufferSpaceLeft = iBufferSpaceLeft - sizeof(TInt32); |
|
500 |
|
501 //reading TPckgBuf<RArray<TComponentId>> |
|
502 HBufC* temp = HBufC::NewLC(aStream , size); |
|
503 |
|
504 TPckgBuf<RArray<TInt> > ids; |
|
505 //extracting RArray from TPckgBuf<RArray<TUids>> |
|
506 ids.Append(temp->Des()); |
|
507 CleanupStack::PopAndDestroy(temp); |
|
508 iUids = ids.operator ()();// populated iUids |
|
509 iBufferSpaceLeft = iBufferSpaceLeft - size; |
|
510 iNumberOfComponents = iUids.Count(); |
|
511 |
|
512 |
|
513 ExtractUidAndComponentIdL(presentComponentsIds,iPresentUids,presentComponentsCount); |
|
514 |
|
515 // calculating the midlets to be deleted from SCR |
|
516 for(j ; j <= iNumberOfComponents ; j++ ) |
|
517 { |
|
518 TInt id = NULL; |
|
519 TInt index = 0; |
|
520 id = iUids.operator [](j); |
|
521 index = iPresentUids.Find(iUids.operator [](j)); |
|
522 if(index != NULL) |
|
523 { |
|
524 presentComponentsIds.Remove(index);// removeing the app that is present in SCr and backed up too |
|
525 iPresentUids.Remove(index);// TODO : check if right component Id is removed |
|
526 } |
|
527 } |
|
528 |
|
529 |
|
530 iPresentUids.Compress(); // need to see if this works |
|
531 presentComponentsIds.Compress();// contains the uids that has to be deleted |
|
532 //Updated the count |
|
533 presentComponentsCount = iPresentUids.Count(); |
|
534 for(j = 0 ; j <= presentComponentsCount ; j++ ) |
|
535 { |
|
536 TRAPD(err ,iScr->DeleteApplicationEntriesL(presentComponentsIds.operator [](j))); |
|
537 if (KErrNone == err) |
|
538 { |
|
539 iScr->DeleteComponentL(presentComponentsIds.operator [](j)); |
|
540 } |
|
541 |
|
542 } |
|
543 |
|
544 |
|
545 } |
|
546 RDesReadStream readStream; |
|
547 readStream.Open(iPtrToWriteBuffer); |
|
548 for( i ; i < iComponentIds.Count() ;) |
|
549 { |
|
550 if(iState == EIsFetchCompleteInfo) |
|
551 { |
|
552 TUid uid ; |
|
553 uid.iUid = iUids.operator [](i); |
|
554 SetDataInScrL(uid,readStream); |
|
555 i++; |
|
556 } |
|
557 if(iState == EIsWriteCompleteInfo) |
|
558 { |
|
559 RDesReadStream readStream; |
|
560 readStream.Open(iPtrToWriteBuffer); |
|
561 iLengthOfString = aStream.ReadInt32L(); |
|
562 |
|
563 |
|
564 //Reading the remaining information into the new buffer |
|
565 if(iBufferToWriteNextTime) |
|
566 { |
|
567 //appened it in the remaing |
|
568 HBufC* remainingBuff = HBufC::NewL(iRemainingBuffer); |
|
569 TPtr ptr(remainingBuff->Des()); |
|
570 aStream.ReadL(ptr,iRemainingBuffer); |
|
571 iPtrToWriteBuffer.Append(ptr); |
|
572 iState = EIsFetchCompleteInfo; |
|
573 iLengthOfString = 0; // to maintain the loop |
|
574 iWriteToStream = EFalse; |
|
575 |
|
576 |
|
577 } |
|
578 if (iLengthOfString > iBufferSpaceLeft && !iBufferToWriteNextTime) |
|
579 { |
|
580 iRemainingBuffer = iLengthOfString - iBufferSpaceLeft; |
|
581 aStream.ReadL(iPtrToWriteBuffer,iBufferSpaceLeft); |
|
582 iBufferToWriteNextTime = ETrue; |
|
583 break ; |
|
584 } |
|
585 // Read the complete string |
|
586 else if(iWriteToStream) |
|
587 { |
|
588 aStream.ReadL(iPtrToWriteBuffer,iLengthOfString); |
|
589 iBufferSpaceLeft = iBufferSpaceLeft - iLengthOfString; |
|
590 iState = EIsFetchCompleteInfo; |
|
591 iLengthOfString = 0; // to maintain the loop |
|
592 |
|
593 } |
|
594 |
|
595 } |
|
596 } |
|
597 //take care of restorestate |
|
598 // SCR restore is over; Set state to EAppArc |
|
599 if(i >= iComponentIds.Count()) |
|
600 { |
|
601 aRestoreState = EAppArc; |
|
602 aBufferSpaceLeft = iBufferSpaceLeft;// need to to this coz of last iteration |
|
603 } |
|
604 |
|
605 LOG(EBackup,EInfo," <--- RestoreScrDataL() "); |
|
606 } |
|
607 void CScrBackupUtil::SetDataInScrL(TUid aUid , RDesReadStream& aStream) |
|
608 { |
|
609 LOG(EBackup,EInfo," ---> SetDataInScrL() "); |
|
610 TInt tempSize = NULL; |
|
611 TInt j = 0; |
|
612 tempSize = aStream.ReadInt32L(); |
|
613 CComponentEntry* entries; |
|
614 entries = CComponentEntry::NewL(); |
|
615 CleanupStack::PushL( entries); |
|
616 entries->InternalizeL(aStream); |
|
617 |
|
618 |
|
619 TBool isComponentPresent = aStream.ReadInt8L(); |
|
620 |
|
621 // Localizable Component info |
|
622 RPointerArray<CLocalizableComponentInfo> localizableComponentInfoArray; // Not owned by me nee to delete in last |
|
623 TInt temp = aStream.ReadInt32L(); |
|
624 for(j ; j <= temp; j++) |
|
625 { |
|
626 CLocalizableComponentInfo* componentinfo = CLocalizableComponentInfo::NewL(aStream); |
|
627 localizableComponentInfoArray.Append(componentinfo); |
|
628 } |
|
629 |
|
630 // now need to set all the properties |
|
631 // extracted the UID |
|
632 CIntPropertyEntry* property; |
|
633 property = (CIntPropertyEntry*)CPropertyEntry::NewL(aStream); |
|
634 TInt64 id = property->Int64Value(); |
|
635 delete property; |
|
636 |
|
637 //extracted midlet Domain-Catogary |
|
638 CLocalizablePropertyEntry* propertyString; |
|
639 propertyString =(CLocalizablePropertyEntry*) CPropertyEntry::NewL(aStream); |
|
640 HBufC* domainCategory = (propertyString->StrValue()).Alloc(); |
|
641 delete propertyString; |
|
642 |
|
643 // Exctracted Media ID |
|
644 property = (CIntPropertyEntry*)CPropertyEntry::NewL(aStream); |
|
645 TInt64 mediaID = property->Int64Value(); |
|
646 delete property; |
|
647 |
|
648 //extracted midlet SettingsValue |
|
649 propertyString =(CLocalizablePropertyEntry*) CPropertyEntry::NewL(aStream); |
|
650 HBufC* SettingsValue = (propertyString->StrValue()).Alloc(); |
|
651 delete propertyString; |
|
652 |
|
653 // Optional Properties |
|
654 // extracted info URL |
|
655 propertyString = propertyString = (CLocalizablePropertyEntry*)CPropertyEntry::NewL(aStream); |
|
656 HBufC* url = (propertyString->StrValue()).Alloc(); |
|
657 delete propertyString; |
|
658 |
|
659 |
|
660 // extracted midlet description |
|
661 propertyString = (CLocalizablePropertyEntry*)CPropertyEntry::NewL(aStream); |
|
662 HBufC* midletDescription = (propertyString->StrValue()).Alloc(); |
|
663 delete propertyString; |
|
664 |
|
665 // midlet deletion conformation has to be here |
|
666 CBinaryPropertyEntry* propertyBinary = (CBinaryPropertyEntry*)CPropertyEntry::NewL(aStream); |
|
667 HBufC8* midletDeletionConformation = (propertyBinary->BinaryValue()).Alloc(); |
|
668 delete propertyBinary; |
|
669 |
|
670 //extracted midlet DN URL |
|
671 propertyString =(CLocalizablePropertyEntry*) CPropertyEntry::NewL(aStream); |
|
672 HBufC* dnUrl = (propertyString->StrValue()).Alloc(); |
|
673 delete propertyString; |
|
674 |
|
675 //Extracting no. of files registered with a component |
|
676 //1st the no. of files |
|
677 RPointerArray<HBufC> componentFilesArray; |
|
678 |
|
679 TInt fileCount = aStream.ReadInt32L(); |
|
680 //now the files |
|
681 for(TInt k = 0 ; k < fileCount ; k++) |
|
682 { |
|
683 TInt size = aStream.ReadInt32L(); |
|
684 HBufC* componentFile = HBufC::NewL(aStream,size); |
|
685 CleanupStack::PushL( componentFile); |
|
686 componentFilesArray.AppendL(componentFile); |
|
687 CleanupStack::Pop( componentFile); |
|
688 } |
|
689 |
|
690 //Extracting no. of apps with a component |
|
691 TInt noOfApps = aStream.ReadInt32L(); |
|
692 RPointerArray<CAppInfo> appinfoArray; |
|
693 for(j = 0 ; j < noOfApps ; j++ ) |
|
694 { |
|
695 CAppInfo* appinfo = CAppInfo::NewL(); |
|
696 CleanupStack::PushL( appinfo);// i will not own it after using has to be destroyed |
|
697 TLanguage language; |
|
698 language = (TLanguage)(aStream.ReadInt32L()); |
|
699 TUid uid; |
|
700 uid.Uid(aStream.ReadInt32L()); |
|
701 |
|
702 TAppCaption caption ; |
|
703 aStream.ReadL(caption); |
|
704 HBufC* appIcon ; |
|
705 TPtr temp(appIcon->Des()); |
|
706 aStream.ReadL(temp); |
|
707 TInt noOfIcons = aStream.ReadInt32L(); |
|
708 |
|
709 appinfo->Set(language,uid,caption,temp,noOfIcons);// TODO: check if it works |
|
710 appinfoArray.Append(appinfo); |
|
711 |
|
712 |
|
713 |
|
714 } |
|
715 |
|
716 |
|
717 TInt index = iPresentUids.Find(aUid.iUid); |
|
718 if(index != NULL) |
|
719 { CComponentEntry* entry = CComponentEntry::NewLC(); |
|
720 TUid uid ; |
|
721 uid.Uid(iPresentUids.operator [](index)); |
|
722 TComponentId componentId = iScr->GetComponentIdForAppL(uid); |
|
723 iScr->GetComponentL(componentId,*entry); |
|
724 HBufC* versionPresent = entry->Version().AllocLC(); |
|
725 CleanupStack::PopAndDestroy(entry); |
|
726 HBufC* versionBackUpComponent = entries->Version().AllocLC(); |
|
727 if((versionPresent->CompareC(versionBackUpComponent->Des())))//check version |
|
728 { |
|
729 //ignore Write a log statement as the midlet is same no need to do any thing :) |
|
730 } |
|
731 else |
|
732 { |
|
733 // delete it and thn register it |
|
734 TRAPD(err ,iScr->DeleteApplicationEntriesL(componentId)); |
|
735 if (KErrNone == err) |
|
736 { |
|
737 iScr->DeleteComponentL(componentId); |
|
738 } |
|
739 // call register |
|
740 TComponentId newComponentId = RegisterComponentL(*entries,uid,url->Des(),midletDescription->Des(),midletDeletionConformation->Des(),dnUrl->Des(),mediaID,domainCategory->Des(),SettingsValue->Des(),componentFilesArray,isComponentPresent,localizableComponentInfoArray); |
|
741 for(j=0; j < appinfoArray.Count() ; j++) |
|
742 { |
|
743 CAppInfo* appInfo = appinfoArray.operator [](j); |
|
744 |
|
745 RegisterApplicationL(newComponentId,appInfo->GetAppUid(),appInfo->GetCaption(),appInfo->GetAppIcon()->Des(),appInfo->NoOfIcons(),appInfo->GetLanguage()); |
|
746 CleanupStack::PopAndDestroy(appInfo); |
|
747 } |
|
748 } |
|
749 CleanupStack::PopAndDestroy(versionPresent); |
|
750 CleanupStack::PopAndDestroy(versionBackUpComponent); |
|
751 } |
|
752 else |
|
753 { |
|
754 //just go register it as its not there in the phone |
|
755 TComponentId newComponentId = RegisterComponentL(*entries,aUid,url->Des(),midletDescription->Des(),midletDeletionConformation->Des(),dnUrl->Des(),mediaID,domainCategory->Des(),SettingsValue->Des(),componentFilesArray,isComponentPresent,localizableComponentInfoArray); |
|
756 for(j=0; j < appinfoArray.Count() ; j++) |
|
757 { |
|
758 CAppInfo* appInfo = appinfoArray.operator [](j); |
|
759 |
|
760 RegisterApplicationL(newComponentId,appInfo->GetAppUid(),appInfo->GetCaption(),appInfo->GetAppIcon()->Des(),appInfo->NoOfIcons(),appInfo->GetLanguage()); |
|
761 CleanupStack::PopAndDestroy(appInfo); |
|
762 } |
|
763 } |
|
764 |
|
765 //CleanupStack::Pop();//componentFilesArray |
|
766 CleanupStack::PopAndDestroy( entries); |
|
767 |
|
768 LOG(EBackup,EInfo," <--- SetDataInScrL() "); |
|
769 } |
|
770 |
|
771 |
|
772 TComponentId CScrBackupUtil::RegisterComponentL(CComponentEntry& aEntry ,TUid aUid,TPtr aMidletInfoUrl, |
|
773 TPtr aMidletDescription,TPtr8 aMidletDeletionConformation, TPtr aDownloadUrl,TInt64 aMediaId,TPtr aDomainCatogary , TPtr aSettingValue, |
|
774 RPointerArray<HBufC>& aComponentFilesArray, TBool aIsComponentPresent,RPointerArray<CLocalizableComponentInfo>& aLocalizableComponentInfoArray) |
|
775 { |
|
776 LOG(EBackup,EInfo," ---> RegisterComponentL() "); |
|
777 HBufC* globalId =( aEntry.GlobalId()).AllocLC(); |
|
778 |
|
779 TComponentId componentId = iScr->AddComponentL(aLocalizableComponentInfoArray,Usif::KSoftwareTypeJava,globalId); |
|
780 |
|
781 |
|
782 |
|
783 iScr->SetComponentVersionL(componentId, aEntry.Version()); |
|
784 //LOG1(EJavaInstaller, EInfo, "RegisterComponentL: version set %s",*version); |
|
785 |
|
786 iScr->SetIsComponentRemovableL(componentId, aEntry.IsRemovable()); |
|
787 |
|
788 |
|
789 iScr->SetIsComponentDrmProtectedL(componentId, aEntry.IsDrmProtected()); |
|
790 |
|
791 |
|
792 iScr->SetIsComponentKnownRevokedL(componentId,aEntry.IsKnownRevoked()); |
|
793 |
|
794 |
|
795 iScr->SetIsComponentOriginVerifiedL(componentId, aEntry.IsOriginVerified()); |
|
796 |
|
797 |
|
798 iScr->SetComponentSizeL(componentId, aEntry.ComponentSize()); |
|
799 |
|
800 |
|
801 iScr->SetScomoStateL(componentId,aEntry.ScomoState()); |
|
802 |
|
803 |
|
804 iScr->SetIsComponentPresentL(componentId,aIsComponentPresent); |
|
805 |
|
806 |
|
807 |
|
808 iScr->SetComponentPropertyL(componentId,KUid(), aUid.iUid); |
|
809 |
|
810 |
|
811 iScr->SetComponentPropertyL(componentId,KMIDletInfoURL(),aMidletInfoUrl); |
|
812 |
|
813 iScr->SetComponentPropertyL(componentId, KMIDletDescription(), aMidletDescription); |
|
814 |
|
815 iScr->SetComponentPropertyL(componentId,KMIDletDeletionConformation(),aMidletDeletionConformation); |
|
816 |
|
817 iScr->SetComponentPropertyL(componentId, KDownloadURL(), aDownloadUrl); |
|
818 |
|
819 iScr->SetComponentPropertyL(componentId,KDomainCategory(),aDomainCatogary); |
|
820 |
|
821 iScr->SetComponentPropertyL(componentId, KMediaId(), aMediaId); |
|
822 |
|
823 |
|
824 iScr->SetComponentPropertyL(componentId, KSettingsPlugin(), aSettingValue); |
|
825 |
|
826 |
|
827 CleanupStack::PopAndDestroy(globalId); |
|
828 |
|
829 TInt fileCount = aComponentFilesArray.Count(); |
|
830 for (TInt i = 0; i < fileCount; i++) |
|
831 { |
|
832 HBufC *componentFile = aComponentFilesArray.operator [](i); |
|
833 iScr->RegisterComponentFileL(componentId, *componentFile); |
|
834 CleanupStack::PopAndDestroy(componentFile); |
|
835 } |
|
836 LOG(EBackup,EInfo," <--- RegisterComponentL() "); |
|
837 return componentId; |
|
838 } |
|
839 |
|
840 void CScrBackupUtil::RegisterApplicationL(TInt aComponentId, TUid aAppUid, |
|
841 TAppCaption aAppName, TDesC aIconFilename, TInt aNumberOfIcons, |
|
842 TLanguage aLanguages) |
|
843 { |
|
844 LOG(EBackup,EInfo," ---> RegisterApplicationL() "); |
|
845 TFileName appName; |
|
846 RPointerArray<HBufC> ownedFileArray; // codescanner::resourcenotoncleanupstack |
|
847 RPointerArray<Usif::CServiceInfo> serviceArray; // codescanner::resourcenotoncleanupstack |
|
848 RPointerArray<Usif::CPropertyEntry> appPropertiesArray; // codescanner::resourcenotoncleanupstack |
|
849 RPointerArray<Usif::CAppViewData> viewDataList; // codescanner::resourcenotoncleanupstack |
|
850 |
|
851 RPointerArray<Usif::COpaqueData> opaqueDataArray; |
|
852 CleanupResetAndDestroyPushL(opaqueDataArray); |
|
853 // Write application Uid to opaque data (needed by MIDlet launcher). |
|
854 TBuf8<4> opaqueDataBuf; // Opaque data will contain one signed 32-bit int. |
|
855 RDesWriteStream writeStream(opaqueDataBuf); |
|
856 writeStream.WriteInt32L(aAppUid.iUid); |
|
857 writeStream.CommitL(); |
|
858 |
|
859 |
|
860 |
|
861 COpaqueData *opaqueData = COpaqueData::NewLC(opaqueDataBuf, KUnspecifiedLocale); |
|
862 opaqueDataArray.AppendL(opaqueData); |
|
863 CleanupStack::Pop(opaqueData); |
|
864 |
|
865 RPointerArray<Usif::CLocalizableAppInfo> localizableAppInfoList; |
|
866 CleanupResetAndDestroyPushL(localizableAppInfoList); |
|
867 // Add non-localized application name (caption) and icon. |
|
868 |
|
869 CCaptionAndIconInfo *captionAndIconInfo = CCaptionAndIconInfo::NewLC(aAppName,aIconFilename,aNumberOfIcons); |
|
870 |
|
871 CLocalizableAppInfo *locAppInfo = CLocalizableAppInfo::NewLC(/*aShortCaption=*/ KNullDesC,KNonLocalized, |
|
872 /*aGroupName=*/ KNullDesC,captionAndIconInfo,viewDataList); |
|
873 localizableAppInfoList.AppendL(locAppInfo); |
|
874 |
|
875 CleanupStack::Pop(locAppInfo); |
|
876 CleanupStack::Pop(captionAndIconInfo); |
|
877 |
|
878 CCaptionAndIconInfo *tmpCaptionAndIconInfo =CCaptionAndIconInfo::NewLC(aAppName,/*aIconFileName=*/ KNullDesC,/*aNumOfAppIcons=*/ 0); |
|
879 CLocalizableAppInfo *tmpLocAppInfo = CLocalizableAppInfo::NewLC(/*aShortCaption=*/ KNullDesC,aLanguages,/*aGroupName=*/ KNullDesC, |
|
880 tmpCaptionAndIconInfo,/*aViewDataList=*/ viewDataList); |
|
881 localizableAppInfoList.AppendL(tmpLocAppInfo); |
|
882 |
|
883 CleanupStack::Pop(tmpLocAppInfo); |
|
884 CleanupStack::Pop(tmpCaptionAndIconInfo); |
|
885 |
|
886 |
|
887 |
|
888 // Create application registration data objects. |
|
889 TApplicationCharacteristics appCharacteristics; |
|
890 appCharacteristics.iAttributes = TApaAppCapability::ENonNative; |
|
891 appCharacteristics.iEmbeddability = TApplicationCharacteristics::ENotEmbeddable; |
|
892 appCharacteristics.iSupportsNewFile = EFalse; |
|
893 appCharacteristics.iAppIsHidden = EFalse; |
|
894 appCharacteristics.iLaunchInBackground = EFalse; |
|
895 |
|
896 CApplicationRegistrationData *appRegData = |
|
897 CApplicationRegistrationData::NewLC(ownedFileArray, serviceArray,localizableAppInfoList,appPropertiesArray,opaqueDataArray, |
|
898 /*aAppUid=*/ aAppUid, /*aAppFile=*/ appName,/*aCharacteristics=*/ appCharacteristics,/*aDefaultScreenNumber=*/ 0); |
|
899 |
|
900 LOG(EJavaInstaller, EInfo,"RegisterApplicationL : Called AddApplicationEntryL >>>>>>>>>>>> "); |
|
901 iScr->AddApplicationEntryL(aComponentId, *appRegData); |
|
902 CleanupStack::PopAndDestroy(appRegData); |
|
903 |
|
904 |
|
905 CleanupStack::Pop(&localizableAppInfoList); // deleted in appRegData destructor |
|
906 CleanupStack::Pop(&opaqueDataArray); // deleted in appRegData destructor |
|
907 |
|
908 LOG(EBackup,EInfo," <--- RegisterApplicationL() "); |
|
909 } |
|
910 |
|
911 CScrBackupUtil::~CScrBackupUtil() |
|
912 { |
|
913 LOG(EBackup,EInfo," ---> ~CScrBackupUtil() "); |
|
914 |
|
915 if(iScr) |
|
916 { |
|
917 iScr->Close(); |
|
918 delete iScr; |
|
919 iScr = NULL; |
|
920 } |
|
921 if(iRemainingInfo) |
|
922 { |
|
923 delete iRemainingInfo; |
|
924 iRemainingInfo = NULL; |
|
925 } |
|
926 |
|
927 LOG(EBackup,EInfo," <--- ~CScrBackupUtil() "); |
|
928 } |
|
929 |
|
930 CAppInfo* CAppInfo::NewL() |
|
931 { |
|
932 LOG(EBackup,EInfo," ---> CAppInfo:NewL()"); |
|
933 CAppInfo *self = CAppInfo::NewLC(); |
|
934 CleanupStack::Pop(self); |
|
935 LOG(EBackup,EInfo," <--- CAppInfo:NewL()"); |
|
936 return self; |
|
937 } |
|
938 |
|
939 |
|
940 CAppInfo* CAppInfo::NewLC() |
|
941 { |
|
942 LOG(EBackup,EInfo," ---> CAppInfo:NewLC"); |
|
943 CAppInfo *self = new(ELeave) CAppInfo(); |
|
944 CleanupStack::PushL(self); |
|
945 self->ConstructL(); |
|
946 LOG(EBackup,EInfo," <---CAppInfo:NewLC"); |
|
947 return self; |
|
948 } |
|
949 CAppInfo::CAppInfo() |
|
950 { |
|
951 |
|
952 } |
|
953 void CAppInfo::ConstructL() |
|
954 { |
|
955 LOG(EBackup,EInfo," ---> CAppInfo:ConstructL "); |
|
956 |
|
957 |
|
958 |
|
959 LOG(EBackup,EInfo," <--- CAppInfo:ConstructL()"); |
|
960 } |
|
961 CAppInfo::~CAppInfo() |
|
962 { |
|
963 LOG(EBackup,EInfo," ---> CAppInfo:~CAppInfo() "); |
|
964 if(iAppIcon) |
|
965 { |
|
966 delete iAppIcon; |
|
967 } |
|
968 LOG(EBackup,EInfo," <--- CAppInfo:~CAppInfo() "); |
|
969 } |
|
970 |
|
971 void CAppInfo::Set(TLanguage language,TUid appUid,Usif::TAppCaption caption,TDesC& appIcon,TInt aNoOfIcons) |
|
972 { |
|
973 LOG(EBackup,EInfo," ---> CAppInfo:Set() "); |
|
974 iLanguage = language; |
|
975 iAppUid = appUid; |
|
976 iCaption = caption; |
|
977 iAppIcon->Des().Copy(appIcon); |
|
978 iNoOfIcons = aNoOfIcons; |
|
979 LOG(EBackup,EInfo," <--- CAppInfo:Set() "); |
|
980 |
|
981 } |
|
982 TLanguage CAppInfo::GetLanguage() |
|
983 { |
|
984 LOG(EBackup,EInfo," ---> CAppInfo:GetLanguage() "); |
|
985 LOG(EBackup,EInfo," <--- CAppInfo:GetLanguage() "); |
|
986 return iLanguage; |
|
987 } |
|
988 TUid CAppInfo::GetAppUid() |
|
989 { |
|
990 LOG(EBackup,EInfo," ---> CAppInfo:GetAppUid() "); |
|
991 LOG(EBackup,EInfo," <--- CAppInfo:GetAppUid() "); |
|
992 return iAppUid; |
|
993 } |
|
994 Usif::TAppCaption CAppInfo::GetCaption() |
|
995 { |
|
996 LOG(EBackup,EInfo," ---> CAppInfo:GetCaption() "); |
|
997 LOG(EBackup,EInfo," <--- CAppInfo:GetCaption() "); |
|
998 return iCaption; |
|
999 |
|
1000 } |
|
1001 HBufC* CAppInfo::GetAppIcon() |
|
1002 { |
|
1003 LOG(EBackup,EInfo," ---> CAppInfo:GetAppIcon() "); |
|
1004 LOG(EBackup,EInfo," <--- CAppInfo:GetAppIcon() "); |
|
1005 return iAppIcon; |
|
1006 |
|
1007 } |
|
1008 |
|
1009 TInt CAppInfo::NoOfIcons() |
|
1010 { |
|
1011 LOG(EBackup,EInfo," ---> CAppInfo:NoOfIcons() "); |
|
1012 LOG(EBackup,EInfo," <--- CAppInfo:NoOfIcons() "); |
|
1013 return iNoOfIcons; |
|
1014 } |
|