1 /* |
|
2 * Copyright (c) 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 "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: Location Centre Server object. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 #include <pathinfo.h> |
|
21 #include <apgcli.h> |
|
22 #include <DocumentHandler.h> // CDocumentHandler |
|
23 #include <pathinfo.h> |
|
24 |
|
25 // USER INCLUDES |
|
26 #include "lcregistry.h" |
|
27 #include "lcregistrationparser.h" |
|
28 #include "lcregistryupdate.h" |
|
29 #include "lcregistrationupdatenotifier.h" |
|
30 #include "lcregapporder.h" |
|
31 #include "lcregistryobserver.h" |
|
32 #include "lcregappinfo.h" |
|
33 #include "lcregappstore.h" |
|
34 #include "lcdebug.h" |
|
35 |
|
36 // CONSTANT DEFINTIONS |
|
37 //Forward declaration. Function for sorted ordering of appinfo array |
|
38 static TInt PositionDescOrdering( const CLcRegAppInfo& aAppInfo1, |
|
39 const CLcRegAppInfo& aAppInfo2 ); |
|
40 |
|
41 |
|
42 |
|
43 // ----- Member funtions for CLcRegistry --------------------------------- |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CLcRegistry::CLcRegistry |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CLcRegistry::CLcRegistry( MLcRegistryObserver& aRegistryObserver ) |
|
50 :CActive(EPriorityStandard), |
|
51 iRegistryObserver( aRegistryObserver ) |
|
52 { |
|
53 // C++ Default constructor. No allocations or functions which can Leave |
|
54 // should be called from here.Initiallize all the variable here |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CLcRegistry::~CLcRegistry |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CLcRegistry::~CLcRegistry() |
|
62 { |
|
63 Cancel(); |
|
64 |
|
65 // C++ Destructor. Free all resources associated with this class. |
|
66 delete iLcRegUpdate; |
|
67 delete iRegAppStore; |
|
68 delete iLcRegAppOrder; |
|
69 |
|
70 //close the file server session. |
|
71 iFs.Close(); |
|
72 // free filename array memory |
|
73 iFileNameArry.Reset(); |
|
74 iFileNameArry.Close(); |
|
75 |
|
76 //delete all items from the appinfo array. |
|
77 iAppInfoArray.ResetAndDestroy(); |
|
78 iAppInfoArray.Close(); |
|
79 |
|
80 iAppInfoNewArray.ResetAndDestroy(); |
|
81 iAppInfoNewArray.Close(); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CLcRegistry* CLcRegistry::NewL |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 CLcRegistry* CLcRegistry::NewL( MLcRegistryObserver& aRegistryObserver ) |
|
89 { |
|
90 CLcRegistry* self = NewLC( aRegistryObserver ); |
|
91 CleanupStack::Pop( self ); |
|
92 return self; |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CLcRegistry* CLcRegistry::NewLC |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 CLcRegistry* CLcRegistry::NewLC( MLcRegistryObserver& aRegistryObserver ) |
|
100 { |
|
101 // Symbian Two phased constructor. Leaves the object on the Clean-up |
|
102 // stack. |
|
103 CLcRegistry* self = new ( ELeave )CLcRegistry( aRegistryObserver ); |
|
104 CleanupStack::PushL( self ); |
|
105 self->ConstructL(); |
|
106 return self; |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // void CLcRegistry::ConstructL |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 void CLcRegistry::ConstructL() |
|
114 { |
|
115 // connect to file server |
|
116 // and pass this session to all the class required. |
|
117 User::LeaveIfError(iFs.Connect()); |
|
118 |
|
119 // creation of dynamic registration notifier object |
|
120 iLcRegUpdate = CLcRegistryUpdate::NewL( *this, iFs); |
|
121 |
|
122 // creation of private info object |
|
123 iRegAppStore = CLcRegAppStore::NewL(iFs); |
|
124 |
|
125 // creation of application order settings object |
|
126 iLcRegAppOrder = CLcRegAppOrder::NewL( *iRegAppStore ); |
|
127 |
|
128 // reset the new applist array count here |
|
129 iAppInfoNewArray.Reset(); |
|
130 /* Now Check if any update needed to that list. |
|
131 * To do that start all the system drive scan and collect |
|
132 * all the registered file names |
|
133 */ |
|
134 iRegistryHasToUpdate = EFalse; |
|
135 |
|
136 // registered for notification in private directory from file server |
|
137 iLcRegUpdate->StartFileNotifation(); |
|
138 // Add it to Active scheduler |
|
139 CActiveScheduler::Add( this ); |
|
140 // issue the request to active scheduker |
|
141 CheckForUpdationL(); |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // void CLcRegistry::CheckForUpdationL() |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 void CLcRegistry::CheckForUpdationL() |
|
149 { |
|
150 // inform registry engine that registration process is under updation |
|
151 iRegistryObserver.RegistryUnderUpdation(); |
|
152 // set the file count to zero |
|
153 iregFileCount = 0; |
|
154 |
|
155 // Scan all the drives and get all the registered file names |
|
156 ScanDrivesAndGetFileNameL(); |
|
157 |
|
158 DEBUG3("Updated File list : %d", iFileNameArry.Count(), 0, 0 ); |
|
159 |
|
160 // issue a request to active scheduler |
|
161 IssueRequest(); |
|
162 } |
|
163 |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // void CLcRegistry::IssueRequest |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 void CLcRegistry::IssueRequest() |
|
170 { |
|
171 if(!IsActive()) |
|
172 { |
|
173 SetActive(); |
|
174 TRequestStatus *status = &iStatus; |
|
175 User::RequestComplete(status,KErrNone); |
|
176 } |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // TInt CLcRegistry::GetAllRegisteredAppsList |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 TInt CLcRegistry::GetAllRegisteredAppsList( RPointerArray<CLcAppInfo>& appInfoArray ) |
|
184 { |
|
185 //DEBUG( "+ CLcRegistry::GetAllRegisteredAppsList"); |
|
186 |
|
187 TInt error = KErrNone; |
|
188 if( iAppInfoArray.Count() <= 0 ) |
|
189 { |
|
190 error = KErrNotFound; |
|
191 } |
|
192 else |
|
193 { |
|
194 for(TInt i = 0; i < iAppInfoArray.Count(); i++) |
|
195 { |
|
196 // check wheather application is present |
|
197 // append only present application |
|
198 if( iAppInfoArray[i]->IsAppPresent() ) |
|
199 { |
|
200 error = appInfoArray.Append( iAppInfoArray[i] ); |
|
201 if ( error ) |
|
202 { |
|
203 break; |
|
204 } |
|
205 } |
|
206 } |
|
207 } |
|
208 DEBUG3("Get Registered Apps : %d", appInfoArray.Count(), 0, 0 ); |
|
209 //DEBUG( "- CLcRegistry::GetAllRegisteredAppsList"); |
|
210 return error; |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // TInt CLcRegistry::GetApplicationInfo |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 TInt CLcRegistry::GetApplicationInfo( const TDesC& aAppUid, |
|
218 CLcBasicAppInfo*& aLcRegAppInfo ) |
|
219 { |
|
220 //DEBUG( "+ CLcRegistry::GetApplicationInfo"); |
|
221 |
|
222 for(TInt i = 0; i< iAppInfoArray.Count(); i++) |
|
223 { |
|
224 if( !aAppUid.Compare( iAppInfoArray[i]->Id()) && |
|
225 iAppInfoArray[i]->IsAppPresent()) |
|
226 { |
|
227 aLcRegAppInfo = iAppInfoArray[i]; |
|
228 return KErrNone; |
|
229 } |
|
230 } |
|
231 |
|
232 //DEBUG( "- CLcRegistry::GetApplicationInfo"); |
|
233 |
|
234 return KErrNotFound; |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // void CLcRegistry::HandleDynamicRegistrationL |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 void CLcRegistry::HandleDynamicRegistrationL() |
|
242 { |
|
243 DEBUG("+CLcRegistry::HandleDynamicRegistrationL"); |
|
244 iRegistryHasToUpdate = ETrue; |
|
245 CheckForUpdationL(); |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // void CLcService::ScanDrivesAndGetFileNameL |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void CLcRegistry::ScanDrivesAndGetFileNameL() |
|
253 { |
|
254 DEBUG( "+ CLcRegistry::ScanDrivesAndGetFileNameL"); |
|
255 |
|
256 iFileNameArry.Reset(); |
|
257 //declare the directory to be scan through |
|
258 _LIT(KPriDirName, ":\\private\\10283138\\import\\" ); |
|
259 TFileName srcDirName( KPriDirName ); |
|
260 TDriveList dirList; |
|
261 |
|
262 if(iFs.DriveList( dirList ) != KErrNone) |
|
263 { |
|
264 return; |
|
265 } |
|
266 |
|
267 TBuf<KMaxFileName> rootDir; |
|
268 //creating the CDirscan object |
|
269 CDirScan* scanner = CDirScan::NewLC(iFs); |
|
270 TChar driveLetter = '?'; |
|
271 TDriveInfo info; |
|
272 TInt error; |
|
273 |
|
274 //Scan for all drives in the system |
|
275 TInt driveListSize = dirList.Length(); |
|
276 for(TInt dir(0); dir < driveListSize; dir++) |
|
277 { |
|
278 error = iFs.Drive(info, dir); |
|
279 if ((error == KErrNone) && |
|
280 (dirList[dir] && info.iType != EMediaNotPresent)) |
|
281 { |
|
282 RFs::DriveToChar(dir, driveLetter); |
|
283 rootDir.Zero();//Clear the previous contents |
|
284 rootDir.Append(driveLetter); |
|
285 rootDir.Append( srcDirName ); |
|
286 |
|
287 CDir *currentDir = NULL; |
|
288 // Go through the files only |
|
289 scanner->SetScanDataL( rootDir, KEntryAttNormal, ESortNone ); |
|
290 |
|
291 TRAP( error, scanner->NextL( currentDir )); |
|
292 if( error ) |
|
293 { |
|
294 continue; |
|
295 } |
|
296 TInt entryCount = currentDir->Count(); |
|
297 while(entryCount--) |
|
298 { |
|
299 TBuf<KMaxFileName> lookup; |
|
300 TEntry entry=( *currentDir )[entryCount]; |
|
301 //Clear the previous values |
|
302 lookup.Zero(); |
|
303 //Append next one |
|
304 lookup.Append(scanner->FullPath()); |
|
305 lookup.Append(entry.iName); |
|
306 //Store it in for future reference |
|
307 iFileNameArry.Append(lookup); |
|
308 } |
|
309 delete currentDir; |
|
310 } |
|
311 } |
|
312 CleanupStack::PopAndDestroy( scanner ); |
|
313 |
|
314 DEBUG( "- CLcRegistry::ScanDrivesAndGetFileNameL"); |
|
315 } |
|
316 |
|
317 // ---------------------------------------------------------------------------- |
|
318 // CLcRegistry::RunL |
|
319 // ---------------------------------------------------------------------------- |
|
320 // |
|
321 void CLcRegistry::RunL() |
|
322 { |
|
323 TUint mmcId = 0; |
|
324 // This check is for if some update events come |
|
325 // during registration updation going on. |
|
326 if( iRegistryHasToUpdate ) |
|
327 { |
|
328 DEBUG( "Dynamic notification recived"); |
|
329 // Add all the appinfo to current list from new created list |
|
330 for( TInt i = 0; i < iAppInfoNewArray.Count(); i++ ) |
|
331 { |
|
332 User::LeaveIfError( iAppInfoArray.Append( iAppInfoNewArray[i] )); |
|
333 } |
|
334 iAppInfoNewArray.Reset(); |
|
335 // end of loop set the flag as EFalse |
|
336 iRegistryHasToUpdate = EFalse; |
|
337 DEBUG( "Notify execute"); |
|
338 IssueRequest(); |
|
339 } |
|
340 else |
|
341 { |
|
342 CLcRegAppInfo* regAppInfo = NULL; |
|
343 if( iregFileCount < iFileNameArry.Count() ) |
|
344 { |
|
345 // Check wheather registration file name is present in the |
|
346 // old registered list.If not then add as a new registration service |
|
347 TBool lResult = DoesApplicationExists( iFileNameArry[ iregFileCount ], |
|
348 regAppInfo ); |
|
349 if ( lResult ) |
|
350 { |
|
351 // Check if the Application suffered an Upgrade. If its an upgrade |
|
352 // then its equivalent to a new installation. |
|
353 TFileName fileName = regAppInfo->FileName(); |
|
354 if ( IsAppUpgraded(fileName) ) |
|
355 { |
|
356 // Remove the element from the Old array |
|
357 TInt index = iAppInfoArray.Find( regAppInfo ); |
|
358 CLcRegAppInfo* info = iAppInfoArray[index]; |
|
359 iAppInfoArray.Remove( index ); |
|
360 delete info; |
|
361 |
|
362 // Parse new registration info validate and append it to list |
|
363 TRAPD( err, regAppInfo = |
|
364 CreateAppRegInfoL(iFileNameArry[ iregFileCount ])); |
|
365 if( !err ) |
|
366 { |
|
367 CleanupStack::PushL( regAppInfo ); |
|
368 InsertAppRegInfoL( regAppInfo ); |
|
369 CleanupStack::Pop( regAppInfo ); |
|
370 } |
|
371 iregFileCount++; |
|
372 IssueRequest(); |
|
373 } |
|
374 else |
|
375 { |
|
376 // Check and Set the Present status of the Application |
|
377 if( !regAppInfo->IsAppPresent() && |
|
378 !GetMmcId( mmcId ) && |
|
379 !mmcId == regAppInfo->MmcId()) |
|
380 { |
|
381 // This condition is only when the Application was registered |
|
382 // prior to this and was on an MMC which was not mounted |
|
383 regAppInfo->SetFilePresenceStatus(ETrue); |
|
384 } |
|
385 |
|
386 // Remove the element from the Old array |
|
387 TInt index = iAppInfoArray.Find( regAppInfo ); |
|
388 iAppInfoArray.Remove( index ); |
|
389 // push the object to cleanup stack before calling |
|
390 // InsertAppRegInfoL. |
|
391 CleanupStack::PushL( regAppInfo ); |
|
392 InsertAppRegInfoL( regAppInfo ); |
|
393 CleanupStack::Pop( regAppInfo ); |
|
394 |
|
395 iregFileCount++; |
|
396 IssueRequest(); |
|
397 } |
|
398 } |
|
399 else |
|
400 { |
|
401 // Parse new registration info validate and append it to list |
|
402 TRAPD( err, regAppInfo = |
|
403 CreateAppRegInfoL( iFileNameArry[ iregFileCount ] )); |
|
404 if( !err ) |
|
405 { |
|
406 CleanupStack::PushL( regAppInfo ); |
|
407 InsertAppRegInfoL( regAppInfo ); |
|
408 CleanupStack::Pop( regAppInfo ); |
|
409 } |
|
410 iregFileCount++; |
|
411 IssueRequest(); |
|
412 } |
|
413 } |
|
414 else |
|
415 { |
|
416 // After completing if part if there is any application present |
|
417 // in the old array then check those application for absent or removal case. |
|
418 if( iAppInfoArray.Count() > 0 ) |
|
419 { |
|
420 //Get current MMC id. |
|
421 if( GetMmcId( mmcId ) ) |
|
422 { |
|
423 // Check for all Absent applications |
|
424 while( iAppInfoArray.Count()) |
|
425 { |
|
426 regAppInfo = iAppInfoArray[0]; |
|
427 iAppInfoArray.Remove( 0 ); |
|
428 |
|
429 if( regAppInfo->MmcId() != mmcId ) |
|
430 { |
|
431 regAppInfo->SetFilePresenceStatus(EFalse); |
|
432 CleanupStack::PushL( regAppInfo ); |
|
433 InsertAppRegInfoL( regAppInfo ); |
|
434 CleanupStack::Pop( regAppInfo ); |
|
435 } |
|
436 else |
|
437 { |
|
438 iLcRegAppOrder->RemoveArrayL( regAppInfo->Id() ); |
|
439 delete regAppInfo; |
|
440 } |
|
441 } |
|
442 } |
|
443 |
|
444 // Check for all de-registered applications |
|
445 while( iAppInfoArray.Count()) |
|
446 { |
|
447 regAppInfo = iAppInfoArray[0]; |
|
448 iAppInfoArray.Remove( 0 ); |
|
449 iLcRegAppOrder->RemoveArrayL( regAppInfo->Id() ); |
|
450 delete regAppInfo; |
|
451 } |
|
452 } |
|
453 iAppInfoArray.ResetAndDestroy(); |
|
454 FinalRegistrationUpdateL(); |
|
455 } |
|
456 } |
|
457 } |
|
458 |
|
459 // --------------------------------------------------------------------------- |
|
460 // CLcServerShutDownTimer::RunError |
|
461 // --------------------------------------------------------------------------- |
|
462 // |
|
463 TInt CLcRegistry::RunError( TInt aError ) |
|
464 { |
|
465 // Dont leave. Continue with the next operation |
|
466 return aError; |
|
467 } |
|
468 |
|
469 |
|
470 // --------------------------------------------------------------------------- |
|
471 // void CLcRegistry::FinalRegistrationUpdateL |
|
472 // --------------------------------------------------------------------------- |
|
473 // |
|
474 void CLcRegistry::FinalRegistrationUpdateL() |
|
475 { |
|
476 // Resync all the existing applications. Their order could have been |
|
477 // changed because of the possible changes in the index ordering |
|
478 |
|
479 // Temporary array to assist copying of all content from one place |
|
480 // to another |
|
481 RPointerArray<CLcRegAppInfo> tempArray; |
|
482 while ( iAppInfoArray.Count()) |
|
483 { |
|
484 CLcRegAppInfo* info = iAppInfoArray[0]; |
|
485 iAppInfoArray.Remove( 0 ); |
|
486 tempArray.Append( info ); |
|
487 } |
|
488 |
|
489 // Insert back all temporary elements back into the Info Array |
|
490 TInt appcount = tempArray.Count(); |
|
491 for( TInt i = 0; i < appcount; i++ ) |
|
492 { |
|
493 User::LeaveIfError( iAppInfoArray.Append( tempArray[i] )); |
|
494 } |
|
495 |
|
496 // Now destroy all the elements back in the temporary array. |
|
497 tempArray.ResetAndDestroy(); |
|
498 tempArray.Close(); |
|
499 |
|
500 // Add all the appinfo to current list from new created list |
|
501 appcount = iAppInfoNewArray.Count(); |
|
502 for( TInt i = 0; i < appcount; i++ ) |
|
503 { |
|
504 User::LeaveIfError(iAppInfoArray.Append( iAppInfoNewArray[i] )); |
|
505 } |
|
506 iAppInfoNewArray.Reset(); |
|
507 |
|
508 DEBUG1("New List Count : %d", iAppInfoArray.Count()) |
|
509 |
|
510 // Send a notification to registry engine that updation completed |
|
511 iRegistryObserver.RegistryUpdated(); |
|
512 } |
|
513 |
|
514 // ---------------------------------------------------------------------------- |
|
515 // CLcRegistry::IsInMMc |
|
516 // ---------------------------------------------------------------------------- |
|
517 // |
|
518 TBool CLcRegistry::IsInMMc( TFileName& aFileName ) |
|
519 { |
|
520 TBool lResult = EFalse; |
|
521 TParse parse; |
|
522 parse.Set(aFileName,NULL,NULL); |
|
523 TPtrC lDrive = parse.Drive(); |
|
524 TInt err,mmcDrive,fileDrive; |
|
525 err = RFs::CharToDrive( PathInfo::MemoryCardRootPath()[0], mmcDrive ); |
|
526 if (err == KErrNone) |
|
527 { |
|
528 err = RFs::CharToDrive( lDrive[0], fileDrive ); |
|
529 if( err == KErrNone ) |
|
530 { |
|
531 if( mmcDrive == fileDrive ) |
|
532 { |
|
533 lResult = ETrue; |
|
534 } |
|
535 } |
|
536 } |
|
537 return lResult; |
|
538 } |
|
539 |
|
540 // ---------------------------------------------------------------------------- |
|
541 // CLcRegistry::DoesApplicationExists |
|
542 // ---------------------------------------------------------------------------- |
|
543 // |
|
544 TBool CLcRegistry::DoesApplicationExists( TFileName& aFileName, |
|
545 CLcRegAppInfo*& alcRegAppInfoPtr ) |
|
546 { |
|
547 // This function checks wheather registration info with same file name |
|
548 // is present in the old list. If present then return ETrue or else EFalse. |
|
549 TInt count = iAppInfoArray.Count(); |
|
550 for( TInt i = 0; i < count; i++ ) |
|
551 { |
|
552 alcRegAppInfoPtr = iAppInfoArray[i]; |
|
553 if( alcRegAppInfoPtr ) |
|
554 { |
|
555 if( aFileName.Compare( alcRegAppInfoPtr->FileName()) == 0 ) |
|
556 { |
|
557 return ETrue; |
|
558 } |
|
559 } |
|
560 } |
|
561 return EFalse; |
|
562 } |
|
563 |
|
564 // ---------------------------------------------------------------------------- |
|
565 // CLcRegistry::CreateAppRegInfoL |
|
566 // ---------------------------------------------------------------------------- |
|
567 // |
|
568 CLcRegAppInfo* CLcRegistry::CreateAppRegInfoL( TFileName& aFileName ) |
|
569 { |
|
570 DEBUG( "+ CLcRegistry::CreateAppRegInfoL" ); |
|
571 |
|
572 CLcRegistrationParser* regParser = CLcRegistrationParser::NewL( iFs ); |
|
573 CleanupStack::PushL( regParser ); |
|
574 |
|
575 //Parse the file content and get all the registration info. |
|
576 CLcRegAppInfo* info = regParser->ParseFileL( aFileName ); |
|
577 |
|
578 CleanupStack::PopAndDestroy( regParser ); |
|
579 |
|
580 CleanupStack::PushL( info ); |
|
581 |
|
582 //Check that same UUID based appinfo is already registered or not. |
|
583 if( DoesSameUuidPresent( info )) |
|
584 { |
|
585 User::Leave( KErrAlreadyExists ); |
|
586 } |
|
587 |
|
588 //validate the application or document |
|
589 if ( info->ApplicationType() == ELcNativeApplication || |
|
590 info->ApplicationType() == ELcDocument ) |
|
591 { |
|
592 //DEBUG("+ Validate") |
|
593 ValidateRegisteredServiceL( *info ); |
|
594 //DEBUG("- Validate") |
|
595 } |
|
596 |
|
597 // Set the language specific name for the service |
|
598 if( info->IsAppNamePresent()) |
|
599 { |
|
600 info->SetAppLangSpecificNameL(iFs); |
|
601 } |
|
602 else |
|
603 { |
|
604 SetAbsentAppNameL( info ); |
|
605 } |
|
606 |
|
607 |
|
608 // Set the file name for future reference. |
|
609 info->SetFileNameL( aFileName ); |
|
610 |
|
611 TUint mmcId; |
|
612 |
|
613 //Get current MMC id. |
|
614 if( !GetMmcId( mmcId ) && IsInMMc( aFileName )) |
|
615 { |
|
616 info->SetMmcId(mmcId); |
|
617 } |
|
618 |
|
619 CleanupStack::Pop( info ); |
|
620 |
|
621 DEBUG( "- CLcRegistry::CreateAppRegInfoL" ); |
|
622 return info; |
|
623 } |
|
624 |
|
625 // ---------------------------------------------------------------------------- |
|
626 // CLcRegistry::InsertAppRegInfoL |
|
627 // ---------------------------------------------------------------------------- |
|
628 // |
|
629 void CLcRegistry::InsertAppRegInfoL( CLcRegAppInfo* aAppInfo ) |
|
630 { |
|
631 TInt index = 0; |
|
632 |
|
633 // Get the required order of the |
|
634 // service from the central repository |
|
635 //Add the appinfo to array |
|
636 if( iLcRegAppOrder->GetRegisteredAppOrder( aAppInfo->Id(), |
|
637 index )) |
|
638 { |
|
639 |
|
640 // this is for new regapp info addition |
|
641 // to db and get the final order |
|
642 index = iLcRegAppOrder->AppendArrayL( aAppInfo->Id()); |
|
643 |
|
644 for ( TInt i = 0; i < iAppInfoArray.Count(); i++ ) |
|
645 { |
|
646 // Get the new order for the respective elements and set the correct values. |
|
647 CLcRegAppInfo* info = iAppInfoArray[i]; |
|
648 TInt currentIndex = 0; |
|
649 iLcRegAppOrder->GetRegisteredAppOrder( info->Id(), |
|
650 currentIndex ); |
|
651 // Set the new Index |
|
652 info->SetArrayIndex( currentIndex ); |
|
653 } |
|
654 |
|
655 // Set the index of all elements in the new array |
|
656 for ( TInt i = 0; i < iAppInfoNewArray.Count(); i++ ) |
|
657 { |
|
658 // Get the new order for the respective elements and set the correct values. |
|
659 CLcRegAppInfo* info = iAppInfoNewArray[i]; |
|
660 TInt currentIndex = 0; |
|
661 iLcRegAppOrder->GetRegisteredAppOrder( info->Id(), |
|
662 currentIndex ); |
|
663 // Set the new Index |
|
664 info->SetArrayIndex( currentIndex ); |
|
665 } |
|
666 } |
|
667 |
|
668 // Set the array index |
|
669 aAppInfo->SetArrayIndex( index ); |
|
670 |
|
671 User::LeaveIfError( |
|
672 iAppInfoNewArray.InsertInOrder( aAppInfo, |
|
673 PositionDescOrdering )); |
|
674 } |
|
675 |
|
676 // ---------------------------------------------------------------------------- |
|
677 // CLcRegistry::DoesSameUuidPresent |
|
678 // ---------------------------------------------------------------------------- |
|
679 // |
|
680 TBool CLcRegistry::DoesSameUuidPresent( CLcRegAppInfo* aLcRegAppInfo ) |
|
681 { |
|
682 // Check in the Old array |
|
683 for( TInt i = 0; i < iAppInfoArray.Count(); i++ ) |
|
684 { |
|
685 CLcRegAppInfo* lcRegAppInfoPtr = iAppInfoArray[i]; |
|
686 if( lcRegAppInfoPtr ) |
|
687 { |
|
688 if( !aLcRegAppInfo->Id().Compare( lcRegAppInfoPtr->Id())) |
|
689 { |
|
690 return ETrue; |
|
691 } |
|
692 } |
|
693 } |
|
694 |
|
695 // Now check in the new array |
|
696 for( TInt i = 0; i < iAppInfoNewArray.Count(); i++ ) |
|
697 { |
|
698 CLcRegAppInfo* lcRegAppInfoPtr = iAppInfoNewArray[i]; |
|
699 if( lcRegAppInfoPtr ) |
|
700 { |
|
701 if( !aLcRegAppInfo->Id().Compare( lcRegAppInfoPtr->Id())) |
|
702 { |
|
703 return ETrue; |
|
704 } |
|
705 } |
|
706 } |
|
707 |
|
708 // No match found |
|
709 return EFalse; |
|
710 } |
|
711 |
|
712 // ---------------------------------------------------------------------------- |
|
713 // CLcRegistry::DoCancel |
|
714 // ---------------------------------------------------------------------------- |
|
715 // |
|
716 void CLcRegistry::DoCancel() |
|
717 { |
|
718 Cancel(); |
|
719 } |
|
720 |
|
721 // --------------------------------------------------------------------------- |
|
722 // void CLcService::ValidateRegisteredAppL |
|
723 // --------------------------------------------------------------------------- |
|
724 // |
|
725 void CLcRegistry::ValidateRegisteredServiceL( CLcRegAppInfo& aApplicationInfo ) |
|
726 { |
|
727 DEBUG( "+ CLcRegistry::ValidateRegisteredServiceL" ) |
|
728 |
|
729 RApaLsSession lsSession; |
|
730 User::LeaveIfError( lsSession.Connect() ); |
|
731 CleanupClosePushL( lsSession ); |
|
732 |
|
733 //Check the application type.If Application then validate it |
|
734 if( aApplicationInfo.ApplicationType() == ELcNativeApplication ) |
|
735 { |
|
736 DEBUG("+ App Validation") |
|
737 TLex lexer(aApplicationInfo.ApplicationData()); |
|
738 TUint32 lAppSid = 0; |
|
739 TUint limit = 0xFFFFFFFF; |
|
740 User::LeaveIfError( lexer.BoundedVal(lAppSid, EHex, limit) ); |
|
741 TApaAppInfo appInfo; |
|
742 User::LeaveIfError( lsSession.GetAppInfo( appInfo, TUid::Uid( lAppSid ))); |
|
743 DEBUG("- App Validation") |
|
744 } |
|
745 else if( aApplicationInfo.ApplicationType() == ELcDocument ) |
|
746 { |
|
747 DEBUG("+ Document Validation") |
|
748 //Validate document |
|
749 CDocumentHandler* documentHandler = CDocumentHandler::NewL(); |
|
750 CleanupStack::PushL( documentHandler ); |
|
751 // empty datatype for automatic recognization |
|
752 TUint8* contentTypeString = NULL; |
|
753 FindContentTypeFromFileL( lsSession, |
|
754 contentTypeString, |
|
755 &aApplicationInfo ); |
|
756 User::LeaveIfNull( contentTypeString ); |
|
757 |
|
758 CleanupStack::PushL( contentTypeString ); |
|
759 documentHandler->CanOpenL( TDataType( TPtrC8( contentTypeString ))); |
|
760 CleanupStack::PopAndDestroy( 2, documentHandler ); |
|
761 DEBUG("- Document Validation") |
|
762 } |
|
763 |
|
764 // Now set the system characteristics for application / document / weburl |
|
765 SetAppSysCharacteristicsL( lsSession, aApplicationInfo ); |
|
766 |
|
767 CleanupStack::PopAndDestroy(); //lsSession |
|
768 |
|
769 DEBUG( "- CLcRegistry::ValidateRegisteredServiceL" ) |
|
770 } |
|
771 |
|
772 |
|
773 // --------------------------------------------------------------------------- |
|
774 // void CLcRegistry::FindContentTypeFromFileL |
|
775 // --------------------------------------------------------------------------- |
|
776 // |
|
777 void CLcRegistry::FindContentTypeFromFileL( RApaLsSession apaSession, |
|
778 TUint8*& aContentTypeString, |
|
779 CLcRegAppInfo* aApplicationInfo ) |
|
780 { |
|
781 TDataRecognitionResult dataType; |
|
782 TInt ret; |
|
783 |
|
784 // Create a buffer to hold data from the file |
|
785 TInt bufferSize = 0; |
|
786 TInt seekPosition = 0; |
|
787 apaSession.GetMaxDataBufSize(bufferSize); |
|
788 HBufC8* buffer = HBufC8::NewLC(bufferSize); |
|
789 TPtr8 buf = buffer->Des(); |
|
790 |
|
791 RFile file; |
|
792 HBufC* fileName = HBufC::NewLC( KMaxPath ); |
|
793 fileName->Des().Copy(aApplicationInfo->ApplicationData()); |
|
794 |
|
795 ret = file.Open( iFs, |
|
796 *fileName, |
|
797 EFileShareAny | EFileRead ); |
|
798 if( !ret ) |
|
799 { |
|
800 // Find current file pointer position |
|
801 file.Seek(ESeekStart, seekPosition); |
|
802 // Read from file |
|
803 file.Read(buf); |
|
804 // return file pointer to original position |
|
805 file.Seek(ESeekStart, seekPosition); |
|
806 // Ask the application architecture to find the file type |
|
807 ret = apaSession.RecognizeData(*fileName, buf, dataType); |
|
808 |
|
809 if (ret == KErrNone && |
|
810 (dataType.iConfidence == CApaDataRecognizerType::ECertain) || |
|
811 (dataType.iConfidence == CApaDataRecognizerType::EProbable)) |
|
812 { |
|
813 // If the file type was found, try to match it to a known file type |
|
814 TPtrC8 mimeTypePtr = dataType.iDataType.Des8(); |
|
815 TInt len = mimeTypePtr.Length() + 1; |
|
816 aContentTypeString = new(ELeave) TUint8 [len]; |
|
817 |
|
818 TPtr8 contentTypeStringPtr(aContentTypeString, len); |
|
819 contentTypeStringPtr.Copy(mimeTypePtr); |
|
820 contentTypeStringPtr.ZeroTerminate(); |
|
821 } |
|
822 file.Close(); |
|
823 } |
|
824 CleanupStack::PopAndDestroy(fileName); //fileName |
|
825 CleanupStack::PopAndDestroy(buffer); //buffer |
|
826 } |
|
827 |
|
828 // ----------------------------------------------------------------------------- |
|
829 // CLcRegistry::MmcIdL |
|
830 // Get the id of the MMC card. |
|
831 // ----------------------------------------------------------------------------- |
|
832 // |
|
833 TInt CLcRegistry::GetMmcId( TUint& aUid ) |
|
834 { |
|
835 TDriveInfo info; |
|
836 info.iType = EMediaNotPresent; |
|
837 TInt mmcDrive; |
|
838 TInt err; |
|
839 TChar cha = '?'; |
|
840 err = RFs::CharToDrive( PathInfo::MemoryCardRootPath()[0], mmcDrive ); |
|
841 if (err == KErrNone) |
|
842 { |
|
843 err = iFs.Drive( info, mmcDrive ); |
|
844 } |
|
845 if( err != KErrNone || |
|
846 info.iType == EMediaNotPresent ) |
|
847 { |
|
848 // MMC locked or not installed |
|
849 err = KErrNotFound; |
|
850 } |
|
851 else |
|
852 { |
|
853 TVolumeInfo volumeInfo; |
|
854 err = iFs.Volume( volumeInfo, mmcDrive ); |
|
855 if( err == KErrNone ) |
|
856 { |
|
857 aUid = volumeInfo.iUniqueID; |
|
858 } |
|
859 } |
|
860 return err; |
|
861 } |
|
862 |
|
863 |
|
864 // ---------------------------------------------------------------------------- |
|
865 // CLcRegistry::SetAppSysCharacteristicsL |
|
866 // ---------------------------------------------------------------------------- |
|
867 // |
|
868 void CLcRegistry::SetAppSysCharacteristicsL( RApaLsSession& alsSession, |
|
869 CLcRegAppInfo& aRegAppInfo ) |
|
870 { |
|
871 TFileName fileName; |
|
872 if( aRegAppInfo.ApplicationType() == ELcNativeApplication ) |
|
873 { |
|
874 // for application we should check |
|
875 // where the binary is present |
|
876 TLex lexer(aRegAppInfo.ApplicationData()); |
|
877 TUint32 lAppSid = 0; |
|
878 TUint limit = 0xFFFFFFFF; |
|
879 User::LeaveIfError( lexer.BoundedVal(lAppSid, EHex, limit) ); |
|
880 TApaAppInfo appInfo; |
|
881 User::LeaveIfError( alsSession.GetAppInfo( appInfo, TUid::Uid( lAppSid ))); |
|
882 // check if the dll file is in ROM or not |
|
883 fileName.Copy( appInfo.iFullName ); |
|
884 } |
|
885 else if( aRegAppInfo.ApplicationType() == ELcDocument ) |
|
886 { |
|
887 // for document we should check for the document file name |
|
888 fileName.Copy( aRegAppInfo.ApplicationData() ); |
|
889 } |
|
890 else if( aRegAppInfo.ApplicationType() == ELcWebUrl ) |
|
891 { |
|
892 // for web url it will be registration filename |
|
893 fileName.Copy( iFileNameArry[ iregFileCount ] ); |
|
894 } |
|
895 |
|
896 if( fileName.Length() > 0 ) |
|
897 { |
|
898 // parse the file name and check the drive letter |
|
899 TParse parse; |
|
900 parse.Set( fileName, NULL, NULL ); |
|
901 TPtrC drive = parse.Drive(); |
|
902 if( drive[0] == PathInfo::RomRootPath()[0] ) |
|
903 { |
|
904 aRegAppInfo.SetSystemCharacteristics( CLcLocationAppInfo::ESysCharRomBased); |
|
905 } |
|
906 else |
|
907 { |
|
908 aRegAppInfo.SetSystemCharacteristics( CLcLocationAppInfo::ESysCharNone); |
|
909 } |
|
910 } |
|
911 } |
|
912 |
|
913 // ----------------------------------------------------------------------------- |
|
914 // CLcRegistry::IsAppUpgraded |
|
915 // ----------------------------------------------------------------------------- |
|
916 // |
|
917 TBool CLcRegistry::IsAppUpgraded( TFileName& aFileName ) |
|
918 { |
|
919 DEBUG( "+ CLcRegistry::CheckforAppUpgrade("); |
|
920 |
|
921 // If filename is already there in the old list and presence |
|
922 // flag also true then check the time stamp between current file and old file |
|
923 TEntry oldEntry,newEntry; |
|
924 TFileName newFileName = iFileNameArry[ iregFileCount ]; |
|
925 iFs.Entry( aFileName, oldEntry ); |
|
926 iFs.Entry( newFileName, newEntry ); |
|
927 |
|
928 if( oldEntry.iModified == newEntry.iModified ) |
|
929 { |
|
930 return EFalse; |
|
931 } |
|
932 else |
|
933 { |
|
934 return ETrue; |
|
935 } |
|
936 } |
|
937 |
|
938 // ----------------------------------------------------------------------------- |
|
939 // CLcRegistry::SetAbsentAppNameL |
|
940 // ----------------------------------------------------------------------------- |
|
941 // |
|
942 void CLcRegistry::SetAbsentAppNameL( CLcRegAppInfo* aAppInfo ) |
|
943 { |
|
944 RApaLsSession lsSession; |
|
945 User::LeaveIfError( lsSession.Connect() ); |
|
946 CleanupClosePushL( lsSession ); |
|
947 //Check the application type.If Application then validate it |
|
948 if( aAppInfo->ApplicationType() == ELcNativeApplication ) |
|
949 { |
|
950 TLex lexer(aAppInfo->ApplicationData()); |
|
951 TUint32 lAppSid = 0; |
|
952 TUint limit = 0xFFFFFFFF; |
|
953 User::LeaveIfError( lexer.BoundedVal(lAppSid, EHex, limit) ); |
|
954 TApaAppInfo appNameInfo; |
|
955 User::LeaveIfError( lsSession.GetAppInfo( appNameInfo, TUid::Uid( lAppSid ))); |
|
956 aAppInfo->SetNameL(appNameInfo.iCaption); |
|
957 } |
|
958 else |
|
959 { |
|
960 aAppInfo->SetNameL( aAppInfo->ApplicationData() ); |
|
961 } |
|
962 CleanupStack::PopAndDestroy(); //lsSession |
|
963 } |
|
964 |
|
965 |
|
966 // --------------------------------------------------------------------------- |
|
967 // static TInt PositionDescOrdering |
|
968 // Ordering function for inserting the elements into the applist array. |
|
969 // The ordering is done first based on the previous index. |
|
970 // |
|
971 // @param CLcRegAppInfo& First appinfo Element |
|
972 // @param CLcRegAppInfo& Second appinfo Element |
|
973 // @return 1. zero, if the two objects are equal. |
|
974 // |
|
975 // 2. a negative value, if the first object is less than the second. |
|
976 // |
|
977 // 3. a positive value, if the first object is greater than the second. |
|
978 // |
|
979 // --------------------------------------------------------------------------- |
|
980 TInt PositionDescOrdering( const CLcRegAppInfo& aAppInfo1, |
|
981 const CLcRegAppInfo& aAppInfo2 ) |
|
982 { |
|
983 CLcRegAppInfo* appInfo1 = const_cast< CLcRegAppInfo*>(&aAppInfo1); |
|
984 CLcRegAppInfo* appInfo2 = const_cast< CLcRegAppInfo*>(&aAppInfo2); |
|
985 return ( appInfo1->Index() - appInfo2->Index()); |
|
986 } |
|
987 //End of file |
|
988 |
|