coreapplicationuis/SysAp/Src/SysApAppUi.cpp
branchRCL_3
changeset 63 c2c61fdca848
parent 62 924385140d98
child 66 9af619316cbf
equal deleted inserted replaced
62:924385140d98 63:c2c61fdca848
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  CSysApAppUi implementation.
    14 * Description:  CSysApAppUi implementation.
    15 *
    15 *
    16 */
    16 */
       
    17 
       
    18 
    17 // INCLUDES
    19 // INCLUDES
    18 
    20 
       
    21 #include<akndiscreetpopup.h>
       
    22 #include <avkon.hrh>
       
    23 #include <avkon.rsg>
       
    24 #include <eikon.hrh>
       
    25 #include <apgwgnam.h>
       
    26 #include <eiksrv.h>
       
    27 #include <eikdll.h>
       
    28 #include <AknSmallIndicator.h>
       
    29 #include <AknBatteryNotify.h>
       
    30 #include <AknSignalNotify.h>
       
    31 #include <AknGlobalNote.h>
       
    32 #include <AknGlobalListQuery.h>
       
    33 #include <aknsoundsystem.h>
       
    34 #include <apgcli.h>
       
    35 
       
    36 #include <hwrmpowerstatesdkpskeys.h>
       
    37 #include <hwrmdomainpskeys.h>
       
    38 
       
    39 #include <PSVariables.h>
       
    40 #include "CoreApplicationUIsPrivatePSKeys.h"
       
    41 #include <ctsydomainpskeys.h>
    19 #include <startupdomainpskeys.h>
    42 #include <startupdomainpskeys.h>
    20 #include "sysapappui.h"
    43 #include <startupdomaincrkeys.h>
    21 #include "coreapplicationuisprivatepskeys.h"
    44 
    22 #include <HbDeviceMessageBoxSymbian.h>
    45 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
    23 //#include <hbdevicepowermenusymbian.h>
    46   #include <ASShdAlarm.h>
    24 #include <sacls.h>
    47 #else
    25 #include <featmgr.h>
    48   #include <asshddefs.h>
    26 #include <DevEncProtectedPSKey.h>
    49   #include <ASShdAlarmCal.h>
    27 #include <ctsydomainpskeys.h>
    50   #include <asshdalarm.h>
       
    51 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    52 
       
    53 #include <MProfileEngine.h>
       
    54 #include <MProfileName.h>
       
    55 #include <MProfilesNamesArray.h>
       
    56 #include <MProfile.h>
       
    57 #include <StringLoader.h>
    28 #include <secuisystemlock.h>
    58 #include <secuisystemlock.h>
    29 #include <apgtask.h>
    59 #include <secui.h>
    30 #include <hwrmpowerstatesdkpskeys.h>
    60 #include <settingsinternalcrkeys.h>
    31 #include <wlaninternalpskeys.h> 
    61 
    32 #include <HbDeviceNotificationDialogSymbian.h>
    62 #include "sysapganhandler.h"
    33 #include <hbsymbianvariant.h>
    63 #include <AknNotifierController.h>
    34 #include <hbtextresolversymbian.h>
    64 #include <eikappui.h>
    35 #include <UikonInternalPSKeys.h>
    65 #include <es_enum.h>
    36 
    66 #include <data_caging_path_literals.hrh>
    37 //#include "SysApWsClient.h"
    67 #include <eikon.hrh>
    38 #include "SysApFeatureManager.h"
    68 
    39 #include "SysApNspsHandler.h"
    69 #include "SysApSimChanged.h"
       
    70 
       
    71 #include <SysAp.rsg>
       
    72 #include "SysApLightsController.h"
       
    73 
    40 #include "SysApPubSubObserver.h"
    74 #include "SysApPubSubObserver.h"
    41 #include "sysapdefaultkeyhandler.h"
    75 #include "SysApProfileObserver.h"
    42 #include "SysApStartupController.h"
    76 
    43 #include "MSysApOfflineModeController.h"
       
    44 #include "SysApCenRepController.h"
       
    45 #include "sysapcenreplightsettingsobserver.h"
    77 #include "sysapcenreplightsettingsobserver.h"
    46 #include "SysApCenRepLogsObserver.h"
    78 #include "SysApCenRepLogsObserver.h"
    47 #include "SysApCenRepBTObserver.h"
    79 #include "SysApCenRepBTObserver.h"
    48 #include "SysApCenRepHacSettingObserver.h"
    80 #include "SysApCenRepHacSettingObserver.h"
       
    81 #include "SysApCenRepController.h"
       
    82 #include "CoreApplicationUIsPrivateCRKeys.h"
       
    83 #include "CoreApplicationUIsPrivatePSKeys.h"
       
    84 #include <UikonInternalPSKeys.h>
       
    85 
       
    86 #include "SysApStartupController.h"
       
    87 #include "SysApConnectionMonitorObserver.h"
       
    88 #include "SysApPowerKeyMenuObserver.h"
       
    89 #include "SysApSsSettingsObserver.h"
       
    90 #include "SysApAppUi.h"
       
    91 #include "SysApShutdownImage.h"
       
    92 #include "SysApEtelConnector.h"
       
    93 
       
    94 #include "SysApApp.h"
       
    95 #include "SysApMsgSimMemLowQuery.h"
       
    96 #include "SysApNspsHandler.h"
       
    97 #include "SysApWaitNote.h"
       
    98 #include "SysApConfirmationQuery.h"
       
    99 #include "SysApFeatureManager.h"
       
   100 #include "SysApSubscriber.h"
       
   101 #include "MSysApOfflineModeController.h"
       
   102 #include "MSysApBtController.h"
       
   103 #include "MSysApBtSapController.h"
       
   104 #include "MSysApLocationPrivacyIndicator.h"
       
   105 #include "MSysApUsbIndicator.h"
       
   106 
       
   107 #include <sysap.mbg>
       
   108 
       
   109 #include "SysApShutdownAnimation.h"
       
   110 
       
   111 #include <hwrmfmtx.h>
       
   112 #include <hwrmfmtxdomainpskeys.h>
       
   113 #include <hwrmfmtxdomaincrkeys.h>
       
   114 #include "sysapcenrepfmtxobserver.h"
       
   115 
       
   116 #include "SysApKeySndHandler.h"
       
   117 
       
   118 #include <ir_sock.h> // KIrdaPropertyCategory // KIrdaStatus
       
   119 
       
   120 #include <NetworkHandlingDomainPSKeys.h>
       
   121 
       
   122 // POC launching
       
   123 #include <AiwServiceHandler.h>
       
   124 #include <AiwPoCParameters.h>
       
   125 
       
   126 #include <sacls.h>  // KUidPhonePwr
       
   127 
       
   128 #include <wlaninternalpskeys.h>  // WLan indicator
       
   129 
       
   130 #include <ecom/ecom.h>
       
   131 #include "sysapkeymanagement.h"
       
   132 
       
   133 #include "SysApMediatorObserver.h"
       
   134 
       
   135 #include <secondarydisplay/SecondaryDisplaySysApAPI.h>
       
   136 #include "aknSDData.h"
       
   137 
       
   138 #include <AknTaskList.h>
       
   139 #include <layoutmetadata.cdl.h>
       
   140 
       
   141 #include "sysapdefaultkeyhandler.h"
    49 #include "sysapaudioroutingobserver.h"
   142 #include "sysapaudioroutingobserver.h"
       
   143 #include "sysapcenrepcallforwardingobserver.h"
       
   144 #include "sysapcenrepmsgwaitingobserver.h"
       
   145 
       
   146 #ifdef RD_MULTIPLE_DRIVE
       
   147  #include "sysapdrivelist.h"
       
   148  #include "sysapdriveunlockhandler.h"
       
   149  #include "sysapdriveejecthandler.h"
       
   150 #endif // RD_MULTIPLE_DRIVE
       
   151 
       
   152 #include "sysappsmcontroller.h"
    50 #include "sysapbatteryinfocontroller.h"
   153 #include "sysapbatteryinfocontroller.h"
    51 #include "SysApSimChanged.h"
   154 
    52 #include "MSysApBtSapController.h"
   155 #include <keylockpolicyapi.h>
    53 #include "MSysApBtController.h"
   156 
    54 #include "MSysApUsbIndicator.h"
       
    55 #include "sysapkeymanagement.h"
       
    56 #include "SysApShutdownImage.h"
       
    57 #include "SysApKeySndHandler.h"
       
    58 
       
    59 #include "SysApShutdownAnimation.h"
       
    60 #include "SysApEtelConnector.h"
       
    61 
       
    62 #ifdef RD_MULTIPLE_DRIVE
       
    63 #include "sysapdrivelist.h"
       
    64 #include "sysapdriveunlockhandler.h"
       
    65 #include "sysapdriveejecthandler.h"
       
    66 #include "hbdeviceinputdialogsymbian.h"
       
    67 #endif // RD_MULTIPLE_DRIVE
       
    68 
       
    69 #include <settingsinternalcrkeys.h>
       
    70 #include <keyguardaccessapi.h>
       
    71 #include <eikdef.h>
       
    72 #include <eikenv.h>
       
    73 #include <UsbWatcherInternalPSKeys.h> // USB transfer modes
   157 #include <UsbWatcherInternalPSKeys.h> // USB transfer modes
    74 #include <usbpersonalityids.h>
   158 #include <usbpersonalityids.h>
    75 #include "sysap.rsg"
   159 #include <smsuaddr.h>
    76 #include <hbindicatorsymbian.h>
   160 #include <featmgr.h>
    77 
   161 #include <DevEncProtectedPSKey.h>
    78 class CHbSymbianVariant;
   162 
       
   163 // CONSTANTS
       
   164 const TInt KPowerKeyMenuSelectionCancelled( -1 );
       
   165 const TInt KPowerKeyMenuSelectionSwitchOff( 0 );
    79 const TInt KModifierMask( 0 );
   166 const TInt KModifierMask( 0 );
    80 _LIT_SECURITY_POLICY_PASS(KAlwaysPassPolicy);
   167 const TInt KDelayBeforeShuttingDownInAlarmAndChargingStates( 500000 );
    81 _LIT_SECURITY_POLICY_C1(KWriteDeviceDataPolicy, ECapabilityWriteDeviceData);
   168 const TInt KDelayBeforeShowingGprsSuspendedNote( 500000 );
    82 const TInt KDelayBeforeNextScanningRound( 1000000 );
   169 const TInt KDelayBeforeNextScanningRound( 1000000 );
       
   170 const TInt KActiveProfile( 0 ); //The value of ActiveProfile for accessory default profile selection in GS/SD.
       
   171 const TInt KProfileListInitialIndex( 0 );
       
   172 const TInt KMaxProfileNameLength( 64 );
       
   173 const TInt KTimeToShowShutdownNote( 2000000 ); //2 seconds time for Goodbye note to show before being shutdown
       
   174 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   175 const TInt KCoefficientToMakeMicroToMilliSeconds = 1000;
       
   176 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
    83 
   177 
    84 /* ENABLE ANIMATION: Add id of background image.
   178 /* ENABLE ANIMATION: Add id of background image.
    85    Example: const TInt KBackgroundImageID = EMbmSysapQgn_graf_startup_bg;
   179    Example: const TInt KBackgroundImageID = EMbmSysapQgn_graf_startup_bg;
    86    If there is no image defined, clear screen is used.*/
   180    If there is no image defined, clear screen is used.*/
    87 const TInt KBackgroundImageID = 0;
   181 const TInt KBackgroundImageID = 0;
    88 
   182 #ifndef RD_MULTIPLE_DRIVE
    89 
   183 const TInt32 KAutolockAppUid = 0x100059B5;
    90 _LIT(KAccesoryPlugin,"com.nokia.accessory.indicatorplugin/1.0");
   184 const TInt KFileManagerAppUid = 0x101F84EB;
    91 _LIT(KAccMode, "AccMode");
   185 #endif // RD_MULTIPLE_DRIVE
    92 _LIT(KAccPhyConType, "AccType");
   186 const TInt KCoefficientKhzToMhz = 1000;
    93 
   187 const TInt KDecimalsInMhzFrequency = 2;
    94 _LIT(KPsmPlugin,"com.nokia.hb.powersavemodeplugin/1.0");
   188 
    95 _LIT(KPsm,"PSM");
   189 const TInt KHWSwitchGroup( 29 );
    96 _LIT(KCharging,"Charging");
   190 const TInt KHWSwitchGrip( 2 );
    97 _LIT(KPsmlocalisationfile, "powermanagement_");
   191 
    98 _LIT(KtsfilePath, "z:/resource/qt/translations/");
   192 _LIT_SECURITY_POLICY_PASS(KAlwaysPassPolicy);
    99 _LIT(KlowbatteryIcon,"qtg_small_bt_low_battery.svg");
   193 _LIT_SECURITY_POLICY_C1(KWriteDeviceDataPolicy, ECapabilityWriteDeviceData);
   100 _LIT(KbatteryFullIcon,"qtg_status_battery.svg");
       
   101 
       
   102 
       
   103 
   194 
   104 // ============================ MEMBER FUNCTIONS ==============================
   195 // ============================ MEMBER FUNCTIONS ==============================
   105 
   196 
   106 // ----------------------------------------------------------------------------
   197 // ----------------------------------------------------------------------------
   107 // CSysApAppUi::CSysApAppUi()
   198 // CSysApAppUi::CSysApAppUi()
   108 // ----------------------------------------------------------------------------
   199 // ----------------------------------------------------------------------------
   109 
   200 
   110 CSysApAppUi::CSysApAppUi()
   201 CSysApAppUi::CSysApAppUi() :
   111     :iSysApShutdownImage(NULL),
   202     iSysApCenRepLogsObserver( NULL ),
   112      iPowerMenuDialog(NULL),
   203     iSysApCenRepHacSettingObserver( NULL ),
   113      iDeviceLockEnabled(EFalse),
   204     iSysApPowerKeyMenuObserver( NULL ),
   114      iKeyLockEnabled(EFalse),
   205     iSysApShutdownImage( NULL ),
   115      iPowerKeyPopupMenuActive(EFalse),
   206     iSysApConfirmationQuery( NULL ),
   116      iResourcesFreed (EFalse),
   207     iSysApConfirmationQueryForRestart( NULL ),
   117      iShutdownStarted (EFalse),
   208     iSignalNotify( NULL ),
   118      iSysApAudioRoutingObserver (NULL),
   209 #ifndef RD_MULTIPLE_DRIVE
   119      iSysApBatteryInfoController (NULL),
   210     iMemoryCardDialog( 0 ),
   120      iSysApPsmController(NULL),
   211 #endif // RD_MULTIPLE_DRIVE
   121      iSapTimer (NULL),
   212     iPowerKeyPopupMenuActive( EFalse ),
   122      iSysApCenRepLogsObserver (NULL),
   213     iDisablePowerkeyMenu( EFalse ),
   123      iSysApUsbIndicatorController(NULL),
   214     iDeviceLockEnabled( EFalse ),
   124      iKeyguardController (NULL),
   215     iKeyLockEnabled( EFalse ),
   125      iKeyLockOnBeforeCall (EFalse),
   216     iShowkeypadActivatedNoteAfterSoftReject( EFalse ),
   126      iCheckLongPowerKeyEvent (EFalse),
   217     iEmergencyCallActive( EFalse ),
   127      iMMCEjectUsed( EFalse ),               
   218     iSimChangedDone( EFalse ),
   128      iMemCardPwdDialog(NULL)
   219     iResourcesFreed( EFalse ),
   129 	{
   220 #ifndef RD_MULTIPLE_DRIVE
   130 	TRACES( RDebug::Print( _L("CSysApAppUi::CSysApAppUi()") ) );
   221     iHideFirstBeep( ETrue ),
       
   222 #endif // RD_MULTIPLE_DRIVE
       
   223     iShutdownStarted( EFalse ),
       
   224     iIgnoreAccessorySpecificProfileChanges( ETrue ),
       
   225     iAccessoryJustConnected( EFalse ),
       
   226     iHandleNextProfileEvent( ETrue ),
       
   227     iActivateBt( EFalse ),
       
   228     iDeactivateBt( EFalse ),
       
   229     iGprsActivated( EFalse ),
       
   230     iGprsSuspended( EFalse ),
       
   231     iCallActivated( EFalse ),
       
   232     iGprsSuspendedNoteShown( EFalse ),
       
   233     iMMCEjectUsed( EFalse ),
       
   234 #ifndef RD_MULTIPLE_DRIVE
       
   235     iMMCPowerMenuEjectUsed( EFalse ),
       
   236     iMMCInserted( EFalse ),
       
   237 #endif // RD_MULTIPLE_DRIVE
       
   238     iTimer( NULL ),
       
   239     iSapTimer( NULL ),
       
   240 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   241     iAnimTimer( NULL ),
       
   242 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   243     iSysApTimer( NULL ),
       
   244 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   245     iAnimationShowingTime( 0 ),
       
   246 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   247     iShutdownContinued( EFalse ),
       
   248     iSysApAudioRoutingObserver( NULL ),
       
   249     iSysApCenRepCallForwardingObserver( NULL ),
       
   250     iSysApCenRepMsgWaitingObserver( NULL ),
       
   251     iSysApGanHandler( NULL ),
       
   252   	iKeyBoardRepeatCount(-1)
       
   253     {
       
   254     TRACES( RDebug::Print( _L("CSysApAppUi::CSysApAppUi()") ) );
   131     }
   255     }
   132 
   256 
   133 // ----------------------------------------------------------------------------
   257 // ----------------------------------------------------------------------------
   134 // CSysApAppUi::ConstructL()
   258 // CSysApAppUi::ConstructL()
   135 // ----------------------------------------------------------------------------
   259 // ----------------------------------------------------------------------------
   136 
   260 
   137 void CSysApAppUi::ConstructL()
   261 void CSysApAppUi::ConstructL()
   138     {
   262     {
   139     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: START") ) );
   263     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: START") ) );
   140     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying BaseConstructL()") ) );
   264     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying BaseConstructL( EAknEnableSkin )") ) );
   141     BaseConstructL();
   265     BaseConstructL( EAknEnableSkin );
   142     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: BaseConstructL() OK") ) );
   266     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: BaseConstructL() OK") ) );
   143 
   267     
       
   268  
       
   269     /*SysAp is set as system application (Symbian terminology). This means some special privilege compared
       
   270       to other applications. For example it does not get closed when system is asked to close applications
       
   271     */
   144     iEikonEnv->SetSystem( ETrue );
   272     iEikonEnv->SetSystem( ETrue );
       
   273 	// For cdma 
       
   274 
       
   275 	iTDEnable = FeatureManager::FeatureSupported( KFeatureIdFfTdScdma ); 
   145 
   276 
   146     iEikonEnv->WsSession().ComputeMode( RWsSession::EPriorityControlDisabled );
   277     iEikonEnv->WsSession().ComputeMode( RWsSession::EPriorityControlDisabled );
   147     
   278 
       
   279     static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PushContextL( R_AVKON_SILENT_SKEY_LIST );
       
   280 
   148     RThread().SetProcessPriority( EPriorityForeground );
   281     RThread().SetProcessPriority( EPriorityForeground );
   149     
   282 
       
   283     /*SysAp does not have any visible Status pane. An exception will be Charging state
       
   284     where SysAp shows Status Pane as it is the only running application.
       
   285     */
   150     TInt mode;
   286     TInt mode;
   151     User::LeaveIfError( RProperty::Get( KPSUidStartup, KPSGlobalStartupMode, mode ) );
   287     User::LeaveIfError( RProperty::Get( KPSUidStartup, KPSGlobalStartupMode, mode ) );
   152     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: KPSGlobalStartupMode = %d"), mode ) );
   288 
   153     
   289     if( mode == EStartupModeCharging || mode == EStartupModeAlarm )
   154     //SysAp needs to capture PowerKey events because it handles all functionality related to that
   290         {
   155     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CEikApplication::RootWin()") ) );
   291         SetStatusPaneLayoutL(
   156     RWindowGroup groupWin = iCoeEnv->RootWin();
   292             mode == EStartupModeCharging ? ESysApCharging : ESysApAlarm );
   157     User::LeaveIfError ( iCapturedEKeyPowerOff = groupWin.CaptureKey( EKeyPowerOff, KModifierMask, KModifierMask ) );
   293 
   158     User::LeaveIfError ( iCapturedEKeyPowerOffUpAndDowns = groupWin.CaptureKeyUpAndDowns( EStdKeyDevice2, KModifierMask, KModifierMask ) );
   294         SetKeyEventFlags(
   159      
   295             CAknAppUiBase::EDisableSendKeyShort |
   160     TRACES ( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApDefaultKeyHandler::NewL()") ) );
   296             CAknAppUiBase::EDisableSendKeyLong );
   161     iSysApDefaultKeyHandler = CSysApDefaultKeyHandler::NewL(*this);
   297         }
   162     
   298     else
   163     // Define P&S keys "owned" by SysAp
   299         {
   164     RProperty::Define( KPSUidUikon, KUikMMCInserted, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   300         SetStatusPaneLayoutL( ESysApNormal );
   165     //initially assuming that the memory card is not inserted
   301         }
   166     RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
   302 
   167     TDriveInfo driveInfo;
       
   168     TInt driveNumber; 
       
   169     TInt err;    
       
   170     RFs& fileServer = iEikonEnv->FsSession();  
       
   171     for ( driveNumber = EDriveD; driveNumber < EDriveZ; driveNumber++ )
       
   172          {
       
   173       err = fileServer.Drive(driveInfo,driveNumber);
       
   174           if(driveNumber == EDriveF && err == KErrNone && driveInfo.iType == EMediaHardDisk &&  driveInfo.iDriveAtt & KDriveAttRemovable)     
       
   175             {     
       
   176             TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: err = %d, driveInfo.iType = %d, driveInfo.iDriveAtt %d, KDriveAttRemovable = %d "),err,driveInfo.iType,driveInfo.iDriveAtt,KDriveAttRemovable) );     
       
   177             RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
       
   178                 break;  // Memory card drive found...     
       
   179             }
       
   180          }
       
   181            
       
   182     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApFeatureManager::NewL()") ) );
   303     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApFeatureManager::NewL()") ) );
   183     iSysApFeatureManager = CSysApFeatureManager::NewL();
   304     iSysApFeatureManager = CSysApFeatureManager::NewL();
   184     
   305 
   185     // Setup USB charging detector
   306     // Setup USB charging detector
   186      iSysApUsbChargerDetector.EnableUsbCharging(
   307     iSysApUsbChargerDetector.EnableUsbCharging(
   187          iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) &&
   308         iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) &&
   188          iSysApFeatureManager->Supported( KSysApFeatureIdUsbChargingWithoutReminderNotes ) );
   309         iSysApFeatureManager->Supported( KSysApFeatureIdUsbChargingWithoutReminderNotes ) );
   189     
   310 
       
   311     // Construct notifiers that are used frequently or in OOM situations.
       
   312     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CAknBatteryNotify::NewL()") ) );
       
   313     iBatteryNotify = CAknBatteryNotify::NewL();
       
   314     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CAknSignalNotify::NewL()") ) );
       
   315     iSignalNotify = CAknSignalNotify::NewL();
       
   316     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying new ( ELeave ) CSysApMsgSimMemLowQuery") ) );
       
   317     iSysApMsgSimMemLowQuery = new( ELeave ) CSysApMsgSimMemLowQuery( iSysApFeatureManager->CoverDisplaySupported() );
       
   318 
   190     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApPubSubObserver::NewL()") ) );
   319     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApPubSubObserver::NewL()") ) );
   191     iSysApPubSubObserver = CSysApPubSubObserver::NewL( *this );
   320     iSysApPubSubObserver = CSysApPubSubObserver::NewL( *this );
   192 
       
   193     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsPoCIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   321     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsPoCIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   194     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPoCIndicator, ECoreAppUIsPocIndicatorUninitialized );
   322     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPoCIndicator, ECoreAppUIsPocIndicatorUninitialized );
   195     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsPoCMissedIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   323     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsPoCMissedIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   196     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPoCMissedIndicator, ECoreAppUIsPocMissedIndicatorUninitialized );
   324     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPoCMissedIndicator, ECoreAppUIsPocMissedIndicatorUninitialized );
   197     
   325     
   199     // remove this definition after all clients have taken the USB personality ids in use
   327     // remove this definition after all clients have taken the USB personality ids in use
   200     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsUSBFileTransfer, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   328     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsUSBFileTransfer, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   201     
   329     
   202     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsVideoSharingIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   330     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsVideoSharingIndicator, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   203     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsVideoSharingIndicator, ECoreAppUIsVideoSharingIndicatorUninitialized );
   331     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsVideoSharingIndicator, ECoreAppUIsVideoSharingIndicatorUninitialized );
       
   332 
       
   333     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApAccessoryObserver::NewL()") ) );
       
   334     iSysApAccessoryObserver = CSysApAccessoryObserver::NewL( *this );
       
   335 
       
   336     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepController::NewL()") ) );
       
   337     iSysApCenRepController = CSysApCenRepController::NewL();
       
   338 
       
   339     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepLightSettingsObserver::NewL") ) );
       
   340     iSysApCenRepLightSettingsObserver = CSysApCenRepLightSettingsObserver::NewL( *this );
       
   341 
       
   342     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepBtObserver::NewL") ) );
       
   343     iSysApCenRepBtObserver = CSysApCenRepBtObserver::NewL( *this );
       
   344 
       
   345     if ( iSysApFeatureManager->FmTxSupported() )
       
   346         {
       
   347         TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepFmTxObserver::NewL") ) );        
       
   348         iSysApCenRepFmTxObserver = CSysApCenRepFmTxObserver::NewL( *this );    
       
   349         }
       
   350 
       
   351     // Define P&S keys "owned" by SysAp
       
   352     RProperty::Define( KPSUidUikon, KUikMMCInserted, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
       
   353     //initially set the value as 0 assuming mmc is not inserted
       
   354     RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
       
   355     TDriveInfo driveInfo;
       
   356     TInt driveNumber; 
       
   357     TInt err;    
       
   358     RFs& fileServer = iEikonEnv->FsSession();  
       
   359     for ( driveNumber = EDriveD; driveNumber < EDriveZ; driveNumber++ )
       
   360          {
       
   361 	  err = fileServer.Drive(driveInfo,driveNumber);
       
   362           if(driveNumber==EDriveF && err == KErrNone && driveInfo.iType == EMediaHardDisk &&  driveInfo.iDriveAtt & KDriveAttRemovable)     
       
   363         	{     
       
   364           TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: err = %d, driveInfo.iType = %d, driveInfo.iDriveAtt %d, KDriveAttRemovable = %d "),err,driveInfo.iType,driveInfo.iDriveAtt,KDriveAttRemovable) );     
       
   365         	RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
       
   366                break;  // Memory card drive found...     
       
   367       		}
       
   368          } 
   204 
   369 
   205     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsHideAlarm, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   370     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsHideAlarm, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   206     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsDisableKeyguard, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   371     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsDisableKeyguard, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   207     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsSoftReject, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   372     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsSoftReject, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   208     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsUipInd, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   373     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsUipInd, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   220     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsMtvDvbhStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   385     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsMtvDvbhStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   221     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsNewEmailStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   386     RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsNewEmailStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   222 
   387 
   223     // Initialize P&S keys "owned" by SysAp
   388     // Initialize P&S keys "owned" by SysAp
   224     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsHideAlarm, ECoreAppUIsHideAlarmUninitialized );
   389     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsHideAlarm, ECoreAppUIsHideAlarmUninitialized );
   225     
   390 
   226     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApAccessoryObserver::NewL()") ) );
       
   227     iSysApAccessoryObserver = CSysApAccessoryObserver::NewL( *this );
       
   228     
       
   229     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepController::NewL()") ) );
       
   230     iSysApCenRepController = CSysApCenRepController::NewL();
       
   231     
       
   232     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepLightSettingsObserver::NewL") ) );
       
   233     iSysApCenRepLightSettingsObserver = CSysApCenRepLightSettingsObserver::NewL( *this );
       
   234     
       
   235     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApCenRepBtObserver::NewL") ) );
       
   236     iSysApCenRepBtObserver = CSysApCenRepBtObserver::NewL( *this );
       
   237     
       
   238     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApStartupController::NewL()") ) );
   391     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApStartupController::NewL()") ) );
   239     iSysApStartupController = CSysApStartupController::NewL( *this, iSysApFeatureManager->OfflineModeSupported() );
   392     iSysApStartupController = CSysApStartupController::NewL( *this, iSysApFeatureManager->OfflineModeSupported() );
   240 
   393 
   241     iActiveProfileBeforeOfflineMode = iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileBeforeOfflineMode );    
       
   242            
       
   243     iSysApFeatureManager->FeatureVariationCheckDone();        
       
   244     
       
   245     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApLightsController::NewL()") ) );
   394     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApLightsController::NewL()") ) );
   246     iSysApLightsController = CSysApLightsController::NewL( *this,
   395     iSysApLightsController = CSysApLightsController::NewL( *this,
   247                                                            iSysApCenRepLightSettingsObserver->GetLightsTimeout(),
   396                                                            iSysApCenRepLightSettingsObserver->GetLightsTimeout(),
   248                                                            iSysApFeatureManager->CoverDisplaySupported() );
   397                                                            iSysApFeatureManager->CoverDisplaySupported() );
   249             
   398 
   250     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : trying CreateSysApOfflineModeControllerL()") ) );
   399     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApEtelConnector::NewL()") ) );
   251     iSysApOfflineModeController = CreateSysApOfflineModeControllerL( *this );
   400     iSysApEtelConnector = CSysApEtelConnector::NewL( *this );
   252     
   401 
   253     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : trying DoInitialSwStateCheckL()") ) );
   402     //SysAp needs to capture PowerKey events because it handles all functionality related to that
   254     iSysApStartupController->DoInitialSwStateCheckL();
   403     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CEikApplication::RootWin()") ) );
   255     
   404     RWindowGroup groupWin = iCoeEnv->RootWin();
   256     TRACES( RDebug::Print( _L("CCSysApAppUi::ConstructL  trying CSysApCenRepHacSettingObserver::NewL") ) );
   405     User::LeaveIfError ( iCapturedEKeyPowerOff = groupWin.CaptureKey( EKeyPowerOff, KModifierMask, KModifierMask ) );
   257     iSysApCenRepHacSettingObserver = CSysApCenRepHacSettingObserver::NewL( *this ); 
   406     User::LeaveIfError ( iCapturedEKeyPowerOffUpAndDowns = groupWin.CaptureKeyUpAndDowns( EStdKeyDevice2, KModifierMask, KModifierMask ) );
   258     
   407 
       
   408     TRACES ( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApDefaultKeyHandler::NewL()") ) );
       
   409     iSysApDefaultKeyHandler = CSysApDefaultKeyHandler::NewL( *this );
       
   410 
       
   411     TInt status(0);
       
   412     err = UserSvr::HalFunction( KHWSwitchGroup, KHWSwitchGrip, &status, 0 );
       
   413     if( err == KErrNone )
       
   414 	    {
       
   415 	    if( status == 0 )
       
   416 		    {
       
   417 	        RProperty::Set( KPSUidHWRM, KHWRMGripStatus, EPSHWRMGripOpen );
       
   418 		    }
       
   419 	    else
       
   420 		    {
       
   421 		    RProperty::Set( KPSUidHWRM, KHWRMGripStatus, EPSHWRMGripClosed );
       
   422 		    }
       
   423 	    }
       
   424      else
       
   425 	    {
       
   426 	    TRACES ( RDebug::Print( _L("CSysApAppUi::ConstructL: error in getting slide status: err = %d"), err ) );
       
   427 	    }
       
   428 
   259 #ifndef RD_MULTIPLE_DRIVE
   429 #ifndef RD_MULTIPLE_DRIVE
   260     if ( iSysApFeatureManager->MmcSupported() )
   430     if ( iSysApFeatureManager->MmcSupported() )
   261         {
   431         {
   262         iSysApMMCObserver = CSysApMMCObserver::NewL( this, &iEikonEnv->FsSession(), iSysApFeatureManager->MmcHotSwapSupported() );
   432         iSysApMMCObserver = CSysApMMCObserver::NewL( this, &iEikonEnv->FsSession(), iSysApFeatureManager->MmcHotSwapSupported() );
   263         }
   433         }
   271             *iSysApDriveList, *this, iSysApFeatureManager->MemoryCardLockSupported() );
   441             *iSysApDriveList, *this, iSysApFeatureManager->MemoryCardLockSupported() );
   272         iSysApDriveEjectHandler = CSysApDriveEjectHandler::NewL(
   442         iSysApDriveEjectHandler = CSysApDriveEjectHandler::NewL(
   273             *iSysApDriveList, *this, iEikonEnv->FsSession() );
   443             *iSysApDriveList, *this, iEikonEnv->FsSession() );
   274         }
   444         }
   275 #endif // RD_MULTIPLE_DRIVE
   445 #endif // RD_MULTIPLE_DRIVE
   276     
   446 
   277     //Instantiate the KEF plugin manager
   447     //Instantiate the KEF plugin manager
   278     //Trap constuction, since Sysap may live without iSysApKeyManagement
   448 	//Trap constuction, since Sysap may live without iSysApKeyManagement
   279     TRAPD(keyManagementErr, iSysApKeyManagement=CSysApKeyManagement::NewL(CCoeEnv::Static()->RootWin(), *this));
   449     TRAPD(keyManagementErr, iSysApKeyManagement=CSysApKeyManagement::NewL(CCoeEnv::Static()->RootWin(), *this));
   280 
   450 
   281     if (keyManagementErr)
   451     if (keyManagementErr)
   282         {
   452     	{
   283         TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : CSysApKeyManagement::NewL returns error=%d"), keyManagementErr ) );
   453     	TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : CSysApKeyManagement::NewL returns error=%d"), keyManagementErr ) );
   284         }
   454     	}
   285     
   455 
   286     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApEtelConnector::NewL()") ) );
   456     iSysApFeatureManager->FeatureVariationCheckDone();
   287     iSysApEtelConnector = CSysApEtelConnector::NewL( *this );
   457 
   288     
   458     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApProfileObserver::NewL()") ) );
       
   459     iSysApProfileObserver = CSysApProfileObserver::NewL( *this );
       
   460 
       
   461     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : trying MProfileEngine* CreateProfileEngineL()") ) );
       
   462     iProfileEngine = CreateProfileEngineL( &( iEikonEnv->FsSession() ) );
       
   463 
       
   464     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : trying CreateSysApOfflineModeControllerL()") ) );
       
   465     iSysApOfflineModeController = CreateSysApOfflineModeControllerL( *this );
       
   466 
       
   467     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL : trying DoInitialSwStateCheckL()") ) );
       
   468     iSysApStartupController->DoInitialSwStateCheckL();
       
   469 
       
   470     iActiveProfileBeforeOfflineMode = iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileBeforeOfflineMode );
       
   471 
   289     // Initialize animdll for handling side volume keys
   472     // Initialize animdll for handling side volume keys
   290     // (needed before normal mode in case emergency number is dialed from PIN query)
   473     // (needed before normal mode in case emergency number is dialed from PIN query)
   291     iSysApKeySndHandler = CSysApKeySndHandler::NewL(iEikonEnv->WsSession());
   474     iSysApKeySndHandler = CSysApKeySndHandler::NewL(iEikonEnv->WsSession());
   292     iKeyguardController = CKeyguardAccessApi::NewL();
   475 
       
   476     // Initialize shutdown image (needed by nspshandler)
   293     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApShutdownImage::NewL()") ) );
   477     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApShutdownImage::NewL()") ) );
   294     iSysApShutdownImage = CSysApShutdownImage::NewL();//NULL; //
   478     iSysApShutdownImage = CSysApShutdownImage::NewL();
   295     
   479 
   296     // Initialize nsps handler. Needed for proper lights control during PIN query.
   480     // Initialize nsps handler. Needed for proper lights control during PIN query.
   297     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApNspsHandler::NewL") ) );
   481     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CSysApNspsHandler::NewL") ) );
   298     iSysApNspsHandler = CSysApNspsHandler::NewL( iEikonEnv->WsSession(), iSysApShutdownImage->ShutdownCoeControlWindow() );
   482     iSysApNspsHandler = CSysApNspsHandler::NewL( iEikonEnv->WsSession(), iSysApShutdownImage->ShutdownCoeControlWindow() );
   299 
   483 
   300     RProperty::Define( KPSUidCoreApplicationUIs,KCoreAppUIsPowerMenuCustomDialogStatus, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy );
   484 #ifdef RD_LIGHT_CONTROL_CHANGE
   301     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPowerMenuCustomDialogStatus, ECoreAppUIsPowerMenuCustomDialogUninitialized );
   485     // NSPS Plugin has been loaded, inform lights controller that in can activate key event forwarding
       
   486     iSysApLightsController->KeyEventForwardingReady();
       
   487 #endif // RD_LIGHT_CONTROL_CHANGE    
       
   488 
       
   489     // Create HAC setting observer now because telephony state may change before entering to normal state
       
   490     TRACES( RDebug::Print( _L("CCSysApAppUi::ConstructL  trying CSysApCenRepHacSettingObserver::NewL") ) );
       
   491     iSysApCenRepHacSettingObserver = CSysApCenRepHacSettingObserver::NewL( *this );
   302     
   492     
   303 	TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: trying CHbIndicatorSymbian::NewL()") ) );
   493     DeactivatePSMifBatteryNotLowL ();
   304     iHbIndicatorSymbian = CHbIndicatorSymbian::NewL();
       
   305 	
       
   306 	  TBool result = HbTextResolverSymbian::Init(KPsmlocalisationfile, KtsfilePath);
       
   307 	
       
   308     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: END") ) );    
       
   309     }
       
   310 
       
   311 // ----------------------------------------------------------------------------
       
   312 // CSysApAppUi::FreeResources()
       
   313 // ----------------------------------------------------------------------------
       
   314 
       
   315 void CSysApAppUi::FreeResources()
       
   316     {
       
   317     TRACES( RDebug::Print( _L("CSysApAppUi::FreeResources") ) );
       
   318     delete iSysApBatteryInfoController;
       
   319     delete iSysApPsmController;
       
   320     delete iVariantAccState; 
       
   321 
       
   322     delete iSysApAudioRoutingObserver;
       
   323     
   494     
   324     if (iMemCardPwdDialog!=NULL)
   495     if( iSysApFeatureManager->GanSupported() )
   325         {
   496         {
   326         //PowerMenu already exist
   497 
   327         delete iMemCardPwdDialog;
   498 
   328         iMemCardPwdDialog = NULL;
   499 				RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsGanPropertyGanMode, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy  );
   329         }
   500 				RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsGanPropertySignalLevel, RProperty::EInt, KAlwaysPassPolicy, KWriteDeviceDataPolicy  );
   330     
   501         iSysApGanHandler = CSysApGanHandler::NewL( *this );
   331     if ( iSapTimer )
   502         }
   332         {
   503 
   333         iSapTimer->Cancel();
   504     TRACES( RDebug::Print( _L("CSysApAppUi::ConstructL: END") ) );
   334         delete iSapTimer;
   505     }
   335         }
   506 
   336     //Powermenu
   507 
   337     if (iPowerMenuDialog!=NULL)
   508 // ----------------------------------------------------------------------------
   338         {
   509 // CSysApAppUi::DeactivatePSMifBatteryNotLow()
   339         //PowerMenu already exist
   510 // ----------------------------------------------------------------------------
   340         delete iPowerMenuDialog;
   511  void CSysApAppUi::DeactivatePSMifBatteryNotLowL ()
   341         iPowerMenuDialog = NULL;
   512     {
   342         }
   513     TRACES( RDebug::Print( _L("CSysApAppUi::DeactivatePSMifBatteryNotLow: Start") ) );
   343     
   514     if ( iSysApFeatureManager->PowerSaveSupported()) //&& iSysApFeatureManager->Supported( KSysApFeatureIdBatteryInfoPopup ))
   344     RWindowGroup groupWin = iCoeEnv->RootWin();
   515         {
   345     groupWin.CancelCaptureKey( iCapturedEKeyPowerOff );
   516         // Create batteruInfoController to get current battery status;
   346     groupWin.CancelCaptureKeyUpAndDowns( iCapturedEKeyPowerOffUpAndDowns );
   517 	if(iSysApBatteryInfoController == NULL)
   347     
   518 	    {
   348     delete iSysApDefaultKeyHandler;
   519 	    iSysApBatteryInfoController = CSysApBatteryInfoController::NewL( 
   349     delete iSysApCenRepLightSettingsObserver;
   520                                                         iSysApCenRepController->GetInt( 
   350     delete iSysApCenRepBtObserver;
   521                                                                 KCRUidCoreApplicationUIsConf,
   351     delete iSysApCenRepHacSettingObserver;
   522                                                                 KCoreAppUIsBatteryInformationLowThreshold ) );
   352     delete iSysApCenRepController;
   523 	    }
   353 
   524         //Querry the battery level 
   354     delete iSysApPubSubObserver;
   525         TBool status = iSysApBatteryInfoController->IsBatteryInfoAboveThreshold();
   355     
   526         TRACES( RDebug::Print( _L("CCSysApAppUi::DeactivatePSMifBatteryNotLow  IsBatteryInfoAboveThreshold=%d"), status ) );
   356     delete iSysApLightsController;
   527         // Querry to deactivate PSM if PSM is activated and battery status is above threshold
   357     delete iSysApFeatureManager;
   528         if (status)
   358     
   529             {
   359     delete iSysApCenRepLogsObserver;
   530 			if(iSysApPsmController == NULL)
   360     delete iSysApOfflineModeController;
   531 				{
   361     
   532 				iSysApPsmController = CSysApPsmController::NewL( *this );
   362     delete iSysApUsbIndicatorController;
   533 				}
   363     delete iKeyguardController;
   534             if ( iSysApPsmController->ShowDeactivateQuery())
   364     delete iHbIndicatorSymbian; 
   535                 ShowQueryL( ESysApBattChargingPowerSavingQuery );
   365     delete iSysApKeyManagement;
   536             else
   366     iSysApKeyManagement = NULL;
   537                 iSysApPsmController->DoEnablePartialPsm( EFalse );
   367     
   538             }
   368     REComSession::FinalClose();
   539         }
   369     iResourcesFreed = ETrue;
   540     TRACES( RDebug::Print( _L("CSysApAppUi::DeactivatePSMifBatteryNotLow: End") ) );
   370     TRACES( RDebug::Print( _L("CSysApAppUi::FreeResources:END") ) );
   541     } 
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // CStartupAppUi::PrepareToExit()
       
   375 // ---------------------------------------------------------------------------
       
   376 void CSysApAppUi::PrepareToExit()
       
   377     {
       
   378     TRACES(RDebug::Print( _L("CSysApAppUi::PrepareToExit()")));
       
   379     CEikAppUi::PrepareToExit();
       
   380     }
       
   381 
       
   382 
       
   383 // ----------------------------------------------------------------------------
       
   384 // CSysApAppUi::StateOfProperty()
       
   385 // ----------------------------------------------------------------------------
       
   386 TInt CSysApAppUi::StateOfProperty( const TUid& aCategory, const TUint aKey ) const
       
   387     {
       
   388     TInt err( KErrNone );
       
   389     TInt value( 0 );
       
   390     err = RProperty::Get( aCategory, aKey, value );
       
   391     if ( err )
       
   392         {
       
   393         TRACES( RDebug::Print( _L("CSysApAppUi::StateOfProperty. RProperty::Get: err=%d"), err ) );
       
   394         return err;
       
   395         }
       
   396     return value;
       
   397     }
       
   398 
       
   399 // ----------------------------------------------------------------------------
       
   400 // CSysApAppUi::OfflineModeActive()
       
   401 // ----------------------------------------------------------------------------
       
   402 TBool CSysApAppUi::OfflineModeActive()
       
   403     {
       
   404     if(iSysApOfflineModeController)
       
   405         {
       
   406         return iSysApOfflineModeController->OfflineModeActive();
       
   407         }
       
   408     else
       
   409         {
       
   410         return EFalse;
       
   411         }
       
   412     }
       
   413 
       
   414 // ----------------------------------------------------------------------------
       
   415 // CSysApAppUi::GoOnlineL()
       
   416 // ----------------------------------------------------------------------------
       
   417 
       
   418 void CSysApAppUi::GoOnlineL( TBool /* aDoProfileChange */ )
       
   419     {
       
   420     if ( iSysApFeatureManager->OfflineModeSupported() )
       
   421         {
       
   422 //        TRACES( RDebug::Print( _L("CSysApAppUi::GoOnlineL: going from off-line into on-line: aDoProfileChange=%d" ), aDoProfileChange ) );
       
   423         iActivateBt = iSysApOfflineModeController->MustBtBeActivated();
       
   424         iSysApOfflineModeController->SwitchFromOfflineToOnlineModeL();
       
   425         TRACES( RDebug::Print( _L("CSysApAppUi::GoOnlineL: iActivateBt = %d" ), iActivateBt ) );
       
   426         }
       
   427     }
       
   428 
       
   429 // ----------------------------------------------------------------------------
       
   430 // CSysApAppUi::GoOfflineL()
       
   431 // ----------------------------------------------------------------------------
       
   432 
       
   433 void CSysApAppUi::GoOfflineL()
       
   434     {
       
   435     if ( iSysApFeatureManager->OfflineModeSupported() )
       
   436         {
       
   437         TRACES( RDebug::Print( _L("CSysApAppUi::GoOfflineL" ) ) );
       
   438         iDeactivateBt = ETrue;
       
   439         iSysApOfflineModeController->SwitchFromOnlineToOfflineModeL();
       
   440         }
       
   441     }
       
   442 
       
   443 #ifndef SYSAP_USE_STARTUP_UI_PHASE
       
   444 // need to configure the above macro.
       
   445 #else // SYSAP_USE_STARTUP_UI_PHASE
       
   446 
       
   447 // ----------------------------------------------------------------------------
       
   448 // CSysApAppUi::HandleUiReadyAfterBootL()
       
   449 // Called when startup UI activities has been finished
       
   450 // ----------------------------------------------------------------------------
       
   451 
       
   452 void CSysApAppUi::HandleUiReadyAfterBootL()
       
   453     {
       
   454     TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL" ) ) );    
       
   455     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
   456 
       
   457     UpdateBatteryBarsL( state );   
       
   458     DoSwStateNormalConstructionL();
       
   459     HandleAccessoryProfileInStartupL();
       
   460           
       
   461     if ( iSysApFeatureManager->MmcSupported() )
       
   462         {
       
   463 #ifndef RD_MULTIPLE_DRIVE
       
   464         MountMMC();
       
   465         MMCStatusChangedL();
       
   466         iHideFirstBeep = EFalse;
       
   467 #else // RD_MULTIPLE_DRIVE
       
   468         iSysApDriveList->MountDrive( iSysApDriveList->DefaultMemoryCard() );
       
   469         UpdateInsertedMemoryCardsL();
       
   470 #endif // RD_MULTIPLE_DRIVE
       
   471         }
       
   472 		
       
   473 	if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
   474         {
       
   475         iSysApMMCObserver->StartMountObserver();
       
   476         }    
       
   477    
       
   478     if ( !iSysApPsmController ) // created here if first state change has not occurred yet
       
   479        {
       
   480        iSysApPsmController = CSysApPsmController::NewL( *this );        
       
   481        }
       
   482 
       
   483     if ( iSysApPsmController )
       
   484        {
       
   485 	   if ( iCharging ) // if charger is connected on boot PSM queries may need to be shown
       
   486         {
       
   487          HandleChargingStatusL( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
   488         }
       
   489 		
       
   490        if ( iSysApPsmController->FullPsmEnabled() )
       
   491            {
       
   492            // activate psm indicator 
       
   493             iVariantAccState = CHbSymbianVariant::NewL(&KPsm, CHbSymbianVariant::EDes);
       
   494             if (!iHbIndicatorSymbian->Activate(KPsmPlugin,iVariantAccState)) 
       
   495                {
       
   496                int error = iHbIndicatorSymbian->Error();
       
   497                //use the errorcode...
       
   498                }
       
   499            }
       
   500      
       
   501        }
       
   502     
       
   503     TInt batteryStatus = StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryStatus );
       
   504     TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: batteryStatus %d" ), batteryStatus ) );
       
   505     if(  batteryStatus == EBatteryStatusLow || batteryStatus == EBatteryStatusEmpty )
       
   506         {
       
   507         // low and empty battery states are informed to the user in device startup
       
   508         HandleBatteryStatusL( batteryStatus );
       
   509         }
       
   510     else if ( iSysApPsmController && !iCharging )
       
   511         {
       
   512             TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: batteryStatus %d, iCharging %d -> disable partial psm" ), batteryStatus, iCharging ) );
       
   513 
       
   514             iSysApPsmController->BatteryLow( EFalse );
       
   515             iSysApPsmController->DoEnablePartialPsm( EFalse );
       
   516         }
       
   517     
       
   518     if ( ! iSysApUsbIndicatorController )
       
   519         {
       
   520         TRAPD ( usbErr, iSysApUsbIndicatorController = CreateSysApUsbIndicatorL( *this ) );
       
   521         if ( usbErr )
       
   522             {
       
   523             TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: error in constructing USB ind. controller %d" ), usbErr ) );
       
   524             }
       
   525         }
       
   526    }
       
   527 
       
   528 // ----------------------------------------------------------------------------
       
   529 // CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
   530 // This method is not called after boot has finished.
       
   531 // ----------------------------------------------------------------------------
       
   532 
       
   533 void CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
   534     {
       
   535     TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: %d" ), aSwState ) );
       
   536 
       
   537     TRAPD( simChangedErr, DoSimChangedFromPreviousBootL() );
       
   538     TRACES( RDebug::Print( _L("CSysApAppUi::DoStateChangedL: simChangedErr = %d" ), simChangedErr ) );
       
   539     simChangedErr = simChangedErr; // suppress 'variable not used' warning
       
   540     LogsObserverL().HandleSimChangedCheckDoneL();
       
   541 
       
   542     if ( iSysApFeatureManager->PowerSaveSupported() )
       
   543         {
       
   544         // create controller before checking battery state, so that power saving can be enabled during boot if needed
       
   545         if ( !iSysApPsmController ) // created only in first state change
       
   546             {
       
   547             iSysApPsmController = CSysApPsmController::NewL( *this );        
       
   548             }
       
   549 
       
   550         // in charger boot explicitly disable  power save mode
       
   551         if ( aSwState == RStarterSession::ECharging )
       
   552             {
       
   553             iSysApPsmController->ChargerConnected();
       
   554             iSysApPsmController->DoEnableFullPsm(EFalse); // disable  power save now
       
   555             }
       
   556         }
       
   557 
       
   558     if ( aSwState == RStarterSession::ECharging || aSwState == RStarterSession::EAlarm )
       
   559         {
       
   560         TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
   561         //Also Charging status will be updated with the following function.
       
   562         UpdateBatteryBarsL( state );    
       
   563         }
       
   564         
       
   565     if( IsStateNormal() )
       
   566         {
       
   567         TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL to normal state.") ) );
       
   568         
       
   569         if ( iSysApFeatureManager->MmcSupported() )
       
   570             {
       
   571 #ifndef RD_MULTIPLE_DRIVE
       
   572             MountMMC();
       
   573             MMCStatusChangedL();
       
   574             iHideFirstBeep = EFalse;
       
   575 #else // RD_MULTIPLE_DRIVE
       
   576             iSysApDriveList->MountDrive( iSysApDriveList->DefaultMemoryCard() );
       
   577             UpdateInsertedMemoryCardsL();
       
   578 #endif // RD_MULTIPLE_DRIVE
       
   579             }
       
   580         if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
   581             {
       
   582             iSysApMMCObserver->StartMountObserver();
       
   583             }
       
   584         
       
   585         iSysApBtController = CreateSysApBtControllerL( *this );
       
   586         iSysApBtSapController = CreateSysApBtSapControllerL( *this );
       
   587 
       
   588         if ( iActivateBt )
       
   589             {
       
   590             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Activating BT" ) ) );
       
   591             SetBtPowerState( ETrue );
       
   592             }
       
   593 
       
   594         if ( iDeactivateBt )
       
   595             {
       
   596             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Deactivating BT" ) ) );
       
   597             SetBtPowerState( EFalse );
       
   598             }
       
   599 
       
   600         if ( !StarterSession().Handle() )
       
   601             {
       
   602             User::Leave( KErrBadHandle );
       
   603             }
       
   604 
       
   605 /*        if ( !KeyLock().Handle() )
       
   606             {
       
   607             User::Leave( KErrBadHandle );
       
   608             }
       
   609 */
       
   610 #ifdef __SYSAP_MODULE_TEST
       
   611         ModuleTestShowUiNoteL( _L("SysAp: SW state normal!") );
       
   612 #endif
       
   613         }
       
   614 
       
   615     // Allow lights
       
   616     iSysApLightsController->AllowLightsOn();
       
   617     }
       
   618 
       
   619 #endif // SYSAP_USE_STARTUP_UI_PHASE
       
   620 
   542 
   621 // ----------------------------------------------------------------------------
   543 // ----------------------------------------------------------------------------
   622 // CSysApAppUi::~CSysApAppUi()
   544 // CSysApAppUi::~CSysApAppUi()
   623 // ----------------------------------------------------------------------------
   545 // ----------------------------------------------------------------------------
   624 
   546 
   625 CSysApAppUi::~CSysApAppUi()
   547 CSysApAppUi::~CSysApAppUi()
   626     {
   548     {
   627     TRACES( RDebug::Print( _L("~CSysApAppUi() started") ) );
   549     TRACES( RDebug::Print( _L("~CSysApAppUi() started") ) );
   628     if( !iResourcesFreed )
   550     if( !iResourcesFreed )
   629       {
   551         {
   630         FreeResources();
   552         FreeResources();
   631 
   553 
   632         iStarterSession.Close();
   554         iStarterSession.Close();
   633 
   555 
   634         }
   556         }
   643         delete iSysApShutdownAnimation;
   565         delete iSysApShutdownAnimation;
   644 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
   566 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
   645         }
   567         }
   646 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
   568 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
   647 
   569 
   648 //    delete iProfileNote;
   570   
   649 
   571 
   650 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
   572 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
   651     if( iAnimTimer )
   573     if( iAnimTimer )
   652         {
   574         {
   653         iAnimTimer->Cancel();
   575         iAnimTimer->Cancel();
   654         }
   576         }
   655     delete iAnimTimer;
   577     delete iAnimTimer;
   656 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
   578 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
   657 
   579 
       
   580     delete iSysApPowerKeyMenuObserver;
       
   581 
   658     delete iSysApStartupController;
   582     delete iSysApStartupController;
       
   583 
       
   584     delete iSysApGanHandler;
   659 
   585 
   660 #ifdef RD_MULTIPLE_DRIVE
   586 #ifdef RD_MULTIPLE_DRIVE
   661     iInsertedMemoryCards.Close();
   587     iInsertedMemoryCards.Close();
   662     delete  iSysApDriveEjectHandler;
   588     delete  iSysApDriveEjectHandler;
   663     delete iSysApDriveUnlockHandler;
   589     delete iSysApDriveUnlockHandler;
   664     delete iSysApDriveList;
   590     delete iSysApDriveList;
   665 #endif // RD_MULTIPLE_DRIVE
   591 #endif // RD_MULTIPLE_DRIVE
   666 
   592 
   667     TRACES( RDebug::Print( _L("~CSysApAppUi() completed") ) );
   593     TRACES( RDebug::Print( _L("~CSysApAppUi() completed") ) );
   668     }
   594     }
       
   595 
       
   596 
       
   597 // ----------------------------------------------------------------------------
       
   598 // CSysApAppUi::HandleLocationPrivacyIndicatorL()
       
   599 // ----------------------------------------------------------------------------
       
   600 
       
   601 void CSysApAppUi::HandleLocationPrivacyIndicatorL( const TInt aState )
       
   602     {
       
   603     TRACES( RDebug::Print( _L("CSysApAppUi::HandleLocationPrivacyIndicatorL() state=%d"), aState ) );
       
   604     if ( iSysApFeatureManager->LocationPrivacySupported() )
       
   605         {
       
   606         // Phase 1. Set all Location Privacy indicators off
       
   607         if ( iSysApLocationPrivacyIndicator->iIndicatorIdAcceptAll != KSysApNoIndicator )
       
   608             {
       
   609             SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdRejectAll, EAknIndicatorStateOff );
       
   610             }
       
   611         if ( iSysApLocationPrivacyIndicator->iIndicatorIdRejectAll != KSysApNoIndicator )
       
   612             {
       
   613             SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdRejectAll, EAknIndicatorStateOff );
       
   614             }
       
   615         if ( iSysApLocationPrivacyIndicator->iIndicatorIdAlwaysAsk != KSysApNoIndicator )
       
   616             {
       
   617             SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdAlwaysAsk, EAknIndicatorStateOff );
       
   618             }
       
   619         if ( iSysApLocationPrivacyIndicator->iIndicatorIdIndividualPrivacy != KSysApNoIndicator )
       
   620             {
       
   621             SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdIndividualPrivacy, EAknIndicatorStateOff );
       
   622             }
       
   623         // Phase 2. Set the required Location Privacy indicator on
       
   624         switch ( aState )
       
   625             {
       
   626             case EPSLocPrivAcceptAll:
       
   627                 if ( iSysApLocationPrivacyIndicator->iIndicatorIdAcceptAll != KSysApNoIndicator )
       
   628                     {
       
   629                     SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdAcceptAll, EAknIndicatorStateOn );
       
   630                     }
       
   631                 break;
       
   632             case EPSLocPrivRejectAll:
       
   633                 if ( iSysApLocationPrivacyIndicator->iIndicatorIdRejectAll != KSysApNoIndicator )
       
   634                     {
       
   635                     SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdRejectAll, EAknIndicatorStateOn );
       
   636                     }
       
   637                 break;
       
   638             case EPSLocPrivAlwaysAsk:
       
   639                 if ( iSysApLocationPrivacyIndicator->iIndicatorIdAlwaysAsk != KSysApNoIndicator )
       
   640                     {
       
   641                     SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdAlwaysAsk, EAknIndicatorStateOn );
       
   642                     }
       
   643                 break;
       
   644             case EPSLocPrivIndividualPrivacy:
       
   645                 if ( iSysApLocationPrivacyIndicator->iIndicatorIdIndividualPrivacy != KSysApNoIndicator )
       
   646                     {
       
   647                     SetIndicatorStateL( iSysApLocationPrivacyIndicator->iIndicatorIdIndividualPrivacy, EAknIndicatorStateOn );
       
   648                     }
       
   649                 break;
       
   650             default:
       
   651                 break;
       
   652             }
       
   653         }
       
   654     }
       
   655 
       
   656 
       
   657 // ----------------------------------------------------------------------------
       
   658 // CSysApAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
       
   659 // ----------------------------------------------------------------------------
       
   660 
       
   661 TKeyResponse CSysApAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
       
   662     {
       
   663     if ( ! iShutdownStarted )
       
   664         {
       
   665         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL: aKeyEvent.iCode:%d, aKeyEvent.iScanCode:%d, aType:%d, iIgnoreNextPowerKeyUpEvent:%d, iPowerKeyPopupMenuActive:%d, iLastPowerKeyWasShort:%d, iPowerKeyPopupMenuDismissed:%d"),
       
   666                                aKeyEvent.iCode, aKeyEvent.iScanCode, aType, iIgnoreNextPowerKeyUpEvent, iPowerKeyPopupMenuActive, iLastPowerKeyWasShort, iPowerKeyPopupMenuDismissed ) );
       
   667 
       
   668 #ifdef _DEBUG
       
   669         // camery latency measurement environment instrumentation, don't remove
       
   670         if ( aType == EEventKey && aKeyEvent.iCode == EKeyCamera )
       
   671             {
       
   672             TRACES( RDebug::Print( _L("e_KEY_EVENT_SENDING 0") ) );
       
   673             }
       
   674 #endif // _DEBUG
       
   675 
       
   676         TBool haveStatusPane = ( StatusPane()== NULL ) ? EFalse : StatusPane()->IsVisible();
       
   677         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL: haveStatusPane = %d" ) ) );
   669         
   678         
   670 TBool CSysApAppUi::ResourcesFreed() const
   679         TKeyResponse response( EKeyWasNotConsumed );
   671     {
   680         if (iSysApKeyManagement && aKeyEvent.iCode != EKeyPowerOff && aKeyEvent.iCode != 'E')
   672     return iResourcesFreed;
   681             {
   673     }
   682             response = iSysApKeyManagement->HandleKeyEventL(aKeyEvent, aType );
   674 
   683             }
   675 void CSysApAppUi::ShowExampleUiNoteL( const TDesC& noteText )const
   684         
   676     {          
   685         if( aType == EEventKey )
   677  	TRACES( RDebug::Print( _L("CSysApAppUi::ShowExampleUiNoteL:: constructing CHbDeviceMessageBoxSymbian:BeGIN") ) );    
   686             {
   678     CHbDeviceMessageBoxSymbian *note = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EInformation);
   687             switch ( aKeyEvent.iCode )
   679  	CleanupStack::PushL(note);
   688                 {
   680     TRACES( RDebug::Print( _L("CSysApAppUi::ShowExampleUiNoteL:: construction of CHbDeviceMessageBoxSymbian:END") ) ); 
   689 #ifdef _DEBUG
   681     note->SetTextL(noteText);
   690                 case 'E': //For testing
   682 	note->SetTimeout(300);
   691                     Exit();
   683  	TRACES( RDebug::Print( _L("CSysApAppUi:: Display of  CHbDeviceMessageBoxSymbian::Begin") ) );    
   692                     break;
   684     note->ShowL();
   693 #endif
   685 	TRACES( RDebug::Print( _L("CSysApAppUi:: Display of  CHbDeviceMessageBoxSymbian::End") ) );
   694                 case EKeyPowerOff:
   686 	CleanupStack::PopAndDestroy(note);
   695                     //Short power key press
   687     }
   696                     iKeyBoardRepeatCount++;
   688 
   697                     if( aKeyEvent.iRepeats == 0 )
   689 
   698                         {
   690 void CSysApAppUi::ExecQueryL( TSysapQuery aQuery, TDes8& aReturn )
   699                         TRACES( RDebug::Print(_L("CSysApAppUi::HandleKeyEventL, Short powerkey") ) );
   691     {
   700                         iLastPowerKeyWasShort = ETrue;
   692     ExecQueryL( aQuery, aReturn, KNullDesC8 );
   701                         if ( IsDefaultPowerKeyBehavior() )
   693     }
   702                             {
   694 
   703                             //do this only if the power key menu is active (handles item navigation)
   695 // ----------------------------------------------------------------------------
   704                             //or if the power key is not the lock key (default)
   696 // CSysApAppUi::ExecQueryL
   705                              HandleShortPowerKeyPressedL();
   697 // ----------------------------------------------------------------------------
   706                             }
   698 //
   707                         
   699 void CSysApAppUi::ExecQueryL( TSysapQuery aQuery, TDes8& aReturn, const TDesC8& /*aParam*/ )
   708                         
   700     {
   709                         iIgnoreNextPowerKeyRepeats = EFalse;
   701     TRACES( RDebug::Print(_L("CSysApAppUi::ExecQueryL: aQuery=%d"), aQuery ) );
   710                         }
   702 
   711                     //Long power key press
   703     switch ( aQuery )
   712                     else if( aKeyEvent.iRepeats > 0 && iKeyBoardRepeatCount >= iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApPowerkeyRepeatcount ))
   704         {
   713                         {
   705         case EGetHwrmLight: // get handle to HWRM client session. Returns CHWRMLight*.
   714                         iKeyBoardRepeatCount = -1;
   706             {
   715                         TRACES( RDebug::Print(_L("CSysApAppUi::HandleKeyEventL, Long powerkey") ) );
   707             THwrmLightBuf retBuf( iSysApLightsController->GetHwrmLight() );
   716                         iLastPowerKeyWasShort = EFalse;
   708             aReturn.Copy( retBuf );
   717                         if (! IsDefaultPowerKeyBehavior() && !iIgnoreNextPowerKeyRepeats )
   709             }
   718                             {
       
   719                             if ( !iGlobalListQuery )
       
   720                                 {
       
   721                                 HandleShortPowerKeyPressedL();
       
   722                                 }
       
   723                             }
       
   724                         else
       
   725                             {
       
   726                             HandleLongPowerKeyPressedL();
       
   727                             }
       
   728                         
       
   729                         }
       
   730                     break;
       
   731 
       
   732                 default:
       
   733                 	{
       
   734                 	TKeyResponse response = EKeyWasNotConsumed;
       
   735                 	if (iSysApKeyManagement)
       
   736                 		{
       
   737                 		response = iSysApKeyManagement->HandleKeyEventL(aKeyEvent, aType );
       
   738                 		}
       
   739 
       
   740                     if ( response == EKeyWasNotConsumed ) // none of the plugins consumed the key, offer it to default handling
       
   741                         {
       
   742                         iSysApDefaultKeyHandler->HandleKeyEventL( aKeyEvent, aType );
       
   743                         }
       
   744                 	}
       
   745                     break;
       
   746                 }
       
   747             }
       
   748         else if ( aType == EEventKeyUp )
       
   749             {
       
   750             TRACES( RDebug::Print( _L( "CSysApAppUi::HandleKeyEventL(): aType == EEventKeyUp, PowerKeyIsLockKey = %d, iLastPowerKeyWasShort = %d, iPowerKeyPopupMenuActive = %d, iCharging = %d" ), iSysApFeatureManager->PowerKeyIsLockKey(), iLastPowerKeyWasShort, iPowerKeyPopupMenuActive, iCharging ) );
       
   751             if ( !IsDefaultPowerKeyBehavior() && 
       
   752                  iLastPowerKeyWasShort && 
       
   753                  ( aKeyEvent.iScanCode == EStdKeyDevice2 ))
       
   754                 {
       
   755                 // if the power key is the lock key && the last keypress was 
       
   756                 // short && the power menu is not active && an alarm is not
       
   757                 // currently being shown, then lock the phone
       
   758                 TInt alarmState=0, securityQueryState=0;
       
   759          		TInt errorCode = RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsDisableKeyguard, alarmState );
       
   760 				TInt errorCode2 = RProperty::Get( KPSUidStartup, KStartupSecurityCodeQueryStatus, securityQueryState);
       
   761             	TRACES( RDebug::Print( _L( "CSysApAppUi::HandleKeyEventL(): Reading value of KCoreAppUIsDisableKeyguard - State Value: %d"),alarmState));
       
   762             	TRACES( RDebug::Print( _L( "CSysApAppUi::HandleKeyEventL(): Reading value of KStartupSecurityCodeQueryStatus - State Value: %d"),securityQueryState));
       
   763             	TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
   764 				//Disable keylock if Alarm is active or if a Security code query is active on the display
       
   765 				if ( alarmState == ECoreAppUIsDisableKeyguard || securityQueryState == ESecurityQueryActive )
       
   766                  	{
       
   767 					KeyLock().DisableWithoutNote();               	
       
   768                  	}
       
   769 			    else
       
   770          		 	{
       
   771                     if( callState != EPSCTsyCallStateConnected && !iDeviceLockEnabled)
       
   772                         {
       
   773                         KeyLock().EnableWithoutNote();
       
   774                         }
       
   775          			}
       
   776                 }
       
   777             else
       
   778                 {
       
   779                 if ( aKeyEvent.iScanCode == EStdKeyDevice2 )
       
   780                     {
       
   781                     if ( iIgnoreNextPowerKeyUpEvent )
       
   782                         {
       
   783                         if ( !iPowerKeyPopupMenuDismissed ) // If the popup menu has been dismissed, do nothing
       
   784                             {
       
   785                             iPowerKeyPopupMenuActive = ETrue;
       
   786                             iIgnoreNextPowerKeyUpEvent = EFalse;
       
   787                             }
       
   788                         }
       
   789                     else if ( iLastPowerKeyWasShort )
       
   790                         {
       
   791                         if ( iPowerKeyPopupMenuActive )
       
   792                             {
       
   793                             if ( iGlobalListQuery )
       
   794                                 {
       
   795                                 if ( iSysApFeatureManager->NoPowerKeySupported() )
       
   796                                     {
       
   797                                     CancelGlobalListQuery();
       
   798                                     }
       
   799                                 else
       
   800                                     {
       
   801                                     iGlobalListQuery->MoveSelectionDown();
       
   802                                     }
       
   803                                 }
       
   804                             }
       
   805                         }
       
   806                     }
       
   807                 }
       
   808             }
       
   809 
       
   810         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL:ended, aKeyEvent.iCode:%d, aKeyEvent.iScanCode:%d, aType:%d, iIgnoreNextPowerKeyUpEvent:%d, iPowerKeyPopupMenuActive:%d, iLastPowerKeyWasShort:%d, iPowerKeyPopupMenuDismissed:%d"),
       
   811                                aKeyEvent.iCode, aKeyEvent.iScanCode, aType, iIgnoreNextPowerKeyUpEvent, iPowerKeyPopupMenuActive, iLastPowerKeyWasShort, iPowerKeyPopupMenuDismissed ) );
       
   812         }
       
   813     else // shutdown started
       
   814         {
       
   815         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL: aKeyEvent.iCode:%d, aKeyEvent.iScanCode:%d, aType:%d"),
       
   816                                aKeyEvent.iCode, aKeyEvent.iScanCode, aType ) );
       
   817 
       
   818         // When shutdown has been started, only device mode key events are passed to plug-in framework
       
   819         // This for enabling plug-in activities during shutdown animation
       
   820         if ( IsDeviceModeKey( aKeyEvent ) ) // Other key events are not passed, because they must cancel the shutdown animation as stated in UI spefication
       
   821             {
       
   822             if ( aType == EEventKey && iSysApKeyManagement )
       
   823                 {
       
   824                 iSysApKeyManagement->HandleKeyEventL( aKeyEvent, aType );
       
   825                 }
       
   826             }
       
   827     #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   828         else if ( aType == EEventKey && iSysApShutdownAnimation && !iShutdownContinued )
       
   829             {
       
   830             if ( aKeyEvent.iCode != EKeyPowerOff || iLastPowerKeyWasShort )
       
   831                 {
       
   832                 iSysApShutdownAnimation->Cancel();
       
   833                 NotifyShutdownAnimationSkip();
       
   834                 }
       
   835             }
       
   836 
       
   837     #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
   838 
       
   839         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL: ended") ) );
       
   840         }
       
   841     return EKeyWasConsumed;
       
   842     }
       
   843 
       
   844 // ----------------------------------------------------------------------------
       
   845 // CSysApAppUi::HandleCommandL( TInt aCommand)
       
   846 // ----------------------------------------------------------------------------
       
   847 
       
   848 void CSysApAppUi::HandleCommandL( TInt aCommand )
       
   849     {
       
   850     TRACES( RDebug::Print( _L("CSysApAppUi::HandleCommandL aCommend: %d"), aCommand ) );
       
   851     switch ( aCommand )
       
   852         {
       
   853         case EEikCmdExit:   // EAknCmdExit
       
   854 	    // Quick fix for Defect: UTUL-7ZQLJU 
       
   855             Exit();
   710             break;
   856             break;
   711 
   857         default:
   712         case EGetKeylock: // get handle to keylock client session. Returns RAknKeylock2*.
       
   713             {
       
   714             // do nothing
       
   715             }
       
   716             break;
   858             break;
   717 
   859         }
       
   860     }
       
   861 
       
   862 // ----------------------------------------------------------------------------
       
   863 // CSysApAppUi::HandleApplicationSpecificEventL(TInt aType,const TWsEvent& aEvent)
       
   864 // ----------------------------------------------------------------------------
       
   865 
       
   866 void CSysApAppUi::HandleApplicationSpecificEventL(TInt aType,const TWsEvent& aEvent)
       
   867     {
       
   868     TRACES( RDebug::Print( _L("CSysApAppUi::HandleApplicationSpecificEventL: aType:%d"), aType ) );
       
   869 
       
   870     CAknAppUi::HandleApplicationSpecificEventL(aType, aEvent);
       
   871     
       
   872     if ( ResourcesFreed() )
       
   873         {
       
   874         TRACES( RDebug::Print( _L("CSysApAppUi::HandleApplicationSpecificEventL: discarded, shutting down") ) );
       
   875         return;
       
   876         }
       
   877     
       
   878     switch( aType )
       
   879         {
       
   880         case EEikKeyLockEnabled:
       
   881             iKeyLockEnabled = ETrue;
       
   882             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 1 );
       
   883             SetIndicatorStateL( EAknIndicatorKeyguard, EAknIndicatorStateOn );
       
   884             iSysApLightsController->KeylockStateChangedL( ETrue );
       
   885             break;
       
   886         case EEikKeyLockDisabled:
       
   887             iKeyLockEnabled = EFalse;
       
   888             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 0 );
       
   889             SetIndicatorStateL( EAknIndicatorKeyguard, EAknIndicatorStateOff );
       
   890             if (! iDeviceLockEnabled )
       
   891                 {
       
   892                 iSysApLightsController->KeylockStateChangedL( EFalse );
       
   893                 if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
   894                     {
       
   895                     if ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateRinging && StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateAlerting )
       
   896                         {
       
   897                         RunUnlockNotifierL();
       
   898                         }
       
   899                     }
       
   900                 }
       
   901             break;
       
   902         case EEikKeyLockPowerKeyPressed: //sent when power key is captured by keylockserver
       
   903             HandleShortPowerKeyPressedL();
       
   904             break;
       
   905 
       
   906         case EEikKeyLockLightsOnRequest:
       
   907             iSysApLightsController->SetLightsOnUnlockNoteL();
       
   908             break;
       
   909 
       
   910         case EEikEcsQueryLights: // emergency note is shown
       
   911             iSysApLightsController->SetLightsOnEcsQueryL();
       
   912             break;
       
   913 
       
   914         case EEikSecurityQueryLights: // for device lock security query
       
   915             iSysApLightsController->SetLightsOnSecurityQueryL();
       
   916             break;
   718 
   917 
   719         default:
   918         default:
   720             __ASSERT_DEBUG( EFalse, User::Panic( _L("CSysApAppUi::ExecQueryL: Invalid query"), KErrArgument ) );
       
   721             User::Leave( KErrArgument );
       
   722             break;
   919             break;
   723         }
   920             }
   724     }
   921     }
   725 
   922 
   726 // ----------------------------------------------------------------------------
   923 
   727 // CSysApAppUi::ExecCommandL
   924 // ----------------------------------------------------------------------------
   728 // ----------------------------------------------------------------------------
   925 // CSysApAppUi::InitializeStatusPaneAreaL()
   729 //
   926 // ----------------------------------------------------------------------------
   730 void CSysApAppUi::ExecCommandL( TSysapCommand aCommand )
   927 
   731     {
   928 void CSysApAppUi::InitializeStatusPaneAreaL()
   732     ExecCommandL( aCommand, KNullDesC8 );
   929     {
   733     }
   930     TRACES( RDebug::Print( _L("CSysApAppUi::InitializeStatusPaneAreaL(): START") ) );
   734 
   931     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
   735 // ----------------------------------------------------------------------------
   932 
   736 // CSysApAppUi::ExecCommandL
   933     //Also Charging status will be updated with the following function.
   737 // ----------------------------------------------------------------------------
   934     UpdateBatteryBarsL( state );
   738 //
   935 
   739 void CSysApAppUi::ExecCommandL( TSysapCommand aCommand, const TDesC8&  /* aParam */ )
   936 #ifdef SYSAP_USE_STARTUP_UI_PHASE
   740     {
   937     if ( OfflineModeActive() )
   741     TRACES( RDebug::Print(_L("CSysApAppUi::ExecCommandL: aCommand=%d"), aCommand ) );
   938         {
   742 
   939         UpdateSignalBarsL( KAknSignalOffLineMode );
   743     switch ( aCommand )
   940         }
   744         {
   941     else
   745         case EResetKeyguardState: // reset the internal keyguard flags of the SysAp, except for iKeyLockOnBeforeCradle
   942         {
   746             iKeyLockOnBeforeCall = EFalse;
   943         UpdateSignalBarsL();    
   747             iKeyLockOnBeforeAlarm = EFalse;
   944         }          
   748             break;
   945 #else
   749 
   946     UpdateSignalBarsL();
   750         default:
   947 #endif // SYSAP_USE_STARTUP_UI_PHASE
   751             // do nothing in release builds since no harm is done
       
   752             __ASSERT_DEBUG( EFalse, User::Panic( _L("CSysApAppUi::ExecCommandL: Invalid command"), KErrArgument ) );
       
   753             break;
       
   754         }
       
   755     }
       
   756     
   948     
   757 // ----------------------------------------------------------------------------
   949     SetSignalIndicatorL();
   758 // CSysApAppUi::TimerExpiredL()
   950     SetIhfIndicatorL();
   759 // ----------------------------------------------------------------------------
   951     SetHacIndicatorL();
   760 void CSysApAppUi::TimerExpiredL()
   952     LogsObserverL().HandleUiReadyL();
   761     {
   953 
   762 /*
   954     if ( iSysApEtelConnector )
   763  * Not suppported , will take care in wk25
   955         {
   764  * #ifndef RD_MULTIPLE_DRIVE 
   956         iSysApEtelConnector->ReadSimSmsStoreStatusInStartup();
   765  * CloseUIAppsInHotSwapL();
   957         }
   766  * #endif // RD_MULTIPLE_DRIVE
   958 
   767 */   
   959     SetEnvelopeIndicatorL();
   768    }
   960 
   769 
   961     TRACES( RDebug::Print( _L("CSysApAppUi::InitializeStatusPaneAreaL(): accessories") ) );
   770 
   962 
   771   // ----------------------------------------------------------------------------
   963     TAccMode accessoryState(EAccModeHandPortable);
   772 // CSysApAppUi::KeyLockState() const
   964     if ( iSysApAccessoryObserver )
   773 // ----------------------------------------------------------------------------
   965         {
   774 
   966         accessoryState = iSysApAccessoryObserver->GetAccessoryMode();
   775 TBool CSysApAppUi::KeyLockState() const
   967         }
   776     {
   968 
   777     return iKeyLockEnabled;
   969     if( accessoryState == EAccModeWiredHeadset ||
   778     }
   970         accessoryState == EAccModeWirelessHeadset ||
   779 
   971         accessoryState == EAccModeHeadphones )
   780 // ----------------------------------------------------------------------------
   972         {
   781 // CSysApAppUi::DeviceLockState() const
   973         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
   782 // ----------------------------------------------------------------------------
   974         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
   783 
   975         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOn );
   784 TBool CSysApAppUi::DeviceLockState() const
   976         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
   785     {
   977         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
   786     return iDeviceLockEnabled;
   978         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
   787     }
   979         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
   980         }
       
   981     else if( accessoryState == EAccModeLoopset )
       
   982         {
       
   983         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
   984         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
   985         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOn );
       
   986         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
   987         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
   988         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
   989         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
   990         }
       
   991     else if( accessoryState == EAccModeTextDevice )
       
   992         {
       
   993         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
   994         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
   995         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOn );
       
   996         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
   997         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
   998         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
   999         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  1000         }
       
  1001     else if( accessoryState == EAccModeWiredCarKit || accessoryState == EAccModeWirelessCarKit )
       
  1002         {
       
  1003         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  1004         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  1005         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  1006         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  1007         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOn );
       
  1008         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  1009         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  1010         }
       
  1011     else if( accessoryState == EAccModeTVOut )
       
  1012         {
       
  1013         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  1014         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  1015         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  1016         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  1017         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  1018         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOn );
       
  1019         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  1020         }
       
  1021     else if (accessoryState == EAccModeHDMI )
       
  1022         {
       
  1023         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  1024                 SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  1025                 SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  1026                 SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  1027                 SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  1028                 SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff);
       
  1029                 SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOn );
       
  1030         }
       
  1031     else // all indicators off
       
  1032         {
       
  1033         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  1034         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  1035         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  1036         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  1037         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  1038         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  1039         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  1040         }
       
  1041 
       
  1042     TRACES( RDebug::Print( _L("CSysApAppUi::InitializeStatusPaneAreaL(): msg") ) );
       
  1043     state = StateOfProperty( KUidSystemCategory, KUidOutboxStatusValue );
       
  1044     if( state == ESADocumentsInOutbox )
       
  1045         {
       
  1046         SetIndicatorStateL( EAknIndicatorOutbox, EAknIndicatorStateOn );
       
  1047         }
       
  1048     else
       
  1049         {
       
  1050         SetIndicatorStateL( EAknIndicatorOutbox, EAknIndicatorStateOff );
       
  1051         }
       
  1052 
       
  1053     state = StateOfProperty( KAlarmServerPubSubCategory, KWakeupAlarmPubSubKey );
   788     
  1054     
   789 // ----------------------------------------------------------------------------
  1055     if( state == EActiveWakeupAlarmSet )
   790 // CSysApAppUi::SysApFeatureManager
  1056         {
   791 // ----------------------------------------------------------------------------
  1057         TRACES( RDebug::Print(_L("CSysApAppUi::InitializeStatusPaneAreaL called the SetIndicatorStateL with EActiveWakeupAlarmSet ")));
   792 
  1058         SetIndicatorStateL( EAknIndicatorAlarmClock, EAknIndicatorStateOn );
   793 CSysApFeatureManager& CSysApAppUi::SysApFeatureManager()
       
   794     {
       
   795     __ASSERT_DEBUG( iSysApFeatureManager, User::Panic( _L("iSysApFeatureManager == NULL"), KErrBadHandle ) );
       
   796 
       
   797     return *iSysApFeatureManager;
       
   798     }
       
   799     
       
   800 // ----------------------------------------------------------------------------
       
   801 // CSysApAppUi::ActivateKeyeventForwardingForLights()
       
   802 // ----------------------------------------------------------------------------
       
   803 
       
   804 void CSysApAppUi::ActivateKeyeventForwardingForLights(TBool aActivate)
       
   805     {
       
   806     if( iSysApNspsHandler )
       
   807         {
       
   808         if ( aActivate )
       
   809             {
       
   810             iSysApNspsHandler->ActivateKeyeventForwardingForLights();
       
   811             }
       
   812         else
       
   813             {
       
   814             iSysApNspsHandler->DeActivateKeyeventForwardingForLights();
       
   815             }
       
   816         }
       
   817     }
       
   818 
       
   819 // ----------------------------------------------------------------------------
       
   820 // CSysApAppUi::StarterSession()
       
   821 // ----------------------------------------------------------------------------
       
   822 
       
   823 RStarterSession& CSysApAppUi::StarterSession()
       
   824     {
       
   825     if ( !iStarterSession.Handle() )
       
   826         {
       
   827         // All server connections are tried to be made KTriesToConnectServer times because occasional
       
   828         // fails on connections are possible at least on some servers
       
   829         TRACES( RDebug::Print( _L("CSysApAppUi::StarterSession: trying RStarterSession::Connect()") ) );
       
   830         TInt thisTry = 0;
       
   831         TInt err;
       
   832         while ( ( err = iStarterSession.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
       
   833             {
       
   834             User::After( KTimeBeforeRetryingServerConnection );
       
   835             }
       
   836 
       
   837         if ( err != KErrNone )
       
   838             {
       
   839             // What do in error case?
       
   840             TRACES( RDebug::Print( _L("CSysApAppUi::StarterSession: RStarterSession::Connect() failed with %d"), err ) );
       
   841             }
       
   842         }
       
   843 
       
   844     return iStarterSession;
       
   845     }
       
   846 
       
   847 // ----------------------------------------------------------------------------
       
   848 // CSysApAppUi::SetBtPowerState()
       
   849 // ----------------------------------------------------------------------------
       
   850 TInt CSysApAppUi::SetBtPowerState( TBool aBtState )
       
   851     {
       
   852     if ( iSysApBtController )
       
   853         {
       
   854         return iSysApBtController->SetPowerState( aBtState );
       
   855         }
  1059         }
   856     else
  1060     else
   857         {
  1061         {
   858         return KErrNotReady;
  1062         TRACES( RDebug::Print(_L("CSysApAppUi::InitializeStatusPaneAreaL called the SetIndicatorStateL with EActiveNoWakeupAlarmsSet ")));
   859         }
  1063         SetIndicatorStateL( EAknIndicatorAlarmClock, EAknIndicatorStateOff );
   860     }
  1064         }
   861 
  1065 
   862 // ----------------------------------------------------------------------------
  1066     state = StateOfProperty( KIrdaPropertyCategory, KIrdaStatus );
   863 // CSysApAppUi::SetStarterState()
  1067     if( state == TIrdaStatusCodes::EIrLoaded || state == TIrdaStatusCodes::EIrDisconnected || state == TIrdaStatusCodes::EIrBlocked )
   864 // ----------------------------------------------------------------------------
  1068         {
   865 
  1069         SetIndicatorStateL( EAknIndicatorIrActive, EAknIndicatorStateAnimate );
   866 TInt CSysApAppUi::SetStarterState( const RStarterSession::TGlobalState aState )
  1070         }
   867     {
  1071     else if( state == TIrdaStatusCodes::EIrConnected  )
   868     if ( iSysApStartupController->GlobalStateChangeAllowed( aState ) )
  1072         {
   869         {
  1073         SetIndicatorStateL( EAknIndicatorIrActive, EAknIndicatorStateOn );
   870         TRACES( RDebug::Print( _L("CSysApAppUi::SetStarterState: aState=%d" ), aState ) );
       
   871         return StarterSession().SetState( aState );
       
   872         }
  1074         }
   873     else
  1075     else
   874         {
  1076         {
   875         TRACES( RDebug::Print( _L("CSysApAppUi::SetStarterState: aState=%d - not allowed" ), aState ) );
  1077         SetIndicatorStateL( EAknIndicatorIrActive, EAknIndicatorStateOff );
   876         return KErrNone;
  1078         }
   877         }
  1079 
   878     }
  1080     iSysApCenRepCallForwardingObserver->UpdateCallForwardingIndicatorsL();
   879 
  1081 
   880 // ----------------------------------------------------------------------------
  1082     iSysApCenRepMsgWaitingObserver->UpdateMessageWaitingIndicatorsL();
   881 // CSysApAppUi::SetNetworkConnectionAllowed()
  1083 
   882 // ----------------------------------------------------------------------------
  1084     state = StateOfProperty( KPSUidNetworkInfo, KNWHomeZoneStatus );
   883 
  1085     if( state == ENWNone || state == ENWCityZone )
   884 void CSysApAppUi::SetNetworkConnectionAllowed( TCoreAppUIsNetworkConnectionAllowed aNetworkConnectionAllowed )
  1086         {
   885     {
  1087         SetIndicatorStateL( EAknIndicatorHomeZone, EAknIndicatorStateOff );
   886     TRACES( RDebug::Print( _L("CSysApAppUi::SetNetworkConnectionAllowed: status: %d" ), aNetworkConnectionAllowed ) );
  1088         }
   887 
  1089     else if( state == ENWHomeZone )
   888     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIs, KCoreAppUIsNetworkConnectionAllowed, (TInt) aNetworkConnectionAllowed );
  1090         {
   889 
  1091         SetIndicatorStateL( EAknIndicatorHomeZone, EAknIndicatorStateOn );
   890     // Also set the Symbian PS key used for the same purpose:
  1092         }
   891     RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, aNetworkConnectionAllowed ? ESAPhoneOn : ESAPhoneOff);
  1093 
   892     }
  1094     // Initialize WLan state
   893 
  1095     state = StateOfProperty( KPSUidWlan, KPSWlanIndicator );
   894 // ----------------------------------------------------------------------------
  1096     HandleWlanIndicatorL(state);
   895 // CSysApAppUi::BluetoothPowerMode()
  1097 
   896 // ----------------------------------------------------------------------------
  1098     // Initialize Tarm state
   897 TInt CSysApAppUi::BluetoothPowerMode() const
  1099     state = StateOfProperty( KPSUidCoreApplicationUIs, KCoreAppUIsTarmIndicator );
   898     {
  1100     HandleTarmIndicatorL(state);
   899     return iSysApCenRepBtObserver->BluetoothPowerMode();
  1101 
   900     }
  1102     TRACES( RDebug::Print( _L("CSysApAppUi::InitializeStatusPaneAreaL(): END") ) );
   901 
  1103     }
   902 // ----------------------------------------------------------------------------
  1104 
   903 // CSysApAppUi::SimSupported()
  1105 // ----------------------------------------------------------------------------
   904 // ----------------------------------------------------------------------------
  1106 // CSysApAppUi::HandleWlanIndicator()
   905 TBool CSysApAppUi::SimSupported()
  1107 // ----------------------------------------------------------------------------
   906     {
  1108 void CSysApAppUi::HandleWlanIndicatorL( TInt aValue )
   907     return iSysApFeatureManager->SimSupported();
  1109     {
   908     }
  1110     if ( aValue == EPSWlanIndicatorAvailable )
   909 
  1111         {
   910 // ----------------------------------------------------------------------------
  1112         SetIndicatorStateL( EAknIndicatorWlanActive,       EAknIndicatorStateOff );
   911 // CSysApAppUi::BtSapEnabled()
  1113         SetIndicatorStateL( EAknIndicatorWlanActiveSecure, EAknIndicatorStateOff );
   912 // ----------------------------------------------------------------------------
  1114         SetIndicatorStateL( EAknIndicatorWlanAvailable,    EAknIndicatorStateOn  );
   913 
  1115         }
   914 TBool CSysApAppUi::BtSapEnabled()
  1116     else if ( aValue == EPSWlanIndicatorActive )
   915     {
  1117         {
   916     if ( iSysApBtSapController )
  1118         SetIndicatorStateL( EAknIndicatorWlanAvailable,    EAknIndicatorStateOff );
   917         {
  1119         SetIndicatorStateL( EAknIndicatorWlanActiveSecure, EAknIndicatorStateOff );
   918         return iSysApBtSapController->BtSapEnabled();    
  1120         SetIndicatorStateL( EAknIndicatorWlanActive,       EAknIndicatorStateOn  );
   919         }  
  1121         }
   920     return EFalse;
  1122     else if ( aValue == EPSWlanIndicatorActiveSecure )
   921     }
  1123         {
   922 
  1124         SetIndicatorStateL( EAknIndicatorWlanAvailable,    EAknIndicatorStateOff );
   923 
  1125         SetIndicatorStateL( EAknIndicatorWlanActive,       EAknIndicatorStateOff );
   924 // ----------------------------------------------------------------------------
  1126         SetIndicatorStateL( EAknIndicatorWlanActiveSecure, EAknIndicatorStateOn  );
   925 // CSysApAppUi::OfflineModeChangedL()
  1127         }
   926 // ----------------------------------------------------------------------------
  1128     else // No indication required
   927 void CSysApAppUi::OfflineModeChangedL()
  1129         {
   928     {
  1130         SetIndicatorStateL( EAknIndicatorWlanAvailable,    EAknIndicatorStateOff );
   929 #ifdef SYSAP_USE_STARTUP_UI_PHASE    
  1131         SetIndicatorStateL( EAknIndicatorWlanActive,       EAknIndicatorStateOff );
   930     // if UI is not ready, don't update indicators
  1132         SetIndicatorStateL( EAknIndicatorWlanActiveSecure, EAknIndicatorStateOff );
   931     if ( !UiReady() )
  1133         }
   932         {
  1134     }
   933         return;
  1135 
   934         }
  1136 // ----------------------------------------------------------------------------
   935 #endif // SYSAP_USE_STARTUP_UI_PHASE
  1137 // CSysApAppUi::HandleTarmIndicatorL()
   936 
  1138 // ----------------------------------------------------------------------------
   937 #if 0 // Not used as of now
  1139 
   938     SetHacIndicatorL();
  1140 void CSysApAppUi::HandleTarmIndicatorL( TInt aValue )
   939 #endif //0	
  1141     {
   940     }
  1142     if ( aValue == ECoreAppUIsTarmTerminalSecurityOnIndicatorOn )
   941 
  1143         {
   942 // ----------------------------------------------------------------------------
  1144         SetIndicatorStateL( EAknIndicatorTARM, EAknIndicatorStateOff );
   943 // CSysApAppUi::UiReady()
  1145         SetIndicatorStateL( EAknIndicatorTARMModuleOn, EAknIndicatorStateOn );
   944 // 
  1146         }
   945 // ----------------------------------------------------------------------------
  1147     else if ( aValue == ECoreAppUIsTarmMngActiveIndicatorOn )
   946 
  1148         {
   947 TBool CSysApAppUi::UiReady() const
  1149         SetIndicatorStateL( EAknIndicatorTARMModuleOn, EAknIndicatorStateOff );
   948     {
  1150         SetIndicatorStateL( EAknIndicatorTARM, EAknIndicatorStateOn );
   949 #ifdef SYSAP_USE_STARTUP_UI_PHASE    
       
   950     return iSysApStartupController->UiReady(); 
       
   951 #else // SYSAP_USE_STARTUP_UI_PHASE
       
   952     // if startup UI phase information is not used, global system state normal is handled as UI idle state
       
   953     return IsStateNormal();
       
   954 #endif // SYSAP_USE_STARTUP_UI_PHASE        
       
   955     }
       
   956 
       
   957 
       
   958 // ----------------------------------------------------------------------------
       
   959 // CSysApAppUi::CompleteShutdown()
       
   960 // ----------------------------------------------------------------------------
       
   961 
       
   962 void CSysApAppUi::CompleteShutdown( const TBool aReset, const TInt aResetReason )
       
   963     {
       
   964     TRACES( RDebug::Print(_L("CSysApAppUi::CompleteShutdown(): START" ) ) );
       
   965     
       
   966     iCheckLongPowerKeyEvent = ETrue;
       
   967 
       
   968     PrepareForShutdownImage();//SysAp's internal preparation for ShutDown with image
       
   969 
       
   970     FreeResources();
       
   971 
       
   972     if ( aReset )
       
   973         {
       
   974         __ASSERT_DEBUG( aResetReason >= RStarterSession::ELanguageSwitchReset &&
       
   975                         aResetReason <= RStarterSession::EDataRestoreReset,
       
   976                         User::Invariant() );
       
   977         StarterSession().Reset( static_cast<RStarterSession::TResetReason>( aResetReason ) );
       
   978         }
  1151         }
   979     else
  1152     else
   980         {
  1153         {
   981         StarterSession().Shutdown();
  1154         SetIndicatorStateL( EAknIndicatorTARM, EAknIndicatorStateOff );
   982         }
  1155         SetIndicatorStateL( EAknIndicatorTARMModuleOn, EAknIndicatorStateOff );
   983 
  1156         }
   984     StarterSession().Close();
  1157     }
   985 
  1158 
   986     TRACES( RDebug::Print(_L("CSysApAppUi::CompleteShutdown(): END" ) ) );
  1159 // ----------------------------------------------------------------------------
   987     }
  1160 // CSysApAppUi::HandleShortPowerKeyPressedL()
   988 
  1161 // ----------------------------------------------------------------------------
   989 
  1162 
   990 
  1163 void CSysApAppUi::HandleShortPowerKeyPressedL()
   991 // ----------------------------------------------------------------------------
  1164     {
   992 // CSysApAppUi::DoShutdownL( const TBool aReset, const TSWStartupReason aSWStartupReason )
  1165     TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
   993 // ----------------------------------------------------------------------------
  1166 
   994 
  1167     TRACES (
   995 void CSysApAppUi::DoShutdownL( const TBool aReset, const TInt aResetReason )
  1168         RDebug::Print(
   996     {
  1169         _L("CSysApAppUi::HandleShortPowerKeyPressedL() callState:%d, iDeviceLockEnabled:%d" ),
   997     TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: aResetReason:%d, aReset:%d" ),
  1170         callState,
   998         aResetReason, aReset ) );
  1171         iDeviceLockEnabled );
   999 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
  1172     );
  1000     TBool animationenabled( EFalse );
  1173     iSysApLightsController->PowerKeyPressedL();
  1001 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
  1174 
  1002 
  1175     RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsHideAlarm, ECoreAppUIsHideAlarm );
  1003     if( OkToInitiateShutdown() )
  1176 
  1004         {
  1177 
  1005         TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: Was OkToToInitiateShutdown" ) ) );
  1178     if( UiReady() && !iDeviceLockEnabled )
  1006 
  1179         {
  1007 
  1180         if ( iPowerKeyPopupMenuActive )
  1008         if ( !aReset && iSysApFeatureManager->Supported(KSysApFeatureIdGoodbyeNote) )
  1181             {
  1009             {
  1182             //Do nothing here. EEventKeyUp moves selection in the list!
  1010             // show shutdown note
  1183             }
  1011             }
  1184         else if ( !iKeyLockEnabled
  1012 
  1185             && callState != EPSCTsyCallStateAlerting
  1013         if( !aReset )
  1186             && callState != EPSCTsyCallStateRinging
  1014             {
  1187             && callState != EPSCTsyCallStateDialling )
  1015     #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
  1188             //Show power key menu
  1016             TRAPD( err, ShowAnimationL() );
  1189             {
  1017             if ( err )
  1190             ShowPowerKeyPopUpMenuL();
  1018                 {
  1191             }
  1019                 TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL ShowAnimationL() leaved: %d" ), err ) );
  1192         }
  1020                 CompleteShutdown(aReset, aResetReason);
  1193     else 
  1021                 }
  1194         {
  1022             }
  1195         TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
  1023         else // aReset
  1196         
  1024            {
  1197         if( swState == ESwStateAlarm )
  1025             CompleteShutdown(aReset, aResetReason);
  1198             //From Alarm state even a short press causes shutdown but charger state need to be checked
  1026             }
  1199             {
  1027     #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
  1200             TInt chargerState( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
  1028             TRAPD( err, animationenabled = ShowAnimationL() );
  1201             if( chargerState == EChargingStatusNotConnected )
  1029             if ( err )
  1202                 //shutdown
  1030                 {
  1203                 {
  1031                 TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL ShowAnimationL() leaved: %d" ), err ) );
  1204                 StartShutDownTimerOnAlarmAndChargingStates();
  1032                 }
       
  1033             }
       
  1034 
       
  1035         if ( !animationenabled )
       
  1036             {
       
  1037             CompleteShutdown(aReset, aResetReason);
       
  1038             }
       
  1039     #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  1040         }
       
  1041     else
       
  1042         {
       
  1043         TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: Was not OkToToInitiateShutdown" ) ) );
       
  1044         }
       
  1045     TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: END" ) ) );
       
  1046     }
       
  1047 
       
  1048 
       
  1049 
       
  1050 /* 
       
  1051 ----------------------------------------------------------------------------
       
  1052 CSysApAppUi::IsEncryptionOperationOngoingL()
       
  1053 Introduced the code as a part of Sub : 405-3362 - Power Management SUB for ES 
       
  1054 recapture functionalities in platform which support multidrive as well. 
       
  1055 -------------------------------------------------------------------------------
       
  1056 */
       
  1057 TBool CSysApAppUi::IsEncryptionOperationOngoingL() const
       
  1058     {
       
  1059         TBool deFeatureSupported(EFalse);
       
  1060         FeatureManager::InitializeLibL();
       
  1061         deFeatureSupported = FeatureManager::FeatureSupported( KFeatureIdFfDeviceEncryptionFeature);
       
  1062         FeatureManager::UnInitializeLib();
       
  1063 
       
  1064         if(deFeatureSupported)
       
  1065             {         
       
  1066             /**
       
  1067              * Store the last memory status changed
       
  1068              * 0: Idle. It can be Encrypted or Decrypted
       
  1069              * 1: Encrypting
       
  1070              * 2: Decrypting
       
  1071              **/
       
  1072              
       
  1073             RProperty deProperty;
       
  1074             User::LeaveIfError(deProperty.Attach(KDevEncProtectedUid, KDevEncOperationKey,EOwnerThread));
       
  1075             TInt deValue = 0;
       
  1076             if((deProperty.Get(deValue)== KErrNone)&&( deValue == EOpEncrypting || deValue == EOpDecrypting))
       
  1077                 {
       
  1078                 deProperty.Close();
       
  1079                 return ETrue;
       
  1080                 }
  1205                 }
  1081             else
  1206             else
  1082                 {
  1207                 //to charging state
  1083                 deProperty.Close();
  1208                 {
  1084                 return EFalse;
  1209                 SetStarterState( RStarterSession::ECharging );
  1085                 }
  1210                 }
  1086             }
  1211             }
  1087         else
  1212         }
  1088             {
       
  1089             return EFalse;
       
  1090             }
       
  1091     }
  1213     }
  1092 
  1214 
  1093 // ----------------------------------------------------------------------------
  1215 // ----------------------------------------------------------------------------
  1094 // CSysApAppUi::HandleLongPowerKeyPressedL()
  1216 // CSysApAppUi::HandleLongPowerKeyPressedL()
  1095 // ----------------------------------------------------------------------------
  1217 // ----------------------------------------------------------------------------
  1098     {
  1220     {
  1099     TRACES( RDebug::Print( _L("CSysApAppUi::HandleLongPowerKeyPressedL()") ) );
  1221     TRACES( RDebug::Print( _L("CSysApAppUi::HandleLongPowerKeyPressedL()") ) );
  1100 
  1222 
  1101     TInt swState;
  1223     TInt swState;
  1102     RProperty::Get( KPSUidStartup, KPSGlobalSystemState, swState );
  1224     RProperty::Get( KPSUidStartup, KPSGlobalSystemState, swState );
  1103     
  1225 
  1104     iSysApLightsController->PowerKeyPressedL();  //need to handle later.
  1226     iSysApLightsController->PowerKeyPressedL();
  1105 
  1227 
  1106     if( swState == ESwStateStartingCriticalApps ||
  1228     if( swState == ESwStateStartingCriticalApps ||
  1107         swState == ESwStateSelfTestOK ||
  1229         swState == ESwStateSelfTestOK ||
  1108         swState == ESwStateSecurityCheck ||
  1230         swState == ESwStateSecurityCheck ||
  1109         swState == ESwStateCriticalPhaseOK ||
  1231         swState == ESwStateCriticalPhaseOK ||
  1115         {
  1237         {
  1116         if( !iDeviceLockEnabled )
  1238         if( !iDeviceLockEnabled )
  1117             {
  1239             {
  1118             if( iPowerKeyPopupMenuActive )
  1240             if( iPowerKeyPopupMenuActive )
  1119                 {
  1241                 {
  1120                 // do nothing
  1242                 if ( iGlobalListQuery )
       
  1243                     {
       
  1244                     iGlobalListQuery->SelectItem();
       
  1245                     }
  1121                 }
  1246                 }
  1122             else if( !iIgnoreNextPowerKeyRepeats )
  1247             else if( !iIgnoreNextPowerKeyRepeats )
  1123                 {
  1248                 {
  1124                 if( !iKeyLockEnabled && !IsEncryptionOperationOngoingL() )
  1249                 if( !iKeyLockEnabled && !IsEncryptionOperationOngoingL() )
  1125                     {
  1250                     {
  1145             }
  1270             }
  1146         }
  1271         }
  1147     }
  1272     }
  1148 
  1273 
  1149 // ----------------------------------------------------------------------------
  1274 // ----------------------------------------------------------------------------
  1150 // CSysApAppUi::IsDeviceModeKey
  1275 // CSysApAppUi::FreeResources()
  1151 // ----------------------------------------------------------------------------
  1276 // ----------------------------------------------------------------------------
  1152 
  1277 
  1153 TBool CSysApAppUi::IsDeviceModeKey( const TKeyEvent& aKeyEvent ) const
  1278 void CSysApAppUi::FreeResources()
  1154     {
  1279     {
  1155     return CSysApDefaultKeyHandler::IsDeviceModeKey( aKeyEvent );
  1280     TRACES( RDebug::Print( _L("CSysApAppUi::FreeResources") ) );
  1156     }
  1281 
  1157 
  1282     delete iSysApBatteryInfoController;
  1158 
  1283     delete iSysApPsmController;
  1159 // ----------------------------------------------------------------------------
  1284 
  1160 // CSysApAppUi::ShowShutdownImage
  1285     delete iSysApAudioRoutingObserver;
       
  1286 
       
  1287     delete iProfileNamesArray;
       
  1288     iProfileNamesArray = NULL;
       
  1289 
       
  1290     if ( iTimer )
       
  1291         {
       
  1292         iTimer->Cancel();
       
  1293         delete iTimer;
       
  1294         }
       
  1295 
       
  1296     if ( iSapTimer )
       
  1297         {
       
  1298         iSapTimer->Cancel();
       
  1299         delete iSapTimer;
       
  1300         }
       
  1301 
       
  1302     if ( iSysApTimer )
       
  1303         {
       
  1304         iSysApTimer->Cancel();
       
  1305         delete iSysApTimer;
       
  1306         }
       
  1307 
       
  1308     delete iGlobalListQuery;
       
  1309 
       
  1310     RWindowGroup groupWin = iCoeEnv->RootWin();
       
  1311     groupWin.CancelCaptureKey( iCapturedEKeyPowerOff );
       
  1312     groupWin.CancelCaptureKeyUpAndDowns( iCapturedEKeyPowerOffUpAndDowns );
       
  1313 
       
  1314     delete iSysApDefaultKeyHandler;
       
  1315 
       
  1316     if ( iProfileEngine )
       
  1317         {
       
  1318         iProfileEngine->Release();
       
  1319         }
       
  1320 
       
  1321     delete iSysApSsSettingsObserver;
       
  1322     delete iSysApEtelConnector;
       
  1323 
       
  1324     delete iSysApProfileObserver;
       
  1325     delete iSysApNspsHandler;
       
  1326     delete iSysApKeySndHandler;
       
  1327     delete iSysApCenRepMsgWaitingObserver;
       
  1328     delete iSysApCenRepCallForwardingObserver;
       
  1329     delete iSysApConnectionMonitorObserver;
       
  1330     delete iSysApCenRepLightSettingsObserver;
       
  1331     delete iSysApCenRepLogsObserver;
       
  1332     delete iSysApCenRepBtObserver;
       
  1333     delete iSysApCenRepFmTxObserver;
       
  1334     delete iSysApCenRepHacSettingObserver;
       
  1335     delete iSysApCenRepController;
       
  1336 
       
  1337     delete iSysApPubSubObserver;
       
  1338 
       
  1339     delete iSysApMMCObserver;
       
  1340     delete iSysApMsgSimMemLowQuery;
       
  1341     delete iSysApWaitNote;
       
  1342     delete iSysApConfirmationQuery;
       
  1343     delete iSysApConfirmationQueryForRestart;
       
  1344     delete iSysApOfflineModeController;
       
  1345     delete iSysApUsbIndicatorController;
       
  1346     delete iSysApBtController;
       
  1347     delete iSysApBtSapController;
       
  1348     delete iSignalNotify;
       
  1349     delete iBatteryNotify;
       
  1350     delete iSysApSystemLock;
       
  1351     delete iSysApLocationPrivacyIndicator;
       
  1352     delete iSysApAccessoryObserver;
       
  1353     delete iSysApMediatorObserver;
       
  1354 
       
  1355     delete iSysApKeyManagement;
       
  1356     iSysApKeyManagement = NULL;
       
  1357     delete iSysApLightsController;
       
  1358     iKeyLock.Close();
       
  1359     delete iSysApFeatureManager;
       
  1360 
       
  1361     // Cleanup ECom, used by key management and light control
       
  1362     REComSession::FinalClose();
       
  1363 
       
  1364     iResourcesFreed = ETrue;
       
  1365     TRACES( RDebug::Print( _L("CSysApAppUi::FreeResources:END") ) );
       
  1366     }
       
  1367 
       
  1368 // ----------------------------------------------------------------------------
       
  1369 // CSysApAppUi::ShowUiNoteL( const TSysApNoteIds aNote ) const
       
  1370 // ----------------------------------------------------------------------------
       
  1371 
       
  1372 void CSysApAppUi::ShowUiNoteL( const TSysApNoteIds aNote ) const
       
  1373     {
       
  1374     TRACES( RDebug::Print( _L("CSysApAppUi::ShowUiNoteL aNote: %d"), aNote ) );
       
  1375     TInt tone( EAvkonSIDNoSound );
       
  1376     TAknGlobalNoteType noteType( EAknGlobalBatteryLowNote );
       
  1377     CAknGlobalNote* note = CAknGlobalNote::NewLC();
       
  1378     TInt secondaryDisplayId(SecondaryDisplay::ECmdNoNote);
       
  1379 
       
  1380     switch ( aNote )
       
  1381         {
       
  1382         case EBatteryLowNote:
       
  1383             noteType = EAknGlobalBatteryLowNote;
       
  1384             tone = EAvkonSIDBatteryLowTone;
       
  1385             break;
       
  1386         case EBatteryFullNote:
       
  1387             noteType = EAknGlobalBatteryFullNote;
       
  1388             tone = EAvkonSIDInformationTone;
       
  1389             break;
       
  1390         case ERechargeBatteryNote:
       
  1391             iSysApLightsController->BatteryEmptyL( ETrue );
       
  1392             noteType = EAknGlobalRechargeBatteryNote;
       
  1393             tone = EAvkonSIDRechargeBatteryTone;
       
  1394             break;
       
  1395         case ENotChargingNote:
       
  1396             noteType = EAknGlobalNotChargingNote;
       
  1397             tone = EAvkonSIDWrongCharger;
       
  1398             break;
       
  1399         case EInsertSimNote:
       
  1400             noteType = EAknGlobalInformationNote;
       
  1401             tone = EAvkonSIDInformationTone;
       
  1402             secondaryDisplayId = SecondaryDisplay::ECmdShowInsertSimNote;
       
  1403             break;
       
  1404         case EMemoryCardRemovedWithoutEjectNote:
       
  1405             noteType = EAknGlobalInformationNote;
       
  1406             tone = EAvkonSIDInformationTone;
       
  1407             secondaryDisplayId = SecondaryDisplay::ECmdShowMemoryCardRemovedWithoutEjectNote;
       
  1408             break;
       
  1409         case EGprsSuspendedNote:
       
  1410             noteType = EAknGlobalInformationNote;
       
  1411             tone = EAvkonSIDInformationTone;
       
  1412             secondaryDisplayId = SecondaryDisplay::ECmdShowGprsSuspendedNote;
       
  1413             break;
       
  1414         case EGprsResumedNote:
       
  1415             noteType = EAknGlobalInformationNote;
       
  1416             tone = EAvkonSIDInformationTone;
       
  1417             secondaryDisplayId = SecondaryDisplay::ECmdShowGprsResumedNote;
       
  1418             break;
       
  1419         case EShutdownNote:
       
  1420             noteType = EAknGlobalInformationNote;
       
  1421             tone = EAvkonSIDInformationTone;
       
  1422             secondaryDisplayId = SecondaryDisplay::ECmdShowShutdownNote;
       
  1423             break;
       
  1424         case ECannotActivateOfflineModeNote:
       
  1425             noteType = EAknGlobalErrorNote;
       
  1426             tone = EAvkonSIDErrorTone;
       
  1427             secondaryDisplayId = SecondaryDisplay::ECmdShowCannotActivateOfflineModeNote;
       
  1428             break;
       
  1429         case ECannotDeactivateOfflineModeNote:
       
  1430             noteType = EAknGlobalErrorNote;
       
  1431             tone = EAvkonSIDErrorTone;
       
  1432             secondaryDisplayId = SecondaryDisplay::ECmdShowCannotDeactivateOfflineModeNote;
       
  1433             break;
       
  1434         case EKeypadActiveNote:
       
  1435             noteType = EAknGlobalInformationNote;
       
  1436             tone = EAvkonSIDInformationTone;
       
  1437             secondaryDisplayId = SecondaryDisplay::ECmdShowKeypadActiveNote;
       
  1438             break;
       
  1439         case EFmTxAccessoryStandbyNote:
       
  1440             noteType = EAknGlobalInformationNote; 
       
  1441             tone = EAvkonSIDInformationTone;
       
  1442             secondaryDisplayId = SecondaryDisplay::ECmdShowFmTxStandbyInAccessoryConnectionNote;
       
  1443             break;
       
  1444         case EFmTxAccessoryForbidsNote:
       
  1445             noteType = EAknGlobalInformationNote; 
       
  1446             tone = EAvkonSIDInformationTone;
       
  1447             secondaryDisplayId = SecondaryDisplay::ECmdShowFmTxCannotEnableWhileAccessoryConnectedNote;
       
  1448             break;
       
  1449         case EFmTxVolumeDisabledNote:
       
  1450             noteType = EAknGlobalInformationNote; 
       
  1451             tone = EAvkonSIDInformationTone;
       
  1452             secondaryDisplayId = SecondaryDisplay::ECmdShowFmTxVolumeDisabledNote;
       
  1453             break;
       
  1454         case EFmTxOnNote:
       
  1455             noteType = EAknGlobalInformationNote; 
       
  1456             tone = EAvkonSIDInformationTone;
       
  1457             secondaryDisplayId = SecondaryDisplay::ECmdShowFmTxTuneRadioToFrequencyNote;
       
  1458             break;
       
  1459         case EFmTxOffNote:
       
  1460             noteType = EAknGlobalInformationNote; 
       
  1461             tone = EAvkonSIDInformationTone;
       
  1462             secondaryDisplayId = SecondaryDisplay::ECmdShowFmTxDisabledNote;
       
  1463             break;
       
  1464         case EBatteryFullUnplugChargerNote:
       
  1465             noteType = EAknGlobalBatteryFullUnplugNote;
       
  1466             tone = EAvkonSIDInformationTone;
       
  1467             break;
       
  1468         case EUnplugChargerNote:
       
  1469             noteType = EAknGlobalUnplugChargerNote;
       
  1470             tone = EAvkonSIDInformationTone;
       
  1471             break;
       
  1472         case EPowerSaveModeActivated:
       
  1473         		noteType = EAknGlobalConfirmationNote;
       
  1474             tone = EAvkonSIDConfirmationTone;
       
  1475             secondaryDisplayId = SecondaryDisplay::ECmdShowPowerSavingActivatedNote;
       
  1476             break;
       
  1477         case EPowerSaveModeDeactivated:
       
  1478             noteType = EAknGlobalConfirmationNote;
       
  1479             tone = EAvkonSIDConfirmationTone;
       
  1480             secondaryDisplayId = SecondaryDisplay::ECmdShowPowerSavingDeactivatedNote;
       
  1481             break;
       
  1482         case ECannotActivatePowerSaveMode:
       
  1483             noteType = EAknGlobalWarningNote;
       
  1484             tone = EAvkonSIDWarningTone;
       
  1485             secondaryDisplayId = SecondaryDisplay::ECmdShowCannotActivatePowerSavingNote;
       
  1486             break;
       
  1487         case ECannotDeactivatePowerSaveMode:
       
  1488             noteType = EAknGlobalWarningNote;
       
  1489             tone = EAvkonSIDWarningTone;
       
  1490             secondaryDisplayId = SecondaryDisplay::ECmdShowCannotDeactivatePowerSavingNote;
       
  1491             break;
       
  1492         default:
       
  1493             break;
       
  1494 
       
  1495         }
       
  1496 
       
  1497     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  1498 
       
  1499     if( UiReady() || swState == ESwStateSecurityCheck)
       
  1500         {
       
  1501         HBufC* noteStringBuf = NULL;
       
  1502 
       
  1503         switch ( aNote )
       
  1504             {
       
  1505             case EInsertSimNote:
       
  1506                 noteStringBuf = StringLoader::LoadLC( R_QTN_SU_NOTE_INSERT_SIM, iEikonEnv );
       
  1507                 break;
       
  1508             case EMemoryCardRemovedWithoutEjectNote:
       
  1509                 noteStringBuf = StringLoader::LoadLC( R_QTN_MEMS_EJECT_ERROR, iEikonEnv );
       
  1510                 note->SetSoftkeys( R_AVKON_SOFTKEYS_OK_EMPTY );
       
  1511                 break;
       
  1512             case EGprsSuspendedNote:
       
  1513                 noteStringBuf = StringLoader::LoadLC( R_QTN_GPRS_CONF_GPRS_SUSPENDED, iEikonEnv );
       
  1514                 break;
       
  1515             case EGprsResumedNote:
       
  1516                 noteStringBuf = StringLoader::LoadLC( R_QTN_GPRS_CONF_GPRS_RESUMED, iEikonEnv );
       
  1517                 break;
       
  1518             case EShutdownNote:
       
  1519                 noteStringBuf = StringLoader::LoadLC( R_QTN_PWRC_INFO_GOODBYE, iEikonEnv);
       
  1520                 break;
       
  1521             case ECannotActivateOfflineModeNote:
       
  1522                 noteStringBuf = StringLoader::LoadLC( R_QTN_ERR_OFFLINE_UNABLE, iEikonEnv );
       
  1523                 break;
       
  1524             case ECannotDeactivateOfflineModeNote:
       
  1525                 noteStringBuf = StringLoader::LoadLC( R_QTN_ERR_OFFLINE_UNABLE_PROFILE, iEikonEnv );
       
  1526                 break;
       
  1527             case EKeypadActiveNote:
       
  1528                 if ( iSysApFeatureManager->PenEnabled() )
       
  1529                     {
       
  1530                     noteStringBuf = StringLoader::LoadLC( R_QTN_KEYG_CONF_DISPLAY_KEYS_ACTIVE,
       
  1531                                                           iEikonEnv );
       
  1532                     }
       
  1533                 else
       
  1534                     {
       
  1535                     noteStringBuf = StringLoader::LoadLC( R_QTN_KEYG_CONF_KEYPAD_ACTIVE,
       
  1536                                                           iEikonEnv );
       
  1537                     }
       
  1538                 note->SetAnimation( R_QGN_NOTE_KEYGUARD_OPEN_ANIM );
       
  1539                 break;
       
  1540             case EFmTxOnNote:
       
  1541                 {
       
  1542                 const TInt KFrequencyMaxLength(7);
       
  1543                 // read frequency
       
  1544                 TInt frequencykHz = iSysApCenRepFmTxObserver->Frequency();
       
  1545                 TReal frequencyMHz = static_cast<TReal>( frequencykHz ) / KCoefficientKhzToMhz; // kHz to Mhz
       
  1546                 TBuf<KFrequencyMaxLength> frequencyAsString;
       
  1547                 frequencyAsString.AppendNum( frequencyMHz, TRealFormat( KFrequencyMaxLength, KDecimalsInMhzFrequency ) );
       
  1548                 AknTextUtils::LanguageSpecificNumberConversion( frequencyAsString );
       
  1549                 noteStringBuf 
       
  1550                       = StringLoader::LoadLC( R_QTN_FMTX_SYSAP_INFO_NOTE_CHANGE_FREQ, 
       
  1551                                               frequencyAsString,
       
  1552                                               iEikonEnv );
       
  1553                 break;
       
  1554                 }
       
  1555             case EFmTxAccessoryForbidsNote:
       
  1556                 {
       
  1557                 noteStringBuf = StringLoader::LoadLC( R_QTN_FMTX_SYSAP_INFO_NOTE_ACCESSORY_FORBIDS, 
       
  1558                                                        iEikonEnv );
       
  1559                 break;
       
  1560                 }
       
  1561             case EFmTxAccessoryStandbyNote:
       
  1562                 {                                     
       
  1563                 noteStringBuf = StringLoader::LoadLC( R_QTN_FMTX_SYSAP_INFO_NOTE_ACCESSORY_STANDBY, 
       
  1564                                                        iEikonEnv );
       
  1565                 break;
       
  1566                 }
       
  1567             case EFmTxVolumeDisabledNote:
       
  1568                 {
       
  1569                 noteStringBuf = StringLoader::LoadLC( R_QTN_FMTX_SYSAP_INFO_NOTE_VOLUME_DISABLED, 
       
  1570                                                        iEikonEnv );
       
  1571                 break;
       
  1572                 }
       
  1573             case EFmTxOffNote:
       
  1574                 {
       
  1575                 noteStringBuf = StringLoader::LoadLC( R_QTN_FMTX_SYSAP_INFO_NOTE_DISABLED, 
       
  1576                                                        iEikonEnv );
       
  1577                 break;
       
  1578                 }
       
  1579             case EPowerSaveModeActivated:
       
  1580                 noteStringBuf = StringLoader::LoadLC( R_QTN_POWER_SAVING_ACTIVATED_CONF_NOTE,  iEikonEnv );
       
  1581                  break;
       
  1582             case EPowerSaveModeDeactivated:
       
  1583                 noteStringBuf = StringLoader::LoadLC( R_QTN_POWER_SAVING_DEACTIVATED_CONF_NOTE,  iEikonEnv );
       
  1584                  break;
       
  1585             case ECannotActivatePowerSaveMode:
       
  1586                 noteStringBuf = StringLoader::LoadLC( R_QTN_POWER_SAVING_FAILED_WARNING_NOTE, iEikonEnv );
       
  1587                 break;
       
  1588             case ECannotDeactivatePowerSaveMode:
       
  1589                 noteStringBuf = StringLoader::LoadLC( R_QTN_POWER_SAVING_DEACTIVATION_FAILED_WARNING_NOTE, iEikonEnv ); 
       
  1590                 break;
       
  1591             default:
       
  1592                 break;
       
  1593             }
       
  1594 
       
  1595         note->SetTone( tone );
       
  1596 
       
  1597         // Set secondary display data if necessary
       
  1598         if ( iSysApFeatureManager->CoverDisplaySupported() && secondaryDisplayId != SecondaryDisplay::ECmdNoNote)
       
  1599             {
       
  1600             TRACES( RDebug::Print( _L("CSysApAppUi::ShowUiNoteL - Notifying secondary display") ) );
       
  1601             CAknSDData* sd;
       
  1602             
       
  1603             if ( aNote == EFmTxOnNote ) // frequency information is passed to secondary display
       
  1604                 {
       
  1605                 SecondaryDisplay::TFmTxFrequencyInKhzPckg pckg( iSysApCenRepFmTxObserver->Frequency() );
       
  1606                 sd = CAknSDData::NewL( SecondaryDisplay::KCatSysAp, secondaryDisplayId, pckg );
       
  1607                 }
       
  1608             else
       
  1609                 {
       
  1610                 sd = CAknSDData::NewL(SecondaryDisplay::KCatSysAp, secondaryDisplayId, KNullDesC8);
       
  1611                 }
       
  1612              
       
  1613             note->SetSecondaryDisplayData(sd); // ownership to notifier client
       
  1614             }
       
  1615 
       
  1616         if ( noteStringBuf )
       
  1617             {
       
  1618             TPtr textBuffer = noteStringBuf->Des();
       
  1619             TRACES( RDebug::Print( _L("CSysApAppUi::ShowUiNoteL Next:note->ShowNoteL" ) ) );
       
  1620             note->ShowNoteL( noteType, textBuffer );
       
  1621             CleanupStack::PopAndDestroy( ); // noteStringbuf
       
  1622             }
       
  1623         else
       
  1624             {
       
  1625             TRACES( RDebug::Print( _L("CSysApAppUi::ShowUiNoteL Next:note->ShowNoteL" ) ) );
       
  1626             note->ShowNoteL( noteType, KNullDesC );
       
  1627             }
       
  1628         }
       
  1629     else if( swState == ESwStateAlarm || swState == ESwStateCharging )
       
  1630         {
       
  1631         if ( aNote != EUnplugChargerNote ) // don't play tone when charger is disconnected in charging state
       
  1632             {
       
  1633             static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( tone );    
       
  1634             }
       
  1635         }
       
  1636 
       
  1637     CleanupStack::PopAndDestroy(); // note
       
  1638     }
       
  1639 
       
  1640 // ----------------------------------------------------------------------------
       
  1641 // CSysApAppUi::ShowChargingNoteL()
       
  1642 // ----------------------------------------------------------------------------
       
  1643 
       
  1644 void CSysApAppUi::ShowChargingNoteL()
       
  1645     {
       
  1646     TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL") ) );
       
  1647     TBool showNote( ETrue );
       
  1648 
       
  1649     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  1650     TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL: swState: %d"), swState ) );
       
  1651 
       
  1652     if( UiReady() || swState == ESwStateSecurityCheck )
       
  1653         {
       
  1654         if ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) ==  EPSCTsyCallStateRinging )
       
  1655             {
       
  1656             showNote = EFalse;
       
  1657             }
       
  1658         TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL KCTsyCallState=%d"), StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) ) );
       
  1659         if ( showNote ) // Power Mgmt UI spec defines that no Charging note is shown while the phone is ringing/alerting
       
  1660             {
       
  1661             CAknGlobalNote* chargingNote = CAknGlobalNote::NewLC();
       
  1662             chargingNote->SetTone( EAvkonSIDChargingBatteryTone );
       
  1663             chargingNote->ShowNoteL( EAknGlobalChargingNote, KNullDesC );
       
  1664             CleanupStack::PopAndDestroy( chargingNote );
       
  1665             }
       
  1666         }
       
  1667     else if( swState == ESwStateAlarm || swState == ESwStateCharging )
       
  1668         {
       
  1669         TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL - Just play tone") ) );
       
  1670         static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( EAvkonSIDChargingBatteryTone );
       
  1671         }
       
  1672     else
       
  1673         {
       
  1674         TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL - No note shown") ) );
       
  1675         }
       
  1676     }
       
  1677 
       
  1678 // ----------------------------------------------------------------------------
       
  1679 // CSysApAppUi::HandleChargerNotesL()
       
  1680 // ----------------------------------------------------------------------------
       
  1681 void CSysApAppUi::HandleChargerNotesL( const TInt aValue )
       
  1682     {
       
  1683     TBool showNote(StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateRinging);
       
  1684     if ( aValue == EChargingStatusCharging )
       
  1685         {
       
  1686         iSysApLightsController->BatteryEmptyL( EFalse );
       
  1687         TRACES( RDebug::Print( _L("SysAp: charger connected") ) );
       
  1688         iSysApLightsController->ChargerConnectedL( ETrue );
       
  1689         ShowChargingNoteL();
       
  1690         }
       
  1691     //Display Not Charging note
       
  1692     else if ( aValue == EChargingStatusError )
       
  1693         {
       
  1694         if(showNote)
       
  1695             {
       
  1696             ShowUiNoteL( ENotChargingNote );
       
  1697             }
       
  1698         }
       
  1699     else if ( aValue == EChargingStatusChargingComplete )
       
  1700         {
       
  1701         iSysApLightsController->ChargingCompleteL();
       
  1702         
       
  1703         TSysApNoteIds note( EBatteryFullNote );
       
  1704         
       
  1705         if ( !iSysApUsbChargerDetector.HostOnlyUsbChargingUsed() &&
       
  1706              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) )
       
  1707             {
       
  1708             note = EBatteryFullUnplugChargerNote;
       
  1709             }
       
  1710         iSysApUsbChargerDetector.Reset();
       
  1711         if(showNote)
       
  1712             {
       
  1713             ShowUiNoteL( note );
       
  1714             }
       
  1715         }
       
  1716     else if ( aValue == EChargingStatusNotConnected )
       
  1717         {
       
  1718         TRACES( RDebug::Print( _L("SysAp: charger removed") ) );
       
  1719         iSysApLightsController->ChargerConnectedL( EFalse );    
       
  1720                 
       
  1721         if ( !iSysApUsbChargerDetector.HostOnlyUsbChargingUsed() &&
       
  1722              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) )
       
  1723             {
       
  1724 			if(showNote)
       
  1725                 {
       
  1726                 ShowUiNoteL( EUnplugChargerNote );
       
  1727                 }
       
  1728             }
       
  1729 		iSysApUsbChargerDetector.Reset();
       
  1730         }
       
  1731     else if ( aValue == EChargingStatusNotCharging )
       
  1732         {
       
  1733         TRACES( RDebug::Print( _L("SysAp: Not charging") ) );
       
  1734         }
       
  1735     else if ( aValue == EChargingStatusAlmostComplete )
       
  1736         {
       
  1737         TRACES( RDebug::Print( _L("SysAp: Charging almost complete") ) );
       
  1738         }
       
  1739     else if ( aValue == EChargingStatusChargingContinued )
       
  1740         {
       
  1741         //in this case we simply want to scroll the battery bars and not turn light on or show ui note
       
  1742         // set lights controller iBatteryEmpty to EFalse
       
  1743         iSysApLightsController->BatteryEmptyL( EFalse );
       
  1744         TRACES( RDebug::Print( _L("SysAp: charging continues") ) );
       
  1745         }
       
  1746     }
       
  1747 
       
  1748 // ----------------------------------------------------------------------------
       
  1749 // CSysApAppUi::ShowProfileNoteL()
       
  1750 // ----------------------------------------------------------------------------
       
  1751 
       
  1752 void CSysApAppUi::ShowProfileNoteL()
       
  1753     {
       
  1754     TRACES( RDebug::Print( _L("CSysApAppUi::ShowProfileNoteL") ) );
       
  1755 
       
  1756     if ( UiReady() )
       
  1757         {
       
  1758       
       
  1759         TBufC<KMaxProfileNameLength> profileName;
       
  1760         HBufC* noteStringBuf = NULL;
       
  1761         ActiveProfileNameL( profileName.Des() );
       
  1762         noteStringBuf = StringLoader::LoadLC( R_TEXT_MODE_SELECTED, profileName, iEikonEnv );
       
  1763         TPtr textBuffer = noteStringBuf->Des();
       
  1764         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( textBuffer );
       
  1765 
       
  1766        
       
  1767         // Set secondary display data if necessary
       
  1768         if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  1769             {
       
  1770             TRACES( RDebug::Print( _L("CSysApAppUi::ShowProfileNoteL - Notifying secondary display") ) );
       
  1771             SecondaryDisplay::TProfileName sdProfileName;
       
  1772             sdProfileName.Append(profileName.Left(SecondaryDisplay::KProfileNameMaxLen));
       
  1773             SecondaryDisplay::TProfileNotePckg pckg(sdProfileName);
       
  1774             CAknSDData* sd = CAknSDData::NewL(SecondaryDisplay::KCatSysAp, SecondaryDisplay::ECmdShowProfileNote, pckg);
       
  1775            
       
  1776             }
       
  1777 
       
  1778 
       
  1779         CAknDiscreetPopup::ShowGlobalPopupL(textBuffer,KNullDesC, KAknsIIDNone, KNullDesC);
       
  1780          
       
  1781         CleanupStack::PopAndDestroy(); // noteStringbuf 
       
  1782 
       
  1783         iSysApLightsController->ProfileChangedL(); // All notes should always turn lights on.
       
  1784         }
       
  1785     }
       
  1786 
       
  1787 // ----------------------------------------------------------------------------
       
  1788 // CSysApAppUi::ShowQueryL()
       
  1789 // ----------------------------------------------------------------------------
       
  1790 
       
  1791 void CSysApAppUi::ShowQueryL( const TSysApConfirmationQueryIds aQueryId, const TDesC& aValue )
       
  1792     {
       
  1793     CancelGlobalListQuery();
       
  1794 
       
  1795     if ( aQueryId == ESysApRestartPhoneQuery )
       
  1796         {
       
  1797         iDisablePowerkeyMenu = ETrue;
       
  1798         // Cancel any other query that might be outstanding (i.e. ESysApRemoveMmcNote),
       
  1799         // to avoid multiple overlapping queries causing problems
       
  1800         if ( iSysApConfirmationQuery )
       
  1801             {
       
  1802             iSysApConfirmationQuery->Cancel();
       
  1803             }
       
  1804 
       
  1805         if ( !iSysApConfirmationQueryForRestart )
       
  1806             {
       
  1807             TRACES( RDebug::Print( _L("CSysApAppUi::ShowQueryL: trying CSysApConfirmationQuery::NewL() for restart") ) );
       
  1808             iSysApConfirmationQueryForRestart = CSysApConfirmationQuery::NewL( *this );
       
  1809             }
       
  1810 
       
  1811         iSysApConfirmationQueryForRestart->ShowQueryL( aQueryId, iEikonEnv );
       
  1812         }
       
  1813     else
       
  1814         {
       
  1815         if ( !iSysApConfirmationQuery )
       
  1816             {
       
  1817             TRACES( RDebug::Print( _L("CSysApAppUi::ShowQueryL: trying CSysApConfirmationQuery::NewL()") ) );
       
  1818             iSysApConfirmationQuery = CSysApConfirmationQuery::NewL( *this );
       
  1819             }
       
  1820 
       
  1821         iSysApConfirmationQuery->ShowQueryL( aQueryId, aValue, iEikonEnv );
       
  1822         }
       
  1823     }
       
  1824 
       
  1825 // ----------------------------------------------------------------------------
       
  1826 // CSysApAppUi::UpdateBatteryBarsL( const TInt aState )
       
  1827 // ----------------------------------------------------------------------------
       
  1828 
       
  1829 void CSysApAppUi::UpdateBatteryBarsL( const TInt aState )
       
  1830     {
       
  1831     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
  1832     TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL aState: %d, chargerState:%d"), aState, state ) );
       
  1833     HandleUsbCharger( state );
       
  1834     if( state == EChargingStatusCharging ||
       
  1835         state == EChargingStatusChargingContinued ||
       
  1836         state == EChargingStatusAlmostComplete )
       
  1837         {
       
  1838         if ( !iCharging )
       
  1839             {
       
  1840             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: Starting Charging") ) );
       
  1841             iBatteryNotify->StartChargingL();
       
  1842             iCharging = ETrue;
       
  1843             }
       
  1844 
       
  1845         // When Avkon supports battery state sending while charging,
       
  1846         // add setting battery level here also.
       
  1847         }
       
  1848     else
       
  1849         {
       
  1850         if ( iCharging )
       
  1851             {
       
  1852             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: Stopping Charging") ) );
       
  1853             iBatteryNotify->StopChargingL();
       
  1854             iCharging = EFalse;
       
  1855             }
       
  1856 
       
  1857         if( state == KErrUnknown || aState == KErrUnknown )
       
  1858             {
       
  1859             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: CAknBatteryNotify::SetBatteryLevelL(0)") ) );
       
  1860             iBatteryNotify->SetBatteryLevelL( 0 );
       
  1861             }
       
  1862         else
       
  1863             {
       
  1864             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: CAknBatteryNotify::SetBatteryLevelL(%d)"), aState - EBatteryLevelLevel0 ) );
       
  1865             iBatteryNotify->SetBatteryLevelL( aState - EBatteryLevelLevel0 );
       
  1866             }
       
  1867         }
       
  1868     
       
  1869     if ( !iSysApPsmController ) // created here if first state change has not occurred yet
       
  1870         {
       
  1871         iSysApPsmController = CSysApPsmController::NewL( *this );        
       
  1872         }
       
  1873 
       
  1874     if ( iSysApPsmController )
       
  1875         {
       
  1876         if ( iSysApPsmController->FullPsmEnabled() )
       
  1877             {
       
  1878             iBatteryNotify->SetBatteryStateL( EAknBatteryIndicatorPowerSave );
       
  1879             }
       
  1880         else
       
  1881             {
       
  1882             iBatteryNotify->SetBatteryStateL( EAknBatteryIndicatorNormal );
       
  1883             }            
       
  1884         }
       
  1885         
       
  1886     if ( iSysApBatteryInfoController )        
       
  1887         {
       
  1888         iSysApBatteryInfoController->BatteryLevelUpdatedL();
       
  1889         }
       
  1890     }
       
  1891 
       
  1892 // ----------------------------------------------------------------------------
       
  1893 // CSysApAppUi::UpdateSignalBarsL()
       
  1894 // ----------------------------------------------------------------------------
       
  1895 
       
  1896 void CSysApAppUi::UpdateSignalBarsL()
       
  1897     {
       
  1898     UpdateSignalBarsL(iSysApEtelConnector->GetSignalBars());
       
  1899     }
       
  1900 
       
  1901 // ----------------------------------------------------------------------------
       
  1902 // CSysApAppUi::UpdateSignalBarsL( const TInt aState )
       
  1903 // ----------------------------------------------------------------------------
       
  1904 
       
  1905 void CSysApAppUi::UpdateSignalBarsL( const TInt aState )
       
  1906     {
       
  1907     TRACES( RDebug::Print( _L("CSysApAppUi::UpdateSignalBarsL aState: %d"), aState ) );
       
  1908     if( iSysApGanHandler && iSysApGanHandler->IsInGanMode() )
       
  1909         {
       
  1910         iSignalNotify->SetSignalLevelL( iSysApGanHandler->GanSignalLevel() );
       
  1911         }
       
  1912 	else if( aState == KAknSignalOffLineMode || (iSysApOfflineModeController->OfflineModeActive() && !iEmergencyCallActive) )
       
  1913         {
       
  1914         iSignalNotify->SetSignalLevelL( KAknSignalOffLineMode );
       
  1915         }
       
  1916     else if( aState <= 0 )
       
  1917         {
       
  1918         // Do not update indicator show zero bars if we should be showing X over bars
       
  1919         // This is required for indicator to work correctly in BT SAP mode.
       
  1920         // Cannot use check for BT SAP enabled status, as zero bars notify comes before enabled status changes.
       
  1921         if ( !iIgnoreZeroNetworkBarNotifications )
       
  1922             {
       
  1923             iSignalNotify->SetSignalLevelL( 0 );
       
  1924             }
       
  1925         }
       
  1926     else
       
  1927         {
       
  1928         iSignalNotify->SetSignalLevelL( aState );
       
  1929         }
       
  1930     }
       
  1931 
       
  1932 // ----------------------------------------------------------------------------
       
  1933 // CSysApAppUi::SetSignalIndicatorL()
       
  1934 // ----------------------------------------------------------------------------
       
  1935 
       
  1936 void CSysApAppUi::SetSignalIndicatorL()
       
  1937     {
       
  1938     TSysApNetworkMode networkMode( ESysApGSM );
       
  1939 
       
  1940     TInt networkModeFromNetworkInfo( StateOfProperty( KPSUidNetworkInfo, KNWTelephonyNetworkMode ) );
       
  1941     if ( networkModeFromNetworkInfo == ENWNetworkModeWcdma )
       
  1942         {
       
  1943         networkMode = ESysApWCDMA;
       
  1944         }
       
  1945     else
       
  1946         {
       
  1947         networkMode = ESysApGSM;
       
  1948         }
       
  1949 
       
  1950     TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorL: networkMode = %d" ), networkMode ) );
       
  1951 
       
  1952     if( iSysApOfflineModeController->OfflineModeActive() && !iEmergencyCallActive )
       
  1953         {
       
  1954         // The device is in Offline Mode
       
  1955         if ( iSysApFeatureManager->Supported( KSysApFeatureIdGprs_G_Icon ) )
       
  1956             {
       
  1957             iSignalNotify->SetGprsStateL( EAknSignalGprsIndicatorOff );
       
  1958             }
       
  1959         else
       
  1960             {
       
  1961             iSignalNotify->SetCommonPacketDataStateL( EAknSignalCommonPacketDataIndicatorOff );
       
  1962             }
       
  1963         iSignalNotify->SetWcdmaStateL( EAknSignalWcdmaIndicatorOff );
       
  1964         iSignalNotify->SetHsdpaStateL( EAknSignalHsdpaIndicatorOff);
       
  1965         TRACES( RDebug::Print(_L("CSysApAppUi::SetSignalIndicatorL: gan off" ) ) );
       
  1966         iSignalNotify->SetUmaStateL( EAknSignalUmaIndicatorOff );
       
  1967         }
       
  1968     else
       
  1969         {
       
  1970         if( iSysApGanHandler && iSysApGanHandler->IsInGanMode() )
       
  1971             {
       
  1972             // Enter GAN: set GAN signal bar
       
  1973             SetSignalIndicatorGanL();
       
  1974             iGanEnabled = ETrue;
       
  1975             }
       
  1976         else
       
  1977             {
       
  1978             if( iGanEnabled )
       
  1979                 {
       
  1980                 UpdateSignalBarsL();
       
  1981                 iGanEnabled = EFalse;
       
  1982                 }
       
  1983 
       
  1984             // The device is in Online Mode
       
  1985             switch ( networkMode )
       
  1986                 {
       
  1987                 case ESysApGSM:
       
  1988                     SetSignalIndicatorGsmL();
       
  1989                     break;
       
  1990 
       
  1991                 case ESysApWCDMA:
       
  1992                     SetSignalIndicatorWcdmaL();
       
  1993                     break;
       
  1994 
       
  1995                 default:
       
  1996                     break;
       
  1997                 }
       
  1998             }
       
  1999         }
       
  2000     }
       
  2001 
       
  2002 // ----------------------------------------------------------------------------
       
  2003 // CSysApAppUi::SetSignalIndicatorGsmL()
       
  2004 // ----------------------------------------------------------------------------
       
  2005 void CSysApAppUi::SetSignalIndicatorGsmL()
       
  2006     {
       
  2007     TInt signalGprsIndicatorState( 0 );
       
  2008     TInt signalIndicatorState( 0 );
       
  2009 	TInt bearerValue = EBearerUnknown;
       
  2010 
       
  2011 	if(iSysApConnectionMonitorObserver)
       
  2012 		{
       
  2013 		bearerValue = iSysApConnectionMonitorObserver->GetBearerValue();
       
  2014 		}
       
  2015 
       
  2016 	if(bearerValue == EBearerEdgeGPRS)
       
  2017 		{
       
  2018 		TInt egprsStatus = StateOfProperty( KUidSystemCategory, KPSUidGprsStatusValue );
       
  2019 	    TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorGsmL gprsStatus: %d" ), egprsStatus ) );
       
  2020 	    iSignalNotify->SetWcdmaStateL( EAknSignalWcdmaIndicatorOff );
       
  2021 	    iSignalNotify->SetHsdpaStateL( EAknSignalHsdpaIndicatorOff );
       
  2022 	    switch ( egprsStatus )
       
  2023 	        {
       
  2024 	        case EPSGprsContextActive:
       
  2025 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorContext;
       
  2026 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorContext;
       
  2027 	            iGprsActivated = ETrue;
       
  2028 	            iGprsSuspended = EFalse;
       
  2029 	            HandleGprsNotesL();
       
  2030 	            break;
       
  2031 
       
  2032 	        case EPSGprsContextActivating:
       
  2033 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorEstablishingContext;
       
  2034 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorEstablishingContext;
       
  2035 	            iGprsActivated = EFalse;
       
  2036 	            iGprsSuspended = EFalse;
       
  2037 	            break;
       
  2038 
       
  2039 	        case EPSGprsSuspend:
       
  2040 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorSuspended;
       
  2041 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorSuspended;
       
  2042 	            iGprsSuspended = ETrue;
       
  2043 	            HandleGprsNotesL();
       
  2044 	            break;
       
  2045 
       
  2046 	        case EPSGprsAttach:
       
  2047 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorAttached;
       
  2048 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorAttached;
       
  2049 	            iGprsActivated = EFalse;
       
  2050 	            iGprsSuspended = EFalse;
       
  2051 	            break;
       
  2052 
       
  2053 	        case EPSGprsMultibleContextActive:
       
  2054 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorMultipdp;
       
  2055 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorMultipdp;
       
  2056 	            iGprsActivated = ETrue;
       
  2057 	            iGprsSuspended = EFalse;
       
  2058 	            HandleGprsNotesL();
       
  2059 	            break;
       
  2060 
       
  2061 	        case EPSGprsUnattached:
       
  2062 	        default:
       
  2063 	        	  if ( iTDEnable )
       
  2064 	            {
       
  2065 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorAvailable;
       
  2066 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorAvailable;
       
  2067 	            }
       
  2068 	            else
       
  2069 	            {
       
  2070 	            signalGprsIndicatorState = EAknSignalEdgeIndicatorOff;
       
  2071 	            signalIndicatorState = EAknSignalCommonPacketDataIndicatorOff;
       
  2072 	            }
       
  2073               iGprsSuspendedNoteShown = EFalse;
       
  2074 	            iGprsActivated = EFalse;
       
  2075 	            iGprsSuspended = EFalse;
       
  2076 	            iCallActivated = EFalse;
       
  2077 	            break;
       
  2078 	        }
       
  2079         }
       
  2080 	else
       
  2081 		{
       
  2082 
       
  2083 		TInt gprsStatus = StateOfProperty( KUidSystemCategory, KPSUidGprsStatusValue );
       
  2084     	TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorGsmL gprsStatus: %d" ), gprsStatus ) );
       
  2085     	iSignalNotify->SetWcdmaStateL( EAknSignalWcdmaIndicatorOff );
       
  2086     	iSignalNotify->SetHsdpaStateL( EAknSignalHsdpaIndicatorOff );
       
  2087     	switch ( gprsStatus )
       
  2088             {
       
  2089             case EPSGprsContextActive:
       
  2090                 signalGprsIndicatorState = EAknSignalGprsIndicatorContext;
       
  2091                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorContext;
       
  2092                 iGprsActivated = ETrue;
       
  2093                 iGprsSuspended = EFalse;
       
  2094                 HandleGprsNotesL();
       
  2095                 break;
       
  2096 
       
  2097             case EPSGprsContextActivating:
       
  2098                 signalGprsIndicatorState = EAknSignalGprsIndicatorEstablishingContext;
       
  2099                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorEstablishingContext;
       
  2100                 iGprsActivated = EFalse;
       
  2101                 iGprsSuspended = EFalse;
       
  2102                 break;
       
  2103 
       
  2104             case EPSGprsSuspend:
       
  2105                 signalGprsIndicatorState = EAknSignalGprsIndicatorSuspended;
       
  2106                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorSuspended;
       
  2107                 iGprsSuspended = ETrue;
       
  2108                 HandleGprsNotesL();
       
  2109                 break;
       
  2110 
       
  2111             case EPSGprsAttach:
       
  2112                 signalGprsIndicatorState = EAknSignalGprsIndicatorAttached;
       
  2113                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorAttached;
       
  2114                 iGprsActivated = EFalse;
       
  2115                 iGprsSuspended = EFalse;
       
  2116                 break;
       
  2117 
       
  2118             case EPSGprsMultibleContextActive:
       
  2119                 signalGprsIndicatorState = EAknSignalGprsIndicatorMultipdp;
       
  2120                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorMultipdp;
       
  2121                 iGprsActivated = ETrue;
       
  2122                 iGprsSuspended = EFalse;
       
  2123                 HandleGprsNotesL();
       
  2124                 break;
       
  2125 
       
  2126             case EPSGprsUnattached:
       
  2127             default:
       
  2128                 if ( iTDEnable )
       
  2129 	              {
       
  2130 	              signalGprsIndicatorState = EAknSignalGprsIndicatorAvailable;
       
  2131 	              signalIndicatorState = EAknSignalCommonPacketDataIndicatorAvailable;
       
  2132 	              }
       
  2133 	              else
       
  2134 	              {
       
  2135                 signalGprsIndicatorState = EAknSignalGprsIndicatorOff;
       
  2136                 signalIndicatorState = EAknSignalCommonPacketDataIndicatorOff;
       
  2137                 }
       
  2138 
       
  2139                 iGprsSuspendedNoteShown = EFalse;
       
  2140                 iGprsActivated = EFalse;
       
  2141                 iGprsSuspended = EFalse;
       
  2142                 iCallActivated = EFalse;
       
  2143                 break;
       
  2144             }
       
  2145 		}
       
  2146 
       
  2147 	if(bearerValue == EBearerEdgeGPRS) //EdgeGPRS connection
       
  2148 		{
       
  2149 		if( iSysApFeatureManager->Supported( KSysApFeatureIdUseEdgeGPRSIcon ) )
       
  2150 	    	{
       
  2151 	    	iSignalNotify->SetEdgeStateL( signalGprsIndicatorState );
       
  2152 	    	}
       
  2153 	    else
       
  2154         	{
       
  2155         	iSignalNotify->SetCommonPacketDataStateL( signalIndicatorState );
       
  2156         	}
       
  2157 		}
       
  2158 	else
       
  2159 		{
       
  2160 
       
  2161 	    if ( iSysApFeatureManager->Supported( KSysApFeatureIdGprs_G_Icon ) )
       
  2162     	    {
       
  2163         	iSignalNotify->SetGprsStateL( signalGprsIndicatorState );
       
  2164         	}
       
  2165     	else
       
  2166         	{
       
  2167         	TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorGsmL SetCommonPacketDataStateL( %d )" ), signalIndicatorState ) );
       
  2168         	iSignalNotify->SetCommonPacketDataStateL( signalIndicatorState );
       
  2169         	}
       
  2170 		}
       
  2171     }
       
  2172 
       
  2173 // ----------------------------------------------------------------------------
       
  2174 // CSysApAppUi::SetSignalIndicatorWcdmaL()
       
  2175 // ----------------------------------------------------------------------------
       
  2176 void CSysApAppUi::SetSignalIndicatorWcdmaL()
       
  2177     {
       
  2178     TInt wcdmaStatus;
       
  2179     wcdmaStatus = StateOfProperty( KUidSystemCategory, KPSUidWcdmaStatusValue );
       
  2180     TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorWcdmaL: wcdmaStatus: %d" ), wcdmaStatus ) );
       
  2181 
       
  2182     if ( iSysApFeatureManager->Supported( KSysApFeatureIdGprs_G_Icon ) )
       
  2183         {
       
  2184         iSignalNotify->SetGprsStateL( EAknSignalGprsIndicatorOff );
       
  2185         }
       
  2186     else
       
  2187         {
       
  2188         iSignalNotify->SetCommonPacketDataStateL( EAknSignalCommonPacketDataIndicatorOff );
       
  2189         }
       
  2190 
       
  2191     TInt signalWcdmaIndicatorState;
       
  2192     TInt signalHsdpaIndicatorState;
       
  2193 
       
  2194     switch ( wcdmaStatus )
       
  2195         {
       
  2196         case EPSWcdmaContextActive:
       
  2197             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorContext;
       
  2198             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorContext;
       
  2199             break;
       
  2200         case EPSWcdmaContextActivating:
       
  2201             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorEstablishingContext;
       
  2202             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorEstablishingContext;
       
  2203             break;
       
  2204         case EPSWcdmaSuspend:
       
  2205             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorSuspended;
       
  2206             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorSuspended;
       
  2207             break;
       
  2208         case EPSWcdmaAttach:
       
  2209             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorAttached;
       
  2210             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorAttached;
       
  2211             break;
       
  2212         case EPSWcdmaMultipleContextActive:
       
  2213             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorMultipdp;
       
  2214             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorMultipdp;
       
  2215             break;
       
  2216         case EPSWcdmaUnattached:
       
  2217         default:
       
  2218             signalWcdmaIndicatorState = EAknSignalWcdmaIndicatorAvailable;
       
  2219             signalHsdpaIndicatorState = EAknSignalHsdpaIndicatorAvailable;
       
  2220             break;
       
  2221         }
       
  2222 
       
  2223     TBool showHsdpaAvailable = EFalse;
       
  2224 
       
  2225     if ( iSysApFeatureManager->Supported( KSysApFeatureIdUseHsdpaAvailableIcon ) )
       
  2226         {
       
  2227         // HSDPA Resource Availability information is a configurable feature.
       
  2228         showHsdpaAvailable = iSysApEtelConnector->HsdpaAvailable();
       
  2229         }
       
  2230     
       
  2231     TBool isHsdpaBearer = iSysApEtelConnector->IsBearerHsdpa();
       
  2232     
       
  2233     TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorWcdmaL: isHdpaBearer=%d, showHsdpaAvailable=%d" ),
       
  2234             isHsdpaBearer, showHsdpaAvailable ) );
       
  2235     
       
  2236     if ( isHsdpaBearer || showHsdpaAvailable )
       
  2237         {
       
  2238         iSignalNotify->SetWcdmaStateL( EAknSignalWcdmaIndicatorOff );
       
  2239     	iSignalNotify->SetHsdpaStateL( signalHsdpaIndicatorState );
       
  2240         }
       
  2241     else
       
  2242         {
       
  2243         iSignalNotify->SetHsdpaStateL( EAknSignalHsdpaIndicatorOff );
       
  2244         iSignalNotify->SetWcdmaStateL( signalWcdmaIndicatorState );
       
  2245         }
       
  2246     }
       
  2247 
       
  2248 // ----------------------------------------------------------------------------
       
  2249 // CSysApAppUi::SetSignalIndicatorGanL()
       
  2250 // ----------------------------------------------------------------------------
       
  2251 void CSysApAppUi::SetSignalIndicatorGanL()
       
  2252     {
       
  2253     TRACES( RDebug::Print(_L("CSysApAppUi::SetSignalIndicatorGanL: available" ) ) );
       
  2254 
       
  2255     TInt gprsStatus( 0 );
       
  2256     gprsStatus = StateOfProperty( KUidSystemCategory, KPSUidGprsStatusValue );
       
  2257 
       
  2258     TRACES( RDebug::Print( _L("CSysApAppUi::SetSignalIndicatorGanL gprsStatus: %d" ), gprsStatus ) );
       
  2259 
       
  2260     switch ( gprsStatus )
       
  2261         {
       
  2262         case EPSGprsContextActive:
       
  2263             iSignalNotify->SetUmaStateL( EAknSignalUmaIndicatorContext );
       
  2264             break;
       
  2265 
       
  2266         case EPSGprsContextActivating:
       
  2267             iSignalNotify->SetUmaStateL( EAknSignalUmaIndicatorEstablishingContext );
       
  2268             break;
       
  2269 
       
  2270         case EPSGprsSuspend:
       
  2271             iSignalNotify->SetUmaStateL( EAknSignalUmaIndicatorSuspended );
       
  2272             break;
       
  2273 
       
  2274         case EPSGprsAttach:
       
  2275             iSignalNotify->SetUmaStateL( EAknSignalUmaIndicatorAttached );
       
  2276             break;
       
  2277 
       
  2278         case EPSGprsMultibleContextActive:
       
  2279             iSignalNotify->SetUmaStateL( EAknSignalUmaIndicatorMultipdp );
       
  2280             break;
       
  2281 
       
  2282         case EPSGprsUnattached:
       
  2283         default:
       
  2284             iSignalNotify->SetUmaStateL( EAknSignalUmaIndicatorAvailable );
       
  2285             break;
       
  2286         }
       
  2287     }
       
  2288 
       
  2289 // ----------------------------------------------------------------------------
       
  2290 // CSysApAppUi::HandleGprsNotesL()
       
  2291 // ----------------------------------------------------------------------------
       
  2292 
       
  2293 void CSysApAppUi::HandleGprsNotesL()
       
  2294     {
       
  2295     TRACES( RDebug::Print( _L("CSysApAppUi::HandleGprsNotesL" ) ) );
       
  2296     if ( iSysApFeatureManager->Supported( KSysApFeatureIdGPRSNotes ) )
       
  2297         {
       
  2298         // In WCDMA system, receiving or making calls has no effect to the possibly
       
  2299         // existing PDP contexts i.e. GPRS notes are not needed.
       
  2300         TInt networkMode = StateOfProperty( KPSUidNetworkInfo, KNWTelephonyNetworkMode );
       
  2301         TRACES( RDebug::Print( _L("CSysApAppUi::HandleGprsNotesL: networkMode %d" ), networkMode ) );
       
  2302         if ( networkMode != ENWNetworkModeWcdma )
       
  2303             {
       
  2304             if ( iGprsActivated && iGprsSuspended && iCallActivated && !iGprsSuspendedNoteShown )
       
  2305                 {
       
  2306                 StartGprsSuspendedTimer();
       
  2307                 }
       
  2308             else if ( iGprsSuspendedNoteShown && !iGprsSuspended )
       
  2309                 {
       
  2310                 iGprsSuspendedNoteShown = EFalse;
       
  2311                 iGprsSuspended = EFalse;
       
  2312                 iCallActivated = EFalse;
       
  2313                 }
       
  2314             }
       
  2315         }
       
  2316     }
       
  2317 
       
  2318 // ----------------------------------------------------------------------------
       
  2319 // CSysApAppUi::SetIndicatorStateL( TInt aIndicator, TInt aState )
       
  2320 // ----------------------------------------------------------------------------
       
  2321 
       
  2322 void CSysApAppUi::SetIndicatorStateL( const TInt aIndicator, const TInt aState ) const
       
  2323     {
       
  2324     CAknSmallIndicator* theIndicator = CAknSmallIndicator::NewLC( TUid::Uid( aIndicator ) );
       
  2325     theIndicator->SetIndicatorStateL( aState );
       
  2326     CleanupStack::PopAndDestroy(); //theIndicator
       
  2327     }
       
  2328 
       
  2329 // ----------------------------------------------------------------------------
       
  2330 // CSysApAppUi::GoOnlineL()
       
  2331 // ----------------------------------------------------------------------------
       
  2332 
       
  2333 void CSysApAppUi::GoOnlineL( TBool aDoProfileChange )
       
  2334     {
       
  2335     if ( iSysApFeatureManager->OfflineModeSupported() )
       
  2336         {
       
  2337         TRACES( RDebug::Print( _L("CSysApAppUi::GoOnlineL: going from off-line into on-line: aDoProfileChange=%d" ), aDoProfileChange ) );
       
  2338         // in case profile change is not needed, event handling for subsequent profile changes are must be allowed
       
  2339         iHandleNextProfileEvent = !aDoProfileChange;
       
  2340         iActivateBt = iSysApOfflineModeController->MustBtBeActivated();
       
  2341 
       
  2342         if ( aDoProfileChange )
       
  2343             {
       
  2344             TRAPD( err, ActivateProfileL( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileBeforeOfflineMode ) ) );
       
  2345             if ( err == KErrNotFound )
       
  2346                 {
       
  2347                 // Activate general profile instead, if previously used profile was not found
       
  2348                 TRACES( RDebug::Print( _L("CSysApAppUi::GoOnlineL: Previously used profile was not found, restoring to general profile" ) ) );
       
  2349                 ActivateProfileL(KGeneralProfileId);
       
  2350                 }
       
  2351             }
       
  2352 
       
  2353         iSysApOfflineModeController->SwitchFromOfflineToOnlineModeL();
       
  2354         TRACES( RDebug::Print( _L("CSysApAppUi::GoOnlineL: iActivateBt = %d" ), iActivateBt ) );
       
  2355         }
       
  2356     }
       
  2357 
       
  2358 // ----------------------------------------------------------------------------
       
  2359 // CSysApAppUi::GoOfflineL()
       
  2360 // ----------------------------------------------------------------------------
       
  2361 
       
  2362 void CSysApAppUi::GoOfflineL()
       
  2363     {
       
  2364     if ( iSysApFeatureManager->OfflineModeSupported() )
       
  2365         {
       
  2366         TRACES( RDebug::Print( _L("CSysApAppUi::GoOfflineL" ) ) );
       
  2367         iHandleNextProfileEvent = EFalse;
       
  2368         iDeactivateBt = ETrue;
       
  2369         ActivateProfileL( KOfflineModeProfileId );
       
  2370         iSysApOfflineModeController->SwitchFromOnlineToOfflineModeL();
       
  2371         }
       
  2372     }
       
  2373 
       
  2374 // ----------------------------------------------------------------------------
       
  2375 // CSysApAppUi::SwitchFromOnlineToOfflineModeL()
       
  2376 // ----------------------------------------------------------------------------
       
  2377 void CSysApAppUi::SwitchFromOnlineToOfflineModeL()
       
  2378     {
       
  2379     if ( iSysApFeatureManager->FmTxSupported() )
       
  2380         {
       
  2381         TFmTxState state = static_cast<TFmTxState>(StateOfProperty( KPSUidHWRMFmTx, KHWRMFmTxStatus ));
       
  2382         switch ( state )
       
  2383             {
       
  2384             case EFmTxStateActive:
       
  2385             case EFmTxStateInactive:
       
  2386             case EFmTxStateScanning:
       
  2387                 ShowQueryL( ESysApUseFmTxInOfflineQuery ); // show "use fm tx in offline?" if FM TX is on
       
  2388                 break;
       
  2389             
       
  2390             default:
       
  2391                 // do nothing
       
  2392                 break;                
       
  2393             }
       
  2394         }
       
  2395     iSysApOfflineModeController->SwitchFromOnlineToOfflineModeL();
       
  2396     }
       
  2397 
       
  2398 // ----------------------------------------------------------------------------
       
  2399 // CSysApAppUi::OfflineModeChangedL()
       
  2400 // ----------------------------------------------------------------------------
       
  2401 void CSysApAppUi::OfflineModeChangedL()
       
  2402     {
       
  2403 #ifdef SYSAP_USE_STARTUP_UI_PHASE    
       
  2404     // if UI is not ready, don't update indicators
       
  2405     if ( !UiReady() )
       
  2406         {
       
  2407         return;
       
  2408         }
       
  2409 #endif // SYSAP_USE_STARTUP_UI_PHASE
       
  2410     
       
  2411     // Update network bar indicator
       
  2412     if ( OfflineModeActive() )
       
  2413         {
       
  2414         UpdateSignalBarsL( KAknSignalOffLineMode );
       
  2415         }
       
  2416     else
       
  2417         {
       
  2418         UpdateSignalBarsL();    
       
  2419         }        
       
  2420     
       
  2421     // Update network mode indicator
       
  2422     SetSignalIndicatorL();
       
  2423     
       
  2424     // Update HAC indicator
       
  2425     SetHacIndicatorL();
       
  2426     }
       
  2427 
       
  2428 // ----------------------------------------------------------------------------
       
  2429 // CSysApAppUi::OfflineModeActive()
       
  2430 // ----------------------------------------------------------------------------
       
  2431 TBool CSysApAppUi::OfflineModeActive()
       
  2432     {
       
  2433     return iSysApOfflineModeController->OfflineModeActive();
       
  2434     }
       
  2435 
       
  2436 // ----------------------------------------------------------------------------
       
  2437 // CSysApAppUi::DoNotActivateBt()
       
  2438 // ----------------------------------------------------------------------------
       
  2439 void CSysApAppUi::DoNotActivateBt()
       
  2440     {
       
  2441     iSysApOfflineModeController->DoNotActivateBt();
       
  2442     }
       
  2443 
       
  2444 // ----------------------------------------------------------------------------
       
  2445 // CSysApAppUi::SetBtPowerState()
       
  2446 // ----------------------------------------------------------------------------
       
  2447 TInt CSysApAppUi::SetBtPowerState( TBool aBtState )
       
  2448     {
       
  2449     if ( iSysApBtController )
       
  2450         {
       
  2451         return iSysApBtController->SetPowerState( aBtState );
       
  2452         }
       
  2453     else
       
  2454         {
       
  2455         return KErrNotReady;
       
  2456         }
       
  2457     }
       
  2458 
       
  2459 // ----------------------------------------------------------------------------
       
  2460 // CSysApAppUi::KeyLockState() const
       
  2461 // ----------------------------------------------------------------------------
       
  2462 
       
  2463 TBool CSysApAppUi::KeyLockState() const
       
  2464     {
       
  2465     return iKeyLockEnabled;
       
  2466     }
       
  2467 
       
  2468 // ----------------------------------------------------------------------------
       
  2469 // CSysApAppUi::DeviceLockState() const
       
  2470 // ----------------------------------------------------------------------------
       
  2471 
       
  2472 TBool CSysApAppUi::DeviceLockState() const
       
  2473     {
       
  2474     return iDeviceLockEnabled;
       
  2475     }
       
  2476 
       
  2477 // ----------------------------------------------------------------------------
       
  2478 // CSysApAppUi::ChangeFmTxStateL()
       
  2479 // ----------------------------------------------------------------------------     
       
  2480 void CSysApAppUi::ChangeFmTxStateL( TBool aEnable )
       
  2481     {
       
  2482     // disable fm transmission
       
  2483     CHWRMFmTx* fmtx = CHWRMFmTx::NewLC();
       
  2484     if ( aEnable )
       
  2485        {
       
  2486        fmtx->EnableL();
       
  2487        }
       
  2488     else 
       
  2489        {
       
  2490        fmtx->DisableL();
       
  2491        }
       
  2492     CleanupStack::PopAndDestroy( fmtx );
       
  2493     } 
       
  2494 
       
  2495 // ----------------------------------------------------------------------------
       
  2496 // CSysApAppUi::SetIhfIndicatorL()
       
  2497 // ----------------------------------------------------------------------------
       
  2498 void CSysApAppUi::SetIhfIndicatorL()
       
  2499     {
       
  2500     TBool accessoryConnected ( EFalse );
       
  2501 
       
  2502     TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  2503 
       
  2504     TAccMode accMode(EAccModeHandPortable);
       
  2505 
       
  2506     if ( iSysApAccessoryObserver )
       
  2507         {
       
  2508         accMode = iSysApAccessoryObserver->GetAccessoryMode();
       
  2509 
       
  2510         if ( accMode != EAccModeHandPortable )
       
  2511             {
       
  2512             accessoryConnected = ETrue;
       
  2513             }
       
  2514         }
       
  2515 
       
  2516     if( (callState != EPSCTsyCallStateNone && IhfEnabledL() && !accessoryConnected)
       
  2517         || accMode == EAccModeMusicStand )  // Music stand always shows IHF indicator
       
  2518         {
       
  2519         SetIndicatorStateL( EAknIndicatorIHFActive, EAknIndicatorStateOn );
       
  2520 
       
  2521         if ( accMode == EAccModeMusicStand )
       
  2522             {
       
  2523             // hide other accessory indicators to prevent displaying of duplicate icons in some cases
       
  2524             // e.g. when wireless hf is connected
       
  2525             SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2526             SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2527             SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2528             SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2529             SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2530             SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2531             SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2532             }
       
  2533         }
       
  2534     else
       
  2535         {
       
  2536         SetIndicatorStateL( EAknIndicatorIHFActive, EAknIndicatorStateOff );
       
  2537         }
       
  2538     }
       
  2539 
       
  2540 // ----------------------------------------------------------------------------
       
  2541 // CSysApAppUi::HandleSmsStorageNotificationL( TBool aSimStoreFull )
       
  2542 // ----------------------------------------------------------------------------
       
  2543 
       
  2544 void CSysApAppUi::HandleSmsStorageNotificationL( TBool aSimStoreFull )
       
  2545     {
       
  2546     TRACES( RDebug::Print( _L("CSysApAppUi::HandleSmsStorageNotificationL: aSimStoreFull: %d "), aSimStoreFull ) );
       
  2547 
       
  2548     if ( aSimStoreFull )
       
  2549         {
       
  2550         HBufC* noteStringBuf;
       
  2551         noteStringBuf = StringLoader::LoadLC( R_QTN_MEMLO_MEMORY_LOW_SIM_MES, iEikonEnv );
       
  2552         TPtr textBuffer = noteStringBuf->Des();
       
  2553         iSysApMsgSimMemLowQuery->StartL( textBuffer );
       
  2554         CleanupStack::PopAndDestroy();
       
  2555         }
       
  2556 
       
  2557     SetEnvelopeIndicatorL();
       
  2558     }
       
  2559 
       
  2560 // ----------------------------------------------------------------------------
       
  2561 // CSysApAppUi::HandleNspsRawKeyEventL()
       
  2562 // ----------------------------------------------------------------------------
       
  2563 
       
  2564 void CSysApAppUi::HandleNspsRawKeyEventL()
       
  2565     {
       
  2566 #ifdef __SYSAP_MODULE_TEST
       
  2567     ModuleTestShowUiNoteL( _L("Network wakeup from NSPS") );
       
  2568 #endif
       
  2569 
       
  2570     if ( iSysApEtelConnector )
       
  2571         {
       
  2572         iSysApEtelConnector->CommandNetCsWakeupOnNsps();
       
  2573         }
       
  2574     }
       
  2575 
       
  2576 // ----------------------------------------------------------------------------
       
  2577 // CSysApAppUi::HandleNetworkNspsNotification( RMmCustomAPI::TNspsStatus aNspsStatus )
       
  2578 // ----------------------------------------------------------------------------
       
  2579 
       
  2580 void CSysApAppUi::HandleNetworkNspsNotification( RMmCustomAPI::TNspsStatus aNspsStatus )
       
  2581     {
       
  2582     TRACES( RDebug::Print( _L("CSysApAppUi::HandleNetworkNspsNotification aNspsStatus:%d, iNsps:%d )" ), aNspsStatus, iNsps ) );
       
  2583     if( iSysApNspsHandler )
       
  2584         {
       
  2585         if( aNspsStatus == RMmCustomAPI::ENspsOn )
       
  2586             {
       
  2587             if( !iNsps )
       
  2588                 {
       
  2589 #ifdef __SYSAP_MODULE_TEST
       
  2590                 TRAPD( err, ModuleTestShowUiNoteL( _L("Setting NSPS on") ) );
       
  2591 #endif
       
  2592                 iSysApNspsHandler->SetNspsOn();
       
  2593                 iNsps = ETrue;
       
  2594                 }
       
  2595             }
       
  2596         else if( aNspsStatus == RMmCustomAPI::ENspsOff )
       
  2597             {
       
  2598             if( iNsps )
       
  2599                 {
       
  2600 #ifdef __SYSAP_MODULE_TEST
       
  2601                 TRAPD( err, ModuleTestShowUiNoteL( _L("Setting NSPS off") ) );
       
  2602 #endif
       
  2603                 iSysApNspsHandler->SetNspsOff();
       
  2604                 iNsps = EFalse;
       
  2605                 }
       
  2606             }
       
  2607         }
       
  2608     }
       
  2609 
       
  2610 // ----------------------------------------------------------------------------
       
  2611 // CSysApAppUi::HandleMessageTonePlayingQuitability( TInt aTonePlayingStatus )
       
  2612 // ----------------------------------------------------------------------------
       
  2613 
       
  2614 void CSysApAppUi::HandleMessageTonePlayingQuitability( TInt aTonePlayingStatus )
       
  2615     {
       
  2616     if( iSysApNspsHandler )
       
  2617         {
       
  2618         if( aTonePlayingStatus == ECoreAppUIsStopTonePlaying )
       
  2619             {
       
  2620             iSysApNspsHandler->SetMessageToneNotPlaying();
       
  2621             }
       
  2622         else if( aTonePlayingStatus == ECoreAppUIsTonePlaying )
       
  2623             {
       
  2624             iSysApNspsHandler->SetMessageTonePlaying();
       
  2625             }
       
  2626         }
       
  2627     }
       
  2628 
       
  2629 // ----------------------------------------------------------------------------
       
  2630 // CSysApAppUi::ActivateKeyeventForwardingForLights()
       
  2631 // ----------------------------------------------------------------------------
       
  2632 
       
  2633 void CSysApAppUi::ActivateKeyeventForwardingForLights(TBool aActivate)
       
  2634     {
       
  2635     if( iSysApNspsHandler )
       
  2636         {
       
  2637         if ( aActivate )
       
  2638             {
       
  2639             iSysApNspsHandler->ActivateKeyeventForwardingForLights();
       
  2640             }
       
  2641         else
       
  2642             {
       
  2643             iSysApNspsHandler->DeActivateKeyeventForwardingForLights();
       
  2644             }
       
  2645         }
       
  2646     }
       
  2647 
       
  2648 // ----------------------------------------------------------------------------
       
  2649 // CSysApAppUi::StartShutDownTimerOnAlarmAndChargingStates()
       
  2650 // ----------------------------------------------------------------------------
       
  2651 
       
  2652 void CSysApAppUi::StartShutDownTimerOnAlarmAndChargingStates()
       
  2653     {
       
  2654     if( !iAlarmOrChargingStateShutdownStarted )
       
  2655         {
       
  2656         if ( !iTimer )
       
  2657             {
       
  2658             TRAPD( err, iTimer = CPeriodic::NewL( EPriorityNormal ) );
       
  2659 
       
  2660             if ( err != KErrNone )
       
  2661                 {
       
  2662                 TRACES( RDebug::Print( _L("CSysApAppUi::StartShutDownTimerOnAlarmAndChargingStates: CPeriodic::NewL failed: %d"), err ) );
       
  2663                 return;
       
  2664                 }
       
  2665             }
       
  2666         iTimer->Cancel();
       
  2667         iTimer->Start( KDelayBeforeShuttingDownInAlarmAndChargingStates,
       
  2668                        KDelayBeforeShuttingDownInAlarmAndChargingStates,
       
  2669                        TCallBack( DoShutdownOnAlarmStateAfterCallBack, this ) );
       
  2670         iAlarmOrChargingStateShutdownStarted = ETrue;
       
  2671         }
       
  2672     }
       
  2673 
       
  2674 // ----------------------------------------------------------------------------
       
  2675 // CSysApAppUi::DoShutdownOnAlarmStateAfterCallBack( TAny* aObject )
       
  2676 // ----------------------------------------------------------------------------
       
  2677 
       
  2678 TInt CSysApAppUi::DoShutdownOnAlarmStateAfterCallBack( TAny* aObject )
       
  2679     {
       
  2680     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  2681 
       
  2682     if ( appUi->iTimer )
       
  2683         {
       
  2684         appUi->iTimer->Cancel();
       
  2685         }
       
  2686 
       
  2687     TRAP_IGNORE( appUi->DoShutdownL( EFalse, KDummyReason ) );
       
  2688 
       
  2689     return KErrNone;
       
  2690     }
       
  2691 
       
  2692 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2693 // ----------------------------------------------------------------------------
       
  2694 // CSysApAppUi::StartAnimTiming()
       
  2695 // ----------------------------------------------------------------------------
       
  2696 void CSysApAppUi::StartAnimTiming()
       
  2697     {
       
  2698     TRACES( RDebug::Print( _L("CSysApAppUi::StartAnimTiming() Start animation timer, time %d ms" ), iAnimationShowingTime  ) );
       
  2699 
       
  2700     if ( !iAnimTimer )
       
  2701         {
       
  2702         TRAPD( err, iAnimTimer = CPeriodic::NewL( EPriorityNormal ) );
       
  2703 
       
  2704         if ( err != KErrNone )
       
  2705             {
       
  2706             TRACES( RDebug::Print( _L("CSysApAppUi::StartAnimTiming() CPeriodic::NewL failed %d " ), err ) );
       
  2707             return;
       
  2708             }
       
  2709         }
       
  2710 
       
  2711     iAnimTimer->Start(
       
  2712         iAnimationShowingTime*KCoefficientToMakeMicroToMilliSeconds,
       
  2713         iAnimationShowingTime*KCoefficientToMakeMicroToMilliSeconds,
       
  2714         TCallBack( DoStopAnimTiming, this ) );
       
  2715     }
       
  2716 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2717 
       
  2718 // ----------------------------------------------------------------------------
       
  2719 // CSysApAppUi::DoStopAnimTiming( TAny* aObject )
       
  2720 // ----------------------------------------------------------------------------
       
  2721 
       
  2722 TInt CSysApAppUi::DoStopAnimTiming( TAny* aObject )
       
  2723     {
       
  2724     TInt err(KErrNone);
       
  2725     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  2726 
       
  2727     // This method could theoretically be called by two timers (iAnimTimer and one in CSysApShutdownAnimation),
       
  2728     // so a check is needed to prevent multiple executions.
       
  2729     if ( !(appUi->iShutdownContinued) )
       
  2730         {
       
  2731         appUi->iShutdownContinued = ETrue;
       
  2732 
       
  2733         TRACES( RDebug::Print( _L("CSysApAppUi::DoStopAnimTiming() Animation timer completed or animation skipped" ) ) );
       
  2734 
       
  2735 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2736         if ( appUi->iAnimTimer )
       
  2737             {
       
  2738             appUi->iAnimTimer->Cancel();
       
  2739             }
       
  2740 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2741 
       
  2742         if ( appUi->iTimer )
       
  2743             {
       
  2744             appUi->iTimer->Cancel();
       
  2745             }
       
  2746 
       
  2747         TRACES( RDebug::Print( _L("CSysApAppUi::DoStopAnimTiming() Call ContinueShutdown(...)" ) ) );
       
  2748         appUi->ContinueShutdown();
       
  2749         TRACES( RDebug::Print( _L("CSysApAppUi::DoStopAnimTiming() end") ) );
       
  2750         }
       
  2751 
       
  2752     return err;
       
  2753     }
       
  2754 
       
  2755 
       
  2756 // ----------------------------------------------------------------------------
       
  2757 // CSysApAppUi::StartGprsSuspendedTimer()
       
  2758 // ----------------------------------------------------------------------------
       
  2759 
       
  2760 void CSysApAppUi::StartGprsSuspendedTimer()
       
  2761     {
       
  2762     TRACES( RDebug::Print( _L("CSysApAppUi::StartGprsSuspendedTimer()") ) );
       
  2763     if( !iAlarmOrChargingStateShutdownStarted ) // not relevant if shutting down
       
  2764         {
       
  2765         if ( !iTimer )
       
  2766             {
       
  2767             TRAPD( err, iTimer = CPeriodic::NewL( EPriorityNormal ) );
       
  2768 
       
  2769             if ( err != KErrNone )
       
  2770                 {
       
  2771                 TRACES( RDebug::Print( _L("CSysApAppUi::StartGprsSuspendedTimer: CPeriodic::NewL failed: %d"), err ) );
       
  2772                 return;
       
  2773                 }
       
  2774             }
       
  2775 
       
  2776         iTimer->Cancel();
       
  2777         iTimer->Start( KDelayBeforeShowingGprsSuspendedNote,
       
  2778                        KDelayBeforeShowingGprsSuspendedNote,
       
  2779                        TCallBack( ShowGprsSuspendedNoteAfterCallBack, this ) );
       
  2780         }
       
  2781     }
       
  2782 
       
  2783 // ----------------------------------------------------------------------------
       
  2784 // CSysApAppUi::ShowGprsSuspendedNoteAfterCallBack( TAny* aObject )
       
  2785 // ----------------------------------------------------------------------------
       
  2786 
       
  2787 TInt CSysApAppUi::ShowGprsSuspendedNoteAfterCallBack( TAny* aObject )
       
  2788     {
       
  2789     TRACES( RDebug::Print( _L("CSysApAppUi::ShowGprsSuspendedNoteAfterCallBack") ) );
       
  2790 
       
  2791     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  2792 
       
  2793     if ( appUi->iTimer )
       
  2794         {
       
  2795         appUi->iTimer->Cancel();
       
  2796         }
       
  2797 
       
  2798     // Note is needed if call is still active and used network is not WCDMA
       
  2799     TInt callType = appUi->StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallType );
       
  2800     TInt networkMode = appUi->StateOfProperty( KPSUidNetworkInfo, KNWTelephonyNetworkMode );
       
  2801     TRACES( RDebug::Print(
       
  2802         _L("CSysApAppUi::ShowGprsSuspendedNoteAfterCallBack: callType %d networkMode %d"),
       
  2803         callType, networkMode ) );
       
  2804     if ( EPSCTsyCallTypeCSVoice == callType && ENWNetworkModeWcdma != networkMode )
       
  2805         {
       
  2806         appUi->iGprsSuspendedNoteShown = ETrue;
       
  2807         }
       
  2808     return KErrNone;
       
  2809     }
       
  2810 
       
  2811 // ----------------------------------------------------------------------------
       
  2812 // CSysApAppUi::HandleAccessoryConnectedL()
       
  2813 // ----------------------------------------------------------------------------
       
  2814 
       
  2815 void CSysApAppUi::HandleAccessoryConnectedL( TAccMode aAccessoryState )
       
  2816     {
       
  2817     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryConnectedL( aAccessoryState: %d ) "), aAccessoryState ) );
       
  2818 
       
  2819     if ( aAccessoryState == EAccModeWirelessHeadset ||
       
  2820          aAccessoryState == EAccModeWiredHeadset ||
       
  2821          aAccessoryState == EAccModeHeadphones )
       
  2822         {
       
  2823         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2824         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2825         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOn );
       
  2826         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2827         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2828         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2829         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2830         }
       
  2831     else if ( aAccessoryState == EAccModeLoopset )
       
  2832         {
       
  2833         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2834         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2835         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOn );
       
  2836         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2837         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2838         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2839         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2840         }
       
  2841     else if ( aAccessoryState == EAccModeTextDevice )
       
  2842         {
       
  2843         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2844         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2845         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOn );
       
  2846         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2847         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2848         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2849         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2850         }
       
  2851     else if ( aAccessoryState == EAccModeWirelessCarKit || aAccessoryState == EAccModeWiredCarKit )
       
  2852         {
       
  2853         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2854         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2855         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2856         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2857         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOn );
       
  2858         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2859         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2860         }
       
  2861     else if ( aAccessoryState == EAccModeTVOut )
       
  2862         {
       
  2863         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2864         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2865         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2866         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2867         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2868         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOn );
       
  2869         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2870         }
       
  2871     else if (aAccessoryState == EAccModeHDMI )
       
  2872             {
       
  2873             SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2874                     SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2875                     SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2876                     SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2877                     SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2878                     SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff);
       
  2879                     SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOn );
       
  2880             }
       
  2881 
       
  2882     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  2883     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryConnectedL: swState: %d"), swState ) );
       
  2884 
       
  2885     if( UiReady() || swState == ESwStateSecurityCheck )
       
  2886         {
       
  2887         iSysApLightsController->AccessoryConnectedL( ETrue );
       
  2888         }
       
  2889 
       
  2890     if ( ( ! iIgnoreAccessorySpecificProfileChanges ) && ( ! iSysApOfflineModeController->OfflineModeActive() ) )
       
  2891         {
       
  2892         TInt profileId( 0 );
       
  2893         TInt currentProfile( 0 );
       
  2894         currentProfile = ActiveProfileId();
       
  2895 
       
  2896         if ( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected ) < 1 )
       
  2897             // accessory not connected already
       
  2898              {
       
  2899             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected, 1 );
       
  2900             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApActiveProfileBeforeAccessoryConnected, currentProfile );
       
  2901             }
       
  2902 
       
  2903         if ( aAccessoryState == EAccModeWirelessCarKit )
       
  2904             {
       
  2905             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApWirelessCarkit );
       
  2906             }
       
  2907         else if( aAccessoryState == EAccModeWiredHeadset ||
       
  2908                  aAccessoryState == EAccModeWirelessHeadset )
       
  2909             {
       
  2910             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApHeadset );
       
  2911             }
       
  2912         else if( aAccessoryState == EAccModeLoopset  )
       
  2913             {
       
  2914             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApLoopset );
       
  2915             }
       
  2916         else if( aAccessoryState == EAccModeTextDevice )
       
  2917             {
       
  2918             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApTty );
       
  2919             }
       
  2920         else if( aAccessoryState == EAccModeTVOut || aAccessoryState == EAccModeHDMI )
       
  2921             {
       
  2922             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApTvOut );
       
  2923             }
       
  2924         else if( aAccessoryState == EAccModeHeadphones )
       
  2925             {
       
  2926             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApHeadphones );
       
  2927             }
       
  2928         else if ( aAccessoryState == EAccModeWiredCarKit )
       
  2929             {
       
  2930             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApCarkit );
       
  2931             }
       
  2932         else if ( aAccessoryState == EAccModeMusicStand )
       
  2933             {
       
  2934             profileId = iSysApCenRepController->ProfileIdForSelectedAccessory( ESysApMusicStand );
       
  2935             }
       
  2936 
       
  2937         // Carkit and music stand have also light on permanently option that needs to be checked
       
  2938         if( aAccessoryState == EAccModeWiredCarKit || aAccessoryState == EAccModeMusicStand )
       
  2939             {
       
  2940             // When device is placed on a handsfree cradle, keyguard must be disabled (unless device is locked)
       
  2941             // Note: It is assumed that if carkit/music stand is connected, the phone is in the cradle.
       
  2942             if ( iKeyLockEnabled || iDeviceLockEnabled || iKeyLockOnBeforeCall || iKeyLockOnBeforeAlarm )
       
  2943                 {
       
  2944                 iKeyLockOnBeforeCradle = ETrue;
       
  2945 
       
  2946                 if ( iKeyLockEnabled && !iDeviceLockEnabled )
       
  2947                     {
       
  2948                     KeyLock().DisableWithoutNote();
       
  2949                     }
       
  2950                 }
       
  2951             }
       
  2952 
       
  2953         if( profileId != KActiveProfile )
       
  2954             {
       
  2955             /*-1 because the first item in Accessory default profiles shared data values
       
  2956             is KActiveProfile and that must be subtracted from the index of profile to be activated*/
       
  2957 
       
  2958             profileId -= 1;
       
  2959 
       
  2960             TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryConnectedL: current profile: %d, accessory profile: %d" ),
       
  2961                                currentProfile, profileId ) );
       
  2962 
       
  2963             if ( profileId != currentProfile )
       
  2964                 {
       
  2965                 iAccessoryJustConnected = ETrue;
       
  2966                 iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileUpdateRequired, 1 );
       
  2967                 ActivateProfileL( profileId );
       
  2968                 }
       
  2969             }
       
  2970         }
       
  2971     SetIhfIndicatorL();
       
  2972     SetHacIndicatorL();
       
  2973     }
       
  2974 
       
  2975 // ----------------------------------------------------------------------------
       
  2976 // CSysApAppUi::HandleAccessoryDisconnectedL()
       
  2977 // ----------------------------------------------------------------------------
       
  2978 
       
  2979 void CSysApAppUi::HandleAccessoryDisconnectedL()
       
  2980     {
       
  2981     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryDisconnectedL()" ) ) );
       
  2982 
       
  2983 
       
  2984     TAccMode accessoryState(EAccModeHandPortable);
       
  2985     if ( iSysApAccessoryObserver )
       
  2986         {
       
  2987         accessoryState = iSysApAccessoryObserver->GetAccessoryMode();
       
  2988         }
       
  2989 
       
  2990     if ( accessoryState == EAccModeHandPortable )
       
  2991         {
       
  2992         SetIndicatorStateL( EAknIndicatorTvOut, EAknIndicatorStateOff );
       
  2993         SetIndicatorStateL( EAknIndicatorLoopset, EAknIndicatorStateOff );
       
  2994         SetIndicatorStateL( EAknIndicatorHeadset, EAknIndicatorStateOff );
       
  2995         SetIndicatorStateL( EAknIndicatorTTY,     EAknIndicatorStateOff );
       
  2996         SetIndicatorStateL( EAknIndicatorHeadsetUnavailable, EAknIndicatorStateOff );
       
  2997         SetIndicatorStateL( EAknIndicatorCarkit, EAknIndicatorStateOff );
       
  2998         SetIndicatorStateL(  EAknIndicatorHDMI, EAknIndicatorStateOff );
       
  2999 
       
  3000         iSysApLightsController->AccessoryConnectedL( EFalse );
       
  3001 
       
  3002         if ( ! iIgnoreAccessorySpecificProfileChanges )
       
  3003             {
       
  3004             TInt activeProfile ( ActiveProfileId() );
       
  3005 
       
  3006             TInt activeProfileBeforeConnectingAccessory(
       
  3007                  iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApActiveProfileBeforeAccessoryConnected )
       
  3008                                                         );
       
  3009             if ( activeProfileBeforeConnectingAccessory < 0 ) // error
       
  3010                 {
       
  3011                 activeProfileBeforeConnectingAccessory = 0; // General Profile
       
  3012                 }
       
  3013             TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryDisconnectedL: active profile now: %d, active profile before: %d," ),
       
  3014                                    activeProfile, activeProfileBeforeConnectingAccessory ) );
       
  3015 
       
  3016             if ( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileUpdateRequired ) == 1 )
       
  3017                 {
       
  3018                 iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileUpdateRequired, 0 );
       
  3019                 if ( activeProfile != activeProfileBeforeConnectingAccessory && ! iSysApOfflineModeController->OfflineModeActive() )
       
  3020                     {
       
  3021                     ActivateProfileL( activeProfileBeforeConnectingAccessory );
       
  3022                     }
       
  3023                 }
       
  3024             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected, 0 );
       
  3025             }
       
  3026         }
       
  3027 
       
  3028     SetIhfIndicatorL();
       
  3029     SetHacIndicatorL();
       
  3030 
       
  3031     // If lock disabled because of accessory, reactivate it, unless phone call or alarm is ongoing
       
  3032     if ( iKeyLockOnBeforeCradle )
       
  3033         {
       
  3034         iKeyLockOnBeforeCradle = EFalse;
       
  3035         if ( !iKeyLockOnBeforeCall && !iKeyLockOnBeforeAlarm )
       
  3036             {
       
  3037             if ( !iDeviceLockEnabled )
       
  3038                 {
       
  3039                 KeyLock().EnableKeyLock();
       
  3040                 }
       
  3041             else
       
  3042                 {
       
  3043                 KeyLock().EnableAutoLockEmulation();
       
  3044                 }
       
  3045             }
       
  3046         }
       
  3047     }
       
  3048 
       
  3049 // ----------------------------------------------------------------------------
       
  3050 // CSysApAppUi::HandleAccessoryProfileInStartupL()
       
  3051 // ----------------------------------------------------------------------------
       
  3052 
       
  3053 void CSysApAppUi::HandleAccessoryProfileInStartupL()
       
  3054     {
       
  3055     TRACES( RDebug::Print( _L( "CSysApAppUi::HandleAccessoryProfileInStartupL" ) ) );
       
  3056 
       
  3057     if ( !iSysApOfflineModeController->OfflineModeActive() )
       
  3058         {
       
  3059         iIgnoreAccessorySpecificProfileChanges = EFalse;
       
  3060         TBool accessoryConnectedInShutdown( EFalse );
       
  3061         TInt accessoryTemp( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected ) );
       
  3062         if ( accessoryTemp == 1 )
       
  3063             {
       
  3064             accessoryConnectedInShutdown = ETrue;
       
  3065             }
       
  3066 
       
  3067         TBool accessoryConnectedNow ( EFalse );
       
  3068 
       
  3069         TAccMode accessoryState(EAccModeHandPortable);
       
  3070         if ( iSysApAccessoryObserver )
       
  3071             {
       
  3072             accessoryState = iSysApAccessoryObserver->GetAccessoryMode();
       
  3073             }
       
  3074 
       
  3075         if ( accessoryState != EAccModeHandPortable )
       
  3076             {
       
  3077             accessoryConnectedNow = ETrue;
       
  3078             }
       
  3079         TRACES( RDebug::Print( _L( "CSysApAppUi::HandleAccessoryProfileInStartupL: accessoryConnectedInShutdown: %d, accessoryConnectedNow: %d" ),
       
  3080                               accessoryConnectedInShutdown, accessoryConnectedNow ) );
       
  3081 
       
  3082         if ( accessoryConnectedInShutdown && !accessoryConnectedNow )
       
  3083             {
       
  3084             HandleAccessoryDisconnectedL();
       
  3085             }
       
  3086         else if ( !accessoryConnectedInShutdown && accessoryConnectedNow )
       
  3087             {
       
  3088             HandleAccessoryConnectedL( accessoryState );
       
  3089             }
       
  3090         else if ( !accessoryConnectedNow )
       
  3091             {
       
  3092             TInt activeProfile ( ActiveProfileId() );
       
  3093             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApActiveProfileBeforeAccessoryConnected, activeProfile );
       
  3094             }
       
  3095         }
       
  3096     }
       
  3097 
       
  3098 #ifndef RD_MULTIPLE_DRIVE
       
  3099 
       
  3100 // ----------------------------------------------------------------------------
       
  3101 // CSysApAppUi::ResolveUidFromThread()
       
  3102 // ----------------------------------------------------------------------------
       
  3103 TInt32 CSysApAppUi::ResolveUidFromThread( TUint aThreadId ) const
       
  3104     {
       
  3105     TInt resolvedUid = 0;
       
  3106 
       
  3107     RThread appThread;
       
  3108     TInt err = appThread.Open( aThreadId );
       
  3109 
       
  3110     if ( err == KErrNone )
       
  3111         {
       
  3112         resolvedUid = appThread.SecureId().iId;
       
  3113         }
       
  3114 
       
  3115     appThread.Close();
       
  3116 
       
  3117     TRACES( RDebug::Print( _L("CSysApAppUi::ResolveUidFromThread: err=%d, aThreadId=%d, resolvedUid=0x%x"),
       
  3118                            err, aThreadId, resolvedUid ) );
       
  3119 
       
  3120     return resolvedUid;
       
  3121     }
       
  3122 
       
  3123 // ----------------------------------------------------------------------------
       
  3124 // CSysApAppUi::CloseUIAppsInHotSwapL()
       
  3125 // ----------------------------------------------------------------------------
       
  3126 void CSysApAppUi::CloseUIAppsInHotSwapL()
       
  3127     {
       
  3128     TRACES( RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL") ) );
       
  3129 
       
  3130     CArrayFixFlat<TInt>* wgIds=new(ELeave) CArrayFixFlat<TInt>(4);
       
  3131     CleanupStack::PushL(wgIds);
       
  3132     User::LeaveIfError(iCoeEnv->WsSession().WindowGroupList(0, wgIds));
       
  3133     TInt lastEntry=wgIds->Count()-1;
       
  3134     TRACES( RDebug::Print( _L( "CSysApAppUi::CloseUIAppsInHotSwapL: Found %d UI applications running." ), lastEntry + 1 ) );
       
  3135     TInt numberOfApplicationsToShutDown( 0 );
       
  3136     iApplicationScanningRoundNumber++;
       
  3137 
       
  3138     for ( TInt i=lastEntry; i>=0; i--)
       
  3139         {
       
  3140         CApaWindowGroupName* doomedApp = CApaWindowGroupName::NewLC(iCoeEnv->WsSession(),wgIds->At(i));
       
  3141 
       
  3142         TBool systemApp = doomedApp->IsSystem();
       
  3143         TBool hiddenApp = doomedApp->Hidden();
       
  3144 
       
  3145         if ( systemApp || hiddenApp )
       
  3146             {
       
  3147             TRACES (
       
  3148                     TPtrC caption=doomedApp->Caption();
       
  3149                     RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Privileged app \"%S\" UID 0x%x will not be closed, system: %d, hidden: %d" ),
       
  3150                                    &caption,
       
  3151                                    doomedApp->AppUid().iUid,
       
  3152                                    systemApp,
       
  3153                                    hiddenApp);
       
  3154                     );
       
  3155             }
       
  3156         else if ( ( iFileManagerCloseDisabled && doomedApp->AppUid().iUid == KFileManagerAppUid ) ||
       
  3157                   doomedApp->AppUid().iUid == KAutolockAppUid )
       
  3158             {
       
  3159             // An additional failure protection: Autolock must not be closed in any circumstances
       
  3160             TRACES (
       
  3161                     TPtrC caption=doomedApp->Caption();
       
  3162                     RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Privileged app \"%S\" will not be closed, UID 0x%x"),
       
  3163                                    &caption,
       
  3164                                    doomedApp->AppUid().iUid );
       
  3165                     );
       
  3166             }
       
  3167         else if ( doomedApp->AppUid().iUid == 0 && !iTimeToKill )
       
  3168             {
       
  3169 #ifdef _DEBUG
       
  3170             TApaTask task(iCoeEnv->WsSession());
       
  3171             task.SetWgId(wgIds->At(i));
       
  3172             TUint threadId = (TUint)(task.ThreadId());
       
  3173             TInt32 uid = ResolveUidFromThread( threadId );
       
  3174             // CApaWindowGroupName stores the application UID, and in early application startup state AppUid()-method returns 0
       
  3175             // In order not to accidentally close application that hasn't yet its window group properly set up, decicision whether
       
  3176             // to close the application is postponed, in maximum to the end of the waiting period.
       
  3177             TRACES ( RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Unknown app will not be closed yet, threadId=%d, UID 0x%x, size=%d"),
       
  3178                                     threadId, uid, sizeof(TApaTask) ) );
       
  3179 #endif // _DEBUG
       
  3180             numberOfApplicationsToShutDown++; // wait note must be displayed
       
  3181             }
       
  3182         else
       
  3183             {
       
  3184             numberOfApplicationsToShutDown++;
       
  3185             TApaTask* task = new (ELeave) TApaTask(iCoeEnv->WsSession());
       
  3186             CleanupDeletePushL(task);
       
  3187             task->SetWgId(wgIds->At(i));
       
  3188 
       
  3189             TRACES (
       
  3190                     const TDesC& caption = doomedApp->Caption();
       
  3191                     const TDesC& docname = doomedApp->DocName();
       
  3192                     const TDesC& wgname = doomedApp->WindowGroupName();
       
  3193                     TUid uid = doomedApp->AppUid();
       
  3194                     RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Closing app \"%S\" (ThreadId %d, WgId %d, UID 0x%X); Docname: %S, WGName : %S"),
       
  3195                                    &caption,
       
  3196                                    (TUint)(task->ThreadId()),
       
  3197                                    wgIds->At(i),
       
  3198                                    uid.iUid,
       
  3199                                    &docname,
       
  3200                                    &wgname);
       
  3201                     );
       
  3202 
       
  3203             ResolveUidFromThread( (TUint)(task->ThreadId()) );
       
  3204 
       
  3205             if ( iApplicationScanningRoundNumber == 1 )
       
  3206                 {
       
  3207                 task->EndTask(); // applications are kindly requested to close themselves on the first round
       
  3208                 }
       
  3209             else if ( iTimeToKill )
       
  3210                 {
       
  3211                 TBool doKill = ETrue;
       
  3212 
       
  3213                 // final check, window group may still be uninitialized so use thread id for checking UID
       
  3214                 if ( doomedApp->AppUid().iUid == 0 )
       
  3215                     {
       
  3216                     if ( ResolveUidFromThread( (TUint)(task->ThreadId()) ) == KAutolockAppUid )
       
  3217                         {
       
  3218                         doKill = EFalse;
       
  3219                         }
       
  3220                     }
       
  3221 
       
  3222                 if ( doKill )
       
  3223                     {
       
  3224                     TRACES( RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Killing app \"%S\""), &caption ) );
       
  3225                     task->KillTask(); // used after timeout on the last round
       
  3226                     }
       
  3227                 }
       
  3228 
       
  3229             CleanupStack::PopAndDestroy(); // task
       
  3230             }
       
  3231         CleanupStack::PopAndDestroy();  // doomedApp
       
  3232         }
       
  3233     CleanupStack::PopAndDestroy(); // wgIds
       
  3234 
       
  3235     if ( numberOfApplicationsToShutDown > 0 && iApplicationScanningRoundNumber <= KMaxExitTimeInHotSwap )
       
  3236         {
       
  3237         TRACES( RDebug::Print( _L("CSysApAppUi::CloseUIAppsInHotSwapL: Show wait note, unless already showing") ) );
       
  3238         if ( !iSysApWaitNote )
       
  3239             {
       
  3240             HBufC* noteStringBuf = StringLoader::LoadLC( R_QTN_MEMC_WAIT_EJECT, iEikonEnv );
       
  3241             iSysApWaitNote = CSysApWaitNote::NewL( iSysApFeatureManager->CoverDisplaySupported() );
       
  3242             iSysApWaitNote->ShowNoteL( EClosingApplicationsNote, noteStringBuf );
       
  3243             CleanupStack::PopAndDestroy();
       
  3244             }
       
  3245 
       
  3246         if ( iApplicationScanningRoundNumber >= KMaxExitTimeInHotSwap )
       
  3247             {
       
  3248             iTimeToKill = ETrue;
       
  3249             }
       
  3250 
       
  3251         if ( !iSysApTimer )
       
  3252             {
       
  3253             iSysApTimer = new ( ELeave ) CSysApTimer( *this );
       
  3254             }
       
  3255 
       
  3256         iSysApTimer->ActivateTimerL( KApplicationScanningInterval );
       
  3257         }
       
  3258     else
       
  3259         {
       
  3260         iFileManagerCloseDisabled = EFalse;
       
  3261         CompleteAppsShuttingInHotSwapL();
       
  3262         }
       
  3263     }
       
  3264 
       
  3265 #endif // RD_MULTIPLE_DRIVE
       
  3266 
       
  3267 // ----------------------------------------------------------------------------
       
  3268 // CSysApAppUi::TimerExpiredL()
       
  3269 // ----------------------------------------------------------------------------
       
  3270 void CSysApAppUi::TimerExpiredL()
       
  3271     {
       
  3272 #ifndef RD_MULTIPLE_DRIVE
       
  3273     CloseUIAppsInHotSwapL();
       
  3274 #endif // RD_MULTIPLE_DRIVE
       
  3275     }
       
  3276 
       
  3277 #ifndef RD_MULTIPLE_DRIVE
       
  3278 // ----------------------------------------------------------------------------
       
  3279 // CSysApAppUi::CompleteAppsShuttingInHotSwapL()
       
  3280 // ----------------------------------------------------------------------------
       
  3281 void CSysApAppUi::CompleteAppsShuttingInHotSwapL()
       
  3282     {
       
  3283     TRACES( RDebug::Print( _L("CSysApAppUi::CompleteAppsShuttingInHotSwapL iMMCEjectUsed=%d, iMMCInserted=%d"), iMMCEjectUsed, iMMCInserted ) );
       
  3284     CancelWaitNote();
       
  3285 
       
  3286     if ( iMMCEjectUsed ) // From Powerkey Menu
       
  3287         {
       
  3288         DismountMMC();
       
  3289         TRACES( RDebug::Print( _L( "CSysApAppUi::CompleteAppsShuttingInHotSwapL: Show note: Remove MMC and press OK...." ) ) );
       
  3290         ShowQueryL( ESysApRemoveMmcNote );
       
  3291         }
       
  3292     else if ( !iMMCInserted ) // The MMC might have been already re-mounted, that's why !iMMCInserted
       
  3293         {
       
  3294         ShowMMCDismountedDialogL();
       
  3295         }
       
  3296     }
       
  3297 #endif // RD_MULTIPLE_DRIVE
       
  3298 
       
  3299 // ----------------------------------------------------------------------------
       
  3300 // CSysApAppUi::InitCloseSimApplicationsL()
       
  3301 // ----------------------------------------------------------------------------
       
  3302 void CSysApAppUi::InitCloseSimApplicationsL()
       
  3303     {
       
  3304     iApplicationScanningRoundNumberInBtSap = 0;
       
  3305     iTimeToKillInBtSap = EFalse;
       
  3306     CloseSimApplicationsL();
       
  3307     }
       
  3308 
       
  3309 // ----------------------------------------------------------------------------
       
  3310 // CSysApAppUi::CloseSimApplicationsL()
       
  3311 // ----------------------------------------------------------------------------
       
  3312 void CSysApAppUi::CloseSimApplicationsL()
       
  3313     {
       
  3314     iApplicationScanningRoundNumberInBtSap++;
       
  3315     TRACES( RDebug::Print( _L("CSysApAppUi::CloseSimApplicationsL: scanning round = %d"),
       
  3316                            iApplicationScanningRoundNumberInBtSap ) );
       
  3317 
       
  3318     if ( iApplicationScanningRoundNumberInBtSap == KMaxExitTimeInBtSap )
       
  3319         {
       
  3320         iTimeToKillInBtSap = ETrue;
       
  3321         }
       
  3322 
       
  3323     const TInt KNumberOfSimDependantApps( 7 );
       
  3324     TUid simDependantAppUid[ KNumberOfSimDependantApps ];
       
  3325     simDependantAppUid[ 0 ] = KSysApGSUid;
       
  3326     simDependantAppUid[ 1 ] = KSysApSATUid;
       
  3327     simDependantAppUid[ 2 ] = KSysApMailboxUid;
       
  3328     simDependantAppUid[ 3 ] = KSysApSpeedDialingUid;
       
  3329     simDependantAppUid[ 4 ] = KSysApSimDirectoryUid;
       
  3330     simDependantAppUid[ 5 ] = KSysApMCEUid;
       
  3331     simDependantAppUid[ 6 ] = KSysApCellBroadcastMessagesUid;
       
  3332 
       
  3333     TBool appsExiting( EFalse );
       
  3334     TApaTaskList apaTaskList( CCoeEnv::Static()->WsSession() );
       
  3335 
       
  3336     for ( TInt i = 0; i < KNumberOfSimDependantApps; i++ )
       
  3337         {
       
  3338         TApaTask apaTask = apaTaskList.FindApp( simDependantAppUid[ i ] );
       
  3339         if ( apaTask.Exists() )
       
  3340             {
       
  3341             appsExiting = ETrue;
       
  3342             if ( iApplicationScanningRoundNumberInBtSap == 1 )
       
  3343                 {
       
  3344                 apaTask.EndTask();  // applications are kindly requested to close themselves on the first round
       
  3345                 }
       
  3346             else if ( iTimeToKillInBtSap )
       
  3347                 {
       
  3348                 apaTask.KillTask(); // used after timeout on the last round
       
  3349                 }
       
  3350             }
       
  3351         }
       
  3352 
       
  3353     if ( !appsExiting || iTimeToKillInBtSap )
       
  3354         {
       
  3355         iSysApBtSapController->SimApplicationsClosed();
       
  3356         }
       
  3357     else
       
  3358         {
       
  3359         if ( !iSapTimer )
       
  3360             {
       
  3361             iSapTimer = CPeriodic::NewL( EPriorityNormal );
       
  3362             }
       
  3363         iSapTimer->Cancel();
       
  3364         iSapTimer->Start( KDelayBeforeNextScanningRound,
       
  3365                           KDelayBeforeNextScanningRound,
       
  3366                           TCallBack( DoCloseSimApplicationsAfterCallBack, this ) );
       
  3367         }
       
  3368     }
       
  3369 
       
  3370 // ----------------------------------------------------------------------------
       
  3371 // CSysApAppUi::DoCloseSimApplicationsAfterCallBack
       
  3372 // ----------------------------------------------------------------------------
       
  3373 TInt CSysApAppUi::DoCloseSimApplicationsAfterCallBack( TAny* aObject )
       
  3374     {
       
  3375     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  3376 
       
  3377     if ( appUi->iSapTimer )
       
  3378         {
       
  3379         appUi->iSapTimer->Cancel();
       
  3380         }
       
  3381 
       
  3382     TRAP_IGNORE( appUi->CloseSimApplicationsL() );
       
  3383 
       
  3384     return KErrNone;
       
  3385     }
       
  3386 
       
  3387 // ----------------------------------------------------------------------------
       
  3388 // CSysApAppUi::AlertUiAlertingL( const TBool aAlerting )
       
  3389 // ----------------------------------------------------------------------------
       
  3390 void CSysApAppUi::AlertUiAlertingL( const TBool aAlerting )
       
  3391     {
       
  3392     TRACES( RDebug::Print( _L("CSysApAppUi::AlertUiAlerting aAlerting:%d"), aAlerting ) );
       
  3393 
       
  3394     if ( aAlerting )
       
  3395         {
       
  3396         TInt swState;
       
  3397         RProperty::Get( KPSUidStartup, KPSGlobalSystemState, swState );
       
  3398 
       
  3399         if( swState == ESwStateCharging )
       
  3400             {
       
  3401             SetStarterState( RStarterSession::EAlarm );
       
  3402             }
       
  3403         }
       
  3404 
       
  3405     iSysApLightsController->AlarmOccuredL( aAlerting );
       
  3406     }
       
  3407 
       
  3408 // ----------------------------------------------------------------------------
       
  3409 // CSysApAppUi::AlertUiKeyLockOff( const TBool aKeyLockOff )
       
  3410 // ----------------------------------------------------------------------------
       
  3411 
       
  3412 void CSysApAppUi::AlertUiKeyLockOff( const TBool aKeyLockOff )
       
  3413     {
       
  3414     TRACES( RDebug::Print( _L("CSysApAppUi::AlertUiKeyLockOff aKeyLockOff:%d, devicelock:%d"), 
       
  3415         aKeyLockOff, iDeviceLockEnabled ) );
       
  3416     
       
  3417     if( aKeyLockOff )
       
  3418         {
       
  3419         // Notification to release keypad might come several times if e.g. calls are received
       
  3420         if ( !iKeyLockOnBeforeAlarm )
       
  3421             {
       
  3422             if ( iKeyLockEnabled || iKeyLockOnBeforeCradle || iKeyLockOnBeforeCall )
       
  3423                 {
       
  3424                 iKeyLockOnBeforeAlarm = ETrue;
       
  3425                 }
       
  3426             }
       
  3427         KeyLock().DisableWithoutNote();
       
  3428         }
       
  3429     else
       
  3430         {
       
  3431         if (iDeviceLockEnabled)
       
  3432             {
       
  3433             // Re-enable keylock in devicelock case only if phone call is not ongoing or is 
       
  3434             // connected. Otherwise e.g. messages can be read using softkeys during ongoing call.
       
  3435             TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  3436             if ( callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateConnected )
       
  3437                 {
       
  3438                 KeyLock().EnableAutoLockEmulation();
       
  3439                 }
       
  3440             }
       
  3441         else if ( iKeyLockOnBeforeAlarm && !iKeyLockOnBeforeCradle && !iKeyLockOnBeforeCall )
       
  3442             {
       
  3443             KeyLock().EnableKeyLock();
       
  3444             }
       
  3445         iKeyLockOnBeforeAlarm = EFalse;
       
  3446         }
       
  3447     }
       
  3448 
       
  3449 // ----------------------------------------------------------------------------
       
  3450 // CSysApAppUi::HandleLightsRequireL()
       
  3451 // ----------------------------------------------------------------------------
       
  3452 
       
  3453 void CSysApAppUi::HandleLightsRequireL() const
       
  3454     {
       
  3455     iSysApLightsController->HandleLightsRequireL();
       
  3456     }
       
  3457 
       
  3458 // ----------------------------------------------------------------------------
       
  3459 // CSysApAppUi::HandleRawKeyEventLightsRequireL()
       
  3460 // ----------------------------------------------------------------------------
       
  3461 
       
  3462 void CSysApAppUi::HandleRawKeyEventLightsRequireL() const
       
  3463     {
       
  3464     iSysApLightsController->HandleRawKeyEventLightsRequireL();
       
  3465     }
       
  3466 
       
  3467 // ----------------------------------------------------------------------------
       
  3468 // CSysApAppUi::HandleForcedLightsVTRequireL( const TInt aLightParameter )
       
  3469 // ----------------------------------------------------------------------------
       
  3470 
       
  3471 void CSysApAppUi::HandleForcedLightsVTRequireL( const TInt aLightsParameter ) const
       
  3472     {
       
  3473     iSysApLightsController->HandleForcedLightsVTRequireL( aLightsParameter );
       
  3474     }
       
  3475 
       
  3476 // ----------------------------------------------------------------------------
       
  3477 // CSysApAppUi::HandleForcedLightsSSRequireL( const TInt aLightParameter )
       
  3478 // ----------------------------------------------------------------------------
       
  3479 
       
  3480 void CSysApAppUi::HandleForcedLightsSSRequireL( const TInt aLightsParameter ) const
       
  3481     {
       
  3482     iSysApLightsController->HandleForcedLightsSSRequireL( aLightsParameter );
       
  3483     }
       
  3484 
       
  3485 // ---------------------------------------------------------------------------- 
       
  3486 // CSysApAppUi::HandleForcedLightsATCRequireL( const TInt aLightParameter ) 
       
  3487 // ---------------------------------------------------------------------------- 
       
  3488 void CSysApAppUi::HandleForcedLightsATCRequireL( const TInt aLightsParameter ) const 
       
  3489     { 
       
  3490     iSysApLightsController->HandleForcedLightsATCRequireL( aLightsParameter ); 
       
  3491     } 
       
  3492       
       
  3493 // ----------------------------------------------------------------------------
       
  3494 // CSysApAppUi::SwitchLightsOnSoftRejectL()
       
  3495 // ----------------------------------------------------------------------------
       
  3496 void CSysApAppUi::SwitchLightsOnSoftRejectL()
       
  3497     {
       
  3498     iSysApLightsController->SwitchLightsOnSoftRejectL();
       
  3499     }
       
  3500 
       
  3501 // ----------------------------------------------------------------------------
       
  3502 // CSysApAppUi::StateOfProperty()
       
  3503 // ----------------------------------------------------------------------------
       
  3504 TInt CSysApAppUi::StateOfProperty( const TUid& aCategory, const TUint aKey ) const
       
  3505     {
       
  3506     TInt err( KErrNone );
       
  3507     TInt value( 0 );
       
  3508     err = RProperty::Get( aCategory, aKey, value );
       
  3509     if ( err )
       
  3510         {
       
  3511         TRACES( RDebug::Print( _L("CSysApAppUi::StateOfProperty. RProperty::Get: err=%d"), err ) );
       
  3512         return err;
       
  3513         }
       
  3514     return value;
       
  3515     }
       
  3516 
       
  3517 // ----------------------------------------------------------------------------
       
  3518 // CSysApAppUi::BluetoothPowerMode()
       
  3519 // ----------------------------------------------------------------------------
       
  3520 TInt CSysApAppUi::BluetoothPowerMode() const
       
  3521     {
       
  3522     return iSysApCenRepBtObserver->BluetoothPowerMode();
       
  3523     }
       
  3524 
       
  3525 // ----------------------------------------------------------------------------
       
  3526 // CSysApAppUi::ActivateProfileL( const TInt aProfileId ) const
       
  3527 // ----------------------------------------------------------------------------
       
  3528 
       
  3529 void CSysApAppUi::ActivateProfileL( const TInt aProfileId ) const
       
  3530     {
       
  3531     TRACES( RDebug::Print( _L("CSysApAppUi::ActivateProfile aProfileId: %d"), aProfileId ) );
       
  3532     //No use of returning the Profile error code since it only tells if the activation was succesfull or not.
       
  3533     iProfileEngine->SetActiveProfileL( aProfileId );
       
  3534     }
       
  3535 
       
  3536 // ----------------------------------------------------------------------------
       
  3537 // CSysApAppUi::ActivateOnlineProfileL() const
       
  3538 // ----------------------------------------------------------------------------
       
  3539 
       
  3540 void CSysApAppUi::ActivateOnlineProfileL() const
       
  3541     {
       
  3542     ActivateProfileL( iProfileToBeActivated );
       
  3543     }
       
  3544 
       
  3545 // ----------------------------------------------------------------------------
       
  3546 // CSysApAppUi::ActiveProfileNameL( TPtr aProfileName ) const
       
  3547 // ----------------------------------------------------------------------------
       
  3548 
       
  3549 void CSysApAppUi::ActiveProfileNameL( TPtr aProfileName )
       
  3550     {
       
  3551     TRACES( RDebug::Print( _L("CSysApAppUi::ActiveProfileNameL START") ) );
       
  3552     MProfile* profile = iProfileEngine->ActiveProfileL();
       
  3553     const MProfileName& mProfileName = profile->ProfileName();
       
  3554     aProfileName = mProfileName.Name();
       
  3555     profile->Release();
       
  3556     TRACES( RDebug::Print( _L("CSysApAppUi::ActiveProfileNameL END") ) );
       
  3557     }
       
  3558 
       
  3559 // ----------------------------------------------------------------------------
       
  3560 // CSysApAppUi::CheckSilentModeL()
       
  3561 // ----------------------------------------------------------------------------
       
  3562 void CSysApAppUi::CheckSilentModeL()
       
  3563     {
       
  3564     TBool isSilent( EFalse );
       
  3565     MProfile* profile = iProfileEngine->ActiveProfileL();
       
  3566     isSilent = profile->IsSilent();
       
  3567     profile->Release();
       
  3568     if ( isSilent )
       
  3569         {
       
  3570         TRACES( RDebug::Print( _L("CSysApAppUi::CheckSilentModeL: active profile is SILENT") ) );
       
  3571         iSysApLightsController->SetSilentModeOn( ETrue );
       
  3572         }
       
  3573     else
       
  3574         {
       
  3575         TRACES( RDebug::Print( _L("CSysApAppUi::CheckSilentModeL: active profile is NOT SILENT") ) );
       
  3576         iSysApLightsController->SetSilentModeOn( EFalse );
       
  3577         }
       
  3578     }
       
  3579 
       
  3580 // ----------------------------------------------------------------------------
       
  3581 // CSysApAppUi::HandleProfileChangedL( const TInt aValue )
       
  3582 // ----------------------------------------------------------------------------
       
  3583 void CSysApAppUi::HandleProfileChangedL( const TInt aNewProfileId )
       
  3584     {
       
  3585     TRACES( RDebug::Print( _L("CSysApAppUi::HandleProfileChangedL: aNewProfileId=%d"), aNewProfileId ) );
       
  3586     CheckSilentModeL();
       
  3587     if ( iHandleNextProfileEvent )
       
  3588         {
       
  3589         if ( iAccessoryJustConnected )
       
  3590             {
       
  3591             iAccessoryJustConnected = EFalse;
       
  3592             }
       
  3593         else
       
  3594             {
       
  3595             // if the user delibarately changes profiles, the selected profile will
       
  3596             // remain active after disconnecting an accessory.
       
  3597             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileUpdateRequired, 0 );
       
  3598             }
       
  3599 
       
  3600 		// Added as a part of REQ 415-6750 : Conditional UI-note for "Activated profile"
       
  3601         TInt   noNeedToShowTheNote = 0;      // if True, then note should not be shown
       
  3602         TInt    err = KErrNone;                            
       
  3603                                      
       
  3604       	err = RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsProfileActivatedNote, 
       
  3605                               noNeedToShowTheNote );   
       
  3606 		/*
       
  3607   		If there occured an error, it is likely caused by the non-existing property. 
       
  3608   		So trying to set it only if no error occured for maintaining the default behavior. 
       
  3609 		*/       
       
  3610         if( KErrNone == err )
       
  3611             { 
       
  3612             TInt error = RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsProfileActivatedNote, 
       
  3613                                      ECoreAppUIsProfileActivatedNoteNotShown );
       
  3614             }
       
  3615                
       
  3616         if(!noNeedToShowTheNote)  //    The value doesn't deny the showing, then...
       
  3617             {
       
  3618             ShowProfileNoteL();
       
  3619             }    
       
  3620         }
       
  3621 
       
  3622     if ( aNewProfileId != KOfflineModeProfileId )
       
  3623         {
       
  3624         iActiveProfileBeforeOfflineMode = aNewProfileId;
       
  3625         iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApProfileBeforeOfflineMode, aNewProfileId );
       
  3626         }
       
  3627 
       
  3628     if ( aNewProfileId == KOfflineModeProfileId && ! iSysApOfflineModeController->OfflineModeActive() )
       
  3629         {
       
  3630         if ( BtSapEnabled() )
       
  3631             {
       
  3632             // Choosing "Offline Mode" will disconnect BT SAP
       
  3633             // SwitchFromOnlineToOfflineModeL() will be called from CSysApBtSapController
       
  3634             iSysApBtSapController->SwitchingToOffline();
       
  3635             iSysApBtSapController->Disconnect();
       
  3636             }
       
  3637         else
       
  3638             {
       
  3639             SwitchFromOnlineToOfflineModeL();
       
  3640             }
       
  3641         }
       
  3642     else if ( aNewProfileId != KOfflineModeProfileId && iSysApOfflineModeController->OfflineModeActive() )
       
  3643         {
       
  3644         if ( BtSapEnabled() )
       
  3645             {
       
  3646             iSysApOfflineModeController->DoNotActivateRF(); // Will be activated after BT SAP disconnection
       
  3647             }
       
  3648         iSysApOfflineModeController->SwitchFromOfflineToOnlineModeL();
       
  3649         }
       
  3650     iHandleNextProfileEvent = ETrue;
       
  3651     }
       
  3652 
       
  3653 
       
  3654 // ----------------------------------------------------------------------------
       
  3655 // CSysApAppUi::RestoreProfileL()
       
  3656 // ----------------------------------------------------------------------------
       
  3657 
       
  3658 void CSysApAppUi::RestoreProfileL( const TBool aOffline )
       
  3659     {
       
  3660     iHandleNextProfileEvent = EFalse;
       
  3661     if ( aOffline )
       
  3662         {
       
  3663         ActivateProfileL( KOfflineModeProfileId );
       
  3664         }
       
  3665     else
       
  3666         {
       
  3667         ActivateProfileL( iActiveProfileBeforeOfflineMode );
       
  3668         }
       
  3669     }
       
  3670 
       
  3671 // ----------------------------------------------------------------------------
       
  3672 // CSysApAppUi::ActiveProfileId()
       
  3673 // ----------------------------------------------------------------------------
       
  3674 
       
  3675 TInt CSysApAppUi::ActiveProfileId()
       
  3676     {
       
  3677     return iProfileEngine->ActiveProfileId();
       
  3678     }
       
  3679 
       
  3680 
       
  3681 // ----------------------------------------------------------------------------
       
  3682 // CSysApAppUi::AddMmcMenuItemsL()
  1161 // ----------------------------------------------------------------------------
  3683 // ----------------------------------------------------------------------------
  1162 //
  3684 //
  1163 TInt CSysApAppUi::ShowShutdownImage( TInt aBitmapId )
  3685 void CSysApAppUi::AddMmcMenuItemsL( CDesCArray*& aProfileNameCDesCArray, RArray<TInt>& aItemIdArray,
  1164     {
  3686                                     TInt& aPowerMenuItemIndex )
  1165     TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImage") ) );
  3687     {
  1166 
  3688     TInt propertyValue( StateOfProperty( KPSUidUsbWatcher,
  1167     TRAPD( err, ShowShutdownImageL( aBitmapId ) );
  3689             KUsbWatcherSelectedPersonality ) );
  1168 
  3690 
  1169     if ( err != KErrNone )
  3691     HBufC* itemStringBuf;
  1170         {
  3692 #ifndef RD_MULTIPLE_DRIVE
  1171         TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImageL failed, err=%d"), err ) );
  3693     iPowerkeyMenuEjectSelection = KErrAccessDenied;
  1172         }
  3694     if ( !IsEncryptionOperationOngoingL() )
  1173 
  3695         {
  1174     return err;
  3696         if ( iSysApFeatureManager->MmcHotSwapSupported() &&
  1175     }
  3697                 iMMCInserted &&
  1176 
  3698                 iSysApFeatureManager->EjectRequiredInPowerMenu() &&
  1177 
  3699                 propertyValue != KUsbPersonalityIdMS )
  1178 // ----------------------------------------------------------------------------
  3700             {
  1179 // CSysApAppUi::ShowShutdownImageL
  3701             iPowerkeyMenuEjectShown = ETrue;
  1180 // ----------------------------------------------------------------------------
  3702             TRACES( RDebug::Print(_L("CSysApAppUi::AddMmcMenuItemsL: adding \"Eject\"" ) ) );
  1181 //
  3703             itemStringBuf = StringLoader::LoadLC( R_QTN_PWRC_EJECT_MMC, iEikonEnv );
  1182 void CSysApAppUi::ShowShutdownImageL( TInt aBitmapId )
  3704             aProfileNameCDesCArray->AppendL( itemStringBuf->Des() );
  1183     {
  3705             CleanupStack::PopAndDestroy(); // itemStringBuf
  1184     TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImageL") ) );
  3706             if ( iSysApFeatureManager->CoverDisplaySupported() )
  1185     // do nothing
  3707                 {
  1186     if ( !iSysApShutdownImage ) // Shutdown image may be shown without entering normal state (e.g. charging), so construct here
  3708                 aItemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemEjectMMC);
  1187         {
  3709                 }
  1188         TRACES( RDebug::Print( _L("CSysApAppUi::ShowShutdownImageL: trying CSysApShutdownImage::NewL()") ) );
  3710             iPowerkeyMenuEjectShown = ETrue;
  1189         iSysApShutdownImage = CSysApShutdownImage::NewL();
  3711             iPowerkeyMenuEjectSelection = aPowerMenuItemIndex;
  1190         }
  3712             aPowerMenuItemIndex++;
  1191     TRACES( RDebug::Print( _L("CSysApAppUi::ShowShutdownImageL: trying CSysApShutdownImage::ShowShutdownImageL()") ) );
  3713             }
  1192     iSysApShutdownImage->ShowShutdownImageL( aBitmapId );
  3714         }
  1193    }
  3715 
  1194    
  3716 #else // RD_MULTIPLE_DRIVE
       
  3717     iPowerkeyMenuEjectSelectionBase = KErrAccessDenied;
       
  3718     if ( !IsEncryptionOperationOngoingL() )
       
  3719         {
       
  3720         if ( iSysApFeatureManager->MmcHotSwapSupported()
       
  3721                 && iSysApFeatureManager->EjectRequiredInPowerMenu()
       
  3722                 && propertyValue != KUsbPersonalityIdMS )
       
  3723             {
       
  3724             // Reset old eject status and dialog
       
  3725             iSysApDriveList->ResetDrivesToEject();
       
  3726             if ( iSysApConfirmationQuery )
       
  3727                 {
       
  3728                 if ( iSysApConfirmationQuery->CurrentQuery() == ESysApEjectMmcQuery )
       
  3729                     {
       
  3730                     iSysApConfirmationQuery->Cancel();
       
  3731                     }
       
  3732                 }
       
  3733 
       
  3734             // Append memory cards for eject selection
       
  3735             TInt count( iInsertedMemoryCards.Count() );
       
  3736             TInt corruptedMedia = 0;
       
  3737             for ( TInt i( 0 ); i < count; ++i )
       
  3738                 {
       
  3739                 TVolumeInfo info;
       
  3740                 TInt err = iEikonEnv->FsSession().Volume(info, iInsertedMemoryCards[ i ].iDrive);
       
  3741                 TRACES( RDebug::Print(_L("CSysApAppUi::AddMmcMenuItemsL: corrupted media, iDrive (%d) Error: %d" ),iInsertedMemoryCards[ i ].iDrive, err ) );
       
  3742                 if(err != KErrNone)
       
  3743                     {
       
  3744                     corruptedMedia++;
       
  3745                     continue;
       
  3746                     }
       
  3747                 itemStringBuf = iSysApDriveList->GetFormattedDriveNameLC(
       
  3748                         iInsertedMemoryCards[ i ].iDrive,
       
  3749                         R_QTN_PWRC_EJECT_MEMORY_STORAGE );
       
  3750                 aProfileNameCDesCArray->AppendL( *itemStringBuf );
       
  3751                 CleanupStack::PopAndDestroy( itemStringBuf );
       
  3752 
       
  3753                 if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3754                     {
       
  3755                     aItemIdArray.AppendL(
       
  3756                             SecondaryDisplay::EPwrMenuItemEjectItemBase + i );
       
  3757                     }
       
  3758                 }
       
  3759             if ( (count-corruptedMedia) > 0 )
       
  3760                 {
       
  3761                 TRACES( RDebug::Print(_L("CSysApAppUi::AddMmcMenuItemsL: added \"Eject\"" ) ) );
       
  3762                 iPowerkeyMenuEjectShown = ETrue;
       
  3763                 iPowerkeyMenuEjectSelectionBase = aPowerMenuItemIndex;
       
  3764                 aPowerMenuItemIndex += (count-corruptedMedia);
       
  3765                 }
       
  3766             }
       
  3767         }
       
  3768 #endif // RD_MULTIPLE_DRIVE
       
  3769     }
       
  3770 
       
  3771 
       
  3772 // ----------------------------------------------------------------------------
       
  3773 // CSysApAppUi::ShowPowerKeyPopUpMenuL()
       
  3774 // ----------------------------------------------------------------------------
       
  3775 
       
  3776 void CSysApAppUi::ShowPowerKeyPopUpMenuL()
       
  3777     {
       
  3778     TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL iPowerKeyPopupMenuActive: %d" ),
       
  3779                           iPowerKeyPopupMenuActive ) );
       
  3780 
       
  3781     if ( !iPowerKeyPopupMenuActive && !iDisablePowerkeyMenu 
       
  3782          && iSysApPowerKeyMenuObserver ) // normal state construction has been executed
       
  3783         {
       
  3784         iPowerKeyPopupMenuDismissed = EFalse;
       
  3785         iPowerkeyMenuPowerOffShown = EFalse;
       
  3786         CancelGlobalListQuery();
       
  3787 
       
  3788         iGlobalListQuery = CAknGlobalListQuery::NewL();
       
  3789 
       
  3790         iSysApPowerKeyMenuObserver->Cancel();
       
  3791 
       
  3792         CDesCArray* profileNameCDesCArray; // Array for Powerkey Menu items
       
  3793 
       
  3794         RArray<TInt> itemIdArray; // needed for cover UI
       
  3795         CleanupClosePushL(itemIdArray);
       
  3796 
       
  3797         // make sure old profile names array is clean
       
  3798         delete iProfileNamesArray;
       
  3799         iProfileNamesArray = NULL;
       
  3800 
       
  3801         // Must pop iProfileNamesArray here as cannot leave trap harness with uneven push/pop count.
       
  3802         // This is because profileEngine doesn't provide non-LC version of ProfilesNamesArrayLC
       
  3803         TRAPD( err,
       
  3804               iProfileNamesArray = iProfileEngine->ProfilesNamesArrayLC();
       
  3805               CleanupStack::Pop();
       
  3806              );
       
  3807 
       
  3808         if ( err != KErrNone )
       
  3809             {
       
  3810             // creating menu failed, return (i.e. just don't show the menu)
       
  3811             TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL iProfileEngine->ProfilesNamesArrayLC() ERROR: %d" ), err ) );
       
  3812             iNumberOfProfileNamesInPowerKeyMenu = 0;
       
  3813             }
       
  3814         else
       
  3815             {
       
  3816             iNumberOfProfileNamesInPowerKeyMenu = iProfileNamesArray->MdcaCount();
       
  3817             TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL iNumberOfProfileNamesInPowerKeyMenu: %d" ),
       
  3818                                   iNumberOfProfileNamesInPowerKeyMenu ) );
       
  3819             }
       
  3820 
       
  3821         if ( BtSapEnabled() )
       
  3822             {
       
  3823             profileNameCDesCArray = new( ELeave ) CDesCArrayFlat( iNumberOfProfileNamesInPowerKeyMenu + 4 );
       
  3824             }
       
  3825         else
       
  3826             {
       
  3827             profileNameCDesCArray = new( ELeave ) CDesCArrayFlat( iNumberOfProfileNamesInPowerKeyMenu + 3 );
       
  3828             }
       
  3829 
       
  3830         CleanupStack::PushL( profileNameCDesCArray );
       
  3831         profileNameCDesCArray->Reset();
       
  3832         HBufC* itemStringBuf;
       
  3833 
       
  3834         TInt powerMenuItemIndex = 0;
       
  3835 
       
  3836         // "Switch off" menu item
       
  3837         if ( !IsEncryptionOperationOngoingL() )
       
  3838             {
       
  3839         itemStringBuf = StringLoader::LoadLC( R_QTN_PWRC_SWITCH_OFF, iEikonEnv );
       
  3840         profileNameCDesCArray->InsertL( 0, itemStringBuf->Des() );
       
  3841         CleanupStack::PopAndDestroy(); // itemStringBuf
       
  3842         if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3843             {
       
  3844             itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemSwitchOff);
       
  3845             }
       
  3846             iPowerkeyMenuPowerOffShown = ETrue;
       
  3847         powerMenuItemIndex++;
       
  3848             }
       
  3849 
       
  3850         iPowerkeyMenuLockKeypadShown     = EFalse;
       
  3851         iPowerkeyMenuExitSapShown        = EFalse;
       
  3852         iPowerkeyMenuLockSystemShown     = EFalse;
       
  3853         iPowerkeyMenuEjectShown          = EFalse;
       
  3854 
       
  3855         iPowerkeyMenuLockKeypadSelection = KErrAccessDenied;
       
  3856         iPowerkeyMenuExitSapSelection    = KErrAccessDenied;
       
  3857         iPowerkeyMenuLockSystemSelection = KErrAccessDenied;
       
  3858 
       
  3859 #ifndef RD_MULTIPLE_DRIVE
       
  3860         iPowerkeyMenuEjectSelection     = KErrAccessDenied;
       
  3861 #else // RD_MULTIPLE_DRIVE
       
  3862         iPowerkeyMenuEjectSelectionBase = KErrAccessDenied;
       
  3863 #endif // RD_MULTIPLE_DRIVE
       
  3864 
       
  3865         // "Lock keypad" menu item
       
  3866 		
       
  3867 		TInt callState ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  3868 		TInt callType ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallType ) );
       
  3869 		if ( !( callState == EPSCTsyCallStateConnected && callType == EPSCTsyCallTypeH324Multimedia ) )
       
  3870 			{
       
  3871         if ( ( iSysApFeatureManager->GripNotSupported() && !iSysApFeatureManager->SlideSupported() ) ||
       
  3872              ( (!iSysApFeatureManager->GripNotSupported() || iSysApFeatureManager->SlideSupported() ) && 
       
  3873              ( StateOfProperty( KPSUidHWRM, KHWRMGripStatus ) ==  EPSHWRMGripClosed ) ) )
       
  3874             // "Lock keypad" command is shown always when there is no grip, and if there
       
  3875             // there is no grip, only when the grip is closed.
       
  3876 				{
       
  3877 				if ( CKeyLockPolicyApi::KeyguardAllowed() )
       
  3878 					{
       
  3879 					if ( iSysApFeatureManager->PenEnabled() )
       
  3880 						{
       
  3881 						itemStringBuf = StringLoader::LoadLC( R_QTN_PWRC_LOCK_DISPLAY, iEikonEnv );
       
  3882 						}
       
  3883 					else
       
  3884 						{
       
  3885 						itemStringBuf = StringLoader::LoadLC( R_QTN_PWRC_LOCK_KEYS, iEikonEnv );
       
  3886 						}                
       
  3887 					profileNameCDesCArray->AppendL( itemStringBuf->Des() );
       
  3888 					CleanupStack::PopAndDestroy(); // itemStringBuf
       
  3889 					if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3890 						{
       
  3891 						itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemLockKeypad);
       
  3892                         }
       
  3893                     iPowerkeyMenuLockKeypadShown = ETrue;
       
  3894                     iPowerkeyMenuLockKeypadSelection = powerMenuItemIndex;
       
  3895                     powerMenuItemIndex++;
       
  3896                     }
       
  3897                 }
       
  3898             }
       
  3899         if ( iSysApFeatureManager->PowerKeyIsLockKey() )
       
  3900             {
       
  3901             AddMmcMenuItemsL( profileNameCDesCArray,
       
  3902                     itemIdArray, powerMenuItemIndex );
       
  3903             }
       
  3904 	    // "Exit SIM access profile" menu item
       
  3905         if ( BtSapEnabled() )
       
  3906             {
       
  3907             TRACES( RDebug::Print(_L( "CSysApAppUi::ShowPowerKeyPopUpMenuL: show \"Exit SIM access profile\" item" ) ) );
       
  3908             itemStringBuf = StringLoader::LoadLC( R_QTN_PWRC_EXIT_SIM_ACCESS, iEikonEnv );
       
  3909             profileNameCDesCArray->AppendL( itemStringBuf->Des() );
       
  3910             CleanupStack::PopAndDestroy(); // itemStringBuf
       
  3911             if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3912                 {
       
  3913                 itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemExitBtSap);
       
  3914                 }
       
  3915             iPowerkeyMenuExitSapShown = ETrue;
       
  3916             iPowerkeyMenuExitSapSelection = powerMenuItemIndex;
       
  3917             powerMenuItemIndex++;
       
  3918             }
       
  3919 
       
  3920         // Profile menu items
       
  3921         iProfileItemsOffset = powerMenuItemIndex;
       
  3922         TInt arrayIndex( 0 );
       
  3923         TBufC<KMaxProfileNameLength> profileName;
       
  3924 
       
  3925         for ( arrayIndex = 0; arrayIndex < iNumberOfProfileNamesInPowerKeyMenu; arrayIndex++ )
       
  3926             {
       
  3927             profileName = iProfileNamesArray->MdcaPoint( arrayIndex );
       
  3928             TPtr profileNamePtr = profileName.Des();
       
  3929             AknTextUtils::DisplayTextLanguageSpecificNumberConversion( profileNamePtr );
       
  3930             profileNameCDesCArray->AppendL( profileNamePtr );
       
  3931 
       
  3932             if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3933                 {
       
  3934                 TInt profileId = ( iProfileNamesArray->ProfileName( arrayIndex ) )->Id();
       
  3935                 itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemProfileItemBase+profileId);
       
  3936                 }
       
  3937             powerMenuItemIndex++;
       
  3938             }
       
  3939 
       
  3940         // "Lock device" menu item
       
  3941 
       
  3942         callState = StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState );
       
  3943         
       
  3944         TInt devLockStatus( EAutolockStatusUninitialized );
       
  3945         devLockStatus = StateOfProperty( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus );  // check whether Autolock has been started
       
  3946         
       
  3947 
       
  3948         if ( callState == EPSCTsyCallStateNone && devLockStatus != EAutolockStatusUninitialized )
       
  3949             {
       
  3950             TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL: adding \"Lock device\", devLockStatus=%d" ), devLockStatus ) );
       
  3951 			iPowerkeyMenuLockSystemShown = ETrue;
       
  3952             itemStringBuf = StringLoader::LoadLC( R_QTN_SET_SEC_LOCK_SYSTEM, iEikonEnv );
       
  3953             profileNameCDesCArray->AppendL( itemStringBuf->Des() );
       
  3954             CleanupStack::PopAndDestroy(); // itemStringBuf
       
  3955             if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3956                 {
       
  3957                 itemIdArray.AppendL(SecondaryDisplay::EPwrMenuItemLockDevice);
       
  3958                 }
       
  3959             iPowerkeyMenuLockSystemShown = ETrue;
       
  3960             iPowerkeyMenuLockSystemSelection = powerMenuItemIndex;
       
  3961             powerMenuItemIndex++;
       
  3962             }
       
  3963         if ( !iSysApFeatureManager->PowerKeyIsLockKey() )
       
  3964             {
       
  3965                 AddMmcMenuItemsL( profileNameCDesCArray, itemIdArray, powerMenuItemIndex );
       
  3966             }
       
  3967         
       
  3968         // Activate/deactive power save mode
       
  3969         if ( iSysApPsmController ) // variable feature, not create if power save is not used
       
  3970             {
       
  3971             TBool showActivate = !(iSysApPsmController->FullPsmEnabled());
       
  3972             
       
  3973             TInt textId = ( showActivate ? R_QTN_PWRC_ACTIVATE_POWER_SAVING : R_QTN_PWRC_DEACTIVATE_POWER_SAVING );
       
  3974             
       
  3975             itemStringBuf = StringLoader::LoadLC( textId, iEikonEnv );
       
  3976             iSysApPsmController->SetNextUiOperation( showActivate );
       
  3977             
       
  3978             if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3979                 {
       
  3980                 itemIdArray.AppendL( showActivate ? 
       
  3981                                      SecondaryDisplay::EPwrMenuItemActivatePowerSaving :
       
  3982                                      SecondaryDisplay::EPwrMenuItemDeactivatePowerSaving );
       
  3983                 }
       
  3984                 
       
  3985             profileNameCDesCArray->AppendL( itemStringBuf->Des() );
       
  3986             CleanupStack::PopAndDestroy( itemStringBuf );
       
  3987                 
       
  3988             iSysApPsmController->SetUiItemId( powerMenuItemIndex );
       
  3989             powerMenuItemIndex++;    
       
  3990             }
       
  3991         
       
  3992         TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL NumberOfAllItemsInPowerKeyMenu: %d" ),
       
  3993                               profileNameCDesCArray->Count() ) );
       
  3994 
       
  3995         iSysApPowerKeyMenuObserver->Start();
       
  3996 
       
  3997         // Set secondary display data if necessary
       
  3998         if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  3999             {
       
  4000             CAknSDData* sd = CAknSDData::NewL(SecondaryDisplay::KCatSysAp, SecondaryDisplay::ECmdShowPowerKeyListQuery, KNullDesC8);
       
  4001             sd->InsertGlobalListQueryItemIdsL(itemIdArray);
       
  4002             iGlobalListQuery->SetSecondaryDisplayData(sd); // ownership to notifier client
       
  4003             }
       
  4004 
       
  4005         iGlobalListQuery->ShowListQueryL( (MDesCArray*) profileNameCDesCArray,
       
  4006                                           iSysApPowerKeyMenuObserver->iStatus,
       
  4007                                           KProfileListInitialIndex );
       
  4008 
       
  4009         TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL: list query shown" ) ) );
       
  4010 
       
  4011         CleanupStack::PopAndDestroy( profileNameCDesCArray ); // profileNameCDesCArray
       
  4012         TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL: profileNameCDesCArray popped" ) ) );
       
  4013 
       
  4014         CleanupStack::Pop(&itemIdArray);
       
  4015         itemIdArray.Close();
       
  4016 
       
  4017         // Without following variable set ETrue powerkey up event would change the hightlighted item to be
       
  4018         // the second one instead of the wanted first one.
       
  4019         iIgnoreNextPowerKeyUpEvent = ETrue;
       
  4020 
       
  4021         if ( iSysApBatteryInfoController )        
       
  4022             {
       
  4023             iSysApBatteryInfoController->PowerMenuShownL();
       
  4024             }
       
  4025         
       
  4026         TRACES( RDebug::Print(_L("CSysApAppUi::ShowPowerKeyPopUpMenuL:end" ) ) );
       
  4027     }
       
  4028 }
       
  4029 
       
  4030 // ----------------------------------------------------------------------------
       
  4031 // CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL( TInt aSelection )
       
  4032 // ----------------------------------------------------------------------------
       
  4033 
       
  4034 void CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL( TInt aSelection )
       
  4035     {
       
  4036     iPowerKeyPopupMenuDismissed = ETrue;
       
  4037     iPowerKeyPopupMenuActive = EFalse;
       
  4038     TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: START aSelection:%d" ), aSelection ) );
       
  4039     if ( aSelection == KPowerKeyMenuSelectionCancelled )
       
  4040         {
       
  4041         TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: Powerkey menu cancelled" ) ) );
       
  4042         }
       
  4043     else if( aSelection < KPowerKeyMenuSelectionCancelled )
       
  4044         {
       
  4045         iIgnoreNextPowerKeyUpEvent = EFalse;
       
  4046         }
       
  4047     else
       
  4048         {
       
  4049         // first menu item <=> Switch off
       
  4050         if ( aSelection == KPowerKeyMenuSelectionSwitchOff )
       
  4051             {
       
  4052             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Switch off\" selected" ) ) );
       
  4053             DoShutdownL( EFalse, KDummyReason );
       
  4054             }
       
  4055         // 2nd menu item: lock display & keys
       
  4056         else if ( iPowerkeyMenuLockKeypadShown && aSelection == iPowerkeyMenuLockKeypadSelection )
       
  4057             {
       
  4058             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Lock keypad\" selected" ) ) );
       
  4059             KeyLock().EnableKeyLock();
       
  4060             }
       
  4061         // BT
       
  4062         else if ( iPowerkeyMenuExitSapShown && aSelection == iPowerkeyMenuExitSapSelection )
       
  4063             {
       
  4064             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Exit SAP\" selected" ) ) );
       
  4065             ShowQueryL( ESysApBtSapDisconnectQuery );
       
  4066             }
       
  4067         // Profile Items
       
  4068         else if ( ( aSelection >= iProfileItemsOffset ) && ( aSelection < iProfileItemsOffset + iNumberOfProfileNamesInPowerKeyMenu ) )
       
  4069             {
       
  4070             __ASSERT_DEBUG( iProfileNamesArray, User::Invariant() );
       
  4071 
       
  4072             if ( iProfileNamesArray )
       
  4073                 {
       
  4074                 iProfileToBeActivated = ( iProfileNamesArray->ProfileName( aSelection - iProfileItemsOffset ) )->Id();
       
  4075 
       
  4076                 TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: profile id: %d selected" ), iProfileToBeActivated ) );
       
  4077                 if ( ! iSysApOfflineModeController->OfflineModeActive() ||
       
  4078                     ( iProfileToBeActivated ) == KOfflineModeProfileId )
       
  4079                     {
       
  4080                     ActivateProfileL( iProfileToBeActivated );
       
  4081                     }
       
  4082                 else
       
  4083                     {
       
  4084                     // iProfileToBeActivated profile will be activated from iSysApOfflineModeController if ok
       
  4085                     iSysApOfflineModeController->GoOnlineIfOkL();
       
  4086                     }
       
  4087                 }
       
  4088             }
       
  4089         // device lock
       
  4090         else if ( iPowerkeyMenuLockSystemShown && aSelection == iPowerkeyMenuLockSystemSelection )
       
  4091             {
       
  4092             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Lock system\" selected" ) ) );
       
  4093             iSysApSystemLock->SetLockedL();
       
  4094             }
       
  4095 #ifndef RD_MULTIPLE_DRIVE
       
  4096         //eject single MMC
       
  4097         else if ( iPowerkeyMenuEjectShown && aSelection == iPowerkeyMenuEjectSelection )
       
  4098             {
       
  4099             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Eject\" selected" ) ) );
       
  4100             ShowQueryL( ESysApEjectMmcQuery );
       
  4101             }
       
  4102 #else // RD_MULTIPLE_DRIVE
       
  4103         //eject nth MMC
       
  4104         else if ( iPowerkeyMenuEjectShown &&
       
  4105                 aSelection >= iPowerkeyMenuEjectSelectionBase &&
       
  4106                 aSelection < iPowerkeyMenuEjectSelectionBase + iInsertedMemoryCards.Count() )
       
  4107             {
       
  4108             iDriveToEject =
       
  4109                 iInsertedMemoryCards[ aSelection - iPowerkeyMenuEjectSelectionBase ].iDrive;
       
  4110             TRACES( RDebug::Print(
       
  4111                 _L( "CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Eject\" selected, drive=%d" ),
       
  4112                 iDriveToEject ) );
       
  4113             iSysApDriveList->ResetDrivesToEject();
       
  4114             RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
       
  4115             EjectMMCL();
       
  4116             }
       
  4117 #endif // RD_MULTIPLE_DRIVE
       
  4118         else if ( iSysApPsmController && aSelection == iSysApPsmController->UiItemId() )
       
  4119             {
       
  4120             TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: \"Activate|Deactivate power save\" selected" ) ) );
       
  4121             iSysApPsmController->DoEnableFullPsm( iSysApPsmController->NextUiOperation() );
       
  4122             }
       
  4123 
       
  4124         }
       
  4125 
       
  4126     delete iProfileNamesArray;
       
  4127     iProfileNamesArray = NULL;
       
  4128     delete iGlobalListQuery;
       
  4129     iGlobalListQuery = NULL;
       
  4130 
       
  4131     TRACES( RDebug::Print(_L("CSysApAppUi::PowerKeyPopUpMenuSelectionDoneL: END" ) ) );
       
  4132     }
       
  4133 
       
  4134 // ----------------------------------------------------------------------------
       
  4135 // CSysApAppUi::SetDeviceLockEnabledL( const TBool aLockEnabled )
       
  4136 // ----------------------------------------------------------------------------
       
  4137 
       
  4138 void CSysApAppUi::SetDeviceLockEnabledL( const TBool aLockEnabled )
       
  4139     {
       
  4140     TRACES( RDebug::Print(_L("CSysApAppUi::SetDeviceLockEnabledL aLockEnabled:%d" ), aLockEnabled ) );
       
  4141     TBool currentState( iDeviceLockEnabled );
       
  4142     
       
  4143     iDeviceLockEnabled = aLockEnabled;
       
  4144     
       
  4145     if ( currentState != iDeviceLockEnabled ) // filter out unnecessary light status modifications
       
  4146         {
       
  4147         iSysApLightsController->DeviceLockStateChangedL( iDeviceLockEnabled );
       
  4148         }
       
  4149     
       
  4150  /*   if( iDeviceLockEnabled )
       
  4151         {
       
  4152         if( iKeyLockEnabled )
       
  4153             {
       
  4154             KeyLock().DisableWithoutNote();
       
  4155             }
       
  4156         }*/
       
  4157     if(! iDeviceLockEnabled )
       
  4158         {
       
  4159         // let's not activate keylock in case device lock was disabled during call or in cradle
       
  4160         iKeyLockOnBeforeCall = EFalse;
       
  4161         iKeyLockOnBeforeCradle = EFalse;
       
  4162 
       
  4163         // Memory card needs to be unlocked when device is unlocked
       
  4164         if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  4165             {
       
  4166             RunUnlockNotifierL();
       
  4167             }
       
  4168         }
       
  4169     }
       
  4170 
       
  4171 // ----------------------------------------------------------------------------
       
  4172 // CSysApAppUi::DoNotEnableKeylock()
       
  4173 // ----------------------------------------------------------------------------
       
  4174 
       
  4175 void CSysApAppUi::DoNotEnableKeylock()
       
  4176     {
       
  4177     if ( !iKeyLockOnBeforeCradle )
       
  4178         {
       
  4179         iShowkeypadActivatedNoteAfterSoftReject = iKeyLockOnBeforeCall;
       
  4180         }
       
  4181 
       
  4182     iKeyLockOnBeforeCall = EFalse;
       
  4183     }
       
  4184 
       
  4185 // ----------------------------------------------------------------------------
       
  4186 // CSysApAppUi::DoShutdownL( const TBool aReset, const TSWStartupReason aSWStartupReason )
       
  4187 // ----------------------------------------------------------------------------
       
  4188 
       
  4189 void CSysApAppUi::DoShutdownL( const TBool aReset, const TInt aResetReason )
       
  4190     {
       
  4191     TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: aResetReason:%d, aReset:%d" ),
       
  4192         aResetReason, aReset ) );
       
  4193 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4194     TBool animationenabled( EFalse );
       
  4195 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4196 
       
  4197     if( OkToInitiateShutdown() )
       
  4198         {
       
  4199         TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: Was OkToToInitiateShutdown" ) ) );
       
  4200 
       
  4201 
       
  4202         if ( !aReset && iSysApFeatureManager->Supported(KSysApFeatureIdGoodbyeNote) )
       
  4203             {
       
  4204             TRAPD( ignore, ShowShutdownNoteL() );
       
  4205             if ( ignore ) ignore = 0; // hide compiler warning about not using variable
       
  4206             }
       
  4207 
       
  4208         if( !aReset )
       
  4209             {
       
  4210     #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4211             TRAPD( err, ShowAnimationL() );
       
  4212             if ( err )
       
  4213                 {
       
  4214                 TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL ShowAnimationL() leaved: %d" ), err ) );
       
  4215                 CompleteShutdown(aReset, aResetReason);
       
  4216                 }
       
  4217             }
       
  4218         else // aReset
       
  4219             {
       
  4220             CompleteShutdown(aReset, aResetReason);
       
  4221             }
       
  4222     #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4223             TRAPD( err, animationenabled = ShowAnimationL() );
       
  4224             if ( err )
       
  4225                 {
       
  4226                 TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL ShowAnimationL() leaved: %d" ), err ) );
       
  4227                 }
       
  4228             }
       
  4229 
       
  4230         if ( !animationenabled )
       
  4231             {
       
  4232             CompleteShutdown(aReset, aResetReason);
       
  4233             }
       
  4234     #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4235         }
       
  4236     else
       
  4237         {
       
  4238         TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: Was not OkToToInitiateShutdown" ) ) );
       
  4239         }
       
  4240     TRACES( RDebug::Print(_L("CSysApAppUi::DoShutdownL: END" ) ) );
       
  4241     }
       
  4242 
       
  4243 // ----------------------------------------------------------------------------
       
  4244 // CSysApAppUi::ContinueShutdown()
       
  4245 // ----------------------------------------------------------------------------
       
  4246 
       
  4247 void CSysApAppUi::ContinueShutdown()
       
  4248     {
       
  4249     TRACES( RDebug::Print(_L("CSysApAppUi::ContinueShutdown() started" ) ) );
       
  4250     CompleteShutdown();
       
  4251     TRACES( RDebug::Print(_L("CSysApAppUi::ContinueShutdown() completed" ) ) );
       
  4252     }
       
  4253 
       
  4254 // ----------------------------------------------------------------------------
       
  4255 // CSysApAppUi::ShowAnimationL()
       
  4256 // ----------------------------------------------------------------------------
       
  4257 
       
  4258 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4259 void
       
  4260 #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4261 TBool
       
  4262 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4263 CSysApAppUi::ShowAnimationL()
       
  4264     {
       
  4265     TRACES( RDebug::Print(_L("CSysApAppUi::ShowAnimationL(): START" ) ) );
       
  4266 
       
  4267     TRACES( RDebug::Print( _L("CSysApAppUi::ShowAnimationL: Initialise shutdown animation") ) );
       
  4268 
       
  4269 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4270 
       
  4271     PrepareForShutdownAnimation();
       
  4272 
       
  4273     iSysApShutdownAnimation = CSysApShutdownAnimation::NewL( *iSysApShutdownImage );
       
  4274     iSysApShutdownAnimation->Play( TCallBack( DoStopAnimTiming, this ) );
       
  4275 
       
  4276     TRACES( RDebug::Print(_L("CSysApAppUi::ShowAnimationL(): End" ) ) );
       
  4277 
       
  4278 #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4279     iSysApShutdownAnimation = CSysApShutdownAnimation::NewL( this );
       
  4280     AddToStackL( iSysApShutdownAnimation );
       
  4281     iAnimationShowingTime = iSysApShutdownAnimation->ShowingTime();
       
  4282     TRACES( RDebug::Print( _L("CSysApAppUi::ShowAnimationL: Shutdown animation initialised. Animation time = %d") ,iAnimationShowingTime) );
       
  4283 
       
  4284     TBool ret_val( EFalse );
       
  4285 
       
  4286     if ( iAnimationShowingTime )
       
  4287         {
       
  4288         if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  4289             {
       
  4290             // Construct mediator observer
       
  4291             iSysApMediatorObserver = CSysApMediatorObserver::NewL( this );
       
  4292 
       
  4293             // Sync animation
       
  4294             TInt err = iSysApMediatorObserver->SyncShutdownAnimation();
       
  4295 
       
  4296             if ( err != KErrNone )
       
  4297                 {
       
  4298                 // Pretend coverUI synced instantly if error in issuing command.
       
  4299                 ShutdownAnimationSyncOK();
       
  4300                 }
       
  4301             }
       
  4302         else
       
  4303             {
       
  4304             // Pretend coverUI synced instantly when it is not supported.
       
  4305             ShutdownAnimationSyncOK();
       
  4306             }
       
  4307 
       
  4308         ret_val = ETrue;
       
  4309         }
       
  4310 
       
  4311     TRACES( RDebug::Print(_L("CSysApAppUi::ShowAnimationL(): returns: %d" ),ret_val ) );
       
  4312     return ret_val;
       
  4313 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4314     }
       
  4315 
       
  4316 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4317 // ----------------------------------------------------------------------------
       
  4318 // CSysApAppUi::ShutdownAnimationSyncOK()
       
  4319 // ----------------------------------------------------------------------------
       
  4320 
       
  4321 void CSysApAppUi::ShutdownAnimationSyncOK()
       
  4322     {
       
  4323     TRACES( RDebug::Print(_L("CSysApAppUi::ShutdownAnimationSyncOK(): Call PrepareForShutdownAnimation()" ) ) );
       
  4324     PrepareForShutdownAnimation();//SysAp's internal preparation for ShutDown with animation
       
  4325     TRACES( RDebug::Print(_L("CSysApAppUi::ShutdownAnimationSyncOK(): Called PrepareForShutdownAnimation()" ) ) );
       
  4326     }
       
  4327 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4328 
       
  4329 // ----------------------------------------------------------------------------
       
  4330 // CSysApAppUi::SkipShutdownAnimation()
       
  4331 // ----------------------------------------------------------------------------
       
  4332 
       
  4333 void CSysApAppUi::SkipShutdownAnimation()
       
  4334     {
       
  4335     TRACES( RDebug::Print(_L("CSysApAppUi::SkipShutdownAnimation() " ) ) );
       
  4336 
       
  4337 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4338     if ( iSysApShutdownAnimation )
       
  4339         {
       
  4340         iSysApShutdownAnimation->Cancel();
       
  4341         }
       
  4342 #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4343     if ( iAnimationShowingTime )
       
  4344         {
       
  4345         iSysApShutdownAnimation->EndAnimation();
       
  4346         }
       
  4347 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4348     }
       
  4349 
       
  4350 // ----------------------------------------------------------------------------
       
  4351 // CSysApAppUi::NotifyShutdownAnimationSkip()
       
  4352 // ----------------------------------------------------------------------------
       
  4353 
       
  4354 void CSysApAppUi::NotifyShutdownAnimationSkip()
       
  4355     {
       
  4356     TRACES( RDebug::Print(_L("CSysApAppUi::NotifyShutdownAnimationSkip() " ) ) );
       
  4357 
       
  4358     if ( iSysApMediatorObserver )
       
  4359         {
       
  4360         iSysApMediatorObserver->ShutdownAnimationSkipped();
       
  4361         }
       
  4362     }
       
  4363 
       
  4364 // ----------------------------------------------------------------------------
       
  4365 // CSysApAppUi::CompleteShutdown()
       
  4366 // ----------------------------------------------------------------------------
       
  4367 
       
  4368 void CSysApAppUi::CompleteShutdown( const TBool aReset, const TInt aResetReason )
       
  4369     {
       
  4370     TRACES( RDebug::Print(_L("CSysApAppUi::CompleteShutdown(): START" ) ) );
       
  4371 
       
  4372     PrepareForShutdownImage();//SysAp's internal preparation for ShutDown with image
       
  4373 
       
  4374     FreeResources();
       
  4375 
       
  4376     if ( aReset )
       
  4377         {
       
  4378         __ASSERT_DEBUG( aResetReason >= RStarterSession::ELanguageSwitchReset &&
       
  4379                         aResetReason <= RStarterSession::EDataRestoreReset,
       
  4380                         User::Invariant() );
       
  4381         StarterSession().Reset( static_cast<RStarterSession::TResetReason>( aResetReason ) );
       
  4382         }
       
  4383     else
       
  4384         {
       
  4385         StarterSession().Shutdown();
       
  4386         }
       
  4387 
       
  4388     StarterSession().Close();
       
  4389 
       
  4390     TRACES( RDebug::Print(_L("CSysApAppUi::CompleteShutdown(): END" ) ) );
       
  4391     }
       
  4392 
       
  4393 #ifndef SYSAP_USE_STARTUP_UI_PHASE
       
  4394 // ----------------------------------------------------------------------------
       
  4395 // CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
  4396 // This method is not called after boot has finished.
       
  4397 // ----------------------------------------------------------------------------
       
  4398 
       
  4399 void CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
  4400     {
       
  4401     TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: %d" ), aSwState ) );
       
  4402 
       
  4403     switch ( aSwState )
       
  4404         {
       
  4405         case RStarterSession::ENormal:
       
  4406             SetStatusPaneLayoutL( ESysApNormal );
       
  4407             break;
       
  4408         case RStarterSession::ECharging:
       
  4409             SetStatusPaneLayoutL( ESysApCharging );
       
  4410             break;
       
  4411         case RStarterSession::EAlarm:
       
  4412             SetStatusPaneLayoutL( ESysApAlarm );
       
  4413             break;
       
  4414         default:
       
  4415             break;
       
  4416         };
       
  4417 
       
  4418     TRAPD( simChangedErr, DoSimChangedFromPreviousBootL() );
       
  4419     TRACES( RDebug::Print( _L("CSysApAppUi::DoStateChangedL: simChangedErr = %d" ), simChangedErr ) );
       
  4420     simChangedErr = simChangedErr; // suppress 'variable not used' warning
       
  4421     LogsObserverL().HandleSimChangedCheckDoneL();
       
  4422 
       
  4423     if ( iSysApFeatureManager->PowerSaveSupported() )
       
  4424         {
       
  4425         // create controller before checking battery state, so that power saving can be enabled during boot if needed
       
  4426         if ( !iSysApPsmController ) // created only in first state change
       
  4427             {
       
  4428             iSysApPsmController = CSysApPsmController::NewL( *this );        
       
  4429             }
       
  4430 
       
  4431         // in charger boot explicitly disable partial power save mode
       
  4432         if ( aSwState == RStarterSession::ECharging && !iCharging )
       
  4433             {
       
  4434             iSysApPsmController->ChargerConnected();
       
  4435             iSysApPsmController->DoEnablePartialPsm( EFalse ); // disable partial power save now
       
  4436             }
       
  4437         }
       
  4438 
       
  4439     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  4440     //Also Charging status will be updated with the following function.
       
  4441     UpdateBatteryBarsL( state );
       
  4442 
       
  4443     if( IsStateNormal() )
       
  4444         {
       
  4445         TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL to normal state.") ) );
       
  4446 
       
  4447         DoSwStateNormalConstructionL();
       
  4448 
       
  4449         InitializeStatusPaneAreaL();
       
  4450         CheckSilentModeL();
       
  4451         HandleAccessoryProfileInStartupL();
       
  4452 
       
  4453         if ( iSysApFeatureManager->MmcSupported() )
       
  4454             {
       
  4455 #ifndef RD_MULTIPLE_DRIVE
       
  4456             MountMMC();
       
  4457             MMCStatusChangedL();
       
  4458             iHideFirstBeep = EFalse;
       
  4459 #else // RD_MULTIPLE_DRIVE
       
  4460             iSysApDriveList->MountDrive( iSysApDriveList->DefaultMemoryCard() );
       
  4461             UpdateInsertedMemoryCardsL();
       
  4462 #endif // RD_MULTIPLE_DRIVE
       
  4463             }
       
  4464         if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  4465             {
       
  4466             iSysApMMCObserver->StartMountObserver();
       
  4467             }
       
  4468 
       
  4469         
       
  4470         if ( iSysApPsmController )
       
  4471             {
       
  4472             if ( iCharging ) // if charger is connected on boot PSM queries may need to be shown
       
  4473                 {
       
  4474                 HandleChargingStatusL( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
  4475                 }
       
  4476             }
       
  4477         
       
  4478         TInt batteryStatus = StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryStatus );
       
  4479         TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: batteryStatus %d" ), batteryStatus ) );
       
  4480         if(  batteryStatus == EBatteryStatusLow || batteryStatus == EBatteryStatusEmpty )
       
  4481             {
       
  4482             // low and empty battery states are informed to the user in device startup
       
  4483             HandleBatteryStatusL( batteryStatus );
       
  4484             }
       
  4485         else if ( iSysApPsmController && !iCharging )
       
  4486         	{
       
  4487 				TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: batteryStatus %d, iCharging %d -> disable partial psm" ), batteryStatus, iCharging ) );
       
  4488 
       
  4489 				iSysApPsmController->BatteryLow( EFalse );
       
  4490 				iSysApPsmController->DoEnablePartialPsm( EFalse );
       
  4491 			}
       
  4492 
       
  4493         iSysApBtController = CreateSysApBtControllerL( *this );
       
  4494         iSysApBtSapController = CreateSysApBtSapControllerL( *this );
       
  4495 
       
  4496         if ( iActivateBt )
       
  4497             {
       
  4498             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Activating BT" ) ) );
       
  4499             SetBtPowerState( ETrue );
       
  4500             }
       
  4501 
       
  4502         if ( iDeactivateBt )
       
  4503             {
       
  4504             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Deactivating BT" ) ) );
       
  4505             SetBtPowerState( EFalse );
       
  4506             }
       
  4507         iSysApLocationPrivacyIndicator = CreateSysApLocationPrivacyIndicatorL( *this );
       
  4508         iSysApLocationPrivacyIndicator->InitL();
       
  4509 
       
  4510         if ( ! iSysApUsbIndicatorController )
       
  4511             {
       
  4512             TRAPD ( usbErr, iSysApUsbIndicatorController = CreateSysApUsbIndicatorL( *this ) );
       
  4513             if ( usbErr )
       
  4514                 {
       
  4515                 TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: error in constructing USB ind. controller %d" ), usbErr ) );
       
  4516                 }
       
  4517             }
       
  4518 
       
  4519         // Other late initializations.
       
  4520         // In order to prevent unexpected behaviour e.g. in OOM situations, these calls are made to ensure
       
  4521         // that the services are connected when they are needed for the first time.
       
  4522         if ( !StarterSession().Handle() )
       
  4523             {
       
  4524             User::Leave( KErrBadHandle );
       
  4525             }
       
  4526 
       
  4527         if ( !KeyLock().Handle() )
       
  4528             {
       
  4529             User::Leave( KErrBadHandle );
       
  4530             }
       
  4531 
       
  4532 #ifdef __SYSAP_MODULE_TEST
       
  4533         ModuleTestShowUiNoteL( _L("SysAp: SW state normal!") );
       
  4534 #endif
       
  4535         }
       
  4536 
       
  4537     // Allow lights
       
  4538     iSysApLightsController->AllowLightsOn();
       
  4539     }
       
  4540 
       
  4541 #else // SYSAP_USE_STARTUP_UI_PHASE
       
  4542 
       
  4543 // ----------------------------------------------------------------------------
       
  4544 // CSysApAppUi::HandleUiReadyAfterBootL()
       
  4545 // Called when startup UI activities has been finished
       
  4546 // ----------------------------------------------------------------------------
       
  4547 
       
  4548 void CSysApAppUi::HandleUiReadyAfterBootL()
       
  4549     {
       
  4550     TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL" ) ) );
       
  4551     
       
  4552     SetStatusPaneLayoutL( ESysApNormal );
       
  4553     
       
  4554     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  4555     //Also Charging status will be updated with the following function.
       
  4556     UpdateBatteryBarsL( state );
       
  4557     
       
  4558     DoSwStateNormalConstructionL();
       
  4559 
       
  4560     InitializeStatusPaneAreaL();
       
  4561     CheckSilentModeL();
       
  4562     HandleAccessoryProfileInStartupL();
       
  4563     
       
  4564     if ( iSysApFeatureManager->MmcSupported() )
       
  4565         {
       
  4566 #ifndef RD_MULTIPLE_DRIVE
       
  4567         MountMMC();
       
  4568         MMCStatusChangedL();
       
  4569         iHideFirstBeep = EFalse;
       
  4570 #else // RD_MULTIPLE_DRIVE
       
  4571         iSysApDriveList->MountDrive( iSysApDriveList->DefaultMemoryCard() );
       
  4572         UpdateInsertedMemoryCardsL();
       
  4573 #endif // RD_MULTIPLE_DRIVE
       
  4574         }
       
  4575     
       
  4576     if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  4577         {
       
  4578         iSysApMMCObserver->StartMountObserver();
       
  4579         }
       
  4580 
       
  4581     if ( iSysApPsmController )
       
  4582         {
       
  4583         if ( iCharging ) // if charger is connected on boot PSM queries may need to be shown
       
  4584             {
       
  4585             HandleChargingStatusL( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
  4586             }
       
  4587         }
       
  4588     
       
  4589     TInt batteryStatus = StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryStatus );
       
  4590     TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: batteryStatus %d" ), batteryStatus ) );
       
  4591     if(  batteryStatus == EBatteryStatusLow || batteryStatus == EBatteryStatusEmpty )
       
  4592         {
       
  4593         // low and empty battery states are informed to the user in device startup
       
  4594         HandleBatteryStatusL( batteryStatus );
       
  4595         }
       
  4596     else if ( iSysApPsmController && !iCharging )
       
  4597       	{
       
  4598 		    TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: batteryStatus %d, iCharging %d -> disable partial psm" ), batteryStatus, iCharging ) );
       
  4599 
       
  4600 			iSysApPsmController->BatteryLow( EFalse );
       
  4601 			iSysApPsmController->DoEnablePartialPsm( EFalse );
       
  4602         }
       
  4603 
       
  4604     iSysApLocationPrivacyIndicator = CreateSysApLocationPrivacyIndicatorL( *this );
       
  4605     iSysApLocationPrivacyIndicator->InitL();
       
  4606 
       
  4607     if ( ! iSysApUsbIndicatorController )
       
  4608         {
       
  4609         TRAPD ( usbErr, iSysApUsbIndicatorController = CreateSysApUsbIndicatorL( *this ) );
       
  4610         if ( usbErr )
       
  4611             {
       
  4612             TRACES( RDebug::Print(_L("CSysApAppUi::HandleUiReadyAfterBootL: error in constructing USB ind. controller %d" ), usbErr ) );
       
  4613             }
       
  4614         }
       
  4615     }
       
  4616 
       
  4617 // ----------------------------------------------------------------------------
       
  4618 // CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
  4619 // This method is not called after boot has finished.
       
  4620 // ----------------------------------------------------------------------------
       
  4621 
       
  4622 void CSysApAppUi::DoStateChangedL(const RStarterSession::TGlobalState aSwState)
       
  4623     {
       
  4624     TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL: %d" ), aSwState ) );
       
  4625 
       
  4626     switch ( aSwState )
       
  4627         {
       
  4628         case RStarterSession::ENormal:
       
  4629             // status pane layout will updated when UI is ready
       
  4630             break;
       
  4631         case RStarterSession::ECharging:
       
  4632             SetStatusPaneLayoutL( ESysApCharging );
       
  4633             break;
       
  4634         case RStarterSession::EAlarm:
       
  4635             SetStatusPaneLayoutL( ESysApAlarm );
       
  4636             break;
       
  4637         default:
       
  4638             break;
       
  4639         };
       
  4640 
       
  4641     TRAPD( simChangedErr, DoSimChangedFromPreviousBootL() );
       
  4642     TRACES( RDebug::Print( _L("CSysApAppUi::DoStateChangedL: simChangedErr = %d" ), simChangedErr ) );
       
  4643     simChangedErr = simChangedErr; // suppress 'variable not used' warning
       
  4644     LogsObserverL().HandleSimChangedCheckDoneL();
       
  4645 
       
  4646     if ( iSysApFeatureManager->PowerSaveSupported() )
       
  4647         {
       
  4648         // create controller before checking battery state, so that power saving can be enabled during boot if needed
       
  4649         if ( !iSysApPsmController ) // created only in first state change
       
  4650             {
       
  4651             iSysApPsmController = CSysApPsmController::NewL( *this );        
       
  4652             }
       
  4653 
       
  4654         // in charger boot explicitly disable partial power save mode
       
  4655         if ( aSwState == RStarterSession::ECharging )
       
  4656             {
       
  4657             iSysApPsmController->ChargerConnected();
       
  4658             iSysApPsmController->DoEnablePartialPsm( EFalse ); // disable partial power save now
       
  4659             }
       
  4660         }
       
  4661 
       
  4662     if ( aSwState == RStarterSession::ECharging || aSwState == RStarterSession::EAlarm )
       
  4663         {
       
  4664         TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  4665         //Also Charging status will be updated with the following function.
       
  4666         UpdateBatteryBarsL( state );    
       
  4667         }
       
  4668         
       
  4669     if( IsStateNormal() )
       
  4670         {
       
  4671         TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL to normal state.") ) );
       
  4672 
       
  4673         iSysApBtController = CreateSysApBtControllerL( *this );
       
  4674         iSysApBtSapController = CreateSysApBtSapControllerL( *this );
       
  4675 
       
  4676         if ( iActivateBt )
       
  4677             {
       
  4678             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Activating BT" ) ) );
       
  4679             SetBtPowerState( ETrue );
       
  4680             }
       
  4681 
       
  4682         if ( iDeactivateBt )
       
  4683             {
       
  4684             TRACES( RDebug::Print(_L("CSysApAppUi::DoStateChangedL Deactivating BT" ) ) );
       
  4685             SetBtPowerState( EFalse );
       
  4686             }
       
  4687 
       
  4688         // Other late initializations.
       
  4689         // In order to prevent unexpected behaviour e.g. in OOM situations, these calls are made to ensure
       
  4690         // that the services are connected when they are needed for the first time.
       
  4691         if ( !StarterSession().Handle() )
       
  4692             {
       
  4693             User::Leave( KErrBadHandle );
       
  4694             }
       
  4695 
       
  4696         if ( !KeyLock().Handle() )
       
  4697             {
       
  4698             User::Leave( KErrBadHandle );
       
  4699             }
       
  4700 
       
  4701 #ifdef __SYSAP_MODULE_TEST
       
  4702         ModuleTestShowUiNoteL( _L("SysAp: SW state normal!") );
       
  4703 #endif
       
  4704         }
       
  4705 
       
  4706     // Allow lights
       
  4707     iSysApLightsController->AllowLightsOn();
       
  4708     }
       
  4709 
       
  4710 
       
  4711 #endif // SYSAP_USE_STARTUP_UI_PHASE
       
  4712 
       
  4713 // ----------------------------------------------------------------------------
       
  4714 // CSysApAppUi::UiReady()
       
  4715 // 
       
  4716 // ----------------------------------------------------------------------------
       
  4717 
       
  4718 TBool CSysApAppUi::UiReady() const
       
  4719     {
       
  4720 #ifdef SYSAP_USE_STARTUP_UI_PHASE    
       
  4721     return iSysApStartupController->UiReady(); 
       
  4722 #else // SYSAP_USE_STARTUP_UI_PHASE
       
  4723     // if startup UI phase information is not used, global system state normal is handled as UI idle state
       
  4724     return IsStateNormal();
       
  4725 #endif // SYSAP_USE_STARTUP_UI_PHASE        
       
  4726     }
       
  4727 
       
  4728 // ----------------------------------------------------------------------------
       
  4729 // CSysApAppUi::PrepareForShutdownAnimation()
       
  4730 // ----------------------------------------------------------------------------
       
  4731 void CSysApAppUi::PrepareForShutdownAnimation()
       
  4732     {
       
  4733     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() begin") ) );
       
  4734 
       
  4735 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4736     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() showtime = %d"), iAnimationShowingTime ) );
       
  4737     if ( iAnimationShowingTime )
       
  4738         {
       
  4739 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4740         static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( EAvkonSIDPowerOffTone );
       
  4741         CancelGlobalListQuery();
       
  4742 
       
  4743         if ( iSysApPowerKeyMenuObserver )
       
  4744             {
       
  4745             iSysApPowerKeyMenuObserver->Cancel();
       
  4746             }
       
  4747 
       
  4748         // deactivate notifiers before showing the shutdown image
       
  4749         AknNotifierController::CancelAllNotifications();
       
  4750         AknNotifierController::HideAllNotifications(ETrue);
       
  4751         RWindowGroup groupWin = iCoeEnv->RootWin();
       
  4752         iCapturedAppskey = groupWin.CaptureKey( EKeyApplication, KModifierMask, KModifierMask );
       
  4753         iCapturedAppskeyUpAndDowns = groupWin.CaptureKeyUpAndDowns( EStdKeyApplication0, KModifierMask, KModifierMask );
       
  4754         iEikonEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront );
       
  4755 
       
  4756         TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() Draw background image" ) ) );
       
  4757 
       
  4758         ShowShutdownImage( KBackgroundImageID );
       
  4759 
       
  4760 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4761         TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() Show Shutdown animation" ) ) );
       
  4762         TInt err(0);
       
  4763         TRAP( err, iSysApShutdownAnimation->StartL( iLastPowerKeyWasShort ) );
       
  4764         if ( err )
       
  4765             {
       
  4766             TRACES( RDebug::Print( _L("SysAp: Shutdown animation fails. Error code: %d" ), err ) );
       
  4767             // Start animation timing immediatily if animation starting fails.
       
  4768             // Otherwise animation will call StartAnimTiming when it is ready.
       
  4769             StartAnimTiming();
       
  4770             }
       
  4771         }
       
  4772 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  4773 
       
  4774     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() end") ) );
       
  4775     }
       
  4776 
       
  4777 
  1195 // ----------------------------------------------------------------------------
  4778 // ----------------------------------------------------------------------------
  1196 // CSysApAppUi::PrepareForShutdownImage()
  4779 // CSysApAppUi::PrepareForShutdownImage()
  1197 // ----------------------------------------------------------------------------
  4780 // ----------------------------------------------------------------------------
  1198 
  4781 
  1199 void CSysApAppUi::PrepareForShutdownImage()
  4782 void CSysApAppUi::PrepareForShutdownImage()
  1200     {
  4783     {
  1201     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() START" ) ) );
  4784     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() START" ) ) );
  1202  
  4785 
  1203     // If RD_STARTUP_ANIMATION_CUSTOMIZATION is enabled, the following actions are always taken in PrepareForShutdownAnimation
  4786     // If RD_STARTUP_ANIMATION_CUSTOMIZATION is enabled, the following actions are always taken in PrepareForShutdownAnimation
  1204 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
  4787 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
  1205     if ( !iAnimationShowingTime ) // actions already taken in PrepareForShutdownAnimation
  4788     if ( !iAnimationShowingTime ) // actions already taken in PrepareForShutdownAnimation
  1206         {
  4789         {
  1207         static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( EAvkonSIDPowerOffTone );
  4790         static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( EAvkonSIDPowerOffTone );
  1222 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
  4805 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
  1223 
  4806 
  1224 #ifndef __SYSAP_MODULE_TEST //to make errors during shutdown sequence being seen more easily
  4807 #ifndef __SYSAP_MODULE_TEST //to make errors during shutdown sequence being seen more easily
  1225     iEikonEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront );
  4808     iEikonEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront );
  1226     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() Show Shutdown image" ) ) );
  4809     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() Show Shutdown image" ) ) );
  1227     ShowShutdownImage( 1  );//EMbmSysapQgn_startup_screen
  4810     ShowShutdownImage( EMbmSysapQgn_startup_screen );
  1228 #endif
  4811 #endif
  1229     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() END" ) ) );
  4812     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownImage() END" ) ) );
       
  4813     }
       
  4814 
       
  4815 // ----------------------------------------------------------------------------
       
  4816 // CSysApAppUi::SetStatusPaneLauoutL( const TSysApPhoneState aState )
       
  4817 // ----------------------------------------------------------------------------
       
  4818 
       
  4819 void CSysApAppUi::SetStatusPaneLayoutL( const TSysApPhoneState aState )
       
  4820     {
       
  4821     TRACES( RDebug::Print( _L("CSysApAppUi::SetStatusPaneLayoutL aState: %d"), aState ) );
       
  4822     if( aState == ESysApNormal )
       
  4823         //Status pane cannot be even visible on Normal mode
       
  4824         {
       
  4825         StatusPane()->MakeVisible( EFalse );
       
  4826         StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_EMPTY );
       
  4827         }
       
  4828     else if( aState == ESysApCharging )
       
  4829         //SysAp's statuspane is visible on Charging mode
       
  4830         {
       
  4831         StatusPane()->MakeVisible( ETrue );
       
  4832         StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE );
       
  4833         }
       
  4834     else if( aState == ESysApAlarm )
       
  4835     	{
       
  4836     	if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  4837     		{
       
  4838     		// Portrait mode
       
  4839 	        StatusPane()->MakeVisible( ETrue );
       
  4840 	        StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE );
       
  4841     		}
       
  4842     	else
       
  4843     		{
       
  4844     		// Landscape mode
       
  4845 	        TInt layout = R_AVKON_STATUS_PANE_LAYOUT_POWER_OFF_RECHARGE;
       
  4846 	        // For side softkey devices, use different layout
       
  4847 	        if (AVKONENV->StatusPaneResIdForCurrentLayout(R_AVKON_STATUS_PANE_LAYOUT_USUAL) == R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_RIGHT)
       
  4848 	        	layout = R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_RIGHT;
       
  4849 	        else if (AVKONENV->StatusPaneResIdForCurrentLayout(R_AVKON_STATUS_PANE_LAYOUT_USUAL) == R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_LEFT)
       
  4850 	        	layout = R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_LEFT;
       
  4851 
       
  4852 	        StatusPane()->MakeVisible( ETrue );
       
  4853 	        StatusPane()->SwitchLayoutL( layout );
       
  4854     		}
       
  4855     	}
  1230     }
  4856     }
  1231 
  4857 
  1232 // ----------------------------------------------------------------------------
  4858 // ----------------------------------------------------------------------------
  1233 // CSysApAppUi::OkToInitiateShutdown()
  4859 // CSysApAppUi::OkToInitiateShutdown()
  1234 // ----------------------------------------------------------------------------
  4860 // ----------------------------------------------------------------------------
  1258         {
  4884         {
  1259         return EFalse;
  4885         return EFalse;
  1260         }
  4886         }
  1261     }
  4887     }
  1262 
  4888 
  1263 
  4889 /**
  1264 void CSysApAppUi::PopupNote()
  4890  * To check the for an emergency call. 
  1265     {
  4891  * 
  1266     iIgnoreNextPowerKeyUpEvent = ETrue;
  4892  * @return ETrue if there is an emergency call active otherwise, EFalse.
  1267     // TRACES( RDebug::Print( _L("CSysApAppUi::Key was consumed") ) );
  4893  */
  1268     _LIT(KPowerPressKey,"Short power key");
  4894 TBool IsEmergencyCall()
  1269     HBufC* aString = HBufC16::NewLC(50);
  4895         {
  1270     TPtrC aStringPointer = aString->Des();
  4896         TBool retVal( EFalse );
  1271     aStringPointer.Set(KPowerPressKey);
  4897         TInt err( KErrNone );
  1272     TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
  4898         TInt state( 0 );
  1273     ShowExampleUiNoteL( aStringPointer );  
  4899      
  1274     CleanupStack::PopAndDestroy(); // aString
  4900         err = RProperty::Get(KPSUidCtsyEmergencyCallInfo, KCTSYEmergencyCallInfo, state );
  1275     }
  4901         if ( err == KErrNone && state )
  1276 
  4902             {
  1277 
  4903             retVal = ETrue;            
  1278 // ----------------------------------------------------------------------------
  4904             }
  1279 // CSysApAppUi::SetUsbAttachStatus
  4905         return retVal;
  1280 // ----------------------------------------------------------------------------
  4906         }	
  1281 #ifndef RD_MULTIPLE_DRIVE
       
  1282 void CSysApAppUi::SetUsbAttachStatus( const TBool aUsbAttached )
       
  1283     {
       
  1284     // Prevent double beep when USB file transfer gets activated but
       
  1285     // allow MMC inserted beep when:
       
  1286     // a) USB file transfer is active
       
  1287     // b) MMC is not inserted when USB cable is attached
       
  1288     iHideNextBeep = ( iMMCInserted && aUsbAttached );
       
  1289     }
       
  1290 #else // RD_MULTIPLE_DRIVE
       
  1291 void CSysApAppUi::SetUsbAttachStatus( const TBool aUsbAttached )
       
  1292     {
       
  1293     TRACES( RDebug::Print(
       
  1294         _L( "CSysApAppUi::SetUsbAttachStatus: aUsbAttached: %d" ),
       
  1295         aUsbAttached ) );
       
  1296 
       
  1297     if ( aUsbAttached )
       
  1298         {
       
  1299           // For ignoring extra beeps caused by USB file transfer
       
  1300         iSysApDriveList->ResetDrivesInsertBeepIgnored();
       
  1301         iSysApDriveList->MarkDrivesInsertBeepIgnored( iInsertedMemoryCards );
       
  1302         }
       
  1303     }
       
  1304 #endif // RD_MULTIPLE_DRIVE
       
  1305 
       
  1306 
       
  1307 // ----------------------------------------------------------------------------
       
  1308 // CSysApAppUi::UsbChargerDetector
       
  1309 // ----------------------------------------------------------------------------
       
  1310 //
       
  1311 TSysApUsbChargerDetector& CSysApAppUi::UsbChargerDetector()
       
  1312     {
       
  1313     return iSysApUsbChargerDetector;
       
  1314     }
       
  1315 
       
  1316 
       
  1317 // ----------------------------------------------------------------------------
       
  1318 // CSysApAppUi::HandleAccessoryDisconnectedL()
       
  1319 // ----------------------------------------------------------------------------
       
  1320 
       
  1321 void CSysApAppUi::HandleAccessoryDisconnectedL()
       
  1322     {
       
  1323     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryDisconnectedL()" ) ) );
       
  1324 
       
  1325 
       
  1326     TAccMode accessoryState(EAccModeHandPortable);
       
  1327     if ( iSysApAccessoryObserver )
       
  1328         {
       
  1329         accessoryState = iSysApAccessoryObserver->GetAccessoryMode();
       
  1330         }
       
  1331 
       
  1332     if ( accessoryState == EAccModeHandPortable )
       
  1333         {
       
  1334         TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryDisconnectedL:Before Deactivating accessory Plugin")));
       
  1335         iHbIndicatorSymbian->Deactivate(KAccesoryPlugin);
       
  1336         TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryDisconnectedL:After  Deactivating accessory Plugin")));
       
  1337         iSysApLightsController->AccessoryConnectedL( EFalse );
       
  1338         iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected, 0 );
       
  1339         }
       
  1340 
       
  1341     SetIhfIndicatorL();
       
  1342     SetHacIndicatorL();
       
  1343 
       
  1344     // If lock disabled because of accessory, reactivate it, unless phone call or alarm is ongoing
       
  1345     if ( iKeyLockOnBeforeCradle )
       
  1346         {
       
  1347         iKeyLockOnBeforeCradle = EFalse;
       
  1348         if ( !iKeyLockOnBeforeCall && !iKeyLockOnBeforeAlarm )
       
  1349             {
       
  1350             if ( !iDeviceLockEnabled )
       
  1351                 {
       
  1352                 iKeyguardController->EnableKeyguard(ETrue);
       
  1353                 }
       
  1354             else
       
  1355                 {
       
  1356                 iKeyguardController->EnableKeyguard(EFalse);
       
  1357                 }
       
  1358             }
       
  1359         }
       
  1360     }
       
  1361 
       
  1362 
       
  1363 // ----------------------------------------------------------------------------
       
  1364 // CSysApAppUi::HandleAccessoryConnectedL()
       
  1365 // ----------------------------------------------------------------------------
       
  1366 
       
  1367 void CSysApAppUi::HandleAccessoryConnectedL( TAccMode aAccessoryState, TInt aPhysicalConnectionType )
       
  1368     {
       
  1369     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryConnectedL( aAccessoryState: %d )(aPhysicalConnectionType: %d "), aAccessoryState, aPhysicalConnectionType ) );
       
  1370 
       
  1371     CHbSymbianVariantMap* iAccVariantMap = CHbSymbianVariantMap::NewL();
       
  1372     CleanupStack::PushL(iAccVariantMap);
       
  1373     CHbSymbianVariant* variantAccState = CHbSymbianVariant::NewL(&aAccessoryState, CHbSymbianVariant::EInt);
       
  1374     iAccVariantMap->Add(KAccMode,variantAccState);
       
  1375     CHbSymbianVariant* variantAccType = CHbSymbianVariant::NewL(&aPhysicalConnectionType, CHbSymbianVariant::EInt);
       
  1376     iAccVariantMap->Add(KAccPhyConType,variantAccType);
       
  1377     
       
  1378     
       
  1379     CHbSymbianVariant* iAccVariant = CHbSymbianVariant::NewL(iAccVariantMap, CHbSymbianVariant::EVariantMap ); 
       
  1380     CleanupStack::PushL(iAccVariant);
       
  1381     iHbIndicatorSymbian->Activate(KAccesoryPlugin, iAccVariant);
       
  1382 
       
  1383 
       
  1384     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  1385     TRACES( RDebug::Print( _L("CSysApAppUi::HandleAccessoryConnectedL: swState: %d"), swState ) );
       
  1386 
       
  1387     if( UiReady() || swState == ESwStateSecurityCheck )
       
  1388         {
       
  1389         iSysApLightsController->AccessoryConnectedL( ETrue );
       
  1390         }
       
  1391 
       
  1392     if ( ( ! iSysApOfflineModeController->OfflineModeActive() ))
       
  1393         {
       
  1394         if ( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected ) < 1 )
       
  1395             // accessory not connected already
       
  1396              {
       
  1397             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected, 1 );
       
  1398            }
       
  1399         }
       
  1400     
       
  1401     // Carkit and music stand have also light on permanently option that needs to be checked
       
  1402     if( aAccessoryState == EAccModeWiredCarKit || aAccessoryState == EAccModeMusicStand )
       
  1403         {
       
  1404         // When device is placed on a handsfree cradle, keyguard must be disabled (unless device is locked)
       
  1405         // Note: It is assumed that if carkit/music stand is connected, the phone is in the cradle.
       
  1406         if ( iKeyLockEnabled || iDeviceLockEnabled || iKeyLockOnBeforeCall || iKeyLockOnBeforeAlarm )
       
  1407             {
       
  1408             iKeyLockOnBeforeCradle = ETrue;
       
  1409 
       
  1410             if ( iKeyLockEnabled && !iDeviceLockEnabled )
       
  1411                 {
       
  1412                 iKeyguardController->DisableKeyguard(EFalse);
       
  1413                 }
       
  1414             }
       
  1415         }
       
  1416     SetIhfIndicatorL();
       
  1417     SetHacIndicatorL();
       
  1418     CleanupStack::PopAndDestroy(2);
       
  1419     }
       
  1420 
       
  1421 
       
  1422 // ----------------------------------------------------------------------------
       
  1423 // CSysApAppUi::SetHacIndicatorL()
       
  1424 // ----------------------------------------------------------------------------
       
  1425 void CSysApAppUi::SetHacIndicatorL()
       
  1426     {
       
  1427 
       
  1428     if ( !iSysApCenRepHacSettingObserver )
       
  1429         {
       
  1430         // Do nothing if HAC setting observer has not been created yet
       
  1431         // This occurs in case some party is trying to set HAC indicator during
       
  1432         // ConstructL(), e.g. when switching from offline to online during startup
       
  1433         TRACES( RDebug::Print( _L("CSysApAppUi::SetHacIndicatorL: do nothing, HAC observer does not exist yet") ) );
       
  1434         return;
       
  1435         }
       
  1436 
       
  1437     if ( iSysApCenRepHacSettingObserver->HacMode() )
       
  1438         {
       
  1439         TBool accessoryConnected ( EFalse );
       
  1440 
       
  1441         TAccMode accMode(EAccModeHandPortable);
       
  1442 
       
  1443         if ( iSysApAccessoryObserver )
       
  1444             {
       
  1445             accMode = iSysApAccessoryObserver->GetAccessoryMode();
       
  1446 
       
  1447             if ( accMode != EAccModeHandPortable )
       
  1448                 {
       
  1449                 accessoryConnected = ETrue;
       
  1450                 }
       
  1451             }
       
  1452 
       
  1453 //        TInt indicatorState = EAknIndicatorStateOn;
       
  1454 
       
  1455         if ( !accessoryConnected ) // When accessory is not connected, check offline and call state
       
  1456             {
       
  1457             if ( OfflineModeActive() ) // HAC indicator is not shown in offline mode
       
  1458                 {
       
  1459  //               indicatorState = EAknIndicatorStateOff;
       
  1460                 }
       
  1461             else
       
  1462                 {
       
  1463                 // during active call with IHF activated HAC indicator is not shown
       
  1464                 TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  1465                 if ( callState < KErrNone )
       
  1466                     {
       
  1467                     callState = EPSCTsyCallStateNone;
       
  1468                     }
       
  1469 
       
  1470                 if ( callState != EPSCTsyCallStateNone && IhfEnabledL() )
       
  1471                     {
       
  1472  //                   indicatorState = EAknIndicatorStateOff;
       
  1473                     }
       
  1474                 }
       
  1475 
       
  1476             }
       
  1477         else
       
  1478             {
       
  1479             // If an accessory is connected, HAC indicator should not be shown
       
  1480 //            indicatorState = EAknIndicatorStateOff;
       
  1481             }
       
  1482 
       
  1483  //       SetIndicatorStateL( EAknIndicatorHAC, indicatorState );
       
  1484 
       
  1485         }
       
  1486     else
       
  1487         {
       
  1488         // If HAC is not active, always disable indicator regardless of accessory state
       
  1489  //       SetIndicatorStateL( EAknIndicatorHAC, EAknIndicatorStateOff );
       
  1490         }
       
  1491 
       
  1492 
       
  1493     }
       
  1494 
       
  1495 
       
  1496 // ----------------------------------------------------------------------------
       
  1497 // CSysApAppUi::DoNotActivateBt()
       
  1498 // ----------------------------------------------------------------------------
       
  1499 void CSysApAppUi::DoNotActivateBt()
       
  1500     {
       
  1501     iSysApOfflineModeController->DoNotActivateBt();
       
  1502     }
       
  1503 
       
  1504 
       
  1505 // ----------------------------------------------------------------------------
       
  1506 // CSysApAppUi::IhfEnabledL
       
  1507 // ----------------------------------------------------------------------------
       
  1508 
       
  1509 TBool CSysApAppUi::IhfEnabledL()
       
  1510     {
       
  1511     TRACES( RDebug::Print( _L("CSysApAppUi::IhfEnabledL(): iSysApAudioRoutingObserver=0x%x"), iSysApAudioRoutingObserver ) );
       
  1512 
       
  1513     if ( !iSysApAudioRoutingObserver ) // create observer if needed
       
  1514         {
       
  1515         iSysApAudioRoutingObserver = CSysApAudioRoutingObserver::NewL( *this );
       
  1516         }
       
  1517 
       
  1518     return iSysApAudioRoutingObserver->IhfEnabled();
       
  1519     }
       
  1520 
       
  1521 
       
  1522 // ----------------------------------------------------------------------------
       
  1523 // CSysApAppUi::SetIhfIndicatorL()
       
  1524 // ----------------------------------------------------------------------------
       
  1525 void CSysApAppUi::SetIhfIndicatorL()
       
  1526     {
       
  1527     TBool accessoryConnected ( EFalse );
       
  1528 
       
  1529     TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  1530 
       
  1531     TAccMode accMode(EAccModeHandPortable);
       
  1532 
       
  1533     if ( iSysApAccessoryObserver )
       
  1534         {
       
  1535         accMode = iSysApAccessoryObserver->GetAccessoryMode();
       
  1536 
       
  1537         if ( accMode != EAccModeHandPortable )
       
  1538             {
       
  1539             accessoryConnected = ETrue;
       
  1540             }
       
  1541         }
       
  1542 
       
  1543     if( (callState != EPSCTsyCallStateNone && IhfEnabledL() && !accessoryConnected)
       
  1544         || accMode == EAccModeMusicStand )  // Music stand always shows IHF indicator
       
  1545         {
       
  1546         if ( accMode == EAccModeMusicStand )
       
  1547             {
       
  1548             // do nothing
       
  1549             }
       
  1550         }
       
  1551     else
       
  1552         {
       
  1553         // do nothing
       
  1554         }
       
  1555     }
       
  1556 
       
  1557 // ----------------------------------------------------------------------------
       
  1558 // CSysApAppUi::EjectStarted()
       
  1559 // ----------------------------------------------------------------------------
       
  1560 
       
  1561 void CSysApAppUi::EjectStarted( TBool ejectStarted )
       
  1562     {
       
  1563     TRACES( RDebug::Print( _L( "CSysApAppUi::EjectStarted" ) ) );
       
  1564     iMMCEjectUsed = ejectStarted;
       
  1565     
       
  1566 #ifndef RD_MULTIPLE_DRIVE
       
  1567     iFileManagerCloseDisabled = ejectStarted;
       
  1568 #endif // RD_MULTIPLE_DRIVE
       
  1569 }
       
  1570 
       
  1571 // ----------------------------------------------------------------------------
       
  1572 // CSysApAppUi::DoLightsTimeoutChangedL
       
  1573 // ----------------------------------------------------------------------------
       
  1574 void CSysApAppUi::DoLightsTimeoutChangedL( const TInt aTimeout )
       
  1575     {
       
  1576     iSysApLightsController->DoLightsTimeoutChangedL( aTimeout );
       
  1577     }
       
  1578 
       
  1579 
       
  1580 // ----------------------------------------------------------------------------
       
  1581 // CSysApAppUi::DoSwStateNormalConstructionL()
       
  1582 // ----------------------------------------------------------------------------
       
  1583 
       
  1584 void CSysApAppUi::DoSwStateNormalConstructionL()
       
  1585     {
       
  1586     // Let's ensure that the lights will remain on for 15 secs after sw state normal
       
  1587     User::ResetInactivityTime();
       
  1588 
       
  1589     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL : START" ) ) );
       
  1590 
       
  1591     // In case of unexpected reset (e.g. hidden boot) the keylock must be enabled silently. Locking is done
       
  1592     // prior to time-consuming initializations, because otherwise UI is in unlocked state for a few seconds.
       
  1593     if ( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive ) == 1  )
       
  1594         {
       
  1595         TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL: enabling keylock") ) );
       
  1596         iKeyguardController->EnableKeyguard(ETrue);
       
  1597         }
       
  1598 
       
  1599     // Initiate bearer change observation
       
  1600 //    iSysApConnectionMonitorObserver = CSysApConnectionMonitorObserver::NewL( *this );
       
  1601 
       
  1602     TRACES( RDebug::Print( _L("SysAp: trying CSystemLock::NewL" ) ) );
       
  1603     iSysApSystemLock = CSystemLock::NewL();
       
  1604 
       
  1605     
       
  1606     if ( iSysApFeatureManager->Supported( KSysApFeatureIdBatteryInfoPopup ) )
       
  1607         {
       
  1608         iSysApBatteryInfoController = CSysApBatteryInfoController::NewL( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsConf, 
       
  1609                                                                                                      KCoreAppUIsBatteryInformationLowThreshold ) );    
       
  1610         }
       
  1611     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL : END" ) ) );
       
  1612     }
       
  1613 
       
  1614 
       
  1615 
       
  1616 // ----------------------------------------------------------------------------
       
  1617 // CSysApAppUi::DoSimChangedFromPreviousBootL()
       
  1618 // ----------------------------------------------------------------------------
       
  1619 
       
  1620 void CSysApAppUi::DoSimChangedFromPreviousBootL()
       
  1621     {
       
  1622     TRACES( RDebug::Print( _L("CSysApAppUi::DoSimChangedFromPreviousBootL: iSimChangedDone=%d" ), iSimChangedDone ) );
       
  1623 
       
  1624     if ( !iSimChangedDone  )
       
  1625         {
       
  1626         iSimChangedDone = ETrue;
       
  1627         CSysApSimChanged* simChanged = CSysApSimChanged::NewL( *this, iEikonEnv->FsSession() );
       
  1628         CleanupStack::PushL( simChanged );
       
  1629         simChanged->HandleSimChangedL();
       
  1630         CleanupStack::PopAndDestroy( simChanged );
       
  1631         }
       
  1632     }
       
  1633 
       
  1634 
       
  1635 // ----------------------------------------------------------------------------
       
  1636 // CSysApAppUi::IgnoreZeroNetworkBarNotifications
       
  1637 // ----------------------------------------------------------------------------
       
  1638 //
       
  1639 void CSysApAppUi::IgnoreZeroNetworkBarNotifications(TBool aIgnore)
       
  1640     {
       
  1641     iIgnoreZeroNetworkBarNotifications = aIgnore;
       
  1642     }
       
  1643 
       
  1644 
       
  1645 
       
  1646 // ----------------------------------------------------------------------------
       
  1647 // CSysApAppUi::SwitchFromOnlineToOfflineModeL()
       
  1648 // ----------------------------------------------------------------------------
       
  1649 void CSysApAppUi::SwitchFromOnlineToOfflineModeL()
       
  1650     {
       
  1651    iSysApOfflineModeController->SwitchFromOnlineToOfflineModeL();
       
  1652     }
       
  1653 
       
  1654 
       
  1655 // ----------------------------------------------------------------------------
       
  1656 // CSysApAppUi::InitCloseSimApplicationsL()
       
  1657 // ----------------------------------------------------------------------------
       
  1658 void CSysApAppUi::InitCloseSimApplicationsL()
       
  1659     {
       
  1660     iApplicationScanningRoundNumberInBtSap = 0;
       
  1661     iTimeToKillInBtSap = EFalse;
       
  1662     CloseSimApplicationsL();
       
  1663     }
       
  1664 
       
  1665 
       
  1666 // ----------------------------------------------------------------------------
       
  1667 // CSysApAppUi::CloseSimApplicationsL()
       
  1668 // ----------------------------------------------------------------------------
       
  1669 void CSysApAppUi::CloseSimApplicationsL()
       
  1670     {
       
  1671     iApplicationScanningRoundNumberInBtSap++;
       
  1672     TRACES( RDebug::Print( _L("CSysApAppUi::CloseSimApplicationsL: scanning round = %d"),
       
  1673                            iApplicationScanningRoundNumberInBtSap ) );
       
  1674 
       
  1675     if ( iApplicationScanningRoundNumberInBtSap == KMaxExitTimeInBtSap )
       
  1676         {
       
  1677         iTimeToKillInBtSap = ETrue;
       
  1678         }
       
  1679 
       
  1680     const TInt KNumberOfSimDependantApps( 7 );
       
  1681     TUid simDependantAppUid[ KNumberOfSimDependantApps ];
       
  1682     simDependantAppUid[ 0 ] = KSysApGSUid;
       
  1683     simDependantAppUid[ 1 ] = KSysApSATUid;
       
  1684     simDependantAppUid[ 2 ] = KSysApMailboxUid;
       
  1685     simDependantAppUid[ 3 ] = KSysApSpeedDialingUid;
       
  1686     simDependantAppUid[ 4 ] = KSysApSimDirectoryUid;
       
  1687     simDependantAppUid[ 5 ] = KSysApMCEUid;
       
  1688     simDependantAppUid[ 6 ] = KSysApCellBroadcastMessagesUid;
       
  1689 
       
  1690     TBool appsExiting( EFalse );
       
  1691     TApaTaskList apaTaskList( CCoeEnv::Static()->WsSession() );
       
  1692 
       
  1693     for ( TInt i = 0; i < KNumberOfSimDependantApps; i++ )
       
  1694         {
       
  1695         TApaTask apaTask = apaTaskList.FindApp( simDependantAppUid[ i ] );
       
  1696         if ( apaTask.Exists() )
       
  1697             {
       
  1698             appsExiting = ETrue;
       
  1699             if ( iApplicationScanningRoundNumberInBtSap == 1 )
       
  1700                 {
       
  1701                 apaTask.EndTask();  // applications are kindly requested to close themselves on the first round
       
  1702                 }
       
  1703             else if ( iTimeToKillInBtSap )
       
  1704                 {
       
  1705                 apaTask.KillTask(); // used after timeout on the last round
       
  1706                 }
       
  1707             }
       
  1708         }
       
  1709 
       
  1710     if ( !appsExiting || iTimeToKillInBtSap )
       
  1711         {
       
  1712         iSysApBtSapController->SimApplicationsClosed();
       
  1713         }
       
  1714     else
       
  1715         {
       
  1716         if ( !iSapTimer )
       
  1717             {
       
  1718             iSapTimer = CPeriodic::NewL( EPriorityNormal );
       
  1719             }
       
  1720         iSapTimer->Cancel();
       
  1721         iSapTimer->Start( KDelayBeforeNextScanningRound,
       
  1722                           KDelayBeforeNextScanningRound,
       
  1723                           TCallBack( DoCloseSimApplicationsAfterCallBack, this ) );
       
  1724         }
       
  1725     }
       
  1726 
       
  1727 
       
  1728 // ----------------------------------------------------------------------------
       
  1729 // CSysApAppUi::DoCloseSimApplicationsAfterCallBack
       
  1730 // ----------------------------------------------------------------------------
       
  1731 TInt CSysApAppUi::DoCloseSimApplicationsAfterCallBack( TAny* aObject )
       
  1732     {
       
  1733     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  1734 
       
  1735     if ( appUi->iSapTimer )
       
  1736         {
       
  1737         appUi->iSapTimer->Cancel();
       
  1738         }
       
  1739 
       
  1740     TRAP_IGNORE( appUi->CloseSimApplicationsL() );
       
  1741 
       
  1742     return KErrNone;
       
  1743     }
       
  1744 
       
  1745 
       
  1746 // ----------------------------------------------------------------------------
       
  1747 // CSysApAppUi::NotifyPowerSaveModeL
       
  1748 // ----------------------------------------------------------------------------
       
  1749 //
       
  1750 void CSysApAppUi::NotifyPowerSaveModeL( TSysApPsmStatus aStatus )
       
  1751     {
       
  1752     TRACES( RDebug::Print( _L("CSysApAppUi::NotifyPowerSaveModeL aStatus: %d"), aStatus ) );
       
  1753 
       
  1754     // cancel any active power saving query because user has changed the state manually
       
  1755     // CancelQuery( ESysApBattChargingPowerSavingQuery );
       
  1756     // CancelQuery( ESysApBattLowPowerSavingQuery );
       
  1757     // will take care in next sub
       
  1758     
       
  1759     switch ( aStatus )
       
  1760         {
       
  1761         case MSysApPsmControllerNotifyCallback::EPsmActivationComplete:
       
  1762              UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  1763              iVariantAccState = CHbSymbianVariant::NewL(&KPsm, CHbSymbianVariant::EDes);
       
  1764              if (!iHbIndicatorSymbian->Activate(KPsmPlugin,iVariantAccState)) 
       
  1765                 {
       
  1766                 int error = iHbIndicatorSymbian->Error();
       
  1767                 //use the errorcode...
       
  1768                 }
       
  1769              break;
       
  1770         
       
  1771         case MSysApPsmControllerNotifyCallback::EPsmDeactivationComplete:
       
  1772              UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  1773              if (!iHbIndicatorSymbian->Deactivate(KPsmPlugin)) 
       
  1774                 {
       
  1775                 int error = iHbIndicatorSymbian->Error();
       
  1776                  //use the errorcode...
       
  1777                 }
       
  1778             break;
       
  1779             
       
  1780         case MSysApPsmControllerNotifyCallback::EPsmActivationFailed:
       
  1781             ShowUiNoteL( ECannotActivatePowerSaveMode );
       
  1782             break;
       
  1783             
       
  1784         case MSysApPsmControllerNotifyCallback::EPsmDeactivationFailed:
       
  1785             ShowUiNoteL( ECannotDeactivatePowerSaveMode );
       
  1786             break;            
       
  1787         
       
  1788         default:
       
  1789             break;   
       
  1790         }
       
  1791     }
       
  1792 
       
  1793 
       
  1794 // ----------------------------------------------------------------------------
       
  1795 // CSysApAppUi::ShowAlarmIndicatorL()
       
  1796 // ----------------------------------------------------------------------------
       
  1797 
       
  1798 void CSysApAppUi::ShowAlarmIndicatorL( TBool aShowIndicator )
       
  1799     {
       
  1800     if ( aShowIndicator)
       
  1801         {
       
  1802         // do nothing
       
  1803         }
       
  1804     else
       
  1805         {
       
  1806         // do nothing
       
  1807         }
       
  1808     }
       
  1809 
       
  1810 
       
  1811 // ----------------------------------------------------------------------------
       
  1812 // CSysApAppUi::AlertUiAlertingL( const TBool aAlerting )
       
  1813 // ----------------------------------------------------------------------------
       
  1814 void CSysApAppUi::AlertUiAlertingL( const TBool aAlerting )
       
  1815     {
       
  1816     TRACES( RDebug::Print( _L("CSysApAppUi::AlertUiAlerting aAlerting:%d"), aAlerting ) );
       
  1817 
       
  1818     if ( aAlerting )
       
  1819         {
       
  1820         TInt swState;
       
  1821         RProperty::Get( KPSUidStartup, KPSGlobalSystemState, swState );
       
  1822 
       
  1823         if( swState == ESwStateCharging )
       
  1824             {
       
  1825             SetStarterState( RStarterSession::EAlarm );
       
  1826             }
       
  1827         }
       
  1828 
       
  1829     iSysApLightsController->AlarmOccuredL( aAlerting );
       
  1830     }
       
  1831 
       
  1832 
       
  1833 // ----------------------------------------------------------------------------
       
  1834 // CSysApAppUi::HandleForcedLightsVTRequireL( const TInt aLightParameter )
       
  1835 // ----------------------------------------------------------------------------
       
  1836 
       
  1837 void CSysApAppUi::HandleForcedLightsVTRequireL( const TInt aLightsParameter ) const
       
  1838     {
       
  1839     iSysApLightsController->HandleForcedLightsVTRequireL( aLightsParameter );
       
  1840     }
       
  1841 
       
  1842 
       
  1843 // ----------------------------------------------------------------------------
       
  1844 // CSysApAppUi::HandleForcedLightsSSRequireL( const TInt aLightParameter )
       
  1845 // ----------------------------------------------------------------------------
       
  1846 
       
  1847 void CSysApAppUi::HandleForcedLightsSSRequireL( const TInt aLightsParameter ) const
       
  1848     {
       
  1849     iSysApLightsController->HandleForcedLightsSSRequireL( aLightsParameter );
       
  1850     }
       
  1851 
       
  1852 // ---------------------------------------------------------------------------- 
       
  1853 // CSysApAppUi::HandleForcedLightsATCRequireL( const TInt aLightParameter ) 
       
  1854 // ---------------------------------------------------------------------------- 
       
  1855 void CSysApAppUi::HandleForcedLightsATCRequireL( const TInt aLightsParameter ) const 
       
  1856     { 
       
  1857     iSysApLightsController->HandleForcedLightsATCRequireL( aLightsParameter ); 
       
  1858     } 
       
  1859 
       
  1860 
       
  1861 // ----------------------------------------------------------------------------
       
  1862 // CSysApAppUi::HandleLightsRequireL()
       
  1863 // ----------------------------------------------------------------------------
       
  1864 
       
  1865 void CSysApAppUi::HandleLightsRequireL() const
       
  1866     {
       
  1867     iSysApLightsController->HandleLightsRequireL();
       
  1868     }
       
  1869 
       
  1870 
       
  1871 // ----------------------------------------------------------------------------
       
  1872 // CSysApAppUi::HandleRawKeyEventLightsRequireL()
       
  1873 // ----------------------------------------------------------------------------
       
  1874 
       
  1875 void CSysApAppUi::HandleRawKeyEventLightsRequireL() const
       
  1876     {
       
  1877     iSysApLightsController->HandleRawKeyEventLightsRequireL();
       
  1878     }
       
  1879 
       
  1880 
       
  1881 // ----------------------------------------------------------------------------
       
  1882 // CSysApAppUi::AlertUiKeyLockOff( const TBool aKeyLockOff )
       
  1883 // ----------------------------------------------------------------------------
       
  1884 
       
  1885 void CSysApAppUi::AlertUiKeyLockOff( const TBool aKeyLockOff )
       
  1886     {
       
  1887     TRACES( RDebug::Print( _L("CSysApAppUi::AlertUiKeyLockOff aKeyLockOff:%d, devicelock:%d"), 
       
  1888         aKeyLockOff, iDeviceLockEnabled ) );
       
  1889     
       
  1890     if( aKeyLockOff )
       
  1891         {
       
  1892         // Notification to release keypad might come several times if e.g. calls are received
       
  1893         if ( !iKeyLockOnBeforeAlarm )
       
  1894             {
       
  1895             if ( iKeyLockEnabled || iKeyLockOnBeforeCradle || iKeyLockOnBeforeCall )
       
  1896                 {
       
  1897                 iKeyLockOnBeforeAlarm = ETrue;
       
  1898                 }
       
  1899             }
       
  1900         iKeyguardController->DisableKeyguard(EFalse);
       
  1901         }
       
  1902     else
       
  1903         {
       
  1904         if (iDeviceLockEnabled)
       
  1905             {
       
  1906             // Re-enable keylock in devicelock case only if phone call is not ongoing or is 
       
  1907             // connected. Otherwise e.g. messages can be read using softkeys during ongoing call.
       
  1908             TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  1909             if ( callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateConnected )
       
  1910                 {
       
  1911                 iKeyguardController->EnableKeyguard(EFalse);
       
  1912                 }
       
  1913             }
       
  1914         else if ( iKeyLockOnBeforeAlarm && !iKeyLockOnBeforeCradle && !iKeyLockOnBeforeCall )
       
  1915             {
       
  1916             iKeyguardController->EnableKeyguard(ETrue);
       
  1917             }
       
  1918         iKeyLockOnBeforeAlarm = EFalse;
       
  1919         }
       
  1920     }
       
  1921 
       
  1922 
       
  1923 // ----------------------------------------------------------------------------
       
  1924 // CSysApAppUi::DoNotEnableKeylock()
       
  1925 // ----------------------------------------------------------------------------
       
  1926 
       
  1927 void CSysApAppUi::DoNotEnableKeylock()
       
  1928     {
       
  1929     if ( !iKeyLockOnBeforeCradle )
       
  1930         {
       
  1931         iShowkeypadActivatedNoteAfterSoftReject = iKeyLockOnBeforeCall;
       
  1932         }
       
  1933 
       
  1934     iKeyLockOnBeforeCall = EFalse;
       
  1935     }
       
  1936 
       
  1937 
       
  1938 // ----------------------------------------------------------------------------
       
  1939 // CSysApAppUi::SwitchLightsOnSoftRejectL()
       
  1940 // ----------------------------------------------------------------------------
       
  1941 void CSysApAppUi::SwitchLightsOnSoftRejectL()
       
  1942     {
       
  1943     iSysApLightsController->SwitchLightsOnSoftRejectL();
       
  1944     }
       
  1945 
       
  1946 
       
  1947 // ----------------------------------------------------------------------------
       
  1948 // CSysApAppUi::SetDeviceLockEnabledL( const TBool aLockEnabled )
       
  1949 // ----------------------------------------------------------------------------
       
  1950 
       
  1951 void CSysApAppUi::SetDeviceLockEnabledL( const TBool aLockEnabled )
       
  1952     {
       
  1953     TRACES( RDebug::Print(_L("CSysApAppUi::SetDeviceLockEnabledL aLockEnabled:%d" ), aLockEnabled ) );
       
  1954     TBool currentState( iDeviceLockEnabled );
       
  1955     
       
  1956     iDeviceLockEnabled = aLockEnabled;
       
  1957     
       
  1958     if ( currentState != iDeviceLockEnabled ) // filter out unnecessary light status modifications
       
  1959         {
       
  1960         iSysApLightsController->DeviceLockStateChangedL( iDeviceLockEnabled );
       
  1961         }
       
  1962     
       
  1963     if( iDeviceLockEnabled )
       
  1964         {
       
  1965         if( iKeyLockEnabled )
       
  1966             {
       
  1967             iKeyguardController->DisableKeyguard(EFalse);
       
  1968             }
       
  1969         }
       
  1970     else
       
  1971         {
       
  1972         // let's not activate keylock in case device lock was disabled during call or in cradle
       
  1973         iKeyLockOnBeforeCall = EFalse;
       
  1974         iKeyLockOnBeforeCradle = EFalse;
       
  1975 
       
  1976         // Memory card needs to be unlocked when device is unlocked
       
  1977         if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  1978             {
       
  1979              RunUnlockNotifierL();
       
  1980             // Need to handle feature for unlocking the MMC card
       
  1981             }
       
  1982         }
       
  1983     }
       
  1984 
       
  1985 
       
  1986 // ----------------------------------------------------------------------------
       
  1987 // CSysApAppUi::HandleBatteryStatusL
       
  1988 // ----------------------------------------------------------------------------
       
  1989 //
       
  1990 void CSysApAppUi::HandleBatteryStatusL( const TInt aValue )
       
  1991     {
       
  1992     TRACES( RDebug::Print( _L("CSysApAppUi::HandleBatteryStatusL aValue: %d"), aValue ) );
       
  1993     
       
  1994     TBool enableAutoPsm(EFalse);
       
  1995     CRepository* repository( NULL );
       
  1996     TRAPD( err, repository = CRepository::NewL( KCRUidDeviceManagementSettings ) );
       
  1997         
       
  1998     if ( err == KErrNone )
       
  1999        {
       
  2000        TInt value( 0 );
       
  2001        err = repository->Get( KSettingsPowerSavingQuery, value );
       
  2002             
       
  2003        if ( err == KErrNone )
       
  2004           {
       
  2005           enableAutoPsm = value ? EFalse: ETrue;
       
  2006           }
       
  2007        }
       
  2008       
       
  2009      _LIT(Klowbattery, "txt_power_management_dpopinfo_low_battery");
       
  2010      // returns the string "low battery"
       
  2011      HBufC* lowBattery = HbTextResolverSymbian::LoadL(Klowbattery);    
       
  2012     
       
  2013     
       
  2014     if ( aValue == EBatteryStatusEmpty )
       
  2015         {
       
  2016         //Display Recharge Battery note
       
  2017         ShowUiNoteL( ERechargeBatteryNote );
       
  2018         BatteryEmptyL();
       
  2019         }
       
  2020     else if ( aValue == EBatteryStatusLow )
       
  2021         {
       
  2022         if ( iSysApPsmController && UiReady() )
       
  2023             {
       
  2024             iSysApPsmController->BatteryLow( ETrue );
       
  2025             
       
  2026                        
       
  2027             if ( enableAutoPsm)
       
  2028                 {
       
  2029                 iSysApPsmController->DoEnableFullPsm( ETrue );
       
  2030                           
       
  2031                 _LIT(KPsmOn, "txt_power_management_dpopinfo_psm_activated_automa");
       
  2032                 // returns the string "power saving mode  on"
       
  2033                 HBufC* psmOn = HbTextResolverSymbian::LoadL(KPsmOn);
       
  2034                              
       
  2035                _LIT(Kicon, "qgn_indi_battery_ps_activate");
       
  2036                // returns the power save mode icon
       
  2037                HBufC* psmIcon = HbTextResolverSymbian::LoadL(Kicon);                  
       
  2038             
       
  2039                CHbDeviceNotificationDialogSymbian::NotificationL(*psmIcon,*psmOn,*lowBattery);       
       
  2040                 }
       
  2041             else // default low warning note must be shown
       
  2042                 {
       
  2043                 //Display Battery Low note.
       
  2044                 CHbDeviceNotificationDialogSymbian::NotificationL(KlowbatteryIcon,KNullDesC,*lowBattery);   
       
  2045                 }                
       
  2046             }
       
  2047         else
       
  2048             {
       
  2049             //Display Battery Low note.
       
  2050             CHbDeviceNotificationDialogSymbian::NotificationL(KlowbatteryIcon,KNullDesC,*lowBattery);     
       
  2051             }            
       
  2052         }
       
  2053         
       
  2054     if ( iSysApBatteryInfoController )
       
  2055     {
       
  2056      iSysApBatteryInfoController->BatteryStatusUpdated( aValue );
       
  2057     }
       
  2058       
       
  2059  delete repository;  
       
  2060    }
       
  2061 
       
  2062 // ----------------------------------------------------------------------------
       
  2063 // CSysApAppUi::ShowUiNoteL( const TSysApNoteIds aNote ) const
       
  2064 // ----------------------------------------------------------------------------
       
  2065 
       
  2066 void CSysApAppUi::ShowUiNoteL( const TSysApNoteIds aNote ) const
       
  2067     {
       
  2068     TRACES( RDebug::Print( _L("CSysApAppUi::ShowUiNoteL aNote: %d"), aNote ) );
       
  2069     
       
  2070     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  2071 
       
  2072     if( UiReady() || swState == ESwStateSecurityCheck)
       
  2073       {
       
  2074           switch ( aNote )
       
  2075             {
       
  2076             case EBatteryLowNote:
       
  2077                 {
       
  2078                  _LIT(KPowerPressKey,"Battery low");
       
  2079                  HBufC* aString = HBufC16::NewLC(100);
       
  2080                  TPtrC aStringPointer = aString->Des();
       
  2081                  aStringPointer.Set(KPowerPressKey);
       
  2082                  TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  2083                  ShowExampleUiNoteL( aStringPointer );
       
  2084                  CleanupStack::PopAndDestroy(); // aString
       
  2085                 }
       
  2086                 break;
       
  2087             case EBatteryFullNote:
       
  2088                 {
       
  2089                 _LIT(KPowerPressKey,"Battery full");
       
  2090                 HBufC* aString = HBufC16::NewLC(100);
       
  2091                 TPtrC aStringPointer = aString->Des();
       
  2092                 aStringPointer.Set(KPowerPressKey);
       
  2093                 TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  2094                 ShowExampleUiNoteL( aStringPointer );
       
  2095                 CleanupStack::PopAndDestroy(); // aString
       
  2096                 }
       
  2097                 break;
       
  2098             case ERechargeBatteryNote:
       
  2099                 {
       
  2100                 iSysApLightsController->BatteryEmptyL( ETrue );
       
  2101                 _LIT(KPowerPressKey,"Battery empty. Recharge");
       
  2102                 HBufC* aString = HBufC16::NewLC(100);
       
  2103                 TPtrC aStringPointer = aString->Des();
       
  2104                 aStringPointer.Set(KPowerPressKey);
       
  2105                 TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  2106                 ShowExampleUiNoteL( aStringPointer );
       
  2107                 CleanupStack::PopAndDestroy(); // aString
       
  2108                 }
       
  2109                 break;
       
  2110             case ENotChargingNote:
       
  2111                 {
       
  2112                 _LIT(KPowerPressKey,"Not charging");
       
  2113                 HBufC* aString = HBufC16::NewLC(100);
       
  2114                 TPtrC aStringPointer = aString->Des();
       
  2115                 aStringPointer.Set(KPowerPressKey);
       
  2116                 TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  2117                 ShowExampleUiNoteL( aStringPointer );
       
  2118                 CleanupStack::PopAndDestroy(); // aString
       
  2119                 }
       
  2120                 break;
       
  2121             case EBatteryFullUnplugChargerNote:
       
  2122                 {
       
  2123                 TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) ); 
       
  2124                 iSysApLightsController->BatteryEmptyL( ETrue );
       
  2125                  _LIT(KunplugCharger,"txt_power_dpopinfo_unplug_charger_to_save_energy");                 
       
  2126                  HBufC* unplugCharger = HbTextResolverSymbian::LoadL(KunplugCharger);
       
  2127                  _LIT(KbatteryFull,"txt_power_management_dpophead_100_full");
       
  2128                  HBufC* batteryFull = HbTextResolverSymbian::LoadL(KbatteryFull);
       
  2129                  CHbDeviceNotificationDialogSymbian::NotificationL(KbatteryFullIcon,*unplugCharger,*batteryFull);       
       
  2130                  }
       
  2131                 break;
       
  2132             case EUnplugChargerNote:
       
  2133                 {
       
  2134                 _LIT(KPowerPressKey,"Unplug charger from power supply to save energy");
       
  2135                 HBufC* aString = HBufC16::NewLC(250);
       
  2136                 TPtrC aStringPointer = aString->Des();
       
  2137                 aStringPointer.Set(KPowerPressKey);
       
  2138                 TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  2139                 ShowExampleUiNoteL( aStringPointer );
       
  2140                 CleanupStack::PopAndDestroy(); // aString
       
  2141                 }
       
  2142                 break;
       
  2143             default:
       
  2144                 break;
       
  2145             }
       
  2146         }
       
  2147     }
       
  2148 
       
  2149 
       
  2150 // ----------------------------------------------------------------------------
       
  2151 // CSysApAppUi::BatteryEmptyL()
       
  2152 // ----------------------------------------------------------------------------
       
  2153 
       
  2154 void CSysApAppUi::BatteryEmptyL()
       
  2155     {
       
  2156     iSysApLightsController->BatteryEmptyL( ETrue );
       
  2157     // Do not reactivate keyguard in the next startup
       
  2158     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 0 );
       
  2159     }
       
  2160 
       
  2161 
       
  2162 // ----------------------------------------------------------------------------
       
  2163 // CSysApAppUi::ShowQueryL()
       
  2164 // ----------------------------------------------------------------------------
       
  2165 
       
  2166 void CSysApAppUi::ShowQueryL( const TSysApConfirmationQueryIds /* aQueryId */, const TDesC& /* aValue */)
       
  2167     {
       
  2168     // do nothing
       
  2169     }
       
  2170 
       
  2171 
       
  2172 
       
  2173 // ----------------------------------------------------------------------------
       
  2174 // CSysApAppUi::HandleChargingStatusL
       
  2175 // ----------------------------------------------------------------------------
       
  2176 //
       
  2177 void CSysApAppUi::HandleChargingStatusL( const TInt aValue )
       
  2178     {
       
  2179     TRACES( RDebug::Print( _L("CSysApAppUi::HandleChargingStatusL aValue: %d"), aValue ) );
       
  2180     
       
  2181     TBool showNote( ETrue );
       
  2182     
       
  2183     UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  2184 
       
  2185     if ( iSysApPsmController && UiReady() ) 
       
  2186         {             
       
  2187         if ( iCharging && !iSysApPsmController->ChargerConnected() ) // first time after charger connection
       
  2188             {
       
  2189             iSysApPsmController->ConnectCharger( ETrue );
       
  2190             iSysApPsmController->DoEnableFullPsm(EFalse);             
       
  2191             iVariantAccState = CHbSymbianVariant::NewL(&KCharging, CHbSymbianVariant::EDes);
       
  2192                
       
  2193             if (!iHbIndicatorSymbian->Activate(KPsmPlugin,iVariantAccState)) 
       
  2194                {
       
  2195                int error = iHbIndicatorSymbian->Error();
       
  2196                //use the errorcode...
       
  2197                }
       
  2198               
       
  2199                            
       
  2200             }
       
  2201         else if ( aValue == EChargingStatusNotConnected )
       
  2202             {
       
  2203             iSysApPsmController->ConnectCharger( EFalse );
       
  2204             if (!iHbIndicatorSymbian->Deactivate(KPsmPlugin)) 
       
  2205                {
       
  2206                int error = iHbIndicatorSymbian->Error();
       
  2207                //use the errorcode...
       
  2208                }
       
  2209             }            
       
  2210         }
       
  2211     if( showNote )
       
  2212         {
       
  2213         HandleChargerNotesL( aValue );    
       
  2214         }
       
  2215     }
       
  2216 
       
  2217 
       
  2218 // ----------------------------------------------------------------------------
       
  2219 // CSysApAppUi::HandleChargerNotesL()
       
  2220 // ----------------------------------------------------------------------------
       
  2221 void CSysApAppUi::HandleChargerNotesL( const TInt aValue )
       
  2222     {
       
  2223     TBool showNote(StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateRinging);
       
  2224     if ( aValue == EChargingStatusCharging )
       
  2225         {
       
  2226         iSysApLightsController->BatteryEmptyL( EFalse );
       
  2227         TRACES( RDebug::Print( _L("SysAp: charger connected") ) );
       
  2228         iSysApLightsController->ChargerConnectedL( ETrue );
       
  2229         ShowChargingNoteL();
       
  2230         }
       
  2231     //Display Not Charging note
       
  2232     else if ( aValue == EChargingStatusError )
       
  2233         {
       
  2234         if(showNote)
       
  2235             {
       
  2236             ShowUiNoteL( ENotChargingNote );
       
  2237             }
       
  2238         }
       
  2239     else if ( aValue == EChargingStatusChargingComplete )
       
  2240         {
       
  2241         iSysApLightsController->ChargingCompleteL();
       
  2242         
       
  2243         TSysApNoteIds note( EBatteryFullNote );
       
  2244         
       
  2245         if ( !iSysApUsbChargerDetector.HostOnlyUsbChargingUsed() &&
       
  2246              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) )
       
  2247             {
       
  2248             note = EBatteryFullUnplugChargerNote;
       
  2249             }
       
  2250         iSysApUsbChargerDetector.Reset();
       
  2251         if(showNote)
       
  2252             {
       
  2253             ShowUiNoteL( note );
       
  2254             }
       
  2255         }
       
  2256     else if ( aValue == EChargingStatusNotConnected )
       
  2257         {
       
  2258         TRACES( RDebug::Print( _L("SysAp: charger removed") ) );
       
  2259         iSysApLightsController->ChargerConnectedL( EFalse );
       
  2260         
       
  2261         if ( !iSysApUsbChargerDetector.HostOnlyUsbChargingUsed() &&
       
  2262              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) )
       
  2263             {
       
  2264         if(showNote)
       
  2265                 {
       
  2266                 ShowUiNoteL( EUnplugChargerNote );
       
  2267                 }
       
  2268             }
       
  2269         iSysApUsbChargerDetector.Reset();
       
  2270         }
       
  2271     else if ( aValue == EChargingStatusNotCharging )
       
  2272         {
       
  2273         TRACES( RDebug::Print( _L("SysAp: Not charging") ) );
       
  2274         }
       
  2275     else if ( aValue == EChargingStatusAlmostComplete )
       
  2276         {
       
  2277         TRACES( RDebug::Print( _L("SysAp: Charging almost complete") ) );
       
  2278         }
       
  2279     else if ( aValue == EChargingStatusChargingContinued )
       
  2280         {
       
  2281         //in this case we simply want to scroll the battery bars and not turn light on or show ui note
       
  2282         // set lights controller iBatteryEmpty to EFalse
       
  2283         iSysApLightsController->BatteryEmptyL( EFalse );
       
  2284         TRACES( RDebug::Print( _L("SysAp: charging continues") ) );
       
  2285         }
       
  2286     }
       
  2287 
       
  2288 
       
  2289 // ----------------------------------------------------------------------------
       
  2290 // CSysApAppUi::UpdateBatteryBarsL( const TInt aState )
       
  2291 // ----------------------------------------------------------------------------
       
  2292 
       
  2293 void CSysApAppUi::UpdateBatteryBarsL( const TInt  /* aState */)
       
  2294     {
       
  2295     TInt state( StateOfProperty( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
       
  2296 //    TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL aState: %d, chargerState:%d"), aState, state ) );
       
  2297     HandleUsbCharger( state );
       
  2298     if( state == EChargingStatusCharging ||
       
  2299         state == EChargingStatusChargingContinued ||
       
  2300         state == EChargingStatusAlmostComplete )
       
  2301         {
       
  2302         if ( !iCharging )
       
  2303             {
       
  2304             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: Starting Charging") ) );
       
  2305             iCharging = ETrue;
       
  2306             }
       
  2307         }
       
  2308     else
       
  2309         {
       
  2310         if ( iCharging )
       
  2311             {
       
  2312             TRACES( RDebug::Print( _L("CSysApAppUi::UpdateBatteryBarsL: Stopping Charging") ) );
       
  2313             iCharging = EFalse;
       
  2314             }
       
  2315         }
       
  2316     
       
  2317     if ( !iSysApPsmController ) // created here if first state change has not occurred yet
       
  2318         {
       
  2319         iSysApPsmController = CSysApPsmController::NewL( *this );        
       
  2320         }
       
  2321 
       
  2322     if ( iSysApPsmController )
       
  2323         {
       
  2324         if ( iSysApPsmController->FullPsmEnabled() )
       
  2325             {
       
  2326              // activate psm indicator 
       
  2327             }
       
  2328         else
       
  2329             {
       
  2330             // deactivate psm indicator
       
  2331             }            
       
  2332         }
       
  2333         
       
  2334        if ( iSysApBatteryInfoController )        
       
  2335         {
       
  2336          iSysApBatteryInfoController->BatteryLevelUpdatedL();
       
  2337         }
       
  2338         
       
  2339      }
       
  2340 
       
  2341 
       
  2342 
       
  2343 // ----------------------------------------------------------------------------
       
  2344 // CSysApAppUi::ShowChargingNoteL()
       
  2345 // ----------------------------------------------------------------------------
       
  2346 
       
  2347 void CSysApAppUi::ShowChargingNoteL()
       
  2348     {
       
  2349     TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL") ) );
       
  2350     TBool showNote( ETrue );
       
  2351 
       
  2352     TInt swState( StateOfProperty( KPSUidStartup, KPSGlobalSystemState ) );
       
  2353     TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL: swState: %d"), swState ) );
       
  2354 
       
  2355     if( UiReady() || swState == ESwStateSecurityCheck )
       
  2356         {
       
  2357         if ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) ==  EPSCTsyCallStateRinging )
       
  2358             {
       
  2359             showNote = EFalse;
       
  2360             }
       
  2361         TRACES( RDebug::Print( _L("CSysApAppUi::ShowChargingNoteL KCTsyCallState=%d"), StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) ) );
       
  2362         if ( showNote ) // Power Mgmt UI spec defines that no Charging note is shown while the phone is ringing/alerting
       
  2363             {
       
  2364             TRACES( RDebug::Print( _L("CSysApWsClient::RunL(): Key EEventKeyUp 01") ) );   
       
  2365             _LIT(KChargingNote,"txt_power_management_dblist_charging");
       
  2366             HBufC* chargingNote = HbTextResolverSymbian::LoadL(KChargingNote);
       
  2367             CHbDeviceNotificationDialogSymbian::NotificationL(KNullDesC,*chargingNote);     
       
  2368                     
       
  2369             }
       
  2370         }
       
  2371     }
       
  2372 
       
  2373 
       
  2374 // ----------------------------------------------------------------------------
       
  2375 // CSysApAppUi::HandleUsbCharger
       
  2376 // ----------------------------------------------------------------------------
       
  2377 //
       
  2378 void CSysApAppUi::HandleUsbCharger( const TInt aValue )
       
  2379     {        
       
  2380     if ( aValue == EChargingStatusCharging ||
       
  2381          aValue == EChargingStatusChargingContinued ||
       
  2382          aValue == EChargingStatusAlmostComplete )
       
  2383         {
       
  2384         iSysApUsbChargerDetector.SetChargingUsed( ETrue );
       
  2385         if ( !iSysApUsbIndicatorController &&
       
  2386              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) &&
       
  2387              iSysApFeatureManager->Supported( KSysApFeatureIdUsbChargingWithoutReminderNotes ) )
       
  2388             {
       
  2389             // Start observing USB state for the reminder note
       
  2390             TRAPD ( usbErr, iSysApUsbIndicatorController = CreateSysApUsbIndicatorL( *this ) );
       
  2391             if ( usbErr )
       
  2392                 {
       
  2393                 TRACES( RDebug::Print(
       
  2394                     _L("CSysApAppUi::HandleUsbCharger: error in constructing USB ind. controller %d" ),
       
  2395                     usbErr ) );
       
  2396                 }
       
  2397             }
       
  2398         }
       
  2399     }
       
  2400 
  4907 
  2401 // ----------------------------------------------------------------------------
  4908 // ----------------------------------------------------------------------------
  2402 // CSysApAppUi::HandleCurrentCallStateChangeL()
  4909 // CSysApAppUi::HandleCurrentCallStateChangeL()
  2403 // ----------------------------------------------------------------------------
  4910 // ----------------------------------------------------------------------------
  2404 
  4911 
  2405 void CSysApAppUi::HandleCurrentCallStateChangeL( TInt aCurrentCallState )
  4912 void CSysApAppUi::HandleCurrentCallStateChangeL( TInt aCurrentCallState )
  2406     {
  4913     {
  2407     TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: KUidCurrentCall: %d" ), aCurrentCallState ) );
  4914     TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: KUidCurrentCall: %d" ), aCurrentCallState ) );
  2408 
  4915 
       
  4916     if( iPowerKeyPopupMenuActive )
       
  4917         {
       
  4918         CancelGlobalListQuery();
       
  4919         }
       
  4920 
  2409     switch ( aCurrentCallState )
  4921     switch ( aCurrentCallState )
  2410         {
  4922         {
  2411         case EPSCTsyCallStateRinging:
  4923         case EPSCTsyCallStateRinging:  
  2412             {
  4924             {
  2413             iSysApLightsController->CallComingInL( ETrue );
  4925             iSysApLightsController->CallComingInL( ETrue );
  2414             // Disable keylock when a call is coming in
  4926             // Disable keylock when a call is coming in
  2415             if ( iKeyLockEnabled || iDeviceLockEnabled || iKeyLockOnBeforeCradle || iKeyLockOnBeforeAlarm )
  4927             if ( iKeyLockEnabled || iDeviceLockEnabled || iKeyLockOnBeforeCradle || iKeyLockOnBeforeAlarm )
  2416                 {
  4928                 {
  2419 
  4931 
  2420                 if ( iKeyLockEnabled || iDeviceLockEnabled )
  4932                 if ( iKeyLockEnabled || iDeviceLockEnabled )
  2421                     {
  4933                     {
  2422                     if ( !iSysApFeatureManager->TouchUnlockStrokeSupported() )
  4934                     if ( !iSysApFeatureManager->TouchUnlockStrokeSupported() )
  2423                         {
  4935                         {
  2424                         iKeyguardController->DisableKeyguard(EFalse);
  4936                         KeyLock().DisableWithoutNote();
  2425                         }
  4937                         }
  2426                     }
  4938                     }
  2427                 }
  4939                 }
  2428             break;
  4940             break;
  2429             }
  4941             }
  2430             
  4942 
  2431         case EPSCTsyCallStateDialling:
  4943         case EPSCTsyCallStateDialling:
  2432             {
  4944             {
  2433             // Disable keypad lock during an emergency call
  4945             // Disable keypad lock during an emergency call
  2434             // no need to disable the key lock when a call is made using the wireless car-kit
  4946             // no need to disable the key lock when a call is made using the wireless car-kit
  2435             // but if the call is an emergency one then we will disable the keypad lock
  4947             // but if the call is an emergency one then we will disable the keypad lock
  2438                 TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: EPSCTsyCallStateDialling: disable keylock") ) );
  4950                 TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: EPSCTsyCallStateDialling: disable keylock") ) );
  2439                 iKeyLockOnBeforeCall = ETrue;
  4951                 iKeyLockOnBeforeCall = ETrue;
  2440 
  4952 
  2441                 if ( IsEmergencyCall() && (iKeyLockEnabled || iDeviceLockEnabled ))
  4953                 if ( IsEmergencyCall() && (iKeyLockEnabled || iDeviceLockEnabled ))
  2442                     {
  4954                     {
  2443                     iKeyguardController->DisableKeyguard(EFalse);
  4955                     KeyLock().DisableWithoutNote();
  2444                     }
  4956                     }
  2445                 }
  4957                 }
  2446 
  4958 
  2447             // Enable signal & network indicators when an emergency call is made in Offline Mode
  4959             // Enable signal & network indicators when an emergency call is made in Offline Mode
  2448             if( iSysApOfflineModeController->OfflineModeActive() )
  4960             if( iSysApOfflineModeController->OfflineModeActive() )
  2449                     {
  4961                     {
  2450                     // Signal indicators not updated with VoIP call
  4962                     // Signal indicators not updated with VoIP call
  2451                     if ( StateOfProperty(KPSUidCtsyCallInformation, KCTsyCallType) != EPSCTsyCallTypeVoIP) 
  4963                     if ( StateOfProperty(KPSUidCtsyCallInformation, KCTsyCallType) != EPSCTsyCallTypeVoIP) 
  2452                         {
  4964                         {
  2453                         iEmergencyCallActive = ETrue;
  4965                         iEmergencyCallActive = ETrue;
  2454                         // not supporting this
  4966                         UpdateSignalBarsL();
  2455                         // UpdateSignalBarsL();
  4967                         SetSignalIndicatorL();
  2456                         // SetSignalIndicatorL();
       
  2457                         }
  4968                         }
  2458                     }
  4969                     }
  2459             break;
  4970             break;
  2460             }
  4971             }
  2461             
  4972             
  2463             {
  4974             {
  2464             if (StateOfProperty(KPSUidCtsyCallInformation, KCTsyCallType) == EPSCTsyCallTypeCSVoice)
  4975             if (StateOfProperty(KPSUidCtsyCallInformation, KCTsyCallType) == EPSCTsyCallTypeCSVoice)
  2465                 {
  4976                 {
  2466                 // Check if GPRS suspended note is required
  4977                 // Check if GPRS suspended note is required
  2467                 iCallActivated = ETrue;
  4978                 iCallActivated = ETrue;
  2468                 // not supporting this
  4979                 HandleGprsNotesL();
  2469                 // HandleGprsNotesL();
       
  2470                 }
  4980                 }
  2471             if ( iDeviceLockEnabled )
  4981             if ( iDeviceLockEnabled )
  2472                 {
  4982                 {
  2473                 // Enable keylock via autolock emulation if device lock enabled. 
  4983                 // Enable keylock via autolock emulation if device lock enabled. 
  2474                 // Otherwise e.g. messages can be read using softkeys during ongoing call.
  4984                 // Otherwise e.g. messages can be read using softkeys during ongoing call.
  2475                 iKeyguardController->EnableKeyguard(EFalse);
  4985                 KeyLock().EnableAutoLockEmulation();
  2476                 }
  4986                 }
  2477             break;
  4987             break;
  2478             }
  4988             }
  2479 
  4989 
  2480         case EPSCTsyCallStateNone:
  4990         case EPSCTsyCallStateNone:
  2481             {
  4991             {
  2482             // Reset timers in ScreenSaver and Autolock
  4992             // reset timers in ScreenSaver and Autolock
  2483             User::ResetInactivityTime();
  4993             User::ResetInactivityTime();
  2484 
  4994 
  2485             if ( iEmergencyCallActive )
  4995             if ( iEmergencyCallActive )
  2486                 {
  4996                 {
  2487                 iEmergencyCallActive = EFalse;
  4997                 iEmergencyCallActive = EFalse;
  2488                 // not supporting this
  4998                 UpdateSignalBarsL( 0 );
  2489                 // UpdateSignalBarsL( 0 );
  4999                 SetSignalIndicatorL();
  2490                 // SetSignalIndicatorL();
       
  2491                 }
  5000                 }
  2492             if ( iKeyLockOnBeforeCall )
  5001             if ( iKeyLockOnBeforeCall )
  2493                 {
  5002                 {
  2494                 TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: EPSCTsyCallStateNone: enable keylock") ) );
  5003                 TRACES( RDebug::Print( _L("CSysApAppUi::HandleCurrentCallStateChangeL: EPSCTsyCallStateNone: enable keylock") ) );
  2495                 iKeyLockOnBeforeCall = EFalse;
  5004                 iKeyLockOnBeforeCall = EFalse;
  2498                     if ( !iKeyLockOnBeforeCradle && !iKeyLockOnBeforeAlarm &&
  5007                     if ( !iKeyLockOnBeforeCradle && !iKeyLockOnBeforeAlarm &&
  2499                           !iSysApFeatureManager->TouchUnlockStrokeSupported() )
  5008                           !iSysApFeatureManager->TouchUnlockStrokeSupported() )
  2500                         {
  5009                         {
  2501                         if ( iSysApCenRepController->GetInt( KCRUidCommonTelephonySettings, KSettingsSummaryAfterCall ) == 1 )
  5010                         if ( iSysApCenRepController->GetInt( KCRUidCommonTelephonySettings, KSettingsSummaryAfterCall ) == 1 )
  2502                             {
  5011                             {
  2503                             // Let's not hide "Summary After Call" dialog
  5012                             KeyLock().EnableWithoutNote(); // Let's not hide "Summary After Call" dialog
  2504                             iKeyguardController->EnableKeyguard(EFalse);
       
  2505                             }
  5013                             }
  2506                         else
  5014                         else
  2507                             {
  5015                             {
  2508                             iKeyguardController->EnableKeyguard(ETrue);
  5016                             KeyLock().EnableKeyLock();
  2509                             }
  5017                             }
  2510                         }
  5018                         }
  2511                     }
  5019                     }
  2512                 else
  5020                 else
  2513                     {
  5021                     {
  2514                     iKeyguardController->EnableKeyguard(EFalse);
  5022                     KeyLock().EnableAutoLockEmulation();
  2515                     }
  5023                     }
  2516                 }
  5024                 }
  2517             if ( iShowkeypadActivatedNoteAfterSoftReject )
  5025             if ( iShowkeypadActivatedNoteAfterSoftReject )
  2518                 {
  5026                 {
  2519                 ShowUiNoteL( EKeypadActiveNote );
  5027                 ShowUiNoteL( EKeypadActiveNote );
  2534 
  5042 
  2535     SetIhfIndicatorL();
  5043     SetIhfIndicatorL();
  2536     SetHacIndicatorL();
  5044     SetHacIndicatorL();
  2537     }
  5045     }
  2538 
  5046 
  2539 
  5047 // ----------------------------------------------------------------------------
  2540 
  5048 // CSysApAppUi::DoSwStateNormalConstructionL()
  2541 /**
  5049 // ----------------------------------------------------------------------------
  2542  * To check the for an emergency call. 
  5050 
  2543  * 
  5051 void CSysApAppUi::DoSwStateNormalConstructionL()
  2544  * @return ETrue if there is an emergency call active otherwise, EFalse.
  5052     {
  2545  */
  5053     // Let's ensure that the lights will remain on for 15 secs after sw state normal
  2546 TBool CSysApAppUi::IsEmergencyCall()
  5054     User::ResetInactivityTime();
  2547         {
  5055 
  2548         TBool retVal( EFalse );
  5056     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL : START" ) ) );
  2549         TInt err( KErrNone );
  5057 
  2550         TInt state( 0 );
  5058     // In case of unexpected reset (e.g. hidden boot) the keylock must be enabled silently. Locking is done
  2551      
  5059     // prior to time-consuming initializations, because otherwise UI is in unlocked state for a few seconds.
  2552         err = RProperty::Get(KPSUidCtsyEmergencyCallInfo, KCTSYEmergencyCallInfo, state );
  5060     if ( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive ) == 1  )
  2553         if ( err == KErrNone && state )
  5061         {
  2554             {
  5062         TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL: enabling keylock") ) );
  2555             retVal = ETrue;            
  5063         KeyLock().EnableWithoutNote();
  2556             }
  5064         }
  2557         return retVal;
  5065 
  2558         }
  5066     // Initiate bearer change observation
  2559 
  5067     iSysApConnectionMonitorObserver = CSysApConnectionMonitorObserver::NewL( *this );
  2560 
  5068 
  2561 
  5069     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL: trying CSysApSsSettingsObserver::NewL()") ) );
  2562 // ----------------------------------------------------------------------------
  5070     iSysApSsSettingsObserver = CSysApSsSettingsObserver::NewL( *this );
  2563 // CSysApAppUi::IsStateNormal()
  5071 
  2564 //
  5072     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL: trying new ( ELeave ) CSysApPowerKeyMenuObserver") ) );
  2565 // ----------------------------------------------------------------------------
  5073     iSysApPowerKeyMenuObserver = new( ELeave ) CSysApPowerKeyMenuObserver( *this );
  2566 TBool CSysApAppUi::IsStateNormal() const
  5074 
  2567     {
  5075     TRACES( RDebug::Print( _L("SysAp: trying CSystemLock::NewL" ) ) );
  2568     TInt state;
  5076     iSysApSystemLock = CSystemLock::NewL();
  2569     TInt errorCode =
  5077 
  2570         RProperty::Get( KPSUidStartup, KPSGlobalSystemState, state );
  5078     iSysApCenRepCallForwardingObserver = CSysApCenRepCallForwardingObserver::NewL( *this );
  2571     if ( errorCode == KErrNone )
  5079 
  2572         {
  5080     iSysApCenRepMsgWaitingObserver = CSysApCenRepMsgWaitingObserver::NewL( *this );
  2573         return state == ESwStateNormalRfOn ||
  5081 
  2574                state == ESwStateNormalRfOff ||
       
  2575                state == ESwStateNormalBTSap;
       
  2576         }
       
  2577     else
       
  2578         {
       
  2579         TRACES( RDebug::Print( _L( "CSysApAppUi::IsStateNormal: Failed to read global system state, error code %d." ), errorCode ) );
       
  2580         return EFalse;
       
  2581         }
       
  2582     }
       
  2583 
       
  2584 
       
  2585 // ----------------------------------------------------------------------------
       
  2586 // CSysApAppUi::HandleAccessoryProfileInStartupL()
       
  2587 // ----------------------------------------------------------------------------
       
  2588 
       
  2589 void CSysApAppUi::HandleAccessoryProfileInStartupL()
       
  2590     {
       
  2591     TRACES( RDebug::Print( _L( "CSysApAppUi::HandleAccessoryProfileInStartupL" ) ) );
       
  2592 
       
  2593     if ( !iSysApOfflineModeController->OfflineModeActive() )
       
  2594         {
       
  2595         iIgnoreAccessorySpecificProfileChanges = EFalse;
       
  2596         TBool accessoryConnectedInShutdown( EFalse );
       
  2597         TInt accessoryTemp( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApAccessoryConnected ) );
       
  2598         if ( accessoryTemp == 1 )
       
  2599             {
       
  2600             accessoryConnectedInShutdown = ETrue;
       
  2601             }
       
  2602 
       
  2603         TBool accessoryConnectedNow ( EFalse );
       
  2604 
       
  2605         TAccMode accessoryState(EAccModeHandPortable);
       
  2606         TInt physicalConnectionType = 0;
       
  2607         if ( iSysApAccessoryObserver )
       
  2608             {
       
  2609             accessoryState = iSysApAccessoryObserver->GetAccessoryMode();
       
  2610             physicalConnectionType = iSysApAccessoryObserver->GetAccessoryConnectionType();
       
  2611             }
       
  2612 
       
  2613         if ( accessoryState != EAccModeHandPortable )
       
  2614             {
       
  2615             accessoryConnectedNow = ETrue;
       
  2616             }
       
  2617         TRACES( RDebug::Print( _L( "CSysApAppUi::HandleAccessoryProfileInStartupL: accessoryConnectedInShutdown: %d, accessoryConnectedNow: %d" ),
       
  2618                               accessoryConnectedInShutdown, accessoryConnectedNow ) );
       
  2619 
       
  2620         if ( accessoryConnectedInShutdown && !accessoryConnectedNow )
       
  2621             {
       
  2622             HandleAccessoryDisconnectedL();
       
  2623             }
       
  2624         else if ( !accessoryConnectedInShutdown && accessoryConnectedNow )
       
  2625             {
       
  2626             HandleAccessoryConnectedL( accessoryState, physicalConnectionType );
       
  2627             }
       
  2628         else if ( !accessoryConnectedNow )
       
  2629             {
       
  2630             // not supporting this 
       
  2631             // TInt activeProfile ( ActiveProfileId() );
       
  2632             // SysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApActiveProfileBeforeAccessoryConnected, activeProfile );
       
  2633             }
       
  2634         }
       
  2635     }
       
  2636 
       
  2637 
       
  2638 // ----------------------------------------------------------------------------
       
  2639 // CSysApAppUi::CenRepController()
       
  2640 // ----------------------------------------------------------------------------
       
  2641 
       
  2642 CSysApCenRepController& CSysApAppUi::CenRepController()
       
  2643     {
       
  2644     __ASSERT_ALWAYS( iSysApCenRepController, User::Panic( _L("CSysApAppUi::CenRepController"), KErrBadHandle ) );
       
  2645 
       
  2646     return *iSysApCenRepController;
       
  2647     }
       
  2648 
       
  2649 
       
  2650 // ----------------------------------------------------------------------------
       
  2651 // CSysApAppUi::LogsObserverL
       
  2652 // ----------------------------------------------------------------------------
       
  2653 //
       
  2654 CSysApCenRepLogsObserver& CSysApAppUi::LogsObserverL()
       
  2655     {
       
  2656     TRACES( RDebug::Print( _L("CSysApAppUi::LogsObserverL()") ) );
       
  2657     
  5082     
  2658     // Create Logs observer when it is needed for the first time
  5083     if ( iSysApFeatureManager->Supported( KSysApFeatureIdBatteryInfoPopup ) )
  2659     if ( !iSysApCenRepLogsObserver )
  5084         {
  2660         {
  5085 		if( iSysApBatteryInfoController == NULL)
  2661         iSysApCenRepLogsObserver = CSysApCenRepLogsObserver::NewL( *this );
  5086             {
       
  5087 			iSysApBatteryInfoController = CSysApBatteryInfoController::NewL( iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsConf, 
       
  5088                                                                                                      KCoreAppUIsBatteryInformationLowThreshold ) );    
       
  5089 	    	}
  2662         }
  5090         }
  2663     
  5091     
  2664     return *iSysApCenRepLogsObserver;
  5092 
  2665     }
  5093     TRACES( RDebug::Print( _L("CSysApAppUi::DoSwStateNormalConstructionL : END" ) ) );
  2666 
  5094     }
  2667 
  5095 
  2668 // ----------------------------------------------------------------------------
  5096 // ----------------------------------------------------------------------------
  2669 // CSysApAppUi::HandleWlanIndicator()
  5097 // CSysApAppUi::DoSimChangedFromPreviousBootL()
  2670 // ----------------------------------------------------------------------------
  5098 // ----------------------------------------------------------------------------
  2671 void CSysApAppUi::HandleWlanIndicatorL( TInt aValue )
  5099 
  2672     {
  5100 void CSysApAppUi::DoSimChangedFromPreviousBootL()
  2673     if ( aValue == EPSWlanIndicatorAvailable )
  5101     {
  2674         {
  5102     TRACES( RDebug::Print( _L("CSysApAppUi::DoSimChangedFromPreviousBootL: iSimChangedDone=%d" ), iSimChangedDone ) );
  2675         // do nothing
  5103 
  2676         }
  5104     if ( !iSimChangedDone  )
  2677     else if ( aValue == EPSWlanIndicatorActive )
  5105         {
  2678         {
  5106         iSimChangedDone = ETrue;
  2679         // do nothing
  5107         CSysApSimChanged* simChanged = CSysApSimChanged::NewL( *this, iEikonEnv->FsSession() );
  2680         }
  5108         CleanupStack::PushL( simChanged );
  2681     else if ( aValue == EPSWlanIndicatorActiveSecure )
  5109         simChanged->HandleSimChangedL();
  2682         {
  5110         CleanupStack::PopAndDestroy( simChanged );
  2683         // do nothing
  5111         }
  2684         }
  5112     }
  2685     else // No indication required
  5113 
  2686         {
  5114 // ----------------------------------------------------------------------------
  2687         // do nothing
  5115 // CSysApAppUi::CancelWaitNote()
  2688         }
  5116 // ----------------------------------------------------------------------------
  2689     }
  5117 
  2690 
  5118 void CSysApAppUi::CancelWaitNote()
  2691 void CSysApAppUi::ShowNotificationDialog(const TDesC& noteText)const
  5119     {
  2692 {
  5120     TRACES( RDebug::Print( _L("CSysApAppUi::CancelWaitNote" ) ) );
  2693     //Todo:4.Notification--Just Popup message
  5121     if ( iSysApWaitNote )
  2694     //Todo: #include <HbDeviceNotificationDialogSymbian.h>
  5122         {
  2695     CHbDeviceNotificationDialogSymbian *notificationDialog =  CHbDeviceNotificationDialogSymbian::NewL();
  5123         iSysApWaitNote->Cancel();
  2696     CleanupStack::PushL(notificationDialog);
  5124         delete iSysApWaitNote;
  2697     notificationDialog->SetTextL(noteText);//noteText with Qm file input
  5125         iSysApWaitNote = NULL;
  2698     notificationDialog->SetTimeout(100);
  5126         }
  2699     notificationDialog->ShowL();
  5127     }
  2700     CleanupStack::PopAndDestroy(notificationDialog);
  5128 
  2701 }
  5129 // ----------------------------------------------------------------------------
  2702 
  5130 // CSysApAppUi::CancelGlobalListQuery()
  2703 void CSysApAppUi::SetKeyLockEnabledL()
  5131 // ----------------------------------------------------------------------------
  2704     {
  5132 
  2705     iKeyLockEnabled = ETrue;
  5133 void CSysApAppUi::CancelGlobalListQuery()
  2706     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 1 );
  5134     {
  2707     // not supporting indicator 
  5135     TRACES( RDebug::Print( _L("CSysApAppUi::CancelGlobalListQuery" ) ) );
  2708 //    SetIndicatorStateL( EAknIndicatorKeyguard, EAknIndicatorStateOn );
  5136     if ( iGlobalListQuery )
  2709     iSysApLightsController->KeylockStateChangedL( ETrue );
  5137         {
  2710     }
  5138         iGlobalListQuery->CancelListQuery();
  2711 
  5139         delete iGlobalListQuery;
  2712 void CSysApAppUi::SetKeyLockDisabledL()
  5140         iGlobalListQuery = NULL;
  2713     {
  5141         }
  2714     iKeyLockEnabled = EFalse;
  5142     }
  2715     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 0 );
       
  2716     // SetIndicatorStateL( EAknIndicatorKeyguard, EAknIndicatorStateOff );
       
  2717     if (! iDeviceLockEnabled )
       
  2718         {
       
  2719         iSysApLightsController->KeylockStateChangedL( EFalse );
       
  2720         if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  2721             {
       
  2722             if ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateRinging && StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateAlerting )
       
  2723                 {
       
  2724                  RunUnlockNotifierL();
       
  2725                 // need to handle MMC unlock query in next sub
       
  2726                 }
       
  2727             }
       
  2728         }
       
  2729     }
       
  2730 
       
  2731 void CSysApAppUi::SetLightsOnUnlockNoteL()
       
  2732     {
       
  2733     iSysApLightsController->SetLightsOnUnlockNoteL();
       
  2734     }
       
  2735 
       
  2736 void CSysApAppUi::SetLightsOnEcsQueryL()
       
  2737     {
       
  2738     iSysApLightsController->SetLightsOnEcsQueryL();
       
  2739     }
       
  2740 
       
  2741 void CSysApAppUi::SetLightsOnSecurityQueryL()
       
  2742     {
       
  2743     iSysApLightsController->SetLightsOnSecurityQueryL();
       
  2744     }
       
  2745 
       
  2746 TBool CSysApAppUi::CheckLongPowerKeyPressed()
       
  2747     {
       
  2748     return iCheckLongPowerKeyEvent;
       
  2749     }
       
  2750 
       
  2751 
       
  2752 // ----------------------------------------------------------------------------
       
  2753 // CSysApAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
       
  2754 // ----------------------------------------------------------------------------
       
  2755 
       
  2756 TKeyResponse CSysApAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
       
  2757     {
       
  2758     if ( ! iShutdownStarted )
       
  2759         {
       
  2760         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL: aKeyEvent.iCode:%d, aKeyEvent.iScanCode:%d, aType:%d, iIgnoreNextPowerKeyUpEvent:%d, iPowerKeyPopupMenuActive:%d, iLastPowerKeyWasShort:%d, iPowerKeyPopupMenuDismissed:%d"),
       
  2761                                aKeyEvent.iCode, aKeyEvent.iScanCode, aType, iIgnoreNextPowerKeyUpEvent, iPowerKeyPopupMenuActive, iLastPowerKeyWasShort, iPowerKeyPopupMenuDismissed ) );
       
  2762 
       
  2763 #ifdef _DEBUG
       
  2764         // camery latency measurement environment instrumentation, don't remove
       
  2765         if ( aType == EEventKey && aKeyEvent.iCode == EKeyCamera )
       
  2766             {
       
  2767             TRACES( RDebug::Print( _L("e_KEY_EVENT_SENDING 0") ) );
       
  2768             }
       
  2769 #endif // _DEBUG
       
  2770 
       
  2771         TKeyResponse response(EKeyWasNotConsumed);
       
  2772         if (response)
       
  2773             {
       
  2774             //Do nothing:: To supress warning
       
  2775             }
       
  2776         if (iSysApKeyManagement && aKeyEvent.iCode != EKeyPowerOff && aKeyEvent.iCode != 'E')
       
  2777             {
       
  2778             response = iSysApKeyManagement->HandleKeyEventL(aKeyEvent, aType );
       
  2779             }
       
  2780         
       
  2781         if( aType == EEventKey )
       
  2782             {
       
  2783             switch ( aKeyEvent.iCode )
       
  2784                 {
       
  2785 #ifdef _DEBUG
       
  2786                 case 'E': //For testing
       
  2787                     Exit();
       
  2788                     break;
       
  2789 #endif
       
  2790                 case EKeyPowerOff:
       
  2791                     //Short power key press
       
  2792                     iKeyBoardRepeatCount++;
       
  2793                     if( aKeyEvent.iRepeats == 0 )
       
  2794                         {
       
  2795                         TRACES( RDebug::Print(_L("CSysApAppUi::HandleKeyEventL, Short powerkey") ) );
       
  2796                         iLastPowerKeyWasShort = ETrue;
       
  2797                         TRACES( RDebug::Print( _L("CSysApAppUi::Key was consumed by pressing short power") ) );          
       
  2798                         //Powermenu
       
  2799                         if (iPowerMenuDialog!=NULL)
       
  2800                             {
       
  2801                             //PowerMenu already exist
       
  2802                             delete iPowerMenuDialog;
       
  2803                             iPowerMenuDialog = NULL;
       
  2804                             }                                               
       
  2805                         iPowerMenuDialog = CHbDevicePowerMenuSymbian::NewL(*this);  
       
  2806                         iPowerMenuDialog->ShowL();           
       
  2807                                          
       
  2808                         iIgnoreNextPowerKeyRepeats = EFalse;
       
  2809                         }
       
  2810                     //Long power key press
       
  2811                     else if( aKeyEvent.iRepeats > 0 && iKeyBoardRepeatCount >= iSysApCenRepController->GetInt( KCRUidCoreApplicationUIsSysAp, KSysApPowerkeyRepeatcount ))
       
  2812                         {
       
  2813                         iKeyBoardRepeatCount = -1;
       
  2814                         TRACES( RDebug::Print(_L("CSysApAppUi::HandleKeyEventL, Long powerkey") ) );
       
  2815                         iLastPowerKeyWasShort = EFalse;
       
  2816                         HandleLongPowerKeyPressedL();
       
  2817                         }
       
  2818                     break;
       
  2819 
       
  2820                 default:
       
  2821                     {
       
  2822                     TKeyResponse response = EKeyWasNotConsumed;
       
  2823                     if (iSysApKeyManagement)
       
  2824                         {
       
  2825                         response = iSysApKeyManagement->HandleKeyEventL(aKeyEvent, aType );
       
  2826                         }
       
  2827 
       
  2828                     if ( response == EKeyWasNotConsumed ) // none of the plugins consumed the key, offer it to default handling
       
  2829                         {
       
  2830                         iSysApDefaultKeyHandler->HandleKeyEventL( aKeyEvent, aType );
       
  2831                         }
       
  2832                     }
       
  2833                     break;
       
  2834                 }
       
  2835             }
       
  2836         else if( aType == EEventKeyUp )
       
  2837             {
       
  2838             if( aKeyEvent.iScanCode == EStdKeyDevice2 )
       
  2839                 {
       
  2840                 if ( iIgnoreNextPowerKeyUpEvent )
       
  2841                     {
       
  2842                     if ( !iPowerKeyPopupMenuDismissed ) // If the popup menu has been dismissed, do nothing
       
  2843                         {
       
  2844                         iPowerKeyPopupMenuActive = ETrue;
       
  2845                         iIgnoreNextPowerKeyUpEvent = EFalse;
       
  2846                         }
       
  2847                     }
       
  2848                 else if( iLastPowerKeyWasShort )
       
  2849                     {
       
  2850                     if ( iPowerKeyPopupMenuActive )
       
  2851                         {
       
  2852                         }
       
  2853                     }
       
  2854 
       
  2855                 }
       
  2856             }
       
  2857 
       
  2858         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL:ended, aKeyEvent.iCode:%d, aKeyEvent.iScanCode:%d, aType:%d, iIgnoreNextPowerKeyUpEvent:%d, iPowerKeyPopupMenuActive:%d, iLastPowerKeyWasShort:%d, iPowerKeyPopupMenuDismissed:%d"),
       
  2859                                aKeyEvent.iCode, aKeyEvent.iScanCode, aType, iIgnoreNextPowerKeyUpEvent, iPowerKeyPopupMenuActive, iLastPowerKeyWasShort, iPowerKeyPopupMenuDismissed ) );
       
  2860         }
       
  2861     else // shutdown started
       
  2862         {
       
  2863         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL: aKeyEvent.iCode:%d, aKeyEvent.iScanCode:%d, aType:%d"),
       
  2864                                aKeyEvent.iCode, aKeyEvent.iScanCode, aType ) );
       
  2865 
       
  2866         // When shutdown has been started, only device mode key events are passed to plug-in framework
       
  2867         // This for enabling plug-in activities during shutdown animation
       
  2868         if ( IsDeviceModeKey( aKeyEvent ) ) // Other key events are not passed, because they must cancel the shutdown animation as stated in UI spefication
       
  2869             {
       
  2870             if ( aType == EEventKey && iSysApKeyManagement )
       
  2871                 {
       
  2872                 iSysApKeyManagement->HandleKeyEventL( aKeyEvent, aType );
       
  2873                 }
       
  2874             }
       
  2875         TRACES( RDebug::Print( _L("CSysApAppUi::HandleKeyEventL: ended") ) );
       
  2876         }
       
  2877     return EKeyWasConsumed;
       
  2878     }
       
  2879 
       
  2880 
       
  2881 // ----------------------------------------------------------------------------
       
  2882 // CSysApAppUi::HandleCommandL( TInt aCommand)
       
  2883 // ----------------------------------------------------------------------------
       
  2884 
       
  2885 void CSysApAppUi::HandleCommandL( TInt aCommand )
       
  2886     {
       
  2887     TRACES( RDebug::Print( _L("CSysApAppUi::HandleCommandL aCommend: %d"), aCommand ) );
       
  2888     switch ( aCommand )
       
  2889         {
       
  2890         case EEikCmdExit:   // EAknCmdExit
       
  2891             Exit();
       
  2892             break;
       
  2893         default:
       
  2894             break;
       
  2895         }
       
  2896     }
       
  2897 
       
  2898 TBool CSysApAppUi::ReleasePowerMenuCustomDialogMemory()
       
  2899     {
       
  2900     if (iPowerMenuDialog!=NULL)
       
  2901         {
       
  2902         //PowerMenu already exist
       
  2903         delete iPowerMenuDialog;
       
  2904         iPowerMenuDialog = NULL;
       
  2905         TRACES( RDebug::Print(_L("CSysApAppUi::ReleasePowerMenuCustomDialogMemory True") ) );                            
       
  2906         return ETrue;
       
  2907         }
       
  2908     TRACES( RDebug::Print(_L("CSysApAppUi::ReleasePowerMenuCustomDialogMemory false") ) );                            
       
  2909     return EFalse;
       
  2910     }
       
  2911 
       
  2912 TBool CSysApAppUi::NotifiedDialogIfRequiredAndReleaseMemory()
       
  2913     {
       
  2914     TRACES( RDebug::Print(_L("CSysApAppUi::NotifiedDialogIfRequiredAndReleaseMemory(): Begin") ) );
       
  2915     TRACES( RDebug::Print(_L("CSysApAppUi::NotifiedDialogIfRequiredAndReleaseMemory(): Enter for popping another dialog") ) );
       
  2916     TInt popUpError = iSysApDriveUnlockHandler->CheckMemoryDialogIfNeeded();
       
  2917     
       
  2918     //Deside if dialog required again !!    
       
  2919     if(popUpError)
       
  2920         {
       
  2921         iSysApDriveUnlockHandler->ReleaseMemoryForInputCardDialog();  // check memory has released.
       
  2922         iSysApDriveUnlockHandler->UnlockComplete(KErrNone);
       
  2923         }
       
  2924     else
       
  2925         {
       
  2926         iSysApDriveUnlockHandler->StartUnlock();// pop up the dialog again !!        
       
  2927         }
       
  2928     
       
  2929     TRACES( RDebug::Print(_L("CSysApAppUi::NotifiedDialogIfRequiredAndReleaseMemory(): End")) );    
       
  2930     return popUpError;
       
  2931     }
       
  2932 
       
  2933 void CSysApAppUi::ReleaseMemoryForMemoryCardDialog()
       
  2934     {
       
  2935     TRACES( RDebug::Print(_L("CSysApAppUi::CSysApAppUi::ReleaseMemoryForMemoryCardDialog()")) );                                    
       
  2936     iSysApDriveUnlockHandler->ReleaseMemoryForInputCardDialog();
       
  2937     }
       
  2938 
       
  2939 // ----------------------------------------------------------------------------
       
  2940 // CSysApAppUi::ShowAnimationL()
       
  2941 // ----------------------------------------------------------------------------
       
  2942 
       
  2943 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2944 void
       
  2945 #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2946 TBool
       
  2947 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2948 CSysApAppUi::ShowAnimationL()
       
  2949     {
       
  2950     TRACES( RDebug::Print(_L("CSysApAppUi::ShowAnimationL(): START" ) ) );
       
  2951 
       
  2952     TRACES( RDebug::Print( _L("CSysApAppUi::ShowAnimationL: Initialise shutdown animation") ) );
       
  2953 
       
  2954 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2955 
       
  2956     PrepareForShutdownAnimation();
       
  2957 
       
  2958     iSysApShutdownAnimation = CSysApShutdownAnimation::NewL( *iSysApShutdownImage );
       
  2959     iSysApShutdownAnimation->Play( TCallBack( DoStopAnimTiming, this ) );
       
  2960 
       
  2961     TRACES( RDebug::Print(_L("CSysApAppUi::ShowAnimationL(): End" ) ) );
       
  2962 
       
  2963 #else // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2964     iSysApShutdownAnimation = CSysApShutdownAnimation::NewL( this );
       
  2965     AddToStackL( iSysApShutdownAnimation );
       
  2966     iAnimationShowingTime = iSysApShutdownAnimation->ShowingTime();
       
  2967     TRACES( RDebug::Print( _L("CSysApAppUi::ShowAnimationL: Shutdown animation initialised. Animation time = %d") ,iAnimationShowingTime) );
       
  2968 
       
  2969     TBool ret_val( EFalse );
       
  2970 
       
  2971     if ( iAnimationShowingTime )
       
  2972         {
       
  2973         if ( iSysApFeatureManager->CoverDisplaySupported() )
       
  2974             {
       
  2975             // Construct mediator observer
       
  2976             iSysApMediatorObserver = CSysApMediatorObserver::NewL( this );
       
  2977 
       
  2978             // Sync animation
       
  2979             TInt err = iSysApMediatorObserver->SyncShutdownAnimation();
       
  2980 
       
  2981             if ( err != KErrNone )
       
  2982                 {
       
  2983                 // Pretend coverUI synced instantly if error in issuing command.
       
  2984                 ShutdownAnimationSyncOK();
       
  2985                 }
       
  2986             }
       
  2987         else
       
  2988             {
       
  2989             // Pretend coverUI synced instantly when it is not supported.
       
  2990             ShutdownAnimationSyncOK();
       
  2991             }
       
  2992 
       
  2993         ret_val = ETrue;
       
  2994         }
       
  2995 
       
  2996     TRACES( RDebug::Print(_L("CSysApAppUi::ShowAnimationL(): returns: %d" ),ret_val ) );
       
  2997     return ret_val;
       
  2998 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  2999     }
       
  3000 
       
  3001 
       
  3002 
       
  3003 // ----------------------------------------------------------------------------
       
  3004 // CSysApAppUi::PrepareForShutdownAnimation()
       
  3005 // ----------------------------------------------------------------------------
       
  3006 void CSysApAppUi::PrepareForShutdownAnimation()
       
  3007     {
       
  3008     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() begin") ) );
       
  3009 
       
  3010 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  3011     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() showtime = %d"), iAnimationShowingTime ) );
       
  3012     if ( iAnimationShowingTime )
       
  3013         {
       
  3014 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  3015         
       
  3016         if (iPowerMenuDialog!=NULL)
       
  3017             {
       
  3018             //PowerMenu already exist
       
  3019             delete iPowerMenuDialog;
       
  3020             iPowerMenuDialog = NULL;
       
  3021             } 
       
  3022 
       
  3023         RWindowGroup groupWin = iCoeEnv->RootWin();
       
  3024         iCapturedAppskey = groupWin.CaptureKey( EKeyApplication, KModifierMask, KModifierMask );
       
  3025         iCapturedAppskeyUpAndDowns = groupWin.CaptureKeyUpAndDowns( EStdKeyApplication0, KModifierMask, KModifierMask );
       
  3026         iEikonEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront );
       
  3027 
       
  3028         TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() Draw background image" ) ) );
       
  3029 
       
  3030         ShowShutdownImage( KBackgroundImageID );
       
  3031 
       
  3032 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  3033         TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() Show Shutdown animation" ) ) );
       
  3034         TInt err(0);
       
  3035         TRAP( err, iSysApShutdownAnimation->StartL( iLastPowerKeyWasShort ) );
       
  3036         if ( err )
       
  3037             {
       
  3038             TRACES( RDebug::Print( _L("SysAp: Shutdown animation fails. Error code: %d" ), err ) );
       
  3039             // Start animation timing immediatily if animation starting fails.
       
  3040             // Otherwise animation will call StartAnimTiming when it is ready.
       
  3041             StartAnimTiming();
       
  3042             }
       
  3043         }
       
  3044 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  3045 
       
  3046     TRACES( RDebug::Print( _L("CSysApAppUi::PrepareForShutdownAnimation() end") ) );
       
  3047     }
       
  3048 
       
  3049 
       
  3050 // ----------------------------------------------------------------------------
       
  3051 // CSysApAppUi::DoStopAnimTiming( TAny* aObject )
       
  3052 // ----------------------------------------------------------------------------
       
  3053 
       
  3054 TInt CSysApAppUi::DoStopAnimTiming( TAny* aObject )
       
  3055     {
       
  3056     TInt err(KErrNone);
       
  3057     CSysApAppUi* appUi = STATIC_CAST( CSysApAppUi*, aObject );
       
  3058 
       
  3059     // This method could theoretically be called by two timers (iAnimTimer and one in CSysApShutdownAnimation),
       
  3060     // so a check is needed to prevent multiple executions.
       
  3061     if ( !(appUi->iShutdownContinued) )
       
  3062         {
       
  3063         appUi->iShutdownContinued = ETrue;
       
  3064 
       
  3065         TRACES( RDebug::Print( _L("CSysApAppUi::DoStopAnimTiming() Animation timer completed or animation skipped" ) ) );
       
  3066 
       
  3067 #ifndef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  3068         if ( appUi->iAnimTimer )
       
  3069             {
       
  3070             appUi->iAnimTimer->Cancel();
       
  3071             }
       
  3072 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  3073 
       
  3074         TRACES( RDebug::Print( _L("CSysApAppUi::DoStopAnimTiming() Call ContinueShutdown(...)" ) ) );
       
  3075         appUi->ContinueShutdown();
       
  3076         TRACES( RDebug::Print( _L("CSysApAppUi::DoStopAnimTiming() end") ) );
       
  3077         }
       
  3078 
       
  3079     return err;
       
  3080     }
       
  3081 
       
  3082 
       
  3083 // ----------------------------------------------------------------------------
       
  3084 // CSysApAppUi::ContinueShutdown()
       
  3085 // ----------------------------------------------------------------------------
       
  3086 
       
  3087 void CSysApAppUi::ContinueShutdown()
       
  3088     {
       
  3089     TRACES( RDebug::Print(_L("CSysApAppUi::ContinueShutdown() started" ) ) );
       
  3090     CompleteShutdown();
       
  3091     TRACES( RDebug::Print(_L("CSysApAppUi::ContinueShutdown() completed" ) ) );
       
  3092     }
       
  3093 
       
  3094 CEikStatusPane* CSysApAppUi::StatusPane()
       
  3095 {
       
  3096 return iEikonEnv->AppUiFactory()->StatusPane();
       
  3097 }
       
  3098  
       
  3099 
       
  3100 #ifndef RD_MULTIPLE_DRIVE
       
  3101 
       
  3102 // ----------------------------------------------------------------------------
       
  3103 // CSysApAppUi::EjectUsed
       
  3104 // ----------------------------------------------------------------------------
       
  3105 
       
  3106 void CSysApAppUi::EjectUsed( TInt /*aDrive*/ )
       
  3107     {
       
  3108     }
       
  3109 
       
  3110 #else // RD_MULTIPLE_DRIVE
       
  3111 
       
  3112 // ----------------------------------------------------------------------------
       
  3113 // CSysApAppUi::ShowEjectWaitNoteL
       
  3114 // ----------------------------------------------------------------------------
       
  3115 
       
  3116 void CSysApAppUi::ShowEjectWaitNoteL( TInt /* aDriveToEject */ )
       
  3117     {
       
  3118  /*   if ( iSysApWaitNote )
       
  3119         {
       
  3120         return;
       
  3121         }
       
  3122     HBufC* text = iSysApDriveList->GetFormattedDriveNameLC(
       
  3123         aDriveToEject,
       
  3124         0, // Not used
       
  3125         R_QTN_EJECTING_MEMORY_NAME_WAIT );
       
  3126     iSysApWaitNote = CSysApWaitNote::NewL(
       
  3127         iSysApFeatureManager->CoverDisplaySupported() );
       
  3128     iSysApWaitNote->ShowNoteL( EClosingApplicationsNote, text );
       
  3129     CleanupStack::PopAndDestroy( text );
       
  3130  */   }
       
  3131 
       
  3132 // ----------------------------------------------------------------------------
       
  3133 // CSysApAppUi::IsEjectQueryVisible
       
  3134 // ----------------------------------------------------------------------------
       
  3135 
       
  3136 TBool CSysApAppUi::IsEjectQueryVisible()
       
  3137     {
       
  3138 //    if ( !iSysApConfirmationQuery )
       
  3139         {
       
  3140         return EFalse;
       
  3141         }
       
  3142 //    TInt queryId( iSysApConfirmationQuery->CurrentQuery() );
       
  3143 //    return ( queryId == ESysApEjectMmcQuery || queryId == ESysApRemoveMmcNote );
       
  3144     }
       
  3145 
       
  3146 // ----------------------------------------------------------------------------
       
  3147 // CSysApAppUi::UpdateInsertedMemoryCardsL
       
  3148 // ----------------------------------------------------------------------------
       
  3149 
       
  3150 void CSysApAppUi::UpdateInsertedMemoryCardsL()
       
  3151     {
       
  3152     // Update inserted memory cards
       
  3153     iSysApDriveList->GetMemoryCardsL(
       
  3154         iInsertedMemoryCards, CSysApDriveList::EIncludeInserted );
       
  3155 
       
  3156     // Update memory card indicator status
       
  3157 //    SetMemoryCardIndicatorL();
       
  3158 
       
  3159     // Handle unlock
       
  3160     RunUnlockNotifierL();
       
  3161     }
       
  3162 
       
  3163 // ----------------------------------------------------------------------------
       
  3164 // CSysApAppUi::EjectUsed
       
  3165 // ----------------------------------------------------------------------------
       
  3166 
       
  3167 void CSysApAppUi::EjectUsed( TInt aDrive )
       
  3168     {
       
  3169     // Check drive inserted before starting eject confirm query
       
  3170     TInt insertedIndex( CSysApDriveList::Find( iInsertedMemoryCards, aDrive ) );
       
  3171 
       
  3172     TRACES( RDebug::Print(
       
  3173         _L( "CSysApAppUi::EjectUsed: drive: %d, index: %d" ),
       
  3174         aDrive, insertedIndex ) );
       
  3175 
       
  3176     if ( insertedIndex == KErrNotFound )
       
  3177         {
       
  3178         return;
       
  3179         }
       
  3180 
       
  3181     iMMCEjectUsed = ETrue;
       
  3182     iDriveToEject = aDrive;
       
  3183     iSysApDriveList->ResetDrivesToEject();
       
  3184     TRAPD( err, EjectMMCL() );
       
  3185     if ( err != KErrNone )
       
  3186         {
       
  3187         TRACES( RDebug::Print(
       
  3188             _L( "CSysApAppUi::EjectUsed: err: %d" ), err ) );
       
  3189         iMMCEjectUsed = EFalse;
       
  3190         }
       
  3191     }
       
  3192 #endif // RD_MULTIPLE_DRIVE
       
  3193 
       
  3194 
       
  3195 // ----------------------------------------------------------------------------
       
  3196 // CSysApAppUi::EjectMMCCanceled
       
  3197 // ----------------------------------------------------------------------------
       
  3198 
       
  3199 void CSysApAppUi::EjectMMCCanceled()
       
  3200     {
       
  3201     // Called from eject confirm query, reset eject status
       
  3202 #ifdef RD_MULTIPLE_DRIVE
       
  3203     iMMCEjectUsed = EFalse;
       
  3204 #endif // RD_MULTIPLE_DRIVE
       
  3205     }
       
  3206 
       
  3207 
       
  3208 
  5143 
  3209 #ifndef RD_MULTIPLE_DRIVE
  5144 #ifndef RD_MULTIPLE_DRIVE
  3210 // ----------------------------------------------------------------------------
  5145 // ----------------------------------------------------------------------------
  3211 // CSysApAppUi::MountMMC()
  5146 // CSysApAppUi::MountMMC()
  3212 // ----------------------------------------------------------------------------
  5147 // ----------------------------------------------------------------------------
  3290         }
  5225         }
  3291     iMMCEjectUsed = EFalse;
  5226     iMMCEjectUsed = EFalse;
  3292     }
  5227     }
  3293 
  5228 
  3294 #endif // RD_MULTIPLE_DRIVE
  5229 #endif // RD_MULTIPLE_DRIVE
       
  5230 
       
  5231 // ----------------------------------------------------------------------------
       
  5232 // CSysApAppUi::DisconnectBtSap()
       
  5233 // ----------------------------------------------------------------------------
       
  5234 
       
  5235 void CSysApAppUi::DisconnectBtSap()
       
  5236     {
       
  5237     TRACES( RDebug::Print( _L("CSysApAppUi::DisconnectBtSap") ) );
       
  5238     iSysApBtSapController->Disconnect();
       
  5239     }
  3295 
  5240 
  3296 #ifndef RD_MULTIPLE_DRIVE
  5241 #ifndef RD_MULTIPLE_DRIVE
  3297 // ----------------------------------------------------------------------------
  5242 // ----------------------------------------------------------------------------
  3298 // CSysApAppUi::RunUnlockNotifierL()
  5243 // CSysApAppUi::RunUnlockNotifierL()
  3299 // ----------------------------------------------------------------------------
  5244 // ----------------------------------------------------------------------------
  3545 void CSysApAppUi::MMCInsertedL()
  5490 void CSysApAppUi::MMCInsertedL()
  3546     {
  5491     {
  3547     TRACES( RDebug::Print( _L( "CSysApAppUi::MMCInsertedL") ) );
  5492     TRACES( RDebug::Print( _L( "CSysApAppUi::MMCInsertedL") ) );
  3548 
  5493 
  3549     if ( iSysApFeatureManager->MmcSupported() && !iShutdownStarted )
  5494     if ( iSysApFeatureManager->MmcSupported() && !iShutdownStarted )
  3550         {
  5495 		{
  3551         TBool normalState( UiReady() );
  5496 		TBool normalState( UiReady() );
  3552 
  5497 
  3553         if ( normalState )
  5498 		if ( normalState )
  3554             {
  5499 			{
  3555             TInt defaultMemoryCard( iSysApDriveList->DefaultMemoryCard() );
  5500 			TInt defaultMemoryCard( iSysApDriveList->DefaultMemoryCard() );
  3556             TSysApMemoryCardStatus memoryCardStatus( iSysApDriveList->MemoryCardStatus( defaultMemoryCard ) );
  5501 			TSysApMemoryCardStatus memoryCardStatus( iSysApDriveList->MemoryCardStatus( defaultMemoryCard ) );
  3557 
  5502 
  3558             TRACES( RDebug::Print(
  5503 			TRACES( RDebug::Print(
  3559                 _L( "CSysApAppUi::MMCInsertedL: drive: %d, memoryCardStatus: %d" ), defaultMemoryCard, memoryCardStatus ) );
  5504 				_L( "CSysApAppUi::MMCInsertedL: drive: %d, memoryCardStatus: %d" ), defaultMemoryCard, memoryCardStatus ) );
  3560 
  5505 
  3561             switch ( memoryCardStatus )
  5506 			switch ( memoryCardStatus )
  3562                 {
  5507 				{
  3563                 case ESysApMemoryCardInserted: // Fall through
  5508 				case ESysApMemoryCardInserted: // Fall through
  3564                 case ESysApMemoryCardLocked:
  5509 				case ESysApMemoryCardLocked:
  3565                     {
  5510 					{
  3566                     // Reset eject and unlock of inserted memory card
  5511 					// Reset eject and unlock of inserted memory card
  3567                     iSysApDriveList->ResetDriveToEject( defaultMemoryCard );
  5512 					iSysApDriveList->ResetDriveToEject( defaultMemoryCard );
  3568                     iSysApDriveList->ResetDriveUnlockQueryShown( defaultMemoryCard );
  5513 					iSysApDriveList->ResetDriveUnlockQueryShown( defaultMemoryCard );
  3569 
  5514 
  3570 //                    CancelWaitNote();
  5515 					CancelWaitNote();
  3571 
  5516 
  3572                     if ( memoryCardStatus == ESysApMemoryCardInserted )
  5517 					if ( memoryCardStatus == ESysApMemoryCardInserted )
  3573                         {
  5518 						{
  3574                         TRACES( RDebug::Print(
  5519 						TRACES( RDebug::Print(
  3575                             _L( "CSysApAppUi::MMCInsertedL: memoryCardStatus ESysApMemoryCardInserted: %d" ), memoryCardStatus ) );
  5520 							_L( "CSysApAppUi::MMCInsertedL: memoryCardStatus ESysApMemoryCardInserted: %d" ), memoryCardStatus ) );
  3576                         RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
  5521 						RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
  3577                         }
  5522 						}
  3578                     else
  5523 					else
  3579                         {
  5524 						{
  3580                         TRACES( RDebug::Print(
  5525 						TRACES( RDebug::Print(
  3581                             _L( "CSysApAppUi::MMCInsertedL: memoryCardStatus ESysApMemoryCardLocked: %d" ), memoryCardStatus ) );
  5526 							_L( "CSysApAppUi::MMCInsertedL: memoryCardStatus ESysApMemoryCardLocked: %d" ), memoryCardStatus ) );
  3582                         RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
  5527 						RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
  3583                         }
  5528 						}
  3584                     break;
  5529 					break;
  3585                     }
  5530 					}
  3586                 case ESysApMemoryCardNotInserted:
  5531 				case ESysApMemoryCardNotInserted:
  3587                     {
  5532 					{
  3588                     // Always reset eject and unlock of removed memory card
  5533 					// Always reset eject and unlock of removed memory card
  3589                     TBool isEject( iSysApDriveList->IsDriveToEject( defaultMemoryCard ) );
  5534 					TBool isEject( iSysApDriveList->IsDriveToEject( defaultMemoryCard ) );
  3590 
  5535 
  3591                     TRACES( RDebug::Print(
  5536 					TRACES( RDebug::Print(
  3592                         _L( "CSysApAppUi::MMCInsertedL: isEject: %d, drive: %d" ),
  5537 						_L( "CSysApAppUi::MMCInsertedL: isEject: %d, drive: %d" ),
  3593                         isEject, defaultMemoryCard ) );
  5538 						isEject, defaultMemoryCard ) );
  3594 
  5539 
  3595                     iSysApDriveList->ResetDriveToEject( defaultMemoryCard );
  5540 					iSysApDriveList->ResetDriveToEject( defaultMemoryCard );
  3596                     iSysApDriveList->ResetDriveUnlockQueryShown( defaultMemoryCard );
  5541 					iSysApDriveList->ResetDriveUnlockQueryShown( defaultMemoryCard );
  3597 
  5542 
  3598                     TRACES( RDebug::Print(
  5543 					TRACES( RDebug::Print(
  3599                         _L( "SysApAppUi::MMCInsertedL: memoryCardStatus ESysApMemoryCardNotInserted: %d" ), memoryCardStatus ) );
  5544 						_L( "SysApAppUi::MMCInsertedL: memoryCardStatus ESysApMemoryCardNotInserted: %d" ), memoryCardStatus ) );
  3600 
  5545 
  3601                     RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
  5546 					RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
  3602                     break;
  5547 					break;
  3603                     }
  5548 					}
  3604                 case ESysApMemoryCardStatusNotKnown: // Fall through
  5549 				case ESysApMemoryCardStatusNotKnown: // Fall through
  3605                 default:
  5550 				default:
  3606                     {
  5551 					{
  3607                     break;
  5552 					break;
  3608                     }
  5553 					}
  3609                 }
  5554 				}
  3610                 RunUnlockNotifierL();
  5555 				RunUnlockNotifierL();
  3611             }
  5556 			}
  3612         }
  5557 		}
  3613     }
  5558 	}
  3614 
  5559 
  3615 
  5560 
  3616 // ----------------------------------------------------------------------------
  5561 // ----------------------------------------------------------------------------
  3617 // CSysApAppUi::RunUnlockNotifierL()
  5562 // CSysApAppUi::RunUnlockNotifierL()
  3618 // ----------------------------------------------------------------------------
  5563 // ----------------------------------------------------------------------------
  3636     // when the user is e.g. making an emergency call
  5581     // when the user is e.g. making an emergency call
  3637     TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
  5582     TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
  3638     if ( callState != EPSCTsyCallStateRinging &&
  5583     if ( callState != EPSCTsyCallStateRinging &&
  3639         callState != EPSCTsyCallStateAlerting )
  5584         callState != EPSCTsyCallStateAlerting )
  3640         {
  5585         {
  3641         TInt defaultMemoryCard( iSysApDriveList->DefaultMemoryCard() );
  5586         iSysApDriveUnlockHandler->StartUnlock();
  3642         TSysApMemoryCardStatus memoryCardStatus( iSysApDriveList->MemoryCardStatus( defaultMemoryCard ) );
       
  3643         if ( memoryCardStatus == ESysApMemoryCardLocked)
       
  3644             {
       
  3645             iSysApDriveUnlockHandler->StartUnlock();
       
  3646             }
       
  3647         }
  5587         }
  3648 
  5588 
  3649     TRACES( RDebug::Print(
  5589     TRACES( RDebug::Print(
  3650         _L("CSysApAppUi::RunUnlockNotifierL: END callState: %d"), callState ) );
  5590         _L("CSysApAppUi::RunUnlockNotifierL: END callState: %d"), callState ) );
  3651     }
  5591     }
  3687                 {
  5627                 {
  3688                 // Reset eject and unlock of inserted memory card
  5628                 // Reset eject and unlock of inserted memory card
  3689                 iSysApDriveList->ResetDriveToEject( aDrive );
  5629                 iSysApDriveList->ResetDriveToEject( aDrive );
  3690                 iSysApDriveList->ResetDriveUnlockQueryShown( aDrive );
  5630                 iSysApDriveList->ResetDriveUnlockQueryShown( aDrive );
  3691 
  5631 
  3692 //                CancelWaitNote();
  5632                 CancelWaitNote();
  3693 
  5633 
  3694                 if ( aDrive == defaultMemoryCard )
  5634                 if ( aDrive == defaultMemoryCard )
  3695                     {
  5635                     {
  3696                     if ( memoryCardStatus == ESysApMemoryCardInserted )
  5636                     if ( memoryCardStatus == ESysApMemoryCardInserted )
  3697                         {
  5637                         {
  3698                          RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
  5638                        	RProperty::Set( KPSUidUikon, KUikMMCInserted, 1 );
  3699                         }
  5639                         }
  3700                     else
  5640                     else
  3701                         {
  5641                         {
  3702                         RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
  5642                         RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
  3703                         }
  5643                         }
  3713                         _L( "CSysApAppUi::MMCStatusChangedL: ignoreBeep: %d, drive: %d" ),
  5653                         _L( "CSysApAppUi::MMCStatusChangedL: ignoreBeep: %d, drive: %d" ),
  3714                         ignoreBeep, aDrive ) );
  5654                         ignoreBeep, aDrive ) );
  3715 
  5655 
  3716                     if ( !ignoreBeep )
  5656                     if ( !ignoreBeep )
  3717                         {
  5657                         {
  3718 //                        Beep();
  5658                         Beep();
  3719                         iSysApLightsController->MemoryCardInsertedL();
  5659                         iSysApLightsController->MemoryCardInsertedL();
  3720                         }
  5660                         }
  3721 
  5661 
  3722                     iSysApDriveList->ResetDriveInsertBeepIgnored( aDrive );
  5662                     iSysApDriveList->ResetDriveInsertBeepIgnored( aDrive );
  3723 
  5663 
  3731                         {
  5671                         {
  3732                         iSysApDriveList->MarkDriveInsertBeepIgnored( aDrive );
  5672                         iSysApDriveList->MarkDriveInsertBeepIgnored( aDrive );
  3733                         }
  5673                         }
  3734                     }
  5674                     }
  3735 
  5675 
  3736 //                if ( iDriveToDismount == aDrive && iSysApConfirmationQuery )
  5676                 if ( iDriveToDismount == aDrive && iSysApConfirmationQuery )
  3737                     {
  5677                     {
  3738 //                    if ( iSysApConfirmationQuery->CurrentQuery() == ESysApRemoveMmcNote )
  5678                     if ( iSysApConfirmationQuery->CurrentQuery() == ESysApRemoveMmcNote )
  3739                         {
  5679                         {
  3740                         // User put back ejected memory card or did not remove it
  5680                         // User put back ejected memory card or did not remove it
  3741 //                        iSysApConfirmationQuery->Cancel();
  5681                         iSysApConfirmationQuery->Cancel();
  3742                         }
  5682                         }
  3743                     }
  5683                     }
  3744                 RunUnlockNotifierL();
  5684                 RunUnlockNotifierL();
  3745                 }
  5685                 }
  3746             break;
  5686             break;
  3763                     {
  5703                     {
  3764                     // Reset extra beep ignore if memory card was removed without eject
  5704                     // Reset extra beep ignore if memory card was removed without eject
  3765                     iSysApDriveList->ResetDriveInsertBeepIgnored( aDrive );
  5705                     iSysApDriveList->ResetDriveInsertBeepIgnored( aDrive );
  3766                     }
  5706                     }
  3767 
  5707 
  3768 //                CancelGlobalListQuery(); // Cancel power menu
  5708                 CancelGlobalListQuery(); // Cancel power menu
  3769 
  5709 
  3770                 if ( aDrive == defaultMemoryCard )
  5710                 if ( aDrive == defaultMemoryCard )
  3771                     {
  5711                     {
  3772                     RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
  5712                     RProperty::Set( KPSUidUikon, KUikMMCInserted, 0 );
  3773                     }
  5713                     }
  3774 
  5714 
  3775 //                if ( iSysApConfirmationQuery )
  5715                 if ( iSysApConfirmationQuery )
  3776                     {
  5716                     {
  3777 //                    if ( iSysApConfirmationQuery->CurrentQuery() == ESysApEjectMmcQuery )
  5717                     if ( iSysApConfirmationQuery->CurrentQuery() == ESysApEjectMmcQuery )
  3778                         {
  5718                         {
  3779                         // User removed memory card too early
  5719                         // User removed memory card too early
  3780 //                        iSysApConfirmationQuery->Cancel();
  5720                         iSysApConfirmationQuery->Cancel();
  3781                         // Allow application closing to execute.
  5721                         // Allow application closing to execute.
  3782                         // Also FileManager is closed in this case, regardless where the eject was initiated from.
  5722                         // Also FileManager is closed in this case, regardless where the eject was initiated from.
  3783                         iMMCEjectUsed = EFalse;
  5723                         iMMCEjectUsed = EFalse;
  3784                         }
  5724                         }
  3785                     }
  5725                     }
  3824     // Update inserted memory cards
  5764     // Update inserted memory cards
  3825     iSysApDriveList->GetMemoryCardsL(
  5765     iSysApDriveList->GetMemoryCardsL(
  3826         iInsertedMemoryCards, CSysApDriveList::EIncludeInserted );
  5766         iInsertedMemoryCards, CSysApDriveList::EIncludeInserted );
  3827 
  5767 
  3828     // Update memory card indicator status
  5768     // Update memory card indicator status
  3829 //    SetMemoryCardIndicatorL();
  5769     SetMemoryCardIndicatorL();
  3830 
  5770 
  3831     TRACES( RDebug::Print(
  5771     TRACES( RDebug::Print(
  3832         _L( "CSysApAppUi::MMCStatusChangedL END: MMCCount: %d, iMMCEjectUsed: %d" ),
  5772         _L( "CSysApAppUi::MMCStatusChangedL END: MMCCount: %d, iMMCEjectUsed: %d" ),
  3833         iInsertedMemoryCards.Count(), iMMCEjectUsed ) );
  5773         iInsertedMemoryCards.Count(), iMMCEjectUsed ) );
  3834     }
  5774     }
  3914     // Try remount to check if drive was put back
  5854     // Try remount to check if drive was put back
  3915     iSysApDriveList->MountDrive( iDriveToDismount );
  5855     iSysApDriveList->MountDrive( iDriveToDismount );
  3916     if ( !iSysApDriveEjectHandler->CompleteDismount( iDriveToDismount ) )
  5856     if ( !iSysApDriveEjectHandler->CompleteDismount( iDriveToDismount ) )
  3917         {
  5857         {
  3918         // When ready, check for locked memory cards and update indicators
  5858         // When ready, check for locked memory cards and update indicators
  3919  //       TRAP_IGNORE( SetMemoryCardIndicatorL() );
  5859         TRAP_IGNORE( SetMemoryCardIndicatorL() );
  3920         TRAP_IGNORE( RunUnlockNotifierL() );
  5860         TRAP_IGNORE( RunUnlockNotifierL() );
  3921         }
  5861         }
  3922     }
  5862     }
  3923 
  5863 
  3924 #endif // RD_MULTIPLE_DRIVE
  5864 #endif // RD_MULTIPLE_DRIVE
  3925 
  5865 
  3926 
  5866 // ----------------------------------------------------------------------------
  3927 // ----------------------------------------------------------------------------
  5867 // CSysApAppUi::EjectStarted()
  3928 // CSysApAppUi::HandleApplicationSpecificEventL(TInt aType,const TWsEvent& aEvent)
  5868 // ----------------------------------------------------------------------------
  3929 // ----------------------------------------------------------------------------
  5869 
  3930 
  5870 void CSysApAppUi::EjectStarted( TBool ejectStarted )
  3931 void CSysApAppUi::HandleApplicationSpecificEventL(TInt aType,const TWsEvent& aEvent)
  5871     {
  3932     {
  5872     TRACES( RDebug::Print( _L( "CSysApAppUi::EjectStarted" ) ) );
  3933     TRACES( RDebug::Print( _L("CSysApAppUi::HandleApplicationSpecificEventL: aType:%d"), aType ) );
  5873     iMMCEjectUsed = ejectStarted;
  3934 
       
  3935     CEikAppUi::HandleApplicationSpecificEventL(aType, aEvent);
       
  3936     
  5874     
  3937     if ( ResourcesFreed() )
  5875 #ifndef RD_MULTIPLE_DRIVE
  3938         {
  5876     iFileManagerCloseDisabled = ejectStarted;
  3939         TRACES( RDebug::Print( _L("CSysApAppUi::HandleApplicationSpecificEventL: discarded, shutting down") ) );
  5877 #endif // RD_MULTIPLE_DRIVE
       
  5878 }
       
  5879 
       
  5880 // ----------------------------------------------------------------------------
       
  5881 // CSysApAppUi::DoLightsTimeoutChangedL
       
  5882 // ----------------------------------------------------------------------------
       
  5883 void CSysApAppUi::DoLightsTimeoutChangedL( const TInt aTimeout )
       
  5884     {
       
  5885     iSysApLightsController->DoLightsTimeoutChangedL( aTimeout );
       
  5886     }
       
  5887 
       
  5888 #ifdef __SYSAP_MODULE_TEST
       
  5889 
       
  5890 // ----------------------------------------------------------------------------
       
  5891 // CSysApAppUi::ModuleTestShowUiNoteL()
       
  5892 // ----------------------------------------------------------------------------
       
  5893 
       
  5894 void CSysApAppUi::ModuleTestShowUiNoteL( const TDesC& noteText ) const
       
  5895     {
       
  5896     CAknGlobalNote* note = CAknGlobalNote::NewLC();
       
  5897     note->SetTone( EAvkonSIDNoSound );
       
  5898     note->ShowNoteL( EAknGlobalInformationNote, noteText );
       
  5899     CleanupStack::PopAndDestroy(); // note
       
  5900     }
       
  5901 
       
  5902 #endif
       
  5903 
       
  5904 // ----------------------------------------------------------------------------
       
  5905 // CSysApAppUi::ShowShutdownNoteL()
       
  5906 // ----------------------------------------------------------------------------
       
  5907 void CSysApAppUi::ShowShutdownNoteL()
       
  5908     {
       
  5909     TRACES( RDebug::Print( _L( "CSysApAppUi::ShowShutdownNoteL") ) );
       
  5910     ShowUiNoteL( EShutdownNote );
       
  5911     User::After( KTimeToShowShutdownNote );
       
  5912     }
       
  5913 
       
  5914 // ----------------------------------------------------------------------------
       
  5915 // CSysApAppUi::Beep()
       
  5916 // ----------------------------------------------------------------------------
       
  5917 void CSysApAppUi::Beep()
       
  5918     {
       
  5919     static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PlaySound( EAvkonSIDInformationTone );
       
  5920     }
       
  5921 
       
  5922 // ----------------------------------------------------------------------------
       
  5923 // CSysApAppUi::SimSupported()
       
  5924 // ----------------------------------------------------------------------------
       
  5925 TBool CSysApAppUi::SimSupported()
       
  5926     {
       
  5927     return iSysApFeatureManager->SimSupported();
       
  5928     }
       
  5929 
       
  5930 // ----------------------------------------------------------------------------
       
  5931 // CSysApAppUi::IsStateNormal()
       
  5932 //
       
  5933 // ----------------------------------------------------------------------------
       
  5934 TBool CSysApAppUi::IsStateNormal() const
       
  5935     {
       
  5936     TInt state;
       
  5937     TInt errorCode =
       
  5938         RProperty::Get( KPSUidStartup, KPSGlobalSystemState, state );
       
  5939     if ( errorCode == KErrNone )
       
  5940         {
       
  5941         return state == ESwStateNormalRfOn ||
       
  5942                state == ESwStateNormalRfOff ||
       
  5943                state == ESwStateNormalBTSap;
       
  5944         }
       
  5945     else
       
  5946         {
       
  5947         TRACES( RDebug::Print( _L( "CSysApAppUi::IsStateNormal: Failed to read global system state, error code %d." ), errorCode ) );
       
  5948         return EFalse;
       
  5949         }
       
  5950     }
       
  5951 
       
  5952 // ----------------------------------------------------------------------------
       
  5953 // CSysApAppUi::BatteryEmptyL()
       
  5954 // ----------------------------------------------------------------------------
       
  5955 
       
  5956 void CSysApAppUi::BatteryEmptyL()
       
  5957     {
       
  5958     iSysApLightsController->BatteryEmptyL( ETrue );
       
  5959     // Do not reactivate keyguard in the next startup
       
  5960     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 0 );
       
  5961     }
       
  5962 
       
  5963 // ----------------------------------------------------------------------------
       
  5964 // CSysApAppUi::Max()
       
  5965 // ----------------------------------------------------------------------------
       
  5966 
       
  5967 TInt CSysApAppUi::Max( const TInt aA, const TInt aB, const TInt aC )
       
  5968      {
       
  5969      TInt max( aA );
       
  5970      if ( aB > max )
       
  5971          {
       
  5972          max = aB;
       
  5973          }
       
  5974      if ( aC > max )
       
  5975          {
       
  5976          max = aC;
       
  5977          }
       
  5978      return max;
       
  5979      }
       
  5980 
       
  5981 // ----------------------------------------------------------------------------
       
  5982 // CSysApAppUi::SetStarterState()
       
  5983 // ----------------------------------------------------------------------------
       
  5984 
       
  5985 TInt CSysApAppUi::SetStarterState( const RStarterSession::TGlobalState aState )
       
  5986     {
       
  5987     if ( iSysApStartupController->GlobalStateChangeAllowed( aState ) )
       
  5988         {
       
  5989         TRACES( RDebug::Print( _L("CSysApAppUi::SetStarterState: aState=%d" ), aState ) );
       
  5990         return StarterSession().SetState( aState );
       
  5991         }
       
  5992     else
       
  5993         {
       
  5994         TRACES( RDebug::Print( _L("CSysApAppUi::SetStarterState: aState=%d - not allowed" ), aState ) );
       
  5995         return KErrNone;
       
  5996         }
       
  5997     }
       
  5998 
       
  5999 // ----------------------------------------------------------------------------
       
  6000 // CSysApAppUi::GetBtSapDeviceNameL()
       
  6001 // ----------------------------------------------------------------------------
       
  6002 
       
  6003 HBufC* CSysApAppUi::GetBtSapDeviceNameL()
       
  6004     {
       
  6005     return iSysApBtSapController->GetBtSapDeviceNameL();
       
  6006     }
       
  6007 
       
  6008 // ----------------------------------------------------------------------------
       
  6009 // CSysApAppUi::ShowAlarmIndicatorL()
       
  6010 // ----------------------------------------------------------------------------
       
  6011 
       
  6012 void CSysApAppUi::ShowAlarmIndicatorL( TBool aShowIndicator )
       
  6013     {
       
  6014     if ( aShowIndicator)
       
  6015         {
       
  6016         SetIndicatorStateL( EAknIndicatorAlarmClock, EAknIndicatorStateOn );
       
  6017         }
       
  6018     else
       
  6019         {
       
  6020         SetIndicatorStateL( EAknIndicatorAlarmClock, EAknIndicatorStateOff );
       
  6021         }
       
  6022     }
       
  6023 
       
  6024 // ----------------------------------------------------------------------------
       
  6025 // CSysApAppUi::SimulateFlipKeyEventL()
       
  6026 // ----------------------------------------------------------------------------
       
  6027 
       
  6028 void CSysApAppUi::SimulateFlipKeyEventL( TBool aFlipOpen )
       
  6029     {
       
  6030     TRACES( RDebug::Print( _L("CSysApAppUi::SimulateFlipKeyEventL: aFlipOpen: %d" ), aFlipOpen ) );
       
  6031 
       
  6032     /*
       
  6033        Flip key is constructed when a flip notification via Pub&Sub is received. The reason behind
       
  6034        providing this as a key event is to enable unified handling of keys also with flip, and because
       
  6035        flip is captured&consumed by Avkon it is not possible to capture flip key events directly
       
  6036        from default handler/plugins.
       
  6037     */
       
  6038 
       
  6039     TKeyEvent flipEvent;
       
  6040     flipEvent.iCode = aFlipOpen ? EKeyFlipOpen : EKeyFlipClose;
       
  6041     flipEvent.iScanCode = 0;
       
  6042     flipEvent.iModifiers = 0;
       
  6043 	flipEvent.iRepeats = 0;
       
  6044 
       
  6045     HandleKeyEventL( flipEvent, EEventKey );
       
  6046     }
       
  6047 
       
  6048 // ----------------------------------------------------------------------------
       
  6049 // CSysApAppUi::SetFlipOpenL()
       
  6050 // ----------------------------------------------------------------------------
       
  6051 
       
  6052 void CSysApAppUi::SetFlipOpenL( TBool aFlipOpen )
       
  6053     {
       
  6054     iSysApLightsController->SetFlipOpenL( aFlipOpen );
       
  6055     }
       
  6056 
       
  6057 // ----------------------------------------------------------------------------
       
  6058 // CSysApAppUi::SetGripOpenL()
       
  6059 // ----------------------------------------------------------------------------
       
  6060 void CSysApAppUi::SetGripOpenL( TBool aGripOpen )
       
  6061     {
       
  6062     iSysApLightsController->SetGripOpenL( aGripOpen );
       
  6063     }
       
  6064 
       
  6065 // ----------------------------------------------------------------------------
       
  6066 // CSysApAppUi::SetNetworkConnectionAllowed()
       
  6067 // ----------------------------------------------------------------------------
       
  6068 
       
  6069 void CSysApAppUi::SetNetworkConnectionAllowed( TCoreAppUIsNetworkConnectionAllowed aNetworkConnectionAllowed )
       
  6070     {
       
  6071     TRACES( RDebug::Print( _L("CSysApAppUi::SetNetworkConnectionAllowed: status: %d" ), aNetworkConnectionAllowed ) );
       
  6072 
       
  6073     iSysApCenRepController->SetInt( KCRUidCoreApplicationUIs, KCoreAppUIsNetworkConnectionAllowed, (TInt) aNetworkConnectionAllowed );
       
  6074 
       
  6075     // Also set the Symbian PS key used for the same purpose:
       
  6076     RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, aNetworkConnectionAllowed ? ESAPhoneOn : ESAPhoneOff);
       
  6077     }
       
  6078 
       
  6079 // ----------------------------------------------------------------------------
       
  6080 // CSysApAppUi::GetTelServerL()
       
  6081 // ----------------------------------------------------------------------------
       
  6082 
       
  6083 RTelServer* CSysApAppUi::GetTelServer()
       
  6084     {
       
  6085     if ( iSysApEtelConnector )
       
  6086         {
       
  6087         return iSysApEtelConnector->GetTelServer();
       
  6088         }
       
  6089     else
       
  6090         {
       
  6091         return NULL;
       
  6092         }
       
  6093     }
       
  6094 
       
  6095 // ----------------------------------------------------------------------------
       
  6096 // CSysApAppUi::CoverDisplaySupported()
       
  6097 // ----------------------------------------------------------------------------
       
  6098 
       
  6099 TBool CSysApAppUi::CoverDisplaySupported()
       
  6100     {
       
  6101     return iSysApFeatureManager->CoverDisplaySupported();
       
  6102     }
       
  6103 
       
  6104 // ----------------------------------------------------------------------------
       
  6105 // CSysApAppUi::StarterSession()
       
  6106 // ----------------------------------------------------------------------------
       
  6107 
       
  6108 RStarterSession& CSysApAppUi::StarterSession()
       
  6109     {
       
  6110     if ( !iStarterSession.Handle() )
       
  6111         {
       
  6112         // All server connections are tried to be made KTriesToConnectServer times because occasional
       
  6113         // fails on connections are possible at least on some servers
       
  6114         TRACES( RDebug::Print( _L("CSysApAppUi::StarterSession: trying RStarterSession::Connect()") ) );
       
  6115         TInt thisTry = 0;
       
  6116         TInt err;
       
  6117         while ( ( err = iStarterSession.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
       
  6118             {
       
  6119             User::After( KTimeBeforeRetryingServerConnection );
       
  6120             }
       
  6121 
       
  6122         if ( err != KErrNone )
       
  6123             {
       
  6124             // What do in error case?
       
  6125             TRACES( RDebug::Print( _L("CSysApAppUi::StarterSession: RStarterSession::Connect() failed with %d"), err ) );
       
  6126             }
       
  6127         }
       
  6128 
       
  6129     return iStarterSession;
       
  6130     }
       
  6131 
       
  6132 // ----------------------------------------------------------------------------
       
  6133 // CSysApAppUi::KeyLock()
       
  6134 // ----------------------------------------------------------------------------
       
  6135 
       
  6136 RAknKeylock2& CSysApAppUi::KeyLock()
       
  6137     {
       
  6138     if ( !iKeyLock.Handle() )
       
  6139         {
       
  6140         // All server connections are tried to be made KTriesToConnectServer times because occasional
       
  6141         // fails on connections are possible at least on some servers
       
  6142         TInt thisTry = 0;
       
  6143         TInt err;
       
  6144 
       
  6145         TRACES( RDebug::Print( _L("CSysApAppUi::KeyLock: trying RAknKeylock2::Connect()") ) );
       
  6146         thisTry = 0;
       
  6147         while ( ( err = iKeyLock.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
       
  6148             {
       
  6149             User::After( KTimeBeforeRetryingServerConnection );
       
  6150             }
       
  6151 
       
  6152         if ( err != KErrNone )
       
  6153             {
       
  6154             // What do in error case?
       
  6155             TRACES( RDebug::Print( _L("CSysApAppUi::KeyLock: RAknKeylock2::Connect() failed with %d"), err ) );
       
  6156             }
       
  6157         }
       
  6158 
       
  6159     return iKeyLock;
       
  6160     }
       
  6161 
       
  6162 // ----------------------------------------------------------------------------
       
  6163 // CSysApAppUi::CenRepController()
       
  6164 // ----------------------------------------------------------------------------
       
  6165 
       
  6166 CSysApCenRepController& CSysApAppUi::CenRepController()
       
  6167     {
       
  6168     __ASSERT_ALWAYS( iSysApCenRepController, User::Panic( _L("CSysApAppUi::CenRepController"), KErrBadHandle ) );
       
  6169 
       
  6170     return *iSysApCenRepController;
       
  6171     }
       
  6172 
       
  6173 // ----------------------------------------------------------------------------
       
  6174 // CSysApAppUi::ExecCommandL
       
  6175 // ----------------------------------------------------------------------------
       
  6176 //
       
  6177 void CSysApAppUi::ExecCommandL( TSysapCommand aCommand )
       
  6178     {
       
  6179     ExecCommandL( aCommand, KNullDesC8 );
       
  6180     }
       
  6181 
       
  6182 // ----------------------------------------------------------------------------
       
  6183 // CSysApAppUi::ExecCommandL
       
  6184 // ----------------------------------------------------------------------------
       
  6185 //
       
  6186 void CSysApAppUi::ExecCommandL( TSysapCommand aCommand, const TDesC8& aParam )
       
  6187     {
       
  6188     TRACES( RDebug::Print(_L("CSysApAppUi::ExecCommandL: aCommand=%d"), aCommand ) );
       
  6189 
       
  6190     switch ( aCommand )
       
  6191         {
       
  6192         case EResetKeyguardState: // reset the internal keyguard flags of the SysAp, except for iKeyLockOnBeforeCradle
       
  6193             iKeyLockOnBeforeCall = EFalse;
       
  6194             iKeyLockOnBeforeAlarm = EFalse;
       
  6195             break;
       
  6196 
       
  6197         case ECancelPowermenu: // hide power menu if it is visible
       
  6198             if( iPowerKeyPopupMenuActive )
       
  6199                 {
       
  6200                 CancelGlobalListQuery();
       
  6201                 }
       
  6202             break;
       
  6203 
       
  6204         case EUpdateLights: // apply key specific light handling
       
  6205             {
       
  6206             TUpdateLightsBuf lightBuf;
       
  6207             lightBuf.Copy( aParam );
       
  6208 
       
  6209             switch ( lightBuf() )
       
  6210                 {
       
  6211                 case EKeyGripClose:
       
  6212                     SetGripOpenL( EFalse );
       
  6213                     break;
       
  6214 
       
  6215                 case EKeyGripOpen:
       
  6216                     SetGripOpenL( ETrue );
       
  6217                     break;
       
  6218 
       
  6219                 case EKeyFlipClose:
       
  6220                     SetFlipOpenL( EFalse );
       
  6221                     break;
       
  6222 
       
  6223                 case EKeyFlipOpen:
       
  6224                     SetFlipOpenL( ETrue );
       
  6225                     break;
       
  6226 
       
  6227                 default:
       
  6228                     // No specific light handling for other keys.
       
  6229                     break;
       
  6230                 }
       
  6231             }
       
  6232             break;
       
  6233 
       
  6234         default:
       
  6235             // do nothing in release builds since no harm is done
       
  6236             __ASSERT_DEBUG( EFalse, User::Panic( _L("CSysApAppUi::ExecCommandL: Invalid command"), KErrArgument ) );
       
  6237             break;
       
  6238         }
       
  6239     }
       
  6240 
       
  6241 // ----------------------------------------------------------------------------
       
  6242 // CSysApAppUi::ExecQueryL
       
  6243 // ----------------------------------------------------------------------------
       
  6244 //
       
  6245 void CSysApAppUi::ExecQueryL( TSysapQuery aQuery, TDes8& aReturn )
       
  6246     {
       
  6247     ExecQueryL( aQuery, aReturn, KNullDesC8 );
       
  6248     }
       
  6249 
       
  6250 // ----------------------------------------------------------------------------
       
  6251 // CSysApAppUi::ExecQueryL
       
  6252 // ----------------------------------------------------------------------------
       
  6253 //
       
  6254 void CSysApAppUi::ExecQueryL( TSysapQuery aQuery, TDes8& aReturn, const TDesC8& /*aParam*/ )
       
  6255     {
       
  6256     TRACES( RDebug::Print(_L("CSysApAppUi::ExecQueryL: aQuery=%d"), aQuery ) );
       
  6257 
       
  6258     switch ( aQuery )
       
  6259         {
       
  6260         case EGetHwrmLight: // get handle to HWRM client session. Returns CHWRMLight*.
       
  6261             {
       
  6262             THwrmLightBuf retBuf( iSysApLightsController->GetHwrmLight() );
       
  6263             aReturn.Copy( retBuf );
       
  6264             }
       
  6265             break;
       
  6266 
       
  6267         case EGetKeylock: // get handle to keylock client session. Returns RAknKeylock2*.
       
  6268             {
       
  6269             TKeyLockBuf retBuf( &(KeyLock()) );
       
  6270             aReturn.Copy( retBuf );
       
  6271             }
       
  6272             break;
       
  6273 
       
  6274         default:
       
  6275             __ASSERT_DEBUG( EFalse, User::Panic( _L("CSysApAppUi::ExecQueryL: Invalid query"), KErrArgument ) );
       
  6276             User::Leave( KErrArgument );
       
  6277             break;
       
  6278         }
       
  6279     }
       
  6280 
       
  6281 // ----------------------------------------------------------------------------
       
  6282 // CSysApAppUi::ShowShutdownImage
       
  6283 // ----------------------------------------------------------------------------
       
  6284 //
       
  6285 TInt CSysApAppUi::ShowShutdownImage( TInt aBitmapId )
       
  6286     {
       
  6287     TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImage") ) );
       
  6288 
       
  6289     TRAPD( err, ShowShutdownImageL( aBitmapId ) );
       
  6290 
       
  6291     if ( err != KErrNone )
       
  6292         {
       
  6293         TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImageL failed, err=%d"), err ) );
       
  6294         }
       
  6295 
       
  6296     return err;
       
  6297     }
       
  6298 
       
  6299 // ----------------------------------------------------------------------------
       
  6300 // CSysApAppUi::ShowShutdownImageL
       
  6301 // ----------------------------------------------------------------------------
       
  6302 //
       
  6303 void CSysApAppUi::ShowShutdownImageL( TInt aBitmapId )
       
  6304     {
       
  6305     TRACES( RDebug::Print(_L("CSysApAppUi::ShowShutdownImageL") ) );
       
  6306 
       
  6307     if ( !iSysApShutdownImage ) // Shutdown image may be shown without entering normal state (e.g. charging), so construct here
       
  6308         {
       
  6309         TRACES( RDebug::Print( _L("CSysApAppUi::ShowShutdownImageL: trying CSysApShutdownImage::NewL()") ) );
       
  6310         iSysApShutdownImage = CSysApShutdownImage::NewL();
       
  6311         }
       
  6312 
       
  6313     TRACES( RDebug::Print( _L("CSysApAppUi::ShowShutdownImageL: trying CSysApShutdownImage::ShowShutdownImageL()") ) );
       
  6314     iSysApShutdownImage->ShowShutdownImageL( aBitmapId );
       
  6315     }
       
  6316 
       
  6317 // ----------------------------------------------------------------------------
       
  6318 // CSysApAppUi::IgnoreZeroNetworkBarNotifications
       
  6319 // ----------------------------------------------------------------------------
       
  6320 //
       
  6321 void CSysApAppUi::IgnoreZeroNetworkBarNotifications(TBool aIgnore)
       
  6322     {
       
  6323     iIgnoreZeroNetworkBarNotifications = aIgnore;
       
  6324     }
       
  6325 
       
  6326 // ----------------------------------------------------------------------------
       
  6327 // CSysApAppUi::BtSapEnabled()
       
  6328 // ----------------------------------------------------------------------------
       
  6329 
       
  6330 TBool CSysApAppUi::BtSapEnabled()
       
  6331     {
       
  6332     if ( iSysApBtSapController )
       
  6333         {
       
  6334         return iSysApBtSapController->BtSapEnabled();    
       
  6335         }
       
  6336     
       
  6337     return EFalse;
       
  6338     }
       
  6339 
       
  6340 // ----------------------------------------------------------------------------
       
  6341 // CSysApAppUi::DeactivateBT
       
  6342 // ----------------------------------------------------------------------------
       
  6343 //
       
  6344 void CSysApAppUi::DeactivateBT()
       
  6345     {
       
  6346     // Will deactivate BT when changing to normal mode
       
  6347     iDeactivateBt = ETrue;
       
  6348     }
       
  6349 
       
  6350 // ----------------------------------------------------------------------------
       
  6351 // CSysApAppUi::SetHacIndicatorL()
       
  6352 // ----------------------------------------------------------------------------
       
  6353 void CSysApAppUi::SetHacIndicatorL()
       
  6354     {
       
  6355 
       
  6356     if ( !iSysApCenRepHacSettingObserver )
       
  6357         {
       
  6358         // Do nothing if HAC setting observer has not been created yet
       
  6359         // This occurs in case some party is trying to set HAC indicator during
       
  6360         // ConstructL(), e.g. when switching from offline to online during startup
       
  6361         TRACES( RDebug::Print( _L("CSysApAppUi::SetHacIndicatorL: do nothing, HAC observer does not exist yet") ) );
  3940         return;
  6362         return;
  3941         }
  6363         }
       
  6364 
       
  6365     if ( iSysApCenRepHacSettingObserver->HacMode() )
       
  6366         {
       
  6367         TBool accessoryConnected ( EFalse );
       
  6368 
       
  6369         TAccMode accMode(EAccModeHandPortable);
       
  6370 
       
  6371         if ( iSysApAccessoryObserver )
       
  6372             {
       
  6373             accMode = iSysApAccessoryObserver->GetAccessoryMode();
       
  6374 
       
  6375             if ( accMode != EAccModeHandPortable )
       
  6376                 {
       
  6377                 accessoryConnected = ETrue;
       
  6378                 }
       
  6379             }
       
  6380 
       
  6381         TInt indicatorState = EAknIndicatorStateOn;
       
  6382 
       
  6383         if ( !accessoryConnected ) // When accessory is not connected, check offline and call state
       
  6384             {
       
  6385             if ( OfflineModeActive() ) // HAC indicator is not shown in offline mode
       
  6386                 {
       
  6387                 indicatorState = EAknIndicatorStateOff;
       
  6388                 }
       
  6389             else
       
  6390                 {
       
  6391                 // during active call with IHF activated HAC indicator is not shown
       
  6392                 TInt callState( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) );
       
  6393                 if ( callState < KErrNone )
       
  6394                     {
       
  6395                     callState = EPSCTsyCallStateNone;
       
  6396                     }
       
  6397 
       
  6398                 if ( callState != EPSCTsyCallStateNone && IhfEnabledL() )
       
  6399                     {
       
  6400                     indicatorState = EAknIndicatorStateOff;
       
  6401                     }
       
  6402                 }
       
  6403 
       
  6404             }
       
  6405         else
       
  6406             {
       
  6407             // If an accessory is connected, HAC indicator should not be shown
       
  6408             indicatorState = EAknIndicatorStateOff;
       
  6409             }
       
  6410 
       
  6411         SetIndicatorStateL( EAknIndicatorHAC, indicatorState );
       
  6412 
       
  6413         }
       
  6414     else
       
  6415         {
       
  6416         // If HAC is not active, always disable indicator regardless of accessory state
       
  6417         SetIndicatorStateL( EAknIndicatorHAC, EAknIndicatorStateOff );
       
  6418         }
       
  6419 
       
  6420 
       
  6421     }
       
  6422 
       
  6423 // ----------------------------------------------------------------------------
       
  6424 // CSysApAppUi::HandleResourceChangeL()
       
  6425 // ----------------------------------------------------------------------------
       
  6426 
       
  6427 void CSysApAppUi::HandleResourceChangeL( TInt aType )
       
  6428     {
       
  6429     TRACES( RDebug::Print( _L("CSysApAppUi::HandleResourceChangeL aType: %d"), aType ) );
       
  6430     CAknAppUi::HandleResourceChangeL(aType);
       
  6431 
       
  6432     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  6433         {
       
  6434 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  6435         iSysApShutdownImage->SetRect( ApplicationRect() );
       
  6436 #endif // RD_STARTUP_ANIMATION_CUSTOMIZATION
       
  6437 
       
  6438         TInt mode;
       
  6439         User::LeaveIfError( RProperty::Get( KPSUidStartup, KPSGlobalStartupMode, mode ) );
       
  6440 
       
  6441         if ( mode == EStartupModeAlarm )
       
  6442             {
       
  6443             SetStatusPaneLayoutL( ESysApAlarm );
       
  6444             }
       
  6445         }
       
  6446     }
       
  6447 
       
  6448 // ----------------------------------------------------------------------------
       
  6449 // CSysApAppUi::SetMemoryCardIndicatorL
       
  6450 // ----------------------------------------------------------------------------
       
  6451 
       
  6452 void CSysApAppUi::SetMemoryCardIndicatorL()
       
  6453     {
       
  6454     if ( iSysApFeatureManager->Supported( KSysApFeatureIdMemoryCardIcon ) )
       
  6455         {
       
  6456 #ifndef RD_MULTIPLE_DRIVE
       
  6457         TSysApMemoryCardStatus memoryCardStatus = iSysApMMCObserver->MemoryCardStatus();
       
  6458 
       
  6459         TRACES( RDebug::Print( _L("CSysApAppUi::SetMemoryCardIndicatorL: memoryCardStatus=%d"), memoryCardStatus ) );
       
  6460 
       
  6461         if ( memoryCardStatus == ESysApMemoryCardInserted || memoryCardStatus == ESysApMemoryCardLocked )
       
  6462 #else // RD_MULTIPLE_DRIVE
       
  6463         TInt insertedCount( CSysApDriveList::NonUsbDriveCount( iInsertedMemoryCards ) );
       
  6464 
       
  6465         TRACES( RDebug::Print( _L("CSysApAppUi::SetMemoryCardIndicatorL: insertedCount=%d"), insertedCount ) );
       
  6466 
       
  6467         if ( insertedCount > 0 )
       
  6468 #endif // RD_MULTIPLE_DRIVE
       
  6469             {
       
  6470             SetIndicatorStateL( EAknIndicatorMemoryCard, EAknIndicatorStateOn );
       
  6471             }
       
  6472         else
       
  6473             {
       
  6474             SetIndicatorStateL( EAknIndicatorMemoryCard, EAknIndicatorStateOff );
       
  6475             }
       
  6476         }
       
  6477     }
       
  6478 
       
  6479 // ----------------------------------------------------------------------------
       
  6480 // CSysApAppUi::SysApFeatureManager
       
  6481 // ----------------------------------------------------------------------------
       
  6482 
       
  6483 CSysApFeatureManager& CSysApAppUi::SysApFeatureManager()
       
  6484     {
       
  6485     __ASSERT_DEBUG( iSysApFeatureManager, User::Panic( _L("iSysApFeatureManager == NULL"), KErrBadHandle ) );
       
  6486 
       
  6487     return *iSysApFeatureManager;
       
  6488     }
       
  6489 
       
  6490 // ----------------------------------------------------------------------------
       
  6491 // CSysApAppUi::SetUsbAttachStatus
       
  6492 // ----------------------------------------------------------------------------
       
  6493 #ifndef RD_MULTIPLE_DRIVE
       
  6494 void CSysApAppUi::SetUsbAttachStatus( const TBool aUsbAttached )
       
  6495     {
       
  6496     // Prevent double beep when USB file transfer gets activated but
       
  6497     // allow MMC inserted beep when:
       
  6498     // a) USB file transfer is active
       
  6499     // b) MMC is not inserted when USB cable is attached
       
  6500     iHideNextBeep = ( iMMCInserted && aUsbAttached );
       
  6501     }
       
  6502 #else // RD_MULTIPLE_DRIVE
       
  6503 void CSysApAppUi::SetUsbAttachStatus( const TBool aUsbAttached )
       
  6504     {
       
  6505     TRACES( RDebug::Print(
       
  6506         _L( "CSysApAppUi::SetUsbAttachStatus: aUsbAttached: %d" ),
       
  6507         aUsbAttached ) );
       
  6508 
       
  6509     if ( aUsbAttached )
       
  6510         {
       
  6511         // For ignoring extra beeps caused by USB file transfer
       
  6512         iSysApDriveList->ResetDrivesInsertBeepIgnored();
       
  6513         iSysApDriveList->MarkDrivesInsertBeepIgnored( iInsertedMemoryCards );
       
  6514         }
       
  6515     }
       
  6516 #endif // RD_MULTIPLE_DRIVE
       
  6517 
       
  6518 // ----------------------------------------------------------------------------
       
  6519 // CSysApAppUi::IhfEnabledL
       
  6520 // ----------------------------------------------------------------------------
       
  6521 
       
  6522 TBool CSysApAppUi::IhfEnabledL()
       
  6523     {
       
  6524     TRACES( RDebug::Print( _L("CSysApAppUi::IhfEnabledL(): iSysApAudioRoutingObserver=0x%x"), iSysApAudioRoutingObserver ) );
       
  6525 
       
  6526     if ( !iSysApAudioRoutingObserver ) // create observer if needed
       
  6527         {
       
  6528         iSysApAudioRoutingObserver = CSysApAudioRoutingObserver::NewL( *this );
       
  6529         }
       
  6530 
       
  6531     return iSysApAudioRoutingObserver->IhfEnabled();
       
  6532     }
       
  6533 
       
  6534 // ----------------------------------------------------------------------------
       
  6535 // CSysApAppUi::IsDeviceModeKey
       
  6536 // ----------------------------------------------------------------------------
       
  6537 
       
  6538 TBool CSysApAppUi::IsDeviceModeKey( const TKeyEvent& aKeyEvent ) const
       
  6539     {
       
  6540     return CSysApDefaultKeyHandler::IsDeviceModeKey( aKeyEvent );
       
  6541     }
       
  6542 
       
  6543 // ----------------------------------------------------------------------------
       
  6544 // CSysApAppUi::ResourcesFreed
       
  6545 // ----------------------------------------------------------------------------
       
  6546 
       
  6547 TBool CSysApAppUi::ResourcesFreed() const
       
  6548     {
       
  6549     return iResourcesFreed;
       
  6550     }
       
  6551 
       
  6552 /* 
       
  6553 ----------------------------------------------------------------------------
       
  6554 CSysApAppUi::IsEncryptionOperationOngoingL()
       
  6555 Introduced the code as a part of Sub : 405-3362 - Power Management SUB for ES 
       
  6556 recapture functionalities in platform which support multidrive as well. 
       
  6557 -------------------------------------------------------------------------------
       
  6558 */
       
  6559 TBool CSysApAppUi::IsEncryptionOperationOngoingL() const
       
  6560     {
       
  6561 		TBool deFeatureSupported(EFalse);
       
  6562 		FeatureManager::InitializeLibL();
       
  6563 		deFeatureSupported = FeatureManager::FeatureSupported( KFeatureIdFfDeviceEncryptionFeature);
       
  6564 		FeatureManager::UnInitializeLib();
       
  6565 
       
  6566 		if(deFeatureSupported)
       
  6567 			{         
       
  6568 			/**
       
  6569 			 * Store the last memory status changed
       
  6570 			 * 0: Idle. It can be Encrypted or Decrypted
       
  6571 			 * 1: Encrypting
       
  6572 			 * 2: Decrypting
       
  6573 			 **/
       
  6574 			 
       
  6575 			RProperty deProperty;
       
  6576 			User::LeaveIfError(deProperty.Attach(KDevEncProtectedUid, KDevEncOperationKey,EOwnerThread));
       
  6577 			TInt deValue = 0;
       
  6578 			if((deProperty.Get(deValue)== KErrNone)&&( deValue == EOpEncrypting || deValue == EOpDecrypting))
       
  6579 				{
       
  6580 				deProperty.Close();
       
  6581 				return ETrue;
       
  6582 				}
       
  6583 			else
       
  6584 				{
       
  6585 				deProperty.Close();
       
  6586 				return EFalse;
       
  6587 				}
       
  6588 			}
       
  6589 		else
       
  6590 			{
       
  6591 			return EFalse;
       
  6592 			}
       
  6593     }
       
  6594 // ----------------------------------------------------------------------------
       
  6595 // CSysApAppUi::EtelConnector
       
  6596 // ----------------------------------------------------------------------------
       
  6597 
       
  6598 CSysApEtelConnector* CSysApAppUi::EtelConnector() const
       
  6599     {
       
  6600     return iSysApEtelConnector;
       
  6601     }
       
  6602 
       
  6603 #ifndef RD_MULTIPLE_DRIVE
       
  6604 
       
  6605 // ----------------------------------------------------------------------------
       
  6606 // CSysApAppUi::EjectUsed
       
  6607 // ----------------------------------------------------------------------------
       
  6608 
       
  6609 void CSysApAppUi::EjectUsed( TInt /*aDrive*/ )
       
  6610     {
       
  6611     }
       
  6612 
       
  6613 #else // RD_MULTIPLE_DRIVE
       
  6614 
       
  6615 // ----------------------------------------------------------------------------
       
  6616 // CSysApAppUi::ShowEjectWaitNoteL
       
  6617 // ----------------------------------------------------------------------------
       
  6618 
       
  6619 void CSysApAppUi::ShowEjectWaitNoteL( TInt aDriveToEject )
       
  6620     {
       
  6621     if ( iSysApWaitNote )
       
  6622         {
       
  6623         return;
       
  6624         }
       
  6625     HBufC* text = iSysApDriveList->GetFormattedDriveNameLC(
       
  6626         aDriveToEject,
       
  6627         0, // Not used
       
  6628         R_QTN_EJECTING_MEMORY_NAME_WAIT );
       
  6629     iSysApWaitNote = CSysApWaitNote::NewL(
       
  6630         iSysApFeatureManager->CoverDisplaySupported() );
       
  6631     iSysApWaitNote->ShowNoteL( EClosingApplicationsNote, text );
       
  6632     CleanupStack::PopAndDestroy( text );
       
  6633     }
       
  6634 
       
  6635 // ----------------------------------------------------------------------------
       
  6636 // CSysApAppUi::IsEjectQueryVisible
       
  6637 // ----------------------------------------------------------------------------
       
  6638 
       
  6639 TBool CSysApAppUi::IsEjectQueryVisible()
       
  6640     {
       
  6641     if ( !iSysApConfirmationQuery )
       
  6642         {
       
  6643         return EFalse;
       
  6644         }
       
  6645     TInt queryId( iSysApConfirmationQuery->CurrentQuery() );
       
  6646     return ( queryId == ESysApEjectMmcQuery || queryId == ESysApRemoveMmcNote );
       
  6647     }
       
  6648 
       
  6649 // ----------------------------------------------------------------------------
       
  6650 // CSysApAppUi::UpdateInsertedMemoryCardsL
       
  6651 // ----------------------------------------------------------------------------
       
  6652 
       
  6653 void CSysApAppUi::UpdateInsertedMemoryCardsL()
       
  6654     {
       
  6655     // Update inserted memory cards
       
  6656     iSysApDriveList->GetMemoryCardsL(
       
  6657         iInsertedMemoryCards, CSysApDriveList::EIncludeInserted );
       
  6658 
       
  6659     // Update memory card indicator status
       
  6660     SetMemoryCardIndicatorL();
       
  6661 
       
  6662     // Handle unlock
       
  6663     RunUnlockNotifierL();
       
  6664     }
       
  6665 
       
  6666 // ----------------------------------------------------------------------------
       
  6667 // CSysApAppUi::EjectUsed
       
  6668 // ----------------------------------------------------------------------------
       
  6669 
       
  6670 void CSysApAppUi::EjectUsed( TInt aDrive )
       
  6671     {
       
  6672     // Check drive inserted before starting eject confirm query
       
  6673     TInt insertedIndex( CSysApDriveList::Find( iInsertedMemoryCards, aDrive ) );
       
  6674 
       
  6675     TRACES( RDebug::Print(
       
  6676         _L( "CSysApAppUi::EjectUsed: drive: %d, index: %d" ),
       
  6677         aDrive, insertedIndex ) );
       
  6678 
       
  6679     if ( insertedIndex == KErrNotFound )
       
  6680         {
       
  6681         return;
       
  6682         }
       
  6683 
       
  6684     iMMCEjectUsed = ETrue;
       
  6685     iDriveToEject = aDrive;
       
  6686     iSysApDriveList->ResetDrivesToEject();
       
  6687     TRAPD( err, EjectMMCL() );
       
  6688     if ( err != KErrNone )
       
  6689         {
       
  6690         TRACES( RDebug::Print(
       
  6691             _L( "CSysApAppUi::EjectUsed: err: %d" ), err ) );
       
  6692         iMMCEjectUsed = EFalse;
       
  6693         }
       
  6694     }
       
  6695 
       
  6696 #endif // RD_MULTIPLE_DRIVE
       
  6697 
       
  6698 // ----------------------------------------------------------------------------
       
  6699 // CSysApAppUi::EjectMMCCanceled
       
  6700 // ----------------------------------------------------------------------------
       
  6701 
       
  6702 void CSysApAppUi::EjectMMCCanceled()
       
  6703     {
       
  6704     // Called from eject confirm query, reset eject status
       
  6705 #ifdef RD_MULTIPLE_DRIVE
       
  6706     iMMCEjectUsed = EFalse;
       
  6707 #endif // RD_MULTIPLE_DRIVE
       
  6708     }
       
  6709 
       
  6710 // ----------------------------------------------------------------------------
       
  6711 // CSysApAppUi::UsbChargerDetector
       
  6712 // ----------------------------------------------------------------------------
       
  6713 //
       
  6714 TSysApUsbChargerDetector& CSysApAppUi::UsbChargerDetector()
       
  6715     {
       
  6716     return iSysApUsbChargerDetector;
       
  6717     }
       
  6718 
       
  6719 // ----------------------------------------------------------------------------
       
  6720 // CSysApAppUi::HandleUsbCharger
       
  6721 // ----------------------------------------------------------------------------
       
  6722 //
       
  6723 void CSysApAppUi::HandleUsbCharger( const TInt aValue )
       
  6724     {        
       
  6725     if ( aValue == EChargingStatusCharging ||
       
  6726          aValue == EChargingStatusChargingContinued ||
       
  6727          aValue == EChargingStatusAlmostComplete )
       
  6728         {
       
  6729         iSysApUsbChargerDetector.SetChargingUsed( ETrue );
       
  6730         if ( !iSysApUsbIndicatorController &&
       
  6731              iSysApFeatureManager->Supported( KSysApFeatureIdChargerReminderNotes ) &&
       
  6732              iSysApFeatureManager->Supported( KSysApFeatureIdUsbChargingWithoutReminderNotes ) )
       
  6733             {
       
  6734             // Start observing USB state for the reminder note
       
  6735             TRAPD ( usbErr, iSysApUsbIndicatorController = CreateSysApUsbIndicatorL( *this ) );
       
  6736             if ( usbErr )
       
  6737                 {
       
  6738                 TRACES( RDebug::Print(
       
  6739                     _L("CSysApAppUi::HandleUsbCharger: error in constructing USB ind. controller %d" ),
       
  6740                     usbErr ) );
       
  6741                 }
       
  6742             }
       
  6743         }
       
  6744     }
       
  6745 
       
  6746 // ----------------------------------------------------------------------------
       
  6747 // CSysApAppUi::SetEnvelopeIndicatorL
       
  6748 // ----------------------------------------------------------------------------
       
  6749 //
       
  6750 void CSysApAppUi::SetEnvelopeIndicatorL()
       
  6751     {
       
  6752     TInt phoneStoreStatus( StateOfProperty( KUidPSSMSStackCategory, KUidPSSMSStackDiskSpaceMonitorKey ) );
       
  6753     TInt inboxStatus( StateOfProperty( KUidSystemCategory, KUidInboxStatusValue ) );
       
  6754     TBool simStoreFull( iSysApEtelConnector && iSysApEtelConnector->IsSimSmsStoreFull() );
       
  6755 
       
  6756     TRACES( RDebug::Print(
       
  6757         _L("CSysApAppUi::SetEnvelopeIndicatorL() phoneStoreStatus %d, simStoreFull %d, inboxStatus %d"),
       
  6758         phoneStoreStatus, simStoreFull, inboxStatus ) );
       
  6759 
       
  6760     if ( phoneStoreStatus == ESmsDiskSpaceFull || simStoreFull )
       
  6761         {
       
  6762         // Blink the Envelope indicator
       
  6763         SetIndicatorStateL( EAknIndicatorEnvelope, EAknIndicatorStateAnimate );
       
  6764         }
       
  6765     else if ( inboxStatus == ESADocumentsInInbox )
       
  6766         {
       
  6767         // Show the Envelope indicator.
       
  6768         SetIndicatorStateL( EAknIndicatorEnvelope, EAknIndicatorStateOn );
       
  6769         }
       
  6770     else
       
  6771         {
       
  6772         // Hide the Envelope indicator.
       
  6773         SetIndicatorStateL( EAknIndicatorEnvelope, EAknIndicatorStateOff );
       
  6774         }
       
  6775     }
  3942     
  6776     
  3943     switch( aType )
  6777 // ----------------------------------------------------------------------------
  3944         {
  6778 // CSysApAppUi::LogsObserverL
  3945         case EEikKeyLockEnabled:
  6779 // ----------------------------------------------------------------------------
  3946             iKeyLockEnabled = ETrue;
  6780 //
  3947             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 1 );
  6781 CSysApCenRepLogsObserver& CSysApAppUi::LogsObserverL()
  3948 //            SetIndicatorStateL( EAknIndicatorKeyguard, EAknIndicatorStateOn );
  6782     {
  3949             iSysApLightsController->KeylockStateChangedL( ETrue );
  6783     TRACES( RDebug::Print( _L("CSysApAppUi::LogsObserverL()") ) );
       
  6784     
       
  6785     // Create Logs observer when it is needed for the first time
       
  6786     if ( !iSysApCenRepLogsObserver )
       
  6787         {
       
  6788         iSysApCenRepLogsObserver = CSysApCenRepLogsObserver::NewL( *this );
       
  6789         }
       
  6790     
       
  6791     return *iSysApCenRepLogsObserver;
       
  6792     }
       
  6793     
       
  6794 // ----------------------------------------------------------------------------
       
  6795 // CSysApAppUi::NotifyPowerSaveModeL
       
  6796 // ----------------------------------------------------------------------------
       
  6797 //
       
  6798 void CSysApAppUi::NotifyPowerSaveModeL( TSysApPsmStatus aStatus )
       
  6799     {
       
  6800     TRACES( RDebug::Print( _L("CSysApAppUi::NotifyPowerSaveModeL aStatus: %d"), aStatus ) );
       
  6801 
       
  6802     // cancel any active power saving query because user has changed the state manually
       
  6803     CancelQuery( ESysApBattChargingPowerSavingQuery );
       
  6804     CancelQuery( ESysApBattLowPowerSavingQuery );
       
  6805 
       
  6806     switch ( aStatus )
       
  6807         {
       
  6808         case MSysApPsmControllerNotifyCallback::EPsmActivationComplete:
       
  6809             UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  6810             ShowUiNoteL( EPowerSaveModeActivated );
       
  6811            break;
       
  6812         
       
  6813         case MSysApPsmControllerNotifyCallback::EPsmDeactivationComplete:
       
  6814             UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
       
  6815             ShowUiNoteL( EPowerSaveModeDeactivated );
  3950             break;
  6816             break;
  3951         case EEikKeyLockDisabled:
  6817             
  3952             iKeyLockEnabled = EFalse;
  6818         case MSysApPsmControllerNotifyCallback::EPsmActivationFailed:
  3953             iSysApCenRepController->SetInt( KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive, 0 );
  6819             ShowUiNoteL( ECannotActivatePowerSaveMode );
  3954 //            SetIndicatorStateL( EAknIndicatorKeyguard, EAknIndicatorStateOff );
       
  3955             if (! iDeviceLockEnabled )
       
  3956                 {
       
  3957                 iSysApLightsController->KeylockStateChangedL( EFalse );
       
  3958                 if ( iSysApFeatureManager->MmcHotSwapSupported() )
       
  3959                     {
       
  3960                     if ( StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateRinging && StateOfProperty( KPSUidCtsyCallInformation, KCTsyCallState ) !=  EPSCTsyCallStateAlerting )
       
  3961                         {
       
  3962                         RunUnlockNotifierL();
       
  3963                         }
       
  3964                     }
       
  3965                 }
       
  3966             break;
  6820             break;
  3967         case EEikKeyLockPowerKeyPressed: //sent when power key is captured by keylockserver
  6821             
  3968 //            HandleShortPowerKeyPressedL();
  6822         case MSysApPsmControllerNotifyCallback::EPsmDeactivationFailed:
  3969             break;
  6823             ShowUiNoteL( ECannotDeactivatePowerSaveMode );
  3970 
  6824             break;            
  3971         case EEikKeyLockLightsOnRequest:
  6825         
  3972             iSysApLightsController->SetLightsOnUnlockNoteL();
       
  3973             break;
       
  3974 
       
  3975         case EEikEcsQueryLights: // emergency note is shown
       
  3976             iSysApLightsController->SetLightsOnEcsQueryL();
       
  3977             break;
       
  3978 
       
  3979         case EEikSecurityQueryLights: // for device lock security query
       
  3980             iSysApLightsController->SetLightsOnSecurityQueryL();
       
  3981             break;
       
  3982 
       
  3983         default:
  6826         default:
  3984             break;
  6827             break;   
  3985             }
  6828         }
  3986     }
  6829     }
  3987 
  6830 
  3988 
  6831 // ----------------------------------------------------------------------------
  3989 
  6832 // CSysApAppUi::HandleBatteryStatusL
  3990 // ----------------------------------------------------------------------------
  6833 // ----------------------------------------------------------------------------
  3991 // CSysApAppUi::HandleNspsRawKeyEventL()
  6834 //
  3992 // ----------------------------------------------------------------------------
  6835 void CSysApAppUi::HandleBatteryStatusL( const TInt aValue )
  3993 
  6836     {
  3994 void CSysApAppUi::HandleNspsRawKeyEventL()
  6837     TRACES( RDebug::Print( _L("CSysApAppUi::HandleBatteryStatusL aValue: %d"), aValue ) );
  3995     {
  6838     
  3996 #ifdef __SYSAP_MODULE_TEST
  6839     if ( aValue == EBatteryStatusEmpty )
  3997     ModuleTestShowUiNoteL( _L("Network wakeup from NSPS") );
  6840         {
  3998 #endif
  6841         //Display Recharge Battery note
  3999 
  6842         ShowUiNoteL( ERechargeBatteryNote );
  4000     if ( iSysApEtelConnector )
  6843         BatteryEmptyL();
  4001         {
  6844         }
  4002         iSysApEtelConnector->CommandNetCsWakeupOnNsps();
  6845     else if ( aValue == EBatteryStatusLow )
  4003         }
  6846         {
  4004     }
  6847         if ( iSysApPsmController && UiReady() )
  4005 
  6848             {
  4006 // ----------------------------------------------------------------------------
  6849             iSysApPsmController->BatteryLow( ETrue );
  4007 // CSysApAppUi::UpdateSignalBarsL()
  6850             
  4008 // ----------------------------------------------------------------------------
  6851             if ( iSysApPsmController->ShowActivateQuery())
  4009 
  6852                 {
  4010 void CSysApAppUi::UpdateSignalBarsL()
  6853                 // show activation query, replaces the first battery low query
  4011     {
  6854                 ShowQueryL( ESysApBattLowPowerSavingQuery );
  4012 //    UpdateSignalBarsL(iSysApEtelConnector->GetSignalBars());
  6855                 }
  4013     }
  6856             else // default low warning note must be shown
  4014 
  6857                 {
  4015 // ----------------------------------------------------------------------------
  6858                 // activate partial power save mode on first low warning
  4016 // CSysApAppUi::HandleSmsStorageNotificationL( TBool aSimStoreFull )
  6859                 iSysApPsmController->DoEnablePartialPsm( ETrue ); // activated on first warning note
  4017 // ----------------------------------------------------------------------------
  6860                 //Display Battery Low note.
  4018 
  6861                 ShowUiNoteL( EBatteryLowNote );    
  4019 void CSysApAppUi::HandleSmsStorageNotificationL( TBool aSimStoreFull )
  6862                 }                
  4020     {
  6863             }
  4021     TRACES( RDebug::Print( _L("CSysApAppUi::HandleSmsStorageNotificationL: aSimStoreFull: %d "), aSimStoreFull ) );
  6864         else
  4022 
  6865             {
  4023     if ( aSimStoreFull )
  6866             //Display Battery Low note.
  4024         {
  6867             ShowUiNoteL( EBatteryLowNote );    
  4025 /*        HBufC* noteStringBuf;
  6868             }            
  4026         noteStringBuf = StringLoader::LoadLC( R_QTN_MEMLO_MEMORY_LOW_SIM_MES, iEikonEnv );
  6869         }
  4027         TPtr textBuffer = noteStringBuf->Des();
  6870     
  4028         iSysApMsgSimMemLowQuery->StartL( textBuffer );
  6871     if ( iSysApBatteryInfoController )
  4029         CleanupStack::PopAndDestroy();
  6872         {
  4030 */        }
  6873         iSysApBatteryInfoController->BatteryStatusUpdated( aValue );
  4031 
  6874         }
  4032 //    SetEnvelopeIndicatorL();
  6875             
  4033     }
  6876     }
  4034 
  6877 
  4035 // ----------------------------------------------------------------------------
  6878 // ----------------------------------------------------------------------------
  4036 // CSysApAppUi::HandleNetworkNspsNotification( RMmCustomAPI::TNspsStatus aNspsStatus )
  6879 // CSysApAppUi::HandleChargingStatusL
  4037 // ----------------------------------------------------------------------------
  6880 // ----------------------------------------------------------------------------
  4038 
  6881 //
  4039 void CSysApAppUi::HandleNetworkNspsNotification( RMmCustomAPI::TNspsStatus aNspsStatus )
  6882 void CSysApAppUi::HandleChargingStatusL( const TInt aValue )
  4040     {
  6883     {
  4041     TRACES( RDebug::Print( _L("CSysApAppUi::HandleNetworkNspsNotification aNspsStatus:%d, iNsps:%d )" ), aNspsStatus, iNsps ) );
  6884     TRACES( RDebug::Print( _L("CSysApAppUi::HandleChargingStatusL aValue: %d"), aValue ) );
  4042     if( iSysApNspsHandler )
  6885     
  4043         {
  6886     TBool showNote( ETrue );
  4044         if( aNspsStatus == RMmCustomAPI::ENspsOn )
  6887     
  4045             {
  6888     UpdateBatteryBarsL( StateOfProperty( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
  4046             if( !iNsps )
  6889 
  4047                 {
  6890     if ( iSysApPsmController && UiReady() ) 
  4048 #ifdef __SYSAP_MODULE_TEST
  6891         {
  4049                 TRAPD( err, ModuleTestShowUiNoteL( _L("Setting NSPS on") ) );
  6892         if ( iCharging ) // iCharging updated in UpdateBatteryBarsL
  4050 #endif
  6893             {
  4051                 iSysApNspsHandler->SetNspsOn();
  6894             // cancel activation query if charger is connected while query is on display
  4052                 iNsps = ETrue;
  6895             CancelQuery( ESysApBattLowPowerSavingQuery );
  4053                 }
  6896             }
  4054             }
  6897              
  4055         else if( aNspsStatus == RMmCustomAPI::ENspsOff )
  6898         if ( iCharging && !iSysApPsmController->ChargerConnected() ) // first time after charger connection
  4056             {
  6899             {
  4057             if( iNsps )
  6900             iSysApPsmController->ConnectCharger( ETrue );
  4058                 {
  6901             
  4059 #ifdef __SYSAP_MODULE_TEST
  6902             if ( iSysApPsmController->ShowDeactivateQuery() )
  4060                 TRAPD( err, ModuleTestShowUiNoteL( _L("Setting NSPS off") ) );
  6903                 {
  4061 #endif
  6904                 ShowQueryL( ESysApBattChargingPowerSavingQuery );
  4062                 iSysApNspsHandler->SetNspsOff();
  6905                 // Query is on the display. Don't show the note.
  4063                 iNsps = EFalse;
  6906                 showNote = EFalse;               
  4064                 }
  6907                 }
  4065             }
  6908             else
  4066         }
  6909                 {
  4067     }
  6910                 iSysApPsmController->DoEnablePartialPsm( EFalse );
  4068 
  6911                 }                
  4069 
  6912             }
  4070 
  6913         else if ( aValue == EChargingStatusNotConnected )
  4071 //end of file
  6914             {
       
  6915             iSysApPsmController->ConnectCharger( EFalse );
       
  6916             
       
  6917             // cancel deactivation query if charger is disconnected while query is on display 
       
  6918             CancelQuery( ESysApBattChargingPowerSavingQuery );
       
  6919             }            
       
  6920         }
       
  6921     if( showNote )
       
  6922         {
       
  6923         HandleChargerNotesL( aValue );    
       
  6924         }
       
  6925     }
       
  6926 
       
  6927 // ----------------------------------------------------------------------------
       
  6928 // CSysApAppUi::HandleActivatePsmQueryResponse
       
  6929 // ----------------------------------------------------------------------------
       
  6930 //
       
  6931 void CSysApAppUi::HandleActivatePsmQueryResponse( TBool aEnable )
       
  6932     {
       
  6933     TRACES( RDebug::Print( _L("CSysApAppUi::HandleActivatePsmQueryResponse aEnable: %d"), 
       
  6934         aEnable ) );
       
  6935     
       
  6936     __ASSERT_DEBUG( iSysApPsmController, User::Invariant() );
       
  6937     
       
  6938     if ( aEnable )
       
  6939         {
       
  6940         iSysApPsmController->DoEnableFullPsm( ETrue );    
       
  6941         }
       
  6942     else
       
  6943         {
       
  6944         iSysApPsmController->DoEnablePartialPsm( ETrue );     
       
  6945         }        
       
  6946     }
       
  6947 
       
  6948 // ----------------------------------------------------------------------------
       
  6949 // CSysApAppUi::HandleDeactivatePsmQueryResponse
       
  6950 // ----------------------------------------------------------------------------
       
  6951 //
       
  6952 void CSysApAppUi::HandleDeactivatePsmQueryResponse( TBool aDisable )
       
  6953     {
       
  6954     TRACES( RDebug::Print( _L("CSysApAppUi::HandleDeactivatePsmQueryResponse aDisable: %d"), 
       
  6955         aDisable ) );
       
  6956 
       
  6957     __ASSERT_DEBUG( iSysApPsmController, User::Invariant() );
       
  6958     
       
  6959     if ( aDisable )
       
  6960         {
       
  6961         iSysApPsmController->DoEnableFullPsm( EFalse );        
       
  6962         }
       
  6963     }
       
  6964     
       
  6965 // ----------------------------------------------------------------------------
       
  6966 // CSysApAppUi::CancelQuery
       
  6967 // ----------------------------------------------------------------------------
       
  6968 //
       
  6969 void CSysApAppUi::CancelQuery( TSysApConfirmationQueryIds aQueryId )
       
  6970     {
       
  6971     TRACES( RDebug::Print( _L("CSysApAppUi::CancelQuery aQueryId: %d"), aQueryId ) );
       
  6972 
       
  6973     if ( iSysApConfirmationQuery )
       
  6974         {
       
  6975         if ( aQueryId == iSysApConfirmationQuery->CurrentQuery() || aQueryId == ESysApNoQuery )
       
  6976             {
       
  6977             iSysApConfirmationQuery->Cancel();
       
  6978             }
       
  6979         }
       
  6980     }
       
  6981 
       
  6982 TBool CSysApAppUi::IsDefaultPowerKeyBehavior()
       
  6983     {
       
  6984     TRACES( RDebug::Print( _L("CSysApAppUi::IsDefaultPowerKeyBehavior" ) ) );
       
  6985     TBool powerKeyIsLockKey = iSysApFeatureManager->PowerKeyIsLockKey();
       
  6986     if ( !powerKeyIsLockKey )
       
  6987         return ETrue; //no need for further processing
       
  6988     TInt securityDialogStatus = StateOfProperty( KPSUidStartup, KStartupSecurityCodeQueryStatus );
       
  6989     TRACES( RDebug::Printf( "CSysApAppUi::IsDefaultPowerKeyBehavior: securityDialogStatus = %d", securityDialogStatus ) );
       
  6990     if ( securityDialogStatus == ESecurityQueryActive  )
       
  6991         {
       
  6992         // handle the exception from the exception. Currently used only when a long power key press is detected
       
  6993         return ETrue; 
       
  6994         }
       
  6995     //make sure we can turn off device when 'sim invalid' dlg is displayed
       
  6996     TInt simStatus = StateOfProperty( KPSUidStartup, KStartupSimSecurityStatus ); 
       
  6997     TBool simBogus = ( simStatus == ESimRejected ) || ( simStatus == ESimUnaccepted ) || (simStatus == ESimInvalid );
       
  6998     
       
  6999     // check if the phone has fully booted into idle  
       
  7000     TInt startupPhase = StateOfProperty ( KPSUidStartup, KPSStartupUiPhase );
       
  7001     TBool bootCompleted = (EStartupUiPhaseAllDone == startupPhase);
       
  7002     
       
  7003 	// Another exception from the exception:
       
  7004     // check if we're in charging or alert mode (only then we have a status pane instance)    
       
  7005     TBool haveStatusPane = ( StatusPane()== NULL ) ? EFalse : StatusPane()->IsVisible();
       
  7006     TBool defaultPowerKeyBehaviour = !bootCompleted || simBogus || haveStatusPane || iPowerKeyPopupMenuActive || !powerKeyIsLockKey;
       
  7007     
       
  7008     TRACES( RDebug::Printf( "CSysApAppUi::IsDefaultPowerKeyBehavior: Sim Status = %d, haveStatusPane = %d, power key menu active? %d" , simStatus, haveStatusPane, iPowerKeyPopupMenuActive  ) );       
       
  7009     TRACES( RDebug::Printf( "CSysApAppUi::IsDefaultPowerKeyBehavior returns %d", defaultPowerKeyBehaviour ) );   
       
  7010     TRACES( RDebug::Printf( "CSysApAppUi::IsDefaultPowerKeyBehavior: startupPhase = %d", startupPhase ) );
       
  7011     return defaultPowerKeyBehaviour;
       
  7012     }
       
  7013 	
       
  7014 // ----------------------------------------------------------------------------
       
  7015 // CSysApAppUi::StartChargingBatteryL
       
  7016 // ----------------------------------------------------------------------------
       
  7017 //
       
  7018 void CSysApAppUi::StartChargingBatteryL() 
       
  7019 	{
       
  7020 	TRACES( RDebug::Print( _L("CSysApAppUi::StartChargingBatteryL") ) );
       
  7021     iBatteryNotify->StartChargingL();
       
  7022     }
       
  7023 	
       
  7024 // ----------------------------------------------------------------------------
       
  7025 // CSysApAppUi::StopChargingBatteryL
       
  7026 // ----------------------------------------------------------------------------
       
  7027 //
       
  7028 void CSysApAppUi::StopChargingBatteryL()
       
  7029 	{
       
  7030 	TRACES( RDebug::Print( _L("CSysApAppUi::StopChargingBatteryL") ) );
       
  7031     iBatteryNotify->StopChargingL();
       
  7032     }
       
  7033 	
       
  7034 // End of File