|
1 /* |
|
2 * Copyright (c) 2002 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 * |
|
16 */ |
|
17 |
|
18 #include <aknappui.h> |
|
19 #include <activitymanager.h> |
|
20 #include <bldvariant.hrh> |
|
21 #include <featmgr.h> |
|
22 #include <AknNotifierController.h> |
|
23 #include <featmgr.h> |
|
24 #include <e32property.h> |
|
25 #include <PSVariables.h> |
|
26 #include <startupdomainpskeys.h> |
|
27 #include <coreapplicationuisdomainpskeys.h> |
|
28 #include <ctsydomainpskeys.h> |
|
29 |
|
30 #include <SCPClient.h> |
|
31 |
|
32 #include "AutoLockModelPS.h" |
|
33 #include "AutolockAppUiPS.h" |
|
34 #include "AutoLockLockObserverPS.h" |
|
35 #include "AutoLockCenRepI.h" |
|
36 |
|
37 |
|
38 const TInt AutoLockOff(60000); |
|
39 |
|
40 |
|
41 |
|
42 // ================= MEMBER FUNCTIONS ======================= |
|
43 // |
|
44 // ---------------------------------------------------------- |
|
45 // CAutoLockModel::NewL() |
|
46 // ---------------------------------------------------------- |
|
47 // |
|
48 |
|
49 CAutoLockModel* CAutoLockModel::NewL(CAutolockAppUi* aAppUi, TBool aLocked) |
|
50 { |
|
51 CAutoLockModel* self = new (ELeave) CAutoLockModel(aAppUi); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL( aLocked ); |
|
54 CleanupStack::Pop(); //self |
|
55 return self; |
|
56 } |
|
57 // |
|
58 // ---------------------------------------------------------- |
|
59 // CAutoLockModel::CAutoLockModel() |
|
60 // C++ default constructor |
|
61 // ---------------------------------------------------------- |
|
62 // |
|
63 CAutoLockModel::CAutoLockModel(CAutolockAppUi* aAppUi) : |
|
64 iAppUi( aAppUi ), iMonitoring(EFalse) |
|
65 { |
|
66 } |
|
67 |
|
68 // |
|
69 // ---------------------------------------------------------- |
|
70 // CAutoLockModel::ConstructL() |
|
71 // Symbian OS default constructor |
|
72 // ---------------------------------------------------------- |
|
73 // |
|
74 void CAutoLockModel::ConstructL( TBool aLocked ) |
|
75 { |
|
76 FeatureManager::InitializeLibL(); |
|
77 #if defined(_DEBUG) |
|
78 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::ConstructL() BEGIN")); |
|
79 #endif |
|
80 iCenRepI = CAutolockCenRepI::NewL(iAppUi); |
|
81 // lock status observer |
|
82 iLockObserver = CLockObserver::NewL(iAppUi); |
|
83 // Activitymanager |
|
84 iActivityManager = CUserActivityManager::NewL(CActive::EPriorityStandard); |
|
85 StartActivityMonitoringL(); |
|
86 // In GSM the device is always unlocked. |
|
87 // In CDMA, SecClientUi will lock the device on boot-up if needed. |
|
88 |
|
89 if ( aLocked == EAutolockStatusUninitialized ) |
|
90 { |
|
91 RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockStatusUninitialized); |
|
92 } |
|
93 else |
|
94 { |
|
95 RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff); |
|
96 } |
|
97 |
|
98 #if defined(_DEBUG) |
|
99 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::ConstructL() END")); |
|
100 #endif |
|
101 } |
|
102 // |
|
103 // ---------------------------------------------------------- |
|
104 // CAutoLockModel::StartActivityMonitoringL() |
|
105 // Start monitoring user activity |
|
106 // ---------------------------------------------------------- |
|
107 // |
|
108 void CAutoLockModel::StartActivityMonitoringL() |
|
109 { |
|
110 SetActivityManagerL(); |
|
111 } |
|
112 |
|
113 // |
|
114 // ---------------------------------------------------------- |
|
115 // CAutoLockModel::StopActivityMonitoring() |
|
116 // Stop monitoring user activity |
|
117 // ---------------------------------------------------------- |
|
118 // |
|
119 void CAutoLockModel::StopActivityMonitoring() |
|
120 { |
|
121 CancelActivityManager(); |
|
122 } |
|
123 |
|
124 // |
|
125 // ---------------------------------------------------------- |
|
126 // CAutoLockModel::SetActivityManagerL() |
|
127 // Initializes activymanager |
|
128 // ---------------------------------------------------------- |
|
129 // |
|
130 void CAutoLockModel::SetActivityManagerL() |
|
131 { |
|
132 if (AutoLockTimeout() ) |
|
133 { |
|
134 iActivityManager->Start(AutoLockTimeout(), TCallBack(HandleInactiveEventL,this), |
|
135 TCallBack(HandleActiveEventL,this)); |
|
136 } |
|
137 else |
|
138 { |
|
139 iActivityManager->Start(AutoLockOff, TCallBack(HandleInactiveEventL,this), |
|
140 TCallBack(HandleActiveEventL,this)); |
|
141 } |
|
142 |
|
143 } |
|
144 // |
|
145 // ---------------------------------------------------------- |
|
146 // CAutoLockModel::CancelActivityManager() |
|
147 // UnInitializes activymanager |
|
148 // ---------------------------------------------------------- |
|
149 // |
|
150 void CAutoLockModel::CancelActivityManager() |
|
151 { |
|
152 if ( iActivityManager ) |
|
153 { |
|
154 iActivityManager->Cancel(); |
|
155 } |
|
156 delete iActivityManager; |
|
157 iActivityManager = NULL; |
|
158 } |
|
159 // |
|
160 // ---------------------------------------------------------- |
|
161 // CAutoLockModel::~CAutoLockModel() |
|
162 // Destructor |
|
163 // ---------------------------------------------------------- |
|
164 // |
|
165 CAutoLockModel::~CAutoLockModel() |
|
166 { |
|
167 delete iCenRepI; |
|
168 delete iLockObserver; |
|
169 StopActivityMonitoring(); |
|
170 FeatureManager::UnInitializeLib(); |
|
171 // close custom phone |
|
172 } |
|
173 // |
|
174 // ---------------------------------------------------------- |
|
175 // CAutoLockModel::AutoLockTimeout() |
|
176 // Returns current autolock period |
|
177 // ---------------------------------------------------------- |
|
178 // |
|
179 TInt CAutoLockModel::AutoLockTimeout() |
|
180 { |
|
181 return iCenRepI->Timeout(); |
|
182 } |
|
183 // |
|
184 // ---------------------------------------------------------- |
|
185 // CAutoLockModel::ResetInactivityTimeoutL() |
|
186 // Gets autolock period and starts monitoring user activity |
|
187 // ---------------------------------------------------------- |
|
188 // |
|
189 void CAutoLockModel::ResetInactivityTimeout() |
|
190 { |
|
191 if (AutoLockTimeout() ) |
|
192 { |
|
193 iActivityManager->SetInactivityTimeout(AutoLockTimeout()); |
|
194 } |
|
195 else |
|
196 { |
|
197 iActivityManager->SetInactivityTimeout(AutoLockOff); |
|
198 } |
|
199 } |
|
200 // |
|
201 // ---------------------------------------------------------- |
|
202 // CAutoLockModel::HandleActiveEventL() |
|
203 // Handles Active event. Called by ActivityManager |
|
204 // ---------------------------------------------------------- |
|
205 // |
|
206 TInt CAutoLockModel::HandleActiveEventL(TAny* /*aPtr*/) |
|
207 { |
|
208 return KErrNone; |
|
209 } |
|
210 |
|
211 // |
|
212 // ---------------------------------------------------------- |
|
213 // CAutoLockModel::HandleInactiveEventL() |
|
214 // Handles InActive event. Called by ActivityManager |
|
215 // ---------------------------------------------------------- |
|
216 // |
|
217 TInt CAutoLockModel::HandleInactiveEventL(TAny* aPtr) |
|
218 { |
|
219 if ( STATIC_CAST(CAutoLockModel*, aPtr)->AutoLockTimeout() ) |
|
220 { |
|
221 TInt value(EStartupUiPhaseUninitialized); |
|
222 RProperty::Get(KPSUidStartup, KPSStartupUiPhase, value); |
|
223 //Don't lock unless boot is over. |
|
224 if(value == EStartupUiPhaseAllDone) |
|
225 { |
|
226 #if defined(_DEBUG) |
|
227 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::HandleInactiveEventL() Boot over")); |
|
228 #endif |
|
229 #ifdef RD_REMOTELOCK |
|
230 STATIC_CAST(CAutoLockModel*, aPtr)->LockSystemL(ETimerLocked); |
|
231 #else |
|
232 STATIC_CAST(CAutoLockModel*, aPtr)->LockSystemL(EAutolockOn); |
|
233 #endif //RD_REMOTELOCK |
|
234 } |
|
235 else |
|
236 { |
|
237 #if defined(_DEBUG) |
|
238 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::HandleInactiveEventL() In boot; don't lock")); |
|
239 #endif |
|
240 } |
|
241 } |
|
242 return KErrNone; |
|
243 } |
|
244 |
|
245 // |
|
246 // ---------------------------------------------------------- |
|
247 // CAutoLockModel::LockSystemL() |
|
248 // Locks system |
|
249 // ---------------------------------------------------------- |
|
250 // |
|
251 void CAutoLockModel::LockSystemL(TInt aAutolockState) |
|
252 { |
|
253 #if defined(_DEBUG) |
|
254 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::LockSystemL() BEGIN")); |
|
255 #endif |
|
256 // If already locked, do nothing. Otherwise we'll end up |
|
257 // on top of Screensaver |
|
258 // Check if iSideKey2 is zero or not (locked if nonzero) |
|
259 // Also, phone should not be locked if PUK1 code query is up. |
|
260 #ifdef FF_STARTUP_OMA_DM_SUPPORT // New booting order Start ID: MVKS-7PZDZ5 |
|
261 TInt autolock_value = 0; |
|
262 RProperty::Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, autolock_value); |
|
263 if (autolock_value == EAutolockStatusUninitialized) |
|
264 { |
|
265 return; |
|
266 } |
|
267 #endif //End ID: MVKS-7PZDZ5 |
|
268 if (iAppUi->Locked() || iAppUi->IsPinBlocked()) |
|
269 { |
|
270 return; |
|
271 } |
|
272 |
|
273 TInt lightStatus=EForcedLightsUninitialized; |
|
274 RProperty::Get(KPSUidCoreApplicationUIs,KLightsVTForcedLightsOn,lightStatus ); |
|
275 //If display is forced on. don't lock |
|
276 if(lightStatus == EForcedLightsOn ) |
|
277 { |
|
278 #if defined(_DEBUG) |
|
279 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::LockSystemL() Display is forced on. Device not locked")); |
|
280 #endif |
|
281 return; |
|
282 } |
|
283 |
|
284 //Check which state we are in to see if it's OK to lock the phone |
|
285 //In CDMA when there is no SIM (RUIM) support we should be able to lock |
|
286 //the phone after reboot. In this case ESWStateNormal is too late to lock the phone |
|
287 //and other states below are needed. |
|
288 TBool okToLock = EFalse; |
|
289 TInt sysState = 0; |
|
290 iProperty.Get(KPSUidStartup, KPSGlobalSystemState, sysState); |
|
291 //If NOT in CDMA the Autolock should come up only after the phone has booted up. |
|
292 if ( FeatureManager::FeatureSupported( KFeatureIdProtocolCdma ) || iAppUi->HiddenReset()) |
|
293 { |
|
294 if( (sysState == ESwStateNormalRfOn || |
|
295 sysState == ESwStateNormalRfOff || |
|
296 sysState == ESwStateCriticalPhaseOK) && |
|
297 (aAutolockState > EAutolockOff) ) // EMKK-7N3G7R |
|
298 { |
|
299 #if defined(_DEBUG) |
|
300 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::LockSystemL() LOCKED AFTER HIDDEN RESET")); |
|
301 #endif |
|
302 okToLock = ETrue; |
|
303 } |
|
304 } |
|
305 else //Feature Manager |
|
306 { |
|
307 if( (sysState == ESwStateNormalRfOn || |
|
308 sysState == ESwStateNormalRfOff) && |
|
309 (aAutolockState > EAutolockOff) ) // EMKK-7N3G7R |
|
310 { |
|
311 okToLock = ETrue; |
|
312 } |
|
313 } |
|
314 TInt tarmFlag; |
|
315 if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw )) |
|
316 { |
|
317 // Get the TARM admin flag value |
|
318 TInt tRet = RProperty::Get( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag ); |
|
319 |
|
320 if ( tRet != KErrNone ) |
|
321 { |
|
322 #if defined(_DEBUG) |
|
323 RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::BringAppToForegroundL():\ |
|
324 Warning: failed to get TARM Admin Flag state")); |
|
325 #endif |
|
326 } |
|
327 else |
|
328 { |
|
329 #if defined(_DEBUG) |
|
330 RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::BringAppToForegroundL(): TARM flag: %d"), |
|
331 tarmFlag ); |
|
332 #endif |
|
333 } |
|
334 } |
|
335 |
|
336 TInt callState; |
|
337 iProperty.Get(KPSUidCtsyCallInformation, KCTsyCallState, callState); |
|
338 TBool isConditionSatisfied = EFalse; |
|
339 if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw )) |
|
340 { |
|
341 if ( ( callState != EPSCTsyCallStateNone ) && (!( tarmFlag & KSCPFlagAdminLock )) ) |
|
342 isConditionSatisfied = ETrue; |
|
343 } |
|
344 else |
|
345 { |
|
346 if ( callState != EPSCTsyCallStateNone ) |
|
347 isConditionSatisfied = ETrue; |
|
348 } |
|
349 if (isConditionSatisfied) |
|
350 { |
|
351 TBool remoteLocked(EFalse); |
|
352 #ifdef RD_REMOTELOCK |
|
353 remoteLocked = (aAutolockState == ERemoteLocked); |
|
354 #endif //RD_REMOTELOCK |
|
355 if(remoteLocked) |
|
356 { |
|
357 #if defined(_DEBUG) |
|
358 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::LockSystemL() REMOTE LOCKED")); |
|
359 #endif |
|
360 okToLock = ETrue; |
|
361 |
|
362 } |
|
363 else |
|
364 okToLock = EFalse; |
|
365 } |
|
366 |
|
367 if (!iAppUi->IsForeground() && okToLock) |
|
368 { |
|
369 #if defined(_DEBUG) |
|
370 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::LockSystemL() LOCK PHONE")); |
|
371 #endif |
|
372 // close fast-swap window |
|
373 CEikonEnv::Static()->DismissTaskList(); |
|
374 // inform Avokon & Other app that system is locked |
|
375 // unless the value has already been set in secuisystemlock |
|
376 #ifdef RD_REMOTELOCK |
|
377 if(aAutolockState != EManualLocked) |
|
378 { |
|
379 #if defined(_DEBUG) |
|
380 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::LockSystemL() Timer/Remote locked: %d"), aAutolockState); |
|
381 #endif |
|
382 SetLockedL(aAutolockState); |
|
383 } |
|
384 else if((aAutolockState == EManualLocked) && !iAppUi->Locked() && iAppUi->HiddenReset()) |
|
385 { //set the PubSub key if we are to be locked after a hidden reset has occurred. |
|
386 #if defined(_DEBUG) |
|
387 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::LockSystemL() HIDDEN RESET LOCK")); |
|
388 #endif |
|
389 SetLockedL(aAutolockState); |
|
390 } |
|
391 else |
|
392 { //Normal manual lock from power key. Just set the CenRep key. |
|
393 iCenRepI->SetLockedL(okToLock); |
|
394 } |
|
395 #else //! RD_REMOTELOCK |
|
396 SetLockedL(aAutolockState); |
|
397 #endif//RD_REMOTELOCK |
|
398 // lock keys |
|
399 iAppUi->LockKeysL(); |
|
400 // app to foreground |
|
401 iAppUi->BringAppToForegroundL(); |
|
402 // Reset inactivity time so that Screensaver gets to |
|
403 // run again after its timeout. We'll ignore the new |
|
404 // inactivity timeout, if already locked |
|
405 User::ResetInactivityTime(); |
|
406 } |
|
407 #if defined(_DEBUG) |
|
408 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::LockSystemL() END")); |
|
409 #endif |
|
410 } |
|
411 |
|
412 // |
|
413 // ---------------------------------------------------------- |
|
414 // CAutoLockModel::SetLocked |
|
415 // Sets lockvalue in Publish & Subscribe and Central Repository |
|
416 // ---------------------------------------------------------- |
|
417 // |
|
418 void CAutoLockModel::SetLockedL(TInt aAutolockState) |
|
419 { |
|
420 #if defined(_DEBUG) |
|
421 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::SetLockedL() begin")); |
|
422 #endif |
|
423 TBool locked = (aAutolockState > EAutolockOff); |
|
424 if (locked) |
|
425 { |
|
426 iProperty.Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, aAutolockState); |
|
427 #if defined(_DEBUG) |
|
428 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::SetLockedL() LOCK")); |
|
429 #endif |
|
430 } |
|
431 else |
|
432 { |
|
433 iProperty.Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff); |
|
434 #if defined(_DEBUG) |
|
435 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::SetLockedL() UNLOCK")); |
|
436 #endif |
|
437 } |
|
438 |
|
439 iCenRepI->SetLockedL(locked); |
|
440 #if defined(_DEBUG) |
|
441 RDebug::Print(_L("(AUTOLOCK)CAutoLockModel::SetLockedL() end")); |
|
442 #endif |
|
443 } |
|
444 |
|
445 // END OF FILE |