|
1 /* |
|
2 * Copyright (c) 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: MidletPackageInfo Factory implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <caf/caf.h> // ContentAccess::CContent |
|
20 |
|
21 #include "appmngr2midletpckginfofactory.h" // CAppMngr2MidletPakageInfoFactory |
|
22 #include "appmngr2midletpackageinfo.h" // CAppMngr2MidletPackageInfo |
|
23 #include "appmngr2recognizedfile.h" // CAppMngr2RecognizedFile |
|
24 #include "appmngr2midletresourcehandler.h" // CAppMngr2MidletResourceHandler |
|
25 |
|
26 #include "logger.h" // LOG |
|
27 |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CAppMngr2MidletPackageInfo::NewL() |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CAppMngr2MidletPckgInfoFactory* CAppMngr2MidletPckgInfoFactory::NewL( |
|
36 CAppMngr2Runtime& aRuntime, RFs& aFs, CAppMngr2MidletResourceHandler& aResourceHandler) |
|
37 { |
|
38 LOG(EJavaAppMngrPlugin, EInfo, "+ CAppMngr2MidletPckgInfoFactory::NewL "); |
|
39 CAppMngr2MidletPckgInfoFactory* self |
|
40 = new(ELeave) CAppMngr2MidletPckgInfoFactory(aRuntime, aFs, aResourceHandler); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop(self); |
|
44 LOG(EJavaAppMngrPlugin, EInfo, "- CAppMngr2MidletPckgInfoFactory::NewL "); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CAppMngr2MidletPckgInfoFactory::~CAppMngr2MidletPckgInfoFactory() |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CAppMngr2MidletPckgInfoFactory::~CAppMngr2MidletPckgInfoFactory() |
|
53 { |
|
54 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::~CAppMngr2MidletPckgInfoFactory "); |
|
55 Cancel(); |
|
56 delete iMatcher; |
|
57 iMatcher = NULL; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // CAppMngr2MidletPckgInfoFactory::GetInstallationFilesL() |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void CAppMngr2MidletPckgInfoFactory::GetInstallationFilesL( |
|
65 RPointerArray<CAppMngr2PackageInfo>& aPackageInfos, |
|
66 const RPointerArray<CAppMngr2RecognizedFile>& aFileList, |
|
67 TRequestStatus& aStatus) |
|
68 { |
|
69 LOG(EJavaAppMngrPlugin, EInfo, "+ CAppMngr2MidletPckgInfoFactory::GetInstallationFilesL "); |
|
70 |
|
71 if (IsActive()) |
|
72 { |
|
73 User::Leave(KErrInUse); |
|
74 } |
|
75 |
|
76 iCounter = 0; |
|
77 iState = ENextPckg; |
|
78 iPackageInfos = &aPackageInfos; |
|
79 iFileList = &aFileList; |
|
80 iExtStatus = &aStatus; |
|
81 *iExtStatus = KRequestPending; |
|
82 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::GetInstallationFilesL:SetActive()"); |
|
83 SetActive(); |
|
84 CompleteRequest(iStatus, KErrNone); |
|
85 |
|
86 LOG(EJavaAppMngrPlugin, EInfo, "- CAppMngr2MidletPckgInfoFactory::GetInstallationFilesL "); |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CAppMngr2MidletPckgInfoFactory::RunL() |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CAppMngr2MidletPckgInfoFactory::RunL() |
|
94 { |
|
95 LOG1(EJavaAppMngrPlugin, EInfo, "+ CAppMngr2MidletPckgInfoFactory::RunL, iState: %d ", iState); |
|
96 |
|
97 CAppMngr2PackageInfo* packageInfo = NULL; |
|
98 |
|
99 switch (iState) |
|
100 { |
|
101 case ENextPckg : |
|
102 { |
|
103 if (iCounter < iFileList->Count()) |
|
104 { |
|
105 LOG1(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::RunL:ENextPckg: iCounter = %d", iCounter); |
|
106 |
|
107 // skip processing if this files was already matched |
|
108 TBool found(EFalse); |
|
109 CAppMngr2RecognizedFile* recognized = (*iFileList)[iCounter]; // not owned |
|
110 for (TInt i(0); i < iPackageInfos->Count(); i++) |
|
111 { |
|
112 CAppMngr2MidletPackageInfo* package |
|
113 = static_cast<CAppMngr2MidletPackageInfo*>((*iPackageInfos)[i]); // not owned |
|
114 |
|
115 if ((recognized->FileName() == package->JadFileName()) |
|
116 || (recognized->FileName() == package->JarFileName())) |
|
117 { |
|
118 found = ETrue; |
|
119 break; |
|
120 } |
|
121 } |
|
122 |
|
123 if (found) |
|
124 { |
|
125 // Continue with next file |
|
126 iCounter++; |
|
127 iState = ENextPckg; |
|
128 CompleteRequest(iStatus, KErrNone); |
|
129 } |
|
130 else |
|
131 { |
|
132 // Get installation file |
|
133 // Counter must be incremented before leave |
|
134 TInt index = iCounter; |
|
135 iCounter++; |
|
136 GetInstallationFileL((*iFileList)[index]->FileName(), |
|
137 (*iFileList)[index]->DataType()); |
|
138 // GetInstallationFileL() changes iState |
|
139 } |
|
140 |
|
141 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::RunL:ENextPckg:SetActive()"); |
|
142 SetActive(); |
|
143 } |
|
144 else |
|
145 { |
|
146 // File name list has been processed |
|
147 // Let's complete GetInstallationFilesL |
|
148 User::RequestComplete(iExtStatus, KErrNone); |
|
149 } |
|
150 break; |
|
151 } |
|
152 case EMatchedJar : |
|
153 { |
|
154 if (iJadFile.Length() == 0) |
|
155 { |
|
156 // Standalone JAR |
|
157 iJadFile = KNullDesC; |
|
158 } |
|
159 iState = EAppendPckg; // Next state |
|
160 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::RunL:EMatchedJar:SetActive()"); |
|
161 SetActive(); |
|
162 CompleteRequest(iStatus, KErrNone); |
|
163 break; |
|
164 } |
|
165 case EMatchedJad : |
|
166 { |
|
167 if (iJarFile.Length() == 0) |
|
168 { |
|
169 // Standalone JAD |
|
170 iJarFile = KNullDesC; |
|
171 } |
|
172 iState = EAppendPckg; // Next state |
|
173 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::RunL:EMatchedJad:SetActive()"); |
|
174 SetActive(); |
|
175 CompleteRequest(iStatus, KErrNone); |
|
176 break; |
|
177 } |
|
178 case EAppendPckg : |
|
179 { |
|
180 packageInfo = CAppMngr2MidletPackageInfo::NewL( |
|
181 iRuntime, iJadFile, iJarFile, iFs, iResourceHandler); |
|
182 CleanupStack::PushL(packageInfo); |
|
183 iPackageInfos->AppendL(packageInfo); |
|
184 |
|
185 CleanupStack::Pop(packageInfo); |
|
186 iState = ENextPckg; // Next state |
|
187 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::RunL:EAppendPckg:SetActive()"); |
|
188 SetActive(); |
|
189 CompleteRequest(iStatus, KErrNone); |
|
190 break; |
|
191 } |
|
192 default : |
|
193 { |
|
194 LOG1(EJavaAppMngrPlugin, EInfo, " Incorrect state, iCounter = %d", iCounter); |
|
195 |
|
196 User::RequestComplete(iExtStatus, KErrGeneral); |
|
197 break; |
|
198 } |
|
199 } |
|
200 |
|
201 LOG(EJavaAppMngrPlugin, EInfo, "- CAppMngr2MidletPckgInfoFactory::RunL "); |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // CAppMngr2MidletPckgInfoFactory::DoCancel() |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 void CAppMngr2MidletPckgInfoFactory::DoCancel() |
|
209 { |
|
210 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::DoCancel "); |
|
211 CancelMatching(); |
|
212 if (iExtStatus->Int() == KRequestPending) |
|
213 { |
|
214 User::RequestComplete(iExtStatus, KErrCancel); |
|
215 } |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // CAppMngr2MidletPckgInfoFactory::RunError() |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 TInt CAppMngr2MidletPckgInfoFactory::RunError(TInt /*aError*/) |
|
223 { |
|
224 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::RunError "); |
|
225 // Creation of pckg info fails continue with next one |
|
226 iState = ENextPckg; // Next state |
|
227 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::RunError:SetActive()"); |
|
228 SetActive(); |
|
229 CompleteRequest(iStatus, KErrGeneral); |
|
230 return KErrNone; |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CAppMngr2MidletPckgInfoFactory::GetInstallationFileL() |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 void CAppMngr2MidletPckgInfoFactory |
|
238 ::GetInstallationFileL(const TDesC& aFileName, const TDataType& aDataType) |
|
239 |
|
240 { |
|
241 LOG(EJavaAppMngrPlugin, EInfo, "+ CAppMngr2MidletPckgInfoFactory::GetInstallationFileL "); |
|
242 |
|
243 TInt err(KErrNone); |
|
244 iJadFile.Zero(); |
|
245 iJarFile.Zero(); |
|
246 |
|
247 // Check MIME type |
|
248 TPtrC8 mimePtr8(aDataType.Des8()); |
|
249 if (mimePtr8 == SwiUI::KJarMIMEType) |
|
250 { |
|
251 // JAR |
|
252 iJarFile = aFileName; |
|
253 // Matching JAR's JAD. MatchL is internally asynchronous |
|
254 TRAP(err, MatchL(iJarFile, SwiUI::KJarMIMEType, iJadFile, iStatus)); |
|
255 |
|
256 if (err != KErrNone) |
|
257 { |
|
258 // Corrupted JAR, allow to create standalone package |
|
259 CancelMatching(); |
|
260 iState = EAppendPckg; // Next state |
|
261 CompleteRequest(iStatus, KErrNone); |
|
262 } |
|
263 iState = EMatchedJar; // Next state |
|
264 } |
|
265 else if (mimePtr8 == SwiUI::KJadMIMEType) |
|
266 { |
|
267 // JAD |
|
268 iJadFile = aFileName; |
|
269 // Matching JAD's JAR. MatchL is internally asynchronous |
|
270 TRAP(err, MatchL(iJadFile, SwiUI::KJadMIMEType, iJarFile, iStatus)); |
|
271 |
|
272 if (err != KErrNone) |
|
273 { |
|
274 // Corrupted JAD, allow to create standalone package |
|
275 CancelMatching(); |
|
276 iState = EAppendPckg; // Next state |
|
277 CompleteRequest(iStatus, KErrNone); |
|
278 } |
|
279 iState = EMatchedJad; // Next state |
|
280 } |
|
281 else |
|
282 { |
|
283 // File name is not recognized |
|
284 User::Leave(KErrGeneral); |
|
285 } |
|
286 |
|
287 LOG(EJavaAppMngrPlugin, EInfo, "- CAppMngr2MidletPckgInfoFactory::GetInstallationFileL "); |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // CAppMngr2MidletPckgInfoFactory::CAppMngr2MidletPckgInfoFactory() |
|
292 // --------------------------------------------------------------------------- |
|
293 // |
|
294 CAppMngr2MidletPckgInfoFactory |
|
295 ::CAppMngr2MidletPckgInfoFactory(CAppMngr2Runtime& aRuntime, RFs& aFs, CAppMngr2MidletResourceHandler& aResourceHandler) : |
|
296 CActive(CActive::EPriorityStandard), iFs(aFs), iRuntime(aRuntime), iResourceHandler(aResourceHandler) |
|
297 { |
|
298 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::CAppMngr2MidletPckgInfoFactory "); |
|
299 CActiveScheduler::Add(this); |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // CAppMngr2MidletPckgInfoFactory::ConstructL() |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 void CAppMngr2MidletPckgInfoFactory::ConstructL() |
|
307 { |
|
308 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::ConstructL "); |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // CAppMngr2MidletPckgInfoFactory::CompleteRequest() |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 void CAppMngr2MidletPckgInfoFactory::CompleteRequest(TRequestStatus& aRequestStatus, |
|
316 TInt aStatus) |
|
317 { |
|
318 LOG(EJavaAppMngrPlugin, EInfo, "CAppMngr2MidletPckgInfoFactory::CompleteRequest "); |
|
319 TRequestStatus* status = &aRequestStatus; |
|
320 User::RequestComplete(status, aStatus); |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CAppMngr2MidletPckgInfoFactory::MatchL() |
|
325 // ----------------------------------------------------------------------------- |
|
326 // |
|
327 void CAppMngr2MidletPckgInfoFactory::MatchL(const TDesC& aMatchingFileName, |
|
328 const TDesC8& aMatchingMimeType, |
|
329 TDes& aMatchedFileName, |
|
330 TRequestStatus &aStatus) |
|
331 { |
|
332 LOG(EJavaAppMngrPlugin, EInfo, " + CAppMngr2MidletPckgInfoFactory::MatchL "); |
|
333 TParse parser; |
|
334 User::LeaveIfError(parser.Set(aMatchingFileName, NULL, NULL)); |
|
335 |
|
336 if (!iMatcher) |
|
337 { |
|
338 iMatcher = CJcfJadJarMatcher::NewL(this, iFs); |
|
339 } |
|
340 |
|
341 if (aMatchingMimeType == SwiUI::KJarMIMEType) |
|
342 { |
|
343 iMatcher->MatchJadL( |
|
344 aMatchingFileName, parser.DriveAndPath(), &aMatchedFileName); |
|
345 } |
|
346 else if (aMatchingMimeType == SwiUI::KJadMIMEType) |
|
347 { |
|
348 iMatcher->MatchJarL( |
|
349 aMatchingFileName, parser.DriveAndPath(), &aMatchedFileName); |
|
350 } |
|
351 else |
|
352 { |
|
353 User::Leave(KErrGeneral); |
|
354 } |
|
355 |
|
356 aStatus = KRequestPending; |
|
357 LOG(EJavaAppMngrPlugin, EInfo, " - CAppMngr2MidletPckgInfoFactory::MatchL "); |
|
358 } |
|
359 |
|
360 // --------------------------------------------------------------------------- |
|
361 // CAppMngr2MidletPckgInfoFactory::CancelMathing() |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 void CAppMngr2MidletPckgInfoFactory::CancelMatching() |
|
365 { |
|
366 LOG(EJavaAppMngrPlugin, EInfo, " + CAppMngr2MidletPckgInfoFactory::CancelMatching "); |
|
367 delete iMatcher; |
|
368 iMatcher = NULL; |
|
369 LOG(EJavaAppMngrPlugin, EInfo, " - CAppMngr2MidletPckgInfoFactory::CancelMatching "); |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------------------------- |
|
373 // CAppMngr2MidletPckgInfoFactory::Update() |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 void CAppMngr2MidletPckgInfoFactory::Update(TInt aArg1) |
|
377 { |
|
378 LOG(EJavaAppMngrPlugin, EInfo, " CAppMngr2MidletPckgInfoFactory::UpdateL "); |
|
379 CompleteRequest(iStatus, aArg1); |
|
380 } |