bluetoothengine/bteng/src/btengsrvsettingsmgr.cpp
branchRCL_3
changeset 55 613943a21004
parent 54 0ba996a9b75d
child 56 9386f31cc85b
equal deleted inserted replaced
54:0ba996a9b75d 55:613943a21004
    20 #include <bt_subscribe_partner.h>
    20 #include <bt_subscribe_partner.h>
    21 #include <btnotif.h>
    21 #include <btnotif.h>
    22 #include <btengdomainpskeys.h>
    22 #include <btengdomainpskeys.h>
    23 #include <centralrepository.h>
    23 #include <centralrepository.h>
    24 #include <featmgr.h>
    24 #include <featmgr.h>
    25 #include <AknSmallIndicator.h>
       
    26 #include <avkon.hrh>
       
    27 
       
    28 #include "btengserver.h"
    25 #include "btengserver.h"
    29 #include "btengsrvpluginmgr.h"
    26 #include "btengsrvpluginmgr.h"
    30 #include "btengsrvbbconnectionmgr.h"
    27 #include "btengsrvbbconnectionmgr.h"
    31 #include "btengsrvstate.h"
    28 #include "btengsrvstate.h"
    32 #include "debug.h"
    29 #include "debug.h"
       
    30 #include <btindicatorconstants.h>
       
    31 #include <hbindicatorsymbian.h>
       
    32 #include <hbsymbianvariant.h>
    33 
    33 
    34 /** ID of active object helper */
    34 /** ID of active object helper */
    35 const TInt KBTEngSettingsActive = 30;
    35 const TInt KBTEngSettingsActive = 30;
    36 /** Constant for converting minutes to microseconds */
    36 /** Constant for converting minutes to microseconds */
    37 //const TInt64 KMinutesInMicroSecs = 60000000;
    37 //const TInt64 KMinutesInMicroSecs = 60000000;
    47 // ---------------------------------------------------------------------------
    47 // ---------------------------------------------------------------------------
    48 // C++ default constructor
    48 // C++ default constructor
    49 // ---------------------------------------------------------------------------
    49 // ---------------------------------------------------------------------------
    50 //
    50 //
    51 CBTEngSrvSettingsMgr::CBTEngSrvSettingsMgr( CBTEngServer* aServer )
    51 CBTEngSrvSettingsMgr::CBTEngSrvSettingsMgr( CBTEngServer* aServer )
    52 :   iServer( aServer )
    52 :   iServer( aServer ),iIndicatorState(-1)
    53     {
    53     {
    54     }
    54     }
    55 
    55 
    56 
    56 
    57 // ---------------------------------------------------------------------------
    57 // ---------------------------------------------------------------------------
    60 //
    60 //
    61 void CBTEngSrvSettingsMgr::ConstructL()
    61 void CBTEngSrvSettingsMgr::ConstructL()
    62     {
    62     {
    63     TRACE_FUNC_ENTRY
    63     TRACE_FUNC_ENTRY
    64     iActive = CBTEngActive::NewL( *this, KBTEngSettingsActive );
    64     iActive = CBTEngActive::NewL( *this, KBTEngSettingsActive );
       
    65     iBTIndicator = CHbIndicatorSymbian::NewL(); 
    65     LoadBTPowerManagerL();
    66     LoadBTPowerManagerL();
    66     iEnterpriseEnablementMode = BluetoothFeatures::EnterpriseEnablementL();
    67     iEnterpriseEnablementMode = BluetoothFeatures::EnterpriseEnablementL();
    67     TRACE_INFO( ( _L( "iEnterpriseEnablementMode = %d" ), iEnterpriseEnablementMode) )
    68     TRACE_INFO( ( _L( "iEnterpriseEnablementMode = %d" ), iEnterpriseEnablementMode) )
    68     if ( iEnterpriseEnablementMode == BluetoothFeatures::EDisabled )
    69     if ( iEnterpriseEnablementMode == BluetoothFeatures::EDisabled )
    69         {
    70         {
    91 // Destructor
    92 // Destructor
    92 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
    93 //
    94 //
    94 CBTEngSrvSettingsMgr::~CBTEngSrvSettingsMgr()
    95 CBTEngSrvSettingsMgr::~CBTEngSrvSettingsMgr()
    95     {
    96     {
    96     if( iActive && iActive->IsActive() )
       
    97         {
       
    98         // Cancel the outstanding request.
       
    99         iPowerMgr.Cancel();
       
   100         }
       
   101     delete iActive;  
    97     delete iActive;  
       
    98     delete iBTIndicator;
   102     iPowerMgr.Close();
    99     iPowerMgr.Close();
   103     }
   100     }
   104 
   101 
   105 
   102 
   106 // ---------------------------------------------------------------------------
   103 // ---------------------------------------------------------------------------
   182         // We don't return an error here, as there is no error situation.
   179         // We don't return an error here, as there is no error situation.
   183         TRACE_INFO( ( _L( "SetPowerStateL: nothing to do" ) ) )
   180         TRACE_INFO( ( _L( "SetPowerStateL: nothing to do" ) ) )
   184         if ( currentState == aState )
   181         if ( currentState == aState )
   185             {
   182             {
   186             // Make sure that the CenRep key is in sync.
   183             // Make sure that the CenRep key is in sync.
   187             // During boot-up, the pwoer is set from the CenRep key, so we could 
   184             // During boot-up, the power is set from the CenRep key, so we could 
   188             // end up out-of-sync.
   185             // end up out-of-sync.
   189             TRACE_INFO( ( _L( "SetPowerStateL: currentState == aState" ) ) )
   186             TRACE_INFO( ( _L( "SetPowerStateL: currentState == aState" ) ) )
   190             UpdateCenRepPowerKeyL( aState );
   187             HandleHwPowerChangeL( aState );
   191             } 
   188             }
   192         return;
   189         return;
   193         }
   190         }
   194     if ( aState == EBTOn )
   191     if ( aState == EBTOn )
   195         {
   192         {
   196         // Hardware power on is the first step.
   193         // Hardware power on is the first step.
   316     TRACE_FUNC_EXIT
   313     TRACE_FUNC_EXIT
   317     }
   314     }
   318 
   315 
   319 
   316 
   320 // ---------------------------------------------------------------------------
   317 // ---------------------------------------------------------------------------
   321 // Update the power state CenRep key.
   318 // Update the power state CenRep key, and start BTNotif server if BT is on.
   322 // ---------------------------------------------------------------------------
   319 // ---------------------------------------------------------------------------
   323 //
   320 //
   324 void CBTEngSrvSettingsMgr::UpdateCenRepPowerKeyL( TBTPowerState aState )
   321 void CBTEngSrvSettingsMgr::HandleHwPowerChangeL( TBTPowerState aState )
   325     {
   322     {
   326     TRACE_FUNC_ENTRY
   323     TRACE_FUNC_ENTRY
   327     CRepository* cenrep = CRepository::NewLC( KCRUidBluetoothPowerState );
   324     CRepository* cenrep = CRepository::NewLC( KCRUidBluetoothPowerState );
   328     // TBTPowerState power state type is inverted from TBTPowerStateValue...
   325     // TBTPowerState power state type is inverted from TBTPowerStateValue...
   329     TBTPowerStateValue power = (TBTPowerStateValue) !aState;
   326     TBTPowerStateValue power = ( aState == EBTOn ) ? EBTPowerOn : EBTPowerOff;
   330     User::LeaveIfError( cenrep->Set( KBTPowerState, (TInt) power ) );
   327     User::LeaveIfError( cenrep->Set( KBTPowerState, (TInt) power ) );
   331     CleanupStack::PopAndDestroy( cenrep );
   328     CleanupStack::PopAndDestroy( cenrep );
   332     TRACE_FUNC_EXIT
   329     TRACE_FUNC_EXIT
   333     }
   330     }
   334 
       
   335 
   331 
   336 // ---------------------------------------------------------------------------
   332 // ---------------------------------------------------------------------------
   337 // ?implementation_description
   333 // ?implementation_description
   338 // ---------------------------------------------------------------------------
   334 // ---------------------------------------------------------------------------
   339 //
   335 //
   652 // ---------------------------------------------------------------------------
   648 // ---------------------------------------------------------------------------
   653 // From class MBTEngActiveObserver.
   649 // From class MBTEngActiveObserver.
   654 // Callback to notify that an outstanding request has completed.
   650 // Callback to notify that an outstanding request has completed.
   655 // ---------------------------------------------------------------------------
   651 // ---------------------------------------------------------------------------
   656 //
   652 //
   657 void CBTEngSrvSettingsMgr::RequestCompletedL( CBTEngActive* aActive, TInt aId, TInt aStatus )
   653 void CBTEngSrvSettingsMgr::RequestCompletedL( CBTEngActive* aActive, TInt aStatus )
   658     {
   654     {
   659     __ASSERT_ALWAYS( aId == KBTEngSettingsActive, PanicServer( EBTEngPanicCorrupt ) );
   655     __ASSERT_ALWAYS( aActive->RequestId() == KBTEngSettingsActive, PanicServer( EBTEngPanicCorrupt ) );
   660     TRACE_FUNC_ENTRY
   656     TRACE_FUNC_ENTRY
   661     (void) aActive;
   657     (void) aActive;
   662     if ( aStatus != KErrNone && aStatus != KErrAlreadyExists && aStatus != KErrCancel )
   658     if ( aStatus != KErrNone && aStatus != KErrAlreadyExists && aStatus != KErrCancel )
   663         {
   659         {
   664         // Something went wrong, so we turn BT off again.
   660         // Something went wrong, so we turn BT off again.
   665         SetPowerStateL( EBTOff, EFalse );
   661         SetPowerStateL( EBTOff, EFalse );
   666         }
   662         }
   667     
       
   668     if ( !iMessage.IsNull())
   663     if ( !iMessage.IsNull())
   669         {
   664         {
   670         iMessage.Complete( aStatus );
   665         iMessage.Complete( aStatus );
   671         }
   666         }
   672     TRACE_FUNC_EXIT
   667     TRACE_FUNC_EXIT
   673     }
   668     }
   674 
   669 
       
   670 // ---------------------------------------------------------------------------
       
   671 // From class MBTEngActiveObserver.
       
   672 // Handles cancelation of an outstanding request
       
   673 // ---------------------------------------------------------------------------
       
   674 //
       
   675 void CBTEngSrvSettingsMgr::CancelRequest( TInt aRequestId )
       
   676     {
       
   677     TRACE_FUNC_ARG( ( _L( "reqID %d" ), aRequestId ) );
       
   678     if ( aRequestId == KBTEngSettingsActive )
       
   679         {
       
   680         iPowerMgr.Cancel();
       
   681         }
       
   682     TRACE_FUNC_EXIT 
       
   683     }
   675 
   684 
   676 // ---------------------------------------------------------------------------
   685 // ---------------------------------------------------------------------------
   677 // From class MBTEngActiveObserver.
   686 // From class MBTEngActiveObserver.
   678 // Callback to notify that an error has occurred in RunL.
   687 // Callback to notify that an error has occurred in RunL.
   679 // ---------------------------------------------------------------------------
   688 // ---------------------------------------------------------------------------
   680 //
   689 //
   681 void CBTEngSrvSettingsMgr::HandleError( CBTEngActive* aActive, TInt aId, TInt aError )
   690 void CBTEngSrvSettingsMgr::HandleError( CBTEngActive* aActive, TInt aError )
   682     {
   691     {
   683     (void) aActive;
   692     (void) aActive;
   684     (void) aId;
       
   685     if ( !iMessage.IsNull())
   693     if ( !iMessage.IsNull())
   686         {
   694         {
   687         iMessage.Complete( aError );
   695         iMessage.Complete( aError );
   688         }
   696         }
   689     }
   697     }
   697     {
   705     {
   698     TRACE_FUNC_ENTRY
   706     TRACE_FUNC_ENTRY
   699     TRACE_INFO( ( _L( "[CBTEngSrvSettingsMgr]\t Using HCI API v2 power manager" ) ) )
   707     TRACE_INFO( ( _L( "[CBTEngSrvSettingsMgr]\t Using HCI API v2 power manager" ) ) )
   700     User::LeaveIfError( iPowerMgr.Open() );
   708     User::LeaveIfError( iPowerMgr.Open() );
   701 #ifndef __WINS__
   709 #ifndef __WINS__
   702 
       
   703     TRequestStatus reqStatus;
   710     TRequestStatus reqStatus;
   704     iPowerMgr.SetPower( EBTOff, NULL, reqStatus );
   711     iPowerMgr.SetPower( EBTOff, NULL, reqStatus );
   705     User::WaitForRequest( reqStatus );
   712     User::WaitForRequest( reqStatus );
   706     TInt status = ( reqStatus.Int() == KErrAlreadyExists ? KErrNone : reqStatus.Int() ); 
   713     TInt status = ( reqStatus.Int() == KErrAlreadyExists ? KErrNone : reqStatus.Int() ); 
   707     User::LeaveIfError( status );
   714     User::LeaveIfError( status );
   721     TRACE_FUNC_ENTRY
   728     TRACE_FUNC_ENTRY
   722     TBTPowerStateValue powerState = EBTPowerOff;
   729     TBTPowerStateValue powerState = EBTPowerOff;
   723     TBTVisibilityMode visibilityMode = EBTVisibilityModeHidden;
   730     TBTVisibilityMode visibilityMode = EBTVisibilityModeHidden;
   724     CRepository* cenrep = NULL;
   731     CRepository* cenrep = NULL;
   725     TInt phys = 0;
   732     TInt phys = 0;
   726     TInt connecting = 0;
   733  //   TInt connecting = 0;
   727 
   734 
   728     cenrep = CRepository::NewLC( KCRUidBluetoothPowerState );
   735     cenrep = CRepository::NewLC( KCRUidBluetoothPowerState );
   729     User::LeaveIfError( cenrep->Get( KBTPowerState, (TInt&) powerState ) );
   736     User::LeaveIfError( cenrep->Get( KBTPowerState, (TInt&) powerState ) );
   730     CleanupStack::PopAndDestroy( cenrep );
   737     CleanupStack::PopAndDestroy( cenrep );
   731     
   738     
   732     if( powerState == EBTPowerOff )
   739     if( powerState == EBTPowerOff )
   733         {
   740         {
   734         SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
   741         SetIndicatorStateL(EBTIndicatorOff);
   735         SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
       
   736         SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
       
   737         SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
       
   738         }
   742         }
   739     else
   743     else
   740         {
   744         {
   741         // Power is on.
   745         // Power is on.
   742         RProperty::Get( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothPHYCount, phys );
   746         RProperty::Get( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothPHYCount, phys );
   743         RProperty::Get( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothConnecting, connecting );
   747  //       RProperty::Get( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothConnecting, connecting );
   744         
   748         
   745         cenrep = CRepository::NewLC( KCRUidBTEngPrivateSettings );
   749         cenrep = CRepository::NewLC( KCRUidBTEngPrivateSettings );
   746         User::LeaveIfError( cenrep->Get( KBTDiscoverable, (TInt&) visibilityMode ) );
   750         User::LeaveIfError( cenrep->Get( KBTDiscoverable, (TInt&) visibilityMode ) );
   747         CleanupStack::PopAndDestroy( cenrep );
   751         CleanupStack::PopAndDestroy( cenrep );
   748         
   752         
   749         if( visibilityMode == EBTVisibilityModeHidden )
   753         if( visibilityMode == EBTVisibilityModeHidden )
   750             {
   754             {
   751              if ( connecting ) // BT connecting and hidden
   755             if ( phys > 0 ) // BT connection active and hidden     
   752                 {
   756                 {
   753                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
   757                 SetIndicatorStateL(EBTIndicatorHiddenConnected);
   754                 SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateAnimate );
       
   755                 }
       
   756             else if ( phys > 0 ) // BT connection active and hidden     
       
   757                 {
       
   758                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
       
   759                 SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOn );
       
   760                 }
   758                 }
   761             else  // BT connection not active and hidden
   759             else  // BT connection not active and hidden
   762                 {
   760                 {
   763                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOn );
   761                 SetIndicatorStateL(EBTIndicatorOnHidden);
   764                 SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
   762                 }
   765                 }
       
   766             SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
       
   767             SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
       
   768             }           
   763             }           
   769         else if( visibilityMode == EBTVisibilityModeGeneral || visibilityMode == EBTVisibilityModeTemporary )
   764         else if( visibilityMode == EBTVisibilityModeGeneral || visibilityMode == EBTVisibilityModeTemporary )
   770             {     
   765             {     
   771             if ( connecting ) // BT connecting and visible
   766             if ( phys > 0 ) // BT connection active and visible 
   772                 {
   767                 {
   773                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
   768                 SetIndicatorStateL(EBTIndicatorVisibleConnected);
   774                 SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateAnimate );
       
   775                 }
       
   776             else if ( phys > 0 ) // BT connection active and visible 
       
   777                 {
       
   778                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
       
   779                 SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOn );
       
   780                 }
   769                 }
   781             else  // BT connection not active and visible
   770             else  // BT connection not active and visible
   782                 {
   771                 {
   783                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOn );
   772                 SetIndicatorStateL(EBTIndicatorOnVisible);
   784                 SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
   773                 }
   785                 }
   774             }
   786             SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
   775         }
   787             SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
   776     TRACE_FUNC_EXIT
   788             }
   777     }
   789         }
   778 
   790     TRACE_FUNC_EXIT
   779 void CBTEngSrvSettingsMgr::SetIndicatorStateL( const TInt aState )
   791     }
   780     {
   792 
   781     TBool success = EFalse;
   793 
   782     if(iIndicatorState != aState)
   794 // ---------------------------------------------------------------------------
   783         {
   795 // ?implementation_description
   784         CHbSymbianVariant* parameters = CHbSymbianVariant::NewL(&aState,CHbSymbianVariant::EInt );
   796 // ---------------------------------------------------------------------------
   785         success = iBTIndicator->Activate(KIndicatorType(),parameters); 
   797 //
   786         delete parameters;
   798 void CBTEngSrvSettingsMgr::SetIndicatorStateL( const TInt aIndicator, const TInt aState )
   787         if(!success)
   799     {
   788             {
   800     CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC( TUid::Uid( aIndicator ) );
   789             User::Leave(iBTIndicator->Error());
   801     indicator->SetIndicatorStateL( aState );
   790             }
   802     CleanupStack::PopAndDestroy( indicator ); //indicator
   791         iIndicatorState = aState;
       
   792         }
   803     }
   793     }
   804 
   794 
   805 
   795 
   806 // ---------------------------------------------------------------------------
   796 // ---------------------------------------------------------------------------
   807 // Gets the current HW power state.
   797 // Gets the current HW power state.
   886         {
   876         {
   887         iAutoOffClients = 0;
   877         iAutoOffClients = 0;
   888         }
   878         }
   889     TRACE_FUNC_EXIT 
   879     TRACE_FUNC_EXIT 
   890     }
   880     }
       
   881