radioengine/utils/src/cradiosystemeventdetector.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 14 63aabac4416d
parent 28 075425b8d9a4
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    28 
    28 
    29 #include <ctsydomainpskeys.h>
    29 #include <ctsydomainpskeys.h>
    30 #include <publicruntimeids.hrh>
    30 #include <publicruntimeids.hrh>
    31 #include <sacls.h>
    31 #include <sacls.h>
    32 
    32 
    33 #ifdef COMPILE_IN_IVALO
       
    34 #   include <voiceuidomainpskeys.h>
       
    35 #endif //COMPILE_IN_IVALO
       
    36 #include <featmgr.h>
       
    37 
       
    38 // User includes
    33 // User includes
    39 #include "cradioenginelogger.h"
    34 #include "cradioenginelogger.h"
    40 #include "cradiosystemeventdetector.h"
    35 #include "cradiosystemeventdetector.h"
    41 #include "mradiosystemeventdetectorobserver.h"
    36 #include "mradiosystemeventdetectorobserver.h"
    42 
    37 
    59 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
    60 //
    55 //
    61 CRadioSystemEventDetector::CRadioSystemEventDetector( MRadioSystemEventDetectorObserver&  aObserver )
    56 CRadioSystemEventDetector::CRadioSystemEventDetector( MRadioSystemEventDetectorObserver&  aObserver )
    62     : iObserver( aObserver )
    57     : iObserver( aObserver )
    63     , iIsMobileNetworkCoverage( EFalse )
    58     , iIsMobileNetworkCoverage( EFalse )
    64     , iIsWlanCoverage( EFalse )
       
    65     , iIsCallActive( EFalse )
    59     , iIsCallActive( EFalse )
    66     , iIsAudioResourcesAvailable( ETrue )
    60     , iIsAudioResourcesAvailable( ETrue )
    67     , iIsVoiceUiActive( EFalse )
    61     {
    68     {
    62     LEVEL3( LOG_METHOD_AUTO );
    69     }
    63     }
    70 
    64 
    71 // ---------------------------------------------------------------------------
    65 // ---------------------------------------------------------------------------
    72 //
    66 //
    73 // ---------------------------------------------------------------------------
    67 // ---------------------------------------------------------------------------
    74 //
    68 //
    75 void CRadioSystemEventDetector::ConstructL()
    69 void CRadioSystemEventDetector::ConstructL()
    76     {
    70     {
    77 //    FeatureManager::InitializeLibL();
    71     LOG_METHOD_AUTO;
    78 //    TBool wlanSupported = FeatureManager::FeatureSupported( KFeatureIdProtocolWlan );
       
    79 //    FeatureManager::UnInitializeLib();
       
    80     TBool wlanSupported = EFalse; //TODO: Check if we have any need for this
       
    81 
       
    82     iNetworkStatusObserver = CRadioPropertyObserver::NewL( *this,
    72     iNetworkStatusObserver = CRadioPropertyObserver::NewL( *this,
    83                                                            KUidSystemCategory,
    73                                                            KUidSystemCategory,
    84                                                            KUidNetworkStatusValue,
    74                                                            KUidNetworkStatusValue,
    85                                                            CRadioPropertyObserver::ERadioPropertyInt );
    75                                                            CRadioPropertyObserver::ERadioPropertyInt );
    86     iNetworkStatusObserver->ActivateL();
    76     iNetworkStatusObserver->ActivateL();
    87 
    77 
    88     iIsMobileNetworkCoverage = iNetworkStatusObserver->ValueInt() == ESANetworkAvailable;
    78     iIsMobileNetworkCoverage = iNetworkStatusObserver->ValueInt() == ESANetworkAvailable;
    89 
       
    90     // On S60 platform, there is no guaranteed way of seeing whether WLAN is explicitly turned off
       
    91     // in the settings, or whether the network is available. For now, we only check the existence of
       
    92     // the WLAN support in the feature manager. We might also want to check whether WLAN access points
       
    93     // have been configured.
       
    94     iIsWlanCoverage = wlanSupported;
       
    95 
    79 
    96     // Initialize call state observer.
    80     // Initialize call state observer.
    97     iCallStatusObserver = CRadioPropertyObserver::NewL( *this,
    81     iCallStatusObserver = CRadioPropertyObserver::NewL( *this,
    98                                                         KPSUidCtsyCallInformation,
    82                                                         KPSUidCtsyCallInformation,
    99                                                         KCTsyCallState,
    83                                                         KCTsyCallState,
   100                                                         CRadioPropertyObserver::ERadioPropertyInt );
    84                                                         CRadioPropertyObserver::ERadioPropertyInt );
   101     iCallStatusObserver->ActivateL();
    85     iCallStatusObserver->ActivateL();
   102     iIsCallActive = iCallStatusObserver->ValueInt() != EPSCTsyCallStateNone;
    86     iIsCallActive = iCallStatusObserver->ValueInt() != EPSCTsyCallStateNone;
   103 
       
   104 #ifdef COMPILE_IN_IVALO
       
   105     // Initialize voice ui observer.
       
   106     iVoiceUiObserver = CRadioPropertyObserver::NewL( *this,
       
   107                                                      KPSUidVoiceUiAccMonitor,
       
   108                                                      KVoiceUiOpenKey,
       
   109                                                      CRadioPropertyObserver::ERadioPropertyInt );
       
   110     iVoiceUiObserver->ActivateL();
       
   111 #endif //COMPILE_IN_IVALO
       
   112 
    87 
   113 #ifndef __WINS__
    88 #ifndef __WINS__
   114     // Define audio types for not resuming.
    89     // Define audio types for not resuming.
   115     iNoAutoResumeAudioCategories = RArray<TInt>( KVRAudioCategoryArrayGranularity );
    90     iNoAutoResumeAudioCategories = RArray<TInt>( KVRAudioCategoryArrayGranularity );
   116     iNoAutoResumeAudioCategories.AppendL( ECatMediaPlayer );
    91     iNoAutoResumeAudioCategories.AppendL( ECatMediaPlayer );
   127 //
   102 //
   128 // ---------------------------------------------------------------------------
   103 // ---------------------------------------------------------------------------
   129 //
   104 //
   130 CRadioSystemEventDetector::~CRadioSystemEventDetector()
   105 CRadioSystemEventDetector::~CRadioSystemEventDetector()
   131     {
   106     {
   132     FeatureManager::UnInitializeLib();
   107     LEVEL3( LOG_METHOD_AUTO );
   133     delete iCallStatusObserver;
   108     delete iCallStatusObserver;
   134     delete iNetworkStatusObserver;
   109     delete iNetworkStatusObserver;
   135     delete iVoiceUiObserver;
       
   136     delete iAudioPolicyObserver;
   110     delete iAudioPolicyObserver;
   137 
   111 
   138     iNoAutoResumeAudioCategories.Close();
   112     iNoAutoResumeAudioCategories.Close();
   139     }
   113     }
   140 
   114 
   142 //
   116 //
   143 // ---------------------------------------------------------------------------
   117 // ---------------------------------------------------------------------------
   144 //
   118 //
   145 CRadioSystemEventDetector* CRadioSystemEventDetector::NewL( MRadioSystemEventDetectorObserver&  aObserver )
   119 CRadioSystemEventDetector* CRadioSystemEventDetector::NewL( MRadioSystemEventDetectorObserver&  aObserver )
   146     {
   120     {
       
   121     LEVEL3( LOG_METHOD_AUTO );
   147     CRadioSystemEventDetector* self = new ( ELeave ) CRadioSystemEventDetector( aObserver );
   122     CRadioSystemEventDetector* self = new ( ELeave ) CRadioSystemEventDetector( aObserver );
   148     CleanupStack::PushL( self );
   123     CleanupStack::PushL( self );
   149     self->ConstructL();
   124     self->ConstructL();
   150     CleanupStack::Pop( self );
   125     CleanupStack::Pop( self );
   151     return self;
   126     return self;
   159 //
   134 //
   160 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& aCategory,
   135 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& aCategory,
   161                                                        const TUint aKey,
   136                                                        const TUint aKey,
   162                                                        const TInt aValue )
   137                                                        const TInt aValue )
   163     {
   138     {
   164     //TODO: Refactor
   139     LEVEL2( LOG_METHOD_AUTO );
   165     if ( aCategory == KUidSystemCategory && aKey == KUidNetworkStatusValue )
   140     if ( aCategory == KPSUidCtsyCallInformation && aKey == KCTsyCallState )
   166         {
       
   167         switch ( aValue )
       
   168             {
       
   169             case ESANetworkAvailable:
       
   170                 {
       
   171                 SetNetworkCoverageL( ETrue, iIsWlanCoverage );
       
   172                 break;
       
   173                 }
       
   174             case ESANetworkUnAvailable:
       
   175                 {
       
   176                 SetNetworkCoverageL( EFalse, iIsWlanCoverage );
       
   177                 break;
       
   178                 }
       
   179             default:
       
   180                 {
       
   181                 break;
       
   182                 }
       
   183             }
       
   184         }
       
   185     else if ( aCategory == KPSUidCtsyCallInformation && aKey == KCTsyCallState )
       
   186         {
   141         {
   187         if ( (!iIsCallActive ) && ( aValue > EPSCTsyCallStateNone ))
   142         if ( (!iIsCallActive ) && ( aValue > EPSCTsyCallStateNone ))
   188             {
   143             {
   189             iIsCallActive = ETrue;
   144             iIsCallActive = ETrue;
   190             iObserver.CallActivatedCallbackL();
   145             iObserver.CallActivatedCallbackL();
   192         else if ( ( iIsCallActive ) && ( aValue <= EPSCTsyCallStateNone ))
   147         else if ( ( iIsCallActive ) && ( aValue <= EPSCTsyCallStateNone ))
   193             {
   148             {
   194             iIsCallActive = EFalse;
   149             iIsCallActive = EFalse;
   195             iObserver.CallDeactivatedCallbackL();
   150             iObserver.CallDeactivatedCallbackL();
   196             }
   151             }
   197         else
       
   198             {
       
   199             // No change
       
   200             }
       
   201         }
       
   202 #ifdef COMPILE_IN_IVALO
       
   203     else if ( aCategory == KPSUidVoiceUiAccMonitor && aKey == KVoiceUiOpenKey )
       
   204         {
       
   205         switch ( aValue )
       
   206             {
       
   207             case KVoiceUiIsClose:
       
   208                 {
       
   209                 if ( iIsVoiceUiActive )
       
   210                     {
       
   211                     iIsVoiceUiActive = EFalse;
       
   212                     LOG( "Voice UI not active." );
       
   213                     if ( iIsAudioResourcesAvailable )
       
   214                         {
       
   215                         LOG( "Audio resources available. Change informed." );
       
   216                         iObserver.AudioResourcesAvailableL();
       
   217                         }
       
   218                     }
       
   219                 break;
       
   220                 }
       
   221             case KVoiceUiIsOpen:
       
   222                 {
       
   223                 if ( !iIsVoiceUiActive )
       
   224                     {
       
   225                     iIsVoiceUiActive = ETrue;
       
   226                     LOG( "Voice UI active." );
       
   227                     }
       
   228                 break;
       
   229                 }
       
   230             default:
       
   231                 {
       
   232                 break;
       
   233                 }
       
   234             }
       
   235         }
       
   236 #endif //COMPILE_IN_IVALO
       
   237     else // NOP
       
   238         {
       
   239         }
   152         }
   240     }
   153     }
   241 
   154 
   242 #ifndef __WINS__
   155 #ifndef __WINS__
   243 // ---------------------------------------------------------------------------
   156 // ---------------------------------------------------------------------------
   249 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& aCategory,
   162 void CRadioSystemEventDetector::HandlePropertyChangeL( const TUid& aCategory,
   250                                                        const TUint aKey,
   163                                                        const TUint aKey,
   251                                                        const TDesC8& aValue )
   164                                                        const TDesC8& aValue )
   252     {
   165     {
   253 #if 0
   166 #if 0
   254     LOG_METHOD_AUTO;
   167     LEVEL2( LOG_METHOD_AUTO );
   255     LOG_FORMAT( "Category: %d, Key: %d", aCategory, aKey );
   168     LOG_FORMAT( "Category: %d, Key: %d", aCategory, aKey );
   256     if ( aCategory == KPSUidMMFAudioServer )
   169     if ( aCategory == KPSUidMMFAudioServer )
   257         {
   170         {
   258         if ( aKey == KAudioPolicyAudioClients )
   171         if ( aKey == KAudioPolicyAudioClients )
   259             {
   172             {
   347 // ---------------------------------------------------------------------------
   260 // ---------------------------------------------------------------------------
   348 // This is a callback function which is called when a P&S components returns
   261 // This is a callback function which is called when a P&S components returns
   349 // an error
   262 // an error
   350 // ---------------------------------------------------------------------------
   263 // ---------------------------------------------------------------------------
   351 //
   264 //
   352 void CRadioSystemEventDetector::HandlePropertyChangeErrorL( const TUid& aCategory,
   265 void CRadioSystemEventDetector::HandlePropertyChangeErrorL( const TUid& /*aCategory*/,
   353                                                             const TUint aKey,
   266                                                             const TUint /*aKey*/,
   354                                                             TInt aError )
   267                                                             TInt /*aError*/ )
   355     {
   268     {
   356 #ifdef COMPILE_IN_IVALO
       
   357     if ( aCategory == KPSUidVoiceUiAccMonitor && aKey == KVoiceUiOpenKey && aError == KErrNotFound )
       
   358         {
       
   359         HandlePropertyChangeL( KPSUidVoiceUiAccMonitor, KVoiceUiOpenKey, KVoiceUiIsClose );
       
   360         }
       
   361     else
       
   362         {
       
   363         iObserver.ErrorCallbackL( aError );
       
   364         }
       
   365 #else
       
   366     (void)aCategory;
       
   367     (void)aKey;
       
   368     (void)aError;
       
   369 #endif //COMPILE_IN_IVALO
       
   370     }
   269     }
   371 
   270 
   372 // ---------------------------------------------------------------------------
   271 // ---------------------------------------------------------------------------
   373 //
   272 //
   374 // ---------------------------------------------------------------------------
   273 // ---------------------------------------------------------------------------
   375 //
   274 //
   376 TBool CRadioSystemEventDetector::IsMobileNetworkCoverage() const
   275 TBool CRadioSystemEventDetector::IsMobileNetworkCoverage() const
   377     {
   276     {
       
   277     LEVEL3( LOG_METHOD_AUTO );
   378     return iIsMobileNetworkCoverage;
   278     return iIsMobileNetworkCoverage;
   379     }
   279     }
   380 
   280 
   381 // ---------------------------------------------------------------------------
   281 // ---------------------------------------------------------------------------
   382 //
   282 //
   383 // ---------------------------------------------------------------------------
   283 // ---------------------------------------------------------------------------
   384 //
   284 //
   385 TBool CRadioSystemEventDetector::IsNetworkCoverage() const
   285 TBool CRadioSystemEventDetector::IsNetworkCoverage() const
   386     {
   286     {
   387     return iIsWlanCoverage || iIsMobileNetworkCoverage;
   287     LEVEL3( LOG_METHOD_AUTO );
       
   288     return iIsMobileNetworkCoverage;
   388     }
   289     }
   389 
   290 
   390 // ---------------------------------------------------------------------------
   291 // ---------------------------------------------------------------------------
   391 //
   292 //
   392 // ---------------------------------------------------------------------------
   293 // ---------------------------------------------------------------------------
   393 //
   294 //
   394 TBool CRadioSystemEventDetector::IsCallActive() const
   295 TBool CRadioSystemEventDetector::IsCallActive() const
   395     {
   296     {
       
   297     LEVEL3( LOG_METHOD_AUTO );
   396     return iIsCallActive;
   298     return iIsCallActive;
   397     }
   299     }
   398 
   300 
   399 // ---------------------------------------------------------------------------
   301 // ---------------------------------------------------------------------------
   400 //
   302 //
   401 // ---------------------------------------------------------------------------
   303 // ---------------------------------------------------------------------------
   402 //
   304 //
   403 TBool CRadioSystemEventDetector::IsAudioResourcesAvailable() const
   305 TBool CRadioSystemEventDetector::IsAudioResourcesAvailable() const
   404     {
   306     {
       
   307     LEVEL3( LOG_METHOD_AUTO );
   405     return iIsAudioResourcesAvailable;
   308     return iIsAudioResourcesAvailable;
   406     }
   309     }
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 //
       
   410 // ---------------------------------------------------------------------------
       
   411 //
       
   412 TBool CRadioSystemEventDetector::IsVoiceUiActive() const
       
   413     {
       
   414     return iIsVoiceUiActive;
       
   415     }
       
   416 
       
   417 // ---------------------------------------------------------------------------
       
   418 //
       
   419 // ---------------------------------------------------------------------------
       
   420 //
       
   421 void CRadioSystemEventDetector::SetNetworkCoverageL( const TBool aIsMobileNetworkCoverage,
       
   422                                                      const TBool aIsWlanCoverage )
       
   423     {
       
   424     LOG_FORMAT( "CRadioSystemEventDetector::SetNetworkCoverageL ( mobile = %d wlan = %d )", aIsMobileNetworkCoverage, aIsWlanCoverage );
       
   425 
       
   426     TBool wasCoverage = IsNetworkCoverage();
       
   427     iIsMobileNetworkCoverage = aIsMobileNetworkCoverage;
       
   428     iIsWlanCoverage = aIsWlanCoverage;
       
   429     TBool isCoverage = IsNetworkCoverage();
       
   430 
       
   431     if ( isCoverage != wasCoverage )
       
   432         {
       
   433         if ( isCoverage )
       
   434             {
       
   435             iObserver.NetworkUpCallbackL();
       
   436             }
       
   437         else
       
   438             {
       
   439             iObserver.NetworkDownCallbackL();
       
   440             }
       
   441         }
       
   442     }