1 /* |
|
2 * Copyright (c) 2008 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <apgcli.h> |
|
19 #include <swi/sisregistrysession.h> |
|
20 #include <swi/sisregistryentry.h> |
|
21 #include "cautils.h" |
|
22 #include "cadef.h" |
|
23 #include "cainnerentry.h" |
|
24 #include "cauninstalloperation.h" |
|
25 _LIT8( KAppMimeType, "x-epoc/x-sisx-app" ); |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // CCaUninstallOperation::~CCaUninstallOperation |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CCaUninstallOperation::~CCaUninstallOperation() |
|
34 { |
|
35 Cancel(); |
|
36 iUninstaller.Close(); |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CCaUninstallOperation::NewL |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CCaUninstallOperation* CCaUninstallOperation::NewL( CCaInnerEntry &aEntry, |
|
44 TInt aPriority ) |
|
45 { |
|
46 CCaUninstallOperation* self; |
|
47 |
|
48 self = new ( ELeave ) CCaUninstallOperation( aEntry, aPriority ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL( aEntry ); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CCaUninstallOperation::CCaUninstallOperation |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CCaUninstallOperation::CCaUninstallOperation( CCaInnerEntry& aEntry, |
|
60 TInt aPriority ) : |
|
61 CActive( aPriority ), iEntry( aEntry ), iUninstaller(), iId( 0 ) |
|
62 { |
|
63 CActiveScheduler::Add( this ); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CCaUninstallOperation::ConstructL |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 void CCaUninstallOperation::ConstructL( CCaInnerEntry& aEntry ) |
|
71 { |
|
72 TBuf<KCaMaxAttrValueLen> uidAttr; |
|
73 TUint uid = aEntry.GetUid(); |
|
74 |
|
75 TUid packageUid = KNullUid; |
|
76 TPtrC8 mimeType; |
|
77 |
|
78 if( !( aEntry.GetFlags() & ERemovable ) ) |
|
79 { |
|
80 User::Leave( KErrAccessDenied ); |
|
81 } |
|
82 |
|
83 User::LeaveIfError( iUninstaller.Connect() ); |
|
84 iId = aEntry.GetId(); |
|
85 if( aEntry.GetEntryTypeName() == KCaTypeWidget() ) |
|
86 { |
|
87 TBuf<KMaxUidName> uidDesc; |
|
88 aEntry.FindAttribute( KCaPackageUid, uidDesc ); |
|
89 TLex uidLex(uidDesc); |
|
90 TUint32 uidValue; |
|
91 User::LeaveIfError( uidLex.Val( uidValue, EHex )); |
|
92 |
|
93 packageUid.iUid = static_cast<TInt32>(uidValue); |
|
94 mimeType.Set( KAppMimeType ); |
|
95 } |
|
96 else |
|
97 { |
|
98 AppInfoL( TUid::Uid( uid ), mimeType, packageUid ); |
|
99 } |
|
100 |
|
101 // Commence the uninstallations |
|
102 iUninstaller.Uninstall( iStatus, packageUid, mimeType ); |
|
103 SetActive(); |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CCaUninstallOperation::AppInfo |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 void CCaUninstallOperation::AppInfoL( const TUid& aAppUid, |
|
111 TPtrC8& aMimeType, TUid& aPackageUid ) |
|
112 { |
|
113 RApaLsSession apaLsSession; |
|
114 |
|
115 User::LeaveIfError( apaLsSession.Connect() ); |
|
116 CleanupClosePushL( apaLsSession ); |
|
117 User::LeaveIfError( apaLsSession.GetAllApps() ); |
|
118 |
|
119 TApaAppInfo appInfo; |
|
120 User::LeaveIfError( apaLsSession.GetAppInfo( appInfo, aAppUid ) ); |
|
121 if( !GetInstallPkgUidL( appInfo.iFullName, aPackageUid ) ) |
|
122 { |
|
123 aPackageUid = aAppUid; |
|
124 } |
|
125 aMimeType.Set( KAppMimeType ); |
|
126 |
|
127 CleanupStack::PopAndDestroy( &apaLsSession ); |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // CCaUninstallOperation::GetInstallPkgUidL |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 TBool CCaUninstallOperation::GetInstallPkgUidL( const TDesC& aAppFullName, |
|
135 TUid& aPackageUid ) |
|
136 { |
|
137 // Search for the full name of the application amongst every file name in |
|
138 // every installed packages. |
|
139 TBool found = EFalse; |
|
140 Swi::RSisRegistrySession iSisRegSession; |
|
141 |
|
142 // Get the array of ids of every installed packages |
|
143 if( KErrNone != iSisRegSession.Connect() ) |
|
144 { |
|
145 return found; |
|
146 } |
|
147 CleanupClosePushL( iSisRegSession ); |
|
148 |
|
149 RArray<TUid> packageIds; |
|
150 CleanupClosePushL( packageIds ); |
|
151 |
|
152 iSisRegSession.InstalledUidsL( packageIds ); |
|
153 |
|
154 RPointerArray<HBufC> packageFiles; |
|
155 CleanupClosePushL( packageFiles ); |
|
156 |
|
157 for( TInt i = 0; i < packageIds.Count() && !found; ++i ) |
|
158 { |
|
159 const TUid packageId = packageIds[i]; |
|
160 Swi::RSisRegistryEntry packageEntry; |
|
161 |
|
162 // Get the array of file names in the current install package and look |
|
163 // if there is one suggesting that the application was installed from |
|
164 // the package. |
|
165 if( KErrNone == packageEntry.Open( iSisRegSession, packageId ) ) |
|
166 { |
|
167 CleanupClosePushL( packageEntry ); |
|
168 packageEntry.FilesL( packageFiles ); |
|
169 for( TInt pf = 0; pf < packageFiles.Count() && !found; ++pf ) |
|
170 { |
|
171 if( packageFiles[pf]->FindC( aAppFullName ) == 0 ) |
|
172 { |
|
173 aPackageUid = packageId; |
|
174 found = ETrue; |
|
175 } |
|
176 } |
|
177 packageFiles.ResetAndDestroy(); |
|
178 CleanupStack::PopAndDestroy( &packageEntry ); |
|
179 } |
|
180 } |
|
181 |
|
182 CleanupStack::PopAndDestroy( &packageFiles ); |
|
183 CleanupStack::PopAndDestroy( &packageIds ); |
|
184 CleanupStack::PopAndDestroy( &iSisRegSession ); |
|
185 |
|
186 return found; |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // CCaUninstallOperation::RunL |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 void CCaUninstallOperation::RunL() |
|
194 { |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // CCaUninstallOperation::DoCancel |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 void CCaUninstallOperation::DoCancel() |
|
202 { |
|
203 iUninstaller.CancelAsyncRequest( SwiUI::ERequestUninstall ); |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // CCaUninstallOperation::RunError |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 TInt CCaUninstallOperation::RunError( TInt /* aError */) |
|
211 { |
|
212 return KErrNone; |
|
213 } |
|