securitydialogs/Autolock/src/Autolock.cpp
changeset 56 25a3fbb5e4d3
parent 51 f479c7dc25d6
child 61 1cc4c46c2963
--- a/securitydialogs/Autolock/src/Autolock.cpp	Thu Sep 02 21:22:45 2010 +0300
+++ b/securitydialogs/Autolock/src/Autolock.cpp	Fri Sep 17 08:35:02 2010 +0300
@@ -62,7 +62,8 @@
 #include <ctsydomainpskeys.h>
 
 #include <hbdevicedialog.h>
-#include <power_save_display_mode.h>
+// handled now directly but screensaver
+// #include <power_save_display_mode.h>
 
 const TInt KPhoneIndex(0);
 const TInt KTriesToConnectServer(2);
@@ -238,6 +239,8 @@
     RDEBUG("mEKeyBellCaptureHandle", mEKeyBellCaptureHandle);
     RDEBUG("got mKeyCaptureHandle", 1);
 
+		iTempDisableOnlyKeyguardBecauseIncomingCall=0;
+		
     iSecQueryUiCreated = -1;
     iDeviceDialogCreated = EDeviceDialogUninitialized;
     RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
@@ -249,7 +252,7 @@
     hide();
 
     iDeviceDialog = new HbDeviceDialog(HbDeviceDialog::NoFlags, this);
-    connect(iDeviceDialog, SIGNAL(dataReceived(QVariantMap)), SLOT(handleMessageFromScreensaver(QVariantMap)));
+    connect(iDeviceDialog, SIGNAL(dataReceived(QVariantMap)), SLOT(handleMessageFromScreensaver(QVariantMap)), Qt::QueuedConnection);	// Qt::QueuedConnection needed to avoid deadlock at waitForClosed
     connect(iDeviceDialog, SIGNAL(deviceDialogClosed()), SLOT(handleScreensaverClosed()));
 
     // screensaver standby mode timer
@@ -257,17 +260,20 @@
     mScreensaverModeTimer->setInterval(5 * 1000); // milliseconds, TODO: read from cenrep
     connect(mScreensaverModeTimer, SIGNAL(timeout()), SLOT(switchScreensaverToPowerSaveMode()));
     // screensaver AMOLED low power mode support
-    mScreensaverPowerSave = CPowerSaveDisplayMode::NewL();
-    mScreensaverPowerSavePixelBuffer = HBufC16::NewL(360 * 640);
-    mScreensaverPowerSavePixelBuffer->Des().Fill(0);
+
+    // handled now directly but screensaver
+    // mScreensaverPowerSave = CPowerSaveDisplayMode::NewL();
+    // mScreensaverPowerSavePixelBuffer = HBufC16::NewL(360 * 640);
+    // mScreensaverPowerSavePixelBuffer->Des().Fill(0);
     }
 
 Autolock::~Autolock()
     {
     RDEBUG("0", 0);
     delete mService;
-    delete mScreensaverPowerSave;
-    delete mScreensaverPowerSavePixelBuffer;
+    // handled now directly but screensaver
+    // delete mScreensaverPowerSave;
+    // delete mScreensaverPowerSavePixelBuffer;
     RDEBUG("1", 1);
     }
 
@@ -285,7 +291,7 @@
     RDEBUG("KSettingsAutomaticKeyguardTime", KSettingsAutomaticKeyguardTime);
     RDEBUG("cRresult", cRresult);
     RDEBUG("keyguardTime", keyguardTime);
-    if (keyguardTime > 0 && keyguardTime < 1000)
+    if (keyguardTime > 2 && keyguardTime < 24 * 60 * 60)
         {
         serviceKeyguard->setInactivityPeriod(keyguardTime);
         }
@@ -300,13 +306,20 @@
     RDEBUG("cRresult", cRresult);
     RDEBUG("lockTime", lockTime);
     if (lockTime == 65535 * 60) // Special setting "lock at same time as keyguard" at CpDeviceLockPluginView::GetAutoLockIndex which uses this magic number
-        lockTime = keyguardTime - 2; // lock 2 seconds before before, to avoid keyguard->devicelock sequence
-    if (lockTime > 60 && lockTime < 24 * 60 * 60) // lock timer can't be bigger than 1 day
+    		{
+        lockTime = keyguardTime - 2; // lock 2 seconds before keyguard, to avoid keyguard->devicelock sequence
+        if(lockTime<=2)
+        	lockTime=2;
+        RDEBUG("new lockTime", lockTime);
+      	}
+    if (lockTime >= 2 && lockTime < 24 * 60 * 60) // lock timer can't be bigger than 1 day
         {
+        RDEBUG("setInactivityPeriod lockTime", lockTime);
         serviceDevicelock->setInactivityPeriod(lockTime);
         }
     else
         {
+        RDEBUG("setInactivityPeriod infinite", lockTime);
         serviceDevicelock->setInactivityPeriod(12 * 31 * 24 * 60 * 60); // 0x1ea6e00
         }
 
@@ -318,6 +331,16 @@
     qApp->quit();
     }
 
+
+int Autolock::TurnLights(int aMode, int aReason, int aCaller)
+    {
+    RDEBUG("aMode", aMode);
+    RDEBUG("aReason", aReason);
+    RDEBUG("aCaller", aCaller);
+    TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, aMode);
+    RDEBUG("KSecurityUIsLights err", err);
+    return err;
+  	}
 int Autolock::AskValidSecCode(int aReason)
     {
     RDEBUG("aReason", aReason);
@@ -333,8 +356,7 @@
     TInt thisTry(0);
     RTelServer iTelServer;
 
-    err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsQueryOnRequest);
-    RDEBUG("KSecurityUIsLights err", err);
+    TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x10);
 
     RMmCustomAPI iCustomPhone;
     while ((err = iTelServer.Connect()) != KErrNone && (thisTry++) <= KTriesToConnectServer)
@@ -465,8 +487,7 @@
         return KErrNone;
 
     // no valid code -> switch off the lights
-    err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsLockOffRequest);
-    RDEBUG("KSecurityUIsLights err", err);
+    TurnLights(ESecurityUIsLightsLockOffRequest, aReason, 0x12);
     return KErrCancel;
     }
 
@@ -635,6 +656,8 @@
             if (iLockCodeQueryInDisplay)
                 {
                 // PIN on top and trying to display unlock-code. This is valid
+                // but needs to turn on lights because SysAp switches them off even if query is present
+                TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x13);
                 return KErrAlreadyExists;
                 }
             switch (iLockStatus)
@@ -733,8 +756,7 @@
             RDEBUG("err", err);
             err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
             RDEBUG("err", err);
-            err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsLockOnRequest); // lights are required
-            RDEBUG("KSecurityUIsLights err", err);
+            TurnLights(ESecurityUIsLightsLockOnRequest, aReason, 0x14);
 
             // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);    // the settings remains. Only ISA changes, as well as the P&S
             cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0);
@@ -748,20 +770,18 @@
                 RDEBUG("KAknKeyguardStatus err", err);
                 err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
                 RDEBUG("KCoreAppUIsAutolockStatus err", err);
-                err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsLockOffRequest); // same for keyguard and devicelock
-                RDEBUG("KSecurityUIsLights err", err);
+                TurnLights(ESecurityUIsLightsLockOffRequest, aReason, 0x16);	// same for keyguard and devicelock
                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);
                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 1);
                 RDEBUG("cRresult", cRresult);
                 }
             else if (aReason >= EDevicelockActive)
                 {
-                err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardAutolockEmulation); // Other candidates might be: EKeyguardLocked and EKeyguardNotActive
+                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
                 RDEBUG("KAknKeyguardStatus err", err);
                 err = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EManualLocked);
                 RDEBUG("KCoreAppUIsAutolockStatus err", err);
-                err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsLockOffRequest);
-                RDEBUG(" KSecurityUIsLights err", err);
+                TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x18);
                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 1);
                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0); // keyguard disabled, so that user can type and DeviceF can be captured
                 RDEBUG("cRresult", cRresult);
@@ -839,6 +859,12 @@
                 publishStatus(EKeyguardActive);
                 setLockDialog(aReason, 1);
                 }
+            // Telephone might want to re-enable only-keyguard after the call ends. Allow it. This means re-showing the screensaver, not more.
+						if (errorInProcess == KErrPermissionDenied && iTempDisableOnlyKeyguardBecauseIncomingCall==1)
+               {
+               setLockDialog(aReason, 1);
+               iTempDisableOnlyKeyguardBecauseIncomingCall=0;
+             	 }
             }
             break;
         case ELockAppDisableKeyguard: // 2
