All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] android/bluetooth: Fix discovering new devices
@ 2014-01-14  9:31 Szymon Janc
  2014-01-14 11:39 ` Johan Hedberg
  0 siblings, 1 reply; 3+ messages in thread
From: Szymon Janc @ 2014-01-14  9:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Device found events should be send also for known devices if this is
new discovery session. Otherwise Android will ignore those devices.
---
 android/bluetooth.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index f1e5458..735b03e 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -90,6 +90,8 @@ struct device {
 	uint32_t timestamp;
 
 	GSList *uuids;
+
+	bool found; /* if device is found in current discovery session */
 };
 
 struct browse_req {
@@ -924,10 +926,19 @@ static void mgmt_discovering_event(uint16_t index, uint16_t length,
 
 	DBG("new discovering state %u", ev->discovering);
 
-	if (adapter.discovering)
+	if (adapter.discovering) {
 		cp.state = HAL_DISCOVERY_STATE_STARTED;
-	else
+	} else {
+		GSList *l;
+
+		for(l = devices; l; l = g_slist_next(l)) {
+			struct device *dev = l->data;
+
+			dev->found = false;
+		}
+
 		cp.state = HAL_DISCOVERY_STATE_STOPPED;
+	}
 
 	ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH,
 			HAL_EV_DISCOVERY_STATE_CHANGED, sizeof(cp), &cp);
@@ -966,6 +977,17 @@ static uint8_t bdaddr_type2android(uint8_t type)
 	return HAL_TYPE_LE;
 }
 
+static bool device_found_needed(struct device *dev)
+{
+	if (!dev)
+		return true;
+
+	if (dev->bond_state == HAL_BOND_STATE_BONDED)
+		return false;
+
+	return !dev->found;
+}
+
 static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
 					int8_t rssi, bool confirm,
 					const uint8_t *data, uint8_t data_len)
@@ -983,12 +1005,15 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
 	eir_parse(&eir, data, data_len);
 
 	dev = find_device(bdaddr);
-	if (!dev) {
+	if (device_found_needed(dev)) {
 		struct hal_ev_device_found *ev = (void *) buf;
 		bdaddr_t android_bdaddr;
 		uint8_t android_type;
 
-		dev = create_device(bdaddr, bdaddr_type);
+		if (!dev)
+			dev = create_device(bdaddr, bdaddr_type);
+
+		dev->found = true;
 
 		size += sizeof(*ev);
 
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] android/bluetooth: Fix discovering new devices
  2014-01-14  9:31 [PATCH] android/bluetooth: Fix discovering new devices Szymon Janc
@ 2014-01-14 11:39 ` Johan Hedberg
  2014-01-16 10:22   ` Szymon Janc
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hedberg @ 2014-01-14 11:39 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth

Hi Szymon,

On Tue, Jan 14, 2014, Szymon Janc wrote:
> +	} else {
> +		GSList *l;
> +
> +		for(l = devices; l; l = g_slist_next(l)) {

Coding style thing here (space after 'for'). You might wanna consider a
helper function and g_slist_foreach here tough.

> +static bool device_found_needed(struct device *dev)
> +{
> +	if (!dev)
> +		return true;
> +
> +	if (dev->bond_state == HAL_BOND_STATE_BONDED)
> +		return false;
> +
> +	return !dev->found;
> +}

I think you should provide lots more code comments here with proper
explanations of each if-statement. E.g. your commit message doesn't
mention anything about bonded devices and yet you have a check for this
state here.

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] android/bluetooth: Fix discovering new devices
  2014-01-14 11:39 ` Johan Hedberg
@ 2014-01-16 10:22   ` Szymon Janc
  0 siblings, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2014-01-16 10:22 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

On Tuesday 14 of January 2014 13:39:20 Johan Hedberg wrote:
> Hi Szymon,
> 
> On Tue, Jan 14, 2014, Szymon Janc wrote:
> > +	} else {
> > +		GSList *l;
> > +
> > +		for(l = devices; l; l = g_slist_next(l)) {
> 
> Coding style thing here (space after 'for'). You might wanna consider a
> helper function and g_slist_foreach here tough.
> 
> > +static bool device_found_needed(struct device *dev)
> > +{
> > +	if (!dev)
> > +		return true;
> > +
> > +	if (dev->bond_state == HAL_BOND_STATE_BONDED)
> > +		return false;
> > +
> > +	return !dev->found;
> > +}
> 
> I think you should provide lots more code comments here with proper
> explanations of each if-statement. E.g. your commit message doesn't
> mention anything about bonded devices and yet you have a check for this
> state here.

Now I think this check is not really needed, if paired remote is responding to
inquiry then just notify HAL as with any other device found.

I'll send V2 shortly.


-- 
Best regards, 
Szymon Janc

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-16 10:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-14  9:31 [PATCH] android/bluetooth: Fix discovering new devices Szymon Janc
2014-01-14 11:39 ` Johan Hedberg
2014-01-16 10:22   ` Szymon Janc

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.