securitydialogs/AutolockSrv/src/AutolockSrv.cpp
changeset 19 098e361762d2
parent 17 8957df7b0072
child 22 6b63ca65093a
equal deleted inserted replaced
17:8957df7b0072 19:098e361762d2
    43 QTM_USE_NAMESPACE
    43 QTM_USE_NAMESPACE
    44 
    44 
    45 #include <HbIndicator>
    45 #include <HbIndicator>
    46 #include <hbdevicemessagebox.h>
    46 #include <hbdevicemessagebox.h>
    47 
    47 
    48 #include "../../SecUi/inc/SecQueryUi.h"
       
    49 
       
    50 #include <lockappclientserver.h>
    48 #include <lockappclientserver.h>
    51 
    49 
    52 #include <xqsharablefile.h>
    50 #include <xqsharablefile.h>
    53 
    51 
    54 #include <QGraphicsLinearLayout>
    52 #include <QGraphicsLinearLayout>
    59 #include <xqserviceutil.h>
    57 #include <xqserviceutil.h>
    60 
    58 
    61 #include "autolockuseractivityservice.h"
    59 #include "autolockuseractivityservice.h"
    62 
    60 
    63 #include <settingsinternalcrkeys.h>		// CenRep keys
    61 #include <settingsinternalcrkeys.h>		// CenRep keys
    64 
       
    65 #include <W32STD.H>
    62 #include <W32STD.H>
    66 #include <eikenv.h>
    63 #include <eikenv.h>
    67 
    64 
    68 #include <qapplication.h>
    65 #include <qapplication.h>
    69 
    66 
    82 #include "../../../inc/securityuisprivatepskeys.h"
    79 #include "../../../inc/securityuisprivatepskeys.h"
    83 #include <avkondomainpskeys.h>
    80 #include <avkondomainpskeys.h>
    84 
    81 
    85 #include <hbdevicedialog.h>
    82 #include <hbdevicedialog.h>
    86 
    83 
    87 const TInt KPhoneIndex( 0 );
    84 const TInt KPhoneIndex(0);
    88 const TInt KTriesToConnectServer( 2 );
    85 const TInt KTriesToConnectServer(2);
    89 const TInt KTimeBeforeRetryingServerConnection( 50000 );
    86 const TInt KTimeBeforeRetryingServerConnection(50000);
    90 
    87 
    91 #define ESecUiTypeLock					0x00100000
    88 #define ESecUiTypeLock					0x00100000
    92 
    89 
    93 _LIT( KMmTsyModuleName, "PhoneTsy"); 
    90 _LIT( KMmTsyModuleName, "PhoneTsy");
    94 
       
    95 
    91 
    96 #define XQSERVICE_DEBUG_PRINT(a) qDebug() << (a)
    92 #define XQSERVICE_DEBUG_PRINT(a) qDebug() << (a)
    97 
    93 
    98 AutolockSrv::AutolockSrv(QWidget *parent, Qt::WFlags f)
    94 AutolockSrv::AutolockSrv(QWidget *parent, Qt::WFlags f) :
    99     : QWidget(parent, f),
    95     QWidget(parent, f), mService(NULL)
   100       mService(NULL)
    96     {
   101 {
       
   102     XQSERVICE_DEBUG_PRINT("AutolockSrv::AutolockSrv");
    97     XQSERVICE_DEBUG_PRINT("AutolockSrv::AutolockSrv");
   103     	RDEBUG( "start", 0 );
    98     RDEBUG("start", 0);
   104     mService = new AutolockSrvService(this);
    99     mService = new AutolockSrvService(this);
   105 
   100 
   106     /* Adjust the palette */
   101     /* Adjust the palette */
   107 #if defined(Q_WS_S60)
   102 #if defined(Q_WS_S60)
   108     	RDEBUG( "Q_WS_S60", 1 );
   103     RDEBUG( "Q_WS_S60", 1 );
   109     QPalette p = qApp->palette();
   104     QPalette p = qApp->palette();
   110     QColor color(192,192,192);
   105     QColor color(192,192,192);
   111     QColor bg(201,250,250);
   106     QColor bg(201,250,250);
   112     p.setColor(QPalette::Highlight, color.lighter(200));
   107     p.setColor(QPalette::Highlight, color.lighter(200));
   113     p.setColor(QPalette::Text, Qt::black);
   108     p.setColor(QPalette::Text, Qt::black);
   131     connect(lockButton, SIGNAL(clicked()), this, SLOT(lockAction()));
   126     connect(lockButton, SIGNAL(clicked()), this, SLOT(lockAction()));
   132     connect(unlockButton, SIGNAL(clicked()), this, SLOT(unlockAction()));
   127     connect(unlockButton, SIGNAL(clicked()), this, SLOT(unlockAction()));
   133     connect(unguardButton, SIGNAL(clicked()), this, SLOT(unguardAction()));
   128     connect(unguardButton, SIGNAL(clicked()), this, SLOT(unguardAction()));
   134     connect(test1Button, SIGNAL(clicked()), this, SLOT(test1Action()));
   129     connect(test1Button, SIGNAL(clicked()), this, SLOT(test1Action()));
   135     connect(test2Button, SIGNAL(clicked()), this, SLOT(test2Action()));
   130     connect(test2Button, SIGNAL(clicked()), this, SLOT(test2Action()));
   136 			RDEBUG( "connect", 1 );
   131     RDEBUG("connect", 1);
   137 
   132 
   138 		/* there's no use for this */
   133     /* there's no use for this */
   139 		/*
   134     /*
   140     bool isService = XQServiceUtil::isService();
   135      bool isService = XQServiceUtil::isService();
   141     
   136      
   142     QString t = "SERVICEAPP:\n";
   137      QString t = "SERVICEAPP:\n";
   143     t = t + (isService ?  "    LAUNCHED AS SERVICE\n" : "    LAUNCHED NORMALLY\n");
   138      t = t + (isService ?  "    LAUNCHED AS SERVICE\n" : "    LAUNCHED NORMALLY\n");
   144     t = t + (XQServiceUtil::isEmbedded() ? "    EMBEDDED\n" : "    NOT EMBEDDED\n");
   139      t = t + (XQServiceUtil::isEmbedded() ? "    EMBEDDED\n" : "    NOT EMBEDDED\n");
   145     
   140      
   146     QStringList args = QApplication::arguments();
   141      QStringList args = QApplication::arguments();
   147     foreach (QString arg, args)
   142      foreach (QString arg, args)
   148     {
   143      {
   149         t += "cmdline arg=" + arg + "\n";
   144      t += "cmdline arg=" + arg + "\n";
   150     }
   145      }
   151     
   146      
   152     QLabel *title = new QLabel(t);
   147      QLabel *title = new QLabel(t);
   153     */
   148      */
   154 
   149 
   155     mLabel = new QLabel("");
   150     mLabel = new QLabel("");
   156     mNumberEdit = new QLineEdit("");
   151     mNumberEdit = new QLineEdit("");
   157     
   152 
   158     QVBoxLayout *vl = new QVBoxLayout;
   153     QVBoxLayout *vl = new QVBoxLayout;
       
   154     RDEBUG("QVBoxLayout", 1);
   159 
   155 
   160     vl->setMargin(0);
   156     vl->setMargin(0);
   161     vl->setSpacing(0);
   157     vl->setSpacing(0);
       
   158     RDEBUG("setSpacing", 1);
   162 
   159 
   163     vl->addWidget(lockButton);
   160     vl->addWidget(lockButton);
   164     vl->addWidget(unlockButton);
   161     vl->addWidget(unlockButton);
   165     vl->addWidget(unguardButton);
   162     vl->addWidget(unguardButton);
   166     vl->addWidget(quitButton);
   163     vl->addWidget(quitButton);
   167     vl->addWidget(test1Button);
   164     vl->addWidget(test1Button);
   168     vl->addWidget(test2Button);
   165     vl->addWidget(test2Button);
   169  			RDEBUG( "added test2Button", 1 );
   166     RDEBUG("added test2Button", 1);
   170 
   167 
   171     mLabelIcon = new QToolButton;
   168     mLabelIcon = new QToolButton;
   172 		mLabelIcon->setIcon(QIcon(":/AutolockSrv_hbicon/qtg_large_device_lock.svg"));
   169     mLabelIcon->setIcon(QIcon(
   173 		mLabelIcon->setIconSize(QSize(300,300));
   170             ":/AutolockSrv_hbicon/qtg_large_device_lock.svg"));
   174     
   171     mLabelIcon->setIconSize(QSize(300, 300));
       
   172 
   175     vl->addWidget(mLabelIcon);
   173     vl->addWidget(mLabelIcon);
   176  			RDEBUG( "added mLabelIcon", 1 );
   174     RDEBUG("added mLabelIcon", 1);
   177 
   175 
   178 /*    vl->addItem(title);
   176     /*    vl->addItem(title);
   179     vl->addWidget(mLabel);
   177      vl->addWidget(mLabel);
   180     vl->addWidget(mNumberEdit);
   178      vl->addWidget(mNumberEdit);
   181 */
   179      */
   182     setLayout(vl);
   180     setLayout(vl);
   183    
   181 
   184 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
   182 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
   185     setFixedSize(QSize(360,640)); // nHD
   183     setFixedSize(QSize(360,640)); // nHD
   186 #elif defined(Q_WS_S60)
   184 #elif defined(Q_WS_S60)
   187     // showMaximized();
   185     // showMaximized();
   188     showFullScreen();
   186     showFullScreen();
   189 #endif
   187 #endif
   190 		mLabelIcon_visible=1;
   188     mLabelIcon_visible = 1;
   191 		serviceKeyguard = new AutolockUserActivityService();
   189     serviceKeyguard = new AutolockUserActivityService();
   192 		serviceDevicelock = new AutolockUserActivityService();
   190     serviceDevicelock = new AutolockUserActivityService();
   193 
   191 
   194 		TInt lockValue = 0;
   192     TInt lockValue = 0;
   195 		TInt lightsTimeout = 0;
   193     TInt lightsTimeout = 0;
   196     CRepository* repository;
   194     CRepository* repository;
   197     TInt cRresult=0;
   195     TInt cRresult = 0;
   198     
   196 
   199  		iLockStatusPrev=ELockNotActive;
   197     iLockStatusPrev = ELockNotActive;
   200  		iLockStatus=ELockNotActive;
   198     iLockStatus = ELockNotActive;
   201     repository = CRepository::NewL(KCRUidSecuritySettings);
   199     repository = CRepository::NewL(KCRUidSecuritySettings);
   202     cRresult = repository->Get(KSettingsAutolockStatus, lockValue);
   200     cRresult = repository->Get(KSettingsAutolockStatus, lockValue);
   203     	RDEBUG( "KSettingsAutolockStatus", KSettingsAutolockStatus );
   201     RDEBUG("KSettingsAutolockStatus", KSettingsAutolockStatus);
   204     	RDEBUG( "cRresult", cRresult );
   202     RDEBUG("cRresult", cRresult);
   205     	RDEBUG( "lockValue", lockValue );
   203     RDEBUG("lockValue", lockValue);
   206     iLockStatus = lockValue;
   204     iLockStatus = lockValue;
   207     // the settings says to lock
   205     // the settings says to lock
   208     delete repository;
   206     delete repository;
   209     
   207 
   210     adjustInactivityTimers(0);
   208     adjustInactivityTimers(0);
   211 
   209 
   212     repository = CRepository::NewL(KCRUidProfileEngine);
   210     repository = CRepository::NewL(KCRUidProfileEngine);
   213     cRresult = repository->Get(KProEngActiveProfile, lightsTimeout);
   211     cRresult = repository->Get(KProEngActiveProfile, lightsTimeout);
   214     delete repository;
   212     delete repository;
   215 
   213 
   216     repository = CRepository::NewL(KCRUidLightSettings);
   214     repository = CRepository::NewL(KCRUidLightSettings);
   217     cRresult = repository->Get(KDisplayLightsTimeout, lightsTimeout);
   215     cRresult = repository->Get(KDisplayLightsTimeout, lightsTimeout);
   218     delete repository;
   216     delete repository;
   219 
   217 
   220 		// TODO flip
   218     // TODO flip
   221 		
   219 
   222 		subscriberKSettingsAutolockStatus = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutolockStatus", this);
   220     subscriberKSettingsAutolockStatus = new QValueSpaceSubscriber(
   223 		connect(subscriberKSettingsAutolockStatus, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutolockStatusChanged()));
   221             "/KCRUidSecuritySettings/KSettingsAutolockStatus", this);
   224 		subscriberKSettingsAutoLockTime = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutoLockTime", this);
   222     connect(subscriberKSettingsAutolockStatus, SIGNAL(contentsChanged()),
   225 		connect(subscriberKSettingsAutoLockTime, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutoLockTimeChanged()));
   223             this, SLOT(subscriberKSettingsAutolockStatusChanged()));
   226 		subscriberKSettingsAutomaticKeyguardTime = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutomaticKeyguardTime", this);
   224     subscriberKSettingsAutoLockTime = new QValueSpaceSubscriber(
   227 		connect(subscriberKSettingsAutomaticKeyguardTime, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutomaticKeyguardTimeChanged()));
   225             "/KCRUidSecuritySettings/KSettingsAutoLockTime", this);
   228 		subscriberKDisplayLightsTimeout = new QValueSpaceSubscriber("/KCRUidLightSettings/KDisplayLightsTimeout", this);
   226     connect(subscriberKSettingsAutoLockTime, SIGNAL(contentsChanged()), this,
   229 		connect(subscriberKDisplayLightsTimeout, SIGNAL(contentsChanged()), this, SLOT(subscriberKDisplayLightsTimeoutChanged()));
   227             SLOT(subscriberKSettingsAutoLockTimeChanged()));
   230 		subscriberKProEngActiveProfile = new QValueSpaceSubscriber("/KCRUidProfileEngine/KProEngActiveProfile", this);
   228     subscriberKSettingsAutomaticKeyguardTime = new QValueSpaceSubscriber(
   231 		connect(subscriberKProEngActiveProfile, SIGNAL(contentsChanged()), this, SLOT(subscriberKProEngActiveProfileChanged()));
   229             "/KCRUidSecuritySettings/KSettingsAutomaticKeyguardTime", this);
   232 
   230     connect(subscriberKSettingsAutomaticKeyguardTime, SIGNAL(
   233 
   231             contentsChanged()), this, SLOT(
   234 		TSecurityPolicy readPolicy( ECapabilityReadDeviceData );
   232             subscriberKSettingsAutomaticKeyguardTimeChanged()));
   235 		TSecurityPolicy writePolicy( ECapabilityWriteDeviceData );
   233     subscriberKDisplayLightsTimeout = new QValueSpaceSubscriber(
   236 		TInt ret = RProperty::Define( KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, RProperty::EInt, readPolicy, writePolicy );
   234             "/KCRUidLightSettings/KDisplayLightsTimeout", this);
   237     	RDEBUG( "defined KSecurityUIsSecUIOriginatedQuery", ret );
   235     connect(subscriberKDisplayLightsTimeout, SIGNAL(contentsChanged()), this,
   238     ret = RProperty::Define( KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, RProperty::EInt, readPolicy, writePolicy );
   236             SLOT(subscriberKDisplayLightsTimeoutChanged()));
   239     	RDEBUG( "defined KSecurityUIsQueryRequestCancel", ret );
   237     subscriberKProEngActiveProfile = new QValueSpaceSubscriber(
   240 
   238             "/KCRUidProfileEngine/KProEngActiveProfile", this);
   241     _LIT_SECURITY_POLICY_PASS(KReadPolicy);
   239     connect(subscriberKProEngActiveProfile, SIGNAL(contentsChanged()), this,
       
   240             SLOT(subscriberKProEngActiveProfileChanged()));
       
   241 
       
   242     TSecurityPolicy readPolicy(ECapabilityReadDeviceData);
       
   243     TSecurityPolicy writePolicy(ECapabilityWriteDeviceData);
       
   244     TInt ret = RProperty::Define(KPSUidSecurityUIs,
       
   245             KSecurityUIsSecUIOriginatedQuery, RProperty::EInt, readPolicy,
       
   246             writePolicy);
       
   247     RDEBUG("defined KSecurityUIsSecUIOriginatedQuery", ret);
       
   248     ret = RProperty::Define(KPSUidSecurityUIs,
       
   249             KSecurityUIsQueryRequestCancel, RProperty::EInt, readPolicy,
       
   250             writePolicy);
       
   251     RDEBUG("defined KSecurityUIsQueryRequestCancel", ret);
       
   252 
       
   253     _LIT_SECURITY_POLICY_PASS( KReadPolicy);
   242     _LIT_SECURITY_POLICY_C1(KWritePolicy, ECapabilityWriteDeviceData);
   254     _LIT_SECURITY_POLICY_C1(KWritePolicy, ECapabilityWriteDeviceData);
   243     ret = RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, RProperty::EInt, KReadPolicy, KWritePolicy);
   255     ret = RProperty::Define(KPSUidCoreApplicationUIs,
   244     	RDEBUG( "defined KCoreAppUIsAutolockStatus", ret );
   256             KCoreAppUIsAutolockStatus, RProperty::EInt, KReadPolicy,
   245 
   257             KWritePolicy);
   246     ret = RProperty::Define(KPSUidAvkonDomain, KAknKeyguardStatus, RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass), KWritePolicy);
   258     RDEBUG("defined KCoreAppUIsAutolockStatus", ret);
   247     	RDEBUG( "defined KAknKeyguardStatus", ret  );
   259 
   248     	
   260     ret = RProperty::Define(KPSUidAvkonDomain, KAknKeyguardStatus,
   249 		// inactivity
   261             RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass),
   250     connect(serviceKeyguard, SIGNAL(active()), this, SLOT(activeKeyguard()) );
   262             KWritePolicy);
   251     connect(serviceKeyguard, SIGNAL(notActive()), this, SLOT(notActiveKeyguard()) );
   263     RDEBUG("defined KAknKeyguardStatus", ret);
   252     connect(serviceDevicelock, SIGNAL(active()), this, SLOT(activeDevicelock()) );
   264 
   253     connect(serviceDevicelock, SIGNAL(notActive()), this, SLOT(notActiveDevicelock()) );
   265     ret = RProperty::Define(KPSUidSecurityUIs,
   254 
   266             KSecurityUIsLockInitiatorUID, RProperty::EInt, readPolicy,
   255 		RWindowGroup& groupWin=CEikonEnv::Static()->RootWin();
   267             writePolicy);
   256 			RDEBUG( "got groupWin", 1 );
   268     RDEBUG("defined KSecurityUIsLockInitiatorUID", ret);
       
   269 
       
   270     ret = RProperty::Define(KPSUidSecurityUIs,
       
   271             KSecurityUIsLockInitiatorTimeHigh, RProperty::EInt, readPolicy,
       
   272             writePolicy);
       
   273     RDEBUG("defined KSecurityUIsLockInitiatorTimeHigh", ret);
       
   274     ret = RProperty::Define(KPSUidSecurityUIs,
       
   275             KSecurityUIsLockInitiatorTimeLow, RProperty::EInt, readPolicy,
       
   276             writePolicy);
       
   277     RDEBUG("defined KSecurityUIsLockInitiatorTimeLow", ret);
       
   278 
       
   279     ret = RProperty::Define(KPSUidSecurityUIs, KSecurityUIsLights,
       
   280             RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass),
       
   281             TSecurityPolicy(TSecurityPolicy::EAlwaysPass));
       
   282     RDEBUG("defined KAknKeyguardStatus", ret);
       
   283 
       
   284     // inactivity
       
   285     connect(serviceKeyguard, SIGNAL(active()), this, SLOT(activeKeyguard()));
       
   286     connect(serviceKeyguard, SIGNAL(notActive()), this, SLOT(
       
   287             notActiveKeyguard()));
       
   288     connect(serviceDevicelock, SIGNAL(active()), this, SLOT(
       
   289             activeDevicelock()));
       
   290     connect(serviceDevicelock, SIGNAL(notActive()), this, SLOT(
       
   291             notActiveDevicelock()));
       
   292 
       
   293     RWindowGroup& groupWin = CEikonEnv::Static()->RootWin();
       
   294     RDEBUG("got groupWin", 1);
   257     // TODO if I want to release, I should do:   mKeyCaptureHandle = env->RootWin().CaptureKey(EKeyBackspace, 0, 0);
   295     // TODO if I want to release, I should do:   mKeyCaptureHandle = env->RootWin().CaptureKey(EKeyBackspace, 0, 0);
   258     groupWin.CaptureKey(EKeyBackspace,0,0);
   296     groupWin.CaptureKey(EKeyBackspace, 0, 0);
   259     groupWin.CaptureKey(EKeyDeviceF,0,0);
   297     groupWin.CaptureKey(EKeyDeviceF, 0, 0);
   260     groupWin.CaptureKey(EKeyBell,0,0);
   298     groupWin.CaptureKey(EKeyBell, 0, 0);
   261     groupWin.CaptureKey(EKeyTab,0,0);
   299     groupWin.CaptureKey(EKeyTab, 0, 0);
   262     groupWin.CaptureKey(EKeyInsert,0,0);
   300     groupWin.CaptureKey(EKeyInsert, 0, 0);
   263     	RDEBUG( "got mKeyCaptureHandle", 1 );
   301     RDEBUG("got mKeyCaptureHandle", 1);
   264 
   302 
   265 		iSecQueryUiCreated=-1;
   303     iSecQueryUiCreated = -1;
   266 		iDeviceDialogCreated = -1;
   304     iDeviceDialogCreated = -1;
   267 		// TODO for now, always starts unlocked
   305     // TODO for now, always starts unlocked
   268 		// TryChangeStatus(iLockStatus);
   306     // TryChangeStatus(iLockStatus);
   269 		TryChangeStatus(ELockNotActive);
   307     TryChangeStatus( ELockNotActive);
   270 		lower();
   308     lower();
   271     hide();
   309     hide();
   272 		// not needed:   new AutolockSrvService(this);
   310     // not needed:   new AutolockSrvService(this);
   273 }
   311     }
   274 
       
   275 
   312 
   276 AutolockSrv::~AutolockSrv()
   313 AutolockSrv::~AutolockSrv()
   277 {
   314     {
   278     	RDEBUG( "0", 0 );
   315     RDEBUG("0", 0);
   279     delete mService;
   316     delete mService;
   280 }
   317     }
   281 
   318 
   282 void AutolockSrv::adjustInactivityTimers(int aReason)
   319 void AutolockSrv::adjustInactivityTimers(int aReason)
   283 {
   320     {
   284     	RDEBUG( "aReason", aReason );
   321     RDEBUG("aReason", aReason);
   285 		TInt keyguardTime = 0;
   322     TInt keyguardTime = 0;
   286 		TInt lockTime = 0;
   323     TInt lockTime = 0;
   287     CRepository* repository;
   324     CRepository* repository;
   288 		TInt cRresult = 0;
   325     TInt cRresult = 0;
   289 
   326 
   290     repository = CRepository::NewL(KCRUidSecuritySettings);
   327     repository = CRepository::NewL(KCRUidSecuritySettings);
   291     cRresult = repository->Get(KSettingsAutoLockTime, lockTime);
   328     cRresult = repository->Get(KSettingsAutoLockTime, lockTime);	// in minutes, handled internally as seconds
   292     	RDEBUG( "KSettingsAutoLockTime", KSettingsAutoLockTime );
   329     lockTime *= 60;
   293     	RDEBUG( "cRresult", cRresult );
   330     RDEBUG("KSettingsAutoLockTime", KSettingsAutoLockTime);
   294     	RDEBUG( "lockTime", lockTime );
   331     RDEBUG("cRresult", cRresult);
   295     if(lockTime>0 && lockTime<1000)
   332     RDEBUG("lockTime", lockTime);
   296     	{
   333     if (lockTime > 60 && lockTime < 24*60*60)	// lock timer can't be bigger than 1 day
   297 			serviceDevicelock->setInactivityPeriod(lockTime);
   334         {
   298 			}
   335         serviceDevicelock->setInactivityPeriod(lockTime);
   299 		else
   336         }
   300 			{
   337     else
   301 			serviceDevicelock->setInactivityPeriod(12*31*24*60*60);
   338         {
   302 			}
   339         serviceDevicelock->setInactivityPeriod(12 * 31 * 24 * 60 * 60);	// 0x1ea6e00
   303 
   340         }
   304     cRresult = repository->Get(KSettingsAutomaticKeyguardTime, keyguardTime);
   341 
   305     	RDEBUG( "KSettingsAutomaticKeyguardTime", KSettingsAutomaticKeyguardTime );
   342     cRresult = repository->Get(KSettingsAutomaticKeyguardTime, keyguardTime);	// in seconds
   306     	RDEBUG( "cRresult", cRresult );
   343     RDEBUG("KSettingsAutomaticKeyguardTime", KSettingsAutomaticKeyguardTime);
   307     	RDEBUG( "keyguardTime", keyguardTime );
   344     RDEBUG("cRresult", cRresult);
   308     if(keyguardTime>0 && keyguardTime<1000)
   345     RDEBUG("keyguardTime", keyguardTime);
   309     	{
   346     if (keyguardTime > 0 && keyguardTime < 1000)
   310 			serviceKeyguard->setInactivityPeriod(keyguardTime);
   347         {
   311 			}
   348         serviceKeyguard->setInactivityPeriod(keyguardTime);
   312 		else
   349         }
   313 			{
   350     else
   314 			serviceKeyguard->setInactivityPeriod(12*31*24*60*60);
   351         {
   315 			}
   352         serviceKeyguard->setInactivityPeriod(12 * 31 * 24 * 60 * 60);
       
   353         }
   316     delete repository;
   354     delete repository;
   317 }
   355     }
   318 void AutolockSrv::quit()
   356 void AutolockSrv::quit()
   319 {
   357     {
   320 			RDEBUG( "0", 0 );
   358     RDEBUG("0", 0);
   321     qApp->quit();
   359     qApp->quit();
   322 }
   360     }
   323 
   361 
   324 // from the button
   362 // from the button
   325 void AutolockSrv::unlockAction()
   363 void AutolockSrv::unlockAction()
   326 {
   364     {
   327 			RDEBUG( "0", 0 );
   365     RDEBUG("0", 0);
   328     TryChangeStatus(ELockAppDisableDevicelock);
   366     TryChangeStatus( ELockAppDisableDevicelock);
   329 }
   367     }
   330 
   368 
   331 void AutolockSrv::unguardAction()
   369 void AutolockSrv::unguardAction()
   332 {
   370     {
   333 			RDEBUG( "0", 0 );
   371     RDEBUG("0", 0);
   334     TryChangeStatus(ELockAppDisableKeyguard);
   372     TryChangeStatus( ELockAppDisableKeyguard);
   335 }
   373     }
   336 
   374 
   337 void AutolockSrv::test1Action()
   375 void AutolockSrv::test1Action()
   338 {
   376     {
   339 			RDEBUG( "Set(KSettingsAutoLockTime, 30000)", 30000 );
   377     RDEBUG("Set(KSettingsAutoLockTime, 2)", 2);
   340 
   378 
   341     CRepository* repositorySet = CRepository::NewL(KCRUidSecuritySettings);
   379     CRepository* repositorySet = CRepository::NewL(KCRUidSecuritySettings);
   342     repositorySet->Set(KSettingsAutoLockTime, 10);
   380     repositorySet->Set(KSettingsAutoLockTime, 2);	// in minutes
   343     delete repositorySet;
   381     delete repositorySet;
   344 }
   382     }
   345 
   383 
   346 void AutolockSrv::test2Action()
   384 void AutolockSrv::test2Action()
   347 {
   385     {
   348 			RDEBUG( "Set(KSettingsAutoLockTime, 20000)", 20000 );
   386     RDEBUG("Set(KSettingsAutoLockTime, 0)", 0);
   349 
   387 
   350     CRepository* repositorySet = CRepository::NewL(KCRUidSecuritySettings);
   388     CRepository* repositorySet = CRepository::NewL(KCRUidSecuritySettings);
   351     repositorySet->Set(KSettingsAutoLockTime, 0);
   389     repositorySet->Set(KSettingsAutoLockTime, 0);	// minutes
   352     delete repositorySet;
   390     delete repositorySet;
   353 }
   391     }
   354 
   392 
   355 int AutolockSrv::AskValidSecCode(int aReason)
   393 int AutolockSrv::AskValidSecCode(int aReason)
   356 {
   394     {
   357 	RDEBUG( "aReason", aReason );
   395     RDEBUG("aReason", aReason);
   358 RMobilePhone	iPhone;	// NULL in emulator
   396     RMobilePhone iPhone; // NULL in emulator
   359 
   397 
   360 #ifdef __WINS__1
   398 #ifdef __WINS__1
   361 return KErrNone;
   399     return KErrNone;
   362 #endif
   400 #endif
   363 
   401 
   364 TInt err( KErrGeneral);
   402 
   365 TBool validCode(EFalse);
   403     TInt err(KErrGeneral);
   366 TInt thisTry( 0);
   404     TBool validCode(EFalse);
   367 RTelServer iTelServer;
   405     TInt thisTry(0);
   368 
   406     RTelServer iTelServer;
   369 RMmCustomAPI iCustomPhone;
   407 
   370 while ( ( err = iTelServer.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
   408     err = RProperty::Set(KPSUidSecurityUIs,
   371 	{
   409             KSecurityUIsLights, ESecurityUIsLightsQueryOnRequest);
   372 	User::After( KTimeBeforeRetryingServerConnection );
   410 		RDEBUG("KSecurityUIsLights err", err);
   373 	}
   411 
   374 err = iTelServer.LoadPhoneModule( KMmTsyModuleName );
   412     RMmCustomAPI iCustomPhone;
   375 RTelServer::TPhoneInfo PhoneInfo;
   413     while ((err = iTelServer.Connect()) != KErrNone && (thisTry++)
   376 		RDEBUG( "err", err );
   414             <= KTriesToConnectServer)
   377 err = iTelServer.SetExtendedErrorGranularity( RTelServer::EErrorExtended ) ;
   415         {
   378 		RDEBUG( "err", err );
   416         User::After( KTimeBeforeRetryingServerConnection);
   379 err = iTelServer.GetPhoneInfo( KPhoneIndex, PhoneInfo ) ;
   417         }
   380 		RDEBUG( "err", err );
   418     err = iTelServer.LoadPhoneModule(KMmTsyModuleName);
   381 err = iPhone.Open( iTelServer, PhoneInfo.iName ) ;
   419     RTelServer::TPhoneInfo PhoneInfo;
   382 		RDEBUG( "err", err );
   420     RDEBUG("err", err);
   383 err = iCustomPhone.Open( iPhone ) ;
   421     err = iTelServer.SetExtendedErrorGranularity(RTelServer::EErrorExtended);
   384 		RDEBUG( "err", err );
   422     RDEBUG("err", err);
   385 
   423     err = iTelServer.GetPhoneInfo(KPhoneIndex, PhoneInfo);
   386 	RDEBUG( "CSecurityHandler", 0 );
   424     RDEBUG("err", err);
   387 CSecurityHandler* handler = new(ELeave) CSecurityHandler(iPhone);
   425     err = iPhone.Open(iTelServer, PhoneInfo.iName);
   388 if(aReason==ELockAppDisableDevicelock)
   426     RDEBUG("err", err);
   389 	{
   427     err = iCustomPhone.Open(iPhone);
   390 		RDEBUG( "calling AskSecCodeInAutoLockL", 0 );
   428     RDEBUG("err", err);
   391 	validCode = handler->AskSecCodeInAutoLockL();	// this returns true/false
   429 
   392 	// TODO should this also do iPhone.SetLockSetting(status, lockType, lockChange); ???
   430     RDEBUG("CSecurityHandler", 0);
   393 	}
   431     CSecurityHandler* handler = new (ELeave) CSecurityHandler(iPhone);
   394 else if(aReason==ELockAppEnableDevicelock)
   432     if (aReason == ELockAppDisableDevicelock)
   395 	{
   433         {
   396 	// check whether code is really needed
   434         RDEBUG("calling AskSecCodeInAutoLockL", 0);
   397 	  RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
   435         validCode = handler->AskSecCodeInAutoLockL(); // this returns true/false
   398     RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
   436         // TODO should this also do iPhone.SetLockSetting(status, lockType, lockChange); ???
   399     RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
   437         }
   400     RMobilePhone::TMobilePhoneLockSetting lockChange(RMobilePhone::ELockSetDisabled);
   438     else if (aReason == ELockAppEnableDevicelock)
   401     TRequestStatus status = KRequestPending;
   439         {
   402     TInt ret=KErrNone;
   440         // check whether code is really needed
   403     	RDEBUG( "GetLockInfo", 0 );
   441         RMobilePhone::TMobilePhoneLock lockType =
   404     iPhone.GetLockInfo(status, lockType, lockInfoPkg);
   442                 RMobilePhone::ELockPhoneDevice;
   405     	RDEBUG( "WaitForRequest", 0 );
   443         RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
   406     User::WaitForRequest( status );
   444         RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
   407     ret = status.Int();
   445         RMobilePhone::TMobilePhoneLockSetting lockChange(
   408     	RDEBUG( "WaitForRequest ret", ret );
   446                 RMobilePhone::ELockSetDisabled);
   409     #ifdef __WINS__
   447         TRequestStatus status = KRequestPending;
   410     if(ret==KErrTimedOut)
   448         TInt ret = KErrNone;
   411     	{
   449         RDEBUG("GetLockInfo", 0);
   412 		  ret = KErrNone;
   450         iPhone.GetLockInfo(status, lockType, lockInfoPkg);
   413 			lockInfo.iSetting = RMobilePhone::ELockSetDisabled;	// ask password only if there's no timeout.
   451         RDEBUG("WaitForRequest", 0);
   414 			}
   452         User::WaitForRequest(status);
   415     #endif
   453         ret = status.Int();
   416     if(ret==KErrNone)
   454         RDEBUG("WaitForRequest ret", ret);
   417     	{
   455 #ifdef __WINS__
   418     		RDEBUG( "lockInfo.iSetting", lockInfo.iSetting );
   456         if(ret==KErrTimedOut)
   419     		RDEBUG( "RMobilePhone::ELockSetDisabled", RMobilePhone::ELockSetDisabled );
   457             {
   420     	if(lockInfo.iSetting == RMobilePhone::ELockSetDisabled)	// ask password only if there's no timeout
   458             ret = KErrNone;
   421     		{
   459             lockInfo.iSetting = RMobilePhone::ELockSetDisabled; // ask password only if there's no timeout.
   422 				lockChange = RMobilePhone::ELockSetEnabled;
   460             }
   423 					RDEBUG( "SetLockSetting lockChange", lockChange );
   461 #endif
   424 				#define OLD_METHODx
   462         if (ret == KErrNone)
   425 				#ifdef OLD_METHOD
   463             {
   426 					status = KRequestPending;
   464             RDEBUG("lockInfo.iSetting", lockInfo.iSetting);
   427 						RDEBUG( "SetLockSetting", 0 );
   465             RDEBUG("RMobilePhone::ELockSetDisabled",
   428 					iPhone.SetLockSetting(status, lockType, lockChange);	// ask for PassPhraseRequiredL
   466                     RMobilePhone::ELockSetDisabled);
   429 			    	RDEBUG( "WaitForRequestL", 0 );
   467             if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled) // ask password only if there's no timeout
   430 			    User::WaitForRequest( status );	// TODO this waits 33 seconds in WINS and returns ffffffdf = KErrTimedOut
   468                 {
   431 			    ret = status.Int();
   469                 lockChange = RMobilePhone::ELockSetEnabled;
   432 			    	RDEBUG( "WaitForRequestL ret", ret );
   470                 RDEBUG("SetLockSetting lockChange", lockChange);
   433 				#else
   471 #define OLD_METHODx
   434 						RDEBUG( "! OLD_METHOD", 0 );
   472 #ifdef OLD_METHOD
   435 					CWait *iWait = NULL;
   473                 status = KRequestPending;
   436 	    		iWait = CWait::NewL();
   474                 RDEBUG( "SetLockSetting", 0 );
   437 	   			iWait->SetRequestType(EMobilePhoneSetLockSetting);
   475                 iPhone.SetLockSetting(status, lockType, lockChange); // ask for PassPhraseRequiredL
   438 					iPhone.SetLockSetting(iWait->iStatus, lockType, lockChange);	// ask for PassPhraseRequiredL
   476                 RDEBUG( "WaitForRequestL", 0 );
   439 			    	RDEBUG( "WaitForRequestL", 0 );
   477                 User::WaitForRequest( status ); // TODO this waits 33 seconds in WINS and returns ffffffdf = KErrTimedOut
   440 		    	ret = iWait->WaitForRequestL();
   478                 ret = status.Int();
   441 			    	RDEBUG( "WaitForRequestL ret", ret );
   479                 RDEBUG( "WaitForRequestL ret", ret );
   442 					if(iWait)
   480 #else
   443 						{
   481                 RDEBUG("! OLD_METHOD", 0);
   444 							RDEBUG( "IsActive", 0 );
   482                 CWait *iWait = NULL;
   445 						if(iWait->IsActive())
   483                 iWait = CWait::NewL();
   446 							{
   484                 iWait->SetRequestType(EMobilePhoneSetLockSetting);
   447 								RDEBUG( "CancelAsyncRequest", 0 );
   485                 iPhone.SetLockSetting(iWait->iStatus, lockType, lockChange); // ask for PassPhraseRequiredL
   448 							iPhone.CancelAsyncRequest(iWait->GetRequestType());
   486                 RDEBUG("WaitForRequestL", 0);
   449 								RDEBUG( "cancelled", 0 );
   487                 ret = iWait->WaitForRequestL();
   450 						}
   488                 RDEBUG("WaitForRequestL ret", ret);
   451 					}
   489                 if (iWait)
   452 					delete iWait;
   490                     {
   453 				#endif
   491                     RDEBUG("IsActive", 0);
   454 				
   492                     if (iWait->IsActive())
   455 		    	RDEBUG( "WaitForRequestL ret", ret );
   493                         {
   456 		    #ifdef __WINS__
   494                         RDEBUG("CancelAsyncRequest", 0);
   457 		    if(ret==KErrTimedOut)
   495                         iPhone.CancelAsyncRequest(iWait->GetRequestType());
   458 		    	ret = KErrNone;
   496                         RDEBUG("cancelled", 0);
   459 		    #endif
   497                         }
   460 	    	if(ret==KErrNone)
   498                     }
   461 	    		validCode = 1;
   499                 delete iWait;
   462 	    	else
   500 #endif
   463 	    		validCode = 0;
   501 
   464 				}
   502                 RDEBUG("WaitForRequestL ret", ret);
   465 			else
   503 #ifdef __WINS__
   466 				validCode = 0x20;
   504                 if(ret==KErrTimedOut)
   467 			}
   505                 ret = KErrNone;
   468 		else
   506 #endif
   469 			validCode = 0x21;
   507                 if (ret == KErrNone)
   470 
   508                     validCode = 1;
   471 	/* Alternative way to ask for password
   509                 else
   472 	RMobilePhone::TMobilePhoneSecurityEvent iEvent;
   510                     validCode = 0;
   473 	TInt result = KErrNone;
   511                 }
   474 	iEvent = RMobilePhone::EPhonePasswordRequired;
   512             else
   475 	RDEBUG( "calling HandleEventL", 0 );
   513                 validCode = 0x20;
   476 	handler->HandleEventL(iEvent, result);	// this is supposed to wait
   514             }
   477 	validCode = false;
   515         else
   478 	if(result)
   516             validCode = 0x21;
   479 		validCode = true;
   517 
   480 	RDEBUG( "result", result );
   518         /* Alternative way to ask for password
   481 	*/
   519          RMobilePhone::TMobilePhoneSecurityEvent iEvent;
   482 	}
   520          TInt result = KErrNone;
   483 // TODO this doesn't wait on WINS , so how do I get the Acceptation?
   521          iEvent = RMobilePhone::EPhonePasswordRequired;
   484 	RDEBUG( "validCode (true/false)", validCode );
   522          RDEBUG( "calling HandleEventL", 0 );
   485 if(validCode)
   523          handler->HandleEventL(iEvent, result);	// this is supposed to wait
   486 	return KErrNone;
   524          validCode = false;
   487 return KErrCancel;
   525          if(result)
   488 }
   526          validCode = true;
       
   527          RDEBUG( "result", result );
       
   528          */
       
   529         }
       
   530     // TODO this doesn't wait on WINS , so how do I get the Acceptation?
       
   531     RDEBUG("validCode (true/false)", validCode);
       
   532     if (validCode)
       
   533         return KErrNone;
       
   534 
       
   535 		// no valid code -> switch off the lights
       
   536     err = RProperty::Set(KPSUidSecurityUIs,
       
   537             KSecurityUIsLights, ESecurityUIsLightsLockOffRequest);
       
   538 		RDEBUG("KSecurityUIsLights err", err);
       
   539     return KErrCancel;
       
   540     }
   489 
   541 
   490 void AutolockSrv::lockAction()
   542 void AutolockSrv::lockAction()
   491 {
   543     {
   492 			RDEBUG( "0", 0 );
   544     RDEBUG("0", 0);
   493 
   545 
   494     XQSERVICE_DEBUG_PRINT("AutolockSrv::lockAction");
   546     XQSERVICE_DEBUG_PRINT("AutolockSrv::lockAction");
   495 		TryChangeStatus(ELockAppOfferDevicelock);
   547     TryChangeStatus( ELockAppOfferDevicelock);
   496 		
   548 
   497 }
   549     }
   498 
   550 
   499 void AutolockSrv::handleAnswerDelivered()
   551 void AutolockSrv::handleAnswerDelivered()
   500 {
   552     {
   501 			RDEBUG( "This should never be called", 0 );
   553     RDEBUG("0", 0);
   502     // quit();
   554     // quit();
   503     
   555 
   504 }
   556     }
   505 
       
   506 
   557 
   507 void AutolockSrv::endCall()
   558 void AutolockSrv::endCall()
   508 {
   559     {
   509 			RDEBUG( "This should never be called", 0 );
   560     RDEBUG("This should never be called", 0);
   510     //QVBoxLayout *vl = qobject_cast<QVBoxLayout *>(layout()) ;
   561     //QVBoxLayout *vl = qobject_cast<QVBoxLayout *>(layout()) ;
   511     //vl->removeWidget(mEndCallButton);
   562     //vl->removeWidget(mEndCallButton);
   512 
   563 
   513     //XQServiceUtil::toBackground(true);
   564     //XQServiceUtil::toBackground(true);
   514 }
   565     }
   515 
   566 
   516 void AutolockSrv::setLabelNumber(QString label,QString number)
   567 void AutolockSrv::setLabelNumber(QString label, QString number)
   517 {
   568     {
   518 			RDEBUG( "0", 0 );
   569     RDEBUG("0", 0);
   519     mLabel->setText("mLabel=" + label);
   570     mLabel->setText("mLabel=" + label);
   520     mNumberEdit->setText("mNumberEdit=" + number);
   571     mNumberEdit->setText("mNumberEdit=" + number);
   521 }
   572     }
   522 
   573 
   523 void AutolockSrv::DebugRequest(int aReason)
   574 void AutolockSrv::DebugRequest(int aReason)
   524 {
   575     {
   525     switch(aReason)
   576     switch (aReason)
   526     {
   577         {
   527     	case ELockAppEnableKeyguard:
   578         case ELockAppEnableKeyguard:
   528 					RDEBUG( "ELockAppEnableKeyguard", aReason );
   579             RDEBUG("ELockAppEnableKeyguard", aReason);
   529     		break;
   580             break;
   530     	case ELockAppDisableKeyguard:
   581         case ELockAppDisableKeyguard:
   531 					RDEBUG( "ELockAppDisableKeyguard", aReason );
   582             RDEBUG("ELockAppDisableKeyguard", aReason);
   532     		break;
   583             break;
   533     	case ELockAppEnableDevicelock:
   584         case ELockAppEnableDevicelock:
   534 					RDEBUG( "ELockAppEnableDevicelock", aReason );
   585             RDEBUG("ELockAppEnableDevicelock", aReason);
   535     		break;
   586             break;
   536     	case ELockAppDisableDevicelock:
   587         case ELockAppDisableDevicelock:
   537 					RDEBUG( "ELockAppDisableDevicelock", aReason );
   588             RDEBUG("ELockAppDisableDevicelock", aReason);
   538     		break;
   589             break;
   539     	case ELockAppOfferKeyguard:
   590         case ELockAppOfferKeyguard:
   540 					RDEBUG( "ELockAppOfferKeyguard", aReason );
   591             RDEBUG("ELockAppOfferKeyguard", aReason);
   541     		break;
   592             break;
   542     	case ELockAppOfferDevicelock:
   593         case ELockAppOfferDevicelock:
   543 					RDEBUG( "ELockAppOfferDevicelock", aReason );
   594             RDEBUG("ELockAppOfferDevicelock", aReason);
   544     		break;
   595             break;
   545     	case ELockAppShowKeysLockedNote:
   596         case ELockAppShowKeysLockedNote:
   546 					RDEBUG( "ELockAppShowKeysLockedNote", aReason );
   597             RDEBUG("ELockAppShowKeysLockedNote", aReason);
   547     		break;
   598             break;
   548     	default:
   599         default:
   549 					RDEBUG( "default", aReason );
   600             RDEBUG("default", aReason);
   550     		break;
   601             break;
   551     }
   602         }
   552 }
   603     }
   553 void AutolockSrv::DebugStatus(int aReason)
   604 void AutolockSrv::DebugStatus(int aReason)
   554 {
   605     {
   555     switch(aReason)
   606     switch (aReason)
   556     {
   607         {
   557     	case ELockNotActive:
   608         case ELockNotActive:
   558 					RDEBUG( "ELockNotActive", aReason );
   609             RDEBUG("ELockNotActive", aReason);
   559     		break;
   610             break;
   560     	case EKeyguardActive:
   611         case EKeyguardActive:
   561 					RDEBUG( "EKeyguardActive", aReason );
   612             RDEBUG("EKeyguardActive", aReason);
   562     		break;
   613             break;
   563     	case EDevicelockActive:
   614         case EDevicelockActive:
   564 					RDEBUG( "EDevicelockActive", aReason );
   615             RDEBUG("EDevicelockActive", aReason);
   565     		break;
   616             break;
   566     	default:
   617         default:
   567 					RDEBUG( "default", aReason );
   618             RDEBUG("default", aReason);
   568     		break;
   619             break;
   569     }
   620         }
   570 }
   621     }
   571 void AutolockSrv::DebugError(int aReason)
   622 void AutolockSrv::DebugError(int aReason)
   572 {
   623     {
   573     switch(aReason)
   624     switch (aReason)
   574     {
   625         {
   575     	case KErrPermissionDenied:
   626         case KErrNone:
   576 					RDEBUG( "KErrPermissionDenied", aReason );
   627             RDEBUG("KErrNone", aReason);
   577     		break;
   628             break;
   578     	case KErrNone:
   629         case KErrPermissionDenied:	// caller doesn't have enough capabilities
   579 					RDEBUG( "KErrNone", aReason );
   630             RDEBUG("KErrPermissionDenied", aReason);
   580     		break;
   631             break;
   581     	case KErrAlreadyExists:
   632         case KErrAlreadyExists:	// this particular lock is already enabled
   582 					RDEBUG( "KErrAlreadyExists", aReason );
   633             RDEBUG("KErrAlreadyExists", aReason);
   583     		break;
   634             break;
   584     	default:
   635         case KErrInUse:	// the dialog is already shown
   585 					RDEBUG( "default", aReason );
   636             RDEBUG("KErrInUse", aReason);
   586     		break;
   637             break;
   587     }
   638         default:
   588 }
   639             RDEBUG("default", aReason);
       
   640             break;
       
   641         }
       
   642     }
   589 
   643 
   590 int AutolockSrv::CheckIfLegal(int aReason)
   644 int AutolockSrv::CheckIfLegal(int aReason)
   591 {
   645     {
   592 		RDEBUG( "aReason", aReason );
   646     RDEBUG("aReason", aReason);
   593     switch ( aReason )
   647     // check whether a dialog is already displayed. This is to prevent timeout-lock and timeout-keyguard for activated on top of a PIN query, in particular at boot-up (TODO Starter)
       
   648     TInt secUiOriginatedQuery(ESecurityUIsSecUIOriginatedUninitialized);
       
   649     TInt err = RProperty::Get(KPSUidSecurityUIs,
       
   650             KSecurityUIsSecUIOriginatedQuery, secUiOriginatedQuery);
       
   651     RDEBUG("err", err);
       
   652     RDEBUG("secUiOriginatedQuery", secUiOriginatedQuery);
       
   653     switch (aReason)
   594         {
   654         {
   595         case ELockAppEnableKeyguard:
   655         case ELockAppEnableKeyguard:
   596             {
   656             {
   597            		RDEBUG( "ELockAppEnableKeyguard iLockStatus", iLockStatus );
   657             RDEBUG("ELockAppEnableKeyguard iLockStatus", iLockStatus);
   598             switch ( iLockStatus )
   658             if (secUiOriginatedQuery
       
   659                     != ESecurityUIsSecUIOriginatedUninitialized)
       
   660                 return KErrInUse; // PIN on top. Don't keyguard
       
   661             switch (iLockStatus)
   599                 {
   662                 {
   600                 case ELockNotActive:
   663                 case ELockNotActive:
   601                     if ( 1==0 )	// !CKeyLockPolicyApi::KeyguardAllowed() )
   664                     if (1 == 0) // !CKeyLockPolicyApi::KeyguardAllowed() )
   602                         return KErrPermissionDenied;
   665                         return KErrPermissionDenied;
   603                     else
   666                     else
   604                         return KErrNone;
   667                         return KErrNone;
   605                 case EKeyguardActive:
   668                 case EKeyguardActive:
   606                     return KErrAlreadyExists;
   669                     return KErrAlreadyExists;
   609                 }
   672                 }
   610             }
   673             }
   611             break;
   674             break;
   612         case ELockAppDisableKeyguard:
   675         case ELockAppDisableKeyguard:
   613             {
   676             {
   614            		RDEBUG( "ELockAppDisableKeyguard iLockStatus", iLockStatus );
   677             RDEBUG("ELockAppDisableKeyguard iLockStatus", iLockStatus);
   615             switch ( iLockStatus )
   678             // no matter whether PIN is displayed
       
   679             switch (iLockStatus)
   616                 {
   680                 {
   617                 case ELockNotActive:
   681                 case ELockNotActive:
   618                     return KErrAlreadyExists;
   682                     return KErrAlreadyExists;
   619                 case EKeyguardActive:
   683                 case EKeyguardActive:
   620                     return KErrNone;
   684                     return KErrNone;
   623                 }
   687                 }
   624             }
   688             }
   625             break;
   689             break;
   626         case ELockAppEnableDevicelock:
   690         case ELockAppEnableDevicelock:
   627             {
   691             {
   628            		RDEBUG( "ELockAppEnableDevicelock iLockStatus", iLockStatus );
   692             RDEBUG("ELockAppEnableDevicelock iLockStatus", iLockStatus);
   629             switch ( iLockStatus )
   693             if (secUiOriginatedQuery
       
   694                     != ESecurityUIsSecUIOriginatedUninitialized
       
   695                     && secUiOriginatedQuery
       
   696                             != ESecurityUIsSystemLockOriginated)
       
   697                 return KErrInUse; // PIN on top. Don't devicelock
       
   698             switch (iLockStatus)
   630                 {
   699                 {
   631                 case ELockNotActive:
   700                 case ELockNotActive:
   632                     return KErrNone;
   701                     return KErrNone;
   633                 case EKeyguardActive:
   702                 case EKeyguardActive:
   634                     return KErrNone;
   703                     return KErrNone;
   637                 }
   706                 }
   638             }
   707             }
   639             break;
   708             break;
   640         case ELockAppDisableDevicelock:
   709         case ELockAppDisableDevicelock:
   641             {
   710             {
   642            		RDEBUG( "ELockAppDisableDevicelock iLockStatus", iLockStatus );
   711             RDEBUG("ELockAppDisableDevicelock iLockStatus", iLockStatus);
   643             switch ( iLockStatus )
   712             if (secUiOriginatedQuery
       
   713                     != ESecurityUIsSecUIOriginatedUninitialized
       
   714                     && secUiOriginatedQuery
       
   715                             != ESecurityUIsSystemLockOriginated)
       
   716                 {
       
   717                 // PIN on top and trying to display unlock-code. This is valid
       
   718                 }
       
   719             switch (iLockStatus)
   644                 {
   720                 {
   645                 case ELockNotActive:
   721                 case ELockNotActive:
   646                     return KErrAlreadyExists;
   722                     return KErrAlreadyExists;
   647                 case EKeyguardActive:
   723                 case EKeyguardActive:
   648                     return KErrPermissionDenied;
   724                     return KErrPermissionDenied;
   651                 }
   727                 }
   652             }
   728             }
   653             break;
   729             break;
   654         case ELockAppOfferKeyguard:
   730         case ELockAppOfferKeyguard:
   655             {
   731             {
   656            		RDEBUG( "ELockAppOfferKeyguard iLockStatus", iLockStatus );
   732             RDEBUG("ELockAppOfferKeyguard iLockStatus", iLockStatus);
   657             switch ( iLockStatus )
   733             if (secUiOriginatedQuery
       
   734                     != ESecurityUIsSecUIOriginatedUninitialized
       
   735                     && secUiOriginatedQuery
       
   736                             != ESecurityUIsSystemLockOriginated)
       
   737                 return KErrInUse; // PIN on top. Don't offer
       
   738             switch (iLockStatus)
   658                 {
   739                 {
   659                 case ELockNotActive:
   740                 case ELockNotActive:
   660                     return KErrNone;
   741                     return KErrNone;
   661                 case EKeyguardActive:
   742                 case EKeyguardActive:
   662                     return KErrPermissionDenied;
   743                     return KErrPermissionDenied;
   665                 }
   746                 }
   666             }
   747             }
   667             break;
   748             break;
   668         case ELockAppOfferDevicelock:
   749         case ELockAppOfferDevicelock:
   669             {
   750             {
   670            		RDEBUG( "ELockAppOfferDevicelock iLockStatus", iLockStatus );
   751             RDEBUG("ELockAppOfferDevicelock iLockStatus", iLockStatus);
   671             switch ( iLockStatus )
   752             if (secUiOriginatedQuery
       
   753                     != ESecurityUIsSecUIOriginatedUninitialized
       
   754                     && secUiOriginatedQuery
       
   755                             != ESecurityUIsSystemLockOriginated)
       
   756                 return KErrInUse; // PIN on top. Don't offer
       
   757             switch (iLockStatus)
   672                 {
   758                 {
   673                 case ELockNotActive:
   759                 case ELockNotActive:
   674                     return KErrNone;
   760                     return KErrNone;
   675                 case EKeyguardActive:
   761                 case EKeyguardActive:
   676                     return KErrNone;
   762                     return KErrNone;
   679                 }
   765                 }
   680             }
   766             }
   681             break;
   767             break;
   682         case ELockAppShowKeysLockedNote:
   768         case ELockAppShowKeysLockedNote:
   683             {
   769             {
   684            		RDEBUG( "ELockAppShowKeysLockedNote iLockStatus", iLockStatus );
   770             RDEBUG("ELockAppShowKeysLockedNote iLockStatus", iLockStatus);
   685             switch ( iLockStatus )
   771             if (secUiOriginatedQuery
       
   772                     != ESecurityUIsSecUIOriginatedUninitialized
       
   773                     && secUiOriginatedQuery
       
   774                             != ESecurityUIsSystemLockOriginated)
       
   775                 return KErrInUse; // PIN on top. Don't display
       
   776             switch (iLockStatus)
   686                 {
   777                 {
   687                 case ELockNotActive:
   778                 case ELockNotActive:
   688                     return KErrPermissionDenied;
   779                     return KErrPermissionDenied;
   689                 case EKeyguardActive:
   780                 case EKeyguardActive:
   690                     return KErrNone;
   781                     return KErrNone;
   693                 }
   784                 }
   694             }
   785             }
   695             break;
   786             break;
   696         default:
   787         default:
   697             {
   788             {
   698            		RDEBUG( "default iLockStatus", iLockStatus );
   789             RDEBUG("default iLockStatus", iLockStatus);
   699             return KErrPermissionDenied;
   790             return KErrPermissionDenied;
   700             }
   791             }
   701             // break;
   792             // break;
   702         }	// switch
   793         } // switch
   703     return KErrPermissionDenied;
   794     return KErrPermissionDenied;
   704 }
   795     }
   705 
   796 
   706 int AutolockSrv::publishStatus(int aReason)
   797 int AutolockSrv::publishStatus(int aReason)
   707 {
   798     {
   708     	RDEBUG( "aReason", aReason );
   799     RDEBUG("aReason", aReason);
   709 const TUid KCRUidCoreApplicationUIsSysAp = { 0x101F8765 };
   800     TInt err;
   710 const TUint32 KSysApKeyguardActive = 0x00000001;
   801     const TUid KCRUidCoreApplicationUIsSysAp = { 0x101F8765 };
   711 CRepository* repositoryDevicelock;
   802     const TUint32 KSysApKeyguardActive = 0x00000001;
   712 CRepository* repositoryKeyguard;
   803     CRepository* repositoryDevicelock;
   713 repositoryDevicelock = CRepository::NewL(KCRUidSecuritySettings);
   804     CRepository* repositoryKeyguard;
   714 repositoryKeyguard = CRepository::NewL(KCRUidSecuritySettings);
   805     repositoryDevicelock = CRepository::NewL(KCRUidSecuritySettings);
   715 TInt cRresult;
   806     repositoryKeyguard = CRepository::NewL(KCRUidCoreApplicationUIsSysAp);
   716 
   807     TInt cRresult = KErrNone;
   717 	if(1==1)
   808     if (1 == 1) // this is a quick way to disable this functionality, for testing
   718 		{
   809         {
   719     	RDEBUG( "publishing", aReason );
   810         RDEBUG("publishing", aReason);
   720 		if(aReason==ELockNotActive)
   811         if (aReason == ELockNotActive)
   721 			{
   812             {
   722 			RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardNotActive);
   813             err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus,
   723 			RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
   814                     EKeyguardNotActive);
   724 			// cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);	// the settings remains. Only ISA changes, as well as the P&S
   815             RDEBUG("err", err);
   725 			cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0);
   816             err = RProperty::Set(KPSUidCoreApplicationUIs,
   726 			}
   817                     KCoreAppUIsAutolockStatus, EAutolockOff);
   727 	if(1==0)
   818             RDEBUG("err", err);
   728 		{
   819             // lights are required ?
   729 		if(aReason==EKeyguardActive)
   820 
   730 			{
   821             // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);	// the settings remains. Only ISA changes, as well as the P&S
   731 			RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardLocked);
   822             cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0);
   732 			RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
   823             RDEBUG("cRresult", cRresult);
   733 			// cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);
   824             }
   734 			cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 1);
   825         if (1 == 1) // this is a quick way to disable this functionality, for testing
   735 			}
   826             {
   736 		else if(aReason>=EDevicelockActive)
   827             if (aReason == EKeyguardActive)
   737 			{
   828                 {
   738 			RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardNotActive);	// EKeyguardLocked sure? maybe EKeyguardNotActive ?
   829                 err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus,
   739 			RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EManualLocked);
   830                         EKeyguardLocked);
   740 			// cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 1);
   831             		RDEBUG("KAknKeyguardStatus err", err);
   741 			cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0);	// keyguard disabled, so that user can type and DeviceF can be captured
   832                 err = RProperty::Set(KPSUidCoreApplicationUIs,
   742 			}
   833                         KCoreAppUIsAutolockStatus, EAutolockOff);
   743 		}
   834             		RDEBUG("KCoreAppUIsAutolockStatus err", err);
   744 		}
   835                 err = RProperty::Set(KPSUidSecurityUIs,
   745 delete repositoryDevicelock;
   836                         KSecurityUIsLights, ESecurityUIsLightsLockOffRequest);	// same for keyguard and devicelock
   746 delete repositoryKeyguard;
   837             		RDEBUG("KSecurityUIsLights err", err);
   747 // this is the real point where everything is done.
   838                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0);
   748 iLockStatusPrev = iLockStatus;
   839                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 1);
   749 iLockStatus = aReason;
   840                 RDEBUG("cRresult", cRresult);
   750 	RDEBUG( "setting iLockStatus", iLockStatus );
   841                 }
   751 return KErrNone;
   842             else if (aReason >= EDevicelockActive)
   752 }
   843                 {
       
   844                 err = RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus,
       
   845                         EKeyguardAutolockEmulation); // not EKeyguardLocked, not EKeyguardNotActive
       
   846             		RDEBUG("KAknKeyguardStatus err", err);
       
   847                 err = RProperty::Set(KPSUidCoreApplicationUIs,
       
   848                         KCoreAppUIsAutolockStatus, EManualLocked);
       
   849             		RDEBUG("KCoreAppUIsAutolockStatus err", err);
       
   850                 err = RProperty::Set(KPSUidSecurityUIs,
       
   851                         KSecurityUIsLights, ESecurityUIsLightsLockOffRequest);
       
   852             		RDEBUG(" KSecurityUIsLights err", err);
       
   853                 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 1);
       
   854                 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0); // keyguard disabled, so that user can type and DeviceF can be captured
       
   855                 RDEBUG("cRresult", cRresult);
       
   856                 }
       
   857             }
       
   858         }
       
   859     delete repositoryDevicelock;
       
   860     delete repositoryKeyguard;
       
   861     // this is the real point where everything is done.
       
   862     iLockStatusPrev = iLockStatus;
       
   863     iLockStatus = aReason;
       
   864     RDEBUG("setting iLockStatus", iLockStatus);
       
   865     return KErrNone;
       
   866     }
   753 /********************/
   867 /********************/
   754 int AutolockSrv::showNoteIfRequested(int aReason)
   868 int AutolockSrv::showNoteIfRequested(int aReason)
   755 {
   869     {
   756     	RDEBUG( "aReason", aReason );
   870     RDEBUG("aReason", aReason);
   757 
   871 
   758 		if(aReason==ELockNotActive)
   872     if (aReason == ELockNotActive)
   759 			{
   873         {
   760 			if(iShowKeyguardNote==1)
   874         if (iShowKeyguardNote == 1)
   761 				{
   875             {
   762 				HbDeviceMessageBox::information ("Keyguard deactivated");
   876             HbDeviceMessageBox::information("Keyguard deactivated");
   763 				}
   877             }
   764 			}
   878         }
   765 		else if(aReason==EKeyguardActive)
   879     else if (aReason == EKeyguardActive)
   766 			{
   880         {
   767 			if(iShowKeyguardNote==1)
   881         if (iShowKeyguardNote == 1)
   768 				{
   882             {
   769 				HbDeviceMessageBox::information ("Keyguard activated");
   883             HbDeviceMessageBox::information("Keyguard activated");
   770 				}
   884             }
   771 			}
   885         }
   772 		else if(aReason>=EDevicelockActive)	// this doesn't happen, but we are prepared nevertheless
   886     else if (aReason >= EDevicelockActive) // this doesn't happen, but we are prepared nevertheless
   773 			{
   887         {
   774 			if(iShowKeyguardNote==1)
   888         if (iShowKeyguardNote == 1)
   775 				{
   889             {
   776 				HbDeviceMessageBox::information ("Devicelock activated");
   890             HbDeviceMessageBox::information("Devicelock activated");
   777 				}
   891             }
   778 			}
   892         }
   779 return KErrNone;
   893     return KErrNone;
   780 }
   894     }
   781 /***********************/
   895 /***********************/
   782 int AutolockSrv::TryChangeStatus(int aReason)
   896 int AutolockSrv::TryChangeStatus(int aReason)
   783 {
   897     {
   784 		RDEBUG( "aReason", aReason );
   898     RDEBUG("aReason", aReason);
   785 	int ret = aReason;
   899     int ret = aReason;
   786 	int errorInProcess = KErrNone;
   900     int errorInProcess = KErrNone;
   787 	DebugRequest(ret);
   901     DebugRequest(ret);
   788 		
   902 
   789 		switch(ret)
   903     switch (ret)
   790 		{
   904         {
   791 			case ELockAppEnableKeyguard:	// 1
   905         case ELockAppEnableKeyguard: // 1
   792 					{
   906             {
   793 					errorInProcess = CheckIfLegal(ret);
   907             errorInProcess = CheckIfLegal(ret);
   794 					DebugError(errorInProcess);
   908             DebugError(errorInProcess);
   795 					if(errorInProcess==KErrNone)
   909             if (errorInProcess == KErrNone)
   796 						{
   910                 {
   797 						setLabelIcon(EKeyguardActive);
   911                 setLabelIcon( EKeyguardActive);
   798 						updateIndicator(EKeyguardActive);
   912                 updateIndicator(EKeyguardActive);
   799 						publishStatus(EKeyguardActive);
   913                 publishStatus(EKeyguardActive);
   800 						showNoteIfRequested(EKeyguardActive);
   914                 showNoteIfRequested(EKeyguardActive);
   801 						}
   915                 }
   802 					}
   916             }
   803 				break;
   917             break;
   804 			case ELockAppDisableKeyguard:	// 2
   918         case ELockAppDisableKeyguard: // 2
   805 					{
   919             {
   806 					errorInProcess = CheckIfLegal(ret);
   920             errorInProcess = CheckIfLegal(ret);
   807 					DebugError(errorInProcess);
   921             DebugError(errorInProcess);
   808 					if(errorInProcess==KErrNone)
   922             if (errorInProcess == KErrNone)
   809 						{
   923                 {
   810 						setLabelIcon(ELockNotActive);
   924                 setLabelIcon( ELockNotActive);
   811 						updateIndicator(ELockNotActive);
   925                 updateIndicator(ELockNotActive);
   812 						publishStatus(ELockNotActive);
   926                 publishStatus(ELockNotActive);
   813 						showNoteIfRequested(ELockNotActive);
   927                 showNoteIfRequested(ELockNotActive);
   814 						}
   928                 }
   815 					}
   929             }
   816 				break;
   930             break;
   817 			case ELockAppEnableDevicelock:	// 3
   931         case ELockAppEnableDevicelock: // 3
   818 					{
   932             {
   819 					errorInProcess = CheckIfLegal(ret);
   933             errorInProcess = CheckIfLegal(ret);
   820 					DebugError(errorInProcess);
   934             DebugError(errorInProcess);
   821 					if(errorInProcess==KErrNone)
   935             if (errorInProcess == KErrNone)
   822 						{
   936                 {
   823 						if(!callerHasECapabilityWriteDeviceData)	// check permissions for calling process, because doesn't AskValidSecCode
   937                 if (!callerHasECapabilityWriteDeviceData) // check permissions for calling process, because doesn't AskValidSecCode
   824 							errorInProcess=KErrPermissionDenied;
   938                     errorInProcess = KErrPermissionDenied;
   825 						DebugError(errorInProcess);
   939                 DebugError(errorInProcess);
   826 						}
   940                 }
   827 					if(errorInProcess==KErrNone)
   941             if (errorInProcess == KErrNone)
   828 						{
   942                 {
   829 						updateIndicator(EDevicelockActive);
   943                 updateIndicator( EDevicelockActive);
   830 						publishStatus(EDevicelockActive);
   944                 publishStatus(EDevicelockActive);
   831 						setLabelIcon(EDevicelockActive);
   945                 setLabelIcon(EDevicelockActive);
   832 						setLockDialog(aReason, 1);
   946                 setLockDialog(aReason, 1);
   833 						}
   947                 }
   834 					// aParam1 is aReason : EDevicelockManual, EDevicelockRemote
   948             // aParam1 is aReason : EDevicelockManual, EDevicelockRemote
   835 					// this never shows a note
   949             // this never shows a note
   836 					}
   950             }
   837 				break;
   951             break;
   838 			case ELockAppDisableDevicelock:	// 4
   952         case ELockAppDisableDevicelock: // 4
   839 					{
   953             {
   840 					errorInProcess = CheckIfLegal(ret);
   954             errorInProcess = CheckIfLegal(ret);
   841 					DebugError(errorInProcess);
   955             DebugError(errorInProcess);
   842 					if(errorInProcess==KErrNone)
   956             if (errorInProcess == KErrNone)
   843 						{
   957                 {
   844 						if(!callerHasECapabilityWriteDeviceData)	// check permissions for calling process, because doesn't AskValidSecCode
   958                 if (!callerHasECapabilityWriteDeviceData) // check permissions for calling process, because doesn't AskValidSecCode
   845 							errorInProcess=KErrPermissionDenied;
   959                     errorInProcess = KErrPermissionDenied;
   846 						DebugError(errorInProcess);
   960                 DebugError(errorInProcess);
   847 						}
   961                 }
   848 					if(errorInProcess==KErrNone)
   962             if (errorInProcess == KErrNone)
   849 						{
   963                 {
   850 							RDEBUG( " calling HbDeviceMessageBox::question", 0 );
   964                 RDEBUG(" calling HbDeviceMessageBox::question", 0);
   851 						bool value = HbDeviceMessageBox::question("Disable Lock?");
   965                 bool value = HbDeviceMessageBox::question("Disable Lock?");
   852 							RDEBUG( "value", value );
   966                 RDEBUG("value", value);
   853 						if(!value)
   967                 if (!value)
   854 							errorInProcess = KErrCancel;
   968                     errorInProcess = KErrCancel;
   855 						}
   969                 }
   856 					if(errorInProcess==KErrNone)
   970             if (errorInProcess == KErrNone)
   857 						{
   971                 {
   858 				    setLockDialog(aReason, 0);	// hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
   972                 setLockDialog(aReason, 0); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
   859 							RDEBUG( "calling AskValidSecCode", 0 );
   973                 RDEBUG("calling AskValidSecCode", 0);
   860 						errorInProcess=AskValidSecCode(ELockAppDisableDevicelock);
   974                 errorInProcess = AskValidSecCode(ELockAppDisableDevicelock);
   861 							RDEBUG( "errorInProcess", errorInProcess );
   975                 RDEBUG("errorInProcess", errorInProcess);
   862 						}
   976                 }
   863 					if(errorInProcess==KErrNone)
   977             if (errorInProcess == KErrNone)
   864 						{
   978                 {
   865 						setLabelIcon(ELockNotActive);
   979                 setLabelIcon( ELockNotActive);
   866 						updateIndicator(ELockNotActive);
   980                 updateIndicator(ELockNotActive);
   867 						publishStatus(ELockNotActive);
   981                 publishStatus(ELockNotActive);
   868 						}
   982                 }
   869 					if(errorInProcess!=KErrNone)
   983             if (errorInProcess != KErrNone)
   870 						{	// re-lock. For example, if password is wrong
   984                 { // re-lock. For example, if password is wrong
   871 				    setLockDialog(aReason, 1);
   985                 setLockDialog(aReason, 1);
   872 				    }
   986                 }
   873 					// this never shows a note
   987             // this never shows a note
   874 					}
   988             }
   875 				break;
   989             break;
   876 			case ELockAppOfferKeyguard:	// 5
   990         case ELockAppOfferKeyguard: // 5
   877 					{
   991             {
   878 					errorInProcess = CheckIfLegal(ret);
   992             errorInProcess = CheckIfLegal(ret);
   879 					DebugError(errorInProcess);
   993             DebugError(errorInProcess);
   880 					if(errorInProcess==KErrNone)
   994             if (errorInProcess == KErrNone)
   881 						{
   995                 {
   882 						bool value = HbDeviceMessageBox::question("Enable Keyguard?");
   996                 bool value = HbDeviceMessageBox::question("Enable Keyguard?");
   883 							// TODO what about a nice icon?
   997                 // TODO what about a nice icon?
   884 							RDEBUG( "value", value );
   998                 RDEBUG("value", value);
   885 						if(!value)
   999                 if (!value)
   886 							errorInProcess = KErrCancel;
  1000                     errorInProcess = KErrCancel;
   887 						}
  1001                 }
   888 					if(errorInProcess==KErrNone)
  1002             if (errorInProcess == KErrNone)
   889 						{
  1003                 {
   890 						errorInProcess = TryChangeStatus(ELockAppEnableKeyguard);
  1004                 errorInProcess = TryChangeStatus(ELockAppEnableKeyguard);
   891 						}
  1005                 }
   892 					// this never shows a note
  1006             // this never shows a note
   893 					}
  1007             }
   894 				break;
  1008             break;
   895 			case ELockAppOfferDevicelock:		// 6
  1009         case ELockAppOfferDevicelock: // 6
   896 					{
  1010             {
   897 					errorInProcess = CheckIfLegal(ret);
  1011             errorInProcess = CheckIfLegal(ret);
   898 					DebugError(errorInProcess);
  1012             DebugError(errorInProcess);
   899 					setLockDialog(aReason, 0);	// hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
  1013             setLockDialog(aReason, 0); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it.
   900 					errorInProcess=AskValidSecCode(ELockAppEnableDevicelock);
  1014             errorInProcess = AskValidSecCode(ELockAppEnableDevicelock);
   901 					if(errorInProcess==KErrNone)
  1015             if (errorInProcess == KErrNone)
   902 						{
  1016                 {
   903 						errorInProcess = TryChangeStatus(ELockAppEnableDevicelock);
  1017                 errorInProcess = TryChangeStatus(ELockAppEnableDevicelock);
   904 						}
  1018                 }
   905 					// this never shows a note. Perhaps ELockAppEnableDevicelock does.
  1019             // this never shows a note. Perhaps ELockAppEnableDevicelock does.
   906 					}
  1020             }
   907 				break;
  1021             break;
   908 			case ELockAppShowKeysLockedNote:
  1022         case ELockAppShowKeysLockedNote:
   909 					{
  1023             {
   910 					iShowKeyguardNote=1;	// this is not sent as parameter, so we need to fake it: ON
  1024             iShowKeyguardNote = 1; // this is not sent as parameter, so we need to fake it: ON
   911 					showNoteIfRequested(EKeyguardActive);
  1025             showNoteIfRequested( EKeyguardActive);
   912 					}
  1026             }
   913 				break;
  1027             break;
   914 			default:
  1028         default:
   915 					RDEBUG( "default", ret );
  1029             RDEBUG("default", ret);
   916 				errorInProcess = KErrNotSupported;
  1030             errorInProcess = KErrNotSupported;
   917 				break;
  1031             break;
   918 
  1032 
   919 		}
  1033         }
   920     return errorInProcess;
  1034     return errorInProcess;
   921 }
  1035     }
   922 /**************************/
  1036 /**************************/
   923 int AutolockSrv::setLockDialog(int aReason, int status)
  1037 int AutolockSrv::setLockDialog(int aReason, int status)
   924 {
  1038     {
   925 			RDEBUG( "aReason", aReason );
  1039     RDEBUG("aReason", aReason);
   926 			RDEBUG( "status", status );
  1040     RDEBUG("status", status);
   927    		RDEBUG( "iDeviceDialogCreated", iDeviceDialogCreated );
  1041     RDEBUG("iDeviceDialogCreated", iDeviceDialogCreated);
   928 		if(status==0)	// hide
  1042     TInt secUiOriginatedQuery(ESecurityUIsSecUIOriginatedUninitialized);
   929 			{
  1043     TInt err = RProperty::Get(KPSUidSecurityUIs,
   930 	    if(iDeviceDialogCreated>0)
  1044             KSecurityUIsSecUIOriginatedQuery, secUiOriginatedQuery);
   931 	    	{
  1045     RDEBUG("err", err);
   932 	    	iDeviceDialogCreated = 0;
  1046     RDEBUG("secUiOriginatedQuery", secUiOriginatedQuery);
   933 	    	iDeviceDialog->cancel();
  1047 
   934 	    	}
  1048     if (status == 0) // hide
   935 			}
  1049         {
   936 		else if(status==1)	// show
  1050         // secUiOriginatedQuery should be ESecurityUIsSystemLockOriginated . If not, this is not correctly setting it
   937 			{
  1051         if (iDeviceDialogCreated > 0)
   938   	  QVariantMap params;
  1052             {
   939   	  TBool err;
  1053             iDeviceDialogCreated = 0;
   940   	  #define ESecUiTypeDeviceLock		0x00100000
  1054             iDeviceDialog->cancel();
   941   	  #define ESecUiTypeKeyguard			0x00200000
  1055             err = iDeviceDialog->error();
   942 
  1056             RDEBUG("err", err);
   943   	  if(aReason==EKeyguardActive)
  1057             TInt err = RProperty::Set(KPSUidSecurityUIs,
   944   	  	params.insert("type", ESecUiTypeKeyguard);
  1058                     KSecurityUIsSecUIOriginatedQuery,
   945   	  else if(aReason>=EDevicelockActive)
  1059                     ESecurityUIsSecUIOriginatedUninitialized);
   946   	  	params.insert("type", ESecUiTypeDeviceLock);
  1060             RDEBUG("err", err);
   947   	  else
  1061             }
   948   	  	{
  1062         }
   949   	  			RDEBUG( "error. status=1 but aReason", aReason );
  1063     else if (status == 1) // show
   950   	  	}
  1064         {
   951   	  // no need for title. Icon should be explicit enough
  1065         // secUiOriginatedQuery should be ESecurityUIsSecUIOriginatedUninitialized . If not, the validation is not correctly filtering it
   952 			// params.insert("title", "Locked");
  1066         QVariantMap params;
   953 			if(iDeviceDialogCreated<=0)
  1067         TBool err;
   954 				{
  1068 #define ESecUiTypeDeviceLock		0x00100000
   955 					RDEBUG( "creating iDeviceDialog", 0 );
  1069 #define ESecUiTypeKeyguard			0x00200000
   956 	    	iDeviceDialog = new HbDeviceDialog(HbDeviceDialog::NoFlags, this);
  1070 
   957 	    	iDeviceDialogCreated = 1;
  1071         if (aReason == EKeyguardActive)
   958 	    	}
  1072             params.insert("type", ESecUiTypeKeyguard);
   959 	    else
  1073         else if (aReason >= EDevicelockActive)
   960 	    	{
  1074             params.insert("type", ESecUiTypeDeviceLock);
   961 					RDEBUG( "raising iDeviceDialog", 0 );
  1075         else
   962 				// confirm that dialog is present
  1076             {
   963 				err = iDeviceDialog->error();
  1077             RDEBUG("error. status=1 but aReason", aReason);
   964 		    	RDEBUG( "err", err );
  1078             }
   965 	    	iDeviceDialogCreated = 2;
  1079         // no need for title. Icon should be explicit enough
   966 	    	}
  1080         // params.insert("title", "Locked");
   967 	    const QString KSecQueryUiDeviceDialog("com.nokia.secuinotificationdialog/1.0");
  1081         if (iDeviceDialogCreated <= 0)
   968 	    	RDEBUG( "pre show", aReason );
  1082             {
   969 	    err = iDeviceDialog->show( KSecQueryUiDeviceDialog, params );
  1083             RDEBUG("creating iDeviceDialog", 0);
   970 	    	RDEBUG( "post show. err", err );
  1084             iDeviceDialog = new HbDeviceDialog(HbDeviceDialog::NoFlags, this);
   971 	    err = iDeviceDialog->error();
  1085             iDeviceDialogCreated = 1;
   972 	    	RDEBUG( "err", err );
  1086             }
   973 			}
  1087         else
   974 		else
  1088             {
   975 			{
  1089             RDEBUG("raising iDeviceDialog", 0);
   976 				RDEBUG( "unknown status", status );
  1090             // confirm that dialog is present
   977 			return KErrNotSupported;
  1091             err = iDeviceDialog->error();
   978 			}
  1092             RDEBUG("err", err);
   979 return KErrNone;
  1093             iDeviceDialogCreated = 2;
   980 }
  1094             }
       
  1095         const QString KSecQueryUiDeviceDialog(
       
  1096                 "com.nokia.secuinotificationdialog/1.0");
       
  1097         RDEBUG("pre show", aReason);
       
  1098         err = iDeviceDialog->show(KSecQueryUiDeviceDialog, params); // and continue processing
       
  1099         RDEBUG("post show. err", err);
       
  1100         err = iDeviceDialog->error();
       
  1101         RDEBUG("err", err);
       
  1102         // This won't be needed when screensaver is in place, as the dialogs will be different, and therefore both can be present
       
  1103         // Somehow this should be handled by Orbit, but unfortunatelly they don't allow the same dialog twice
       
  1104         err = RProperty::Set(KPSUidSecurityUIs,
       
  1105                 KSecurityUIsSecUIOriginatedQuery,
       
  1106                 ESecurityUIsSecUIOriginatedUninitialized);
       
  1107         RDEBUG("err", err);
       
  1108 
       
  1109         }
       
  1110     else
       
  1111         {
       
  1112         RDEBUG("unknown status", status);
       
  1113         return KErrNotSupported;
       
  1114         }
       
  1115     return KErrNone;
       
  1116     }
   981 void AutolockSrv::setLabelIcon(int aReason)
  1117 void AutolockSrv::setLabelIcon(int aReason)
   982 {
  1118     {
   983 			RDEBUG( "aReason", aReason );
  1119     RDEBUG("aReason", aReason);
   984 		
  1120 
   985     if(aReason==ELockNotActive)
  1121     if (aReason == ELockNotActive)
   986     	{
  1122         {
   987 	    mLabelIcon->setVisible(false);
  1123         mLabelIcon->setVisible(false);
   988 	    setLockDialog(aReason, 0);	// TODO isn't this done already at TryChangeStatus ???
  1124         setLockDialog(aReason, 0); // TODO isn't this done already at TryChangeStatus ???
   989 	    lower();
  1125         lower();
   990 	    hide();
  1126         hide();
   991 	  	}
  1127         }
   992     else if(aReason==EKeyguardActive)
  1128     else if (aReason == EKeyguardActive)
   993     	{
  1129         {
   994 	    mLabelIcon->setVisible(true);
  1130         mLabelIcon->setVisible(true);
   995 	    setLockDialog(aReason, 1);
  1131         setLockDialog(aReason, 1);
   996 	   	raise();	// not repaint(), not show() , not setVisible(true), not showFullScreen() , not ???
  1132         raise(); // not repaint(), not show() , not setVisible(true), not showFullScreen() , not ???
   997 	   	show();
  1133         show();
   998 	  	}
  1134         }
   999     else if(aReason==EDevicelockActive)
  1135     else if (aReason == EDevicelockActive)
  1000     	{
  1136         {
  1001 	    mLabelIcon->setVisible(true);
  1137         mLabelIcon->setVisible(true);
  1002 			raise();
  1138         raise();
  1003 			show();
  1139         show();
  1004 	  	}
  1140         }
  1005 	  else
  1141     else
  1006 	  	{
  1142         {
  1007 				RDEBUG( "error: aReason", aReason );
  1143         RDEBUG("error: aReason", aReason);
  1008 			}
  1144         }
  1009 }
  1145     }
  1010 
  1146 
  1011 int AutolockSrv::updateIndicator(int aReason)
  1147 int AutolockSrv::updateIndicator(int aReason)
  1012 {
  1148     {
  1013     	RDEBUG( "aReason", aReason );
  1149     RDEBUG("aReason", aReason);
  1014 		QList<QVariant> list;
  1150     QList<QVariant> list;
  1015 		list.insert(0, 1);
  1151     list.insert(0, 1);
  1016 		list.insert(1, "aaa");
  1152     list.insert(1, "aaa");
  1017 		list.insert(2, 2);
  1153     list.insert(2, 2);
  1018 		
  1154 
  1019 		HbIndicator indicator;
  1155     HbIndicator indicator;
  1020 		bool success;
  1156     bool success;
  1021 		if(aReason==ELockNotActive)
  1157     if (aReason == ELockNotActive)
  1022 			success	= indicator.deactivate("com.nokia.hb.indicator.autolocksrv.autolocksrv_8/1.0");	// maybe it's already deactivated. Not a problem
  1158         success = indicator.deactivate(
  1023 		else if(aReason==EKeyguardActive)
  1159                 "com.nokia.hb.indicator.autolocksrv.autolocksrv_8/1.0"); // maybe it's already deactivated. Not a problem
  1024 			success	= indicator.activate("com.nokia.hb.indicator.autolocksrv.autolocksrv_8/1.0");
  1160     else if (aReason == EKeyguardActive)
  1025 		else if(aReason==EDevicelockActive)
  1161         success = indicator.activate(
  1026 			success	= indicator.activate("com.nokia.hb.indicator.autolocksrv.autolocksrv_8/1.0");	// same. We have just 1 indicator
  1162                 "com.nokia.hb.indicator.autolocksrv.autolocksrv_8/1.0");
  1027 		else
  1163     else if (aReason == EDevicelockActive)
  1028 			success = 0;
  1164         success = indicator.activate(
  1029 			RDEBUG( "success", success );
  1165                 "com.nokia.hb.indicator.autolocksrv.autolocksrv_8/1.0"); // same. We have just 1 indicator
  1030 		return success;
  1166     else
  1031 }
  1167         success = 0;
       
  1168     RDEBUG("success", success);
       
  1169     return success;
       
  1170     }
  1032 
  1171 
  1033 void AutolockSrv::activeKeyguard()
  1172 void AutolockSrv::activeKeyguard()
  1034 {
  1173     {
  1035 		// activity while keyguarded. Nothing to do
  1174     // activity while keyguarded. Nothing to do
  1036     	RDEBUG( "0", 0 );
  1175     RDEBUG("0", 0);
  1037 }
  1176     }
  1038 
  1177 
  1039 void AutolockSrv::notActiveKeyguard()
  1178 void AutolockSrv::notActiveKeyguard()
  1040 {
  1179     {
  1041 		// inactivity. Keyguard should be activated
  1180     // inactivity. Keyguard should be activated
  1042     	RDEBUG( "0", 0 );
  1181     RDEBUG("0", 0);
  1043    	int ret = 0;
  1182     int ret = KErrNone;
  1044    	DebugStatus(iLockStatus);
  1183     DebugStatus( iLockStatus);
  1045    	if(iLockStatus==ELockNotActive)	// not possible if it's keyguarded, or locked
  1184     if (iLockStatus == ELockNotActive) // not possible if it's keyguarded, or locked
  1046    		{
  1185         {
  1047     	ret = TryChangeStatus(ELockAppEnableKeyguard);
  1186         ret = TryChangeStatus(ELockAppEnableKeyguard);
  1048    		}
  1187         }
  1049 }
  1188     RDEBUG("ret", ret);
  1050 
  1189     }
       
  1190 /* Some activity detected while the deviceLock is enabled */
  1051 void AutolockSrv::activeDevicelock()
  1191 void AutolockSrv::activeDevicelock()
  1052 {
  1192     {
  1053     	RDEBUG( "0", 0 );
  1193     // nothing to do
  1054 }
  1194     RDEBUG("0", 0);
       
  1195     }
  1055 
  1196 
  1056 void AutolockSrv::notActiveDevicelock()
  1197 void AutolockSrv::notActiveDevicelock()
  1057 {
  1198     {
  1058 		// inactivity. Devicelock should be activated
  1199     // inactivity. Devicelock should be activated
  1059     	RDEBUG( "0", 0 );
  1200     RDEBUG("0", 0);
  1060    	int ret = 0;
  1201     int ret = KErrNone;
  1061    	DebugStatus(iLockStatus);
  1202     DebugStatus( iLockStatus);
  1062    	if(iLockStatus==ELockNotActive || iLockStatus==EKeyguardActive )	// not possible if it's locked
  1203     if (iLockStatus == ELockNotActive || iLockStatus == EKeyguardActive) // not possible if it's locked
  1063    		{
  1204         {
  1064     	ret = TryChangeStatus(ELockAppEnableDevicelock);
  1205         ret = TryChangeStatus(ELockAppEnableDevicelock);
  1065    		}
  1206         }
  1066 }
  1207     RDEBUG("ret", ret);
       
  1208 
       
  1209     }
  1067 
  1210 
  1068 // some key is pressed
  1211 // some key is pressed
  1069 bool AutolockSrv::event(QEvent *ev)
  1212 bool AutolockSrv::event(QEvent *ev)
  1070 {
  1213     {
  1071     if (ev)
  1214     if (ev)
  1072     {
  1215         {
  1073     	 int isSwitchKey=0;
  1216         int isSwitchKey = 0;
  1074     		// on device, this doesn't seem to get the EKeyDeviceF key: only 1ffffff
  1217         // on device, this doesn't seem to get the EKeyDeviceF key: only 1ffffff
  1075        if (ev->type() == QEvent::KeyPress){
  1218         if (ev->type() == QEvent::KeyPress)
  1076            QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
  1219             {
  1077            qDebug() << QString("KeyPress:%1\n").arg(keyEvent->key(), 0, 16) ;
  1220             QKeyEvent *keyEvent = static_cast<QKeyEvent *> (ev);
  1078            qDebug() << keyEvent->key();
  1221             qDebug() << QString("KeyPress:%1\n").arg(keyEvent->key(), 0, 16);
  1079            qDebug() << EKeyInsert;
  1222             qDebug() << keyEvent->key();
  1080            qDebug() << (keyEvent->key()&0xFF);
  1223             qDebug() << EKeyInsert;
  1081            qDebug() << (EKeyInsert&0xFF);
  1224             qDebug() << (keyEvent->key() & 0xFF);
  1082            if((keyEvent->key()&0xFF) == (EKeyInsert&0xFF))
  1225             qDebug() << (EKeyInsert & 0xFF);
  1083            	{
  1226             if ((keyEvent->key() & 0xFF) == (EKeyInsert & 0xFF))
  1084            		qDebug() << "pressed EKeyInsert";
  1227                 {
  1085            		// only reacts on release, not on press
  1228                 qDebug() << "pressed EKeyInsert";
  1086            		isSwitchKey=1;
  1229                 // only reacts on release, not on press
  1087            	}
  1230                 isSwitchKey = 1;
  1088            if((keyEvent->key()&0xFF) == (EKeyTab&0xFF))
  1231                 }
  1089            	{
  1232             if ((keyEvent->key() & 0xFF) == (EKeyTab & 0xFF))
  1090            		qDebug() << "pressed EKeyTab";
  1233                 {
  1091            	}
  1234                 qDebug() << "pressed EKeyTab";
  1092            if((keyEvent->key()&0xFF) == (EKeyDeviceF&0xFF))
  1235                 }
  1093            	{
  1236             if ((keyEvent->key() & 0xFF) == (EKeyDeviceF & 0xFF))
  1094            		qDebug() << "pressed EKeyDeviceF";
  1237                 {
  1095            	}
  1238                 qDebug() << "pressed EKeyDeviceF";
  1096            if( keyEvent->key() ==0x1ffffff )
  1239                 }
  1097            	{
  1240             if (keyEvent->key() == 0x1ffffff)
  1098            		qDebug() << "pressed EKeyDeviceF-1ffffff";
  1241                 {
  1099            		isSwitchKey=1;
  1242                 qDebug() << "pressed EKeyDeviceF-1ffffff";
  1100            	}
  1243                 isSwitchKey = 1;
  1101        }
  1244                 }
  1102        else if (ev->type() == QEvent::KeyRelease)
  1245             }
  1103        	{
  1246         else if (ev->type() == QEvent::KeyRelease)
  1104            QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
  1247             {
  1105            qDebug() << QString("KeyRelease:%1\n").arg(keyEvent->key(), 0, 16) ;
  1248             QKeyEvent *keyEvent = static_cast<QKeyEvent *> (ev);
  1106            if( keyEvent->key() ==0x1ffffff )
  1249             qDebug()
  1107            	{
  1250                     << QString("KeyRelease:%1\n").arg(keyEvent->key(), 0, 16);
  1108            		RDEBUG( "released EKeyDeviceF-1ffffff", 1 );
  1251             if (keyEvent->key() == 0x1ffffff)
  1109            		// isSwitchKey=1; this should happen is   pressed  was not processed (hint: if it is/was in background)
  1252                 {
  1110            	}
  1253                 RDEBUG("released EKeyDeviceF-1ffffff", 1);
  1111        }
  1254                 // isSwitchKey=1; this should happen is   pressed  was not processed (hint: if it is/was in background)
  1112     	RDEBUG( "isSwitchKey", isSwitchKey );
  1255                 }
  1113     if(isSwitchKey)
  1256             }
  1114     	{
  1257         RDEBUG("isSwitchKey", isSwitchKey);
  1115    		int ret;
  1258         if (isSwitchKey)
  1116 	    DebugStatus(iLockStatus);
  1259             {
  1117 	   	if(iLockStatus==ELockNotActive)
  1260             int ret = KErrNone;
  1118 	   		{
  1261             DebugStatus( iLockStatus);
  1119 	   		iShowKeyguardNote = 1;	// note on enable keyguard
  1262             if (iLockStatus == ELockNotActive)
  1120 	    	ret = TryChangeStatus(ELockAppEnableKeyguard);	// this should not ask confirmation
  1263                 {
  1121 	   		}
  1264                 iShowKeyguardNote = 1; // note on enable keyguard
  1122 	   	else if(iLockStatus==EKeyguardActive)
  1265                 ret = TryChangeStatus(ELockAppEnableKeyguard); // this should not ask confirmation
  1123 	   		{
  1266                 }
  1124 	   		iShowKeyguardNote = 1;	// note on disable keyguard
  1267             else if (iLockStatus == EKeyguardActive)
  1125 	    	ret = TryChangeStatus(ELockAppDisableKeyguard);
  1268                 {
  1126 	   		}
  1269                 iShowKeyguardNote = 1; // note on disable keyguard
  1127 	   	else if(iLockStatus==EDevicelockActive)
  1270                 ret = TryChangeStatus(ELockAppDisableKeyguard);
  1128 	   		{
  1271                 }
  1129 	    	ret = TryChangeStatus(ELockAppDisableDevicelock);
  1272             else if (iLockStatus == EDevicelockActive)
  1130 	   		}
  1273                 {
  1131   		}	// isSwitchKey
  1274                 ret = TryChangeStatus(ELockAppDisableDevicelock);
  1132     }	// ev
  1275                 }
  1133 		// Process if not done before. For example, redraw or quit
  1276             else
       
  1277                 {
       
  1278                 RDEBUG("unknown iLockStatus", iLockStatus);
       
  1279                 }
       
  1280             RDEBUG("ret", ret);
       
  1281             } // isSwitchKey
       
  1282         } // ev
       
  1283     // Process if not done before. For example, redraw or quit
  1134     return QWidget::event(ev);
  1284     return QWidget::event(ev);
  1135 }
  1285     }
  1136 
  1286 
  1137 bool AutolockSrv::eventFilter(QObject *o, QEvent *ev)
  1287 bool AutolockSrv::eventFilter(QObject *o, QEvent *ev)
  1138 {
  1288     {
  1139 		// this never happens
  1289     // this never happens
  1140     	RDEBUG( "0", 0 );
  1290     RDEBUG("0", 0);
  1141     return QWidget::eventFilter(o, ev);
  1291     return QWidget::eventFilter(o, ev);
  1142     
  1292 
  1143 }
  1293     }
  1144 
  1294 
  1145 void AutolockSrv::subscriberKSettingsAutolockStatusChanged()
  1295 void AutolockSrv::subscriberKSettingsAutolockStatusChanged()
  1146     {
  1296     {
  1147     			RDEBUG( "0", 0 );
  1297     RDEBUG("0", 0);
  1148         QVariant v = subscriberKSettingsAutolockStatus->value("/KCRUidSecuritySettings/KSettingsAutolockStatus");
  1298     QVariant v = subscriberKSettingsAutolockStatus->value(
  1149         adjustInactivityTimers(KSettingsAutolockStatus);
  1299             "/KCRUidSecuritySettings/KSettingsAutolockStatus");
  1150         qDebug() << "AutolockSrv::subscriberKSettingsAutolockStatusChanged" << v;
  1300     adjustInactivityTimers( KSettingsAutolockStatus);
  1151 		}
  1301     qDebug() << "AutolockSrv::subscriberKSettingsAutolockStatusChanged" << v;
       
  1302     }
  1152 void AutolockSrv::subscriberKSettingsAutoLockTimeChanged()
  1303 void AutolockSrv::subscriberKSettingsAutoLockTimeChanged()
  1153     {
  1304     {
  1154     			RDEBUG( "0", 0 );
  1305     RDEBUG("0", 0);
  1155         QVariant v = subscriberKSettingsAutoLockTime->value("/KCRUidSecuritySettings/KSettingsAutoLockTime");
  1306     QVariant v = subscriberKSettingsAutoLockTime->value(
  1156         adjustInactivityTimers(KSettingsAutoLockTime);
  1307             "/KCRUidSecuritySettings/KSettingsAutoLockTime");
  1157         qDebug() << "AutolockSrv::subscriberKSettingsAutoLockTimeChanged" << v;
  1308     adjustInactivityTimers( KSettingsAutoLockTime);
  1158 		}
  1309     qDebug() << "AutolockSrv::subscriberKSettingsAutoLockTimeChanged" << v;
       
  1310     }
  1159 void AutolockSrv::subscriberKSettingsAutomaticKeyguardTimeChanged()
  1311 void AutolockSrv::subscriberKSettingsAutomaticKeyguardTimeChanged()
  1160     {
  1312     {
  1161     			RDEBUG( "0", 0 );
  1313     RDEBUG("0", 0);
  1162         QVariant v = subscriberKSettingsAutomaticKeyguardTime->value("/KCRUidSecuritySettings/KSettingsAutomaticKeyguardTime");
  1314     QVariant v = subscriberKSettingsAutomaticKeyguardTime->value(
  1163         adjustInactivityTimers(KSettingsAutoLockTime);
  1315             "/KCRUidSecuritySettings/KSettingsAutomaticKeyguardTime");
  1164         qDebug() << "AutolockSrv::subscriberKSettingsAutomaticKeyguardTimeChanged" << v;
  1316     adjustInactivityTimers( KSettingsAutoLockTime);
  1165 		}
  1317     qDebug()
       
  1318             << "AutolockSrv::subscriberKSettingsAutomaticKeyguardTimeChanged"
       
  1319             << v;
       
  1320     }
  1166 void AutolockSrv::subscriberKDisplayLightsTimeoutChanged()
  1321 void AutolockSrv::subscriberKDisplayLightsTimeoutChanged()
  1167     {
  1322     {
  1168     			RDEBUG( "0", 0 );
  1323     RDEBUG("0", 0);
  1169         QVariant v = subscriberKDisplayLightsTimeout->value("/KCRUidLightSettings/KDisplayLightsTimeout");
  1324     QVariant v = subscriberKDisplayLightsTimeout->value(
  1170         // nothing to do
  1325             "/KCRUidLightSettings/KDisplayLightsTimeout");
  1171         qDebug() << "AutolockSrv::subscriberKDisplayLightsTimeoutChanged" << v;
  1326     // nothing to do
  1172 		}
  1327     qDebug() << "AutolockSrv::subscriberKDisplayLightsTimeoutChanged" << v;
       
  1328     }
  1173 void AutolockSrv::subscriberKProEngActiveProfileChanged()
  1329 void AutolockSrv::subscriberKProEngActiveProfileChanged()
  1174     {
  1330     {
  1175     			RDEBUG( "0", 0 );
  1331     RDEBUG("0", 0);
  1176         QVariant v = subscriberKProEngActiveProfile->value("/KCRUidProfileEngine/KProEngActiveProfile");
  1332     QVariant v = subscriberKProEngActiveProfile->value(
  1177         // nothing to do
  1333             "/KCRUidProfileEngine/KProEngActiveProfile");
  1178         qDebug() << "AutolockSrv::subscriberKProEngActiveProfileChanged" << v;
  1334     // nothing to do
  1179 		}
  1335     qDebug() << "AutolockSrv::subscriberKProEngActiveProfileChanged" << v;
       
  1336     }
  1180 
  1337 
  1181 // ----------AutolockSrvService---------------
  1338 // ----------AutolockSrvService---------------
  1182 
  1339 
  1183 AutolockSrvService::AutolockSrvService(AutolockSrv* parent)
  1340 AutolockSrvService::AutolockSrvService(AutolockSrv* parent) :
  1184 : XQServiceProvider(QLatin1String("com.nokia.services.AutolockSrv.AutolockSrv"),parent),
  1341     XQServiceProvider(QLatin1String(
  1185     mAutolockSrv(parent),
  1342             "com.nokia.services.AutolockSrv.AutolockSrv"), parent),
  1186     mAsyncReqId(-1),
  1343             mAutolockSrv(parent), mAsyncReqId(-1), mAsyncAnswer(false)
  1187     mAsyncAnswer(false)
  1344     {
  1188 {
  1345     RDEBUG("0", 0);
  1189 			RDEBUG( "0", 0 );
  1346     publishAll();
  1190 	  publishAll();
  1347     connect(this, SIGNAL(returnValueDelivered()), parent, SLOT(
  1191     connect(this, SIGNAL(returnValueDelivered()), parent, SLOT(handleAnswerDelivered()));
  1348             handleAnswerDelivered()));
  1192 }
  1349     }
  1193 
  1350 
  1194 AutolockSrvService::~AutolockSrvService()
  1351 AutolockSrvService::~AutolockSrvService()
  1195 {
  1352     {
  1196     	RDEBUG( "0", 0 );
  1353     RDEBUG("0", 0);
  1197 }
  1354     }
  1198 
  1355 
  1199 void AutolockSrvService::complete(QString number)
  1356 void AutolockSrvService::complete(QString number)
  1200 {
  1357     {
  1201 			RDEBUG( "0", 0 );
  1358     RDEBUG("0", 0);
  1202     if (mAsyncReqId == -1)
  1359     if (mAsyncReqId == -1)
  1203         return;
  1360         return;
  1204     XQSERVICE_DEBUG_PRINT("AutolockSrvService::complete");
  1361     XQSERVICE_DEBUG_PRINT("AutolockSrvService::complete");
  1205     completeRequest(mAsyncReqId,number.toInt());
  1362     completeRequest(mAsyncReqId, number.toInt());
  1206 }
  1363     }
  1207 
  1364 
  1208 // gor API request
  1365 // gor API request
  1209 int AutolockSrvService::service(const QString& number, const QString& aParam1, const QString& aParam2 )
  1366 int AutolockSrvService::service(const QString& number,
  1210 {
  1367         const QString& aParam1, const QString& aParam2)
  1211 			RDEBUG( "0", 0 );
  1368     {
  1212 		qDebug() << "number=" << number;
  1369     RDEBUG("0", 0);
  1213 		qDebug() << "aParam1=" << aParam1;
  1370     TInt err = KErrNone;
  1214 		qDebug() << "aParam2=" << aParam2;
  1371     qDebug() << "number=" << number;
  1215 		mAsyncAnswer = false;
  1372     qDebug() << "aParam1=" << aParam1;
       
  1373     qDebug() << "aParam2=" << aParam2;
       
  1374     mAsyncAnswer = false;
  1216     XQRequestInfo info = requestInfo();
  1375     XQRequestInfo info = requestInfo();
  1217     QSet<int> caps = info.clientCapabilities();
  1376     QSet<int> caps = info.clientCapabilities();
  1218    	
  1377 
  1219    	mAutolockSrv->callerHasECapabilityWriteDeviceData=0;
  1378     mAutolockSrv->callerHasECapabilityWriteDeviceData = 0;
  1220     if(caps.contains(ECapabilityWriteDeviceData))
  1379     if (caps.contains(ECapabilityWriteDeviceData))
  1221     	{
  1380         {
  1222    			RDEBUG( "callerHasECapabilityWriteDeviceData", ECapabilityWriteDeviceData );
  1381         RDEBUG("callerHasECapabilityWriteDeviceData",
  1223     	mAutolockSrv->callerHasECapabilityWriteDeviceData=1;
  1382                 ECapabilityWriteDeviceData);
  1224     	}
  1383         mAutolockSrv->callerHasECapabilityWriteDeviceData = 1;
  1225     
  1384         }
       
  1385 
  1226     QString label = "AutolockSrv::service:\n";
  1386     QString label = "AutolockSrv::service:\n";
  1227     label += QString("number=%1\n").arg(number);
  1387     label += QString("number=%1\n").arg(number);
  1228     
  1388 
  1229     mNumber = number ;
  1389     mNumber = number;
  1230     mAutolockSrv->setLabelNumber(label, number);
  1390     mAutolockSrv->setLabelNumber(label, number);
  1231     int ret = 0;
  1391     int ret = 0;
  1232     ret = number.toInt();
  1392     ret = number.toInt();
  1233 
  1393 
  1234 		mAutolockSrv->mParam1 = aParam1.toInt();
  1394     mAutolockSrv->mParam1 = aParam1.toInt();
  1235 		mAutolockSrv->iShowKeyguardNote = aParam1.toInt();
  1395     mAutolockSrv->iShowKeyguardNote = aParam1.toInt();
  1236 		mAutolockSrv->mParam2 = aParam2.toInt();
  1396     mAutolockSrv->mParam2 = aParam2.toInt();
  1237 		ret = mAutolockSrv->TryChangeStatus(ret);
  1397     TTime myTime;
  1238 			RDEBUG( "ret", ret );
  1398     myTime.HomeTime();
       
  1399     TInt myTimeHigh = 0;
       
  1400     TInt myTimeLow = 0;
       
  1401     err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsLockInitiatorTimeHigh, myTimeHigh );
       
  1402     RDEBUG("err", err);
       
  1403     RDEBUG("myTimeHigh", myTimeHigh);
       
  1404     err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsLockInitiatorTimeLow, myTimeLow );
       
  1405     RDEBUG("err", err);
       
  1406     RDEBUG("myTimeLow", myTimeLow);
       
  1407     
       
  1408     myTimeHigh = myTime.Int64() >> 16;
       
  1409     myTimeLow = myTime.Int64() & 0xFFFFFFFF ;
       
  1410     RDEBUG("myTimeHigh", myTimeHigh);
       
  1411     RDEBUG("myTimeLow", myTimeLow);
       
  1412     err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLockInitiatorTimeHigh, myTimeHigh );
       
  1413     err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsLockInitiatorTimeLow, myTimeLow );
       
  1414 
       
  1415 
       
  1416     ret = mAutolockSrv->TryChangeStatus(ret);
       
  1417     RDEBUG("ret", ret);
  1239     return ret;
  1418     return ret;
  1240 }
  1419     }
  1241 
  1420 
  1242 void AutolockSrvService::handleClientDisconnect()
  1421 void AutolockSrvService::handleClientDisconnect()
  1243 {
  1422     {
  1244 			RDEBUG( "0", 0 );
  1423     RDEBUG("0", 0);
  1245     // Just quit service application if client ends
  1424     // Just quit service application if client ends
  1246     mAsyncAnswer = false;
  1425     mAsyncAnswer = false;
  1247     	RDEBUG( "0", 0 );
  1426     RDEBUG("0", 0);
  1248     // mAutolockSrv->quit();
  1427     // mAutolockSrv->quit();
  1249 }
  1428     }
  1250 
  1429 
  1251 /****************/
  1430 /****************/
  1252 CWait* CWait::NewL()
  1431 CWait* CWait::NewL()
  1253     {
  1432     {
  1254     CWait* self = new(ELeave) CWait();
  1433     CWait* self = new (ELeave) CWait();
  1255     CleanupStack::PushL(self);
  1434     CleanupStack::PushL(self);
  1256     self->ConstructL();
  1435     self->ConstructL();
  1257     CleanupStack::Pop();
  1436     CleanupStack::Pop();
  1258     return self;
  1437     return self;
  1259     }
  1438     }
  1260 void CWait::ConstructL()	
  1439 void CWait::ConstructL()
  1261 	{	
  1440     {
  1262 	CActiveScheduler::Add(this);			
  1441     CActiveScheduler::Add(this);
  1263 	}
  1442     }
  1264 CWait::CWait() : CActive(0)
  1443 CWait::CWait() :
  1265 	{ 
  1444     CActive(0)
  1266 	}
  1445     {
       
  1446     }
  1267 CWait::~CWait()
  1447 CWait::~CWait()
  1268     {
  1448     {
  1269         Cancel();
  1449     Cancel();
  1270 	}
  1450     }
  1271 TInt CWait::WaitForRequestL()
  1451 TInt CWait::WaitForRequestL()
  1272     {	
  1452     {
  1273 	SetActive();
  1453     SetActive();
  1274 	iWait.Start();
  1454     iWait.Start();
  1275 	return iStatus.Int();
  1455     return iStatus.Int();
  1276 	}
  1456     }
  1277 void CWait::RunL()
  1457 void CWait::RunL()
  1278 	{
  1458     {
  1279 	if(iWait.IsStarted())		
  1459     if (iWait.IsStarted())
  1280 	    iWait.AsyncStop();
  1460         iWait.AsyncStop();
  1281 	}
  1461     }
  1282 void CWait::DoCancel()
  1462 void CWait::DoCancel()
  1283     {
  1463     {
  1284     if(iWait.IsStarted())
  1464     if (iWait.IsStarted())
  1285 	    iWait.AsyncStop();
  1465         iWait.AsyncStop();
  1286     }
  1466     }
  1287 void CWait::SetRequestType(TInt aRequestType)
  1467 void CWait::SetRequestType(TInt aRequestType)
  1288 {
  1468     {
  1289     iRequestType = aRequestType;
  1469     iRequestType = aRequestType;
  1290 }
  1470     }
  1291 TInt CWait::GetRequestType()
  1471 TInt CWait::GetRequestType()
  1292 {
  1472     {
  1293     return iRequestType;
  1473     return iRequestType;
  1294 }
  1474     }
  1295 
  1475