|
1 /* |
|
2 * Copyright (c) 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 "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: Implementation of CSsmStartupPolicy class. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <centralrepository.h> |
|
19 #include <e32property.h> |
|
20 #include <e32uid.h> |
|
21 #include <featmgr.h> |
|
22 #include <ssm/ssmdomaindefs.h> |
|
23 #include <ssm/ssmcmd.hrh> |
|
24 #include <ssm/ssmcommandlistresourcereader.h> |
|
25 #include <ssm/ssmstate.h> |
|
26 #include <ssm/ssmstateawaresession.h> |
|
27 #include <ssm/ssmstatetransition.h> |
|
28 #include <ssm/startupdomainpskeys.h> |
|
29 |
|
30 #include "ssmsubstateext.hrh" |
|
31 #include "ssmmapperutility.h" |
|
32 #include "ssmmapperutilitystatic.h" |
|
33 #include "ssmstartuppolicy.h" |
|
34 #include "ssmpolicypluginsprivatecrkeys.h" |
|
35 #include "trace.h" |
|
36 |
|
37 /** |
|
38 * Start-up state policy resource file path format : |
|
39 * "\private\<SID of SSM>\startup\<Value of KSystemStartupModeKey>\" |
|
40 */ |
|
41 _LIT( KCommandListPath, "Z:\\private\\2000D75B\\startup\\%d\\" ); |
|
42 |
|
43 // ======== LOCAL FUNCTIONS ======== |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // GetStartupMode |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 static TInt GetStartupMode() |
|
50 { |
|
51 FUNC_LOG; |
|
52 |
|
53 TInt startupMode( EStartupModeNormal ); |
|
54 TInt errorCode = RProperty::Get( |
|
55 SsmMapperUtility::PsUid( KPSUidStartup ), KPSGlobalStartupMode, startupMode ); |
|
56 ERROR( errorCode, "Failed to read startup mode from P&S" ); |
|
57 INFO_1( "Startup mode is %d", startupMode ); |
|
58 return startupMode; |
|
59 } |
|
60 |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // DecideStateByStartupMode |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 static TSsmStartupSubStateExt DecideStateByStartupMode() |
|
67 { |
|
68 FUNC_LOG; |
|
69 |
|
70 TInt startupMode( GetStartupMode() ); |
|
71 TSsmStartupSubStateExt nextState( ESsmStateSecurityCheck ); |
|
72 switch ( startupMode ) |
|
73 { |
|
74 case EStartupModeTest: |
|
75 nextState = ESsmStateTest; |
|
76 break; |
|
77 case EStartupModeAlarm: |
|
78 nextState = ESsmStateAlarm; |
|
79 break; |
|
80 case EStartupModeCharging: |
|
81 nextState = ESsmStateCharging; |
|
82 break; |
|
83 default: |
|
84 break; |
|
85 } |
|
86 |
|
87 return nextState; |
|
88 } |
|
89 |
|
90 |
|
91 // ======== MEMBER FUNCTIONS ======== |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CSsmStartupPolicy::NewL |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 EXPORT_C MSsmStatePolicy* CSsmStartupPolicy::NewL() |
|
98 { |
|
99 CSsmStartupPolicy* self = new( ELeave ) CSsmStartupPolicy; |
|
100 CleanupStack::PushL( self ); |
|
101 self->ConstructL(); |
|
102 CleanupStack::Pop( self ); |
|
103 return self; |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CSsmStartupPolicy::~CSsmStartupPolicy |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 CSsmStartupPolicy::~CSsmStartupPolicy() |
|
112 { |
|
113 FUNC_LOG; |
|
114 } |
|
115 |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CSsmStartupPolicy::GetNextState |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 // TomP - We've simplified this: we now only have 3 sub-states: PreUIServices StartingUIServices and StartingCriticalApps |
|
122 // After that we'll drop into the Normal state which with it's 1 sub-state: NonCritcalApps |
|
123 TBool CSsmStartupPolicy::GetNextState( |
|
124 TSsmState aCurrentTransition, |
|
125 TInt /*aReason*/, |
|
126 TInt aError, |
|
127 TInt aSeverity, |
|
128 TSsmState& aNextState ) |
|
129 { |
|
130 FUNC_LOG; |
|
131 INFO_2( "Current state %04x.%04x", |
|
132 aCurrentTransition.MainState(), aCurrentTransition.SubState() ); |
|
133 ERROR_1( aError, "State transition resulted in an error, severity %d", aSeverity ); |
|
134 ASSERT_TRACE( aCurrentTransition.MainState() == ESsmStartup ); |
|
135 |
|
136 TBool moreToCome = EFalse; |
|
137 if ( aError == KErrNone || aSeverity < ECmdHighSeverity ) |
|
138 { |
|
139 switch( aCurrentTransition.SubState() ) |
|
140 { |
|
141 case KSsmAnySubState: |
|
142 case ESsmStatePreUiServices: |
|
143 aNextState = TSsmState( ESsmStartup, ESsmStateStartingUiServices ); |
|
144 moreToCome = ETrue; |
|
145 break; |
|
146 case ESsmStateStartingUiServices: |
|
147 aNextState = TSsmState( ESsmStartup, ESsmStateStartingCriticalApps ); |
|
148 moreToCome = ETrue; |
|
149 break; |
|
150 case ESsmStateStartingCriticalApps: |
|
151 //TomP aNextState = TSsmState( ESsmStartup, ESsmStateSelfTestOK ); |
|
152 moreToCome = EFalse; |
|
153 break; |
|
154 /*TomP |
|
155 case ESsmStateSelfTestOK: |
|
156 aNextState = TSsmState( ESsmStartup, DecideStateByStartupMode() ); |
|
157 moreToCome = ETrue; |
|
158 break; |
|
159 case ESsmStateChargingToNormal: |
|
160 case ESsmStateAlarmToNormal: |
|
161 aNextState = TSsmState( ESsmStartup, ESsmStateSecurityCheck ); |
|
162 moreToCome = ETrue; |
|
163 break; |
|
164 case ESsmStateSecurityCheck: |
|
165 aNextState = TSsmState( ESsmStartup, SelectStateAfterSecurityCheck() ); |
|
166 moreToCome = ETrue; |
|
167 break; |
|
168 case ESsmStateChargingToAlarm: |
|
169 aNextState = TSsmState( ESsmStartup, ESsmStateAlarm ); |
|
170 moreToCome = ETrue; |
|
171 break; |
|
172 case ESsmStateAlarmToCharging: |
|
173 aNextState = TSsmState( ESsmStartup, ESsmStateCharging ); |
|
174 moreToCome = ETrue; |
|
175 break; |
|
176 case ESsmStateNonCritical: |
|
177 ClearResetCounter(); // start-up is successful |
|
178 aNextState = TSsmState( ESsmNormal, KSsmAnySubState ); |
|
179 moreToCome = ETrue; |
|
180 break; |
|
181 case ESsmStateAlarm: |
|
182 case ESsmStateCharging: |
|
183 case ESsmStateTest: |
|
184 moreToCome = EFalse; |
|
185 break; |
|
186 case ESsmStateEmergencyCallsOnly: |
|
187 ClearResetCounter(); // start-up is successful |
|
188 moreToCome = EFalse; |
|
189 break; |
|
190 */ |
|
191 default: |
|
192 ASSERT_ALWAYS_TRACE; |
|
193 moreToCome = EFalse; |
|
194 break; |
|
195 } |
|
196 } |
|
197 else |
|
198 { |
|
199 if ( ResetLimitReached() ) // Updates the reset count |
|
200 { |
|
201 aNextState = TSsmState( ESsmFail, KSsmAnySubState ); |
|
202 moreToCome = ETrue; |
|
203 } |
|
204 else |
|
205 { |
|
206 aNextState = TSsmState( ESsmShutdown, ESsmErrorShutdown ); |
|
207 moreToCome = ETrue; |
|
208 } |
|
209 } |
|
210 |
|
211 return moreToCome; |
|
212 } |
|
213 |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // CSsmStartupPolicy::GetCommandListPathL |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 void CSsmStartupPolicy::GetCommandListPathL( TDes& aCmdListPath ) |
|
220 { |
|
221 FUNC_LOG; |
|
222 |
|
223 aCmdListPath.Format( KCommandListPath, iHardwareReason ); |
|
224 iUtil->GetCommandListPath( aCmdListPath ); |
|
225 } |
|
226 |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // CSsmStartupPolicy::IsAllowedTargetState |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 TBool CSsmStartupPolicy::IsAllowedTargetState( |
|
233 const TSsmStateTransition& aRequest ) const |
|
234 { |
|
235 FUNC_LOG; |
|
236 |
|
237 TSsmState currentState; |
|
238 TInt errorCode = GetCurrentState( currentState ); |
|
239 ERROR( errorCode, "Failed to get current state" ); |
|
240 |
|
241 if ( errorCode == KErrNone ) |
|
242 { |
|
243 TUint16 reqMainState( aRequest.State().MainState() ); |
|
244 TUint16 reqSubState( aRequest.State().SubState() ); |
|
245 INFO_2( "Requested target state = %04x.%04x", reqMainState, reqSubState ); |
|
246 TUint16 curMainState( currentState.MainState() ); |
|
247 TUint16 curSubState( currentState.SubState() ); |
|
248 INFO_2( "Current state = %04x.%04x", curMainState, curSubState ); |
|
249 |
|
250 // TomP - We'll allow any state transition as long as there was no error |
|
251 return ETrue; |
|
252 if ( reqMainState == ESsmStartup ) |
|
253 { |
|
254 if ( ( curSubState == ESsmStateCharging && |
|
255 ( reqSubState == ESsmStateChargingToAlarm || |
|
256 reqSubState == ESsmStateChargingToNormal ) ) || |
|
257 ( curSubState == ESsmStateAlarm && |
|
258 ( reqSubState == ESsmStateAlarmToCharging || |
|
259 reqSubState == ESsmStateAlarmToNormal ) ) ) |
|
260 { |
|
261 return ETrue; |
|
262 } |
|
263 } |
|
264 else if ( reqMainState == ESsmNormal ) |
|
265 { |
|
266 if ( ( curMainState == ESsmStartup && |
|
267 curSubState == ESsmStateNonCritical ) ) |
|
268 { |
|
269 return ETrue; |
|
270 } |
|
271 } |
|
272 else if ( reqMainState == ESsmFail || |
|
273 reqMainState == ESsmShutdown ) |
|
274 { |
|
275 return ETrue; |
|
276 } |
|
277 } |
|
278 |
|
279 return EFalse; |
|
280 } |
|
281 |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // CSsmStartupPolicy::TargetSubState |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 TUint16 CSsmStartupPolicy::TargetSubState( const TUint16 aRequestedSubState ) |
|
288 { |
|
289 FUNC_LOG; |
|
290 INFO_1( "Requested sub state %04x", aRequestedSubState ); |
|
291 |
|
292 return ( aRequestedSubState == KSsmAnySubState ) ? |
|
293 ESsmStatePreUiServices : aRequestedSubState; |
|
294 } |
|
295 |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // CSsmStartupPolicy::CSsmStartupPolicy |
|
299 // --------------------------------------------------------------------------- |
|
300 // |
|
301 CSsmStartupPolicy::CSsmStartupPolicy() |
|
302 { |
|
303 FUNC_LOG; |
|
304 } |
|
305 |
|
306 |
|
307 // --------------------------------------------------------------------------- |
|
308 // CSsmStartupPolicy::ConstructL |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 void CSsmStartupPolicy::ConstructL() |
|
312 { |
|
313 FUNC_LOG; |
|
314 |
|
315 // Read the hardware reason |
|
316 User::LeaveIfError( RProperty::Get( |
|
317 KUidSystemCategory, KSystemStartupModeKey, iHardwareReason ) ); |
|
318 |
|
319 BaseConstructL(); |
|
320 } |
|
321 |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CSsmStartupPolicy::IsSimlessOfflineSupported |
|
325 // --------------------------------------------------------------------------- |
|
326 // |
|
327 TBool CSsmStartupPolicy::IsSimlessOfflineSupported() |
|
328 { |
|
329 FUNC_LOG; |
|
330 /* |
|
331 TBool ret( EFalse ); |
|
332 |
|
333 ret = ( iUtil->FeatureStatus( TUid::Uid( KFeatureIdOfflineMode ) ) || |
|
334 iUtil->FeatureStatus( TUid::Uid( KFeatureIdFlightMode ) ) ) && |
|
335 iUtil->FeatureStatus( TUid::Uid( KFeatureIdFfSimlessOfflineSupport ) ); |
|
336 |
|
337 INFO_1( "Simless offline supported = %d", ret ); |
|
338 */ |
|
339 //TomP - SIMless Offline is always supported |
|
340 return ETrue; |
|
341 } |
|
342 |
|
343 |
|
344 // --------------------------------------------------------------------------- |
|
345 // CSsmStartupPolicy::SelectStateAfterSecurityCheck |
|
346 // --------------------------------------------------------------------------- |
|
347 // |
|
348 TUint16 CSsmStartupPolicy::SelectStateAfterSecurityCheck() |
|
349 { |
|
350 FUNC_LOG; |
|
351 /* |
|
352 TInt value( ESimStatusUninitialized ); |
|
353 TInt errorCode = RProperty::Get( iUtil->PsUid( KPSUidStartup ), KPSSimStatus, value ); |
|
354 ERROR( errorCode, "Failed to read KPSUidStartup::KPSSimStatus P&S key" ); |
|
355 INFO_1( "Current SIM status = %d", value ); |
|
356 TUint16 retVal( ESsmStateEmergencyCallsOnly ); |
|
357 if ( errorCode == KErrNone ) |
|
358 { |
|
359 if ( value == ESimUsable || value == ESimNotSupported ) |
|
360 { |
|
361 retVal = ESsmStateNonCritical; |
|
362 } |
|
363 else if ( value == ESimNotPresent && IsSimlessOfflineSupported() ) |
|
364 { |
|
365 retVal = ESsmStateNonCritical; |
|
366 } |
|
367 } |
|
368 |
|
369 INFO_1( "State selected after security check = %04x", retVal ); |
|
370 */ |
|
371 // TomP - Always jump straight into Non Critical State next |
|
372 return ESsmStateNonCritical; |
|
373 } |
|
374 |
|
375 |
|
376 // --------------------------------------------------------------------------- |
|
377 // CSsmStartupPolicy::ClearResetCounter |
|
378 // --------------------------------------------------------------------------- |
|
379 // |
|
380 void CSsmStartupPolicy::ClearResetCounter() |
|
381 { |
|
382 FUNC_LOG; |
|
383 |
|
384 TRAPD_ERR( errorCode, ClearResetCounterL() ); |
|
385 ERROR( errorCode, "Failed to clear reset counter" ); |
|
386 } |
|
387 |
|
388 |
|
389 // --------------------------------------------------------------------------- |
|
390 // ClearResetCounterL |
|
391 // --------------------------------------------------------------------------- |
|
392 // |
|
393 void CSsmStartupPolicy::ClearResetCounterL() |
|
394 { |
|
395 FUNC_LOG; |
|
396 |
|
397 CRepository* repository = CRepository::NewLC( iUtil->CrUid( KCRUidSsmStartupPolicy ) ); |
|
398 User::LeaveIfError( repository->Set( KSsmStartupErrorResetCounter, 0 ) ); |
|
399 CleanupStack::PopAndDestroy( repository ); |
|
400 } |