|
1 /* |
|
2 * Copyright (c) 2009-2010 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 * CInstallManager implementation |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include <swi/swispubsubdefs.h> |
|
22 #include <swi/sisregistrysession.h> |
|
23 #include <swi/sisregistryentry.h> |
|
24 #include <swi/sisregistrypackage.h> |
|
25 #include <e32base.h> |
|
26 #include "ADMAppUi.h" |
|
27 #include "ADMInstallManager.h" |
|
28 |
|
29 #include "macros.h" |
|
30 #include "debug.h" |
|
31 |
|
32 class TSisInfo |
|
33 { |
|
34 public: |
|
35 TVersion iVersion; |
|
36 TChar iInstalledDrive; |
|
37 RArray<TUid> iSids; |
|
38 }; |
|
39 |
|
40 _LIT8(KMIME,"x-epoc/x-sisx-app"); |
|
41 |
|
42 #ifdef USE_LOGFILE |
|
43 CInstallManager* CInstallManager::NewLC(MInstallClient* aInstallClient, RFileLogger& aLogger) |
|
44 { |
|
45 CInstallManager* object = new ( ELeave ) CInstallManager(aInstallClient, aLogger); |
|
46 CleanupStack::PushL( object ); |
|
47 object->ConstructL(); |
|
48 return object; |
|
49 } |
|
50 |
|
51 CInstallManager* CInstallManager::NewL(MInstallClient* aInstallClient, RFileLogger& aLogger) |
|
52 { |
|
53 CInstallManager* object = CInstallManager::NewLC(aInstallClient, aLogger); |
|
54 CleanupStack::Pop(); |
|
55 return object; |
|
56 } |
|
57 |
|
58 CInstallManager::CInstallManager(MInstallClient* aInstallClient, RFileLogger& aLogger) : |
|
59 CActive(EPriorityStandard), |
|
60 iLog(aLogger), |
|
61 iInstallClient(aInstallClient) |
|
62 { |
|
63 CActiveScheduler::Add(this); |
|
64 } |
|
65 #else |
|
66 CInstallManager* CInstallManager::NewLC(MInstallClient* aInstallClient) |
|
67 { |
|
68 CInstallManager* object = new ( ELeave ) CInstallManager(aInstallClient); |
|
69 CleanupStack::PushL( object ); |
|
70 object->ConstructL(); |
|
71 return object; |
|
72 } |
|
73 |
|
74 CInstallManager* CInstallManager::NewL(MInstallClient* aInstallClient) |
|
75 { |
|
76 CInstallManager* object = CInstallManager::NewLC(aInstallClient); |
|
77 CleanupStack::Pop(); |
|
78 return object; |
|
79 } |
|
80 |
|
81 CInstallManager::CInstallManager(MInstallClient* aInstallClient) : |
|
82 CActive(EPriorityStandard), |
|
83 iInstallClient(aInstallClient) |
|
84 { |
|
85 CActiveScheduler::Add(this); |
|
86 } |
|
87 #endif |
|
88 |
|
89 CInstallManager::~CInstallManager() |
|
90 { |
|
91 Cancel(); |
|
92 iLauncher.Close(); |
|
93 DELETE_IF_NONNULL( iInstallFilename ); |
|
94 } |
|
95 |
|
96 void CInstallManager::RunL() |
|
97 { |
|
98 if ( ((iStatus.Int() == SwiUI::KSWInstErrBusy )||(iStatus.Int() == KErrInUse) || (iStatus.Int() == KErrServerBusy) ) && |
|
99 ((++iInstallAttempt) <= KAttemptsToAccessInstaller) ) |
|
100 { |
|
101 LOG( "CInstallManager: Installer busy, waiting" ); |
|
102 User::After( KIterationTimer ); |
|
103 // Start asynchronous silent installation again |
|
104 if( !IsActive() ) |
|
105 { |
|
106 SetActive(); |
|
107 } |
|
108 |
|
109 iStatus = KRequestPending; |
|
110 |
|
111 iLauncher.SilentInstall( iStatus, *iInstallFilename, iOptionsPckg ); |
|
112 } |
|
113 else |
|
114 { |
|
115 LOG2( "CInstallManager: Install completed (%d)", iInstallAttempt ); |
|
116 iInstallClient->HandleInstallCompletedL( iStatus.Int() ); |
|
117 } |
|
118 } |
|
119 |
|
120 void CInstallManager::DoCancel() |
|
121 { |
|
122 CancelInstallation(); |
|
123 CancelUninstallation(); |
|
124 } |
|
125 |
|
126 void CInstallManager::ConstructL() |
|
127 { |
|
128 User::LeaveIfError(iLauncher.Connect()); |
|
129 } |
|
130 |
|
131 TBool CInstallManager::IsPackagePresentL( const TUid& aUid ) |
|
132 { |
|
133 TSisInfo sisInfo; |
|
134 TBool isInstalled; |
|
135 |
|
136 sisInfo = GetPackageInfoL(aUid, isInstalled); |
|
137 |
|
138 return isInstalled; |
|
139 } |
|
140 |
|
141 TBool CInstallManager::GetPackageSidsL(const TUid& aUid, RArray<TUid>& aSids) |
|
142 { |
|
143 TSisInfo sisInfo; |
|
144 TBool isInstalled; |
|
145 |
|
146 sisInfo = GetPackageInfoL(aUid, isInstalled); |
|
147 |
|
148 if (isInstalled) |
|
149 { |
|
150 aSids = sisInfo.iSids; |
|
151 } |
|
152 |
|
153 return isInstalled; |
|
154 } |
|
155 |
|
156 TBool CInstallManager::GetPackageInstalledDriveL(const TUid& aUid, TChar& aWrapperDrive) |
|
157 { |
|
158 TSisInfo sisInfo; |
|
159 TBool isInstalled; |
|
160 |
|
161 sisInfo = GetPackageInfoL(aUid, isInstalled); |
|
162 |
|
163 if (isInstalled) |
|
164 { |
|
165 aWrapperDrive = sisInfo.iInstalledDrive; |
|
166 } |
|
167 |
|
168 return isInstalled; |
|
169 } |
|
170 |
|
171 TBool CInstallManager::GetPackageVersionInfoL(const TUid& aUid, TVersion& aVersion) |
|
172 { |
|
173 TSisInfo sisInfo; |
|
174 TBool isInstalled; |
|
175 |
|
176 sisInfo = GetPackageInfoL(aUid, isInstalled); |
|
177 |
|
178 if (isInstalled) |
|
179 { |
|
180 aVersion = sisInfo.iVersion; |
|
181 } |
|
182 |
|
183 return isInstalled; |
|
184 } |
|
185 |
|
186 TSisInfo CInstallManager::GetPackageInfoL(const TUid& aUid, TBool& aIsPkgInstalled) |
|
187 { |
|
188 TSisInfo sisInfo; |
|
189 // Connect to SisRegistry to fetch Package info |
|
190 Swi::RSisRegistrySession registrySession; |
|
191 |
|
192 User::LeaveIfError( registrySession.Connect() ); |
|
193 CleanupClosePushL(registrySession); |
|
194 |
|
195 aIsPkgInstalled = registrySession.IsInstalledL( aUid ); |
|
196 |
|
197 if ( aIsPkgInstalled ) |
|
198 { |
|
199 Swi::RSisRegistryEntry entry; |
|
200 |
|
201 // Open registry entry to get version information. |
|
202 User::LeaveIfError(entry.Open(registrySession, aUid)); |
|
203 CleanupClosePushL(entry); |
|
204 |
|
205 // Get the data |
|
206 sisInfo.iVersion = entry.VersionL(); |
|
207 sisInfo.iInstalledDrive = entry.SelectedDriveL(); |
|
208 entry.SidsL(sisInfo.iSids); |
|
209 |
|
210 CleanupStack::PopAndDestroy(&entry); |
|
211 } |
|
212 |
|
213 CleanupStack::PopAndDestroy(®istrySession); |
|
214 |
|
215 return sisInfo; |
|
216 } |
|
217 |
|
218 void CInstallManager::SilentInstallPackageL(const TDesC& aInstallFilename, const TChar aInstallDrive) |
|
219 { |
|
220 LOG2( "+ SilentInstallPackage(): '%S'", &aInstallFilename ); |
|
221 |
|
222 DELETE_IF_NONNULL( iInstallFilename ); |
|
223 iInstallFilename = aInstallFilename.AllocL(); |
|
224 iInstallAttempt = 0; |
|
225 |
|
226 SwiUI::TInstallOptions Options; |
|
227 |
|
228 Options.iUpgrade = SwiUI::EPolicyAllowed; |
|
229 Options.iOCSP = SwiUI::EPolicyNotAllowed; |
|
230 RFs::DriveToChar(aInstallDrive, Options.iDrive); |
|
231 Options.iUntrusted = SwiUI::EPolicyNotAllowed; |
|
232 Options.iCapabilities = SwiUI::EPolicyAllowed; |
|
233 Options.iOverwrite = SwiUI::EPolicyAllowed; |
|
234 |
|
235 iOptionsPckg = Options; |
|
236 |
|
237 // We have to cancel any pending async request, because we might |
|
238 // get called during installation (user cancel, for instance) |
|
239 if (IsActive()) |
|
240 { |
|
241 Cancel(); |
|
242 } |
|
243 |
|
244 // Start asynchronous silent installation |
|
245 iStatus = KRequestPending; |
|
246 SetActive(); |
|
247 iLauncher.SilentInstall( iStatus, *iInstallFilename, iOptionsPckg); |
|
248 } |
|
249 |
|
250 TInt CInstallManager::SilentUnInstallPackage(const TUid& aPkgUid) |
|
251 { |
|
252 TInt ret; |
|
253 |
|
254 SwiUI::TUninstallOptions Options; |
|
255 SwiUI::TUninstallOptionsPckg OptionsPckg; |
|
256 |
|
257 // TODO: Missing iBreakDependency: Allowed or not? |
|
258 Options.iBreakDependency = SwiUI::EPolicyAllowed; |
|
259 Options.iKillApp = SwiUI::EPolicyAllowed; |
|
260 OptionsPckg = Options; |
|
261 |
|
262 // Start silent uninstallation |
|
263 // If connection to Install server fails, |
|
264 // make KAttemptsToAccessInstaller connection attempts |
|
265 for (TInt i = 0; i < KAttemptsToAccessInstaller; i++) |
|
266 { |
|
267 // Silent Uninstallation |
|
268 ret = iLauncher.SilentUninstall( aPkgUid, OptionsPckg, KMIME ); |
|
269 |
|
270 // SWI returns KErrInUse & KErrServerBusy as well. |
|
271 // SwiUI errors are returned as is |
|
272 if ( ret == SwiUI::KSWInstErrBusy || |
|
273 ret == KErrInUse || |
|
274 ret == KErrServerBusy) |
|
275 { |
|
276 LOG3( "Installer busy, retrying (%d: %d)", i, ret ); |
|
277 // Wait a while and then retry the uninstallation again |
|
278 User::After( KIterationTimer ); |
|
279 } |
|
280 else |
|
281 { |
|
282 break; |
|
283 } |
|
284 } |
|
285 |
|
286 return ret; |
|
287 } |
|
288 |
|
289 void CInstallManager::SilentUninstallPackageAsync(const TUid& aPkgUid) |
|
290 { |
|
291 SwiUI::TUninstallOptions options; |
|
292 |
|
293 // TODO: Missing iBreakDependency: Allowed or not? |
|
294 options.iBreakDependency = SwiUI::EPolicyAllowed; |
|
295 options.iKillApp = SwiUI::EPolicyAllowed; |
|
296 iUninstallOptionsPckg = options; |
|
297 |
|
298 // We have to cancel any pending async request, because we might |
|
299 // get called during uninstallation (user cancel, for instance) |
|
300 if (IsActive()) |
|
301 { |
|
302 Cancel(); |
|
303 } |
|
304 |
|
305 // Start asynchronous silent uninstallation |
|
306 iStatus = KRequestPending; |
|
307 SetActive(); |
|
308 iLauncher.SilentUninstall( iStatus, aPkgUid, iUninstallOptionsPckg, KMIME ); |
|
309 } |
|
310 |
|
311 void CInstallManager::CancelAll() |
|
312 { |
|
313 Cancel(); |
|
314 CancelInstallation(); |
|
315 CancelUninstallation(); |
|
316 } |
|
317 |
|
318 TInt CInstallManager::CancelInstallation() |
|
319 { |
|
320 return iLauncher.CancelAsyncRequest(SwiUI::ERequestSilentInstall); |
|
321 } |
|
322 |
|
323 TInt CInstallManager::CancelUninstallation() |
|
324 { |
|
325 return iLauncher.CancelAsyncRequest(SwiUI::ERequestSilentUninstall); |
|
326 } |
|
327 |
|
328 TInt CInstallManager::InstallPackage(const TDesC& aInstallFilename) |
|
329 { |
|
330 LOG2( "+ InstallPackage(): '%S'", &aInstallFilename ); |
|
331 |
|
332 DELETE_IF_NONNULL( iInstallFilename ); |
|
333 iInstallFilename = aInstallFilename.AllocL(); |
|
334 |
|
335 TInt ret; |
|
336 SwiUI::RSWInstLauncher Launcher; |
|
337 |
|
338 ret = Launcher.Connect(); |
|
339 if (ret != KErrNone) |
|
340 { |
|
341 return ret; |
|
342 } |
|
343 |
|
344 // Start Installation |
|
345 // If connection to Install server fails, |
|
346 // make KAttemptsToAccessInstaller connection attempts |
|
347 for (TInt i = 0; i < KAttemptsToAccessInstaller; i++) |
|
348 { |
|
349 // Normal installation |
|
350 ret = Launcher.Install(*iInstallFilename); |
|
351 |
|
352 // SWI returns KErrInUse & KErrServerBusy as well. |
|
353 // SwiUI errors are returned as is |
|
354 if ( ret == SwiUI::KSWInstErrBusy || |
|
355 ret == KErrInUse || |
|
356 ret == KErrServerBusy) |
|
357 { |
|
358 LOG3( "Installer busy, retrying (%d: %d)", i, ret ); |
|
359 // Wait a while and then retry the uninstallation again |
|
360 User::After( KIterationTimer ); |
|
361 } |
|
362 else |
|
363 { |
|
364 break; |
|
365 } |
|
366 } |
|
367 Launcher.Close(); |
|
368 return ret; |
|
369 } |
|
370 |
|
371 TUid CInstallManager::GetPackageUidL(const TUid& aSid) |
|
372 { |
|
373 // Connect to SisRegistry to fetch Package info |
|
374 Swi::RSisRegistrySession registrySession; |
|
375 User::LeaveIfError(registrySession.Connect()); |
|
376 CleanupClosePushL(registrySession); |
|
377 |
|
378 Swi::CSisRegistryPackage* pkg = NULL; |
|
379 pkg = registrySession.SidToPackageL(aSid); |
|
380 |
|
381 CleanupStack::PopAndDestroy(®istrySession); |
|
382 |
|
383 TUid uid = TUid::Uid(0); |
|
384 if ( pkg ) |
|
385 { |
|
386 uid = pkg->Uid(); |
|
387 } |
|
388 |
|
389 delete pkg; |
|
390 |
|
391 return uid; |
|
392 } |