fix removal of unpaired device

Two uses of remove() were passing different info. So pass the other one
from the other use.
This commit is contained in:
Eric House 2020-10-29 08:39:50 -07:00
parent 1019271c94
commit a5b98c483c

View file

@ -351,31 +351,26 @@ public class BTInviteDelegate extends InviteDelegate
private static void removeNotPaired( Persisted prs ) private static void removeNotPaired( Persisted prs )
{ {
Log.d( TAG, "removeNotPaired()" ); Log.d( TAG, "removeNotPaired()" );
BluetoothAdapter adapter = BTUtils.getAdapterIf(); Set<BluetoothDevice> pairedDevs = BTUtils.getCandidates();
if ( null != adapter ) { Set<String> paired = new HashSet<>();
Set<BluetoothDevice> pairedDevs = BTUtils.getCandidates(); for ( BluetoothDevice dev : pairedDevs ) {
Set<String> paired = new HashSet<>(); Log.d( TAG, "removeNotPaired(): paired dev: %s", dev.getName() );
for ( BluetoothDevice dev : pairedDevs ) { paired.add( dev.getName() );
Log.d( TAG, "removeNotPaired(): paired dev: %s", dev.getName() ); }
paired.add( dev.getName() );
}
Set<String> toRemove = new HashSet<>(); Set<String> toRemove = new HashSet<>();
for ( TwoStringPair pair : prs.pairs ) { for ( TwoStringPair pair : prs.pairs ) {
String name = pair.str2; String name = pair.str2;
if ( ! paired.contains( name ) ) { if ( ! paired.contains( name ) ) {
Log.d( TAG, "%s no longer paired; removing", name ); Log.d( TAG, "%s no longer paired; removing", name );
toRemove.add( name ); toRemove.add( pair.getDev() );
} else { } else {
Log.d( TAG, "%s STILL paired", name ); Log.d( TAG, "%s STILL paired", name );
}
} }
}
if ( ! toRemove.isEmpty() ) { if ( ! toRemove.isEmpty() ) {
prs.remove( toRemove ); prs.remove( toRemove );
}
} else {
Log.e( TAG, "removeNotPaired(): adapter null" );
} }
} }