mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-24 07:58:34 +01:00
fix another source of bad/marshmallow addresses, and add asserts to
catch any others.
This commit is contained in:
parent
162ab11f12
commit
f78cd0f656
1 changed files with 33 additions and 23 deletions
|
@ -136,22 +136,30 @@ public class BTService extends XWService {
|
||||||
Assert.assertTrue( null != btAddr && 0 < btAddr.length() );
|
Assert.assertTrue( null != btAddr && 0 < btAddr.length() );
|
||||||
m_msg = buf; m_btAddr = btAddr;
|
m_msg = buf; m_btAddr = btAddr;
|
||||||
m_gameID = gameID;
|
m_gameID = gameID;
|
||||||
|
checkAddr();
|
||||||
}
|
}
|
||||||
public BTQueueElem( BTCmd cmd, String btAddr, int gameID ) {
|
public BTQueueElem( BTCmd cmd, String btAddr, int gameID ) {
|
||||||
this( cmd );
|
this( cmd );
|
||||||
Assert.assertTrue( null != btAddr && 0 < btAddr.length() );
|
Assert.assertTrue( null != btAddr && 0 < btAddr.length() );
|
||||||
m_btAddr = btAddr;
|
m_btAddr = btAddr;
|
||||||
m_gameID = gameID;
|
m_gameID = gameID;
|
||||||
|
checkAddr();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BTQueueElem( BTCmd cmd, NetLaunchInfo nli, String btAddr ) {
|
public BTQueueElem( BTCmd cmd, NetLaunchInfo nli, String btAddr ) {
|
||||||
this( cmd );
|
this( cmd );
|
||||||
m_nli = nli;
|
m_nli = nli;
|
||||||
m_btAddr = btAddr;
|
m_btAddr = btAddr;
|
||||||
|
checkAddr();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int incrFailCount() { return ++m_failCount; }
|
public int incrFailCount() { return ++m_failCount; }
|
||||||
public boolean failCountExceeded() { return m_failCount >= MAX_SEND_FAIL; }
|
public boolean failCountExceeded() { return m_failCount >= MAX_SEND_FAIL; }
|
||||||
|
|
||||||
|
private void checkAddr()
|
||||||
|
{
|
||||||
|
Assert.assertFalse( BOGUS_MARSHMALLOW_ADDR.equals( m_btAddr ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BluetoothAdapter m_adapter;
|
private BluetoothAdapter m_adapter;
|
||||||
|
@ -300,13 +308,14 @@ public class BTService extends XWService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int enqueueFor( Context context, byte[] buf,
|
public static int enqueueFor( Context context, byte[] buf,
|
||||||
String targetAddr, int gameID )
|
CommsAddrRec targetAddr, int gameID )
|
||||||
{
|
{
|
||||||
int nSent = -1;
|
int nSent = -1;
|
||||||
if ( null != targetAddr && 0 < targetAddr.length() ) {
|
if ( null != targetAddr ) {
|
||||||
|
String btAddr = getSafeAddr( targetAddr );
|
||||||
Intent intent = getIntentTo( context, BTAction.SEND );
|
Intent intent = getIntentTo( context, BTAction.SEND );
|
||||||
intent.putExtra( MSG_KEY, buf );
|
intent.putExtra( MSG_KEY, buf );
|
||||||
intent.putExtra( ADDR_KEY, targetAddr );
|
intent.putExtra( ADDR_KEY, btAddr );
|
||||||
intent.putExtra( GAMEID_KEY, gameID );
|
intent.putExtra( GAMEID_KEY, gameID );
|
||||||
context.startService( intent );
|
context.startService( intent );
|
||||||
nSent = buf.length;
|
nSent = buf.length;
|
||||||
|
@ -647,26 +656,30 @@ public class BTService extends XWService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, String> s_namesToAddrs;
|
private static Map<String, String> s_namesToAddrs;
|
||||||
private String lookupAddr( String btName )
|
private static String getSafeAddr( CommsAddrRec addr )
|
||||||
{
|
{
|
||||||
if ( null == s_namesToAddrs ) {
|
String btAddr = addr.bt_btAddr;
|
||||||
s_namesToAddrs = new HashMap<String, String>();
|
if ( BOGUS_MARSHMALLOW_ADDR.equals( btAddr ) ) {
|
||||||
}
|
String btName = addr.bt_hostName;
|
||||||
if ( ! s_namesToAddrs.containsKey( btName ) ) {
|
if ( null == s_namesToAddrs ) {
|
||||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
s_namesToAddrs = new HashMap<String, String>();
|
||||||
if ( null != adapter ) {
|
}
|
||||||
Set<BluetoothDevice> devs = adapter.getBondedDevices();
|
if ( ! s_namesToAddrs.containsKey( btName ) ) {
|
||||||
Iterator<BluetoothDevice> iter = devs.iterator();
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
while ( iter.hasNext() ) {
|
if ( null != adapter ) {
|
||||||
BluetoothDevice dev = iter.next();
|
Set<BluetoothDevice> devs = adapter.getBondedDevices();
|
||||||
s_namesToAddrs.put( dev.getName(), dev.getAddress() );
|
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 );
|
btAddr = s_namesToAddrs.get( btName );
|
||||||
DbgUtils.logf( "lookupAddr(%s) => %s", btName, result );
|
DbgUtils.logf( "lookupAddr(%s) => %s", btName, btAddr );
|
||||||
return result;
|
}
|
||||||
|
return btAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearDevs( String[] btAddrs )
|
private void clearDevs( String[] btAddrs )
|
||||||
|
@ -1216,10 +1229,7 @@ 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;
|
String btAddr = getSafeAddr( addr );
|
||||||
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,
|
||||||
|
|
Loading…
Add table
Reference in a new issue