|
1 /* |
|
2 * Copyright (c) 2007-2007 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: This Class provides information of Application installed on phone. |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <javaregistryentrytype.h> |
|
21 #include <e32cmn.h> |
|
22 #include "pkginfo.h" |
|
23 |
|
24 _LIT(KHEXAdd,"0x"); |
|
25 |
|
26 _LIT(KSEPERATOR , ":"); |
|
27 |
|
28 _LIT(KEDRIVE,"E"); |
|
29 |
|
30 _LIT(KCDRIVE,"C"); |
|
31 |
|
32 //(8*8) + (2 * 8) = 64 + 16 = 80 , 10 bytes + 1 = 11 bytes |
|
33 const TInt KUidLength = 20; |
|
34 // (1* 8) + (1 * 8) + (1* 8) = 24 , 3 bytes + 1 = 4 bytes |
|
35 const TInt KVersionLength = 4; |
|
36 |
|
37 const TInt KdriveLen = 1 ; |
|
38 |
|
39 const TInt KDeriveE = 4; |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CAppInfo::NewL |
|
42 // Returns the instance of CPkgInfo class. |
|
43 // ----------------------------------------------------------------------------- |
|
44 CPkgInfo* CPkgInfo::NewL( Swi::RSisRegistrySession* aSisRegSession) |
|
45 { |
|
46 CPkgInfo* self = new(ELeave) CPkgInfo(aSisRegSession); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CAppInfo::CPkgInfo |
|
56 // C++ constructor |
|
57 // ----------------------------------------------------------------------------- |
|
58 CPkgInfo::CPkgInfo( Swi::RSisRegistrySession* aSisRegSession):iSisRegSession(aSisRegSession) |
|
59 { |
|
60 |
|
61 } |
|
62 |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CAppInfo::NewL |
|
66 // Returns the instance of CPkgInfo class. |
|
67 // ----------------------------------------------------------------------------- |
|
68 CPkgInfo* CPkgInfo::NewL( Java::CJavaRegistry* aJavaReg) |
|
69 { |
|
70 CPkgInfo* self = new(ELeave) CPkgInfo(aJavaReg); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 CleanupStack::Pop(self); |
|
74 return self; |
|
75 } |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CAppInfo::CPkgInfo |
|
78 // C++ constructor |
|
79 // ----------------------------------------------------------------------------- |
|
80 CPkgInfo::CPkgInfo(Java::CJavaRegistry* aJavaReg):iJavaReg(aJavaReg) |
|
81 { |
|
82 |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CAppInfo::ConstructL |
|
87 // Two-Phase constructor |
|
88 // ----------------------------------------------------------------------------- |
|
89 void CPkgInfo::ConstructL() |
|
90 { |
|
91 iKeyArray = new(ELeave) CDesC8ArraySeg( KArrayGranularity ); |
|
92 //Inserting the Keys |
|
93 iKeyArray->AppendL(KPkgName); |
|
94 iKeyArray->AppendL(KUid); |
|
95 iKeyArray->AppendL(KVersion); |
|
96 iKeyArray->AppendL(KVendor); |
|
97 iKeyArray->AppendL(KDrive); |
|
98 |
|
99 for(TInt index = 0 ; index < iKeyArray->Count() ;index++) |
|
100 { |
|
101 iKeyValArray.AppendL(NULL); |
|
102 } |
|
103 |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CAppInfo::~CPkgInfo |
|
108 // Destructor |
|
109 // ----------------------------------------------------------------------------- |
|
110 CPkgInfo::~CPkgInfo() |
|
111 { |
|
112 |
|
113 if(iKeyArray) |
|
114 { |
|
115 iKeyArray->Reset(); |
|
116 delete iKeyArray; |
|
117 } |
|
118 |
|
119 iKeyValArray.ResetAndDestroy(); |
|
120 |
|
121 iSisRegEntry.Close(); |
|
122 |
|
123 if(iJavaRegEntry) |
|
124 { |
|
125 delete iJavaRegEntry; |
|
126 } |
|
127 |
|
128 iSisRegSession = NULL; |
|
129 |
|
130 iJavaReg = NULL; |
|
131 } |
|
132 |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CAppInfo::AtL |
|
136 // This function gives the key value at a given index |
|
137 // ----------------------------------------------------------------------------- |
|
138 TBool CPkgInfo::AtL(TInt aIndex, TDes8& aKeyVal) |
|
139 { |
|
140 |
|
141 if(0<= aIndex < iKeyArray->Count() ) |
|
142 { |
|
143 aKeyVal.Copy((*iKeyArray)[aIndex]); |
|
144 return ETrue; |
|
145 } |
|
146 else |
|
147 { |
|
148 return EFalse; |
|
149 } |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CAppInfo::Count |
|
154 // This function gives the number of keys |
|
155 // ----------------------------------------------------------------------------- |
|
156 TInt CPkgInfo::Count() const |
|
157 { |
|
158 return iKeyArray->Count(); |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CAppInfo::SetEntryL |
|
163 // This function sets the appropriate entry as per uid |
|
164 // ----------------------------------------------------------------------------- |
|
165 void CPkgInfo::SetEntryL(TUid aUid,TBool& aErrflg) |
|
166 { |
|
167 |
|
168 //It will accept the UID and also validate (i.e if that application currently prsent or not) |
|
169 if( iJavaReg ) |
|
170 { |
|
171 iJavaRegEntry = iJavaReg->RegistryEntryL(aUid); |
|
172 |
|
173 if( iJavaRegEntry ) |
|
174 { |
|
175 |
|
176 if( (Java::EGeneralPackage <= iJavaRegEntry->Type()) && (iJavaRegEntry->Type()< Java::EGeneralApplication) ) |
|
177 aErrflg = ETrue; |
|
178 else |
|
179 aErrflg = EFalse; |
|
180 |
|
181 if(aErrflg == EFalse) |
|
182 { |
|
183 delete iJavaRegEntry ; |
|
184 iJavaRegEntry = NULL ; |
|
185 } |
|
186 } |
|
187 else |
|
188 { |
|
189 aErrflg = EFalse; |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 |
|
195 User::LeaveIfError(iSisRegEntry.Open(*iSisRegSession,aUid)); |
|
196 |
|
197 aErrflg = (iSisRegEntry.IsPresentL() && !iSisRegEntry.IsInRomL()); |
|
198 if( aErrflg == EFalse ) |
|
199 { |
|
200 iSisRegEntry.Close(); |
|
201 } |
|
202 |
|
203 } |
|
204 |
|
205 } |
|
206 |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CAppInfo::FindL |
|
210 // This function finds the value as per key given in argument. |
|
211 // ----------------------------------------------------------------------------- |
|
212 TBool CPkgInfo::FindL(const TDesC8& aKey, TPtrC& aVal) |
|
213 { |
|
214 TBool retValue = EFalse; |
|
215 if(iJavaReg) |
|
216 { |
|
217 retValue = GetJavaInfoL(aKey,aVal); |
|
218 |
|
219 } // for iJavaRegEntry |
|
220 else |
|
221 { |
|
222 |
|
223 retValue = GetSisxInfoL(aKey,aVal); |
|
224 } |
|
225 return retValue; |
|
226 } |
|
227 |
|
228 // ----------------------------------------------------------------------------- |
|
229 // CPkgInfo::GetJavaInfo |
|
230 // Gives the value as per key input for java installed packages |
|
231 // ----------------------------------------------------------------------------- |
|
232 TBool CPkgInfo::GetJavaInfoL(const TDesC8& aKey, TPtrC& aVal) |
|
233 { |
|
234 TBool retVal = ETrue; |
|
235 TInt index = -1 ; |
|
236 |
|
237 if(aKey.CompareF(KPkgName)==KErrNone) |
|
238 { |
|
239 |
|
240 iKeyArray->Find(KPkgName,index); |
|
241 |
|
242 if(index >= 0) |
|
243 { |
|
244 if(NULL == iKeyValArray[index] ) |
|
245 { |
|
246 // create heap object |
|
247 HBufC* keyval = HBufC::NewL(iJavaRegEntry->Name().Length()); |
|
248 |
|
249 TPtr val(keyval->Des()); |
|
250 |
|
251 val.Append(iJavaRegEntry->Name()); |
|
252 |
|
253 iKeyValArray[index] = keyval; |
|
254 |
|
255 } |
|
256 |
|
257 aVal.Set(*iKeyValArray[index]); // Seting the TPtrC with the keyval in array |
|
258 |
|
259 } |
|
260 |
|
261 } |
|
262 else if(aKey.CompareF(KUid) == KErrNone) |
|
263 { |
|
264 |
|
265 iKeyArray->Find(KUid,index); |
|
266 |
|
267 if(index >= 0) |
|
268 { |
|
269 if(NULL == iKeyValArray[index]) |
|
270 { |
|
271 // Taking buffer for manipulation |
|
272 |
|
273 HBufC* keyval = HBufC::NewL(KUidLength); |
|
274 |
|
275 TPtr val(keyval->Des()); |
|
276 val.Append(KHEXAdd); |
|
277 val.AppendNum(iJavaRegEntry->Uid().iUid,EHex); |
|
278 |
|
279 iKeyValArray[index] = keyval; |
|
280 |
|
281 } |
|
282 |
|
283 aVal.Set(*iKeyValArray[index]); // Seting the TPtrC with the keyval in array |
|
284 |
|
285 } |
|
286 } |
|
287 else if(aKey.CompareF(KVersion) == KErrNone) |
|
288 { |
|
289 |
|
290 iKeyArray->Find(KVersion,index); |
|
291 |
|
292 if(index >= 0) |
|
293 { |
|
294 if(NULL == iKeyValArray[index]) |
|
295 { |
|
296 // Taking buffer for manipulation |
|
297 |
|
298 HBufC* keyval = HBufC::NewL(KVersionLength); |
|
299 TAppVersion ver = ((Java::CJavaRegistryPackageEntry*)iJavaRegEntry)->Version(); |
|
300 |
|
301 TPtr val(keyval->Des()); |
|
302 |
|
303 val.AppendNum(ver.iMajor); |
|
304 val.Append(KSEPERATOR); |
|
305 val.AppendNum(ver.iMinor); |
|
306 |
|
307 iKeyValArray[index] = keyval; |
|
308 |
|
309 } |
|
310 |
|
311 aVal.Set(*iKeyValArray[index]); // Seting the TPtrC with the keyval in array |
|
312 |
|
313 } |
|
314 |
|
315 } |
|
316 else if(aKey.CompareF(KVendor) == KErrNone) |
|
317 { |
|
318 |
|
319 iKeyArray->Find(KVendor,index); |
|
320 |
|
321 if(index >= 0) |
|
322 { |
|
323 if(NULL == iKeyValArray[index]) |
|
324 { |
|
325 // Taking buffer for manipulation |
|
326 HBufC* keyval = HBufC::NewL(((Java::CJavaRegistryPackageEntry*)iJavaRegEntry)->Vendor().Length()); |
|
327 |
|
328 TPtr val(keyval->Des()); |
|
329 |
|
330 val.Append(((Java::CJavaRegistryPackageEntry*)iJavaRegEntry)->Vendor()); |
|
331 |
|
332 iKeyValArray[index] = keyval; |
|
333 |
|
334 } |
|
335 |
|
336 aVal.Set(*iKeyValArray[index]); // Seting the TPtrC with the keyval in array |
|
337 |
|
338 } |
|
339 } |
|
340 else if(aKey.CompareF(KDrive) == KErrNone) |
|
341 { |
|
342 |
|
343 iKeyArray->Find(KDrive,index); |
|
344 |
|
345 if(index >= 0) |
|
346 { |
|
347 if(NULL == iKeyValArray[index]) // chk the condition depend on how we initialise the array in constructor |
|
348 { |
|
349 |
|
350 HBufC* keyval = HBufC::NewL(KdriveLen); |
|
351 TPtr val(keyval->Des()); |
|
352 |
|
353 |
|
354 TInt x = iJavaRegEntry->Drive(); |
|
355 |
|
356 if(KDeriveE == x) |
|
357 { |
|
358 val.Append(KEDRIVE); |
|
359 |
|
360 } |
|
361 else |
|
362 { |
|
363 val.Append(KCDRIVE); |
|
364 |
|
365 } |
|
366 |
|
367 iKeyValArray[index] = keyval; |
|
368 } |
|
369 |
|
370 aVal.Set(*iKeyValArray[index]); // Seting the TPtrC with the keyval in array |
|
371 |
|
372 } |
|
373 |
|
374 } |
|
375 else |
|
376 { |
|
377 |
|
378 retVal = EFalse; |
|
379 |
|
380 } |
|
381 |
|
382 return retVal; |
|
383 |
|
384 } |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // CPkgInfo::GetSisxInfo |
|
388 // Gives the value as per key input for S60(Sisx) installed packages |
|
389 // ----------------------------------------------------------------------------- |
|
390 TBool CPkgInfo::GetSisxInfoL(const TDesC8& aKey, TPtrC& aVal) |
|
391 { |
|
392 TBool retVal= ETrue; |
|
393 TInt index = -1; |
|
394 |
|
395 |
|
396 if(aKey.CompareF(KPkgName)==KErrNone) |
|
397 { |
|
398 |
|
399 iKeyArray->Find(KPkgName,index); |
|
400 |
|
401 if(index >= 0) |
|
402 { |
|
403 if(NULL == iKeyValArray[index]) |
|
404 { |
|
405 |
|
406 HBufC* keyval = iSisRegEntry.PackageNameL(); |
|
407 |
|
408 iKeyValArray[index] = keyval; |
|
409 |
|
410 } |
|
411 |
|
412 aVal.Set(*iKeyValArray[index]); |
|
413 |
|
414 } |
|
415 |
|
416 } |
|
417 else if(aKey.CompareF(KUid) == KErrNone) |
|
418 { |
|
419 |
|
420 iKeyArray->Find(KUid,index); |
|
421 |
|
422 if(index >= 0) |
|
423 { |
|
424 if(NULL == iKeyValArray[index]) |
|
425 { |
|
426 |
|
427 HBufC* keyval = HBufC::NewL(KUidLength); |
|
428 |
|
429 TPtr val(keyval->Des()); |
|
430 |
|
431 val.Append(KHEXAdd); |
|
432 val.AppendNum(iSisRegEntry.UidL().iUid,EHex); |
|
433 |
|
434 iKeyValArray[index] = keyval; |
|
435 |
|
436 } |
|
437 |
|
438 aVal.Set(*iKeyValArray[index]); |
|
439 |
|
440 } |
|
441 |
|
442 } |
|
443 else if(aKey.CompareF(KVersion) == KErrNone) |
|
444 { |
|
445 |
|
446 iKeyArray->Find(KVersion,index); |
|
447 |
|
448 if(index >= 0) |
|
449 { |
|
450 if(NULL == iKeyValArray[index]) |
|
451 { |
|
452 |
|
453 HBufC* keyval = HBufC::NewL(KVersionLength); |
|
454 |
|
455 TVersion ver = iSisRegEntry.VersionL(); |
|
456 |
|
457 TPtr val(keyval->Des()); |
|
458 |
|
459 val.Num(ver.iMajor); |
|
460 |
|
461 val.Append(KSEPERATOR); |
|
462 |
|
463 val.AppendNum(ver.iMinor); |
|
464 |
|
465 iKeyValArray[index] = keyval; |
|
466 |
|
467 } |
|
468 |
|
469 aVal.Set(*iKeyValArray[index]); |
|
470 |
|
471 } |
|
472 |
|
473 } |
|
474 else if(aKey.CompareF(KVendor) == KErrNone) |
|
475 { |
|
476 |
|
477 iKeyArray->Find(KVendor,index); |
|
478 |
|
479 if(index >= 0) |
|
480 { |
|
481 if(NULL == iKeyValArray[index]) |
|
482 { |
|
483 |
|
484 HBufC* keyval = iSisRegEntry.UniqueVendorNameL(); |
|
485 |
|
486 iKeyValArray[index] = keyval; |
|
487 |
|
488 } |
|
489 |
|
490 aVal.Set(*iKeyValArray[index]); |
|
491 |
|
492 } |
|
493 |
|
494 } |
|
495 else if(aKey.CompareF(KDrive) == KErrNone) |
|
496 { |
|
497 |
|
498 iKeyArray->Find(KDrive,index); |
|
499 |
|
500 if(index >= 0) |
|
501 { |
|
502 if(NULL == iKeyValArray[index]) |
|
503 { |
|
504 |
|
505 HBufC* keyval = HBufC::NewL(KdriveLen); |
|
506 TPtr val(keyval->Des()); |
|
507 |
|
508 if( iSisRegEntry.SelectedDriveL() == 'c' || iSisRegEntry.SelectedDriveL() == 'C' ) |
|
509 { |
|
510 val.Append(KCDRIVE); |
|
511 } |
|
512 else |
|
513 { |
|
514 RPointerArray<HBufC> files ; |
|
515 iSisRegEntry.FilesL(files); |
|
516 // Check the disk from files |
|
517 // if all have C, the software is installed to phone |
|
518 // else it is installed to memory card |
|
519 TInt count = files.Count(); |
|
520 |
|
521 TInt allFilesInCZ = 0; |
|
522 for ( TInt index = 0; index < count; index++ ) |
|
523 { |
|
524 TPtrC firstChar = files[index]->Des().Left(1); |
|
525 // Note here find the contents of file and see what we can get |
|
526 |
|
527 |
|
528 if ( ( firstChar.Compare( KDriveC ) == KErrNone ) || |
|
529 ( firstChar.Compare( KDrivec ) == KErrNone ) || |
|
530 ( firstChar.Compare( KDrivez ) == KErrNone ) || |
|
531 ( firstChar.Compare( KDriveZ ) == KErrNone ) ) |
|
532 { |
|
533 allFilesInCZ++; |
|
534 } |
|
535 } // for |
|
536 |
|
537 if ( allFilesInCZ == count ) |
|
538 { |
|
539 // Phone memory |
|
540 val.Append(KCDRIVE); |
|
541 |
|
542 } |
|
543 else |
|
544 { |
|
545 // Memory card |
|
546 val.Append(KEDRIVE); |
|
547 } |
|
548 files.ResetAndDestroy(); |
|
549 } |
|
550 |
|
551 iKeyValArray[index] = keyval; |
|
552 |
|
553 } |
|
554 |
|
555 aVal.Set(*iKeyValArray[index]); |
|
556 |
|
557 } |
|
558 |
|
559 } |
|
560 else |
|
561 { |
|
562 |
|
563 retVal = EFalse; |
|
564 } |
|
565 |
|
566 return retVal; |
|
567 |
|
568 |
|
569 } |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |