85
|
1 |
/*
|
|
2 |
* Copyright (c) 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 "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: causifscanner.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <e32property.h>
|
|
19 |
#include <f32file.h>
|
|
20 |
#include <badesca.h>
|
125
|
21 |
#include <driveinfo.h>
|
85
|
22 |
|
|
23 |
#include "causifscanner.h"
|
|
24 |
#include "cainnerentry.h"
|
|
25 |
#include "cainnerquery.h"
|
|
26 |
#include "cadef.h"
|
|
27 |
#include "castorageproxy.h"
|
|
28 |
#include "caarraycleanup.inl"
|
|
29 |
|
|
30 |
using namespace Usif;
|
|
31 |
|
|
32 |
// ---------------------------------------------------------------------------
|
|
33 |
//
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
CCaUsifScanner* CCaUsifScanner::NewL( TPluginParams* aPluginParams )
|
|
37 |
{
|
92
|
38 |
CCaUsifScanner* self = new ( ELeave ) CCaUsifScanner(
|
102
|
39 |
*aPluginParams->storageProxy, *aPluginParams->softwareRegistry );
|
85
|
40 |
CleanupStack::PushL( self );
|
|
41 |
self->ConstructL();
|
|
42 |
CleanupStack::Pop( self );
|
|
43 |
return self;
|
|
44 |
}
|
|
45 |
|
|
46 |
// ---------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
//
|
102
|
50 |
CCaUsifScanner::CCaUsifScanner( CCaStorageProxy& aStorageProxy,
|
|
51 |
RSoftwareComponentRegistry& aSoftwareRegistry ) :
|
|
52 |
iStorageProxy( aStorageProxy ), iSoftwareRegistry(aSoftwareRegistry)
|
85
|
53 |
{
|
|
54 |
}
|
|
55 |
|
|
56 |
// ---------------------------------------------------------------------------
|
|
57 |
//
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
//
|
|
60 |
void CCaUsifScanner::ConstructL()
|
|
61 |
{
|
119
|
62 |
iInstallNotifier = CCaInstallNotifier::NewL( *this );
|
92
|
63 |
|
|
64 |
User::LeaveIfError( iFs.Connect() );
|
|
65 |
iMmcWatcher = CCaMmcWatcher::NewL( iFs, this );
|
|
66 |
|
|
67 |
UpdateUsifListL();
|
85
|
68 |
}
|
|
69 |
|
|
70 |
// ---------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
CCaUsifScanner::~CCaUsifScanner()
|
|
75 |
{
|
92
|
76 |
delete iMmcWatcher;
|
94
|
77 |
iFs.Close();
|
119
|
78 |
delete iInstallNotifier;
|
85
|
79 |
}
|
|
80 |
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
//
|
92
|
85 |
/*void CCaUsifScanner::InstallL( const TDesC& aFileName )
|
|
86 |
{
|
|
87 |
RSoftwareInstall sif;
|
|
88 |
CleanupClosePushL( sif );
|
|
89 |
User::LeaveIfError( sif.Connect());
|
|
90 |
|
|
91 |
// Install the component
|
|
92 |
TRequestStatus status;
|
|
93 |
sif.Install( aFileName, status, EFalse );
|
|
94 |
User::WaitForRequest( status );
|
|
95 |
User::LeaveIfError(status.Int());
|
|
96 |
|
|
97 |
// Disconnect from the SIF server
|
|
98 |
CleanupStack::PopAndDestroy( &sif );
|
|
99 |
}*/
|
|
100 |
|
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
// ---------------------------------------------------------------------------
|
|
104 |
//
|
119
|
105 |
void CCaUsifScanner::HandleInstallNotifyL()
|
85
|
106 |
{
|
92
|
107 |
UpdateUsifListL();
|
85
|
108 |
}
|
|
109 |
|
|
110 |
// ---------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
// ---------------------------------------------------------------------------
|
|
113 |
//
|
92
|
114 |
#ifdef COVERAGE_MEASUREMENT
|
|
115 |
#pragma CTC SKIP
|
|
116 |
#endif //COVERAGE_MEASUREMENT
|
|
117 |
void CCaUsifScanner::MmcChangeL()
|
85
|
118 |
{
|
92
|
119 |
UpdateUsifListL();
|
|
120 |
}
|
|
121 |
#ifdef COVERAGE_MEASUREMENT
|
|
122 |
#pragma CTC ENDSKIP
|
|
123 |
#endif //COVERAGE_MEASUREMENT
|
|
124 |
// ---------------------------------------------------------------------------
|
|
125 |
//
|
|
126 |
// ---------------------------------------------------------------------------
|
|
127 |
//
|
|
128 |
void CCaUsifScanner::UpdateUsifListL()
|
|
129 |
{
|
|
130 |
AddPackageL();
|
|
131 |
UpdatePackagesL();
|
85
|
132 |
}
|
|
133 |
|
|
134 |
// ---------------------------------------------------------------------------
|
|
135 |
//
|
|
136 |
// ---------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
void CCaUsifScanner::CreateCaEntryFromEntryL(
|
|
139 |
const CComponentEntry* aEntry, CCaInnerEntry* aCaEntry )
|
|
140 |
{
|
|
141 |
aCaEntry->SetRole( EItemEntryRole );
|
92
|
142 |
aCaEntry->SetEntryTypeNameL( KCaTypePackage );
|
|
143 |
if( !aEntry->SoftwareType().Compare( KSoftwareTypeNative ) )
|
|
144 |
{
|
|
145 |
aCaEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueNative );
|
|
146 |
}
|
|
147 |
else if( !aEntry->SoftwareType().Compare( KSoftwareTypeJava ) )
|
85
|
148 |
{
|
92
|
149 |
aCaEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueJava );
|
|
150 |
}
|
116
|
151 |
else if( !aEntry->SoftwareType().Compare( KSoftwareTypeWidget ) )
|
|
152 |
{
|
|
153 |
aCaEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueCWRT );
|
119
|
154 |
}
|
92
|
155 |
if( aEntry->Name().Compare( KNullDesC ) )
|
|
156 |
{
|
|
157 |
aCaEntry->SetTextL( aEntry->Name() );
|
85
|
158 |
}
|
|
159 |
if( !aEntry->IsHidden() )
|
|
160 |
{
|
|
161 |
aCaEntry->SetFlags( EVisible );
|
|
162 |
}
|
|
163 |
if( aEntry->IsRemovable() )
|
|
164 |
{
|
|
165 |
aCaEntry->SetFlags( aCaEntry->GetFlags() | ERemovable );
|
125
|
166 |
|
|
167 |
TChar drive;
|
|
168 |
RBuf drives;
|
|
169 |
drives.CreateL(KMaxFileName);
|
|
170 |
CleanupClosePushL( drives );
|
|
171 |
const TInt driveListLen(aEntry->InstalledDrives().Length());
|
|
172 |
for (TInt i( 0 ); i < driveListLen; ++i)
|
|
173 |
{
|
|
174 |
// Skip PhoneMemory and if we have some icon resolved
|
|
175 |
if (aEntry->InstalledDrives()[i] != '\0' && drives.Length() == 0
|
|
176 |
&& (DriveInfo::GetDefaultDrive(
|
|
177 |
DriveInfo::EDefaultPhoneMemory, drive ) == KErrNone
|
|
178 |
&& TChar('A'+ i) != TChar(drive)))
|
|
179 |
{
|
|
180 |
TUint drvStatus( 0 );
|
|
181 |
int err = DriveInfo::GetDriveStatus( iFs, i, drvStatus );
|
|
182 |
if ( ( drvStatus & DriveInfo::EDriveInternal ) &&
|
|
183 |
( drvStatus & DriveInfo::EDriveExternallyMountable ) ){
|
|
184 |
// Mass Storage
|
|
185 |
drives.Append(_L("qtg_mono_hard_disk"));
|
|
186 |
}
|
|
187 |
else if(drvStatus & DriveInfo::EDriveRemote ||
|
|
188 |
drvStatus & DriveInfo::EDriveUsbMemory)
|
|
189 |
{
|
|
190 |
// Usb or remote drive
|
|
191 |
drives.Append(_L("qtg_mono_usb"));
|
|
192 |
}
|
|
193 |
else if( ( drvStatus & DriveInfo::EDriveRemovable ) &&
|
|
194 |
( drvStatus & DriveInfo::EDriveExternallyMountable ) )
|
|
195 |
{
|
|
196 |
// MMC
|
|
197 |
drives.Append(_L("qtg_mono_memory_in_use"));
|
|
198 |
}
|
|
199 |
}
|
|
200 |
}
|
|
201 |
if (drives.Length() > 0) {
|
|
202 |
aCaEntry->AddAttributeL( KCaAttrDrivesIconIds, drives );
|
85
|
203 |
}
|
125
|
204 |
CleanupStack::PopAndDestroy( &drives );
|
|
205 |
}
|
|
206 |
|
|
207 |
|
92
|
208 |
// entries obtained with usif should have component id.
|
|
209 |
//it's needed for uninstalling
|
85
|
210 |
RBuf compIdDesc;
|
92
|
211 |
CleanupClosePushL( compIdDesc );
|
|
212 |
compIdDesc.CreateL( KCaMaxAttrValueLen );
|
|
213 |
compIdDesc.Num( aEntry->ComponentId() );
|
85
|
214 |
aCaEntry->AddAttributeL( KCaAttrComponentId, compIdDesc );
|
|
215 |
CleanupStack::PopAndDestroy( &compIdDesc );
|
|
216 |
}
|
|
217 |
|
|
218 |
// ---------------------------------------------------------------------------
|
|
219 |
//
|
|
220 |
// ---------------------------------------------------------------------------
|
|
221 |
//
|
92
|
222 |
void CCaUsifScanner::AddPackageL()
|
85
|
223 |
{
|
|
224 |
RPointerArray<CCaInnerEntry> entries;
|
|
225 |
CleanupResetAndDestroyPushL( entries );
|
92
|
226 |
GetCaPackageEntriesL( entries );
|
85
|
227 |
|
92
|
228 |
RPointerArray<CComponentEntry> resultUsifArray;
|
|
229 |
CleanupResetAndDestroyPushL( resultUsifArray );
|
|
230 |
GetUsifPackageEntriesL( resultUsifArray );
|
|
231 |
|
94
|
232 |
for( TInt i(0); i < resultUsifArray.Count(); i++ )
|
85
|
233 |
{
|
112
|
234 |
TInt entryIndex = PackageExists( entries, resultUsifArray[i]);
|
|
235 |
// entry is not present in CaStorage
|
|
236 |
if( entryIndex == KErrNotFound )
|
85
|
237 |
{
|
92
|
238 |
CCaInnerEntry *caEntry = CCaInnerEntry::NewLC();
|
94
|
239 |
CreateCaEntryFromEntryL( resultUsifArray[i], caEntry );
|
112
|
240 |
// in case we rebuild our db mark as missing
|
119
|
241 |
if( !(iSoftwareRegistry.IsComponentPresentL(
|
112
|
242 |
resultUsifArray[i]->ComponentId())) )
|
|
243 |
{
|
|
244 |
caEntry->SetFlags( caEntry->GetFlags() | EMissing );
|
|
245 |
}
|
85
|
246 |
iStorageProxy.AddL( caEntry );
|
92
|
247 |
CleanupStack::PopAndDestroy( caEntry );
|
119
|
248 |
}
|
112
|
249 |
// found in the CaStorage, mark is as missing
|
119
|
250 |
else if( !(iSoftwareRegistry.IsComponentPresentL(
|
|
251 |
resultUsifArray[i]->ComponentId() )) )
|
112
|
252 |
{
|
|
253 |
if( !( entries[entryIndex]->GetFlags() & EMissing ) )
|
|
254 |
{
|
119
|
255 |
entries[entryIndex]->SetFlags(
|
112
|
256 |
( entries[entryIndex]->GetFlags() | EMissing ) );
|
119
|
257 |
iStorageProxy.AddL(
|
112
|
258 |
entries[entryIndex], EFalse, EItemDisappeared );
|
|
259 |
}
|
|
260 |
}
|
|
261 |
// found in the storage remove missing flag as this is Present in scr
|
|
262 |
else if (entries[entryIndex]->GetFlags() & EMissing)
|
|
263 |
{
|
119
|
264 |
entries[entryIndex]->SetFlags(
|
112
|
265 |
entries[entryIndex]->GetFlags() & ~EMissing );
|
119
|
266 |
iStorageProxy.AddL( entries[entryIndex]);
|
85
|
267 |
}
|
|
268 |
}
|
|
269 |
|
92
|
270 |
CleanupStack::PopAndDestroy( &resultUsifArray );
|
85
|
271 |
CleanupStack::PopAndDestroy( &entries );
|
|
272 |
}
|
|
273 |
|
|
274 |
// ---------------------------------------------------------------------------
|
|
275 |
//
|
|
276 |
// ---------------------------------------------------------------------------
|
|
277 |
//
|
92
|
278 |
void CCaUsifScanner::UpdatePackagesL()
|
|
279 |
{
|
|
280 |
RPointerArray<CCaInnerEntry> resultCaArray;
|
|
281 |
CleanupResetAndDestroyPushL( resultCaArray );
|
|
282 |
GetCaPackageEntriesL( resultCaArray );
|
|
283 |
|
|
284 |
RPointerArray<CComponentEntry> resultUsifArray;
|
|
285 |
CleanupResetAndDestroyPushL( resultUsifArray );
|
|
286 |
GetUsifPackageEntriesL( resultUsifArray );
|
|
287 |
|
|
288 |
FindDeletedEntriesL( resultCaArray, resultUsifArray );
|
|
289 |
RemoveEntriesFromDbL( resultCaArray );
|
|
290 |
|
|
291 |
CleanupStack::PopAndDestroy( &resultUsifArray );
|
|
292 |
CleanupStack::PopAndDestroy( &resultCaArray );
|
|
293 |
}
|
|
294 |
|
|
295 |
// ---------------------------------------------------------------------------
|
|
296 |
//
|
|
297 |
// ---------------------------------------------------------------------------
|
|
298 |
//
|
|
299 |
void CCaUsifScanner::GetCaPackageEntriesL(
|
85
|
300 |
RPointerArray<CCaInnerEntry>& aArray )
|
|
301 |
{
|
|
302 |
CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC();
|
94
|
303 |
CDesC16ArrayFlat* appType =
|
|
304 |
new ( ELeave ) CDesC16ArrayFlat( KGranularityOne );
|
85
|
305 |
CleanupStack::PushL( appType );
|
92
|
306 |
appType->AppendL( KCaTypePackage );
|
85
|
307 |
allAppQuery->SetEntryTypeNames( appType );
|
|
308 |
CleanupStack::Pop( appType );
|
|
309 |
iStorageProxy.GetEntriesL( allAppQuery, aArray );
|
|
310 |
CleanupStack::PopAndDestroy( allAppQuery );
|
|
311 |
}
|
|
312 |
|
|
313 |
// ---------------------------------------------------------------------------
|
|
314 |
//
|
|
315 |
// ---------------------------------------------------------------------------
|
|
316 |
//
|
92
|
317 |
void CCaUsifScanner::GetUsifPackageEntriesL(
|
|
318 |
RPointerArray<CComponentEntry>& aArray )
|
85
|
319 |
{
|
92
|
320 |
CComponentFilter *filter = CComponentFilter::NewL();
|
|
321 |
CleanupStack::PushL( filter );
|
|
322 |
filter->SetRemovable( ETrue );
|
|
323 |
filter->SetHidden( EFalse );
|
|
324 |
|
|
325 |
// Create an SCR view
|
|
326 |
RSoftwareComponentRegistryView scrView;
|
|
327 |
CleanupClosePushL( scrView );
|
|
328 |
scrView.OpenViewL( iSoftwareRegistry, filter );
|
|
329 |
|
|
330 |
// Iterate over the matching components
|
|
331 |
//The ownership is transferred to the calling client.
|
94
|
332 |
while( CComponentEntry* entry = scrView.NextComponentL() )
|
92
|
333 |
{
|
|
334 |
CleanupStack::PushL( entry );
|
112
|
335 |
aArray.AppendL( entry );
|
|
336 |
CleanupStack::Pop( entry );
|
92
|
337 |
}
|
|
338 |
CleanupStack::PopAndDestroy( &scrView );
|
|
339 |
CleanupStack::PopAndDestroy( filter );
|
|
340 |
}
|
|
341 |
|
|
342 |
// ---------------------------------------------------------------------------
|
|
343 |
//
|
|
344 |
// ---------------------------------------------------------------------------
|
|
345 |
//
|
94
|
346 |
TInt CCaUsifScanner::PackageExists( RPointerArray<CCaInnerEntry>& aArray,
|
92
|
347 |
const CComponentEntry* aEntry )
|
|
348 |
{
|
94
|
349 |
TInt retVal( KErrNotFound );
|
|
350 |
for( TInt i( 0 ); i < aArray.Count(); i++ )
|
85
|
351 |
{
|
92
|
352 |
TBuf<KMaxUnits> compIdDes;
|
94
|
353 |
if( aArray[i]->FindAttribute( KCaAttrComponentId, compIdDes ) )
|
92
|
354 |
{
|
|
355 |
TLex lex( compIdDes );
|
|
356 |
TUint uint( 0 );
|
94
|
357 |
if( lex.Val( uint ) == KErrNone && aEntry->ComponentId() == uint )
|
92
|
358 |
{
|
94
|
359 |
retVal = i;
|
92
|
360 |
}
|
|
361 |
}
|
85
|
362 |
}
|
94
|
363 |
return retVal;
|
85
|
364 |
}
|
92
|
365 |
|
|
366 |
// ---------------------------------------------------------------------------
|
|
367 |
//
|
|
368 |
// ---------------------------------------------------------------------------
|
|
369 |
//
|
|
370 |
void CCaUsifScanner::FindDeletedEntriesL(
|
|
371 |
RPointerArray<CCaInnerEntry>& aCaArray, const RPointerArray<
|
|
372 |
CComponentEntry>& aUsifArray )
|
|
373 |
{
|
94
|
374 |
for( TInt i( aCaArray.Count() - 1 ); i >= 0; i-- )
|
92
|
375 |
{
|
|
376 |
TBuf<KMaxUnits> compIdDes;
|
94
|
377 |
if( aCaArray[i]->FindAttribute( KCaAttrComponentId, compIdDes ) )
|
92
|
378 |
{
|
|
379 |
TLex lex( compIdDes );
|
|
380 |
TUint uint( 0 );
|
|
381 |
User::LeaveIfError( lex.Val( uint ) );
|
|
382 |
//for each usif entry check if entry has to be removed
|
|
383 |
for( TInt k( 0 ); k < aUsifArray.Count(); k++ )
|
|
384 |
{
|
112
|
385 |
if( aUsifArray[k]->ComponentId() == uint)
|
92
|
386 |
{
|
94
|
387 |
delete aCaArray[i];
|
|
388 |
aCaArray.Remove( i );
|
92
|
389 |
break;
|
|
390 |
}
|
|
391 |
}
|
|
392 |
}
|
|
393 |
}
|
|
394 |
}
|
|
395 |
|
|
396 |
// ---------------------------------------------------------------------------
|
|
397 |
//
|
|
398 |
// ---------------------------------------------------------------------------
|
|
399 |
//
|
|
400 |
void CCaUsifScanner::RemoveEntriesFromDbL(
|
|
401 |
RPointerArray<CCaInnerEntry>& aCaArray )
|
|
402 |
{
|
|
403 |
RArray<TInt> entriesId;
|
|
404 |
CleanupClosePushL( entriesId );
|
|
405 |
for( TInt i( 0 ); i < aCaArray.Count(); i++ )
|
|
406 |
{
|
|
407 |
entriesId.Append( aCaArray[i]->GetId() );
|
|
408 |
}
|
|
409 |
iStorageProxy.RemoveL( entriesId );
|
|
410 |
CleanupStack::PopAndDestroy( &entriesId );
|
|
411 |
}
|
125
|
412 |
|