securitydialogs/Autolock/src/Autolock.cpp
changeset 56 25a3fbb5e4d3
parent 51 f479c7dc25d6
child 61 1cc4c46c2963
equal deleted inserted replaced
51:f479c7dc25d6 56:25a3fbb5e4d3
    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 <hbdevicedialog.h>
    64 #include <hbdevicedialog.h>
    65 #include <power_save_display_mode.h>
    65 // handled now directly but screensaver
       
    66 // #include <power_save_display_mode.h>
    66 
    67 
    67 const TInt KPhoneIndex(0);
    68 const TInt KPhoneIndex(0);
    68 const TInt KTriesToConnectServer(2);
    69 const TInt KTriesToConnectServer(2);
    69 const TInt KTimeBeforeRetryingServerConnection(50000);
    70 const TInt KTimeBeforeRetryingServerConnection(50000);
    70 #define ESecUiTypeLock                  0x00100000
    71 #define ESecUiTypeLock                  0x00100000
   236     RDEBUG("mEKeyDeviceFCaptureHandle", mEKeyDeviceFCaptureHandle);
   237     RDEBUG("mEKeyDeviceFCaptureHandle", mEKeyDeviceFCaptureHandle);
   237     mEKeyBellCaptureHandle = groupWin.CaptureKey(EKeyBell, 0, 0);
   238     mEKeyBellCaptureHandle = groupWin.CaptureKey(EKeyBell, 0, 0);
   238     RDEBUG("mEKeyBellCaptureHandle", mEKeyBellCaptureHandle);
   239     RDEBUG("mEKeyBellCaptureHandle", mEKeyBellCaptureHandle);
   239     RDEBUG("got mKeyCaptureHandle", 1);
   240     RDEBUG("got mKeyCaptureHandle", 1);
   240 
   241 
       
   242 		iTempDisableOnlyKeyguardBecauseIncomingCall=0;
       
   243 		
   241     iSecQueryUiCreated = -1;
   244     iSecQueryUiCreated = -1;
   242     iDeviceDialogCreated = EDeviceDialogUninitialized;
   245     iDeviceDialogCreated = EDeviceDialogUninitialized;
   243     RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
   246     RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
   244     iDeviceDialog = NULL;
   247     iDeviceDialog = NULL;
   245     // for now, always starts unlocked. This is correct because if locked, the unlock-query (from starter) is on top
   248     // for now, always starts unlocked. This is correct because if locked, the unlock-query (from starter) is on top
   247     TryChangeStatus( ELockNotActive);
   250     TryChangeStatus( ELockNotActive);
   248     lower();
   251     lower();
   249     hide();
   252     hide();
   250 
   253 
   251     iDeviceDialog = new HbDeviceDialog(HbDeviceDialog::NoFlags, this);
   254     iDeviceDialog = new HbDeviceDialog(HbDeviceDialog::NoFlags, this);
   252     connect(iDeviceDialog, SIGNAL(dataReceived(QVariantMap)), SLOT(handleMessageFromScreensaver(QVariantMap)));
   255     connect(iDeviceDialog, SIGNAL(dataReceived(QVariantMap)), SLOT(handleMessageFromScreensaver(QVariantMap)), Qt::QueuedConnection);	// Qt::QueuedConnection needed to avoid deadlock at waitForClosed
   253     connect(iDeviceDialog, SIGNAL(deviceDialogClosed()), SLOT(handleScreensaverClosed()));
   256     connect(iDeviceDialog, SIGNAL(deviceDialogClosed()), SLOT(handleScreensaverClosed()));
   254 
   257 
   255     // screensaver standby mode timer
   258     // screensaver standby mode timer
   256     mScreensaverModeTimer = new QTimer(this);
   259     mScreensaverModeTimer = new QTimer(this);
   257     mScreensaverModeTimer->setInterval(5 * 1000); // milliseconds, TODO: read from cenrep
   260     mScreensaverModeTimer->setInterval(5 * 1000); // milliseconds, TODO: read from cenrep
   258     connect(mScreensaverModeTimer, SIGNAL(timeout()), SLOT(switchScreensaverToPowerSaveMode()));
   261     connect(mScreensaverModeTimer, SIGNAL(timeout()), SLOT(switchScreensaverToPowerSaveMode()));
   259     // screensaver AMOLED low power mode support
   262     // screensaver AMOLED low power mode support
   260     mScreensaverPowerSave = CPowerSaveDisplayMode::NewL();
   263 
   261     mScreensaverPowerSavePixelBuffer = HBufC16::NewL(360 * 640);
   264     // handled now directly but screensaver
   262     mScreensaverPowerSavePixelBuffer->Des().Fill(0);
   265     // mScreensaverPowerSave = CPowerSaveDisplayMode::NewL();
       
   266     // mScreensaverPowerSavePixelBuffer = HBufC16::NewL(360 * 640);
       
   267     // mScreensaverPowerSavePixelBuffer->Des().Fill(0);
   263     }
   268     }
   264 
   269 
   265 Autolock::~Autolock()
   270 Autolock::~Autolock()
   266     {
   271     {
   267     RDEBUG("0", 0);
   272     RDEBUG("0", 0);
   268     delete mService;
   273     delete mService;
   269     delete mScreensaverPowerSave;
   274     // handled now directly but screensaver
   270     delete mScreensaverPowerSavePixelBuffer;
   275     // delete mScreensaverPowerSave;
       
   276     // delete mScreensaverPowerSavePixelBuffer;
   271     RDEBUG("1", 1);
   277     RDEBUG("1", 1);
   272     }
   278     }
   273 
   279 
   274 void Autolock::adjustInactivityTimers(int aReason)
   280 void Autolock::adjustInactivityTimers(int aReason)
   275     {
   281     {
   283     QT_TRAP_THROWING(repository = CRepository::NewL(KCRUidSecuritySettings));
   289     QT_TRAP_THROWING(repository = CRepository::NewL(KCRUidSecuritySettings));
   284     cRresult = repository->Get(KSettingsAutomaticKeyguardTime, keyguardTime); // in seconds
   290     cRresult = repository->Get(KSettingsAutomaticKeyguardTime, keyguardTime); // in seconds
   285     RDEBUG("KSettingsAutomaticKeyguardTime", KSettingsAutomaticKeyguardTime);
   291     RDEBUG("KSettingsAutomaticKeyguardTime", KSettingsAutomaticKeyguardTime);
   286     RDEBUG("cRresult", cRresult);
   292     RDEBUG("cRresult", cRresult);
   287     RDEBUG("keyguardTime", keyguardTime);
   293     RDEBUG("keyguardTime", keyguardTime);
   288     if (keyguardTime > 0 && keyguardTime < 1000)
   294     if (keyguardTime > 2 && keyguardTime < 24 * 60 * 60)
   289         {
   295         {
   290         serviceKeyguard->setInactivityPeriod(keyguardTime);
   296         serviceKeyguard->setInactivityPeriod(keyguardTime);
   291         }
   297         }
   292     else
   298     else
   293         {
   299         {
   298     lockTime *= 60;
   304     lockTime *= 60;
   299     RDEBUG("KSettingsAutoLockTime", KSettingsAutoLockTime);
   305     RDEBUG("KSettingsAutoLockTime", KSettingsAutoLockTime);
   300     RDEBUG("cRresult", cRresult);
   306     RDEBUG("cRresult", cRresult);
   301     RDEBUG("lockTime", lockTime);
   307     RDEBUG("lockTime", lockTime);
   302     if (lockTime == 65535 * 60) // Special setting "lock at same time as keyguard" at CpDeviceLockPluginView::GetAutoLockIndex which uses this magic number
   308     if (lockTime == 65535 * 60) // Special setting "lock at same time as keyguard" at CpDeviceLockPluginView::GetAutoLockIndex which uses this magic number
   303         lockTime = keyguardTime - 2; // lock 2 seconds before before, to avoid keyguard->devicelock sequence
   309     		{
   304     if (lockTime > 60 && lockTime < 24 * 60 * 60) // lock timer can't be bigger than 1 day
   310         lockTime = keyguardTime - 2; // lock 2 seconds before keyguard, to avoid keyguard->devicelock sequence
   305         {
   311         if(lockTime<=2)
       
   312         	lockTime=2;
       
   313         RDEBUG("new lockTime", lockTime);
       
   314       	}
       
   315     if (lockTime >= 2 && lockTime < 24 * 60 * 60) // lock timer can't be bigger than 1 day
       
   316         {
       
   317         RDEBUG("setInactivityPeriod lockTime", lockTime);
   306         serviceDevicelock->setInactivityPeriod(lockTime);
   318         serviceDevicelock->setInactivityPeriod(lockTime);
   307         }
   319         }
   308     else
   320     else
   309         {
   321         {
       
   322         RDEBUG("setInactivityPeriod infinite", lockTime);
   310         serviceDevicelock->setInactivityPeriod(12 * 31 * 24 * 60 * 60); // 0x1ea6e00
   323         serviceDevicelock->setInactivityPeriod(12 * 31 * 24 * 60 * 60); // 0x1ea6e00
   311         }
   324         }
   312 
   325 
   313     delete repository;
   326     delete repository;
   314     }
   327     }
   316     {
   329     {
   317     RDEBUG("0", 0);
   330     RDEBUG("0", 0);
   318     qApp->quit();
   331     qApp->quit();
   319     }
   332     }
   320 
   333 
       
   334 
       
   335 int Autolock::TurnLights(int aMode, int aReason, int aCaller)
       
   336     {
       
   337     RDEBUG("aMode", aMode);
       
   338     RDEBUG("aReason", aReason);
       
   339     RDEBUG("aCaller", aCaller);
       
   340     TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, aMode);
       
   341     RDEBUG("KSecurityUIsLights err", err);
       
   342     return err;
       
   343   	}
   321 int Autolock::AskValidSecCode(int aReason)
   344 int Autolock::AskValidSecCode(int aReason)
   322     {
   345     {
   323     RDEBUG("aReason", aReason);
   346     RDEBUG("aReason", aReason);
   324     RMobilePhone iPhone; // NULL in emulator
   347     RMobilePhone iPhone; // NULL in emulator
   325 
   348 
   331     Q_UNUSED(err);
   354     Q_UNUSED(err);
   332     TBool validCode(EFalse);
   355     TBool validCode(EFalse);
   333     TInt thisTry(0);
   356     TInt thisTry(0);
   334     RTelServer iTelServer;
   357     RTelServer iTelServer;
   335 
   358 
   336     err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsQueryOnRequest);
   359     TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x10);
   337     RDEBUG("KSecurityUIsLights err", err);
       
   338 
   360 
   339     RMmCustomAPI iCustomPhone;
   361     RMmCustomAPI iCustomPhone;
   340     while ((err = iTelServer.Connect()) != KErrNone && (thisTry++) <= KTriesToConnectServer)
   362     while ((err = iTelServer.Connect()) != KErrNone && (thisTry++) <= KTriesToConnectServer)
   341         {
   363         {
   342         User::After( KTimeBeforeRetryingServerConnection);
   364         User::After( KTimeBeforeRetryingServerConnection);
   463     RDEBUG("validCode", validCode);
   485     RDEBUG("validCode", validCode);
   464     if (validCode > 0)
   486     if (validCode > 0)
   465         return KErrNone;
   487         return KErrNone;
   466 
   488 
   467     // no valid code -> switch off the lights
   489     // no valid code -> switch off the lights
   468     err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsLockOffRequest);
   490     TurnLights(ESecurityUIsLightsLockOffRequest, aReason, 0x12);
   469     RDEBUG("KSecurityUIsLights err", err);
       
   470     return KErrCancel;
   491     return KErrCancel;
   471     }
   492     }
   472 
   493 
   473 void Autolock::handleAnswerDelivered()
   494 void Autolock::handleAnswerDelivered()
   474     {
   495     {
   633             {
   654             {
   634             RDEBUG("ELockAppDisableDevicelock iLockStatus", iLockStatus);
   655             RDEBUG("ELockAppDisableDevicelock iLockStatus", iLockStatus);
   635             if (iLockCodeQueryInDisplay)
   656             if (iLockCodeQueryInDisplay)
   636                 {
   657                 {
   637                 // PIN on top and trying to display unlock-code. This is valid
   658                 // PIN on top and trying to display unlock-code. This is valid
       
   659                 // but needs to turn on lights because SysAp switches them off even if query is present
       
   660                 TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x13);
   638                 return KErrAlreadyExists;
   661                 return KErrAlreadyExists;
   639                 }
   662                 }
   640             switch (iLockStatus)
   663             switch (iLockStatus)
   641                 {
   664                 {
   642                 case ELockNotActive:
   665                 case ELockNotActive:
   731             {
   754             {
   732             err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardNotActive);
   755             err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardNotActive);
   733             RDEBUG("err", err);
   756             RDEBUG("err", err);
   734             err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
   757             err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
   735             RDEBUG("err", err);
   758             RDEBUG("err", err);
   736             err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsLockOnRequest); // lights are required
   759             TurnLights(ESecurityUIsLightsLockOnRequest, aReason, 0x14);
   737             RDEBUG("KSecurityUIsLights err", err);
       
   738 
   760 
   739             // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);    // the settings remains. Only ISA changes, as well as the P&S
   761             // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);    // the settings remains. Only ISA changes, as well as the P&S
   740             cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0);
   762             cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0);
   741             RDEBUG("cRresult", cRresult);
   763             RDEBUG("cRresult", cRresult);
   742             }
   764             }
   746                 {
   768                 {
   747                 err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardLocked);
   769                 err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardLocked);
   748                 RDEBUG("KAknKeyguardStatus err", err);
   770                 RDEBUG("KAknKeyguardStatus err", err);
   749                 err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
   771                 err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
   750                 RDEBUG("KCoreAppUIsAutolockStatus err", err);
   772                 RDEBUG("KCoreAppUIsAutolockStatus err", err);
   751                 err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsLockOffRequest); // same for keyguard and devicelock
   773                 TurnLights(ESecurityUIsLightsLockOffRequest, aReason, 0x16);	// same for keyguard and devicelock
   752                 RDEBUG("KSecurityUIsLights err", err);
       
   753                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);
   774                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);
   754                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 1);
   775                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 1);
   755                 RDEBUG("cRresult", cRresult);
   776                 RDEBUG("cRresult", cRresult);
   756                 }
   777                 }
   757             else if (aReason >= EDevicelockActive)
   778             else if (aReason >= EDevicelockActive)
   758                 {
   779                 {
   759                 err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardAutolockEmulation); // Other candidates might be: EKeyguardLocked and EKeyguardNotActive
   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
   760                 RDEBUG("KAknKeyguardStatus err", err);
   781                 RDEBUG("KAknKeyguardStatus err", err);
   761                 err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EManualLocked);
   782                 err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EManualLocked);
   762                 RDEBUG("KCoreAppUIsAutolockStatus err", err);
   783                 RDEBUG("KCoreAppUIsAutolockStatus err", err);
   763                 err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsLockOffRequest);
   784                 TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x18);
   764                 RDEBUG(" KSecurityUIsLights err", err);
       
   765                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 1);
   785                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 1);
   766                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0); // keyguard disabled, so that user can type and DeviceF can be captured
   786                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0); // keyguard disabled, so that user can type and DeviceF can be captured
   767                 RDEBUG("cRresult", cRresult);
   787                 RDEBUG("cRresult", cRresult);
   768                 }
   788                 }
   769             }
   789             }
   837                 setLabelIcon(EKeyguardActive);
   857                 setLabelIcon(EKeyguardActive);
   838                 updateIndicator(EKeyguardActive);
   858                 updateIndicator(EKeyguardActive);
   839                 publishStatus(EKeyguardActive);
   859                 publishStatus(EKeyguardActive);
   840                 setLockDialog(aReason, 1);
   860                 setLockDialog(aReason, 1);
   841                 }
   861                 }
       
   862             // 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)
       
   864                {
       
   865                setLockDialog(aReason, 1);
       
   866                iTempDisableOnlyKeyguardBecauseIncomingCall=0;
       
   867              	 }
   842             }
   868             }
   843             break;
   869             break;
   844         case ELockAppDisableKeyguard: // 2
   870         case ELockAppDisableKeyguard: // 2
   845             {
   871             {
   846             errorInProcess = CheckIfLegal(ret);
   872             errorInProcess = CheckIfLegal(ret);
   852                 updateIndicator(ELockNotActive);
   878                 updateIndicator(ELockNotActive);
   853                 publishStatus(ELockNotActive);
   879                 publishStatus(ELockNotActive);
   854                 setLockDialog(aReason, 0);
   880                 setLockDialog(aReason, 0);
   855                 }
   881                 }
   856             }
   882             }
       
   883             RDEBUG("errorInProcess", errorInProcess);
       
   884             // Telephone might want to disnable only-keyguard during a call. Allow it. This means hiding the screensaver, not more.
       
   885             if(errorInProcess==KErrPermissionDenied)
       
   886             	{
       
   887 					    TInt aCallStatus;
       
   888 					    TInt err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, aCallStatus);
       
   889 					    RDEBUG("err", err);
       
   890 					    RDEBUG("aCallStatus", aCallStatus);
       
   891 							if (aCallStatus != EPSCTsyCallStateUninitialized && aCallStatus != EPSCTsyCallStateNone)
       
   892 								{
       
   893 								RDEBUG("allowing telephone to disable keyguard . Call setLockDialog 0", 0);
       
   894 								setLockDialog(aReason, 0);
       
   895 								iTempDisableOnlyKeyguardBecauseIncomingCall=1;
       
   896 								errorInProcess=KErrNone;
       
   897 								}
       
   898             	}
   857             break;
   899             break;
   858         case ELockAppEnableDevicelock: // 3
   900         case ELockAppEnableDevicelock: // 3
   859             {
   901             {
   860             errorInProcess = CheckIfLegal(ret);
   902             errorInProcess = CheckIfLegal(ret);
   861             DebugError(errorInProcess);
   903             DebugError(errorInProcess);
   886                     errorInProcess = KErrPermissionDenied;
   928                     errorInProcess = KErrPermissionDenied;
   887                 DebugError(errorInProcess);
   929                 DebugError(errorInProcess);
   888                 }
   930                 }
   889             if (errorInProcess == KErrNone)
   931             if (errorInProcess == KErrNone)
   890                 {
   932                 {
   891                 setLockDialog(aReason, 0); // hide temporarilly because HbDeviceMessageBox doesn't get in top of the Lock-icon. Thus, dismiss it.
   933                 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.
       
   935                 // setLockDialog(aReason, 0); // hide temporarilly because HbDeviceMessageBox doesn't get in top of the Lock-icon. Thus, dismiss it.
   892                 // do I need to enable touch? it seems to work without it
   936                 // do I need to enable touch? it seems to work without it
   893                 // in any case, lights are needed
   937                 // in any case, lights are needed
   894                 err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsQueryOnRequest);
   938                 TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x20);
   895                 RDEBUG("calling HbDeviceMessageBox::question", 0);
   939                 RDEBUG("calling HbDeviceMessageBox::question", 0);
   896                 bool value = true;
   940                 bool value = true;
   897                 // not sure whether this question is really needed. The UI doesn't say anything, so I remove it for now.
   941                 // not sure whether this question is really needed. The UI doesn't say anything, so I remove it for now.
   898                 // HbDeviceMessageBox::question("Disable Lock?");   // this doesn't block other events, so after return everything might be messed up.
   942                 // HbDeviceMessageBox::question("Disable Lock?");   // this doesn't block other events, so after return everything might be messed up.
   899                 RDEBUG("value", value);
   943                 RDEBUG("value", value);
   900                 if (!value)
   944                 if (!value)
   901                     errorInProcess = KErrCancel;
   945                     errorInProcess = KErrCancel;
   902                 }
   946                 }
   903             if (errorInProcess == KErrNone)
   947             if (errorInProcess == KErrNone)
   904                 {
   948                 {
   905                 setLockDialog(aReason, 0); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
   949                 RDEBUG("skip setLockDialog", 1);
       
   950                 // 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.
   906                 RDEBUG("calling AskValidSecCode", 0);
   952                 RDEBUG("calling AskValidSecCode", 0);
   907                 errorInProcess = AskValidSecCode(ELockAppDisableDevicelock);
   953                 errorInProcess = AskValidSecCode(ELockAppDisableDevicelock);
   908                 RDEBUG("errorInProcess", errorInProcess);
   954                 RDEBUG("errorInProcess", errorInProcess);
   909                 }
   955                 }
   910             if (errorInProcess == KErrNone)
   956             if (errorInProcess == KErrNone)
   913                 updateIndicator(ELockNotActive);
   959                 updateIndicator(ELockNotActive);
   914                 setLockDialog(aReason, 0);
   960                 setLockDialog(aReason, 0);
   915                 publishStatus(ELockNotActive);
   961                 publishStatus(ELockNotActive);
   916                 }
   962                 }
   917             if (errorInProcess != KErrNone)
   963             if (errorInProcess != KErrNone)
   918                 { // re-lock. For example, if password is wrong
   964                 { // re-lock. For example, if password is cancelled
   919                 if (iLockStatus >= EDevicelockActive) // this skips the case "unlocking although it wasn't locked"
   965                 if (iLockStatus >= EDevicelockActive) // this skips the case "unlocking although it wasn't locked"
   920                     setLockDialog(ELockAppEnableDevicelock, 1);
   966                     setLockDialog(ELockAppEnableDevicelock, 1);
   921                 }
   967                 }
   922             // this never shows a note
   968             // this never shows a note
   923             }
   969             }
  1030             err = iDeviceDialog->error();
  1076             err = iDeviceDialog->error();
  1031             RDEBUG("err", err);
  1077             RDEBUG("err", err);
  1032 
  1078 
  1033             TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsSecUIOriginatedUninitialized);
  1079             TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsSecUIOriginatedUninitialized);
  1034             RDEBUG("reset KSecurityUIsSecUIOriginatedQuery. err", err);
  1080             RDEBUG("reset KSecurityUIsSecUIOriginatedQuery. err", err);
       
  1081             handleScreensaverClosed();
       
  1082             TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x22);
  1035             // Cancel power key and application key capturing
  1083             // Cancel power key and application key capturing
  1036             groupWin.CancelCaptureKey(mPowerKeyCaptureHandle);
  1084             groupWin.CancelCaptureKey(mPowerKeyCaptureHandle);
  1037             groupWin.CancelCaptureKey(mApplicationKeyCaptureHandle);
  1085             groupWin.CancelCaptureKey(mApplicationKeyCaptureHandle);
  1038             groupWin.CancelCaptureLongKey(mApplicationLongKeyCaptureHandle);
  1086             groupWin.CancelCaptureLongKey(mApplicationLongKeyCaptureHandle);
  1039             RDEBUG("done CancelCaptureKey", 1);
  1087             RDEBUG("done CancelCaptureKey", 1);
  1066         static_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())->KeySounds()->LockContext();
  1114         static_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())->KeySounds()->LockContext();
  1067         RDEBUG("PushContextL Done", 0x92);
  1115         RDEBUG("PushContextL Done", 0x92);
  1068 
  1116 
  1069         // secUiOriginatedQuery should be ESecurityUIsSecUIOriginatedUninitialized . If not, the validation is not correctly filtering it
  1117         // secUiOriginatedQuery should be ESecurityUIsSecUIOriginatedUninitialized . If not, the validation is not correctly filtering it
  1070         QVariantMap params;
  1118         QVariantMap params;
  1071         TBool err;
  1119         TBool err=EFalse;
  1072 #define ESecUiTypeDeviceLock        0x00100000
  1120 #define ESecUiTypeDeviceLock        0x00100000
  1073 #define ESecUiTypeKeyguard          0x00200000
  1121 #define ESecUiTypeKeyguard          0x00200000
  1074 
  1122 
  1075         if (aReason == ELockAppEnableKeyguard)
  1123         if (aReason == ELockAppEnableKeyguard)
  1076             params.insert("type", ESecUiTypeKeyguard);
  1124             params.insert("type", ESecUiTypeKeyguard);
  1089                 RDEBUG("!!!!!!*********!!!!!!!! error: iDeviceDialog != NULL", 0);
  1137                 RDEBUG("!!!!!!*********!!!!!!!! error: iDeviceDialog != NULL", 0);
  1090                 }
  1138                 }
  1091             RDEBUG("creating iDeviceDialog", 0);
  1139             RDEBUG("creating iDeviceDialog", 0);
  1092             iDeviceDialog = new HbDeviceDialog(HbDeviceDialog::NoFlags, this);
  1140             iDeviceDialog = new HbDeviceDialog(HbDeviceDialog::NoFlags, this);
  1093             // in theory this is needed only for screensaver, not for LockIcon. But it doesn't harm
  1141             // in theory this is needed only for screensaver, not for LockIcon. But it doesn't harm
  1094             connect(iDeviceDialog, SIGNAL(dataReceived(QVariantMap)), SLOT(handleMessageFromScreensaver(QVariantMap)));
  1142             connect(iDeviceDialog, SIGNAL(dataReceived(QVariantMap)), SLOT(handleMessageFromScreensaver(QVariantMap)), Qt::QueuedConnection);	// Qt::QueuedConnection needed to avoid deadlock at waitForClosed
  1095             connect(iDeviceDialog, SIGNAL(deviceDialogClosed()), SLOT(handleScreensaverClosed()));
  1143             connect(iDeviceDialog, SIGNAL(deviceDialogClosed()), SLOT(handleScreensaverClosed()));
  1096             iDeviceDialogCreated = EDeviceDialogCreated;
  1144             iDeviceDialogCreated = EDeviceDialogCreated;
  1097             RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
  1145             RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
  1098             }
  1146             }
  1099         else
  1147         else
  1335             // contain the pixels shown in the active area of the screen. Currently, we
  1383             // contain the pixels shown in the active area of the screen. Currently, we
  1336             // pass a buffer filled with 0s, and this works fine on the reference
  1384             // pass a buffer filled with 0s, and this works fine on the reference
  1337             // hardware. However, according to display driver people, this doesn't
  1385             // hardware. However, according to display driver people, this doesn't
  1338             // work if the display component of the device doesn't have internal memory
  1386             // work if the display component of the device doesn't have internal memory
  1339             // which may be the case in some of our target devices.
  1387             // which may be the case in some of our target devices.
       
  1388 
       
  1389 			// handled now directly by screensaver
       
  1390 			/*
  1340             TUint16 *ptr = const_cast<TUint16 *> (mScreensaverPowerSavePixelBuffer->Ptr());
  1391             TUint16 *ptr = const_cast<TUint16 *> (mScreensaverPowerSavePixelBuffer->Ptr());
  1341             RDEBUG("switching screen power save on, number of visible rows", endRow-startRow);
  1392             RDEBUG("switching screen power save on, number of visible rows", endRow-startRow);
  1342             int err = mScreensaverPowerSave->Set(startRow, endRow, ptr);
  1393             int err = mScreensaverPowerSave->Set(startRow, endRow, ptr);
  1343             RDEBUG("err", err);
  1394             RDEBUG("err", err);
       
  1395             */
  1344             }
  1396             }
  1345         else
  1397         else
  1346             {
  1398             {
  1347             // any other case is interpreted as an order to switch off the power save and
  1399             // any other case is interpreted as an order to switch off the power save and
  1348             // return to the normal mode
  1400             // return to the normal mode
  1349             RDEBUG("switching screen power save off 0", 0);
  1401             RDEBUG("switching screen power save off 0", 0);
  1350             int err = mScreensaverPowerSave->Exit();
  1402             // handled now directly by screensaver
  1351             RDEBUG("err", err);
  1403             // int err = mScreensaverPowerSave->Exit();
       
  1404             // RDEBUG("err", err);
  1352             }
  1405             }
  1353         }
  1406         }
  1354     }
  1407     }
  1355 
  1408 
  1356 void Autolock::handleScreensaverClosed()
  1409 void Autolock::handleScreensaverClosed()
  1358     RDEBUG("0", 0);
  1411     RDEBUG("0", 0);
  1359     int err(0);
  1412     int err(0);
  1360     // Screensaver (usually) cannot send anymore any commands when
  1413     // Screensaver (usually) cannot send anymore any commands when
  1361     // it's being closed. Thus, we need to ensure here that screen has lights and
  1414     // it's being closed. Thus, we need to ensure here that screen has lights and
  1362     // full-power mode once screensaver is closed.
  1415     // full-power mode once screensaver is closed.
       
  1416 
       
  1417     // handled now directly by screensaver
       
  1418     /*
  1363     if (mScreensaverPowerSave)
  1419     if (mScreensaverPowerSave)
  1364         {
  1420         {
  1365         RDEBUG("switching screen power save off", 0);
  1421         RDEBUG("switching screen power save off", 0);
  1366         err = mScreensaverPowerSave->Exit();
  1422         err = mScreensaverPowerSave->Exit();
  1367         RDEBUG("error=", err);
  1423         RDEBUG("error=", err);
  1368         }
  1424         }
       
  1425     */
  1369     RDEBUG("switching screen lights on", 1);
  1426     RDEBUG("switching screen lights on", 1);
  1370     err = RProperty::Set(KPSUidCoreApplicationUIs, KLightsSSForcedLightsOn, 30);
  1427     err = RProperty::Set(KPSUidCoreApplicationUIs, KLightsSSForcedLightsOn, 30);
  1371     RDEBUG("err", err);
  1428     RDEBUG("err", err);
  1372     }
  1429     }
  1373 
  1430 
  1394                 {
  1451                 {
  1395                 // switch to active screensaver if application key or power key pressed while screensaver active
  1452                 // switch to active screensaver if application key or power key pressed while screensaver active
  1396                 // This key can be repeated, so that the screensaver remains as long as key is pushed
  1453                 // This key can be repeated, so that the screensaver remains as long as key is pushed
  1397                 // TODO what happens when holding Power key ?
  1454                 // TODO what happens when holding Power key ?
  1398                 switchScreensaverMode( ESnsrViewTypeActive);
  1455                 switchScreensaverMode( ESnsrViewTypeActive);
       
  1456                 TurnLights(ESecurityUIsLightsQueryOnRequest, 0x22 /*aReason*/, 0x24);
  1399                 }
  1457                 }
  1400             else if (!keyEvent->isAutoRepeat())
  1458             else if (!keyEvent->isAutoRepeat())
  1401                 {
  1459                 {
  1402                 if (keyEvent->key() == EKeyInsert)
  1460                 if (keyEvent->key() == EKeyInsert)
  1403                     {
  1461                     {
  1484 	        {
  1542 	        {
  1485 	        RDEBUG("unknown iLockStatus", iLockStatus);
  1543 	        RDEBUG("unknown iLockStatus", iLockStatus);
  1486 	        }
  1544 	        }
  1487     	iProcessingEvent = 0;
  1545     	iProcessingEvent = 0;
  1488 	    }
  1546 	    }
       
  1547 	  else
       
  1548 	  	{
       
  1549 	  	// user presses side-switch while another is in process, most probably a unlock-query. Thus, re-switch on the lights
       
  1550 	  	if (iLockStatus == EDevicelockActive)
       
  1551 	  		{
       
  1552         TurnLights(ESecurityUIsLightsQueryOnRequest, ELockAppEnableDevicelock, 0x26);
       
  1553 	  		}
       
  1554 	  	}
  1489     RDEBUG("ret", ret);
  1555     RDEBUG("ret", ret);
  1490     return ret;
  1556     return ret;
  1491     }
  1557     }
  1492 
  1558 
  1493 bool Autolock::eventFilter(QObject *o, QEvent *ev)
  1559 bool Autolock::eventFilter(QObject *o, QEvent *ev)
  1577     TInt aCallStatus;
  1643     TInt aCallStatus;
  1578     TInt err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, aCallStatus);
  1644     TInt err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, aCallStatus);
  1579     RDEBUG("err", err);
  1645     RDEBUG("err", err);
  1580     RDEBUG("aCallStatus", aCallStatus);
  1646     RDEBUG("aCallStatus", aCallStatus);
  1581     RWindowGroup& groupWin = CEikonEnv::Static()->RootWin();
  1647     RWindowGroup& groupWin = CEikonEnv::Static()->RootWin();
       
  1648     RDEBUG("iLockStatus", iLockStatus);
  1582     if (aCallStatus == EPSCTsyCallStateUninitialized || aCallStatus == EPSCTsyCallStateNone)
  1649     if (aCallStatus == EPSCTsyCallStateUninitialized || aCallStatus == EPSCTsyCallStateNone)
  1583         {
  1650         {
  1584         RDEBUG("call is inactive", aCallStatus);
  1651         RDEBUG("call is inactive", aCallStatus);
  1585         RDEBUG("iLockStatus", iLockStatus);
       
  1586         if (iLockStatus == EKeyguardActive || iLockStatus == EDevicelockActive)
  1652         if (iLockStatus == EKeyguardActive || iLockStatus == EDevicelockActive)
  1587             {
  1653             {
  1588             if (!mEKeyYesCaptureHandle)
  1654             if (!mEKeyYesCaptureHandle)
  1589                 mEKeyYesCaptureHandle = groupWin.CaptureKey(EKeyYes, 0, 0);
  1655                 mEKeyYesCaptureHandle = groupWin.CaptureKey(EKeyYes, 0, 0);
  1590             if (!mEKeyNoCaptureHandle)
  1656             if (!mEKeyNoCaptureHandle)
  1606             {
  1672             {
  1607             RDEBUG("mEKeyNoCaptureHandle", mEKeyNoCaptureHandle);
  1673             RDEBUG("mEKeyNoCaptureHandle", mEKeyNoCaptureHandle);
  1608             groupWin.CancelCaptureKey(mEKeyNoCaptureHandle);
  1674             groupWin.CancelCaptureKey(mEKeyNoCaptureHandle);
  1609             mEKeyNoCaptureHandle = NULL;
  1675             mEKeyNoCaptureHandle = NULL;
  1610             }
  1676             }
       
  1677         // 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);
  1611         }
  1679         }
  1612     RDEBUG("9", 9);
  1680     RDEBUG("9", 9);
  1613     }
  1681     }
  1614 // SecUiNotificationDialog::subscriberKSecurityUIsDismissDialogChanged()
  1682 // SecUiNotificationDialog::subscriberKSecurityUIsDismissDialogChanged()
  1615 // A way for Autolock to dismiss any possible PIN dialog
  1683 // A way for Autolock to dismiss any possible PIN dialog