mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +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;
|
boolean success = false;
|
||||||
Log.d( TAG, "sendInvite(name=%s, addr=%s, nli=%s)", btName, btAddr, nli );
|
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 );
|
getPA( btName, btAddr ).addInvite( nli );
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,7 @@ public class BTUtils {
|
||||||
|
|
||||||
private static PacketAccumulator getPA( String name, String addr )
|
private static PacketAccumulator getPA( String name, String addr )
|
||||||
{
|
{
|
||||||
Assert.assertTrue( !TextUtils.isEmpty(addr) );
|
Assert.assertTrue( !TextUtils.isEmpty(name) );
|
||||||
PacketAccumulator pa = getSenderFor( name, addr ).wake();
|
PacketAccumulator pa = getSenderFor( name, addr ).wake();
|
||||||
return pa;
|
return pa;
|
||||||
}
|
}
|
||||||
|
@ -440,10 +440,10 @@ public class BTUtils {
|
||||||
{
|
{
|
||||||
try ( DeadlockWatch dw = new DeadlockWatch( sSenders ) ) {
|
try ( DeadlockWatch dw = new DeadlockWatch( sSenders ) ) {
|
||||||
synchronized ( sSenders ) {
|
synchronized ( sSenders ) {
|
||||||
if ( pa == sSenders.get( pa.getBTAddr() ) ) {
|
if ( pa == sSenders.get( pa.getName() ) ) {
|
||||||
sSenders.remove( pa );
|
sSenders.remove( pa );
|
||||||
} else {
|
} 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;
|
PacketAccumulator result;
|
||||||
try ( DeadlockWatch dw = new DeadlockWatch( sSenders ) ) {
|
try ( DeadlockWatch dw = new DeadlockWatch( sSenders ) ) {
|
||||||
synchronized ( sSenders ) {
|
synchronized ( sSenders ) {
|
||||||
if ( create && !sSenders.containsKey( btAddr ) ) {
|
if ( create && !sSenders.containsKey( btName ) ) {
|
||||||
sSenders.put( btAddr, new PacketAccumulator( btName, btAddr ) );
|
sSenders.put( btName, new PacketAccumulator( btName, btAddr ) );
|
||||||
}
|
}
|
||||||
result = sSenders.get( btAddr );
|
result = sSenders.get( btName );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -670,7 +670,7 @@ public class BTUtils {
|
||||||
// Ping case -- used only once
|
// Ping case -- used only once
|
||||||
PacketAccumulator( String btName, String btAddr, int timeoutMS )
|
PacketAccumulator( String btName, String btAddr, int timeoutMS )
|
||||||
{
|
{
|
||||||
Assert.assertTrue( !TextUtils.isEmpty(btAddr) );
|
Assert.assertTrue( !TextUtils.isEmpty(btName) );
|
||||||
mName = btName;
|
mName = btName;
|
||||||
mAddr = btAddr;
|
mAddr = btAddr;
|
||||||
Log.d( TAG, "PacketAccumulator(name=%s, addr=%s)", mName, mAddr );
|
Log.d( TAG, "PacketAccumulator(name=%s, addr=%s)", mName, mAddr );
|
||||||
|
@ -910,8 +910,11 @@ public class BTUtils {
|
||||||
|
|
||||||
private BluetoothDevice getRemoteDevice( String btName, String btAddr )
|
private BluetoothDevice getRemoteDevice( String btName, String btAddr )
|
||||||
{
|
{
|
||||||
BluetoothDevice result = mAdapter.getRemoteDevice( btAddr );
|
BluetoothDevice result = null;
|
||||||
if ( TextUtils.isEmpty( result.getName() ) ) {
|
if ( !TextUtils.isEmpty(btAddr) ) {
|
||||||
|
result = mAdapter.getRemoteDevice( btAddr );
|
||||||
|
}
|
||||||
|
if ( null == result || TextUtils.isEmpty( result.getName() ) ) {
|
||||||
result = null;
|
result = null;
|
||||||
Log.d( TAG, "getRemoteDevice(%s); no name; trying again", btAddr );
|
Log.d( TAG, "getRemoteDevice(%s); no name; trying again", btAddr );
|
||||||
Assert.assertTrueNR( !TextUtils.isEmpty( btName ) );
|
Assert.assertTrueNR( !TextUtils.isEmpty( btName ) );
|
||||||
|
|
|
@ -1694,7 +1694,7 @@ void
|
||||||
comms_invite( CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli,
|
comms_invite( CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli,
|
||||||
const CommsAddrRec* destAddr, XP_Bool sendNow )
|
const CommsAddrRec* destAddr, XP_Bool sendNow )
|
||||||
{
|
{
|
||||||
LOG_FUNC();
|
COMMS_LOGFF("(sendNow=%s)", boolToStr(sendNow));
|
||||||
LOGNLI(nli);
|
LOGNLI(nli);
|
||||||
XP_PlayerAddr forceChannel = nli->forceChannel;
|
XP_PlayerAddr forceChannel = nli->forceChannel;
|
||||||
XP_ASSERT( 0 < forceChannel && (forceChannel & CHANNEL_MASK) == 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 );
|
elem = addToQueue( comms, xwe, elem, XP_TRUE );
|
||||||
if ( !!elem ) {
|
if ( !!elem ) {
|
||||||
XP_ASSERT( !elem->smp.next );
|
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
|
/* Let's let platform code decide whether to call sendMsg() . On
|
||||||
Android creating a game with an invitation in its queue is always
|
Android creating a game with an invitation in its queue is always
|
||||||
followed by opening the game, which results in comms_resendAll()
|
followed by opening the game, which results in comms_resendAll()
|
||||||
getting called leading to a second send immediately after this. So
|
getting called leading to a second send immediately after this. So
|
||||||
let Android drop it. Linux, though, needs it for now. */
|
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 );
|
sendMsg( comms, xwe, elem, COMMS_CONN_NONE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue