Diff between d1f4727b778c24b9fcc257d4404144f04c7af66d and a79f778498f257b9dba92a29478ed4b41f3bf670

Changed Files

File Additions Deletions Status
android/bluetooth.c +24 -33 modified

Full Patch

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 2093730..2d16858 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1068,58 +1068,49 @@ static void mgmt_discovering_event(uint16_t index, uint16_t length,
 {
 	const struct mgmt_ev_discovering *ev = param;
 	struct hal_ev_discovery_state_changed cp;
-	bool is_discovering = adapter.cur_discovery_type;
+	uint8_t type;
 
 	if (length < sizeof(*ev)) {
 		error("Too small discovering event");
 		return;
 	}
 
-	DBG("hci%u type %u discovering %u", index, ev->type,
-							ev->discovering);
+	DBG("type %u discovering %u", ev->type, ev->discovering);
 
-	if (is_discovering == !!ev->discovering)
+	if (!!adapter.cur_discovery_type == !!ev->discovering)
 		return;
 
-	adapter.cur_discovery_type = ev->discovering ?
-						ev->type : SCAN_TYPE_NONE;
-
-	DBG("new discovering state %u", ev->discovering);
-
-	if (adapter.cur_discovery_type != SCAN_TYPE_NONE) {
+	if (ev->discovering) {
+		adapter.cur_discovery_type = ev->type;
 		cp.state = HAL_DISCOVERY_STATE_STARTED;
-	} else {
-		g_slist_foreach(bonded_devices, clear_device_found, NULL);
-		g_slist_foreach(cached_devices, clear_device_found, NULL);
-		cp.state = HAL_DISCOVERY_STATE_STOPPED;
+
+		goto done;
 	}
 
-	ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
-			HAL_EV_DISCOVERY_STATE_CHANGED, sizeof(cp), &cp);
+	adapter.cur_discovery_type = SCAN_TYPE_NONE;
+	cp.state = HAL_DISCOVERY_STATE_STOPPED;
 
-	if (gatt_discovery_stopped_cb &&
-			(adapter.cur_discovery_type == SCAN_TYPE_NONE)) {
-		/* One shot notification about discovery stopped send to gatt*/
+	g_slist_foreach(bonded_devices, clear_device_found, NULL);
+	g_slist_foreach(cached_devices, clear_device_found, NULL);
+
+	/* One shot notification about discovery stopped */
+	if (gatt_discovery_stopped_cb) {
 		gatt_discovery_stopped_cb();
 		gatt_discovery_stopped_cb = NULL;
 	}
 
-	/*
-	 * If discovery is ON or there is no expected next discovery session
-	 * then just return
-	 */
-	if ((adapter.cur_discovery_type != SCAN_TYPE_NONE) ||
-		(adapter.exp_discovery_type == SCAN_TYPE_NONE))
-		return;
+	type = adapter.exp_discovery_type;
+	adapter.exp_discovery_type = SCAN_TYPE_NONE;
 
-	start_discovery(adapter.exp_discovery_type);
+	if (type == SCAN_TYPE_NONE && gatt_device_found_cb)
+		type = SCAN_TYPE_LE;
 
-	/*
-	 * Maintain expected discovery type if there is gatt client
-	 * registered
-	 */
-	adapter.exp_discovery_type = gatt_device_found_cb ?
-						SCAN_TYPE_LE : SCAN_TYPE_NONE;
+	if (type != SCAN_TYPE_NONE)
+		start_discovery(type);
+
+done:
+	ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+			HAL_EV_DISCOVERY_STATE_CHANGED, sizeof(cp), &cp);
 }
 
 static void confirm_device_name_cb(uint8_t status, uint16_t length,