@@ -69,7 +69,7 @@ static void background_connections_lazy_init()
6969 }
7070}
7171
72- static void background_connection_add (bt_bdaddr_t * address )
72+ static BOOLEAN background_connection_add (bt_bdaddr_t * address )
7373{
7474 assert (address );
7575 background_connections_lazy_init ();
@@ -78,14 +78,17 @@ static void background_connection_add(bt_bdaddr_t *address)
7878 connection = osi_calloc (sizeof (background_connection_t ));
7979 connection -> address = * address ;
8080 hash_map_set (background_connections , & (connection -> address ), connection );
81+ return TRUE;
8182 }
83+ return FALSE;
8284}
8385
84- static void background_connection_remove (bt_bdaddr_t * address )
86+ static BOOLEAN background_connection_remove (bt_bdaddr_t * address )
8587{
8688 if (address && background_connections ) {
87- hash_map_erase (background_connections , address );
89+ return hash_map_erase (background_connections , address );
8890 }
91+ return FALSE;
8992}
9093
9194static void background_connections_clear ()
@@ -265,17 +268,30 @@ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBTM_ADD_W
265268 }
266269 return FALSE;
267270 }
268- if (add_wl_cb ){
269- //save add whitelist complete callback
270- p_cb -> add_wl_cb = add_wl_cb ;
271- }
272271
273272 if (to_add ) {
274273 /* added the bd_addr to the connection hash map queue */
275- background_connection_add ((bt_bdaddr_t * )bd_addr );
274+ if (!background_connection_add ((bt_bdaddr_t * )bd_addr )) {
275+ /* if the bd_addr already exist in whitelist, just callback return TRUE */
276+ if (add_wl_cb ){
277+ add_wl_cb (HCI_SUCCESS ,to_add );
278+ }
279+ return TRUE;
280+ }
276281 } else {
277282 /* remove the bd_addr to the connection hash map queue */
278- background_connection_remove ((bt_bdaddr_t * )bd_addr );
283+ if (!background_connection_remove ((bt_bdaddr_t * )bd_addr )){
284+ /* if the bd_addr don't exist in whitelist, just callback return TRUE */
285+ if (add_wl_cb ){
286+ add_wl_cb (HCI_SUCCESS ,to_add );
287+ }
288+ return TRUE;
289+ }
290+ }
291+
292+ if (add_wl_cb ){
293+ //save add whitelist complete callback
294+ p_cb -> add_wl_cb = add_wl_cb ;
279295 }
280296 /* stop the auto connect */
281297 btm_suspend_wl_activity (p_cb -> wl_state );
0 commit comments