bluetoothengine/btnotif/src/btnumcmpnotifier.cpp
changeset 0 f63038272f30
child 6 6a29d5ad0713
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Declares Numeric Comparison notifier for Secure Simle Pairing 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <StringLoader.h>    // Localisation stringloader
       
    21 #include <utf.h>             // Unicode character conversion utilities
       
    22 #include <avkon.mbg>
       
    23 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    24 #include <btextnotifiers.h>
       
    25 #else
       
    26 #include <btextnotifiers.h>
       
    27 #include <btextnotifierspartner.h>
       
    28 #endif
       
    29 #include <BTNotif.rsg>       // Own resources
       
    30 #include "btnotif.hrh"       // Own resource header
       
    31 #include "btnumcmpnotifier.h"  // Own class definition
       
    32 #include "btNotifDebug.h"    // Debugging macros
       
    33 #include <btotgpairpub.inl>
       
    34 #include <btengconnman.h>
       
    35 #include <SecondaryDisplay/BTnotifSecondaryDisplayAPI.h>
       
    36 #include "btnotifnameutils.h"
       
    37 
       
    38 #ifdef __SERIES60_HELP
       
    39 #include <hlplch.h>
       
    40 #include <csxhelp/bt.hlp.hrh> // The bt hrh info is needed, for help launching
       
    41 #endif
       
    42 
       
    43 // ================= MEMBER FUNCTIONS =======================
       
    44 
       
    45 // ----------------------------------------------------------
       
    46 // CBTNumCmpNotifier::NewL
       
    47 // Two-phased constructor.
       
    48 // ----------------------------------------------------------
       
    49 //
       
    50 CBTNumCmpNotifier* CBTNumCmpNotifier::NewL()
       
    51     {
       
    52     CBTNumCmpNotifier* self=new (ELeave) CBTNumCmpNotifier();
       
    53     CleanupStack::PushL(self);
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop(self);
       
    56     return self;
       
    57     }
       
    58 
       
    59 // ----------------------------------------------------------
       
    60 // CBTNumCmpNotifier::CBTNumCmpNotifier
       
    61 // C++ default constructor can NOT contain any code, that
       
    62 // might leave.
       
    63 // ----------------------------------------------------------
       
    64 //
       
    65 CBTNumCmpNotifier::CBTNumCmpNotifier()
       
    66     {
       
    67     iPasskeyToShow.Zero();
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------
       
    71 // Destructor
       
    72 // ----------------------------------------------------------
       
    73 //
       
    74 CBTNumCmpNotifier::~CBTNumCmpNotifier()
       
    75     {
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------
       
    79 // CBTNumCmpNotifier::RegisterL
       
    80 // Register notifier.
       
    81 // ----------------------------------------------------------
       
    82 //
       
    83 CBTNumCmpNotifier::TNotifierInfo CBTNumCmpNotifier::RegisterL()
       
    84     {
       
    85     iInfo.iUid = KBTNumericComparisonNotifierUid;
       
    86     iInfo.iChannel = KBTNumericComparisonNotifierUid;
       
    87     iInfo.iPriority=ENotifierPriorityVHigh;
       
    88     return iInfo;
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------------
       
    92 // CBTNumCmpNotifier::GetParamsL
       
    93 // Initialize parameters and check if device is already
       
    94 // in registry. Jump to RunL as soon as possible.
       
    95 // ----------------------------------------------------------
       
    96 //
       
    97 void CBTNumCmpNotifier::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
    98     {
       
    99     FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::GetParamsL()"));
       
   100 
       
   101     CBTNPairNotifierBase::GetParamsL( aBuffer, aReplySlot, aMessage );
       
   102     
       
   103     TBTNumericComparisonParamsPckg pckg;
       
   104  	pckg.Copy(aBuffer);
       
   105  	iBTAddr = pckg().DeviceAddress();
       
   106     if ( OtherOutgoPairing( iBTAddr) )
       
   107         {
       
   108         // We won't allow incoming pairing during outgoing pairing:
       
   109         FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier: outgoing pair in progress, reject incoming pair"));
       
   110         CompleteMessage(KErrCancel);
       
   111         return;
       
   112         }
       
   113     
       
   114 	TUint32 passkey = pckg().NumericalValue(); 
       
   115 	iLocallyInitiated = pckg().LocallyInitiated(); 
       
   116 	iPasskeyToShow.AppendNumFixedWidth(passkey, EDecimal, Klength);
       
   117 	iPasskeyToShow.Insert(3,_L(" "));
       
   118 
       
   119 	// base class
       
   120 	ProcessParamsGetDeviceL( iBTAddr, pckg().DeviceName() );
       
   121 	
       
   122 	FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::GetParamsL() completed"));
       
   123     }
       
   124 
       
   125 // ----------------------------------------------------------
       
   126 // CBTNumCmpNotifier::HandleGetDeviceCompletedL
       
   127 // Ask user response and return it to caller.
       
   128 // Store device into registry if user has accepted pairing.
       
   129 // ----------------------------------------------------------
       
   130 //
       
   131 void CBTNumCmpNotifier::HandleGetDeviceCompletedL(const CBTDevice* /*aDev*/)
       
   132     {
       
   133     FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::HandleGetDeviceCompletedL()"));
       
   134     
       
   135     // Check if blocked device. 
       
   136     if( CheckBlockedDeviceL() )
       
   137         return;
       
   138     
       
   139     // Turn lights on and deactivate apps -key
       
   140     iNotifUiUtil->TurnLightsOn();
       
   141 
       
   142    	// For incoming pairing request
       
   143 	if(!iLocallyInitiated)
       
   144 	    {
       
   145 	    TBool keypress = AuthoriseIncomingPairingL();
       
   146 	    if( !keypress ) 
       
   147 	        {
       
   148 	        //User rejects the incoming pairing, complete message in QueryBlockDevice.
       
   149 	        FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::HandleGetDeviceCompletedL() <<"));
       
   150 	        return;
       
   151 	        }
       
   152 	    }
       
   153 	
       
   154 	// For outgoing pairing request or accepted incoming pairing request,
       
   155 	// ask user to compare the pincodes in two devices.
       
   156 	TBTDeviceName nameCoverUi( KNullDesC );
       
   157 	HBufC* prompt = GenerateQueryPromoptLC(); 
       
   158     TInt answer = iNotifUiUtil->ShowQueryL( *prompt, R_BT_GENERIC_QUERY, ECmdShowBtOpenCoverNote, nameCoverUi );   
       
   159 	CleanupStack::PopAndDestroy( prompt ); 
       
   160 	
       
   161     if( answer )
       
   162         {
       
   163         CompleteMessage(answer, KErrNone);
       
   164         }
       
   165     else
       
   166         {
       
   167         // If the outgoing pairing mode is set, then this is bonding initiated by the user.
       
   168         TBool incomingConn = ( OutgoPairingMode( iBTAddr ) == EBTOutgoingPairNone );
       
   169 
       
   170         if( !iMessage.IsNull() )
       
   171             {
       
   172             // No need to inform the user of the pairing result if the user cancelled it.
       
   173             // If user doesn't answer anything but stack cancels, pairing result is needed 
       
   174             // to show for outgoing pairing. In this case, don't stop pairng observer.
       
   175             CBTEngConnMan::StopPairingObserver( iBTAddr );
       
   176             }
       
   177         // We may be asking for pairing (locally initiated), because a remote device is requesting
       
   178         // accesss to a service for which we require authentication.
       
   179         if( iLocallyInitiated && incomingConn )
       
   180             {
       
   181             CheckAndHandleQueryIntervalL();
       
   182             }
       
   183         CompleteMessage(KErrCancel);
       
   184         }
       
   185 
       
   186     FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::HandleGetDeviceCompletedL() completed"));
       
   187     }
       
   188 
       
   189 // ----------------------------------------------------------
       
   190 // CBTNumCmpNotifier::GenerateQueryPromoptLC
       
   191 // Generate prompt for Numeric Comparison query and return.
       
   192 // ----------------------------------------------------------
       
   193 //
       
   194 HBufC* CBTNumCmpNotifier::GenerateQueryPromoptLC()
       
   195     {
       
   196     FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::GenerateQueryPromoptLC()"));
       
   197     TBTDeviceName devName;
       
   198     BtNotifNameUtils::GetDeviceDisplayName( devName, iDevice );
       
   199     
       
   200     CPtrCArray* subs = new (ELeave) CPtrCArray(2);
       
   201     CleanupStack::PushL( subs );
       
   202     TBuf<KBTDeviceShortNameLength> shortName;
       
   203     
       
   204     // Cut the name and put ellipsis in the middle if necessary
       
   205     // By example "SampleSymbianDevice" after this operation will be shown in
       
   206     // the dialog as "Sam...ice"(for 7 chars device name limit)
       
   207     // This need to be done, because if name of the device is too long, the PIN
       
   208     // codes aren't visible and user can't compare it with PIN code taken from
       
   209     // other phone
       
   210     if ( devName.Length() > KBTDeviceShortNameLength ) 
       
   211         {
       
   212         shortName.Copy( devName.Left( KBTDeviceShortNameLength/2 ) );
       
   213         //adding ellipsis ("...") char in the middle of the string
       
   214         shortName.Append( TChar( KEllipsis) );
       
   215         //adding only end of the name to the final string
       
   216         shortName.Append( devName.Right( shortName.MaxLength() - 
       
   217                           shortName.Length() ) );
       
   218         subs->AppendL( shortName );
       
   219         }
       
   220     else
       
   221         {
       
   222         subs->AppendL( devName );
       
   223         }
       
   224     subs->AppendL( iPasskeyToShow );
       
   225     HBufC* prompt = StringLoader::LoadL( R_BT_SSP_PASSKEY_COMPARISON_PROMPT, *subs );
       
   226     CleanupStack::PopAndDestroy( subs );
       
   227     CleanupStack::PushL( prompt );
       
   228     FLOG(_L("[BTNOTIF]\t CBTNumCmpNotifier::GenerateQueryPromoptLC() <<"));
       
   229     return prompt;
       
   230     }
       
   231 
       
   232 // End of File