mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-09 05:24:44 +01:00
fix, at least for most cases, Marshmallow change that doesn't let an
app know the BT/Mac addr of its own interface. The new bogus addr is transmitted in common/ structs, and so sending code need to look up by name when told to use that address.
This commit is contained in:
parent
536d220ba7
commit
79e1473bf6
1 changed files with 32 additions and 2 deletions
|
@ -42,6 +42,7 @@ import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -57,6 +58,7 @@ import org.eehouse.android.xw4.loc.LocUtils;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
public class BTService extends XWService {
|
public class BTService extends XWService {
|
||||||
|
private static final String BOGUS_MARSHMALLOW_ADDR = "02:00:00:00:00:00";
|
||||||
|
|
||||||
private static final long RESEND_TIMEOUT = 5; // seconds
|
private static final long RESEND_TIMEOUT = 5; // seconds
|
||||||
private static final int MAX_SEND_FAIL = 3;
|
private static final int MAX_SEND_FAIL = 3;
|
||||||
|
@ -654,6 +656,29 @@ public class BTService extends XWService {
|
||||||
return m_addrs.contains( btAddr );
|
return m_addrs.contains( btAddr );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> s_namesToAddrs;
|
||||||
|
private String lookupAddr( String btName )
|
||||||
|
{
|
||||||
|
if ( null == s_namesToAddrs ) {
|
||||||
|
s_namesToAddrs = new HashMap<String, String>();
|
||||||
|
}
|
||||||
|
if ( ! s_namesToAddrs.containsKey( btName ) ) {
|
||||||
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
if ( null != adapter ) {
|
||||||
|
Set<BluetoothDevice> devs = adapter.getBondedDevices();
|
||||||
|
Iterator<BluetoothDevice> iter = devs.iterator();
|
||||||
|
while ( iter.hasNext() ) {
|
||||||
|
BluetoothDevice dev = iter.next();
|
||||||
|
s_namesToAddrs.put( dev.getName(), dev.getAddress() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String result = s_namesToAddrs.get( btName );
|
||||||
|
DbgUtils.logf( "lookupAddr(%s) => %s", btName, result );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private void clearDevs( String[] btAddrs )
|
private void clearDevs( String[] btAddrs )
|
||||||
{
|
{
|
||||||
if ( null != btAddrs ) {
|
if ( null != btAddrs ) {
|
||||||
|
@ -1207,9 +1232,14 @@ public class BTService extends XWService {
|
||||||
@Override
|
@Override
|
||||||
public int sendViaBluetooth( byte[] buf, int gameID, CommsAddrRec addr )
|
public int sendViaBluetooth( byte[] buf, int gameID, CommsAddrRec addr )
|
||||||
{
|
{
|
||||||
|
String btAddr = addr.bt_btAddr;
|
||||||
|
if ( BOGUS_MARSHMALLOW_ADDR.equals( btAddr ) ) {
|
||||||
|
btAddr = lookupAddr( addr.bt_hostName );
|
||||||
|
}
|
||||||
|
|
||||||
Assert.assertTrue( addr.contains( CommsConnType.COMMS_CONN_BT ) );
|
Assert.assertTrue( addr.contains( CommsConnType.COMMS_CONN_BT ) );
|
||||||
m_sender.add( new BTQueueElem( BTCmd.MESG_SEND, buf,
|
m_sender.add( new BTQueueElem( BTCmd.MESG_SEND, buf,
|
||||||
addr.bt_btAddr, gameID ) );
|
btAddr, gameID ) );
|
||||||
return buf.length;
|
return buf.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue