camerauis/cameraxui/cxui/src/cxuiapplicationframeworkmonitorprivate.cpp
changeset 40 2922f70fca82
parent 28 3075d9b614e6
child 52 7e18d488ac5f
equal deleted inserted replaced
39:c5025ea871a1 40:2922f70fca82
    23 #include <apgwgnam.h>
    23 #include <apgwgnam.h>
    24 #include <apgtask.h>
    24 #include <apgtask.h>
    25 #include <eikenv.h>
    25 #include <eikenv.h>
    26 #include <avkondomainpskeys.h>  // keyguard state
    26 #include <avkondomainpskeys.h>  // keyguard state
    27 #include <hwrmpowerstatesdkpskeys.h> // battery status
    27 #include <hwrmpowerstatesdkpskeys.h> // battery status
       
    28 #include <UsbWatcherInternalPSKeys.h> // usb status
       
    29 #include <usbman.h>
       
    30 #include <usbpersonalityids.h>
    28 
    31 
    29 #include <QMetaEnum>
    32 #include <QMetaEnum>
    30 #include <QString>
    33 #include <QString>
    31 #include <QVariant>
    34 #include <QVariant>
    32 #include <qsymbianevent.h>
    35 #include <qsymbianevent.h>
       
    36 
    33 #endif // Q_OS_SYMBIAN
    37 #endif // Q_OS_SYMBIAN
    34 
    38 
    35 #include "cxutils.h"
    39 #include "cxutils.h"
       
    40 #include "cxuieventlog.h"
    36 #include "cxuiapplication.h"
    41 #include "cxuiapplication.h"
    37 #include "cxesettings.h"
    42 #include "cxesettings.h"
    38 #include "cxuiapplicationframeworkmonitorprivate.h"
    43 #include "cxuiapplicationframeworkmonitorprivate.h"
    39 
    44 
    40 
    45 
    62             }
    67             }
    63         }
    68         }
    64         return convertTDesC2QString(name);
    69         return convertTDesC2QString(name);
    65     }
    70     }
    66 
    71 
       
    72     inline QString bitString(int number, char fill = '0', int width = 32)
       
    73     {
       
    74         return QString::number(number, 2).rightJustified(width, fill);
       
    75     }
       
    76 
    67     //!@todo: Avkon UIDs not needed once device dialogs fully implemented in Orbit.
    77     //!@todo: Avkon UIDs not needed once device dialogs fully implemented in Orbit.
    68 
    78 
    69     // AknCapServer
    79     // AknCapServer
    70     static const unsigned int UID_AKNCAPSERVER    = 0x10207218;
    80     static const unsigned int UID_AKNCAPSERVER    = 0x10207218;
    71 
    81 
    73     static const unsigned int UID_PHONEUI         = 0x100058B3;
    83     static const unsigned int UID_PHONEUI         = 0x100058B3;
    74     // Task switcher
    84     // Task switcher
    75     static const unsigned int UID_TASKSWITCHER    = 0x2002677D;
    85     static const unsigned int UID_TASKSWITCHER    = 0x2002677D;
    76     // Dialog server
    86     // Dialog server
    77     static const unsigned int UID_DIALOGAPPSERVER = 0x20022FC5;
    87     static const unsigned int UID_DIALOGAPPSERVER = 0x20022FC5;
       
    88 
       
    89     // Log event types
       
    90     static const char *EVENT_USB        = "usb";
       
    91     static const char *EVENT_FOREGROUND = "foreground";
    78 }
    92 }
    79 #endif // Q_OS_SYMBIAN
    93 #endif // Q_OS_SYMBIAN
    80 
    94 
    81 
    95 
    82 /*!
    96 /*!
    83 * Constructor
    97 * Constructor
    84 */
    98 */
    85 CxuiApplicationFrameworkMonitorPrivate::CxuiApplicationFrameworkMonitorPrivate(CxuiApplication &application, CxeSettings& settings)
    99 CxuiApplicationFrameworkMonitorPrivate::CxuiApplicationFrameworkMonitorPrivate(CxuiApplicationFrameworkMonitor *parent,
    86     :  mApplication(application),
   100                                                                                CxuiApplication &application,
       
   101                                                                                CxeSettings& settings)
       
   102     :  q(parent),
       
   103        mApplication(application),
    87        mSettings(settings),
   104        mSettings(settings),
    88 #ifdef Q_OS_SYMBIAN
   105 #ifdef Q_OS_SYMBIAN
    89        mWsSession(CCoeEnv::Static()->WsSession()),
   106        mWsSession(CCoeEnv::Static()->WsSession()),
    90        mWindowGroup(CCoeEnv::Static()->RootWin()),
   107        mWindowGroup(CCoeEnv::Static()->RootWin()),
    91        mWindowGroupId(mWindowGroup.Identifier()),
   108        mWindowGroupId(mWindowGroup.Identifier()),
    92        mWindowGroupName(),
   109        mWindowGroupName(),
    93        mKeyLockState(EKeyguardNotActive),
   110        mKeyLockState(EKeyguardNotActive),
    94        mBatteryStatus(EBatteryStatusUnknown),
   111        mBatteryStatus(EBatteryStatusUnknown),
       
   112        mUsbPersonality(0),
       
   113        mEventLog(NULL),
    95 #endif // Q_OS_SYMBIAN
   114 #endif // Q_OS_SYMBIAN
    96        mState(CxuiApplicationFrameworkMonitor::ForegroundOwned)
   115        mState(CxuiApplicationFrameworkMonitor::ForegroundOwned)
    97 {
   116 {
    98     CX_DEBUG_ENTER_FUNCTION();
   117     CX_DEBUG_ENTER_FUNCTION();
    99 
       
   100 #ifdef Q_OS_SYMBIAN
   118 #ifdef Q_OS_SYMBIAN
   101     mWindowGroup.EnableFocusChangeEvents();
   119     mWindowGroup.EnableFocusChangeEvents();
   102     mWindowGroupName = windowGroupName(mWsSession, mWindowGroupId);
   120     mWindowGroupName = windowGroupName(mWsSession, mWindowGroupId);
       
   121     mEventLog = new CxuiEventLog("CxuiApplicationFrameworkMonitorPrivate");
   103     init();
   122     init();
   104 #endif // Q_OS_SYMBIAN
   123 #endif // Q_OS_SYMBIAN
   105 
       
   106     CX_DEBUG_EXIT_FUNCTION();
   124     CX_DEBUG_EXIT_FUNCTION();
   107 }
   125 }
   108 
   126 
   109 /*!
   127 /*!
   110 * Destructor
   128 * Destructor
   111 */
   129 */
   112 CxuiApplicationFrameworkMonitorPrivate::~CxuiApplicationFrameworkMonitorPrivate()
   130 CxuiApplicationFrameworkMonitorPrivate::~CxuiApplicationFrameworkMonitorPrivate()
   113 {
   131 {
   114     CX_DEBUG_IN_FUNCTION();
   132     CX_DEBUG_ENTER_FUNCTION();
       
   133 #ifdef Q_OS_SYMBIAN
       
   134     delete mEventLog;
       
   135 #endif // Q_OS_SYMBIAN
       
   136     CX_DEBUG_EXIT_FUNCTION();
   115 }
   137 }
   116 
   138 
   117 /*!
   139 /*!
   118 * Current foreground owning state of this application.
   140 * Current foreground owning state of this application.
   119 * @return Foreground owning state.
   141 * @return Foreground owning state.
   120 */
   142 */
   121 CxuiApplicationFrameworkMonitor::ForegroundState CxuiApplicationFrameworkMonitorPrivate::foregroundState() const
   143 CxuiApplicationFrameworkMonitor::ForegroundState CxuiApplicationFrameworkMonitorPrivate::foregroundState() const
   122 {
   144 {
   123     return mState;
   145     return mState;
   124 }
   146 }
       
   147 
       
   148 /*!
       
   149 * Is USB connected in mass memory mode?
       
   150 * @return True if USB mass memory mode is active and connected, false otherwise.
       
   151 */
       
   152 bool CxuiApplicationFrameworkMonitorPrivate::isUsbMassMemoryModeActive() const
       
   153 {
       
   154     bool active(false);
       
   155 #ifdef Q_OS_SYMBIAN
       
   156     // Mass memory mode activity can be seen from the KUsbWatcherSelectedPersonality property.
       
   157     // When USB is connected in Mass Memory Mode, we get KUsbPersonalityIdMS as personality id.
       
   158     // If USB is not connected, personality id is KUsbWatcherSelectedPersonalityNone.
       
   159     active = (mUsbPersonality == KUsbPersonalityIdMS);
       
   160 #endif // Q_OS_SYMBIAN
       
   161     return active;
       
   162 }
       
   163 
       
   164 
   125 
   165 
   126 #ifdef Q_OS_SYMBIAN
   166 #ifdef Q_OS_SYMBIAN
   127 /*!
   167 /*!
   128 * Slot to handle Symbian event.
   168 * Slot to handle Symbian event.
   129 * @param event Symbian event to be handled. (Ownership not taken.)
   169 * @param event Symbian event to be handled. (Ownership not taken.)
   151 void CxuiApplicationFrameworkMonitorPrivate::handlePropertyEvent(long int uid, unsigned long int key, QVariant value)
   191 void CxuiApplicationFrameworkMonitorPrivate::handlePropertyEvent(long int uid, unsigned long int key, QVariant value)
   152 {
   192 {
   153     CX_DEBUG_ENTER_FUNCTION();
   193     CX_DEBUG_ENTER_FUNCTION();
   154 
   194 
   155     if (uid == KPSUidAvkonDomain.iUid && key == KAknKeyguardStatus) {
   195     if (uid == KPSUidAvkonDomain.iUid && key == KAknKeyguardStatus) {
   156         CX_DEBUG(("CxuiApplicationFrameworkMonitor - keylock status changed: %d -> %d", value.toInt(), mKeyLockState));
   196         CX_DEBUG(("CxuiApplicationFrameworkMonitor - keylock status changed: %d -> %d", mKeyLockState, value.toInt()));
   157 
   197 
   158         // Check if the keylock value has actually changed
   198         // Check if the keylock value has actually changed
   159         const int newKeyLockState = value.toInt();
   199         const int newKeyLockState = value.toInt();
   160         if (newKeyLockState != mKeyLockState) {
   200         if (newKeyLockState != mKeyLockState) {
   161             mKeyLockState = newKeyLockState;
   201             mKeyLockState = newKeyLockState;
   162             // Set foreground state based on keylock status and focused application info.
   202             // Set foreground state based on keylock status and focused application info.
   163             setState(getCurrentState());
   203             setState(getCurrentState());
   164         }
   204         }
   165     } else if (uid == KPSUidHWRMPowerState.iUid && key == KHWRMBatteryStatus ) {
   205     } else if (uid == KPSUidHWRMPowerState.iUid && key == KHWRMBatteryStatus ) {
   166         CX_DEBUG(("CxuiApplicationFrameworkMonitor - battery status changed: %d -> %d", value.toInt(), mBatteryStatus));
   206         CX_DEBUG(("CxuiApplicationFrameworkMonitor - battery status changed: %d -> %d", mBatteryStatus, value.toInt() ));
   167 
   207 
   168         // If status changed, check if battery is going empty.
   208         // If status changed, check if battery is going empty.
   169         const int newBatteryStatus = value.toInt();
   209         const int newBatteryStatus = value.toInt();
   170         if (newBatteryStatus != mBatteryStatus) {
   210         if (newBatteryStatus != mBatteryStatus) {
   171             mBatteryStatus = newBatteryStatus;
   211             mBatteryStatus = newBatteryStatus;
   172 
   212 
   173             // Notify that battery is almost empty,
   213             // Notify that battery is almost empty,
   174             // need to stop any recordings etc.
   214             // need to stop any recordings etc.
   175             if( mBatteryStatus == EBatteryStatusEmpty ) {
   215             if(mBatteryStatus == EBatteryStatusEmpty) {
   176                 emit batteryEmpty();
   216                 emit q->batteryEmpty();
       
   217             }
       
   218         }
       
   219     } else if (uid == KPSUidUsbWatcher.iUid && key == KUsbWatcherSelectedPersonality) {
       
   220         CX_DEBUG(("CxuiApplicationFrameworkMonitor - usb personality changed: %d -> %d", mUsbPersonality, value.toInt()));
       
   221 
       
   222         const int newUsbPersonality(value.toInt());
       
   223         if (newUsbPersonality != mUsbPersonality) {
       
   224             // Check before saving the new state if mass memory mode was active,
       
   225             // so we know when to emit the unactivated signal.
       
   226             const bool wasUsbMassMemoryModeActive(isUsbMassMemoryModeActive());
       
   227             // Store new state.
       
   228             mUsbPersonality = newUsbPersonality;
       
   229 
       
   230             // Save state to log.
       
   231             if (mEventLog) {
       
   232                 mEventLog->append(EVENT_USB, QString::number(mUsbPersonality));
       
   233             }
       
   234 
       
   235             // Check if mass memory mode activity changed.
       
   236             if (wasUsbMassMemoryModeActive != isUsbMassMemoryModeActive()) {
       
   237                 emit q->usbMassMemoryModeToggled(isUsbMassMemoryModeActive());
   177             }
   238             }
   178         }
   239         }
   179     }
   240     }
   180 
   241 
   181     CX_DEBUG_EXIT_FUNCTION();
   242     CX_DEBUG_EXIT_FUNCTION();
   199 
   260 
   200     // Get initial keylock status.
   261     // Get initial keylock status.
   201     mSettings.get(KPSUidAvkonDomain.iUid, KAknKeyguardStatus, Cxe::PublishAndSubscribe, value);
   262     mSettings.get(KPSUidAvkonDomain.iUid, KAknKeyguardStatus, Cxe::PublishAndSubscribe, value);
   202     mKeyLockState = value.toInt();
   263     mKeyLockState = value.toInt();
   203 
   264 
       
   265     // Get current USB personality
       
   266     mSettings.get(KPSUidUsbWatcher.iUid, KUsbWatcherSelectedPersonality, Cxe::PublishAndSubscribe, value);
       
   267     mUsbPersonality = value.toInt();
       
   268 
   204     bool ok = connect(&mSettings, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)),
   269     bool ok = connect(&mSettings, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)),
   205                       this, SLOT(handlePropertyEvent(long int, unsigned long int, QVariant)));
   270                       this, SLOT(handlePropertyEvent(long int, unsigned long int, QVariant)));
   206     CX_DEBUG_ASSERT(ok);
   271     CX_DEBUG_ASSERT(ok);
   207 
   272 
   208     // Get foreground state. Depends on keyguard status, so that needs to be read first.
   273     // Get foreground state. Depends on keyguard status, so that needs to be read first.
   213 
   278 
   214 /*!
   279 /*!
   215 * Helper method to handle Symbian event that specificly is of type QSymbianEvent::WindowServerEvent.
   280 * Helper method to handle Symbian event that specificly is of type QSymbianEvent::WindowServerEvent.
   216 * @param event Symbian event to be handled. (Ownership not taken.)
   281 * @param event Symbian event to be handled. (Ownership not taken.)
   217 */
   282 */
   218 bool CxuiApplicationFrameworkMonitorPrivate::handleWindowServerEvent(const QSymbianEvent *event)
   283 void CxuiApplicationFrameworkMonitorPrivate::handleWindowServerEvent(const QSymbianEvent *event)
   219     {
   284     {
   220     // We receive tons of these events, so function start and end traces
   285     // We receive tons of these events, so function start and end traces
   221     // are intentionally left out.
   286     // are intentionally left out.
   222 
   287 
   223     const TWsEvent *wsEvent = event->windowServerEvent();
   288     const TWsEvent *wsEvent = event->windowServerEvent();
   240         }
   305         }
   241         case EEventWindowVisibilityChanged: {
   306         case EEventWindowVisibilityChanged: {
   242             const TWsVisibilityChangedEvent *visibilityEvent = wsEvent->VisibilityChanged();
   307             const TWsVisibilityChangedEvent *visibilityEvent = wsEvent->VisibilityChanged();
   243             if (visibilityEvent) {
   308             if (visibilityEvent) {
   244                 CX_DEBUG(("CxuiApplicationFrameworkMonitor - EFullyVisible: bits[%s]",
   309                 CX_DEBUG(("CxuiApplicationFrameworkMonitor - EFullyVisible: bits[%s]",
   245                     QString::number(TWsVisibilityChangedEvent::EFullyVisible, 2).toAscii().constData() ));
   310                     bitString(TWsVisibilityChangedEvent::EFullyVisible).toAscii().constData() ));
   246                 CX_DEBUG(("CxuiApplicationFrameworkMonitor - EPartiallyVisible: bits[%s]",
   311                 CX_DEBUG(("CxuiApplicationFrameworkMonitor - EPartiallyVisible: bits[%s]",
   247                     QString::number(TWsVisibilityChangedEvent::EPartiallyVisible, 2).toAscii().constData() ));
   312                     bitString(TWsVisibilityChangedEvent::EPartiallyVisible).toAscii().constData() ));
   248                 CX_DEBUG(("CxuiApplicationFrameworkMonitor - ENotVisible: bits[%s]",
   313                 CX_DEBUG(("CxuiApplicationFrameworkMonitor - ENotVisible: bits[%s]",
   249                     QString::number(TWsVisibilityChangedEvent::ENotVisible, 2).toAscii().constData() ));
   314                     bitString(TWsVisibilityChangedEvent::ENotVisible).toAscii().constData() ));
   250                 CX_DEBUG(("CxuiApplicationFrameworkMonitor - event:       bits[%s]",
   315                 CX_DEBUG(("CxuiApplicationFrameworkMonitor - event:       bits[%s]",
   251                     QString::number(visibilityEvent->iFlags, 2).toAscii().constData() ));
   316                     bitString(visibilityEvent->iFlags).toAscii().constData() ));
   252             }
   317             }
   253             break;
   318             break;
   254         }
   319         }
   255         default:
   320         default:
   256             break;
   321             break;
   257         }
   322         }
   258     }
   323     }
   259 
       
   260     return false;
       
   261 }
   324 }
   262 
   325 
   263 /*!
   326 /*!
   264 * Set state and emit signal if state really changes.
   327 * Set state and emit signal if state really changes.
   265 * @param state New state.
   328 * @param state New state.
   285                 CX_DEBUG(("CxuiApplicationFrameworkMonitor - state change full bg -> partial bg ignored"));
   348                 CX_DEBUG(("CxuiApplicationFrameworkMonitor - state change full bg -> partial bg ignored"));
   286             }
   349             }
   287         }
   350         }
   288 
   351 
   289         if (mState != original) {
   352         if (mState != original) {
   290             CX_DEBUG(("CxuiApplicationFrameworkMonitor - state change [%s] -> [%s]",
   353             // Print the event log with this foreground event included.
   291                 CxuiApplicationFrameworkMonitor::staticMetaObject.enumerator(
   354             if (mEventLog) {
   292                     CxuiApplicationFrameworkMonitor::staticMetaObject.indexOfEnumerator("ForegroundState")).valueToKey(original),
   355                 mEventLog->append(
   293                 CxuiApplicationFrameworkMonitor::staticMetaObject.enumerator(
   356                     EVENT_FOREGROUND,
   294                     CxuiApplicationFrameworkMonitor::staticMetaObject.indexOfEnumerator("ForegroundState")).valueToKey(mState) ));
   357                     CxuiApplicationFrameworkMonitor::staticMetaObject.enumerator(
       
   358                         CxuiApplicationFrameworkMonitor::staticMetaObject.indexOfEnumerator("ForegroundState")).valueToKey(mState));
       
   359                 mEventLog->print();
       
   360             }
   295 
   361 
   296             // If state was changed, signal it to listeners.
   362             // If state was changed, signal it to listeners.
   297             emit foregroundStateChanged(mState);
   363             emit q->foregroundStateChanged(mState);
   298         }
   364         }
   299     }
   365     }
   300 }
   366 }
   301 
   367 
   302 /*!
   368 /*!
   310     CxuiApplicationFrameworkMonitor::ForegroundState state(CxuiApplicationFrameworkMonitor::ForegroundOwned);
   376     CxuiApplicationFrameworkMonitor::ForegroundState state(CxuiApplicationFrameworkMonitor::ForegroundOwned);
   311     int focusWindowGroupId(mWsSession.GetFocusWindowGroup());
   377     int focusWindowGroupId(mWsSession.GetFocusWindowGroup());
   312 
   378 
   313     if (mKeyLockState != EKeyguardNotActive) {
   379     if (mKeyLockState != EKeyguardNotActive) {
   314         // Keylock enabled is the same as if other application is in foreground.
   380         // Keylock enabled is the same as if other application is in foreground.
       
   381         CX_DEBUG(("CxuiApplicationFrameworkMonitor - key lock on"));
   315         state = CxuiApplicationFrameworkMonitor::ForegroundFullyLost;
   382         state = CxuiApplicationFrameworkMonitor::ForegroundFullyLost;
   316     } else if (focusWindowGroupId == mWindowGroupId) {
   383     } else if (focusWindowGroupId == mWindowGroupId) {
   317         // If our window group has focus, we clearly are the foreground owning application.
   384         // If our window group has focus, we clearly are the foreground owning application.
   318         CX_DEBUG(("CxuiApplicationFrameworkMonitor - Foreground window group matches ours."));
   385         CX_DEBUG(("CxuiApplicationFrameworkMonitor - Foreground window group matches ours."));
   319         state = CxuiApplicationFrameworkMonitor::ForegroundOwned;
   386         state = CxuiApplicationFrameworkMonitor::ForegroundOwned;
   372         t.Close();
   439         t.Close();
   373     }
   440     }
   374 
   441 
   375 #ifdef CX_DEBUG
   442 #ifdef CX_DEBUG
   376     QString name(windowGroupName(mWsSession, focusWgId));
   443     QString name(windowGroupName(mWsSession, focusWgId));
   377 
       
   378     CX_DEBUG(("CxuiApplicationFrameworkMonitor - Own window group id:     0x%08x", mWindowGroupId));
   444     CX_DEBUG(("CxuiApplicationFrameworkMonitor - Own window group id:     0x%08x", mWindowGroupId));
   379     CX_DEBUG(("CxuiApplicationFrameworkMonitor - Focused window group id: 0x%08x", focusWgId));
   445     CX_DEBUG(("CxuiApplicationFrameworkMonitor - Focused window group id: 0x%08x", focusWgId));
   380     CX_DEBUG(("CxuiApplicationFrameworkMonitor - Own window group name:        [%s]", mWindowGroupName.toAscii().constData()));
   446     CX_DEBUG(("CxuiApplicationFrameworkMonitor - Own window group name:        [%s]", mWindowGroupName.toAscii().constData()));
   381     CX_DEBUG(("CxuiApplicationFrameworkMonitor - Focused window group name:    [%s]", name.toAscii().constData()));
   447     CX_DEBUG(("CxuiApplicationFrameworkMonitor - Focused window group name:    [%s]", name.toAscii().constData()));
   382     CX_DEBUG(("CxuiApplicationFrameworkMonitor - Focused application uid: 0x%08x", uid));
   448     CX_DEBUG(("CxuiApplicationFrameworkMonitor - Focused application uid: 0x%08x", uid));