|
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 |
|
120 iKeyValArray.ResetAndDestroy(); |
|
121 |
|
122 |
|
123 iSisRegEntry.Close(); |
|
124 |
|
125 if(iJavaRegEntry) |
|
126 { |
|
127 delete iJavaRegEntry; |
|
128 } |
|
129 |
|
130 iSisRegSession = NULL; |
|
131 |
|
132 iJavaReg = NULL; |
|
133 } |
|
134 |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CAppInfo::AtL |
|
138 // This function gives the key value at a given index |
|
139 // ----------------------------------------------------------------------------- |
|
140 TBool CPkgInfo::AtL(TInt aIndex, TDes8& aKeyVal) |
|
141 { |
|
142 |
|
143 if(0<= aIndex < iKeyArray->Count() ) |
|
144 { |
|
145 aKeyVal.Copy((*iKeyArray)[aIndex]); |
|
146 return ETrue; |
|
147 } |
|
148 else |
|
149 { |
|
150 return EFalse; |
|
151 } |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CAppInfo::Count |
|
156 // This function gives the number of keys |
|
157 // ----------------------------------------------------------------------------- |
|
158 TInt CPkgInfo::Count() const |
|
159 { |
|
160 return iKeyArray->Count(); |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CAppInfo::SetEntryL |
|
165 // This function sets the appropriate entry as per uid |
|
166 // ----------------------------------------------------------------------------- |
|
167 void CPkgInfo::SetEntryL(TUid aUid,TBool& aErrflg) |
|
168 { |
|
169 |
|
170 //It will accept the UID and also validate (i.e if that application currently prsent or not) |
|
171 if( iJavaReg ) |
|
172 { |
|
173 iJavaRegEntry = iJavaReg->RegistryEntryL(aUid); |
|
174 |
|
175 if( iJavaRegEntry ) |
|
176 { |
|
177 aErrflg = (Java::EGeneralPackage <= iJavaRegEntry->Type()< Java::EGeneralApplication); |
|
178 if(aErrflg == EFalse) |
|
179 { |
|
180 delete iJavaRegEntry ; |
|
181 iJavaRegEntry = NULL ; |
|
182 } |
|
183 } |
|
184 else |
|
185 { |
|
186 aErrflg = EFalse; |
|
187 } |
|
188 } |
|
189 else |
|
190 { |
|
191 |
|
192 User::LeaveIfError(iSisRegEntry.Open(*iSisRegSession,aUid)); |
|
193 |
|
194 aErrflg = (iSisRegEntry.IsPresentL() && !iSisRegEntry.IsInRomL()); |
|
195 if( aErrflg == EFalse ) |
|
196 { |
|
197 iSisRegEntry.Close(); |
|
198 } |
|
199 |
|
200 } |
|
201 |
|
202 } |
|
203 |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CAppInfo::FindL |
|
207 // This function finds the value as per key given in argument. |
|
208 // ----------------------------------------------------------------------------- |
|
209 TBool CPkgInfo::FindL(const TDesC8& aKey, TPtrC& aVal) |
|
210 { |
|
211 TBool retValue = EFalse; |
|
212 if(iJavaReg) |
|
213 { |
|
214 retValue = GetJavaInfoL(aKey,aVal); |
|
215 |
|
216 } // for iJavaRegEntry |
|
217 else |
|
218 { |
|
219 |
|
220 retValue = GetSisxInfoL(aKey,aVal); |
|
221 } |
|
222 return retValue; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CPkgInfo::GetJavaInfo |
|
227 // Gives the value as per key input for java installed packages |
|
228 // ----------------------------------------------------------------------------- |
|
229 TBool CPkgInfo::GetJavaInfoL(const TDesC8& aKey, TPtrC& aVal) |
|
230 { |
|
231 TBool retVal = ETrue; |
|
232 TInt index = -1 ; |
|
233 |
|
234 if(aKey.CompareF(KPkgName)==KErrNone) |
|
235 { |
|
236 |
|
237 iKeyArray->Find(KPkgName,index); |
|
238 |
|
239 if(index >= 0) |
|
240 { |
|
241 if(NULL == iKeyValArray[index] ) |
|
242 { |
|
243 // create heap object |
|
244 |
|
245 HBufC* keyval = HBufC::NewL(iJavaRegEntry->Name().Length()); |
|
246 |
|
247 TPtr val(keyval->Des()); |
|
248 |
|
249 val.Append(iJavaRegEntry->Name()); |
|
250 |
|
251 |
|
252 iKeyValArray.Insert(keyval,index); // it can b made as leaving function so what to do |
|
253 |
|
254 } |
|
255 |
|
256 aVal.Set(*iKeyValArray[index]); // Seting the TPtrC with the keyval in array |
|
257 |
|
258 } |
|
259 |
|
260 } |
|
261 else if(aKey.CompareF(KUid) == KErrNone) |
|
262 { |
|
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 |
|
280 |
|
281 iKeyValArray.Insert(keyval,index); // it can b made as leaving function so what to do |
|
282 |
|
283 } |
|
284 |
|
285 aVal.Set(*iKeyValArray[index]); // Seting the TPtrC with the keyval in array |
|
286 |
|
287 } |
|
288 |
|
289 |
|
290 } |
|
291 else if(aKey.CompareF(KVersion) == KErrNone) |
|
292 { |
|
293 |
|
294 iKeyArray->Find(KVersion,index); |
|
295 |
|
296 if(index >= 0) |
|
297 { |
|
298 if(NULL == iKeyValArray[index]) |
|
299 { |
|
300 // Taking buffer for manipulation |
|
301 |
|
302 |
|
303 HBufC* keyval = HBufC::NewL(KVersionLength); |
|
304 TAppVersion ver = ((Java::CJavaRegistryPackageEntry*)iJavaRegEntry)->Version(); |
|
305 |
|
306 TPtr val(keyval->Des()); |
|
307 |
|
308 val.AppendNum(ver.iMajor); |
|
309 val.Append(KSEPERATOR); |
|
310 val.AppendNum(ver.iMinor); |
|
311 |
|
312 |
|
313 iKeyValArray.Insert(keyval,index); // it can b made as leaving function so what to do |
|
314 |
|
315 } |
|
316 |
|
317 aVal.Set(*iKeyValArray[index]); // Seting the TPtrC with the keyval in array |
|
318 |
|
319 } |
|
320 |
|
321 } |
|
322 else if(aKey.CompareF(KVendor) == KErrNone) |
|
323 { |
|
324 |
|
325 iKeyArray->Find(KVendor,index); |
|
326 |
|
327 if(index >= 0) |
|
328 { |
|
329 if(NULL == iKeyValArray[index]) |
|
330 { |
|
331 // Taking buffer for manipulation |
|
332 HBufC* keyval = HBufC::NewL(((Java::CJavaRegistryPackageEntry*)iJavaRegEntry)->Vendor().Length()); |
|
333 |
|
334 TPtr val(keyval->Des()); |
|
335 |
|
336 val.Append(((Java::CJavaRegistryPackageEntry*)iJavaRegEntry)->Vendor()); |
|
337 |
|
338 |
|
339 iKeyValArray.Insert(keyval,index); // it can b made as leaving function so what to do |
|
340 |
|
341 } |
|
342 |
|
343 aVal.Set(*iKeyValArray[index]); // Seting the TPtrC with the keyval in array |
|
344 |
|
345 } |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 } |
|
351 else if(aKey.CompareF(KDrive) == KErrNone) |
|
352 { |
|
353 |
|
354 iKeyArray->Find(KDrive,index); |
|
355 |
|
356 if(index >= 0) |
|
357 { |
|
358 if(NULL == iKeyValArray[index]) // chk the condition depend on how we initialise the array in constructor |
|
359 { |
|
360 |
|
361 HBufC* keyval = HBufC::NewL(KdriveLen); |
|
362 TPtr val(keyval->Des()); |
|
363 |
|
364 |
|
365 TInt x = iJavaRegEntry->Drive(); |
|
366 |
|
367 if(KDeriveE == x) |
|
368 { |
|
369 val.Append(KEDRIVE); |
|
370 |
|
371 } |
|
372 else |
|
373 { |
|
374 val.Append(KCDRIVE); |
|
375 |
|
376 } |
|
377 |
|
378 iKeyValArray.Insert(keyval,index); // it can b made as leaving function so what to do |
|
379 } |
|
380 |
|
381 aVal.Set(*iKeyValArray[index]); // Seting the TPtrC with the keyval in array |
|
382 |
|
383 } |
|
384 |
|
385 } |
|
386 else |
|
387 { |
|
388 |
|
389 retVal = EFalse; |
|
390 |
|
391 } |
|
392 |
|
393 return retVal; |
|
394 |
|
395 } |
|
396 |
|
397 // ----------------------------------------------------------------------------- |
|
398 // CPkgInfo::GetSisxInfo |
|
399 // Gives the value as per key input for S60(Sisx) installed packages |
|
400 // ----------------------------------------------------------------------------- |
|
401 TBool CPkgInfo::GetSisxInfoL(const TDesC8& aKey, TPtrC& aVal) |
|
402 { |
|
403 TBool retVal= ETrue; |
|
404 TInt index = -1; |
|
405 |
|
406 |
|
407 if(aKey.CompareF(KPkgName)==KErrNone) |
|
408 { |
|
409 |
|
410 iKeyArray->Find(KPkgName,index); |
|
411 |
|
412 if(index >= 0) |
|
413 { |
|
414 if(NULL == iKeyValArray[index]) |
|
415 { |
|
416 |
|
417 HBufC* keyval = HBufC::NewL(iSisRegEntry.PackageNameL()->Length()); |
|
418 |
|
419 TPtr val(keyval->Des()); |
|
420 |
|
421 val.Append(*(iSisRegEntry.PackageNameL())); |
|
422 |
|
423 iKeyValArray.Insert(keyval,index); // it can b made as leaving function so what to do |
|
424 |
|
425 } |
|
426 |
|
427 aVal.Set(*iKeyValArray[index]); |
|
428 |
|
429 } |
|
430 |
|
431 } |
|
432 else if(aKey.CompareF(KUid) == KErrNone) |
|
433 { |
|
434 |
|
435 iKeyArray->Find(KUid,index); |
|
436 |
|
437 if(index >= 0) |
|
438 { |
|
439 if(NULL == iKeyValArray[index]) |
|
440 { |
|
441 |
|
442 HBufC* keyval = HBufC::NewL(KUidLength); |
|
443 |
|
444 TPtr val(keyval->Des()); |
|
445 |
|
446 val.Append(KHEXAdd); |
|
447 val.AppendNum(iSisRegEntry.UidL().iUid,EHex); |
|
448 |
|
449 |
|
450 iKeyValArray.Insert(keyval,index); // it can b made as leaving function so what to do |
|
451 |
|
452 } |
|
453 |
|
454 aVal.Set(*iKeyValArray[index]); |
|
455 |
|
456 } |
|
457 |
|
458 } |
|
459 else if(aKey.CompareF(KVersion) == KErrNone) |
|
460 { |
|
461 |
|
462 |
|
463 iKeyArray->Find(KVersion,index); |
|
464 |
|
465 if(index >= 0) |
|
466 { |
|
467 if(NULL == iKeyValArray[index]) |
|
468 { |
|
469 |
|
470 HBufC* keyval = HBufC::NewL(KVersionLength); |
|
471 |
|
472 TVersion ver = iSisRegEntry.VersionL(); |
|
473 |
|
474 TPtr val(keyval->Des()); |
|
475 |
|
476 val.Num(ver.iMajor); |
|
477 |
|
478 val.Append(KSEPERATOR); |
|
479 |
|
480 val.AppendNum(ver.iMinor); |
|
481 |
|
482 iKeyValArray.Insert(keyval,index); // it can b made as leaving function so what to do |
|
483 |
|
484 } |
|
485 |
|
486 aVal.Set(*iKeyValArray[index]); |
|
487 |
|
488 } |
|
489 |
|
490 } |
|
491 else if(aKey.CompareF(KVendor) == KErrNone) |
|
492 { |
|
493 |
|
494 |
|
495 iKeyArray->Find(KVendor,index); |
|
496 |
|
497 if(index >= 0) |
|
498 { |
|
499 if(NULL == iKeyValArray[index]) |
|
500 { |
|
501 HBufC* keyval = HBufC::NewL(iSisRegEntry.UniqueVendorNameL()->Length()); |
|
502 |
|
503 TPtr val(keyval->Des()); |
|
504 |
|
505 val.Append(*(iSisRegEntry.UniqueVendorNameL())); |
|
506 |
|
507 iKeyValArray.Insert(keyval,index); // it can b made as leaving function so what to do |
|
508 |
|
509 } |
|
510 |
|
511 aVal.Set(*iKeyValArray[index]); |
|
512 |
|
513 } |
|
514 |
|
515 } |
|
516 else if(aKey.CompareF(KDrive) == KErrNone) |
|
517 { |
|
518 |
|
519 iKeyArray->Find(KDrive,index); |
|
520 |
|
521 if(index >= 0) |
|
522 { |
|
523 if(NULL == iKeyValArray[index]) |
|
524 { |
|
525 |
|
526 HBufC* keyval = HBufC::NewL(KdriveLen); |
|
527 TPtr val(keyval->Des()); |
|
528 |
|
529 if( iSisRegEntry.SelectedDriveL() == 'c' || iSisRegEntry.SelectedDriveL() == 'C' ) |
|
530 { |
|
531 val.Append(KCDRIVE); |
|
532 } |
|
533 else |
|
534 { |
|
535 RPointerArray<HBufC> files ; |
|
536 iSisRegEntry.FilesL(files); |
|
537 // Check the disk from files |
|
538 // if all have C, the software is installed to phone |
|
539 // else it is installed to memory card |
|
540 TInt count = files.Count(); |
|
541 |
|
542 TInt allFilesInCZ = 0; |
|
543 for ( TInt index = 0; index < count; index++ ) |
|
544 { |
|
545 TPtrC firstChar = files[index]->Des().Left(1); |
|
546 // Note here find the contents of file and see what we can get |
|
547 |
|
548 |
|
549 if ( ( firstChar.Compare( KDriveC ) == KErrNone ) || |
|
550 ( firstChar.Compare( KDrivec ) == KErrNone ) || |
|
551 ( firstChar.Compare( KDrivez ) == KErrNone ) || |
|
552 ( firstChar.Compare( KDriveZ ) == KErrNone ) ) |
|
553 { |
|
554 allFilesInCZ++; |
|
555 } |
|
556 } // for |
|
557 |
|
558 if ( allFilesInCZ == count ) |
|
559 { |
|
560 // Phone memory |
|
561 val.Append(KCDRIVE); |
|
562 |
|
563 } |
|
564 else |
|
565 { |
|
566 // Memory card |
|
567 val.Append(KEDRIVE); |
|
568 } |
|
569 files.Close(); |
|
570 } |
|
571 |
|
572 |
|
573 iKeyValArray.Insert(keyval,index); // it can b made as leaving function so what to do |
|
574 |
|
575 } |
|
576 |
|
577 |
|
578 aVal.Set(*iKeyValArray[index]); |
|
579 |
|
580 } |
|
581 |
|
582 } |
|
583 else |
|
584 { |
|
585 |
|
586 retVal = EFalse; |
|
587 } |
|
588 |
|
589 return retVal; |
|
590 |
|
591 |
|
592 } |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |