phoneclientserver/phoneserver/src/ussd/cphsrvussdmanager.cpp
changeset 33 8d5d7fcf9b59
child 36 7c428525956b
equal deleted inserted replaced
32:1f002146abb4 33:8d5d7fcf9b59
       
     1 /*
       
     2 * Copyright (c) 2002-2010 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:  USSD Manager.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "cphsrvussdmanager.h" 
       
    20 #include "phsrvutils.h" 
       
    21 #include "cphsrvussdsendhandler.h" 
       
    22 #include "cphsrvussdreceivehandler.h" 
       
    23 #include "cphsrvussdnotifynwrelease.h" 
       
    24 #include "cphsrvresourcemanager.h" 
       
    25 #include "cphsrvussdreplytimer.h" 
       
    26 #include "mphsrvussdmessagesentobserver.h" 
       
    27 #include "mphsrvphoneinterface.h" 
       
    28 #include "cphsrvussdsessioncancelwaiter.h" 
       
    29 
       
    30 #include <apacmdln.h>
       
    31 #include <apgtask.h>
       
    32 #include <bautils.h>
       
    33 #include <textresolver.h>
       
    34 #include <charconv.h>
       
    35 #include <gsmuelem.h>
       
    36 #include <exterror.h>
       
    37 #include <rmmcustomapi.h>
       
    38 
       
    39 #include <w32std.h>
       
    40 #include <apgcli.h>
       
    41 #include <cphcltussd.h> 
       
    42 #include <hbtextresolversymbian.h>
       
    43 #include <phoneserver.rsg> 
       
    44 #include "phsrvdebuginfo.h" 
       
    45 #include <e32property.h>
       
    46 #include <centralrepository.h>
       
    47 #include <coreapplicationuisdomainpskeys.h>
       
    48 
       
    49 
       
    50 // CONSTANTS
       
    51 const TInt KPhSrvDefaultValue = 0x00000000;
       
    52 // See SharedDataKeysVariant.h or NcnListInternalPSKeys.h
       
    53 // const TInt KPhSrvUssdNoTone = 0; 
       
    54 // const TInt KPhSrvUssdTimeOutObserverGranularity = 2;
       
    55 // const TInt KPhSrvUssdSentMessageObserverGranularity = 2;
       
    56 // See KUssdSecureId in phcltclientserver.h
       
    57 //const TInt KPhSrvUssdAppUID = 0x10005955; 
       
    58 
       
    59 const TInt KPhSrvUssdMessageQueryInterval = 500000; // 0.5 sec
       
    60 //const TInt KPhSrvUssdNoteExitPeriod = 500000; // 0.5 sec
       
    61 //
       
    62 const TUint KPhSrvUssdDefaultDCS = 0x0f;                        // 00001111
       
    63 
       
    64 const TUint KPhSrvUssdDcsAlphabetDefaultPrecededLanguage = 0x10;// 00010000
       
    65 const TUint KPhSrvUssdDcsAlphabetDefaultPrecededLanguageSkipChars3 = 3;
       
    66 const TUint KPhSrvUssdDcsAlphabetDefaultPrecededLanguageSkipChars2 = 2;
       
    67 const TUint KPhSrvUssdDcsAlphabetDefaultPrecededLanguageStartBit = 5;
       
    68 
       
    69 const TUint KPhSrvUssdDcsAlphabetUCS2PrecededLanguage = 0x11;   // 00010001
       
    70 const TUint KPhSrvUssdDcsAlphabetUCS2PrecededLanguageSkipChars = 2;
       
    71 
       
    72 const TUint KPhSrvUssdDcsGeneralInformationMask = 0xc0;         // 11000000
       
    73 const TUint KPhSrvUssdDcsGeneralInformation = 0x40;             // 01xxxxxx
       
    74 const TUint KPhSrvUssdDcsGeneralInformationCompressed = 0x20;   // xx1xxxxx
       
    75 const TUint KPhSrvUssdDcsGeneralInformationSimMask = 0x13;      // 00010011
       
    76 const TUint KPhSrvUssdDcsGeneralInformationSim = 0x12;          // xxx1xx10
       
    77 const TUint KPhSrvUssdDcsGeneralInformationAlphabetMask = 0x0c; // 00001100
       
    78 const TUint KPhSrvUssdDcsGeneralInformationAlphabet8Bit = 0x04; // xxxx01xx
       
    79 const TUint KPhSrvUssdDcsGeneralInformationAlphabetUCS2 = 0x08; // xxxx10xx
       
    80 
       
    81 const TUint KPhSrvUssdDcsMessageHandlingAlphabetMask = 0xf4;    // 11110100
       
    82 const TUint KPhSrvUssdDcsMessageHandlingAlphabet8Bit = 0xf4;    // 1111x1xx
       
    83 const TInt KPhrUssdNotifyArraySize = 1;
       
    84 
       
    85 // Refers to HbPopup::NoDismiss = 0
       
    86 const TInt KPhSrvUssdPopupDismissPolicy = 0; 
       
    87 // The time out only for testing, from CPhSrvUssdReplyTimer.cpp
       
    88 const TUint KPhSrvUssdTimeout = 300000000;
       
    89 
       
    90 // Use QT style localization
       
    91 _LIT(KUssdLocFilename, "ussd_");
       
    92 _LIT(KCommonLocFilename, "common_");
       
    93 _LIT(KLocPath, "z:\\resource\\qt\\translations");
       
    94 _LIT(KUssdReply, "txt_ussd_button_reply"); // Reply
       
    95 _LIT(KUssdExit, "txt_ussd_button_exit"); // Exit
       
    96 _LIT(KUssdNext, "txt_ussd_button_next"); //Next
       
    97 _LIT(KUssdYes, "txt_common_button_yes"); // Yes
       
    98 _LIT(KUssdNo, "txt_common_button_no"); // No
       
    99 _LIT(KUssdTitle, "txt_ussd_title_message"); // Message
       
   100 _LIT(KUssdDone, "txt_ussd_dpopinfo_done"); // Done
       
   101 _LIT(KUssdConfirm, "txt_ussd_info_there_are_still_unread_notifications");
       
   102 
       
   103 // MACROS
       
   104 
       
   105 #define _DPRINT_FLAGS() \
       
   106     _DDPRINT( 4, "PhSrv.FLAGS.MsgTypeReply ", iMsgTypeReply ); \
       
   107     _DDPRINT( 4, "PhSrv.FLAGS.NwReleased   ", iNetworkReleased ); \
       
   108     _DDPRINT( 4, "PhSrv.FLAGS.SendingAck   ", iSendingAck ); \
       
   109     _DDPRINT( 4, "PhSrv.FLAGS.AcksToBeSent ", iAcksToBeSent ); \
       
   110     _DDPRINT( 4, "PhSrv.FLAGS.iSendRelease ", iSendRelease ); \
       
   111     _DDPRINT( 4, "PhSrv.FLAGS.iClearArray  ", iClearArray ); \
       
   112     _DDPRINT( 4, "PhSrv.FLAGS.iLaunchGMQ   ", iLaunchGMQ ); \
       
   113     _DDPRINT( 4, "PhSrv.FLAGS.NotifyCount  ", NotifyCount() ); \
       
   114     _DDPRINT( 4, "PhSrv.FLAGS.iShowDone    ", iShowDone ); 
       
   115 
       
   116 // ============================= LOCAL FUNCTIONS ===============================
       
   117 
       
   118 // CLASS DECLARATION
       
   119 
       
   120 #ifndef TPHSRVUSSDALPHABETPACKER_H
       
   121 #define TPHSRVUSSDALPHABETPACKER_H
       
   122 
       
   123 // CONSTANTS
       
   124 const TUint8 KPhSrvUssdCarriageReturn = 0x0d;
       
   125 
       
   126 /**
       
   127 *  Packs and unpacks data encoded in an Ussd alphabet.
       
   128 *
       
   129 *  @since 1.0
       
   130 */
       
   131 class TPhSrvUssdAlphabetPacker
       
   132     {
       
   133     public:  // Constructors and destructor
       
   134 
       
   135         /**
       
   136         * Constructor.
       
   137         *
       
   138         * @param aAlphabet The alphabet that is used.
       
   139         * @param aIsBinary Is the data binary, that will be converted.
       
   140         * @param aStartBit The start bit for conversion.
       
   141         */
       
   142         TPhSrvUssdAlphabetPacker(
       
   143             TSmsDataCodingScheme::TSmsAlphabet aAlphabet,
       
   144             TBool aIsBinary,
       
   145             TInt aStartBit );
       
   146 
       
   147 
       
   148     public: // New functions
       
   149 
       
   150         /**
       
   151         * Unpacks 7-bit buffer to 8-bit buffer.
       
   152         *
       
   153         * @param aIn Descriptor where the 7-bit buffer is.
       
   154         * @param aOut 8-bit buffer to set the result.
       
   155         * @param aNumUDUnits Buffer length.
       
   156         * @return Length of the result buffer.
       
   157         */
       
   158         TInt UnpackL(
       
   159             const TDesC8& aIn,
       
   160             TDes8& aOut,
       
   161             TInt aNumUDUnits );
       
   162 
       
   163         /**
       
   164         * Unpacks 7-bit buffer to 8-bit and converts to unicode.
       
   165         *
       
   166         * @param aCharacterSetConverter Does the converting.
       
   167         * @param aFs File server session.
       
   168         * @param aIn Packed 7-bit buffer.
       
   169         * @param aOut Unicode buffer.
       
   170         * @param aNumUDUnits Number of charahters.
       
   171         * @return Number of used octets in 8-bit buffer.
       
   172         */
       
   173         TInt UnpackAndConvertL(
       
   174             CCnvCharacterSetConverter& aCharacterSetConverter,
       
   175             RFs& aFs,
       
   176             const TDesC8& aIn,
       
   177             TDes& aOut,
       
   178             TInt aNumUDUnits );
       
   179 
       
   180         /**
       
   181         * Counts the needed octet amout.
       
   182         *
       
   183         * @param aNumUDUnits Number of source characters.
       
   184         * @return Octets needed.
       
   185         */
       
   186         TInt PackedOctetsRequiredL( TInt aNumUDUnits ) const;
       
   187 
       
   188 
       
   189     private:
       
   190 
       
   191         // Private helper methods
       
   192         TInt ElementSizeInBitsL() const;
       
   193 
       
   194 
       
   195     private:    // Data
       
   196 
       
   197         // The used coding alphabet.
       
   198         TSmsDataCodingScheme::TSmsAlphabet iAlphabet;
       
   199 
       
   200         // Is the packed data binary.
       
   201         TBool iIsBinary;
       
   202 
       
   203         // The start bit for packing.
       
   204         TInt iStartBit;
       
   205     };
       
   206 
       
   207 #endif // TPHSRVUSSDALPHABETPACKER_H
       
   208 
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // TPhSrvUssdAlphabetPacker::TPhSrvUssdAlphabetPacker
       
   212 // Constructor.
       
   213 //
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 TPhSrvUssdAlphabetPacker::TPhSrvUssdAlphabetPacker(
       
   217     TSmsDataCodingScheme::TSmsAlphabet aAlphabet,
       
   218     TBool aIsBinary,
       
   219     TInt aStartBit)
       
   220     : iAlphabet( aAlphabet ),iIsBinary( aIsBinary ),iStartBit( aStartBit )
       
   221     {
       
   222     }
       
   223 
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // TPhSrvUssdAlphabetPacker::UnpackL
       
   227 // Unpacks user data units from aIn and appends to aOut.
       
   228 //
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 TInt TPhSrvUssdAlphabetPacker::UnpackL(
       
   232     const TDesC8& aIn,
       
   233     TDes8& aOut,
       
   234     TInt aNumUDUnits )
       
   235     {
       
   236     TInt length = aNumUDUnits;
       
   237     // Ensure we've got enough  output buffer
       
   238     if ( aOut.Length() + length > aOut.MaxLength() )
       
   239         {
       
   240         User::Leave(KErrCorrupt);
       
   241         }
       
   242 
       
   243     TInt elementSizeInBits = ElementSizeInBitsL();
       
   244     if ( elementSizeInBits == 8 ) // 8-bit data?
       
   245         {
       
   246         aOut.Append( aIn );
       
   247         }
       
   248     else if ( elementSizeInBits == 7 ) // need unpacking from 7-bit data
       
   249         {
       
   250         // Get raw pointers and do unpacking
       
   251         TUint8* outPtr = ( TUint8* )aOut.Ptr() + aOut.Length();
       
   252         const TUint8* inPtr = aIn.Ptr();
       
   253 
       
   254         for ( TInt i = 0; i < length; i++ )
       
   255             {
       
   256             TInt from = ( *inPtr >> iStartBit ) & 0x7F; // Take seven bits
       
   257             if ( iStartBit )
       
   258                 {
       
   259                 inPtr++;
       
   260                 // Take more from next byte
       
   261                 from |= ( *inPtr << ( 8 - iStartBit ) ) & 0x7F;
       
   262                 }
       
   263             outPtr[i] = ( TUint8 ) from;
       
   264             iStartBit = ( iStartBit + 7 ) % 8; // roll: 0,1,2,...,6,7,0,1,2...
       
   265             }
       
   266 
       
   267         // The last character will be ignored if message ends
       
   268         // on an octet bounday with CR.
       
   269         if ( outPtr[ length-1 ] == KPhSrvUssdCarriageReturn && iStartBit == 0 )
       
   270             {
       
   271             length--;
       
   272             }
       
   273         aOut.SetLength( aOut.Length() + length );
       
   274         }
       
   275     else
       
   276         {
       
   277         __ASSERT_DEBUG(EFalse,
       
   278             PhoneServerUtils::Panic( EPhoneServerPanicModeLogicFault ) );
       
   279         }
       
   280     return length;
       
   281     }
       
   282 
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // TPhSrvUssdAlphabetPacker::UnpackAndConvertL
       
   286 // Unpacks the converts the input data, aIn, and appends to aOut
       
   287 //
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 TInt TPhSrvUssdAlphabetPacker::UnpackAndConvertL(
       
   291     CCnvCharacterSetConverter& aCharacterSetConverter,
       
   292     RFs& aFs,
       
   293     const TDesC8& aIn,
       
   294     TDes& aOut,
       
   295     TInt aNumUDUnits )
       
   296     {
       
   297 
       
   298     // Unpack first
       
   299     HBufC8* unpackedBuffer = HBufC8::NewLC( aNumUDUnits );
       
   300     TPtr8 unpackedBufferPtr( unpackedBuffer->Des() );
       
   301     UnpackL( aIn, unpackedBufferPtr,aNumUDUnits );
       
   302 
       
   303     // Convert
       
   304     CSmsAlphabetConverter* converter =
       
   305         CSmsAlphabetConverter::NewLC(
       
   306             aCharacterSetConverter, aFs, iAlphabet, iIsBinary );
       
   307 
       
   308     TPtrC convertedPtr = converter->ConvertToNativeL( *unpackedBuffer );
       
   309     if ( convertedPtr.Length() > ( aOut.MaxLength() - aOut.Length() ) )
       
   310         {
       
   311         User::Leave( KErrCorrupt );
       
   312         }
       
   313     // Cleanup and return
       
   314     aOut.Append( convertedPtr );
       
   315     CleanupStack::PopAndDestroy( 2 );    // unpackedBuffer, converter
       
   316     return aNumUDUnits;
       
   317     }
       
   318 
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // TPhSrvUssdAlphabetPacker::PackedOctetsRequiredL
       
   322 // Returns the number of octets needed to pack the specified number of
       
   323 //
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 TInt TPhSrvUssdAlphabetPacker::PackedOctetsRequiredL( TInt aNumUDUnits ) const
       
   327 
       
   328     {
       
   329     TInt octetsRequired = 0;
       
   330     TInt elementSizeInBits = ElementSizeInBitsL();
       
   331     if ( elementSizeInBits == 8 )
       
   332         {
       
   333         octetsRequired=aNumUDUnits;
       
   334         }
       
   335     else
       
   336         {
       
   337         octetsRequired =
       
   338             ( iStartBit+aNumUDUnits * elementSizeInBits + 7 ) / 8;  // Rounds up
       
   339         }
       
   340     return octetsRequired;
       
   341     }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // TPhSrvUssdAlphabetPacker::ElementSizeInBitsL
       
   345 // Returns the size in bits of a UDL element for the alphabet.  Leaves if
       
   346 // invalid data coding scheme.
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 TInt TPhSrvUssdAlphabetPacker::ElementSizeInBitsL() const
       
   350     {
       
   351     if (iIsBinary)
       
   352         return 8;
       
   353     switch ( iAlphabet )
       
   354         {
       
   355         case TSmsDataCodingScheme::ESmsAlphabet7Bit:
       
   356             {
       
   357             return 7;
       
   358             }
       
   359         case TSmsDataCodingScheme::ESmsAlphabet8Bit:
       
   360         case TSmsDataCodingScheme::ESmsAlphabetUCS2:
       
   361             {
       
   362             return 8;
       
   363             }
       
   364         default:
       
   365             {
       
   366             User::Leave(KErrGsmSMSDataCodingSchemeNotSupported);
       
   367             return 8;
       
   368             }
       
   369         }
       
   370     }
       
   371 
       
   372 
       
   373 
       
   374 // ============================ MEMBER FUNCTIONS ===============================
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CPhSrvUssdManager::CPhSrvUssdManager
       
   378 //
       
   379 // Constructor
       
   380 //
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 CPhSrvUssdManager::CPhSrvUssdManager(
       
   384     RFs& aFsSession,
       
   385     CPhSrvResourceManager& aResourceManager
       
   386     )
       
   387     :CActive( EPriorityLow ),
       
   388      iFsSession( aFsSession ),
       
   389      iResourceManager( aResourceManager ),
       
   390      iDeviceDialog( NULL ),
       
   391      iDCS ( KPhCltDcsUnknown ),
       
   392      iReturnResultPckg ( iReturnResult ),
       
   393      iTextBuffer ( NULL )
       
   394     {
       
   395     CActiveScheduler::Add( this );
       
   396     }
       
   397 
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CPhSrvUssdManager::~CPhSrvUssdManager
       
   401 //
       
   402 // Destructor
       
   403 //
       
   404 // -----------------------------------------------------------------------------
       
   405 //
       
   406 CPhSrvUssdManager::~CPhSrvUssdManager()
       
   407     {
       
   408     _DPRINT( 4, "PhSrv.~CPhSrvUssdManager.start" );
       
   409 
       
   410 
       
   411     delete iUssdSendHandler;
       
   412     iUssdSendHandler = NULL;
       
   413 
       
   414     delete iUssdReceiveHandler;
       
   415     iUssdReceiveHandler = NULL;
       
   416 
       
   417     delete iUssdNotifyNWRelease;
       
   418     iUssdNotifyNWRelease = NULL;
       
   419 
       
   420     Cancel();
       
   421 
       
   422     iTimer.Close();
       
   423     
       
   424     delete iTextBuffer;
       
   425     iTextBuffer = NULL;
       
   426     
       
   427     delete iDeviceDialog;
       
   428     iDeviceDialog = NULL;
       
   429 
       
   430     if ( iNotifyArray )
       
   431         {
       
   432         iNotifyArray->Reset();
       
   433         }
       
   434     delete iNotifyArray;
       
   435     if ( iUssdReplyTimer )
       
   436         {
       
   437         iUssdReplyTimer->Stop();
       
   438         }
       
   439     delete iUssdReplyTimer;
       
   440     iUssdReplyTimer = NULL;
       
   441 
       
   442     iFsSession.Close();
       
   443 
       
   444     iMobileUssdMessaging.Close();
       
   445     
       
   446     delete iMoAckCallback;
       
   447 
       
   448     _DPRINT( 4, "PhSrv.~CPhSrvUssdManager.end" );
       
   449     }
       
   450 
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // CPhSrvUssdManager::ConstructL
       
   454 //
       
   455 // Symbian OS 2nd phase constructor
       
   456 //
       
   457 // -----------------------------------------------------------------------------
       
   458 //
       
   459 void CPhSrvUssdManager::ConstructL( MPhSrvPhoneInterface& aPhoneInterface )
       
   460     {
       
   461     _DPRINT( 4, "PhSrv.ConstructL.Start" );
       
   462     const TBool textResolver = HbTextResolverSymbian::Init( 
       
   463         KUssdLocFilename, KLocPath );
       
   464     _DDPRINT( 4, "PhSrv.ConstructL.ussd loc:", textResolver );
       
   465     User::LeaveIfError( iTimer.CreateLocal() );
       
   466 
       
   467     User::LeaveIfError( iMobileUssdMessaging.Open( aPhoneInterface.PhSrvMobilePhone() ) );
       
   468 
       
   469     // Check support
       
   470     RMobileUssdMessaging::TMobileUssdCapsV1 caps;
       
   471     RMobileUssdMessaging::TMobileUssdCapsV1Pckg pckgCaps( caps );
       
   472     User::LeaveIfError( iMobileUssdMessaging.GetCaps( pckgCaps ) );
       
   473 
       
   474     if ( !( ( caps.iUssdTypes & RMobileUssdMessaging::KCapsMTUssd ) == 0 &&
       
   475         ( caps.iUssdFormat & RMobileUssdMessaging::KCapsPackedString ) == 0 ) )
       
   476         {
       
   477         _DPRINT( 4, "PhSrv.CPhSrvUssdManager::ConstructL" );
       
   478         iUssdReceiveHandler = new( ELeave ) CPhSrvUssdReceiveHandler(
       
   479             *this,
       
   480             iMobileUssdMessaging );
       
   481         iUssdReceiveHandler->ConstructL();
       
   482 
       
   483         iUssdNotifyNWRelease = new( ELeave )  CPhSrvUssdNotifyNWRelease(
       
   484             *this,
       
   485             iMobileUssdMessaging );
       
   486 
       
   487         iUssdNotifyNWRelease->ConstructL();
       
   488         }
       
   489 
       
   490     iPhoneInterface = &aPhoneInterface;
       
   491 
       
   492     SendHandlerL();
       
   493     
       
   494     iMoAckCallback = new (ELeave) CAsyncCallBack( TCallBack( MoAckCallback, this ), CActive::EPriorityIdle );
       
   495 
       
   496     iVariantReadOnlyValues = KPhSrvDefaultValue;
       
   497 
       
   498     User::LeaveIfError( GetTelephonyVariantData() );
       
   499 
       
   500     _DDPRINT( 4, "PhSrv.ConstructL.iSatCanceled ", iSatCanceled );
       
   501     _DDPRINT( 4, "PhSrv.ConstructL.iShowDone ", iShowDone );
       
   502     iNotifyArray = new( ELeave ) CDesCArrayFlat( KPhrUssdNotifyArraySize );
       
   503     _DPRINT( 4, "PhSrv.ConstructL.End" );
       
   504     }
       
   505 
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // CPhSrvUssdManager::SendHandlerL
       
   509 //
       
   510 // The send handler.
       
   511 //
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 CPhSrvUssdSendHandler& CPhSrvUssdManager::SendHandlerL()
       
   515     {
       
   516     // If SendHandler is not created, first check that MO Ussd
       
   517     // is supported by the TSY.
       
   518     _DPRINT( 4, "PhSrv.SendHandlerL.Start" );
       
   519     if ( iUssdSendHandler == NULL )
       
   520         {
       
   521         _DPRINT( 4, "PhSrv.SendHandlerL.iUssdSendHandler.NULL" );
       
   522         RMobileUssdMessaging::TMobileUssdCapsV1 caps;
       
   523         RMobileUssdMessaging::TMobileUssdCapsV1Pckg pckgCaps( caps );
       
   524         User::LeaveIfError( iMobileUssdMessaging.GetCaps( pckgCaps ) );
       
   525         _DPRINT( 4, "PhSrv.SendHandlerL.iMobileUssdMessaging.GetCaps" );
       
   526 
       
   527         if ( ( caps.iUssdTypes & RMobileUssdMessaging::KCapsMOUssd ) == 0 ||
       
   528             ( caps.iUssdFormat & RMobileUssdMessaging::KCapsPackedString )
       
   529             == 0 )
       
   530             {
       
   531             _DPRINT( 4, "PhSrv.SendHandlerL.KErrNotSupported" );
       
   532             User::Leave( KErrNotSupported );
       
   533             }
       
   534 
       
   535         iUssdSendHandler =
       
   536             new( ELeave ) CPhSrvUssdSendHandler(
       
   537                 *this,
       
   538                 iMobileUssdMessaging,
       
   539                 *iPhoneInterface );
       
   540         }
       
   541     _DPRINT( 4, "PhSrv.SendHandlerL.End" );
       
   542     return *iUssdSendHandler;
       
   543     }
       
   544 
       
   545 
       
   546 // -----------------------------------------------------------------------------
       
   547 // CPhSrvUssdManager::SendUssdL
       
   548 //
       
   549 // Send the USSD message.
       
   550 //
       
   551 // -----------------------------------------------------------------------------
       
   552 //
       
   553 void CPhSrvUssdManager::SendUssdL(
       
   554     const TDesC8& aMsgData,
       
   555     RMobileUssdMessaging::TMobileUssdAttributesV1& aMsgAttribute,
       
   556     MPhSrvUssdMessageSentObserver& aObserver )
       
   557     {
       
   558     _DPRINT( 4, "PhSrv.SendUssdL.Start ######" );
       
   559     _DPRINT_FLAGS();
       
   560     
       
   561     if ( iObserver && iNetworkReleased ) 
       
   562         {
       
   563         // Network has been released but the previous send request is still alive.
       
   564         // Cancel the pervious send operation, complete the old request with error
       
   565         // and clean up the pointer.
       
   566         _DPRINT( 4, "PhSrv.SendUssdL.Error.Complete.Existing" );
       
   567         if ( iUssdSendHandler ) 
       
   568             {
       
   569             iUssdSendHandler->Cancel();
       
   570             }
       
   571         iObserver->UssdMessageSentObserverHandleResult( KErrSessionClosed );
       
   572         iObserver = NULL;
       
   573         }
       
   574     
       
   575     if ( iObserver || iSendingAck )
       
   576         {
       
   577         _DPRINT( 4, "PhSrv.SendUssdL.KErrInUse" );
       
   578         // Other client is using the service.
       
   579         User::Leave( KErrInUse );
       
   580         }
       
   581 
       
   582     // Check that message type is set
       
   583     if( ( aMsgAttribute.iFlags & RMobileUssdMessaging::KUssdMessageType )
       
   584         == 0 )
       
   585         _DPRINT( 4, "PhSrv.SendUssdL.KUssdMessageType.0" );
       
   586         {
       
   587         // Mesasge type not set -> Set it.
       
   588         aMsgAttribute.iFlags |= RMobileUssdMessaging::KUssdMessageType;
       
   589         if ( NetworkWaitingForAnAnswer() )
       
   590             {
       
   591             // Network is waiting for an answer
       
   592             _DPRINT( 4, "PhSrv.SendUssdL.EUssdMOReply" );   // debug print
       
   593             aMsgAttribute.iType = RMobileUssdMessaging::EUssdMOReply;
       
   594             }
       
   595         else
       
   596             {
       
   597             _DPRINT( 4, "PhSrv.SendUssdL.EUssdMORequest" );  // debug print
       
   598             aMsgAttribute.iType = RMobileUssdMessaging::EUssdMORequest;
       
   599             }
       
   600         }
       
   601         
       
   602     RMobileUssdMessaging::TMobileUssdAttributesV1Pckg attribs( aMsgAttribute );
       
   603     iShowDone = ETrue;
       
   604     _DPRINT( 4, "PhSrv.SendUssdL.iShowDone.ETrue" );
       
   605     _DPRINT( 4, "PhSrv.SendUssdL.Send" );
       
   606     SendHandlerL().SendUssdL( aMsgData , attribs );
       
   607     iObserver = &aObserver;
       
   608     // Not closing nor closed anymore
       
   609     iNetworkReleased = EFalse;
       
   610     iSendRelease = EFalse;
       
   611     iClearArray = EFalse;
       
   612     
       
   613     // Reply timer can be killed here... Receive event might come right after this
       
   614     // which will setup the timer again if needed.
       
   615     if ( NetworkWaitingForAnAnswer() )
       
   616         {
       
   617         _DPRINT( 4, "PhSrv.SendUssdCancel.TimerStop" );   // debug print
       
   618         iUssdReplyTimer->Stop();
       
   619         }
       
   620     _DPRINT( 4, "PhSrv.SendUssdL.End" );
       
   621     }
       
   622 
       
   623 // -----------------------------------------------------------------------------
       
   624 // CPhSrvUssdManager::NetworkWaitingForAnAnswer
       
   625 // -----------------------------------------------------------------------------
       
   626 //
       
   627 TBool CPhSrvUssdManager::NetworkWaitingForAnAnswer() 
       
   628     {
       
   629     return iUssdReplyTimer && iUssdReplyTimer->IsTimerActive();
       
   630     }
       
   631 // -----------------------------------------------------------------------------
       
   632 // CPhSrvUssdManager::SendUssdCancel
       
   633 //
       
   634 // Cancel the USSD sending.
       
   635 //
       
   636 // -----------------------------------------------------------------------------
       
   637 //
       
   638 void CPhSrvUssdManager::SendUssdCancel()
       
   639     {
       
   640     _DPRINT( 4, "PhSrv.SendUssdCancel.Start #######" );
       
   641 
       
   642     // Ack sending should not be canceled unless it's about terminating
       
   643     // the whole session
       
   644     _DPRINT_FLAGS();
       
   645     if ( !iSendingAck || iSendRelease ) 
       
   646         {
       
   647         _DPRINT( 4, "PhSrv.SendUssdCancel.DoingCancel" );
       
   648         iUssdSendHandler->SendUssdCancel();
       
   649         }
       
   650 
       
   651     if ( iHavePendingSatMessagePointer )
       
   652         {
       
   653         _DPRINT( 4, "PhSrv.SendUssdCancel.SatCancel" );
       
   654         iSatCanceled = ETrue;
       
   655         }
       
   656     iObserver = NULL;
       
   657     
       
   658     SetActiveIfPendingNotificationsExist();
       
   659     _DPRINT( 4, "PhSrv.SendUssdCancel.End" );
       
   660     }
       
   661 
       
   662 // -----------------------------------------------------------------------------
       
   663 // CPhSrvUssdManager::SetActiveIfPendingNotificationsExist
       
   664 // -----------------------------------------------------------------------------
       
   665 //
       
   666 void CPhSrvUssdManager::SetActiveIfPendingNotificationsExist()
       
   667     {
       
   668     if ( !IsActive() && NotifyCount() > 0 )
       
   669         {
       
   670         _DPRINT( 4, "PhSrv.AcrtivateIf.NotActiveSelf" );
       
   671         iLaunchGMQ = ETrue;
       
   672         iNotifyMessage = ETrue;
       
   673         _DPRINT( 4, "PhSrv.SendUssdCancel.iNotifyMessage.ETrue" );
       
   674         iTimer.After( iStatus , KPhSrvUssdMessageQueryInterval );
       
   675         SetActive();
       
   676         _DPRINT_FLAGS();
       
   677         _DDPRINT( 4, "PhSrv.AcrtivateIf.SetActive ", iStatus.Int() );
       
   678         }
       
   679     }
       
   680 // -----------------------------------------------------------------------------
       
   681 // CPhSrvUssdManager::UssdNetworkObserverHandleSendEventL
       
   682 //
       
   683 //
       
   684 //
       
   685 // -----------------------------------------------------------------------------
       
   686 //
       
   687 void CPhSrvUssdManager::UssdNetworkObserverHandleSendEventL( TInt aError )
       
   688     {
       
   689     // debug print
       
   690     _DDPRINT(
       
   691         4,
       
   692         "PhSrv.UssdNetworkObserverHandleSendEventL.Start: ##### ",
       
   693         aError );
       
   694 
       
   695     // complete SAT if needed
       
   696     if ( aError < KErrNone )
       
   697         {
       
   698  
       
   699         _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleSendEventL.CompleteSat" );
       
   700         CompleteSatL( NULL, aError );
       
   701         }
       
   702 
       
   703     if ( iObserver )
       
   704         {
       
   705  
       
   706         _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleSendEventL.Observer" );
       
   707 
       
   708         iObserver->UssdMessageSentObserverHandleResult( aError );
       
   709         iObserver = NULL;
       
   710         }
       
   711     
       
   712     iSendingAck = EFalse;
       
   713     
       
   714     AsyncProcessMoAcks();
       
   715     
       
   716     // debug print
       
   717     _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleSendEventL.End" );
       
   718     }
       
   719 
       
   720 
       
   721 // -----------------------------------------------------------------------------
       
   722 // CPhSrvUssdManager::UssdAppTaskExists
       
   723 //
       
   724 //
       
   725 //
       
   726 // -----------------------------------------------------------------------------
       
   727 //
       
   728 TBool CPhSrvUssdManager::UssdAppTaskExistsL()
       
   729 {   
       
   730     TBool ret = EFalse;
       
   731     RWsSession wsSession;
       
   732     User::LeaveIfError(wsSession.Connect());
       
   733     _DPRINT( 4, "PhSrv.UssdAppTaskExists.wsSession.Connect" );
       
   734     CleanupClosePushL(wsSession);
       
   735     TApaTaskList tasklist(wsSession);
       
   736     TApaTask task = tasklist.FindApp( KUssdSecureId );
       
   737     ret = task.Exists();
       
   738 
       
   739     CleanupStack::PopAndDestroy();
       
   740     return ret;
       
   741 }
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 // CPhSrvUssdManager::UssdNetworkObserverHandleReceivedEventL
       
   745 //
       
   746 //
       
   747 //
       
   748 // -----------------------------------------------------------------------------
       
   749 //
       
   750 void CPhSrvUssdManager::UssdNetworkObserverHandleReceivedEventL(
       
   751     const TDes8& aMsgData,
       
   752     const RMobileUssdMessaging::TMobileUssdAttributesV1& aMsgAttributes,
       
   753     TInt aError )
       
   754     {
       
   755     _DDPRINT(
       
   756         4,
       
   757         "PhSrv.UssdNetworkObserverHandleReceivedEventL.Start: ### ",
       
   758         aError );
       
   759     _DPRINT_FLAGS();
       
   760     if ( aError != KErrNone )
       
   761         {
       
   762         TurnLightsOn(); //Ensure lights on
       
   763  
       
   764         _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleReceivedEventL.ShErNote" );
       
   765         ShowErrorNoteL( aError );
       
   766         }
       
   767     else if ( iSendRelease )
       
   768         {
       
   769         // Ignore if sendrelease is to be done. If the message was
       
   770         _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleReceivedEventL.SendRelease.Ignore" );
       
   771         }
       
   772     else
       
   773         {
       
   774         UssdHandleReceivedEventL( aMsgData, aMsgAttributes );
       
   775         }
       
   776     }
       
   777 
       
   778 // -----------------------------------------------------------------------------
       
   779 // CPhSrvUssdManager::UssdHandleReceivedEventL
       
   780 // -----------------------------------------------------------------------------
       
   781 //
       
   782 void CPhSrvUssdManager::UssdHandleReceivedEventL(
       
   783     const TDes8& aMsgData,
       
   784     const RMobileUssdMessaging::TMobileUssdAttributesV1& aMsgAttributes )
       
   785     {
       
   786     // This always is either ongoing transaction or starting a new based
       
   787     // on incoming message, mark transaction to be open.
       
   788     iNetworkReleased = EFalse;
       
   789         
       
   790     // 2. Complete Send with some positive value.
       
   791     if ( iObserver )
       
   792         {
       
   793  
       
   794         _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.Observer" );
       
   795         UssdNetworkObserverHandleSendEventL( 1 ); // some positive value
       
   796         }
       
   797     
       
   798     if ( aMsgAttributes.iFlags&RMobileUssdMessaging::KUssdMessageType &&
       
   799          aMsgAttributes.iType == RMobileUssdMessaging::EUssdMTRequest )
       
   800         {
       
   801         // 3. Stop old reply timer and start new one if needed.
       
   802         RestartReplyTimerL();
       
   803         _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleReceivedEventL.Timer.Stop" );
       
   804         _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleReceivedEventL.Timer.New" );
       
   805         }
       
   806     _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.Decode" );
       
   807     TUint8 dcs = KPhSrvUssdDefaultDCS;
       
   808     if(aMsgAttributes.iFlags & RMobileUssdMessaging::KUssdMessageDcs)
       
   809         {
       
   810         dcs = aMsgAttributes.iDcs;
       
   811         }
       
   812     iDecodedMessage.Zero();
       
   813     iReceivedMessage.Zero();
       
   814     DecodeL(aMsgData, iDecodedMessage, dcs);
       
   815     if(iDecodedMessage.Length() > 0)
       
   816         {
       
   817         iReceivedMessage = iDecodedMessage;
       
   818         }
       
   819     // 5. Show note.
       
   820     // debug print
       
   821     _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.Note" );
       
   822     if ( !( aMsgAttributes.iFlags & RMobileUssdMessaging::KUssdMessageType ) ||
       
   823             aMsgAttributes.iType != RMobileUssdMessaging::EUssdMTRequest )
       
   824         {
       
   825         if ( !ShowNotesL() )
       
   826             {
       
   827      
       
   828             _DPRINT( 4,
       
   829                 "PhSrv.UssdHandleReceivedEventL.SAtReturn" );
       
   830             return;
       
   831             }
       
   832         }
       
   833 
       
   834     // empty string is handled as ok message
       
   835     if ( !iDecodedMessage.Length() )
       
   836         {
       
   837         TurnLightsOn(); //Ensure lights on
       
   838  
       
   839         _DPRINT( 4,
       
   840             "PhSrv.UssdHandleReceivedEventL.EmptyString" );
       
   841         
       
   842         ShowDoneNoteL();
       
   843 
       
   844  
       
   845         _DPRINT( 4,
       
   846             "PhSrv.UssdHandleReceivedEventL.EmptyString.OK" );
       
   847         }
       
   848     else
       
   849         {
       
   850         _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.String" );
       
   851         iNotifyMessage = ( aMsgAttributes.iType == RMobileUssdMessaging::EUssdMTNotify );
       
   852         _DDPRINT( 4, "PhSrv.UssdHandleReceivedEventL.iNotifyMessage: ", iNotifyMessage );
       
   853         _DDPRINT( 4, "PhSrv.UssdNOHREventL.iNotifyMessage: ", iNotifyMessage );
       
   854         iMsgTypeReply = ( aMsgAttributes.iType == RMobileUssdMessaging::EUssdMTReply );
       
   855         _DDPRINT( 4, "PhSrv.UssdHandleReceivedEventL.iMsgTypeReply: ", iMsgTypeReply );
       
   856         
       
   857         if ( iNotifyMessage ) 
       
   858             {
       
   859             // need to send an MO ack
       
   860             iAcksToBeSent ++;
       
   861             }
       
   862         
       
   863         if ( !iDeviceDialog  ){
       
   864             iDeviceDialog = CHbDeviceMessageBoxSymbian::NewL(
       
   865                 CHbDeviceMessageBoxSymbian::EInformation );
       
   866             iDeviceDialog->SetObserver( this );
       
   867             iDeviceDialog->SetTimeout( KPhSrvUssdTimeout );
       
   868             iDeviceDialog->SetDismissPolicy ( KPhSrvUssdPopupDismissPolicy );
       
   869             
       
   870             // Show left key with empty string accoring to ui concept
       
   871             iDeviceDialog->SetButton( 
       
   872                 CHbDeviceMessageBoxSymbian::EAcceptButton, EFalse );
       
   873             // Show Exit Key always
       
   874             iDeviceDialog->SetButton( 
       
   875                 CHbDeviceMessageBoxSymbian::ERejectButton, ETrue );
       
   876             iDeviceDialog->SetButtonTextL(
       
   877                 CHbDeviceMessageBoxSymbian::ERejectButton, 
       
   878                 LoadDefaultString( KUssdExit ) );
       
   879             _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.Exit" );             
       
   880         }
       
   881       
       
   882         if ( iNotifyMessage || iMsgTypeReply )
       
   883             {
       
   884             //This is for reply message in notifyarray
       
   885             iNotifyMessage = ETrue;
       
   886             _DDPRINT( 4, "PhSrv.UssdHandleReceivedEventL.iNotifyMessage: ", iNotifyMessage );
       
   887 
       
   888             //Notify added to array
       
   889             iNotifyArray->AppendL( iReceivedMessage );
       
   890 
       
   891             _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.AppendL" );
       
   892             UpdateNotifyMessageL();
       
   893 
       
   894             if ( !iSendRelease && NotifyCount() <= 1 )
       
   895                 {
       
   896                 _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.!SendRelease.Cancel" );
       
   897                 Cancel();
       
   898                 }
       
   899             }
       
   900         else
       
   901             {
       
   902             // New message deletes old message, i.e. Cancel existing query.
       
   903             Cancel();
       
   904             _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.NewAnswerable" );
       
   905             }
       
   906 
       
   907         // Remove Reply key
       
   908         if( !( aMsgAttributes.iFlags & RMobileUssdMessaging::KUssdMessageType )
       
   909              || aMsgAttributes.iType != RMobileUssdMessaging::EUssdMTRequest )
       
   910             {
       
   911             // Remove Answer key
       
   912             iDeviceDialog->SetButton( 
       
   913                 CHbDeviceMessageBoxSymbian::EAcceptButton, EFalse );
       
   914             _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.NoAnswer" ); 
       
   915             }
       
   916         // Show Reply key
       
   917         else
       
   918             {
       
   919             iDeviceDialog->SetButton( 
       
   920                 CHbDeviceMessageBoxSymbian::EAcceptButton, ETrue );              
       
   921             iDeviceDialog->SetButtonTextL(
       
   922                 CHbDeviceMessageBoxSymbian::EAcceptButton, 
       
   923                 LoadDefaultString( KUssdReply ) ); 
       
   924             _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.WithAnswer" ); 
       
   925             }
       
   926 
       
   927  
       
   928         _DPRINT( 4,
       
   929             "PhSrv.UssdHandleReceivedEventL.String.Middle" );
       
   930 
       
   931         // Play the USSD tone if needed. Logically should be in RunL, but here
       
   932         // to give better balancing with voice and visible message.
       
   933         // <-- QT PHONE START-->
       
   934         /*
       
   935         if ( IsTelephonyFeatureSupported( KTelephonyLVFlagUssdTone ) )
       
   936             {
       
   937             _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.PlayTone" );
       
   938             PlayUssdTone();
       
   939             }
       
   940         */
       
   941             // <-- QT PHONE END-->
       
   942         // Launch the new message query
       
   943         if ( !IsActive() )
       
   944             {
       
   945             iLaunchGMQ = ETrue;
       
   946             iTimer.After( iStatus , KPhSrvUssdMessageQueryInterval );
       
   947             SetActive();
       
   948             }
       
   949         AsyncProcessMoAcks();
       
   950         }
       
   951     _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.Editor" );
       
   952     if( aMsgAttributes.iType == RMobileUssdMessaging::EUssdMTRequest && UssdAppTaskExistsL() )
       
   953         {
       
   954         iEmptyEditor = ETrue;
       
   955         }
       
   956     _DPRINT( 4, "PhSrv.UssdHandleReceivedEventL.End" );
       
   957     }
       
   958 
       
   959 // -----------------------------------------------------------------------------
       
   960 // CPhSrvUssdManager::RestartReplyTimerL
       
   961 //
       
   962 //
       
   963 //
       
   964 // -----------------------------------------------------------------------------
       
   965 //
       
   966 void CPhSrvUssdManager::RestartReplyTimerL()
       
   967     {
       
   968     if ( iUssdReplyTimer )
       
   969         {
       
   970         _DPRINT( 4, "PhSrv.RestartReplyTimerL.Stop" );
       
   971         iUssdReplyTimer->Stop();
       
   972         }
       
   973 
       
   974     if ( !iUssdReplyTimer )
       
   975         {
       
   976         _DPRINT( 4, "PhSrv.RestartReplyTimerL.New" );
       
   977         iUssdReplyTimer = CPhSrvUssdReplyTimer::NewL( *this );
       
   978         }
       
   979     
       
   980     _DPRINT( 4, "PhSrv.RestartReplyTimerL.Start" );
       
   981     iUssdReplyTimer->Start();
       
   982     }
       
   983 
       
   984 // -----------------------------------------------------------------------------
       
   985 // CPhSrvUssdManager::UssdNetworkObserverHandleNotifyNWReleaseL
       
   986 //
       
   987 //
       
   988 //
       
   989 // -----------------------------------------------------------------------------
       
   990 //
       
   991 void CPhSrvUssdManager::UssdNetworkObserverHandleNotifyNWReleaseL(
       
   992 const RMobilePhone::TMobilePhoneSendSSRequestV3 & aReturnResult,
       
   993 TInt aError )
       
   994     {
       
   995     _DDPRINT( 4, "PhSrv.UssdNotifyNWRelease ##### ", aError ); // debug print
       
   996     _DPRINT_FLAGS();
       
   997     TBool showNotes = ShowNotesL();
       
   998     iNetworkReleased = ETrue;
       
   999     iSendingAck = EFalse;
       
  1000     iSendRelease = EFalse;
       
  1001     iAcksToBeSent = 0;
       
  1002     
       
  1003     if ( iHavePendingSatMessagePointer )
       
  1004         {
       
  1005         iReturnResult = aReturnResult;
       
  1006         if ( !iSatCanceled )
       
  1007             {
       
  1008             CompleteSatL(&iReceivedMessage, aError );
       
  1009             _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleNotifyNWReleaseL.CompleteSat" );
       
  1010             }
       
  1011         }
       
  1012     if ( iUssdReplyTimer && iUssdReplyTimer->IsTimerActive() )
       
  1013         {
       
  1014         _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleNotifyNWReleaseL.Timer.Stop" );
       
  1015         iUssdReplyTimer->Stop();
       
  1016         Cancel();
       
  1017         CheckArray();
       
  1018         }
       
  1019     if ( showNotes && iShowDone )
       
  1020         {
       
  1021         ShowDoneNoteL();
       
  1022         }
       
  1023     if ( iUssdSendHandler && iSendingAck ) 
       
  1024         {
       
  1025         // if we are sending ack, it can be canceled.
       
  1026         iUssdSendHandler->Cancel();
       
  1027         }
       
  1028     
       
  1029     iSatCanceled = EFalse;
       
  1030     _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleNotifyNWReleaseL.iSatCanceled.EFalse" );
       
  1031     iShowDone = EFalse;
       
  1032     _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleNotifyNWReleaseL.Ending" );
       
  1033     _DPRINT_FLAGS();
       
  1034     _DPRINT( 4, "PhSrv.UssdNetworkObserverHandleNotifyNWReleaseL.End" );
       
  1035     }
       
  1036 
       
  1037 // -----------------------------------------------------------------------------
       
  1038 // CPhSrvUssdManager::ShowDoneNoteL
       
  1039 //
       
  1040 // -----------------------------------------------------------------------------
       
  1041 //
       
  1042 void CPhSrvUssdManager::ShowDoneNoteL()
       
  1043     {
       
  1044     _DDPRINT( 4, "PhSrv.ShowDoneNoteL.iShowDone", iShowDone );
       
  1045     // Show global confirmation note "Done"
       
  1046     CHbDeviceMessageBoxSymbian::InformationL(
       
  1047         LoadDefaultString( KUssdDone ) );
       
  1048     iShowDone = EFalse;
       
  1049     }
       
  1050 
       
  1051 // -----------------------------------------------------------------------------
       
  1052 // CPhSrvUssdManager::ShowErrorNoteL
       
  1053 //
       
  1054 // -----------------------------------------------------------------------------
       
  1055 //
       
  1056 void CPhSrvUssdManager::ShowErrorNoteL( TInt aError )
       
  1057     {
       
  1058     _DDPRINT( 4, "PhSrv.ShowErrorNoteL.Start ", aError );
       
  1059     if ( aError == KErrCancel )
       
  1060         {
       
  1061         _DPRINT( 4, "PhSrv.ShowErrorNoteL.Return" );
       
  1062         return;
       
  1063         }
       
  1064 
       
  1065     // Show specific error message
       
  1066     CTextResolver* textResolver = CTextResolver::NewLC();
       
  1067     HBufC* buffer = textResolver->ResolveErrorString( aError ).AllocLC();
       
  1068 
       
  1069     CHbDeviceMessageBoxSymbian::InformationL( buffer ->Des() );
       
  1070 
       
  1071     CleanupStack::PopAndDestroy( buffer ); 
       
  1072     CleanupStack::PopAndDestroy( textResolver ); 
       
  1073     
       
  1074     
       
  1075     _DPRINT( 4, "PhSrv.ShowErrorNoteL.End" );
       
  1076     return;
       
  1077     }
       
  1078 
       
  1079 
       
  1080 // -----------------------------------------------------------------------------
       
  1081 // CPhSrvUssdManager::DecodeL
       
  1082 //
       
  1083 // -----------------------------------------------------------------------------
       
  1084 //
       
  1085 void CPhSrvUssdManager::DecodeL(
       
  1086     const TDesC8& aSrc,
       
  1087     TDes& aDes ,
       
  1088     TUint8 aDcs )
       
  1089     {
       
  1090     _DPRINT( 4, "PhSrv.DecodeL.Start" );
       
  1091     aDes.Zero();
       
  1092     CCnvCharacterSetConverter* charConv = CCnvCharacterSetConverter::NewLC();
       
  1093 
       
  1094     iDCS = KPhCltDcsUnknown; // default
       
  1095 
       
  1096     // Check DCS
       
  1097     TSmsDataCodingScheme::TSmsAlphabet alphabet =
       
  1098         TSmsDataCodingScheme::ESmsAlphabet7Bit; // default
       
  1099     TUint cutChars = 0;
       
  1100     TUint startBit = 0;
       
  1101 
       
  1102     // Codes from GSM 03.38
       
  1103     if ( aDcs == KPhSrvUssdDcsAlphabetDefaultPrecededLanguage )
       
  1104         {
       
  1105         FindFirstCarriageReturnL( aSrc , cutChars , startBit );
       
  1106         }
       
  1107     else if ( aDcs == KPhSrvUssdDcsAlphabetUCS2PrecededLanguage )
       
  1108         {
       
  1109         alphabet = TSmsDataCodingScheme::ESmsAlphabetUCS2;
       
  1110         cutChars = KPhSrvUssdDcsAlphabetUCS2PrecededLanguageSkipChars;
       
  1111         }
       
  1112     else if ( (aDcs&KPhSrvUssdDcsGeneralInformationMask)  ==
       
  1113             KPhSrvUssdDcsGeneralInformation ) // General data coding information
       
  1114         {
       
  1115         //Is text compressed?
       
  1116         if ( aDcs & KPhSrvUssdDcsGeneralInformationCompressed )
       
  1117             {
       
  1118             _DPRINT( 4, "PhSrv.DecodeL.KErrNotSupported" );
       
  1119             User::Leave( KErrNotSupported );
       
  1120             }
       
  1121         // Is SIM specific message
       
  1122         else if ( ( aDcs & KPhSrvUssdDcsGeneralInformationSimMask )
       
  1123                    == KPhSrvUssdDcsGeneralInformationSim )
       
  1124             {
       
  1125             _DPRINT( 4, "PhSrv.DecodeL.KErrAbort" );
       
  1126             User::Leave( KErrAbort ); // Do not show any messages
       
  1127             }
       
  1128         // 8 bit data?
       
  1129         else if ( ( aDcs&KPhSrvUssdDcsGeneralInformationAlphabetMask ) ==
       
  1130                    KPhSrvUssdDcsGeneralInformationAlphabet8Bit )
       
  1131             {
       
  1132             alphabet = TSmsDataCodingScheme::ESmsAlphabet8Bit;
       
  1133             }
       
  1134         // UCS2 bit data?
       
  1135         else if ( ( aDcs&KPhSrvUssdDcsGeneralInformationAlphabetMask ) ==
       
  1136                    KPhSrvUssdDcsGeneralInformationAlphabetUCS2 )
       
  1137             {
       
  1138             alphabet = TSmsDataCodingScheme::ESmsAlphabetUCS2;
       
  1139             }
       
  1140         }
       
  1141     // Data coding/message handling
       
  1142     else if ( ( aDcs & KPhSrvUssdDcsMessageHandlingAlphabetMask )
       
  1143                == KPhSrvUssdDcsMessageHandlingAlphabet8Bit )
       
  1144         {
       
  1145         alphabet = TSmsDataCodingScheme::ESmsAlphabet8Bit;
       
  1146         }
       
  1147 
       
  1148     TPhSrvUssdAlphabetPacker* packer =
       
  1149         new ( ELeave ) TPhSrvUssdAlphabetPacker( alphabet , EFalse, startBit );
       
  1150     CleanupStack::PushL( packer );
       
  1151 
       
  1152     if ( alphabet == TSmsDataCodingScheme::ESmsAlphabet7Bit )
       
  1153         {
       
  1154         TInt numberOfElem = ( ( aSrc.Length() - cutChars ) * 8 - startBit ) / 7;
       
  1155         packer->UnpackAndConvertL(
       
  1156             *charConv ,
       
  1157             iFsSession ,
       
  1158             aSrc.Right( aSrc.Length() - cutChars ),
       
  1159             aDes ,
       
  1160             numberOfElem );
       
  1161 
       
  1162         // DCS was 7-bit data.
       
  1163         iDCS = KPhCltDcs7Bit;
       
  1164         }
       
  1165     else // ESmsAlphabet8Bit || ESmsAlphabetUCS2
       
  1166         {
       
  1167         CSmsAlphabetConverter* converter =
       
  1168             CSmsAlphabetConverter::NewLC(
       
  1169                 *charConv , iFsSession,alphabet,EFalse );
       
  1170 
       
  1171         aDes = converter->ConvertToNativeL(
       
  1172             aSrc.Right( aSrc.Length() - cutChars ) );
       
  1173         CleanupStack::PopAndDestroy( converter );
       
  1174 
       
  1175         if( alphabet == TSmsDataCodingScheme::ESmsAlphabet8Bit )
       
  1176             {
       
  1177             // DCS was 8-bit data.
       
  1178             iDCS = KPhCltDcs8Bit;
       
  1179             }
       
  1180         else if( alphabet == TSmsDataCodingScheme::ESmsAlphabetUCS2 )
       
  1181             {
       
  1182             // DCS was UCS2 data.
       
  1183             iDCS = KPhCltDcsUcs2;
       
  1184             }
       
  1185         // If DCS not 8-bit or UCS2, then EPhCltDcsUnknown is returned.
       
  1186         }
       
  1187 
       
  1188     //
       
  1189     CleanupStack::PopAndDestroy(2); // packer, charConv
       
  1190     _DPRINT( 4, "PhSrv.DecodeL.End" );
       
  1191     }
       
  1192 
       
  1193 
       
  1194 // -----------------------------------------------------------------------------
       
  1195 // CPhSrvUssdManager::FindFirstCarriageReturnL
       
  1196 // -----------------------------------------------------------------------------
       
  1197 //
       
  1198 void CPhSrvUssdManager::FindFirstCarriageReturnL(
       
  1199     const TDesC8& aBuffer ,
       
  1200     TUint& aSkipChars ,
       
  1201     TUint& aStartBit )
       
  1202     {
       
  1203     _DPRINT( 4, "PhSrv.FindFirstCarriageReturnL.Start" );
       
  1204     if ( aBuffer.Length() < 3 )
       
  1205         {
       
  1206         _DPRINT( 4, "PhSrv.FindFirstCarriageReturnL.KErrUnderflow" );
       
  1207         User::Leave( KErrUnderflow );
       
  1208         }
       
  1209 
       
  1210     aSkipChars = 0;
       
  1211     aStartBit = 0;
       
  1212 
       
  1213     // Try out two different cases:
       
  1214     // 1. Find CR from thrid byte
       
  1215     // 2. Find CR from second byte, starting from bit 6
       
  1216 
       
  1217     // 1.:
       
  1218     if ( aBuffer[2] == KPhSrvUssdCarriageReturn )
       
  1219         {
       
  1220         aSkipChars = KPhSrvUssdDcsAlphabetDefaultPrecededLanguageSkipChars3;
       
  1221         aStartBit = 0;
       
  1222         _DPRINT( 4, "PhSrv.FindFirstCarriageReturnL.ThirdByte.Return" );
       
  1223         return;
       
  1224         }
       
  1225 
       
  1226     // 2.:
       
  1227     // First put the pieces together and then compare
       
  1228     // Take last 2 bits from the second byte:
       
  1229     TUint result1 = aBuffer[1];
       
  1230     result1 = result1 >> 6;
       
  1231 
       
  1232     // Take first 5 bits from the third byte:
       
  1233     TUint result2 = aBuffer[2];
       
  1234     result2 = result2 & 0x1f; // bits 0-4.
       
  1235     result2 = result2 << 2; // move to bits 2-6.
       
  1236 
       
  1237     TUint result = result1 + result2; // 0000 00xx + 0xxx xx00
       
  1238     if ( result == KPhSrvUssdCarriageReturn )
       
  1239         {
       
  1240         aSkipChars = KPhSrvUssdDcsAlphabetDefaultPrecededLanguageSkipChars2;
       
  1241         aStartBit = KPhSrvUssdDcsAlphabetDefaultPrecededLanguageStartBit;
       
  1242         _DPRINT( 4, "PhSrv.FindFirstCarriageReturnL.SecondByte.Return" );
       
  1243         return;
       
  1244         }
       
  1245 
       
  1246     // Is was not case 1. or 2. so we are not supporting sort of string.
       
  1247     User::Leave( KErrNotSupported );
       
  1248     _DPRINT( 4, "PhSrv.FindFirstCarriageReturnL.KErrNotSupported" );
       
  1249     }
       
  1250 
       
  1251 
       
  1252 // -----------------------------------------------------------------------------
       
  1253 // CPhSrvUssdManager::UssdReplyTimerObserverHandleExpired
       
  1254 //
       
  1255 //
       
  1256 //
       
  1257 // -----------------------------------------------------------------------------
       
  1258 //
       
  1259 void CPhSrvUssdManager::UssdReplyTimerObserverHandleExpiredL( TInt aError )
       
  1260     {
       
  1261     _DDPRINT( 4, "PhSrv.ReplyTimer.Start.aError ", aError );     // debug print
       
  1262     delete iUssdReplyTimer;
       
  1263     iUssdReplyTimer = NULL;
       
  1264 
       
  1265     if ( aError == KErrNone &&
       
  1266          IsActive() &&
       
  1267          iDeviceDialog ) 
       
  1268         {
       
  1269         Cancel();
       
  1270         // Terminates USSD session.
       
  1271         _DPRINT( 4, "PhSrv.ReplyTimer.SendRelease" );     // debug print
       
  1272         if ( iNotifyArray ) 
       
  1273             {
       
  1274             iNotifyArray->Reset();
       
  1275             }
       
  1276         TryCloseSession();
       
  1277         }
       
  1278     _DPRINT( 4, "PhSrv.ReplyTimer.End" );     // debug print
       
  1279     }
       
  1280 
       
  1281 
       
  1282 // -----------------------------------------------------------------------------
       
  1283 // CPhSrvUssdManager::MessageBoxClosed
       
  1284 // -----------------------------------------------------------------------------
       
  1285 //       
       
  1286 void CPhSrvUssdManager::MessageBoxClosed(
       
  1287     const CHbDeviceMessageBoxSymbian* aMessageBox,
       
  1288     CHbDeviceMessageBoxSymbian::TButtonId aButton)
       
  1289     {
       
  1290     _DPRINT( 4, "PhSrv.MsgClose.Start" );
       
  1291     // ussd device dialog observer callback function
       
  1292     TPtrC leftBtn = aMessageBox->ButtonText( 
       
  1293         CHbDeviceMessageBoxSymbian::EAcceptButton );
       
  1294     TPtrC rightBtn = aMessageBox->ButtonText( 
       
  1295         CHbDeviceMessageBoxSymbian::ERejectButton );    
       
  1296 
       
  1297     TInt err = KErrNone;
       
  1298     // Click Yes on Confirmation note (Yes, No) 
       
  1299     if ( !leftBtn.Compare( 
       
  1300           LoadDefaultString( KUssdYes ) ) && 
       
  1301           ( CHbDeviceMessageBoxSymbian::EAcceptButton == aButton ) )
       
  1302         {
       
  1303         _DPRINT( 4, "PhSrv.MsgClose.SK.Yes" );
       
  1304         iClearArray = EFalse;
       
  1305         iNotifyArray->Reset();
       
  1306         TryCloseSession();
       
  1307         }
       
  1308     // Click "No" on Confirmation note (Yes, No) 
       
  1309     else if ( !rightBtn.Compare( 
       
  1310                LoadDefaultString( KUssdNo ) ) && 
       
  1311               ( CHbDeviceMessageBoxSymbian::ERejectButton == aButton ) )
       
  1312         {
       
  1313         _DPRINT( 4, "PhSrv.MsgClose.SK.No" );
       
  1314         iClearArray = EFalse;
       
  1315         iNotifyMessage = ETrue; // for removing the yes/no query
       
  1316         CheckArray();
       
  1317         TryCloseSession();
       
  1318         }
       
  1319     // Click "Next" on Notification note (Next, Exit) 
       
  1320     else if ( !leftBtn.Compare( 
       
  1321                LoadDefaultString( KUssdNext ) ) && 
       
  1322                ( CHbDeviceMessageBoxSymbian::EAcceptButton == aButton ) )
       
  1323         {
       
  1324         _DPRINT( 4, "PhSrv.MsgClose.SK.Next" ); 
       
  1325         CheckArray();
       
  1326         TryCloseSession();
       
  1327         }
       
  1328     // Click "Exit" on Notification note (Next, Exit or only Exit) 
       
  1329     else if ( !rightBtn.Compare( 
       
  1330                LoadDefaultString( KUssdExit ) ) && 
       
  1331                ( CHbDeviceMessageBoxSymbian::ERejectButton == aButton ) )
       
  1332         {
       
  1333         TRAP( err, ClearArrayL() );
       
  1334         _DDPRINT( 4, "PhSrv.MsgClose.SK.Clear.%d", err );
       
  1335         TryCloseSession();
       
  1336         _DPRINT( 4, "PhSrv.MsgClose.SK.Exit" ); 
       
  1337         }
       
  1338     // Click "Reply" on Message note (Reply, Exit) 
       
  1339     else if ( !leftBtn.Compare( 
       
  1340                LoadDefaultString( KUssdReply ) ) && 
       
  1341                ( CHbDeviceMessageBoxSymbian::EAcceptButton == aButton ) )
       
  1342         {
       
  1343         // Answer
       
  1344         iStartEditor = ETrue;
       
  1345         iShowDone = EFalse;
       
  1346         // Start the USSD editor now.
       
  1347         TRAP( err, RequestStartEditingL() );
       
  1348         _DDPRINT( 4, "PhSrv.MsgClose.RequestStartEditingL.%d", err );
       
  1349         }    
       
  1350     else 
       
  1351         {
       
  1352         _DPRINT( 4, "PhSrv.MsgClose.SK.Default" ); 
       
  1353         }
       
  1354   
       
  1355     _DPRINT( 4, "PhSrv.MsgClose.End" ); 
       
  1356     }
       
  1357 
       
  1358 // -----------------------------------------------------------------------------
       
  1359 // CPhSrvUssdManager::RunL
       
  1360 // -----------------------------------------------------------------------------
       
  1361 //
       
  1362 void CPhSrvUssdManager::RunL()
       
  1363     {
       
  1364     _DPRINT( 4, "PhSrv.RunL.Start" );    
       
  1365 
       
  1366     ProcessMoAcksL();
       
  1367     
       
  1368     if ( iLaunchGMQ )
       
  1369         {
       
  1370         LaunchGlobalMessageQueryL();
       
  1371         // Do not launch Global Message Query next time.
       
  1372         iLaunchGMQ = EFalse;
       
  1373         _DPRINT( 4, "PhSrv.iLaunchGMQ.EFalse" );
       
  1374         }
       
  1375     else
       
  1376         {
       
  1377         iStartEditor = EFalse;
       
  1378         // update device dialog
       
  1379         _DPRINT( 4, "PhSrv.RunL.End" );     // debug print
       
  1380         }
       
  1381     }
       
  1382 
       
  1383 // -----------------------------------------------------------------------------
       
  1384 // CPhSrvUssdManager::LaunchGlobalMessageQueryL
       
  1385 // -----------------------------------------------------------------------------
       
  1386 //
       
  1387 void CPhSrvUssdManager::LaunchGlobalMessageQueryL()
       
  1388     {
       
  1389     _DPRINT( 4, "PhSrv.LGMQ.start" );
       
  1390     _DPRINT_FLAGS();
       
  1391 
       
  1392     if ( iNotifyMessage )
       
  1393         {
       
  1394         _DDPRINT( 4, "PhSrv.LGMQ.NotifyMessage", iNotifyMessage );
       
  1395         iNotifyMessage = ETrue;
       
  1396         TInt count = NotifyCount();
       
  1397         //check softkey in avkon.rss 
       
  1398         if ( count > 1 )
       
  1399             {
       
  1400             // Next, Exit
       
  1401             iDeviceDialog->SetButton(
       
  1402                 CHbDeviceMessageBoxSymbian::EAcceptButton, ETrue );            
       
  1403             iDeviceDialog->SetButtonTextL(
       
  1404                 CHbDeviceMessageBoxSymbian::EAcceptButton, 
       
  1405                 LoadDefaultString( KUssdNext ) );
       
  1406             iDeviceDialog->SetButton(
       
  1407                 CHbDeviceMessageBoxSymbian::ERejectButton, ETrue );    
       
  1408             iDeviceDialog->SetButtonTextL(
       
  1409                 CHbDeviceMessageBoxSymbian::ERejectButton, 
       
  1410                 LoadDefaultString( KUssdExit ) );  
       
  1411             _DPRINT( 4, "PhSrv.LGMQ.Next&Exit" );
       
  1412             }
       
  1413         else
       
  1414             {
       
  1415             // Only Exit
       
  1416             iDeviceDialog->SetButton(
       
  1417                 CHbDeviceMessageBoxSymbian::EAcceptButton, EFalse ); 
       
  1418             iDeviceDialog->SetButton(
       
  1419                 CHbDeviceMessageBoxSymbian::ERejectButton, ETrue );               
       
  1420             iDeviceDialog->SetButtonTextL(
       
  1421                 CHbDeviceMessageBoxSymbian::ERejectButton, 
       
  1422                 LoadDefaultString( KUssdExit ) );   
       
  1423             _DPRINT( 4, "PhSrv.LGMQ.onlyExit" );
       
  1424             }
       
  1425         if ( iClearArray )
       
  1426             {
       
  1427             HbTextResolverSymbian::Init( KCommonLocFilename, KLocPath );
       
  1428             _DPRINT( 4, "PhSrv.LGMQ.use common loc file" );
       
  1429             // Yes, No
       
  1430             iDeviceDialog->SetButton(
       
  1431                 CHbDeviceMessageBoxSymbian::EAcceptButton, ETrue );               
       
  1432             iDeviceDialog->SetButtonTextL(
       
  1433                 CHbDeviceMessageBoxSymbian::EAcceptButton, 
       
  1434                 LoadDefaultString( KUssdYes ) );
       
  1435             iDeviceDialog->SetButton(
       
  1436                 CHbDeviceMessageBoxSymbian::ERejectButton, ETrue );              
       
  1437             iDeviceDialog->SetButtonTextL(
       
  1438                 CHbDeviceMessageBoxSymbian::ERejectButton, 
       
  1439                 LoadDefaultString( KUssdNo ) );  
       
  1440             _DPRINT( 4, "PhSrv.LGMQ.Yes&No" );
       
  1441             HbTextResolverSymbian::Init( KUssdLocFilename, KLocPath );
       
  1442             _DPRINT( 4, "PhSrv.LGMQ.back up to use ussd loc file" );
       
  1443             }
       
  1444         iReceivedMessage.Zero();
       
  1445         iReceivedMessage = (*iNotifyArray)[0];
       
  1446         }
       
  1447     TurnLightsOn(); //Ensure lights on
       
  1448 
       
  1449     _DPRINT( 4, "PhSrv.LGMQ.ShMsgQuery" ); // debug print
       
  1450     // Launch Global MessageQuery as requested.
       
  1451     // Dialog not support header text, this code is only 
       
  1452     // for testing, not final solution.
       
  1453     TInt receiveLength = iReceivedMessage.Length();
       
  1454     _DDPRINT( 4, "PhSrv.LGMQ.ShMsgQuery.MsgLength", receiveLength ); 
       
  1455     
       
  1456     TInt titleLength = LoadDefaultString( KUssdTitle ).Length();
       
  1457     _DDPRINT( 4, "PhSrv.LGMQ.ShMsgQuery.TilteLength", titleLength );
       
  1458     
       
  1459     TInt length = receiveLength + titleLength;
       
  1460     _DDPRINT( 4, "PhSrv.LGMQ.ShMsgQuery.TotalLength", length );    
       
  1461         
       
  1462     HBufC* titleAndText = HBufC::NewLC( length );
       
  1463     titleAndText->Des().Append( LoadDefaultString( KUssdTitle ) );
       
  1464     titleAndText->Des().Append( iReceivedMessage );
       
  1465     iDeviceDialog->SetTextL( titleAndText->Des() );
       
  1466     CleanupStack::Pop( titleAndText );
       
  1467     
       
  1468     iDeviceDialog->Close();
       
  1469     iDeviceDialog->ShowL();
       
  1470     iShowDone = EFalse;
       
  1471    
       
  1472     // Do nothing else in RunL this time.
       
  1473     _DPRINT( 4, "PhSrv.LGMQ.ShMsgQuery.ret" ); // debug print
       
  1474     }
       
  1475 
       
  1476 // -----------------------------------------------------------------------------
       
  1477 // CPhSrvUssdManager::ProcessMoAcksL()
       
  1478 // -----------------------------------------------------------------------------
       
  1479 //
       
  1480 void CPhSrvUssdManager::ProcessMoAcksL()
       
  1481     {
       
  1482     //Acknowledgment is sent if notify message
       
  1483     if ( iNotifyMessage && iAcksToBeSent )
       
  1484         {
       
  1485         _DPRINT( 4, "PhSrv.LGMQ.SendMoAcknowledgementL, start" );
       
  1486         _DPRINT_FLAGS();
       
  1487         if ( iUssdSendHandler && !iUssdSendHandler->IsActive() &&
       
  1488              !iNetworkReleased && !iSendRelease && !iSendingAck )
       
  1489             {
       
  1490             _DPRINT( 4, "PhSrv.LGMQ.MoAckNeededToBeSent" );
       
  1491             SendMoAcknowledgementL();
       
  1492             iAcksToBeSent--;
       
  1493             iSendingAck = ETrue;
       
  1494             }
       
  1495         _DPRINT( 4, "PhSrv.LGMQ.SendMoAcknowledgementL, end" );
       
  1496         }
       
  1497     }
       
  1498  
       
  1499 // -----------------------------------------------------------------------------
       
  1500 // CPhSrvUssdManager::AsyncProcessMoAcks()
       
  1501 // -----------------------------------------------------------------------------
       
  1502 //
       
  1503 void CPhSrvUssdManager::AsyncProcessMoAcks()
       
  1504     {
       
  1505     if ( iMoAckCallback ) 
       
  1506         {
       
  1507         iMoAckCallback->CallBack();
       
  1508         _DPRINT( 4, "PhSrv.LGMQ.AsyncProcessMoAcksL, queued" );
       
  1509         }
       
  1510     }
       
  1511 // -----------------------------------------------------------------------------
       
  1512 // CPhSrvUssdManager::MoAckCallback()
       
  1513 // -----------------------------------------------------------------------------
       
  1514 //
       
  1515 TInt CPhSrvUssdManager::MoAckCallback( TAny *aUssdManager )
       
  1516     {
       
  1517     _DPRINT( 4, "PhSrv.MoAckCallback.start" );
       
  1518     if ( aUssdManager )
       
  1519         {
       
  1520         CPhSrvUssdManager* manager = static_cast<CPhSrvUssdManager*>( aUssdManager );
       
  1521         TRAP_IGNORE( manager->ProcessMoAcksL() );
       
  1522         }
       
  1523     _DPRINT( 4, "PhSrv.MoAckCallback.end" );
       
  1524     return ETrue;
       
  1525     }
       
  1526 
       
  1527 // -----------------------------------------------------------------------------
       
  1528 // CPhSrvUssdManager::TryCloseSession()
       
  1529 // -----------------------------------------------------------------------------
       
  1530 //
       
  1531 void CPhSrvUssdManager::TryCloseSession() 
       
  1532     {
       
  1533     // Dismiss, cancel the session.
       
  1534     _DPRINT( 4, "PhSrv.CheckAndCloseSession.close" );  // debug print
       
  1535        
       
  1536     iShowDone = EFalse;
       
  1537     iEmptyEditor = EFalse;
       
  1538     
       
  1539     // If the notification array is empty, close the session.
       
  1540     if ( NotifyCount() == 0 && !iNetworkReleased )
       
  1541         {
       
  1542         CloseSession();
       
  1543         }
       
  1544     }
       
  1545 // -----------------------------------------------------------------------------
       
  1546 // CPhSrvUssdManager::CloseSession()
       
  1547 // -----------------------------------------------------------------------------
       
  1548 //
       
  1549 void CPhSrvUssdManager::CloseSession()
       
  1550     {
       
  1551     iSendRelease = ETrue;
       
  1552     iClearArray = EFalse;
       
  1553     iAcksToBeSent = 0;
       
  1554     _DPRINT( 4, "PhSrv.CheckAndCloseSession.canceling" ); 
       
  1555     SendUssdCancel();
       
  1556     Cancel();
       
  1557         
       
  1558     // Terminates USSD session.
       
  1559     if ( !iNetworkReleased ) 
       
  1560         {
       
  1561         iUssdSendHandler->SendReleaseSession();
       
  1562         }
       
  1563     if ( iUssdReplyTimer )
       
  1564         {
       
  1565         _DPRINT( 4, "PhSrv.CheckAndCloseSession.Timer.Stop" );
       
  1566         iUssdReplyTimer->Stop();
       
  1567         }
       
  1568     }
       
  1569  
       
  1570 // -----------------------------------------------------------------------------
       
  1571 // CPhSrvUssdManager::CheckArray()
       
  1572 // -----------------------------------------------------------------------------
       
  1573 //
       
  1574 void CPhSrvUssdManager::CheckArray()
       
  1575     {
       
  1576     _DPRINT( 4, "PhSrv.CheckArray.Start" );     // debug print
       
  1577     if (iNotifyArray  && NotifyCount() > 0)
       
  1578         {
       
  1579         if  ( !iNotifyMessage && !iClearArray )
       
  1580             {
       
  1581             iLaunchGMQ = ETrue;
       
  1582             iNotifyMessage = ETrue;
       
  1583             _DPRINT( 4, "PhSrv.CheckArray.iNotifyMessage.ETrue" );
       
  1584             iTimer.After( iStatus , KPhSrvUssdMessageQueryInterval );
       
  1585             _DDPRINT( 4, "PhSrv.CheckArray.SetActive.NoNotifyMessage ", iStatus.Int() );
       
  1586             SetActive();
       
  1587             }
       
  1588         else if( NotifyCount() > 1 )
       
  1589             {
       
  1590             ( iNotifyArray )->Delete( 0 );
       
  1591             ( iNotifyArray )->Compress();
       
  1592             iLaunchGMQ = ETrue;
       
  1593             iNotifyMessage = ETrue;
       
  1594             _DPRINT( 4, "PhSrv.CheckArray.iNotifyMessage.ETrue" );
       
  1595             iTimer.After( iStatus , KPhSrvUssdMessageQueryInterval );
       
  1596             _DDPRINT( 4, "PhSrv.CheckArray.SetActive.NotifyCount>1 ", iStatus.Int() );
       
  1597             SetActive();
       
  1598             }
       
  1599         else
       
  1600             {
       
  1601             iNotifyArray->Reset();
       
  1602             iNotifyMessage = EFalse;
       
  1603             _DPRINT( 4, "PhSrv.CheckArray.iNotifyMessage.EFalse" );
       
  1604             }
       
  1605         }
       
  1606     _DPRINT_FLAGS();
       
  1607     _DPRINT( 4, "PhSrv.CheckArray.End" );     // debug print
       
  1608     }
       
  1609 
       
  1610 // -----------------------------------------------------------------------------
       
  1611 // CPhSrvUssdManager::ClearArray()
       
  1612 // -----------------------------------------------------------------------------
       
  1613 //
       
  1614   void CPhSrvUssdManager::ClearArrayL()
       
  1615     {
       
  1616     _DPRINT( 4, "PhSrv.ClearArrayL.Start" );     // debug print
       
  1617     if (iNotifyArray && NotifyCount() > 0)
       
  1618         {
       
  1619         if (iNotifyMessage && NotifyCount()== 1 )
       
  1620             {
       
  1621             iNotifyArray->Reset();
       
  1622             }
       
  1623         else
       
  1624             {
       
  1625             iReceivedMessage.Zero();
       
  1626             iReceivedMessage.Append( 
       
  1627                 LoadDefaultString( KUssdConfirm ) );
       
  1628             iNotifyArray->InsertL( 0, iReceivedMessage );
       
  1629             iLaunchGMQ = ETrue;
       
  1630             iNotifyMessage = ETrue;
       
  1631             _DPRINT( 4, "PhSrv.ClearArrayL.iNotifyMessage.ETrue" );
       
  1632             iClearArray = ETrue;
       
  1633             iTimer.After( iStatus , KPhSrvUssdMessageQueryInterval );
       
  1634             _DDPRINT( 4, "PhSrv.ClearArrayL.iTimer ", iStatus.Int() );
       
  1635             SetActive();
       
  1636             }
       
  1637         }
       
  1638     _DPRINT_FLAGS();
       
  1639     _DPRINT( 4, "PhSrv.ClearArrayL.End" );     // debug print
       
  1640     }
       
  1641 
       
  1642 // -----------------------------------------------------------------------------
       
  1643 // CPhSrvUssdManager::NotifyCount()
       
  1644 // -----------------------------------------------------------------------------
       
  1645 //
       
  1646 TInt CPhSrvUssdManager:: NotifyCount()
       
  1647 {
       
  1648     TInt count = iNotifyArray->Count();
       
  1649     _DDPRINT( 4, "PhSrv.NotifyCount:", count );     // debug print
       
  1650     return count;
       
  1651 }
       
  1652 
       
  1653 // -----------------------------------------------------------------------------
       
  1654 // CPhSrvUssdManager::UpdateNotifyMessageL()
       
  1655 // -----------------------------------------------------------------------------
       
  1656 //
       
  1657   void CPhSrvUssdManager:: UpdateNotifyMessageL()
       
  1658     {
       
  1659     _DDPRINT( 4, "PhSrv.UpdateNotifyMessageL.Start, clear: ", iClearArray );     // debug print
       
  1660 
       
  1661     // Show left softkey - "Next"
       
  1662     if (NotifyCount() > 1 && !iClearArray )
       
  1663         {
       
  1664         _DPRINT( 4, "PhSrv.UpdateNotifyMessageL" );     // debug print
       
  1665         iDeviceDialog->SetButton( 
       
  1666             CHbDeviceMessageBoxSymbian::EAcceptButton, ETrue ); 
       
  1667         iDeviceDialog->SetButtonTextL(
       
  1668             CHbDeviceMessageBoxSymbian::EAcceptButton, 
       
  1669             LoadDefaultString( KUssdNext ) );
       
  1670         }
       
  1671     // Remove left softkey
       
  1672     else
       
  1673         {
       
  1674         iDeviceDialog->SetButton( 
       
  1675                     CHbDeviceMessageBoxSymbian::EAcceptButton, EFalse );         
       
  1676         }
       
  1677     iDeviceDialog->UpdateL();        
       
  1678     
       
  1679     _DPRINT( 4, "PhSrv.UpdateNotifyMessageL.End" );     // debug print
       
  1680     }
       
  1681 
       
  1682 // -----------------------------------------------------------------------------
       
  1683 // CPhSrvUssdManager::DoCancel
       
  1684 // -----------------------------------------------------------------------------
       
  1685 //
       
  1686 void CPhSrvUssdManager::DoCancel()
       
  1687     {
       
  1688     _DPRINT( 4, "PhSrv.DoCancel.Start" ); // debug print
       
  1689     iTimer.Cancel();
       
  1690     iLaunchGMQ = EFalse;
       
  1691     if ( iDeviceDialog )
       
  1692         {
       
  1693         _DPRINT( 4, "PhSrv.DoCancel" ); // debug print
       
  1694         iDeviceDialog->Close();
       
  1695         delete iDeviceDialog;
       
  1696         iDeviceDialog = NULL;
       
  1697         }
       
  1698     _DPRINT( 4, "PhSrv.DoCancel.End" ); // debug print
       
  1699     }
       
  1700 
       
  1701 // -----------------------------------------------------------------------------
       
  1702 // CPhSrvUssdManager::RunError
       
  1703 //
       
  1704 // Because the RunL can leave, this function exists.
       
  1705 // In case of error, just returning KErrNone is OK.
       
  1706 // -----------------------------------------------------------------------------
       
  1707 //
       
  1708 TInt CPhSrvUssdManager::RunError( TInt /*aError*/ )
       
  1709     {
       
  1710     _DPRINT( 4, "PhSrv.RunError.Start" );     // debug print
       
  1711     return KErrNone;
       
  1712     }
       
  1713 
       
  1714 // -----------------------------------------------------------------------------
       
  1715 // CPhSrvUssdManager::RequestStartEditingL
       
  1716 // -----------------------------------------------------------------------------
       
  1717 //
       
  1718 void CPhSrvUssdManager::RequestStartEditingL()
       
  1719     {
       
  1720     _DPRINT( 4, "PhSrv.UssdM.RequestStartEditingL.start" ); // debug print
       
  1721 
       
  1722     RWsSession wsSession;
       
  1723     User::LeaveIfError( wsSession.Connect() );
       
  1724     _DPRINT( 4, "PhSrv.RequestStartEditingL.wsSession.connect" );     // debug print
       
  1725     CleanupClosePushL( wsSession );
       
  1726 
       
  1727     // Find the task with name
       
  1728     TApaTaskList tasklist( wsSession );
       
  1729     TApaTask task = tasklist.FindApp( KUssdSecureId );
       
  1730 
       
  1731     // If task exists, bring it to foreground
       
  1732     if ( task.Exists() )
       
  1733         {
       
  1734         _DPRINT( 4, "PhSrv.UssdM.RequestStartEditingL.task.BringToForeground" );
       
  1735         task.BringToForeground();
       
  1736         }
       
  1737     else
       
  1738         {
       
  1739         // Start new app
       
  1740         RApaLsSession apaLsSession;
       
  1741         User::LeaveIfError( apaLsSession.Connect() );
       
  1742         _DPRINT( 4, "PhSrv.RequestStartEditingL.apaLsSession.connect" );     // debug print
       
  1743         CleanupClosePushL( apaLsSession );
       
  1744 
       
  1745         TApaAppInfo appInfo;
       
  1746         
       
  1747         TInt err = apaLsSession.GetAppInfo( appInfo, KUssdSecureId );
       
  1748         _DDPRINT( 4, "PhSrv.RequestStartEditingL.GetAppInfo ", err );     // debug print
       
  1749         
       
  1750         if ( err == KErrNone )
       
  1751             {
       
  1752         #ifndef SYMBIAN_SUPPORT_UI_FRAMEWORKS_V1
       
  1753             CApaCommandLine* apaCommandLine = CApaCommandLine::NewLC();
       
  1754             apaCommandLine->SetExecutableNameL( appInfo.iFullName );
       
  1755         #else // SYMBIAN_SUPPORT_UI_FRAMEWORKS_V1
       
  1756             CApaCommandLine* apaCommandLine =
       
  1757                 CApaCommandLine::NewLC( appInfo.iFullName );
       
  1758         #endif // SYMBIAN_SUPPORT_UI_FRAMEWORKS_V1
       
  1759 
       
  1760             TThreadId id( static_cast<TInt64>( 0 ) );
       
  1761             err = apaLsSession.StartApp( *apaCommandLine, id );
       
  1762             _DDPRINT( 4, "PhSrv.RequestStartEditingL.ThreadId ", id ); 
       
  1763             CleanupStack::PopAndDestroy( apaCommandLine );
       
  1764             }
       
  1765         CleanupStack::PopAndDestroy( &apaLsSession ); // apaLsSession
       
  1766         
       
  1767         // bring the ussd editor to foreground, only for testing
       
  1768         TApaTaskList tasklist( wsSession );
       
  1769         TApaTask task = tasklist.FindApp( KUssdSecureId );
       
  1770         if ( task.Exists() )
       
  1771             {
       
  1772             _DPRINT( 4, "PhSrv.UssdM.RequestStartEditingL.task.BringToForeground" );
       
  1773             task.BringToForeground();
       
  1774             }
       
  1775         // bring the ussd editor to foreground, only for testing
       
  1776         }
       
  1777     CleanupStack::PopAndDestroy(); // wsSession
       
  1778 
       
  1779     _DPRINT( 4, "PhSrv.UssdM.RequestStartEditingL.end" ); // debug print
       
  1780     }
       
  1781 
       
  1782 
       
  1783 // -----------------------------------------------------------------------------
       
  1784 // CPhSrvUssdManager::InformUssdApplicationStarting
       
  1785 // -----------------------------------------------------------------------------
       
  1786 //
       
  1787 void CPhSrvUssdManager::InformUssdApplicationStarting()
       
  1788     {
       
  1789     _DPRINT( 4, "PhSrv.UssdM.InfUssdAppStarting.start" ); // debug print
       
  1790     if ( iUssdReplyTimer )
       
  1791         {
       
  1792         _DPRINT( 4, "PhSrv.InformUssdApplicationStarting.iUssdReplyTimer" );
       
  1793         if ( iUssdReplyTimer->IsTimerActive() )
       
  1794             {
       
  1795             _DPRINT( 4, "PhSrv.InformUssdApplicationStarting.iUssdReplyTimer.active" );
       
  1796             iUssdReplyTimer->Pause();
       
  1797             }
       
  1798         }
       
  1799     _DPRINT( 4, "PhSrv.UssdM.InfUssdAppStarting.end" ); // debug print
       
  1800     }
       
  1801 
       
  1802 // -----------------------------------------------------------------------------
       
  1803 // CPhSrvUssdManager::InformUssdApplicationTerminatingL
       
  1804 // -----------------------------------------------------------------------------
       
  1805 //
       
  1806 void CPhSrvUssdManager::InformUssdApplicationTerminatingL(
       
  1807     const RMessage2& aMessage )
       
  1808     {
       
  1809     _DPRINT( 4, "PhSrv.UssdM.InfUssdAppTerminatingL.start" ); // debug print
       
  1810     if ( iUssdReplyTimer )
       
  1811         {
       
  1812         if ( iUssdReplyTimer->IsTimerActive() )
       
  1813             {
       
  1814      
       
  1815             _DPRINT( 4, "PhSrv.UssdM.InfUssdAppTerminatingL.timer" );
       
  1816 
       
  1817             // Read the information what is the reason
       
  1818             // for application termination.
       
  1819             TPhCltUssdAppExitReason exitReason = EPhCltExitReasonUnknown;
       
  1820             TPckg< TPhCltUssdAppExitReason > exitReasonPckg( exitReason );
       
  1821             aMessage.ReadL(
       
  1822                 0,
       
  1823                 exitReasonPckg );
       
  1824 
       
  1825      
       
  1826             _DPRINT( 4, "PhSrv.UssdM.InfUssdAppTerminatingL.timer2" );
       
  1827 
       
  1828             // If reason was the completion of send operation, the USSD
       
  1829             // session is not canceled, otherwise it is canceled.
       
  1830             if ( exitReason != EPhCltSendCompleted )
       
  1831                 {
       
  1832          
       
  1833                 _DPRINT( 4, "PhSrv.UssdM.InfUssdAppTerminatingL.SendRelease" );
       
  1834                 CloseSession();
       
  1835                 }
       
  1836             }
       
  1837         }
       
  1838     _DPRINT( 4, "PhSrv.UssdM.InfUssdAppTerminatingL.end" ); // debug print
       
  1839     }
       
  1840 
       
  1841 
       
  1842 // -----------------------------------------------------------------------------
       
  1843 // CPhSrvUssdManager::InformUssdApplicationToForeground
       
  1844 // -----------------------------------------------------------------------------
       
  1845 //
       
  1846 TInt CPhSrvUssdManager::InformUssdApplicationToForeground()
       
  1847     {
       
  1848     _DPRINT( 4, "PhSrv.UssdM.InfUssdAppToForeground.start" ); // debug print
       
  1849 
       
  1850     // Do the same actions as in InformUssdApplicationStarting,
       
  1851     // that is why it is called.
       
  1852     InformUssdApplicationStarting();
       
  1853 
       
  1854     if ( iEmptyEditor )
       
  1855         {
       
  1856         _DPRINT( 4, "PhSrv.UssdM.InfUssdAppToForeground.empty" ); // debug print
       
  1857         iEmptyEditor = EFalse;
       
  1858         return 1; // some positive number
       
  1859         }
       
  1860     _DPRINT( 4, "PhSrv.UssdM.InfUssdAppToForeground.end" ); // debug print
       
  1861     return KErrNone;
       
  1862     }
       
  1863 
       
  1864 
       
  1865 // -----------------------------------------------------------------------------
       
  1866 // CPhSrvUssdManager::InformUssdApplicationToBackground
       
  1867 // -----------------------------------------------------------------------------
       
  1868 //
       
  1869 void CPhSrvUssdManager::InformUssdApplicationToBackground()
       
  1870     {
       
  1871     _DPRINT( 4, "PhSrv.UssdM.InfUssdAppToBackground.start" ); // debug print
       
  1872     if ( iUssdReplyTimer )
       
  1873         {
       
  1874         _DPRINT( 4, "PhSrv.UssdM.InfUssdAppToBackground.timer" ); // debug print
       
  1875         if ( iUssdReplyTimer->IsTimerActive() )
       
  1876             {
       
  1877             _DPRINT( 4, "PhSrv.UssdM.InfUssdAppToBackground.timer.Active" ); // debug print
       
  1878             iUssdReplyTimer->Continue();
       
  1879             }
       
  1880         }
       
  1881     _DPRINT( 4, "PhSrv.UssdM.InfUssdAppToBackground.end" ); // debug print
       
  1882     }
       
  1883 
       
  1884 
       
  1885 // -----------------------------------------------------------------------------
       
  1886 // CPhSrvUssdManager::InformStartSAT
       
  1887 // -----------------------------------------------------------------------------
       
  1888 //
       
  1889 void CPhSrvUssdManager::InformStartSAT( const RMessage2& aSatMessage )
       
  1890     {
       
  1891     _DPRINT( 4, "PhSrv.InformStartSAT.Start" );    // debug print
       
  1892 
       
  1893     if ( iHavePendingSatMessagePointer )
       
  1894         {
       
  1895         _DPRINT( 4, "PhSrv.InformStartSAT.Complete.InUse" ); // debug print
       
  1896         aSatMessage.Complete( KErrInUse );
       
  1897         }
       
  1898     else
       
  1899         {
       
  1900         _DPRINT( 4, "PhSrv.InformStartSAT.Set" );    
       
  1901 
       
  1902         // There was not pending SAT message
       
  1903         iHavePendingSatMessagePointer = ETrue;
       
  1904         _DDPRINT( 4, "PhSrv.UssdM.InformStartSAT.PendingSatPointer ", iHavePendingSatMessagePointer );
       
  1905         iPendingSatMessagePointer = aSatMessage;
       
  1906         }
       
  1907 
       
  1908     _DPRINT( 4, "PhSrv.InformStartSAT.End" );   // debug print
       
  1909     }
       
  1910 
       
  1911 
       
  1912 // -----------------------------------------------------------------------------
       
  1913 // CPhSrvUssdManager::InformStopSAT
       
  1914 // -----------------------------------------------------------------------------
       
  1915 //
       
  1916 void CPhSrvUssdManager::InformStopSAT()
       
  1917     {
       
  1918     _DPRINT( 4, "PhSrv.InformStopSAT.Start" );        
       
  1919 
       
  1920     // Do the actions only if there is pending SAT message.
       
  1921     if ( iHavePendingSatMessagePointer )
       
  1922         {
       
  1923         _DPRINT( 4, "PhSrv.InformStopSAT.Complete.Cancel" ); // debug print
       
  1924         if ( !iPendingSatMessagePointer.IsNull() )
       
  1925             {
       
  1926             iPendingSatMessagePointer.Complete( KErrCancel );
       
  1927             _DPRINT( 4, "PhSrv.InformStopSAT.Complete.KErrCancel" );
       
  1928             }
       
  1929         iHavePendingSatMessagePointer = EFalse;
       
  1930         }
       
  1931     _DPRINT( 4, "PhSrv.InformStopSAT.End" );          
       
  1932     }
       
  1933 
       
  1934 // -----------------------------------------------------------------------------
       
  1935 // CPhSrvUssdManager::ShowNotes
       
  1936 // -----------------------------------------------------------------------------
       
  1937 //
       
  1938 
       
  1939 
       
  1940 TBool CPhSrvUssdManager::ShowNotesL()
       
  1941 {
       
  1942 _DPRINT( 4, "PhSrv.ShowNotesL.Start" );
       
  1943 
       
  1944 if ( !iHavePendingSatMessagePointer )
       
  1945     {
       
  1946     if ( iSatCanceled )
       
  1947         {
       
  1948         _DPRINT( 4, "PhSrv.ShowNotesL, EFalse" );  // debug print
       
  1949         return EFalse;
       
  1950         }
       
  1951     else
       
  1952         {
       
  1953         _DPRINT( 4, "PhSrv.ShowNotesL, ETrue" );  // debug print
       
  1954         return ETrue;
       
  1955         }
       
  1956     }
       
  1957 // Read the information whether the notes are shown or not.
       
  1958     TUint notesShown = 0;
       
  1959     TPckg< TUint > noShPckg( notesShown );
       
  1960     iPendingSatMessagePointer.ReadL(
       
  1961         0,
       
  1962         noShPckg );
       
  1963 
       
  1964     TBool showNotes = EFalse;
       
  1965     _DPRINT( 4, "PhSrv.ShowNotes Sat= EFalse" );    // debug print
       
  1966     if ( notesShown == KPhCltShowNotes )
       
  1967         {
       
  1968         _DPRINT( 4, "PhSrv.ShowNotes Sat= ETrue" ); // debug print
       
  1969         showNotes = ETrue;
       
  1970         }
       
  1971     _DPRINT( 4, "PhSrv.ShowNotesL.End" );
       
  1972     return showNotes;
       
  1973 }
       
  1974 
       
  1975 // -----------------------------------------------------------------------------
       
  1976 // CPhSrvUssdManager::CompleteSatL
       
  1977 // -----------------------------------------------------------------------------
       
  1978 //
       
  1979 void CPhSrvUssdManager::CompleteSatL(
       
  1980     TDesC* aReceiveString,
       
  1981     TInt aError )
       
  1982     {
       
  1983     _DPRINT( 4, "PhSrv.CompleteSatL.Start" );         
       
  1984     if ( aReceiveString )
       
  1985         {
       
  1986         if ( aReceiveString->Length() )
       
  1987             {
       
  1988             _DPRINT( 4, "PhSrv.CompleteSatL.recString.>0" ); // debug print
       
  1989             // copy the received string to client side.
       
  1990             if ( iPendingSatMessagePointer.Int1() < aReceiveString->Length() )
       
  1991                 {
       
  1992          
       
  1993                 _DPRINT( 4, "PhSrv.CompleteSatL.recString.LengthError" );
       
  1994                 if ( !iPendingSatMessagePointer.IsNull() )
       
  1995                     {
       
  1996                     iPendingSatMessagePointer.Complete( KErrOverflow );
       
  1997                     _DPRINT( 4, "PhSrv.CompleteSatLComplete.KErrOverFlow" );
       
  1998                     }
       
  1999                 iHavePendingSatMessagePointer = EFalse;
       
  2000                 }
       
  2001             else
       
  2002                 {
       
  2003             _DPRINT( 4, "PhSrv.CompleteSatL.recString.Write" );  // debug print
       
  2004             iPendingSatMessagePointer.WriteL(
       
  2005                 2,
       
  2006                 *aReceiveString );
       
  2007 
       
  2008             _DPRINT( 4, "PhSrv.CompleteSatL.recString.Write2" ); // debug print
       
  2009             TPckg< TUint > dcsPackage( iDCS );
       
  2010             iPendingSatMessagePointer.WriteL(
       
  2011                 0,
       
  2012                 dcsPackage );
       
  2013             }
       
  2014         }
       
  2015         }
       
  2016     _DPRINT( 4, "PhSrv.CompleteSatL.Middle" );    
       
  2017     if ( !iPendingSatMessagePointer.IsNull() )
       
  2018         {
       
  2019         if ( aReceiveString && !iSatCanceled )
       
  2020             {
       
  2021             _DDPRINT( 4, "PhSrv.CompleteSatL.Complete.", iReturnResult.iOpCode  );   // debug print
       
  2022             iPendingSatMessagePointer.Complete( iReturnResult.iOpCode ); // Some positive value
       
  2023             }
       
  2024         else
       
  2025             {
       
  2026             _DPRINT( 4, "PhSrv.CompleteSatL.Complete.aError" ); // debug print
       
  2027             iPendingSatMessagePointer.Complete( aError );
       
  2028             }
       
  2029         }
       
  2030 
       
  2031     iHavePendingSatMessagePointer = EFalse;
       
  2032 
       
  2033     _DPRINT( 4, "PhSrv.CompleteSatL.End" );    
       
  2034     }
       
  2035 
       
  2036 
       
  2037 // -----------------------------------------------------------------------------
       
  2038 // CPhSrvUssdManager::IsTelephonyFeatureSupported
       
  2039 //
       
  2040 // -----------------------------------------------------------------------------
       
  2041 //
       
  2042 TBool CPhSrvUssdManager::IsTelephonyFeatureSupported(
       
  2043     const TInt aFeatureId )
       
  2044     {
       
  2045     return ( aFeatureId & iVariantReadOnlyValues );
       
  2046     }
       
  2047 
       
  2048 
       
  2049 // -----------------------------------------------------------------------------
       
  2050 // CPhSrvUssdManager::PlayUssdTone
       
  2051 //
       
  2052 // -----------------------------------------------------------------------------
       
  2053 //
       
  2054 TInt CPhSrvUssdManager::PlayUssdTone()
       
  2055     {
       
  2056     _DPRINT( 4, "PhSrv.UssdM.PlayTone.start" );    
       
  2057 
       
  2058     TInt err = KErrNone;
       
  2059 // <-- QT PHONE  START-->
       
  2060 //    RProperty::Define( KPSUidNcnList, KNcnPlayAlertTone, RProperty::EInt, ECapability_None , ECapabilityWriteDeviceData );
       
  2061 //    RProperty::Set( KPSUidNcnList, KNcnPlayAlertTone, KPhSrvUssdTone );
       
  2062 // <-- QT PHONE END-->
       
  2063 
       
  2064     // debug print
       
  2065     _DDPRINT(
       
  2066         4,
       
  2067         "PhSrv.UssdM.PlayTone.end",
       
  2068         err );
       
  2069     return err;
       
  2070     }
       
  2071 
       
  2072 // -----------------------------------------------------------------------------
       
  2073 // CPhSrvUssdManager::GetTelephonyVariantData
       
  2074 //
       
  2075 // -----------------------------------------------------------------------------
       
  2076 //
       
  2077 TInt CPhSrvUssdManager::GetTelephonyVariantData()
       
  2078     {
       
  2079     _DPRINT( 4, "PhSrv.UssdM.GetTelephonyVariantData.Start" );
       
  2080     TInt err = KErrNone;
       
  2081 // <-- QT PHONE START-->
       
  2082 /*
       
  2083     // Variation data should be unchangable during run-time,
       
  2084     // therefore, if once succesfully read, later reads are
       
  2085     // not allowed.
       
  2086     if ( iVariantReadOnlyValues == KPhSrvDefaultValue )
       
  2087         {
       
  2088         CRepository* cenRepSession = NULL;
       
  2089         TRAP ( err ,
       
  2090                cenRepSession = CRepository::NewL( KCRUidTelVariation ) );
       
  2091         if ( err == KErrNone )
       
  2092             {
       
  2093             err = cenRepSession->Get( KTelVariationFlags,
       
  2094                                    iVariantReadOnlyValues );
       
  2095             }
       
  2096         delete cenRepSession;
       
  2097         }
       
  2098 
       
  2099     _DDPRINT( 4, "PhSrv.UssdM.variant", iVariantReadOnlyValues ); // debug print
       
  2100     _DPRINT( 4, "PhSrv.UssdM.GetTelephonyVariantData.End" );
       
  2101     */
       
  2102 // <-- QT PHONE END-->
       
  2103     return err;
       
  2104     }
       
  2105 
       
  2106 
       
  2107 // -----------------------------------------------------------------------------
       
  2108 // CPhSrvUssdManager::SendMoAcknowledgementL
       
  2109 //
       
  2110 // -----------------------------------------------------------------------------
       
  2111 //
       
  2112 void CPhSrvUssdManager::SendMoAcknowledgementL()
       
  2113     {
       
  2114     _DPRINT( 4, "PhSrv.SendMoAckL.Start" );    
       
  2115 
       
  2116     // Acknowledge MT USSD message.
       
  2117     RMobileUssdMessaging::TMobileUssdAttributesV1 msgAttribs;
       
  2118     msgAttribs.iFlags =
       
  2119         RMobileUssdMessaging::KUssdMessageType +
       
  2120         RMobileUssdMessaging::KUssdDataFormat  +
       
  2121         RMobileUssdMessaging::KUssdMessageDcs;
       
  2122 
       
  2123     msgAttribs.iType   = RMobileUssdMessaging::EUssdMOAcknowledgement;
       
  2124     _DDPRINT( 4, "PhSrv.SendMoAckL.msgAttribs.iType ", msgAttribs.iType );
       
  2125     msgAttribs.iFormat = RMobileUssdMessaging::EFormatUnspecified;
       
  2126     _DDPRINT( 4, "PhSrv.SendMoAckL.msgAttribs.iFormat ", msgAttribs.iFormat );
       
  2127     msgAttribs.iDcs    = KPhSrvUssdDefaultDCS;
       
  2128 
       
  2129     RMobileUssdMessaging::TMobileUssdAttributesV1Pckg attribs = msgAttribs;
       
  2130     SendHandlerL().SendUssdL( KNullDesC8() , attribs );
       
  2131 
       
  2132     _DPRINT( 4, "PhSrv.SendMoAckL.End" );    
       
  2133     }
       
  2134 
       
  2135 // -----------------------------------------------------------------------------
       
  2136 // CPhSrvUssdManager::TurnLightsOn
       
  2137 //
       
  2138 // -----------------------------------------------------------------------------
       
  2139 //
       
  2140 void CPhSrvUssdManager::TurnLightsOn()
       
  2141     {
       
  2142     _DPRINT( 4, "PhSrv.TurnLightsOn.Start" );    
       
  2143 
       
  2144 
       
  2145      // Change the bit on and off. SysAp will detect that
       
  2146      // the lights should be switched on for the specified time.
       
  2147      //
       
  2148      RProperty::Set(KPSUidCoreApplicationUIs, KLightsControl, ELightsOn);
       
  2149      TInt err = RProperty::Set(KPSUidCoreApplicationUIs, KLightsControl, ELightsOff);
       
  2150 
       
  2151      if ( err != KErrNone )
       
  2152          {
       
  2153          _DDPRINT( 4,"PhSrv.TurnLightsOn.Error: ",err );// debug print
       
  2154          }
       
  2155 
       
  2156     _DPRINT( 4, "PhSrv.TurnLightsOn.End" );    
       
  2157     }
       
  2158 
       
  2159 // -----------------------------------------------------------------------------
       
  2160 // CPhSrvUssdManager::LoadDefaultString
       
  2161 // -----------------------------------------------------------------------------
       
  2162 //
       
  2163 const TPtrC CPhSrvUssdManager::LoadDefaultString( const TDesC& aText )
       
  2164     {
       
  2165     _DPRINT( 4, "PhSrv.LoadDefaultString.Start" );
       
  2166     
       
  2167     if ( iTextBuffer )
       
  2168         {
       
  2169         delete iTextBuffer;
       
  2170         iTextBuffer = NULL;
       
  2171         _DPRINT( 4, "PhSrv.LoadDefaultString.Clear" );
       
  2172         }
       
  2173     TInt err = KErrNone;
       
  2174     TPtrC ptr( aText );
       
  2175     if ( ptr.Length() )
       
  2176         {
       
  2177         TRAP( err, iTextBuffer = HbTextResolverSymbian::LoadL( ptr ) );
       
  2178         _DDPRINT( 4, "PhSrv.LoadDefaultString.LoadL.%d", err );
       
  2179         if ( iTextBuffer )
       
  2180             {
       
  2181             ptr.Set( iTextBuffer->Des() );   
       
  2182             _DPRINT( 4, "PhSrv.LoadDefaultString.Set" );
       
  2183             }
       
  2184         }    
       
  2185     _DPRINT( 4, "PhSrv.LoadDefaultString.End" );
       
  2186     return ptr;
       
  2187     }
       
  2188 
       
  2189 // End of File