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>
|
|
21 |
#include <usif/sif/sif.h>
|
|
22 |
#include <usif/scr/scr.h>
|
|
23 |
#include <usif/sif/sifcommon.h>
|
|
24 |
|
|
25 |
#include "causifscanner.h"
|
|
26 |
#include "cainnerentry.h"
|
|
27 |
#include "cainnerquery.h"
|
|
28 |
#include "cadef.h"
|
|
29 |
#include "castorageproxy.h"
|
|
30 |
#include "caarraycleanup.inl"
|
|
31 |
|
|
32 |
using namespace Usif;
|
|
33 |
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
// ---------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
CCaUsifScanner* CCaUsifScanner::NewL( TPluginParams* aPluginParams )
|
|
39 |
{
|
92
|
40 |
CCaUsifScanner* self = new ( ELeave ) CCaUsifScanner(
|
|
41 |
*aPluginParams->storageProxy );
|
85
|
42 |
CleanupStack::PushL( self );
|
|
43 |
self->ConstructL();
|
|
44 |
CleanupStack::Pop( self );
|
|
45 |
return self;
|
|
46 |
}
|
|
47 |
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
// ---------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
CCaUsifScanner::CCaUsifScanner( CCaStorageProxy& aStorageProxy ) :
|
|
53 |
iStorageProxy( aStorageProxy )
|
|
54 |
{
|
|
55 |
}
|
|
56 |
|
|
57 |
// ---------------------------------------------------------------------------
|
|
58 |
//
|
|
59 |
// ---------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
void CCaUsifScanner::ConstructL()
|
|
62 |
{
|
92
|
63 |
iSystemInstallNotifier = CCaInstallNotifier::NewL( *this,
|
|
64 |
CCaInstallNotifier::ESisInstallNotification );
|
|
65 |
|
|
66 |
iUsifUninstallNotifier = CCaInstallNotifier::NewL( *this,
|
|
67 |
CCaInstallNotifier::EUsifUninstallNotification );
|
|
68 |
|
|
69 |
iJavaInstallNotifier = CCaInstallNotifier::NewL( *this,
|
|
70 |
CCaInstallNotifier::EJavaInstallNotification );
|
|
71 |
|
|
72 |
User::LeaveIfError( iFs.Connect() );
|
|
73 |
iMmcWatcher = CCaMmcWatcher::NewL( iFs, this );
|
|
74 |
|
|
75 |
User::LeaveIfError( iSoftwareRegistry.Connect() );
|
|
76 |
|
|
77 |
UpdateUsifListL();
|
85
|
78 |
}
|
|
79 |
|
|
80 |
// ---------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
// ---------------------------------------------------------------------------
|
|
83 |
//
|
|
84 |
CCaUsifScanner::~CCaUsifScanner()
|
|
85 |
{
|
92
|
86 |
delete iMmcWatcher;
|
|
87 |
delete iSystemInstallNotifier;
|
|
88 |
delete iUsifUninstallNotifier;
|
|
89 |
delete iJavaInstallNotifier;
|
|
90 |
iFs.Close();
|
|
91 |
iSoftwareRegistry.Close();
|
85
|
92 |
}
|
|
93 |
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
// ---------------------------------------------------------------------------
|
|
97 |
//
|
92
|
98 |
/*void CCaUsifScanner::InstallL( const TDesC& aFileName )
|
|
99 |
{
|
|
100 |
RSoftwareInstall sif;
|
|
101 |
CleanupClosePushL( sif );
|
|
102 |
User::LeaveIfError( sif.Connect());
|
|
103 |
|
|
104 |
// Install the component
|
|
105 |
TRequestStatus status;
|
|
106 |
sif.Install( aFileName, status, EFalse );
|
|
107 |
User::WaitForRequest( status );
|
|
108 |
User::LeaveIfError(status.Int());
|
|
109 |
|
|
110 |
// Disconnect from the SIF server
|
|
111 |
CleanupStack::PopAndDestroy( &sif );
|
|
112 |
}*/
|
|
113 |
|
|
114 |
// ---------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
// ---------------------------------------------------------------------------
|
|
117 |
//
|
|
118 |
void CCaUsifScanner::HandleInstallNotifyL( TInt /*aUid*/)
|
85
|
119 |
{
|
92
|
120 |
UpdateUsifListL();
|
85
|
121 |
}
|
|
122 |
|
|
123 |
// ---------------------------------------------------------------------------
|
|
124 |
//
|
|
125 |
// ---------------------------------------------------------------------------
|
|
126 |
//
|
92
|
127 |
#ifdef COVERAGE_MEASUREMENT
|
|
128 |
#pragma CTC SKIP
|
|
129 |
#endif //COVERAGE_MEASUREMENT
|
|
130 |
void CCaUsifScanner::MmcChangeL()
|
85
|
131 |
{
|
92
|
132 |
UpdateUsifListL();
|
|
133 |
}
|
|
134 |
#ifdef COVERAGE_MEASUREMENT
|
|
135 |
#pragma CTC ENDSKIP
|
|
136 |
#endif //COVERAGE_MEASUREMENT
|
|
137 |
// ---------------------------------------------------------------------------
|
|
138 |
//
|
|
139 |
// ---------------------------------------------------------------------------
|
|
140 |
//
|
|
141 |
void CCaUsifScanner::UpdateUsifListL()
|
|
142 |
{
|
|
143 |
AddPackageL();
|
|
144 |
UpdatePackagesL();
|
85
|
145 |
}
|
|
146 |
|
|
147 |
// ---------------------------------------------------------------------------
|
|
148 |
//
|
|
149 |
// ---------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
void CCaUsifScanner::CreateCaEntryFromEntryL(
|
|
152 |
const CComponentEntry* aEntry, CCaInnerEntry* aCaEntry )
|
|
153 |
{
|
|
154 |
aCaEntry->SetRole( EItemEntryRole );
|
92
|
155 |
aCaEntry->SetEntryTypeNameL( KCaTypePackage );
|
|
156 |
if( !aEntry->SoftwareType().Compare( KSoftwareTypeNative ) )
|
|
157 |
{
|
|
158 |
aCaEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueNative );
|
|
159 |
}
|
|
160 |
else if( !aEntry->SoftwareType().Compare( KSoftwareTypeJava ) )
|
85
|
161 |
{
|
92
|
162 |
aCaEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueJava );
|
|
163 |
}
|
|
164 |
if( aEntry->Name().Compare( KNullDesC ) )
|
|
165 |
{
|
|
166 |
aCaEntry->SetTextL( aEntry->Name() );
|
|
167 |
aCaEntry->AddAttributeL( KCaAttrLongName, aEntry->Name() );
|
85
|
168 |
}
|
|
169 |
if( !aEntry->IsHidden() )
|
|
170 |
{
|
|
171 |
aCaEntry->SetFlags( EVisible );
|
|
172 |
}
|
|
173 |
if( aEntry->IsRemovable() )
|
|
174 |
{
|
|
175 |
aCaEntry->SetFlags( aCaEntry->GetFlags() | ERemovable );
|
|
176 |
}
|
92
|
177 |
// entries obtained with usif should have component id.
|
|
178 |
//it's needed for uninstalling
|
85
|
179 |
RBuf compIdDesc;
|
92
|
180 |
CleanupClosePushL( compIdDesc );
|
|
181 |
compIdDesc.CreateL( KCaMaxAttrValueLen );
|
|
182 |
compIdDesc.Num( aEntry->ComponentId() );
|
85
|
183 |
aCaEntry->AddAttributeL( KCaAttrComponentId, compIdDesc );
|
|
184 |
CleanupStack::PopAndDestroy( &compIdDesc );
|
|
185 |
}
|
|
186 |
|
|
187 |
// ---------------------------------------------------------------------------
|
|
188 |
//
|
|
189 |
// ---------------------------------------------------------------------------
|
|
190 |
//
|
92
|
191 |
void CCaUsifScanner::AddPackageL()
|
85
|
192 |
{
|
|
193 |
RPointerArray<CCaInnerEntry> entries;
|
|
194 |
CleanupResetAndDestroyPushL( entries );
|
92
|
195 |
GetCaPackageEntriesL( entries );
|
85
|
196 |
|
92
|
197 |
RPointerArray<CComponentEntry> resultUsifArray;
|
|
198 |
CleanupResetAndDestroyPushL( resultUsifArray );
|
|
199 |
GetUsifPackageEntriesL( resultUsifArray );
|
|
200 |
|
|
201 |
for( TInt idx(0); idx < resultUsifArray.Count(); idx++ )
|
85
|
202 |
{
|
92
|
203 |
if( PackageExistL( entries, resultUsifArray[idx] ) == KErrNotFound )
|
85
|
204 |
{
|
92
|
205 |
CCaInnerEntry *caEntry = CCaInnerEntry::NewLC();
|
|
206 |
CreateCaEntryFromEntryL( resultUsifArray[idx], caEntry );
|
85
|
207 |
iStorageProxy.AddL( caEntry );
|
92
|
208 |
CleanupStack::PopAndDestroy( caEntry );
|
85
|
209 |
}
|
|
210 |
}
|
|
211 |
|
92
|
212 |
CleanupStack::PopAndDestroy( &resultUsifArray );
|
85
|
213 |
CleanupStack::PopAndDestroy( &entries );
|
|
214 |
}
|
|
215 |
|
|
216 |
// ---------------------------------------------------------------------------
|
|
217 |
//
|
|
218 |
// ---------------------------------------------------------------------------
|
|
219 |
//
|
92
|
220 |
void CCaUsifScanner::UpdatePackagesL()
|
|
221 |
{
|
|
222 |
RPointerArray<CCaInnerEntry> resultCaArray;
|
|
223 |
CleanupResetAndDestroyPushL( resultCaArray );
|
|
224 |
GetCaPackageEntriesL( resultCaArray );
|
|
225 |
|
|
226 |
RPointerArray<CComponentEntry> resultUsifArray;
|
|
227 |
CleanupResetAndDestroyPushL( resultUsifArray );
|
|
228 |
GetUsifPackageEntriesL( resultUsifArray );
|
|
229 |
|
|
230 |
FindDeletedEntriesL( resultCaArray, resultUsifArray );
|
|
231 |
RemoveEntriesFromDbL( resultCaArray );
|
|
232 |
|
|
233 |
CleanupStack::PopAndDestroy( &resultUsifArray );
|
|
234 |
CleanupStack::PopAndDestroy( &resultCaArray );
|
|
235 |
}
|
|
236 |
|
|
237 |
// ---------------------------------------------------------------------------
|
|
238 |
//
|
|
239 |
// ---------------------------------------------------------------------------
|
|
240 |
//
|
|
241 |
void CCaUsifScanner::GetCaPackageEntriesL(
|
85
|
242 |
RPointerArray<CCaInnerEntry>& aArray )
|
|
243 |
{
|
|
244 |
CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC();
|
|
245 |
CDesC16ArrayFlat* appType = new ( ELeave ) CDesC16ArrayFlat( 1 );
|
|
246 |
CleanupStack::PushL( appType );
|
92
|
247 |
appType->AppendL( KCaTypePackage );
|
85
|
248 |
allAppQuery->SetEntryTypeNames( appType );
|
|
249 |
CleanupStack::Pop( appType );
|
|
250 |
iStorageProxy.GetEntriesL( allAppQuery, aArray );
|
|
251 |
CleanupStack::PopAndDestroy( allAppQuery );
|
|
252 |
}
|
|
253 |
|
|
254 |
// ---------------------------------------------------------------------------
|
|
255 |
//
|
|
256 |
// ---------------------------------------------------------------------------
|
|
257 |
//
|
92
|
258 |
void CCaUsifScanner::GetUsifPackageEntriesL(
|
|
259 |
RPointerArray<CComponentEntry>& aArray )
|
85
|
260 |
{
|
92
|
261 |
CComponentFilter *filter = CComponentFilter::NewL();
|
|
262 |
CleanupStack::PushL( filter );
|
|
263 |
filter->SetRemovable( ETrue );
|
|
264 |
filter->SetHidden( EFalse );
|
|
265 |
|
|
266 |
// Create an SCR view
|
|
267 |
RSoftwareComponentRegistryView scrView;
|
|
268 |
CleanupClosePushL( scrView );
|
|
269 |
scrView.OpenViewL( iSoftwareRegistry, filter );
|
|
270 |
|
|
271 |
// Iterate over the matching components
|
|
272 |
//The ownership is transferred to the calling client.
|
|
273 |
CComponentEntry* entry = scrView.NextComponentL();
|
|
274 |
while( entry )
|
|
275 |
{
|
|
276 |
CleanupStack::PushL( entry );
|
|
277 |
if( iSoftwareRegistry.IsComponentPresentL( entry->ComponentId() ) )
|
|
278 |
{
|
|
279 |
aArray.AppendL( entry );
|
|
280 |
CleanupStack::Pop( entry );
|
|
281 |
}
|
|
282 |
else
|
|
283 |
{
|
|
284 |
CleanupStack::PopAndDestroy( entry );
|
|
285 |
}
|
|
286 |
entry = scrView.NextComponentL();
|
|
287 |
}
|
|
288 |
CleanupStack::PopAndDestroy( &scrView );
|
|
289 |
CleanupStack::PopAndDestroy( filter );
|
|
290 |
}
|
|
291 |
|
|
292 |
// ---------------------------------------------------------------------------
|
|
293 |
//
|
|
294 |
// ---------------------------------------------------------------------------
|
|
295 |
//
|
|
296 |
TInt CCaUsifScanner::PackageExistL( RPointerArray<CCaInnerEntry>& aArray,
|
|
297 |
const CComponentEntry* aEntry )
|
|
298 |
{
|
|
299 |
for( TInt idx( 0 ); idx < aArray.Count(); idx++ )
|
85
|
300 |
{
|
92
|
301 |
TBuf<KMaxUnits> compIdDes;
|
|
302 |
if( aArray[idx]->FindAttribute( KCaAttrComponentId, compIdDes ) )
|
|
303 |
{
|
|
304 |
TLex lex( compIdDes );
|
|
305 |
TUint uint( 0 );
|
|
306 |
User::LeaveIfError( lex.Val( uint ) );
|
|
307 |
if( aEntry->ComponentId() == uint )
|
|
308 |
{
|
|
309 |
return idx;
|
|
310 |
}
|
|
311 |
}
|
85
|
312 |
}
|
92
|
313 |
return KErrNotFound;
|
85
|
314 |
}
|
92
|
315 |
|
|
316 |
// ---------------------------------------------------------------------------
|
|
317 |
//
|
|
318 |
// ---------------------------------------------------------------------------
|
|
319 |
//
|
|
320 |
void CCaUsifScanner::FindDeletedEntriesL(
|
|
321 |
RPointerArray<CCaInnerEntry>& aCaArray, const RPointerArray<
|
|
322 |
CComponentEntry>& aUsifArray )
|
|
323 |
{
|
|
324 |
for( TInt idx( aCaArray.Count() - 1 ); idx >= 0; idx-- )
|
|
325 |
{
|
|
326 |
TBuf<KMaxUnits> compIdDes;
|
|
327 |
if( aCaArray[idx]->FindAttribute( KCaAttrComponentId, compIdDes ) )
|
|
328 |
{
|
|
329 |
TLex lex( compIdDes );
|
|
330 |
TUint uint( 0 );
|
|
331 |
User::LeaveIfError( lex.Val( uint ) );
|
|
332 |
//for each usif entry check if entry has to be removed
|
|
333 |
for( TInt k( 0 ); k < aUsifArray.Count(); k++ )
|
|
334 |
{
|
|
335 |
if( aUsifArray[k]->ComponentId() == uint
|
|
336 |
&& iSoftwareRegistry.IsComponentPresentL( uint ) )
|
|
337 |
{
|
|
338 |
delete aCaArray[idx];
|
|
339 |
aCaArray.Remove( idx );
|
|
340 |
break;
|
|
341 |
}
|
|
342 |
}
|
|
343 |
}
|
|
344 |
}
|
|
345 |
}
|
|
346 |
|
|
347 |
// ---------------------------------------------------------------------------
|
|
348 |
//
|
|
349 |
// ---------------------------------------------------------------------------
|
|
350 |
//
|
|
351 |
void CCaUsifScanner::RemoveEntriesFromDbL(
|
|
352 |
RPointerArray<CCaInnerEntry>& aCaArray )
|
|
353 |
{
|
|
354 |
RArray<TInt> entriesId;
|
|
355 |
CleanupClosePushL( entriesId );
|
|
356 |
for( TInt i( 0 ); i < aCaArray.Count(); i++ )
|
|
357 |
{
|
|
358 |
entriesId.Append( aCaArray[i]->GetId() );
|
|
359 |
}
|
|
360 |
iStorageProxy.RemoveL( entriesId );
|
|
361 |
CleanupStack::PopAndDestroy( &entriesId );
|
|
362 |
}
|