@@ -854,6 +880,22 @@
                 setLockDialog(aReason, 0);
                 }
             }
+            RDEBUG("errorInProcess", errorInProcess);
+            // Telephone might want to disnable only-keyguard during a call. Allow it. This means hiding the screensaver, not more.
+            if(errorInProcess==KErrPermissionDenied)
+            	{
+					    TInt aCallStatus;
+					    TInt err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, aCallStatus);
+					    RDEBUG("err", err);
+					    RDEBUG("aCallStatus", aCallStatus);
+							if (aCallStatus != EPSCTsyCallStateUninitialized && aCallStatus != EPSCTsyCallStateNone)
+								{
+								RDEBUG("allowing telephone to disable keyguard . Call setLockDialog 0", 0);
+								setLockDialog(aReason, 0);
+								iTempDisableOnlyKeyguardBecauseIncomingCall=1;
+								errorInProcess=KErrNone;
+								}
+            	}
             break;
         case ELockAppEnableDevicelock: // 3
             {
@@ -888,10 +930,12 @@
                 }
             if (errorInProcess == KErrNone)
                 {
-                setLockDialog(aReason, 0); // hide temporarilly because HbDeviceMessageBox doesn't get in top of the Lock-icon. Thus, dismiss it.
+                RDEBUG("skip setLockDialog", 0);
+                // No need to disable screensaver. Notes now can get on top. Also, this avoids the transition Screensaver->unlockQuery, which produces flicker on HomeScreen.
+                // setLockDialog(aReason, 0); // hide temporarilly because HbDeviceMessageBox doesn't get in top of the Lock-icon. Thus, dismiss it.
                 // do I need to enable touch? it seems to work without it
                 // in any case, lights are needed
-                err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLights, ESecurityUIsLightsQueryOnRequest);
+                TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x20);
                 RDEBUG("calling HbDeviceMessageBox::question", 0);
                 bool value = true;
                 // not sure whether this question is really needed. The UI doesn't say anything, so I remove it for now.
@@ -902,7 +946,9 @@
                 }
             if (errorInProcess == KErrNone)
                 {
-                setLockDialog(aReason, 0); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
+                RDEBUG("skip setLockDialog", 1);
+                // No need to disable screensaver. Notes now can get on top. Also, this avoids the transition Screensaver->unlockQuery, which produces flicker on HomeScreen.
+                // setLockDialog(aReason, 0); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
                 RDEBUG("calling AskValidSecCode", 0);
                 errorInProcess = AskValidSecCode(ELockAppDisableDevicelock);
                 RDEBUG("errorInProcess", errorInProcess);
@@ -915,7 +961,7 @@
                 publishStatus(ELockNotActive);
                 }
             if (errorInProcess != KErrNone)
-                { // re-lock. For example, if password is wrong
+                { // re-lock. For example, if password is cancelled
                 if (iLockStatus >= EDevicelockActive) // this skips the case "unlocking although it wasn't locked"
                     setLockDialog(ELockAppEnableDevicelock, 1);
                 }
@@ -1032,6 +1078,8 @@
 
             TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsSecUIOriginatedUninitialized);
             RDEBUG("reset KSecurityUIsSecUIOriginatedQuery. err", err);
+            handleScreensaverClosed();
+            TurnLights(ESecurityUIsLightsQueryOnRequest, aReason, 0x22);
             // Cancel power key and application key capturing
             groupWin.CancelCaptureKey(mPowerKeyCaptureHandle);
             groupWin.CancelCaptureKey(mApplicationKeyCaptureHandle);
@@ -1068,7 +1116,7 @@
 
         // secUiOriginatedQuery should be ESecurityUIsSecUIOriginatedUninitialized . If not, the validation is not correctly filtering it
         QVariantMap params;
-        TBool err;
+        TBool err=EFalse;
 #define ESecUiTypeDeviceLock        0x00100000
 #define ESecUiTypeKeyguard          0x00200000
 
@@ -1091,7 +1139,7 @@
             RDEBUG("creating iDeviceDialog", 0);
             iDeviceDialog = new HbDeviceDialog(HbDeviceDialog::NoFlags, this);
             // in theory this is needed only for screensaver, not for LockIcon. But it doesn't harm
