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