178 TInt val = *(static_cast<TInt*>(aData.Get(_L("selectedindex"))->Data())); |
178 TInt val = *(static_cast<TInt*>(aData.Get(_L("selectedindex"))->Data())); |
179 BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val ); |
179 BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val ); |
180 |
180 |
181 if ( !iMessage.IsNull() ) |
181 if ( !iMessage.IsNull() ) |
182 { |
182 { |
183 // TInt sel = val;// - TBluetoothDialogParams::EDialogExt; |
|
184 TBTDeviceResponseParamsPckg devParams; |
183 TBTDeviceResponseParamsPckg devParams; |
185 if ( val > -1 && val < iDevices.Count() ) |
184 if ( val > -1 && val < iDevices.Count() ) |
186 { |
185 { |
187 TRAP(err,SendSelectedDeviceL(aData)); |
186 TRAP(err,SendSelectedDeviceL(aData)); |
188 /* devParams().SetDeviceAddress( iDevices[val]->Addr() ); |
|
189 devParams().SetDeviceClass(iDevices[val]->Device().DeviceClass()); |
|
190 devParams().SetDeviceName(iDevices[val]->Alias()); |
|
191 err = iMessage.Write( EBTNotifSrvReplySlot, devParams );*/ |
|
192 iNotification->RemoveObserver(); |
187 iNotification->RemoveObserver(); |
193 iNotification->Close(); // Also dequeues the notification from the queue. |
188 iNotification->Close(); // Also dequeues the notification from the queue. |
194 iNotification = NULL; |
189 iNotification = NULL; |
195 } |
190 } |
196 iMessage.Complete( err ); |
191 iMessage.Complete( err ); |
261 |
251 |
262 if(iNotification) |
252 if(iNotification) |
263 {// conditional check required as CAdvanceDevDiscoverer sends discovered devices at times |
253 {// conditional check required as CAdvanceDevDiscoverer sends discovered devices at times |
264 // even after canceldiscovery is issued and notification is set to NULL |
254 // even after canceldiscovery is issued and notification is set to NULL |
265 // this causes EExcDataAbort |
255 // this causes EExcDataAbort |
266 CHbSymbianVariantMap* map = iNotification->Data(); |
256 LoadDeviceDetailsL(*devext); |
267 /* TBuf<KMaxKeyDesCLength> keyStr; |
|
268 CHbSymbianVariant* devEntry; |
|
269 |
|
270 keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 ); |
|
271 devEntry = CHbSymbianVariant::NewL( (TAny*) &(devext->Alias()), |
|
272 CHbSymbianVariant::EDes ); |
|
273 map->Add( keyStr, devEntry );*/ |
|
274 |
|
275 User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceName, |
|
276 devext->Alias())); |
|
277 |
|
278 devext->Addr().GetReadable(addr); |
|
279 User::LeaveIfError(iNotification->SetData(TBluetoothDialogParams::EAddress,addr)); |
|
280 |
|
281 TInt classOfDevice; |
|
282 classOfDevice = devext->Device().DeviceClass().DeviceClass(); |
|
283 User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceClass,classOfDevice)); |
|
284 |
|
285 TBool status; |
|
286 status = isBonded( devext->Device()); |
|
287 |
|
288 // setMajorProperty(majorProperty, _L("Bonded"), isBonded( devArray[i]->Device() )); |
|
289 AddDataL(map,_L("Bonded"),&status,CHbSymbianVariant::EBool); |
|
290 status = devext->Device().GlobalSecurity().Banned(); |
|
291 AddDataL(map,_L("Blocked"),&status, |
|
292 CHbSymbianVariant::EBool); |
|
293 status = devext->Device().GlobalSecurity().NoAuthorise(); |
|
294 AddDataL(map,_L("Trusted"),&status, |
|
295 CHbSymbianVariant::EBool); |
|
296 status = devext->ServiceConnectionStatus() == EBTEngConnected; |
|
297 AddDataL(map,_L("Connected"),&status, |
|
298 CHbSymbianVariant::EBool); |
|
299 |
|
300 iNotification->Update(); |
|
301 } |
257 } |
302 } |
258 } |
303 |
259 |
304 // --------------------------------------------------------------------------- |
260 // --------------------------------------------------------------------------- |
305 // HandleDiscoveryCompleted |
261 // HandleDiscoveryCompleted |
408 } |
363 } |
409 |
364 |
410 void CBTNotifDeviceSelector::LoadUsedDevicesL() |
365 void CBTNotifDeviceSelector::LoadUsedDevicesL() |
411 { |
366 { |
412 const RDevExtensionArray& devArray= iServer.DevRepository().AllDevices(); |
367 const RDevExtensionArray& devArray= iServer.DevRepository().AllDevices(); |
413 TBuf<KBTDevAddrSize * 2> addr; |
|
414 for(TInt i=0; i< devArray.Count(); i++ ) |
368 for(TInt i=0; i< devArray.Count(); i++ ) |
415 { |
369 { |
416 const TTime& usedTime = devArray[i]->Device().Used(); |
370 iDevices.AppendL( devArray[i]->CopyL() ); |
417 TTime monthBack; |
371 } |
418 monthBack.HomeTime(); |
372 SortUsedDevicesL(); |
419 monthBack -= TTimeIntervalDays(30); |
373 RemoveUnWantedDevices(); |
420 if(usedTime >= monthBack) |
374 SendLastUsedDevicesL(); |
421 { |
375 SendPairedDevicesL(); |
422 iDevices.AppendL( devArray[i]->CopyL() ); |
376 |
423 CHbSymbianVariantMap* map = iNotification->Data(); |
377 } |
424 // TBuf<KMaxKeyDesCLength> keyStr; |
378 |
425 // CHbSymbianVariant* devEntry; |
379 |
426 |
380 void CBTNotifDeviceSelector::SortUsedDevicesL() |
427 // keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 ); |
381 { |
428 // devEntry = CHbSymbianVariant::NewL( (TAny*) &(devArray[i]->Alias()), |
382 TInt count = iDevices.Count(); |
429 // CHbSymbianVariant::EDes ); |
383 for(TInt i=0;i<(count-1);i++) |
430 // map->Add( keyStr, devEntry, ); |
384 { |
431 User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceName, |
385 for(TInt j=0;j<(count-(i+1));j++) |
432 devArray[i]->Alias())); |
386 { |
433 // AddDataL(map,keyStr,&(devArray[i]->Alias()),CHbSymbianVariant::EDes); |
387 if(iDevices[j]->Device().Used().Int64() < iDevices[j+1]->Device().Used().Int64()) |
434 devArray[i]->Addr().GetReadable(addr); |
388 { |
435 User::LeaveIfError(iNotification->SetData(TBluetoothDialogParams::EAddress,addr)); |
389 CBtDevExtension* devextension = iDevices[j+1]; |
436 addr.Zero(); |
390 iDevices.Remove(j+1); |
437 TInt classOfDevice; |
391 iDevices.InsertL(devextension,j); |
438 classOfDevice = devArray[i]->Device().DeviceClass().DeviceClass(); |
392 } |
439 User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceClass,classOfDevice)); |
393 } |
440 |
394 } |
441 TBool status; |
395 } |
442 status = isBonded( devArray[i]->Device()); |
396 |
443 |
397 |
444 // setMajorProperty(majorProperty, _L("Bonded"), isBonded( devArray[i]->Device() )); |
398 void CBTNotifDeviceSelector::RemoveUnWantedDevices() |
445 AddDataL(map,_L("Bonded"),&status,CHbSymbianVariant::EBool); |
399 { |
446 status = devArray[i]->Device().GlobalSecurity().Banned(); |
400 for(TInt i=(iDevices.Count()-1);i>-1;i--) |
447 AddDataL(map,_L("Blocked"),&status, |
401 { |
448 CHbSymbianVariant::EBool); |
402 TInt classOfDevice = iDevices[i]->Device().DeviceClass().DeviceClass(); |
449 status = devArray[i]->Device().GlobalSecurity().NoAuthorise(); |
403 TBTDeviceClass codClass = TBTDeviceClass( classOfDevice ); |
450 AddDataL(map,_L("Trusted"),&status, |
404 TUint8 majorDevCls = codClass.MajorDeviceClass(); |
451 CHbSymbianVariant::EBool); |
405 if((majorDevCls ==EMajorDeviceComputer)|| (majorDevCls ==EMajorDevicePhone)) |
452 status = devArray[i]->ServiceConnectionStatus() == EBTEngConnected; |
406 { |
453 AddDataL(map,_L("Connected"),&status, |
407 } |
454 CHbSymbianVariant::EBool); |
408 else |
455 // set blocked status: |
409 { |
456 /* setMajorProperty(majorProperty, BtuiDevProperty::Blocked, |
410 CBtDevExtension* devextension = iDevices[i]; |
457 devArray[i]->Device().GlobalSecurity().Banned() ); |
411 iDevices.Remove(i); |
458 // set trusted status: |
412 delete devextension; |
459 setMajorProperty(majorProperty, BtuiDevProperty::Trusted, |
413 devextension = NULL; |
460 devArray[i]->Device().GlobalSecurity().NoAuthorise() ); |
414 iDevices.Compress(); |
461 // set connected status: |
415 } |
462 // EBTEngConnecting is an intermediate state between connected and not-connected, |
416 } |
463 // we do not treat it as connected: |
417 } |
464 setMajorProperty(majorProperty, BtuiDevProperty::Connected, devArray[i]->ServiceConnectionStatus() == EBTEngConnected); |
418 |
465 |
419 void CBTNotifDeviceSelector::SendLastUsedDevicesL() |
466 */ |
420 { |
467 |
421 TInt Count = iDevices.Count(); |
468 // AddDataL(map,keyStr,&(devArray[i]->Alias()),CHbSymbianVariant::EDes); |
422 if(Count > KLastUsedDevices) |
469 iNotification->Update(); |
423 Count = KLastUsedDevices; |
470 } |
424 for(TInt i=0;i < Count;i++) |
471 } |
425 { |
472 } |
426 LoadDeviceDetailsL(*(iDevices[i])); |
473 |
427 } |
474 |
428 } |
|
429 |
|
430 |
|
431 void CBTNotifDeviceSelector::SendPairedDevicesL() |
|
432 { |
|
433 TInt count = iDevices.Count(); |
|
434 if(count > KLastUsedDevices) |
|
435 { |
|
436 for(TInt i = KLastUsedDevices; i< count; i++) |
|
437 { |
|
438 if(isBonded( iDevices[i]->Device())) |
|
439 { |
|
440 LoadDeviceDetailsL(*(iDevices[i])); |
|
441 } |
|
442 } |
|
443 } |
|
444 |
|
445 } |
|
446 |
|
447 void CBTNotifDeviceSelector::LoadDeviceDetailsL(const CBtDevExtension& aDevice) |
|
448 { |
|
449 TBuf<KBTDevAddrSize * 2> addr; |
|
450 TUint32 classOfDevice; |
|
451 TBool status; |
|
452 |
|
453 //TODO Need to create string constants Also try Enum value for device name rather |
|
454 //than hadrdcoded string for key. It was not working previously |
|
455 CHbSymbianVariantMap* map = iNotification->CreateNotificationDataL(); |
|
456 AddDataL(map,_L("Name"),(TAny*) &(aDevice.Alias()),CHbSymbianVariant::EDes); |
|
457 |
|
458 aDevice.Addr().GetReadable(addr); |
|
459 User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EAddress,addr)); |
|
460 |
|
461 classOfDevice = aDevice.Device().DeviceClass().DeviceClass(); |
|
462 User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceClass,classOfDevice)); |
|
463 |
|
464 status = isBonded( aDevice.Device()); |
|
465 AddDataL(map,_L("Bonded"),&status,CHbSymbianVariant::EBool); |
|
466 |
|
467 status = aDevice.Device().GlobalSecurity().Banned(); |
|
468 AddDataL(map,_L("Blocked"),&status,CHbSymbianVariant::EBool); |
|
469 |
|
470 status = aDevice.Device().GlobalSecurity().NoAuthorise(); |
|
471 AddDataL(map,_L("Trusted"),&status,CHbSymbianVariant::EBool); |
|
472 |
|
473 status = aDevice.ServiceConnectionStatus() == EBTEngConnected; |
|
474 AddDataL(map,_L("Connected"),&status,CHbSymbianVariant::EBool); |
|
475 iNotification->Update(); |
|
476 } |
475 |
477 |
476 /*! |
478 /*! |
477 Tells if the given device is bonded. |
479 Tells if the given device is bonded. |
478 */ |
480 */ |
479 TBool CBTNotifDeviceSelector::isBonded( const CBTDevice &dev ) |
481 TBool CBTNotifDeviceSelector::isBonded( const CBTDevice &dev ) const |
480 { |
482 { |
481 // todo: this has not addresses Just Works pairing mode yet. |
483 // todo: this has not addresses Just Works pairing mode yet. |
482 return dev.IsValidPaired() && dev.IsPaired() && |
484 return dev.IsValidPaired() && dev.IsPaired() && |
483 dev.LinkKeyType() != ELinkKeyUnauthenticatedUpgradable; |
485 dev.LinkKeyType() != ELinkKeyUnauthenticatedUpgradable; |
484 } |
486 } |