securitydialogs/Autolock/src/Autolock.cpp
changeset 61 1cc4c46c2963
parent 56 25a3fbb5e4d3
equal deleted inserted replaced
56:25a3fbb5e4d3 61:1cc4c46c2963
    59 #include "../PubSub/securityuisprivatepskeys.h"
    59 #include "../PubSub/securityuisprivatepskeys.h"
    60 #include <avkondomainpskeys.h>
    60 #include <avkondomainpskeys.h>
    61 #include <hwrmdomainpskeys.h>
    61 #include <hwrmdomainpskeys.h>
    62 #include <ctsydomainpskeys.h>
    62 #include <ctsydomainpskeys.h>
    63 
    63 
       
    64 #include <startupdomainpskeys.h>
       
    65 
    64 #include <hbdevicedialog.h>
    66 #include <hbdevicedialog.h>
    65 // handled now directly but screensaver
    67 // handled now directly but screensaver
    66 // #include <power_save_display_mode.h>
    68 // #include <power_save_display_mode.h>
    67 
    69 
    68 const TInt KPhoneIndex(0);
    70 const TInt KPhoneIndex(0);
    69 const TInt KTriesToConnectServer(2);
    71 const TInt KTriesToConnectServer(2);
    70 const TInt KTimeBeforeRetryingServerConnection(50000);
    72 const TInt KTimeBeforeRetryingServerConnection(50000);
    71 #define ESecUiTypeLock                  0x00100000
    73 #define ESecUiTypeDeviceLock        0x00100000
       
    74 #define ESecUiTypeKeyguard          0x00200000
    72 _LIT( KMmTsyModuleName, "PhoneTsy");
    75 _LIT( KMmTsyModuleName, "PhoneTsy");
    73 
    76 
    74 // Constant definitions to control screensaver view types
    77 // Constant definitions to control screensaver view types
    75 static const char *KSnsrViewTypeKey = "view_type";
    78 static const char *KSnsrViewTypeKey = "view_type";
    76 enum TSnsrViewType
    79 enum TSnsrViewType
    83 static const char *KSnsrCmdUnlock = "unlock";
    86 static const char *KSnsrCmdUnlock = "unlock";
    84 static const char *KSnsrCmdSwitchLights = "switch_lights";
    87 static const char *KSnsrCmdSwitchLights = "switch_lights";
    85 static const char *KSnsrCmdSwitchLowPower = "switch_low_power";
    88 static const char *KSnsrCmdSwitchLowPower = "switch_low_power";
    86 
    89 
    87 Autolock::Autolock(QWidget *parent, Qt::WFlags f) :
    90 Autolock::Autolock(QWidget *parent, Qt::WFlags f) :
    88     QWidget(parent, f), mService(NULL)
    91     QWidget(parent, f),
       
    92     mService(NULL),
       
    93     mPowerKeyCaptureHandle(0),
       
    94     mApplicationKeyCaptureHandle(0),
       
    95     mApplicationLongKeyCaptureHandle(0),
       
    96     mEKeyDeviceFCaptureHandle(0),
       
    97     mEKeyBellCaptureHandle(0),
       
    98     mEKeyYesCaptureHandle(0),
       
    99     mEKeyNoCaptureHandle(0),
       
   100     iLockCodeQueryInDisplay(false),
       
   101     mScreensaverModeTimer(0)
       
   102     
    89     {
   103     {
    90     RDEBUG("start autolock", 0);
   104     RDEBUG("start autolock", 0);
    91 
   105 
    92     // The very first thing is to define the properties, so that others can use them.
   106     // The very first thing is to define the properties, so that others can use them.
    93     TSecurityPolicy readPolicy(ECapabilityReadDeviceData);
   107     TSecurityPolicy readPolicy(ECapabilityReadDeviceData);
   169     TInt lightsTimeout = 0;
   183     TInt lightsTimeout = 0;
   170     CRepository* repository = NULL;
   184     CRepository* repository = NULL;
   171     TInt cRresult = 0;
   185     TInt cRresult = 0;
   172     iLockCodeQueryInDisplay = EFalse;
   186     iLockCodeQueryInDisplay = EFalse;
   173     Q_UNUSED(cRresult);
   187     Q_UNUSED(cRresult);
       
   188     TInt err = 0;
   174 
   189 
   175 		iProcessingEvent = -1;
   190 		iProcessingEvent = -1;
   176     iLockStatusPrev = ELockNotActive;
   191     iLockStatusPrev = ELockNotActive;
   177     iLockStatus = ELockNotActive;
   192     iLockStatus = ELockNotActive;
   178     QT_TRAP_THROWING(repository = CRepository::NewL(KCRUidSecuritySettings));
   193     QT_TRAP_THROWING(repository = CRepository::NewL(KCRUidSecuritySettings));
   196     // this value is not used for now
   211     // this value is not used for now
   197     delete repository;
   212     delete repository;
   198 
   213 
   199     // subscribe to settings changes
   214     // subscribe to settings changes
   200     subscriberKSettingsAutolockStatus = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutolockStatus", this);
   215     subscriberKSettingsAutolockStatus = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutolockStatus", this);
   201     connect(subscriberKSettingsAutolockStatus, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutolockStatusChanged()));
   216     err = connect(subscriberKSettingsAutolockStatus, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutolockStatusChanged()));
       
   217     RDEBUG("err", err);
   202     subscriberKSettingsAutoLockTime = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutoLockTime", this);
   218     subscriberKSettingsAutoLockTime = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutoLockTime", this);
   203     connect(subscriberKSettingsAutoLockTime, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutoLockTimeChanged()));
   219     err = connect(subscriberKSettingsAutoLockTime, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutoLockTimeChanged()));
       
   220     RDEBUG("err", err);
   204     subscriberKSettingsAutomaticKeyguardTime = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutomaticKeyguardTime", this);
   221     subscriberKSettingsAutomaticKeyguardTime = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutomaticKeyguardTime", this);
   205     connect(subscriberKSettingsAutomaticKeyguardTime, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutomaticKeyguardTimeChanged()));
   222     err = connect(subscriberKSettingsAutomaticKeyguardTime, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutomaticKeyguardTimeChanged()));
       
   223     RDEBUG("err", err);
   206     subscriberKDisplayLightsTimeout = new QValueSpaceSubscriber("/KCRUidLightSettings/KDisplayLightsTimeout", this);
   224     subscriberKDisplayLightsTimeout = new QValueSpaceSubscriber("/KCRUidLightSettings/KDisplayLightsTimeout", this);
   207     connect(subscriberKDisplayLightsTimeout, SIGNAL(contentsChanged()), this, SLOT(subscriberKDisplayLightsTimeoutChanged()));
   225     err = connect(subscriberKDisplayLightsTimeout, SIGNAL(contentsChanged()), this, SLOT(subscriberKDisplayLightsTimeoutChanged()));
       
   226     RDEBUG("err", err);
   208     subscriberKProEngActiveProfile = new QValueSpaceSubscriber("/KCRUidProfileEngine/KProEngActiveProfile", this);
   227     subscriberKProEngActiveProfile = new QValueSpaceSubscriber("/KCRUidProfileEngine/KProEngActiveProfile", this);
   209     connect(subscriberKProEngActiveProfile, SIGNAL(contentsChanged()), this, SLOT(subscriberKProEngActiveProfileChanged()));
   228     err = connect(subscriberKProEngActiveProfile, SIGNAL(contentsChanged()), this, SLOT(subscriberKProEngActiveProfileChanged()));
       
   229     RDEBUG("err", err);
   210 
   230 
   211     subscriberKSecurityUIsDismissDialog = new QValueSpaceSubscriber("/KPSUidSecurityUIs/KSecurityUIsDismissDialog", this);
   231     subscriberKSecurityUIsDismissDialog = new QValueSpaceSubscriber("/KPSUidSecurityUIs/KSecurityUIsDismissDialog", this);
   212     connect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
   232     err = connect(subscriberKSecurityUIsDismissDialog, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsDismissDialogChanged()));
       
   233     RDEBUG("err", err);
   213 
   234 
   214     // subscribe to environment changes
   235     // subscribe to environment changes
   215     subscriberKHWRMGripStatus = new QValueSpaceSubscriber("/KPSUidHWRM/KHWRMGripStatus");
   236     subscriberKHWRMGripStatus = new QValueSpaceSubscriber("/KPSUidHWRM/KHWRMGripStatus", this);
   216     connect(subscriberKHWRMGripStatus, SIGNAL(contentsChanged()), this, SLOT(subscriberKHWRMGripStatusChanged()));
   237     err = connect(subscriberKHWRMGripStatus, SIGNAL(contentsChanged()), this, SLOT(subscriberKHWRMGripStatusChanged()));
   217 
   238     RDEBUG("err", err);
   218     subscriberKAknKeyguardStatus = new QValueSpaceSubscriber("/KPSUidAvkonDomain/KAknKeyguardStatus");
   239 
   219     connect(subscriberKAknKeyguardStatus, SIGNAL(contentsChanged()), this, SLOT(subscriberKAknKeyguardStatusChanged()));
   240     subscriberKAknKeyguardStatus = new QValueSpaceSubscriber("/KPSUidAvkonDomain/KAknKeyguardStatus", this);
   220 
   241     err = connect(subscriberKAknKeyguardStatus, SIGNAL(contentsChanged()), this, SLOT(subscriberKAknKeyguardStatusChanged()));
   221     subscriberKCoreAppUIsAutolockStatus = new QValueSpaceSubscriber("/KPSUidCoreApplicationUIs/KCoreAppUIsAutolockStatus");
   242     RDEBUG("err", err);
   222     connect(subscriberKCoreAppUIsAutolockStatus, SIGNAL(contentsChanged()), this, SLOT(subscriberKCoreAppUIsAutolockStatusChanged()));
   243 
   223 
   244     subscriberKCoreAppUIsAutolockStatus = new QValueSpaceSubscriber("/KPSUidCoreApplicationUIs/KCoreAppUIsAutolockStatus", this);
   224     subscriberKCTsyCallState = new QValueSpaceSubscriber("/KPSUidCtsyCallInformation/KCTsyCallState");
   245     err = connect(subscriberKCoreAppUIsAutolockStatus, SIGNAL(contentsChanged()), this, SLOT(subscriberKCoreAppUIsAutolockStatusChanged()));
   225     connect(subscriberKCTsyCallState, SIGNAL(contentsChanged()), this, SLOT(subscriberKCTsyCallStateChanged()));
   246     RDEBUG("err", err);
       
   247 
       
   248     subscriberKCTsyCallState = new QValueSpaceSubscriber("/KPSUidCtsyCallInformation/KCTsyCallState", this);
       
   249     err = connect(subscriberKCTsyCallState, SIGNAL(contentsChanged()), this, SLOT(subscriberKCTsyCallStateChanged()));
       
   250     RDEBUG("err", err);
       
   251 
       
   252     subscriberKSecurityUIsTestCode = new QValueSpaceSubscriber("/KPSUidSecurityUIs/KSecurityUIsTestCode", this);
       
   253     err = connect(subscriberKSecurityUIsTestCode, SIGNAL(contentsChanged()), this, SLOT(subscriberKSecurityUIsTestCodeChanged()));
       
   254     RDEBUG("err", err);
   226 
   255 
   227     // inactivity
   256     // inactivity
   228     connect(serviceKeyguard, SIGNAL(active()), this, SLOT(activeKeyguard()));
   257     connect(serviceKeyguard, SIGNAL(active()), this, SLOT(activeKeyguard()));
   229     connect(serviceKeyguard, SIGNAL(notActive()), this, SLOT(notActiveKeyguard()));
   258     connect(serviceKeyguard, SIGNAL(notActive()), this, SLOT(notActiveKeyguard()));
   230     connect(serviceDevicelock, SIGNAL(active()), this, SLOT(activeDevicelock()));
   259     connect(serviceDevicelock, SIGNAL(active()), this, SLOT(activeDevicelock()));
   263 
   292 
   264     // handled now directly but screensaver
   293     // handled now directly but screensaver
   265     // mScreensaverPowerSave = CPowerSaveDisplayMode::NewL();
   294     // mScreensaverPowerSave = CPowerSaveDisplayMode::NewL();
   266     // mScreensaverPowerSavePixelBuffer = HBufC16::NewL(360 * 640);
   295     // mScreensaverPowerSavePixelBuffer = HBufC16::NewL(360 * 640);
   267     // mScreensaverPowerSavePixelBuffer->Des().Fill(0);
   296     // mScreensaverPowerSavePixelBuffer->Des().Fill(0);
       
   297     RDEBUG("99", 0x99);
   268     }
   298     }
   269 
   299 
   270 Autolock::~Autolock()
   300 Autolock::~Autolock()
   271     {
   301     {
   272     RDEBUG("0", 0);
   302     RDEBUG("0", 0);
   273     delete mService;
   303     delete mService;
   274     // handled now directly but screensaver
   304     // handled now directly but screensaver
   275     // delete mScreensaverPowerSave;
   305     // delete mScreensaverPowerSave;
   276     // delete mScreensaverPowerSavePixelBuffer;
   306     // delete mScreensaverPowerSavePixelBuffer;
   277     RDEBUG("1", 1);
   307     RDEBUG("99", 0x99);
   278     }
   308     }
   279 
   309 
   280 void Autolock::adjustInactivityTimers(int aReason)
   310 void Autolock::adjustInactivityTimers(int aReason)
   281     {
   311     {
   282     RDEBUG("aReason", aReason);
   312     RDEBUG("aReason", aReason);
   322         RDEBUG("setInactivityPeriod infinite", lockTime);
   352         RDEBUG("setInactivityPeriod infinite", lockTime);
   323         serviceDevicelock->setInactivityPeriod(12 * 31 * 24 * 60 * 60); // 0x1ea6e00
   353         serviceDevicelock->setInactivityPeriod(12 * 31 * 24 * 60 * 60); // 0x1ea6e00
   324         }
   354         }
   325 
   355 
   326     delete repository;
   356     delete repository;
       
   357     RDEBUG("99", 0x99);
   327     }
   358     }
   328 void Autolock::quit()
   359 void Autolock::quit()
   329     {
   360     {
   330     RDEBUG("0", 0);
   361     RDEBUG("0", 0);
   331     qApp->quit();
   362     qApp->quit();
   335 int Autolock::TurnLights(int aMode, int aReason, int aCaller)
   366 int Autolock::TurnLights(int aMode, int aReason, int aCaller)
   336     {
   367     {
   337     RDEBUG("aMode", aMode);
   368     RDEBUG("aMode", aMode);
   338     RDEBUG("aReason", aReason);
   369     RDEBUG("aReason", aReason);
   339     RDEBUG("aCaller", aCaller);
   370     RDEBUG("aCaller", aCaller);
   340     TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, aMode);
   371     TInt err = 0;
       
   372     if(aMode!=ESecurityUIsLightsLockOffRequest)
       
   373     	{
       
   374     	RDEBUG("KLightsSSForcedLightsOn", KLightsSSForcedLightsOn);
       
   375     	err = RProperty::Set(KPSUidCoreApplicationUIs, KLightsSSForcedLightsOn, 30);
       
   376     	}
       
   377     RDEBUG("err", err);
       
   378     err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, aMode);
   341     RDEBUG("KSecurityUIsLights err", err);
   379     RDEBUG("KSecurityUIsLights err", err);
   342     return err;
   380     return err;
   343   	}
   381   	}
       
   382 
   344 int Autolock::AskValidSecCode(int aReason)
   383 int Autolock::AskValidSecCode(int aReason)
   345     {
   384     {
   346     RDEBUG("aReason", aReason);
   385     RDEBUG("aReason", aReason);
   347     RMobilePhone iPhone; // NULL in emulator
   386     RMobilePhone iPhone; // NULL in emulator
   348 
   387 
   581             break;
   620             break;
   582         case KErrInUse: // the dialog is already shown
   621         case KErrInUse: // the dialog is already shown
   583             RDEBUG("KErrInUse", aReason)
   622             RDEBUG("KErrInUse", aReason)
   584             ;
   623             ;
   585             break;
   624             break;
       
   625         case KErrLocked: // never happens
       
   626             RDEBUG("KErrLocked", aReason)
       
   627             ;
       
   628             break;
   586         default:
   629         default:
   587             RDEBUG("default", aReason)
   630             RDEBUG("default", aReason)
   588             ;
   631             ;
   589             break;
   632             break;
   590         }
   633         }
   596     // check whether a dialog is already displayed. This is to prevent timeout-lock and timeout-keyguard activated on top of a PIN query, in particular at boot-up (TODO check for Starter)
   639     // check whether a dialog is already displayed. This is to prevent timeout-lock and timeout-keyguard activated on top of a PIN query, in particular at boot-up (TODO check for Starter)
   597     TInt secUiOriginatedQuery(ESecurityUIsSecUIOriginatedUninitialized);
   640     TInt secUiOriginatedQuery(ESecurityUIsSecUIOriginatedUninitialized);
   598     TInt err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, secUiOriginatedQuery);
   641     TInt err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, secUiOriginatedQuery);
   599     RDEBUG("err", err);
   642     RDEBUG("err", err);
   600     RDEBUG("secUiOriginatedQuery", secUiOriginatedQuery);
   643     RDEBUG("secUiOriginatedQuery", secUiOriginatedQuery);
       
   644 
       
   645     TInt startupValue(EStartupUiPhaseUninitialized);
       
   646 		err = RProperty::Get(KPSUidStartup, KPSStartupUiPhase, startupValue);
       
   647     RDEBUG("err", err);
       
   648     RDEBUG("startupValue", startupValue);
       
   649 
       
   650     TInt simStatusValue(0);
       
   651 		err = RProperty::Get(KPSUidStartup, KPSSimStatus, simStatusValue);
       
   652     RDEBUG("err", err);
       
   653     RDEBUG("simStatusValue", simStatusValue);
       
   654     if(startupValue<EStartupUiPhaseAllDone && aReason!=ELockAppDisableKeyguard && aReason!=ELockAppDisableDevicelock )
       
   655     	{
       
   656     	// before bootup, it can't be manually nor automatically keyguarded/locked
       
   657     	RDEBUG("before bootup, it can't be manually nor automatically keyguarded/locked KErrInUse", KErrInUse);
       
   658     	return KErrInUse;
       
   659     	}
       
   660 
   601     switch (aReason)
   661     switch (aReason)
   602         {
   662         {
   603         case ELockAppEnableKeyguard:
   663         case ELockAppEnableKeyguard:
   604             {
   664             {
   605             RDEBUG("ELockAppEnableKeyguard iLockStatus", iLockStatus);
   665             RDEBUG("ELockAppEnableKeyguard iLockStatus", iLockStatus);
   745     CRepository* repositoryKeyguard = NULL;
   805     CRepository* repositoryKeyguard = NULL;
   746     QT_TRAP_THROWING(repositoryDevicelock = CRepository::NewL(KCRUidSecuritySettings));
   806     QT_TRAP_THROWING(repositoryDevicelock = CRepository::NewL(KCRUidSecuritySettings));
   747     QT_TRAP_THROWING(repositoryKeyguard = CRepository::NewL(KCRUidCoreApplicationUIsSysAp));
   807     QT_TRAP_THROWING(repositoryKeyguard = CRepository::NewL(KCRUidCoreApplicationUIsSysAp));
   748     TInt cRresult = KErrNone;
   808     TInt cRresult = KErrNone;
   749     Q_UNUSED(cRresult);
   809     Q_UNUSED(cRresult);
       
   810 
       
   811     TInt autolockState;
       
   812     err = RProperty::Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, autolockState);
       
   813     RDEBUG("Get KCoreAppUIsAutolockStatus", err);
       
   814     RDEBUG("autolockState", autolockState);
       
   815 
   750     if (1 == 1) // this is a quick way to disable this functionality, for testing
   816     if (1 == 1) // this is a quick way to disable this functionality, for testing
   751         {
   817         {
   752         RDEBUG("publishing", aReason);
   818         RDEBUG("publishing", aReason);
   753         if (aReason == ELockNotActive)
   819         if (aReason == ELockNotActive)
   754             {
   820             {
   755             err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardNotActive);
   821             err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardNotActive);
   756             RDEBUG("err", err);
   822             RDEBUG("err", err);
   757             err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
   823 				    if(autolockState!=EAutolockOff)
   758             RDEBUG("err", err);
   824 				    	{
       
   825             	err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
       
   826             	RDEBUG("err", err);
       
   827             	}
       
   828             else
       
   829             	{
       
   830             	RDEBUG("not set KCoreAppUIsAutolockStatus because already ", EAutolockOff);
       
   831             	}
   759             TurnLights(ESecurityUIsLightsLockOnRequest, aReason, 0x14);
   832             TurnLights(ESecurityUIsLightsLockOnRequest, aReason, 0x14);
   760 
   833 
   761             // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);    // the settings remains. Only ISA changes, as well as the P&S
   834             // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);    // the settings remains. Only ISA changes, as well as the P&S
   762             cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0);
   835             cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0);
   763             RDEBUG("cRresult", cRresult);
   836             RDEBUG("cRresult", cRresult);
   766             {
   839             {
   767             if (aReason == EKeyguardActive)
   840             if (aReason == EKeyguardActive)
   768                 {
   841                 {
   769                 err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardLocked);
   842                 err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardLocked);
   770                 RDEBUG("KAknKeyguardStatus err", err);
   843                 RDEBUG("KAknKeyguardStatus err", err);
   771                 err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
   844                 if(autolockState!=EAutolockOff)
   772                 RDEBUG("KCoreAppUIsAutolockStatus err", err);
   845                 	{
       
   846 	                err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
       
   847   	              RDEBUG("KCoreAppUIsAutolockStatus err", err);
       
   848   	            	}
       
   849 		            else
       
   850 		            	{
       
   851 		            	RDEBUG("not set KCoreAppUIsAutolockStatus because already ", EAutolockOff);
       
   852 		            	}
   773                 TurnLights(ESecurityUIsLightsLockOffRequest, aReason, 0x16);	// same for keyguard and devicelock
   853                 TurnLights(ESecurityUIsLightsLockOffRequest, aReason, 0x16);	// same for keyguard and devicelock
   774                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);
   854                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);
   775                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 1);
   855                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 1);
   776                 RDEBUG("cRresult", cRresult);
   856                 RDEBUG("cRresult", cRresult);
   777                 }
   857                 }
   778             else if (aReason >= EDevicelockActive)
   858             else if (aReason >= EDevicelockActive)
   779                 {
   859                 {
   780                 err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardLocked); // previously EKeyguardAutolockEmulation, but then Telephone doesn't understand that it's keyguarded. Other candidates might be: EKeyguardLocked and EKeyguardNotActive
   860                 err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardLocked); // previously EKeyguardAutolockEmulation, but then Telephone doesn't understand that it's keyguarded. Other candidates might be: EKeyguardLocked and EKeyguardNotActive
   781                 RDEBUG("KAknKeyguardStatus err", err);
   861                 RDEBUG("KAknKeyguardStatus err", err);
   782                 err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EManualLocked);
   862                 if(autolockState!=EManualLocked)
   783                 RDEBUG("KCoreAppUIsAutolockStatus err", err);
   863                 	{
       
   864 	                err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EManualLocked);
       
   865   	              RDEBUG("KCoreAppUIsAutolockStatus err", err);
       
   866   	            	}
       
   867 		            else
       
   868 		            	{
       
   869 		            	RDEBUG("not set KCoreAppUIsAutolockStatus because already ", EManualLocked);
       
   870 		            	}
   784                 TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x18);
   871                 TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x18);
   785                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 1);
   872                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 1);
   786                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0); // keyguard disabled, so that user can type and DeviceF can be captured
   873                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0); // keyguard disabled, so that user can type and DeviceF can be captured
   787                 RDEBUG("cRresult", cRresult);
   874                 RDEBUG("cRresult", cRresult);
   788                 }
   875                 }
   855                 {
   942                 {
   856                 showNoteIfRequested( EKeyguardActive);
   943                 showNoteIfRequested( EKeyguardActive);
   857                 setLabelIcon(EKeyguardActive);
   944                 setLabelIcon(EKeyguardActive);
   858                 updateIndicator(EKeyguardActive);
   945                 updateIndicator(EKeyguardActive);
   859                 publishStatus(EKeyguardActive);
   946                 publishStatus(EKeyguardActive);
   860                 setLockDialog(aReason, 1);
   947                 setLockDialog(aReason, EDeviceDialogCreated);
   861                 }
   948                 }
   862             // Telephone might want to re-enable only-keyguard after the call ends. Allow it. This means re-showing the screensaver, not more.
   949             // Telephone might want to re-enable only-keyguard after the call ends. Allow it. This means re-showing the screensaver, not more.
   863 						if (errorInProcess == KErrPermissionDenied && iTempDisableOnlyKeyguardBecauseIncomingCall==1)
   950             // Note: this is already done in CallStateChanged, so it's useless. Therefore it expects KErrLocked, which never happens
       
   951 						if (errorInProcess == KErrLocked && iTempDisableOnlyKeyguardBecauseIncomingCall==1)
   864                {
   952                {
   865                setLockDialog(aReason, 1);
   953 							 RDEBUG("allowing telephone to re-enable keyguard . Call setLockDialog EDeviceDialogScreenSaverReDisplay", EDeviceDialogScreenSaverReDisplay);
       
   954                setLockDialog(aReason, EDeviceDialogScreenSaverReDisplay);
   866                iTempDisableOnlyKeyguardBecauseIncomingCall=0;
   955                iTempDisableOnlyKeyguardBecauseIncomingCall=0;
   867              	 }
   956              	 }
   868             }
   957             }
   869             break;
   958             break;
   870         case ELockAppDisableKeyguard: // 2
   959         case ELockAppDisableKeyguard: // 2
   875                 {
   964                 {
   876                 showNoteIfRequested( ELockNotActive);
   965                 showNoteIfRequested( ELockNotActive);
   877                 setLabelIcon(ELockNotActive);
   966                 setLabelIcon(ELockNotActive);
   878                 updateIndicator(ELockNotActive);
   967                 updateIndicator(ELockNotActive);
   879                 publishStatus(ELockNotActive);
   968                 publishStatus(ELockNotActive);
   880                 setLockDialog(aReason, 0);
   969                 setLockDialog(aReason, EDeviceDialogDestroyed);
   881                 }
   970                 }
   882             }
   971             }
   883             RDEBUG("errorInProcess", errorInProcess);
   972             RDEBUG("errorInProcess", errorInProcess);
   884             // Telephone might want to disnable only-keyguard during a call. Allow it. This means hiding the screensaver, not more.
   973             // Telephone might want to disable only-keyguard during a call. Allow it. This means hiding the screensaver, not more.
   885             if(errorInProcess==KErrPermissionDenied)
   974             // Note: this is already done in CallStateChanged, so it's useless. Therefore it expects KErrLocked, which never happens
       
   975             if(errorInProcess==KErrLocked)
   886             	{
   976             	{
   887 					    TInt aCallStatus;
   977 					    TInt aCallStatus=-1;
   888 					    TInt err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, aCallStatus);
   978 					    TInt err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, aCallStatus);
   889 					    RDEBUG("err", err);
   979 					    RDEBUG("err", err);
   890 					    RDEBUG("aCallStatus", aCallStatus);
   980 					    RDEBUG("aCallStatus", aCallStatus);
   891 							if (aCallStatus != EPSCTsyCallStateUninitialized && aCallStatus != EPSCTsyCallStateNone)
   981 							if (aCallStatus != EPSCTsyCallStateUninitialized && aCallStatus != EPSCTsyCallStateNone)
   892 								{
   982 								{
   893 								RDEBUG("allowing telephone to disable keyguard . Call setLockDialog 0", 0);
   983 								RDEBUG("allowing telephone to disable keyguard . Call setLockDialog EDeviceDialogScreenSaverHidden", EDeviceDialogScreenSaverHidden);
   894 								setLockDialog(aReason, 0);
   984 								setLockDialog(aReason, EDeviceDialogScreenSaverHidden);
   895 								iTempDisableOnlyKeyguardBecauseIncomingCall=1;
   985 								iTempDisableOnlyKeyguardBecauseIncomingCall=1;
   896 								errorInProcess=KErrNone;
   986 								errorInProcess=KErrNone;
   897 								}
   987 								}
   898             	}
   988             	}
   899             break;
   989             break;
   910             if (errorInProcess == KErrNone)
  1000             if (errorInProcess == KErrNone)
   911                 {
  1001                 {
   912                 updateIndicator( EDevicelockActive);
  1002                 updateIndicator( EDevicelockActive);
   913                 publishStatus(EDevicelockActive);
  1003                 publishStatus(EDevicelockActive);
   914                 setLabelIcon(EDevicelockActive);
  1004                 setLabelIcon(EDevicelockActive);
   915                 setLockDialog(aReason, 1);
  1005                 setLockDialog(aReason, EDeviceDialogCreated);
   916                 }
  1006                 }
   917             // aParam1 is aReason : EDevicelockManual, EDevicelockRemote
  1007             // aParam1 is aReason : EDevicelockManual, EDevicelockRemote
   918             // this never shows a note
  1008             // this never shows a note
   919             }
  1009             }
   920             break;
  1010             break;
   930                 }
  1020                 }
   931             if (errorInProcess == KErrNone)
  1021             if (errorInProcess == KErrNone)
   932                 {
  1022                 {
   933                 RDEBUG("skip setLockDialog", 0);
  1023                 RDEBUG("skip setLockDialog", 0);
   934                 // No need to disable screensaver. Notes now can get on top. Also, this avoids the transition Screensaver->unlockQuery, which produces flicker on HomeScreen.
  1024                 // No need to disable screensaver. Notes now can get on top. Also, this avoids the transition Screensaver->unlockQuery, which produces flicker on HomeScreen.
   935                 // setLockDialog(aReason, 0); // hide temporarilly because HbDeviceMessageBox doesn't get in top of the Lock-icon. Thus, dismiss it.
  1025                 setLockDialog(aReason, EDeviceDialogScreenSaverHidden); // hide temporarilly because HbDeviceMessageBox doesn't get in top of the Lock-icon. Thus, dismiss it.
   936                 // do I need to enable touch? it seems to work without it
  1026                 // do I need to enable touch? it seems to work without it
   937                 // in any case, lights are needed
  1027                 // in any case, lights are needed
   938                 TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x20);
  1028                 TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x20);
   939                 RDEBUG("calling HbDeviceMessageBox::question", 0);
       
   940                 bool value = true;
  1029                 bool value = true;
   941                 // not sure whether this question is really needed. The UI doesn't say anything, so I remove it for now.
  1030                 // not sure whether this question is really needed. The UI doesn't say anything, so I remove it for now.
   942                 // HbDeviceMessageBox::question("Disable Lock?");   // this doesn't block other events, so after return everything might be messed up.
  1031                 RDEBUG("not calling HbDeviceMessageBox::question", 0);
       
  1032                 // value = HbDeviceMessageBox::question("Disable Lock?");   // this doesn't block other events, so after return everything might be messed up.
   943                 RDEBUG("value", value);
  1033                 RDEBUG("value", value);
   944                 if (!value)
  1034                 if (!value)
   945                     errorInProcess = KErrCancel;
  1035                     errorInProcess = KErrCancel;
   946                 }
  1036                 }
   947             if (errorInProcess == KErrNone)
  1037             if (errorInProcess == KErrNone)
   948                 {
  1038                 {
   949                 RDEBUG("skip setLockDialog", 1);
  1039                 RDEBUG("skip setLockDialog", 0);
   950                 // No need to disable screensaver. Notes now can get on top. Also, this avoids the transition Screensaver->unlockQuery, which produces flicker on HomeScreen.
  1040                 // No need to disable screensaver. Notes now can get on top. Also, this avoids the transition Screensaver->unlockQuery, which produces flicker on HomeScreen.
   951                 // setLockDialog(aReason, 0); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
  1041                 setLockDialog(aReason, EDeviceDialogScreenSaverHidden); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
   952                 RDEBUG("calling AskValidSecCode", 0);
  1042                 RDEBUG("calling AskValidSecCode", 0);
   953                 errorInProcess = AskValidSecCode(ELockAppDisableDevicelock);
  1043                 errorInProcess = AskValidSecCode(ELockAppDisableDevicelock);
   954                 RDEBUG("errorInProcess", errorInProcess);
  1044                 RDEBUG("errorInProcess", errorInProcess);
   955                 }
  1045                 }
   956             if (errorInProcess == KErrNone)
  1046             if (errorInProcess == KErrNone)
   957                 {
  1047                 {
       
  1048                 // code is correct. Time to destroy the lock-icon
   958                 setLabelIcon( ELockNotActive);
  1049                 setLabelIcon( ELockNotActive);
   959                 updateIndicator(ELockNotActive);
  1050                 updateIndicator(ELockNotActive);
   960                 setLockDialog(aReason, 0);
  1051                 setLockDialog(aReason, EDeviceDialogDestroyed);
   961                 publishStatus(ELockNotActive);
  1052                 publishStatus(ELockNotActive);
   962                 }
  1053                 }
   963             if (errorInProcess != KErrNone)
  1054             if (errorInProcess != KErrNone)
   964                 { // re-lock. For example, if password is cancelled
  1055                 { // re-lock. For example, if password is cancelled
       
  1056 						    TInt aCallStatus=-1;
       
  1057 						    TInt skipScreenSaver=0;
       
  1058 						    TInt err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, aCallStatus);
       
  1059 						    RDEBUG("err", err);
       
  1060 						    RDEBUG("aCallStatus", aCallStatus);
       
  1061 								if (aCallStatus != EPSCTsyCallStateUninitialized && aCallStatus != EPSCTsyCallStateNone)
       
  1062 									{
       
  1063 									// if there's an active call and the query is cancelled, screensaver should not show.
       
  1064 									skipScreenSaver=1;	// if it's skipped, it will be set at CallStateChanged
       
  1065 									RDEBUG("new skipScreenSaver", skipScreenSaver);
       
  1066 									}
       
  1067 								RDEBUG("skipScreenSaver", skipScreenSaver);
   965                 if (iLockStatus >= EDevicelockActive) // this skips the case "unlocking although it wasn't locked"
  1068                 if (iLockStatus >= EDevicelockActive) // this skips the case "unlocking although it wasn't locked"
   966                     setLockDialog(ELockAppEnableDevicelock, 1);
  1069                     if(!skipScreenSaver)
       
  1070                     	setLockDialog(ELockAppEnableDevicelock, EDeviceDialogScreenSaverReDisplay);
   967                 }
  1071                 }
   968             // this never shows a note
  1072             // this never shows a note
   969             }
  1073             }
   970             break;
  1074             break;
   971         case ELockAppOfferKeyguard: // 5
  1075         case ELockAppOfferKeyguard: // 5
   993             {
  1097             {
   994             errorInProcess = CheckIfLegal(ret);
  1098             errorInProcess = CheckIfLegal(ret);
   995             DebugError(errorInProcess);
  1099             DebugError(errorInProcess);
   996             if (errorInProcess == KErrNone)
  1100             if (errorInProcess == KErrNone)
   997                 {
  1101                 {
   998                 setLockDialog(aReason, 0); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
  1102                 RDEBUG("skip setLockDialog", 0);
       
  1103                 // No need to disable screensaver. Notes now can get on top. Also, this avoids the transition Screensaver->unlockQuery, which produces flicker on HomeScreen.
       
  1104                 setLockDialog(aReason, EDeviceDialogScreenSaverHidden); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
   999                 errorInProcess = AskValidSecCode(ELockAppEnableDevicelock);
  1105                 errorInProcess = AskValidSecCode(ELockAppEnableDevicelock);
  1000                 }
  1106                 }
  1001             if (errorInProcess == KErrNone)
  1107             if (errorInProcess == KErrNone)
  1002                 {
  1108                 {
  1003                 RDEBUG("ELockAppOfferDevicelock calling ELockAppEnableDevicelock", ELockAppEnableDevicelock);
  1109                 RDEBUG("ELockAppOfferDevicelock calling ELockAppEnableDevicelock", ELockAppEnableDevicelock);
  1023             errorInProcess = KErrNotSupported;
  1129             errorInProcess = KErrNotSupported;
  1024             }
  1130             }
  1025             break;
  1131             break;
  1026 
  1132 
  1027         }
  1133         }
       
  1134     RDEBUG("errorInProcess", errorInProcess);
  1028     return errorInProcess;
  1135     return errorInProcess;
  1029     }
  1136     }
  1030 /**************************/
  1137 /**************************/
  1031 int Autolock::setLockDialog(int aReason, int status)
  1138 int Autolock::setLockDialog(int aReason, int status)
  1032     {
  1139     {
  1038     RDEBUG("err", err);
  1145     RDEBUG("err", err);
  1039     RDEBUG("secUiOriginatedQuery", secUiOriginatedQuery);
  1146     RDEBUG("secUiOriginatedQuery", secUiOriginatedQuery);
  1040 
  1147 
  1041     RWindowGroup& groupWin = CEikonEnv::Static()->RootWin();
  1148     RWindowGroup& groupWin = CEikonEnv::Static()->RootWin();
  1042 
  1149 
  1043     if (status == 0) // hide
  1150     if (status == EDeviceDialogDestroyed || status == EDeviceDialogScreenSaverHidden) // hide
  1044         {
  1151         {
  1045         // aReason is not important here, but let's check nevertheless
  1152         // aReason is not important here, but let's check nevertheless
  1046         RDEBUG("ReleaseContext", R_AVKON_DEFAULT_SKEY_LIST);
  1153         RDEBUG("ReleaseContext", R_AVKON_DEFAULT_SKEY_LIST);
  1047         static_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())->KeySounds()->ReleaseContext();
  1154         static_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())->KeySounds()->ReleaseContext();
  1048         RDEBUG("PopContext", 0x90);
  1155         RDEBUG("PopContext", 0x90);
  1049         static_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())->KeySounds()->PopContext();
  1156         static_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())->KeySounds()->PopContext();
  1050         RDEBUG("ReleaseContext done", 0x92);
  1157         RDEBUG("ReleaseContext done", 0x92);
  1051 
  1158 
  1052         if (aReason != ELockAppDisableKeyguard && aReason != ELockAppDisableDevicelock)
  1159         if (aReason != ELockAppDisableKeyguard && aReason != ELockAppDisableDevicelock && aReason != ELockAppOfferDevicelock)
  1053             {
  1160             {
  1054             RDEBUG("!!!!****!!!!! error. status=0 but aReason", aReason);
  1161             RDEBUG("!!!!****!!!!! error. status=0 but aReason", aReason);
  1055             }
  1162             }
  1056         // secUiOriginatedQuery should be ESecurityUIsSystemLockOriginated . If not, this is not correctly setting it
  1163         // secUiOriginatedQuery should be ESecurityUIsSystemLockOriginated . If not, this is not correctly setting it
  1057         if (iDeviceDialogCreated >= EDeviceDialogCreated)
  1164         if (iDeviceDialogCreated >= EDeviceDialogCreated)
  1058             {
  1165             {
  1059             iDeviceDialogCreated = EDeviceDialogDestroyed;
  1166 						if(status == EDeviceDialogDestroyed)
  1060             RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
  1167 							{
  1061 
  1168 	            disconnect(iDeviceDialog, SIGNAL(dataReceived(QVariantMap)), this, SLOT(handleMessageFromScreensaver(QVariantMap)));
  1062             RDEBUG("calling switchScreensaverMode", ESnsrViewTypeDisabled);
  1169 	            disconnect(iDeviceDialog, SIGNAL(deviceDialogClosed()), this, SLOT(handleScreensaverClosed()));
  1063             switchScreensaverMode( ESnsrViewTypeDisabled);
  1170 	            RDEBUG("signal disconnected", err);
  1064 
  1171 	            // TODO this crashes for EDeviceDialogScreenSaver
  1065             disconnect(iDeviceDialog, SIGNAL(dataReceived(QVariantMap)), this, SLOT(handleMessageFromScreensaver(QVariantMap)));
  1172 	            err = iDeviceDialog->cancel();
  1066             disconnect(iDeviceDialog, SIGNAL(deviceDialogClosed()), this, SLOT(handleScreensaverClosed()));
  1173 	            RDEBUG("cancel (bool: 1= wellCancelled) err", err);
  1067             RDEBUG("signal disconnected", err);
  1174 	            err = iDeviceDialog->error();
  1068             // TODO this crashes for EDeviceDialogScreenSaver
  1175 	            RDEBUG("err", err);
  1069             err = iDeviceDialog->cancel();
  1176 	            RDEBUG("calling iDeviceDialog->waitForClosed()", 0);
  1070             RDEBUG("cancel (bool: 1= wellCancelled) err", err);
  1177 	            err = iDeviceDialog->waitForClosed();
  1071             err = iDeviceDialog->error();
  1178 	            RDEBUG("cancel (bool: 1= well waitForClosed) err", err);
  1072             RDEBUG("err", err);
  1179 	            err = iDeviceDialog->error();
  1073             RDEBUG("calling iDeviceDialog->waitForClosed()", 0);
  1180 	            RDEBUG("err", err);
  1074             err = iDeviceDialog->waitForClosed();
  1181             	handleScreensaverClosed();
  1075             RDEBUG("cancel (bool: 1= well waitForClosed) err", err);
  1182 	            RDEBUG("deleting iDeviceDialog", 0);
  1076             err = iDeviceDialog->error();
  1183 	            delete iDeviceDialog;
  1077             RDEBUG("err", err);
  1184 	            RDEBUG("deleted iDeviceDialog", 1);
       
  1185 	            iDeviceDialog = NULL;
       
  1186 							}
       
  1187 						else if(status == EDeviceDialogScreenSaverHidden)
       
  1188 							{
       
  1189 	            RDEBUG("calling switchScreensaverMode", ESnsrViewTypeDisabled);
       
  1190   	          switchScreensaverMode( ESnsrViewTypeDisabled);
       
  1191   	        	}
  1078 
  1192 
  1079             TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsSecUIOriginatedUninitialized);
  1193             TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsSecUIOriginatedUninitialized);
  1080             RDEBUG("reset KSecurityUIsSecUIOriginatedQuery. err", err);
  1194             RDEBUG("reset KSecurityUIsSecUIOriginatedQuery. err", err);
  1081             handleScreensaverClosed();
  1195 
  1082             TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x22);
  1196             TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x22);
  1083             // Cancel power key and application key capturing
  1197             // Cancel power key and application key capturing
  1084             groupWin.CancelCaptureKey(mPowerKeyCaptureHandle);
  1198             groupWin.CancelCaptureKey(mPowerKeyCaptureHandle);
  1085             groupWin.CancelCaptureKey(mApplicationKeyCaptureHandle);
  1199             groupWin.CancelCaptureKey(mApplicationKeyCaptureHandle);
  1086             groupWin.CancelCaptureLongKey(mApplicationLongKeyCaptureHandle);
  1200             groupWin.CancelCaptureLongKey(mApplicationLongKeyCaptureHandle);
  1095                 {
  1209                 {
  1096                 RDEBUG("mEKeyNoCaptureHandle", mEKeyNoCaptureHandle);
  1210                 RDEBUG("mEKeyNoCaptureHandle", mEKeyNoCaptureHandle);
  1097                 groupWin.CancelCaptureKey(mEKeyNoCaptureHandle);
  1211                 groupWin.CancelCaptureKey(mEKeyNoCaptureHandle);
  1098                 mEKeyNoCaptureHandle = NULL;
  1212                 mEKeyNoCaptureHandle = NULL;
  1099                 }
  1213                 }
  1100 
  1214             iDeviceDialogCreated = status;
  1101             RDEBUG("deleting iDeviceDialog", 0);
  1215             RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
  1102             delete iDeviceDialog;
  1216             }
  1103             RDEBUG("deleted iDeviceDialog", 1);
  1217         }
  1104             iDeviceDialog = NULL;
  1218     else if (status == EDeviceDialogCreated || status == EDeviceDialogScreenSaverReDisplay) // show
  1105             }
       
  1106         }
       
  1107     else if (status == 1) // show
       
  1108         {
  1219         {
  1109         RDEBUG("PushContextL", R_AVKON_DEFAULT_SKEY_LIST);
  1220         RDEBUG("PushContextL", R_AVKON_DEFAULT_SKEY_LIST);
  1110         static_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())->KeySounds()->PushContextL(R_AVKON_SILENT_SKEY_LIST);
  1221         static_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())->KeySounds()->PushContextL(R_AVKON_SILENT_SKEY_LIST);
  1111         RDEBUG("BringToForeground", 0x90);
  1222         RDEBUG("BringToForeground", 0x90);
  1112         static_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())->KeySounds()->BringToForeground();
  1223         static_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())->KeySounds()->BringToForeground();
  1115         RDEBUG("PushContextL Done", 0x92);
  1226         RDEBUG("PushContextL Done", 0x92);
  1116 
  1227 
  1117         // secUiOriginatedQuery should be ESecurityUIsSecUIOriginatedUninitialized . If not, the validation is not correctly filtering it
  1228         // secUiOriginatedQuery should be ESecurityUIsSecUIOriginatedUninitialized . If not, the validation is not correctly filtering it
  1118         QVariantMap params;
  1229         QVariantMap params;
  1119         TBool err=EFalse;
  1230         TBool err=EFalse;
  1120 #define ESecUiTypeDeviceLock        0x00100000
       
  1121 #define ESecUiTypeKeyguard          0x00200000
       
  1122 
  1231 
  1123         if (aReason == ELockAppEnableKeyguard)
  1232         if (aReason == ELockAppEnableKeyguard)
  1124             params.insert("type", ESecUiTypeKeyguard);
  1233             params.insert("type", ESecUiTypeKeyguard);
  1125         else if (aReason == ELockAppEnableDevicelock)
  1234         else if (aReason == ELockAppEnableDevicelock)
  1126             params.insert("type", ESecUiTypeDeviceLock);
  1235             params.insert("type", ESecUiTypeDeviceLock);
  1127         else
  1236         else
  1128             {
  1237             {
  1129             RDEBUG("error. status=1 but aReason", aReason);
  1238             RDEBUG("!!!!****!!!!! error. status=1 but aReason", aReason);
  1130             }
  1239             }
  1131         // no need for title. Icon should be explicit enough
  1240         // no need for title. Icon should be explicit enough
  1132         // params.insert("title", "Locked");
  1241         // params.insert("title", "Locked");
  1133         if (iDeviceDialogCreated < EDeviceDialogCreated)
  1242         if (iDeviceDialogCreated < EDeviceDialogCreated)
  1134             {
  1243             {
  1153             iDeviceDialogCreated = EDeviceDialogRaised;
  1262             iDeviceDialogCreated = EDeviceDialogRaised;
  1154             RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
  1263             RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
  1155             }
  1264             }
  1156         const QString KScreensaverDeviceDialog("com.nokia.screensaver.snsrdevicedialogplugin/1.0");
  1265         const QString KScreensaverDeviceDialog("com.nokia.screensaver.snsrdevicedialogplugin/1.0");
  1157         RDEBUG("pre show", aReason);
  1266         RDEBUG("pre show", aReason);
  1158         bool launchSuccesful = iDeviceDialog->show(KScreensaverDeviceDialog, params); // and continue processing
  1267         TInt skipScreenSaver=0;
  1159         RDEBUG("post show. bool launchSuccesful", launchSuccesful);
  1268         bool launchSuccesful = EFalse;
       
  1269 
       
  1270 		    TInt aCallStatus=-1;
       
  1271 		    err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, aCallStatus);
       
  1272 		    RDEBUG("aCallStatus", aCallStatus);
       
  1273 		    // never create screensaver if active call.
       
  1274 				if (aCallStatus != EPSCTsyCallStateUninitialized && aCallStatus != EPSCTsyCallStateNone && iLockStatus >= EDevicelockActive )
       
  1275 					{
       
  1276 					skipScreenSaver=1;
       
  1277 					RDEBUG("new skipScreenSaver", skipScreenSaver);
       
  1278 					}
       
  1279 				RDEBUG("skipScreenSaver", skipScreenSaver);
       
  1280 				if(!skipScreenSaver)
       
  1281 					{
       
  1282 	        if(iDeviceDialogCreated == EDeviceDialogCreated)
       
  1283 	        	{
       
  1284 	        	launchSuccesful = iDeviceDialog->show(KScreensaverDeviceDialog, params); // and continue processing
       
  1285 	        	RDEBUG("post show. bool launchSuccesful", launchSuccesful);
       
  1286 	        	}
       
  1287 	        else if(iDeviceDialogCreated == EDeviceDialogScreenSaverHidden || iDeviceDialogCreated == EDeviceDialogRaised)
       
  1288 	        	{
       
  1289         		RDEBUG("calling switchScreensaverMode ESnsrViewTypeActive", ESnsrViewTypeActive);
       
  1290 	        	switchScreensaverMode( ESnsrViewTypeActive);
       
  1291 	        	launchSuccesful = ETrue;
       
  1292 	        	}
       
  1293         	}
       
  1294         RDEBUG("bool launchSuccesful", launchSuccesful);
  1160         err = iDeviceDialog->error();
  1295         err = iDeviceDialog->error();
  1161         RDEBUG("iDeviceDialog->error", err);
  1296         RDEBUG("iDeviceDialog->error", err);
  1162         if (launchSuccesful) // TODO && !error ???
  1297         if (launchSuccesful) // TODO && !error ???
  1163             {
  1298             {
  1164             iDeviceDialogCreated = EDeviceDialogScreenSaver;
  1299             iDeviceDialogCreated = EDeviceDialogScreenSaver;
  1166             // TODO this is needed if creating dialog for first time? switchScreensaverToActiveMode(); // this is needed in case the dialog was existing.
  1301             // TODO this is needed if creating dialog for first time? switchScreensaverToActiveMode(); // this is needed in case the dialog was existing.
  1167             // Start standy mode timer. The initial state may already be the standby
  1302             // Start standy mode timer. The initial state may already be the standby
  1168             // mode but setting screensaver again to standby doesn't hurt.
  1303             // mode but setting screensaver again to standby doesn't hurt.
  1169             mScreensaverModeTimer->start();
  1304             mScreensaverModeTimer->start();
  1170             }
  1305             }
  1171         else // some err. Usually 3 (not existing)
  1306         else if (!skipScreenSaver)// some err. Usually 3 (not existing)
  1172             {
  1307             {
  1173             // screensaver has failed. Probably because it's not installed. Then, try the standard lock-icon
  1308             // screensaver has failed. Probably because it's not installed. Then, try the standard lock-icon
  1174             iDeviceDialogCreated = EDeviceDialogLockIcon;
  1309             iDeviceDialogCreated = EDeviceDialogLockIcon;
  1175             RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
  1310             RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
  1176             const QString KSecQueryUiDeviceDialog("com.nokia.secuinotificationdialog/1.0");
  1311             const QString KSecQueryUiDeviceDialog("com.nokia.secuinotificationdialog/1.0");
  1245     return success;
  1380     return success;
  1246     }
  1381     }
  1247 
  1382 
  1248 void Autolock::activeKeyguard()
  1383 void Autolock::activeKeyguard()
  1249     {
  1384     {
       
  1385     RDEBUG("0", 0);
  1250     // activity while keyguarded. Nothing to do
  1386     // activity while keyguarded. Nothing to do
  1251     RDEBUG("0", 0);
  1387     RDEBUG("99", 0x99);
  1252     }
  1388     }
  1253 
  1389 
  1254 void Autolock::notActiveKeyguard()
  1390 void Autolock::notActiveKeyguard()
  1255     {
  1391     {
  1256     // inactivity. Keyguard should be activated
  1392     // inactivity. Keyguard should be activated
  1285     RDEBUG("ret", ret);
  1421     RDEBUG("ret", ret);
  1286     }
  1422     }
  1287 /* Some activity detected while the deviceLock is enabled */
  1423 /* Some activity detected while the deviceLock is enabled */
  1288 void Autolock::activeDevicelock()
  1424 void Autolock::activeDevicelock()
  1289     {
  1425     {
       
  1426     RDEBUG("0", 0);
  1290     // nothing to do
  1427     // nothing to do
  1291     RDEBUG("0", 0);
  1428     RDEBUG("99", 0x99);
  1292     }
  1429     }
  1293 
  1430 
  1294 void Autolock::notActiveDevicelock()
  1431 void Autolock::notActiveDevicelock()
  1295     {
  1432     {
  1296     // inactivity. Devicelock should be activated
  1433     // inactivity. Devicelock should be activated
  1302         {
  1439         {
  1303         // this is independent of the call status
  1440         // this is independent of the call status
  1304         ret = TryChangeStatus(ELockAppEnableDevicelock);
  1441         ret = TryChangeStatus(ELockAppEnableDevicelock);
  1305         }
  1442         }
  1306     RDEBUG("ret", ret);
  1443     RDEBUG("ret", ret);
  1307 
       
  1308     }
  1444     }
  1309 
  1445 
  1310 void Autolock::switchScreensaverMode(int mode)
  1446 void Autolock::switchScreensaverMode(int mode)
  1311     {
  1447     {
  1312     RDEBUG("mode", mode);
  1448     RDEBUG("mode", mode);
  1338                 RDEBUG("start mScreensaverModeTimer", 0);
  1474                 RDEBUG("start mScreensaverModeTimer", 0);
  1339             		mScreensaverModeTimer->start();
  1475             		mScreensaverModeTimer->start();
  1340             		}
  1476             		}
  1341             }
  1477             }
  1342         }
  1478         }
  1343     RDEBUG("1", 1);
  1479     RDEBUG("99", 0x99);
  1344     }
  1480     }
  1345 
  1481 
  1346 void Autolock::switchScreensaverToPowerSaveMode()
  1482 void Autolock::switchScreensaverToPowerSaveMode()
  1347     {
  1483     {
  1348     RDEBUG("0", 0);
  1484     RDEBUG("0", 0);
  1349     switchScreensaverMode( ESnsrViewTypeStandby);
  1485     switchScreensaverMode( ESnsrViewTypeStandby);
  1350     RDEBUG("1", 1);
  1486     RDEBUG("99", 0x99);
  1351     }
  1487     }
  1352 
  1488 
  1353 void Autolock::handleMessageFromScreensaver(const QVariantMap &data)
  1489 void Autolock::handleMessageFromScreensaver(const QVariantMap &data)
  1354     {
  1490     {
  1355     RDEBUG("0", 0);
  1491     RDEBUG("0", 0);
  1402             // handled now directly by screensaver
  1538             // handled now directly by screensaver
  1403             // int err = mScreensaverPowerSave->Exit();
  1539             // int err = mScreensaverPowerSave->Exit();
  1404             // RDEBUG("err", err);
  1540             // RDEBUG("err", err);
  1405             }
  1541             }
  1406         }
  1542         }
       
  1543     RDEBUG("99", 0x99);
  1407     }
  1544     }
  1408 
  1545 
  1409 void Autolock::handleScreensaverClosed()
  1546 void Autolock::handleScreensaverClosed()
  1410     {
  1547     {
  1411     RDEBUG("0", 0);
  1548     RDEBUG("0", 0);
  1503             RDEBUG("0", 0);
  1640             RDEBUG("0", 0);
  1504             } // isSwitchKey
  1641             } // isSwitchKey
  1505         } // ev
  1642         } // ev
  1506     // Process if not done before. For example, redraw or quit
  1643     // Process if not done before. For example, redraw or quit
  1507     TBool widgetEventSuccesful = QWidget::event(ev);
  1644     TBool widgetEventSuccesful = QWidget::event(ev);
  1508     RDEBUG("9", 9);
  1645     RDEBUG("99", 0x99);
  1509     return widgetEventSuccesful;
  1646     return widgetEventSuccesful;
  1510     }
  1647     }
  1511 
  1648 
  1512 int Autolock::handleLockSwitch()
  1649 int Autolock::handleLockSwitch()
  1513     {
  1650     {
  1514     RDEBUG("0", 0);
  1651     RDEBUG("0", 0);
  1515     int ret = KErrNone;
  1652     int ret = KErrNone;
  1516    	RDEBUG("iProcessingEvent", iProcessingEvent);
  1653    	RDEBUG("iProcessingEvent", iProcessingEvent);
       
  1654    	RDEBUG("iLockStatus", iLockStatus);
  1517    	// iProcessingEvent is used to avoid concurrent processing, i.e. 2 side-switch presses; because it needs time to create (and dismiss) the dialog
  1655    	// iProcessingEvent is used to avoid concurrent processing, i.e. 2 side-switch presses; because it needs time to create (and dismiss) the dialog
  1518    	// However this disallows keyguard during unlock-quey.
  1656    	// However this disallows keyguard during unlock-quey.
  1519    	if(iProcessingEvent < 1)
  1657    	if(iProcessingEvent < 1)
  1520    		{
  1658    		{
  1521 	    iProcessingEvent = 1;
  1659 	    iProcessingEvent = 1;
  1523 	    DebugStatus( iLockStatus);
  1661 	    DebugStatus( iLockStatus);
  1524 	    if (iLockStatus == ELockNotActive)
  1662 	    if (iLockStatus == ELockNotActive)
  1525 	        {
  1663 	        {
  1526 	        iShowKeyguardNote = 0; // no note on enable keyguard
  1664 	        iShowKeyguardNote = 0; // no note on enable keyguard
  1527 	        callerHasECapabilityWriteDeviceData = 1;
  1665 	        callerHasECapabilityWriteDeviceData = 1;
  1528 	        ret = TryChangeStatus(ELockAppEnableKeyguard); // this should not ask confirmation
  1666             // TODO ELockAppEnableDevicelock
       
  1667 	        CRepository *repository = 0;
       
  1668 	        int deviceLock = 0;
       
  1669 	        QT_TRAP_THROWING(repository = CRepository::NewL(KCRUidSecuritySettings));
       
  1670 	        repository->Get(KSettingsAutoLockTime, deviceLock);
       
  1671 	        delete repository;
       
  1672 	        if (65535 == deviceLock) {
       
  1673 				// Setting says "When keys& screen locked". Therefore device is also locked when screen is manually locked.
       
  1674 				// TODO what about the API for screen lock?
       
  1675 	            ret = TryChangeStatus(ELockAppEnableDevicelock); // this should not ask confirmation
       
  1676 	        } else {
       
  1677 	            ret = TryChangeStatus(ELockAppEnableKeyguard); // this should not ask confirmation
       
  1678 	        }
       
  1679 
  1529 	        }
  1680 	        }
  1530 	    else if (iLockStatus == EKeyguardActive)
  1681 	    else if (iLockStatus == EKeyguardActive)
  1531 	        {
  1682 	        {
  1532 	        iShowKeyguardNote = 0; // no note on disable keyguard
  1683 	        iShowKeyguardNote = 0; // no note on disable keyguard
  1533 	        callerHasECapabilityWriteDeviceData = 1;
  1684 	        callerHasECapabilityWriteDeviceData = 1;
  1545     	iProcessingEvent = 0;
  1696     	iProcessingEvent = 0;
  1546 	    }
  1697 	    }
  1547 	  else
  1698 	  else
  1548 	  	{
  1699 	  	{
  1549 	  	// user presses side-switch while another is in process, most probably a unlock-query. Thus, re-switch on the lights
  1700 	  	// user presses side-switch while another is in process, most probably a unlock-query. Thus, re-switch on the lights
       
  1701 	  	iProcessingEvent++;	// just to know how many processes we missed
       
  1702 	  	if(iProcessingEvent>=10)
       
  1703 	  		iProcessingEvent=0;	// if user really insists, then try again
  1550 	  	if (iLockStatus == EDevicelockActive)
  1704 	  	if (iLockStatus == EDevicelockActive)
  1551 	  		{
  1705 	  		{
  1552         TurnLights(ESecurityUIsLightsQueryOnRequest, ELockAppEnableDevicelock, 0x26);
  1706         TurnLights(ESecurityUIsLightsQueryOnRequest, ELockAppEnableDevicelock, 0x26);
  1553 	  		}
  1707 	  		}
  1554 	  	}
  1708 	  	}
  1646     RDEBUG("aCallStatus", aCallStatus);
  1800     RDEBUG("aCallStatus", aCallStatus);
  1647     RWindowGroup& groupWin = CEikonEnv::Static()->RootWin();
  1801     RWindowGroup& groupWin = CEikonEnv::Static()->RootWin();
  1648     RDEBUG("iLockStatus", iLockStatus);
  1802     RDEBUG("iLockStatus", iLockStatus);
  1649     if (aCallStatus == EPSCTsyCallStateUninitialized || aCallStatus == EPSCTsyCallStateNone)
  1803     if (aCallStatus == EPSCTsyCallStateUninitialized || aCallStatus == EPSCTsyCallStateNone)
  1650         {
  1804         {
       
  1805         // Telephone might want to re-enable only-keyguard after the call ends. Allow it. This means re-showing the screensaver, not more.
  1651         RDEBUG("call is inactive", aCallStatus);
  1806         RDEBUG("call is inactive", aCallStatus);
       
  1807         if(iLockStatus == EDevicelockActive)
       
  1808             setLockDialog(ELockAppEnableKeyguard, 1);
       
  1809         
  1652         if (iLockStatus == EKeyguardActive || iLockStatus == EDevicelockActive)
  1810         if (iLockStatus == EKeyguardActive || iLockStatus == EDevicelockActive)
  1653             {
  1811             {
  1654             if (!mEKeyYesCaptureHandle)
  1812             if (!mEKeyYesCaptureHandle)
  1655                 mEKeyYesCaptureHandle = groupWin.CaptureKey(EKeyYes, 0, 0);
  1813                 mEKeyYesCaptureHandle = groupWin.CaptureKey(EKeyYes, 0, 0);
  1656             if (!mEKeyNoCaptureHandle)
  1814             if (!mEKeyNoCaptureHandle)
  1658             }
  1816             }
  1659         }
  1817         }
  1660     else
  1818     else
  1661         {
  1819         {
  1662         RDEBUG("call is active", aCallStatus);
  1820         RDEBUG("call is active", aCallStatus);
       
  1821 
       
  1822         RDEBUG("allowing telephone to disable keyguard . Call setLockDialog 0", 0);
       
  1823         if(iLockStatus == EDevicelockActive)
       
  1824             setLockDialog(ELockAppDisableKeyguard, 0);
       
  1825 
  1663         // Telephone should be on top, but nevertheless we give End/Send to them
  1826         // Telephone should be on top, but nevertheless we give End/Send to them
  1664         // This should be done only if locked, but it doesn't harm
  1827         // This should be done only if locked, but it doesn't harm
  1665         if (mEKeyYesCaptureHandle)
  1828         if (mEKeyYesCaptureHandle)
  1666             {
  1829             {
  1667             RDEBUG("mEKeyYesCaptureHandle", mEKeyYesCaptureHandle);
  1830             RDEBUG("mEKeyYesCaptureHandle", mEKeyYesCaptureHandle);
  1675             mEKeyNoCaptureHandle = NULL;
  1838             mEKeyNoCaptureHandle = NULL;
  1676             }
  1839             }
  1677         // it seems that Telephone doesn't turn-on the lights when an incoming call on deviceLock. It's done here.
  1840         // it seems that Telephone doesn't turn-on the lights when an incoming call on deviceLock. It's done here.
  1678         TurnLights(ESecurityUIsLightsQueryOnRequest, ELockAppDisableKeyguard, 0x28);
  1841         TurnLights(ESecurityUIsLightsQueryOnRequest, ELockAppDisableKeyguard, 0x28);
  1679         }
  1842         }
  1680     RDEBUG("9", 9);
  1843     RDEBUG("99", 0x99);
  1681     }
  1844     }
  1682 // SecUiNotificationDialog::subscriberKSecurityUIsDismissDialogChanged()
  1845 // SecUiNotificationDialog::subscriberKSecurityUIsDismissDialogChanged()
  1683 // A way for Autolock to dismiss any possible PIN dialog
  1846 // A way for Autolock to dismiss any possible PIN dialog
  1684 // ----------------------------------------------------------------------------
  1847 // ----------------------------------------------------------------------------
  1685 //
  1848 //
  1688     RDEBUG("0", 0);
  1851     RDEBUG("0", 0);
  1689     TInt aDismissDialog = ESecurityUIsDismissDialogUninitialized;
  1852     TInt aDismissDialog = ESecurityUIsDismissDialogUninitialized;
  1690     TInt err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsDismissDialog, aDismissDialog);
  1853     TInt err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsDismissDialog, aDismissDialog);
  1691     RDEBUG("err", err);
  1854     RDEBUG("err", err);
  1692     RDEBUG("aDismissDialog", aDismissDialog);
  1855     RDEBUG("aDismissDialog", aDismissDialog);
       
  1856     }
       
  1857 
       
  1858 void Autolock::subscriberKSecurityUIsTestCodeChanged()
       
  1859     {
       
  1860     RDEBUG("0", 0);
       
  1861     TInt aTestCode = -1;
       
  1862     TInt err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsTestCode, aTestCode);
       
  1863     RDEBUG("err", err);
       
  1864     RDEBUG("aTestCode", aTestCode);
  1693     }
  1865     }
  1694 // ----------AutolockService---------------
  1866 // ----------AutolockService---------------
  1695 
  1867 
  1696 AutolockService::AutolockService(Autolock* parent) :
  1868 AutolockService::AutolockService(Autolock* parent) :
  1697     XQServiceProvider(QLatin1String("com.nokia.services.Autolock.Autolock"), parent), mAutolock(parent), mAsyncReqId(-1), mAsyncAnswer(false)
  1869     XQServiceProvider(QLatin1String("com.nokia.services.Autolock.Autolock"), parent), mAutolock(parent), mAsyncReqId(-1), mAsyncAnswer(false)
  1781 void AutolockService::handleClientDisconnect()
  1953 void AutolockService::handleClientDisconnect()
  1782     {
  1954     {
  1783     RDEBUG("0", 0);
  1955     RDEBUG("0", 0);
  1784     // Just quit service application if client ends
  1956     // Just quit service application if client ends
  1785     mAsyncAnswer = false;
  1957     mAsyncAnswer = false;
  1786     RDEBUG("0", 0);
  1958     RDEBUG("99", 0x99);
  1787     // mAutolock->quit();
  1959     // mAutolock->quit();
  1788     }
  1960     }
  1789 
  1961 
  1790 /****************/
  1962 /****************/
  1791 CWait* CWait::NewL()
  1963 CWait* CWait::NewL()