bluetoothengine/btnotif/src/BTNAuthNotifier.cpp
changeset 42 b72428996822
parent 32 19bd632b5100
child 43 7d241e669870
equal deleted inserted replaced
32:19bd632b5100 42:b72428996822
     1 /*
       
     2 * Copyright (c) 2002 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:  Implements authorisation notifier class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <BTNotif.rsg>       // Own resources
       
    21 #include "btnauthnotifier.h" // Own class definition
       
    22 #include "btNotifDebug.h"    // Debugging macros
       
    23 #include <btextnotifiers.h>
       
    24 #include <AknMediatorFacade.h> // Cover UI
       
    25 #include <secondarydisplay/BTnotifSecondaryDisplayAPI.h>
       
    26 #include <btengconstants.h>
       
    27 #include <btengsettings.h>
       
    28 #include <e32cmn.h>
       
    29 #include <btotgpairpub.inl>
       
    30 #include <btengprivatecrkeys.h>
       
    31 #include <e32property.h>
       
    32 #include <e32const.h>
       
    33 #include <e32des8.h>
       
    34 #include <e32cmn.h>
       
    35 #include <utf.h> // Unicode character conversion utilities
       
    36 #include <btengutil.h>
       
    37 #ifdef __SERIES60_HELP
       
    38 #include <hlplch.h>
       
    39 #include <csxhelp/bt.hlp.hrh> // The bt hrh info is needed, for help launching
       
    40 #endif
       
    41 #include <bluetoothuiutil.h>
       
    42 #include "btnotifnameutils.h"
       
    43 
       
    44 
       
    45 //
       
    46 // SDP UUID Constants - Short form
       
    47 // Taken from Bluetooth Profile specification v1.1
       
    48 // These are used when registering the service to
       
    49 // local SDP database and when searching the service
       
    50 // information from remote device.
       
    51 const TUint KBTSdpDun                   = 0x1103;
       
    52 const TUint KBTSdpGenericTelephony      = 0x1204;
       
    53 const TUint KBTSdpFax                   = 0x1111;
       
    54 const TUint KBTSdpObjectPush            = 0x1105;
       
    55 const TUint KBTSdpFileTransfer          = 0x1106;
       
    56 const TUint KBTSdpHeadSet               = 0x1108;
       
    57 const TUint KBTSdpGenericNetworking     = 0x1201;
       
    58 const TUint KBTSdpBasicImaging          = 0x111b;
       
    59 
       
    60 /**  Identification for active object */
       
    61 const TInt KBTNotifAuthNotifierLockReq = 10;
       
    62 
       
    63 // ================= MEMBER FUNCTIONS =======================
       
    64 
       
    65 // ----------------------------------------------------------
       
    66 // CBTAuthNotifier::NewL
       
    67 // Two-phased constructor.
       
    68 // ----------------------------------------------------------
       
    69 //
       
    70 CBTAuthNotifier* CBTAuthNotifier::NewL()
       
    71     {
       
    72     CBTAuthNotifier* self = new (ELeave) CBTAuthNotifier();
       
    73     CleanupStack::PushL(self);
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop();
       
    76     return self;
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------------
       
    80 // CBTAuthNotifier::CBTAuthNotifier
       
    81 // C++ default constructor can NOT contain any code, that
       
    82 // might leave.
       
    83 // ----------------------------------------------------------
       
    84 //
       
    85 CBTAuthNotifier::CBTAuthNotifier()
       
    86     {
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------------
       
    90 // Destructor
       
    91 // ----------------------------------------------------------
       
    92 //
       
    93 CBTAuthNotifier::~CBTAuthNotifier()
       
    94     {
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------
       
    98 // CBTAuthNotifier::RegisterL
       
    99 // ----------------------------------------------------------
       
   100 //
       
   101 CBTAuthNotifier::TNotifierInfo CBTAuthNotifier::RegisterL()
       
   102     {
       
   103     iInfo.iUid=KBTManAuthNotifierUid;
       
   104     iInfo.iChannel=KBTAuthorisationChannel;
       
   105     iInfo.iPriority=ENotifierPriorityVHigh;
       
   106     return iInfo;
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------
       
   110 // CBTAuthNotifier::GetParamsL
       
   111 // Initialize parameters and check if device is already
       
   112 // in registry. Jump to RunL as soon as possible.
       
   113 // ----------------------------------------------------------
       
   114 //
       
   115 void CBTAuthNotifier::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   116     {
       
   117     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::GetParamsL()"));
       
   118 
       
   119     if( !iMessage.IsNull())
       
   120         {
       
   121         User::Leave(KErrInUse);
       
   122         }
       
   123 
       
   124     iMessage = aMessage;
       
   125     iReplySlot = aReplySlot;
       
   126 
       
   127     if ( AutoLockOnL() )
       
   128         {
       
   129         // The phone is locked, access denied.
       
   130         // Write results back to caller and complete message.	
       
   131 	CompleteMessage(EFalse, KErrNone);	
       
   132         return;
       
   133         }
       
   134     
       
   135     TBTAuthorisationParams param;
       
   136     TPckgC<TBTAuthorisationParams> pckg(param);
       
   137     pckg.Set(aBuffer);
       
   138 
       
   139     iServiceUid = pckg().iUid.iUid;  // Pick up service uid from message
       
   140     iBTAddr = pckg().iBDAddr;
       
   141     if ( OtherOutgoPairing( iBTAddr ) )
       
   142         {
       
   143         // We won't allow connection request from another device during outgoing pairing:
       
   144         FLOG(_L("[BTNOTIF]\t CBTAuthNotifier: outgoing pair in progress, reject request from other device"));
       
   145         CompleteMessage(KErrCancel);
       
   146         return;
       
   147         }	
       
   148  	
       
   149     // create iDevice so that the name won't be lost if the device does
       
   150     // not exist in registry.
       
   151     iDevice = CBTDevice::NewL( iBTAddr );
       
   152     BtNotifNameUtils::SetDeviceNameL(pckg().iName, *iDevice);
       
   153 
       
   154     if ( !iNotifLockProp.Handle() )
       
   155         {
       
   156         User::LeaveIfError( iNotifLockProp.Attach( 
       
   157                 KPSUidBluetoothEnginePrivateCategory, KBTNotifierLocks ) );
       
   158         }
       
   159     
       
   160     if(!iLockActive)
       
   161         {
       
   162         iLockActive = CBTNotifActive::NewL( this, KBTNotifAuthNotifierLockReq, CActive::EPriorityStandard );
       
   163         }
       
   164 
       
   165     CheckAndSubscribeNotifLocks();
       
   166     
       
   167     if ( !iSuspended )
       
   168         {
       
   169         // Check if device is in the registry, function of notifier base  
       
   170         GetDeviceFromRegL( iBTAddr );
       
   171         }
       
   172 
       
   173 #ifdef _DEBUG
       
   174     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::GetParamsL() Executing authorisation..."));
       
   175     TBuf<12> deviceAddressString;
       
   176     pckg().iBDAddr.GetReadable(deviceAddressString);
       
   177     FTRACE(FPrint(_L("[BTNOTIF]\t  BT Address: %S"), &deviceAddressString));
       
   178     FTRACE(FPrint(_L("[BTNOTIF]\t CBTAuthNotifier::GetParamsL Service Uid: %d = 0x%X"), iServiceUid, iServiceUid ));
       
   179 #endif
       
   180     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::GetParamsL() completed"));
       
   181     }
       
   182 
       
   183 // ----------------------------------------------------------
       
   184 // CBTAuthNotifier::UpdateL
       
   185 // Notifier update. Stores the received bluetooth
       
   186 // device name into registry and show it on screen.
       
   187 // ----------------------------------------------------------
       
   188 //
       
   189 TPtrC8 CBTAuthNotifier::UpdateL(const TDesC8& aBuffer)
       
   190     {
       
   191     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::UpdateL()"));
       
   192 
       
   193     TBTNotifierUpdateParams params; // Contains iName and iResult (name request)
       
   194     TPckgC<TBTNotifierUpdateParams> pckg(params);
       
   195     pckg.Set(aBuffer);
       
   196 
       
   197     FTRACE(FPrint(_L("[BTNOTIF]\t CBTAuthNotifier::UpdateL - Name: '%S' length: %d"), &pckg().iName, pckg().iName.Length() ));
       
   198 
       
   199 
       
   200     // If the device name request was successful and if new name is valid, show the new name.
       
   201     if (pckg().iResult == KErrNone)
       
   202         {
       
   203         BtNotifNameUtils::SetDeviceNameL(pckg().iName, *iDevice); // Override possible previous device name
       
   204 
       
   205         // Show new prompt for dialog if it is still on the screen
       
   206         if ( !iDevice->IsValidFriendlyName() && iDevice->IsValidDeviceName())
       
   207             {
       
   208             // Create new prompt string with new device name
       
   209             RBuf stringholder;
       
   210             CleanupClosePushL( stringholder );
       
   211             BluetoothUiUtil::LoadResourceAndSubstringL( 
       
   212                     stringholder, iStrResourceId, 
       
   213                     BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName()), 0 );
       
   214             iNotifUiUtil->UpdateQueryDlgL( stringholder );
       
   215             iNotifUiUtil->UpdateCoverUiL( iDevice->DeviceName() );
       
   216             CleanupStack::PopAndDestroy();  // stringholder
       
   217             }
       
   218         }
       
   219     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::UpdateL() completed"));
       
   220     TPtrC8 ret(KNullDesC8);
       
   221     return (ret);
       
   222     }
       
   223 
       
   224 // ----------------------------------------------------------
       
   225 // CBTAuthNotifier::RequestCompletedL
       
   226 // Gets called when P&S key notifies change
       
   227 // ----------------------------------------------------------
       
   228 void CBTAuthNotifier::RequestCompletedL( CBTNotifActive* aActive, TInt aId, TInt aStatus )
       
   229     {
       
   230     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::RequestCompletedL()"));
       
   231     ASSERT( aId == KBTNotifAuthNotifierLockReq );
       
   232     (void) aActive;
       
   233     (void) aId;
       
   234     
       
   235     if ( aStatus == KErrNone )
       
   236         {
       
   237         TBool prevSuspend = iSuspended;
       
   238         // check the latest lock status and subscribe to further lock event:
       
   239         CheckAndSubscribeNotifLocks();
       
   240         if ( prevSuspend && !iSuspended )
       
   241             {
       
   242             // Check if device is in the registry, function of notifier base  
       
   243             GetDeviceFromRegL( iBTAddr ); 
       
   244             }
       
   245         else if ( iSuspended && !(iNotifUiUtil->IsQueryReleased()) )
       
   246             {
       
   247             iNotifUiUtil->DismissDialog();
       
   248             }
       
   249         }
       
   250     else
       
   251         {
       
   252         HandleError( aActive, KBTNotifAuthNotifierLockReq, iLockActive->RequestStatus().Int() );
       
   253         }
       
   254         
       
   255     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::RequestCompletedL() completed"));
       
   256     
       
   257     }
       
   258 
       
   259 // ----------------------------------------------------------
       
   260 // CBTAuthNotifier::HandleError
       
   261 // ----------------------------------------------------------
       
   262 void CBTAuthNotifier::HandleError( CBTNotifActive* aActive, TInt aId, TInt aError )
       
   263     {
       
   264     FTRACE(FPrint(_L("[BTNOTIF]\t CBTAuthNotifier::HandleError() error = %d"), aError ));
       
   265     (void) aActive;
       
   266     (void) aId;
       
   267     (void) aError;
       
   268     }
       
   269 
       
   270 // ----------------------------------------------------------
       
   271 // CBTAuthNotifier::DoCancelRequest
       
   272 // Root caller is CBTNotifActive::CancelRequest(), which calls 
       
   273 // CActive::Cancel that calls DoCancel() if request is active.
       
   274 // ----------------------------------------------------------
       
   275 void CBTAuthNotifier::DoCancelRequest( CBTNotifActive* aActive, TInt aId )
       
   276     {
       
   277     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::DoCancel() >>"));
       
   278     ASSERT( aId == KBTNotifAuthNotifierLockReq );
       
   279     (void) aActive;
       
   280     (void) aId;
       
   281     
       
   282     iNotifLockProp.Cancel();
       
   283     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::DoCancel() <<"));
       
   284     }
       
   285 	
       
   286 // ----------------------------------------------------------
       
   287 // CBTAuthNotifier::Cancel
       
   288 // Not Active Object's cancel, but notifier deactivation
       
   289 // Release all own resources (member variables)
       
   290 // ----------------------------------------------------------
       
   291 //
       
   292 void CBTAuthNotifier::Cancel()
       
   293     {
       
   294     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::Cancel()"));
       
   295     
       
   296     if (iLockActive)
       
   297         {
       
   298         iLockActive->CancelRequest();
       
   299         delete iLockActive;
       
   300         iLockActive = NULL;
       
   301         }
       
   302     
       
   303     iNotifLockProp.Close();
       
   304     
       
   305 	CBTNotifierBase::Cancel(); 
       
   306     
       
   307     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::Cancel() completed"));
       
   308     }
       
   309    
       
   310 void CBTAuthNotifier::HandleGetDeviceCompletedL(const CBTDevice* aDev)
       
   311 	{
       
   312 	FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::HandleGetDeviceCompleted()"));	
       
   313     (void) aDev;
       
   314     if ( iSuspended)
       
   315         {
       
   316         FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::HandleGetDeviceCompleted, still suspended, wait"));
       
   317         return;
       
   318         }
       
   319         
       
   320     TBool reqAllowed = IsJustWorksPaired( iDevice->AsNamelessDevice() ) ? 
       
   321         IsUserAwarePaired( iDevice->AsNamelessDevice() ) : ETrue ;
       
   322     FTRACE(FPrint(_L("[BTNOTIF]\t CBTAuthNotifier, reqAllowed %d" ), reqAllowed ) );
       
   323     if ( !reqAllowed )
       
   324         {
       
   325         // Do not grant access to device that is not paired in Just Works mode without
       
   326         // user awareness, e.g. pairing due to an incoming connection request from a 
       
   327         // headset.
       
   328         CompleteMessage(KErrAccessDenied);
       
   329         return;
       
   330         }
       
   331     
       
   332     iStrResourceId = R_BT_AUTHORISATION_NAME;
       
   333 
       
   334     // Select authorisation state for further use (dialogue selection)
       
   335     switch( iServiceUid )
       
   336         {
       
   337         case KBTSdpObjectPush:
       
   338         case KBTSdpBasicImaging: 
       
   339             iAuthState = EBTObexAuthorisation;
       
   340             iStrResourceId = R_BT_RECEIVE_MESSAGE;
       
   341             iCoverUiDlgId = ECmdShowReceiveMessageFromDeviceDlg;
       
   342             
       
   343             if( IsUserAwarePaired( iDevice->AsNamelessDevice() ) )
       
   344                 {
       
   345                 iAuthState = EBTObexAuthForPairedDevice;
       
   346                 iStrResourceId = R_BT_RECEIVE_MESSAGE_PAIRED;
       
   347                 iCoverUiDlgId = ECmdShowReceiveMessageFromPairedDeviceDlg; 
       
   348                 }
       
   349             break;
       
   350         case KBTSdpFax:
       
   351         case KBTSdpDun:
       
   352         case KBTSdpFileTransfer:
       
   353         case KBTSdpHeadSet:
       
   354         case KBTSdpGenericTelephony:
       
   355         case KBTSdpGenericNetworking:
       
   356             if ( iDevice->GlobalSecurity().NoAuthorise() )
       
   357                 {
       
   358                 iAuthState = EBTAutoAuthorisation;
       
   359                 }
       
   360             else
       
   361                 {
       
   362                 iAuthState = EBTNormalAuthorisation;
       
   363                 }
       
   364             iCoverUiDlgId = ECmdShowAcceptConnRequestDlg;
       
   365             break;
       
   366         default:
       
   367             { // check if device is authorized
       
   368             if ( iDevice->GlobalSecurity().NoAuthorise() )
       
   369                 {
       
   370                 iAuthState = EBTAutoAuthorisation;
       
   371                 }
       
   372             else
       
   373                 {
       
   374                 iAuthState = EBTAutoAuthorisationNotAuthorisedOnPhone;                        
       
   375                 }
       
   376             break;
       
   377             }
       
   378         }
       
   379     FTRACE(FPrint(_L("[BTNOTIF]\t CBTAuthNotifier::HandleGetDeviceComplete() Complete. iAuthState = %d"), iAuthState ));    
       
   380     ShowAuthoQueryL();
       
   381 	}
       
   382 
       
   383 // ----------------------------------------------------------
       
   384 // CBTAuthNotifier::GetByPassAudioNotifier
       
   385 // is bypassing this audio connection query needed and if it is, will the
       
   386 // query be automatically accepted or rejected.
       
   387 //
       
   388 // This is used for bypassing the notifiers of the 2nd audio connection, so
       
   389 // the the user needs to reply to the incoming audio link only once.
       
   390 // ----------------------------------------------------------
       
   391 //    
       
   392 TBool CBTAuthNotifier::GetByPassAudioNotifier(const TBTDevAddr& aDeviceAddress,TBool& aAccept)
       
   393 	{
       
   394 	FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::GetByPassAudioNotifier()"));	
       
   395 		TBuf8<48> buf;
       
   396 		
       
   397 		RProperty::Define(KPSUidBluetoothEnginePrivateCategory,KBTAuthorInfoPerDevice, RProperty::EByteArray );
       
   398 		RProperty::Get(KPSUidBluetoothEnginePrivateCategory,KBTAuthorInfoPerDevice,buf);
       
   399 
       
   400 		if(buf.Length()>2)
       
   401 			{
       
   402 			// accept status of last attempt			
       
   403 			aAccept= (buf[0]=='1');
       
   404 
       
   405 			// last address						
       
   406 			TBuf<12> oldAddrString;
       
   407 			oldAddrString.Copy(buf.Mid(2,12));
       
   408 			TBTDevAddr lastAddress;
       
   409 			lastAddress.SetReadable(oldAddrString);
       
   410 			
       
   411 			// last time
       
   412 			TInt64 num(0);
       
   413 			TLex8 lex;			
       
   414 			lex=buf.Mid(15);	
       
   415 			TBuf<32> tmp_debug;
       
   416 			tmp_debug.Copy(buf.Mid(15));
       
   417 				
       
   418 			lex.Val( num );
       
   419 			TTime lastConnectionTime( num );
       
   420 			TTime now;			
       
   421 			now.UniversalTime();			
       
   422 
       
   423 			TBuf16<48> buf2;
       
   424 			buf2.Copy(buf);
       
   425 			
       
   426 			FTRACE(FPrint(_L("[BTNOTIF]\t CBTAuthNotifier::GetByPassAudioNotifier() Complete same_address=%d Time_ok=%d last_reply=%d"),lastAddress==aDeviceAddress,now>=lastConnectionTime && now <lastConnectionTime+ TTimeIntervalSeconds(5),aAccept));	
       
   427 			return lastAddress==aDeviceAddress && (now>=lastConnectionTime && now <lastConnectionTime+ TTimeIntervalSeconds(5) );		
       
   428 			}
       
   429 		FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::GetByPassAudioNotifier() Complete - empty key"));				
       
   430 		return EFalse;
       
   431 	}
       
   432 // ----------------------------------------------------------
       
   433 // CBTAuthNotifier::MemorizeCurrentAudioAttempt
       
   434 // Store the information about this audio connection attempt 
       
   435 // and what user replied to that. This is used by
       
   436 // GetBypassAudio Notifier.
       
   437 // ----------------------------------------------------------
       
   438 //    
       
   439     			
       
   440 void CBTAuthNotifier::MemorizeCurrentAudioAttempt(const TBool aAccept,const TBTDevAddr& aDeviceAddress)    			
       
   441 	{
       
   442 	FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::MemorizeCurrentAudioAttempt()"));	
       
   443 	TBuf8<48> buf;
       
   444 	buf.Zero();
       
   445 	buf.AppendNum(aAccept!=EFalse);//now 0/1 only.
       
   446 	buf.Append(';');
       
   447 	
       
   448 	TBuf<12> a;
       
   449 	aDeviceAddress.GetReadable(a);
       
   450 	for(TInt t=0;t<12;t++)
       
   451 		buf.Append(a[t]);
       
   452 	buf.Append(';');		
       
   453 
       
   454 	TTime writeTime;
       
   455 	writeTime.UniversalTime();		
       
   456 	buf.AppendNum(  writeTime.Int64()  );
       
   457 	
       
   458 	RProperty::Set(KPSUidBluetoothEnginePrivateCategory,KBTAuthorInfoPerDevice,buf);
       
   459 	FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::MemorizeCurrentAudioAttempt() complete"));	
       
   460 	}
       
   461 
       
   462 
       
   463 // ----------------------------------------------------------
       
   464 // CBTAuthNotifier::ShowAuthoQueryL
       
   465 // Ask user's response on authorization query
       
   466 // ----------------------------------------------------------
       
   467 // 
       
   468 void CBTAuthNotifier::ShowAuthoQueryL()
       
   469     {
       
   470     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::ShowAuthoQueryL"));
       
   471     
       
   472     if ( iAuthState == EBTAutoAuthorisation )
       
   473         {
       
   474         // device alreay set trusted now. allow connection automatically       
       
   475         CompleteMessage(ETrue, KErrNone);        
       
   476         FLOG(_L("[BTNOTIF]\t CBTAuthNotifier, device authorized already, allow connection automatically" ));
       
   477         return;
       
   478         }
       
   479 
       
   480     TBool reply;
       
   481     if ( GetByPassAudioNotifier(iDevice->BDAddr(),reply) )
       
   482         {
       
   483         FTRACE(FPrint(_L("[BTNOTIF]\t CBTAuthNotifier::ShowAuthoQueryL bypassing notifier with reply: %d"),reply));          
       
   484         CompleteMessage(reply, KErrNone);
       
   485         return;
       
   486         }
       
   487 
       
   488     // Not asking user's response if auth request is for: profile HFP/HSP/A2DP/AVRCP, and
       
   489     // there is already existing connection to one of those profiles from the same device.
       
   490     // 
       
   491     TBool connectStatus = IsExistingConnectionToAudioL( iDevice->BDAddr() );  
       
   492     // if iAuthState==EBTAutoAuthorisationNotAuthorised and device is connected it means it tries several connections
       
   493     // so we just approve this. Also if connected & EBTAutoAuthorisation.
       
   494     //                              
       
   495     if(connectStatus && ( iAuthState==EBTAutoAuthorisationNotAuthorisedOnPhone))                                         
       
   496         {
       
   497         FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::Automatic authorisation ()"));
       
   498         //Antomatic authorisation without asking user           
       
   499         CompleteMessage(ETrue, KErrNone);   
       
   500         FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::ShowAuthoQueryL() completed-"    ));     
       
   501         return;                 
       
   502         }
       
   503 
       
   504     // check if we're showing bt off query
       
   505     TInt queryValue=EBTQueryOff;
       
   506     RProperty::Get(KPSUidBluetoothEnginePrivateCategory,KBTTurnBTOffQueryOn,queryValue);                
       
   507     if( queryValue == EBTQueryOn )
       
   508         {
       
   509         CompleteMessage(KErrCancel);
       
   510         return;
       
   511         }
       
   512 
       
   513     TBTDeviceName tempDeviceName; 
       
   514     BtNotifNameUtils::GetDeviceDisplayName(tempDeviceName, iDevice);
       
   515     RBuf stringholder;
       
   516     CleanupClosePushL( stringholder );
       
   517     BluetoothUiUtil::LoadResourceAndSubstringL( 
       
   518             stringholder, iStrResourceId, tempDeviceName, 0);
       
   519     TInt keypress = iNotifUiUtil->ShowQueryL( stringholder, R_BT_AUTHORISATION_QUERY, 
       
   520             iCoverUiDlgId, tempDeviceName, CAknQueryDialog::EConfirmationTone );
       
   521     CleanupStack::PopAndDestroy();  // stringholder
       
   522     // If this notifier is cancelled by the caller, no need to perform the rest operation:
       
   523     if ( iSuspended || iMessage.IsNull() )
       
   524         {
       
   525         return;
       
   526         }
       
   527     
       
   528     if( keypress )  // User has accepted the dialog
       
   529         {
       
   530         if( iDevice && !iDevice->IsValidLinkKey() )
       
   531             {               
       
   532             TTime now;
       
   533             now.UniversalTime();
       
   534             TBuf8<32> buf;
       
   535             buf.AppendNum(  now.Int64()  );             
       
   536             RProperty::Set(KPSUidBluetoothEnginePrivateCategory,KBTConnectionTimeStamp,buf);                
       
   537             }
       
   538         
       
   539         MemorizeCurrentAudioAttempt(ETrue,iDevice->BDAddr() );
       
   540         CompleteMessage( ETrue, KErrNone );
       
   541         }
       
   542     else // User has rejected the dialog.
       
   543         {
       
   544         iLockActive->CancelRequest();
       
   545         DoRejectAuthorizationL();
       
   546         }
       
   547     }
       
   548 
       
   549 
       
   550 // ----------------------------------------------------------
       
   551 // CBTAuthNotifier::DoRejectAuthorizationL
       
   552 // Handle query threshold and block after user rejects authorization
       
   553 // ----------------------------------------------------------
       
   554 //
       
   555 void CBTAuthNotifier::DoRejectAuthorizationL()
       
   556     {
       
   557     FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::DoRejectAuthorizationL()"));
       
   558     
       
   559     CheckAndHandleQueryIntervalL();
       
   560     if( iMessage.IsNull() )
       
   561         {
       
   562         return; // No need to continue.
       
   563         }
       
   564 
       
   565     MemorizeCurrentAudioAttempt(EFalse,iDevice->BDAddr());
       
   566     
       
   567     //Logic: query block only at the second time for the same paired device
       
   568     //       query block everytime after rejection for non-paired device.
       
   569     if( IsPaired( iDevice->AsNamelessDevice() ) )
       
   570         {
       
   571         FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::DoRejectAuthorizationL() rejected a paired device."));            
       
   572         
       
   573         TBuf<2*KBTDevAddrSize> tmp; //2 hex digits per byte
       
   574         RProperty::Get(KPSUidBluetoothEnginePrivateCategory, KBTBlockDevAddr, tmp);
       
   575         TBTDevAddr priorDeviceaddress;
       
   576         priorDeviceaddress.Reset();
       
   577         priorDeviceaddress.SetReadable(tmp);
       
   578         
       
   579         if(priorDeviceaddress != iDevice->BDAddr() )                            
       
   580             {
       
   581             FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::DoRejectAuthorizationL() NOT the prior rejected device, no block query."));           
       
   582             
       
   583             // The last device was not current device,
       
   584             // so the last device is updated to be current device.                  
       
   585             iDevice->BDAddr().GetReadable(tmp);
       
   586             RProperty::Set(KPSUidBluetoothEnginePrivateCategory, KBTBlockDevAddr, tmp );
       
   587 
       
   588             // Complete message and free resources
       
   589             CompleteMessage(EFalse, KErrNone);
       
   590             FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::DoRejectAuthorizationL() completed"));
       
   591             return;
       
   592             }
       
   593         else 
       
   594             {
       
   595             FLOG(_L("[BTNOTIF]\t CBTAuthNotifier::DoRejectAuthorizationL() IS SAME as the prior rejected device."));           
       
   596             
       
   597             // this was 2nd time in row. Clear the key, so the question will not be made next time.
       
   598             TBuf<2*KBTDevAddrSize> tmp;                 
       
   599             TBTDevAddr emptyAddr;
       
   600             emptyAddr.Reset();
       
   601             emptyAddr.GetReadable(tmp);                 
       
   602             RProperty::Set(KPSUidBluetoothEnginePrivateCategory, KBTBlockDevAddr, tmp );
       
   603             }
       
   604         }
       
   605         
       
   606     // Ask user to Block this device or not.
       
   607     if( !iMessage.IsNull() )
       
   608         {
       
   609         QueryBlockDeviceL();
       
   610         }
       
   611     }
       
   612 
       
   613 // ----------------------------------------------------------
       
   614 // CBTAuthNotifier::CheckAndSubscribeNotifLocks
       
   615 // Subscribe to PS key and check key value.
       
   616 // ----------------------------------------------------------
       
   617 //
       
   618 void CBTAuthNotifier::CheckAndSubscribeNotifLocks()
       
   619     {
       
   620     if ( !iLockActive->IsActive() )
       
   621         {
       
   622         FLOG(_L("[BTNOTIF]\t CBTAuthNotifier, Subscribe Device Operation Info"));
       
   623         iNotifLockProp.Subscribe( iLockActive->RequestStatus() );
       
   624         iLockActive->GoActive();
       
   625         }
       
   626     TInt ops;
       
   627     TBTNotifLockPublish::GetNotifLocks( iNotifLockProp, 
       
   628             ops, iBTAddr );
       
   629     iSuspended = ops & EBTNotiferLockPairedDeviceSetting;
       
   630     FTRACE(FPrint(_L("[BTNOTIF]\t CBTAuthNotifier suspended ? %d"), iSuspended ));    
       
   631     }
       
   632 
       
   633 
       
   634 // End of File