bluetoothengine/btnotif/src/btnpairnotifier.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:  Base class for all notifiers for pairing purpose.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #include <btextnotifiers.h>
       
    20 #else
       
    21 #include <btextnotifiers.h>
       
    22 #include <btextnotifierspartner.h> // new file introduced by xSymbian
       
    23 #endif
       
    24 
       
    25 #include <StringLoader.h>    // Localisation stringloader
       
    26 #include <utf.h>             // Unicode character conversion utilities
       
    27 #include <btengconnman.h>
       
    28 #include <BTNotif.rsg>       // Own resources
       
    29 #include "btnpairnotifier.h"
       
    30 #include "btNotifDebug.h"
       
    31 #include "btnotifnameutils.h"
       
    32 
       
    33 // ----------------------------------------------------------
       
    34 // CBTNPairNotifierBase::NewL
       
    35 // ----------------------------------------------------------
       
    36 //
       
    37 CBTNPairNotifierBase* CBTNPairNotifierBase::NewL()
       
    38     {
       
    39     CBTNPairNotifierBase* self = new (ELeave) CBTNPairNotifierBase();
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 // ----------------------------------------------------------
       
    47 // CBTNPairNotifierBase Destructor
       
    48 // ----------------------------------------------------------
       
    49 //
       
    50 CBTNPairNotifierBase::~CBTNPairNotifierBase()
       
    51     {
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------
       
    55 // CBTNPairNotifierBase default construct
       
    56 // ----------------------------------------------------------
       
    57 //
       
    58 CBTNPairNotifierBase::CBTNPairNotifierBase()
       
    59     :iLocallyInitiated(EFalse)
       
    60     {
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------
       
    64 // CBTNPairNotifierBase::RegisterL
       
    65 // ----------------------------------------------------------
       
    66 //
       
    67 CBTNPairNotifierBase::TNotifierInfo CBTNPairNotifierBase::RegisterL()
       
    68     {
       
    69     return iInfo;
       
    70     }
       
    71 
       
    72 // ----------------------------------------------------------
       
    73 // CBTNPairNotifierBase::GetParamsL
       
    74 // ----------------------------------------------------------
       
    75 //
       
    76 void CBTNPairNotifierBase::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
    77     {
       
    78     (void)aBuffer;
       
    79     if( !iMessage.IsNull() )
       
    80         {
       
    81         User::Leave(KErrInUse);
       
    82         }
       
    83     else if ( AutoLockOnL() )
       
    84         {
       
    85         // The phone is locked, access denied.
       
    86         //
       
    87         CompleteMessage(KErrCancel);
       
    88         return;
       
    89         }
       
    90 
       
    91     iMessage = (RMessage2)aMessage;
       
    92     iReplySlot = aReplySlot;
       
    93     }
       
    94 
       
    95 // ----------------------------------------------------------
       
    96 // CBTNPairNotifierBase::UpdateL
       
    97 // ----------------------------------------------------------
       
    98 //
       
    99 void CBTNPairNotifierBase::UpdateL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   100     {
       
   101     (void) aReplySlot;
       
   102     UpdateL(aBuffer);
       
   103     aMessage.Complete(KErrNone);
       
   104     }
       
   105 
       
   106 // ----------------------------------------------------------
       
   107 // CBTNPairNotifierBase::UpdateL
       
   108 // ----------------------------------------------------------
       
   109 //
       
   110 TPtrC8 CBTNPairNotifierBase::UpdateL( const TDesC8& aBuffer )
       
   111     {
       
   112     FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::UpdateL()"));
       
   113 
       
   114     TBTDeviceNameUpdateParamsPckg pckg;
       
   115     pckg.Copy( aBuffer );
       
   116     if (pckg().Type() != TBTNotifierUpdateParams2::EDeviceName)
       
   117         {
       
   118         TPtrC8 ret(KNullDesC8);
       
   119         return (ret);
       
   120         }
       
   121 
       
   122     if (pckg().Result() == KErrNone)
       
   123         {
       
   124         BtNotifNameUtils::SetDeviceNameL(pckg().DeviceName(), *iDevice);
       
   125 
       
   126     // Finally show new prompt for dialog if it is still on the screen
       
   127     // and user has not given a alias for device.   
       
   128         if( !iNotifUiUtil->IsQueryReleased() && !iDevice->IsValidFriendlyName() )
       
   129             {
       
   130             HBufC* prompt = GenerateQueryPromoptLC();
       
   131             iNotifUiUtil->UpdateQueryDlgL( *prompt );
       
   132             CleanupStack::PopAndDestroy( prompt );
       
   133             }
       
   134         }
       
   135 
       
   136     FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::UpdateL() completed"));
       
   137     TPtrC8 ret(KNullDesC8);
       
   138     return (ret);
       
   139     }
       
   140 
       
   141 // ----------------------------------------------------------
       
   142 // CBTNPairNotifierBase::ProcessParamsGetDeviceL
       
   143 // Get device from registry based on notifier's param
       
   144 // ----------------------------------------------------------
       
   145 //
       
   146 void CBTNPairNotifierBase::ProcessParamsGetDeviceL( const TBTDevAddr& aAddr, const TBTDeviceName& aName )
       
   147     {
       
   148     iDevice = CBTDevice::NewL(aAddr);
       
   149     BtNotifNameUtils::SetDeviceNameL(aName, *iDevice);
       
   150 
       
   151     // Get all properties of device from registry. 
       
   152     GetDeviceFromRegL( aAddr ); 
       
   153     
       
   154 #ifdef _DEBUG
       
   155     FTRACE(FPrint(_L("[BTNOTIF]\t Executing authentication... Parameters:")));
       
   156     TBuf<12> deviceAddressString;
       
   157     aAddr.GetReadable(deviceAddressString);
       
   158     FTRACE(FPrint(_L("[BTNOTIF]\t BT Address: %S"), &deviceAddressString));
       
   159 #endif
       
   160     }
       
   161 
       
   162 // ----------------------------------------------------------
       
   163 // CBTNPairNotifierBase::CheckBlockedDeviceL
       
   164 // Forbid pairing from remote banned devices
       
   165 // ----------------------------------------------------------
       
   166 //
       
   167 TBool CBTNPairNotifierBase::CheckBlockedDeviceL()
       
   168     {
       
   169     if ( !iDevice )
       
   170         {
       
   171         User::Leave( KErrGeneral );
       
   172         }
       
   173 
       
   174     // Do not allow pairing attempt from banned devices
       
   175     if( iDevice->GlobalSecurity().Banned() && !iLocallyInitiated )
       
   176        {
       
   177        FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::CheckBlockedDeviceL() Pairing attempt from banned device is denied.")); 
       
   178        CompleteMessage(KErrCancel);       
       
   179        return ETrue;
       
   180        }
       
   181     return EFalse;
       
   182     }
       
   183 
       
   184 // ----------------------------------------------------------
       
   185 // CBTNPairNotifierBase::AuthoriseIncomingPairingL
       
   186 // Query user to authorise imcoming pair request or not.
       
   187 // If reject, query whether to block the remot device. 
       
   188 // ----------------------------------------------------------
       
   189 //
       
   190 TBool CBTNPairNotifierBase::AuthoriseIncomingPairingL()
       
   191     {
       
   192     FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::AuthoriseIncomingPairingL() >>"));
       
   193     
       
   194     // Start pairing observer so that user will be informed about the result:
       
   195     TInt err = CBTEngConnMan::StartPairingObserver( iBTAddr );
       
   196     if ( err )
       
   197         {
       
   198         // Failed to start observer because of other ongoing pairing,
       
   199         // reject this request:
       
   200         CompleteMessage( err );
       
   201         return EFalse;            
       
   202         }
       
   203     
       
   204     TBTDeviceName devName;
       
   205     BtNotifNameUtils::GetDeviceDisplayName( devName, iDevice );
       
   206     HBufC* prompt = StringLoader::LoadLC( R_BT_ACCEPT_PAIRING_REQUEST, devName );   
       
   207 
       
   208     TBTDeviceName nameCoverUi( KNullDesC );
       
   209     // Show query for use to accept/reject incoming pairing request
       
   210     TInt keypress = iNotifUiUtil->ShowQueryL( *prompt, R_BT_GENERIC_QUERY, 
       
   211              ECmdBTnotifUnavailable, nameCoverUi, CAknQueryDialog::EConfirmationTone );
       
   212     CleanupStack::PopAndDestroy( prompt );
       
   213 
       
   214     if( iMessage.IsNull() ) // cancelled by the stack
       
   215         {
       
   216         return EFalse;
       
   217         }
       
   218     else if( !keypress ) // User rejected pairing
       
   219         {
       
   220         FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase: user rejected incoming pairing"));
       
   221         // stop observer to omit pairing failure note.
       
   222         CBTEngConnMan::StopPairingObserver( iDevice->BDAddr() );
       
   223         iDevice->SetPaired(EFalse);
       
   224         CheckAndHandleQueryIntervalL();
       
   225         if( !iMessage.IsNull() )
       
   226             {
       
   227             // Ask user does he/she wishes to block this device (if not canceled because the 
       
   228             // frequency is too high).
       
   229             QueryBlockDeviceL();
       
   230             }
       
   231         return EFalse;
       
   232         }
       
   233 
       
   234     FLOG(_L("[BTNOTIF]\t CBTNPairNotifierBase::AuthoriseIncomingPairingL() << "));
       
   235     return ETrue;
       
   236     }
       
   237 
       
   238 // ----------------------------------------------------------
       
   239 // CBTNPairNotifierBase::GenerateQueryPromoptLC
       
   240 // To be implemented in derived classes.
       
   241 // ----------------------------------------------------------
       
   242 //
       
   243 HBufC* CBTNPairNotifierBase::GenerateQueryPromoptLC()
       
   244     {
       
   245     return NULL;
       
   246     }