improve bad-protocol messaging: suggestion to upgrade is displayed on

both sides.
This commit is contained in:
Eric House 2014-09-22 08:09:58 -07:00
parent 59f5c17e78
commit 4c2c6e5814
6 changed files with 81 additions and 43 deletions

View file

@ -1856,8 +1856,11 @@
<!-- --> <!-- -->
<string name="new_bt_body_fmt">From a player on the device %1$s wants to start a game</string> <string name="new_bt_body_fmt">From a player on the device %1$s wants to start a game</string>
<!-- --> <!-- -->
<string name="bt_bad_proto_fmt">Crosswords on %1$s wrong version for <string name="bt_bad_proto_fmt">The version of Crosswords on
Bluetooth play.</string> \"%1$s\" is incompatible with this one for play using
Bluetooth. One of you may need to upgrade before you can
continue.</string>
<!-- --> <!-- -->
<string name="new_btmove_title">Invitation via Bluetooth</string> <string name="new_btmove_title">Invitation via Bluetooth</string>
<!-- --> <!-- -->

View file

@ -1593,8 +1593,10 @@
<!-- --> <!-- -->
<string name="new_bt_body_fmt">Morf a reyalp no eht ecived %1$s stnaw ot trats a emag</string> <string name="new_bt_body_fmt">Morf a reyalp no eht ecived %1$s stnaw ot trats a emag</string>
<!-- --> <!-- -->
<string name="bt_bad_proto_fmt">Sdrowssorc no %1$s gnorw noisrev rof <string name="bt_bad_proto_fmt">Eht noisrev fo Sdrowssorc no
Htooteulb yalp.</string> \"%1$s\" si elbitapmocni htiw siht eno rof yalp gnisu
Htooteulb. Eno fo uoy yam deen ot edargpu erofeb uoy nac
eunitnoc.</string>
<!-- --> <!-- -->
<string name="new_btmove_title">Noitativni aiv Htooteulb</string> <string name="new_btmove_title">Noitativni aiv Htooteulb</string>
<!-- --> <!-- -->

View file

@ -1593,8 +1593,10 @@
<!-- --> <!-- -->
<string name="new_bt_body_fmt">FROM A PLAYER ON THE DEVICE %1$s WANTS TO START A GAME</string> <string name="new_bt_body_fmt">FROM A PLAYER ON THE DEVICE %1$s WANTS TO START A GAME</string>
<!-- --> <!-- -->
<string name="bt_bad_proto_fmt">CROSSWORDS ON %1$s WRONG VERSION FOR <string name="bt_bad_proto_fmt">THE VERSION OF CROSSWORDS ON
BLUETOOTH PLAY.</string> \"%1$s\" IS INCOMPATIBLE WITH THIS ONE FOR PLAY USING
BLUETOOTH. ONE OF YOU MAY NEED TO UPGRADE BEFORE YOU CAN
CONTINUE.</string>
<!-- --> <!-- -->
<string name="new_btmove_title">INVITATION VIA BLUETOOTH</string> <string name="new_btmove_title">INVITATION VIA BLUETOOTH</string>
<!-- --> <!-- -->

View file

