bluetoothengine/btnotif/btnotifsrv/src/btnotifserviceauthorizer.cpp
changeset 41 0b2439c3e397
parent 40 997690c3397a
child 52 4545c04e61e1
equal deleted inserted replaced
40:997690c3397a 41:0b2439c3e397
    63         // Clear the notification callback, we cannot receive them anymore.
    63         // Clear the notification callback, we cannot receive them anymore.
    64         iNotification->RemoveObserver();
    64         iNotification->RemoveObserver();
    65         iNotification->Close(); // Also dequeues the notification from the queue.
    65         iNotification->Close(); // Also dequeues the notification from the queue.
    66         iNotification = NULL;
    66         iNotification = NULL;
    67         }
    67         }
       
    68     if ( !iNotifierMessage.IsNull() )
       
    69         {
       
    70         iNotifierMessage.Complete( KErrServerTerminated );
       
    71         }
    68     }
    72     }
    69 
    73 
    70 CBTNotifServiceAuthorizer::CBTNotifServiceAuthorizer(
    74 CBTNotifServiceAuthorizer::CBTNotifServiceAuthorizer(
    71                                         CBTNotifSecurityManager& aParent)
    75                                         CBTNotifSecurityManager& aParent)
    72 :iParent(aParent)
    76 :iParent(aParent)
    90             }
    94             }
    91         BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNotif]:We are busy");
    95         BOstrace0(TRACE_DEBUG,DUMMY_DEVLIST,"[BTNotif]:We are busy");
    92         User::Leave(KErrServerBusy );
    96         User::Leave(KErrServerBusy );
    93         }
    97         }
    94 
    98 
    95     iParams.CreateL( aMessage.GetDesLengthL( EBTNotifSrvParamSlot ) );
    99     iParams.ReAllocL( aMessage.GetDesLengthL( EBTNotifSrvParamSlot ) );
    96     aMessage.ReadL( EBTNotifSrvParamSlot, iParams );
   100     aMessage.ReadL( EBTNotifSrvParamSlot, iParams );
    97     
   101     
    98     TBTAuthorisationParams params;
   102     TBTAuthorisationParams params;
    99     TPckgC<TBTAuthorisationParams> paramsPckg( params );
   103     TPckgC<TBTAuthorisationParams> paramsPckg( params );
   100     paramsPckg.Set( iParams );
   104     paramsPckg.Set( iParams );
   128     iPairedDevice = (dev == NULL ) ? EFalse : dev->IsUserAwareBonded();
   132     iPairedDevice = (dev == NULL ) ? EFalse : dev->IsUserAwareBonded();
   129     iDeviceClass = (dev == NULL ) ? 0 : dev->Device().DeviceClass().DeviceClass();
   133     iDeviceClass = (dev == NULL ) ? 0 : dev->Device().DeviceClass().DeviceClass();
   130     TBTNotifUtil::GetDeviceUiNameL(iCurrentDeviceName, 
   134     TBTNotifUtil::GetDeviceUiNameL(iCurrentDeviceName, 
   131             dev, paramsPckg().iName, paramsPckg().iBDAddr );
   135             dev, paramsPckg().iName, paramsPckg().iBDAddr );
   132 
   136 
   133     PrepareNotificationL(TBluetoothDialogParams::EUserAuthorization, EAuthorization, iPairedDevice);
   137     TBool autoAuthorize;
   134     iNotification->ShowL();
   138     PrepareNotificationL(autoAuthorize,
   135     // we do not save the message until all leavable functions have executed successfully.
   139             TBluetoothDialogParams::EUserAuthorization, 
   136     // This makes sure the iNotifierMessage has a valid handle.
   140             EAuthorization, iPairedDevice);
   137     iNotifierMessage = aMessage;
   141     if ( autoAuthorize ) 
       
   142         {
       
   143         TPckgBuf<TBool> answer; 
       
   144         answer() = ETrue;
       
   145         aMessage.Write(EBTNotifSrvReplySlot, answer);
       
   146         aMessage.Complete(KErrNone);
       
   147         }
       
   148     else 
       
   149         {
       
   150         iNotification->ShowL();
       
   151         // we do not save the message until all leavable functions have executed successfully.
       
   152         // This makes sure the iNotifierMessage has a valid handle.
       
   153         iNotifierMessage = aMessage;
       
   154         }
   138     }
   155     }
   139 
   156 
   140 void CBTNotifServiceAuthorizer::MBRDataReceived( CHbSymbianVariantMap& aData )
   157 void CBTNotifServiceAuthorizer::MBRDataReceived( CHbSymbianVariantMap& aData )
   141     {
   158     {
   142     // "actionResult" will be true if the user clicks 'Yes' on the dialog and false, if he/she clicks 'No'
   159     // "actionResult" will be true if the user clicks 'Yes' on the dialog and false, if he/she clicks 'No'
   171                 
   188                 
   172                 //Set the device "Blocked" property
   189                 //Set the device "Blocked" property
   173                 iParent.BlockDevice(paramsPckg().iBDAddr,ETrue);
   190                 iParent.BlockDevice(paramsPckg().iBDAddr,ETrue);
   174                 }
   191                 }
   175             }
   192             }
   176         iNotifierMessage.Write(EBTNotifSrvReplySlot, answer);
   193         if ( !iNotifierMessage.IsNull() )
   177         iNotifierMessage.Complete(KErrNone);
   194             {
       
   195             iNotifierMessage.Write(EBTNotifSrvReplySlot, answer);
       
   196             iNotifierMessage.Complete(KErrNone);
       
   197             }
   178         }
   198         }
   179     else if(aData.Keys().MdcaPoint(0).Compare(_L("checkBoxState")) == 0)
   199     else if(aData.Keys().MdcaPoint(0).Compare(_L("checkBoxState")) == 0)
   180         {
   200         {
   181         iCheckBoxState = *(static_cast<TInt*>(aData.Get(_L("checkBoxState"))->Data()));
   201         iCheckBoxState = *(static_cast<TInt*>(aData.Get(_L("checkBoxState"))->Data()));
   182         }
   202         }
   183     }
   203     }
   184 
   204 
   185 void CBTNotifServiceAuthorizer::MBRNotificationClosed( TInt /*aError*/, const TDesC8& /*aData*/ )
   205 void CBTNotifServiceAuthorizer::MBRNotificationClosed( TInt aError, const TDesC8& aData )
   186     {
   206     {
   187     }
   207     (void) aError;
   188 
   208     (void) aData;
   189 void CBTNotifServiceAuthorizer::PrepareNotificationL(TBluetoothDialogParams::TBTDialogType aType,
   209     iNotification->RemoveObserver();
       
   210     iNotification = NULL;
       
   211     }
       
   212 
       
   213 void CBTNotifServiceAuthorizer::PrepareNotificationL(TBool& aAutoAuthorize,
       
   214         TBluetoothDialogParams::TBTDialogType aType,
   190     TBTDialogResourceId aResourceId, TBool aPaired)
   215     TBTDialogResourceId aResourceId, TBool aPaired)
   191     {
   216     {
   192     iNotification = iParent.ConnectionTracker().NotificationManager()->GetNotification();
   217     iNotification = iParent.ConnectionTracker().NotificationManager()->GetNotification();
   193     User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
   218     User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
   194     iNotification->SetObserver( this );
   219     iNotification->SetObserver( this );
   195     iNotification->SetNotificationType( aType, aResourceId );
   220     iNotification->SetNotificationType( aType, aResourceId );
   196     TInt err = KErrNone;
   221     TInt err = KErrNone;
       
   222     aAutoAuthorize = EFalse;
   197     
   223     
   198     //Set the dialog title based on the service IDs
   224     //Set the dialog title based on the service IDs
   199     switch(iServiceId)
   225     switch(iServiceId)
   200         {
   226         {
   201         case KBTSdpObjectPush:
   227         case KBTSdpObjectPush:
   212                 {
   238                 {
   213                 err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EReceive);
   239                 err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EReceive);
   214                 iCheckBoxState = EFalse;
   240                 iCheckBoxState = EFalse;
   215                 User::LeaveIfError(err);
   241                 User::LeaveIfError(err);
   216                 }
   242                 }
   217             }break;
   243             }
       
   244             break;
   218             
   245             
   219         case KBTSdpFax:
   246         case KBTSdpFax:
   220         case KBTSdpDun:
   247         case KBTSdpDun:
   221         case KBTSdpFileTransfer:
   248         case KBTSdpFileTransfer:
   222         case KBTSdpHeadSet:
   249         case KBTSdpHeadSet:
   225             {
   252             {
   226             err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EConnect);
   253             err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EConnect);
   227             // In case of an incoming connection, the checkbox is checked by default.
   254             // In case of an incoming connection, the checkbox is checked by default.
   228             iCheckBoxState = ETrue;
   255             iCheckBoxState = ETrue;
   229             User::LeaveIfError(err);
   256             User::LeaveIfError(err);
   230             }break;
   257             }
       
   258             break;
   231             
   259             
   232         default:
   260         default:
   233             {
   261             {
   234             TBTAuthorisationParams params;
   262             TBTAuthorisationParams params;
   235             TPckgC<TBTAuthorisationParams> paramsPckg(params);
   263             TPckgC<TBTAuthorisationParams> paramsPckg(params);
   238             // In this case, if there already exists a connection to an audio device, then we simply accept
   266             // In this case, if there already exists a connection to an audio device, then we simply accept
   239             // the incoming connection without querying the user.
   267             // the incoming connection without querying the user.
   240             // If there is no existing connection, then we pop up a query message.
   268             // If there is no existing connection, then we pop up a query message.
   241             if(IsExistingConnectionToAudioL(paramsPckg().iBDAddr))
   269             if(IsExistingConnectionToAudioL(paramsPckg().iBDAddr))
   242                 {
   270                 {
   243                 TPckgBuf<TBool> answer;
   271                 aAutoAuthorize = ETrue;
   244                 answer() = ETrue;
       
   245                 iNotifierMessage.Write(EBTNotifSrvReplySlot, answer);
       
   246                 iNotifierMessage.Complete(KErrNone);
       
   247                 return;
   272                 return;
   248                 }
   273                 }
   249             else
   274             else
   250                 {
   275                 {
   251                 err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EConnect);
   276                 err = iNotification->SetData( TBluetoothDialogParams::EDialogTitle, TBluetoothDialogParams::EConnect);
   252                 // In case of an incoming connection, the checkbox is checked by default.
   277                 // In case of an incoming connection, the checkbox is checked by default.
   253                 iCheckBoxState = ETrue;
   278                 iCheckBoxState = ETrue;
   254                 User::LeaveIfError(err);
   279                 User::LeaveIfError(err);
   255                 }
   280                 }
   256             }break;
   281             }
       
   282             break;
   257         }
   283         }
   258     
   284     
   259     //Add the device name 
   285     //Add the device name 
   260     err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, iCurrentDeviceName );
   286     err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, iCurrentDeviceName );
   261     User::LeaveIfError(err);
   287     User::LeaveIfError(err);
   262     //Add the device class
   288     //Add the device class
   263     err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceClass, iDeviceClass );
   289     err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceClass, iDeviceClass );
   264     User::LeaveIfError(err);
   290     User::LeaveIfError(err);
       
   291     
   265     }
   292     }
   266 
   293 
   267 TBool CBTNotifServiceAuthorizer::IsExistingConnectionToAudioL(const TBTDevAddr& aDevAddr)
   294 TBool CBTNotifServiceAuthorizer::IsExistingConnectionToAudioL(const TBTDevAddr& aDevAddr)
   268     {
   295     {
   269     CBTEngConnMan* connMan = CBTEngConnMan::NewL();
   296     CBTEngConnMan* connMan = CBTEngConnMan::NewL();