mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-14 20:47:54 +01:00
scan all paired devices at same time
One thread per device: brute force, but the threads live a few seconds and the user just triggered the action so should be ok with it.
This commit is contained in:
parent
61dc8e837e
commit
2ab04901a7
1 changed files with 33 additions and 7 deletions
|
@ -698,7 +698,7 @@ public class BTService extends XWService {
|
||||||
try {
|
try {
|
||||||
// Give legitimate caller 10 seconds to retry with
|
// Give legitimate caller 10 seconds to retry with
|
||||||
// a packet that we'll recognize.
|
// a packet that we'll recognize.
|
||||||
Thread.sleep( 10 * 1000 );
|
Thread.sleep( 20 * 1000 );
|
||||||
stopYourself( BTListenerThread.this );
|
stopYourself( BTListenerThread.this );
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
Log.e( TAG, "kill timer thread exiting; we're live!" );
|
Log.e( TAG, "kill timer thread exiting; we're live!" );
|
||||||
|
@ -1041,12 +1041,25 @@ public class BTService extends XWService {
|
||||||
private void sendPings( MultiEvent event, Set<BluetoothDevice> addrs )
|
private void sendPings( MultiEvent event, Set<BluetoothDevice> addrs )
|
||||||
{
|
{
|
||||||
Set<BluetoothDevice> pairedDevs = m_adapter.getBondedDevices();
|
Set<BluetoothDevice> pairedDevs = m_adapter.getBondedDevices();
|
||||||
// DbgUtils.logf( "ping: got %d paired devices", pairedDevs.size() );
|
Map<BluetoothDevice, PingThread> threads = new HashMap<>();
|
||||||
for ( BluetoothDevice dev : pairedDevs ) {
|
for ( BluetoothDevice dev : pairedDevs ) {
|
||||||
// Skip things that can't host an Android app
|
// Skip things that can't host an Android app
|
||||||
int clazz = dev.getBluetoothClass().getMajorDeviceClass();
|
int clazz = dev.getBluetoothClass().getMajorDeviceClass();
|
||||||
if ( Major.PHONE == clazz || Major.COMPUTER == clazz ) {
|
if ( Major.PHONE == clazz || Major.COMPUTER == clazz ) {
|
||||||
if ( sendPing( dev, 0 ) ) { // did we get a reply?
|
PingThread thread = new PingThread(dev);
|
||||||
|
thread.start();
|
||||||
|
threads.put( dev, thread );
|
||||||
|
} else {
|
||||||
|
Log.d( TAG, "skipping %s; not an android device!",
|
||||||
|
dev.getName() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( BluetoothDevice dev : threads.keySet() ) {
|
||||||
|
PingThread thread = threads.get( dev );
|
||||||
|
try {
|
||||||
|
thread.join();
|
||||||
|
if ( thread.gotResponse() ) {
|
||||||
if ( null != addrs ) {
|
if ( null != addrs ) {
|
||||||
addrs.add( dev );
|
addrs.add( dev );
|
||||||
}
|
}
|
||||||
|
@ -1054,13 +1067,26 @@ public class BTService extends XWService {
|
||||||
mHelper.postEvent( event, dev.getName() );
|
mHelper.postEvent( event, dev.getName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} catch ( InterruptedException ex ) {
|
||||||
Log.d( TAG, "skipping %s; not an android device!",
|
Assert.assertFalse( BuildConfig.DEBUG );
|
||||||
dev.getName() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class PingThread extends Thread {
|
||||||
|
private boolean mGotResponse;
|
||||||
|
private BluetoothDevice mDev;
|
||||||
|
|
||||||
|
PingThread(BluetoothDevice dev) { mDev = dev; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mGotResponse = sendPing( mDev, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean gotResponse() { return mGotResponse; }
|
||||||
|
}
|
||||||
|
|
||||||
private boolean sendPing( BluetoothDevice dev, int gameID )
|
private boolean sendPing( BluetoothDevice dev, int gameID )
|
||||||
{
|
{
|
||||||
boolean gotReply = false;
|
boolean gotReply = false;
|
||||||
|
@ -1375,7 +1401,7 @@ public class BTService extends XWService {
|
||||||
|
|
||||||
// Try for 8 seconds. Some devices take a long time to get ACL conn
|
// Try for 8 seconds. Some devices take a long time to get ACL conn
|
||||||
// ACTION
|
// ACTION
|
||||||
for ( long end = 10000 + System.currentTimeMillis(); ; ) {
|
for ( long end = 20000 + System.currentTimeMillis(); ; ) {
|
||||||
try {
|
try {
|
||||||
socket.connect();
|
socket.connect();
|
||||||
Log.i( TAG, "connect(%s) succeeded", name );
|
Log.i( TAG, "connect(%s) succeeded", name );
|
||||||
|
|
Loading…
Add table
Reference in a new issue