author | Shabe Razvi <shaber@symbian.org> |
Fri, 24 Sep 2010 16:04:33 +0100 | |
changeset 94 | 6364b99b9e27 |
parent 90 | 3ac3aaebaee5 |
permissions | -rw-r--r-- |
63 | 1 |
/* |
2 |
* Copyright (c) 2008 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: application class. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include <e32property.h> |
|
19 |
#include <e32debug.h> |
|
20 |
#include "hsapplicationlauncher.h" |
|
21 |
||
22 |
// ========================= DECLARATIONS ================================== |
|
23 |
_LIT( KHsExeName, "hsapplication.exe" ); |
|
24 |
_LIT( KHsProcessName, "hsapplication.exe" ); |
|
25 |
const TInt KSleepOnRetry = 250000; // 250ms |
|
26 |
const TUid KPSCategoryUid = TUid::Uid( 0x20022F36 ); |
|
27 |
const TInt KPSCrashCountKey = 1; |
|
28 |
_LIT_SECURITY_POLICY_C1( KPSReadPolicy, ECapabilityReadDeviceData ); |
|
29 |
_LIT_SECURITY_POLICY_C1( KPSWritePolicy, ECapabilityWriteDeviceData ); |
|
30 |
||
31 |
// ========================= LOCAL FUNCTIONS ================================== |
|
32 |
#ifdef COVERAGE_MEASUREMENT |
|
33 |
#pragma CTC SKIP |
|
34 |
#endif //COVERAGE_MEASUREMENT |
|
35 |
void RunAppL() |
|
36 |
{ |
|
37 |
// Construct active scheduler. |
|
38 |
CActiveScheduler* activeScheduler = new ( ELeave )CActiveScheduler(); |
|
39 |
CleanupStack::PushL( activeScheduler ); |
|
40 |
CActiveScheduler::Install( activeScheduler ); |
|
41 |
||
42 |
// Construct app. |
|
43 |
CHsLaunch* app = CHsLaunch::NewL(); |
|
44 |
CleanupStack::PushL( app ); |
|
45 |
||
46 |
app->Activate(); |
|
47 |
||
48 |
// Signal startup. |
|
49 |
RProcess::Rendezvous(KErrNone); |
|
50 |
||
51 |
// Start active scheduler. |
|
52 |
CActiveScheduler::Start(); |
|
53 |
||
54 |
User::LeaveIfError( app->ApplicationReturnValue() ); |
|
55 |
||
56 |
// Cleanup. |
|
57 |
CleanupStack::PopAndDestroy( app ); |
|
58 |
CleanupStack::PopAndDestroy( activeScheduler ); |
|
59 |
} |
|
60 |
||
61 |
#ifndef HOMESCREEN_TEST |
|
62 |
// ----------------------------------------------------------------------------- |
|
63 |
// E32Main |
|
64 |
// entry-point |
|
65 |
// ----------------------------------------------------------------------------- |
|
66 |
// |
|
67 |
TInt E32Main() |
|
68 |
{ |
|
69 |
TInt error = KErrNone; |
|
70 |
||
71 |
__UHEAP_MARK; |
|
72 |
||
73 |
// Construct cleanup stack. |
|
74 |
CTrapCleanup* cleanupstack = CTrapCleanup::New(); |
|
75 |
if( !cleanupstack ) |
|
76 |
{ |
|
77 |
error = KErrNoMemory; |
|
78 |
} |
|
79 |
||
80 |
// Call next phase of startup. |
|
81 |
if( !error ) |
|
82 |
{ |
|
83 |
TRAP( error, RunAppL() ); |
|
84 |
} |
|
85 |
||
86 |
// Cleanup. |
|
87 |
delete cleanupstack; |
|
88 |
cleanupstack = NULL; |
|
89 |
||
90 |
__UHEAP_MARKEND; |
|
91 |
||
92 |
return error; |
|
93 |
} |
|
94 |
#endif //HOMESCREEN_TEST |
|
95 |
#ifdef COVERAGE_MEASUREMENT |
|
96 |
#pragma CTC ENDSKIP |
|
97 |
#endif //COVERAGE_MEASUREMENT |
|
98 |
// ========================= MEMBER FUNCTIONS ================================== |
|
99 |
||
100 |
// ----------------------------------------------------------------------------- |
|
101 |
// CHsLaunch::NewL() |
|
102 |
// Two-phased constructor. |
|
103 |
// ----------------------------------------------------------------------------- |
|
104 |
CHsLaunch* CHsLaunch::NewL() |
|
105 |
{ |
|
106 |
CHsLaunch* self = new ( ELeave ) CHsLaunch(); |
|
107 |
CleanupStack::PushL( self ); |
|
108 |
self->ConstructL(); |
|
109 |
CleanupStack::Pop( self ); |
|
110 |
return self; |
|
111 |
} |
|
112 |
||
113 |
// ----------------------------------------------------------------------------- |
|
114 |
// CHsLaunch::ConstructL() |
|
115 |
// Symbian 2nd phase constructor can leave. |
|
116 |
// ----------------------------------------------------------------------------- |
|
117 |
// |
|
118 |
void CHsLaunch::ConstructL() |
|
119 |
{ |
|
94
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
120 |
// iRepository = CRepository::NewL(TUid::Uid(0x2002b3aa)); |
63 | 121 |
|
122 |
iShutdownMonitor = CHsShutdownMonitor::NewL( *this ); |
|
123 |
iShutdownMonitor->StartMonitor(); |
|
124 |
||
125 |
// Create property to pub/sub. |
|
126 |
TInt error = RProperty::Define( KPSCrashCountKey, |
|
127 |
RProperty::EInt, |
|
128 |
KPSReadPolicy, |
|
129 |
KPSWritePolicy ); |
|
130 |
if( error == KErrNone ) |
|
131 |
{ |
|
132 |
// Init it to zero. |
|
133 |
error = RProperty::Set( KPSCategoryUid, KPSCrashCountKey, 0 ); |
|
134 |
} |
|
135 |
else if( error == KErrAlreadyExists ) |
|
136 |
{ |
|
137 |
error = KErrNone; |
|
138 |
} |
|
139 |
||
140 |
User::LeaveIfError( error ); |
|
141 |
} |
|
142 |
||
143 |
// ----------------------------------------------------------------------------- |
|
144 |
// CHsLaunch::CHsLaunch() |
|
145 |
// C++ default constructor can NOT contain any code, that might leave. |
|
146 |
// ----------------------------------------------------------------------------- |
|
147 |
CHsLaunch::CHsLaunch() : |
|
148 |
CActive( EPriorityStandard ), |
|
149 |
iApplicationReturnValue( KErrNone ) |
|
150 |
{ |
|
151 |
CActiveScheduler::Add( this ); |
|
152 |
} |
|
153 |
||
154 |
// ----------------------------------------------------------------------------- |
|
155 |
// CHsLaunch::~CHsLaunch() |
|
156 |
// Destructor. |
|
157 |
// ----------------------------------------------------------------------------- |
|
158 |
// |
|
159 |
CHsLaunch::~CHsLaunch() |
|
160 |
{ |
|
161 |
Cancel(); |
|
162 |
||
163 |
delete iRepository; |
|
164 |
iRepository = NULL; |
|
165 |
||
166 |
delete iProcessMonitor; |
|
167 |
iProcessMonitor = NULL; |
|
168 |
||
169 |
delete iShutdownMonitor; |
|
170 |
iShutdownMonitor = NULL; |
|
171 |
} |
|
172 |
||
173 |
// ----------------------------------------------------------------------------- |
|
174 |
// CHsLaunch::Activate() |
|
175 |
// Set active object to be ran |
|
176 |
// ----------------------------------------------------------------------------- |
|
177 |
// |
|
178 |
void CHsLaunch::Activate() |
|
179 |
{ |
|
180 |
SetActive(); |
|
181 |
TRequestStatus* tmp = &iStatus; |
|
182 |
User::RequestComplete( tmp, KErrNone ); |
|
183 |
} |
|
184 |
||
185 |
// ----------------------------------------------------------------------------- |
|
186 |
// CHsLaunch::ApplicationReturnValue() |
|
187 |
// Get application return value |
|
188 |
// ----------------------------------------------------------------------------- |
|
189 |
// |
|
190 |
TInt CHsLaunch::ApplicationReturnValue() |
|
191 |
{ |
|
192 |
return iApplicationReturnValue; |
|
193 |
} |
|
194 |
||
195 |
// ----------------------------------------------------------------------------- |
|
196 |
// CHsLaunch::RunL |
|
197 |
// ----------------------------------------------------------------------------- |
|
198 |
// |
|
199 |
void CHsLaunch::RunL() |
|
200 |
{ |
|
201 |
#if defined( __WINS__ ) |
|
202 |
StartHomeScreen(); |
|
203 |
#else |
|
204 |
if (IsLanguageSelectedL()) |
|
205 |
{ |
|
206 |
StartHomeScreen(); |
|
207 |
} |
|
208 |
else |
|
209 |
{ |
|
210 |
StartListeningLanguageSelectionL(); |
|
211 |
} |
|
212 |
#endif //__WINS__ |
|
213 |
} |
|
214 |
||
215 |
// ----------------------------------------------------------------------------- |
|
216 |
// CHsLaunch::DoCancel() |
|
217 |
// From CActive. |
|
218 |
// ----------------------------------------------------------------------------- |
|
219 |
// |
|
220 |
void CHsLaunch::DoCancel() |
|
221 |
{ |
|
222 |
if( iProcessMonitor ) |
|
223 |
{ |
|
224 |
iProcessMonitor->Cancel(); |
|
225 |
} |
|
226 |
||
227 |
if( iShutdownMonitor ) |
|
228 |
{ |
|
229 |
iShutdownMonitor->Cancel(); |
|
230 |
} |
|
231 |
} |
|
232 |
||
233 |
// ----------------------------------------------------------------------------- |
|
234 |
// CHsLaunch::RunError() |
|
235 |
// From CActive. |
|
236 |
// ----------------------------------------------------------------------------- |
|
237 |
// |
|
90 | 238 |
TInt CHsLaunch::RunError( TInt /*aError*/ ) |
63 | 239 |
{ |
240 |
/* Shutdown. This application |
|
241 |
* will be restarted by startup sw. */ |
|
242 |
ShutdownApp( KErrGeneral ); |
|
243 |
return KErrNone; |
|
244 |
} |
|
245 |
||
246 |
// ----------------------------------------------------------------------------- |
|
247 |
// CHsLaunch::HandleNotifyInt() |
|
248 |
// From MCenRepNotifyHandlerCallback |
|
249 |
// ----------------------------------------------------------------------------- |
|
250 |
// |
|
251 |
void CHsLaunch::HandleNotifyInt(TUint32 aId, TInt aNewValue) |
|
252 |
{ |
|
253 |
if (aId == 0x00000007 && aNewValue) |
|
254 |
{ |
|
255 |
StopListeningLanguageSelection(); |
|
256 |
StartHomeScreen(); |
|
257 |
} |
|
258 |
} |
|
259 |
||
260 |
// ----------------------------------------------------------------------------- |
|
261 |
// CHsLaunch::ProcessEndedL() |
|
262 |
// From MHsProcessMonitorObserver |
|
263 |
// ----------------------------------------------------------------------------- |
|
264 |
// |
|
265 |
void CHsLaunch::ProcessEnded( const TExitType& aExitType, |
|
266 |
const TInt aExitReason, |
|
267 |
const TExitCategoryName& /*aExitCategory*/ ) |
|
268 |
{ |
|
269 |
TInt crashCount = 0; |
|
270 |
TInt error = RProperty::Get( KPSCategoryUid, |
|
271 |
KPSCrashCountKey, |
|
272 |
crashCount ); |
|
273 |
||
274 |
// increment crash count in cenrep if the process has panic'd or killed with |
|
275 |
// an error code |
|
276 |
if( aExitType == EExitPanic || |
|
277 |
( aExitType == EExitKill && aExitReason != KErrNone ) ) |
|
278 |
{ |
|
279 |
if( error == KErrNone ) |
|
280 |
{ |
|
281 |
crashCount++; |
|
282 |
error = RProperty::Set( KPSCategoryUid, |
|
283 |
KPSCrashCountKey, |
|
284 |
crashCount ); |
|
285 |
} |
|
286 |
||
287 |
if( error == KErrNone ) |
|
288 |
{ |
|
289 |
User::After( KSleepOnRetry ); |
|
290 |
Activate(); |
|
291 |
} |
|
292 |
else |
|
293 |
{ |
|
294 |
ShutdownApp( error ); |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
// ----------------------------------------------------------------------------- |
|
300 |
// CHsLaunch::ProcessMonitoringErrorL() |
|
301 |
// From MHsProcessMonitorObserver |
|
302 |
// ----------------------------------------------------------------------------- |
|
303 |
// |
|
304 |
void CHsLaunch::ProcessMonitoringError( TInt aError ) |
|
305 |
{ |
|
306 |
/* Error in this method is critical and it might cause |
|
307 |
* endless active scheduler loop if no active objects are |
|
308 |
* not triggered. Therefore shutdown. This application |
|
309 |
* will be restarted by startup sw. */ |
|
310 |
ShutdownApp( aError ); |
|
311 |
} |
|
312 |
||
313 |
// ----------------------------------------------------------------------------- |
|
314 |
// CHsLaunch::SystemShutdownEvent() |
|
315 |
// From MHsShutdownMonitorObserver |
|
316 |
// ----------------------------------------------------------------------------- |
|
317 |
// |
|
318 |
void CHsLaunch::SystemShutdownEvent() |
|
319 |
{ |
|
320 |
// Do not shut down app. Startup app would try to restart this app. |
|
321 |
// Just deactivate all active objects and wait for power off. |
|
322 |
if( IsActive() ) |
|
323 |
{ |
|
324 |
Cancel(); |
|
325 |
} |
|
326 |
else |
|
327 |
{ |
|
328 |
DoCancel(); |
|
329 |
} |
|
330 |
} |
|
331 |
||
332 |
// ----------------------------------------------------------------------------- |
|
333 |
// CHsLaunch::InitProcessMonitorL() |
|
334 |
// Initialize process monitor |
|
335 |
// ----------------------------------------------------------------------------- |
|
336 |
// |
|
337 |
void CHsLaunch::InitProcessMonitorL( const TInt aProcessId ) |
|
338 |
{ |
|
339 |
if( iProcessMonitor ) |
|
340 |
{ |
|
341 |
delete iProcessMonitor; |
|
342 |
iProcessMonitor = NULL; |
|
343 |
} |
|
344 |
iProcessMonitor = CHsProcessMonitor::NewL( aProcessId, *this ); |
|
345 |
User::LeaveIfError( iProcessMonitor->StartMonitor() ); |
|
346 |
} |
|
347 |
||
348 |
// ----------------------------------------------------------------------------- |
|
349 |
// CHsLaunch::ShutdownApp() |
|
350 |
// Shut down application |
|
351 |
// ----------------------------------------------------------------------------- |
|
352 |
// |
|
353 |
void CHsLaunch::ShutdownApp( const TInt aApplicationReturnValue ) |
|
354 |
{ |
|
355 |
if( IsActive() ) |
|
356 |
{ |
|
357 |
Cancel(); |
|
358 |
} |
|
359 |
else |
|
360 |
{ |
|
361 |
DoCancel(); |
|
362 |
} |
|
363 |
||
364 |
iApplicationReturnValue = aApplicationReturnValue; |
|
365 |
#ifndef HOMESCREEN_TEST |
|
366 |
CActiveScheduler::Stop(); |
|
367 |
#endif //HOMESCREEN_TEST |
|
368 |
} |
|
369 |
||
370 |
// ----------------------------------------------------------------------------- |
|
371 |
// CHsLaunch::StartHomeScreen() |
|
372 |
// Starts the homescreen application. |
|
373 |
// ----------------------------------------------------------------------------- |
|
374 |
// |
|
375 |
void CHsLaunch::StartHomeScreen() |
|
376 |
{ |
|
377 |
// Create app or connect to existing. |
|
378 |
TInt processExisted = EFalse; |
|
379 |
||
380 |
RProcess process; |
|
381 |
TInt processError = process.Create( KHsExeName, KNullDesC ); |
|
382 |
if( processError == KErrAlreadyExists ) |
|
383 |
{ |
|
384 |
processError = process.Open( KHsProcessName, EOwnerProcess ); |
|
385 |
processExisted = ETrue; |
|
386 |
} |
|
387 |
TInt monitorError = KErrNone; |
|
388 |
if( processError == KErrNone ) |
|
389 |
{ |
|
390 |
TRAP( monitorError, InitProcessMonitorL( process.Id() ) ); |
|
391 |
} |
|
392 |
||
393 |
if( processError == KErrNone && |
|
394 |
!processExisted ) |
|
395 |
{ |
|
396 |
// Make sure process is started even if monitor startup |
|
397 |
// fails. This will assure that process is not left in |
|
398 |
// suspended state. Resume can not be called for |
|
399 |
// already running process (will cause KERN-EXEC 46). |
|
400 |
process.Resume(); |
|
401 |
} |
|
402 |
||
403 |
process.Close(); |
|
404 |
||
405 |
if( processError != KErrNone || |
|
406 |
monitorError != KErrNone ) |
|
407 |
{ |
|
408 |
/* Error in this method is critical and it might cause |
|
409 |
* endless active scheduler loop if no active objects are |
|
410 |
* not triggered. Therefore shutdown. This application |
|
411 |
* will be restarted by startup sw. */ |
|
412 |
ShutdownApp( KErrGeneral ); |
|
413 |
} |
|
414 |
} |
|
415 |
||
416 |
// ----------------------------------------------------------------------------- |
|
417 |
// CHsLaunch::IsLanguageSelected() |
|
418 |
// Checks if the language is selected. |
|
419 |
// ----------------------------------------------------------------------------- |
|
420 |
// |
|
421 |
TBool CHsLaunch::IsLanguageSelectedL() |
|
422 |
{ |
|
94
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
423 |
TInt value = 1; // yes? |
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
424 |
// User::LeaveIfError(iRepository->Get(0x00000007, value)); |
63 | 425 |
return value; |
426 |
} |
|
427 |
||
428 |
// ----------------------------------------------------------------------------- |
|
429 |
// CHsLaunch::StartListeningLanguageSelection() |
|
430 |
// Starts to listen repository notifications. |
|
431 |
// ----------------------------------------------------------------------------- |
|
432 |
// |
|
433 |
void CHsLaunch::StartListeningLanguageSelectionL() |
|
434 |
{ |
|
94
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
435 |
if (iRepository) |
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
436 |
{ |
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
437 |
iCenRepNotifyHandler = CCenRepNotifyHandler::NewL( |
63 | 438 |
*this, *iRepository, CCenRepNotifyHandler::EIntKey, 0x00000007); |
94
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
439 |
iCenRepNotifyHandler->StartListeningL(); |
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
440 |
} |
63 | 441 |
} |
442 |
||
443 |
// ----------------------------------------------------------------------------- |
|
444 |
// CHsLaunch::StopListeningLanguageSelection() |
|
445 |
// Stops to listen repository notifications. |
|
446 |
// ----------------------------------------------------------------------------- |
|
447 |
// |
|
448 |
void CHsLaunch::StopListeningLanguageSelection() |
|
449 |
{ |
|
94
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
450 |
if (iCenRepNotifyHandler) |
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
451 |
{ |
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
452 |
iCenRepNotifyHandler->StopListening(); |
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
453 |
delete iCenRepNotifyHandler; |
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
454 |
iCenRepNotifyHandler = NULL; |
6364b99b9e27
Remove attempts to access unknown cenrep repository 0x2002b3aa, to workaround Bug 3711
Shabe Razvi <shaber@symbian.org>
parents:
90
diff
changeset
|
455 |
} |
63 | 456 |
} |
457 |
||
458 |
// End of File |