|
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 * CBootstrapAppUi class implementation. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <aknglobalnote.h> |
|
23 #include <stringloader.h> |
|
24 #include <smartinstaller.rsg> |
|
25 #include <apgcli.h> |
|
26 #include <swi/swispubsubdefs.h> |
|
27 |
|
28 #include "bootstrapapplication.h" |
|
29 #include "bootstrapappui.h" |
|
30 #include "bootstrapglobalwaitnoteobserver.h" |
|
31 #include "bootstrapstatemachine.h" |
|
32 #include "debug.h" |
|
33 #include "globals.h" |
|
34 #include "macros.h" |
|
35 #include "config.h" |
|
36 #include "utils.h" |
|
37 |
|
38 #ifdef USE_LOGFILE |
|
39 // Logging information |
|
40 _LIT(KADMLogDir, "ADM"); |
|
41 _LIT(KBootstrapLogFileName, "log-boot.txt" ); |
|
42 _LIT(KBootstrapLogFile, "?:\\logs\\ADM\\log-boot.txt"); |
|
43 #endif |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CBootstrapAppUi::ConstructL() |
|
47 // ConstructL of BootstrapApp. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CBootstrapAppUi::ConstructL() |
|
51 { |
|
52 TRAPD(err, InitializeSIL()); |
|
53 |
|
54 if(err != KErrNone) |
|
55 { |
|
56 LOG2( "Init failed %d", err ); |
|
57 SetErrorId(EInstallationFailed); |
|
58 ExitApp(EBSStateInit); |
|
59 } |
|
60 else |
|
61 { |
|
62 iStateMachine = CStateMachine::NewL(*this,iWrapperPackageUid); |
|
63 iStateMachine->Start(); |
|
64 } |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CBootstrapAppUi::CBootstrapAppUi() |
|
69 // C++ default constructor can NOT contain any code, that might leave. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CBootstrapAppUi::CBootstrapAppUi(): |
|
73 iAllowForeground(EFalse) |
|
74 { |
|
75 LOG ( "SmartInstaller bootstrap begins" ); |
|
76 // disable possible transition effects |
|
77 SetFullScreenApp(EFalse); |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CBootstrapAppUi::~CBootstrapAppUi() |
|
82 // Destructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CBootstrapAppUi::~CBootstrapAppUi() |
|
86 { |
|
87 LOG( "~SmartInstaller()" ); |
|
88 |
|
89 delete iGlobalWaitNoteObserver; |
|
90 delete iGlobalWaitNote; |
|
91 delete iStateMachine; |
|
92 |
|
93 LOG( "SmartInstaller bootstrap ends" ); |
|
94 CLOSE_DEBUG_LOG; |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CBootstrapAppUi::InitializeSIL |
|
99 // Enter function in EBSStateInit, |
|
100 // Leaves if Connect failure to downloadmanager,SWI Launcher, Unable to identify ADM Presence |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 void CBootstrapAppUi::InitializeSIL() |
|
104 { |
|
105 LOG("+ Init()"); |
|
106 |
|
107 // Create the log |
|
108 INIT_DEBUG_LOG( KBootstrapLogFile(), KADMLogDir, KBootstrapLogFileName ); |
|
109 |
|
110 // Hide from application task list |
|
111 HideApplicationFromFSW(); |
|
112 |
|
113 // Send application to background |
|
114 SendToBackgroundL(); |
|
115 |
|
116 // Check if Ovi Store client is running |
|
117 // Logging purposes only at the moment |
|
118 iOviStoreRunning = CUtils::OviStoreRunning(); |
|
119 if ( iOviStoreRunning ) |
|
120 { |
|
121 LOG( "! Ovi Store running" ); |
|
122 } |
|
123 |
|
124 // Wait for the installer to be free |
|
125 WaitForInstallCompleteL(); |
|
126 |
|
127 // Initialise app UI with standard value. |
|
128 BaseConstructL( ENoScreenFurniture /* CAknAppUi::EAknEnableSkin */ ); |
|
129 StatusPane()->MakeVisible(EFalse); |
|
130 |
|
131 LOG("- Init()"); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CBootstrapAppUi::WaitForInstallCompleteL |
|
136 // called in EBSStateInit, |
|
137 // Wait for the wrapper package to be completed. Then fetch the wrapper package UID |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 void CBootstrapAppUi::WaitForInstallCompleteL() |
|
141 { |
|
142 LOG( "+ WaitForInstallComplete()" ); |
|
143 |
|
144 // Use publish and subscribe mechanism to |
|
145 // get notified when installer is free. |
|
146 RProperty installComplete; |
|
147 User::LeaveIfError(installComplete.Attach(KUidSystemCategory, Swi::KUidSoftwareInstallKey)); |
|
148 |
|
149 TInt value(-1); |
|
150 TInt err(-1); |
|
151 err = installComplete.Get( KUidSystemCategory, Swi::KUidSoftwareInstallKey, value ); |
|
152 if ( err != KErrNone) |
|
153 { |
|
154 LOG( "! Unable to get installer" ); |
|
155 installComplete.Close(); |
|
156 User::Leave(err); |
|
157 } |
|
158 else if((value & Swi::KSwisOperationMask) == Swi::ESwisNone) |
|
159 { |
|
160 LOG( "Installer is idle" ); |
|
161 // Installer is idle. |
|
162 } |
|
163 else |
|
164 { |
|
165 LOG( "Waiting for installer to become idle" ); |
|
166 TRequestStatus status; |
|
167 installComplete.Subscribe(status); |
|
168 User::WaitForRequest( status ); |
|
169 if ( status.Int() != KErrNone ) |
|
170 { |
|
171 LOG2( "Failed to subscribe: %d", status.Int() ); |
|
172 installComplete.Close(); |
|
173 User::Leave( status.Int() ); |
|
174 } |
|
175 } |
|
176 |
|
177 // Get the Uid of the latest installed package |
|
178 iWrapperPackageUid = GetLatestInstalledL(); |
|
179 |
|
180 iAllowForeground = ETrue; |
|
181 |
|
182 installComplete.Close(); |
|
183 |
|
184 ShowGlobalWaitNoteL(); |
|
185 |
|
186 SendToBackgroundL(EFalse); |
|
187 |
|
188 LOG( "- WaitForInstallComplete()" ); |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // CBootstrapAppUi::GetLatestInstalledL |
|
193 // Get the latest package installed in the device. |
|
194 // Called in EBSStateInit on completion of wrapper installation. |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 TUint32 CBootstrapAppUi::GetLatestInstalledL() |
|
198 { |
|
199 LOG( "+ GetLatestInstalled()" ); |
|
200 |
|
201 // Use publish and subscribe mechanism to |
|
202 // get Uid of the latest installed package. |
|
203 RProperty lastInstall; |
|
204 User::LeaveIfError(lastInstall.Attach(KUidSystemCategory, KUidSwiLatestInstallation)); |
|
205 |
|
206 TInt value = -1; |
|
207 User::LeaveIfError(lastInstall.Get( KUidSystemCategory, KUidSwiLatestInstallation, value )); |
|
208 |
|
209 LOG2( "- GetLatestInstalled(): 0x%08x", value ); |
|
210 return value; |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CBootstrapAppUi::HandleGlobalWaitNoteCancel |
|
215 // Call OnExitOfState() when the process is cancelled. |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void CBootstrapAppUi::HandleGlobalWaitNoteCancel(const TInt& aStatus) |
|
219 { |
|
220 LOG2( "+ CancelNoteEvent(%d) ", aStatus ); |
|
221 |
|
222 // Do the cleanup based on the state |
|
223 if (aStatus == -1) |
|
224 { |
|
225 iGlobalWaitNoteId = -1; |
|
226 //TODO: Is there a possibility of statemachine not being present here.? |
|
227 iStateMachine->HandleWaitNoteCancel(); |
|
228 } |
|
229 |
|
230 LOG( "- CancelNoteEvent() "); |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CBootstrapAppUi::SendToBackgroundL |
|
235 // Called to move the app background/foreground. |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 void CBootstrapAppUi::SendToBackgroundL(TBool aBackground) |
|
239 { |
|
240 LOG2( "+ SendToBackground(%d)", aBackground ); |
|
241 // We have gained the focus |
|
242 RWsSession aWsSession; |
|
243 User::LeaveIfError( aWsSession.Connect() ); |
|
244 TApaTask task(aWsSession); |
|
245 |
|
246 // Initialise the object with the window group id of |
|
247 // our application (so that it represent our app) |
|
248 task.SetWgId(CEikonEnv::Static()->RootWin().Identifier()); |
|
249 if (aBackground) |
|
250 { |
|
251 task.SendToBackground(); |
|
252 } |
|
253 else |
|
254 { |
|
255 task.BringToForeground(); |
|
256 } |
|
257 aWsSession.Close(); |
|
258 LOG( "- SendToBackground() "); |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------------------------- |
|
262 // CBootstrapAppUi::ShowGlobalWaitNoteL |
|
263 // Show the Global wait note. (starts in EBSStateInit) |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 void CBootstrapAppUi::ShowGlobalWaitNoteL() |
|
267 { |
|
268 // Allocate TBuf with constant length. |
|
269 TBuf<KMaxMsgSize> text( NULL ); |
|
270 |
|
271 // Reads a resource into a descriptor. |
|
272 CEikonEnv::Static()->ReadResource( text, R_ADM_VERIFYING_SW_TEXT ); |
|
273 |
|
274 // Create new CAknGlobalNote instance. |
|
275 iGlobalWaitNote = CAknGlobalNote::NewL(); |
|
276 |
|
277 iGlobalWaitNoteObserver = new (ELeave) CGlobalWaitNoteObserver(this); |
|
278 iGlobalWaitNoteObserver->iStatus = KRequestPending; |
|
279 iGlobalWaitNoteObserver->Start(); |
|
280 |
|
281 iGlobalWaitNoteId = iGlobalWaitNote->ShowNoteL( |
|
282 iGlobalWaitNoteObserver->iStatus, |
|
283 EAknGlobalWaitNote, |
|
284 text ); |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // CBootstrapAppUi::StopGlobalWaitNoteL |
|
289 // Stop the Global wait note, incase of any exit. |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 void CBootstrapAppUi::StopGlobalWaitNoteL() |
|
293 { |
|
294 LOG2( "+ StopWaitNote(%d)", iGlobalWaitNoteId ); |
|
295 if ( iGlobalWaitNote && (iGlobalWaitNoteId >= 0) ) |
|
296 { |
|
297 iGlobalWaitNote->CancelNoteL(iGlobalWaitNoteId); |
|
298 } |
|
299 iGlobalWaitNoteId = -1; |
|
300 |
|
301 DELETE_IF_NONNULL( iGlobalWaitNote ); |
|
302 DELETE_IF_NONNULL( iGlobalWaitNoteObserver ); |
|
303 LOG( "- StopWaitNote()" ); |
|
304 } |
|
305 |
|
306 // --------------------------------------------------------------------------- |
|
307 // CBootstrapAppUi::ShowNoteL |
|
308 // Show the note on Exit on Error |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 void CBootstrapAppUi::ShowNoteL( const TAknGlobalNoteType& aType, const TInt& aResourceId ) |
|
312 { |
|
313 // Allocate TBuf with constant length. |
|
314 TBuf<KMaxMsgSize> text; |
|
315 |
|
316 // Reads a resource into a descriptor. |
|
317 CEikonEnv::Static()->ReadResource( text, aResourceId ); |
|
318 |
|
319 // Create new CAknGlobalNote instance. |
|
320 CAknGlobalNote* globalNote = CAknGlobalNote::NewLC(); |
|
321 globalNote->ShowNoteL( aType , text ); |
|
322 CleanupStack::PopAndDestroy(globalNote); |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CBootstrapAppUi::HandleForegroundEventL |
|
327 // On receiving the foreground event, send the app to background. |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 void CBootstrapAppUi::HandleForegroundEventL(TBool aForeground) |
|
331 { |
|
332 LOG3("+ HandleForegroundEvent(%d): %d", aForeground, iAllowForeground ); |
|
333 CAknAppUi::HandleForegroundEventL(aForeground); |
|
334 |
|
335 if (aForeground && !iAllowForeground) |
|
336 { |
|
337 SendToBackgroundL(); |
|
338 } |
|
339 LOG("- HandleForegroundEvent()" ); |
|
340 } |
|
341 |
|
342 // --------------------------------------------------------------------------- |
|
343 // CBootstrapAppUi::ExitApp |
|
344 // Handle success and failures on all cases |
|
345 // Display an error notice and exit the application. |
|
346 // Perform the necessary state specific cleanup. |
|
347 // --------------------------------------------------------------------------- |
|
348 // |
|
349 void CBootstrapAppUi::ExitApp(TInt aAppState) |
|
350 { |
|
351 LOG3( "+ ExitApp(%d): %d", aAppState, iErrorId ); |
|
352 |
|
353 TInt resourceId = ENoAppError; |
|
354 |
|
355 switch ( iErrorId ) |
|
356 { |
|
357 case ENoAppError: |
|
358 break; |
|
359 case EInstallationFailed: |
|
360 { |
|
361 resourceId = R_INSTALLATION_FAILURE_ERR; |
|
362 } |
|
363 break; |
|
364 case EDownloadFailed: |
|
365 { |
|
366 resourceId = R_HTTP_TRANSACTION_ERR; |
|
367 } |
|
368 break; |
|
369 default: |
|
370 LOG2( "Unknown error %d, ignoring", iErrorId ); |
|
371 break; |
|
372 } |
|
373 |
|
374 if (resourceId != 0) |
|
375 { |
|
376 // Display error message |
|
377 TRAP_IGNORE( { |
|
378 StopGlobalWaitNoteL(); |
|
379 ShowNoteL(EAknGlobalErrorNote, resourceId); |
|
380 } ); |
|
381 } |
|
382 else |
|
383 { |
|
384 // the final error note is displayed by ADM. |
|
385 // make a pause before removing the note to hide the "installation OK" |
|
386 // note displayed by S60 installer |
|
387 User::After(1500000); |
|
388 TRAP_IGNORE( StopGlobalWaitNoteL() ); |
|
389 } |
|
390 |
|
391 // Stop the state machine |
|
392 iStateMachine->Stop(); |
|
393 |
|
394 LOG( "StateMachine stopped" ); |
|
395 |
|
396 Exit(); |
|
397 |
|
398 LOG( "- ExitApp()" ); |
|
399 } |