gssettingsuis/Gs/GSNetworkPlugin/Src/PSMNetworkPlugin.cpp
changeset 68 13e71d907dc3
equal deleted inserted replaced
40:6465d5bb863a 68:13e71d907dc3
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Stub imlementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <psmsettingsprovider.h>
       
    21 #include <psmsrvdomaincrkeys.h>
       
    22 #include <featmgr.h>
       
    23 #include <CoreApplicationUIsSDKCRKeys.h> // KCRUidCoreApplicationUIs, TCoreAppUIsNetworkConnectionAllowed
       
    24 #include "PSMNetworkPlugin.h"
       
    25 #include "GSNetworkPluginModel.h"
       
    26 #include "GsLogger.h"
       
    27 
       
    28 // CONSTANT DEFINITIONS
       
    29 const TUint32 KPSMNetworkPluginStorageId = 0x2000B593;
       
    30 // default value for network mode change key
       
    31 const TInt KPowersavingNetworkmodeNoChanged = 0; 
       
    32 
       
    33 enum TPSMNetworkPluginKeys
       
    34     {
       
    35     ENetworkMode = 1,
       
    36     };
       
    37 
       
    38 //
       
    39 // ----------------------------------------------------------------------------------
       
    40 // CPSMNetworkPlugin::CPSMNetworkPlugin()
       
    41 // ----------------------------------------------------------------------------------
       
    42 //
       
    43 CPSMNetworkPlugin::CPSMNetworkPlugin( TPsmPluginCTorParams& aInitParams ) :
       
    44     CPsmPluginBase( aInitParams )
       
    45 	{
       
    46 	}
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CPSMNetworkPlugin::ConstructL()
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CPSMNetworkPlugin::ConstructL()
       
    54     {
       
    55     __GSLOGSTRING( "[GS]-->[CPSMNetworkPlugin::ConstructL]" );
       
    56     
       
    57     iModel = CGSNetworkPluginModel::NewL( NULL,NULL );
       
    58     iPsmRepository = CRepository::NewL( KCRUidPowerSaveMode );
       
    59     // Read from CenRep so iPsmMode gets correct init value
       
    60     TInt psmMode;
       
    61     iPsmRepository->Get( KPsmCurrentMode, psmMode );
       
    62     iPsmMode = ( TPsmsrvMode )psmMode;
       
    63     
       
    64     __GSLOGSTRING( "[GS]<--[CPSMNetworkPlugin::ConstructL]" );
       
    65     }
       
    66 
       
    67 //
       
    68 // ----------------------------------------------------------------------------------
       
    69 // CPSMNetworkPlugin::NewL()
       
    70 // ----------------------------------------------------------------------------------
       
    71 //
       
    72 // Two-phased constructor.
       
    73 CPSMNetworkPlugin* CPSMNetworkPlugin::NewL( TPsmPluginCTorParams& aInitParams )
       
    74 	{
       
    75 	CPSMNetworkPlugin* self = new ( ELeave ) CPSMNetworkPlugin( aInitParams );
       
    76 
       
    77 	CleanupStack::PushL( self );
       
    78     self->ConstructL();
       
    79     CleanupStack::Pop( self );
       
    80 
       
    81     return self;
       
    82 	}
       
    83 
       
    84 // ----------------------------------------------------------------------------------
       
    85 // CPSMNetworkPlugin::~CPSMNetworkPlugin()
       
    86 // ----------------------------------------------------------------------------------
       
    87 //
       
    88 // Destructor.
       
    89 CPSMNetworkPlugin::~CPSMNetworkPlugin()
       
    90 	{
       
    91     __GSLOGSTRING( "[CPSMNetworkPlugin::~CPSMNetworkPlugin]" );
       
    92     delete iModel;
       
    93     iModel = NULL;
       
    94     delete iPsmRepository;
       
    95     iPsmRepository = NULL;
       
    96 	}
       
    97 
       
    98 // ---------------------------------------------------------
       
    99 // CPSMNetworkPlugin::IsPhoneOfflineL
       
   100 //
       
   101 // Checks if phone is in offline mode or not.
       
   102 // Return ETrue if phone is in offline mode.
       
   103 // Return EFalse if phone is not in offline mode.
       
   104 // ---------------------------------------------------------
       
   105 //
       
   106 TBool CPSMNetworkPlugin::IsPhoneOfflineL() const
       
   107     {
       
   108     if ( FeatureManager::FeatureSupported( KFeatureIdOfflineMode ) )
       
   109         {
       
   110         CRepository* repository = CRepository::NewLC( KCRUidCoreApplicationUIs );
       
   111         TInt connAllowed = 1;
       
   112         repository->Get( KCoreAppUIsNetworkConnectionAllowed, connAllowed );
       
   113         CleanupStack::PopAndDestroy();  // repository
       
   114         if ( !connAllowed )
       
   115             {
       
   116             return ETrue;
       
   117             }
       
   118         }
       
   119     return EFalse;
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------------------------------------
       
   123 // CPSMNetworkPlugin::NotifyModeChange()
       
   124 // ----------------------------------------------------------------------------------
       
   125 //
       
   126 void CPSMNetworkPlugin::NotifyModeChange( const TInt aMode )
       
   127     {
       
   128     TInt err = KErrNone;
       
   129     TRAP( err, DoModeChangeL( aMode ) );
       
   130     if ( KErrNone != err)
       
   131         {}
       
   132     __GSLOGSTRING2( "[CPSMNetworkPlugin::NotifyModeChange]: Mode:%d Err:%d", aMode, err );
       
   133     }
       
   134 
       
   135 
       
   136 // ----------------------------------------------------------------------------------
       
   137 // CPSMNetworkPlugin::NotifyModeChange()
       
   138 // ----------------------------------------------------------------------------------
       
   139 //
       
   140 void CPSMNetworkPlugin::DoModeChangeL( const TInt aMode )
       
   141     {
       
   142 	TPsmsrvMode newMode = ( TPsmsrvMode )aMode;
       
   143     if ( !IsPhoneOfflineL() && 
       
   144          FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma ) &&
       
   145          iModel->IsNetworkModeVisible() && IsChangeNetworkModeL ( iPsmMode, newMode ) )
       
   146         {
       
   147         RConfigInfoArray infoArray;
       
   148     
       
   149         TPsmsrvConfigInfo info1;
       
   150         info1.iConfigId = ENetworkMode;
       
   151         info1.iConfigType = EConfigTypeInt;
       
   152         info1.iIntValue = iModel->GetNetworkMode();
       
   153         infoArray.Append( info1 );
       
   154         
       
   155         __GSLOGSTRING1( "[CPSMNetworkPlugin::NotifyModeChangeL] Switching to mode:%d", aMode );
       
   156     
       
   157         __GSLOGSTRING1( "[CPSMNetworkPlugin::NotifyModeChangeL]: oldValue info1: %d", infoArray[0].iIntValue );
       
   158     
       
   159         iSettingsProvider.BackupAndGetSettingsL( infoArray, KPSMNetworkPluginStorageId );
       
   160         
       
   161         __GSLOGSTRING1( "[CPSMNetworkPlugin::NotifyModeChangeL]: newValue info1: %d", infoArray[0].iIntValue );
       
   162     
       
   163         // Don't change the network mode if there is ongoing phone call
       
   164         // since this will disconnect it
       
   165         if ( !iModel->IsCallActive() )
       
   166             {
       
   167             iModel->SetNetworkModeL ( infoArray[0].iIntValue  );
       
   168             }
       
   169         
       
   170         infoArray.Reset();       
       
   171         }
       
   172     }
       
   173 
       
   174 // ----------------------------------------------------------------------------------
       
   175 // CPSMNetworkPlugin::IsChangeNetworkMode
       
   176 // ----------------------------------------------------------------------------------
       
   177 //
       
   178 TBool CPSMNetworkPlugin::IsChangeNetworkModeL( TPsmsrvMode& aOldMode, TPsmsrvMode aNewMode )
       
   179     {
       
   180     // get the value of network mode change key  
       
   181     TInt modeChange = iModel->GetPsmNetworkModeChangeL();    
       
   182     TPsmsrvMode oldMode = aOldMode;
       
   183     aOldMode = aNewMode;
       
   184     if ( ( oldMode == EPsmsrvModeNormal && aNewMode == EPsmsrvPartialMode )
       
   185          || ( oldMode == EPsmsrvModePowerSave && aNewMode == EPsmsrvPartialMode )
       
   186          || ( KPowersavingNetworkmodeNoChanged == modeChange ) )
       
   187         {
       
   188         return EFalse;
       
   189         }
       
   190     else
       
   191         {
       
   192         return ETrue;
       
   193         }
       
   194     }
       
   195 
       
   196 //End of File
       
   197 
       
   198