fix another source of bad/marshmallow addresses, and add asserts to

catch any others.
This commit is contained in:
Eric House 2015-12-21 16:26:30 -08:00
parent 79e1473bf6
commit 7805900c07

View file

@ -141,22 +141,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;
@ -305,13 +313,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;
@ -657,8 +666,11 @@ 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 )
{ {
String btAddr = addr.bt_btAddr;
if ( BOGUS_MARSHMALLOW_ADDR.equals( btAddr ) ) {
String btName = addr.bt_hostName;
if ( null == s_namesToAddrs ) { if ( null == s_namesToAddrs ) {
s_namesToAddrs = new HashMap<String, String>(); s_namesToAddrs = new HashMap<String, String>();
} }
@ -674,9 +686,10 @@ public class BTService extends XWService {
} }
} }
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 )
@ -1232,10 +1245,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,