|
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: |
|
15 * |
|
16 */ |
|
17 #include <apgcli.h> |
|
18 #include <swi/sisregistrysession.h> |
|
19 #include <swi/sisregistryentry.h> |
|
20 #include <WidgetRegistryClient.h> |
|
21 #include <javaregistry.h> |
|
22 #include <javaregistrypackageentry.h> |
|
23 #include <javaregistryapplicationentry.h> |
|
24 #include <mcsmenuutils.h> |
|
25 #include "mcsdef.h" |
|
26 #include "mcsmenu.h" |
|
27 #include "mcsmenuitem.h" |
|
28 #include "menuuninstalloperation.h" |
|
29 |
|
30 _LIT8( KAppMimeType, "x-epoc/x-sisx-app" ); |
|
31 _LIT8( KMidletMimeType, "application/java-archive" ); |
|
32 _LIT8( KWidgetMimeType, "application/x-nokia-widget"); |
|
33 |
|
34 const TUid KMidletType = { 0x10210E26 }; |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 |
|
38 // --------------------------------------------------------- |
|
39 // CMenuUninstallOperation::~CMenuUninstallOperation |
|
40 // --------------------------------------------------------- |
|
41 // |
|
42 CMenuUninstallOperation::~CMenuUninstallOperation() |
|
43 { |
|
44 Cancel(); |
|
45 iUninstaller.Close(); |
|
46 delete iRemoveOperation; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CMenuUninstallOperation::NewL |
|
51 // --------------------------------------------------------- |
|
52 // |
|
53 CMenuUninstallOperation* CMenuUninstallOperation::NewL( |
|
54 RMenu &aMenu, |
|
55 TInt aPriority, |
|
56 TRequestStatus &aObserverStatus, |
|
57 CMenuItem& aItem ) |
|
58 { |
|
59 CMenuUninstallOperation* self; |
|
60 |
|
61 self = new ( ELeave ) CMenuUninstallOperation( aMenu, aPriority, aObserverStatus ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL( aItem ); |
|
64 CleanupStack::Pop( self ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CMenuUninstallOperation::CMenuUninstallOperation |
|
70 // --------------------------------------------------------- |
|
71 // |
|
72 CMenuUninstallOperation::CMenuUninstallOperation |
|
73 ( RMenu &aMenu, TInt aPriority, TRequestStatus &aObserverStatus ) |
|
74 : CMenuOperation( aMenu, aPriority, aObserverStatus ), |
|
75 iState( EIdle ), |
|
76 iRemoveOperation( NULL ) |
|
77 { |
|
78 CActiveScheduler::Add( this ); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CMenuUninstallOperation::ConstructL |
|
83 // --------------------------------------------------------- |
|
84 // |
|
85 void CMenuUninstallOperation::ConstructL( CMenuItem& aItem ) |
|
86 { |
|
87 TBool exists; |
|
88 TPtrC uidAttr( aItem.GetAttributeL( KMenuAttrUid, exists ) ); |
|
89 TUint uid; |
|
90 TUid packageUid = KNullUid; |
|
91 TPtrC8 mimeType; |
|
92 |
|
93 |
|
94 if( !exists ) |
|
95 { |
|
96 User::Leave( KErrCorrupt ); |
|
97 } |
|
98 |
|
99 if( aItem.Flags() & TMenuItem::ELockDelete ) |
|
100 { |
|
101 iObserverStatus = KRequestPending; |
|
102 SetActive(); |
|
103 TRequestStatus* status = &iStatus; |
|
104 User::RequestComplete( status, KErrAccessDenied ); |
|
105 return; |
|
106 } |
|
107 |
|
108 User::LeaveIfError( iUninstaller.Connect() ); |
|
109 |
|
110 iId = aItem.Id(); |
|
111 |
|
112 // Prepare parameters |
|
113 MenuUtils::GetTUint( uidAttr, uid ); |
|
114 |
|
115 AppInfoL( TUid::Uid( uid ), mimeType, packageUid ); |
|
116 |
|
117 // Commence the uninstallations |
|
118 iUninstaller.Uninstall( iStatus, packageUid, mimeType ); |
|
119 iObserverStatus = KRequestPending; |
|
120 if( mimeType == KMidletMimeType() |
|
121 && IsWidgetL( TUid::Uid( uid ) ) ) |
|
122 { |
|
123 //we remove java type app(it will gain different uid |
|
124 //during next install) and widget type app(it MIGHT get |
|
125 //different uid during next install) from xml |
|
126 iState = EUninstalling; |
|
127 } |
|
128 else |
|
129 { |
|
130 //if its not java or widget app we leave it in xml, |
|
131 //appscanner will hide it for later passible reinstallation |
|
132 iState = ERemoving; |
|
133 } |
|
134 |
|
135 SetActive(); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------- |
|
139 // CMenuUninstallOperation::AppInfo |
|
140 // --------------------------------------------------------- |
|
141 // |
|
142 void CMenuUninstallOperation::AppInfoL( const TUid& aAppUid, TPtrC8& aMimeType, TUid& aPackageUid ) |
|
143 { |
|
144 TUid typeUid; |
|
145 RApaLsSession apaLsSession; |
|
146 |
|
147 User::LeaveIfError( apaLsSession.Connect() ); |
|
148 CleanupClosePushL( apaLsSession ); |
|
149 User::LeaveIfError( apaLsSession.GetAllApps() ); |
|
150 |
|
151 if( KErrNone == apaLsSession.GetAppType( typeUid, aAppUid ) && |
|
152 typeUid == KMidletType ) |
|
153 { |
|
154 GetJavaSuitUidL( aAppUid, aPackageUid ); |
|
155 aMimeType.Set( KMidletMimeType ); |
|
156 } |
|
157 else if( IsWidgetL( aAppUid ) ) |
|
158 { |
|
159 aPackageUid = aAppUid; |
|
160 aMimeType.Set( KWidgetMimeType ); |
|
161 } |
|
162 else |
|
163 { |
|
164 TApaAppInfo appInfo; |
|
165 User::LeaveIfError( apaLsSession.GetAppInfo( appInfo, aAppUid ) ); |
|
166 if( !GetInstallPkgUidL( appInfo.iFullName, aPackageUid ) ) |
|
167 { |
|
168 aPackageUid = aAppUid; |
|
169 } |
|
170 aMimeType.Set( KAppMimeType ); |
|
171 } |
|
172 |
|
173 CleanupStack::PopAndDestroy( &apaLsSession ); |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------- |
|
177 // CMenuUninstallOperation::GetInstallPkgUidL |
|
178 // --------------------------------------------------------- |
|
179 // |
|
180 TBool CMenuUninstallOperation::GetInstallPkgUidL( const TDesC& aAppFullName, TUid& aPackageUid ) |
|
181 { |
|
182 // Search for the full name of the application amongst every file name in |
|
183 // every installed packages. |
|
184 TBool found = EFalse; |
|
185 Swi::RSisRegistrySession iSisRegSession; |
|
186 |
|
187 // Get the array of ids of every installed packages |
|
188 if( KErrNone != iSisRegSession.Connect() ) |
|
189 { |
|
190 return found; |
|
191 } |
|
192 CleanupClosePushL( iSisRegSession ); |
|
193 |
|
194 RArray<TUid> packageIds; |
|
195 CleanupClosePushL( packageIds ); |
|
196 |
|
197 iSisRegSession.InstalledUidsL( packageIds ); |
|
198 |
|
199 RPointerArray< HBufC > packageFiles; |
|
200 CleanupClosePushL( packageFiles ); |
|
201 |
|
202 for( TInt i = 0; i < packageIds.Count() && !found; ++i ) |
|
203 { |
|
204 const TUid packageId = packageIds[i]; |
|
205 Swi::RSisRegistryEntry packageEntry; |
|
206 |
|
207 // Get the array of file names in the current install package and look |
|
208 // if there is one suggesting that the application was installed from |
|
209 // the package. |
|
210 if( KErrNone == packageEntry.Open( iSisRegSession, packageId ) ) |
|
211 { |
|
212 CleanupClosePushL( packageEntry ); |
|
213 packageEntry.FilesL( packageFiles ); |
|
214 for( TInt pf = 0; pf < packageFiles.Count() && !found; ++pf ) |
|
215 { |
|
216 if( packageFiles[pf]->FindC( aAppFullName ) == 0 ) |
|
217 { |
|
218 aPackageUid = packageId; |
|
219 found = ETrue; |
|
220 } |
|
221 } |
|
222 packageFiles.ResetAndDestroy(); |
|
223 CleanupStack::PopAndDestroy( &packageEntry ); |
|
224 } |
|
225 } |
|
226 |
|
227 CleanupStack::PopAndDestroy( &packageFiles ); |
|
228 CleanupStack::PopAndDestroy( &packageIds ); |
|
229 CleanupStack::PopAndDestroy( &iSisRegSession ); |
|
230 |
|
231 return found; |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------- |
|
235 // CMenuUninstallOperation::GetJavaSuitUidL |
|
236 // --------------------------------------------------------- |
|
237 // |
|
238 void CMenuUninstallOperation::GetJavaSuitUidL( const TUid& aAppUid, TUid& aPackageUid ) |
|
239 { |
|
240 Java::CJavaRegistry* javaRegistry; |
|
241 javaRegistry = Java::CJavaRegistry::NewLC(); |
|
242 |
|
243 Java::CJavaRegistryEntry* regEntry = |
|
244 javaRegistry->RegistryEntryL( aAppUid ); |
|
245 if( regEntry ) |
|
246 { |
|
247 CleanupStack::PushL( regEntry ); |
|
248 |
|
249 Java::TJavaRegistryEntryType entryType = regEntry->Type(); |
|
250 |
|
251 if ( ( entryType >= Java::EGeneralPackage ) && |
|
252 (entryType < Java::EGeneralApplication) ) |
|
253 { |
|
254 //package entry |
|
255 aPackageUid = regEntry->Uid(); |
|
256 } |
|
257 else |
|
258 { |
|
259 //application entry |
|
260 Java::CJavaRegistryApplicationEntry* regApplicationEntry = |
|
261 static_cast<Java::CJavaRegistryApplicationEntry*>( regEntry ); |
|
262 Java::CJavaRegistryPackageEntry* regPackageEntry = |
|
263 regApplicationEntry->PackageEntryL(); |
|
264 aPackageUid = regPackageEntry->Uid(); |
|
265 delete regPackageEntry; |
|
266 } |
|
267 CleanupStack::PopAndDestroy( regEntry ); |
|
268 } |
|
269 else |
|
270 { |
|
271 aPackageUid = aAppUid; |
|
272 } |
|
273 CleanupStack::PopAndDestroy( javaRegistry ); |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------- |
|
277 // CMenuUninstallOperation::IsWidget |
|
278 // --------------------------------------------------------- |
|
279 // |
|
280 |
|
281 TBool CMenuUninstallOperation::IsWidgetL( const TUid& aAppUid ) |
|
282 { |
|
283 RWidgetRegistryClientSession widgetReg; |
|
284 TBool isWidget; |
|
285 |
|
286 if( KErrNone != widgetReg.Connect() ) |
|
287 { |
|
288 return EFalse; |
|
289 } |
|
290 CleanupClosePushL( widgetReg); |
|
291 isWidget = widgetReg.IsWidget( aAppUid ); |
|
292 CleanupStack::PopAndDestroy( &widgetReg ); |
|
293 |
|
294 return isWidget; |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------- |
|
298 // CMenuUninstallOperation::RunL |
|
299 // --------------------------------------------------------- |
|
300 // |
|
301 void CMenuUninstallOperation::RunL() |
|
302 { |
|
303 if( KErrNone == iStatus.Int() ) |
|
304 { |
|
305 switch( iState ) |
|
306 { |
|
307 case EUninstalling: |
|
308 { |
|
309 __ASSERT_DEBUG( NULL == iRemoveOperation, User::Invariant() ); |
|
310 iState = ERemoving; |
|
311 iRemoveOperation = iMenu.RemoveL( iId, iStatus ); |
|
312 SetActive(); |
|
313 } |
|
314 break; |
|
315 |
|
316 case ERemoving: |
|
317 { |
|
318 delete iRemoveOperation; |
|
319 iRemoveOperation = NULL; |
|
320 iState = EIdle; |
|
321 TRequestStatus* status = &iObserverStatus; |
|
322 User::RequestComplete( status, iStatus.Int() ); |
|
323 } |
|
324 break; |
|
325 |
|
326 default: |
|
327 // Object is in an unexpected state |
|
328 __ASSERT_DEBUG( 0, User::Invariant() ); |
|
329 } |
|
330 } |
|
331 else if ( KErrNotFound == iStatus.Int() && iState == ERemoving ) |
|
332 { |
|
333 // Most probably: After uninstalling the application the application |
|
334 // scanner removed the corresponding item from the xml so not finding |
|
335 // the menuitem is not an error here. |
|
336 delete iRemoveOperation; |
|
337 iRemoveOperation = NULL; |
|
338 iState = EIdle; |
|
339 TRequestStatus* status = &iObserverStatus; |
|
340 User::RequestComplete( status, KErrNone ); |
|
341 } |
|
342 else |
|
343 { |
|
344 // Report error |
|
345 delete iRemoveOperation; |
|
346 iRemoveOperation = NULL; |
|
347 iState = EIdle; |
|
348 TRequestStatus* status = &iObserverStatus; |
|
349 User::RequestComplete( status, iStatus.Int() ); |
|
350 } |
|
351 } |
|
352 |
|
353 // --------------------------------------------------------- |
|
354 // CMenuUninstallOperation::DoCancel |
|
355 // --------------------------------------------------------- |
|
356 // |
|
357 void CMenuUninstallOperation::DoCancel() |
|
358 { |
|
359 switch( iState ) |
|
360 { |
|
361 case EUninstalling: |
|
362 { |
|
363 iState = EIdle; |
|
364 } |
|
365 break; |
|
366 |
|
367 case ERemoving: |
|
368 { |
|
369 delete iRemoveOperation; |
|
370 iRemoveOperation = NULL; |
|
371 iState = EIdle; |
|
372 } |
|
373 break; |
|
374 |
|
375 default: |
|
376 // Object is in an unexpected state |
|
377 __ASSERT_DEBUG( 0, User::Invariant() ); |
|
378 } |
|
379 iUninstaller.CancelAsyncRequest( SwiUI::ERequestUninstall ); |
|
380 // Complete the caller: |
|
381 TRequestStatus* status = &iObserverStatus; |
|
382 User::RequestComplete( status, iStatus.Int() ); |
|
383 } |
|
384 |
|
385 // --------------------------------------------------------- |
|
386 // CMenuUninstallOperation::RunError |
|
387 // --------------------------------------------------------- |
|
388 // |
|
389 TInt CMenuUninstallOperation::RunError( TInt aError ) |
|
390 { |
|
391 TRequestStatus* status = &iObserverStatus; |
|
392 User::RequestComplete( status, aError ); |
|
393 |
|
394 return KErrNone; |
|
395 } |