|
1 /* |
|
2 * Copyright (c) 2004 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 |
|
18 #include "uninstaller.h" |
|
19 #include "versionRevisor.h" |
|
20 #include "SWInstDebug.h" |
|
21 |
|
22 #include "sisregistrysession.h" |
|
23 #include "siscontents.h" |
|
24 #include "sisparser.h" |
|
25 #include "filesisdataprovider.h" |
|
26 |
|
27 #include "dessisdataprovider.h" |
|
28 #include "siscontroller.h" |
|
29 #include "sisinfo.h" |
|
30 #include "sisuid.h" |
|
31 #include "sisregistryentry.h" |
|
32 #include "DialogWrapper.h" |
|
33 |
|
34 using namespace Swi; |
|
35 |
|
36 const static TInt KWaitTime = 3000000; // 2 secs |
|
37 |
|
38 // ----------------------------------------------------------------------- |
|
39 // Two phased construction |
|
40 // ----------------------------------------------------------------------- |
|
41 // |
|
42 CSisPkgUninstaller* CSisPkgUninstaller::NewL( |
|
43 CProgramStatus& aMainStatus, |
|
44 CVersionRevisor& aRevisor ) |
|
45 { |
|
46 CSisPkgUninstaller* self = new (ELeave) CSisPkgUninstaller(); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL( aMainStatus, aRevisor ); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------- |
|
55 // c++ constructor |
|
56 // ----------------------------------------------------------------------- |
|
57 // |
|
58 CSisPkgUninstaller::CSisPkgUninstaller() : CActive( CActive::EPriorityStandard ) |
|
59 { |
|
60 CActiveScheduler::Add( this ); |
|
61 } |
|
62 |
|
63 |
|
64 // ----------------------------------------------------------------------- |
|
65 // c++ destructor |
|
66 // ----------------------------------------------------------------------- |
|
67 // |
|
68 CSisPkgUninstaller::~CSisPkgUninstaller() |
|
69 { |
|
70 FLOG( _L("[SISUninstaller] ~CSisPkgUninstaller start")); |
|
71 |
|
72 if ( EStateUninstalling == iProgramStatus->GetProgramStatus() ) |
|
73 { |
|
74 FLOG( _L("[SISUninstaller] Set status to idle")); |
|
75 iProgramStatus->SetProgramStatusToIdle(); |
|
76 } |
|
77 |
|
78 FLOG( _L("[SISUninstaller] ~CSisPkgUninstaller: Cancel()")); |
|
79 // Cancels the wait for completion of an outstanding request. |
|
80 Cancel(); |
|
81 FLOG( _L("[SISUninstaller] ~CSisPkgUninstaller: Deque()")); |
|
82 // Removes the active object from the active scheduler's list. |
|
83 Deque(); |
|
84 FLOG( _L("[SISUninstaller] ~CSisPkgUninstaller: iTimer.Close()")); |
|
85 iTimer.Close(); |
|
86 iPkgUidArray.Close(); |
|
87 delete iSilentUninstaller; |
|
88 FLOG( _L("[SISUninstaller] ~CSisPkgUninstaller: delete iMime")); |
|
89 delete iMime; |
|
90 FLOG( _L("[SISUninstaller] ~CSisPkgUninstaller: delete iDialogs")); |
|
91 delete iDialogs; |
|
92 FLOG( _L("[SISUninstaller] ~CSisPkgUninstaller: iApaSession.Close()")); |
|
93 iApaSession.Close(); |
|
94 FLOG( _L("[SISUninstaller] ~CSisPkgUninstaller: iFs.Close();")); |
|
95 iFs.Close(); |
|
96 |
|
97 FLOG( _L("[SISUninstaller] ~CSisPkgUninstaller end")); |
|
98 } |
|
99 |
|
100 |
|
101 // ----------------------------------------------------------------------- |
|
102 // 2nd phase construction |
|
103 // ----------------------------------------------------------------------- |
|
104 // |
|
105 void CSisPkgUninstaller::ConstructL( |
|
106 CProgramStatus& aMainStatus, |
|
107 CVersionRevisor& aRevisor ) |
|
108 { |
|
109 iProgramStatus = &aMainStatus; |
|
110 iRevisor = &aRevisor; |
|
111 User::LeaveIfError( iTimer.CreateLocal() ); |
|
112 User::LeaveIfError( iFs.Connect() ); |
|
113 User::LeaveIfError( iApaSession.Connect() ); |
|
114 iFs.ShareProtected(); |
|
115 iUidArrayIndex = 0; |
|
116 iSilentUninstaller = NULL; |
|
117 iState = EUninstallerStateIdle; |
|
118 // Alloc descriptor for mime type sis/sisx |
|
119 iMime = SwiUI::KSisxMimeType().AllocL(); |
|
120 // Note this will create new instance for dialog class and |
|
121 // also new dialog watcher AO for uninstaller. |
|
122 // Since uninstaller is used rarely this is not big issue. |
|
123 // In future dialog class could be added to CProgramStatus class |
|
124 // member from where both installer and uninstaller could us it. |
|
125 iDialogs = CDialogWrapper::NewL( iFs ); |
|
126 } |
|
127 |
|
128 |
|
129 // ----------------------------------------------------------------------- |
|
130 // This function adds package uid to uninstall array. |
|
131 // ----------------------------------------------------------------------- |
|
132 // |
|
133 void CSisPkgUninstaller::AddUidToListL( const TUid& aUID ) |
|
134 { |
|
135 iPkgUidArray.AppendL( aUID ); |
|
136 } |
|
137 |
|
138 |
|
139 // ----------------------------------------------------------------------- |
|
140 // This function starts uninstall process. Leaves if nothing to do. |
|
141 // ----------------------------------------------------------------------- |
|
142 // |
|
143 void CSisPkgUninstaller::StartUninstallL() |
|
144 { |
|
145 FLOG( _L("[SISUninstaller] StartUninstallL")); |
|
146 |
|
147 if( iPkgUidArray.Count() == 0 ) |
|
148 { |
|
149 FLOG( _L("[SISUninstaller] No UIDs leave uninstaller")); |
|
150 User::Leave( KErrAbort ); |
|
151 } |
|
152 |
|
153 // If daemon installer is in idle, start uninstall and |
|
154 // set process status as uninstalling. |
|
155 if ( EStateIdle == iProgramStatus->GetProgramStatus() ) |
|
156 { |
|
157 FLOG( _L("[SISUninstaller] StartUninstallL: Set EStateUninstalling") ); |
|
158 iProgramStatus->SetProgramStatus( EStateUninstalling ); |
|
159 } |
|
160 |
|
161 if ( iSilentUninstaller == NULL ) |
|
162 { |
|
163 FLOG( _L("[SISUninstaller] Create SilentUninstaller")); |
|
164 iSilentUninstaller = CSilentUninstaller::NewL( iFs ); |
|
165 } |
|
166 |
|
167 if ( iState == EUninstallerStateIdle ) |
|
168 { |
|
169 CompleteSelf(); |
|
170 } |
|
171 } |
|
172 |
|
173 |
|
174 // ----------------------------------------------------------------------- |
|
175 // Complete the request manually. |
|
176 // ----------------------------------------------------------------------- |
|
177 // |
|
178 void CSisPkgUninstaller::CompleteSelf() |
|
179 { |
|
180 FLOG( _L("[SISUninstaller] CompleteSelf")); |
|
181 |
|
182 if ( !IsActive() ) |
|
183 { |
|
184 TRequestStatus* status = &iStatus; |
|
185 User::RequestComplete( status, KErrNone ); |
|
186 SetActive(); |
|
187 } |
|
188 } |
|
189 |
|
190 |
|
191 // ----------------------------------------------------------------------- |
|
192 // Cancel the active request. |
|
193 // ----------------------------------------------------------------------- |
|
194 // |
|
195 void CSisPkgUninstaller::DoCancel() |
|
196 { |
|
197 FLOG( _L("[SISUninstaller] DoCancel") ); |
|
198 iTimer.Close(); |
|
199 if ( iState == EUninstallerStateUninstalling ) |
|
200 { |
|
201 iSilentUninstaller->Cancel(); |
|
202 } |
|
203 } |
|
204 |
|
205 |
|
206 // ----------------------------------------------------------------------- |
|
207 // Handles the active object's request completion. Process the uninstall |
|
208 // tasks and waits install process if needed. |
|
209 // ----------------------------------------------------------------------- |
|
210 // |
|
211 void CSisPkgUninstaller::RunL() |
|
212 { |
|
213 FLOG_1( _L("[SISUninstaller] RunL: ProgramStatus = %d"), |
|
214 iProgramStatus->GetProgramStatus() ); |
|
215 |
|
216 // If daemon installer is running let's wait some time and try again. |
|
217 if ( EStateInstalling == iProgramStatus->GetProgramStatus() ) |
|
218 { |
|
219 FLOG( _L("[SISUninstaller] RunL: Wait daemon installer ! ! !") ); |
|
220 TTimeIntervalMicroSeconds32 time( KWaitTime ); |
|
221 iTimer.After( iStatus, time ); |
|
222 SetActive(); |
|
223 } |
|
224 // Ok, run uninstaller. |
|
225 else |
|
226 { |
|
227 FLOG( _L("[SISUninstaller] RunL: Start uninstalling process") ); |
|
228 iProgramStatus->SetProgramStatus( EStateUninstalling ); |
|
229 FLOG_1( _L("Daemon Uninstaller: RunL: SWI iStatus = %d"), |
|
230 iStatus.Int()); |
|
231 |
|
232 switch ( iState ) |
|
233 { |
|
234 case EUninstallerStateUninstalling: |
|
235 { |
|
236 FLOG( _L("[SISUninstaller] RunL: EUninstallerStateUninstal.")); |
|
237 // We are not checking SWI error status here because |
|
238 // there is not need for that. If uninstall fails because |
|
239 // some error, we can not fix it. In case of error we will |
|
240 // start next uninstall. |
|
241 |
|
242 // Ok, server busy, we have to wait. |
|
243 if ( iStatus.Int() == SwiUI::KSWInstErrBusy ) |
|
244 { |
|
245 FLOG(_L("[SISUninstaller] RunL: iStatus: KSWInstErrBusy")); |
|
246 TTimeIntervalMicroSeconds32 time( KWaitTime ); |
|
247 iTimer.After( iStatus, time ); |
|
248 iState = EUninstallerStateBusy; |
|
249 SetActive(); |
|
250 break; |
|
251 } |
|
252 // Check if we have more to uninstall |
|
253 else if ( iUidArrayIndex < iPkgUidArray.Count() ) |
|
254 { |
|
255 FLOG(_L("[SISUninstaller] RunL: Complete self and cont.")); |
|
256 // Run again to kick of the next uninstallation. |
|
257 iState = EUninstallerStateIdle; |
|
258 CompleteSelf(); |
|
259 } |
|
260 // Ok all is done. |
|
261 else |
|
262 { |
|
263 FLOG( _L("[SISUninstaller] RunL: Completed") ); |
|
264 UninstallationCompleted( KErrNone ); |
|
265 ExitUninstaller(); |
|
266 } |
|
267 } |
|
268 break; |
|
269 |
|
270 case EUninstallerStateIdle: |
|
271 { |
|
272 FLOG( _L("[SISUninstaller] RunL: EDSisInstallerStateIdle") ); |
|
273 // Check if there is pkgs to be uninstalled. |
|
274 if ( iUidArrayIndex < iPkgUidArray.Count() ) |
|
275 { |
|
276 // Display installing note for user. |
|
277 iDialogs->ShowWaitingNoteForUninstallerL(); |
|
278 |
|
279 FLOG_1( _L("[SISUninstaller] Run uninstall index = %d"), |
|
280 iUidArrayIndex ); |
|
281 |
|
282 // Get next UID. |
|
283 iUID = iPkgUidArray[ iUidArrayIndex ]; |
|
284 // Increas pkg counter. |
|
285 iUidArrayIndex++; |
|
286 // Start uninstall process |
|
287 iSilentUninstaller->UninstallL( iUID, iStatus, *iMime ); |
|
288 //iDialogs->ShowWaitingNoteL(); |
|
289 iState = EUninstallerStateUninstalling; |
|
290 SetActive(); |
|
291 } |
|
292 else |
|
293 { |
|
294 // No more pkgs to uninstall. Let's quit. |
|
295 FLOG( _L("[SISUninstaller] RunL: Completed") ); |
|
296 UninstallationCompleted( KErrNone ); |
|
297 ExitUninstaller(); |
|
298 } |
|
299 } |
|
300 break; |
|
301 |
|
302 case EUninstallerStateBusy: |
|
303 { |
|
304 FLOG( _L("[SISUninstaller] RunL: EUninstallerStateBusy") ); |
|
305 FLOG_1( _L("[SISUninstaller] Run uninstall again index = %d"), |
|
306 iUidArrayIndex-1 ); |
|
307 // Start uninstall process |
|
308 iSilentUninstaller->UninstallL( iUID, iStatus, *iMime ); |
|
309 iState = EUninstallerStateUninstalling; |
|
310 SetActive(); |
|
311 } |
|
312 break; |
|
313 |
|
314 default: |
|
315 FLOG(_L("[SISUninstaller] RunL: KErrNotSupported EXIT!!!")); |
|
316 // This state is not supported, let's exit. |
|
317 DoCancel(); |
|
318 UninstallationCompleted( KErrNotSupported ); |
|
319 ExitUninstaller(); |
|
320 break; |
|
321 } //switch case |
|
322 } //if-else |
|
323 } |
|
324 |
|
325 |
|
326 // ----------------------------------------------------------------------- |
|
327 // This function is called when RunL leaves. |
|
328 // ----------------------------------------------------------------------- |
|
329 // |
|
330 TInt CSisPkgUninstaller::RunError( TInt aError ) |
|
331 { |
|
332 FLOG_1( _L("[SISUninstaller] RunError: error = %d"), aError ); |
|
333 UninstallationCompleted( aError ); |
|
334 return aError; |
|
335 } |
|
336 |
|
337 |
|
338 // ----------------------------------------------------------------------- |
|
339 // This function is called after uninstall tasks are done. |
|
340 // ----------------------------------------------------------------------- |
|
341 // |
|
342 void CSisPkgUninstaller::UninstallationCompleted( TInt /*aResult*/ ) |
|
343 { |
|
344 FLOG( _L("[SISUninstaller] UninstallationCompleted") ); |
|
345 |
|
346 if ( EStateUninstalling == iProgramStatus->GetProgramStatus() ) |
|
347 { |
|
348 FLOG( _L("[SISUninstaller] Set status to idle")); |
|
349 iProgramStatus->SetProgramStatusToIdle(); |
|
350 } |
|
351 |
|
352 iUidArrayIndex = 0; |
|
353 iState = EUninstallerStateIdle; |
|
354 |
|
355 // Cancel waiting note. |
|
356 TRAP_IGNORE( iDialogs->CancelWaitingNoteL() ); |
|
357 } |
|
358 |
|
359 |
|
360 // ----------------------------------------------------------------------- |
|
361 // This is for self exit. |
|
362 // ----------------------------------------------------------------------- |
|
363 // |
|
364 void CSisPkgUninstaller::ExitUninstaller() |
|
365 { |
|
366 FLOG( _L("[SISUninstaller] ExitUninstaller") ); |
|
367 // Uninstall is completed and we do not need uninstaller anymore. |
|
368 // Call revisor's destructor. |
|
369 iRevisor->Exit(); |
|
370 } |
|
371 |
|
372 //EOF |