|
1 /* |
|
2 * Copyright (c) 1997-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 the License "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 * SWIS implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 */ |
|
23 |
|
24 #include "installserver.h" |
|
25 #include "installclientserver.h" |
|
26 #include "installmachine.h" |
|
27 #include "uninstallmachine.h" |
|
28 #include "swispubsubdefs.h" |
|
29 #include "restoremachine.h" |
|
30 #include "log.h" |
|
31 #include "packageremover.h" |
|
32 |
|
33 #include <connect/sbdefs.h> |
|
34 #include <swi/pkgremover.h> |
|
35 |
|
36 namespace Swi |
|
37 { |
|
38 |
|
39 /** |
|
40 * Local function to panic an offending client |
|
41 * @internalTechnology |
|
42 * @released |
|
43 */ |
|
44 static void PanicClient(const RMessagePtr2& aMessage, |
|
45 TInstallServerPanic aPanic) |
|
46 { |
|
47 aMessage.Panic(KInstallServerName, aPanic); |
|
48 } |
|
49 |
|
50 // |
|
51 // CInstallSession |
|
52 // |
|
53 |
|
54 // 2nd phase construction, called by the server framework |
|
55 void CInstallSession::CreateL() |
|
56 { |
|
57 Server().AddSession(); |
|
58 |
|
59 #ifdef __WINSCW__ |
|
60 // For 2 minutes after initial boot, DLLs are not unloaded. If we are doing an |
|
61 // install/uninstall/restore, we need to make sure any pending unloadeds are actioned, |
|
62 // otherwise a previously loaded DLL could cause the rollback to fail on windows (on |
|
63 // arm it is legal to delete a loaded DLL/EXE, whilst on windows it is not). |
|
64 RLoader loader; |
|
65 TInt r = loader.Connect(); |
|
66 if(r == KErrNone) |
|
67 { |
|
68 (void)loader.CancelLazyDllUnload(); |
|
69 loader.Close(); |
|
70 } |
|
71 #endif |
|
72 } |
|
73 |
|
74 CInstallSession::~CInstallSession() |
|
75 { |
|
76 delete iMachine; |
|
77 delete iRestoreMachine; |
|
78 delete iRemover; |
|
79 Server().ListRemoveInProgress(EFalse); |
|
80 RProperty::Set(KUidSystemCategory, KUidSoftwareInstallKey, ESwisNone); |
|
81 Server().DropSession(); |
|
82 } |
|
83 |
|
84 CInstallServer& CInstallSession::Server() |
|
85 { |
|
86 return *static_cast<CInstallServer*>(const_cast<CServer2*>( |
|
87 CSession2::Server())); |
|
88 } |
|
89 |
|
90 // Handle a client request. Leaving is handled by ServiceError() which reports |
|
91 // the error code to the client |
|
92 void CInstallSession::ServiceL(const RMessage2& aMessage) |
|
93 { |
|
94 // Handle the cancel message first |
|
95 if (aMessage.Function()==ECancel) |
|
96 { |
|
97 DEBUG_PRINTF(_L8("CInstallSession::ServiceL() cancel function called")); |
|
98 // Set status as aborted |
|
99 TInt property; |
|
100 if (RProperty::Get(KUidSystemCategory, KUidSoftwareInstallKey, property) == KErrNone) |
|
101 { |
|
102 RProperty::Set(KUidSystemCategory, KUidSoftwareInstallKey, property | ESwisStatusAborted); |
|
103 } |
|
104 |
|
105 if (iMachine) |
|
106 { |
|
107 iMachine->CancelInstallation(); |
|
108 } |
|
109 |
|
110 aMessage.Complete(KErrNone); |
|
111 return; |
|
112 } |
|
113 |
|
114 TInt property = 0; |
|
115 TInt err = RProperty::Get(KUidSystemCategory, conn::KUidBackupRestoreKey, property); |
|
116 |
|
117 if (err != KErrNone && err != KErrNotFound) |
|
118 { |
|
119 User::Leave(err); |
|
120 } |
|
121 |
|
122 if (iMachine != NULL) |
|
123 { |
|
124 DEBUG_PRINTF2(_L8("Install Server Message %d refused. Install/Uninstall in progress"), aMessage.Function()); |
|
125 aMessage.Complete(KErrInUse); |
|
126 } |
|
127 |
|
128 /* |
|
129 * We must return KErrInUse if: |
|
130 * 1) The Connect P&S property indicates we are doing a backup/restore |
|
131 * 2) We are not servicing that restore operation with this request |
|
132 * 3) A list/remove operation is in progress |
|
133 * |
|
134 */ |
|
135 else if ((iRemover != NULL) || Server().IsListRemoveInProgress()) |
|
136 { |
|
137 // Remove operation in progress |
|
138 DEBUG_PRINTF2(_L8("Install Server Message '%d' refused. List/Remove in progress"), aMessage.Function()); |
|
139 aMessage.Complete(KErrInUse); |
|
140 } |
|
141 else if (err != KErrNotFound && (property & (conn::KBURPartTypeMask^conn::EBURNormal)) |
|
142 && aMessage.Function() != ERestore && !iRestoreMachine) |
|
143 { |
|
144 DEBUG_PRINTF2(_L8("Install Server Message '%d' refused. Backup/Restore in progress"), aMessage.Function()); |
|
145 aMessage.Complete(KErrInUse); |
|
146 } |
|
147 else |
|
148 { |
|
149 switch (aMessage.Function()) |
|
150 { |
|
151 case EInstall: |
|
152 { |
|
153 DEBUG_PRINTF(_L8("CInstallSession::ServiceL() install function called")); |
|
154 |
|
155 err = RProperty::Set(KUidSystemCategory, KUidSoftwareInstallKey, ESwisInstall); |
|
156 User::LeaveIfError(err); |
|
157 |
|
158 iMachine=CInstallMachine::NewL(aMessage); |
|
159 User::LeaveIfError(iMachine->Start()); |
|
160 // The state machine will complete the client once the work |
|
161 // is done. |
|
162 break; |
|
163 } |
|
164 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
165 case EGetComponentInfo: |
|
166 { |
|
167 DEBUG_PRINTF(_L8("CInstallSession::ServiceL() get component info function called")); |
|
168 |
|
169 iMachine=CInstallMachine::NewL(aMessage, ETrue); |
|
170 // Set the install machine to run on comp info collection mode. |
|
171 User::LeaveIfError(iMachine->Start()); |
|
172 // The state machine will complete the client once the work |
|
173 // is done. |
|
174 break; |
|
175 } |
|
176 #endif |
|
177 case EUninstall: |
|
178 { |
|
179 DEBUG_PRINTF(_L8("CInstallSession::ServiceL() uninstall function called")); |
|
180 |
|
181 err = RProperty::Set(KUidSystemCategory, KUidSoftwareInstallKey, ESwisUninstall); |
|
182 User::LeaveIfError(err); |
|
183 |
|
184 iMachine=CUninstallMachine::NewL(aMessage); |
|
185 User::LeaveIfError(iMachine->Start()); |
|
186 |
|
187 // The state machine will complete the client once the work |
|
188 // is done. |
|
189 break; |
|
190 } |
|
191 |
|
192 case ERestore: |
|
193 { |
|
194 |
|
195 DEBUG_PRINTF(_L8("CInstallSession::ServiceL() restore function called")); |
|
196 |
|
197 err = RProperty::Set(KUidSystemCategory, KUidSoftwareInstallKey, ESwisRestore); |
|
198 User::LeaveIfError(err); |
|
199 |
|
200 if (iRestoreMachine && !iRestoreMachine->IsComplete()) |
|
201 { |
|
202 |
|
203 aMessage.Complete(KErrInUse); |
|
204 |
|
205 } |
|
206 |
|
207 if (iRestoreMachine) |
|
208 { |
|
209 |
|
210 delete iRestoreMachine; |
|
211 iRestoreMachine = NULL; |
|
212 |
|
213 } |
|
214 |
|
215 iRestoreMachine = CRestoreMachine::NewL(aMessage); |
|
216 break; |
|
217 |
|
218 } |
|
219 case ERestoreFile: |
|
220 { |
|
221 |
|
222 DEBUG_PRINTF(_L8("CInstallSession::ServiceL() restore file function called")); |
|
223 |
|
224 if (iRestoreMachine == NULL) |
|
225 { |
|
226 |
|
227 // Should never be reached |
|
228 aMessage.Panic(KInstallServerName, KErrNotReady); |
|
229 |
|
230 } |
|
231 else |
|
232 { |
|
233 |
|
234 iRestoreMachine->ServiceFileRequestL(aMessage); |
|
235 |
|
236 } |
|
237 break; |
|
238 |
|
239 } |
|
240 case ERestoreCommit: |
|
241 { |
|
242 |
|
243 DEBUG_PRINTF(_L8("CInstallSession::ServiceL() commit function called")); |
|
244 |
|
245 if (iRestoreMachine == NULL) |
|
246 { |
|
247 |
|
248 // Should never be reached |
|
249 aMessage.Panic(KInstallServerName, KErrNotReady); |
|
250 |
|
251 } |
|
252 else |
|
253 { |
|
254 |
|
255 iRestoreMachine->ServiceCommitRequestL(aMessage); |
|
256 |
|
257 } |
|
258 break; |
|
259 |
|
260 } |
|
261 case EListUnInstalledPkgs: |
|
262 { |
|
263 Server().ListRemoveInProgress(ETrue); |
|
264 |
|
265 iRemover = CPackageRemover::NewL(aMessage); |
|
266 iRemover->ListL(); |
|
267 // The state will complete the client once the work |
|
268 // is done. |
|
269 break; |
|
270 } |
|
271 case ERemoveUnInstalledPkg: |
|
272 { |
|
273 Server().ListRemoveInProgress(ETrue); |
|
274 |
|
275 iRemover = CPackageRemover::NewL(aMessage); |
|
276 iRemover->RemoveL(); |
|
277 // The state will complete the client once the work |
|
278 // is done. |
|
279 break; |
|
280 } |
|
281 default: |
|
282 { |
|
283 DEBUG_PRINTF2(_L8("CInstallSession::ServiceL() unknown function called (%d)"), aMessage.Function()); |
|
284 PanicClient(aMessage, Swi::EPanicInstallServerIllegalFunction); |
|
285 break; |
|
286 } |
|
287 } |
|
288 } |
|
289 } |
|
290 |
|
291 // Handle an error from ServiceL(). A bad descriptor error implies a badly |
|
292 // programmed client, so panic it. Otherwise use the default handling (report |
|
293 // the error to the client). |
|
294 void CInstallSession::ServiceError(const RMessage2& aMessage, TInt aError) |
|
295 { |
|
296 |
|
297 // set the pubsub flag to aborted status |
|
298 TInt property = 0; |
|
299 TInt err = RProperty::Get(KUidSystemCategory, KUidSoftwareInstallKey, property); |
|
300 |
|
301 if (err == KErrNone) |
|
302 { |
|
303 RProperty::Set(KUidSystemCategory, KUidSoftwareInstallKey, property | ESwisStatusAborted); |
|
304 } |
|
305 |
|
306 if (aError==KErrBadDescriptor) |
|
307 PanicClient(aMessage, EPanicInstallServerBadDescriptor); |
|
308 CSession2::ServiceError(aMessage, aError); |
|
309 } |
|
310 |
|
311 // |
|
312 // CInstallServerShutdown |
|
313 // |
|
314 |
|
315 inline CInstallServerShutdown::CInstallServerShutdown() |
|
316 : CTimer(-1) |
|
317 { |
|
318 CActiveScheduler::Add(this); |
|
319 } |
|
320 |
|
321 CInstallServerShutdown::~CInstallServerShutdown() |
|
322 { |
|
323 Cancel(); |
|
324 } |
|
325 |
|
326 inline void CInstallServerShutdown::ConstructL() |
|
327 { |
|
328 CTimer::ConstructL(); |
|
329 } |
|
330 |
|
331 inline void CInstallServerShutdown::Start() |
|
332 { |
|
333 After(KShutdownDelay); |
|
334 } |
|
335 |
|
336 // Initiate server exit when the timer expires |
|
337 void CInstallServerShutdown::RunL() |
|
338 { |
|
339 CActiveScheduler::Stop(); |
|
340 } |
|
341 |
|
342 // |
|
343 // CInstallServer |
|
344 // |
|
345 |
|
346 // All functions require TrustedUI capability |
|
347 const TInt CInstallServer::iRanges[iRangeCount] = |
|
348 { |
|
349 0 // All connect attempts |
|
350 }; |
|
351 |
|
352 const TUint8 CInstallServer::iElementsIndex[iRangeCount] = |
|
353 { |
|
354 CPolicyServer::ECustomCheck // Custom check polices for TrustedUI or SID from connect. |
|
355 }; |
|
356 |
|
357 const CPolicyServer::TPolicy CInstallServer::iPolicy = |
|
358 { |
|
359 CPolicyServer::ECustomCheck, // specifies all connect attempts |
|
360 iRangeCount, |
|
361 iRanges, |
|
362 iElementsIndex, |
|
363 NULL, |
|
364 }; |
|
365 |
|
366 CInstallServer* CInstallServer::NewLC() |
|
367 { |
|
368 CInstallServer* self = new(ELeave) CInstallServer(); |
|
369 CleanupStack::PushL(self); |
|
370 self->ConstructL(); |
|
371 return self; |
|
372 } |
|
373 |
|
374 CInstallServer::~CInstallServer() |
|
375 { |
|
376 DEBUG_PRINTF(_L8("Install Server Shutdown")); |
|
377 CSecurityPolicy::ReleaseResource(); |
|
378 delete iShutdown; |
|
379 iShutdown = NULL; //required in case the server dies before the session |
|
380 } |
|
381 |
|
382 // This server does not offer sharable sessions |
|
383 CInstallServer::CInstallServer() |
|
384 : CPolicyServer(EPriorityMore, iPolicy, EUnsharableSessions), |
|
385 iListRemoveInProgress(EFalse) |
|
386 { |
|
387 } |
|
388 |
|
389 // Ensure the timer and server objects are running |
|
390 void CInstallServer::ConstructL() |
|
391 { |
|
392 DEBUG_PRINTF(_L8("Install Server Created")); |
|
393 StartL(KInstallServerName); |
|
394 iShutdown = new(ELeave) CInstallServerShutdown; |
|
395 iShutdown->ConstructL(); |
|
396 // Ensure that the server still exits even if the 1st client fails to |
|
397 // connect |
|
398 iShutdown->Start(); |
|
399 |
|
400 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
401 // Create the property used to publish SWI Progress Bar Value. Since this property is not needed |
|
402 // if the SWI component doesn't exist, it is created here. |
|
403 TInt err = RProperty::Define(KUidInstallServerCategory, KUidSwiProgressBarValueKey, RProperty::EInt); |
|
404 if (err != KErrNone && err != KErrAlreadyExists) |
|
405 { |
|
406 DEBUG_PRINTF2(_L8("Progress Bar Property couldn't be created. Error=%d."), err); |
|
407 User::Leave(err); |
|
408 } |
|
409 #endif |
|
410 } |
|
411 |
|
412 |
|
413 CPolicyServer::TCustomResult CInstallServer::CustomSecurityCheckL(const RMessage2& aMsg, |
|
414 TInt& /*aAction*/, TSecurityInfo& aMissing) |
|
415 { |
|
416 |
|
417 _LIT_SECURE_ID(secureBackupClientSID, 0x10202D56); |
|
418 |
|
419 if (aMsg.SecureId().iId == secureBackupClientSID.iId) |
|
420 { |
|
421 return CPolicyServer::EPass; |
|
422 } |
|
423 else if (aMsg.HasCapability(ECapabilityTrustedUI, |
|
424 __PLATSEC_DIAGNOSTIC_STRING("CInstallServer::CustomSecurityTest client process does not have Trusted UI Capability"))) |
|
425 { |
|
426 // Check additional capability for listing and removing "uninstalled" packages |
|
427 if ((aMsg.Function() == EListUnInstalledPkgs) && !aMsg.HasCapability(ECapabilityReadDeviceData, |
|
428 __PLATSEC_DIAGNOSTIC_STRING("CInstallServer::CustomSecurityTest client process does not have ReadDeviceData Capability"))) |
|
429 { |
|
430 aMissing.iCaps.Set(ECapabilityReadDeviceData); |
|
431 return CPolicyServer::EFail; |
|
432 } |
|
433 |
|
434 if ((aMsg.Function() == ERemoveUnInstalledPkg) && !aMsg.HasCapability(ECapabilityWriteDeviceData, |
|
435 __PLATSEC_DIAGNOSTIC_STRING("CInstallServer::CustomSecurityTest client process does not have WriteDeviceData Capability"))) |
|
436 { |
|
437 aMissing.iCaps.Set(ECapabilityWriteDeviceData); |
|
438 return CPolicyServer::EFail; |
|
439 } |
|
440 |
|
441 return CPolicyServer::EPass; |
|
442 } |
|
443 else |
|
444 { |
|
445 // Missing connect SID or TrustedUI capability, cannot complete connection |
|
446 aMissing.iCaps.Set(ECapabilityTrustedUI); |
|
447 return CPolicyServer::EFail; |
|
448 } |
|
449 } |
|
450 |
|
451 CSession2* CInstallServer::NewSessionL(const TVersion& aClientVersion, |
|
452 const RMessage2&) const |
|
453 { |
|
454 |
|
455 // Currently there is only one version of the InstallServer |
|
456 const TVersion serverVersion(KInstallServerVersionMajor,KInstallServerVersionMinor,KInstallServerVersionBuild); |
|
457 |
|
458 // Check that the version of the server requested is not greater than |
|
459 // that available. |
|
460 if (!User::QueryVersionSupported(serverVersion, aClientVersion)) |
|
461 { |
|
462 User::Leave(KErrNotSupported); |
|
463 } |
|
464 |
|
465 return new(ELeave) CInstallSession(); |
|
466 } |
|
467 |
|
468 void CInstallServer::AddSession() |
|
469 { |
|
470 ++iSessionCount; |
|
471 DEBUG_PRINTF2(_L8("Install Server Session Created (%d sessions active)"), iSessionCount); |
|
472 iShutdown->Cancel(); |
|
473 } |
|
474 |
|
475 void CInstallServer::DropSession() |
|
476 { |
|
477 // if last session is dropped and server still alive start shutdown timer |
|
478 if (--iSessionCount==0 && iShutdown) |
|
479 { |
|
480 iShutdown->Start(); |
|
481 DEBUG_PRINTF(_L8("Install Server Starting Shutdown Timer")); |
|
482 } |
|
483 DEBUG_PRINTF2(_L8("Install Server Session Destroyed (%d sessions active)"), iSessionCount); |
|
484 } |
|
485 |
|
486 } // namespace Swi |