satengine/SatServer/Commands/SetUpIdleModeTextCmd/src/CSetUpIdleModeTextHandler.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Handles SetUpIdleModeText command
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    <e32property.h>
       
    20 #include    <centralrepository.h>
       
    21 #include    <NetworkHandlingDomainPSKeys.h>
       
    22 #include    "SATPrivateCRKeys.h"
       
    23 #include    "MSatApi.h"
       
    24 #include    "MSatUtils.h"
       
    25 #include    "MSatUiSession.h"
       
    26 #include    "SatSOpcodes.h"
       
    27 #include    "MSatSUiClientHandler.h"
       
    28 #include    "MSatSystemState.h"
       
    29 #include    "CSetUpIdleModeTextHandler.h"
       
    30 #include    "SatLog.h"
       
    31 
       
    32 // This was agreed with Idle.
       
    33 const TInt KNoIcon = -1;
       
    34 
       
    35 // ======== MEMBER FUNCTIONS ========
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CSetUpIdleModeTextHandler::CSetUpIdleModeTextHandler
       
    39 // C++ default constructor can NOT contain any code, that
       
    40 // might leave.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CSetUpIdleModeTextHandler::CSetUpIdleModeTextHandler() :
       
    44     CSatCommandHandler(),
       
    45     iSetUpIdleModeTextData(),
       
    46     iSetUpIdleModeTextPckg( iSetUpIdleModeTextData ),
       
    47     iSetUpIdleModeTextRsp(),
       
    48     iSetUpIdleModeTextRspPckg( iSetUpIdleModeTextRsp ),
       
    49     iSimResetExecuting( EFalse ),
       
    50     iLastValidText( KNullDesC ),
       
    51     iLastValidIconId( KNoIcon ),
       
    52     iLastValidIconQualifier( RSat::EIconQualifierNotSet ),
       
    53     iHasHomezoneIndicator( 0 )
       
    54     {
       
    55     LOG( SIMPLE, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::\
       
    56         CSetUpIdleModeTextHandler calling - exiting" )
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CSetUpIdleModeTextHandler::ConstructL
       
    61 // Symbian 2nd phase constructor can leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 void CSetUpIdleModeTextHandler::ConstructL()
       
    65     {
       
    66     LOG( SIMPLE, "SETUPIDLEMODETEXT: \
       
    67         CSetUpIdleModeTextHandler::ConstructL calling" )
       
    68 
       
    69     iWaitingForResponse = EFalse;
       
    70 
       
    71     // Register to listen Idle mode responses.
       
    72     iUtils->RegisterL( this, MSatUtils::EIdleModeResponseSuccess );
       
    73     iUtils->RegisterL( this, MSatUtils::EIdleModeResponseSuccessNoIcon );
       
    74     iUtils->RegisterL( this, MSatUtils::EIdleModeResponseUnableToProcess );
       
    75     iUtils->RegisterL( this, MSatUtils::EIdleModeResponseBeyondCapabilities );
       
    76 
       
    77     // Register to listen ESimReset execution.
       
    78     iUtils->RegisterL( this, MSatUtils::ESimResetCalled );
       
    79     iUtils->RegisterL( this, MSatUtils::ESimResetCancelled );
       
    80     iUtils->RegisterL( this, MSatUtils::ESimInitDone );
       
    81     // Get the homezone indicator flag from the Central Repository.
       
    82     CRepository* repo = CRepository::NewLC( KCRUidSatServer );
       
    83     TInt errorCode = repo->Get( KSatHomeZoneIconVisible, iHasHomezoneIndicator );
       
    84     LOG2( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::ConstructL \
       
    85         get homezone indicator flag and return: %d", errorCode )
       
    86     CleanupStack::PopAndDestroy( repo );
       
    87 
       
    88     LOG( SIMPLE, "SETUPIDLEMODETEXT: \
       
    89         CSetUpIdleModeTextHandler::ConstructL exiting" )
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CSetUpIdleModeTextHandler::NewL
       
    94 // Two-phased constructor.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CSetUpIdleModeTextHandler* CSetUpIdleModeTextHandler::NewL( MSatUtils* aUtils )
       
    98     {
       
    99     LOG( SIMPLE,
       
   100         "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::NewL calling" )
       
   101 
       
   102     CSetUpIdleModeTextHandler* self = new( ELeave ) CSetUpIdleModeTextHandler;
       
   103 
       
   104     CleanupStack::PushL( self );
       
   105     self->BaseConstructL( aUtils );
       
   106     self->ConstructL();
       
   107     CleanupStack::Pop( self );
       
   108 
       
   109     LOG( SIMPLE,
       
   110         "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::NewL exiting" )
       
   111     return self;
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CSetUpIdleModeTextHandler::~CSetUpIdleModeTextHandler
       
   116 // Destructor.
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 CSetUpIdleModeTextHandler::~CSetUpIdleModeTextHandler()
       
   120     {
       
   121     LOG( SIMPLE, "SETUPIDLEMODETEXT: \
       
   122         CSetUpIdleModeTextHandler::~CSetUpIdleModeTextHandler calling" )
       
   123 
       
   124     Cancel();
       
   125 
       
   126     LOG( SIMPLE, "SETUPIDLEMODETEXT: \
       
   127         CSetUpIdleModeTextHandler::~CSetUpIdleModeTextHandler exiting" )
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CSetUpIdleModeTextHandler::Event
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void CSetUpIdleModeTextHandler::Event( TInt aEvent )
       
   135     {
       
   136     LOG( SIMPLE,
       
   137         "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::Event calling" )
       
   138     TBool responseOk( EFalse );
       
   139 
       
   140     // Check the response
       
   141     switch ( aEvent )
       
   142         {
       
   143         case MSatUtils::EIdleModeResponseSuccess:
       
   144             {
       
   145             LOG( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   146                 KSuccess")
       
   147             iSetUpIdleModeTextRsp.iGeneralResult = RSat::KSuccess;
       
   148             responseOk = ETrue;
       
   149             break;
       
   150             }
       
   151 
       
   152         case MSatUtils::EIdleModeResponseSuccessNoIcon:
       
   153             {
       
   154             LOG( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   155                 KSuccessReqIconNotDisplayed")
       
   156             iSetUpIdleModeTextRsp.iGeneralResult =
       
   157                 RSat::KSuccessRequestedIconNotDisplayed;
       
   158             responseOk = ETrue;
       
   159             break;
       
   160             }
       
   161 
       
   162         case MSatUtils::EIdleModeResponseUnableToProcess:
       
   163             {
       
   164             LOG( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   165                 KMeUnableToProcessCmd")
       
   166             iSetUpIdleModeTextRsp.iGeneralResult =
       
   167                 RSat::KMeUnableToProcessCmd;
       
   168             responseOk = ETrue;
       
   169             break;
       
   170             }
       
   171 
       
   172         case MSatUtils::EIdleModeResponseBeyondCapabilities:
       
   173             {
       
   174             LOG( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   175                 KBeyondMeCapabilities")
       
   176             iSetUpIdleModeTextRsp.iGeneralResult =
       
   177                 RSat::KCmdBeyondMeCapabilities;
       
   178             responseOk = ETrue;
       
   179             break;
       
   180             }
       
   181 
       
   182         case MSatUtils::ESimResetCalled:
       
   183             {
       
   184             LOG( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   185                  ESimResetCalled")
       
   186             iSimResetExecuting = ETrue;
       
   187             }
       
   188             //lint -fallthrough intended here
       
   189 
       
   190         case MSatUtils::ESimInitDone:
       
   191             {
       
   192             LOG( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   193                 remove idle mode text")
       
   194 
       
   195             // Remove the idle mode text and icon.
       
   196             // Note no response now, responseOk remains EFalse.
       
   197             iUtils->SystemState().WriteSetIdleModeText(
       
   198                 KNullDesC, KNoIcon, RSat::ENoIconId );
       
   199             // Remove the homezone indicator.
       
   200             if ( iHasHomezoneIndicator && iLastValidText.Length() )
       
   201                 {
       
   202                 TInt errorCode = RProperty::Set(
       
   203                         KPSUidNetworkInfo,
       
   204                         KNWHomeZoneStatus,
       
   205                         ENWNone );
       
   206                 LOG2( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   207                     remove the homezone indicator and return %d", errorCode )
       
   208                 }
       
   209             break;
       
   210             }
       
   211 
       
   212         case MSatUtils::ESimResetCancelled:
       
   213             {
       
   214             LOG( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   215                 ESimResetCancelled")
       
   216 
       
   217             // Restore the idle mode text and icon.
       
   218             // Note no response now, responseOk remains EFalse.
       
   219             if ( iSimResetExecuting )
       
   220                 {
       
   221                 LOG( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   222                 iSimResetExecuting true")
       
   223                 iUtils->SystemState().WriteSetIdleModeText(
       
   224                     iLastValidText, iLastValidIconId, iLastValidIconQualifier );
       
   225                 // Restore the homezone indicator as SIM reset was cancelled.
       
   226                 if ( iHasHomezoneIndicator && iLastValidText.Length() )
       
   227                     {
       
   228                     TInt errorCode = RProperty::Set(
       
   229                             KPSUidNetworkInfo,
       
   230                             KNWHomeZoneStatus,
       
   231                             ENWHomeZone );
       
   232                     LOG2( NORMAL, "SETUPIDLEMODETEXT: \
       
   233                     CSetUpIdleModeTextHandler restore the homezone indicator \
       
   234                     and return %d", errorCode )
       
   235                     }
       
   236                 iSimResetExecuting = EFalse;
       
   237                 }
       
   238             break;
       
   239             }
       
   240 
       
   241         default:
       
   242             {
       
   243             CSatCommandHandler::Event( aEvent );
       
   244             break;
       
   245             }
       
   246         }
       
   247 
       
   248     if ( responseOk && iWaitingForResponse )
       
   249         {
       
   250         LOG( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   251         send response")
       
   252         iWaitingForResponse = EFalse;
       
   253 
       
   254         // Send terminal response, if the event was solved
       
   255         TerminalRsp( RSat::ESetUpIdleModeText, iSetUpIdleModeTextRspPckg );
       
   256         }
       
   257 
       
   258     LOG( SIMPLE,
       
   259         "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::Event exiting" )
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CSetUpIdleModeTextHandler::DoCancel
       
   264 // Cancels the sat request.
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 void CSetUpIdleModeTextHandler::DoCancel()
       
   268     {
       
   269     LOG( SIMPLE,
       
   270         "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::DoCancel calling" )
       
   271 
       
   272     iUtils->USatAPI().NotifySetUpIdleModeTextCancel();
       
   273 
       
   274     LOG( SIMPLE,
       
   275         "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::DoCancel exiting" )
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CSetUpIdleModeTextHandler::IssueUSATRequest
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CSetUpIdleModeTextHandler::IssueUSATRequest( TRequestStatus& aStatus )
       
   283     {
       
   284     LOG( SIMPLE, "SETUPIDLEMODETEXT: \
       
   285         CSetUpIdleModeTextHandler::IssueUSATRequest calling" )
       
   286 
       
   287     // Clear the IPC package.
       
   288     new (&iSetUpIdleModeTextData) RSat::TSetUpIdleModeTextV1();
       
   289 
       
   290     iUtils->USatAPI().NotifySetUpIdleModeText(
       
   291         aStatus, iSetUpIdleModeTextPckg );
       
   292 
       
   293     LOG( SIMPLE, "SETUPIDLEMODETEXT: \
       
   294         CSetUpIdleModeTextHandler::IssueUSATRequest exiting" )
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CSetUpIdleModeTextHandler::CommandAllowed
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 TBool CSetUpIdleModeTextHandler::CommandAllowed()
       
   302     {
       
   303     LOG( SIMPLE, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::\
       
   304         CommandAllowed calling" )
       
   305     TBool commandAllowed( ETrue );
       
   306 
       
   307     if ( ( 0 == iSetUpIdleModeTextData.iText.Length() ) &&
       
   308          ( RSat::ENotSelfExplanatory ==
       
   309             iSetUpIdleModeTextData.iIconId.iQualifier ||
       
   310            RSat::ESelfExplanatory ==
       
   311             iSetUpIdleModeTextData.iIconId.iQualifier ) )
       
   312         {
       
   313         iSetUpIdleModeTextRsp.iGeneralResult = RSat::KCmdDataNotUnderstood;
       
   314         iSetUpIdleModeTextRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   315         iSetUpIdleModeTextRsp.iAdditionalInfo.Zero();
       
   316         iSetUpIdleModeTextRsp.SetPCmdNumber(
       
   317             iSetUpIdleModeTextData.PCmdNumber() );
       
   318         TerminalRsp( RSat::ESetUpIdleModeText, iSetUpIdleModeTextRspPckg );
       
   319         commandAllowed = EFalse;
       
   320         LOG( NORMAL,
       
   321             "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   322             CommandAllowed icon received without alpha id" )
       
   323         }
       
   324 
       
   325     LOG2( SIMPLE, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::\
       
   326         CommandAllowed exiting,commandAllowed: %d", commandAllowed )
       
   327     return commandAllowed;
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CSetUpIdleModeTextHandler::NeedUiSession
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 TBool CSetUpIdleModeTextHandler::NeedUiSession()
       
   335     {
       
   336     LOG( SIMPLE, "SETUPIDLEMODETEXT: \
       
   337         CSetUpIdleModeTextHandler::NeedUiSession calling - exiting" )
       
   338     return EFalse; // No need for UI Session.
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CSetUpIdleModeTextHandler::HandleCommand
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void CSetUpIdleModeTextHandler::HandleCommand()
       
   346     {
       
   347     LOG( SIMPLE,
       
   348         "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::HandleCommand calling" )
       
   349 
       
   350     iUtils->NotifyEvent( MSatUtils::ESetUpIdleModeTextExecuting );
       
   351 
       
   352     // The idle mode text is not written to shared data if
       
   353     // Sim indicates the removal of idle mode text.
       
   354     TPtrC idleModeText( iSetUpIdleModeTextData.iText );
       
   355     TInt iconId( iSetUpIdleModeTextData.iIconId.iIdentifier );
       
   356 
       
   357     // Get the icon description.
       
   358     const RSat::TIconQualifier qualifier
       
   359         ( iSetUpIdleModeTextData.iIconId.iQualifier );
       
   360 
       
   361     if ( RSat::ERemoveExistingIdleModeText == iSetUpIdleModeTextData.iType )
       
   362         {
       
   363         LOG( SIMPLE,
       
   364         "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::HandleCommand \
       
   365         ERemoveExistingIdleModeText" )
       
   366         idleModeText.Set( KNullDesC );
       
   367         iconId = KErrNotFound;
       
   368         }
       
   369     else
       
   370         {
       
   371         if ( ( RSat::ENoIconId == qualifier ) ||
       
   372              ( RSat::EIconQualifierNotSet == qualifier ) )
       
   373             {
       
   374             LOG( SIMPLE,
       
   375             "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::HandleCommand \
       
   376             KErrNotFound" )
       
   377             // Icon information not provided in command.
       
   378             iconId = KErrNotFound;
       
   379             }
       
   380         }
       
   381 
       
   382     // Write text and icon id to P&S.
       
   383     const TInt err(
       
   384         iUtils->SystemState().WriteSetIdleModeText(
       
   385             idleModeText, iconId, qualifier ) );
       
   386 
       
   387     iSetUpIdleModeTextRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   388     iSetUpIdleModeTextRsp.iAdditionalInfo.Zero();
       
   389     iSetUpIdleModeTextRsp.SetPCmdNumber(
       
   390         iSetUpIdleModeTextData.PCmdNumber() );
       
   391 
       
   392     // Send the terminal response now, if there was an error.
       
   393     if ( KErrNone != err )
       
   394         {
       
   395         LOG( NORMAL,
       
   396             "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::HandleCommand \
       
   397             Error, Sending Terminal Response" )
       
   398         iSetUpIdleModeTextRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   399 
       
   400         // Send the response.
       
   401         TerminalRsp( RSat::ESetUpIdleModeText, iSetUpIdleModeTextRspPckg );
       
   402         }
       
   403     else
       
   404         {
       
   405         iWaitingForResponse = ETrue;
       
   406 
       
   407         // Save data for restore.
       
   408         iSimResetExecuting = EFalse;
       
   409         iLastValidText = idleModeText;
       
   410         iLastValidIconId = iconId;
       
   411         iLastValidIconQualifier = qualifier;
       
   412         // Show or remove the homezone indicator.
       
   413         if ( iHasHomezoneIndicator )
       
   414             {
       
   415             if ( iLastValidText.Length() )
       
   416                 {
       
   417                 TInt errorCode = RProperty::Set(
       
   418                         KPSUidNetworkInfo,
       
   419                         KNWHomeZoneStatus,
       
   420                         ENWHomeZone );
       
   421                 LOG2( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   422                     show the homezone indicator and return %d", errorCode )
       
   423                 }
       
   424             else 
       
   425                 {
       
   426                 TInt errorCode = RProperty::Set(
       
   427                         KPSUidNetworkInfo,
       
   428                         KNWHomeZoneStatus,
       
   429                         ENWNone );
       
   430                 LOG2( NORMAL, "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler \
       
   431                     remove the homezone indicator and return %d", errorCode )
       
   432                 }
       
   433             }
       
   434         }
       
   435 
       
   436     LOG( SIMPLE,
       
   437         "SETUPIDLEMODETEXT: CSetUpIdleModeTextHandler::HandleCommand exiting" )
       
   438     }
       
   439 
       
   440 // -----------------------------------------------------------------------------
       
   441 // CSetUpIdleModeTextHandler::UiLaunchFailed
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 void CSetUpIdleModeTextHandler::UiLaunchFailed()
       
   445     {
       
   446     LOG( SIMPLE, "SETUPIDLEMODETEXT: \
       
   447         CSetUpIdleModeTextHandler::UiLaunchFailed calling - exiting" )
       
   448     // We don't need UI. This is derived function from CSatSCommandHandler,
       
   449     // so this function must exist, even if it is never called.
       
   450     }