coreapplicationuis/SysAp/Src/OfflineModeController/SysApOfflineModeControllerImpl.cpp
branchRCL_3
changeset 63 c2c61fdca848
parent 62 924385140d98
equal deleted inserted replaced
62:924385140d98 63:c2c61fdca848
     1 /*
     1 /*
     2  * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2005-2008 Nokia Corporation and/or its subsidiary(-ies). 
     3  * All rights reserved.
     3 * All rights reserved.
     4  * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6  * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     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:  CSysApOfflineModeController implementation
     8  *
    15  *
     9  * Initial Contributors:
    16 */
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  * CSysApOfflineModeController controls the offline mode.
       
    16  * It turns OFF RF, BT and WLAN when offline mode is enabled and turns them ON when
       
    17  * Offline mode is disabled
       
    18  *
       
    19  */
       
    20 
    17 
    21 
    18 
    22 // INCLUDES
    19 // INCLUDES
    23 
    20 
    24 #include "SysApOfflineModeControllerImpl.h"
    21 #include "SysApOfflineModeControllerImpl.h"
    25 #include "SysApAppUi.h"
    22 #include "SysApAppUi.h"
    26 #include "SysAp.hrh"
    23 #include "SysAp.hrh"
    27 #include "DosSvrServices.h"
    24 #include "DosSvrServices.h"
    28 #include "SysApCenRepController.h"
    25 #include "SysApCenRepController.h"
    29 #include "sysapcenrepofflinemodeobserver.h"
       
    30 #include <startupdomainpskeys.h>
    26 #include <startupdomainpskeys.h>
    31 #include <PSVariables.h>
    27 #include <PSVariables.h>
    32 #include <wlandevicesettingsinternalcrkeys.h> // For Turning ON/OFF WLAN
       
    33 
    28 
    34 
    29 
    35 MSysApOfflineModeController* CreateSysApOfflineModeControllerL( CSysApAppUi& aSysApAppUi )
    30 MSysApOfflineModeController* CreateSysApOfflineModeControllerL( CSysApAppUi& aSysApAppUi )
    36     {
    31     {
    37     return CSysApOfflineModeController::NewL( aSysApAppUi );
    32     return CSysApOfflineModeController::NewL( aSysApAppUi );
    56 // CSysApOfflineModeController::ConstructL() 
    51 // CSysApOfflineModeController::ConstructL() 
    57 // ----------------------------------------------------------------------------
    52 // ----------------------------------------------------------------------------
    58 void CSysApOfflineModeController::ConstructL()
    53 void CSysApOfflineModeController::ConstructL()
    59     {
    54     {
    60     TRACES( RDebug::Print( _L("CSysApOfflineModeController::ConstructL") ) ); 
    55     TRACES( RDebug::Print( _L("CSysApOfflineModeController::ConstructL") ) ); 
    61     
    56     // Check the active profile
    62     // create an observer for Offline Mode
    57     TInt activeProfile( iSysApAppUi.ActiveProfileId() );
    63     TRACES( RDebug::Print( _L("CSysApOfflineModeController::ConstructL: trying CSysApCenRepOfflineModeObserver::NewL") ) );
    58     activeProfile = iSysApAppUi.ActiveProfileId();
    64     iSysApCenRepOfflineModeObserver = CSysApCenRepOfflineModeObserver::NewL(*this );         
    59     if ( activeProfile == KOfflineModeProfileId )
    65     iOfflineModeActive = iSysApCenRepOfflineModeObserver->IsOffline();
    60         {
       
    61         iOfflineModeActive = ETrue;
       
    62         }
    66     }
    63     }
    67 
    64 
    68 // ----------------------------------------------------------------------------
    65 // ----------------------------------------------------------------------------
    69 // CSysApOfflineModeController::CSysApOfflineModeController() 
    66 // CSysApOfflineModeController::CSysApOfflineModeController() 
    70 // ----------------------------------------------------------------------------
    67 // ----------------------------------------------------------------------------
    71 CSysApOfflineModeController::CSysApOfflineModeController( CSysApAppUi& aSysApAppUi ) :
    68 CSysApOfflineModeController::CSysApOfflineModeController( CSysApAppUi& aSysApAppUi ) :
    72   iSysApAppUi( aSysApAppUi )
    69   iSysApAppUi( aSysApAppUi ),
       
    70   iOfflineModeActive( EFalse ),
       
    71   iDoNotActivateRF( EFalse )
    73     {
    72     {
    74 
    73 
    75     }
    74     }
    76 
    75 
    77 // ----------------------------------------------------------------------------
    76 // ----------------------------------------------------------------------------
    78 // CSysApOfflineModeController::~CSysApOfflineModeController()
    77 // CSysApOfflineModeController::~CSysApOfflineModeController()
    79 // ----------------------------------------------------------------------------
    78 // ----------------------------------------------------------------------------
    80 
    79 
    81 CSysApOfflineModeController::~CSysApOfflineModeController()
    80 CSysApOfflineModeController::~CSysApOfflineModeController()
    82     {
    81     {
    83     delete iSysApCenRepOfflineModeObserver;
       
    84     }
    82     }
    85 
    83 
    86 // ----------------------------------------------------------------------------
    84 // ----------------------------------------------------------------------------
    87 // CSysApOfflineModeController::OfflineModeActive()
    85 // CSysApOfflineModeController::OfflineModeActive()
    88 // ----------------------------------------------------------------------------
    86 // ----------------------------------------------------------------------------
    89 
    87 
    90 TBool CSysApOfflineModeController::OfflineModeActive()
    88 TBool CSysApOfflineModeController::OfflineModeActive()
    91     {
    89     {
    92     TRACES( RDebug::Print( _L("CSysApOfflineModeController::OfflineModeActive returns %d"), iOfflineModeActive ) );
       
    93     return iOfflineModeActive;
    90     return iOfflineModeActive;
    94     }
    91     }
    95 
    92 
    96 // ----------------------------------------------------------------------------
    93 // ----------------------------------------------------------------------------
    97 // CSysApOfflineModeController::SwitchFromOnlineToOfflineModeL()
    94 // CSysApOfflineModeController::SwitchFromOnlineToOfflineModeL()
    98 // ----------------------------------------------------------------------------
    95 // ----------------------------------------------------------------------------
    99 
    96 
   100 void CSysApOfflineModeController::SwitchFromOnlineToOfflineModeL()
    97 void CSysApOfflineModeController::SwitchFromOnlineToOfflineModeL()
   101     {
    98     {
   102     TRACES( RDebug::Print( _L("CSysApOfflineModeController::SwitchFromOnlineToOfflineModeL") ) ); 
    99     TRACES( RDebug::Print( _L("CSysApOfflineModeController::SwitchFromOnlineToOfflineModeL") ) ); 
   103         
       
   104     TInt err ( 0 );
   100     TInt err ( 0 );
   105 
   101 
   106     // Set state to starter. Note that if state is same as the current state, then nothing happens.
   102     // Set state to starter. Note that if state is same as the current state, then nothing happens.
   107     err = iSysApAppUi.SetStarterState(RStarterSession::EOffline);
   103     err = iSysApAppUi.SetStarterState(RStarterSession::EOffline);
   108 
   104 
   109     if ( err )
   105     if ( err )
   110         {
   106         {
       
   107         iSysApAppUi.RestoreProfileL( EFalse );
   111         iSysApAppUi.ShowUiNoteL( ECannotActivateOfflineModeNote );
   108         iSysApAppUi.ShowUiNoteL( ECannotActivateOfflineModeNote );
   112         }
   109         }
   113     else
   110     else
   114         {
   111         {
   115         iOfflineModeActive = ETrue;
   112         iOfflineModeActive = ETrue;
   120             {
   117             {
   121             err = iSysApAppUi.SetBtPowerState( EFalse ); // Switch BT off
   118             err = iSysApAppUi.SetBtPowerState( EFalse ); // Switch BT off
   122             SetBtActiveBeforeOfflineMode( ETrue );       // Update "BT active" setting
   119             SetBtActiveBeforeOfflineMode( ETrue );       // Update "BT active" setting
   123             TRACES( RDebug::Print( _L("CSysApOfflineModeController SetBtPowerStateL returned %d"), err ) );
   120             TRACES( RDebug::Print( _L("CSysApOfflineModeController SetBtPowerStateL returned %d"), err ) );
   124             }
   121             }
   125         /* Turn OFF WLAN */        
   122         
   126         TInt err( KErrNone );
   123         iSysApAppUi.OfflineModeChangedL();
   127         CRepository* repository = CRepository::NewL( KCRUidWlanDeviceSettingsRegistryId );
       
   128         err = repository->Set(KWlanOnOff, 0);
       
   129         delete repository;
       
   130         if(err) 
       
   131 		{
       
   132            TRACES( RDebug::Printf("CSysApOfflineModeController::SwitchFromOnlineToOfflineModeL Could not disable WLAN") );
       
   133 		    User::Leave(err);
       
   134         }
       
   135         else 
       
   136 		{
       
   137             TRACES( RDebug::Printf("CSysApOfflineModeController::SwitchFromOnlineToOfflineModeL WLAN Disabled" ) );
       
   138         }
       
   139 		
       
   140 		iSysApAppUi.OfflineModeChangedL();
       
   141         }
   124         }
   142     }
   125     }
   143 
   126 
   144 // ----------------------------------------------------------------------------
   127 // ----------------------------------------------------------------------------
   145 // CSysApOfflineModeController::SwitchFromOfflineToOnlineModeL()
   128 // CSysApOfflineModeController::SwitchFromOfflineToOnlineModeL()
   159         err = iSysApAppUi.SetStarterState(RStarterSession::ENormal);
   142         err = iSysApAppUi.SetStarterState(RStarterSession::ENormal);
   160         }
   143         }
   161         
   144         
   162     if ( err )
   145     if ( err )
   163         {
   146         {
       
   147         iSysApAppUi.RestoreProfileL( ETrue );
   164         iSysApAppUi.ShowUiNoteL( ECannotDeactivateOfflineModeNote );
   148         iSysApAppUi.ShowUiNoteL( ECannotDeactivateOfflineModeNote );
   165         }
   149         }
   166     else
   150     else
   167         {
   151         {
   168         iOfflineModeActive = EFalse;
   152         iOfflineModeActive = EFalse;
   173             err = iSysApAppUi.SetBtPowerState( ETrue );  // Switch BT on
   157             err = iSysApAppUi.SetBtPowerState( ETrue );  // Switch BT on
   174             SetBtActiveBeforeOfflineMode( EFalse );      // Update "BT active" setting
   158             SetBtActiveBeforeOfflineMode( EFalse );      // Update "BT active" setting
   175             TRACES( RDebug::Print( _L("CSysApOfflineModeController SetBtPowerStateL returned %d"), err ) );
   159             TRACES( RDebug::Print( _L("CSysApOfflineModeController SetBtPowerStateL returned %d"), err ) );
   176             }
   160             }
   177         
   161         
   178 		        /* Turn ON WLAN */    
       
   179            TInt err( KErrNone );
       
   180            CRepository* repository = CRepository::NewL( KCRUidWlanDeviceSettingsRegistryId );
       
   181            err = repository->Set(KWlanOnOff, 1);
       
   182            delete repository;
       
   183            if(err)
       
   184 		   {
       
   185                TRACES( RDebug::Printf("CSysApOfflineModeController::SwitchFromOfflineToOnlineModeL Could not enable WLAN") );
       
   186 		       User::Leave(err);
       
   187            }
       
   188            else
       
   189 		   {
       
   190                TRACES( RDebug::Printf("CSysApOfflineModeController::SwitchFromOfflineToOnlineModeL WLAN Enabled") );
       
   191            }
       
   192 
       
   193         iSysApAppUi.OfflineModeChangedL();
   162         iSysApAppUi.OfflineModeChangedL();
   194 		iSysApAppUi.SetNetworkConnectionAllowed( ECoreAppUIsNetworkConnectionAllowed );
   163 
   195 		}
   164         iSysApAppUi.SetNetworkConnectionAllowed( ECoreAppUIsNetworkConnectionAllowed );
   196 	}
   165         }
       
   166     }
   197 
   167 
   198 // ----------------------------------------------------------------------------
   168 // ----------------------------------------------------------------------------
   199 // CSysApOfflineModeController::CheckOfflineModeInitialStatusesL()
   169 // CSysApOfflineModeController::CheckOfflineModeInitialStatusesL()
   200 // ----------------------------------------------------------------------------
   170 // ----------------------------------------------------------------------------
   201 
   171 
   232     TInt simStatus = iSysApAppUi.StateOfProperty( KPSUidStartup, KPSSimStatus );
   202     TInt simStatus = iSysApAppUi.StateOfProperty( KPSUidStartup, KPSSimStatus );
   233     if ( ( !iSysApAppUi.SimSupported() ) ||
   203     if ( ( !iSysApAppUi.SimSupported() ) ||
   234          ( iSysApAppUi.BtSapEnabled() && simStatus != ESimNotPresent ) ||     
   204          ( iSysApAppUi.BtSapEnabled() && simStatus != ESimNotPresent ) ||     
   235          simStatus == ESimUsable )
   205          simStatus == ESimUsable )
   236         {
   206         {
   237         TRACES( RDebug::Printf("CSysApOfflineModeController::GoOnlineIfOkL SIM check PASSED") );
   207         iSysApAppUi.ShowQueryL( ESysApLeaveOfflineModeQuery );
   238         SwitchFromOfflineToOnlineModeL();
       
   239         }
   208         }
   240     else    
   209     else    
   241         {
   210         {
   242         TRACES( RDebug::Printf("CSysApOfflineModeController::GoOnlineIfOkL SIM check FALIED" ) );
       
   243         iSysApAppUi.ShowUiNoteL( EInsertSimNote );
   211         iSysApAppUi.ShowUiNoteL( EInsertSimNote );
   244         }
   212         }
   245     }
   213     }
   246 
   214 
   247 // ----------------------------------------------------------------------------
   215 // ----------------------------------------------------------------------------
   263     TBool err = EFalse;
   231     TBool err = EFalse;
   264     
   232     
   265     TInt btToBeActivated = iSysApAppUi.CenRepController().GetInt( KCRUidCoreApplicationUIsSysAp,
   233     TInt btToBeActivated = iSysApAppUi.CenRepController().GetInt( KCRUidCoreApplicationUIsSysAp,
   266                                                                   KSysApBtStatusBeforeOfflineMode,
   234                                                                   KSysApBtStatusBeforeOfflineMode,
   267                                                                   &err );
   235                                                                   &err );
   268 
       
   269     if ( err )
   236     if ( err )
   270         {
   237         {
   271         TRACES( RDebug::Print( _L("CSysApOfflineModeController::BtActiveBeforeOfflineMode: ERROR: %d" ), err ) );
   238         TRACES( RDebug::Print( _L("CSysApOfflineModeController::BtActiveBeforeOfflineMode: ERROR: %d" ), err ) );
   272         return EFalse;
   239         return EFalse;
   273         }
   240         }
   274     else
   241     else
   275         {
   242         {
   276         return ( TBool ) btToBeActivated;
   243         return ( TBool ) btToBeActivated;
   277         //return ETrue;
       
   278         }
   244         }
   279 
   245 
   280     }
   246     }
   281 
   247 
   282 // ----------------------------------------------------------------------------
   248 // ----------------------------------------------------------------------------
   285 TBool CSysApOfflineModeController::MustBtBeActivated()
   251 TBool CSysApOfflineModeController::MustBtBeActivated()
   286     {
   252     {
   287     return BtActiveBeforeOfflineMode();
   253     return BtActiveBeforeOfflineMode();
   288     }
   254     }
   289 
   255 
   290 
       
   291 // End of File
   256 // End of File
   292 
   257 
   293 
   258 
   294 
   259