camerauis/cameraxui/cxui/src/cxuiapplicationframeworkmonitorprivate.cpp
author hgs
Thu, 15 Jul 2010 01:49:11 +0300
changeset 40 2922f70fca82
parent 28 3075d9b614e6
child 52 7e18d488ac5f
permissions -rw-r--r--
201023
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
     1
/*
3075d9b614e6 201017_1
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
3075d9b614e6 201017_1
hgs
parents:
diff changeset
     3
* All rights reserved.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
3075d9b614e6 201017_1
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
3075d9b614e6 201017_1
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
3075d9b614e6 201017_1
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
3075d9b614e6 201017_1
hgs
parents:
diff changeset
     8
*
3075d9b614e6 201017_1
hgs
parents:
diff changeset
     9
* Initial Contributors:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    11
*
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    12
* Contributors:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    13
*
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    14
* Description:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    15
*
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    16
*/
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    17
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    18
#include <QObject>
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    19
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    20
#ifdef Q_OS_SYMBIAN
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    21
#include <e32cmn.h>
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    22
#include <w32std.h>
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    23
#include <apgwgnam.h>
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    24
#include <apgtask.h>
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    25
#include <eikenv.h>
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    26
#include <avkondomainpskeys.h>  // keyguard state
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    27
#include <hwrmpowerstatesdkpskeys.h> // battery status
40
hgs
parents: 28
diff changeset
    28
#include <UsbWatcherInternalPSKeys.h> // usb status
hgs
parents: 28
diff changeset
    29
#include <usbman.h>
hgs
parents: 28
diff changeset
    30
#include <usbpersonalityids.h>
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    31
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    32
#include <QMetaEnum>
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    33
#include <QString>
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    34
#include <QVariant>
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    35
#include <qsymbianevent.h>
40
hgs
parents: 28
diff changeset
    36
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    37
#endif // Q_OS_SYMBIAN
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    38
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    39
#include "cxutils.h"
40
hgs
parents: 28
diff changeset
    40
#include "cxuieventlog.h"
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    41
#include "cxuiapplication.h"
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    42
#include "cxesettings.h"
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    43
#include "cxuiapplicationframeworkmonitorprivate.h"
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    44
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    45
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    46
#ifdef Q_OS_SYMBIAN
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    47
namespace
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    48
{
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    49
    inline QString convertTDesC2QString(const TDesC& aDescriptor)
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    50
    {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    51
        #ifdef QT_NO_UNICODE
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    52
            return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length());
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    53
        #else
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    54
            return QString::fromUtf16(aDescriptor.Ptr(), aDescriptor.Length());
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    55
        #endif
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    56
    }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    57
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    58
    inline QString windowGroupName(RWsSession& ws, int id)
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    59
    {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    60
        TBuf<CApaWindowGroupName::EMaxLength> name;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    61
        ws.GetWindowGroupNameFromIdentifier(id, name);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    62
        // Window group name contains "null" characters,
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    63
        // which are considered end-of-string if not replaced.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    64
        for (int i=0; i < name.Length(); i++) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    65
            if (name[i] == NULL) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    66
                name[i] = ' ';
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    67
            }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    68
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    69
        return convertTDesC2QString(name);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    70
    }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    71
40
hgs
parents: 28
diff changeset
    72
    inline QString bitString(int number, char fill = '0', int width = 32)
hgs
parents: 28
diff changeset
    73
    {
hgs
parents: 28
diff changeset
    74
        return QString::number(number, 2).rightJustified(width, fill);
hgs
parents: 28
diff changeset
    75
    }
hgs
parents: 28
diff changeset
    76
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    77
    //!@todo: Avkon UIDs not needed once device dialogs fully implemented in Orbit.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    78
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    79
    // AknCapServer
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    80
    static const unsigned int UID_AKNCAPSERVER    = 0x10207218;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    81
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    82
    // Phone ui
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    83
    static const unsigned int UID_PHONEUI         = 0x100058B3;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    84
    // Task switcher
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    85
    static const unsigned int UID_TASKSWITCHER    = 0x2002677D;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    86
    // Dialog server
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    87
    static const unsigned int UID_DIALOGAPPSERVER = 0x20022FC5;
40
hgs
parents: 28
diff changeset
    88
