|
1 /* |
|
2 * Copyright (c) 2005-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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "backuprestore.h" |
|
20 |
|
21 #include <s32mem.h> |
|
22 |
|
23 #include "sisregistryentry.h" |
|
24 #include "sisregistrywritableentry.h" |
|
25 #include "siscontroller.h" |
|
26 #include "cleanuputils.h" |
|
27 #include "sisregistrypackage.h" |
|
28 #include "log.h" |
|
29 |
|
30 |
|
31 namespace Swi |
|
32 { |
|
33 |
|
34 EXPORT_C TInt RBackupSession::Connect() |
|
35 { |
|
36 DEBUG_PRINTF(_L8("RBackupSession::Connect")); |
|
37 return iSession.Connect(); |
|
38 } |
|
39 |
|
40 EXPORT_C void RBackupSession::Close() |
|
41 { |
|
42 DEBUG_PRINTF(_L8("RBackupSession::Close")); |
|
43 iSession.Close(); |
|
44 } |
|
45 |
|
46 EXPORT_C HBufC8* RBackupSession::GetMetaDataL(TUid aPackageUid, RPointerArray<HBufC>& aFilesArray) |
|
47 { |
|
48 DEBUG_PRINTF2(_L8("Getting backup meta data for puid=0x%08x"), aPackageUid.iUid); |
|
49 RSisRegistryWritableEntry entry; |
|
50 User::LeaveIfError(entry.Open(iSession, aPackageUid)); |
|
51 CleanupClosePushL(entry); |
|
52 |
|
53 RPointerArray<HBufC8> controllers; |
|
54 entry.ControllersL(controllers); |
|
55 CleanupResetAndDestroyPushL(controllers); |
|
56 |
|
57 const TInt KDefaultBufferSize = 2048; |
|
58 |
|
59 CBufFlat* tempBuffer = CBufFlat::NewL(KDefaultBufferSize); |
|
60 CleanupStack::PushL(tempBuffer); |
|
61 |
|
62 // Include the drive letter at the head of the metadata |
|
63 TChar drive = entry.SelectedDriveL(); |
|
64 RArray<TLanguage> matchingSupportedLanguagesArray; |
|
65 CleanupClosePushL(matchingSupportedLanguagesArray); |
|
66 entry.GetMatchingSupportedLanguagesL(matchingSupportedLanguagesArray); |
|
67 // Appending ELangNone at the end as marker for the end of the language IDs |
|
68 // as we also append the language ID's from Augmentations |
|
69 matchingSupportedLanguagesArray.AppendL(ELangNone); |
|
70 |
|
71 RPointerArray<CSisRegistryPackage> packages; |
|
72 CleanupResetAndDestroyPushL(packages); |
|
73 entry.AugmentationsL(packages); |
|
74 |
|
75 RBufWriteStream stream(*tempBuffer); |
|
76 CleanupClosePushL(stream); |
|
77 stream.WriteUint32L(drive); |
|
78 |
|
79 // backup the base package (except for PA and ROM stubs) plus partial upgrades and augmentations. |
|
80 entry.FilesL(aFilesArray); |
|
81 |
|
82 |
|
83 // Filter out any files on the Z drive |
|
84 TInt fileIndex = aFilesArray.Count() - 1; |
|
85 while (fileIndex >= 0) |
|
86 { |
|
87 TChar driveCh = (*aFilesArray[fileIndex])[0]; |
|
88 if (driveCh == 'z' || driveCh == 'Z') |
|
89 { |
|
90 delete aFilesArray[fileIndex]; |
|
91 aFilesArray.Remove(fileIndex); |
|
92 } |
|
93 --fileIndex; |
|
94 } |
|
95 |
|
96 TInt controllersCount = controllers.Count(); |
|
97 TInt firstController = 0; |
|
98 if (entry.PreInstalledL() || entry.IsInRomL()) |
|
99 { |
|
100 firstController = 1; // Don't backup the controller for the ROM stub |
|
101 if (controllersCount <= 1) |
|
102 { |
|
103 DEBUG_PRINTF(_L8("Base package is pre-installed or in ROM and has not been upgraded")); |
|
104 stream.WriteInt32L(packages.Count()); |
|
105 if (entry.IsInRomL()) |
|
106 { |
|
107 matchingSupportedLanguagesArray.Close(); |
|
108 } |
|
109 } |
|
110 else |
|
111 { |
|
112 // Backup any PUs for the ROM stub. |
|
113 DEBUG_PRINTF2(_L8("Found %d partial upgrades"), controllersCount - 1); |
|
114 stream.WriteInt32L(controllersCount - 1 + packages.Count()); |
|
115 } |
|
116 } |
|
117 else |
|
118 { |
|
119 // Standard SA package |
|
120 DEBUG_PRINTF2(_L8("Found %d controllers"), controllersCount); |
|
121 stream.WriteInt32L(controllers.Count() + packages.Count()); |
|
122 } |
|
123 |
|
124 for (TInt i = firstController; i < controllersCount; ++i) |
|
125 { |
|
126 stream << *controllers[i]; |
|
127 } |
|
128 |
|
129 TInt augmentationCount(packages.Count()); |
|
130 RArray<TChar> augmentationDrives; |
|
131 CleanupClosePushL(augmentationDrives); |
|
132 |
|
133 for (TInt i = 0; i < augmentationCount; ++i) |
|
134 { |
|
135 RSisRegistryEntry augmentation; |
|
136 augmentation.OpenL(iSession, *packages[i]); |
|
137 CleanupClosePushL(augmentation); |
|
138 |
|
139 augmentation.FilesL(aFilesArray); |
|
140 |
|
141 RPointerArray<HBufC8> augmentationControllers; |
|
142 CleanupResetAndDestroyPushL(augmentationControllers); |
|
143 augmentation.ControllersL(augmentationControllers); |
|
144 |
|
145 stream << *augmentationControllers[0]; |
|
146 |
|
147 DEBUG_PRINTF3(_L("Augmentation %d installed to drive %d"), i, augmentation.SelectedDriveL().GetNumericValue()); |
|
148 // The drives for all SPs need to be appended after the file to |
|
149 // list to preserve BC with backup data created before SP drives |
|
150 // were backed up. |
|
151 augmentationDrives.AppendL(augmentation.SelectedDriveL()); |
|
152 // Get the matching supported languages |
|
153 entry.GetMatchingSupportedLanguagesL(matchingSupportedLanguagesArray); |
|
154 |
|
155 // Appending ELangNone at the end as marker for the end of the language IDs |
|
156 // as we also append the language ID's from other Augmentations |
|
157 matchingSupportedLanguagesArray.Append(ELangNone); |
|
158 |
|
159 CleanupStack::PopAndDestroy(2, &augmentation); |
|
160 } |
|
161 |
|
162 // Write the number of files originally installed, |
|
163 // and their names to the backup metadata |
|
164 TInt filesCount(aFilesArray.Count()); |
|
165 DEBUG_PRINTF2(_L8("Files installed originally %d"), filesCount); |
|
166 stream.WriteInt32L(filesCount); |
|
167 for (TInt i = 0; i < filesCount; ++i) |
|
168 { |
|
169 stream << *aFilesArray[i]; |
|
170 } |
|
171 |
|
172 // Add the selected drive for each augmentation in the same order as |
|
173 // as the list of controllers. The augmentation controllers will |
|
174 // be counted on restore to be sure to correct number of drives. |
|
175 for (TInt k = 0; k < augmentationCount; ++k) |
|
176 { |
|
177 stream.WriteUint32L(augmentationDrives[k]); |
|
178 } |
|
179 |
|
180 //Add the array of matching device supported languages |
|
181 TInt supportedLanguageCount = matchingSupportedLanguagesArray.Count(); |
|
182 |
|
183 stream.WriteInt32L(supportedLanguageCount); |
|
184 for (TInt k = 0; k < supportedLanguageCount; ++k) |
|
185 { |
|
186 stream.WriteInt32L(matchingSupportedLanguagesArray[k]); |
|
187 } |
|
188 |
|
189 stream.CommitL(); |
|
190 |
|
191 HBufC8* result = tempBuffer->Ptr(0).AllocL(); |
|
192 CleanupStack::PopAndDestroy(7, &entry); // augmentationDrives, stream, controllers, matchingSupportedLanguagesArray, tempBuffer, packages |
|
193 return result; |
|
194 |
|
195 } |
|
196 |
|
197 } |