53 // --------------------------------------------------------------------------- |
50 // --------------------------------------------------------------------------- |
54 // |
51 // |
55 CCaUsifScanner::CCaUsifScanner( CCaStorageProxy& aStorageProxy ) : |
52 CCaUsifScanner::CCaUsifScanner( CCaStorageProxy& aStorageProxy ) : |
56 iStorageProxy( aStorageProxy ) |
53 iStorageProxy( aStorageProxy ) |
57 { |
54 { |
58 |
|
59 } |
55 } |
60 |
56 |
61 // --------------------------------------------------------------------------- |
57 // --------------------------------------------------------------------------- |
62 // |
58 // |
63 // --------------------------------------------------------------------------- |
59 // --------------------------------------------------------------------------- |
64 // |
60 // |
65 void CCaUsifScanner::ConstructL() |
61 void CCaUsifScanner::ConstructL() |
66 { |
62 { |
67 AddCollectionUsifL(); |
63 iSystemInstallNotifier = CCaInstallNotifier::NewL( *this, |
68 AddNativeAppsL(); |
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(); |
69 } |
78 } |
70 |
79 |
71 // --------------------------------------------------------------------------- |
80 // --------------------------------------------------------------------------- |
72 // |
81 // |
73 // --------------------------------------------------------------------------- |
82 // --------------------------------------------------------------------------- |
74 // |
83 // |
75 CCaUsifScanner::~CCaUsifScanner() |
84 CCaUsifScanner::~CCaUsifScanner() |
76 { |
85 { |
77 } |
86 delete iMmcWatcher; |
78 |
87 delete iSystemInstallNotifier; |
79 // --------------------------------------------------------------------------- |
88 delete iUsifUninstallNotifier; |
80 // |
89 delete iJavaInstallNotifier; |
81 // --------------------------------------------------------------------------- |
90 iFs.Close(); |
82 // |
91 iSoftwareRegistry.Close(); |
83 void CCaUsifScanner::InstallL( const TDesC& aFileName ) |
92 } |
84 { |
93 |
85 RSoftwareInstall sif; |
94 // --------------------------------------------------------------------------- |
86 CleanupClosePushL( sif ); |
95 // |
87 User::LeaveIfError( sif.Connect()); |
96 // --------------------------------------------------------------------------- |
88 |
97 // |
89 // Install the component |
98 /*void CCaUsifScanner::InstallL( const TDesC& aFileName ) |
90 TRequestStatus status; |
99 { |
91 sif.Install( aFileName, status, EFalse ); |
100 RSoftwareInstall sif; |
92 User::WaitForRequest( status ); |
101 CleanupClosePushL( sif ); |
93 User::LeaveIfError(status.Int()); |
102 User::LeaveIfError( sif.Connect()); |
94 |
103 |
95 // Disconnect from the SIF server |
104 // Install the component |
96 CleanupStack::PopAndDestroy( &sif ); |
105 TRequestStatus status; |
97 } |
106 sif.Install( aFileName, status, EFalse ); |
98 |
107 User::WaitForRequest( status ); |
99 // --------------------------------------------------------------------------- |
108 User::LeaveIfError(status.Int()); |
100 // |
109 |
101 // --------------------------------------------------------------------------- |
110 // Disconnect from the SIF server |
102 // |
111 CleanupStack::PopAndDestroy( &sif ); |
103 void CCaUsifScanner::AddCollectionUsifL() |
112 }*/ |
104 { |
113 |
105 if( GetCollectionUsifIdL() == 0 ) |
114 // --------------------------------------------------------------------------- |
106 { |
115 // |
107 CCaInnerEntry *entry = CCaInnerEntry::NewLC(); |
116 // --------------------------------------------------------------------------- |
108 entry->SetRole( EGroupEntryRole ); |
117 // |
109 entry->SetEntryTypeNameL( KCaTypeCollection ); |
118 void CCaUsifScanner::HandleInstallNotifyL( TInt /*aUid*/) |
110 entry->SetFlags( ERemovable | EVisible ); |
119 { |
111 entry->SetTextL( KUsifPluginCollection ); |
120 UpdateUsifListL(); |
112 iStorageProxy.AddL( entry ); |
121 } |
113 iCollectionUsifId = entry->GetId(); |
122 |
114 CleanupStack::PopAndDestroy( entry ); |
123 // --------------------------------------------------------------------------- |
115 |
124 // |
116 TCaOperationParams params = |
125 // --------------------------------------------------------------------------- |
117 { |
126 // |
118 TCaOperationParams::EPrepend, 2, 0 |
127 #ifdef COVERAGE_MEASUREMENT |
119 }; |
128 #pragma CTC SKIP |
120 RArray<TInt> ids; |
129 #endif //COVERAGE_MEASUREMENT |
121 CleanupClosePushL( ids ); |
130 void CCaUsifScanner::MmcChangeL() |
122 ids.AppendL( iCollectionUsifId ); |
131 { |
123 iStorageProxy.OrganizeL( ids, params ); |
132 UpdateUsifListL(); |
124 CleanupStack::PopAndDestroy( &ids ); |
133 } |
125 } |
134 #ifdef COVERAGE_MEASUREMENT |
126 } |
135 #pragma CTC ENDSKIP |
127 |
136 #endif //COVERAGE_MEASUREMENT |
128 // --------------------------------------------------------------------------- |
137 // --------------------------------------------------------------------------- |
129 // |
138 // |
130 // --------------------------------------------------------------------------- |
139 // --------------------------------------------------------------------------- |
131 // |
140 // |
132 TInt CCaUsifScanner::GetCollectionUsifIdL() |
141 void CCaUsifScanner::UpdateUsifListL() |
133 { |
142 { |
134 if( iCollectionUsifId == 0 ) |
143 AddPackageL(); |
135 { |
144 UpdatePackagesL(); |
136 RPointerArray<CCaInnerEntry> resultArray; |
|
137 CleanupResetAndDestroyPushL( resultArray ); |
|
138 CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC(); |
|
139 CDesC16ArrayFlat* appType = new ( ELeave ) CDesC16ArrayFlat( 1 ); |
|
140 CleanupStack::PushL( appType ); |
|
141 appType->AppendL( KCaTypeCollection ); |
|
142 allAppQuery->SetEntryTypeNames( appType ); |
|
143 allAppQuery->SetRole(CCaInnerQuery::Group); |
|
144 CleanupStack::Pop( appType ); |
|
145 iStorageProxy.GetEntriesL( allAppQuery, resultArray ); |
|
146 CleanupStack::PopAndDestroy( allAppQuery ); |
|
147 for(TInt i(0); i< resultArray.Count(); i++ ) |
|
148 { |
|
149 if(!resultArray[i]->GetText().Compare(KUsifPluginCollection)) |
|
150 iCollectionUsifId = resultArray[i]->GetId(); |
|
151 } |
|
152 CleanupStack::PopAndDestroy( &resultArray ); |
|
153 } |
|
154 return iCollectionUsifId; |
|
155 } |
145 } |
156 |
146 |
157 // --------------------------------------------------------------------------- |
147 // --------------------------------------------------------------------------- |
158 // |
148 // |
159 // --------------------------------------------------------------------------- |
149 // --------------------------------------------------------------------------- |
160 // |
150 // |
161 void CCaUsifScanner::CreateCaEntryFromEntryL( |
151 void CCaUsifScanner::CreateCaEntryFromEntryL( |
162 const CComponentEntry* aEntry, CCaInnerEntry* aCaEntry ) |
152 const CComponentEntry* aEntry, CCaInnerEntry* aCaEntry ) |
163 { |
153 { |
164 aCaEntry->SetRole( EItemEntryRole ); |
154 aCaEntry->SetRole( EItemEntryRole ); |
165 aCaEntry->SetEntryTypeNameL(KCaTypeApp); |
155 aCaEntry->SetEntryTypeNameL( KCaTypePackage ); |
166 if( aEntry->Name().Compare(KNullDesC)) |
156 if( !aEntry->SoftwareType().Compare( KSoftwareTypeNative ) ) |
167 { |
157 { |
168 aCaEntry->SetTextL(aEntry->Name()); |
158 aCaEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueNative ); |
|
159 } |
|
160 else if( !aEntry->SoftwareType().Compare( KSoftwareTypeJava ) ) |
|
161 { |
|
162 aCaEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueJava ); |
|
163 } |
|
164 if( aEntry->Name().Compare( KNullDesC ) ) |
|
165 { |
|
166 aCaEntry->SetTextL( aEntry->Name() ); |
|
167 aCaEntry->AddAttributeL( KCaAttrLongName, aEntry->Name() ); |
169 } |
168 } |
170 if( !aEntry->IsHidden() ) |
169 if( !aEntry->IsHidden() ) |
171 { |
170 { |
172 aCaEntry->SetFlags( EVisible ); |
171 aCaEntry->SetFlags( EVisible ); |
173 } |
172 } |
174 if( aEntry->IsRemovable() ) |
173 if( aEntry->IsRemovable() ) |
175 { |
174 { |
176 aCaEntry->SetFlags( aCaEntry->GetFlags() | ERemovable ); |
175 aCaEntry->SetFlags( aCaEntry->GetFlags() | ERemovable ); |
177 } |
176 } |
178 if( aEntry->GlobalId().Compare( KNullDesC ) ) |
177 // entries obtained with usif should have component id. |
179 { |
178 //it's needed for uninstalling |
180 TLex lex( aEntry->GlobalId() ); |
|
181 TUint uint( 0 ); |
|
182 User::LeaveIfError( lex.Val( uint, EHex ) ); |
|
183 aCaEntry->SetUid( uint ); |
|
184 } |
|
185 RBuf compIdDesc; |
179 RBuf compIdDesc; |
186 CleanupClosePushL(compIdDesc); |
180 CleanupClosePushL( compIdDesc ); |
187 compIdDesc.CreateL(KCaMaxAttrValueLen); |
181 compIdDesc.CreateL( KCaMaxAttrValueLen ); |
188 compIdDesc.Num(aEntry->ComponentId()); |
182 compIdDesc.Num( aEntry->ComponentId() ); |
189 aCaEntry->AddAttributeL( KCaAttrComponentId, compIdDesc ); |
183 aCaEntry->AddAttributeL( KCaAttrComponentId, compIdDesc ); |
190 CleanupStack::PopAndDestroy( &compIdDesc ); |
184 CleanupStack::PopAndDestroy( &compIdDesc ); |
191 |
185 } |
192 } |
186 |
193 |
187 // --------------------------------------------------------------------------- |
194 // --------------------------------------------------------------------------- |
188 // |
195 // |
189 // --------------------------------------------------------------------------- |
196 // --------------------------------------------------------------------------- |
190 // |
197 // |
191 void CCaUsifScanner::AddPackageL() |
198 void CCaUsifScanner::AddNativeAppsL() |
192 { |
199 { |
|
200 TLanguage locale = TLanguage(-1); |
|
201 |
|
202 CComponentFilter *filter = CComponentFilter::NewL(); |
|
203 CleanupStack::PushL(filter); |
|
204 filter->SetSoftwareTypeL( KSoftwareTypeNative ); |
|
205 filter->SetRemovable(ETrue); |
|
206 |
|
207 // Connect to the SCR server |
|
208 RSoftwareComponentRegistry *scr = new RSoftwareComponentRegistry(); |
|
209 CleanupClosePushL(*scr); |
|
210 User::LeaveIfError( scr->Connect() ); |
|
211 |
|
212 // Create an SCR view |
|
213 RSoftwareComponentRegistryView *scrView = |
|
214 new RSoftwareComponentRegistryView(); |
|
215 CleanupClosePushL(*scrView); |
|
216 scrView->OpenViewL( *scr, filter ); |
|
217 |
|
218 // Iterate over the matching components |
|
219 CComponentEntry* entry = CComponentEntry::NewLC(); |
|
220 |
|
221 RPointerArray<CCaInnerEntry> entries; |
193 RPointerArray<CCaInnerEntry> entries; |
222 CleanupResetAndDestroyPushL( entries ); |
194 CleanupResetAndDestroyPushL( entries ); |
223 GetCaAppEntriesL(entries); |
195 GetCaPackageEntriesL( entries ); |
224 |
196 |
225 RArray<TInt> entryIds; |
197 RPointerArray<CComponentEntry> resultUsifArray; |
226 CleanupClosePushL(entryIds); |
198 CleanupResetAndDestroyPushL( resultUsifArray ); |
227 while( scrView->NextComponentL( *entry, locale ) ) |
199 GetUsifPackageEntriesL( resultUsifArray ); |
228 { |
200 |
229 CCaInnerEntry *caEntry = CCaInnerEntry::NewLC(); |
201 for( TInt idx(0); idx < resultUsifArray.Count(); idx++ ) |
230 CreateCaEntryFromEntryL( entry, caEntry ); |
202 { |
231 |
203 if( PackageExistL( entries, resultUsifArray[idx] ) == KErrNotFound ) |
232 if( !AppExist(entries, caEntry)) |
204 { |
233 { |
205 CCaInnerEntry *caEntry = CCaInnerEntry::NewLC(); |
|
206 CreateCaEntryFromEntryL( resultUsifArray[idx], caEntry ); |
234 iStorageProxy.AddL( caEntry ); |
207 iStorageProxy.AddL( caEntry ); |
235 entryIds.Append( caEntry->GetId() ); |
208 CleanupStack::PopAndDestroy( caEntry ); |
236 } |
209 } |
237 CleanupStack::PopAndDestroy( caEntry ); |
210 } |
238 } |
211 |
239 TCaOperationParams params = |
212 CleanupStack::PopAndDestroy( &resultUsifArray ); |
240 { |
|
241 TCaOperationParams::EAppend, iCollectionUsifId, 0 |
|
242 }; |
|
243 iStorageProxy.OrganizeL( entryIds, params ); |
|
244 |
|
245 CleanupStack::PopAndDestroy( &entryIds ); |
|
246 CleanupStack::PopAndDestroy( &entries ); |
213 CleanupStack::PopAndDestroy( &entries ); |
247 CleanupStack::PopAndDestroy( entry ); |
214 } |
248 CleanupStack::PopAndDestroy(scrView); |
215 |
249 CleanupStack::PopAndDestroy(scr); |
216 // --------------------------------------------------------------------------- |
250 CleanupStack::PopAndDestroy(filter); |
217 // |
251 } |
218 // --------------------------------------------------------------------------- |
252 |
219 // |
253 // --------------------------------------------------------------------------- |
220 void CCaUsifScanner::UpdatePackagesL() |
254 // |
221 { |
255 // --------------------------------------------------------------------------- |
222 RPointerArray<CCaInnerEntry> resultCaArray; |
256 // |
223 CleanupResetAndDestroyPushL( resultCaArray ); |
257 void CCaUsifScanner::GetCaAppEntriesL( |
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( |
258 RPointerArray<CCaInnerEntry>& aArray ) |
242 RPointerArray<CCaInnerEntry>& aArray ) |
259 { |
243 { |
260 CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC(); |
244 CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC(); |
261 CDesC16ArrayFlat* appType = new ( ELeave ) CDesC16ArrayFlat( 1 ); |
245 CDesC16ArrayFlat* appType = new ( ELeave ) CDesC16ArrayFlat( 1 ); |
262 CleanupStack::PushL( appType ); |
246 CleanupStack::PushL( appType ); |
263 appType->AppendL( KCaTypeApp ); |
247 appType->AppendL( KCaTypePackage ); |
264 allAppQuery->SetEntryTypeNames( appType ); |
248 allAppQuery->SetEntryTypeNames( appType ); |
265 CleanupStack::Pop( appType ); |
249 CleanupStack::Pop( appType ); |
266 iStorageProxy.GetEntriesL( allAppQuery, aArray ); |
250 iStorageProxy.GetEntriesL( allAppQuery, aArray ); |
267 CleanupStack::PopAndDestroy( allAppQuery ); |
251 CleanupStack::PopAndDestroy( allAppQuery ); |
268 } |
252 } |
269 |
253 |
270 // --------------------------------------------------------------------------- |
254 // --------------------------------------------------------------------------- |
271 // |
255 // |
272 // --------------------------------------------------------------------------- |
256 // --------------------------------------------------------------------------- |
273 // |
257 // |
274 TInt CCaUsifScanner::AppExist( RPointerArray<CCaInnerEntry>& aArray, |
258 void CCaUsifScanner::GetUsifPackageEntriesL( |
275 CCaInnerEntry* aEntry ) |
259 RPointerArray<CComponentEntry>& aArray ) |
276 { |
260 { |
277 for (TInt i(0); i < aArray.Count(); i++) |
261 CComponentFilter *filter = CComponentFilter::NewL(); |
278 { |
262 CleanupStack::PushL( filter ); |
279 if( aArray[i]->GetUid() == aEntry->GetUid()) |
263 filter->SetRemovable( ETrue ); |
280 return KErrAlreadyExists; |
264 filter->SetHidden( EFalse ); |
281 } |
265 |
282 return KErrNone; |
266 // Create an SCR view |
283 } |
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++ ) |
|
300 { |
|
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 } |
|
312 } |
|
313 return KErrNotFound; |
|
314 } |
|
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 } |