@ -86,20 +86,21 @@ public class BTService extends XWService {
private static final String BT_ADDRESS_STR = "BT_ADDRESS_STR"; private static final String BT_ADDRESS_STR = "BT_ADDRESS_STR";
private enum BTCmd { private enum BTCmd {
PING, BAD_PROTO,
PONG, PING,
SCAN, PONG,
INVITE, SCAN,
INVITE_ACCPT, INVITE,
INVITE_DECL, INVITE_ACCPT,
INVITE_DUPID, INVITE_DECL,
INVITE_FAILED, // generic error INVITE_DUPID,
MESG_SEND, INVITE_FAILED, // generic error
MESG_ACCPT, MESG_SEND,
MESG_DECL, MESG_ACCPT,
MESG_GAMEGONE, MESG_DECL,
REMOVE_FOR, MESG_GAMEGONE,
}; REMOVE_FOR,
};
private class BTQueueElem { private class BTQueueElem {
int m_failCount; int m_failCount;
@ -409,9 +410,12 @@ public class BTService extends XWService {
byte proto = inStream.readByte(); byte proto = inStream.readByte();
if ( proto != BT_PROTO ) { if ( proto != BT_PROTO ) {
DataOutputStream os = new DataOutputStream( socket.getOutputStream() );
os.writeByte( BTCmd.BAD_PROTO.ordinal() );
os.flush();
socket.close(); socket.close();
sendResult( MultiEvent.BAD_PROTO,
socket.getRemoteDevice().getName() ); sendBadProto( socket );
} else { } else {
byte msg = inStream.readByte(); byte msg = inStream.readByte();
BTCmd cmd = BTCmd.values()[msg]; BTCmd cmd = BTCmd.values()[msg];
@ -464,7 +468,6 @@ public class BTService extends XWService {
private void receivePing( BluetoothSocket socket ) throws IOException private void receivePing( BluetoothSocket socket ) throws IOException
{ {
DbgUtils.logf( "got PING!!!" );
DataInputStream inStream = new DataInputStream( socket.getInputStream() ); DataInputStream inStream = new DataInputStream( socket.getInputStream() );
int gameID = inStream.readInt(); int gameID = inStream.readInt();
boolean deleted = 0 != gameID && !DBUtils.haveGame( BTService.this, gameID ); boolean deleted = 0 != gameID && !DBUtils.haveGame( BTService.this, gameID );
@ -716,9 +719,14 @@ public class BTService extends XWService {
DataInputStream is = DataInputStream is =
new DataInputStream( socket.getInputStream() ); new DataInputStream( socket.getInputStream() );
gotReply = BTCmd.PONG == BTCmd.values()[is.readByte()]; BTCmd reply = BTCmd.values()[is.readByte()];
if ( gotReply && is.readBoolean() ) { if ( BTCmd.BAD_PROTO == reply ) {
sendResult( MultiEvent.MESSAGE_NOGAME, gameID ); sendBadProto( socket );
} else {
gotReply = BTCmd.PONG == reply;
if ( gotReply && is.readBoolean() ) {
sendResult( MultiEvent.MESSAGE_NOGAME, gameID );
}
} }
receiveWorking = true; receiveWorking = true;
@ -751,7 +759,7 @@ public class BTService extends XWService {
BluetoothSocket socket = BluetoothSocket socket =
dev.createRfcommSocketToServiceRecord( XWApp.getAppUUID() ); dev.createRfcommSocketToServiceRecord( XWApp.getAppUUID() );
if ( null != socket ) { if ( null != socket ) {
boolean success = false; BTCmd reply = null;
DataOutputStream outStream = connect( socket, BTCmd.INVITE ); DataOutputStream outStream = connect( socket, BTCmd.INVITE );
if ( null != outStream ) { if ( null != outStream ) {
outStream.writeInt( elem.m_gameID ); outStream.writeInt( elem.m_gameID );
@ -764,16 +772,23 @@ public class BTService extends XWService {
DataInputStream inStream = DataInputStream inStream =
new DataInputStream( socket.getInputStream() ); new DataInputStream( socket.getInputStream() );
success = BTCmd.INVITE_ACCPT reply = BTCmd.values()[inStream.readByte()];
== BTCmd.values()[inStream.readByte()];
DbgUtils.logf( "sendInvite(): invite done: success=%b",
success );
} }
socket.close(); socket.close();
MultiEvent evt = success ? MultiEvent.NEWGAME_SUCCESS if ( BTCmd.BAD_PROTO == reply ) {
: MultiEvent.NEWGAME_FAILURE; sendBadProto( socket );
sendResult( evt, elem.m_gameID ); } else {
MultiEvent evt = null;
switch( reply ) {
case INVITE_ACCPT:
evt = MultiEvent.NEWGAME_SUCCESS;
break;
default:
evt = MultiEvent.NEWGAME_FAILURE;
}
sendResult( evt, elem.m_gameID );
}
} }
} catch ( IOException ioe ) { } catch ( IOException ioe ) {
logIOE( ioe ); logIOE( ioe );
@ -820,6 +835,10 @@ public class BTService extends XWService {
success = true; success = true;
switch ( reply ) { switch ( reply ) {
case BAD_PROTO:
sendBadProto( socket );
evt = null;
break;
case MESG_ACCPT: case MESG_ACCPT:
evt = MultiEvent.MESSAGE_ACCEPTED; evt = MultiEvent.MESSAGE_ACCEPTED;
break; break;
@ -836,12 +855,14 @@ public class BTService extends XWService {
} }
} }
String btName = nameForAddr( elem.m_btAddr ); if ( null != evt ) {
sendResult( evt, elem.m_gameID, 0, btName ); String btName = nameForAddr( elem.m_btAddr );
if ( ! success ) { sendResult( evt, elem.m_gameID, 0, btName );
int failCount = elem.incrFailCount(); if ( ! success ) {
sendResult( MultiEvent.MESSAGE_RESEND, btName, int failCount = elem.incrFailCount();
RESEND_TIMEOUT, failCount ); sendResult( MultiEvent.MESSAGE_RESEND, btName,
RESEND_TIMEOUT, failCount );
}
} }
return success; return success;
} // sendMsg } // sendMsg
@ -1058,6 +1079,11 @@ public class BTService extends XWService {
// } // }
} }
private void sendBadProto( BluetoothSocket socket )
{
sendResult( MultiEvent.BAD_PROTO, socket.getRemoteDevice().getName() );
}
private void postNotification( int gameID, int title, String body, private void postNotification( int gameID, int title, String body,
long rowid ) long rowid )
{ {

View file

@ -456,6 +456,14 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
} catch ( java.lang.RuntimeException re ) {} } catch ( java.lang.RuntimeException re ) {}
DbgUtils.logf( "Bluetooth error count: %d", count ); DbgUtils.logf( "Bluetooth error count: %d", count );
break; break;
case BAD_PROTO:
final String msg = getString( R.string.bt_bad_proto_fmt, (String)args[0] );
runOnUiThread( new Runnable() {
public void run() {
showOKOnlyDialog( msg );
}
});
break;
default: default:
DbgUtils.logf( "DelegateBase.eventOccurred(event=%s) (DROPPED)", event.toString() ); DbgUtils.logf( "DelegateBase.eventOccurred(event=%s) (DROPPED)", event.toString() );
} }

View file

@ -394,9 +394,6 @@ public class DlgDelegate {
String msg = null; String msg = null;
boolean asToast = true; boolean asToast = true;
switch( event ) { switch( event ) {
case BAD_PROTO:
msg = getString( R.string.bt_bad_proto_fmt, (String)args[0] );
break;
case MESSAGE_RESEND: case MESSAGE_RESEND:
msg = getString( R.string.bt_resend_fmt, (String)args[0], msg = getString( R.string.bt_resend_fmt, (String)args[0],
(Long)args[1], (Integer)args[2] ); (Long)args[1], (Integer)args[2] );