|
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 * Declaration of CStateMachine class. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <downloadmgrclient.h> |
|
23 #include <swinstapi.h> |
|
24 |
|
25 #include "bootstrapappui.h" |
|
26 #include "globals.h" |
|
27 #include "debug.h" |
|
28 |
|
29 // Mandatory changes XML elements |
|
30 _LIT8(KFieldVersion, "Version"); |
|
31 _LIT8(KFieldSisName, "SisFileName"); |
|
32 // Optional changes XML elements |
|
33 _LIT8(KFieldUrl, "Url"); |
|
34 |
|
35 // SmartInstaller bootstrap states |
|
36 enum EBSAppState |
|
37 { |
|
38 EBSStateInit = 0, // 0 |
|
39 EBSStateSetup, |
|
40 EBSStateDownloadChanges, |
|
41 EBSStateParseChanges, |
|
42 EBSStateDownloadAdm, |
|
43 EBSStateInstallAdm, // 5 |
|
44 EBSStateLaunchAdm, |
|
45 EBSStateExitWithError, |
|
46 EBSStateExit, |
|
47 EBSStateLast // not actual state |
|
48 }; |
|
49 |
|
50 enum EXmlParserError |
|
51 { |
|
52 EXmlErrorNotWelformed, |
|
53 EXmlErrorMissingVersion, |
|
54 EXmlErrorInvalidVersion, |
|
55 EXmlErrorMissingSisFileName, |
|
56 }; |
|
57 |
|
58 struct TAdmChangesInfo |
|
59 { |
|
60 TAdmChangesInfo(): |
|
61 iVersion(0,0,0), |
|
62 iSisName(NULL), |
|
63 iUrl(NULL) |
|
64 {} |
|
65 ~TAdmChangesInfo() |
|
66 { |
|
67 delete iSisName; |
|
68 delete iUrl; |
|
69 } |
|
70 |
|
71 TVersion iVersion; |
|
72 HBufC* iSisName; |
|
73 HBufC8* iUrl; |
|
74 }; |
|
75 |
|
76 // Forward declarations |
|
77 class CInstallObserver; |
|
78 class RConnectionMonitor; |
|
79 class CHelper; |
|
80 |
|
81 class CStateMachine : public CActive, |
|
82 public MHttpDownloadMgrObserver |
|
83 { |
|
84 public: |
|
85 static CStateMachine* NewL(CBootstrapAppUi& aSIUiObj, TUint32 aWrapperUid); |
|
86 static CStateMachine* NewLC(CBootstrapAppUi& aSIUiObj, TUint32 aWrapperUid); |
|
87 |
|
88 /** |
|
89 * ~CStateMachine. |
|
90 * Virtual Destructor. |
|
91 */ |
|
92 virtual ~CStateMachine(); |
|
93 |
|
94 /** |
|
95 * Start the state machine |
|
96 */ |
|
97 void Start(); |
|
98 |
|
99 /** |
|
100 * Stop the state machine |
|
101 */ |
|
102 void Stop(); |
|
103 |
|
104 /** |
|
105 * HandleWaitNoteCancel |
|
106 * Called by AppUi on User Press Cancel |
|
107 */ |
|
108 void HandleWaitNoteCancel(); |
|
109 |
|
110 /** |
|
111 * HandleInstallCompleteL |
|
112 * Called on installation complete by Installation Observer |
|
113 */ |
|
114 void HandleInstallCompleteL(const TInt& aStatus); |
|
115 |
|
116 /** |
|
117 * HandleDMgrEventL |
|
118 * Handle download manager events. |
|
119 */ |
|
120 void HandleDMgrEventL(RHttpDownload& aDownload, THttpDownloadEvent aEvent ); |
|
121 |
|
122 /** |
|
123 * HandleFailure |
|
124 * Perform the state specific cleanup in case of a failure |
|
125 */ |
|
126 void HandleFailure(TBool aUserCancel = EFalse); |
|
127 |
|
128 private: |
|
129 /** |
|
130 * CStateMachine. |
|
131 * C++ default constructor. |
|
132 */ |
|
133 CStateMachine(CBootstrapAppUi& aSIUiObj, TUint32 aWrapperUid); |
|
134 |
|
135 /** |
|
136 * ConstructL. |
|
137 * 2nd phase constructor. |
|
138 */ |
|
139 void ConstructL(); |
|
140 |
|
141 /** |
|
142 * RunL |
|
143 * Called for each state transition |
|
144 */ |
|
145 void RunL(); |
|
146 |
|
147 /** |
|
148 * RunError |
|
149 * Called incase of an error |
|
150 */ |
|
151 TInt RunError(TInt aError); |
|
152 |
|
153 /** |
|
154 * DoCancel |
|
155 * |
|
156 */ |
|
157 void DoCancel(); |
|
158 |
|
159 /** |
|
160 * SetNextState |
|
161 * Transition to the next state |
|
162 */ |
|
163 void RequestState(const EBSAppState aNextState); |
|
164 |
|
165 /** |
|
166 * StateInitL |
|
167 * Set the sisfilename and dep filename to be passed to ADM |
|
168 */ |
|
169 void StateInitL(); |
|
170 |
|
171 /** |
|
172 * StateDownloadL |
|
173 * Download the specified file. |
|
174 */ |
|
175 void StateDownloadL(); |
|
176 |
|
177 /** |
|
178 * StateParseChangesL |
|
179 * Parse the ADM changes file |
|
180 */ |
|
181 void StateParseChangesL(); |
|
182 |
|
183 /** |
|
184 * StateInstallAdmL |
|
185 * Installs the specified package |
|
186 */ |
|
187 void StateInstallAdmL(); |
|
188 |
|
189 /** |
|
190 * StateLaunchAdmL |
|
191 * Launch ADM |
|
192 */ |
|
193 void StateLaunchAdmL(); |
|
194 |
|
195 /** |
|
196 * IsAdmDownloadRequired |
|
197 * Check whether ADM sis needs to be downloaded |
|
198 */ |
|
199 TBool IsAdmDownloadRequired(); |
|
200 |
|
201 /** |
|
202 * DeleteFile |
|
203 * Delete the given file |
|
204 */ |
|
205 void DeleteFile(const TDesC& aFileName); |
|
206 |
|
207 /** |
|
208 * IsPackagePresentL |
|
209 * Check if the ADM is already present in the device or not |
|
210 */ |
|
211 TBool IsPackagePresentL(const TUid& aUid, TVersion& aVersion); |
|
212 |
|
213 /** |
|
214 * ReadConfigurationL |
|
215 * Read the config file |
|
216 */ |
|
217 TInt ReadConfigurationL(); |
|
218 |
|
219 /** |
|
220 * ProcessDlErrors |
|
221 * Identify the download error |
|
222 */ |
|
223 TBool ProcessDlErrors(const TInt32 aErrId, const TInt32 aGlErrId, EDownloadError& aDownloadError); |
|
224 |
|
225 /** |
|
226 * Returns ETrue, if Ovi Store client is running |
|
227 */ |
|
228 inline TBool OviStoreRunning() const { return iAppUi.iOviStoreRunning; } |
|
229 |
|
230 #ifdef FEATURE_BOOTSTRAP_SETIAP |
|
231 void SetIAP(const TUint aIAP); |
|
232 void SetAndValidateIAPL(); |
|
233 void GetSnapIapsL(const TUint aSNAPId); |
|
234 TBool IsIapActive(RConnectionMonitor& aMonitor, TInt& aIAP); |
|
235 #endif |
|
236 |
|
237 private: |
|
238 CBootstrapAppUi& iAppUi; |
|
239 |
|
240 /** |
|
241 * ADM installation status on the device |
|
242 */ |
|
243 TBool iIsAdmInstalled; |
|
244 |
|
245 /** |
|
246 * Current application state |
|
247 */ |
|
248 EBSAppState iAppState; |
|
249 |
|
250 /** |
|
251 * Wrapper package UID. Passed to ADM. |
|
252 */ |
|
253 TUint32 iWrapperPackageUid; |
|
254 |
|
255 /** |
|
256 * IAP for Download Manager. Passed to ADM. |
|
257 */ |
|
258 TInt32 iIAP; |
|
259 |
|
260 /** |
|
261 * IAP array for the browser SNAP. |
|
262 */ |
|
263 RArray<TUint32> iIapArray; |
|
264 |
|
265 /** |
|
266 * IAP array index. Points to the IAP currently in use. |
|
267 */ |
|
268 TUint32 iIapArrayIndex; |
|
269 |
|
270 /** |
|
271 * Dep filename. Passed to ADM. |
|
272 */ |
|
273 HBufC* iDepFilename; |
|
274 |
|
275 /** |
|
276 * Main application SIS filename. Passed to ADM. |
|
277 */ |
|
278 HBufC* iSisFilename; |
|
279 |
|
280 /** |
|
281 * ADM changes info, filled by parsing downloaded adm_changes.xml |
|
282 */ |
|
283 TAdmChangesInfo iAdmChangesInfo; |
|
284 |
|
285 /** |
|
286 * Bootstrap failure status. Passed to ADM. |
|
287 */ |
|
288 TBool iBootstrapFailed; |
|
289 |
|
290 /** |
|
291 * IAP cancel flag. |
|
292 */ |
|
293 TBool iIsIapCancelled; |
|
294 |
|
295 /** |
|
296 * URL provided by the configuration file to the server root or |
|
297 * the default URL, if config file is missing. |
|
298 */ |
|
299 HBufC8* iConfigUrl; |
|
300 |
|
301 /** |
|
302 * URL |
|
303 */ |
|
304 HBufC8* iUrl; |
|
305 |
|
306 /** |
|
307 * File to be downloaded |
|
308 */ |
|
309 TPtrC iFileName; |
|
310 |
|
311 /** |
|
312 * Url to download from. |
|
313 */ |
|
314 HBufC8* iDownloadUrl; |
|
315 |
|
316 /** |
|
317 * Downloaded filename |
|
318 */ |
|
319 HBufC* iDownloadFileName; |
|
320 |
|
321 /** |
|
322 * Version of ADM present in the device. |
|
323 */ |
|
324 TVersion iAdmInstalledVersion; |
|
325 |
|
326 /* |
|
327 * DownloadManager |
|
328 */ |
|
329 RHttpDownloadMgr iDownloadManager; |
|
330 |
|
331 /** |
|
332 * SwiUI launcher |
|
333 */ |
|
334 SwiUI::RSWInstSilentLauncher iLauncher; |
|
335 |
|
336 /** |
|
337 * Options for Swi Launcher |
|
338 */ |
|
339 SwiUI::TInstallOptionsPckg iOptionsPckg; |
|
340 |
|
341 /** |
|
342 * Current installation attempt |
|
343 */ |
|
344 TInt iInstallAttempt; |
|
345 |
|
346 /** |
|
347 * Track the download State - mainly for logging. |
|
348 */ |
|
349 TInt iDownloadState; |
|
350 |
|
351 /** |
|
352 * Track the Progress State of a download - mainly for logging. |
|
353 */ |
|
354 TInt iProgressState; |
|
355 |
|
356 /** |
|
357 * Current connnection reattempt number. |
|
358 */ |
|
359 TInt iConnectionAttempt; |
|
360 |
|
361 /** |
|
362 * Specific download error. |
|
363 */ |
|
364 EDownloadError iDownloadError; |
|
365 |
|
366 CInstallObserver* iInstallObsrv; //< owns |
|
367 |
|
368 #ifdef USE_LOGFILE |
|
369 RFileLogger& iLog; //< reference to iAppUi.iLog |
|
370 #endif |
|
371 }; |