mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-27 09:58:45 +01:00
fix sending invitations via BT
This commit is contained in:
parent
aa0aded8c4
commit
b6cff507fa
2 changed files with 17 additions and 13 deletions
|
@ -329,7 +329,7 @@ public class BTUtils {
|
|||
{
|
||||
boolean success = false;
|
||||
Log.d( TAG, "sendInvite(name=%s, addr=%s, nli=%s)", btName, btAddr, nli );
|
||||
if ( !TextUtils.isEmpty(btAddr) ) {
|
||||
if ( !TextUtils.isEmpty(btName) ) {
|
||||
getPA( btName, btAddr ).addInvite( nli );
|
||||
success = true;
|
||||
}
|
||||
|
@ -431,7 +431,7 @@ public class BTUtils {
|
|||
|
||||
private static PacketAccumulator getPA( String name, String addr )
|
||||
{
|
||||
Assert.assertTrue( !TextUtils.isEmpty(addr) );
|
||||
Assert.assertTrue( !TextUtils.isEmpty(name) );
|
||||
PacketAccumulator pa = getSenderFor( name, addr ).wake();
|
||||
return pa;
|
||||
}
|
||||
|
@ -440,10 +440,10 @@ public class BTUtils {
|
|||
{
|
||||
try ( DeadlockWatch dw = new DeadlockWatch( sSenders ) ) {
|
||||
synchronized ( sSenders ) {
|
||||
if ( pa == sSenders.get( pa.getBTAddr() ) ) {
|
||||
if ( pa == sSenders.get( pa.getName() ) ) {
|
||||
sSenders.remove( pa );
|
||||
} else {
|
||||
Log.e( TAG, "race? There's a different PA for %s", pa.getBTAddr() );
|
||||
Log.e( TAG, "race? There's a different PA for %s", pa.getName() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -459,10 +459,10 @@ public class BTUtils {
|
|||
PacketAccumulator result;
|
||||
try ( DeadlockWatch dw = new DeadlockWatch( sSenders ) ) {
|
||||
synchronized ( sSenders ) {
|
||||
if ( create && !sSenders.containsKey( btAddr ) ) {
|
||||
sSenders.put( btAddr, new PacketAccumulator( btName, btAddr ) );
|
||||
if ( create && !sSenders.containsKey( btName ) ) {
|
||||
sSenders.put( btName, new PacketAccumulator( btName, btAddr ) );
|
||||
}
|
||||
result = sSenders.get( btAddr );
|
||||
result = sSenders.get( btName );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -670,7 +670,7 @@ public class BTUtils {
|
|||
// Ping case -- used only once
|
||||
PacketAccumulator( String btName, String btAddr, int timeoutMS )
|
||||
{
|
||||
Assert.assertTrue( !TextUtils.isEmpty(btAddr) );
|
||||
Assert.assertTrue( !TextUtils.isEmpty(btName) );
|
||||
mName = btName;
|
||||
mAddr = btAddr;
|
||||
Log.d( TAG, "PacketAccumulator(name=%s, addr=%s)", mName, mAddr );
|
||||
|
@ -910,8 +910,11 @@ public class BTUtils {
|
|||
|
||||
private BluetoothDevice getRemoteDevice( String btName, String btAddr )
|
||||
{
|
||||
BluetoothDevice result = mAdapter.getRemoteDevice( btAddr );
|
||||
if ( TextUtils.isEmpty( result.getName() ) ) {
|
||||
BluetoothDevice result = null;
|
||||
if ( !TextUtils.isEmpty(btAddr) ) {
|
||||
result = mAdapter.getRemoteDevice( btAddr );
|
||||
}
|
||||
if ( null == result || TextUtils.isEmpty( result.getName() ) ) {
|
||||
result = null;
|
||||
Log.d( TAG, "getRemoteDevice(%s); no name; trying again", btAddr );
|
||||
Assert.assertTrueNR( !TextUtils.isEmpty( btName ) );
|
||||
|
|
|
@ -1694,7 +1694,7 @@ void
|
|||
comms_invite( CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli,
|
||||
const CommsAddrRec* destAddr, XP_Bool sendNow )
|
||||
{
|
||||
LOG_FUNC();
|
||||
COMMS_LOGFF("(sendNow=%s)", boolToStr(sendNow));
|
||||
LOGNLI(nli);
|
||||
XP_PlayerAddr forceChannel = nli->forceChannel;
|
||||
XP_ASSERT( 0 < forceChannel && (forceChannel & CHANNEL_MASK) == forceChannel );
|
||||
|
@ -1714,13 +1714,14 @@ comms_invite( CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli,
|
|||
elem = addToQueue( comms, xwe, elem, XP_TRUE );
|
||||
if ( !!elem ) {
|
||||
XP_ASSERT( !elem->smp.next );
|
||||
COMMS_LOGFF( "added invite on channel %d", elem->channelNo & CHANNEL_MASK );
|
||||
COMMS_LOGFF( "added invite with sum %s on channel %d", elem->checksum,
|
||||
elem->channelNo & CHANNEL_MASK );
|
||||
/* Let's let platform code decide whether to call sendMsg() . On
|
||||
Android creating a game with an invitation in its queue is always
|
||||
followed by opening the game, which results in comms_resendAll()
|
||||
getting called leading to a second send immediately after this. So
|
||||
let Android drop it. Linux, though, needs it for now. */
|
||||
if ( sendNow && !!elem && !!comms->procs.sendInvt ) {
|
||||
if ( sendNow && !!comms->procs.sendInvt ) {
|
||||
sendMsg( comms, xwe, elem, COMMS_CONN_NONE );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue