bluetoothengine/bteng/src/btengsrvsettingsmgr.cpp
author hgs
Fri, 23 Apr 2010 23:54:40 +0300
changeset 24 8930e1d1d530
parent 23 988cddd6adbd
child 13 b6f55cd40afd
permissions -rw-r--r--
201009
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: Class to manage Bluetooth hardware and stack settings.
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "btengsrvsettingsmgr.h"
hgs
parents:
diff changeset
    19
#include <bthci.h>
hgs
parents:
diff changeset
    20
#include <bt_subscribe_partner.h>
hgs
parents:
diff changeset
    21
#include <btnotif.h>
hgs
parents:
diff changeset
    22
#include <btengdomainpskeys.h>
hgs
parents:
diff changeset
    23
#include <centralrepository.h>
hgs
parents:
diff changeset
    24
#include <featmgr.h>
hgs
parents:
diff changeset
    25
#include <AknSmallIndicator.h>
hgs
parents:
diff changeset
    26
#include <avkon.hrh>
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
#include "btengserver.h"
hgs
parents:
diff changeset
    29
#include "btengsrvpluginmgr.h"
hgs
parents:
diff changeset
    30
#include "btengsrvbbconnectionmgr.h"
hgs
parents:
diff changeset
    31
#include "btengsrvstate.h"
hgs
parents:
diff changeset
    32
#include "debug.h"
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
#ifndef SETLOCALNAME
hgs
parents:
diff changeset
    35
#include <btengsettings.h>
hgs
parents:
diff changeset
    36
#endif
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
/** ID of active object helper */
hgs
parents:
diff changeset
    39
const TInt KBTEngSettingsActive = 30;
hgs
parents:
diff changeset
    40
/** Constant for converting minutes to microseconds */
hgs
parents:
diff changeset
    41
//const TInt64 KMinutesInMicroSecs = 60000000;
hgs
parents:
diff changeset
    42
const TInt64 KMinutesInMicroSecs = MAKE_TINT64( 0, 60000000 );
hgs
parents:
diff changeset
    43
/**  Timeout for disabling Simple Pairing debug mode. The value is 30 minutes. */
hgs
parents:
diff changeset
    44
//const TInt KBTEngSspDebugModeTimeout = 1800000000;
hgs
parents:
diff changeset
    45
const TInt64 KBTEngSspDebugModeTimeout = MAKE_TINT64( 0, 1800000000 );
hgs
parents:
diff changeset
    46
/**  Timeout for turning BT off automatically. The value is 10.5 seconds. */
hgs
parents:
diff changeset
    47
const TInt KBTEngBtAutoOffTimeout = 10500000;
hgs
parents:
diff changeset
    48
/**  Default values for Major Service Class */
hgs
parents:
diff changeset
    49
const TUint16 KCoDDefaultServiceClass = EMajorServiceTelephony | EMajorServiceObjectTransfer | EMajorServiceNetworking;
hgs
parents:
diff changeset
    50
/**  Default values for Major Device Class */
hgs
parents:
diff changeset
    51
const TUint8 KCoDDefaultMajorDeviceClass = EMajorDevicePhone;
hgs
parents:
diff changeset
    52
/**  Default values for Minor Device Class */
hgs
parents:
diff changeset
    53
const TUint8 KCoDDefaultMinorDeviceClass = EMinorDevicePhoneSmartPhone;
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
hgs
parents:
diff changeset
    56
// ======== MEMBER FUNCTIONS ========
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    59
// C++ default constructor
hgs
parents:
diff changeset
    60
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    61
//
hgs
parents:
diff changeset
    62
CBTEngSrvSettingsMgr::CBTEngSrvSettingsMgr( CBTEngServer* aServer )
hgs
parents:
diff changeset
    63
:   iServer( aServer )
hgs
parents:
diff changeset
    64
    {
hgs
parents:
diff changeset
    65
    }
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    69
// Symbian second-phase constructor
hgs
parents:
diff changeset
    70
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    71
//
hgs
parents:
diff changeset
    72
void CBTEngSrvSettingsMgr::ConstructL()
hgs
parents:
diff changeset
    73
    {
hgs
parents:
diff changeset
    74
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
    75
    iActive = CBTEngActive::NewL( *this, KBTEngSettingsActive );
hgs
parents:
diff changeset
    76
    LoadBTPowerManagerL();
hgs
parents:
diff changeset
    77
    iEnterpriseEnablementMode = BluetoothFeatures::EnterpriseEnablementL();
hgs
parents:
diff changeset
    78
    TRACE_INFO( ( _L( "iEnterpriseEnablementMode = %d" ), iEnterpriseEnablementMode) )
hgs
parents:
diff changeset
    79
    if ( iEnterpriseEnablementMode == BluetoothFeatures::EDisabled )
hgs
parents:
diff changeset
    80
        {
hgs
parents:
diff changeset
    81
        SetVisibilityModeL( EBTVisibilityModeNoScans, 0 );
hgs
parents:
diff changeset
    82
        }
hgs
parents:
diff changeset
    83
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
    84
    }
hgs
parents:
diff changeset
    85
hgs
parents:
diff changeset
    86
hgs
parents:
diff changeset
    87
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    88
// NewL
hgs
parents:
diff changeset
    89
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    90
//
hgs
parents:
diff changeset
    91
CBTEngSrvSettingsMgr* CBTEngSrvSettingsMgr::NewL( CBTEngServer* aServer )
hgs
parents:
diff changeset
    92
    {
hgs
parents:
diff changeset
    93
    CBTEngSrvSettingsMgr* self = new( ELeave ) CBTEngSrvSettingsMgr( aServer );
hgs
parents:
diff changeset
    94
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    95
    self->ConstructL();
hgs
parents:
diff changeset
    96
    CleanupStack::Pop( self );
hgs
parents:
diff changeset
    97
    return self;
hgs
parents:
diff changeset
    98
    }
hgs
parents:
diff changeset
    99
hgs
parents:
diff changeset
   100
hgs
parents:
diff changeset
   101
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   102
// Destructor
hgs
parents:
diff changeset
   103
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   104
//
hgs
parents:
diff changeset
   105
CBTEngSrvSettingsMgr::~CBTEngSrvSettingsMgr()
hgs
parents:
diff changeset
   106
    {
hgs
parents:
diff changeset
   107
    if( iActive && iActive->IsActive() )
hgs
parents:
diff changeset
   108
        {
hgs
parents:
diff changeset
   109
        // Cancel the outstanding request.
hgs
parents:
diff changeset
   110
        iPowerMgr.Cancel();
hgs
parents:
diff changeset
   111
        }
hgs
parents:
diff changeset
   112
    delete iActive;  
hgs
parents:
diff changeset
   113
    iPowerMgr.Close();
hgs
parents:
diff changeset
   114
    }
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   118
// Power Bluetooth hardware on or off.
hgs
parents:
diff changeset
   119
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   120
//
hgs
parents:
diff changeset
   121
TInt CBTEngSrvSettingsMgr::SetHwPowerState( TBTPowerState aState )
hgs
parents:
diff changeset
   122
    {
hgs
parents:
diff changeset
   123
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   124
    TInt err = KErrNone;
hgs
parents:
diff changeset
   125
#ifndef __WINS__
hgs
parents:
diff changeset
   126
    if( iActive->IsActive() )
hgs
parents:
diff changeset
   127
        {
hgs
parents:
diff changeset
   128
        // Cancel the outstanding request.
hgs
parents:
diff changeset
   129
        iPowerMgr.Cancel();
hgs
parents:
diff changeset
   130
        iActive->Cancel();
hgs
parents:
diff changeset
   131
        }
hgs
parents:
diff changeset
   132
    iPowerMgr.SetPower( aState, NULL, iActive->RequestStatus() );
hgs
parents:
diff changeset
   133
    iActive->GoActive();
hgs
parents:
diff changeset
   134
#else   //__WINS__
hgs
parents:
diff changeset
   135
    iPowerState = aState;
hgs
parents:
diff changeset
   136
#endif  //__WINS__
hgs
parents:
diff changeset
   137
hgs
parents:
diff changeset
   138
   if( !err && aState == EBTOn )
hgs
parents:
diff changeset
   139
        {
hgs
parents:
diff changeset
   140
        TInt dutMode = EBTDutOff;
hgs
parents:
diff changeset
   141
        err = RProperty::Get( KPSUidBluetoothTestingMode, KBTDutEnabled, dutMode );
hgs
parents:
diff changeset
   142
        if( !err && dutMode == EBTDutOn )
hgs
parents:
diff changeset
   143
            {
hgs
parents:
diff changeset
   144
            // Set the DUT mode key to OFF since DUT mode is disabled at this point
hgs
parents:
diff changeset
   145
            err = RProperty::Set( KPSUidBluetoothTestingMode, KBTDutEnabled, EBTDutOff );
hgs
parents:
diff changeset
   146
            }
hgs
parents:
diff changeset
   147
        }
hgs
parents:
diff changeset
   148
    if( err )
hgs
parents:
diff changeset
   149
        {
hgs
parents:
diff changeset
   150
        // Power off if an error occurred during power on sequence.
hgs
parents:
diff changeset
   151
#ifndef __WINS__
hgs
parents:
diff changeset
   152
            // This cannot happen in emulator environment.
hgs
parents:
diff changeset
   153
        iPowerMgr.Cancel();
hgs
parents:
diff changeset
   154
        iActive->Cancel();
hgs
parents:
diff changeset
   155
        iPowerMgr.SetPower( EBTOff, NULL, iActive->RequestStatus() );
hgs
parents:
diff changeset
   156
        User::WaitForRequest( iActive->RequestStatus() );
hgs
parents:
diff changeset
   157
        // Result will be communicated through the caller of this function (by leaving).
hgs
parents:
diff changeset
   158
#else   //__WINS__
hgs
parents:
diff changeset
   159
        iPowerState = EBTOff;
hgs
parents:
diff changeset
   160
#endif  //__WINS__
hgs
parents:
diff changeset
   161
        } 
hgs
parents:
diff changeset
   162
    TRACE_FUNC_RES( ( _L( "result: %d" ), err ) )
hgs
parents:
diff changeset
   163
    return err;
hgs
parents:
diff changeset
   164
    }
hgs
parents:
diff changeset
   165
hgs
parents:
diff changeset
   166
hgs
parents:
diff changeset
   167
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   168
// Turn BT on or off.
hgs
parents:
diff changeset
   169
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   170
//
hgs
parents:
diff changeset
   171
void CBTEngSrvSettingsMgr::SetPowerStateL( TBTPowerState aState, TBool aTemporary )
hgs
parents:
diff changeset
   172
    {
hgs
parents:
diff changeset
   173
    TRACE_FUNC_ARG( ( _L( "%d (temporary=%d" ), aState, aTemporary ) )
hgs
parents:
diff changeset
   174
    if ( aState == EBTOn && iEnterpriseEnablementMode == BluetoothFeatures::EDisabled )
hgs
parents:
diff changeset
   175
        {
hgs
parents:
diff changeset
   176
        TRACE_INFO( ( _L( "no we're not... Bluetooth is enterprise-IT-disabled" ) ) )
hgs
parents:
diff changeset
   177
        User::Leave(KErrNotSupported);
hgs
parents:
diff changeset
   178
        }
hgs
parents:
diff changeset
   179
    TBool idle = ( iServer->StateMachine()->CurrentOperation() == CBTEngSrvState::ESrvOpIdle );
hgs
parents:
diff changeset
   180
    TBTPowerState currentState = EBTOff;
hgs
parents:
diff changeset
   181
    CheckTemporaryPowerStateL( currentState, aState, aTemporary );
hgs
parents:
diff changeset
   182
hgs
parents:
diff changeset
   183
    if ( ( currentState == aState || ( aTemporary && aState == EBTOff ) ) && idle )
hgs
parents:
diff changeset
   184
        {
hgs
parents:
diff changeset
   185
        // The requested power state is already active, ignore silently.
hgs
parents:
diff changeset
   186
        // We don't return an error here, as there is no error situation.
hgs
parents:
diff changeset
   187
        TRACE_INFO( ( _L( "SetPowerStateL: nothing to do" ) ) )
hgs
parents:
diff changeset
   188
        if ( currentState == aState )
hgs
parents:
diff changeset
   189
            {
hgs
parents:
diff changeset
   190
            // Make sure that the CenRep key is in sync.
hgs
parents:
diff changeset
   191
            // During boot-up, the pwoer is set from the CenRep key, so we could 
hgs
parents:
diff changeset
   192
            // end up out-of-sync.
hgs
parents:
diff changeset
   193
            TRACE_INFO( ( _L( "SetPowerStateL: currentState == aState" ) ) )
hgs
parents:
diff changeset
   194
            UpdateCenRepPowerKeyL( aState );
hgs
parents:
diff changeset
   195
            } 
hgs
parents:
diff changeset
   196
        return;
hgs
parents:
diff changeset
   197
        }
hgs
parents:
diff changeset
   198
    if ( aState == EBTOn )
hgs
parents:
diff changeset
   199
        {
hgs
parents:
diff changeset
   200
        // Hardware power on is the first step.
hgs
parents:
diff changeset
   201
        User::LeaveIfError( SetHwPowerState( aState ) );
hgs
parents:
diff changeset
   202
        }
hgs
parents:
diff changeset
   203
    else
hgs
parents:
diff changeset
   204
        {
hgs
parents:
diff changeset
   205
        //Prevent BT visibility in the situation when we turn OFF BT Engine 
hgs
parents:
diff changeset
   206
        //but FM Radio is still alive
hgs
parents:
diff changeset
   207
        SetVisibilityModeL( EBTVisibilityModeNoScans, 0 );
hgs
parents:
diff changeset
   208
        // Hardware power off is the last step.
hgs
parents:
diff changeset
   209
        // First disconnect all plug-ins.
hgs
parents:
diff changeset
   210
        iServer->PluginManager()->DisconnectAllPlugins();
hgs
parents:
diff changeset
   211
        }
hgs
parents:
diff changeset
   212
    // We only signal that BT is on after everything has completed (through 
hgs
parents:
diff changeset
   213
    // the CenRep power state key), so that all services are initialized.
hgs
parents:
diff changeset
   214
    // We signal that BT is off immediately though, so that our clients will 
hgs
parents:
diff changeset
   215
    // not try to use BT during power down.
hgs
parents:
diff changeset
   216
    iServer->StateMachine()->StartStateMachineL( aState );
hgs
parents:
diff changeset
   217
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   218
    }
hgs
parents:
diff changeset
   219
hgs
parents:
diff changeset
   220
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   221
// Turn BT on or off.
hgs
parents:
diff changeset
   222
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   223
//
hgs
parents:
diff changeset
   224
void CBTEngSrvSettingsMgr::SetPowerStateL(const RMessage2 aMessage )
hgs
parents:
diff changeset
   225
    {
hgs
parents:
diff changeset
   226
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   227
    __ASSERT_ALWAYS( aMessage.Function() == EBTEngSetPowerState, 
hgs
parents:
diff changeset
   228
            PanicServer( EBTEngPanicExpectSetPowerOpcode ) );
hgs
parents:
diff changeset
   229
    if ( !iMessage.IsNull() )
hgs
parents:
diff changeset
   230
        {
hgs
parents:
diff changeset
   231
        // A power management request from a client is outstanding.
hgs
parents:
diff changeset
   232
        User::Leave( KErrAlreadyExists );
hgs
parents:
diff changeset
   233
        }
hgs
parents:
diff changeset
   234
 
hgs
parents:
diff changeset
   235
    TBTPowerStateValue arg = (TBTPowerStateValue) aMessage.Int0();
hgs
parents:
diff changeset
   236
    // TBTPowerState power state type is inverted from TBTPowerStateValue,
hgs
parents:
diff changeset
   237
    // which is used by the client to pass the parameter...
hgs
parents:
diff changeset
   238
    TBTPowerState reqedPowerState( EBTOff );
hgs
parents:
diff changeset
   239
    if ( arg == EBTPowerOn )
hgs
parents:
diff changeset
   240
        {
hgs
parents:
diff changeset
   241
        reqedPowerState = EBTOn;
hgs
parents:
diff changeset
   242
        }
hgs
parents:
diff changeset
   243
    TBool tempPowerOn = (TBool) aMessage.Int1();
hgs
parents:
diff changeset
   244
    
hgs
parents:
diff changeset
   245
    SetPowerStateL( reqedPowerState, tempPowerOn );
hgs
parents:
diff changeset
   246
    if ( iServer->StateMachine()->CurrentOperation() == CBTEngSrvState::ESrvOpIdle )
hgs
parents:
diff changeset
   247
        {
hgs
parents:
diff changeset
   248
        // The request is accepted but the state machine is not running. This means the
hgs
parents:
diff changeset
   249
        // requested power state is already active. Request is done.
hgs
parents:
diff changeset
   250
        aMessage.Complete( KErrNone );
hgs
parents:
diff changeset
   251
        }
hgs
parents:
diff changeset
   252
    else
hgs
parents:
diff changeset
   253
        {
hgs
parents:
diff changeset
   254
        iMessage = RMessage2( aMessage );
hgs
parents:
diff changeset
   255
        }
hgs
parents:
diff changeset
   256
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   257
    }
hgs
parents:
diff changeset
   258
hgs
parents:
diff changeset
   259
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   260
// Initialize Bluetooth stack settings.
hgs
parents:
diff changeset
   261
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   262
//
hgs
parents:
diff changeset
   263
void CBTEngSrvSettingsMgr::InitBTStackL()
hgs
parents:
diff changeset
   264
    {
hgs
parents:
diff changeset
   265
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   266
    iServer->BasebandConnectionManager()->Subscribe();
hgs
parents:
diff changeset
   267
    TBTVisibilityMode visibility = EBTVisibilityModeHidden;
hgs
parents:
diff changeset
   268
    CRepository* cenRep = CRepository::NewL( KCRUidBTEngPrivateSettings );
hgs
parents:
diff changeset
   269
    TInt err = cenRep->Get( KBTDiscoverable, (TInt&) visibility );
hgs
parents:
diff changeset
   270
    delete cenRep;
hgs
parents:
diff changeset
   271
    if (iRestoreVisibility == EFalse)
hgs
parents:
diff changeset
   272
        {
hgs
parents:
diff changeset
   273
        if( err || visibility == EBTVisibilityModeTemporary &&
hgs
parents:
diff changeset
   274
            !( iServer->IsTimerQueued( CBTEngServer::EScanModeTimer ) ) )
hgs
parents:
diff changeset
   275
            {
hgs
parents:
diff changeset
   276
            visibility = EBTVisibilityModeHidden;
hgs
parents:
diff changeset
   277
            }
hgs
parents:
diff changeset
   278
        SetVisibilityModeL( visibility, 0 );
hgs
parents:
diff changeset
   279
        }
hgs
parents:
diff changeset
   280
hgs
parents:
diff changeset
   281
    TBool sspDebugMode = EFalse;
hgs
parents:
diff changeset
   282
    (void) RProperty::Get( KPropertyUidBluetoothCategory,
hgs
parents:
diff changeset
   283
                KPropertyKeyBluetoothGetSimplePairingDebugMode, (TInt&) sspDebugMode );
hgs
parents:
diff changeset
   284
        // Only set debug mode to off if it is on, to prevent a loop notifications.
hgs
parents:
diff changeset
   285
    if( sspDebugMode )
hgs
parents:
diff changeset
   286
        {
hgs
parents:
diff changeset
   287
        sspDebugMode = EFalse;
hgs
parents:
diff changeset
   288
        // Add LeaveIfError if unsuccessful
hgs
parents:
diff changeset
   289
        (void) RProperty::Set(KPropertyUidBluetoothCategory,
hgs
parents:
diff changeset
   290
                    KPropertyKeyBluetoothSetSimplePairingDebugMode, (TInt) sspDebugMode );
hgs
parents:
diff changeset
   291
        }
hgs
parents:
diff changeset
   292
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   293
    }
hgs
parents:
diff changeset
   294
hgs
parents:
diff changeset
   295
hgs
parents:
diff changeset
   296
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   297
// Reset settings and disconnect all links.
hgs
parents:
diff changeset
   298
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   299
//
hgs
parents:
diff changeset
   300
void CBTEngSrvSettingsMgr::StopBTStackL()
hgs
parents:
diff changeset
   301
    {
hgs
parents:
diff changeset
   302
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   303
    TBTVisibilityMode visibility = EBTVisibilityModeHidden;
hgs
parents:
diff changeset
   304
    CRepository* cenRep = CRepository::NewL( KCRUidBTEngPrivateSettings );
hgs
parents:
diff changeset
   305
          // Ignore error here; if we can't read it, likely we can't set it either.
hgs
parents:
diff changeset
   306
    (void) cenRep->Get( KBTDiscoverable, (TInt&) visibility );
hgs
parents:
diff changeset
   307
    delete cenRep;
hgs
parents:
diff changeset
   308
    if( visibility == EBTVisibilityModeTemporary )
hgs
parents:
diff changeset
   309
        {
hgs
parents:
diff changeset
   310
        visibility = EBTVisibilityModeHidden;
hgs
parents:
diff changeset
   311
        SetVisibilityModeL( visibility, 0 );    // Also cancels scan mode timer.
hgs
parents:
diff changeset
   312
        }
hgs
parents:
diff changeset
   313
hgs
parents:
diff changeset
   314
        // Stop listening to events
hgs
parents:
diff changeset
   315
    iServer->BasebandConnectionManager()->Unsubscribe();
hgs
parents:
diff changeset
   316
        // Disconnect all links
hgs
parents:
diff changeset
   317
    TCallBack cb( CBTEngServer::DisconnectAllCallBack, iServer );
hgs
parents:
diff changeset
   318
    iServer->BasebandConnectionManager()->DisconnectAllLinksL( cb );
hgs
parents:
diff changeset
   319
        // Results in a callback (which is called directly when there are no links).
hgs
parents:
diff changeset
   320
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   321
    }
hgs
parents:
diff changeset
   322
hgs
parents:
diff changeset
   323
hgs
parents:
diff changeset
   324
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   325
// Update the power state CenRep key.
hgs
parents:
diff changeset
   326
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   327
//
hgs
parents:
diff changeset
   328
void CBTEngSrvSettingsMgr::UpdateCenRepPowerKeyL( TBTPowerState aState )
hgs
parents:
diff changeset
   329
    {
hgs
parents:
diff changeset
   330
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   331
    CRepository* cenrep = CRepository::NewLC( KCRUidBluetoothPowerState );
hgs
parents:
diff changeset
   332
    // TBTPowerState power state type is inverted from TBTPowerStateValue...
hgs
parents:
diff changeset
   333
    TBTPowerStateValue power = (TBTPowerStateValue) !aState;
hgs
parents:
diff changeset
   334
    User::LeaveIfError( cenrep->Set( KBTPowerState, (TInt) power ) );
hgs
parents:
diff changeset
   335
    CleanupStack::PopAndDestroy( cenrep );
hgs
parents:
diff changeset
   336
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   337
    }
hgs
parents:
diff changeset
   338
hgs
parents:
diff changeset
   339
hgs
parents:
diff changeset
   340
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   341
// ?implementation_description
hgs
parents:
diff changeset
   342
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   343
//
hgs
parents:
diff changeset
   344
void CBTEngSrvSettingsMgr::SetVisibilityModeL( TBTVisibilityMode aMode, TInt aTime )
hgs
parents:
diff changeset
   345
    {
hgs
parents:
diff changeset
   346
    TRACE_FUNC_ARG( ( _L( "[aMode: %d" ), aMode ) )
hgs
parents:
diff changeset
   347
    if ( aMode != EBTVisibilityModeNoScans && iEnterpriseEnablementMode == BluetoothFeatures::EDisabled )
hgs
parents:
diff changeset
   348
        {
hgs
parents:
diff changeset
   349
        TRACE_INFO( ( _L( "\tnot changing anything... Bluetooth is enterprise-IT-disabled" ) ) )
hgs
parents:
diff changeset
   350
        User::Leave( KErrNotSupported );
hgs
parents:
diff changeset
   351
        }
hgs
parents:
diff changeset
   352
hgs
parents:
diff changeset
   353
    TInt err = KErrNone;
hgs
parents:
diff changeset
   354
    iServer->RemoveTimer( CBTEngServer::EScanModeTimer );
hgs
parents:
diff changeset
   355
    if( aMode != EBTVisibilityModeNoScans )
hgs
parents:
diff changeset
   356
        {
hgs
parents:
diff changeset
   357
        CRepository* cenRep = CRepository::NewL( KCRUidBTEngPrivateSettings );
hgs
parents:
diff changeset
   358
        err = cenRep->Set( KBTDiscoverable, aMode );
hgs
parents:
diff changeset
   359
        delete cenRep;
hgs
parents:
diff changeset
   360
        }
hgs
parents:
diff changeset
   361
    if( !err && aMode == EBTVisibilityModeTemporary )
hgs
parents:
diff changeset
   362
        {
hgs
parents:
diff changeset
   363
            // We need TInt64 here, as the max. time in microseconds for the 
hgs
parents:
diff changeset
   364
            // max. value (1 hour) is larger than KMaxTInt32.
hgs
parents:
diff changeset
   365
        TInt64 timeMicroSec = MAKE_TINT64( 0, aTime );
hgs
parents:
diff changeset
   366
        timeMicroSec = timeMicroSec * KMinutesInMicroSecs;
hgs
parents:
diff changeset
   367
            // Queue callback to set the visibility back to hidden.
hgs
parents:
diff changeset
   368
        iServer->QueueTimer( CBTEngServer::EScanModeTimer, (TInt64) timeMicroSec );
hgs
parents:
diff changeset
   369
        aMode = EBTVisibilityModeGeneral;
hgs
parents:
diff changeset
   370
        }
hgs
parents:
diff changeset
   371
    else if( !err && iRestoreVisibility )
hgs
parents:
diff changeset
   372
        {
hgs
parents:
diff changeset
   373
            // The user overrides, do not restore visibility mode anymore.
hgs
parents:
diff changeset
   374
        iRestoreVisibility = EFalse;
hgs
parents:
diff changeset
   375
        }
hgs
parents:
diff changeset
   376
    if( !err )
hgs
parents:
diff changeset
   377
        {
hgs
parents:
diff changeset
   378
        err = RProperty::Set( KUidSystemCategory, 
hgs
parents:
diff changeset
   379
                               KPropertyKeyBluetoothSetScanningStatus, aMode );
hgs
parents:
diff changeset
   380
        }
hgs
parents:
diff changeset
   381
    TBool hiddenMode = ( aMode == EBTVisibilityModeHidden );
hgs
parents:
diff changeset
   382
    if( !err && aMode != EBTVisibilityModeNoScans )
hgs
parents:
diff changeset
   383
        {
hgs
parents:
diff changeset
   384
            // In hidden mode, we only accept connections from paired devices.
hgs
parents:
diff changeset
   385
        err = RProperty::Set( KUidSystemCategory, 
hgs
parents:
diff changeset
   386
                               KPropertyKeyBluetoothSetAcceptPairedOnlyMode, 
hgs
parents:
diff changeset
   387
                               hiddenMode );
hgs
parents:
diff changeset
   388
        }
hgs
parents:
diff changeset
   389
hgs
parents:
diff changeset
   390
    User::LeaveIfError( err );  // To communicate the result to the client.
hgs
parents:
diff changeset
   391
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   392
    }
hgs
parents:
diff changeset
   393
hgs
parents:
diff changeset
   394
hgs
parents:
diff changeset
   395
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   396
// Timed visible mode has expired.
hgs
parents:
diff changeset
   397
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   398
//
hgs
parents:
diff changeset
   399
void CBTEngSrvSettingsMgr::ScanModeTimerCompletedL()
hgs
parents:
diff changeset
   400
    {
hgs
parents:
diff changeset
   401
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   402
    SetVisibilityModeL( EBTVisibilityModeHidden, 0 );
hgs
parents:
diff changeset
   403
    TBTPowerState power = EBTOff;
hgs
parents:
diff changeset
   404
    TInt err = GetHwPowerState( power );
hgs
parents:
diff changeset
   405
    if( !err && power )
hgs
parents:
diff changeset
   406
        {
hgs
parents:
diff changeset
   407
        // Show a notification to the user
hgs
parents:
diff changeset
   408
        TBTGenericInfoNotiferParamsPckg pckg;
hgs
parents:
diff changeset
   409
        pckg().iMessageType = EBTVisibilityTimeout;
hgs
parents:
diff changeset
   410
        
hgs
parents:
diff changeset
   411
        RNotifier notifier;
hgs
parents:
diff changeset
   412
        TInt err = notifier.Connect();
hgs
parents:
diff changeset
   413
        if( !err )
hgs
parents:
diff changeset
   414
            {
hgs
parents:
diff changeset
   415
            err = notifier.StartNotifier( KBTGenericInfoNotifierUid, pckg );
hgs
parents:
diff changeset
   416
            notifier.Close();
hgs
parents:
diff changeset
   417
            }
hgs
parents:
diff changeset
   418
        }
hgs
parents:
diff changeset
   419
    TRACE_FUNC_RES( ( _L( "result: %d" ), err ) )
hgs
parents:
diff changeset
   420
    }
hgs
parents:
diff changeset
   421
hgs
parents:
diff changeset
   422
hgs
parents:
diff changeset
   423
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   424
// Check the secure simple pairing debug mode and turn it off if needed.
hgs
parents:
diff changeset
   425
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   426
//
hgs
parents:
diff changeset
   427
void CBTEngSrvSettingsMgr::CheckSspDebugModeL( TBool aDebugMode )
hgs
parents:
diff changeset
   428
    {
hgs
parents:
diff changeset
   429
    TRACE_FUNC_ARG( ( _L( "SSP debug mode state %d" ), (TInt) aDebugMode ) )
hgs
parents:
diff changeset
   430
    TBTPowerState pwr = EBTOff;
hgs
parents:
diff changeset
   431
    TBool currentMode = EFalse;
hgs
parents:
diff changeset
   432
    TInt err = RProperty::Get( KPropertyUidBluetoothCategory, 
hgs
parents:
diff changeset
   433
                                KPropertyKeyBluetoothGetSimplePairingDebugMode, 
hgs
parents:
diff changeset
   434
                                (TInt&) currentMode );
hgs
parents:
diff changeset
   435
#ifndef __WINS__
hgs
parents:
diff changeset
   436
    err = iPowerMgr.GetPower( pwr, NULL ); // Treat error as power off.
hgs
parents:
diff changeset
   437
#else   //__WINS__
hgs
parents:
diff changeset
   438
    pwr = iPowerState;
hgs
parents:
diff changeset
   439
#endif  //__WINS__
hgs
parents:
diff changeset
   440
    if( err || pwr == EBTOff )
hgs
parents:
diff changeset
   441
        {
hgs
parents:
diff changeset
   442
        iServer->RemoveTimer( CBTEngServer::ESspDebugModeTimer );
hgs
parents:
diff changeset
   443
            // Only set debug mode to off if it is on, to prevent a loop notifications.
hgs
parents:
diff changeset
   444
        if( currentMode )
hgs
parents:
diff changeset
   445
            {
hgs
parents:
diff changeset
   446
            (void) RProperty::Set( KPropertyUidBluetoothCategory, 
hgs
parents:
diff changeset
   447
                                    KPropertyKeyBluetoothSetSimplePairingDebugMode,
hgs
parents:
diff changeset
   448
                                    (TInt) aDebugMode );
hgs
parents:
diff changeset
   449
            }
hgs
parents:
diff changeset
   450
            // In case of an error in getting the power state, turn BT off. 
hgs
parents:
diff changeset
   451
            // If BT is already off, this call will be ignored.
hgs
parents:
diff changeset
   452
        SetPowerStateL( EBTOff, EFalse );
hgs
parents:
diff changeset
   453
        }
hgs
parents:
diff changeset
   454
    else if( aDebugMode )
hgs
parents:
diff changeset
   455
        {
hgs
parents:
diff changeset
   456
            // Ignore if there already is a timer queued.
hgs
parents:
diff changeset
   457
        if( !( iServer->IsTimerQueued( CBTEngServer::ESspDebugModeTimer ) ) )
hgs
parents:
diff changeset
   458
            {
hgs
parents:
diff changeset
   459
            iServer->QueueTimer( CBTEngServer::ESspDebugModeTimer, (TInt64) KBTEngSspDebugModeTimeout );
hgs
parents:
diff changeset
   460
            err =  RProperty::Set(KPropertyUidBluetoothCategory, 
hgs
parents:
diff changeset
   461
                                   KPropertyKeyBluetoothSetSimplePairingDebugMode, 
hgs
parents:
diff changeset
   462
                                   (TInt) aDebugMode );
hgs
parents:
diff changeset
   463
            }
hgs
parents:
diff changeset
   464
        }
hgs
parents:
diff changeset
   465
    else
hgs
parents:
diff changeset
   466
        {
hgs
parents:
diff changeset
   467
            // Power is on, and debug mode is set to off.
hgs
parents:
diff changeset
   468
        TInt linkCount = 0;
hgs
parents:
diff changeset
   469
        err = RProperty::Get( KPropertyUidBluetoothCategory, 
hgs
parents:
diff changeset
   470
                               KPropertyKeyBluetoothGetPHYCount, linkCount );
hgs
parents:
diff changeset
   471
        if( err || !linkCount )
hgs
parents:
diff changeset
   472
            {
hgs
parents:
diff changeset
   473
            (void) RProperty::Set(KPropertyUidBluetoothCategory, 
hgs
parents:
diff changeset
   474
                                   KPropertyKeyBluetoothSetSimplePairingDebugMode,
hgs
parents:
diff changeset
   475
                                   (TInt) aDebugMode );
hgs
parents:
diff changeset
   476
            SetPowerStateL( EBTOff, EFalse );
hgs
parents:
diff changeset
   477
            }
hgs
parents:
diff changeset
   478
        else
hgs
parents:
diff changeset
   479
            {
hgs
parents:
diff changeset
   480
            // There are still existing connections, queue the
hgs
parents:
diff changeset
   481
            // timer again for half the period.
hgs
parents:
diff changeset
   482
            TInt64 interval = KBTEngSspDebugModeTimeout / 2;
hgs
parents:
diff changeset
   483
            iServer->QueueTimer( CBTEngServer::ESspDebugModeTimer, interval );
hgs
parents:
diff changeset
   484
            }
hgs
parents:
diff changeset
   485
        }
hgs
parents:
diff changeset
   486
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   487
    }
hgs
parents:
diff changeset
   488
hgs
parents:
diff changeset
   489
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   490
// A session will be ended, completes the pending request for this session.
hgs
parents:
diff changeset
   491
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   492
//
hgs
parents:
diff changeset
   493
void CBTEngSrvSettingsMgr::SessionClosed( CSession2* aSession )
hgs
parents:
diff changeset
   494
    {
hgs
parents:
diff changeset
   495
    TRACE_FUNC_ARG( ( _L( " session %x"), aSession ) )
hgs
parents:
diff changeset
   496
    if ( !iMessage.IsNull() && iMessage.Session() == aSession )
hgs
parents:
diff changeset
   497
        {
hgs
parents:
diff changeset
   498
        iMessage.Complete( KErrCancel );
hgs
parents:
diff changeset
   499
        }
hgs
parents:
diff changeset
   500
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   501
    }
hgs
parents:
diff changeset
   502
hgs
parents:
diff changeset
   503
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   504
// Check the power state and if BT gets turned off automatically.
hgs
parents:
diff changeset
   505
// This method is invoked either when the timer has expired, or
hgs
parents:
diff changeset
   506
// if there are no more connections while the timer was running.
hgs
parents:
diff changeset
   507
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   508
//
hgs
parents:
diff changeset
   509
void CBTEngSrvSettingsMgr::CheckAutoPowerOffL()
hgs
parents:
diff changeset
   510
    {
hgs
parents:
diff changeset
   511
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   512
    if ( iAutoOffClients > 0 )
hgs
parents:
diff changeset
   513
        {
hgs
parents:
diff changeset
   514
        TRACE_INFO( ( _L( "[CBTEngServer]\t iAutoOffClients %d"), iAutoOffClients ) )
hgs
parents:
diff changeset
   515
        return;
hgs
parents:
diff changeset
   516
        }
hgs
parents:
diff changeset
   517
    TInt linkCount = 0;
hgs
parents:
diff changeset
   518
    TInt err = RProperty::Get( KPropertyUidBluetoothCategory, 
hgs
parents:
diff changeset
   519
                                KPropertyKeyBluetoothGetPHYCount, linkCount );
hgs
parents:
diff changeset
   520
    if( !err && !linkCount )
hgs
parents:
diff changeset
   521
        {
hgs
parents:
diff changeset
   522
        TRACE_INFO( ( _L( "[CBTEngServer]\t SetPowerStateL( EBTOff, EFalse );")))
hgs
parents:
diff changeset
   523
        SetPowerStateL( EBTOff, EFalse );
hgs
parents:
diff changeset
   524
        }
hgs
parents:
diff changeset
   525
    else
hgs
parents:
diff changeset
   526
        {
hgs
parents:
diff changeset
   527
        if( iRestoreVisibility )
hgs
parents:
diff changeset
   528
            {
hgs
parents:
diff changeset
   529
                // Set visibility mode back to the value selected by the user.
hgs
parents:
diff changeset
   530
            SetVisibilityModeL( EBTVisibilityModeGeneral, 0 );
hgs
parents:
diff changeset
   531
            iRestoreVisibility = EFalse;
hgs
parents:
diff changeset
   532
            }
hgs
parents:
diff changeset
   533
            // show note if non-audio connection exists
hgs
parents:
diff changeset
   534
        if ( !iServer->PluginManager()->CheckAudioConnectionsL() )
hgs
parents:
diff changeset
   535
            {
hgs
parents:
diff changeset
   536
            RNotifier notifier;
hgs
parents:
diff changeset
   537
            TInt err = notifier.Connect();
hgs
parents:
diff changeset
   538
            if( !err )
hgs
parents:
diff changeset
   539
                {
hgs
parents:
diff changeset
   540
                TRequestStatus status;
hgs
parents:
diff changeset
   541
                TBTGenericInfoNotiferParamsPckg pckg;
hgs
parents:
diff changeset
   542
                pckg().iMessageType = EBTStayPowerOn;
hgs
parents:
diff changeset
   543
                TBuf8<sizeof(TInt)> result;
hgs
parents:
diff changeset
   544
                //notifier.StartNotifier( KBTGenericInfoNotifierUid, pckg, result );
hgs
parents:
diff changeset
   545
                notifier.StartNotifierAndGetResponse( status, 
hgs
parents:
diff changeset
   546
                                                  KBTGenericInfoNotifierUid, 
hgs
parents:
diff changeset
   547
                                                  pckg, result );   // Reply buffer not used.
hgs
parents:
diff changeset
   548
                User::WaitForRequest( status );
hgs
parents:
diff changeset
   549
                notifier.Close();
hgs
parents:
diff changeset
   550
                }
hgs
parents:
diff changeset
   551
            }
hgs
parents:
diff changeset
   552
        iAutoOffClients = 0;
hgs
parents:
diff changeset
   553
        iAutoSwitchOff = EFalse;
hgs
parents:
diff changeset
   554
        TCallBack cb;
hgs
parents:
diff changeset
   555
        iServer->BasebandConnectionManager()->SetAutoSwitchOff( EFalse, cb );
hgs
parents:
diff changeset
   556
        }
hgs
parents:
diff changeset
   557
    TRACE_FUNC_EXIT 
hgs
parents:
diff changeset
   558
    }
hgs
parents:
diff changeset
   559
hgs
parents:
diff changeset
   560
hgs
parents:
diff changeset
   561
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   562
// The method is called when BT stack scanning mode P&S key is changed
hgs
parents:
diff changeset
   563
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   564
//
hgs
parents:
diff changeset
   565
void CBTEngSrvSettingsMgr::UpdateVisibilityModeL( TInt aStackScanMode )
hgs
parents:
diff changeset
   566
    {
hgs
parents:
diff changeset
   567
    TRACE_FUNC_ARG( ( _L( "[aStackScanMode: %d" ), aStackScanMode ) )
hgs
parents:
diff changeset
   568
    TBTVisibilityMode currentMode;
hgs
parents:
diff changeset
   569
hgs
parents:
diff changeset
   570
    CRepository* cenRep = CRepository::NewLC( KCRUidBTEngPrivateSettings );
hgs
parents:
diff changeset
   571
    User::LeaveIfError( cenRep->Get( KBTDiscoverable, (TInt&) currentMode ) );
hgs
parents:
diff changeset
   572
hgs
parents:
diff changeset
   573
        // In case we are in temp visibility mode, we cannot always know whether the BT stack
hgs
parents:
diff changeset
   574
        // scan mode key was set by some external party or by us in SetVisibilityModeL above.
hgs
parents:
diff changeset
   575
        // Therefore we cannot stop the timer in case aMode is EBTVisibilityModeGeneral and 
hgs
parents:
diff changeset
   576
        // currentmode is EBTVisibilityModeTemporary
hgs
parents:
diff changeset
   577
    if( !( currentMode == EBTVisibilityModeTemporary && aStackScanMode == EBTVisibilityModeGeneral ) )
hgs
parents:
diff changeset
   578
        {
hgs
parents:
diff changeset
   579
            // Cancel the timer and queue it again if needed.
hgs
parents:
diff changeset
   580
        iServer->RemoveTimer( CBTEngServer::EScanModeTimer );
hgs
parents:
diff changeset
   581
        if( currentMode != aStackScanMode )
hgs
parents:
diff changeset
   582
            {
hgs
parents:
diff changeset
   583
            if( aStackScanMode == EPageScanOnly || aStackScanMode == EInquiryAndPageScan )
hgs
parents:
diff changeset
   584
                {
hgs
parents:
diff changeset
   585
                User::LeaveIfError( cenRep->Set( KBTDiscoverable, aStackScanMode ) );
hgs
parents:
diff changeset
   586
                }
hgs
parents:
diff changeset
   587
            else if( aStackScanMode == EInquiryScanOnly )
hgs
parents:
diff changeset
   588
                {
hgs
parents:
diff changeset
   589
                    // We don't support ENoScansEnabled nor EInquiryScanOnly mode
hgs
parents:
diff changeset
   590
                    // -> Consider these as same as Hidden 
hgs
parents:
diff changeset
   591
                User::LeaveIfError( cenRep->Set( KBTDiscoverable, EBTVisibilityModeHidden ) );
hgs
parents:
diff changeset
   592
                }
hgs
parents:
diff changeset
   593
            else if( aStackScanMode == ENoScansEnabled )
hgs
parents:
diff changeset
   594
                {
hgs
parents:
diff changeset
   595
                //We don't change KBTDiscoverable here, because ENoScansEnabled
hgs
parents:
diff changeset
   596
                //indicates BT/SYSTEM shutdown is happening
hgs
parents:
diff changeset
   597
                }
hgs
parents:
diff changeset
   598
            }
hgs
parents:
diff changeset
   599
        }
hgs
parents:
diff changeset
   600
    SetUiIndicatorsL();
hgs
parents:
diff changeset
   601
    CleanupStack::PopAndDestroy( cenRep );
hgs
parents:
diff changeset
   602
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   603
    }
hgs
parents:
diff changeset
   604
hgs
parents:
diff changeset
   605
hgs
parents:
diff changeset
   606
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   607
// Set Device Under Test mode.
hgs
parents:
diff changeset
   608
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   609
//
hgs
parents:
diff changeset
   610
void CBTEngSrvSettingsMgr::SetDutMode( TInt aDutMode )
hgs
parents:
diff changeset
   611
    {
hgs
parents:
diff changeset
   612
    TRACE_FUNC_ARG( ( _L( "DUT mode %d" ), aDutMode ) )
hgs
parents:
diff changeset
   613
hgs
parents:
diff changeset
   614
    if (aDutMode == EBTDutOff)
hgs
parents:
diff changeset
   615
        {
hgs
parents:
diff changeset
   616
        return;
hgs
parents:
diff changeset
   617
        }
hgs
parents:
diff changeset
   618
hgs
parents:
diff changeset
   619
    TInt powerState = EBTOff;
hgs
parents:
diff changeset
   620
    CRepository* cenrep = NULL;
hgs
parents:
diff changeset
   621
    
hgs
parents:
diff changeset
   622
    TRAPD(err, cenrep = CRepository::NewL(KCRUidBluetoothPowerState));
hgs
parents:
diff changeset
   623
    
hgs
parents:
diff changeset
   624
    if (!err && cenrep)
hgs
parents:
diff changeset
   625
        {
hgs
parents:
diff changeset
   626
        cenrep->Get(KBTPowerState, powerState);
hgs
parents:
diff changeset
   627
        delete cenrep;
hgs
parents:
diff changeset
   628
        cenrep = NULL;
hgs
parents:
diff changeset
   629
        }
hgs
parents:
diff changeset
   630
    else
hgs
parents:
diff changeset
   631
        {
hgs
parents:
diff changeset
   632
        return;
hgs
parents:
diff changeset
   633
        }
hgs
parents:
diff changeset
   634
24
hgs
parents: 23
diff changeset
   635
    if (powerState == EBTPowerOn)
23
hgs
parents:
diff changeset
   636
        {
hgs
parents:
diff changeset
   637
hgs
parents:
diff changeset
   638
#ifndef __WINS__
hgs
parents:
diff changeset
   639
        RBluetoothDutMode dutMode;
hgs
parents:
diff changeset
   640
        TInt err = dutMode.Open();
hgs
parents:
diff changeset
   641
        TRACE_FUNC_ARG( ( _L( "Open DUT mode handle err %d" ), err) )
hgs
parents:
diff changeset
   642
        if(!err) 
hgs
parents:
diff changeset
   643
            {
hgs
parents:
diff changeset
   644
            dutMode.ActivateDutMode();
hgs
parents:
diff changeset
   645
            dutMode.Close();
hgs
parents:
diff changeset
   646
            }
hgs
parents:
diff changeset
   647
#endif  //__WINS__                        
hgs
parents:
diff changeset
   648
        }
hgs
parents:
diff changeset
   649
    }
hgs
parents:
diff changeset
   650
hgs
parents:
diff changeset
   651
hgs
parents:
diff changeset
   652
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   653
// From class MBTEngActiveObserver.
hgs
parents:
diff changeset
   654
// Callback to notify that an outstanding request has completed.
hgs
parents:
diff changeset
   655
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   656
//
hgs
parents:
diff changeset
   657
void CBTEngSrvSettingsMgr::RequestCompletedL( CBTEngActive* aActive, TInt aId, TInt aStatus )
hgs
parents:
diff changeset
   658
    {
hgs
parents:
diff changeset
   659
    __ASSERT_ALWAYS( aId == KBTEngSettingsActive, PanicServer( EBTEngPanicCorrupt ) );
hgs
parents:
diff changeset
   660
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   661
    (void) aActive;
hgs
parents:
diff changeset
   662
    if ( aStatus != KErrNone && aStatus != KErrAlreadyExists && aStatus != KErrCancel )
hgs
parents:
diff changeset
   663
        {
hgs
parents:
diff changeset
   664
        // Something went wrong, so we turn BT off again.
hgs
parents:
diff changeset
   665
        SetPowerStateL( EBTOff, EFalse );
hgs
parents:
diff changeset
   666
        }
hgs
parents:
diff changeset
   667
    else
hgs
parents:
diff changeset
   668
        {
hgs
parents:
diff changeset
   669
        // Write CoD only when the hardware has fully powered up.
hgs
parents:
diff changeset
   670
        TBTPowerState currState ( EBTOff );
hgs
parents:
diff changeset
   671
        (void) GetHwPowerState( currState );
hgs
parents:
diff changeset
   672
        if ( currState == EBTOn )
hgs
parents:
diff changeset
   673
            {
hgs
parents:
diff changeset
   674
            SetClassOfDeviceL();
hgs
parents:
diff changeset
   675
#ifndef SETLOCALNAME 
hgs
parents:
diff changeset
   676
            // the macro SETLOCALNAME is used as a workaround to tackle the BT name 
hgs
parents:
diff changeset
   677
            // could not be saved to BT chip before chip initialization completed for the first time,
hgs
parents:
diff changeset
   678
            // which is one of the regression after improving the BT boot up time. 
hgs
parents:
diff changeset
   679
            // To be removed once the final solution is in place. 
hgs
parents:
diff changeset
   680
            CBTEngSettings* settings = CBTEngSettings::NewL();
hgs
parents:
diff changeset
   681
            TBTDeviceName localName;           
hgs
parents:
diff changeset
   682
            localName.Zero();
hgs
parents:
diff changeset
   683
            TInt err = settings->GetLocalName(localName);
hgs
parents:
diff changeset
   684
            if (err == KErrNone)
hgs
parents:
diff changeset
   685
                {
hgs
parents:
diff changeset
   686
                settings->SetLocalName(localName);
hgs
parents:
diff changeset
   687
                }
hgs
parents:
diff changeset
   688
            delete settings;
hgs
parents:
diff changeset
   689
#endif
hgs
parents:
diff changeset
   690
            }
hgs
parents:
diff changeset
   691
        }
hgs
parents:
diff changeset
   692
    if ( !iMessage.IsNull())
hgs
parents:
diff changeset
   693
        {
hgs
parents:
diff changeset
   694
        iMessage.Complete( aStatus );
hgs
parents:
diff changeset
   695
        }
hgs
parents:
diff changeset
   696
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   697
    }
hgs
parents:
diff changeset
   698
hgs
parents:
diff changeset
   699
hgs
parents:
diff changeset
   700
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   701
// From class MBTEngActiveObserver.
hgs
parents:
diff changeset
   702
// Callback to notify that an error has occurred in RunL.
hgs
parents:
diff changeset
   703
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   704
//
hgs
parents:
diff changeset
   705
void CBTEngSrvSettingsMgr::HandleError( CBTEngActive* aActive, TInt aId, TInt aError )
hgs
parents:
diff changeset
   706
    {
hgs
parents:
diff changeset
   707
    (void) aActive;
hgs
parents:
diff changeset
   708
    (void) aId;
hgs
parents:
diff changeset
   709
    if ( !iMessage.IsNull())
hgs
parents:
diff changeset
   710
        {
hgs
parents:
diff changeset
   711
        iMessage.Complete( aError );
hgs
parents:
diff changeset
   712
        }
hgs
parents:
diff changeset
   713
    }
hgs
parents:
diff changeset
   714
hgs
parents:
diff changeset
   715
hgs
parents:
diff changeset
   716
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   717
// Loads the BT Power Manager; leaves if it cannot be loaded.
hgs
parents:
diff changeset
   718
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   719
//
hgs
parents:
diff changeset
   720
void CBTEngSrvSettingsMgr::LoadBTPowerManagerL()
hgs
parents:
diff changeset
   721
    {
hgs
parents:
diff changeset
   722
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   723
    TRACE_INFO( ( _L( "[CBTEngSrvSettingsMgr]\t Using HCI API v2 power manager" ) ) )
hgs
parents:
diff changeset
   724
    User::LeaveIfError( iPowerMgr.Open() );
hgs
parents:
diff changeset
   725
#ifndef __WINS__
hgs
parents:
diff changeset
   726
    iPowerMgr.SetPower( EBTOff, NULL, iActive->RequestStatus() );
hgs
parents:
diff changeset
   727
    User::WaitForRequest( iActive->RequestStatus() );
hgs
parents:
diff changeset
   728
    TInt status = ( iActive->RequestStatus().Int() == KErrAlreadyExists ? KErrNone : iActive->RequestStatus().Int() ); 
hgs
parents:
diff changeset
   729
    User::LeaveIfError( status );
hgs
parents:
diff changeset
   730
#else   //__WINS__
hgs
parents:
diff changeset
   731
    iPowerState = EBTOff;
hgs
parents:
diff changeset
   732
#endif  //__WINS__
hgs
parents:
diff changeset
   733
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   734
    }
hgs
parents:
diff changeset
   735
hgs
parents:
diff changeset
   736
hgs
parents:
diff changeset
   737
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   738
// ?implementation_description
hgs
parents:
diff changeset
   739
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   740
//
hgs
parents:
diff changeset
   741
void CBTEngSrvSettingsMgr::SetUiIndicatorsL()
hgs
parents:
diff changeset
   742
    {
hgs
parents:
diff changeset
   743
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   744
    TBTPowerStateValue powerState = EBTPowerOff;
hgs
parents:
diff changeset
   745
    TBTVisibilityMode visibilityMode = EBTVisibilityModeHidden;
hgs
parents:
diff changeset
   746
    CRepository* cenrep = NULL;
hgs
parents:
diff changeset
   747
    TInt phys = 0;
hgs
parents:
diff changeset
   748
    TInt connecting = 0;
hgs
parents:
diff changeset
   749
hgs
parents:
diff changeset
   750
    cenrep = CRepository::NewLC( KCRUidBluetoothPowerState );
hgs
parents:
diff changeset
   751
    User::LeaveIfError( cenrep->Get( KBTPowerState, (TInt&) powerState ) );
hgs
parents:
diff changeset
   752
    CleanupStack::PopAndDestroy( cenrep );
hgs
parents:
diff changeset
   753
    
hgs
parents:
diff changeset
   754
    if( powerState == EBTPowerOff )
hgs
parents:
diff changeset
   755
        {
hgs
parents:
diff changeset
   756
        SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   757
        SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   758
        SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   759
        SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   760
        }
hgs
parents:
diff changeset
   761
    else
hgs
parents:
diff changeset
   762
        {
hgs
parents:
diff changeset
   763
        // Power is on.
hgs
parents:
diff changeset
   764
        RProperty::Get( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothPHYCount, phys );
hgs
parents:
diff changeset
   765
        RProperty::Get( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothConnecting, connecting );
hgs
parents:
diff changeset
   766
        
hgs
parents:
diff changeset
   767
        cenrep = CRepository::NewLC( KCRUidBTEngPrivateSettings );
hgs
parents:
diff changeset
   768
        User::LeaveIfError( cenrep->Get( KBTDiscoverable, (TInt&) visibilityMode ) );
hgs
parents:
diff changeset
   769
        CleanupStack::PopAndDestroy( cenrep );
hgs
parents:
diff changeset
   770
        
hgs
parents:
diff changeset
   771
        if( visibilityMode == EBTVisibilityModeHidden )
hgs
parents:
diff changeset
   772
            {
hgs
parents:
diff changeset
   773
             if ( connecting ) // BT connecting and hidden
hgs
parents:
diff changeset
   774
                {
hgs
parents:
diff changeset
   775
                SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   776
                SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateAnimate );
hgs
parents:
diff changeset
   777
                }
hgs
parents:
diff changeset
   778
            else if ( phys > 0 ) // BT connection active and hidden     
hgs
parents:
diff changeset
   779
                {
hgs
parents:
diff changeset
   780
                SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   781
                SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOn );
hgs
parents:
diff changeset
   782
                }
hgs
parents:
diff changeset
   783
            else  // BT connection not active and hidden
hgs
parents:
diff changeset
   784
                {
hgs
parents:
diff changeset
   785
                SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOn );
hgs
parents:
diff changeset
   786
                SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   787
                }
hgs
parents:
diff changeset
   788
            SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   789
            SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   790
            }           
hgs
parents:
diff changeset
   791
        else if( visibilityMode == EBTVisibilityModeGeneral || visibilityMode == EBTVisibilityModeTemporary )
hgs
parents:
diff changeset
   792
            {     
hgs
parents:
diff changeset
   793
            if ( connecting ) // BT connecting and visible
hgs
parents:
diff changeset
   794
                {
hgs
parents:
diff changeset
   795
                SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   796
                SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateAnimate );
hgs
parents:
diff changeset
   797
                }
hgs
parents:
diff changeset
   798
            else if ( phys > 0 ) // BT connection active and visible 
hgs
parents:
diff changeset
   799
                {
hgs
parents:
diff changeset
   800
                SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   801
                SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOn );
hgs
parents:
diff changeset
   802
                }
hgs
parents:
diff changeset
   803
            else  // BT connection not active and visible
hgs
parents:
diff changeset
   804
                {
hgs
parents:
diff changeset
   805
                SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOn );
hgs
parents:
diff changeset
   806
                SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   807
                }
hgs
parents:
diff changeset
   808
            SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   809
            SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
hgs
parents:
diff changeset
   810
            }
hgs
parents:
diff changeset
   811
        }
hgs
parents:
diff changeset
   812
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   813
    }
hgs
parents:
diff changeset
   814
hgs
parents:
diff changeset
   815
hgs
parents:
diff changeset
   816
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   817
// ?implementation_description
hgs
parents:
diff changeset
   818
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   819
//
hgs
parents:
diff changeset
   820
void CBTEngSrvSettingsMgr::SetIndicatorStateL( const TInt aIndicator, const TInt aState )
hgs
parents:
diff changeset
   821
    {
hgs
parents:
diff changeset
   822
    CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC( TUid::Uid( aIndicator ) );
hgs
parents:
diff changeset
   823
    indicator->SetIndicatorStateL( aState );
hgs
parents:
diff changeset
   824
    CleanupStack::PopAndDestroy( indicator ); //indicator
hgs
parents:
diff changeset
   825
    }
hgs
parents:
diff changeset
   826
hgs
parents:
diff changeset
   827
hgs
parents:
diff changeset
   828
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   829
// Gets the current HW power state.
hgs
parents:
diff changeset
   830
// For now this is a separate method to isolate the different variations.
hgs
parents:
diff changeset
   831
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   832
//
hgs
parents:
diff changeset
   833
TInt CBTEngSrvSettingsMgr::GetHwPowerState( TBTPowerState& aState )
hgs
parents:
diff changeset
   834
    {
hgs
parents:
diff changeset
   835
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   836
    TInt err = KErrNone;
hgs
parents:
diff changeset
   837
    
hgs
parents:
diff changeset
   838
#ifndef __WINS__
hgs
parents:
diff changeset
   839
    err = iPowerMgr.GetPower( aState, NULL );
hgs
parents:
diff changeset
   840
#else   //__WINS__
hgs
parents:
diff changeset
   841
    aState = iPowerState;
hgs
parents:
diff changeset
   842
#endif  //__WINS__
hgs
parents:
diff changeset
   843
    TRACE_FUNC_ARG( ( _L( "Power state is %d, result %d" ), (TInt) aState, err ) )
hgs
parents:
diff changeset
   844
    return err;
hgs
parents:
diff changeset
   845
    }
hgs
parents:
diff changeset
   846
hgs
parents:
diff changeset
   847
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   848
// Check the power state and if BT gets turned off automatically.
hgs
parents:
diff changeset
   849
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   850
//
hgs
parents:
diff changeset
   851
void CBTEngSrvSettingsMgr::CheckTemporaryPowerStateL( TBTPowerState& aCurrentState, 
hgs
parents:
diff changeset
   852
    TBTPowerState aNewState, TBool aTemporary )
hgs
parents:
diff changeset
   853
    {
hgs
parents:
diff changeset
   854
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   855
    User::LeaveIfError( GetHwPowerState( aCurrentState ) );
hgs
parents:
diff changeset
   856
    if( !aTemporary )
hgs
parents:
diff changeset
   857
        {
hgs
parents:
diff changeset
   858
            // Force the new power state, so clear all auto switch off flags.
hgs
parents:
diff changeset
   859
            // If power is off, this will anyway be ignored.
hgs
parents:
diff changeset
   860
        iAutoOffClients = 0;
hgs
parents:
diff changeset
   861
        iAutoSwitchOff = EFalse;
hgs
parents:
diff changeset
   862
        TCallBack cb;
hgs
parents:
diff changeset
   863
        iServer->BasebandConnectionManager()->SetAutoSwitchOff( EFalse, cb );
hgs
parents:
diff changeset
   864
        if( iRestoreVisibility && aCurrentState == EBTOn )
hgs
parents:
diff changeset
   865
            {
hgs
parents:
diff changeset
   866
                // Set visibility mode back to the value selected by the user.
hgs
parents:
diff changeset
   867
            SetVisibilityModeL( EBTVisibilityModeGeneral, 0 );
hgs
parents:
diff changeset
   868
            iRestoreVisibility = EFalse;
hgs
parents:
diff changeset
   869
            }
hgs
parents:
diff changeset
   870
        }
hgs
parents:
diff changeset
   871
    else
hgs
parents:
diff changeset
   872
        {
hgs
parents:
diff changeset
   873
        if( aCurrentState == aNewState )
hgs
parents:
diff changeset
   874
            {
hgs
parents:
diff changeset
   875
            if( iAutoSwitchOff && aNewState == EBTOn )
hgs
parents:
diff changeset
   876
                {
hgs
parents:
diff changeset
   877
                iAutoOffClients++;
hgs
parents:
diff changeset
   878
                iServer->RemoveTimer( CBTEngServer::EAutoPowerOffTimer );
hgs
parents:
diff changeset
   879
                }
hgs
parents:
diff changeset
   880
            }
hgs
parents:
diff changeset
   881
        else if( iAutoSwitchOff || aNewState == EBTOn )
hgs
parents:
diff changeset
   882
            {
hgs
parents:
diff changeset
   883
            aNewState == EBTOff ? iAutoOffClients-- : iAutoOffClients++;
hgs
parents:
diff changeset
   884
            iAutoSwitchOff = ETrue;
hgs
parents:
diff changeset
   885
            if( aNewState == EBTOff && iAutoOffClients <= 0 )
hgs
parents:
diff changeset
   886
                {
hgs
parents:
diff changeset
   887
                TCallBack powerOffCb( CBTEngServer::AutoPowerOffCallBack, iServer );
hgs
parents:
diff changeset
   888
                iServer->BasebandConnectionManager()->SetAutoSwitchOff( ETrue, powerOffCb );
hgs
parents:
diff changeset
   889
                TInt64 interval = KBTEngBtAutoOffTimeout;
hgs
parents:
diff changeset
   890
                iServer->QueueTimer( CBTEngServer::EAutoPowerOffTimer, interval );
hgs
parents:
diff changeset
   891
                }
hgs
parents:
diff changeset
   892
            else if( aNewState == EBTOn )
hgs
parents:
diff changeset
   893
                {
hgs
parents:
diff changeset
   894
                CRepository* cenRep = CRepository::NewLC( KCRUidBTEngPrivateSettings );
hgs
parents:
diff changeset
   895
                TBTVisibilityMode visibility = EBTVisibilityModeGeneral;
hgs
parents:
diff changeset
   896
                TInt err = cenRep->Get( KBTDiscoverable, (TInt&) visibility );
hgs
parents:
diff changeset
   897
                CleanupStack::PopAndDestroy( cenRep );
hgs
parents:
diff changeset
   898
                if( !err && visibility == EBTVisibilityModeGeneral )
hgs
parents:
diff changeset
   899
                    {
hgs
parents:
diff changeset
   900
                    SetVisibilityModeL( EBTVisibilityModeHidden, 0 );
hgs
parents:
diff changeset
   901
                    iRestoreVisibility = ETrue;
hgs
parents:
diff changeset
   902
                   }
hgs
parents:
diff changeset
   903
                iServer->RemoveTimer( CBTEngServer::EAutoPowerOffTimer );
hgs
parents:
diff changeset
   904
                }
hgs
parents:
diff changeset
   905
            }
hgs
parents:
diff changeset
   906
        }
hgs
parents:
diff changeset
   907
    if( iAutoOffClients < 0 )
hgs
parents:
diff changeset
   908
        {
hgs
parents:
diff changeset
   909
        iAutoOffClients = 0;
hgs
parents:
diff changeset
   910
        }
hgs
parents:
diff changeset
   911
    TRACE_FUNC_EXIT 
hgs
parents:
diff changeset
   912
    }
hgs
parents:
diff changeset
   913
hgs
parents:
diff changeset
   914
hgs
parents:
diff changeset
   915
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   916
// Set the Class of Device.
hgs
parents:
diff changeset
   917
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   918
//
hgs
parents:
diff changeset
   919
void CBTEngSrvSettingsMgr::SetClassOfDeviceL()
hgs
parents:
diff changeset
   920
    {
hgs
parents:
diff changeset
   921
    TRACE_FUNC_ENTRY
hgs
parents:
diff changeset
   922
    TUint16 serviceClass = KCoDDefaultServiceClass;
hgs
parents:
diff changeset
   923
        // Check from feature manager if stereo audio is enabled.
hgs
parents:
diff changeset
   924
    FeatureManager::InitializeLibL();
hgs
parents:
diff changeset
   925
    TBool supported = FeatureManager::FeatureSupported( KFeatureIdBtStereoAudio );
hgs
parents:
diff changeset
   926
    FeatureManager::UnInitializeLib();
hgs
parents:
diff changeset
   927
    if( supported )
hgs
parents:
diff changeset
   928
        {
hgs
parents:
diff changeset
   929
        // A2DP spec says we should set this bit as we are a SRC
hgs
parents:
diff changeset
   930
        serviceClass |= EMajorServiceCapturing;
hgs
parents:
diff changeset
   931
        }
hgs
parents:
diff changeset
   932
        // These values may nayway be overridden by HCI
hgs
parents:
diff changeset
   933
    TBTDeviceClass cod( serviceClass, KCoDDefaultMajorDeviceClass, 
hgs
parents:
diff changeset
   934
                         KCoDDefaultMinorDeviceClass );
hgs
parents:
diff changeset
   935
        // Ignore error, it is non-critical
hgs
parents:
diff changeset
   936
    (void) RProperty::Set( KPropertyUidBluetoothControlCategory, 
hgs
parents:
diff changeset
   937
                            KPropertyKeyBluetoothSetDeviceClass, cod.DeviceClass() );
hgs
parents:
diff changeset
   938
    TRACE_FUNC_EXIT
hgs
parents:
diff changeset
   939
    }