Commit 9c01ce1b6397b8cee5ad25ea3ec006a201a8f119

launcher: fix suspend time check by reading RTC instead of system time

  In testing with a Zaurus SL-C3000 it seems that when the device resumes
  apmd calls our script and the QCop systemResume() message is sent to Opie,
  the system clock has not been updated and always reads as a few seconds
  after the suspend event regardless of how long the device has been
  suspended. This change makes the launcher read the hardware real time clock
  instead of using the system clock.
  
8080INCLUDEPATH += $(OPIEDIR)/noncore/settings/mediummount
8181DEPENDPATH += $(OPIEDIR)/noncore/settings/mediummount
8282
83LIBS += -lqpe -lopiecore2 -lopieui2 -lopiesecurity2 -lqrsync
83LIBS += -lqpe -lopiecore2 -lopieui2 -lopiesecurity2 -lqrsync -lsysfs
8484TARGET = qpe
8585
8686## not ready for use yet
  
5454#endif
5555#include <stdlib.h>
5656
57#include <sysfs/libsysfs.h>
58
5759// NOTE: when we talk about "login" here we are talking about the
5860// authentication system (MultiAuth) and not opie-login
5961
6062static ServerApplication *serverApp = 0;
6163static bool loginlock = false; // TRUE if the authentication system is currently shown
62static QDateTime suspendDateTime;
64static int suspendEpoch;
65static int resumeEpoch;
6366
6467QCopKeyRegister::QCopKeyRegister()
6568 : m_keyCode( 0 )
598598 bool skipEnabled = pcfg.readBoolEntry( "suspendTime", false );
599599 if( skipEnabled ) {
600600 int skipTime = pcfg.readNumEntry( "suspendTimeMins", 2 ) * 60;
601 int secsSuspended = suspendDateTime.secsTo( QDateTime::currentDateTime() );
601 int secsSuspended = resumeEpoch - suspendEpoch;
602602 if ( secsSuspended < skipTime )
603603 return true;
604604 }
626626#endif
627627
628628namespace {
629 void execAutoStart(const QDateTime& suspendTime ) {
629 void execAutoStart() {
630630 QString appName;
631631 int delay;
632632 QDateTime now = QDateTime::currentDateTime();
638638
639639 // If the time between suspend and resume was longer then the
640640 // value saved as delay, start the app
641 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) {
641 if ( (resumeEpoch - suspendEpoch) >= ( delay * 60 ) && !appName.isEmpty() ) {
642642 QCopEnvelope e( "QPE/System", "execute(QString)" );
643643 e << QString( appName );
644644 }
645645 }
646646}
647647
648int ServerApplication::readRtc()
649{
650 int ret = 0;
651
652 struct sysfs_class *cls = sysfs_open_class( "rtc" );
653 if( cls ) {
654 struct sysfs_class_device *cdev = sysfs_get_class_device( cls, "rtc0" );
655 if( cdev ) {
656 struct sysfs_attribute *attr = sysfs_get_classdev_attr( cdev, "since_epoch" );
657 if( attr ) {
658 if( sysfs_read_attribute( attr ) == 0 )
659 ret = atoi( attr->value );
660 }
661 }
662 sysfs_close_class( cls );
663 }
664
665 return ret;
666}
667
648668void ServerApplication::doBeforeSuspend()
649669{
650 suspendDateTime = QDateTime::currentDateTime();
670 suspendEpoch = readRtc();
651671
652672#ifdef QWS
653673 // Notify user that the system is suspending
696696 e << QString::null;
697697#endif
698698
699 resumeEpoch = readRtc();
700
699701 if( !loginlock && Opie::Security::MultiauthPassword::isAuthenticating() ) {
700702 // Authentication is already taking place but not by us (eg. because the
701703 // user used the lock applet before suspending), so we need to let it
721721
722722void ServerApplication::doAfterResume()
723723{
724 execAutoStart( suspendDateTime );
724 execAutoStart();
725725}
726726
727727void ServerApplication::togglePower()
  
139139 void doResume();
140140 void doAfterResume();
141141 void doBeforeSuspend();
142 int readRtc();
142143
143144protected slots:
144145 void shutdown(ShutdownImpl::Type);