-            connect(iDeviceDialog, SIGNAL(dataReceived(QVariantMap)), SLOT(handleMessageFromScreensaver(QVariantMap)));
+            connect(iDeviceDialog, SIGNAL(dataReceived(QVariantMap)), SLOT(handleMessageFromScreensaver(QVariantMap)), Qt::QueuedConnection);	// Qt::QueuedConnection needed to avoid deadlock at waitForClosed
             connect(iDeviceDialog, SIGNAL(deviceDialogClosed()), SLOT(handleScreensaverClosed()));
             iDeviceDialogCreated = EDeviceDialogCreated;
             RDEBUG("new iDeviceDialogCreated", iDeviceDialogCreated);
@@ -1337,18 +1385,23 @@
             // hardware. However, according to display driver people, this doesn't
             // work if the display component of the device doesn't have internal memory
             // which may be the case in some of our target devices.
+
+			// handled now directly by screensaver
+			/*
             TUint16 *ptr = const_cast<TUint16 *> (mScreensaverPowerSavePixelBuffer->Ptr());
             RDEBUG("switching screen power save on, number of visible rows", endRow-startRow);
             int err = mScreensaverPowerSave->Set(startRow, endRow, ptr);
             RDEBUG("err", err);
+            */
             }
         else
             {
             // any other case is interpreted as an order to switch off the power save and
             // return to the normal mode
             RDEBUG("switching screen power save off 0", 0);
-            int err = mScreensaverPowerSave->Exit();
-            RDEBUG("err", err);
+            // handled now directly by screensaver
+            // int err = mScreensaverPowerSave->Exit();
+            // RDEBUG("err", err);
             }
         }
     }
@@ -1360,12 +1413,16 @@
     // Screensaver (usually) cannot send anymore any commands when
     // it's being closed. Thus, we need to ensure here that screen has lights and
     // full-power mode once screensaver is closed.
+
+    // handled now directly by screensaver
+    /*
     if (mScreensaverPowerSave)
         {
         RDEBUG("switching screen power save off", 0);
         err = mScreensaverPowerSave->Exit();
         RDEBUG("error=", err);
         }
+    */
     RDEBUG("switching screen lights on", 1);
     err = RProperty::Set(KPSUidCoreApplicationUIs, KLightsSSForcedLightsOn, 30);
     RDEBUG("err", err);
@@ -1396,6 +1453,7 @@
                 // This key can be repeated, so that the screensaver remains as long as key is pushed
                 // TODO what happens when holding Power key ?
                 switchScreensaverMode( ESnsrViewTypeActive);
+                TurnLights(ESecurityUIsLightsQueryOnRequest, 0x22 /*aReason*/, 0x24);
                 }
             else if (!keyEvent->isAutoRepeat())
                 {
@@ -1486,6 +1544,14 @@
 	        }
     	iProcessingEvent = 0;
 	    }
+	  else
+	  	{
+	  	// user presses side-switch while another is in process, most probably a unlock-query. Thus, re-switch on the lights
+	  	if (iLockStatus == EDevicelockActive)
+	  		{
+        TurnLights(ESecurityUIsLightsQueryOnRequest, ELockAppEnableDevicelock, 0x26);
+	  		}
+	  	}
     RDEBUG("ret", ret);
     return ret;
     }
@@ -1579,10 +1645,10 @@
     RDEBUG("err", err);
     RDEBUG("aCallStatus", aCallStatus);
     RWindowGroup& groupWin = CEikonEnv::Static()->RootWin();
+    RDEBUG("iLockStatus", iLockStatus);
     if (aCallStatus == EPSCTsyCallStateUninitialized || aCallStatus == EPSCTsyCallStateNone)
         {
         RDEBUG("call is inactive", aCallStatus);
-        RDEBUG("iLockStatus", iLockStatus);
         if (iLockStatus == EKeyguardActive || iLockStatus == EDevicelockActive)
             {
             if (!mEKeyYesCaptureHandle)
@@ -1608,6 +1674,8 @@
             groupWin.CancelCaptureKey(mEKeyNoCaptureHandle);
             mEKeyNoCaptureHandle = NULL;
             }
+        // it seems that Telephone doesn't turn-on the lights when an incoming call on deviceLock. It's done here.
+        TurnLights(ESecurityUIsLightsQueryOnRequest, ELockAppDisableKeyguard, 0x28);
         }
     RDEBUG("9", 9);
     }