hgs
parents: 28
diff changeset
    89
    // Log event types
hgs
parents: 28
diff changeset
    90
    static const char *EVENT_USB        = "usb";
hgs
parents: 28
diff changeset
    91
    static const char *EVENT_FOREGROUND = "foreground";
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    92
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    93
#endif // Q_OS_SYMBIAN
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    94
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    95
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    96
/*!
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    97
* Constructor
3075d9b614e6 201017_1
hgs
parents:
diff changeset
    98
*/
40
hgs
parents: 28
diff changeset
    99
CxuiApplicationFrameworkMonitorPrivate::CxuiApplicationFrameworkMonitorPrivate(CxuiApplicationFrameworkMonitor *parent,
hgs
parents: 28
diff changeset
   100
                                                                               CxuiApplication &application,
hgs
parents: 28
diff changeset
   101
                                                                               CxeSettings& settings)
hgs
parents: 28
diff changeset
   102
    :  q(parent),
hgs
parents: 28
diff changeset
   103
       mApplication(application),
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   104
       mSettings(settings),
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   105
#ifdef Q_OS_SYMBIAN
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   106
       mWsSession(CCoeEnv::Static()->WsSession()),
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   107
       mWindowGroup(CCoeEnv::Static()->RootWin()),
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   108
       mWindowGroupId(mWindowGroup.Identifier()),
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   109
       mWindowGroupName(),
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   110
       mKeyLockState(EKeyguardNotActive),
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   111
       mBatteryStatus(EBatteryStatusUnknown),
40
hgs
parents: 28
diff changeset
   112
       mUsbPersonality(0),
hgs
parents: 28
diff changeset
   113
       mEventLog(NULL),
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   114
#endif // Q_OS_SYMBIAN
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   115
       mState(CxuiApplicationFrameworkMonitor::ForegroundOwned)
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   116
{
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   117
    CX_DEBUG_ENTER_FUNCTION();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   118
#ifdef Q_OS_SYMBIAN
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   119
    mWindowGroup.EnableFocusChangeEvents();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   120
    mWindowGroupName = windowGroupName(mWsSession, mWindowGroupId);
40
hgs
parents: 28
diff changeset
   121
    mEventLog = new CxuiEventLog("CxuiApplicationFrameworkMonitorPrivate");
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   122
    init();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   123
#endif // Q_OS_SYMBIAN
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   124
    CX_DEBUG_EXIT_FUNCTION();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   125
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   126
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   127
/*!
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   128
* Destructor
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   129
*/
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   130
CxuiApplicationFrameworkMonitorPrivate::~CxuiApplicationFrameworkMonitorPrivate()
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   131
{
40
hgs
parents: 28
diff changeset
   132
    CX_DEBUG_ENTER_FUNCTION();
hgs
parents: 28
diff changeset
   133
#ifdef Q_OS_SYMBIAN
hgs
parents: 28
diff changeset
   134
    delete mEventLog;
hgs
parents: 28
diff changeset
   135
#endif // Q_OS_SYMBIAN
hgs
parents: 28
diff changeset
   136
    CX_DEBUG_EXIT_FUNCTION();
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   137
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   138
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   139
/*!
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   140
* Current foreground owning state of this application.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   141
* @return Foreground owning state.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   142
*/
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   143
CxuiApplicationFrameworkMonitor::ForegroundState CxuiApplicationFrameworkMonitorPrivate::foregroundState() const
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   144
{
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   145
    return mState;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   146
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   147
40
hgs
parents: 28
diff changeset
   148
/*!
hgs
parents: 28
diff changeset
   149
* Is USB connected in mass memory mode?
hgs
parents: 28
diff changeset
   150
* @return True if USB mass memory mode is active and connected, false otherwise.
hgs
parents: 28
diff changeset
   151
*/
hgs
parents: 28
diff changeset
   152
bool CxuiApplicationFrameworkMonitorPrivate::isUsbMassMemoryModeActive() const
hgs
parents: 28
diff changeset
   153
{
hgs
parents: 28
diff changeset
   154
    bool active(false);
hgs
parents: 28
diff changeset
   155
#ifdef Q_OS_SYMBIAN
hgs
parents: 28
diff changeset
   156
    // Mass memory mode activity can be seen from the KUsbWatcherSelectedPersonality property.
hgs
parents: 28
diff changeset
   157
    // When USB is connected in Mass Memory Mode, we get KUsbPersonalityIdMS as personality id.
hgs
parents: 28
diff changeset
   158
    // If USB is not connected, personality id is KUsbWatcherSelectedPersonalityNone.
hgs
parents: 28
diff changeset
   159
    active = (mUsbPersonality == KUsbPersonalityIdMS);
hgs
parents: 28
diff changeset
   160
#endif // Q_OS_SYMBIAN
hgs
parents: 28
diff changeset
   161
    return active;
hgs
parents: 28
diff changeset
   162
}
hgs
parents: 28
diff changeset
   163
hgs
parents: 28
diff changeset
   164
hgs
parents: 28
diff changeset
   165
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   166
#ifdef Q_OS_SYMBIAN
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   167
/*!
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   168
* Slot to handle Symbian event.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   169
* @param event Symbian event to be handled. (Ownership not taken.)
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   170
*/
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   171
void CxuiApplicationFrameworkMonitorPrivate::handleEvent(const QSymbianEvent *event)
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   172
{
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   173
    // We receive tons of these events, so function start and end traces
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   174
    // are intentionally left out.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   175
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   176
    if (event) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   177
        switch (event->type()) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   178
        case QSymbianEvent::WindowServerEvent:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   179
            handleWindowServerEvent(event);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   180
            break;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   181
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   182
    }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   183
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   184
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   185
/*!
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   186
* Handle changes in RProperty values of keylock state and battery status.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   187
* @param uid Category uid of the changed property.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   188
* @param key Integer key of the changed property.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   189
* @param value New value of the changed property.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   190
*/
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   191
void CxuiApplicationFrameworkMonitorPrivate::handlePropertyEvent(long int uid, unsigned long int key, QVariant value)
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   192
{
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   193
    CX_DEBUG_ENTER_FUNCTION();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   194
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   195
    if (uid == KPSUidAvkonDomain.iUid && key == KAknKeyguardStatus) {
40
hgs
parents: 28
diff changeset
   196
        CX_DEBUG(("CxuiApplicationFrameworkMonitor - keylock status changed: %d -> %d", mKeyLockState, value.toInt()));
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   197
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   198
        // Check if the keylock value has actually changed
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   199
        const int newKeyLockState = value.toInt();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   200
        if (newKeyLockState != mKeyLockState) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   201
            mKeyLockState = newKeyLockState;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   202
            // Set foreground state based on keylock status and focused application info.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   203
            setState(getCurrentState());
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   204
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   205
    } else if (uid == KPSUidHWRMPowerState.iUid && key == KHWRMBatteryStatus ) {
40
hgs
parents: 28
diff changeset
   206
        CX_DEBUG(("CxuiApplicationFrameworkMonitor - battery status changed: %d -> %d", mBatteryStatus, value.toInt() ));
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   207
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   208
        // If status changed, check if battery is going empty.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   209
        const int newBatteryStatus = value.toInt();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   210
        if (newBatteryStatus != mBatteryStatus) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   211
            mBatteryStatus = newBatteryStatus;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   212
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   213
            // Notify that battery is almost empty,
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   214
            // need to stop any recordings etc.
40
hgs
parents: 28
diff changeset
   215
            if(mBatteryStatus == EBatteryStatusEmpty) {
hgs
parents: 28
diff changeset
   216
                emit q->batteryEmpty();
hgs
parents: 28
diff changeset
   217
            }
hgs
parents: 28
diff changeset
   218
        }
hgs
parents: 28
diff changeset
   219
    } else if (uid == KPSUidUsbWatcher.iUid && key == KUsbWatcherSelectedPersonality) {
hgs
parents: 28
diff changeset
   220
        CX_DEBUG(("CxuiApplicationFrameworkMonitor - usb personality changed: %d -> %d", mUsbPersonality, value.toInt()));
hgs
parents: 28
diff changeset
   221
hgs
parents: 28
diff changeset
   222
        const int newUsbPersonality(value.toInt());
hgs
parents: 28
diff changeset
   223
        if (newUsbPersonality != mUsbPersonality) {
hgs
parents: 28
diff changeset
   224
            // Check before saving the new state if mass memory mode was active,
hgs
parents: 28
diff changeset
   225
            // so we know when to emit the unactivated signal.
hgs
parents: 28
diff changeset
   226
            const bool wasUsbMassMemoryModeActive(isUsbMassMemoryModeActive());
hgs
parents: 28
diff changeset
   227
            // Store new state.
hgs
parents: 28
diff changeset
   228
            mUsbPersonality = newUsbPersonality;
hgs
parents: 28
diff changeset
   229
hgs
parents: 28
diff changeset
   230
            // Save state to log.
hgs
parents: 28
diff changeset
   231
            if (mEventLog) {
hgs
parents: 28
diff changeset
   232
                mEventLog->append(EVENT_USB, QString::number(mUsbPersonality));
hgs
parents: 28
diff changeset
   233
            }
hgs
parents: 28
diff changeset
   234
hgs
parents: 28
diff changeset
   235
            // Check if mass memory mode activity changed.
hgs
parents: 28
diff changeset
   236
            if (wasUsbMassMemoryModeActive != isUsbMassMemoryModeActive()) {
hgs
parents: 28
diff changeset
   237
                emit q->usbMassMemoryModeToggled(isUsbMassMemoryModeActive());
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   238
            }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   239
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   240
    }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   241
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   242
    CX_DEBUG_EXIT_FUNCTION();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   243
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   244
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   245
/*!
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   246
* Set initial values.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   247
*/
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   248
void CxuiApplicationFrameworkMonitorPrivate::init()
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   249
{
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   250
    CX_DEBUG_ENTER_FUNCTION();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   251
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   252
    // Connect to application (window server) events.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   253
    connect(&mApplication, SIGNAL(symbianEvent(const QSymbianEvent *)), this, SLOT(handleEvent(const QSymbianEvent *)));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   254
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   255
    QVariant value;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   256
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   257
    // Get initial battery status.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   258
    mSettings.get(KPSUidHWRMPowerState.iUid, KHWRMBatteryStatus, Cxe::PublishAndSubscribe, value);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   259
    mBatteryStatus = value.toInt();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   260
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   261
    // Get initial keylock status.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   262
    mSettings.get(KPSUidAvkonDomain.iUid, KAknKeyguardStatus, Cxe::PublishAndSubscribe, value);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   263
    mKeyLockState = value.toInt();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   264
40
hgs
parents: 28
diff changeset
   265
    // Get current USB personality
hgs
parents: 28
diff changeset
   266
    mSettings.get(KPSUidUsbWatcher.iUid, KUsbWatcherSelectedPersonality, Cxe::PublishAndSubscribe, value);
hgs
parents: 28
diff changeset
   267
    mUsbPersonality = value.toInt();
hgs
parents: 28
diff changeset
   268
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   269
    bool ok = connect(&mSettings, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)),
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   270
                      this, SLOT(handlePropertyEvent(long int, unsigned long int, QVariant)));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   271
    CX_DEBUG_ASSERT(ok);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   272
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   273
    // Get foreground state. Depends on keyguard status, so that needs to be read first.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   274
    mState = getCurrentState();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   275
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   276
    CX_DEBUG_EXIT_FUNCTION();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   277
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   278
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   279
/*!
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   280
* Helper method to handle Symbian event that specificly is of type QSymbianEvent::WindowServerEvent.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   281
* @param event Symbian event to be handled. (Ownership not taken.)
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   282
*/
40
hgs
parents: 28
diff changeset
   283
void CxuiApplicationFrameworkMonitorPrivate::handleWindowServerEvent(const QSymbianEvent *event)
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   284
    {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   285
    // We receive tons of these events, so function start and end traces
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   286
    // are intentionally left out.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   287
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   288
    const TWsEvent *wsEvent = event->windowServerEvent();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   289
    if (wsEvent) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   290
        switch (wsEvent->Type()) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   291
        case EEventFocusGroupChanged: {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   292
            CX_DEBUG(("CxuiApplicationFrameworkMonitor - EEventFocusGroupChanged event"));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   293
            setState(getCurrentState());
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   294
            break;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   295
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   296
        case EEventFocusGained: {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   297
            CX_DEBUG(("CxuiApplicationFrameworkMonitor - EEventFocusGained event"));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   298
            setState(getCurrentState());
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   299
            break;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   300
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   301
        case EEventFocusLost: {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   302
            CX_DEBUG(("CxuiApplicationFrameworkMonitor - EEventFocusLost event"));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   303
            setState(getCurrentState());
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   304
            break;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   305
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   306
        case EEventWindowVisibilityChanged: {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   307
            const TWsVisibilityChangedEvent *visibilityEvent = wsEvent->VisibilityChanged();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   308
            if (visibilityEvent) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   309
                CX_DEBUG(("CxuiApplicationFrameworkMonitor - EFullyVisible: bits[%s]",
40
hgs
parents: 28
diff changeset
   310
                    bitString(TWsVisibilityChangedEvent::EFullyVisible).toAscii().constData() ));
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   311
                CX_DEBUG(("CxuiApplicationFrameworkMonitor - EPartiallyVisible: bits[%s]",
40
hgs
parents: 28
diff changeset
   312
                    bitString(TWsVisibilityChangedEvent::EPartiallyVisible).toAscii().constData() ));
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   313
                CX_DEBUG(("CxuiApplicationFrameworkMonitor - ENotVisible: bits[%s]",
40
hgs
parents: 28
diff changeset
   314
                    bitString(TWsVisibilityChangedEvent::ENotVisible).toAscii().constData() ));
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   315
                CX_DEBUG(("CxuiApplicationFrameworkMonitor - event:       bits[%s]",
40
hgs
parents: 28
diff changeset
   316
                    bitString(visibilityEvent->iFlags).toAscii().constData() ));
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   317
            }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   318
            break;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   319
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   320
        default:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   321
            break;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   322
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   323
    }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   324
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   325
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   326
/*!
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   327
* Set state and emit signal if state really changes.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   328
* @param state New state.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   329
*/
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   330
void CxuiApplicationFrameworkMonitorPrivate::setState(CxuiApplicationFrameworkMonitor::ForegroundState state)
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   331
{
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   332
    if (mState != state) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   333
        const CxuiApplicationFrameworkMonitor::ForegroundState original(mState);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   334
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   335
        // Check if state transition is acceptable in current state.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   336
        switch (mState) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   337
        case CxuiApplicationFrameworkMonitor::ForegroundOwned:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   338
        case CxuiApplicationFrameworkMonitor::ForegroundPartiallyLost:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   339
            // All changes accepted.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   340
            mState = state;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   341
            break;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   342
        case CxuiApplicationFrameworkMonitor::ForegroundFullyLost:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   343
            // If foreground application is changed to note when we are already
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   344
            // fully in background, cannot accept state change to "partial foreground".
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   345
            if (state != CxuiApplicationFrameworkMonitor::ForegroundPartiallyLost) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   346
                mState = state;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   347
            } else {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   348
                CX_DEBUG(("CxuiApplicationFrameworkMonitor - state change full bg -> partial bg ignored"));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   349
            }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   350
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   351
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   352
        if (mState != original) {
40
hgs
parents: 28
diff changeset
   353
            // Print the event log with this foreground event included.
hgs
parents: 28
diff changeset
   354
            if (mEventLog) {
hgs
parents: 28
diff changeset
   355
                mEventLog->append(
hgs
parents: 28
diff changeset
   356
                    EVENT_FOREGROUND,
hgs
parents: 28
diff changeset
   357
                    CxuiApplicationFrameworkMonitor::staticMetaObject.enumerator(
hgs
parents: 28
diff changeset
   358
                        CxuiApplicationFrameworkMonitor::staticMetaObject.indexOfEnumerator("ForegroundState")).valueToKey(mState));
hgs
parents: 28
diff changeset
   359
                mEventLog->print();
hgs
parents: 28
diff changeset
   360
            }
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   361
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   362
            // If state was changed, signal it to listeners.
40
hgs
parents: 28
diff changeset
   363
            emit q->foregroundStateChanged(mState);
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   364
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   365
    }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   366
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   367
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   368
/*!
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   369
* Get the current foreground state.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   370
* @return Current state for foreground ownership.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   371
*/
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   372
CxuiApplicationFrameworkMonitor::ForegroundState CxuiApplicationFrameworkMonitorPrivate::getCurrentState()
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   373
{
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   374
    CX_DEBUG_ENTER_FUNCTION();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   375
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   376
    CxuiApplicationFrameworkMonitor::ForegroundState state(CxuiApplicationFrameworkMonitor::ForegroundOwned);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   377
    int focusWindowGroupId(mWsSession.GetFocusWindowGroup());
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   378
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   379
    if (mKeyLockState != EKeyguardNotActive) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   380
        // Keylock enabled is the same as if other application is in foreground.
40
hgs
parents: 28
diff changeset
   381
        CX_DEBUG(("CxuiApplicationFrameworkMonitor - key lock on"));
28
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   382
        state = CxuiApplicationFrameworkMonitor::ForegroundFullyLost;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   383
    } else if (focusWindowGroupId == mWindowGroupId) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   384
        // If our window group has focus, we clearly are the foreground owning application.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   385
        CX_DEBUG(("CxuiApplicationFrameworkMonitor - Foreground window group matches ours."));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   386
        state = CxuiApplicationFrameworkMonitor::ForegroundOwned;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   387
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   388
    } else {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   389
        // Need to check if foreground is owned by known apps.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   390
        unsigned int uid(focusedApplicationUid());
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   391
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   392
        // Check the app uid.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   393
        switch (uid) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   394
        case UID_AKNCAPSERVER:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   395
        case UID_TASKSWITCHER:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   396
        case UID_DIALOGAPPSERVER:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   397
            // Note or task switcher in foreground.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   398
            state = CxuiApplicationFrameworkMonitor::ForegroundPartiallyLost;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   399
            break;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   400
        case UID_PHONEUI:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   401
        default:
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   402
            // Foreground owned by other app.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   403
            state = CxuiApplicationFrameworkMonitor::ForegroundFullyLost;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   404
            break;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   405
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   406
    }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   407
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   408
    CX_DEBUG_EXIT_FUNCTION();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   409
    return state;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   410
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   411
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   412
/*!
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   413
* Get the uid of application in foreground.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   414
* @return Application uid for the foreground application.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   415
*/
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   416
unsigned int CxuiApplicationFrameworkMonitorPrivate::focusedApplicationUid()
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   417
{
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   418
    unsigned int uid(0);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   419
    int focusWgId(mWsSession.GetFocusWindowGroup());
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   420
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   421
    TRAP_IGNORE({
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   422
        CApaWindowGroupName* wgn = CApaWindowGroupName::NewLC(mWsSession, focusWgId);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   423
        uid = wgn->AppUid().iUid;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   424
        CleanupStack::PopAndDestroy(wgn);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   425
    });
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   426
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   427
    // If the window group identifier does not have the application uid set,
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   428
    // get it via thread secure id.
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   429
    if (uid == 0) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   430
        TApaTask task(mWsSession);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   431
        task.SetWgId(focusWgId);
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   432
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   433
        RThread t;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   434
        int err = t.Open(task.ThreadId());
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   435
        if (err == KErrNone) {
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   436
            uid = t.SecureId().iId;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   437
            CX_DEBUG(("CxuiApplicationFrameworkMonitor - uid resolved from thread"));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   438
        }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   439
        t.Close();
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   440
    }
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   441
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   442
#ifdef CX_DEBUG
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   443
    QString name(windowGroupName(mWsSession, focusWgId));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   444
    CX_DEBUG(("CxuiApplicationFrameworkMonitor - Own window group id:     0x%08x", mWindowGroupId));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   445
    CX_DEBUG(("CxuiApplicationFrameworkMonitor - Focused window group id: 0x%08x", focusWgId));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   446
    CX_DEBUG(("CxuiApplicationFrameworkMonitor - Own window group name:        [%s]", mWindowGroupName.toAscii().constData()));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   447
    CX_DEBUG(("CxuiApplicationFrameworkMonitor - Focused window group name:    [%s]", name.toAscii().constData()));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   448
    CX_DEBUG(("CxuiApplicationFrameworkMonitor - Focused application uid: 0x%08x", uid));
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   449
#endif
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   450
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   451
    return uid;
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   452
}
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   453
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   454
#endif // Q_OS_SYMBIAN
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   455
3075d9b614e6 201017_1
hgs
parents:
diff changeset
   456
// end of file